Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "www-epivis",
"version": "2.1.6",
"version": "2.1.7",
"private": true,
"license": "MIT",
"description": "",
Expand Down Expand Up @@ -52,7 +52,7 @@
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"prettier-plugin-svelte": "^2.7.0",
"rollup": "^2.78.1",
"rollup": "^2.79.2",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-scss": "^3.0.0",
Expand Down
4 changes: 1 addition & 3 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Chart from './components/Chart.svelte';
import LeftMenu from './components/LeftMenu.svelte';
import TopMenu from './components/TopMenu.svelte';
import { activeDatasets, initialViewport, isShowingPoints, navMode } from './store';
import { initialViewport, isShowingPoints, navMode } from './store';
import type { IChart } from './store';
import { onMount } from 'svelte';
import { tour } from './tour';
Expand Down Expand Up @@ -31,8 +31,6 @@
if (ds) {
// add the dataset itself
addDataSet(ds);
// reset active datasets to fluview -> wili
$activeDatasets = [ds.datasets[0]];
if (chart) {
chart.fitData(true);
}
Expand Down
18 changes: 16 additions & 2 deletions src/api/EpiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,14 @@ export function importCOVIDcast({
{ data_source, signal, time_type, geo_type, geo_value },
['value', 'stderr', 'sample_size'],
api_key,
);
).then((ds) => {
// get inside the Promise and make sure its not null,
// then enable display of 'value' data
if (ds instanceof DataGroup) {
ds.defaultEnabled = ['value'];
}
return ds;
});
}

export function importCOVIDHosp({
Expand Down Expand Up @@ -414,7 +421,14 @@ export function importFluView({
wili: '%wILI',
ili: '%ILI',
},
);
).then((ds) => {
// get inside the Promise and make sure its not null,
// then enable display of 'percent weighted ILI' data
if (ds instanceof DataGroup) {
ds.defaultEnabled = ['%wILI'];
}
return ds;
});
}

export function importGFT({ locations }: { locations: string }): Promise<DataGroup | null> {
Expand Down
3 changes: 3 additions & 0 deletions src/data/DataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class DataSet {
public readonly data: readonly EpiPoint[],
public title = '',
public readonly params: Record<string, unknown> | unknown[] | null = null,
public customTitle: string | null = null,
public color = getRandomColor(),
) {
this.gap = computeGap(data);
Expand Down Expand Up @@ -102,6 +103,8 @@ export default class DataSet {

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

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

Expand Down
46 changes: 28 additions & 18 deletions src/deriveLinkDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function endpointParams(endpoint: string, params: unknown[]): Record<string, unk
return r;
}

function patchDataSet(title: string, color: string) {
function patchDataSet(title: string, color: string, customTitle: string) {
return (dg: DataGroup | null) => {
if (!dg) {
return null;
Expand All @@ -102,6 +102,7 @@ function patchDataSet(title: string, color: string) {
const d = datasets.find((di) => di.title === title);
if (d) {
d.color = color;
d.customTitle = customTitle;
}
return d;
};
Expand All @@ -120,12 +121,34 @@ export function initialLoader(datasets: ILinkConfig['datasets']) {
}
const key = `${endpoint}:${JSON.stringify(params)}`;
const existing = loadingDataSets.get(key);

/* eslint-disable @typescript-eslint/restrict-template-expressions */
let customTitle = title;
if (params.custom_title) {
// Custom title present (e.g. from signal documentation) - apply directly
customTitle = `${params.custom_title}`;
} else if (params._endpoint) {
// Derive custom title from params
customTitle = `${params._endpoint}`;
if (params.data_source && params.signal) {
customTitle += ` > ${params.data_source}:${params.signal}`;
}
if (params.geo_type && params.geo_value) {
customTitle += ` > ${params.geo_type}:${params.geo_value}`;
}
if (params.regions) {
customTitle += ` > ${params.regions}`;
}
customTitle += ` > ${title}`;
}
/* eslint-enable @typescript-eslint/restrict-template-expressions */

if (existing) {
resolvedDataSets.push(existing.then(patchDataSet(title, color)));
resolvedDataSets.push(existing.then(patchDataSet(title, color, customTitle)));
} else {
const loadingDataSet = func(params);
loadingDataSets.set(key, loadingDataSet);
resolvedDataSets.push(loadingDataSet.then(patchDataSet(title, color)));
resolvedDataSets.push(loadingDataSet.then(patchDataSet(title, color, customTitle)));
}
}

Expand Down Expand Up @@ -156,21 +179,8 @@ export function initialLoader(datasets: ILinkConfig['datasets']) {
return Promise.all(resolvedDataSets).then((data) => {
const cleaned = data.filter((d): d is DataSet => d != null);
cleaned.forEach((d) => {
if (d.params && !Array.isArray(d.params) && d.params._endpoint) {
/* eslint-disable @typescript-eslint/restrict-template-expressions */
const col_name = d.title;
d.title = `${d.params._endpoint}`;
if (d.params.data_source && d.params.signal) {
d.title += ` > ${d.params.data_source}:${d.params.signal}`;
}
if (d.params.geo_type && d.params.geo_value) {
d.title += ` > ${d.params.geo_type}:${d.params.geo_value}`;
}
if (d.params.regions) {
d.title += ` > ${d.params.regions}`;
}
d.title += ` > ${col_name}`;
/* eslint-enable @typescript-eslint/restrict-template-expressions */
if (d.customTitle) {
d.title = d.customTitle;
}
add(d);
});
Expand Down
26 changes: 16 additions & 10 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ formSelections.subscribe((val) => {
sessionStorage.setItem('form', JSON.stringify(val));
});

export const apiKey = writable(localStorage.getItem('api-key')! || '');
apiKey.subscribe((val) => {
// always keep key in session storage (resets on window close)
sessionStorage.setItem('api-key', val);
if (localStorage.getItem('store-api-key') === 'true') {
// if flag set, also store key in local persistent storage
localStorage.setItem('api-key', val);
}
});

export const storeApiKeys = writable(localStorage.getItem('store-api-key') === 'true');
storeApiKeys.subscribe((val) => {
localStorage.setItem('store-api-key', val.toString());
Expand All @@ -47,16 +57,6 @@ storeApiKeys.subscribe((val) => {
}
});

export const apiKey = writable(localStorage.getItem('api-key')! || '');
apiKey.subscribe((val) => {
// always keep key around in session storage (resets on page refresh)
sessionStorage.setItem('api-key', val);
if (localStorage.getItem('store-api-key') === 'true') {
// store it in local storage (persistent)
localStorage.setItem('api-key', val);
}
});

export function addDataSet(dataset: DataSet | DataGroup): void {
const root = get(datasetTree);
root.datasets.push(dataset);
Expand All @@ -66,6 +66,12 @@ export function addDataSet(dataset: DataSet | DataGroup): void {
if (dataset instanceof DataGroup) {
// auto expand
expandedDataGroups.set([...get(expandedDataGroups), dataset]);
// add defaultEnabled datasets to the list of active datasets
for (const ds of dataset.datasets) {
if (ds instanceof DataSet && dataset.defaultEnabled.includes(ds.title)) {
activeDatasets.set([...get(activeDatasets), ds]);
}
}
} else {
activeDatasets.set([...get(activeDatasets), dataset]);
}
Expand Down