@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/baseclient.js
CHANGED
|
@@ -98,13 +98,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
98
98
|
return result;
|
|
99
99
|
};
|
|
100
100
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
101
|
-
exports.
|
|
101
|
+
exports.getPalette = exports.orderedColors = exports.genColor = exports.defaultDistrictsPalette = exports.EthnicBackgroundColor = exports.CountEthnicBackgroundColor = exports.PartisanDistrictClassicColors = exports.CountPartisanDistrictClassicColors = exports.PartisanPrecinctClassicColors = exports.CountPartisanPrecinctClassicColors = exports.EthnicFewClassicColors = exports.CountEthnicFewClassicColors = exports.ColorValues = exports.DefaultColorNames = exports.MaxClassicColors = exports.MaxColors = exports.MaxOrderedColors = void 0;
|
|
102
102
|
const JsColorMapsData = __importStar(__webpack_require__(/*! ./jscolormapsdata */ "./lib/colors/jscolormapsdata.ts"));
|
|
103
103
|
const all_1 = __webpack_require__(/*! ../all/all */ "./lib/all/all.ts");
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
exports.MaxOrderedColors = 50;
|
|
105
|
+
exports.MaxColors = exports.MaxOrderedColors * 3; // Tied to orderedColors()
|
|
106
|
+
exports.MaxClassicColors = 55;
|
|
107
|
+
exports.DefaultColorNames = [
|
|
108
108
|
'GhostWhite',
|
|
109
109
|
'Blue',
|
|
110
110
|
'Green',
|
|
@@ -304,12 +304,16 @@ exports.ColorValues = {
|
|
|
304
304
|
'Yellow': '#FFFF00',
|
|
305
305
|
'YellowGreen': '#9ACD32',
|
|
306
306
|
};
|
|
307
|
+
// For Demographics scale (4 colors)
|
|
308
|
+
exports.CountEthnicFewClassicColors = 4;
|
|
307
309
|
exports.EthnicFewClassicColors = [
|
|
308
310
|
'#fafafa',
|
|
309
311
|
'#aaaaaa',
|
|
310
312
|
'#666666',
|
|
311
313
|
'#111111', //
|
|
312
314
|
];
|
|
315
|
+
// For Partisan Precinct Scale (12 colors)
|
|
316
|
+
exports.CountPartisanPrecinctClassicColors = 12;
|
|
313
317
|
exports.PartisanPrecinctClassicColors = [
|
|
314
318
|
'#960018',
|
|
315
319
|
'#FF2020',
|
|
@@ -324,91 +328,106 @@ exports.PartisanPrecinctClassicColors = [
|
|
|
324
328
|
'#2020FF',
|
|
325
329
|
'#00008B', // Dark blue
|
|
326
330
|
];
|
|
331
|
+
// For Partisan District Scale (12 stops)
|
|
332
|
+
exports.CountPartisanDistrictClassicColors = 12;
|
|
333
|
+
exports.PartisanDistrictClassicColors = [
|
|
334
|
+
'#960018',
|
|
335
|
+
'#960018',
|
|
336
|
+
'#FF2020',
|
|
337
|
+
'#FF2020',
|
|
338
|
+
'#FF6060',
|
|
339
|
+
'#FFDEDE',
|
|
340
|
+
'#DEDEFF',
|
|
341
|
+
'#6060FF',
|
|
342
|
+
'#2020FF',
|
|
343
|
+
'#2020FF',
|
|
344
|
+
'#00008B',
|
|
345
|
+
'#00008B', // .60 <= 1.0
|
|
346
|
+
];
|
|
347
|
+
// All Groups Mosaic 16 colors
|
|
348
|
+
exports.CountEthnicBackgroundColor = 16;
|
|
349
|
+
exports.EthnicBackgroundColor = [
|
|
350
|
+
'#c0392b',
|
|
351
|
+
'#3498db',
|
|
352
|
+
'#2ecc71',
|
|
353
|
+
'#9b59b6',
|
|
354
|
+
'#d98880',
|
|
355
|
+
'#aed6f1',
|
|
356
|
+
'#abebc6',
|
|
357
|
+
'#bb8fce',
|
|
358
|
+
'#f1c40f',
|
|
359
|
+
'#aab7b8',
|
|
360
|
+
'#d5f5e3',
|
|
361
|
+
'#d6eaf8',
|
|
362
|
+
'#186a3b',
|
|
363
|
+
'#e8daef',
|
|
364
|
+
'#45b39d',
|
|
365
|
+
'#4a235a', // black / asian
|
|
366
|
+
];
|
|
367
|
+
exports.defaultDistrictsPalette = 'jet_r';
|
|
368
|
+
// Static color tables; lazily populated
|
|
327
369
|
let ColorTable = {};
|
|
328
370
|
let OrderedColorTable = {};
|
|
329
371
|
function genColor(i, useFirstColor, palette) {
|
|
330
372
|
// i is district number, 0 => District[0] (unassigned), so subtract 1 to access ColorTable
|
|
331
|
-
if (!useFirstColor || !palette)
|
|
332
|
-
return genDRAColor(i, useFirstColor);
|
|
333
373
|
if (i == 0)
|
|
334
|
-
return exports.ColorValues[DefaultColorNames[0]];
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
case 'inferno':
|
|
343
|
-
case 'turbo':
|
|
344
|
-
default:
|
|
345
|
-
return orderedColors(palette)[(i - 1) % MaxOrderedColors];
|
|
346
|
-
case 'draclassic':
|
|
347
|
-
return genDRAColor(i, useFirstColor);
|
|
348
|
-
}
|
|
374
|
+
return exports.ColorValues[exports.DefaultColorNames[0]];
|
|
375
|
+
if (!useFirstColor || !palette || palette === 'draclassic')
|
|
376
|
+
return genDRAColor(i, useFirstColor);
|
|
377
|
+
const colors = orderedColors(palette);
|
|
378
|
+
if (colors.length >= exports.MaxOrderedColors)
|
|
379
|
+
return colors[(i - 1) % exports.MaxOrderedColors];
|
|
380
|
+
// Unexpected to get here, but something in case of an error
|
|
381
|
+
return genDRAColor(i, useFirstColor);
|
|
349
382
|
}
|
|
350
383
|
exports.genColor = genColor;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
case 'demographicsclassic':
|
|
362
|
-
case 'partisanclassic':
|
|
363
|
-
case 'allgroupsclassic':
|
|
364
|
-
return getColorTable(palette, true);
|
|
365
|
-
case 'greys':
|
|
366
|
-
return getColorTable(palette, false);
|
|
367
|
-
default:
|
|
368
|
-
// return draclassic palette with only 30 colors
|
|
369
|
-
for (let i = 1; i < 30; i++)
|
|
370
|
-
colors.push(genDRAColor(i, true));
|
|
371
|
-
return colors;
|
|
384
|
+
// DRA classic color palette
|
|
385
|
+
function genDRAColor(i, useFirstColor) {
|
|
386
|
+
// i is district number, 0 => District[0] (unassigned), so subtract 1 to access ColorTable
|
|
387
|
+
function gen_table() {
|
|
388
|
+
ColorTable['draclassic'] = [];
|
|
389
|
+
for (let i = 0; i < exports.MaxClassicColors; i++) {
|
|
390
|
+
// A little funky math below to skip the first (white) color
|
|
391
|
+
let j = (i % (exports.DefaultColorNames.length - 1)) + 1;
|
|
392
|
+
ColorTable['draclassic'].push(exports.ColorValues[exports.DefaultColorNames[j]]);
|
|
393
|
+
}
|
|
372
394
|
}
|
|
395
|
+
if (!ColorTable['draclassic'])
|
|
396
|
+
gen_table();
|
|
397
|
+
if (i == 0)
|
|
398
|
+
return exports.ColorValues[exports.DefaultColorNames[0]];
|
|
399
|
+
return ColorTable['draclassic'][((i - 1) + (useFirstColor ? 0 : 1)) % exports.MaxClassicColors];
|
|
373
400
|
}
|
|
374
|
-
exports.getPalette = getPalette;
|
|
375
401
|
const DistrictsColorOrder = [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,
|
|
376
402
|
7, 31, 13, 37, 19, 47, 25, 43, 8, 32, 14, 38, 2, 20, 26, 44];
|
|
377
403
|
function orderedColors(palette) {
|
|
378
404
|
const colors = getPalette(palette);
|
|
379
405
|
if (!OrderedColorTable[palette]) {
|
|
380
406
|
OrderedColorTable[palette] = [];
|
|
381
|
-
for (let i = 0; i < MaxColors; i++) {
|
|
407
|
+
for (let i = 0; i < exports.MaxColors; i++) {
|
|
382
408
|
OrderedColorTable[palette].push(colors[DistrictsColorOrder[i] * 3]);
|
|
383
409
|
}
|
|
384
410
|
}
|
|
385
411
|
return OrderedColorTable[palette];
|
|
386
412
|
}
|
|
387
|
-
exports.
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
let j = (i % (DefaultColorNames.length - 1)) + 1;
|
|
396
|
-
ColorTable['draclassic'].push(exports.ColorValues[DefaultColorNames[j]]);
|
|
397
|
-
}
|
|
413
|
+
exports.orderedColors = orderedColors;
|
|
414
|
+
function getPalette(palette) {
|
|
415
|
+
if (palette === 'draclassic') {
|
|
416
|
+
// return draclassic palette with only 50 colors
|
|
417
|
+
let colors = [];
|
|
418
|
+
for (let i = 1; i < exports.MaxOrderedColors; i++)
|
|
419
|
+
colors.push(genDRAColor(i, true));
|
|
420
|
+
return colors;
|
|
398
421
|
}
|
|
399
|
-
|
|
400
|
-
gen_table();
|
|
401
|
-
if (i == 0)
|
|
402
|
-
return exports.ColorValues[DefaultColorNames[0]];
|
|
403
|
-
return ColorTable['draclassic'][((i - 1) + (useFirstColor ? 0 : 1)) % MaxClassicColors];
|
|
422
|
+
return getColorTable(palette);
|
|
404
423
|
}
|
|
405
|
-
exports.
|
|
424
|
+
exports.getPalette = getPalette;
|
|
406
425
|
// Generate table for palette
|
|
407
|
-
function getColorTable(palette
|
|
426
|
+
function getColorTable(palette) {
|
|
408
427
|
if (palette === 'demographicsclassic') {
|
|
409
428
|
if (!ColorTable[palette]) {
|
|
410
429
|
ColorTable[palette] = [];
|
|
411
|
-
for (let i = 0; i <
|
|
430
|
+
for (let i = 0; i < exports.CountEthnicFewClassicColors; i++)
|
|
412
431
|
ColorTable[palette].push(exports.EthnicFewClassicColors[i]);
|
|
413
432
|
}
|
|
414
433
|
return ColorTable[palette];
|
|
@@ -416,16 +435,30 @@ function getColorTable(palette, reverse) {
|
|
|
416
435
|
else if (palette === 'partisanclassic') {
|
|
417
436
|
if (!ColorTable[palette]) {
|
|
418
437
|
ColorTable[palette] = [];
|
|
419
|
-
for (let i = 0; i <
|
|
438
|
+
for (let i = 0; i < exports.CountPartisanPrecinctClassicColors; i++)
|
|
420
439
|
ColorTable[palette].push(exports.PartisanPrecinctClassicColors[i]);
|
|
421
440
|
}
|
|
422
441
|
return ColorTable[palette];
|
|
423
442
|
}
|
|
424
|
-
if (
|
|
425
|
-
|
|
443
|
+
else if (palette === 'partisandistrictsclassic') {
|
|
444
|
+
if (!ColorTable[palette]) {
|
|
445
|
+
ColorTable[palette] = [];
|
|
446
|
+
for (let i = 0; i < exports.CountPartisanDistrictClassicColors; i++)
|
|
447
|
+
ColorTable[palette].push(exports.PartisanDistrictClassicColors[i]);
|
|
448
|
+
}
|
|
449
|
+
return ColorTable[palette];
|
|
450
|
+
}
|
|
451
|
+
else if (palette === 'allgroupsclassic') {
|
|
452
|
+
if (!ColorTable[palette]) {
|
|
453
|
+
ColorTable[palette] = [];
|
|
454
|
+
for (let i = 0; i < exports.CountEthnicBackgroundColor; i++)
|
|
455
|
+
ColorTable[palette].push(exports.EthnicBackgroundColor[i]);
|
|
456
|
+
return ColorTable[palette];
|
|
457
|
+
}
|
|
458
|
+
}
|
|
426
459
|
if (allPaletteNames.includes(palette)) {
|
|
427
460
|
if (!ColorTable[palette])
|
|
428
|
-
ColorTable[palette] = jscolormap(palette, MaxColors);
|
|
461
|
+
ColorTable[palette] = jscolormap(palette, exports.MaxColors);
|
|
429
462
|
return ColorTable[palette];
|
|
430
463
|
}
|
|
431
464
|
else
|
|
@@ -438,7 +471,7 @@ function toHexColor(r, g, b) {
|
|
|
438
471
|
function jscolormap(name, shades) {
|
|
439
472
|
let result = [];
|
|
440
473
|
for (let i = 0; i < shades; i++) {
|
|
441
|
-
const rgb = partial(name)((i + 0.5) / shades);
|
|
474
|
+
const rgb = partial(name)((i + 0.5) / shades);
|
|
442
475
|
result.push(toHexColor(rgb[0], rgb[1], rgb[2]));
|
|
443
476
|
}
|
|
444
477
|
return result;
|
|
@@ -2233,6 +2266,8 @@ function mergePolygon(f1, f2) {
|
|
|
2233
2266
|
function geoNormalizeCollection(col, options) {
|
|
2234
2267
|
options = Util.shallowAssignImmutable(NormalizeAll, options);
|
|
2235
2268
|
// Normalize individual features
|
|
2269
|
+
if (col && Array.isArray(col.features))
|
|
2270
|
+
col.features = col.features.filter((f) => f.properties && f.geometry && f.geometry.coordinates);
|
|
2236
2271
|
if (col && Array.isArray(col.features))
|
|
2237
2272
|
col.features.forEach((f) => geoNormalizeFeature(f, options));
|
|
2238
2273
|
// Ensure ID
|
|
@@ -7428,9 +7463,9 @@ function featureRewind(f, options) {
|
|
|
7428
7463
|
return null;
|
|
7429
7464
|
// Has to be an unpacked feature
|
|
7430
7465
|
if (f.type !== 'Feature')
|
|
7431
|
-
|
|
7466
|
+
return f;
|
|
7432
7467
|
if (!f.geometry || f.geometry.packed)
|
|
7433
|
-
|
|
7468
|
+
return f;
|
|
7434
7469
|
// Non polygons are simpler
|
|
7435
7470
|
if (f.geometry.type !== 'Polygon' && f.geometry.type !== 'MultiPolygon')
|
|
7436
7471
|
return canonicalPoint(f, options);
|