Skip to content

Commit 60cf7c3

Browse files
committed
feat: resolve states to their counties
closes #721
1 parent 01743d3 commit 60cf7c3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/modes/exportdata/ExportData.svelte

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { onMount } from 'svelte';
99
import { trackEvent } from '../../stores/ga';
1010
import Search from '../../components/Search.svelte';
11-
import { infosByLevel } from '../../maps';
11+
import { getCountiesOfState, infosByLevel } from '../../maps';
1212
import { formatDateISO } from '../../formats';
1313
import { questionCategories, refSensor } from '../../modes/survey/questions';
1414
import { CASES_DEATH_SOURCE, getDataSource } from '../../stores/dataSourceLookup';
@@ -59,15 +59,23 @@
5959
6060
let geoValuesMode = 'all';
6161
let geoValues = [];
62-
$: geoItems = infosByLevel[geoType] || [];
62+
$: geoItems = [...infosByLevel[geoType] || [], ...(geoType === 'county' ? infosByLevel.state : [])];
6363
$: {
6464
if (geoItems != null) {
6565
geoValues = [];
6666
geoValuesMode = guessMode(geoItems.length);
6767
}
6868
}
69+
function flatIds(geoValues) {
70+
if (geoType === 'county') {
71+
// flatten states to its counties
72+
return geoValues.map((d) => d.level === 'state' ? getCountiesOfState(d).map((d) => d.propertyId) : d.propertyId).flat();
73+
} else {
74+
return geoValues.map((d) => d.propertyId);
75+
}
76+
}
6977
$: isAllRegions = geoValuesMode === 'all' || geoValues.length === 0;
70-
$: geoIDs = geoValues.map((d) => d.propertyId);
78+
$: geoIDs = flatIds(geoValues);
7179
7280
let asOfMode = 'latest';
7381
let asOfDate = new Date();

0 commit comments

Comments
 (0)