Skip to content

Commit 3773169

Browse files
committed
Merge branch 'dev' into rzatserkovnyi/api-key
2 parents 51c1dbc + d944baf commit 3773169

File tree

14 files changed

+181
-167
lines changed

14 files changed

+181
-167
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "www-epivis",
3-
"version": "2.1.2",
3+
"version": "2.1.4",
44
"private": true,
55
"license": "MIT",
66
"description": "",

src/App.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
if (ds) {
3232
// add the dataset itself
3333
addDataSet(ds);
34-
// reset active datasets to fluview -> ili
35-
$activeDatasets = [ds.datasets[1]];
34+
// reset active datasets to fluview -> wili
35+
$activeDatasets = [ds.datasets[0]];
3636
if (chart) {
3737
chart.fitData(true);
3838
}

src/api/EpiData.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
fluViewRegions,
1010
gftLocations,
1111
ghtLocations,
12-
nidssDenqueLocations,
12+
nidssDengueLocations,
1313
nidssFluLocations,
1414
nowcastLocations,
1515
quidelLocations,
@@ -64,9 +64,11 @@ function loadEpidata(
6464
name: string,
6565
epidata: Record<string, unknown>[],
6666
columns: string[],
67+
columnRenamings: Record<string, string>,
6768
params: Record<string, unknown>,
6869
): DataGroup {
6970
const datasets: DataSet[] = [];
71+
const colRenamings = new Map(Object.entries(columnRenamings));
7072

7173
for (const col of columns) {
7274
const points: EpiPoint[] = [];
@@ -91,7 +93,11 @@ function loadEpidata(
9193
}
9294
points.push(new EpiPoint(date, row[col] as number));
9395
}
94-
datasets.push(new DataSet(points, col, params));
96+
if (points.length > 0) {
97+
// overwrite default column name if there's an overwrite in columnRenamings
98+
const title = colRenamings.has(col) ? colRenamings.get(col) : col;
99+
datasets.push(new DataSet(points, title, params));
100+
}
95101
}
96102
return new DataGroup(name, datasets);
97103
}
@@ -113,6 +119,7 @@ export function loadDataSet(
113119
userParams: Record<string, unknown>,
114120
columns: string[],
115121
api_key = '',
122+
columnRenamings: Record<string, string> = {},
116123
): Promise<DataGroup | null> {
117124
const duplicates = get(expandedDataGroups).filter((d) => d.title == title);
118125
if (duplicates.length > 0) {
@@ -140,7 +147,18 @@ export function loadDataSet(
140147
url.searchParams.set('format', 'json');
141148
return fetchImpl<Record<string, unknown>[]>(url)
142149
.then((res) => {
143-
return loadEpidata(title, res, columns, { _endpoint: endpoint, ...params });
150+
const data = loadEpidata(title, res, columns, columnRenamings, { _endpoint: endpoint, ...params });
151+
if (data.datasets.length == 0) {
152+
return UIkit.modal
153+
.alert(
154+
`
155+
<div class="uk-alert uk-alert-error">
156+
<a href="${url.href}">API Link</a> returned no data.
157+
</div>`,
158+
)
159+
.then(() => null);
160+
}
161+
return data;
144162
})
145163
.catch((error) => {
146164
console.warn('failed fetching data', error);
@@ -330,7 +348,7 @@ export function importFluView({
330348
auth?: string;
331349
}): Promise<DataGroup | null> {
332350
const regionLabel = fluViewRegions.find((d) => d.value === regions)?.label ?? '?';
333-
const title = appendIssueToTitle(`[API] FluView: ${regionLabel}`, { issues, lag });
351+
const title = appendIssueToTitle(`[API] ILINet (aka FluView): ${regionLabel}`, { issues, lag });
334352
return loadDataSet(
335353
title,
336354
'fluview',
@@ -351,6 +369,10 @@ export function importFluView({
351369
'num_age_4',
352370
'num_age_5',
353371
],
372+
{
373+
wili: '%wILI',
374+
ili: '%ILI',
375+
},
354376
);
355377
}
356378

@@ -390,9 +412,9 @@ export function importGHT({
390412
);
391413
}
392414

393-
export function importNIDSSDenque({ locations }: { locations: string }): Promise<DataGroup | null> {
394-
const regionLabel = nidssDenqueLocations.find((d) => d.value === locations)?.label ?? '?';
395-
const title = `[API] NIDSS-Denque: ${regionLabel}`;
415+
export function importNIDSSDengue({ locations }: { locations: string }): Promise<DataGroup | null> {
416+
const regionLabel = nidssDengueLocations.find((d) => d.value === locations)?.label ?? '?';
417+
const title = `[API] NIDSS-Dengue: ${regionLabel}`;
396418
return loadDataSet(
397419
title,
398420
'nidss_dengue',

src/components/Chart.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@
134134
setNavMode(NavMode.zoom);
135135
}
136136
}
137-
if (navMode == NavMode.crop) {
137+
if (navMode == NavMode.autofit) {
138+
navMode = NavMode.pan;
139+
} else if (navMode == NavMode.crop) {
138140
navBox = { x: m.x, y: m.y, w: 0, h: 0 };
139141
}
140142
}
@@ -268,6 +270,9 @@
268270
dx = ((xMax - xMin) / 2) * fx;
269271
dy = ((yMax - yMin) / 2) * fy;
270272
setViewport(xMin - dx, yMin - dy, xMax - dx, yMax - dy);
273+
if (navMode == NavMode.autofit) {
274+
navMode = NavMode.pan;
275+
}
271276
}
272277
273278
function zoom(x: number, y: number): void {

src/components/TopMenu.svelte

Lines changed: 58 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
faLink,
1111
faPaintBrush,
1212
faQuestion,
13-
faReceipt,
1413
faSearchPlus,
15-
faUpDown,
14+
faShuffle,
1615
} from '@fortawesome/free-solid-svg-icons';
1716
import Fa from 'svelte-fa';
18-
import { activeDatasets, isShowingPoints, navMode, randomizeColors, reset, scaleMean, autoFit } from '../store';
17+
import { activeDatasets, isShowingPoints, navMode, randomizeColors, reset, scaleMean } from '../store';
1918
import type { IChart } from '../store';
2019
import { NavMode } from './chartUtils';
2120
import { tour } from '../tour';
@@ -50,10 +49,8 @@
5049
return;
5150
}
5251
switch (e.key) {
53-
case 'f':
54-
if (chart) {
55-
chart.fitData(true);
56-
}
52+
case 'a':
53+
$navMode = NavMode.autofit;
5754
break;
5855
case 'p':
5956
$navMode = NavMode.pan;
@@ -70,9 +67,6 @@
7067
case 's':
7168
$isShowingPoints = !$isShowingPoints;
7269
break;
73-
case 'a':
74-
$autoFit = !$autoFit;
75-
break;
7670
case 'h':
7771
tour.cancel();
7872
tour.start();
@@ -82,35 +76,57 @@
8276
</script>
8377

8478
<div class="menu" {style} data-tour="top">
85-
<div class="uk-button-group">
79+
<div class="uk-button-group" data-tour="navmode">
8680
<button
8781
type="button"
88-
class="uk-button uk-button-default uk-button-small"
89-
on:click|preventDefault={randomizeColors}
90-
title="Randomize Colors<br/>(Keyboard Shortcut: r)"
91-
data-tour="random"
92-
uk-tooltip><Fa icon={faPaintBrush} /></button
82+
class="uk-button uk-button-small"
83+
disabled={!chart}
84+
class:uk-active={$navMode === NavMode.autofit}
85+
class:uk-button-secondary={$navMode === NavMode.autofit}
86+
class:uk-button-default={$navMode !== NavMode.autofit}
87+
on:click|preventDefault={() => ($navMode = NavMode.autofit)}
88+
title="Autofit Mode<br/>(Keyboard Shortcut: a)"
89+
uk-tooltip><Fa icon={faExpand} /></button
9390
>
9491
<button
9592
type="button"
96-
class="uk-button uk-button-default uk-button-small"
97-
disabled={!chart}
98-
on:click|preventDefault={() => (chart ? chart.fitData(true) : null)}
99-
title="Fit Data to Screen<br/>(Keyboard Shortcut: f)"
100-
data-tour="fit"
101-
uk-tooltip><Fa icon={faExpand} /></button
93+
class="uk-button uk-button-small"
94+
class:uk-active={$navMode === NavMode.pan}
95+
title="Pan Mode<br/>(Keyboard Shortcut: p)"
96+
class:uk-button-secondary={$navMode === NavMode.pan}
97+
class:uk-button-default={$navMode !== NavMode.pan}
98+
uk-tooltip
99+
on:click|preventDefault={() => ($navMode = NavMode.pan)}><Fa icon={faArrowsAlt} /></button
102100
>
103101
<button
104102
type="button"
105103
class="uk-button uk-button-small"
106-
disabled={!chart}
107-
class:uk-active={$autoFit}
108-
class:uk-button-secondary={$autoFit}
109-
class:uk-button-default={!$autoFit}
110-
on:click|preventDefault={() => ($autoFit = !$autoFit)}
111-
title="Automatically Fit Data<br/>(Keyboard Shortcut: a)"
112-
data-tour="autofit"
113-
uk-tooltip><Fa icon={faUpDown} /></button
104+
class:uk-active={$navMode === NavMode.crop}
105+
class:uk-button-secondary={$navMode === NavMode.crop}
106+
class:uk-button-default={$navMode !== NavMode.crop}
107+
title="Crop Mode<br/>(Keyboard Shortcut: c)"
108+
uk-tooltip
109+
on:click|preventDefault={() => ($navMode = NavMode.crop)}><Fa icon={faCrop} /></button
110+
>
111+
<button
112+
type="button"
113+
class="uk-button uk-button-small"
114+
class:uk-active={$navMode === NavMode.zoom}
115+
class:uk-button-secondary={$navMode === NavMode.zoom}
116+
class:uk-button-default={$navMode !== NavMode.zoom}
117+
title="Zoom Mode<br/>(Keyboard Shortcut: z)"
118+
uk-tooltip
119+
on:click|preventDefault={() => ($navMode = NavMode.zoom)}><Fa icon={faSearchPlus} /></button
120+
>
121+
</div>
122+
<div class="uk-button-group">
123+
<button
124+
type="button"
125+
class="uk-button uk-button-default uk-button-small"
126+
on:click|preventDefault={randomizeColors}
127+
title="Randomize Colors<br/>(Keyboard Shortcut: r)"
128+
data-tour="random"
129+
uk-tooltip><Fa icon={faPaintBrush} /></button
114130
>
115131
<button
116132
type="button"
@@ -119,17 +135,10 @@
119135
class:uk-button-secondary={$isShowingPoints}
120136
class:uk-button-default={!$isShowingPoints}
121137
on:click|preventDefault={() => ($isShowingPoints = !$isShowingPoints)}
122-
title="Show or Hide points<br/>(Keyboard Shortcut: s)"
138+
title="Show or Hide Points<br/>(Keyboard Shortcut: s)"
123139
data-tour="points"
124140
uk-tooltip><Fa icon={faEllipsisH} /></button
125141
>
126-
<button
127-
type="button"
128-
class="uk-button uk-button-default uk-button-small"
129-
on:click|preventDefault={scaleMean}
130-
title="Scale by 1/mean"
131-
uk-tooltip><Fa icon={faAnchor} /></button
132-
>
133142
<button
134143
type="button"
135144
class="uk-button uk-button-default uk-button-small"
@@ -138,12 +147,21 @@
138147
uk-tooltip
139148
disabled={$activeDatasets.length < 2}><Fa icon={faChartLine} /></button
140149
>
150+
</div>
151+
<div class="uk-button-group" data-tour="scale">
152+
<button
153+
type="button"
154+
class="uk-button uk-button-default uk-button-small"
155+
on:click|preventDefault={scaleMean}
156+
title="Scale by 1/mean"
157+
uk-tooltip><Fa icon={faAnchor} /></button
158+
>
141159
<button
142160
type="button"
143161
class="uk-button uk-button-default uk-button-small"
144162
on:click|preventDefault={reset}
145-
title="Reset DataSet Scaling"
146-
uk-tooltip><Fa icon={faReceipt} /></button
163+
title="Reset Dataset Scaling"
164+
uk-tooltip><Fa icon={faShuffle} /></button
147165
>
148166
</div>
149167
<div class="uk-button-group">
@@ -166,38 +184,6 @@
166184
on:click|preventDefault={() => (doDialog = 'directLink')}><Fa icon={faLink} /></button
167185
>
168186
</div>
169-
<div class="uk-button-group" data-tour="navmode">
170-
<button
171-
type="button"
172-
class="uk-button uk-button-small"
173-
class:uk-active={$navMode === NavMode.pan}
174-
title="Pan Mode<br/>(Keyboard Shortcut: p)"
175-
class:uk-button-secondary={$navMode === NavMode.pan}
176-
class:uk-button-default={$navMode !== NavMode.pan}
177-
uk-tooltip
178-
on:click|preventDefault={() => ($navMode = NavMode.pan)}><Fa icon={faArrowsAlt} /></button
179-
>
180-
<button
181-
type="button"
182-
class="uk-button uk-button-small"
183-
class:uk-active={$navMode === NavMode.crop}
184-
class:uk-button-secondary={$navMode === NavMode.crop}
185-
class:uk-button-default={$navMode !== NavMode.crop}
186-
title="Crop Mode<br/>(Keyboard Shortcut: c)"
187-
uk-tooltip
188-
on:click|preventDefault={() => ($navMode = NavMode.crop)}><Fa icon={faCrop} /></button
189-
>
190-
<button
191-
type="button"
192-
class="uk-button uk-button-small"
193-
class:uk-active={$navMode === NavMode.zoom}
194-
class:uk-button-secondary={$navMode === NavMode.zoom}
195-
class:uk-button-default={$navMode !== NavMode.zoom}
196-
title="Zoom Mode<br/>(Keyboard Shortcut: z)"
197-
uk-tooltip
198-
on:click|preventDefault={() => ($navMode = NavMode.zoom)}><Fa icon={faSearchPlus} /></button
199-
>
200-
</div>
201187
<div class="uk-button-group">
202188
<button
203189
type="button"

src/components/chartUtils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export enum NavMode {
2-
pan = 0,
3-
crop = 1,
4-
zoom = 2,
2+
autofit = 0,
3+
pan = 1,
4+
crop = 2,
5+
zoom = 3,
56
}
67

78
export enum Align {

0 commit comments

Comments
 (0)