@dra2020/dra-types 1.8.100 → 1.8.102
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/colormgr.d.ts +2 -0
- package/dist/dra-types.js +54 -9
- package/dist/dra-types.js.map +1 -1
- package/dist/packedfields.d.ts +2 -3
- package/lib/colormgr.ts +54 -7
- package/lib/packedfields.ts +9 -3
- package/package.json +1 -1
package/dist/packedfields.d.ts
CHANGED
|
@@ -50,12 +50,10 @@ export interface PrimaryDatasetKeys {
|
|
|
50
50
|
}
|
|
51
51
|
export interface DatasetContext {
|
|
52
52
|
dsIndex: GroupPackedMetaIndex;
|
|
53
|
+
dsMeta: DatasetsMeta;
|
|
53
54
|
primeDDS: string;
|
|
54
55
|
primeVDS: string;
|
|
55
56
|
primeEDS: string;
|
|
56
|
-
datasetMetaDDS: DatasetMeta;
|
|
57
|
-
datasetMetaVDS: DatasetMeta;
|
|
58
|
-
datasetMetaEDS: DatasetMeta;
|
|
59
57
|
}
|
|
60
58
|
export type DSListItem = {
|
|
61
59
|
key: string;
|
|
@@ -76,6 +74,7 @@ export declare function computePackedFields(f: any, index: PackedMetaIndex): Pac
|
|
|
76
74
|
export declare function hasPackedFields(f: any): boolean;
|
|
77
75
|
export declare function setPackedFields(f: any, pf: PackedFields, fIndex: any): void;
|
|
78
76
|
export declare function isExtDataset(did: string): boolean;
|
|
77
|
+
export declare function toDatasetID(datasetKey: string): string;
|
|
79
78
|
export type ExtPackedFields = Uint32Array;
|
|
80
79
|
export type ExtBlockCardinality = Map<string, number>;
|
|
81
80
|
export declare function featurePushExtPackedFields(f: any, datasetid: string, index: PackedMetaIndex, data: ExtPackedFields, card: ExtBlockCardinality): void;
|
package/lib/colormgr.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// App libraries
|
|
2
2
|
import * as PF from "./packedfields";
|
|
3
|
+
import {isColorBy, parseColorBy} from './datasets';
|
|
3
4
|
import {Util, Colors} from '@dra2020/baseclient'
|
|
4
5
|
|
|
5
6
|
// All Groups Mosaic has 16 colors
|
|
@@ -172,7 +173,8 @@ export function ToAllEthnicColor(agg: PF.PackedFields, dc: PF.DatasetContext, pd
|
|
|
172
173
|
{
|
|
173
174
|
// Use VAP/CVAP if it exists
|
|
174
175
|
const dataset: string = dc.primeVDS ? dc.primeVDS : dc.primeDDS
|
|
175
|
-
|
|
176
|
+
const did = PF.toDatasetID(dataset);
|
|
177
|
+
return AggregateEthnicColor(PF.ToGetter(agg, dc, did, dataset), pd, dataset.endsWith('NH'));
|
|
176
178
|
}
|
|
177
179
|
|
|
178
180
|
export function ToPartisanColorStr(agg: PF.PackedFields, dc: PF.DatasetContext, pd: PaletteDefaults): string
|
|
@@ -187,10 +189,12 @@ export function ToPartisanDistrictColor(agg: PF.PackedFields, dc: PF.DatasetCont
|
|
|
187
189
|
|
|
188
190
|
function ToPartisanColor(agg: PF.PackedFields, dc: PF.DatasetContext, stops: Util.GradientStops): string
|
|
189
191
|
{
|
|
192
|
+
const did = PF.toDatasetID(dc.primeEDS);
|
|
193
|
+
|
|
190
194
|
if (dc.primeEDS === PF.DS_PVI2020)
|
|
191
195
|
{
|
|
192
|
-
const getter16 = PF.ToGetter(agg, dc,
|
|
193
|
-
const getter20 = PF.ToGetter(agg, dc,
|
|
196
|
+
const getter16 = PF.ToGetter(agg, dc, did, PF.DS_PRES2016);
|
|
197
|
+
const getter20 = PF.ToGetter(agg, dc, did, PF.DS_PRES2020);
|
|
194
198
|
|
|
195
199
|
const pviRaw = PF.calcRaw2020Pvi(getter16, getter20);
|
|
196
200
|
const color: string = ColorFromRGBPcts((1 - pviRaw / 100), 0, pviRaw / 100, stops);
|
|
@@ -199,14 +203,14 @@ function ToPartisanColor(agg: PF.PackedFields, dc: PF.DatasetContext, stops: Uti
|
|
|
199
203
|
}
|
|
200
204
|
else if (dc.primeEDS === PF.DS_PVI2016)
|
|
201
205
|
{
|
|
202
|
-
const getter = PF.ToGetter(agg, dc,
|
|
206
|
+
const getter = PF.ToGetter(agg, dc, did, dc.primeEDS);
|
|
203
207
|
const pviRaw = PF.calcRawPvi(getter);
|
|
204
208
|
const color: string = ColorFromRGBPcts((1 - pviRaw/100), 0, pviRaw/100, stops);
|
|
205
209
|
return color;
|
|
206
210
|
}
|
|
207
211
|
else
|
|
208
212
|
{
|
|
209
|
-
const getter = PF.ToGetter(agg, dc,
|
|
213
|
+
const getter = PF.ToGetter(agg, dc, did, dc.primeEDS);
|
|
210
214
|
return AggregatePartisanColorStr(getter, stops);
|
|
211
215
|
}
|
|
212
216
|
}
|
|
@@ -233,6 +237,7 @@ export function ToEthnicColorStr(agg: PF.PackedFields, dc: PF.DatasetContext, pd
|
|
|
233
237
|
let total: string = 'Tot';
|
|
234
238
|
let bInvert: boolean = false;
|
|
235
239
|
const dataset = dc.primeVDS ? dc.primeVDS : dc.primeDDS;
|
|
240
|
+
const did = PF.toDatasetID(dataset);
|
|
236
241
|
switch (detail)
|
|
237
242
|
{
|
|
238
243
|
case null: case '': case 'all':
|
|
@@ -251,7 +256,7 @@ export function ToEthnicColorStr(agg: PF.PackedFields, dc: PF.DatasetContext, pd
|
|
|
251
256
|
default: break;
|
|
252
257
|
}
|
|
253
258
|
|
|
254
|
-
const getter = PF.ToGetter(agg, dc,
|
|
259
|
+
const getter = PF.ToGetter(agg, dc, did, dataset);
|
|
255
260
|
let den = getter(total);
|
|
256
261
|
let num = getter(ethnic);
|
|
257
262
|
if (den === undefined || isNaN(den) || num === undefined || isNaN(num))
|
|
@@ -504,6 +509,7 @@ export interface DistrictCache
|
|
|
504
509
|
{
|
|
505
510
|
colorElection?: string;
|
|
506
511
|
colorEthnic?: string;
|
|
512
|
+
colorExtended?: string;
|
|
507
513
|
colorSolid?: string;
|
|
508
514
|
}
|
|
509
515
|
|
|
@@ -525,6 +531,41 @@ export interface DistrictColorParams
|
|
|
525
531
|
colorDistrictsBy: string,
|
|
526
532
|
}
|
|
527
533
|
|
|
534
|
+
export function ToExtendedColor(agg: PF.PackedFields, dc: PF.DatasetContext, colorBy: string): string
|
|
535
|
+
{
|
|
536
|
+
// compute pct
|
|
537
|
+
const {datasetid, field} = parseColorBy(colorBy);
|
|
538
|
+
if (!datasetid || !field || !dc.dsMeta || !dc.dsMeta[datasetid] || !dc.dsMeta[datasetid]?.fields[field]) return '#ffffff';
|
|
539
|
+
const meta = dc.dsMeta[datasetid];
|
|
540
|
+
let getter = PF.ToGetter(agg, dc, datasetid, datasetid);
|
|
541
|
+
let fields = PF.sortedFieldList(meta);
|
|
542
|
+
let den = 0;
|
|
543
|
+
if (meta.fields['Tot'])
|
|
544
|
+
den = getter('Tot');
|
|
545
|
+
else
|
|
546
|
+
fields.forEach(f => { den += getter(f) });
|
|
547
|
+
let num = 0;
|
|
548
|
+
let dfield = meta.fields[field];
|
|
549
|
+
if (dfield.colorBySum)
|
|
550
|
+
for (let i = 0; i < fields.length; i++)
|
|
551
|
+
{
|
|
552
|
+
num += getter(fields[i]);
|
|
553
|
+
if (fields[i] === field)
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
else
|
|
557
|
+
num = getter(field);
|
|
558
|
+
|
|
559
|
+
// Careful...
|
|
560
|
+
if (den == 0 || den === undefined || isNaN(den) || num === undefined || isNaN(num))
|
|
561
|
+
return '#ffffff';
|
|
562
|
+
|
|
563
|
+
const pct = dfield.invert ? 1 - (num / den) : num / den;
|
|
564
|
+
const color = Util.execGradient(makeStops(EthnicFewStops, Colors.EthnicFewClassicColors), pct);
|
|
565
|
+
|
|
566
|
+
return color;
|
|
567
|
+
}
|
|
568
|
+
|
|
528
569
|
export function computeDistrictColors(params: DistrictColorParams): DistrictCache[]
|
|
529
570
|
{
|
|
530
571
|
let dcNew: DistrictCache[] = [];
|
|
@@ -554,7 +595,13 @@ export function computeDistrictColors(params: DistrictColorParams): DistrictCach
|
|
|
554
595
|
dc.colorSolid = dc.colorEthnic;
|
|
555
596
|
break;
|
|
556
597
|
default:
|
|
557
|
-
|
|
598
|
+
if (isColorBy(params.colorDistrictsBy))
|
|
599
|
+
{
|
|
600
|
+
dc.colorExtended = ToExtendedColor(agg, params.datasetContext, params.colorDistrictsBy);
|
|
601
|
+
dc.colorSolid = dc.colorExtended;
|
|
602
|
+
}
|
|
603
|
+
else
|
|
604
|
+
dc.colorSolid = mapColor;
|
|
558
605
|
break;
|
|
559
606
|
}
|
|
560
607
|
dcNew.push(dc);
|
package/lib/packedfields.ts
CHANGED
|
@@ -95,12 +95,13 @@ export interface PrimaryDatasetKeys
|
|
|
95
95
|
export interface DatasetContext
|
|
96
96
|
{
|
|
97
97
|
dsIndex: GroupPackedMetaIndex;
|
|
98
|
+
dsMeta: DatasetsMeta;
|
|
98
99
|
primeDDS: string; // Demographic (Census)
|
|
99
100
|
primeVDS: string; // VAP/CVAP
|
|
100
101
|
primeEDS: string; // Election
|
|
101
|
-
datasetMetaDDS: DatasetMeta;
|
|
102
|
-
datasetMetaVDS: DatasetMeta;
|
|
103
|
-
datasetMetaEDS: DatasetMeta;
|
|
102
|
+
//datasetMetaDDS: DatasetMeta;
|
|
103
|
+
//datasetMetaVDS: DatasetMeta;
|
|
104
|
+
//datasetMetaEDS: DatasetMeta;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
// Dataset Lists
|
|
@@ -229,6 +230,11 @@ export function isExtDataset(did: string): boolean
|
|
|
229
230
|
return did && reExtDataset.test(did);
|
|
230
231
|
}
|
|
231
232
|
|
|
233
|
+
export function toDatasetID(datasetKey: string): string
|
|
234
|
+
{
|
|
235
|
+
return isExtDataset(datasetKey) ? datasetKey : '';
|
|
236
|
+
}
|
|
237
|
+
|
|
232
238
|
export type ExtPackedFields = Uint32Array; // [nblocks][nfields][fields]...
|
|
233
239
|
export type ExtBlockCardinality = Map<string, number>;
|
|
234
240
|
|