chartjs-plugin-autocolors 0.0.9 → 0.2.0
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 +4 -3
- package/dist/{chartjs-plugin-autocolors.js → chartjs-plugin-autocolors.cjs} +36 -17
- package/dist/chartjs-plugin-autocolors.cjs.map +1 -0
- package/dist/chartjs-plugin-autocolors.esm.js +36 -53
- package/dist/chartjs-plugin-autocolors.esm.js.map +1 -0
- package/dist/chartjs-plugin-autocolors.min.js +6 -6
- package/dist/chartjs-plugin-autocolors.min.js.map +1 -1
- package/package.json +38 -8
- package/types/index.esm.d.ts +28 -0
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ This plugin requires Chart.js 3.0.0 or later. Could work with v2, but it is not
|
|
|
12
12
|
|
|
13
13
|
## Example
|
|
14
14
|
|
|
15
|
-

|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
@@ -84,10 +84,11 @@ const chart = new Chart(ctx, {
|
|
|
84
84
|
|
|
85
85
|
**NOTE:** `'dataset'` mode does not work properly for **Pie / Doughnut** charts, so using `'data'` mode with those charts is advised.
|
|
86
86
|
|
|
87
|
-
There are two modes, `'dataset'` (default) and `'
|
|
87
|
+
There are two modes, `'dataset'` (default) `'data'` and `'label'`
|
|
88
88
|
|
|
89
89
|
- In `'dataset'` mode, a new color is picked for each dataset.
|
|
90
90
|
- In `'data'` mode, an array of colors, equivalent to the length of data is provided for each dataset.
|
|
91
|
+
- In `'label'` mode, color is picked for each different dataset label.
|
|
91
92
|
|
|
92
93
|
```js
|
|
93
94
|
const chart = new Chart(ctx, {
|
|
@@ -170,4 +171,4 @@ This plugin uses a generator function, so it is not compatible with Internet Exp
|
|
|
170
171
|
|
|
171
172
|
## License
|
|
172
173
|
|
|
173
|
-
`chartjs-plugin-autocolors.js` is available under the [MIT license](https://github.com/kurkle/chartjs-plugin-autocolors/blob/
|
|
174
|
+
`chartjs-plugin-autocolors.js` is available under the [MIT license](https://github.com/kurkle/chartjs-plugin-autocolors/blob/main/LICENSE).
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* chartjs-plugin-autocolors v0.0
|
|
2
|
+
* chartjs-plugin-autocolors v0.2.0
|
|
3
3
|
* https://github.com/kurkle/chartjs-plugin-autocolors#readme
|
|
4
|
-
* (c) 2022 Jukka Kurkela
|
|
5
|
-
* Released under the MIT
|
|
4
|
+
* (c) 2022 Jukka Kurkela <jukka.kurkela@gmail.com>
|
|
5
|
+
* Released under the MIT license
|
|
6
6
|
*/
|
|
7
7
|
(function (global, factory) {
|
|
8
8
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -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.3.
|
|
14
|
+
* @kurkle/color v0.3.1
|
|
15
15
|
* https://github.com/kurkle/color#readme
|
|
16
16
|
* (c) 2022 Jukka Kurkela
|
|
17
17
|
* Released under the MIT License
|
|
@@ -77,6 +77,7 @@ function* colorGen(repeat = 1) {
|
|
|
77
77
|
function setColors(dataset, background, border) {
|
|
78
78
|
dataset.backgroundColor = dataset.backgroundColor || background;
|
|
79
79
|
dataset.borderColor = dataset.borderColor || border;
|
|
80
|
+
return dataset.backgroundColor === background && dataset.borderColor === border;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
function getNext(color, customize, context) {
|
|
@@ -96,29 +97,34 @@ var index = {
|
|
|
96
97
|
return;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
const gen = colorGen(repeat);
|
|
101
|
+
|
|
102
|
+
if (options.offset) {
|
|
103
|
+
// offset the color generation by n colors
|
|
104
|
+
for (let i = 0; i < options.offset; i++) {
|
|
105
|
+
gen.next();
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
if (mode === 'label') {
|
|
110
|
+
return labelMode(chart, gen, customize);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const datasetMode = mode === 'dataset';
|
|
114
|
+
|
|
115
|
+
let c = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: datasetMode ? undefined : 0});
|
|
108
116
|
for (const dataset of chart.data.datasets) {
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const c = getNext(chart._autocolor, customize, {chart, datasetIndex: dataset.index});
|
|
114
|
-
setColors(dataset, c.background, c.border);
|
|
117
|
+
if (datasetMode) {
|
|
118
|
+
if (setColors(dataset, c.background, c.border)) {
|
|
119
|
+
c = getNext(gen, customize, {chart, datasetIndex: dataset.index});
|
|
120
|
+
}
|
|
115
121
|
} else {
|
|
116
122
|
const background = [];
|
|
117
123
|
const border = [];
|
|
118
124
|
for (let i = 0; i < dataset.data.length; i++) {
|
|
119
|
-
const c = getNext(chart._autocolor, customize, {chart, datasetIndex: dataset.index, dataIndex: i});
|
|
120
125
|
background.push(c.background);
|
|
121
126
|
border.push(c.border);
|
|
127
|
+
c = getNext(gen, customize, {chart, datasetIndex: dataset.index, dataIndex: i});
|
|
122
128
|
}
|
|
123
129
|
setColors(dataset, background, border);
|
|
124
130
|
}
|
|
@@ -126,6 +132,19 @@ var index = {
|
|
|
126
132
|
}
|
|
127
133
|
};
|
|
128
134
|
|
|
135
|
+
function labelMode(chart, gen, customize) {
|
|
136
|
+
const colors = {};
|
|
137
|
+
for (const dataset of chart.data.datasets) {
|
|
138
|
+
const label = dataset.label ?? '';
|
|
139
|
+
if (!colors[label]) {
|
|
140
|
+
colors[label] = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: undefined, label});
|
|
141
|
+
}
|
|
142
|
+
const c = colors[label];
|
|
143
|
+
setColors(dataset, c.background, c.border);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
129
147
|
return index;
|
|
130
148
|
|
|
131
149
|
}));
|
|
150
|
+
//# sourceMappingURL=chartjs-plugin-autocolors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartjs-plugin-autocolors.cjs","sources":["../node_modules/@kurkle/color/dist/color.esm.js","../src/index.js"],"sourcesContent":["/*!\n * @kurkle/color v0.3.1\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 return dataset.backgroundColor === background && 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 const gen = colorGen(repeat);\n\n if (options.offset) {\n // offset the color generation by n colors\n for (let i = 0; i < options.offset; i++) {\n gen.next();\n }\n }\n\n if (mode === 'label') {\n return labelMode(chart, gen, customize);\n }\n\n const datasetMode = mode === 'dataset';\n\n let c = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: datasetMode ? undefined : 0});\n for (const dataset of chart.data.datasets) {\n if (datasetMode) {\n if (setColors(dataset, c.background, c.border)) {\n c = getNext(gen, customize, {chart, datasetIndex: dataset.index});\n }\n } else {\n const background = [];\n const border = [];\n for (let i = 0; i < dataset.data.length; i++) {\n background.push(c.background);\n border.push(c.border);\n c = getNext(gen, customize, {chart, datasetIndex: dataset.index, dataIndex: i});\n }\n setColors(dataset, background, border);\n }\n }\n }\n};\n\nfunction labelMode(chart, gen, customize) {\n const colors = {};\n for (const dataset of chart.data.datasets) {\n const label = dataset.label ?? '';\n if (!colors[label]) {\n colors[label] = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: undefined, label});\n }\n const c = colors[label];\n setColors(dataset, c.background, c.border);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,KAAK,CAAC,CAAC,EAAE;AAClB,EAAE,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;AACrB,CAAC;AACD,MAAM,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAOrD,SAAS,GAAG,CAAC,CAAC,EAAE;AAChB,EAAE,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC;AACD,SAAS,GAAG,CAAC,CAAC,EAAE;AAChB,EAAE,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1C,CAAC;AA+CD,SAAS,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;AAC3B,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC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AAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;AACrG,KAAK;AACL,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5B,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/C,GAAG;AACH;;;;;;;;"}
|
|
@@ -1,46 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* chartjs-plugin-autocolors v0.0
|
|
2
|
+
* chartjs-plugin-autocolors v0.2.0
|
|
3
3
|
* https://github.com/kurkle/chartjs-plugin-autocolors#readme
|
|
4
|
-
* (c) 2022 Jukka Kurkela
|
|
5
|
-
* Released under the MIT
|
|
4
|
+
* (c) 2022 Jukka Kurkela <jukka.kurkela@gmail.com>
|
|
5
|
+
* Released under the MIT license
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
* @kurkle/color v0.3.0
|
|
9
|
-
* https://github.com/kurkle/color#readme
|
|
10
|
-
* (c) 2022 Jukka Kurkela
|
|
11
|
-
* Released under the MIT License
|
|
12
|
-
*/
|
|
13
|
-
function round(v) {
|
|
14
|
-
return v + 0.5 | 0;
|
|
15
|
-
}
|
|
16
|
-
const lim = (v, l, h) => Math.max(Math.min(v, h), l);
|
|
17
|
-
function n2b(v) {
|
|
18
|
-
return lim(round(v * 255), 0, 255);
|
|
19
|
-
}
|
|
20
|
-
function b2n(v) {
|
|
21
|
-
return lim(round(v / 2.55) / 100, 0, 1);
|
|
22
|
-
}
|
|
23
|
-
function hsv2rgbn(h, s, v) {
|
|
24
|
-
const f = (n, k = (n + h / 60) % 6) => v - v * s * Math.max(Math.min(k, 4 - k, 1), 0);
|
|
25
|
-
return [f(5), f(3), f(1)];
|
|
26
|
-
}
|
|
27
|
-
function calln(f, a, b, c) {
|
|
28
|
-
return (
|
|
29
|
-
Array.isArray(a)
|
|
30
|
-
? f(a[0], a[1], a[2])
|
|
31
|
-
: f(a, b, c)
|
|
32
|
-
).map(n2b);
|
|
33
|
-
}
|
|
34
|
-
function hsv2rgb(h, s, v) {
|
|
35
|
-
return calln(hsv2rgbn, h, s, v);
|
|
36
|
-
}
|
|
37
|
-
function rgbString(v) {
|
|
38
|
-
return v && (
|
|
39
|
-
v.a < 255
|
|
40
|
-
? `rgba(${v.r}, ${v.g}, ${v.b}, ${b2n(v.a)})`
|
|
41
|
-
: `rgb(${v.r}, ${v.g}, ${v.b})`
|
|
42
|
-
);
|
|
43
|
-
}
|
|
7
|
+
import { hsv2rgb, rgbString } from '@kurkle/color';
|
|
44
8
|
|
|
45
9
|
function* hueGen() {
|
|
46
10
|
yield 0;
|
|
@@ -71,6 +35,7 @@ function* colorGen(repeat = 1) {
|
|
|
71
35
|
function setColors(dataset, background, border) {
|
|
72
36
|
dataset.backgroundColor = dataset.backgroundColor || background;
|
|
73
37
|
dataset.borderColor = dataset.borderColor || border;
|
|
38
|
+
return dataset.backgroundColor === background && dataset.borderColor === border;
|
|
74
39
|
}
|
|
75
40
|
|
|
76
41
|
function getNext(color, customize, context) {
|
|
@@ -90,29 +55,34 @@ var index = {
|
|
|
90
55
|
return;
|
|
91
56
|
}
|
|
92
57
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
58
|
+
const gen = colorGen(repeat);
|
|
59
|
+
|
|
60
|
+
if (options.offset) {
|
|
61
|
+
// offset the color generation by n colors
|
|
62
|
+
for (let i = 0; i < options.offset; i++) {
|
|
63
|
+
gen.next();
|
|
99
64
|
}
|
|
100
65
|
}
|
|
101
66
|
|
|
67
|
+
if (mode === 'label') {
|
|
68
|
+
return labelMode(chart, gen, customize);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const datasetMode = mode === 'dataset';
|
|
72
|
+
|
|
73
|
+
let c = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: datasetMode ? undefined : 0});
|
|
102
74
|
for (const dataset of chart.data.datasets) {
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const c = getNext(chart._autocolor, customize, {chart, datasetIndex: dataset.index});
|
|
108
|
-
setColors(dataset, c.background, c.border);
|
|
75
|
+
if (datasetMode) {
|
|
76
|
+
if (setColors(dataset, c.background, c.border)) {
|
|
77
|
+
c = getNext(gen, customize, {chart, datasetIndex: dataset.index});
|
|
78
|
+
}
|
|
109
79
|
} else {
|
|
110
80
|
const background = [];
|
|
111
81
|
const border = [];
|
|
112
82
|
for (let i = 0; i < dataset.data.length; i++) {
|
|
113
|
-
const c = getNext(chart._autocolor, customize, {chart, datasetIndex: dataset.index, dataIndex: i});
|
|
114
83
|
background.push(c.background);
|
|
115
84
|
border.push(c.border);
|
|
85
|
+
c = getNext(gen, customize, {chart, datasetIndex: dataset.index, dataIndex: i});
|
|
116
86
|
}
|
|
117
87
|
setColors(dataset, background, border);
|
|
118
88
|
}
|
|
@@ -120,4 +90,17 @@ var index = {
|
|
|
120
90
|
}
|
|
121
91
|
};
|
|
122
92
|
|
|
93
|
+
function labelMode(chart, gen, customize) {
|
|
94
|
+
const colors = {};
|
|
95
|
+
for (const dataset of chart.data.datasets) {
|
|
96
|
+
const label = dataset.label ?? '';
|
|
97
|
+
if (!colors[label]) {
|
|
98
|
+
colors[label] = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: undefined, label});
|
|
99
|
+
}
|
|
100
|
+
const c = colors[label];
|
|
101
|
+
setColors(dataset, c.background, c.border);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
123
105
|
export { index as default };
|
|
106
|
+
//# sourceMappingURL=chartjs-plugin-autocolors.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chartjs-plugin-autocolors.esm.js","sources":["../src/index.js"],"sourcesContent":["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 return dataset.backgroundColor === background && 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 const gen = colorGen(repeat);\n\n if (options.offset) {\n // offset the color generation by n colors\n for (let i = 0; i < options.offset; i++) {\n gen.next();\n }\n }\n\n if (mode === 'label') {\n return labelMode(chart, gen, customize);\n }\n\n const datasetMode = mode === 'dataset';\n\n let c = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: datasetMode ? undefined : 0});\n for (const dataset of chart.data.datasets) {\n if (datasetMode) {\n if (setColors(dataset, c.background, c.border)) {\n c = getNext(gen, customize, {chart, datasetIndex: dataset.index});\n }\n } else {\n const background = [];\n const border = [];\n for (let i = 0; i < dataset.data.length; i++) {\n background.push(c.background);\n border.push(c.border);\n c = getNext(gen, customize, {chart, datasetIndex: dataset.index, dataIndex: i});\n }\n setColors(dataset, background, border);\n }\n }\n }\n};\n\nfunction labelMode(chart, gen, customize) {\n const colors = {};\n for (const dataset of chart.data.datasets) {\n const label = dataset.label ?? '';\n if (!colors[label]) {\n colors[label] = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: undefined, label});\n }\n const c = colors[label];\n setColors(dataset, c.background, c.border);\n }\n}\n"],"names":[],"mappings":";;;;;;;;AAEA,UAAU,MAAM,GAAG;AACnB,EAAE,MAAM,CAAC,CAAC;AACV,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;AAC/B,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACrB,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;AACpC,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;AAClB,KAAK;AACL,GAAG;AACH,CAAC;AACD;AACA,UAAU,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;AAC/B,EAAE,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;AACvB,EAAE,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;AACrB,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;AAClB,IAAI,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAC3D,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;AACrC,MAAM,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,C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KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE;AAC7C,IAAI,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;AACtC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;AACxB,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;AACrG,KAAK;AACL,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5B,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/C,GAAG;AACH;;;;"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* chartjs-plugin-autocolors v0.0
|
|
2
|
+
* chartjs-plugin-autocolors v0.2.0
|
|
3
3
|
* https://github.com/kurkle/chartjs-plugin-autocolors#readme
|
|
4
|
-
* (c) 2022 Jukka Kurkela
|
|
5
|
-
* Released under the MIT
|
|
4
|
+
* (c) 2022 Jukka Kurkela <jukka.kurkela@gmail.com>
|
|
5
|
+
* Released under the MIT license
|
|
6
6
|
*/
|
|
7
|
-
!function(o
|
|
7
|
+
!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(t="undefined"!=typeof globalThis?globalThis:t||self)["chartjs-plugin-autocolors"]=o()}(this,(function(){"use strict";
|
|
8
8
|
/*!
|
|
9
|
-
* @kurkle/color v0.3.
|
|
9
|
+
* @kurkle/color v0.3.1
|
|
10
10
|
* https://github.com/kurkle/color#readme
|
|
11
11
|
* (c) 2022 Jukka Kurkela
|
|
12
12
|
* Released under the MIT License
|
|
13
|
-
*/function
|
|
13
|
+
*/function t(t){return t+.5|0}const o=(t,o,e)=>Math.max(Math.min(t,e),o);function e(e){return o(t(255*e),0,255)}function n(t,o,e){const n=(n,r=(n+t/60)%6)=>e-e*o*Math.max(Math.min(r,4-r,1),0);return[n(5),n(3),n(1)]}function r(t,o,r){return a=n,d=t,u=o,c=r,(Array.isArray(d)?a(d[0],d[1],d[2]):a(d,u,c)).map(e);var a,d,u,c}function a(e){return e&&(e.a<255?`rgba(${e.r}, ${e.g}, ${e.b}, ${function(e){return o(t(e/2.55)/100,0,1)}(e.a)})`:`rgb(${e.r}, ${e.g}, ${e.b})`)}function d(t,o,e){return t.backgroundColor=t.backgroundColor||o,t.borderColor=t.borderColor||e,t.backgroundColor===o&&t.borderColor===e}function u(t,o,e){const n=t.next().value;return"function"==typeof o?o(Object.assign({colors:n},e)):n}return{id:"autocolors",beforeUpdate(t,o,e){const{mode:n="dataset",enabled:c=!0,customize:f,repeat:s}=e;if(!c)return;const i=function*(t=1){const o=function*(){yield 0;for(let t=1;t<10;t++){const o=1<<t;for(let t=1;t<=o;t+=2)yield t/o}}();let e=o.next();for(;!e.done;){let n=r(Math.round(360*e.value),.6,.8);for(let o=0;o<t;o++)yield{background:a({r:n[0],g:n[1],b:n[2],a:192}),border:a({r:n[0],g:n[1],b:n[2],a:144})};n=r(Math.round(360*e.value),.6,.5);for(let o=0;o<t;o++)yield{background:a({r:n[0],g:n[1],b:n[2],a:192}),border:a({r:n[0],g:n[1],b:n[2],a:144})};e=o.next()}}(s);if(e.offset)for(let t=0;t<e.offset;t++)i.next();if("label"===n)return function(t,o,e){const n={};for(const r of t.data.datasets){const a=r.label??"";n[a]||(n[a]=u(o,e,{chart:t,datasetIndex:0,dataIndex:void 0,label:a}));const c=n[a];d(r,c.background,c.border)}}(t,i,f);const l="dataset"===n;let b=u(i,f,{chart:t,datasetIndex:0,dataIndex:l?void 0:0});for(const o of t.data.datasets)if(l)d(o,b.background,b.border)&&(b=u(i,f,{chart:t,datasetIndex:o.index}));else{const e=[],n=[];for(let r=0;r<o.data.length;r++)e.push(b.background),n.push(b.border),b=u(i,f,{chart:t,datasetIndex:o.index,dataIndex:r});d(o,e,n)}}}}));
|
|
14
14
|
//# sourceMappingURL=chartjs-plugin-autocolors.min.js.map
|
|
@@ -1 +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,EAAEI,EAAE,GAAIA,EAAE,GAAIA,EAAE,IAChBJ,EAAEI,EAAGC,EAAGC,IACZG,IAAIZ,GALR,IAAeG,EAAGI,EAAGC,EAAGC,CAexB,CAgSA,SAASI,EAAUpB,GACjB,OAAOA,IACLA,EAAEc,EAAI,IACF,QAAQd,EAAEqB,MAAMrB,EAAEsB,MAAMtB,EAAEe,MA/YlC,SAAaf,GACX,OAAOC,EAAIF,EAAMC,EAAI,MAAQ,IAAK,EAAG,EACvC,CA6YwCuB,CAAIvB,EAAEc,MACtC,OAA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AYN,EAAU,CAACC,EAAGiC,EAAI,GAAIhC,EAAGgC,EAAI,GAAIvC,EAAGuC,EAAI,GAAIxC,EAAG,MAAOa,OAAQP,EAAU,CAACC,EAAGiC,EAAI,GAAIhC,EAAGgC,EAAI,GAAIvC,EAAGuC,EAAI,GAAIxC,EAAG,OAElIX,EAAI6C,EAAId,MACT,CACH,CAyByBqB,CAAST,GACxBH,EAAQa,QACV,IAAK,IAAIP,EAAI,EAAGA,EAAIN,EAAQa,OAAQP,IAClCR,EAAMM,WAAWb,OAKvB,IAAK,MAAMT,KAAWgB,EAAMgB,KAAKC,SAC/B,IAAIjC,EAAQG,kBAAmBH,EAAQI,YAGvC,GAAa,YAATe,EAAoB,CACtB,MAAM5B,EAAIc,EAAQW,EAAMM,WAAYf,EAAW,CAACS,QAAOkB,aAAclC,EAAQmC,QAC7EpC,EAAUC,EAAST,EAAEU,WAAYV,EAAEW,OAC3C,KAAa,CACL,MAAMD,EAAa,GACbC,EAAS,GACf,IAAK,IAAIsB,EAAI,EAAGA,EAAIxB,EAAQgC,KAAKI,OAAQZ,IAAK,CAC5C,MAAMjC,EAAIc,EAAQW,EAAMM,WAAYf,EAAW,CAACS,QAAOkB,aAAclC,EAAQmC,MAAOE,UAAWb,IAC/FvB,EAAWqC,KAAK/C,EAAEU,YAClBC,EAAOoC,KAAK/C,EAAEW,OACf,CACDH,EAAUC,EAASC,EAAYC,EAChC,CA3BF,CA6BF"}
|
|
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.1\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 return dataset.backgroundColor === background && 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 const gen = colorGen(repeat);\n\n if (options.offset) {\n // offset the color generation by n colors\n for (let i = 0; i < options.offset; i++) {\n gen.next();\n }\n }\n\n if (mode === 'label') {\n return labelMode(chart, gen, customize);\n }\n\n const datasetMode = mode === 'dataset';\n\n let c = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: datasetMode ? undefined : 0});\n for (const dataset of chart.data.datasets) {\n if (datasetMode) {\n if (setColors(dataset, c.background, c.border)) {\n c = getNext(gen, customize, {chart, datasetIndex: dataset.index});\n }\n } else {\n const background = [];\n const border = [];\n for (let i = 0; i < dataset.data.length; i++) {\n background.push(c.background);\n border.push(c.border);\n c = getNext(gen, customize, {chart, datasetIndex: dataset.index, dataIndex: i});\n }\n setColors(dataset, background, border);\n }\n }\n }\n};\n\nfunction labelMode(chart, gen, customize) {\n const colors = {};\n for (const dataset of chart.data.datasets) {\n const label = dataset.label ?? '';\n if (!colors[label]) {\n colors[label] = getNext(gen, customize, {chart, datasetIndex: 0, dataIndex: undefined, label});\n }\n const c = colors[label];\n setColors(dataset, c.background, c.border);\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","gen","hue","i","d","j","hueGen","done","rgb","colorGen","offset","data","datasets","label","datasetIndex","dataIndex","undefined","labelMode","datasetMode","index","length","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,EAAEI,EAAE,GAAIA,EAAE,GAAIA,EAAE,IAChBJ,EAAEI,EAAGC,EAAGC,IACZG,IAAIZ,GALR,IAAeG,EAAGI,EAAGC,EAAGC,CAexB,CAgSA,SAASI,EAAUpB,GACjB,OAAOA,IACLA,EAAEc,EAAI,IACF,QAAQd,EAAEqB,MAAMrB,EAAEsB,MAAMtB,EAAEe,MA/YlC,SAAaf,GACX,OAAOC,EAAIF,EAAMC,EAAI,MAAQ,IAAK,EAAG,EACvC,CA6YwCuB,CAAIvB,EAAEc,MACtC,OAAOd,EAAEqB,MAAMrB,EAAEsB,MAAMtB,EAAEe,KAEjC,CCzYA,SAASS,EAAUC,EAASC,EAAYC,GAGtC,OAFAF,EAAQG,gBAAkBH,EAAQG,iBAAmBF,EACrDD,EAAQI,YAAcJ,EAAQI,aAAeF,EAC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"chartjs-plugin-autocolors",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Automatic color generation for Chart.js",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/chartjs-plugin-autocolors.
|
|
6
|
+
"main": "dist/chartjs-plugin-autocolors.cjs",
|
|
7
|
+
"module": "dist/chartjs-plugin-autocolors.esm.js",
|
|
8
|
+
"types": "types/index.esm.d.ts",
|
|
7
9
|
"jsdelivr": "dist/chartjs-plugin-autocolors.min.js",
|
|
8
10
|
"unpkg": "dist/chartjs-plugin-autocolors.min.js",
|
|
9
11
|
"exports": {
|
|
12
|
+
"types": "./types/index.esm.d.ts",
|
|
10
13
|
"import": "./dist/chartjs-plugin-autocolors.esm.js",
|
|
11
|
-
"require": "./dist/chartjs-plugin-autocolors.
|
|
14
|
+
"require": "./dist/chartjs-plugin-autocolors.cjs",
|
|
15
|
+
"script": "./dist/chartjs-plugin-autocolors.min.js"
|
|
12
16
|
},
|
|
17
|
+
"sideEffects": false,
|
|
13
18
|
"scripts": {
|
|
19
|
+
"autobuild": "rollup -c -w",
|
|
14
20
|
"build": "rollup -c",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
21
|
+
"dev": "karma start ./karma.conf.cjs --no-signle-run --auto-watch --browsers chrome",
|
|
22
|
+
"lint": "concurrently -r \"npm:lint-*\"",
|
|
23
|
+
"lint-js": "eslint \"src/**/*.js\"",
|
|
24
|
+
"lint-md": "eslint \"**/*.md\"",
|
|
25
|
+
"lint-types": "eslint \"types/**/*.ts\" && tsc -p types/tests/",
|
|
26
|
+
"lint-html": "eslint \"samples/**/*.html\"",
|
|
27
|
+
"test": "cross-env NODE_ENV=test concurrently \"npm:test-*\"",
|
|
28
|
+
"test-lint": "npm run lint",
|
|
29
|
+
"test-karma": "karma start ./karma.conf.cjs --auto-watch --single-run"
|
|
17
30
|
},
|
|
18
31
|
"repository": {
|
|
19
32
|
"type": "git",
|
|
20
33
|
"url": "git+https://github.com/kurkle/chartjs-plugin-autocolors.git"
|
|
21
34
|
},
|
|
22
35
|
"files": [
|
|
23
|
-
"dist/*"
|
|
36
|
+
"dist/*",
|
|
37
|
+
"types/index.esm.d.ts"
|
|
24
38
|
],
|
|
25
39
|
"keywords": [
|
|
26
40
|
"chart.js",
|
|
@@ -37,17 +51,33 @@
|
|
|
37
51
|
},
|
|
38
52
|
"homepage": "https://github.com/kurkle/chartjs-plugin-autocolors#readme",
|
|
39
53
|
"devDependencies": {
|
|
40
|
-
"@kurkle/color": "^0.3.
|
|
54
|
+
"@kurkle/color": "^0.3.1",
|
|
55
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
41
56
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
42
57
|
"@rollup/plugin-terser": "^0.1.0",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.46.0",
|
|
59
|
+
"chartjs-test-utils": "^0.5.0",
|
|
60
|
+
"concurrently": "^7.6.0",
|
|
61
|
+
"cross-env": "^7.0.3",
|
|
43
62
|
"eslint": "^8.29.0",
|
|
44
63
|
"eslint-config-chartjs": "^0.3.0",
|
|
45
64
|
"eslint-plugin-es": "^4.1.0",
|
|
46
65
|
"eslint-plugin-html": "^7.1.0",
|
|
47
66
|
"eslint-plugin-markdown": "^3.0.0",
|
|
48
|
-
"
|
|
67
|
+
"karma": "^6.4.1",
|
|
68
|
+
"karma-chrome-launcher": "^3.1.1",
|
|
69
|
+
"karma-coverage": "^2.2.0",
|
|
70
|
+
"karma-firefox-launcher": "^2.1.2",
|
|
71
|
+
"karma-jasmine": "^5.1.0",
|
|
72
|
+
"karma-jasmine-html-reporter": "^2.0.0",
|
|
73
|
+
"karma-rollup-preprocessor": "^7.0.7",
|
|
74
|
+
"karma-spec-reporter": "^0.0.36",
|
|
75
|
+
"rollup": "^3.7.0",
|
|
76
|
+
"rollup-plugin-istanbul": "^4.0.0",
|
|
77
|
+
"typescript": "^4.9.4"
|
|
49
78
|
},
|
|
50
79
|
"peerDependencies": {
|
|
80
|
+
"@kurkle/color": "^0.3.1",
|
|
51
81
|
"chart.js": "^4.0.1"
|
|
52
82
|
}
|
|
53
83
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Chart, ChartType } from 'chart.js';
|
|
2
|
+
|
|
3
|
+
declare module 'chart.js' {
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
interface PluginOptionsByType<TType extends ChartType> {
|
|
6
|
+
autocolors?: AutocolorsOptions
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ColorsDescriptor {
|
|
11
|
+
background: string
|
|
12
|
+
border: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface AutocolorsOptions {
|
|
16
|
+
enabled?: boolean,
|
|
17
|
+
mode?: 'dataset' | 'data' | 'label',
|
|
18
|
+
offset?: number,
|
|
19
|
+
repeat?: number,
|
|
20
|
+
customize?: (ctx: AutocolorsContext, options: AutocolorsOptions) => ColorsDescriptor
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface AutocolorsContext {
|
|
24
|
+
chart: Chart
|
|
25
|
+
colors: ColorsDescriptor
|
|
26
|
+
dataIndex?: number
|
|
27
|
+
datasetIndex: number
|
|
28
|
+
}
|