@dra2020/dra-types 1.8.109 → 1.8.111

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.
@@ -5,9 +5,6 @@ export interface DatasetField {
5
5
  order?: number;
6
6
  isCombo?: boolean;
7
7
  colorBy?: boolean;
8
- invert?: boolean;
9
- colorBySum?: boolean;
10
- colorLabel?: string;
11
8
  sumOf?: string[];
12
9
  }
13
10
  export declare function sortFields(f1: DatasetField, f2: DatasetField): number;
@@ -20,14 +17,20 @@ export declare function isColorBy(colorby: string): boolean;
20
17
  export type DatasetFields = {
21
18
  [key: string]: DatasetField;
22
19
  };
23
- export type DatasetColor = {
24
- intensity: string;
20
+ export interface DatasetColor {
21
+ shortCaption: string;
22
+ longCaption: string;
23
+ expr: string;
25
24
  colors: string;
26
25
  stops: string;
27
- };
28
- export type DatasetColors = {
29
- [key: string]: DatasetColor;
30
- };
26
+ }
27
+ export type DatasetColors = DatasetColor[];
28
+ export interface DatasetFormat {
29
+ shortCaption: string;
30
+ longCaption: string;
31
+ expr: string;
32
+ }
33
+ export type DatasetFormats = DatasetFormat[];
31
34
  export interface DatasetMeta {
32
35
  type: string;
33
36
  year: number;
@@ -42,9 +45,8 @@ export interface DatasetMeta {
42
45
  [key: number]: string;
43
46
  };
44
47
  fields?: DatasetFields;
45
- detailFormat?: string;
46
- detailTooltip?: string;
47
48
  colors?: DatasetColors;
49
+ formats?: DatasetFormats;
48
50
  }
49
51
  export type DatasetsMeta = {
50
52
  [dataset: string]: DatasetMeta;
@@ -63,6 +65,7 @@ export interface Dataset {
63
65
  datasource?: string;
64
66
  dotmap?: boolean;
65
67
  blobid?: string;
68
+ dataid?: string;
66
69
  meta?: DatasetsMeta;
67
70
  groups?: G.GroupMapIndex;
68
71
  }
package/dist/dra-types.js CHANGED
@@ -159,17 +159,17 @@ exports.ColorByGoodD = 5;
159
159
  exports.ColorByGreatD = 6;
160
160
  // ****************** Colors, Color Stops and Color Functions for "classic" palettes *******************
161
161
  const PartisanFewStops = [
162
- 0.00,
163
- 0.20,
164
- 0.30,
165
- 0.40,
166
- 0.45,
167
- 0.50,
168
- 0.50,
169
- 0.55,
170
- 0.60,
171
- 0.70,
172
- 0.80,
162
+ 0.00, // Carmine
163
+ 0.20, //
164
+ 0.30, //
165
+ 0.40, //
166
+ 0.45, //
167
+ 0.50, // pale red
168
+ 0.50, // pale blue
169
+ 0.55, //
170
+ 0.60, //
171
+ 0.70, //
172
+ 0.80, //
173
173
  1.00, // Dark blue
174
174
  ];
175
175
  // Like PartisanFewStops, but lose the gradient at two buckets at each edge to focus on competitive district differentiation
@@ -184,17 +184,17 @@ exports.PartisanDistrictStops = [
184
184
  //{ stop: 0.00, color: '#C21807' }, // Chilli Red
185
185
  //{ stop: 0.40, color: '#C21807' }, // .00 <= .40
186
186
  // Carmine
187
- 0.00,
188
- 0.40,
189
- 0.40,
190
- 0.45,
191
- 0.45,
192
- 0.50,
193
- 0.50,
194
- 0.55,
195
- 0.55,
196
- 0.60,
197
- 0.60,
187
+ 0.00, // Carmine
188
+ 0.40, // .00 <= .40
189
+ 0.40, //
190
+ 0.45, // .40 <= .45
191
+ 0.45, //
192
+ 0.50, // .45 <= .50
193
+ 0.50, //
194
+ 0.55, // .50 <= .55
195
+ 0.55, //
196
+ 0.60, // .55 <= .60
197
+ 0.60, //
198
198
  1.00, // .60 <= 1.0
199
199
  ];
200
200
  /*export let PartisanCustomStops = [
@@ -214,9 +214,9 @@ exports.PartisanDistrictStops = [
214
214
  ];*/
215
215
  exports.PartisanPrecinctStops = PartisanFewStops;
216
216
  exports.EthnicFewStops = [
217
- 0.00,
218
- 0.40,
219
- 0.50,
217
+ 0.00, //
218
+ 0.40, //
219
+ 0.50, //
220
220
  1.00, //
221
221
  ];
222
222
  exports.DefaultPaletteDefaults = {
@@ -574,36 +574,56 @@ function allGroups16Colors(palette, colors) {
574
574
  return modColors;
575
575
  }
576
576
  exports.allGroups16Colors = allGroups16Colors;
577
+ function safeNumber(n) { n = Number(n); return typeof n !== 'number' || isNaN(n) ? 0 : n; }
578
+ function safeStops(s) {
579
+ if (!s)
580
+ return exports.EthnicFewStops;
581
+ return s.split(',').map(safeNumber);
582
+ }
583
+ function safeColors(s) {
584
+ if (!s)
585
+ return ['#fafafa', '#aaaaaa', '#666666', '#111111'];
586
+ return s.split(',').map(s => s.trim());
587
+ }
577
588
  function ToExtendedColor(agg, dc, colorBy) {
578
- var _a;
579
589
  // compute pct
580
590
  const { datasetid, field } = (0, datasets_1.parseColorBy)(colorBy);
581
- if (!datasetid || !field || !dc.dsMeta || !dc.dsMeta[datasetid] || !((_a = dc.dsMeta[datasetid]) === null || _a === void 0 ? void 0 : _a.fields[field]))
591
+ if (!datasetid || !field || !dc.dsMeta || !dc.dsMeta[datasetid])
582
592
  return '#ffffff';
583
593
  const meta = dc.dsMeta[datasetid];
584
- let getter = PF.ToGetter(agg, dc, datasetid, datasetid);
585
- let fields = PF.sortedFieldList(meta);
586
- let den = 0;
587
- if (meta.fields['Tot'])
588
- den = getter('Tot');
589
- else
590
- fields.forEach(f => { den += getter(f); });
591
- let num = 0;
592
- let dfield = meta.fields[field];
593
- if (dfield.colorBySum)
594
- for (let i = 0; i < fields.length; i++) {
595
- num += getter(fields[i]);
596
- if (fields[i] === field)
597
- break;
598
- }
599
- else
600
- num = getter(field);
601
- // Careful...
602
- if (den == 0 || den === undefined || isNaN(den) || num === undefined || isNaN(num))
594
+ const dsfield = meta.fields ? meta.fields[field] : null;
595
+ const dscolor = meta.colors ? meta.colors.find((c) => c.shortCaption === field) : null;
596
+ if (!dsfield && !dscolor)
603
597
  return '#ffffff';
604
- const pct = dfield.invert ? 1 - (num / den) : num / den;
605
- const color = baseclient_1.Util.execGradient(makeStops(exports.EthnicFewStops, baseclient_1.Colors.EthnicFewClassicColors), pct);
606
- return color;
598
+ if (dscolor) {
599
+ let stops = safeStops(dscolor.stops);
600
+ let colors = safeColors(dscolor.colors);
601
+ if (stops.length != colors.length) {
602
+ stops = exports.EthnicFewStops;
603
+ colors = safeColors('');
604
+ }
605
+ let o = {};
606
+ let getter = PF.ToGetter(agg, dc, datasetid, datasetid);
607
+ Object.keys(meta.fields).forEach(f => o[f] = getter(f));
608
+ let formatter = new baseclient_1.Detail.FormatDetail(dscolor.expr);
609
+ let result = formatter.format(baseclient_1.Detail.FormatDetail.prepare(o));
610
+ let intensity = Math.min(Math.max(result.n || 0, 0), 1);
611
+ return baseclient_1.Util.execGradient(makeStops(stops, colors), intensity);
612
+ }
613
+ else {
614
+ let getter = PF.ToGetter(agg, dc, datasetid, datasetid);
615
+ let fields = PF.sortedFieldList(meta);
616
+ let den = 0;
617
+ if (meta.fields['Tot'])
618
+ den = getter('Tot');
619
+ else
620
+ fields.forEach(f => { den += getter(f); });
621
+ let num = getter(field);
622
+ // Careful...
623
+ if (den == 0 || den === undefined || isNaN(den) || num === undefined || isNaN(num))
624
+ return '#ffffff';
625
+ return baseclient_1.Util.execGradient(makeStops(exports.EthnicFewStops, baseclient_1.Colors.EthnicFewClassicColors), num / den);
626
+ }
607
627
  }
608
628
  exports.ToExtendedColor = ToExtendedColor;
609
629
  function computeDistrictColors(params) {
@@ -662,22 +682,22 @@ exports.BinDarkViolet = 14;
662
682
  exports.BinMagenta = 15;
663
683
  exports.BinDeepPink = 16;
664
684
  exports.BinColorLookup = [
665
- { r: 0xff, g: 0x00, b: 0x00 },
666
- { r: 0xff, g: 0x45, b: 0x00 },
667
- { r: 0x99, g: 0x66, b: 0x33 },
668
- { r: 0xff, g: 0xaa, b: 0x00 },
669
- { r: 0xff, g: 0xd7, b: 0x00 },
670
- { r: 0xff, g: 0xd7, b: 0x00 },
671
- { r: 0x9f, g: 0xd4, b: 0x00 },
672
- { r: 0x7f, g: 0xff, b: 0x00 },
673
- { r: 0x00, g: 0xff, b: 0x00 },
674
- { r: 0x00, g: 0xfa, b: 0x9a },
675
- { r: 0x00, g: 0xff, b: 0xff },
676
- { r: 0x73, g: 0xb2, b: 0xff },
677
- { r: 0x00, g: 0x00, b: 0xff },
678
- { r: 0x8a, g: 0x2b, b: 0xe2 },
679
- { r: 0x94, g: 0x00, b: 0xd3 },
680
- { r: 0xff, g: 0x00, b: 0xff },
685
+ { r: 0xff, g: 0x00, b: 0x00 }, // 0 - red
686
+ { r: 0xff, g: 0x45, b: 0x00 }, // 1 - orange red
687
+ { r: 0x99, g: 0x66, b: 0x33 }, // 2 - brown
688
+ { r: 0xff, g: 0xaa, b: 0x00 }, // 3 - orange
689
+ { r: 0xff, g: 0xd7, b: 0x00 }, // 4 - gold
690
+ { r: 0xff, g: 0xd7, b: 0x00 }, // 5 - yellow
691
+ { r: 0x9f, g: 0xd4, b: 0x00 }, // 6 - greenish
692
+ { r: 0x7f, g: 0xff, b: 0x00 }, // 7 - chartreuse
693
+ { r: 0x00, g: 0xff, b: 0x00 }, // 8 - lime
694
+ { r: 0x00, g: 0xfa, b: 0x9a }, // 9 - medium spring green
695
+ { r: 0x00, g: 0xff, b: 0xff }, // 10 - cyan
696
+ { r: 0x73, g: 0xb2, b: 0xff }, // 11 - light blue
697
+ { r: 0x00, g: 0x00, b: 0xff }, // 12 - blue
698
+ { r: 0x8a, g: 0x2b, b: 0xe2 }, // 13 - blue violet
699
+ { r: 0x94, g: 0x00, b: 0xd3 }, // 14 - dark violet
700
+ { r: 0xff, g: 0x00, b: 0xff }, // 15 - magenta
681
701
  { r: 0xff, g: 0x14, b: 0x93 }, // 16 - deep pink
682
702
  ];
683
703
  // Map ordering to Bin* lookup values
@@ -1391,6 +1411,8 @@ function isColorBy(colorby) {
1391
1411
  return !!datasetid && !!field;
1392
1412
  }
1393
1413
  exports.isColorBy = isColorBy;
1414
+ ;
1415
+ ;
1394
1416
 
1395
1417
 
1396
1418
  /***/ }),