@dra2020/baseclient 1.0.67 → 1.0.70

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