@dra2020/dra-types 1.8.88 → 1.8.89
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/all.d.ts +6 -14
- package/dist/alldt.d.ts +14 -0
- package/dist/colormgr.d.ts +69 -0
- package/dist/dra-types.d.ts +1 -0
- package/dist/dra-types.js +801 -13
- package/dist/dra-types.js.map +1 -1
- package/dist/packedfields.d.ts +103 -1
- package/lib/all.ts +6 -14
- package/lib/alldt.ts +14 -0
- package/lib/colormgr.ts +563 -0
- package/lib/dra-types.ts +1 -0
- package/lib/packedfields.ts +396 -1
- package/package.json +1 -1
package/dist/dra-types.js
CHANGED
|
@@ -12,10 +12,10 @@ return /******/ (() => { // webpackBootstrap
|
|
|
12
12
|
/******/ "use strict";
|
|
13
13
|
/******/ var __webpack_modules__ = ({
|
|
14
14
|
|
|
15
|
-
/***/ "./lib/
|
|
16
|
-
|
|
17
|
-
!*** ./lib/
|
|
18
|
-
|
|
15
|
+
/***/ "./lib/alldt.ts":
|
|
16
|
+
/*!**********************!*\
|
|
17
|
+
!*** ./lib/alldt.ts ***!
|
|
18
|
+
\**********************/
|
|
19
19
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
20
20
|
|
|
21
21
|
|
|
@@ -94,6 +94,512 @@ exports.BucketMap = {
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
|
|
97
|
+
/***/ }),
|
|
98
|
+
|
|
99
|
+
/***/ "./lib/colormgr.ts":
|
|
100
|
+
/*!*************************!*\
|
|
101
|
+
!*** ./lib/colormgr.ts ***!
|
|
102
|
+
\*************************/
|
|
103
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
107
|
+
exports.computeDistrictColors = exports.allGroups16Colors = exports.colorsFromStopsPartisan = exports.colorsFromStops = exports.PaletteNames = exports.ColorFromRGBPcts = exports.AggregatePartisanColorStr = exports.AggregatePartisanColor = exports.AggregateEthnicColor = exports.ToEthnicColorStr = exports.ToPartisanShiftColor = exports.ToPartisanDistrictColor = exports.ToPartisanColorStr = exports.ToAllEthnicColor = exports.ethnicBackgroundColor = exports.makeStops = exports.DefaultPaletteDefaults = exports.EthnicFewStops = exports.PartisanPrecinctStops = exports.PartisanDistrictStops = exports.ColorByGreatD = exports.ColorByGoodD = exports.ColorByFairD = exports.ColorByEven = exports.ColorByFairR = exports.ColorByGoodR = exports.ColorByGreatR = exports.EthnicTextColor = exports.ColorByBlackAsian = exports.ColorByAsianHispanic = exports.ColorByAsianWhite = exports.ColorByHispanicBlack = exports.ColorByBlackWhite = exports.ColorByHispanicWhite = exports.ColorByMix = exports.ColorByMostlyNative = exports.ColorByMostlyAsian = exports.ColorByMostlyHispanic = exports.ColorByMostlyBlack = exports.ColorByMostlyWhite = exports.ColorBySolidAsian = exports.ColorBySolidHispanic = exports.ColorBySolidBlack = exports.ColorBySolidWhite = void 0;
|
|
108
|
+
// App libraries
|
|
109
|
+
const PF = __webpack_require__(/*! ./packedfields */ "./lib/packedfields.ts");
|
|
110
|
+
const baseclient_1 = __webpack_require__(/*! @dra2020/baseclient */ "@dra2020/baseclient");
|
|
111
|
+
// All Groups Mosaic has 16 colors
|
|
112
|
+
// Index values into the 16 colors
|
|
113
|
+
exports.ColorBySolidWhite = 0;
|
|
114
|
+
exports.ColorBySolidBlack = 1;
|
|
115
|
+
exports.ColorBySolidHispanic = 2;
|
|
116
|
+
exports.ColorBySolidAsian = 3;
|
|
117
|
+
exports.ColorByMostlyWhite = 4;
|
|
118
|
+
exports.ColorByMostlyBlack = 5;
|
|
119
|
+
exports.ColorByMostlyHispanic = 6;
|
|
120
|
+
exports.ColorByMostlyAsian = 7;
|
|
121
|
+
exports.ColorByMostlyNative = 8;
|
|
122
|
+
exports.ColorByMix = 9;
|
|
123
|
+
exports.ColorByHispanicWhite = 10;
|
|
124
|
+
exports.ColorByBlackWhite = 11;
|
|
125
|
+
exports.ColorByHispanicBlack = 12;
|
|
126
|
+
exports.ColorByAsianWhite = 13;
|
|
127
|
+
exports.ColorByAsianHispanic = 14;
|
|
128
|
+
exports.ColorByBlackAsian = 15;
|
|
129
|
+
// Text color for All Groups Mosaic (Legend)
|
|
130
|
+
exports.EthnicTextColor = [
|
|
131
|
+
'#ffffff',
|
|
132
|
+
'#ffffff',
|
|
133
|
+
'#ffffff',
|
|
134
|
+
'#ffffff',
|
|
135
|
+
'#000000',
|
|
136
|
+
'#000000',
|
|
137
|
+
'#000000',
|
|
138
|
+
'#000000',
|
|
139
|
+
'#000000',
|
|
140
|
+
'#000000',
|
|
141
|
+
'#000000',
|
|
142
|
+
'#000000',
|
|
143
|
+
'#ffffff',
|
|
144
|
+
'#000000',
|
|
145
|
+
'#000000',
|
|
146
|
+
'#ffffff',
|
|
147
|
+
];
|
|
148
|
+
exports.ColorByGreatR = 0;
|
|
149
|
+
exports.ColorByGoodR = 1;
|
|
150
|
+
exports.ColorByFairR = 2;
|
|
151
|
+
exports.ColorByEven = 3;
|
|
152
|
+
exports.ColorByFairD = 4;
|
|
153
|
+
exports.ColorByGoodD = 5;
|
|
154
|
+
exports.ColorByGreatD = 6;
|
|
155
|
+
// ****************** Colors, Color Stops and Color Functions for "classic" palettes *******************
|
|
156
|
+
const PartisanFewStops = [
|
|
157
|
+
0.00,
|
|
158
|
+
0.20,
|
|
159
|
+
0.30,
|
|
160
|
+
0.40,
|
|
161
|
+
0.45,
|
|
162
|
+
0.50,
|
|
163
|
+
0.50,
|
|
164
|
+
0.55,
|
|
165
|
+
0.60,
|
|
166
|
+
0.70,
|
|
167
|
+
0.80,
|
|
168
|
+
1.00, // Dark blue
|
|
169
|
+
];
|
|
170
|
+
// Like PartisanFewStops, but lose the gradient at two buckets at each edge to focus on competitive district differentiation
|
|
171
|
+
exports.PartisanDistrictStops = [
|
|
172
|
+
// Dark red
|
|
173
|
+
//{ stop: 0.00, color: '#8B0000' }, // Dark red
|
|
174
|
+
//{ stop: 0.40, color: '#8B0000' }, // .00 <= .40
|
|
175
|
+
// Crimson
|
|
176
|
+
//{ stop: 0.00, color: '#DC143C' }, // Crimson
|
|
177
|
+
//{ stop: 0.40, color: '#DC143C' }, // .00 <= .40
|
|
178
|
+
// Chilli Red
|
|
179
|
+
//{ stop: 0.00, color: '#C21807' }, // Chilli Red
|
|
180
|
+
//{ stop: 0.40, color: '#C21807' }, // .00 <= .40
|
|
181
|
+
// Carmine
|
|
182
|
+
0.00,
|
|
183
|
+
0.40,
|
|
184
|
+
0.40,
|
|
185
|
+
0.45,
|
|
186
|
+
0.45,
|
|
187
|
+
0.50,
|
|
188
|
+
0.50,
|
|
189
|
+
0.55,
|
|
190
|
+
0.55,
|
|
191
|
+
0.60,
|
|
192
|
+
0.60,
|
|
193
|
+
1.00, // .60 <= 1.0
|
|
194
|
+
];
|
|
195
|
+
/*export let PartisanCustomStops = [
|
|
196
|
+
{ stop: 0.00, color: '#FF0000' }, // Dark red
|
|
197
|
+
{ stop: 0.20, color: '#FF0000' }, //
|
|
198
|
+
{ stop: 0.30, color: '#FF0000' }, //
|
|
199
|
+
{ stop: 0.40, color: '#CD5C5C' }, // Indian red
|
|
200
|
+
{ stop: 0.45, color: '#DB7093' }, // Pale Violet Red
|
|
201
|
+
{ stop: 0.499, color: '#DB7093' }, // Light Pink
|
|
202
|
+
{ stop: 0.50, color: '#FFFFFF' }, // white
|
|
203
|
+
{ stop: 0.501, color: '#87CEFA' }, // Light Sky Blue
|
|
204
|
+
{ stop: 0.55, color: '#00bFFF' }, // Deep Sky Blue
|
|
205
|
+
{ stop: 0.60, color: '#002366' }, // Royal Blue
|
|
206
|
+
{ stop: 0.70, color: '#0000CD' }, // Medium Blue
|
|
207
|
+
{ stop: 0.80, color: '#191970' }, //
|
|
208
|
+
{ stop: 1.00, color: '#191970' }, // Midnight Blue
|
|
209
|
+
];*/
|
|
210
|
+
exports.PartisanPrecinctStops = PartisanFewStops;
|
|
211
|
+
exports.EthnicFewStops = [
|
|
212
|
+
0.00,
|
|
213
|
+
0.40,
|
|
214
|
+
0.50,
|
|
215
|
+
1.00, //
|
|
216
|
+
];
|
|
217
|
+
exports.DefaultPaletteDefaults = {
|
|
218
|
+
partisanScale: 'partisanclassic',
|
|
219
|
+
partisanDistrictsScale: 'partisandistrictsclassic',
|
|
220
|
+
demographicsScale: 'demographicsclassic',
|
|
221
|
+
demographicsAllGroups: 'allgroupsclassic',
|
|
222
|
+
};
|
|
223
|
+
function makeStops(stops, colors) {
|
|
224
|
+
// Lengths should be equal
|
|
225
|
+
const len = stops.length <= colors.length ? stops.length : colors.length;
|
|
226
|
+
let result = [];
|
|
227
|
+
for (let i = 0; i < len; i++)
|
|
228
|
+
result.push({ stop: stops[i], color: colors[i] });
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
exports.makeStops = makeStops;
|
|
232
|
+
function partisanStops(stops, pd) {
|
|
233
|
+
const palette = pd['partisanScale'];
|
|
234
|
+
return makeStops(stops, colorsFromStopsPartisan(palette, 'partisanScale', stops));
|
|
235
|
+
}
|
|
236
|
+
function partisanDistrictStops(stops, pd) {
|
|
237
|
+
const palette = pd['partisanDistrictsScale'];
|
|
238
|
+
return makeStops(stops, colorsFromStopsPartisan(palette, 'partisanDistrictsScale', stops));
|
|
239
|
+
}
|
|
240
|
+
function ethnicStops(stops, pd) {
|
|
241
|
+
const palette = pd['demographicsScale'];
|
|
242
|
+
if (palette === 'demographicsclassic')
|
|
243
|
+
return makeStops(stops, baseclient_1.Colors.EthnicFewClassicColors);
|
|
244
|
+
return makeStops(stops, colorsFromStops(palette, stops, baseclient_1.Colors.EthnicFewClassicColors));
|
|
245
|
+
}
|
|
246
|
+
function ethnicBackgroundColor(index, pd) {
|
|
247
|
+
const palette = pd['demographicsAllGroups'];
|
|
248
|
+
const colors = allGroups16Colors(palette, baseclient_1.Colors.getPalette(palette));
|
|
249
|
+
if (index < colors.length)
|
|
250
|
+
return colors[index];
|
|
251
|
+
return '#ffffff';
|
|
252
|
+
}
|
|
253
|
+
exports.ethnicBackgroundColor = ethnicBackgroundColor;
|
|
254
|
+
function ToAllEthnicColor(agg, dc, pd) {
|
|
255
|
+
// Use VAP/CVAP if it exists
|
|
256
|
+
const dataset = dc.primeVDS ? dc.primeVDS : dc.primeDDS;
|
|
257
|
+
return AggregateEthnicColor(PF.ToGetter(agg, dc, dataset), pd, dataset.endsWith('NH'));
|
|
258
|
+
}
|
|
259
|
+
exports.ToAllEthnicColor = ToAllEthnicColor;
|
|
260
|
+
function ToPartisanColorStr(agg, dc, pd) {
|
|
261
|
+
return ToPartisanColor(agg, dc, partisanStops(exports.PartisanPrecinctStops, pd));
|
|
262
|
+
}
|
|
263
|
+
exports.ToPartisanColorStr = ToPartisanColorStr;
|
|
264
|
+
function ToPartisanDistrictColor(agg, dc, pd) {
|
|
265
|
+
return ToPartisanColor(agg, dc, partisanDistrictStops(exports.PartisanDistrictStops, pd));
|
|
266
|
+
}
|
|
267
|
+
exports.ToPartisanDistrictColor = ToPartisanDistrictColor;
|
|
268
|
+
function ToPartisanColor(agg, dc, stops) {
|
|
269
|
+
if (dc.primeEDS === PF.DS_PVI2020) {
|
|
270
|
+
const getter16 = PF.ToGetter(agg, dc, PF.DS_PRES2016);
|
|
271
|
+
const getter20 = PF.ToGetter(agg, dc, PF.DS_PRES2020);
|
|
272
|
+
const pviRaw = PF.calcRaw2020Pvi(getter16, getter20);
|
|
273
|
+
const color = ColorFromRGBPcts((1 - pviRaw / 100), 0, pviRaw / 100, stops);
|
|
274
|
+
//console.log('Pvi (r, d, color): (' + (1 - pviRaw/100) + ', ' + pviRaw/100 + ', ' + color + ')');
|
|
275
|
+
return color;
|
|
276
|
+
}
|
|
277
|
+
else if (dc.primeEDS === PF.DS_PVI2016) {
|
|
278
|
+
const getter = PF.ToGetter(agg, dc, dc.primeEDS);
|
|
279
|
+
const pviRaw = PF.calcRawPvi(getter);
|
|
280
|
+
const color = ColorFromRGBPcts((1 - pviRaw / 100), 0, pviRaw / 100, stops);
|
|
281
|
+
return color;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const getter = PF.ToGetter(agg, dc, dc.primeEDS);
|
|
285
|
+
return AggregatePartisanColorStr(getter, stops);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function ToPartisanShiftColor(agg, dc, datasets, pd) {
|
|
289
|
+
if (!datasets || datasets.length < 2)
|
|
290
|
+
return '';
|
|
291
|
+
const shift = PF.calcShift(agg, dc, datasets[0], datasets[1]);
|
|
292
|
+
if (shift == null)
|
|
293
|
+
return null;
|
|
294
|
+
const rep = 0.5 - (shift / 2);
|
|
295
|
+
const dem = 0.5 + (shift / 2);
|
|
296
|
+
const stops = partisanStops(exports.PartisanPrecinctStops, pd);
|
|
297
|
+
const color = ColorFromRGBPcts(rep, 0, dem, stops);
|
|
298
|
+
//console.log('Shift (r, d, color): (' + rep + ', ' + dem + ', ' + color + ')');
|
|
299
|
+
return color;
|
|
300
|
+
}
|
|
301
|
+
exports.ToPartisanShiftColor = ToPartisanShiftColor;
|
|
302
|
+
function ToEthnicColorStr(agg, dc, pd, detail) {
|
|
303
|
+
let ethnic = 'Wh';
|
|
304
|
+
let total = 'Tot';
|
|
305
|
+
let bInvert = false;
|
|
306
|
+
const dataset = dc.primeVDS ? dc.primeVDS : dc.primeDDS;
|
|
307
|
+
switch (detail) {
|
|
308
|
+
case null:
|
|
309
|
+
case '':
|
|
310
|
+
case 'all':
|
|
311
|
+
let c = ToAllEthnicColor(agg, dc, pd); // special case
|
|
312
|
+
return c >= 0 ? ethnicBackgroundColor(c, pd) : '#ffffff';
|
|
313
|
+
case 'white':
|
|
314
|
+
ethnic = 'Wh';
|
|
315
|
+
break;
|
|
316
|
+
case 'nonwhite':
|
|
317
|
+
ethnic = 'Wh';
|
|
318
|
+
bInvert = true;
|
|
319
|
+
break;
|
|
320
|
+
case 'black':
|
|
321
|
+
ethnic = dataset.endsWith('NH') ? 'Bl' : 'BlC';
|
|
322
|
+
break;
|
|
323
|
+
case 'hisp':
|
|
324
|
+
ethnic = 'His';
|
|
325
|
+
break;
|
|
326
|
+
case 'native':
|
|
327
|
+
ethnic = dataset.endsWith('NH') ? 'Nat' : 'NatC';
|
|
328
|
+
break;
|
|
329
|
+
case 'asianpi':
|
|
330
|
+
ethnic = 'AsnPI';
|
|
331
|
+
break;
|
|
332
|
+
case 'asian':
|
|
333
|
+
ethnic = dataset.endsWith('NH') ? 'Asn' : 'AsnC';
|
|
334
|
+
break;
|
|
335
|
+
case 'pac':
|
|
336
|
+
ethnic = dataset.endsWith('NH') ? 'Pac' : 'PacC';
|
|
337
|
+
break;
|
|
338
|
+
case 'other':
|
|
339
|
+
ethnic = 'OthAl';
|
|
340
|
+
break;
|
|
341
|
+
case 'mix':
|
|
342
|
+
ethnic = 'Mix';
|
|
343
|
+
break;
|
|
344
|
+
default: break;
|
|
345
|
+
}
|
|
346
|
+
const getter = PF.ToGetter(agg, dc, dataset);
|
|
347
|
+
let den = getter(total);
|
|
348
|
+
let num = getter(ethnic);
|
|
349
|
+
if (den === undefined || isNaN(den) || num === undefined || isNaN(num))
|
|
350
|
+
return '#ffffff';
|
|
351
|
+
if (den == 0)
|
|
352
|
+
return '#ffffff';
|
|
353
|
+
const pct = bInvert ? 1 - (num / den) : num / den;
|
|
354
|
+
return baseclient_1.Util.execGradient(ethnicStops(exports.EthnicFewStops, pd), pct);
|
|
355
|
+
}
|
|
356
|
+
exports.ToEthnicColorStr = ToEthnicColorStr;
|
|
357
|
+
// All Groups Mosaic
|
|
358
|
+
function AggregateEthnicColor(getter, pd, nhAlone) {
|
|
359
|
+
// Dataset should have 'Tot' field
|
|
360
|
+
let totField = 'Tot';
|
|
361
|
+
let totalPop = getter(totField);
|
|
362
|
+
if (totalPop == 0)
|
|
363
|
+
return -1;
|
|
364
|
+
// Field names hard-coded
|
|
365
|
+
let white = getter('Wh') / totalPop;
|
|
366
|
+
let hisp = getter('His') / totalPop;
|
|
367
|
+
let black = 0;
|
|
368
|
+
let native = 0;
|
|
369
|
+
let asianPI = 0;
|
|
370
|
+
if (nhAlone) {
|
|
371
|
+
black = getter('Bl') / totalPop;
|
|
372
|
+
native = getter('Nat') / totalPop;
|
|
373
|
+
asianPI = (getter('Asn') + getter('Pac')) / totalPop;
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
black = getter('BlC') / totalPop;
|
|
377
|
+
native = getter('NatC') / totalPop;
|
|
378
|
+
asianPI = (getter('AsnC') + getter('PacC')) / totalPop;
|
|
379
|
+
}
|
|
380
|
+
if (white >= 0.75)
|
|
381
|
+
return exports.ColorBySolidWhite;
|
|
382
|
+
if (black >= 0.75)
|
|
383
|
+
return exports.ColorBySolidBlack;
|
|
384
|
+
if (hisp >= 0.75)
|
|
385
|
+
return exports.ColorBySolidHispanic;
|
|
386
|
+
if (asianPI >= 0.75)
|
|
387
|
+
return exports.ColorBySolidAsian;
|
|
388
|
+
if (white >= 0.5 && black < 0.3 && hisp < 0.3 && native < 0.3 && asianPI < 0.3)
|
|
389
|
+
return exports.ColorByMostlyWhite;
|
|
390
|
+
if (black >= 0.5 && white < 0.3 && hisp < 0.3 && native < 0.3 && asianPI < 0.3)
|
|
391
|
+
return exports.ColorByMostlyBlack;
|
|
392
|
+
if (hisp >= 0.5 && white < 0.3 && black < 0.3 && native < 0.3 && asianPI < 0.3)
|
|
393
|
+
return exports.ColorByMostlyHispanic;
|
|
394
|
+
if (asianPI >= 0.5 && white < 0.3 && black < 0.3 && native < 0.3 && hisp < 0.3)
|
|
395
|
+
return exports.ColorByMostlyAsian;
|
|
396
|
+
if (native > 0.5)
|
|
397
|
+
return exports.ColorByMostlyNative;
|
|
398
|
+
if (hisp >= 0.3 && white >= 0.3 && hisp + white > 0.75)
|
|
399
|
+
return exports.ColorByHispanicWhite;
|
|
400
|
+
if (black >= 0.3 && white >= 0.3 && black + white > 0.75)
|
|
401
|
+
return exports.ColorByBlackWhite;
|
|
402
|
+
if (hisp >= 0.3 && black >= 0.3 && hisp + black > 0.75)
|
|
403
|
+
return exports.ColorByHispanicBlack;
|
|
404
|
+
if (asianPI >= 0.3 && white >= 0.3 && asianPI + white > 0.75)
|
|
405
|
+
return exports.ColorByAsianWhite;
|
|
406
|
+
if (asianPI >= 0.3 && hisp >= 0.3 && asianPI + hisp > 0.75)
|
|
407
|
+
return exports.ColorByAsianHispanic;
|
|
408
|
+
if (black >= 0.3 && asianPI >= 0.3 && black + asianPI > 0.75)
|
|
409
|
+
return exports.ColorByBlackAsian;
|
|
410
|
+
return exports.ColorByMix;
|
|
411
|
+
}
|
|
412
|
+
exports.AggregateEthnicColor = AggregateEthnicColor;
|
|
413
|
+
// This is used only for 2016_BG analytics, seemingly only for values, not colors (dave 12/9/21)
|
|
414
|
+
function AggregatePartisanColor(getter) {
|
|
415
|
+
// Dataset should have 'Tot' field
|
|
416
|
+
let totField = 'Tot';
|
|
417
|
+
let presTot = getter(totField);
|
|
418
|
+
if (presTot == 0)
|
|
419
|
+
return -1;
|
|
420
|
+
// TODO: Field names hard-coded
|
|
421
|
+
let presR = getter('R');
|
|
422
|
+
let presD = getter(' D');
|
|
423
|
+
if (presTot === undefined || presD === undefined || presR === undefined || presTot <= 0)
|
|
424
|
+
return -1;
|
|
425
|
+
let pctD = presD / presTot;
|
|
426
|
+
let pctR = presR / presTot;
|
|
427
|
+
let diff = pctD - pctR;
|
|
428
|
+
if (diff < -0.20)
|
|
429
|
+
return exports.ColorByGreatR;
|
|
430
|
+
if (diff < -0.10)
|
|
431
|
+
return exports.ColorByGoodR;
|
|
432
|
+
if (diff < -0.02)
|
|
433
|
+
return exports.ColorByFairR;
|
|
434
|
+
if (diff > 0.20)
|
|
435
|
+
return exports.ColorByGreatD;
|
|
436
|
+
if (diff > 0.10)
|
|
437
|
+
return exports.ColorByGoodD;
|
|
438
|
+
if (diff > 0.02)
|
|
439
|
+
return exports.ColorByFairD;
|
|
440
|
+
return exports.ColorByEven;
|
|
441
|
+
}
|
|
442
|
+
exports.AggregatePartisanColor = AggregatePartisanColor;
|
|
443
|
+
function AggregatePartisanColorStr(getter, stops) {
|
|
444
|
+
// Dataset should have 'Tot' field
|
|
445
|
+
let totField = 'Tot';
|
|
446
|
+
let presTot = getter(totField);
|
|
447
|
+
if (presTot == 0)
|
|
448
|
+
return '';
|
|
449
|
+
// TODO: Field names hard-coded
|
|
450
|
+
let presR = getter('R');
|
|
451
|
+
let presD = getter('D');
|
|
452
|
+
if (presTot === undefined || presD === undefined || presR === undefined || presTot <= 0)
|
|
453
|
+
return '';
|
|
454
|
+
let pctD = presD / presTot;
|
|
455
|
+
let pctR = presR / presTot;
|
|
456
|
+
let pctOth = (presTot - presD - presR) / presTot;
|
|
457
|
+
const color = ColorFromRGBPcts(pctR, pctOth, pctD, stops);
|
|
458
|
+
//console.log('Agg (r, d, color): (' + pctR + ', ' + pctD + ', ' + color + ')');
|
|
459
|
+
return color;
|
|
460
|
+
}
|
|
461
|
+
exports.AggregatePartisanColorStr = AggregatePartisanColorStr;
|
|
462
|
+
// This is the new gradient code
|
|
463
|
+
function ColorFromRGBPcts(pctRed, pctGreen, pctBlue, stops) {
|
|
464
|
+
let pctTot = pctRed + pctBlue;
|
|
465
|
+
if (pctTot == 0)
|
|
466
|
+
return '#ffffff';
|
|
467
|
+
pctBlue /= pctTot;
|
|
468
|
+
return baseclient_1.Util.execGradient(stops, pctBlue);
|
|
469
|
+
}
|
|
470
|
+
exports.ColorFromRGBPcts = ColorFromRGBPcts;
|
|
471
|
+
// Currently supported palettes
|
|
472
|
+
exports.PaletteNames = ['jet_r', 'turbo_r', 'inferno_r', 'viridis_r', 'magma_r', 'plasma_r', 'Greys', 'bone_r',
|
|
473
|
+
'draclassic', 'demographicsclassic', 'partisanclassic', 'allgroupsclassic', 'partisandistrictsclassic'];
|
|
474
|
+
function colorsFromStops(palette, stops, classicColors) {
|
|
475
|
+
// Use classicColors to see where there are duplicate colors
|
|
476
|
+
const allColors = baseclient_1.Colors.getPalette(palette);
|
|
477
|
+
let colors = [];
|
|
478
|
+
for (let i = 0; i < stops.length; i++) {
|
|
479
|
+
const stop = (i + 1 < classicColors.length && classicColors[i] == classicColors[i + 1]) ? (stops[i] + stops[i + 1]) / 2 :
|
|
480
|
+
(i > 0 && i < classicColors.length && classicColors[i - 1] == classicColors[i]) ? (stops[i - 1] + stops[i]) / 2 : stops[i];
|
|
481
|
+
let inx = Math.floor(allColors.length * stop);
|
|
482
|
+
if (inx >= allColors.length)
|
|
483
|
+
inx = allColors.length - 1;
|
|
484
|
+
colors.push(allColors[inx]);
|
|
485
|
+
}
|
|
486
|
+
return colors;
|
|
487
|
+
}
|
|
488
|
+
exports.colorsFromStops = colorsFromStops;
|
|
489
|
+
function colorsFromStopsPartisan(palette, colorUse, stops) {
|
|
490
|
+
if (palette === 'partisanclassic')
|
|
491
|
+
return baseclient_1.Colors.PartisanPrecinctClassicColors;
|
|
492
|
+
if (palette === 'partisandistrictsclassic')
|
|
493
|
+
return baseclient_1.Colors.PartisanDistrictClassicColors;
|
|
494
|
+
// For partisanScale and partisanDistrictsScale; indexes match classic color pattern
|
|
495
|
+
const allColors = baseclient_1.Colors.getPalette(palette);
|
|
496
|
+
if (allColors.length < baseclient_1.Colors.MaxColors)
|
|
497
|
+
return baseclient_1.Colors.PartisanPrecinctClassicColors; // Safety check; shouldn't happen
|
|
498
|
+
let colors = [];
|
|
499
|
+
const indexes = colorUse === 'partisanScale' ?
|
|
500
|
+
[15, 27, 37, 47, 57, 67, 82, 92, 102, 112, 122, 134] : [15, 15, 37, 37, 47, 67, 82, 102, 122, 122, 134, 134];
|
|
501
|
+
for (let i = 0; i < stops.length; i++) {
|
|
502
|
+
colors.push(allColors[indexes[i]]);
|
|
503
|
+
}
|
|
504
|
+
return colors;
|
|
505
|
+
}
|
|
506
|
+
exports.colorsFromStopsPartisan = colorsFromStopsPartisan;
|
|
507
|
+
function allGroups16Colors(palette, colors) {
|
|
508
|
+
let modColors = [];
|
|
509
|
+
//if (palette === 'allgroupsclassic') // Only support classic for now
|
|
510
|
+
{
|
|
511
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorBySolidWhite]); // pos 0
|
|
512
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorBySolidBlack]); // pos 1
|
|
513
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorBySolidHispanic]); // pos 2
|
|
514
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorBySolidAsian]); // pos 3
|
|
515
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByMostlyWhite]); // pos 4
|
|
516
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByMostlyBlack]); // pos 5
|
|
517
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByMostlyHispanic]); // pos 6
|
|
518
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByMostlyAsian]); // pos 7
|
|
519
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByMostlyNative]); // pos 8
|
|
520
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByMix]); // pos 9
|
|
521
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByHispanicWhite]); // pos 10
|
|
522
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByBlackWhite]); // pos 11
|
|
523
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByHispanicBlack]); // pos 12
|
|
524
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByAsianWhite]); // pos 13
|
|
525
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByAsianHispanic]); // pos 14
|
|
526
|
+
modColors.push(baseclient_1.Colors.EthnicBackgroundColor[exports.ColorByBlackAsian]); // pos 15
|
|
527
|
+
}
|
|
528
|
+
/*else if (palette === 'viridis_r' || palette === 'plasma_r')
|
|
529
|
+
{
|
|
530
|
+
modColors.push(colors[149]);
|
|
531
|
+
modColors.push(colors[129]);
|
|
532
|
+
modColors.push(colors[109]);
|
|
533
|
+
modColors.push(colors[89]);
|
|
534
|
+
modColors.push(colors[139]);
|
|
535
|
+
modColors.push(colors[119]);
|
|
536
|
+
modColors.push(colors[99]);
|
|
537
|
+
modColors.push(colors[79]);
|
|
538
|
+
modColors.push(colors[0]);
|
|
539
|
+
modColors.push(colors[9]);
|
|
540
|
+
modColors.push(colors[29]);
|
|
541
|
+
modColors.push(colors[19]);
|
|
542
|
+
modColors.push(colors[49]);
|
|
543
|
+
modColors.push(colors[39]);
|
|
544
|
+
modColors.push(colors[69]);
|
|
545
|
+
modColors.push(colors[59]);
|
|
546
|
+
}
|
|
547
|
+
else if (palette === 'magma_r')
|
|
548
|
+
{
|
|
549
|
+
modColors.push(colors[134]);
|
|
550
|
+
modColors.push(colors[116]);
|
|
551
|
+
modColors.push(colors[98]);
|
|
552
|
+
modColors.push(colors[80]);
|
|
553
|
+
modColors.push(colors[125]);
|
|
554
|
+
modColors.push(colors[107]);
|
|
555
|
+
modColors.push(colors[89]);
|
|
556
|
+
modColors.push(colors[71]);
|
|
557
|
+
modColors.push(colors[0]);
|
|
558
|
+
modColors.push(colors[8]);
|
|
559
|
+
modColors.push(colors[26]);
|
|
560
|
+
modColors.push(colors[17]);
|
|
561
|
+
modColors.push(colors[44]);
|
|
562
|
+
modColors.push(colors[35]);
|
|
563
|
+
modColors.push(colors[62]);
|
|
564
|
+
modColors.push(colors[53]);
|
|
565
|
+
}*/
|
|
566
|
+
return modColors;
|
|
567
|
+
}
|
|
568
|
+
exports.allGroups16Colors = allGroups16Colors;
|
|
569
|
+
function computeDistrictColors(params) {
|
|
570
|
+
let dcNew = [];
|
|
571
|
+
for (let i = 0; i < params.aggregates.length; i++) {
|
|
572
|
+
let agg = params.aggregates[i];
|
|
573
|
+
let mapColor = i < params.mapColors.length ? params.mapColors[i].color : baseclient_1.Colors.genColor(i, params.useFirstColor, params.usePalette);
|
|
574
|
+
let dc = {};
|
|
575
|
+
// Compute election color and partisan color
|
|
576
|
+
dc.colorEthnic = mapColor;
|
|
577
|
+
dc.colorElection = ToPartisanDistrictColor(agg, params.datasetContext, params.paletteDefaults);
|
|
578
|
+
switch (params.colorDistrictsBy) {
|
|
579
|
+
case 'election':
|
|
580
|
+
dc.colorSolid = dc.colorElection;
|
|
581
|
+
break;
|
|
582
|
+
case 'nonwhite':
|
|
583
|
+
case 'hisp':
|
|
584
|
+
case 'black':
|
|
585
|
+
case 'native':
|
|
586
|
+
case 'asian':
|
|
587
|
+
case 'pac':
|
|
588
|
+
case 'all':
|
|
589
|
+
dc.colorEthnic = ToEthnicColorStr(agg, params.datasetContext, params.paletteDefaults, params.colorDistrictsBy);
|
|
590
|
+
dc.colorSolid = dc.colorEthnic;
|
|
591
|
+
break;
|
|
592
|
+
default:
|
|
593
|
+
dc.colorSolid = mapColor;
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
dcNew.push(dc);
|
|
597
|
+
}
|
|
598
|
+
return dcNew;
|
|
599
|
+
}
|
|
600
|
+
exports.computeDistrictColors = computeDistrictColors;
|
|
601
|
+
|
|
602
|
+
|
|
97
603
|
/***/ }),
|
|
98
604
|
|
|
99
605
|
/***/ "./lib/csv.ts":
|
|
@@ -847,22 +1353,177 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
847
1353
|
/*!*****************************!*\
|
|
848
1354
|
!*** ./lib/packedfields.ts ***!
|
|
849
1355
|
\*****************************/
|
|
850
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
1356
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
851
1357
|
|
|
852
1358
|
|
|
853
1359
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
854
|
-
exports.aggregatePackedFields = exports.packedCopy = exports.zeroPackedCopy = exports.
|
|
1360
|
+
exports.pvi2020Str = exports.calcRaw2020Pvi = exports.pviStr = exports.calcRawPvi = exports.calcShift = exports.ToGetterPvi20 = exports.ToGetterPvi16 = exports.ToGetter = exports.findPackedField = exports.getPackedField = exports.diffPackedFields = exports.aggregatePackedFields = exports.packedCopy = exports.zeroPackedCopy = exports.zeroPackedFields = exports.retrievePackedFields = exports.setPackedFields = exports.hasPackedFields = exports.computePackedFields = exports.computeMetaIndex = exports.fGet = exports.fGetJoined = exports.fieldGetterNotLoaded = exports.DS_PRES2016 = exports.DS_PRES2020 = exports.DS_PVI2016 = exports.PVI2020_Title = exports.DS_PVI2020 = exports.DATASET_TYPE_PVI = exports.DATASET_TYPE_ELECTION = exports.DATASET_TYPE_DEMOGRAPHIC = exports.AGG_pvi = exports.AGG_pres2016 = exports.AGG_pres2008 = exports.AGG_DEMOGRAPHIC18 = exports.AGG_DEMOGRAPHIC = void 0;
|
|
1361
|
+
const baseclient_1 = __webpack_require__(/*! @dra2020/baseclient */ "@dra2020/baseclient");
|
|
1362
|
+
// **** Dataset Codes Explained ****
|
|
1363
|
+
// Elections:
|
|
1364
|
+
// EYYGCC, where YY = year and CC = contest [PR, SE, GO, AG]
|
|
1365
|
+
// C16GCO = composite (spans number of years)
|
|
1366
|
+
// PYYGPR = PVI, where YY is year [16, 20]
|
|
1367
|
+
// Census/ACS:
|
|
1368
|
+
// DYYF = Census/ACS Total Pop, where YY = year [10, 18, 19, 20]
|
|
1369
|
+
// DYYT = Census/ACS VAP/CVAP, where YY = year [10, 18, 19, 20]
|
|
1370
|
+
// D20FA = Census 2020 Total Prisoner-Adjusted Pop
|
|
1371
|
+
// D20TNH = Census 2020 VAP with Non-Hispanic Alone Race fields
|
|
1372
|
+
// **** Dataset Fields Explained ****
|
|
1373
|
+
// Elections:
|
|
1374
|
+
// D: Democratic
|
|
1375
|
+
// R: Republican
|
|
1376
|
+
// Tot (Total R + D + Other)
|
|
1377
|
+
// Census/ACS/VAP/CVAP:
|
|
1378
|
+
// Tot: total
|
|
1379
|
+
// Wh: White alone, not Hispanic
|
|
1380
|
+
// His: All Hispanics
|
|
1381
|
+
// Bl: Black alone, not Hispanic; BlC: Black combo, incl Hispanic
|
|
1382
|
+
// Asn: Asian alone, not Hispanic; AsnC: Asian combo, incl Hispanic
|
|
1383
|
+
// Nat: Native alone, not Hispanic; NatC: Native combo, incl Hispanic
|
|
1384
|
+
// Pac (also PI): Pacific alone, not Hispanic; PacC: Pacific combo, incl Hispanic
|
|
1385
|
+
// OthAl: Other alone, not Hispanic; Oth: Other + Two or more races, incl Hispanic
|
|
1386
|
+
// Mix: Two or more races, not Hispanic
|
|
1387
|
+
// AsnPI: Asian + Pacific, not Hispanic
|
|
1388
|
+
exports.AGG_DEMOGRAPHIC = 'demographic';
|
|
1389
|
+
exports.AGG_DEMOGRAPHIC18 = 'demographic18';
|
|
1390
|
+
exports.AGG_pres2008 = 'pres2008';
|
|
1391
|
+
exports.AGG_pres2016 = 'pres2016';
|
|
1392
|
+
exports.AGG_pvi = 'pvi';
|
|
1393
|
+
exports.DATASET_TYPE_DEMOGRAPHIC = 'demographic';
|
|
1394
|
+
exports.DATASET_TYPE_ELECTION = 'election';
|
|
1395
|
+
exports.DATASET_TYPE_PVI = 'pvi';
|
|
1396
|
+
exports.DS_PVI2020 = 'P20GPR';
|
|
1397
|
+
exports.PVI2020_Title = 'PVI 2016/2020';
|
|
1398
|
+
exports.DS_PVI2016 = 'P16GPR';
|
|
1399
|
+
exports.DS_PRES2020 = 'E20GPR';
|
|
1400
|
+
exports.DS_PRES2016 = 'E16GPR';
|
|
1401
|
+
function fieldGetterNotLoaded(f) { return undefined; }
|
|
1402
|
+
exports.fieldGetterNotLoaded = fieldGetterNotLoaded;
|
|
1403
|
+
function fGetJoined(f) {
|
|
1404
|
+
return (f.properties && f.properties.joined) ? f.properties.joined : undefined;
|
|
1405
|
+
}
|
|
1406
|
+
exports.fGetJoined = fGetJoined;
|
|
1407
|
+
function fGet(f, p) {
|
|
1408
|
+
return fGetW(f, null, p);
|
|
1409
|
+
}
|
|
1410
|
+
exports.fGet = fGet;
|
|
1411
|
+
// Note f is a direct GeoJSON feature
|
|
1412
|
+
// Called when building packedFields; after that f.properties.datasets is deleted, so then it's only useful for non-dataset properties.
|
|
1413
|
+
function fGetW(f, datasetKey, p) {
|
|
1414
|
+
// pBackup helps support 2016_BG, which don't have the 'C' fields
|
|
1415
|
+
const pBackup = (p === 'BlC') ? 'Bl' : (p === 'AsnC' || p === 'PacC') ? 'AsnPI' : (p === 'NatC') ? 'Nat' : null;
|
|
1416
|
+
// Direct property?
|
|
1417
|
+
if (f.properties && f.properties[p] !== undefined)
|
|
1418
|
+
return f.properties[p];
|
|
1419
|
+
else if (datasetKey && f.properties && f.properties.datasets && f.properties.datasets[datasetKey]) {
|
|
1420
|
+
if (f.properties.datasets[datasetKey][p] != null)
|
|
1421
|
+
return f.properties.datasets[datasetKey][p];
|
|
1422
|
+
else if (pBackup && f.properties.datasets[datasetKey][pBackup] != null)
|
|
1423
|
+
return f.properties.datasets[datasetKey][pBackup];
|
|
1424
|
+
}
|
|
1425
|
+
// Joined property?
|
|
1426
|
+
let a = fGetJoined(f);
|
|
1427
|
+
if (a) {
|
|
1428
|
+
for (let i = 0; i < a.length; i++) {
|
|
1429
|
+
let o = a[i];
|
|
1430
|
+
if (!datasetKey) {
|
|
1431
|
+
if (o[p] !== undefined)
|
|
1432
|
+
return o[p];
|
|
1433
|
+
}
|
|
1434
|
+
else {
|
|
1435
|
+
if (o['datasets'] && o['datasets'][datasetKey] != null) {
|
|
1436
|
+
if (o['datasets'][datasetKey][p] != null)
|
|
1437
|
+
return o['datasets'][datasetKey][p];
|
|
1438
|
+
else if (pBackup && o['datasets'][datasetKey][pBackup] != null)
|
|
1439
|
+
return o['datasets'][datasetKey][pBackup];
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
return undefined;
|
|
1445
|
+
}
|
|
1446
|
+
function computeMetaIndex(meta) {
|
|
1447
|
+
if (meta == null)
|
|
1448
|
+
return null;
|
|
1449
|
+
let offset = 1; // first entry is count of aggregates
|
|
1450
|
+
let index = { length: 0, fields: {}, getDatasetField: null };
|
|
1451
|
+
Object.keys(meta).forEach((datasetKey) => {
|
|
1452
|
+
let dataset = meta[datasetKey];
|
|
1453
|
+
let fieldsIndex = {};
|
|
1454
|
+
Object.keys(dataset.fields).forEach((field) => {
|
|
1455
|
+
fieldsIndex[field] = offset++;
|
|
1456
|
+
});
|
|
1457
|
+
index.fields[datasetKey] = fieldsIndex;
|
|
1458
|
+
});
|
|
1459
|
+
index.length = offset;
|
|
1460
|
+
index.getDatasetField = (f, dataset, field) => {
|
|
1461
|
+
let pf = retrievePackedFields(f);
|
|
1462
|
+
return getPackedField(index, pf, dataset, field);
|
|
1463
|
+
};
|
|
1464
|
+
return index;
|
|
1465
|
+
}
|
|
1466
|
+
exports.computeMetaIndex = computeMetaIndex;
|
|
1467
|
+
let nAlloc = 0;
|
|
855
1468
|
function allocPackedFields(length) {
|
|
856
1469
|
let ab = new ArrayBuffer(8 * length);
|
|
857
1470
|
let af = new Float64Array(ab);
|
|
1471
|
+
nAlloc++;
|
|
1472
|
+
//if ((nAlloc % 10000) == 0) console.log(`allocPackedFields: ${nAlloc} allocs`);
|
|
858
1473
|
return af;
|
|
859
1474
|
}
|
|
860
|
-
|
|
1475
|
+
function computePackedFields(f, index) {
|
|
1476
|
+
if (f.properties.packedFields)
|
|
1477
|
+
return f.properties.packedFields;
|
|
1478
|
+
let af = allocPackedFields(index.length);
|
|
1479
|
+
af[0] = 0; // count of number of aggregates
|
|
1480
|
+
Object.keys(index.fields).forEach((dataset) => {
|
|
1481
|
+
let fields = index.fields[dataset];
|
|
1482
|
+
Object.keys(fields).forEach((field) => {
|
|
1483
|
+
let n = fGetW(f, dataset, field);
|
|
1484
|
+
if (isNaN(n))
|
|
1485
|
+
n = 0;
|
|
1486
|
+
af[fields[field]] = n;
|
|
1487
|
+
});
|
|
1488
|
+
});
|
|
1489
|
+
f.properties.packedFields = af; // cache here
|
|
1490
|
+
f.properties.getDatasetField = index.getDatasetField;
|
|
1491
|
+
// Major memory savings to delete this after packing
|
|
1492
|
+
delete f.properties.datasets;
|
|
1493
|
+
return af;
|
|
1494
|
+
}
|
|
1495
|
+
exports.computePackedFields = computePackedFields;
|
|
1496
|
+
function hasPackedFields(f) {
|
|
1497
|
+
return f.properties.packedFields !== undefined;
|
|
1498
|
+
}
|
|
1499
|
+
exports.hasPackedFields = hasPackedFields;
|
|
1500
|
+
function setPackedFields(f, pf, fIndex) {
|
|
1501
|
+
if (f.properties.packedFields !== undefined)
|
|
1502
|
+
throw 'Packed fields already set';
|
|
1503
|
+
f.properties.packedFields = pf;
|
|
1504
|
+
f.properties.getDatasetField = fIndex.properties.getDatasetField;
|
|
1505
|
+
}
|
|
1506
|
+
exports.setPackedFields = setPackedFields;
|
|
1507
|
+
function retrievePackedFields(f) {
|
|
1508
|
+
if (f.properties.packedFields === undefined)
|
|
1509
|
+
throw 'Feature should have pre-computed packed fields';
|
|
1510
|
+
return f.properties.packedFields;
|
|
1511
|
+
}
|
|
1512
|
+
exports.retrievePackedFields = retrievePackedFields;
|
|
861
1513
|
// The first entry in the PackedFields aggregate is the count of items aggregated.
|
|
862
1514
|
// Treat a null instance as just a single entry with no aggregates.
|
|
863
1515
|
let abZero = new ArrayBuffer(8);
|
|
864
1516
|
let afZero = new Float64Array(abZero);
|
|
865
1517
|
afZero[0] = 0;
|
|
1518
|
+
function zeroPackedFields(index) {
|
|
1519
|
+
if (index == null)
|
|
1520
|
+
return afZero;
|
|
1521
|
+
let af = allocPackedFields(index.length);
|
|
1522
|
+
for (let i = 0; i < af.length; i++)
|
|
1523
|
+
af[i] = 0;
|
|
1524
|
+
return af;
|
|
1525
|
+
}
|
|
1526
|
+
exports.zeroPackedFields = zeroPackedFields;
|
|
866
1527
|
function zeroPackedCopy(pf) {
|
|
867
1528
|
if (pf == null)
|
|
868
1529
|
return afZero;
|
|
@@ -895,6 +1556,120 @@ function aggregatePackedFields(agg, pf) {
|
|
|
895
1556
|
return agg;
|
|
896
1557
|
}
|
|
897
1558
|
exports.aggregatePackedFields = aggregatePackedFields;
|
|
1559
|
+
function diffPackedFields(main, parts) {
|
|
1560
|
+
main = packedCopy(retrievePackedFields(main));
|
|
1561
|
+
if (main == null || parts == null || parts.length == 0)
|
|
1562
|
+
return null;
|
|
1563
|
+
parts = parts.map(retrievePackedFields);
|
|
1564
|
+
parts.forEach((pf) => {
|
|
1565
|
+
for (let i = 0; i < main.length; i++)
|
|
1566
|
+
main[i] -= pf[i];
|
|
1567
|
+
});
|
|
1568
|
+
return main;
|
|
1569
|
+
}
|
|
1570
|
+
exports.diffPackedFields = diffPackedFields;
|
|
1571
|
+
function getPackedField(index, pf, dataset, field) {
|
|
1572
|
+
if (index == null || pf == null)
|
|
1573
|
+
return 0;
|
|
1574
|
+
let fields = index.fields[dataset];
|
|
1575
|
+
return fields ? (fields[field] !== undefined ? pf[fields[field]] : 0) : 0;
|
|
1576
|
+
}
|
|
1577
|
+
exports.getPackedField = getPackedField;
|
|
1578
|
+
function findPackedField(index, pf, dataset, field) {
|
|
1579
|
+
let fields = index.fields[dataset];
|
|
1580
|
+
return fields ? (fields[field] !== undefined ? fields[field] : -1) : -1;
|
|
1581
|
+
}
|
|
1582
|
+
exports.findPackedField = findPackedField;
|
|
1583
|
+
function ToGetter(agg, dc, datasetKey) {
|
|
1584
|
+
return (field) => { return getPackedField(dc.dsIndex, agg, datasetKey, field); };
|
|
1585
|
+
}
|
|
1586
|
+
exports.ToGetter = ToGetter;
|
|
1587
|
+
function ToGetterPvi16(agg, dc, datasetKey) {
|
|
1588
|
+
return (field) => {
|
|
1589
|
+
if (field === 'R')
|
|
1590
|
+
return Math.round((getPackedField(dc.dsIndex, agg, datasetKey, 'R12') + getPackedField(dc.dsIndex, agg, datasetKey, 'R16')) / 2);
|
|
1591
|
+
if (field === 'D')
|
|
1592
|
+
return Math.round((getPackedField(dc.dsIndex, agg, datasetKey, 'D12') + getPackedField(dc.dsIndex, agg, datasetKey, 'D16')) / 2);
|
|
1593
|
+
if (field === 'Tot')
|
|
1594
|
+
return Math.round((getPackedField(dc.dsIndex, agg, datasetKey, 'R12') + getPackedField(dc.dsIndex, agg, datasetKey, 'R16') +
|
|
1595
|
+
getPackedField(dc.dsIndex, agg, datasetKey, 'D12') + getPackedField(dc.dsIndex, agg, datasetKey, 'D16')) / 2);
|
|
1596
|
+
return 0;
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
exports.ToGetterPvi16 = ToGetterPvi16;
|
|
1600
|
+
function ToGetterPvi20(agg, dc) {
|
|
1601
|
+
return (field) => {
|
|
1602
|
+
if (field === 'R')
|
|
1603
|
+
return Math.round((getPackedField(dc.dsIndex, agg, exports.DS_PRES2016, 'R') + getPackedField(dc.dsIndex, agg, exports.DS_PRES2020, 'R')) / 2);
|
|
1604
|
+
if (field === 'D')
|
|
1605
|
+
return Math.round((getPackedField(dc.dsIndex, agg, exports.DS_PRES2016, 'D') + getPackedField(dc.dsIndex, agg, exports.DS_PRES2020, 'D')) / 2);
|
|
1606
|
+
if (field === 'Tot')
|
|
1607
|
+
return Math.round((getPackedField(dc.dsIndex, agg, exports.DS_PRES2016, 'R') + getPackedField(dc.dsIndex, agg, exports.DS_PRES2020, 'R') +
|
|
1608
|
+
getPackedField(dc.dsIndex, agg, exports.DS_PRES2016, 'D') + getPackedField(dc.dsIndex, agg, exports.DS_PRES2020, 'D')) / 2);
|
|
1609
|
+
return 0;
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
exports.ToGetterPvi20 = ToGetterPvi20;
|
|
1613
|
+
function calcShift(agg, dc, datasetOld, datasetNew) {
|
|
1614
|
+
const getterOld = datasetOld === exports.DS_PVI2016 ?
|
|
1615
|
+
ToGetterPvi16(agg, dc, datasetOld) :
|
|
1616
|
+
datasetOld === exports.DS_PVI2020 ?
|
|
1617
|
+
ToGetterPvi20(agg, dc) :
|
|
1618
|
+
ToGetter(agg, dc, datasetOld);
|
|
1619
|
+
const getterNew = datasetNew === exports.DS_PVI2016 ?
|
|
1620
|
+
ToGetterPvi16(agg, dc, datasetNew) :
|
|
1621
|
+
datasetNew === exports.DS_PVI2020 ?
|
|
1622
|
+
ToGetterPvi20(agg, dc) :
|
|
1623
|
+
ToGetter(agg, dc, datasetNew);
|
|
1624
|
+
// Calc two-party Swing
|
|
1625
|
+
const repOld = getterOld('R');
|
|
1626
|
+
const demOld = getterOld('D');
|
|
1627
|
+
const repNew = getterNew('R');
|
|
1628
|
+
const demNew = getterNew('D');
|
|
1629
|
+
if (repOld === undefined || demOld === undefined || repNew === undefined || demNew === undefined)
|
|
1630
|
+
return null;
|
|
1631
|
+
const totOld = demOld + repOld;
|
|
1632
|
+
const totNew = demNew + repNew;
|
|
1633
|
+
if (totOld <= 0 || totNew <= 0)
|
|
1634
|
+
return null;
|
|
1635
|
+
const pctDemOld = demOld / totOld;
|
|
1636
|
+
const pctRepOld = repOld / totOld;
|
|
1637
|
+
const pctDemNew = demNew / totNew;
|
|
1638
|
+
const pctRepNew = repNew / totNew;
|
|
1639
|
+
const shift = Math.max(Math.min((pctDemNew - pctDemOld) - (pctRepNew - pctRepOld), 1.0), -1.0);
|
|
1640
|
+
return shift;
|
|
1641
|
+
}
|
|
1642
|
+
exports.calcShift = calcShift;
|
|
1643
|
+
function calcRawPvi(getter) {
|
|
1644
|
+
// ((((sum(d_2016) / (sum(d_2016) + sum(r_2016))) * 100) + ((sum(d_2012) / (sum(d_2012) + sum(r_2012))) * 100)) / 2) - 51.54
|
|
1645
|
+
// Fields hard coded
|
|
1646
|
+
let total2012 = getter('D12') + getter('R12');
|
|
1647
|
+
let total2016 = getter('D16') + getter('R16');
|
|
1648
|
+
let pct2012 = total2012 != 0 ? (getter('D12') / total2012) * 100 : 0;
|
|
1649
|
+
let pct2016 = total2016 != 0 ? (getter('D16') / total2016) * 100 : 0;
|
|
1650
|
+
return (pct2012 + pct2016) / ((total2012 != 0 && total2016 != 0) ? 2 : 1);
|
|
1651
|
+
}
|
|
1652
|
+
exports.calcRawPvi = calcRawPvi;
|
|
1653
|
+
function pviStr(getter) {
|
|
1654
|
+
const pviRaw = calcRawPvi(getter);
|
|
1655
|
+
const pvi = baseclient_1.Util.precisionRound(pviRaw != 0 ? pviRaw - 51.54 : 0, 2);
|
|
1656
|
+
return pvi >= 0 ? 'D+' + pvi : 'R+' + (-pvi);
|
|
1657
|
+
}
|
|
1658
|
+
exports.pviStr = pviStr;
|
|
1659
|
+
function calcRaw2020Pvi(getter16, getter20) {
|
|
1660
|
+
let total2016 = getter16('D') + getter16('R');
|
|
1661
|
+
let total2020 = getter20('D') + getter20('R');
|
|
1662
|
+
let pct2016 = total2016 != 0 ? (getter16('D') / total2016) * 100 : 0;
|
|
1663
|
+
let pct2020 = total2020 != 0 ? (getter20('D') / total2020) * 100 : 0;
|
|
1664
|
+
return (pct2020 + pct2016) / ((total2020 != 0 && total2016 != 0) ? 2 : 1);
|
|
1665
|
+
}
|
|
1666
|
+
exports.calcRaw2020Pvi = calcRaw2020Pvi;
|
|
1667
|
+
function pvi2020Str(getter16, getter20) {
|
|
1668
|
+
const pviRaw = calcRaw2020Pvi(getter16, getter20);
|
|
1669
|
+
const pvi = baseclient_1.Util.precisionRound(pviRaw != 0 ? pviRaw - 51.54 : 0, 2);
|
|
1670
|
+
return pvi >= 0 ? 'D+' + pvi : 'R+' + (-pvi);
|
|
1671
|
+
}
|
|
1672
|
+
exports.pvi2020Str = pvi2020Str;
|
|
898
1673
|
|
|
899
1674
|
|
|
900
1675
|
/***/ }),
|
|
@@ -1791,12 +2566,25 @@ module.exports = require("object-hash");
|
|
|
1791
2566
|
/******/ }
|
|
1792
2567
|
/******/
|
|
1793
2568
|
/************************************************************************/
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
2569
|
+
var __webpack_exports__ = {};
|
|
2570
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
2571
|
+
(() => {
|
|
2572
|
+
var exports = __webpack_exports__;
|
|
2573
|
+
/*!********************!*\
|
|
2574
|
+
!*** ./lib/all.ts ***!
|
|
2575
|
+
\********************/
|
|
2576
|
+
|
|
2577
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2578
|
+
exports.CM = exports.PF = exports.DT = void 0;
|
|
2579
|
+
const DT = __webpack_require__(/*! ./alldt */ "./lib/alldt.ts");
|
|
2580
|
+
exports.DT = DT;
|
|
2581
|
+
const PF = __webpack_require__(/*! ./packedfields */ "./lib/packedfields.ts");
|
|
2582
|
+
exports.PF = PF;
|
|
2583
|
+
const CM = __webpack_require__(/*! ./colormgr */ "./lib/colormgr.ts");
|
|
2584
|
+
exports.CM = CM;
|
|
2585
|
+
|
|
2586
|
+
})();
|
|
2587
|
+
|
|
1800
2588
|
/******/ return __webpack_exports__;
|
|
1801
2589
|
/******/ })()
|
|
1802
2590
|
;
|