@dra2020/baseclient 1.0.69 → 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.
- package/dist/baseclient.js +102 -54
- package/dist/baseclient.js.map +1 -1
- package/dist/colors/colors.d.ts +13 -4
- package/lib/colors/colors.ts +165 -115
- package/lib/poly/poly.ts +2 -2
- package/package.json +1 -1
package/dist/colors/colors.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
|
|
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 {
|
|
2
6
|
[key: string]: string;
|
|
3
7
|
}
|
|
4
8
|
export declare const ColorValues: ColorLookup;
|
|
9
|
+
export declare const CountEthnicFewClassicColors = 4;
|
|
5
10
|
export declare const EthnicFewClassicColors: string[];
|
|
11
|
+
export declare const CountPartisanPrecinctClassicColors = 12;
|
|
6
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";
|
|
7
18
|
export declare function genColor(i: number, useFirstColor: boolean, palette: string): string;
|
|
19
|
+
export declare function orderedColors(palette: string): string[];
|
|
8
20
|
export declare function getPalette(palette: string): string[];
|
|
9
|
-
export declare const defaultDistrictsPalette = "jet_r";
|
|
10
|
-
export declare function genDRAColor(i: number, useFirstColor: boolean): string;
|
|
11
|
-
export {};
|
package/lib/colors/colors.ts
CHANGED
|
@@ -1,73 +1,72 @@
|
|
|
1
1
|
import * as JsColorMapsData from './jscolormapsdata';
|
|
2
2
|
import {Util} from '../all/all'
|
|
3
3
|
|
|
4
|
-
const MaxOrderedColors: number = 50;
|
|
5
|
-
const MaxColors: number = MaxOrderedColors * 3;
|
|
6
|
-
const MaxClassicColors: number = 55;
|
|
7
|
-
|
|
8
|
-
const DefaultColorNames: string[] =
|
|
9
|
-
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
43
|
-
'
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
'
|
|
56
|
-
'
|
|
57
|
-
'
|
|
58
|
-
'
|
|
59
|
-
'
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
'
|
|
65
|
-
'RosyBrown',
|
|
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',
|
|
66
65
|
];
|
|
67
66
|
|
|
68
|
-
interface ColorLookup
|
|
67
|
+
export interface ColorLookup
|
|
69
68
|
{
|
|
70
|
-
|
|
69
|
+
[key: string]: string;
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
export const ColorValues: ColorLookup =
|
|
@@ -214,6 +213,8 @@ export const ColorValues: ColorLookup =
|
|
|
214
213
|
'YellowGreen': '#9ACD32',
|
|
215
214
|
};
|
|
216
215
|
|
|
216
|
+
// For Demographics scale (4 colors)
|
|
217
|
+
export const CountEthnicFewClassicColors = 4;
|
|
217
218
|
export const EthnicFewClassicColors = [
|
|
218
219
|
'#fafafa', //
|
|
219
220
|
'#aaaaaa', //
|
|
@@ -221,6 +222,8 @@ export const EthnicFewClassicColors = [
|
|
|
221
222
|
'#111111', //
|
|
222
223
|
];
|
|
223
224
|
|
|
225
|
+
// For Partisan Precinct Scale (12 colors)
|
|
226
|
+
export const CountPartisanPrecinctClassicColors = 12;
|
|
224
227
|
export const PartisanPrecinctClassicColors = [
|
|
225
228
|
'#960018', // Carmine
|
|
226
229
|
'#FF2020', //
|
|
@@ -236,57 +239,95 @@ export const PartisanPrecinctClassicColors = [
|
|
|
236
239
|
'#00008B', // Dark blue
|
|
237
240
|
];
|
|
238
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
|
|
239
283
|
let ColorTable: {[key: string]: string[]} = {};
|
|
240
284
|
let OrderedColorTable: {[key: string]: string[]} = {};
|
|
241
285
|
|
|
242
|
-
|
|
243
286
|
export function genColor(i: number, useFirstColor: boolean, palette: string): string
|
|
244
287
|
{
|
|
245
288
|
// 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
289
|
if (i == 0)
|
|
251
290
|
return ColorValues[DefaultColorNames[0]];
|
|
252
291
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
case 'turbo':
|
|
263
|
-
default:
|
|
264
|
-
return orderedColors(palette)[(i - 1) % MaxOrderedColors];
|
|
265
|
-
|
|
266
|
-
case 'draclassic':
|
|
267
|
-
return genDRAColor(i, useFirstColor);
|
|
268
|
-
}
|
|
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);
|
|
269
301
|
}
|
|
270
302
|
|
|
271
|
-
|
|
303
|
+
// DRA classic color palette
|
|
304
|
+
function genDRAColor(i: number, useFirstColor: boolean): string
|
|
272
305
|
{
|
|
273
|
-
|
|
306
|
+
// i is district number, 0 => District[0] (unassigned), so subtract 1 to access ColorTable
|
|
307
|
+
function gen_table(): void
|
|
274
308
|
{
|
|
275
|
-
|
|
276
|
-
let
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
+
}
|
|
280
316
|
}
|
|
281
317
|
|
|
282
|
-
|
|
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];
|
|
283
324
|
}
|
|
284
325
|
|
|
285
326
|
const DistrictsColorOrder: number[] =
|
|
286
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,
|
|
287
328
|
7, 31, 13, 37, 19, 47, 25, 43, 8, 32, 14, 38, 2, 20, 26, 44];
|
|
288
329
|
|
|
289
|
-
function orderedColors(palette: string): string[]
|
|
330
|
+
export function orderedColors(palette: string): string[]
|
|
290
331
|
{
|
|
291
332
|
const colors = getPalette(palette);
|
|
292
333
|
if (!OrderedColorTable[palette])
|
|
@@ -300,29 +341,18 @@ function orderedColors(palette: string): string[]
|
|
|
300
341
|
return OrderedColorTable[palette];
|
|
301
342
|
}
|
|
302
343
|
|
|
303
|
-
export
|
|
304
|
-
|
|
305
|
-
// DRA classic color palette
|
|
306
|
-
export function genDRAColor(i: number, useFirstColor: boolean): string
|
|
344
|
+
export function getPalette(palette: string): string[]
|
|
307
345
|
{
|
|
308
|
-
|
|
309
|
-
function gen_table(): void
|
|
346
|
+
if (palette === 'draclassic')
|
|
310
347
|
{
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
ColorTable['draclassic'].push(ColorValues[DefaultColorNames[j]]);
|
|
317
|
-
}
|
|
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;
|
|
318
353
|
}
|
|
319
354
|
|
|
320
|
-
|
|
321
|
-
gen_table();
|
|
322
|
-
|
|
323
|
-
if (i == 0)
|
|
324
|
-
return ColorValues[DefaultColorNames[0]];
|
|
325
|
-
return ColorTable['draclassic'][((i - 1) + (useFirstColor ? 0 : 1)) % MaxClassicColors];
|
|
355
|
+
return getColorTable(palette);
|
|
326
356
|
}
|
|
327
357
|
|
|
328
358
|
// Generate table for palette
|
|
@@ -333,7 +363,7 @@ function getColorTable(palette: string): string[]
|
|
|
333
363
|
if (!ColorTable[palette])
|
|
334
364
|
{
|
|
335
365
|
ColorTable[palette] = [];
|
|
336
|
-
for (let i = 0; i <
|
|
366
|
+
for (let i = 0; i < CountEthnicFewClassicColors; i++)
|
|
337
367
|
ColorTable[palette].push(EthnicFewClassicColors[i]);
|
|
338
368
|
}
|
|
339
369
|
return ColorTable[palette];
|
|
@@ -343,11 +373,31 @@ function getColorTable(palette: string): string[]
|
|
|
343
373
|
if (!ColorTable[palette])
|
|
344
374
|
{
|
|
345
375
|
ColorTable[palette] = [];
|
|
346
|
-
for (let i = 0; i <
|
|
376
|
+
for (let i = 0; i < CountPartisanPrecinctClassicColors; i++)
|
|
347
377
|
ColorTable[palette].push(PartisanPrecinctClassicColors[i]);
|
|
348
378
|
}
|
|
349
379
|
return ColorTable[palette];
|
|
350
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
|
+
}
|
|
351
401
|
|
|
352
402
|
if (allPaletteNames.includes(palette))
|
|
353
403
|
{
|
package/lib/poly/poly.ts
CHANGED
|
@@ -749,8 +749,8 @@ export function featureRewind(f: any, options?: RewindOptions): any
|
|
|
749
749
|
if (!f) return null;
|
|
750
750
|
|
|
751
751
|
// Has to be an unpacked feature
|
|
752
|
-
if (f.type !== 'Feature')
|
|
753
|
-
if (!f.geometry || f.geometry.packed)
|
|
752
|
+
if (f.type !== 'Feature') return f;
|
|
753
|
+
if (!f.geometry || f.geometry.packed) return f;
|
|
754
754
|
|
|
755
755
|
// Non polygons are simpler
|
|
756
756
|
if (f.geometry.type !== 'Polygon' && f.geometry.type !== 'MultiPolygon') return canonicalPoint(f, options);
|