@dra2020/baseclient 1.0.65 → 1.0.68
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/dist/all/all.d.ts +2 -0
- package/dist/baseclient.js +653 -19
- package/dist/baseclient.js.map +1 -1
- package/dist/colors/colors.d.ts +11 -0
- package/dist/colors/jscolormapsdata.d.ts +7 -0
- package/lib/all/all.ts +2 -0
- package/lib/colors/colors.ts +634 -0
- package/lib/colors/jscolormapsdata.ts +9 -0
- package/lib/poly/poly.ts +2 -0
- package/package.json +11 -11
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ColorLookup {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}
|
|
4
|
+
export declare const ColorValues: ColorLookup;
|
|
5
|
+
export declare const EthnicFewClassicColors: string[];
|
|
6
|
+
export declare const PartisanPrecinctClassicColors: string[];
|
|
7
|
+
export declare function genColor(i: number, useFirstColor: boolean, palette: string): string;
|
|
8
|
+
export declare function getPalette(palette: string): string[];
|
|
9
|
+
export declare const defaultDistrictsPalette = "jet";
|
|
10
|
+
export declare function genDRAColor(i: number, useFirstColor: boolean): string;
|
|
11
|
+
export {};
|
package/lib/all/all.ts
CHANGED
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import * as JsColorMapsData from './jscolormapsdata';
|
|
2
|
+
import {Util} from '../all/all'
|
|
3
|
+
|
|
4
|
+
const MaxOrderedColors: number = 50;
|
|
5
|
+
const MaxColors: number = MaxOrderedColors * 3;
|
|
6
|
+
const MaxClassicColors: number = 55;
|
|
7
|
+
|
|
8
|
+
const DefaultColorNames: string[] =
|
|
9
|
+
[
|
|
10
|
+
'GhostWhite',
|
|
11
|
+
'Blue',
|
|
12
|
+
'Green',
|
|
13
|
+
'DarkMagenta',
|
|
14
|
+
'Red',
|
|
15
|
+
'Gold',
|
|
16
|
+
'Teal',
|
|
17
|
+
'Chocolate', //'DarkGray', //
|
|
18
|
+
'SlateBlue',
|
|
19
|
+
'Cyan',
|
|
20
|
+
'DeepPink',
|
|
21
|
+
'Chartreuse',
|
|
22
|
+
'CornflowerBlue',
|
|
23
|
+
'DarkSalmon',
|
|
24
|
+
'Olive',
|
|
25
|
+
'DarkOrange',
|
|
26
|
+
'Lime',
|
|
27
|
+
'DarkSlateBlue',
|
|
28
|
+
'Yellow',
|
|
29
|
+
'YellowGreen',
|
|
30
|
+
'Pink',
|
|
31
|
+
'Maroon',
|
|
32
|
+
'Sienna',
|
|
33
|
+
'Aquamarine',
|
|
34
|
+
'Indigo',
|
|
35
|
+
'PaleVioletRed',
|
|
36
|
+
'Navy', // 'Gray', //
|
|
37
|
+
'SpringGreen',
|
|
38
|
+
'Plum',
|
|
39
|
+
'DarkSeaGreen',
|
|
40
|
+
'LightCoral',
|
|
41
|
+
'Khaki',
|
|
42
|
+
'OrangeRed',
|
|
43
|
+
'RoyalBlue',
|
|
44
|
+
'LimeGreen',
|
|
45
|
+
'DarkOrchid',
|
|
46
|
+
'Orange',
|
|
47
|
+
'DodgerBlue',
|
|
48
|
+
'MediumAquamarine',
|
|
49
|
+
'Moccasin',
|
|
50
|
+
'Firebrick',
|
|
51
|
+
'LightSteelBlue',
|
|
52
|
+
'LawnGreen',
|
|
53
|
+
'Magenta',
|
|
54
|
+
'MediumVioletRed',
|
|
55
|
+
'Turquoise',
|
|
56
|
+
'Tomato',
|
|
57
|
+
'Thistle',
|
|
58
|
+
'SandyBrown',
|
|
59
|
+
'IndianRed',
|
|
60
|
+
'PowderBlue',
|
|
61
|
+
'SaddleBrown',
|
|
62
|
+
'OliveDrab',
|
|
63
|
+
'Fuchsia', // 'Gainsboro', //
|
|
64
|
+
'PeachPuff',
|
|
65
|
+
'RosyBrown',
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
interface ColorLookup
|
|
69
|
+
{
|
|
70
|
+
[key: string]: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const ColorValues: ColorLookup =
|
|
74
|
+
{
|
|
75
|
+
'AliceBlue': '#F0F8FF',
|
|
76
|
+
'AntiqueWhite': '#FAEBD7',
|
|
77
|
+
'Aqua': '#00FFFF',
|
|
78
|
+
'Aquamarine': '#7FFFD4',
|
|
79
|
+
'Azure': '#F0FFFF',
|
|
80
|
+
'Beige': '#F5F5DC',
|
|
81
|
+
'Bisque': '#FFE4C4',
|
|
82
|
+
'Black': '#000000',
|
|
83
|
+
'BlanchedAlmond': '#FFEBCD',
|
|
84
|
+
'Blue': '#0000FF',
|
|
85
|
+
'BlueViolet': '#8A2BE2',
|
|
86
|
+
'Brown': '#A52A2A',
|
|
87
|
+
'BurlyWood': '#DEB887',
|
|
88
|
+
'CadetBlue': '#5F9EA0',
|
|
89
|
+
'Chartreuse': '#7FFF00',
|
|
90
|
+
'Chocolate': '#D2691E',
|
|
91
|
+
'Coral': '#FF7F50',
|
|
92
|
+
'CornflowerBlue': '#6495ED',
|
|
93
|
+
'Cornsilk': '#FFF8DC',
|
|
94
|
+
'Crimson': '#DC143C',
|
|
95
|
+
'Cyan': '#00FFFF',
|
|
96
|
+
'DarkBlue': '#00008B',
|
|
97
|
+
'DarkCyan': '#008B8B',
|
|
98
|
+
'DarkGoldenrod': '#B8860B',
|
|
99
|
+
'DarkGray': '#A9A9A9',
|
|
100
|
+
'DarkGreen': '#006400',
|
|
101
|
+
'DarkKhaki': '#BDB76B',
|
|
102
|
+
'DarkMagenta': '#8B008B',
|
|
103
|
+
'DarkOliveGreen': '#556B2F',
|
|
104
|
+
'DarkOrange': '#FF8C00',
|
|
105
|
+
'DarkOrchid': '#9932CC',
|
|
106
|
+
'DarkRed': '#8B0000',
|
|
107
|
+
'DarkSalmon': '#E9967A',
|
|
108
|
+
'DarkSeaGreen': '#8FBC8F',
|
|
109
|
+
'DarkSlateBlue': '#483D8B',
|
|
110
|
+
'DarkSlateGray': '#2F4F4F',
|
|
111
|
+
'DarkTurquoise': '#00CED1',
|
|
112
|
+
'DarkViolet': '#9400D3',
|
|
113
|
+
'DeepPink': '#FF1493',
|
|
114
|
+
'DeepSkyBlue': '#00BFFF',
|
|
115
|
+
'DimGray': '#696969',
|
|
116
|
+
'DodgerBlue': '#1E90FF',
|
|
117
|
+
'Firebrick': '#B22222',
|
|
118
|
+
'FloralWhite': '#FFFAF0',
|
|
119
|
+
'ForestGreen': '#228B22',
|
|
120
|
+
'Fuchsia': '#FF00FF',
|
|
121
|
+
'Gainsboro': '#DCDCDC',
|
|
122
|
+
'GhostWhite': '#F8F8FF',
|
|
123
|
+
'Gold': '#FFD700',
|
|
124
|
+
'Goldenrod': '#DAA520',
|
|
125
|
+
'Gray': '#808080',
|
|
126
|
+
'Green': '#008000',
|
|
127
|
+
'GreenYellow': '#ADFF2F',
|
|
128
|
+
'Honeydew': '#F0FFF0',
|
|
129
|
+
'HotPink': '#FF69B4',
|
|
130
|
+
'IndianRed': '#CD5C5C',
|
|
131
|
+
'Indigo': '#4B0082',
|
|
132
|
+
'Ivory': '#FFFFF0',
|
|
133
|
+
'Khaki': '#F0E68C',
|
|
134
|
+
'Lavender': '#E6E6FA',
|
|
135
|
+
'LavenderBlush': '#FFF0F5',
|
|
136
|
+
'LawnGreen': '#7CFC00',
|
|
137
|
+
'LemonChiffon': '#FFFACD',
|
|
138
|
+
'LightBlue': '#ADD8E6',
|
|
139
|
+
'LightCoral': '#F08080',
|
|
140
|
+
'LightCyan': '#E0FFFF',
|
|
141
|
+
'LightGoldenrodYellow': '#FAFAD2',
|
|
142
|
+
'LightGray': '#D3D3D3',
|
|
143
|
+
'LightGreen': '#90EE90',
|
|
144
|
+
'LightPink': '#FFB6C1',
|
|
145
|
+
'LightSalmon': '#FFA07A',
|
|
146
|
+
'LightSeaGreen': '#20B2AA',
|
|
147
|
+
'LightSkyBlue': '#87CEFA',
|
|
148
|
+
'LightSlateGray': '#778899',
|
|
149
|
+
'LightSteelBlue': '#B0C4DE',
|
|
150
|
+
'LightYellow': '#FFFFE0',
|
|
151
|
+
'Lime': '#00FF00',
|
|
152
|
+
'LimeGreen': '#32CD32',
|
|
153
|
+
'Linen': '#FAF0E6',
|
|
154
|
+
'Magenta': '#FF00FF',
|
|
155
|
+
'Maroon': '#800000',
|
|
156
|
+
'MediumAquamarine': '#66CDAA',
|
|
157
|
+
'MediumBlue': '#0000CD',
|
|
158
|
+
'MediumOrchid': '#BA55D3',
|
|
159
|
+
'MediumPurple': '#9370DB',
|
|
160
|
+
'MediumSeaGreen': '#3CB371',
|
|
161
|
+
'MediumSlateBlue': '#7B68EE',
|
|
162
|
+
'MediumSpringGreen': '#00FA9A',
|
|
163
|
+
'MediumTurquoise': '#48D1CC',
|
|
164
|
+
'MediumVioletRed': '#C71585',
|
|
165
|
+
'MidnightBlue': '#191970',
|
|
166
|
+
'MintCream': '#F5FFFA',
|
|
167
|
+
'MistyRose': '#FFE4E1',
|
|
168
|
+
'Moccasin': '#FFE4B5',
|
|
169
|
+
'NavajoWhite': '#FFDEAD',
|
|
170
|
+
'Navy': '#000080',
|
|
171
|
+
'OldLace': '#FDF5E6',
|
|
172
|
+
'Olive': '#808000',
|
|
173
|
+
'OliveDrab': '#6B8E23',
|
|
174
|
+
'Orange': '#FFA500',
|
|
175
|
+
'OrangeRed': '#FF4500',
|
|
176
|
+
'Orchid': '#DA70D6',
|
|
177
|
+
'PaleGoldenrod': '#EEE8AA',
|
|
178
|
+
'PaleGreen': '#98FB98',
|
|
179
|
+
'PaleTurquoise': '#AFEEEE',
|
|
180
|
+
'PaleVioletRed': '#DB7093',
|
|
181
|
+
'PapayaWhip': '#FFEFD5',
|
|
182
|
+
'PeachPuff': '#FFDAB9',
|
|
183
|
+
'Peru': '#CD853F',
|
|
184
|
+
'Pink': '#FFC0CB',
|
|
185
|
+
'Plum': '#DDA0DD',
|
|
186
|
+
'PowderBlue': '#B0E0E6',
|
|
187
|
+
'Purple': '#800080',
|
|
188
|
+
'Red': '#FF0000',
|
|
189
|
+
'RosyBrown': '#BC8F8F',
|
|
190
|
+
'RoyalBlue': '#4169E1',
|
|
191
|
+
'SaddleBrown': '#8B4513',
|
|
192
|
+
'Salmon': '#FA8072',
|
|
193
|
+
'SandyBrown': '#F4A460',
|
|
194
|
+
'SeaGreen': '#2E8B57',
|
|
195
|
+
'SeaShell': '#FFF5EE',
|
|
196
|
+
'Sienna': '#A0522D',
|
|
197
|
+
'Silver': '#C0C0C0',
|
|
198
|
+
'SkyBlue': '#87CEEB',
|
|
199
|
+
'SlateBlue': '#6A5ACD',
|
|
200
|
+
'SlateGray': '#708090',
|
|
201
|
+
'Snow': '#FFFAFA',
|
|
202
|
+
'SpringGreen': '#00FF7F',
|
|
203
|
+
'SteelBlue': '#4682B4',
|
|
204
|
+
'Tan': '#D2B48C',
|
|
205
|
+
'Teal': '#008080',
|
|
206
|
+
'Thistle': '#D8BFD8',
|
|
207
|
+
'Tomato': '#FF6347',
|
|
208
|
+
'Turquoise': '#40E0D0',
|
|
209
|
+
'Violet': '#EE82EE',
|
|
210
|
+
'Wheat': '#F5DEB3',
|
|
211
|
+
'White': '#FFFFFF',
|
|
212
|
+
'WhiteSmoke': '#F5F5F5',
|
|
213
|
+
'Yellow': '#FFFF00',
|
|
214
|
+
'YellowGreen': '#9ACD32',
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export const EthnicFewClassicColors = [
|
|
218
|
+
'#fafafa', //
|
|
219
|
+
'#aaaaaa', //
|
|
220
|
+
'#666666', //
|
|
221
|
+
'#111111', //
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
export const PartisanPrecinctClassicColors = [
|
|
225
|
+
'#960018', // Carmine
|
|
226
|
+
'#FF2020', //
|
|
227
|
+
'#FF6060', //
|
|
228
|
+
'#FFA0A0', //
|
|
229
|
+
'#FFC0C0', //
|
|
230
|
+
'#FFDEDE', // pale red
|
|
231
|
+
'#DEDEFF', // pale blue
|
|
232
|
+
'#C0C0FF', //
|
|
233
|
+
'#A0A0FF', //
|
|
234
|
+
'#6060FF', //
|
|
235
|
+
'#2020FF', //
|
|
236
|
+
'#00008B', // Dark blue
|
|
237
|
+
];
|
|
238
|
+
|
|
239
|
+
let ColorTable: {[key: string]: string[]} = {};
|
|
240
|
+
let OrderedColorTable: {[key: string]: string[]} = {};
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
export function genColor(i: number, useFirstColor: boolean, palette: string): string
|
|
244
|
+
{
|
|
245
|
+
// i is district number, 0 => District[0] (unassigned), so subtract 1 to access ColorTable
|
|
246
|
+
|
|
247
|
+
if (!useFirstColor || !palette)
|
|
248
|
+
return genDRAColor(i, useFirstColor);
|
|
249
|
+
|
|
250
|
+
if (i == 0)
|
|
251
|
+
return ColorValues[DefaultColorNames[0]];
|
|
252
|
+
|
|
253
|
+
switch (palette)
|
|
254
|
+
{
|
|
255
|
+
case 'jet':
|
|
256
|
+
case 'viridis':
|
|
257
|
+
case 'magma':
|
|
258
|
+
case 'plasma':
|
|
259
|
+
case 'bone':
|
|
260
|
+
case 'greys':
|
|
261
|
+
case 'inferno':
|
|
262
|
+
case 'turbo':
|
|
263
|
+
default:
|
|
264
|
+
return orderedColors(palette)[(i - 1) % MaxOrderedColors];
|
|
265
|
+
|
|
266
|
+
case 'draclassic':
|
|
267
|
+
return genDRAColor(i, useFirstColor);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function getPalette(palette: string): string[]
|
|
272
|
+
{
|
|
273
|
+
let colors: string[] = [];
|
|
274
|
+
switch (palette)
|
|
275
|
+
{
|
|
276
|
+
case 'jet':
|
|
277
|
+
case 'viridis':
|
|
278
|
+
case 'magma':
|
|
279
|
+
case 'plasma':
|
|
280
|
+
case 'bone':
|
|
281
|
+
case 'inferno':
|
|
282
|
+
case 'turbo':
|
|
283
|
+
case 'demographicsclassic':
|
|
284
|
+
case 'partisanclassic':
|
|
285
|
+
case 'allgroupsclassic':
|
|
286
|
+
return getColorTable(palette, true);
|
|
287
|
+
case 'greys':
|
|
288
|
+
return getColorTable(palette, false);
|
|
289
|
+
|
|
290
|
+
default:
|
|
291
|
+
// return draclassic palette with only 30 colors
|
|
292
|
+
for (let i = 1; i < 30; i++)
|
|
293
|
+
colors.push(genDRAColor(i, true));
|
|
294
|
+
return colors;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const DistrictsColorOrder: number[] =
|
|
299
|
+
[0, 49, 24, 36, 12, 42, 6, 30, 18, 45, 3, 27, 9, 33, 15, 46, 21, 39, 4, 28, 10, 34, 16, 48, 22, 40, 5, 29, 11, 35, 17, 1, 23, 41,
|
|
300
|
+
7, 31, 13, 37, 19, 47, 25, 43, 8, 32, 14, 38, 2, 20, 26, 44];
|
|
301
|
+
|
|
302
|
+
function orderedColors(palette: string): string[]
|
|
303
|
+
{
|
|
304
|
+
const colors = getPalette(palette);
|
|
305
|
+
if (!OrderedColorTable[palette])
|
|
306
|
+
{
|
|
307
|
+
OrderedColorTable[palette] = [];
|
|
308
|
+
for (let i: number = 0; i < MaxColors; i++)
|
|
309
|
+
{
|
|
310
|
+
OrderedColorTable[palette].push(colors[DistrictsColorOrder[i] * 3]);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return OrderedColorTable[palette];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export const defaultDistrictsPalette = 'jet';
|
|
317
|
+
|
|
318
|
+
// DRA classic color palette
|
|
319
|
+
export function genDRAColor(i: number, useFirstColor: boolean): string
|
|
320
|
+
{
|
|
321
|
+
// i is district number, 0 => District[0] (unassigned), so subtract 1 to access ColorTable
|
|
322
|
+
function gen_table(): void
|
|
323
|
+
{
|
|
324
|
+
ColorTable['draclassic'] = [];
|
|
325
|
+
for (let i: number = 0; i < MaxClassicColors; i++)
|
|
326
|
+
{
|
|
327
|
+
// A little funky math below to skip the first (white) color
|
|
328
|
+
let j = (i % (DefaultColorNames.length - 1)) + 1;
|
|
329
|
+
ColorTable['draclassic'].push(ColorValues[DefaultColorNames[j]]);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (ColorTable == null)
|
|
334
|
+
gen_table();
|
|
335
|
+
|
|
336
|
+
if (i == 0)
|
|
337
|
+
return ColorValues[DefaultColorNames[0]];
|
|
338
|
+
return ColorTable['draclassic'][((i - 1) + (useFirstColor ? 0 : 1)) % MaxClassicColors];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Generate table for palette
|
|
342
|
+
function getColorTable(palette: string, reverse: boolean): string[]
|
|
343
|
+
{
|
|
344
|
+
if (palette === 'demographicsclassic')
|
|
345
|
+
{
|
|
346
|
+
if (!ColorTable[palette])
|
|
347
|
+
{
|
|
348
|
+
ColorTable[palette] = [];
|
|
349
|
+
for (let i = 0; i < 4; i++)
|
|
350
|
+
ColorTable[palette].push(EthnicFewClassicColors[i]);
|
|
351
|
+
}
|
|
352
|
+
return ColorTable[palette];
|
|
353
|
+
}
|
|
354
|
+
else if (palette === 'partisanclassic')
|
|
355
|
+
{
|
|
356
|
+
if (!ColorTable[palette])
|
|
357
|
+
{
|
|
358
|
+
ColorTable[palette] = [];
|
|
359
|
+
for (let i = 0; i < 12; i++)
|
|
360
|
+
ColorTable[palette].push(PartisanPrecinctClassicColors[i]);
|
|
361
|
+
}
|
|
362
|
+
return ColorTable[palette];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (reverse && !palette.endsWith('_r'))
|
|
366
|
+
palette = palette + '_r';
|
|
367
|
+
|
|
368
|
+
if (allPaletteNames.includes(palette))
|
|
369
|
+
{
|
|
370
|
+
if (!ColorTable[palette])
|
|
371
|
+
ColorTable[palette] = jscolormap(palette, MaxColors);
|
|
372
|
+
return ColorTable[palette];
|
|
373
|
+
}
|
|
374
|
+
else
|
|
375
|
+
return ['#ffffff'];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Helpers
|
|
379
|
+
function toHexColor(r: number, g: number, b: number): string
|
|
380
|
+
{
|
|
381
|
+
return `#${Util.toHex(r)}${Util.toHex(g)}${Util.toHex(b)}`;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function jscolormap(name: string, shades: number): string[]
|
|
385
|
+
{
|
|
386
|
+
let result: string[] = [];
|
|
387
|
+
for (let i = 0; i < shades; i++)
|
|
388
|
+
{
|
|
389
|
+
const rgb: number[] = partial(name)((i + 0.5) / shades); //evaluate_cmap((i + 0.5) / shades, name, reverse);
|
|
390
|
+
result.push(toHexColor(rgb[0], rgb[1], rgb[2]));
|
|
391
|
+
}
|
|
392
|
+
return result;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// ****************************************************************
|
|
396
|
+
// js-colormaps was made by Timothy Gebhard (https://github.com/timothygebhard/js-colormaps),
|
|
397
|
+
// used here under MIT License, and modified for TypeScript
|
|
398
|
+
|
|
399
|
+
const allPaletteNames: string[] = [
|
|
400
|
+
'Accent',
|
|
401
|
+
'Accent_r',
|
|
402
|
+
'Blues',
|
|
403
|
+
'Blues_r',
|
|
404
|
+
'BrBG',
|
|
405
|
+
'BrBG_r',
|
|
406
|
+
'BuGn',
|
|
407
|
+
'BuGn_r',
|
|
408
|
+
'BuPu',
|
|
409
|
+
'BuPu_r',
|
|
410
|
+
'CMRmap',
|
|
411
|
+
'CMRmap_r',
|
|
412
|
+
'Dark2',
|
|
413
|
+
'Dark2_r',
|
|
414
|
+
'GnBu',
|
|
415
|
+
'GnBu_r',
|
|
416
|
+
'Greens',
|
|
417
|
+
'Greens_r',
|
|
418
|
+
'Greys',
|
|
419
|
+
'Greys_r',
|
|
420
|
+
'OrRd',
|
|
421
|
+
'OrRd_r',
|
|
422
|
+
'Oranges',
|
|
423
|
+
'Oranges_r',
|
|
424
|
+
'PRGn',
|
|
425
|
+
'PRGn_r',
|
|
426
|
+
'Paired',
|
|
427
|
+
'Paired_r',
|
|
428
|
+
'Pastel1',
|
|
429
|
+
'Pastel1_r',
|
|
430
|
+
'Pastel2',
|
|
431
|
+
'Pastel2_r',
|
|
432
|
+
'PiYG',
|
|
433
|
+
'PiYG_r',
|
|
434
|
+
'PuBu',
|
|
435
|
+
'PuBu_r',
|
|
436
|
+
'PuBuGn',
|
|
437
|
+
'PuBuGn_r',
|
|
438
|
+
'PuOr',
|
|
439
|
+
'PuOr_r',
|
|
440
|
+
'PuRd',
|
|
441
|
+
'PuRd_r',
|
|
442
|
+
'Purples',
|
|
443
|
+
'Purples_r',
|
|
444
|
+
'RdBu',
|
|
445
|
+
'RdBu_r',
|
|
446
|
+
'RdGy',
|
|
447
|
+
'RdGy_r',
|
|
448
|
+
'RdPu',
|
|
449
|
+
'RdPu_r',
|
|
450
|
+
'RdYlBu',
|
|
451
|
+
'RdYlBu_r',
|
|
452
|
+
'RdYlGn',
|
|
453
|
+
'RdYlGn_r',
|
|
454
|
+
'Reds',
|
|
455
|
+
'Reds_r',
|
|
456
|
+
'Set1',
|
|
457
|
+
'Set1_r',
|
|
458
|
+
'Set2',
|
|
459
|
+
'Set2_r',
|
|
460
|
+
'Set3',
|
|
461
|
+
'Set3_r',
|
|
462
|
+
'Spectral',
|
|
463
|
+
'Spectral_r',
|
|
464
|
+
'Wistia',
|
|
465
|
+
'Wistia_r',
|
|
466
|
+
'YlGn',
|
|
467
|
+
'YlGn_r',
|
|
468
|
+
'YlGnBu',
|
|
469
|
+
'YlGnBu_r',
|
|
470
|
+
'YlOrBr',
|
|
471
|
+
'YlOrBr_r',
|
|
472
|
+
'YlOrRd',
|
|
473
|
+
'YlOrRd_r',
|
|
474
|
+
'afmhot',
|
|
475
|
+
'afmhot_r',
|
|
476
|
+
'autumn',
|
|
477
|
+
'autumn_r',
|
|
478
|
+
'binary',
|
|
479
|
+
'binary_r',
|
|
480
|
+
'bone',
|
|
481
|
+
'bone_r',
|
|
482
|
+
'brg',
|
|
483
|
+
'brg_r',
|
|
484
|
+
'bwr',
|
|
485
|
+
'bwr_r',
|
|
486
|
+
'cividis',
|
|
487
|
+
'cividis_r',
|
|
488
|
+
'cool',
|
|
489
|
+
'cool_r',
|
|
490
|
+
'coolwarm',
|
|
491
|
+
'coolwarm_r',
|
|
492
|
+
'copper',
|
|
493
|
+
'copper_r',
|
|
494
|
+
'cubehelix',
|
|
495
|
+
'cubehelix_r',
|
|
496
|
+
'flag',
|
|
497
|
+
'flag_r',
|
|
498
|
+
'gist_earth',
|
|
499
|
+
'gist_earth_r',
|
|
500
|
+
'gist_gray',
|
|
501
|
+
'gist_gray_r',
|
|
502
|
+
'gist_heat',
|
|
503
|
+
'gist_heat_r',
|
|
504
|
+
'gist_ncar',
|
|
505
|
+
'gist_ncar_r',
|
|
506
|
+
'gist_rainbow',
|
|
507
|
+
'gist_rainbow_r',
|
|
508
|
+
'gist_stern',
|
|
509
|
+
'gist_stern_r',
|
|
510
|
+
'gist_yarg',
|
|
511
|
+
'gist_yarg_r',
|
|
512
|
+
'gnuplot',
|
|
513
|
+
'gnuplot_r',
|
|
514
|
+
'gnuplot2',
|
|
515
|
+
'gnuplot2_r',
|
|
516
|
+
'gray',
|
|
517
|
+
'gray_r',
|
|
518
|
+
'hot',
|
|
519
|
+
'hot_r',
|
|
520
|
+
'hsv',
|
|
521
|
+
'hsv_r',
|
|
522
|
+
'inferno',
|
|
523
|
+
'inferno_r',
|
|
524
|
+
'jet',
|
|
525
|
+
'jet_r',
|
|
526
|
+
'magma',
|
|
527
|
+
'magma_r',
|
|
528
|
+
'nipy_spectral',
|
|
529
|
+
'nipy_spectral_r',
|
|
530
|
+
'ocean',
|
|
531
|
+
'ocean_r',
|
|
532
|
+
'pink',
|
|
533
|
+
'pink_r',
|
|
534
|
+
'plasma',
|
|
535
|
+
'plasma_r',
|
|
536
|
+
'prism',
|
|
537
|
+
'prism_r',
|
|
538
|
+
'rainbow',
|
|
539
|
+
'rainbow_r',
|
|
540
|
+
'seismic',
|
|
541
|
+
'seismic_r',
|
|
542
|
+
'spring',
|
|
543
|
+
'spring_r',
|
|
544
|
+
'summer',
|
|
545
|
+
'summer_r',
|
|
546
|
+
'tab10',
|
|
547
|
+
'tab10_r',
|
|
548
|
+
'tab20',
|
|
549
|
+
'tab20_r',
|
|
550
|
+
'tab20b',
|
|
551
|
+
'tab20b_r',
|
|
552
|
+
'tab20c',
|
|
553
|
+
'tab20c_r',
|
|
554
|
+
'terrain',
|
|
555
|
+
'terrain_r',
|
|
556
|
+
'turbo',
|
|
557
|
+
'turbo_r',
|
|
558
|
+
'twilight',
|
|
559
|
+
'twilight_r',
|
|
560
|
+
'twilight_shifted',
|
|
561
|
+
'twilight_shifted_r',
|
|
562
|
+
'viridis',
|
|
563
|
+
'viridis_r',
|
|
564
|
+
'winter',
|
|
565
|
+
'winter_r'];
|
|
566
|
+
|
|
567
|
+
/*
|
|
568
|
+
Define auxiliary functions for evaluating colormaps
|
|
569
|
+
*/
|
|
570
|
+
|
|
571
|
+
function evaluate_cmap(x: number, name: string, reverse: boolean) {
|
|
572
|
+
/**
|
|
573
|
+
* Evaluate colormap `name` at some value `x`.
|
|
574
|
+
* @param {number} x - The value (between 0 and 1) at which to evaluate the colormap.
|
|
575
|
+
* @param {string} name - The name of the colormap (see matplotlib documentation).
|
|
576
|
+
* @reverse {boolean} reverse - Whether or not to reverse the colormap.
|
|
577
|
+
* @return {list} - A 3-tuple (R, G, B) containing the color assigned to `x`.
|
|
578
|
+
*/
|
|
579
|
+
|
|
580
|
+
// Ensure that the value of `x` is valid (i.e., 0 <= x <= 1)
|
|
581
|
+
if (!(0 <= x && x <= 1)) {
|
|
582
|
+
alert('Illegal value for x! Must be in [0, 1].')
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Ensure that `name` is a valid colormap
|
|
586
|
+
if (!(name in JsColorMapsData.data)) {
|
|
587
|
+
alert('Colormap ' + name + 'does not exist!');
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// We can get the reverse colormap by evaluating colormap(1-x)
|
|
591
|
+
if (reverse === true) {
|
|
592
|
+
x = 1 - x;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// Get the colors and whether or not we need to interpolate
|
|
596
|
+
let colors = JsColorMapsData.data[name]['colors'];
|
|
597
|
+
let interpolate = JsColorMapsData.data[name]['interpolate'];
|
|
598
|
+
|
|
599
|
+
if (interpolate === true) {
|
|
600
|
+
return interpolated(x, colors);
|
|
601
|
+
} else {
|
|
602
|
+
return qualitative(x, colors);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function interpolated(x: number, colors: any[]) {
|
|
607
|
+
let lo = Math.floor(x * (colors.length - 1));
|
|
608
|
+
let hi = Math.ceil(x * (colors.length - 1));
|
|
609
|
+
let r = Math.round((colors[lo][0] + colors[hi][0]) / 2 * 255);
|
|
610
|
+
let g = Math.round((colors[lo][1] + colors[hi][1]) / 2 * 255);
|
|
611
|
+
let b = Math.round((colors[lo][2] + colors[hi][2]) / 2 * 255);
|
|
612
|
+
return [r, g, b];
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function qualitative(x: number, colors: any[]) {
|
|
616
|
+
let idx = 0;
|
|
617
|
+
while (x > (idx + 1) / (colors.length - 0) ) { idx++; }
|
|
618
|
+
let r = Math.round(colors[idx][0] * 255);
|
|
619
|
+
let g = Math.round(colors[idx][1] * 255);
|
|
620
|
+
let b = Math.round(colors[idx][2] * 255);
|
|
621
|
+
return [r, g, b];
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function partial(name: string) {
|
|
625
|
+
if (name.endsWith('_r')) {
|
|
626
|
+
return function(x: number) { return evaluate_cmap(x, name.substring(0, name.length - 2), true) };
|
|
627
|
+
} else {
|
|
628
|
+
return function(x: number) { return evaluate_cmap(x, name, false) };
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// End of js-colormaps
|
|
634
|
+
// *********************************************************
|