@dra2020/dra-types 1.8.99 → 1.8.101

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.
@@ -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;
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
@@ -504,6 +505,7 @@ export interface DistrictCache
504
505
  {
505
506
  colorElection?: string;
506
507
  colorEthnic?: string;
508
+ colorExtended?: string;
507
509
  colorSolid?: string;
508
510
  }
509
511
 
@@ -525,6 +527,41 @@ export interface DistrictColorParams
525
527
  colorDistrictsBy: string,
526
528
  }
527
529
 
530
+ export function ToExtendedColor(agg: PF.PackedFields, dc: PF.DatasetContext, colorBy: string): string
531
+ {
532
+ // compute pct
533
+ const {datasetid, field} = parseColorBy(colorBy);
534
+ if (!datasetid || !field || !dc.dsMeta || !dc.dsMeta[datasetid] || !dc.dsMeta[datasetid]?.fields[field]) return '#ffffff';
535
+ const meta = dc.dsMeta[datasetid];
536
+ let getter = PF.ToGetter(agg, dc, datasetid, datasetid);
537
+ let fields = PF.sortedFieldList(meta);
538
+ let den = 0;
539
+ if (meta.fields['Tot'])
540
+ den = getter('Tot');
541
+ else
542
+ fields.forEach(f => { den += getter(f) });
543
+ let num = 0;
544
+ let dfield = meta.fields[field];
545
+ if (dfield.colorBySum)
546
+ for (let i = 0; i < fields.length; i++)
547
+ {
548
+ num += getter(fields[i]);
549
+ if (fields[i] === field)
550
+ break;
551
+ }
552
+ else
553
+ num = getter(field);
554
+
555
+ // Careful...
556
+ if (den == 0 || den === undefined || isNaN(den) || num === undefined || isNaN(num))
557
+ return '#ffffff';
558
+
559
+ const pct = dfield.invert ? 1 - (num / den) : num / den;
560
+ const color = Util.execGradient(makeStops(EthnicFewStops, Colors.EthnicFewClassicColors), pct);
561
+
562
+ return color;
563
+ }
564
+
528
565
  export function computeDistrictColors(params: DistrictColorParams): DistrictCache[]
529
566
  {
530
567
  let dcNew: DistrictCache[] = [];
@@ -554,7 +591,13 @@ export function computeDistrictColors(params: DistrictColorParams): DistrictCach
554
591
  dc.colorSolid = dc.colorEthnic;
555
592
  break;
556
593
  default:
557
- dc.colorSolid = mapColor;
594
+ if (isColorBy(params.colorDistrictsBy))
595
+ {
596
+ dc.colorExtended = ToExtendedColor(agg, params.datasetContext, params.colorDistrictsBy);
597
+ dc.colorSolid = dc.colorExtended;
598
+ }
599
+ else
600
+ dc.colorSolid = mapColor;
558
601
  break;
559
602
  }
560
603
  dcNew.push(dc);
package/lib/datasets.ts CHANGED
@@ -31,6 +31,12 @@ export function parseColorBy(colorby: string): { datasetid: string, field: strin
31
31
  return { datasetid: '', field: '' };
32
32
  }
33
33
 
34
+ export function isColorBy(colorby: string): boolean
35
+ {
36
+ let {datasetid, field} = parseColorBy(colorby);
37
+ return !!datasetid && !!field;
38
+ }
39
+
34
40
  // For Partisan fields, expect keys of 'D', 'R' and 'Tot'
35
41
  // For Demographic Fields, expect keys of 'Tot', 'Wh', 'Bl', 'His', 'AsnPI', 'Nat', 'Oth',
36
42
  // 'Asn', 'Pac', 'OthAl', 'Mix', 'BlC', 'NatC', 'AsnC', 'PacC',
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/dra-types",
3
- "version": "1.8.99",
3
+ "version": "1.8.101",
4
4
  "description": "Shared types used between client, server and tools.",
5
5
  "main": "dist/dra-types.js",
6
6
  "types": "./dist/all.d.ts",