chartjs-plugin-autocolors 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  *Automatic color generation for [Chart.js](https://www.chartjs.org)*
4
4
 
5
+ ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/kurkle/chartjs-plugin-autocolors/CI)
6
+
5
7
  The generation is based on Janus Troelsen's answer at [Stack Overflow](https://stackoverflow.com/a/13781114/10359775).
6
8
 
7
9
  This plugin requires Chart.js 3.0.0 or later. Could work with v2, but it is not supported.
@@ -80,6 +82,8 @@ const chart = new Chart(ctx, {
80
82
 
81
83
  ### Mode
82
84
 
85
+ **NOTE:** `'dataset'` mode does not work properly for **Pie / Doughnut** charts, so using `'data'` mode with those charts is advised.
86
+
83
87
  There are two modes, `'dataset'` (default) and `'data'`
84
88
 
85
89
  - In `'dataset'` mode, a new color is picked for each dataset.
@@ -142,6 +146,24 @@ const chart = new Chart(ctx, {
142
146
  });
143
147
  ```
144
148
 
149
+ ### Repeat
150
+
151
+ Sometimes you might need to color multiple adjacent datasets with same color. The `repeat` option is for that use case.
152
+
153
+
154
+ ```js
155
+ const chart = new Chart(ctx, {
156
+ // ...
157
+ options: {
158
+ plugins: {
159
+ autocolors: {
160
+ repeat: 2
161
+ }
162
+ }
163
+ }
164
+ });
165
+ ```
166
+
145
167
  ## Browser compatibility
146
168
 
147
169
  This plugin uses a generator function, so it is not compatible with Internet Explorer.
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * chartjs-plugin-autocolors v0.0.7
2
+ * chartjs-plugin-autocolors v0.0.8
3
3
  * https://github.com/kurkle/chartjs-plugin-autocolors#readme
4
4
  * (c) 2022 Jukka Kurkela
5
5
  * Released under the MIT License
6
6
  */
7
7
  /*!
8
- * @kurkle/color v0.2.1
8
+ * @kurkle/color v0.3.0
9
9
  * https://github.com/kurkle/color#readme
10
10
  * (c) 2022 Jukka Kurkela
11
11
  * Released under the MIT License
@@ -52,14 +52,18 @@ function* hueGen() {
52
52
  }
53
53
  }
54
54
 
55
- function* colorGen() {
55
+ function* colorGen(repeat = 1) {
56
56
  const hue = hueGen();
57
57
  let h = hue.next();
58
58
  while (!h.done) {
59
59
  let rgb = hsv2rgb(Math.round(h.value * 360), 0.6, 0.8);
60
- yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};
60
+ for (let i = 0; i < repeat; i++) {
61
+ yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};
62
+ }
61
63
  rgb = hsv2rgb(Math.round(h.value * 360), 0.6, 0.5);
62
- yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};
64
+ for (let i = 0; i < repeat; i++) {
65
+ yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};
66
+ }
63
67
  h = hue.next();
64
68
  }
65
69
  }
@@ -80,14 +84,14 @@ function getNext(color, customize, context) {
80
84
  var index = {
81
85
  id: 'autocolors',
82
86
  beforeUpdate(chart, args, options) {
83
- const {mode = 'dataset', enabled = true, customize} = options;
87
+ const {mode = 'dataset', enabled = true, customize, repeat} = options;
84
88
 
85
89
  if (!enabled) {
86
90
  return;
87
91
  }
88
92
 
89
93
  if (!chart._autocolor) {
90
- chart._autocolor = colorGen();
94
+ chart._autocolor = colorGen(repeat);
91
95
  if (options.offset) {
92
96
  for (let i = 0; i < options.offset; i++) {
93
97
  chart._autocolor.next();
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * chartjs-plugin-autocolors v0.0.7
2
+ * chartjs-plugin-autocolors v0.0.8
3
3
  * https://github.com/kurkle/chartjs-plugin-autocolors#readme
4
4
  * (c) 2022 Jukka Kurkela
5
5
  * Released under the MIT License
@@ -11,7 +11,7 @@ typeof define === 'function' && define.amd ? define(factory) :
11
11
  })(this, (function () { 'use strict';
12
12
 
13
13
  /*!
14
- * @kurkle/color v0.2.1
14
+ * @kurkle/color v0.3.0
15
15
  * https://github.com/kurkle/color#readme
16
16
  * (c) 2022 Jukka Kurkela
17
17
  * Released under the MIT License
@@ -58,14 +58,18 @@ function* hueGen() {
58
58
  }
59
59
  }
60
60
 
61
- function* colorGen() {
61
+ function* colorGen(repeat = 1) {
62
62
  const hue = hueGen();
63
63
  let h = hue.next();
64
64
  while (!h.done) {
65
65
  let rgb = hsv2rgb(Math.round(h.value * 360), 0.6, 0.8);
66
- yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};
66
+ for (let i = 0; i < repeat; i++) {
67
+ yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};
68
+ }
67
69
  rgb = hsv2rgb(Math.round(h.value * 360), 0.6, 0.5);
68
- yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};
70
+ for (let i = 0; i < repeat; i++) {
71
+ yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};
72
+ }
69
73
  h = hue.next();
70
74
  }
71
75
  }
@@ -86,14 +90,14 @@ function getNext(color, customize, context) {
86
90
  var index = {
87
91
  id: 'autocolors',
88
92
  beforeUpdate(chart, args, options) {
89
- const {mode = 'dataset', enabled = true, customize} = options;
93
+ const {mode = 'dataset', enabled = true, customize, repeat} = options;
90
94
 
91
95
  if (!enabled) {
92
96
  return;
93
97
  }
94
98
 
95
99
  if (!chart._autocolor) {
96
- chart._autocolor = colorGen();
100
+ chart._autocolor = colorGen(repeat);
97
101
  if (options.offset) {
98
102
  for (let i = 0; i < options.offset; i++) {
99
103
  chart._autocolor.next();
@@ -1,14 +1,14 @@
1
1
  /*!
2
- * chartjs-plugin-autocolors v0.0.7
2
+ * chartjs-plugin-autocolors v0.0.8
3
3
  * https://github.com/kurkle/chartjs-plugin-autocolors#readme
4
4
  * (c) 2022 Jukka Kurkela
5
5
  * Released under the MIT License
6
6
  */
7
7
  !function(o,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(o="undefined"!=typeof globalThis?globalThis:o||self)["chartjs-plugin-autocolors"]=t()}(this,(function(){"use strict";
8
8
  /*!
9
- * @kurkle/color v0.2.1
9
+ * @kurkle/color v0.3.0
10
10
  * https://github.com/kurkle/color#readme
11
11
  * (c) 2022 Jukka Kurkela
12
12
  * Released under the MIT License
13
- */function o(o){return o+.5|0}const t=(o,t,r)=>Math.max(Math.min(o,r),t);function r(r){return t(o(255*r),0,255)}function e(o,t,r){const e=(e,n=(e+o/60)%6)=>r-r*t*Math.max(Math.min(n,4-n,1),0);return[e(5),e(3),e(1)]}function n(o,t,n){return a=e,u=o,d=t,c=n,(Array.isArray(u)?a(u[0],u[1],u[2]):a(u,d,c)).map(r);var a,u,d,c}function a(r){return r&&(r.a<255?`rgba(${r.r}, ${r.g}, ${r.b}, ${function(r){return t(o(r/2.55)/100,0,1)}(r.a)})`:`rgb(${r.r}, ${r.g}, ${r.b})`)}function u(o,t,r){o.backgroundColor=o.backgroundColor||t,o.borderColor=o.borderColor||r}function d(o,t,r){const e=o.next().value;return"function"==typeof t?t(Object.assign({colors:e},r)):e}return{id:"autocolors",beforeUpdate(o,t,r){const{mode:e="dataset",enabled:c=!0,customize:f}=r;if(c){if(!o._autocolor&&(o._autocolor=function*(){const o=function*(){yield 0;for(let o=1;o<10;o++){const t=1<<o;for(let o=1;o<=t;o+=2)yield o/t}}();let t=o.next();for(;!t.done;){let r=n(Math.round(360*t.value),.6,.8);yield{background:a({r:r[0],g:r[1],b:r[2],a:192}),border:a({r:r[0],g:r[1],b:r[2],a:144})},r=n(Math.round(360*t.value),.6,.5),yield{background:a({r:r[0],g:r[1],b:r[2],a:192}),border:a({r:r[0],g:r[1],b:r[2],a:144})},t=o.next()}}(),r.offset))for(let t=0;t<r.offset;t++)o._autocolor.next();for(const t of o.data.datasets)if(!t.backgroundColor||!t.borderColor)if("dataset"===e){const r=d(o._autocolor,f,{chart:o,datasetIndex:t.index});u(t,r.background,r.border)}else{const r=[],e=[];for(let n=0;n<t.data.length;n++){const a=d(o._autocolor,f,{chart:o,datasetIndex:t.index,dataIndex:n});r.push(a.background),e.push(a.border)}u(t,r,e)}}}}}));
13
+ */function o(o){return o+.5|0}const t=(o,t,e)=>Math.max(Math.min(o,e),t);function e(e){return t(o(255*e),0,255)}function r(o,t,e){const r=(r,n=(r+o/60)%6)=>e-e*t*Math.max(Math.min(n,4-n,1),0);return[r(5),r(3),r(1)]}function n(o,t,n){return a=r,u=o,d=t,c=n,(Array.isArray(u)?a(u[0],u[1],u[2]):a(u,d,c)).map(e);var a,u,d,c}function a(e){return e&&(e.a<255?`rgba(${e.r}, ${e.g}, ${e.b}, ${function(e){return t(o(e/2.55)/100,0,1)}(e.a)})`:`rgb(${e.r}, ${e.g}, ${e.b})`)}function u(o,t,e){o.backgroundColor=o.backgroundColor||t,o.borderColor=o.borderColor||e}function d(o,t,e){const r=o.next().value;return"function"==typeof t?t(Object.assign({colors:r},e)):r}return{id:"autocolors",beforeUpdate(o,t,e){const{mode:r="dataset",enabled:c=!0,customize:f,repeat:i}=e;if(c){if(!o._autocolor&&(o._autocolor=function*(o=1){const t=function*(){yield 0;for(let o=1;o<10;o++){const t=1<<o;for(let o=1;o<=t;o+=2)yield o/t}}();let e=t.next();for(;!e.done;){let r=n(Math.round(360*e.value),.6,.8);for(let t=0;t<o;t++)yield{background:a({r:r[0],g:r[1],b:r[2],a:192}),border:a({r:r[0],g:r[1],b:r[2],a:144})};r=n(Math.round(360*e.value),.6,.5);for(let t=0;t<o;t++)yield{background:a({r:r[0],g:r[1],b:r[2],a:192}),border:a({r:r[0],g:r[1],b:r[2],a:144})};e=t.next()}}(i),e.offset))for(let t=0;t<e.offset;t++)o._autocolor.next();for(const t of o.data.datasets)if(!t.backgroundColor||!t.borderColor)if("dataset"===r){const e=d(o._autocolor,f,{chart:o,datasetIndex:t.index});u(t,e.background,e.border)}else{const e=[],r=[];for(let n=0;n<t.data.length;n++){const a=d(o._autocolor,f,{chart:o,datasetIndex:t.index,dataIndex:n});e.push(a.background),r.push(a.border)}u(t,e,r)}}}}}));
14
14
  //# sourceMappingURL=chartjs-plugin-autocolors.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chartjs-plugin-autocolors.min.js","sources":["../node_modules/@kurkle/color/dist/color.esm.js","../src/index.js"],"sourcesContent":["/*!\n * @kurkle/color v0.3.0\n * https://github.com/kurkle/color#readme\n * (c) 2022 Jukka Kurkela\n * Released under the MIT License\n */\nfunction round(v) {\n return v + 0.5 | 0;\n}\nconst lim = (v, l, h) => Math.max(Math.min(v, h), l);\nfunction p2b(v) {\n return lim(round(v * 2.55), 0, 255);\n}\nfunction b2p(v) {\n return lim(round(v / 2.55), 0, 100);\n}\nfunction n2b(v) {\n return lim(round(v * 255), 0, 255);\n}\nfunction b2n(v) {\n return lim(round(v / 2.55) / 100, 0, 1);\n}\nfunction n2p(v) {\n return lim(round(v * 100), 0, 100);\n}\n\nconst map$1 = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, A: 10, B: 11, C: 12, D: 13, E: 14, F: 15, a: 10, b: 11, c: 12, d: 13, e: 14, f: 15};\nconst hex = [...'0123456789ABCDEF'];\nconst h1 = b => hex[b & 0xF];\nconst h2 = b => hex[(b & 0xF0) >> 4] + hex[b & 0xF];\nconst eq = b => ((b & 0xF0) >> 4) === (b & 0xF);\nconst isShort = v => eq(v.r) && eq(v.g) && eq(v.b) && eq(v.a);\nfunction hexParse(str) {\n var len = str.length;\n var ret;\n if (str[0] === '#') {\n if (len === 4 || len === 5) {\n ret = {\n r: 255 & map$1[str[1]] * 17,\n g: 255 & map$1[str[2]] * 17,\n b: 255 & map$1[str[3]] * 17,\n a: len === 5 ? map$1[str[4]] * 17 : 255\n };\n } else if (len === 7 || len === 9) {\n ret = {\n r: map$1[str[1]] << 4 | map$1[str[2]],\n g: map$1[str[3]] << 4 | map$1[str[4]],\n b: map$1[str[5]] << 4 | map$1[str[6]],\n a: len === 9 ? (map$1[str[7]] << 4 | map$1[str[8]]) : 255\n };\n }\n }\n return ret;\n}\nconst alpha = (a, f) => a < 255 ? f(a) : '';\nfunction hexString(v) {\n var f = isShort(v) ? h1 : h2;\n return v\n ? '#' + f(v.r) + f(v.g) + f(v.b) + alpha(v.a, f)\n : undefined;\n}\n\nconst HUE_RE = /^(hsla?|hwb|hsv)\\(\\s*([-+.e\\d]+)(?:deg)?[\\s,]+([-+.e\\d]+)%[\\s,]+([-+.e\\d]+)%(?:[\\s,]+([-+.e\\d]+)(%)?)?\\s*\\)$/;\nfunction hsl2rgbn(h, s, l) {\n const a = s * Math.min(l, 1 - l);\n const f = (n, k = (n + h / 30) % 12) => l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);\n return [f(0), f(8), f(4)];\n}\nfunction hsv2rgbn(h, s, v) {\n const f = (n, k = (n + h / 60) % 6) => v - v * s * Math.max(Math.min(k, 4 - k, 1), 0);\n return [f(5), f(3), f(1)];\n}\nfunction hwb2rgbn(h, w, b) {\n const rgb = hsl2rgbn(h, 1, 0.5);\n let i;\n if (w + b > 1) {\n i = 1 / (w + b);\n w *= i;\n b *= i;\n }\n for (i = 0; i < 3; i++) {\n rgb[i] *= 1 - w - b;\n rgb[i] += w;\n }\n return rgb;\n}\nfunction hueValue(r, g, b, d, max) {\n if (r === max) {\n return ((g - b) / d) + (g < b ? 6 : 0);\n }\n if (g === max) {\n return (b - r) / d + 2;\n }\n return (r - g) / d + 4;\n}\nfunction rgb2hsl(v) {\n const range = 255;\n const r = v.r / range;\n const g = v.g / range;\n const b = v.b / range;\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const l = (max + min) / 2;\n let h, s, d;\n if (max !== min) {\n d = max - min;\n s = l > 0.5 ? d / (2 - max - min) : d / (max + min);\n h = hueValue(r, g, b, d, max);\n h = h * 60 + 0.5;\n }\n return [h | 0, s || 0, l];\n}\nfunction calln(f, a, b, c) {\n return (\n Array.isArray(a)\n ? f(a[0], a[1], a[2])\n : f(a, b, c)\n ).map(n2b);\n}\nfunction hsl2rgb(h, s, l) {\n return calln(hsl2rgbn, h, s, l);\n}\nfunction hwb2rgb(h, w, b) {\n return calln(hwb2rgbn, h, w, b);\n}\nfunction hsv2rgb(h, s, v) {\n return calln(hsv2rgbn, h, s, v);\n}\nfunction hue(h) {\n return (h % 360 + 360) % 360;\n}\nfunction hueParse(str) {\n const m = HUE_RE.exec(str);\n let a = 255;\n let v;\n if (!m) {\n return;\n }\n if (m[5] !== v) {\n a = m[6] ? p2b(+m[5]) : n2b(+m[5]);\n }\n const h = hue(+m[2]);\n const p1 = +m[3] / 100;\n const p2 = +m[4] / 100;\n if (m[1] === 'hwb') {\n v = hwb2rgb(h, p1, p2);\n } else if (m[1] === 'hsv') {\n v = hsv2rgb(h, p1, p2);\n } else {\n v = hsl2rgb(h, p1, p2);\n }\n return {\n r: v[0],\n g: v[1],\n b: v[2],\n a: a\n };\n}\nfunction rotate(v, deg) {\n var h = rgb2hsl(v);\n h[0] = hue(h[0] + deg);\n h = hsl2rgb(h);\n v.r = h[0];\n v.g = h[1];\n v.b = h[2];\n}\nfunction hslString(v) {\n if (!v) {\n return;\n }\n const a = rgb2hsl(v);\n const h = a[0];\n const s = n2p(a[1]);\n const l = n2p(a[2]);\n return v.a < 255\n ? `hsla(${h}, ${s}%, ${l}%, ${b2n(v.a)})`\n : `hsl(${h}, ${s}%, ${l}%)`;\n}\n\nconst map = {\n x: 'dark',\n Z: 'light',\n Y: 're',\n X: 'blu',\n W: 'gr',\n V: 'medium',\n U: 'slate',\n A: 'ee',\n T: 'ol',\n S: 'or',\n B: 'ra',\n C: 'lateg',\n D: 'ights',\n R: 'in',\n Q: 'turquois',\n E: 'hi',\n P: 'ro',\n O: 'al',\n N: 'le',\n M: 'de',\n L: 'yello',\n F: 'en',\n K: 'ch',\n G: 'arks',\n H: 'ea',\n I: 'ightg',\n J: 'wh'\n};\nconst names$1 = {\n OiceXe: 'f0f8ff',\n antiquewEte: 'faebd7',\n aqua: 'ffff',\n aquamarRe: '7fffd4',\n azuY: 'f0ffff',\n beige: 'f5f5dc',\n bisque: 'ffe4c4',\n black: '0',\n blanKedOmond: 'ffebcd',\n Xe: 'ff',\n XeviTet: '8a2be2',\n bPwn: 'a52a2a',\n burlywood: 'deb887',\n caMtXe: '5f9ea0',\n KartYuse: '7fff00',\n KocTate: 'd2691e',\n cSO: 'ff7f50',\n cSnflowerXe: '6495ed',\n cSnsilk: 'fff8dc',\n crimson: 'dc143c',\n cyan: 'ffff',\n xXe: '8b',\n xcyan: '8b8b',\n xgTMnPd: 'b8860b',\n xWay: 'a9a9a9',\n xgYF: '6400',\n xgYy: 'a9a9a9',\n xkhaki: 'bdb76b',\n xmagFta: '8b008b',\n xTivegYF: '556b2f',\n xSange: 'ff8c00',\n xScEd: '9932cc',\n xYd: '8b0000',\n xsOmon: 'e9967a',\n xsHgYF: '8fbc8f',\n xUXe: '483d8b',\n xUWay: '2f4f4f',\n xUgYy: '2f4f4f',\n xQe: 'ced1',\n xviTet: '9400d3',\n dAppRk: 'ff1493',\n dApskyXe: 'bfff',\n dimWay: '696969',\n dimgYy: '696969',\n dodgerXe: '1e90ff',\n fiYbrick: 'b22222',\n flSOwEte: 'fffaf0',\n foYstWAn: '228b22',\n fuKsia: 'ff00ff',\n gaRsbSo: 'dcdcdc',\n ghostwEte: 'f8f8ff',\n gTd: 'ffd700',\n gTMnPd: 'daa520',\n Way: '808080',\n gYF: '8000',\n gYFLw: 'adff2f',\n gYy: '808080',\n honeyMw: 'f0fff0',\n hotpRk: 'ff69b4',\n RdianYd: 'cd5c5c',\n Rdigo: '4b0082',\n ivSy: 'fffff0',\n khaki: 'f0e68c',\n lavFMr: 'e6e6fa',\n lavFMrXsh: 'fff0f5',\n lawngYF: '7cfc00',\n NmoncEffon: 'fffacd',\n ZXe: 'add8e6',\n ZcSO: 'f08080',\n Zcyan: 'e0ffff',\n ZgTMnPdLw: 'fafad2',\n ZWay: 'd3d3d3',\n ZgYF: '90ee90',\n ZgYy: 'd3d3d3',\n ZpRk: 'ffb6c1',\n ZsOmon: 'ffa07a',\n ZsHgYF: '20b2aa',\n ZskyXe: '87cefa',\n ZUWay: '778899',\n ZUgYy: '778899',\n ZstAlXe: 'b0c4de',\n ZLw: 'ffffe0',\n lime: 'ff00',\n limegYF: '32cd32',\n lRF: 'faf0e6',\n magFta: 'ff00ff',\n maPon: '800000',\n VaquamarRe: '66cdaa',\n VXe: 'cd',\n VScEd: 'ba55d3',\n VpurpN: '9370db',\n VsHgYF: '3cb371',\n VUXe: '7b68ee',\n VsprRggYF: 'fa9a',\n VQe: '48d1cc',\n VviTetYd: 'c71585',\n midnightXe: '191970',\n mRtcYam: 'f5fffa',\n mistyPse: 'ffe4e1',\n moccasR: 'ffe4b5',\n navajowEte: 'ffdead',\n navy: '80',\n Tdlace: 'fdf5e6',\n Tive: '808000',\n TivedBb: '6b8e23',\n Sange: 'ffa500',\n SangeYd: 'ff4500',\n ScEd: 'da70d6',\n pOegTMnPd: 'eee8aa',\n pOegYF: '98fb98',\n pOeQe: 'afeeee',\n pOeviTetYd: 'db7093',\n papayawEp: 'ffefd5',\n pHKpuff: 'ffdab9',\n peru: 'cd853f',\n pRk: 'ffc0cb',\n plum: 'dda0dd',\n powMrXe: 'b0e0e6',\n purpN: '800080',\n YbeccapurpN: '663399',\n Yd: 'ff0000',\n Psybrown: 'bc8f8f',\n PyOXe: '4169e1',\n saddNbPwn: '8b4513',\n sOmon: 'fa8072',\n sandybPwn: 'f4a460',\n sHgYF: '2e8b57',\n sHshell: 'fff5ee',\n siFna: 'a0522d',\n silver: 'c0c0c0',\n skyXe: '87ceeb',\n UXe: '6a5acd',\n UWay: '708090',\n UgYy: '708090',\n snow: 'fffafa',\n sprRggYF: 'ff7f',\n stAlXe: '4682b4',\n tan: 'd2b48c',\n teO: '8080',\n tEstN: 'd8bfd8',\n tomato: 'ff6347',\n Qe: '40e0d0',\n viTet: 'ee82ee',\n JHt: 'f5deb3',\n wEte: 'ffffff',\n wEtesmoke: 'f5f5f5',\n Lw: 'ffff00',\n LwgYF: '9acd32'\n};\nfunction unpack() {\n const unpacked = {};\n const keys = Object.keys(names$1);\n const tkeys = Object.keys(map);\n let i, j, k, ok, nk;\n for (i = 0; i < keys.length; i++) {\n ok = nk = keys[i];\n for (j = 0; j < tkeys.length; j++) {\n k = tkeys[j];\n nk = nk.replace(k, map[k]);\n }\n k = parseInt(names$1[ok], 16);\n unpacked[nk] = [k >> 16 & 0xFF, k >> 8 & 0xFF, k & 0xFF];\n }\n return unpacked;\n}\n\nlet names;\nfunction nameParse(str) {\n if (!names) {\n names = unpack();\n names.transparent = [0, 0, 0, 0];\n }\n const a = names[str.toLowerCase()];\n return a && {\n r: a[0],\n g: a[1],\n b: a[2],\n a: a.length === 4 ? a[3] : 255\n };\n}\n\nconst RGB_RE = /^rgba?\\(\\s*([-+.\\d]+)(%)?[\\s,]+([-+.e\\d]+)(%)?[\\s,]+([-+.e\\d]+)(%)?(?:[\\s,/]+([-+.e\\d]+)(%)?)?\\s*\\)$/;\nfunction rgbParse(str) {\n const m = RGB_RE.exec(str);\n let a = 255;\n let r, g, b;\n if (!m) {\n return;\n }\n if (m[7] !== r) {\n const v = +m[7];\n a = m[8] ? p2b(v) : lim(v * 255, 0, 255);\n }\n r = +m[1];\n g = +m[3];\n b = +m[5];\n r = 255 & (m[2] ? p2b(r) : lim(r, 0, 255));\n g = 255 & (m[4] ? p2b(g) : lim(g, 0, 255));\n b = 255 & (m[6] ? p2b(b) : lim(b, 0, 255));\n return {\n r: r,\n g: g,\n b: b,\n a: a\n };\n}\nfunction rgbString(v) {\n return v && (\n v.a < 255\n ? `rgba(${v.r}, ${v.g}, ${v.b}, ${b2n(v.a)})`\n : `rgb(${v.r}, ${v.g}, ${v.b})`\n );\n}\n\nconst to = v => v <= 0.0031308 ? v * 12.92 : Math.pow(v, 1.0 / 2.4) * 1.055 - 0.055;\nconst from = v => v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);\nfunction interpolate(rgb1, rgb2, t) {\n const r = from(b2n(rgb1.r));\n const g = from(b2n(rgb1.g));\n const b = from(b2n(rgb1.b));\n return {\n r: n2b(to(r + t * (from(b2n(rgb2.r)) - r))),\n g: n2b(to(g + t * (from(b2n(rgb2.g)) - g))),\n b: n2b(to(b + t * (from(b2n(rgb2.b)) - b))),\n a: rgb1.a + t * (rgb2.a - rgb1.a)\n };\n}\n\nfunction modHSL(v, i, ratio) {\n if (v) {\n let tmp = rgb2hsl(v);\n tmp[i] = Math.max(0, Math.min(tmp[i] + tmp[i] * ratio, i === 0 ? 360 : 1));\n tmp = hsl2rgb(tmp);\n v.r = tmp[0];\n v.g = tmp[1];\n v.b = tmp[2];\n }\n}\nfunction clone(v, proto) {\n return v ? Object.assign(proto || {}, v) : v;\n}\nfunction fromObject(input) {\n var v = {r: 0, g: 0, b: 0, a: 255};\n if (Array.isArray(input)) {\n if (input.length >= 3) {\n v = {r: input[0], g: input[1], b: input[2], a: 255};\n if (input.length > 3) {\n v.a = n2b(input[3]);\n }\n }\n } else {\n v = clone(input, {r: 0, g: 0, b: 0, a: 1});\n v.a = n2b(v.a);\n }\n return v;\n}\nfunction functionParse(str) {\n if (str.charAt(0) === 'r') {\n return rgbParse(str);\n }\n return hueParse(str);\n}\nclass Color {\n constructor(input) {\n if (input instanceof Color) {\n return input;\n }\n const type = typeof input;\n let v;\n if (type === 'object') {\n v = fromObject(input);\n } else if (type === 'string') {\n v = hexParse(input) || nameParse(input) || functionParse(input);\n }\n this._rgb = v;\n this._valid = !!v;\n }\n get valid() {\n return this._valid;\n }\n get rgb() {\n var v = clone(this._rgb);\n if (v) {\n v.a = b2n(v.a);\n }\n return v;\n }\n set rgb(obj) {\n this._rgb = fromObject(obj);\n }\n rgbString() {\n return this._valid ? rgbString(this._rgb) : undefined;\n }\n hexString() {\n return this._valid ? hexString(this._rgb) : undefined;\n }\n hslString() {\n return this._valid ? hslString(this._rgb) : undefined;\n }\n mix(color, weight) {\n if (color) {\n const c1 = this.rgb;\n const c2 = color.rgb;\n let w2;\n const p = weight === w2 ? 0.5 : weight;\n const w = 2 * p - 1;\n const a = c1.a - c2.a;\n const w1 = ((w * a === -1 ? w : (w + a) / (1 + w * a)) + 1) / 2.0;\n w2 = 1 - w1;\n c1.r = 0xFF & w1 * c1.r + w2 * c2.r + 0.5;\n c1.g = 0xFF & w1 * c1.g + w2 * c2.g + 0.5;\n c1.b = 0xFF & w1 * c1.b + w2 * c2.b + 0.5;\n c1.a = p * c1.a + (1 - p) * c2.a;\n this.rgb = c1;\n }\n return this;\n }\n interpolate(color, t) {\n if (color) {\n this._rgb = interpolate(this._rgb, color._rgb, t);\n }\n return this;\n }\n clone() {\n return new Color(this.rgb);\n }\n alpha(a) {\n this._rgb.a = n2b(a);\n return this;\n }\n clearer(ratio) {\n const rgb = this._rgb;\n rgb.a *= 1 - ratio;\n return this;\n }\n greyscale() {\n const rgb = this._rgb;\n const val = round(rgb.r * 0.3 + rgb.g * 0.59 + rgb.b * 0.11);\n rgb.r = rgb.g = rgb.b = val;\n return this;\n }\n opaquer(ratio) {\n const rgb = this._rgb;\n rgb.a *= 1 + ratio;\n return this;\n }\n negate() {\n const v = this._rgb;\n v.r = 255 - v.r;\n v.g = 255 - v.g;\n v.b = 255 - v.b;\n return this;\n }\n lighten(ratio) {\n modHSL(this._rgb, 2, ratio);\n return this;\n }\n darken(ratio) {\n modHSL(this._rgb, 2, -ratio);\n return this;\n }\n saturate(ratio) {\n modHSL(this._rgb, 1, ratio);\n return this;\n }\n desaturate(ratio) {\n modHSL(this._rgb, 1, -ratio);\n return this;\n }\n rotate(deg) {\n rotate(this._rgb, deg);\n return this;\n }\n}\n\nfunction index_esm(input) {\n return new Color(input);\n}\n\nexport { Color, b2n, b2p, index_esm as default, hexParse, hexString, hsl2rgb, hslString, hsv2rgb, hueParse, hwb2rgb, lim, n2b, n2p, nameParse, p2b, rgb2hsl, rgbParse, rgbString, rotate, round };\n","import {hsv2rgb, rgbString} from '@kurkle/color';\n\nfunction* hueGen() {\n yield 0;\n for (let i = 1; i < 10; i++) {\n const d = 1 << i;\n for (let j = 1; j <= d; j += 2) {\n yield j / d;\n }\n }\n}\n\nfunction* colorGen(repeat = 1) {\n const hue = hueGen();\n let h = hue.next();\n while (!h.done) {\n let rgb = hsv2rgb(Math.round(h.value * 360), 0.6, 0.8);\n for (let i = 0; i < repeat; i++) {\n yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};\n }\n rgb = hsv2rgb(Math.round(h.value * 360), 0.6, 0.5);\n for (let i = 0; i < repeat; i++) {\n yield {background: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 192}), border: rgbString({r: rgb[0], g: rgb[1], b: rgb[2], a: 144})};\n }\n h = hue.next();\n }\n}\n\nfunction setColors(dataset, background, border) {\n dataset.backgroundColor = dataset.backgroundColor || background;\n dataset.borderColor = dataset.borderColor || border;\n}\n\nfunction getNext(color, customize, context) {\n const c = color.next().value;\n if (typeof customize === 'function') {\n return customize(Object.assign({colors: c}, context));\n }\n return c;\n}\n\nexport default {\n id: 'autocolors',\n beforeUpdate(chart, args, options) {\n const {mode = 'dataset', enabled = true, customize, repeat} = options;\n\n if (!enabled) {\n return;\n }\n\n if (!chart._autocolor) {\n chart._autocolor = colorGen(repeat);\n if (options.offset) {\n for (let i = 0; i < options.offset; i++) {\n chart._autocolor.next();\n }\n }\n }\n\n for (const dataset of chart.data.datasets) {\n if (dataset.backgroundColor && dataset.borderColor) {\n continue;\n }\n if (mode === 'dataset') {\n const c = getNext(chart._autocolor, customize, {chart, datasetIndex: dataset.index});\n setColors(dataset, c.background, c.border);\n } else {\n const background = [];\n const border = [];\n for (let i = 0; i < dataset.data.length; i++) {\n const c = getNext(chart._autocolor, customize, {chart, datasetIndex: dataset.index, dataIndex: i});\n background.push(c.background);\n border.push(c.border);\n }\n setColors(dataset, background, border);\n }\n }\n }\n};\n"],"names":["round","v","lim","l","h","Math","max","min","n2b","hsv2rgbn","s","f","n","k","hsv2rgb","a","b","c","Array","isArray","map","rgbString","r","g","b2n","setColors","dataset","background","border","backgroundColor","borderColor","getNext","color","customize","context","next","value","Object","assign","colors","id","beforeUpdate","chart","args","options","mode","enabled","repeat","_autocolor","hue","i","d","j","hueGen","done","rgb","colorGen","offset","data","datasets","datasetIndex","index","length","dataIndex","push"],"mappings":";;;;;;;;;;;;GAMA,SAASA,EAAMC,GACb,OAAOA,EAAI,GAAM,CACnB,CACA,MAAMC,EAAM,CAACD,EAAGE,EAAGC,IAAMC,KAAKC,IAAID,KAAKE,IAAIN,EAAGG,GAAID,GAOlD,SAASK,EAAIP,GACX,OAAOC,EAAIF,EAAU,IAAJC,GAAU,EAAG,IAChC,CAkDA,SAASQ,EAASL,EAAGM,EAAGT,GACtB,MAAMU,EAAI,CAACC,EAAGC,GAAKD,EAAIR,EAAI,IAAM,IAAMH,EAAIA,EAAIS,EAAIL,KAAKC,IAAID,KAAKE,IAAIM,EAAG,EAAIA,EAAG,GAAI,GACnF,MAAO,CAACF,EAAE,GAAIA,EAAE,GAAIA,EAAE,GACxB,CAsDA,SAASG,EAAQV,EAAGM,EAAGT,GACrB,OAdaU,EAcAF,EAdGM,EAcOX,EAdJY,EAcON,EAdJO,EAcOhB,GAZ3BiB,MAAMC,QAAQJ,GACVJ,EA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package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
2
  "name": "chartjs-plugin-autocolors",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Automatic color generation for Chart.js",
5
- "main": "dist/chartjs-plugin-autocolors.js",
6
- "module": "dist/chartjs-plugin-autocolors.esm.js",
5
+ "type": "module",
6
+ "main": "dist/chartjs-plugin-autocolors.esm.js",
7
+ "jsdelivr": "dist/dist/chartjs-plugin-autocolors.min.js",
8
+ "unpkg": "dist/dist/chartjs-plugin-autocolors.min.js",
9
+ "exports": {
10
+ ".": "./dist/chartjs-plugin-autocolors.esm.js"
11
+ },
7
12
  "scripts": {
8
13
  "build": "rollup -c",
9
- "lint": "eslint samples/**/*.html samples/**/*.js src/**/*.js **/*.md"
14
+ "lint": "eslint samples/**/*.html samples/**/*.js src/**/*.js **/*.md",
15
+ "test": "npm run lint"
10
16
  },
11
17
  "repository": {
12
18
  "type": "git",
13
19
  "url": "git+https://github.com/kurkle/chartjs-plugin-autocolors.git"
14
20
  },
15
21
  "files": [
16
- "dist/*.js"
22
+ "dist/*"
17
23
  ],
18
24
  "keywords": [
19
25
  "chart.js",
@@ -30,14 +36,17 @@
30
36
  },
31
37
  "homepage": "https://github.com/kurkle/chartjs-plugin-autocolors#readme",
32
38
  "devDependencies": {
33
- "@kurkle/color": "^0.2.1",
34
- "@rollup/plugin-node-resolve": "^14.1.0",
35
- "eslint": "^8.17.0",
39
+ "@kurkle/color": "^0.3.0",
40
+ "@rollup/plugin-node-resolve": "^15.0.1",
41
+ "@rollup/plugin-terser": "^0.1.0",
42
+ "eslint": "^8.29.0",
36
43
  "eslint-config-chartjs": "^0.3.0",
37
44
  "eslint-plugin-es": "^4.1.0",
38
45
  "eslint-plugin-html": "^7.1.0",
39
46
  "eslint-plugin-markdown": "^3.0.0",
40
- "rollup": "^2.33.2",
41
- "rollup-plugin-terser": "^7.0.2"
47
+ "rollup": "^3.7.0"
48
+ },
49
+ "peerDependencies": {
50
+ "chart.js": "^4.0.1"
42
51
  }
43
52
  }