Skip to content

Commit 45d4389

Browse files
authored
Merge pull request #102 from cmu-delphi/release/v2.1.7
Release v2.1.7
2 parents 4b7a05a + de56405 commit 45d4389

File tree

7 files changed

+76
-44
lines changed

7 files changed

+76
-44
lines changed

package-lock.json

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "www-epivis",
3-
"version": "2.1.6",
3+
"version": "2.1.7",
44
"private": true,
55
"license": "MIT",
66
"description": "",
@@ -52,7 +52,7 @@
5252
"lint-staged": "^13.0.3",
5353
"prettier": "^2.7.1",
5454
"prettier-plugin-svelte": "^2.7.0",
55-
"rollup": "^2.78.1",
55+
"rollup": "^2.79.2",
5656
"rollup-plugin-css-only": "^3.1.0",
5757
"rollup-plugin-livereload": "^2.0.5",
5858
"rollup-plugin-scss": "^3.0.0",

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default class DataSet {
2828
public readonly data: readonly EpiPoint[],
2929
public title = '',
3030
public readonly params: Record<string, unknown> | unknown[] | null = null,
31+
public customTitle: string | null = null,
3132
public color = getRandomColor(),
3233
) {
3334
this.gap = computeGap(data);
@@ -102,6 +103,8 @@ export default class DataSet {
102103

103104
export class DataGroup {
104105
public parent?: DataGroup;
106+
// which fields of this DataGroup should be "enabled" (shown/displayed) on load:
107+
public defaultEnabled: string[] = [];
105108

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

src/deriveLinkDefaults.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function endpointParams(endpoint: string, params: unknown[]): Record<string, unk
9393
return r;
9494
}
9595

96-
function patchDataSet(title: string, color: string) {
96+
function patchDataSet(title: string, color: string, customTitle: string) {
9797
return (dg: DataGroup | null) => {
9898
if (!dg) {
9999
return null;
@@ -102,6 +102,7 @@ function patchDataSet(title: string, color: string) {
102102
const d = datasets.find((di) => di.title === title);
103103
if (d) {
104104
d.color = color;
105+
d.customTitle = customTitle;
105106
}
106107
return d;
107108
};
@@ -120,12 +121,34 @@ export function initialLoader(datasets: ILinkConfig['datasets']) {
120121
}
121122
const key = `${endpoint}:${JSON.stringify(params)}`;
122123
const existing = loadingDataSets.get(key);
124+
125+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
126+
let customTitle = title;
127+
if (params.custom_title) {
128+
// Custom title present (e.g. from signal documentation) - apply directly
129+
customTitle = `${params.custom_title}`;
130+
} else if (params._endpoint) {
131+
// Derive custom title from params
132+
customTitle = `${params._endpoint}`;
133+
if (params.data_source && params.signal) {
134+
customTitle += ` > ${params.data_source}:${params.signal}`;
135+
}
136+
if (params.geo_type && params.geo_value) {
137+
customTitle += ` > ${params.geo_type}:${params.geo_value}`;
138+
}
139+
if (params.regions) {
140+
customTitle += ` > ${params.regions}`;
141+
}
142+
customTitle += ` > ${title}`;
143+
}
144+
/* eslint-enable @typescript-eslint/restrict-template-expressions */
145+
123146
if (existing) {
124-
resolvedDataSets.push(existing.then(patchDataSet(title, color)));
147+
resolvedDataSets.push(existing.then(patchDataSet(title, color, customTitle)));
125148
} else {
126149
const loadingDataSet = func(params);
127150
loadingDataSets.set(key, loadingDataSet);
128-
resolvedDataSets.push(loadingDataSet.then(patchDataSet(title, color)));
151+
resolvedDataSets.push(loadingDataSet.then(patchDataSet(title, color, customTitle)));
129152
}
130153
}
131154

@@ -156,21 +179,8 @@ export function initialLoader(datasets: ILinkConfig['datasets']) {
156179
return Promise.all(resolvedDataSets).then((data) => {
157180
const cleaned = data.filter((d): d is DataSet => d != null);
158181
cleaned.forEach((d) => {
159-
if (d.params && !Array.isArray(d.params) && d.params._endpoint) {
160-
/* eslint-disable @typescript-eslint/restrict-template-expressions */
161-
const col_name = d.title;
162-
d.title = `${d.params._endpoint}`;
163-
if (d.params.data_source && d.params.signal) {
164-
d.title += ` > ${d.params.data_source}:${d.params.signal}`;
165-
}
166-
if (d.params.geo_type && d.params.geo_value) {
167-
d.title += ` > ${d.params.geo_type}:${d.params.geo_value}`;
168-
}
169-
if (d.params.regions) {
170-
d.title += ` > ${d.params.regions}`;
171-
}
172-
d.title += ` > ${col_name}`;
173-
/* eslint-enable @typescript-eslint/restrict-template-expressions */
182+
if (d.customTitle) {
183+
d.title = d.customTitle;
174184
}
175185
add(d);
176186
});

src/store.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ formSelections.subscribe((val) => {
3535
sessionStorage.setItem('form', JSON.stringify(val));
3636
});
3737

38+
export const apiKey = writable(localStorage.getItem('api-key')! || '');
39+
apiKey.subscribe((val) => {
40+
// always keep key in session storage (resets on window close)
41+
sessionStorage.setItem('api-key', val);
42+
if (localStorage.getItem('store-api-key') === 'true') {
43+
// if flag set, also store key in local persistent storage
44+
localStorage.setItem('api-key', val);
45+
}
46+
});
47+
3848
export const storeApiKeys = writable(localStorage.getItem('store-api-key') === 'true');
3949
storeApiKeys.subscribe((val) => {
4050
localStorage.setItem('store-api-key', val.toString());
@@ -47,16 +57,6 @@ storeApiKeys.subscribe((val) => {
4757
}
4858
});
4959

50-
export const apiKey = writable(localStorage.getItem('api-key')! || '');
51-
apiKey.subscribe((val) => {
52-
// always keep key around in session storage (resets on page refresh)
53-
sessionStorage.setItem('api-key', val);
54-
if (localStorage.getItem('store-api-key') === 'true') {
55-
// store it in local storage (persistent)
56-
localStorage.setItem('api-key', val);
57-
}
58-
});
59-
6060
export function addDataSet(dataset: DataSet | DataGroup): void {
6161
const root = get(datasetTree);
6262
root.datasets.push(dataset);
@@ -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)