Skip to content

Commit bb1ce09

Browse files
rzatsmelange396
andauthored
Mark COVIDcast value as active by default (#90)
* Mark COVIDcast value as active by default * Fix type * Revert previous changes, add default_enabled * Lint fix * Set `defaultEnabled` explicitly instead of passing thru call chain (#93) * DataGroup: use .defaultEnabled as mutable member instead of constructor-only arg * typo --------- Co-authored-by: george <george.haff@gmail.com>
1 parent 485d4dc commit bb1ce09

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/App.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Chart from './components/Chart.svelte';
33
import LeftMenu from './components/LeftMenu.svelte';
44
import TopMenu from './components/TopMenu.svelte';
5-
import { activeDatasets, initialViewport, isShowingPoints, navMode } from './store';
5+
import { initialViewport, isShowingPoints, navMode } from './store';
66
import type { IChart } from './store';
77
import { onMount } from 'svelte';
88
import { tour } from './tour';
@@ -31,8 +31,6 @@
3131
if (ds) {
3232
// add the dataset itself
3333
addDataSet(ds);
34-
// reset active datasets to fluview -> wili
35-
$activeDatasets = [ds.datasets[0]];
3634
if (chart) {
3735
chart.fitData(true);
3836
}

src/api/EpiData.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,14 @@ export function importCOVIDcast({
273273
{ data_source, signal, time_type, geo_type, geo_value },
274274
['value', 'stderr', 'sample_size'],
275275
api_key,
276-
);
276+
).then((ds) => {
277+
// get inside the Promise and make sure its not null,
278+
// then enable display of 'value' data
279+
if (ds instanceof DataGroup) {
280+
ds.defaultEnabled = ['value'];
281+
}
282+
return ds;
283+
});
277284
}
278285

279286
export function importCOVIDHosp({
@@ -414,7 +421,14 @@ export function importFluView({
414421
wili: '%wILI',
415422
ili: '%ILI',
416423
},
417-
);
424+
).then((ds) => {
425+
// get inside the Promise and make sure its not null,
426+
// then enable display of 'percent weighted ILI' data
427+
if (ds instanceof DataGroup) {
428+
ds.defaultEnabled = ['%wILI'];
429+
}
430+
return ds;
431+
});
418432
}
419433

420434
export function importGFT({ locations }: { locations: string }): Promise<DataGroup | null> {

src/data/DataSet.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ export default class DataSet {
102102

103103
export class DataGroup {
104104
public parent?: DataGroup;
105+
// which fields of this DataGroup should be "enabled" (shown/displayed) on load:
106+
public defaultEnabled: string[] = [];
105107

106108
constructor(public readonly title: string, public readonly datasets: (DataSet | DataGroup)[]) {}
107109

src/store.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export function addDataSet(dataset: DataSet | DataGroup): void {
6666
if (dataset instanceof DataGroup) {
6767
// auto expand
6868
expandedDataGroups.set([...get(expandedDataGroups), dataset]);
69+
// add defaultEnabled datasets to the list of active datasets
70+
for (const ds of dataset.datasets) {
71+
if (ds instanceof DataSet && dataset.defaultEnabled.includes(ds.title)) {
72+
activeDatasets.set([...get(activeDatasets), ds]);
73+
}
74+
}
6975
} else {
7076
activeDatasets.set([...get(activeDatasets), dataset]);
7177
}

0 commit comments

Comments
 (0)