@dra2020/baseclient 1.0.68 → 1.0.71
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 +106 -71
- package/dist/baseclient.js.map +1 -1
- package/dist/colors/colors.d.ts +13 -4
- package/lib/colors/colors.ts +168 -134
- package/lib/geo/geo.ts +4 -1
- 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";
|
|
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,70 +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
|
-
|
|
274
|
-
|
|
306
|
+
// i is district number, 0 => District[0] (unassigned), so subtract 1 to access ColorTable
|
|
307
|
+
function gen_table(): void
|
|
275
308
|
{
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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;
|
|
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
|
+
}
|
|
295
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];
|
|
296
324
|
}
|
|
297
325
|
|
|
298
326
|
const DistrictsColorOrder: number[] =
|
|
299
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,
|
|
300
328
|
7, 31, 13, 37, 19, 47, 25, 43, 8, 32, 14, 38, 2, 20, 26, 44];
|
|
301
329
|
|
|
302
|
-
function orderedColors(palette: string): string[]
|
|
330
|
+
export function orderedColors(palette: string): string[]
|
|
303
331
|
{
|
|
304
332
|
const colors = getPalette(palette);
|
|
305
333
|
if (!OrderedColorTable[palette])
|
|
@@ -313,40 +341,29 @@ function orderedColors(palette: string): string[]
|
|
|
313
341
|
return OrderedColorTable[palette];
|
|
314
342
|
}
|
|
315
343
|
|
|
316
|
-
export
|
|
317
|
-
|
|
318
|
-
// DRA classic color palette
|
|
319
|
-
export function genDRAColor(i: number, useFirstColor: boolean): string
|
|
344
|
+
export function getPalette(palette: string): string[]
|
|
320
345
|
{
|
|
321
|
-
|
|
322
|
-
function gen_table(): void
|
|
346
|
+
if (palette === 'draclassic')
|
|
323
347
|
{
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
ColorTable['draclassic'].push(ColorValues[DefaultColorNames[j]]);
|
|
330
|
-
}
|
|
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;
|
|
331
353
|
}
|
|
332
354
|
|
|
333
|
-
|
|
334
|
-
gen_table();
|
|
335
|
-
|
|
336
|
-
if (i == 0)
|
|
337
|
-
return ColorValues[DefaultColorNames[0]];
|
|
338
|
-
return ColorTable['draclassic'][((i - 1) + (useFirstColor ? 0 : 1)) % MaxClassicColors];
|
|
355
|
+
return getColorTable(palette);
|
|
339
356
|
}
|
|
340
357
|
|
|
341
358
|
// Generate table for palette
|
|
342
|
-
function getColorTable(palette: string
|
|
359
|
+
function getColorTable(palette: string): string[]
|
|
343
360
|
{
|
|
344
361
|
if (palette === 'demographicsclassic')
|
|
345
362
|
{
|
|
346
363
|
if (!ColorTable[palette])
|
|
347
364
|
{
|
|
348
365
|
ColorTable[palette] = [];
|
|
349
|
-
for (let i = 0; i <
|
|
366
|
+
for (let i = 0; i < CountEthnicFewClassicColors; i++)
|
|
350
367
|
ColorTable[palette].push(EthnicFewClassicColors[i]);
|
|
351
368
|
}
|
|
352
369
|
return ColorTable[palette];
|
|
@@ -356,15 +373,32 @@ function getColorTable(palette: string, reverse: boolean): string[]
|
|
|
356
373
|
if (!ColorTable[palette])
|
|
357
374
|
{
|
|
358
375
|
ColorTable[palette] = [];
|
|
359
|
-
for (let i = 0; i <
|
|
376
|
+
for (let i = 0; i < CountPartisanPrecinctClassicColors; i++)
|
|
360
377
|
ColorTable[palette].push(PartisanPrecinctClassicColors[i]);
|
|
361
378
|
}
|
|
362
379
|
return ColorTable[palette];
|
|
363
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
|
+
}
|
|
364
401
|
|
|
365
|
-
if (reverse && !palette.endsWith('_r'))
|
|
366
|
-
palette = palette + '_r';
|
|
367
|
-
|
|
368
402
|
if (allPaletteNames.includes(palette))
|
|
369
403
|
{
|
|
370
404
|
if (!ColorTable[palette])
|
|
@@ -386,7 +420,7 @@ function jscolormap(name: string, shades: number): string[]
|
|
|
386
420
|
let result: string[] = [];
|
|
387
421
|
for (let i = 0; i < shades; i++)
|
|
388
422
|
{
|
|
389
|
-
const rgb: number[] = partial(name)((i + 0.5) / shades);
|
|
423
|
+
const rgb: number[] = partial(name)((i + 0.5) / shades);
|
|
390
424
|
result.push(toHexColor(rgb[0], rgb[1], rgb[2]));
|
|
391
425
|
}
|
|
392
426
|
return result;
|
package/lib/geo/geo.ts
CHANGED
|
@@ -106,7 +106,10 @@ export function geoNormalizeCollection(col: GeoFeatureCollection, options?: Norm
|
|
|
106
106
|
options = Util.shallowAssignImmutable(NormalizeAll, options);
|
|
107
107
|
|
|
108
108
|
// Normalize individual features
|
|
109
|
-
if (col && Array.isArray(col.features))
|
|
109
|
+
if (col && Array.isArray(col.features))
|
|
110
|
+
col.features = col.features.filter((f: any) => f.properties && f.geometry && f.geometry.coordinates);
|
|
111
|
+
if (col && Array.isArray(col.features))
|
|
112
|
+
col.features.forEach((f: GeoFeature) => geoNormalizeFeature(f, options));
|
|
110
113
|
|
|
111
114
|
// Ensure ID
|
|
112
115
|
if (options.ensureID)
|
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);
|