@hpcc-js/common 2.73.3 → 2.73.4

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.
Files changed (58) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +59 -59
  3. package/dist/index.es6.js +2 -2
  4. package/dist/index.es6.js.map +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.min.js +1 -1
  8. package/dist/index.min.js.map +1 -1
  9. package/package.json +3 -3
  10. package/src/CanvasWidget.ts +31 -31
  11. package/src/Class.ts +67 -67
  12. package/src/Database.ts +856 -856
  13. package/src/Entity.ts +235 -235
  14. package/src/EntityCard.ts +66 -66
  15. package/src/EntityPin.ts +103 -103
  16. package/src/EntityRect.css +15 -15
  17. package/src/EntityRect.ts +236 -236
  18. package/src/EntityVertex.ts +86 -86
  19. package/src/FAChar.css +2 -2
  20. package/src/FAChar.ts +82 -82
  21. package/src/HTMLWidget.ts +191 -191
  22. package/src/IList.ts +4 -4
  23. package/src/IMenu.ts +5 -5
  24. package/src/Icon.css +9 -9
  25. package/src/Icon.ts +164 -164
  26. package/src/Image.ts +95 -95
  27. package/src/List.css +13 -13
  28. package/src/List.ts +99 -99
  29. package/src/Menu.css +23 -23
  30. package/src/Menu.ts +134 -134
  31. package/src/Palette.ts +341 -341
  32. package/src/Platform.ts +125 -125
  33. package/src/ProgressBar.ts +105 -105
  34. package/src/PropertyExt.ts +793 -793
  35. package/src/ResizeSurface.css +39 -39
  36. package/src/ResizeSurface.ts +221 -221
  37. package/src/SVGWidget.ts +567 -567
  38. package/src/SVGZoomWidget.css +12 -12
  39. package/src/SVGZoomWidget.ts +426 -426
  40. package/src/Shape.css +3 -3
  41. package/src/Shape.ts +186 -186
  42. package/src/Surface.css +35 -35
  43. package/src/Surface.ts +349 -349
  44. package/src/Text.css +4 -4
  45. package/src/Text.ts +131 -131
  46. package/src/TextBox.css +4 -4
  47. package/src/TextBox.ts +168 -168
  48. package/src/TitleBar.css +99 -99
  49. package/src/TitleBar.ts +401 -401
  50. package/src/Transition.ts +45 -45
  51. package/src/Utility.ts +839 -839
  52. package/src/Widget.css +8 -8
  53. package/src/Widget.ts +730 -730
  54. package/src/WidgetArray.ts +13 -13
  55. package/src/__package__.ts +3 -3
  56. package/src/index.ts +55 -55
  57. package/types/__package__.d.ts +2 -2
  58. package/types-3.4/__package__.d.ts +2 -2
package/src/Palette.ts CHANGED
@@ -1,341 +1,341 @@
1
- import * as _colorbrewer from "colorbrewer";
2
- import { values as d3Values } from "d3-collection";
3
- import { rgb as d3RGB } from "d3-color";
4
- import { interpolateLab as d3InterpolateLab } from "d3-interpolate";
5
- import { interpolateInferno as d3InterpolateInferno, interpolateMagma as d3InterpolateMagma, interpolatePlasma as d3InterpolatePlasma, interpolateViridis as d3InterpolateViridis, scaleLinear as d3ScaleLinear, scaleOrdinal as d3ScaleOrdinal, scaleQuantize as d3ScaleQuantize, scaleSequential as d3ScaleSequential, schemeCategory10 as d3SchemeCategory10, schemeCategory20 as d3SchemeCategory20, schemeCategory20b as d3SchemeCategory20b, schemeCategory20c as d3SchemeCategory20c } from "d3-scale";
6
- import { select as d3Select } from "d3-selection";
7
-
8
- const d3Schemes = {
9
- category10: d3SchemeCategory10,
10
- category20: d3SchemeCategory20,
11
- category20b: d3SchemeCategory20b,
12
- category20c: d3SchemeCategory20c
13
- };
14
-
15
- const m_colorbrewer = _colorbrewer.default || _colorbrewer;
16
-
17
- const m_d3 = {
18
- Viridis: d3InterpolateViridis,
19
- Magma: d3InterpolateMagma,
20
- Inferno: d3InterpolateInferno,
21
- Plasma: d3InterpolatePlasma
22
- };
23
-
24
- const d3Ordinal = [
25
- "category10", "category20", "category20b", "category20c"
26
- ];
27
-
28
- const brewerOrdinal = [
29
- "Accent", "Dark2", "Paired", "Pastel1", "Pastel2", "Set1", "Set2", "Set3"
30
- ];
31
-
32
- const hpccOrdinal = [
33
- "hpcc10", "hpcc20"
34
- ];
35
-
36
- // These color schemes are from www.flatuicolors.com
37
- const flatuiSchemes = {
38
- FlatUI_default: ["rgb(26, 188, 156)", "rgb(46, 204, 113)", "rgb(52, 152, 219)", "rgb(155, 89, 182)", "rgb(52, 73, 94)", "rgb(22, 160, 133)", "rgb(39, 174, 96)", "rgb(41, 128, 185)", "rgb(142, 68, 173)", "rgb(44, 62, 80)", "rgb(241, 196, 15)", "rgb(230, 126, 34)", "rgb(231, 76, 60)", "rgb(236, 240, 241)", "rgb(149, 165, 166)", "rgb(243, 156, 18)", "rgb(211, 84, 0)", "rgb(192, 57, 43)", "rgb(189, 195, 199)", "rgb(127, 140, 141)"],
39
- FlatUI_American: ["rgb(85, 239, 196)", "rgb(129, 236, 236)", "rgb(116, 185, 255)", "rgb(162, 155, 254)", "rgb(223, 230, 233)", "rgb(0, 184, 148)", "rgb(0, 206, 201)", "rgb(9, 132, 227)", "rgb(108, 92, 231)", "rgb(178, 190, 195)", "rgb(255, 234, 167)", "rgb(250, 177, 160)", "rgb(255, 118, 117)", "rgb(253, 121, 168)", "rgb(99, 110, 114)", "rgb(253, 203, 110)", "rgb(225, 112, 85)", "rgb(214, 48, 49)", "rgb(232, 67, 147)", "rgb(45, 52, 54)"],
40
- FlatUI_Aussie: ["rgb(246, 229, 141)", "rgb(255, 190, 118)", "rgb(255, 121, 121)", "rgb(186, 220, 88)", "rgb(223, 249, 251)", "rgb(249, 202, 36)", "rgb(240, 147, 43)", "rgb(235, 77, 75)", "rgb(106, 176, 76)", "rgb(199, 236, 238)", "rgb(126, 214, 223)", "rgb(224, 86, 253)", "rgb(104, 109, 224)", "rgb(48, 51, 107)", "rgb(149, 175, 192)", "rgb(34, 166, 179)", "rgb(190, 46, 221)", "rgb(72, 52, 212)", "rgb(19, 15, 64)", "rgb(83, 92, 104)"],
41
- FlatUI_British: ["rgb(0, 168, 255)", "rgb(156, 136, 255)", "rgb(251, 197, 49)", "rgb(76, 209, 55)", "rgb(72, 126, 176)", "rgb(0, 151, 230)", "rgb(140, 122, 230)", "rgb(225, 177, 44)", "rgb(68, 189, 50)", "rgb(64, 115, 158)", "rgb(232, 65, 24)", "rgb(245, 246, 250)", "rgb(127, 143, 166)", "rgb(39, 60, 117)", "rgb(53, 59, 72)", "rgb(194, 54, 22)", "rgb(220, 221, 225)", "rgb(113, 128, 147)", "rgb(25, 42, 86)", "rgb(47, 54, 64)"],
42
- FlatUI_Canadian: ["rgb(255, 159, 243)", "rgb(254, 202, 87)", "rgb(255, 107, 107)", "rgb(72, 219, 251)", "rgb(29, 209, 161)", "rgb(243, 104, 224)", "rgb(255, 159, 67)", "rgb(238, 82, 83)", "rgb(10, 189, 227)", "rgb(16, 172, 132)", "rgb(0, 210, 211)", "rgb(84, 160, 255)", "rgb(95, 39, 205)", "rgb(200, 214, 229)", "rgb(87, 101, 116)", "rgb(1, 163, 164)", "rgb(46, 134, 222)", "rgb(52, 31, 151)", "rgb(131, 149, 167)", "rgb(34, 47, 62)"],
43
- FlatUI_Chinese: ["rgb(236, 204, 104)", "rgb(255, 127, 80)", "rgb(255, 107, 129)", "rgb(164, 176, 190)", "rgb(87, 96, 111)", "rgb(255, 165, 2)", "rgb(255, 99, 72)", "rgb(255, 71, 87)", "rgb(116, 125, 140)", "rgb(47, 53, 66)", "rgb(123, 237, 159)", "rgb(112, 161, 255)", "rgb(83, 82, 237)", "rgb(255, 255, 255)", "rgb(223, 228, 234)", "rgb(46, 213, 115)", "rgb(30, 144, 255)", "rgb(55, 66, 250)", "rgb(241, 242, 246)", "rgb(206, 214, 224)"],
44
- FlatUI_Dutch: ["rgb(255, 195, 18)", "rgb(196, 229, 56)", "rgb(18, 203, 196)", "rgb(253, 167, 223)", "rgb(237, 76, 103)", "rgb(247, 159, 31)", "rgb(163, 203, 56)", "rgb(18, 137, 167)", "rgb(217, 128, 250)", "rgb(181, 52, 113)", "rgb(238, 90, 36)", "rgb(0, 148, 50)", "rgb(6, 82, 221)", "rgb(153, 128, 250)", "rgb(131, 52, 113)", "rgb(234, 32, 39)", "rgb(0, 98, 102)", "rgb(27, 20, 100)", "rgb(87, 88, 187)", "rgb(111, 30, 81)"],
45
- FlatUI_French: ["rgb(250, 211, 144)", "rgb(248, 194, 145)", "rgb(106, 137, 204)", "rgb(130, 204, 221)", "rgb(184, 233, 148)", "rgb(246, 185, 59)", "rgb(229, 80, 57)", "rgb(74, 105, 189)", "rgb(96, 163, 188)", "rgb(120, 224, 143)", "rgb(250, 152, 58)", "rgb(235, 47, 6)", "rgb(30, 55, 153)", "rgb(60, 99, 130)", "rgb(56, 173, 169)", "rgb(229, 142, 38)", "rgb(183, 21, 64)", "rgb(12, 36, 97)", "rgb(10, 61, 98)", "rgb(7, 153, 146)"],
46
- FlatUI_German: ["rgb(252, 92, 101)", "rgb(253, 150, 68)", "rgb(254, 211, 48)", "rgb(38, 222, 129)", "rgb(43, 203, 186)", "rgb(235, 59, 90)", "rgb(250, 130, 49)", "rgb(247, 183, 49)", "rgb(32, 191, 107)", "rgb(15, 185, 177)", "rgb(69, 170, 242)", "rgb(75, 123, 236)", "rgb(165, 94, 234)", "rgb(209, 216, 224)", "rgb(119, 140, 163)", "rgb(45, 152, 218)", "rgb(56, 103, 214)", "rgb(136, 84, 208)", "rgb(165, 177, 194)", "rgb(75, 101, 132)"],
47
- FlatUI_Indian: ["rgb(254, 164, 127)", "rgb(37, 204, 247)", "rgb(234, 181, 67)", "rgb(85, 230, 193)", "rgb(202, 211, 200)", "rgb(249, 127, 81)", "rgb(27, 156, 252)", "rgb(248, 239, 186)", "rgb(88, 177, 159)", "rgb(44, 58, 71)", "rgb(179, 55, 113)", "rgb(59, 59, 152)", "rgb(253, 114, 114)", "rgb(154, 236, 219)", "rgb(214, 162, 232)", "rgb(109, 33, 79)", "rgb(24, 44, 97)", "rgb(252, 66, 123)", "rgb(189, 197, 129)", "rgb(130, 88, 159)"],
48
- FlatUI_Russian: ["rgb(243, 166, 131)", "rgb(247, 215, 148)", "rgb(119, 139, 235)", "rgb(231, 127, 103)", "rgb(207, 106, 135)", "rgb(241, 144, 102)", "rgb(245, 205, 121)", "rgb(84, 109, 229)", "rgb(225, 95, 65)", "rgb(196, 69, 105)", "rgb(120, 111, 166)", "rgb(248, 165, 194)", "rgb(99, 205, 218)", "rgb(234, 134, 133)", "rgb(89, 98, 117)", "rgb(87, 75, 144)", "rgb(247, 143, 179)", "rgb(61, 193, 211)", "rgb(230, 103, 103)", "rgb(48, 57, 82)"],
49
- FlatUI_Spanish: ["rgb(64, 64, 122)", "rgb(112, 111, 211)", "rgb(247, 241, 227)", "rgb(52, 172, 224)", "rgb(51, 217, 178)", "rgb(44, 44, 84)", "rgb(71, 71, 135)", "rgb(170, 166, 157)", "rgb(34, 112, 147)", "rgb(33, 140, 116)", "rgb(255, 82, 82)", "rgb(255, 121, 63)", "rgb(209, 204, 192)", "rgb(255, 177, 66)", "rgb(255, 218, 121)", "rgb(179, 57, 57)", "rgb(205, 97, 51)", "rgb(132, 129, 122)", "rgb(204, 142, 53)", "rgb(204, 174, 98)"],
50
- FlatUI_Swedish: ["rgb(239, 87, 119)", "rgb(87, 95, 207)", "rgb(75, 207, 250)", "rgb(52, 231, 228)", "rgb(11, 232, 129)", "rgb(245, 59, 87)", "rgb(60, 64, 198)", "rgb(15, 188, 249)", "rgb(0, 216, 214)", "rgb(5, 196, 107)", "rgb(255, 192, 72)", "rgb(255, 221, 89)", "rgb(255, 94, 87)", "rgb(210, 218, 226)", "rgb(72, 84, 96)", "rgb(255, 168, 1)", "rgb(255, 211, 42)", "rgb(255, 63, 52)", "rgb(128, 142, 155)", "rgb(30, 39, 46)"],
51
- FlatUI_Turkish: ["rgb(205, 132, 241)", "rgb(255, 204, 204)", "rgb(255, 77, 77)", "rgb(255, 175, 64)", "rgb(255, 250, 101)", "rgb(197, 108, 240)", "rgb(255, 184, 184)", "rgb(255, 56, 56)", "rgb(255, 159, 26)", "rgb(255, 242, 0)", "rgb(50, 255, 126)", "rgb(126, 255, 245)", "rgb(24, 220, 255)", "rgb(125, 95, 255)", "rgb(75, 75, 75)", "rgb(58, 227, 116)", "rgb(103, 230, 220)", "rgb(23, 192, 235)", "rgb(113, 88, 226)", "rgb(61, 61, 61)"]
52
- };
53
- const flatuiOrdinal = Object.keys(flatuiSchemes);
54
-
55
- const ordinalCache = {};
56
-
57
- export interface PaletteFunc {
58
- switch(id?: string, colors?: string[]);
59
- type(): "ordinal" | "rainbow";
60
- }
61
-
62
- export interface OrdinalPaletteFunc extends PaletteFunc {
63
- (label: string): string;
64
- }
65
- export function fetchOrdinalItem(): string[];
66
- export function fetchOrdinalItem(id: string, colors?: string[]): OrdinalPaletteFunc;
67
- export function fetchOrdinalItem(id?: string, colors?: string[]): string[] | OrdinalPaletteFunc {
68
- if (!id) return palette_ordinal();
69
- let retVal = ordinalCache[id];
70
- if (!retVal) {
71
- retVal = palette_ordinal(id, colors);
72
- ordinalCache[id] = retVal;
73
- }
74
- return retVal;
75
- }
76
-
77
- function palette_ordinal(id?, colors?): any {
78
- if (!id) return ["default"].concat(d3Ordinal.concat(brewerOrdinal).concat(hpccOrdinal).concat(flatuiOrdinal));
79
- let scale = null;
80
-
81
- if (colors) {
82
- scale = d3ScaleOrdinal().range(colors);
83
- } else {
84
- if (d3Ordinal.indexOf(id) >= 0) {
85
- scale = d3ScaleOrdinal(d3Schemes[id]);
86
- } else if (flatuiOrdinal.indexOf(id) >= 0) {
87
- scale = d3ScaleOrdinal().range(flatuiSchemes[id]);
88
- } else if (hpccOrdinal.indexOf(id) >= 0) {
89
- let newColors = [];
90
- switch (id) {
91
- case "hpcc10":
92
- const defColors = palette_ordinal("default").colors();
93
- newColors = defColors.filter(function (_item, idx) {
94
- if (idx % 2) {
95
- return true;
96
- }
97
- return false;
98
- });
99
- break;
100
- case "hpcc20":
101
- newColors = palette_ordinal("category10").colors().concat(palette_ordinal("hpcc10").colors());
102
- break;
103
- }
104
- scale = d3ScaleOrdinal().range(newColors);
105
- } else if (brewerOrdinal.indexOf(id) >= 0) {
106
- let largestPalette = 12;
107
- while (largestPalette > 0) {
108
- if (m_colorbrewer[id][largestPalette]) {
109
- scale = d3ScaleOrdinal().range(m_colorbrewer[id][largestPalette]);
110
- break;
111
- }
112
- --largestPalette;
113
- }
114
- }
115
- if (!scale) {
116
- // Default to Category20 ---
117
- scale = d3ScaleOrdinal(d3SchemeCategory20);
118
- }
119
- colors = scale.range();
120
- }
121
- const ordinal: any = function (_) {
122
- return scale(_);
123
- };
124
- ordinal.type = function () {
125
- return "ordinal";
126
- };
127
- ordinal.id = function (_) {
128
- if (!arguments.length) return id;
129
- id = _;
130
- return ordinal;
131
- };
132
- ordinal.colors = function (_) {
133
- if (!arguments.length) return colors;
134
- colors = _;
135
- return ordinal;
136
- };
137
- ordinal.clone = function (newID) {
138
- ordinalCache[newID] = palette_ordinal(newID, this.colors());
139
- return ordinalCache[newID];
140
-
141
- };
142
- ordinal.cloneNotExists = function (newID) {
143
- if (ordinalCache[newID]) {
144
- return ordinalCache[newID];
145
- }
146
- return this.clone(newID);
147
- };
148
- ordinal.switch = function (_id, _colors) {
149
- if (id === _id) {
150
- return this;
151
- }
152
- return arguments.length ? fetchOrdinalItem(_id, _colors) : fetchOrdinalItem();
153
- };
154
-
155
- return ordinal;
156
- }
157
-
158
- const rainbowCache = {};
159
- export interface RainbowPaletteFunc extends PaletteFunc {
160
- (value: number, domainLow: number, domainHigh: number): string;
161
- }
162
- export function fetchRainbowItem(): string[];
163
- export function fetchRainbowItem(id: string): RainbowPaletteFunc;
164
- export function fetchRainbowItem(id: string, colors: string[], steps?: number): RainbowPaletteFunc;
165
- export function fetchRainbowItem(id?: string, colors?: string[], steps?: number): string[] | RainbowPaletteFunc {
166
- if (!id) return palette_rainbow();
167
- let retVal = rainbowCache[id];
168
- if (!retVal) {
169
- retVal = palette_rainbow(id, colors, steps);
170
- rainbowCache[id] = retVal;
171
- }
172
- return retVal;
173
- }
174
-
175
- function palette_rainbow(id?, _colors?, _steps?) {
176
- if (!arguments.length) {
177
- const retVal = ["default"];
178
- for (const key in m_colorbrewer) {
179
- if (brewerOrdinal.indexOf(key) === -1) {
180
- retVal.push(key);
181
- }
182
- }
183
- return retVal;
184
- }
185
-
186
- let scale = null;
187
- let colors = _colors;
188
-
189
- const _custom = function (colors, steps?) {
190
- steps = steps || 32;
191
- const subPaletteSize = Math.ceil(steps / (colors.length - 1));
192
- const range = [];
193
- let prevColor = null;
194
- colors.forEach(function (color) {
195
- if (prevColor) {
196
- const scale = d3ScaleLinear()
197
- .domain([0, subPaletteSize])
198
- .range([prevColor, color])
199
- .interpolate(d3InterpolateLab as any)
200
- ;
201
- for (let i = 0; i < subPaletteSize; ++i) {
202
- range.push(scale(i));
203
- }
204
- }
205
- prevColor = color;
206
- });
207
- scale = d3ScaleQuantize().domain([0, 100]).range(range);
208
- return scale;
209
- };
210
-
211
- if (_colors) {
212
- scale = _custom(_colors, _steps);
213
- } else {
214
- if (m_colorbrewer[id]) {
215
- let largestPalette = 12;
216
- while (largestPalette > 0) {
217
- if (m_colorbrewer[id][largestPalette]) {
218
- scale = _custom(m_colorbrewer[id][largestPalette]);
219
- break;
220
- }
221
- --largestPalette;
222
- }
223
- }
224
- if (m_d3[id]) {
225
- scale = d3ScaleSequential(m_d3[id]).domain([0, 100]);
226
- }
227
- if (!scale) {
228
- scale = _custom(m_colorbrewer["RdYlGn"][11]);
229
- }
230
- colors = scale.range ? scale.range() : scale;
231
-
232
- }
233
- const rainbow: any = function (x, low, high) {
234
- if (low === high) {
235
- return scale.domain([low - 1, high + 1])(x);
236
- }
237
- return scale.domain([low, high])(x);
238
- };
239
- rainbow.type = function () {
240
- return "rainbow";
241
- };
242
- rainbow.id = function (_) {
243
- if (!arguments.length) return id;
244
- id = _;
245
- return rainbow;
246
- };
247
- rainbow.colors = function (_) {
248
- if (!arguments.length) return colors;
249
- colors = _;
250
- return rainbow;
251
- };
252
- rainbow.clone = function (newID) {
253
- rainbowCache[newID] = palette_rainbow(newID, this.colors());
254
- return rainbowCache[newID];
255
- };
256
- rainbow.cloneNotExists = function (newID) {
257
- if (rainbowCache[newID]) {
258
- return rainbowCache[newID];
259
- }
260
- return this.clone(newID);
261
- };
262
- rainbow.switch = function (_id, _colors) {
263
- if (id === _id) {
264
- return this;
265
- }
266
- return arguments.length ? fetchRainbowItem(_id, _colors) : fetchRainbowItem();
267
- };
268
-
269
- return rainbow;
270
- }
271
-
272
- export function test(ordinalDivID, brewerDivID, customDivID, customArr, steps) {
273
- d3Select(ordinalDivID)
274
- .selectAll(".palette")
275
- .data(palette_ordinal(), function (d: any) { return d; })
276
- .enter().append("span")
277
- .attr("class", "palette")
278
- .attr("title", function (d: any) { return d; })
279
- .on("click", function (d: any) {
280
- console.info(d3Values(d.value).map(JSON.stringify as any).join("\n"));
281
- })
282
- .selectAll(".swatch").data(function (d) { return palette_ordinal(d).colors(); })
283
- .enter().append("span")
284
- .attr("class", "swatch")
285
- .style("background-color", function (d: any) { return d; });
286
-
287
- d3Select(brewerDivID)
288
- .selectAll(".palette")
289
- .data(palette_rainbow(), function (d: any) { return d; })
290
- .enter().append("span")
291
- .attr("class", "palette")
292
- .attr("title", function (d: any) { return d; })
293
- .on("click", function (d: any) {
294
- console.info(d3Values(d.value).map(JSON.stringify as any).join("\n"));
295
- })
296
- .selectAll(".swatch2").data(function (d) { return palette_rainbow(d).colors(); })
297
- .enter().append("span")
298
- .attr("class", "swatch2")
299
- .style("height", (256 / 32) + "px")
300
- .style("background-color", function (d: any) { return d; });
301
-
302
- const palette = { id: customArr.join("_") + steps, scale: palette_rainbow("custom", customArr, steps) };
303
- d3Select(customDivID)
304
- .selectAll(".palette")
305
- .data([palette], function (d: any) { return d.id; })
306
- .enter().append("span")
307
- .attr("class", "palette")
308
- .attr("title", function () { return "aaa"; /*d.from + "->" + d.to;*/ })
309
- .on("click", function (d) {
310
- console.info(d3Values(d.id).map(JSON.stringify as any).join("\n"));
311
- })
312
- .selectAll(".swatch2").data(function () {
313
- const retVal = [];
314
- for (let i = 0; i <= 255; ++i) {
315
- retVal.push(palette.scale(i, 0, 255));
316
- }
317
- return retVal;
318
- })
319
- .enter().append("span")
320
- .attr("class", "swatch2")
321
- .style("background-color", function (d) { return d; });
322
- }
323
-
324
- m_colorbrewer["RdWhGr"] = {
325
- 3: ["red", "white", "green"]
326
- };
327
-
328
- export const ordinal = fetchOrdinalItem;
329
- export const rainbow = fetchRainbowItem;
330
- export function textColor(backgroundColor: string): string {
331
- let rgb;
332
- switch (backgroundColor) {
333
- case "":
334
- case "transparent":
335
- rgb = d3RGB("white");
336
- break;
337
- default:
338
- rgb = d3RGB(backgroundColor);
339
- }
340
- return ((rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114) > 149) ? "black" : "white";
341
- }
1
+ import * as _colorbrewer from "colorbrewer";
2
+ import { values as d3Values } from "d3-collection";
3
+ import { rgb as d3RGB } from "d3-color";
4
+ import { interpolateLab as d3InterpolateLab } from "d3-interpolate";
5
+ import { interpolateInferno as d3InterpolateInferno, interpolateMagma as d3InterpolateMagma, interpolatePlasma as d3InterpolatePlasma, interpolateViridis as d3InterpolateViridis, scaleLinear as d3ScaleLinear, scaleOrdinal as d3ScaleOrdinal, scaleQuantize as d3ScaleQuantize, scaleSequential as d3ScaleSequential, schemeCategory10 as d3SchemeCategory10, schemeCategory20 as d3SchemeCategory20, schemeCategory20b as d3SchemeCategory20b, schemeCategory20c as d3SchemeCategory20c } from "d3-scale";
6
+ import { select as d3Select } from "d3-selection";
7
+
8
+ const d3Schemes = {
9
+ category10: d3SchemeCategory10,
10
+ category20: d3SchemeCategory20,
11
+ category20b: d3SchemeCategory20b,
12
+ category20c: d3SchemeCategory20c
13
+ };
14
+
15
+ const m_colorbrewer = _colorbrewer.default || _colorbrewer;
16
+
17
+ const m_d3 = {
18
+ Viridis: d3InterpolateViridis,
19
+ Magma: d3InterpolateMagma,
20
+ Inferno: d3InterpolateInferno,
21
+ Plasma: d3InterpolatePlasma
22
+ };
23
+
24
+ const d3Ordinal = [
25
+ "category10", "category20", "category20b", "category20c"
26
+ ];
27
+
28
+ const brewerOrdinal = [
29
+ "Accent", "Dark2", "Paired", "Pastel1", "Pastel2", "Set1", "Set2", "Set3"
30
+ ];
31
+
32
+ const hpccOrdinal = [
33
+ "hpcc10", "hpcc20"
34
+ ];
35
+
36
+ // These color schemes are from www.flatuicolors.com
37
+ const flatuiSchemes = {
38
+ FlatUI_default: ["rgb(26, 188, 156)", "rgb(46, 204, 113)", "rgb(52, 152, 219)", "rgb(155, 89, 182)", "rgb(52, 73, 94)", "rgb(22, 160, 133)", "rgb(39, 174, 96)", "rgb(41, 128, 185)", "rgb(142, 68, 173)", "rgb(44, 62, 80)", "rgb(241, 196, 15)", "rgb(230, 126, 34)", "rgb(231, 76, 60)", "rgb(236, 240, 241)", "rgb(149, 165, 166)", "rgb(243, 156, 18)", "rgb(211, 84, 0)", "rgb(192, 57, 43)", "rgb(189, 195, 199)", "rgb(127, 140, 141)"],
39
+ FlatUI_American: ["rgb(85, 239, 196)", "rgb(129, 236, 236)", "rgb(116, 185, 255)", "rgb(162, 155, 254)", "rgb(223, 230, 233)", "rgb(0, 184, 148)", "rgb(0, 206, 201)", "rgb(9, 132, 227)", "rgb(108, 92, 231)", "rgb(178, 190, 195)", "rgb(255, 234, 167)", "rgb(250, 177, 160)", "rgb(255, 118, 117)", "rgb(253, 121, 168)", "rgb(99, 110, 114)", "rgb(253, 203, 110)", "rgb(225, 112, 85)", "rgb(214, 48, 49)", "rgb(232, 67, 147)", "rgb(45, 52, 54)"],
40
+ FlatUI_Aussie: ["rgb(246, 229, 141)", "rgb(255, 190, 118)", "rgb(255, 121, 121)", "rgb(186, 220, 88)", "rgb(223, 249, 251)", "rgb(249, 202, 36)", "rgb(240, 147, 43)", "rgb(235, 77, 75)", "rgb(106, 176, 76)", "rgb(199, 236, 238)", "rgb(126, 214, 223)", "rgb(224, 86, 253)", "rgb(104, 109, 224)", "rgb(48, 51, 107)", "rgb(149, 175, 192)", "rgb(34, 166, 179)", "rgb(190, 46, 221)", "rgb(72, 52, 212)", "rgb(19, 15, 64)", "rgb(83, 92, 104)"],
41
+ FlatUI_British: ["rgb(0, 168, 255)", "rgb(156, 136, 255)", "rgb(251, 197, 49)", "rgb(76, 209, 55)", "rgb(72, 126, 176)", "rgb(0, 151, 230)", "rgb(140, 122, 230)", "rgb(225, 177, 44)", "rgb(68, 189, 50)", "rgb(64, 115, 158)", "rgb(232, 65, 24)", "rgb(245, 246, 250)", "rgb(127, 143, 166)", "rgb(39, 60, 117)", "rgb(53, 59, 72)", "rgb(194, 54, 22)", "rgb(220, 221, 225)", "rgb(113, 128, 147)", "rgb(25, 42, 86)", "rgb(47, 54, 64)"],
42
+ FlatUI_Canadian: ["rgb(255, 159, 243)", "rgb(254, 202, 87)", "rgb(255, 107, 107)", "rgb(72, 219, 251)", "rgb(29, 209, 161)", "rgb(243, 104, 224)", "rgb(255, 159, 67)", "rgb(238, 82, 83)", "rgb(10, 189, 227)", "rgb(16, 172, 132)", "rgb(0, 210, 211)", "rgb(84, 160, 255)", "rgb(95, 39, 205)", "rgb(200, 214, 229)", "rgb(87, 101, 116)", "rgb(1, 163, 164)", "rgb(46, 134, 222)", "rgb(52, 31, 151)", "rgb(131, 149, 167)", "rgb(34, 47, 62)"],
43
+ FlatUI_Chinese: ["rgb(236, 204, 104)", "rgb(255, 127, 80)", "rgb(255, 107, 129)", "rgb(164, 176, 190)", "rgb(87, 96, 111)", "rgb(255, 165, 2)", "rgb(255, 99, 72)", "rgb(255, 71, 87)", "rgb(116, 125, 140)", "rgb(47, 53, 66)", "rgb(123, 237, 159)", "rgb(112, 161, 255)", "rgb(83, 82, 237)", "rgb(255, 255, 255)", "rgb(223, 228, 234)", "rgb(46, 213, 115)", "rgb(30, 144, 255)", "rgb(55, 66, 250)", "rgb(241, 242, 246)", "rgb(206, 214, 224)"],
44
+ FlatUI_Dutch: ["rgb(255, 195, 18)", "rgb(196, 229, 56)", "rgb(18, 203, 196)", "rgb(253, 167, 223)", "rgb(237, 76, 103)", "rgb(247, 159, 31)", "rgb(163, 203, 56)", "rgb(18, 137, 167)", "rgb(217, 128, 250)", "rgb(181, 52, 113)", "rgb(238, 90, 36)", "rgb(0, 148, 50)", "rgb(6, 82, 221)", "rgb(153, 128, 250)", "rgb(131, 52, 113)", "rgb(234, 32, 39)", "rgb(0, 98, 102)", "rgb(27, 20, 100)", "rgb(87, 88, 187)", "rgb(111, 30, 81)"],
45
+ FlatUI_French: ["rgb(250, 211, 144)", "rgb(248, 194, 145)", "rgb(106, 137, 204)", "rgb(130, 204, 221)", "rgb(184, 233, 148)", "rgb(246, 185, 59)", "rgb(229, 80, 57)", "rgb(74, 105, 189)", "rgb(96, 163, 188)", "rgb(120, 224, 143)", "rgb(250, 152, 58)", "rgb(235, 47, 6)", "rgb(30, 55, 153)", "rgb(60, 99, 130)", "rgb(56, 173, 169)", "rgb(229, 142, 38)", "rgb(183, 21, 64)", "rgb(12, 36, 97)", "rgb(10, 61, 98)", "rgb(7, 153, 146)"],
46
+ FlatUI_German: ["rgb(252, 92, 101)", "rgb(253, 150, 68)", "rgb(254, 211, 48)", "rgb(38, 222, 129)", "rgb(43, 203, 186)", "rgb(235, 59, 90)", "rgb(250, 130, 49)", "rgb(247, 183, 49)", "rgb(32, 191, 107)", "rgb(15, 185, 177)", "rgb(69, 170, 242)", "rgb(75, 123, 236)", "rgb(165, 94, 234)", "rgb(209, 216, 224)", "rgb(119, 140, 163)", "rgb(45, 152, 218)", "rgb(56, 103, 214)", "rgb(136, 84, 208)", "rgb(165, 177, 194)", "rgb(75, 101, 132)"],
47
+ FlatUI_Indian: ["rgb(254, 164, 127)", "rgb(37, 204, 247)", "rgb(234, 181, 67)", "rgb(85, 230, 193)", "rgb(202, 211, 200)", "rgb(249, 127, 81)", "rgb(27, 156, 252)", "rgb(248, 239, 186)", "rgb(88, 177, 159)", "rgb(44, 58, 71)", "rgb(179, 55, 113)", "rgb(59, 59, 152)", "rgb(253, 114, 114)", "rgb(154, 236, 219)", "rgb(214, 162, 232)", "rgb(109, 33, 79)", "rgb(24, 44, 97)", "rgb(252, 66, 123)", "rgb(189, 197, 129)", "rgb(130, 88, 159)"],
48
+ FlatUI_Russian: ["rgb(243, 166, 131)", "rgb(247, 215, 148)", "rgb(119, 139, 235)", "rgb(231, 127, 103)", "rgb(207, 106, 135)", "rgb(241, 144, 102)", "rgb(245, 205, 121)", "rgb(84, 109, 229)", "rgb(225, 95, 65)", "rgb(196, 69, 105)", "rgb(120, 111, 166)", "rgb(248, 165, 194)", "rgb(99, 205, 218)", "rgb(234, 134, 133)", "rgb(89, 98, 117)", "rgb(87, 75, 144)", "rgb(247, 143, 179)", "rgb(61, 193, 211)", "rgb(230, 103, 103)", "rgb(48, 57, 82)"],
49
+ FlatUI_Spanish: ["rgb(64, 64, 122)", "rgb(112, 111, 211)", "rgb(247, 241, 227)", "rgb(52, 172, 224)", "rgb(51, 217, 178)", "rgb(44, 44, 84)", "rgb(71, 71, 135)", "rgb(170, 166, 157)", "rgb(34, 112, 147)", "rgb(33, 140, 116)", "rgb(255, 82, 82)", "rgb(255, 121, 63)", "rgb(209, 204, 192)", "rgb(255, 177, 66)", "rgb(255, 218, 121)", "rgb(179, 57, 57)", "rgb(205, 97, 51)", "rgb(132, 129, 122)", "rgb(204, 142, 53)", "rgb(204, 174, 98)"],
50
+ FlatUI_Swedish: ["rgb(239, 87, 119)", "rgb(87, 95, 207)", "rgb(75, 207, 250)", "rgb(52, 231, 228)", "rgb(11, 232, 129)", "rgb(245, 59, 87)", "rgb(60, 64, 198)", "rgb(15, 188, 249)", "rgb(0, 216, 214)", "rgb(5, 196, 107)", "rgb(255, 192, 72)", "rgb(255, 221, 89)", "rgb(255, 94, 87)", "rgb(210, 218, 226)", "rgb(72, 84, 96)", "rgb(255, 168, 1)", "rgb(255, 211, 42)", "rgb(255, 63, 52)", "rgb(128, 142, 155)", "rgb(30, 39, 46)"],
51
+ FlatUI_Turkish: ["rgb(205, 132, 241)", "rgb(255, 204, 204)", "rgb(255, 77, 77)", "rgb(255, 175, 64)", "rgb(255, 250, 101)", "rgb(197, 108, 240)", "rgb(255, 184, 184)", "rgb(255, 56, 56)", "rgb(255, 159, 26)", "rgb(255, 242, 0)", "rgb(50, 255, 126)", "rgb(126, 255, 245)", "rgb(24, 220, 255)", "rgb(125, 95, 255)", "rgb(75, 75, 75)", "rgb(58, 227, 116)", "rgb(103, 230, 220)", "rgb(23, 192, 235)", "rgb(113, 88, 226)", "rgb(61, 61, 61)"]
52
+ };
53
+ const flatuiOrdinal = Object.keys(flatuiSchemes);
54
+
55
+ const ordinalCache = {};
56
+
57
+ export interface PaletteFunc {
58
+ switch(id?: string, colors?: string[]);
59
+ type(): "ordinal" | "rainbow";
60
+ }
61
+
62
+ export interface OrdinalPaletteFunc extends PaletteFunc {
63
+ (label: string): string;
64
+ }
65
+ export function fetchOrdinalItem(): string[];
66
+ export function fetchOrdinalItem(id: string, colors?: string[]): OrdinalPaletteFunc;
67
+ export function fetchOrdinalItem(id?: string, colors?: string[]): string[] | OrdinalPaletteFunc {
68
+ if (!id) return palette_ordinal();
69
+ let retVal = ordinalCache[id];
70
+ if (!retVal) {
71
+ retVal = palette_ordinal(id, colors);
72
+ ordinalCache[id] = retVal;
73
+ }
74
+ return retVal;
75
+ }
76
+
77
+ function palette_ordinal(id?, colors?): any {
78
+ if (!id) return ["default"].concat(d3Ordinal.concat(brewerOrdinal).concat(hpccOrdinal).concat(flatuiOrdinal));
79
+ let scale = null;
80
+
81
+ if (colors) {
82
+ scale = d3ScaleOrdinal().range(colors);
83
+ } else {
84
+ if (d3Ordinal.indexOf(id) >= 0) {
85
+ scale = d3ScaleOrdinal(d3Schemes[id]);
86
+ } else if (flatuiOrdinal.indexOf(id) >= 0) {
87
+ scale = d3ScaleOrdinal().range(flatuiSchemes[id]);
88
+ } else if (hpccOrdinal.indexOf(id) >= 0) {
89
+ let newColors = [];
90
+ switch (id) {
91
+ case "hpcc10":
92
+ const defColors = palette_ordinal("default").colors();
93
+ newColors = defColors.filter(function (_item, idx) {
94
+ if (idx % 2) {
95
+ return true;
96
+ }
97
+ return false;
98
+ });
99
+ break;
100
+ case "hpcc20":
101
+ newColors = palette_ordinal("category10").colors().concat(palette_ordinal("hpcc10").colors());
102
+ break;
103
+ }
104
+ scale = d3ScaleOrdinal().range(newColors);
105
+ } else if (brewerOrdinal.indexOf(id) >= 0) {
106
+ let largestPalette = 12;
107
+ while (largestPalette > 0) {
108
+ if (m_colorbrewer[id][largestPalette]) {
109
+ scale = d3ScaleOrdinal().range(m_colorbrewer[id][largestPalette]);
110
+ break;
111
+ }
112
+ --largestPalette;
113
+ }
114
+ }
115
+ if (!scale) {
116
+ // Default to Category20 ---
117
+ scale = d3ScaleOrdinal(d3SchemeCategory20);
118
+ }
119
+ colors = scale.range();
120
+ }
121
+ const ordinal: any = function (_) {
122
+ return scale(_);
123
+ };
124
+ ordinal.type = function () {
125
+ return "ordinal";
126
+ };
127
+ ordinal.id = function (_) {
128
+ if (!arguments.length) return id;
129
+ id = _;
130
+ return ordinal;
131
+ };
132
+ ordinal.colors = function (_) {
133
+ if (!arguments.length) return colors;
134
+ colors = _;
135
+ return ordinal;
136
+ };
137
+ ordinal.clone = function (newID) {
138
+ ordinalCache[newID] = palette_ordinal(newID, this.colors());
139
+ return ordinalCache[newID];
140
+
141
+ };
142
+ ordinal.cloneNotExists = function (newID) {
143
+ if (ordinalCache[newID]) {
144
+ return ordinalCache[newID];
145
+ }
146
+ return this.clone(newID);
147
+ };
148
+ ordinal.switch = function (_id, _colors) {
149
+ if (id === _id) {
150
+ return this;
151
+ }
152
+ return arguments.length ? fetchOrdinalItem(_id, _colors) : fetchOrdinalItem();
153
+ };
154
+
155
+ return ordinal;
156
+ }
157
+
158
+ const rainbowCache = {};
159
+ export interface RainbowPaletteFunc extends PaletteFunc {
160
+ (value: number, domainLow: number, domainHigh: number): string;
161
+ }
162
+ export function fetchRainbowItem(): string[];
163
+ export function fetchRainbowItem(id: string): RainbowPaletteFunc;
164
+ export function fetchRainbowItem(id: string, colors: string[], steps?: number): RainbowPaletteFunc;
165
+ export function fetchRainbowItem(id?: string, colors?: string[], steps?: number): string[] | RainbowPaletteFunc {
166
+ if (!id) return palette_rainbow();
167
+ let retVal = rainbowCache[id];
168
+ if (!retVal) {
169
+ retVal = palette_rainbow(id, colors, steps);
170
+ rainbowCache[id] = retVal;
171
+ }
172
+ return retVal;
173
+ }
174
+
175
+ function palette_rainbow(id?, _colors?, _steps?) {
176
+ if (!arguments.length) {
177
+ const retVal = ["default"];
178
+ for (const key in m_colorbrewer) {
179
+ if (brewerOrdinal.indexOf(key) === -1) {
180
+ retVal.push(key);
181
+ }
182
+ }
183
+ return retVal;
184
+ }
185
+
186
+ let scale = null;
187
+ let colors = _colors;
188
+
189
+ const _custom = function (colors, steps?) {
190
+ steps = steps || 32;
191
+ const subPaletteSize = Math.ceil(steps / (colors.length - 1));
192
+ const range = [];
193
+ let prevColor = null;
194
+ colors.forEach(function (color) {
195
+ if (prevColor) {
196
+ const scale = d3ScaleLinear()
197
+ .domain([0, subPaletteSize])
198
+ .range([prevColor, color])
199
+ .interpolate(d3InterpolateLab as any)
200
+ ;
201
+ for (let i = 0; i < subPaletteSize; ++i) {
202
+ range.push(scale(i));
203
+ }
204
+ }
205
+ prevColor = color;
206
+ });
207
+ scale = d3ScaleQuantize().domain([0, 100]).range(range);
208
+ return scale;
209
+ };
210
+
211
+ if (_colors) {
212
+ scale = _custom(_colors, _steps);
213
+ } else {
214
+ if (m_colorbrewer[id]) {
215
+ let largestPalette = 12;
216
+ while (largestPalette > 0) {
217
+ if (m_colorbrewer[id][largestPalette]) {
218
+ scale = _custom(m_colorbrewer[id][largestPalette]);
219
+ break;
220
+ }
221
+ --largestPalette;
222
+ }
223
+ }
224
+ if (m_d3[id]) {
225
+ scale = d3ScaleSequential(m_d3[id]).domain([0, 100]);
226
+ }
227
+ if (!scale) {
228
+ scale = _custom(m_colorbrewer["RdYlGn"][11]);
229
+ }
230
+ colors = scale.range ? scale.range() : scale;
231
+
232
+ }
233
+ const rainbow: any = function (x, low, high) {
234
+ if (low === high) {
235
+ return scale.domain([low - 1, high + 1])(x);
236
+ }
237
+ return scale.domain([low, high])(x);
238
+ };
239
+ rainbow.type = function () {
240
+ return "rainbow";
241
+ };
242
+ rainbow.id = function (_) {
243
+ if (!arguments.length) return id;
244
+ id = _;
245
+ return rainbow;
246
+ };
247
+ rainbow.colors = function (_) {
248
+ if (!arguments.length) return colors;
249
+ colors = _;
250
+ return rainbow;
251
+ };
252
+ rainbow.clone = function (newID) {
253
+ rainbowCache[newID] = palette_rainbow(newID, this.colors());
254
+ return rainbowCache[newID];
255
+ };
256
+ rainbow.cloneNotExists = function (newID) {
257
+ if (rainbowCache[newID]) {
258
+ return rainbowCache[newID];
259
+ }
260
+ return this.clone(newID);
261
+ };
262
+ rainbow.switch = function (_id, _colors) {
263
+ if (id === _id) {
264
+ return this;
265
+ }
266
+ return arguments.length ? fetchRainbowItem(_id, _colors) : fetchRainbowItem();
267
+ };
268
+
269
+ return rainbow;
270
+ }
271
+
272
+ export function test(ordinalDivID, brewerDivID, customDivID, customArr, steps) {
273
+ d3Select(ordinalDivID)
274
+ .selectAll(".palette")
275
+ .data(palette_ordinal(), function (d: any) { return d; })
276
+ .enter().append("span")
277
+ .attr("class", "palette")
278
+ .attr("title", function (d: any) { return d; })
279
+ .on("click", function (d: any) {
280
+ console.info(d3Values(d.value).map(JSON.stringify as any).join("\n"));
281
+ })
282
+ .selectAll(".swatch").data(function (d) { return palette_ordinal(d).colors(); })
283
+ .enter().append("span")
284
+ .attr("class", "swatch")
285
+ .style("background-color", function (d: any) { return d; });
286
+
287
+ d3Select(brewerDivID)
288
+ .selectAll(".palette")
289
+ .data(palette_rainbow(), function (d: any) { return d; })
290
+ .enter().append("span")
291
+ .attr("class", "palette")
292
+ .attr("title", function (d: any) { return d; })
293
+ .on("click", function (d: any) {
294
+ console.info(d3Values(d.value).map(JSON.stringify as any).join("\n"));
295
+ })
296
+ .selectAll(".swatch2").data(function (d) { return palette_rainbow(d).colors(); })
297
+ .enter().append("span")
298
+ .attr("class", "swatch2")
299
+ .style("height", (256 / 32) + "px")
300
+ .style("background-color", function (d: any) { return d; });
301
+
302
+ const palette = { id: customArr.join("_") + steps, scale: palette_rainbow("custom", customArr, steps) };
303
+ d3Select(customDivID)
304
+ .selectAll(".palette")
305
+ .data([palette], function (d: any) { return d.id; })
306
+ .enter().append("span")
307
+ .attr("class", "palette")
308
+ .attr("title", function () { return "aaa"; /*d.from + "->" + d.to;*/ })
309
+ .on("click", function (d) {
310
+ console.info(d3Values(d.id).map(JSON.stringify as any).join("\n"));
311
+ })
312
+ .selectAll(".swatch2").data(function () {
313
+ const retVal = [];
314
+ for (let i = 0; i <= 255; ++i) {
315
+ retVal.push(palette.scale(i, 0, 255));
316
+ }
317
+ return retVal;
318
+ })
319
+ .enter().append("span")
320
+ .attr("class", "swatch2")
321
+ .style("background-color", function (d) { return d; });
322
+ }
323
+
324
+ m_colorbrewer["RdWhGr"] = {
325
+ 3: ["red", "white", "green"]
326
+ };
327
+
328
+ export const ordinal = fetchOrdinalItem;
329
+ export const rainbow = fetchRainbowItem;
330
+ export function textColor(backgroundColor: string): string {
331
+ let rgb;
332
+ switch (backgroundColor) {
333
+ case "":
334
+ case "transparent":
335
+ rgb = d3RGB("white");
336
+ break;
337
+ default:
338
+ rgb = d3RGB(backgroundColor);
339
+ }
340
+ return ((rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114) > 149) ? "black" : "white";
341
+ }