@dra2020/dra-types 1.8.115 → 1.8.116
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 -1
- package/dist/datasets.d.ts +0 -1
- package/dist/dra-types.js +12 -3
- package/dist/dra-types.js.map +1 -1
- package/lib/colormgr.ts +17 -3
- package/lib/datasets.ts +0 -1
- package/package.json +1 -1
package/lib/colormgr.ts
CHANGED
|
@@ -215,7 +215,7 @@ function ToPartisanColor(agg: PF.PackedFields, dc: PF.DatasetContext, stops: Uti
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
export function ToPartisanShiftColor(agg: PF.PackedFields, dc: PF.DatasetContext, datasets: string[], pd: PaletteDefaults): string
|
|
218
|
+
export function ToPartisanShiftColor(agg: PF.PackedFields, dc: PF.DatasetContext, datasets: string[], pd: PaletteDefaults, isDistrict?: boolean): string
|
|
219
219
|
{
|
|
220
220
|
if (!datasets || datasets.length < 2)
|
|
221
221
|
return '';
|
|
@@ -223,11 +223,14 @@ export function ToPartisanShiftColor(agg: PF.PackedFields, dc: PF.DatasetContext
|
|
|
223
223
|
const shift: number = PF.calcShift(agg, dc, datasets[0], datasets[1]);
|
|
224
224
|
if (shift == null)
|
|
225
225
|
return null;
|
|
226
|
+
|
|
227
|
+
const defaultIsDistrict = isDistrict ?? false; // make the optional isDistrict parameter to false by default
|
|
228
|
+
|
|
226
229
|
const rep: number = 0.5 - (shift / 2);
|
|
227
230
|
const dem: number = 0.5 + (shift / 2);
|
|
228
|
-
const stops: Util.GradientStops = partisanStops(PartisanPrecinctStops, pd);
|
|
231
|
+
const stops: Util.GradientStops = partisanStops(defaultIsDistrict ? PartisanDistrictStops : PartisanPrecinctStops, pd);
|
|
229
232
|
const color: string = ColorFromRGBPcts(rep, 0, dem, stops);
|
|
230
|
-
//console.log('Shift (r, d, color): (' + rep + ', ' + dem + ', ' + color + ')');
|
|
233
|
+
// console.log('Shift (r, d, color): (' + rep + ', ' + dem + ', ' + color + ')');
|
|
231
234
|
return color;
|
|
232
235
|
}
|
|
233
236
|
|
|
@@ -529,6 +532,7 @@ export interface DistrictColorParams
|
|
|
529
532
|
useFirstColor: boolean,
|
|
530
533
|
usePalette: string,
|
|
531
534
|
colorDistrictsBy: string,
|
|
535
|
+
shiftDatasets?: string[],
|
|
532
536
|
}
|
|
533
537
|
|
|
534
538
|
function safeNumber(n: any): number { n = Number(n); return typeof n !== 'number' || isNaN(n) ? 0 : n }
|
|
@@ -618,6 +622,16 @@ export function computeDistrictColors(params: DistrictColorParams): DistrictCach
|
|
|
618
622
|
dc.colorEthnic = ToEthnicColorStr(agg, params.datasetContext, params.paletteDefaults, params.colorDistrictsBy);
|
|
619
623
|
dc.colorSolid = dc.colorEthnic;
|
|
620
624
|
break;
|
|
625
|
+
case 'elecshift':
|
|
626
|
+
if (params.shiftDatasets && params.shiftDatasets.length == 2)
|
|
627
|
+
{
|
|
628
|
+
dc.colorSolid = ToPartisanShiftColor(agg, params.datasetContext, params.shiftDatasets, params.paletteDefaults, true);
|
|
629
|
+
}
|
|
630
|
+
else
|
|
631
|
+
{
|
|
632
|
+
dc.colorSolid = mapColor;
|
|
633
|
+
}
|
|
634
|
+
break;
|
|
621
635
|
default:
|
|
622
636
|
if (isColorBy(params.colorDistrictsBy))
|
|
623
637
|
{
|
package/lib/datasets.ts
CHANGED