Skip to content

Commit 832ac51

Browse files
committed
feat: compare indicator plot
1 parent ef32883 commit 832ac51

File tree

5 files changed

+192
-129
lines changed

5 files changed

+192
-129
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script>
2+
import { formatDateShortDayOfWeekAbbr } from '../formats';
3+
import SensorValue from '../components/SensorValue.svelte';
4+
5+
export let hidden = false;
6+
/**
7+
* @type {import('../../data').EpiDataRow}
8+
*/
9+
export let item;
10+
11+
/**
12+
* @type {View}
13+
*/
14+
export let view;
15+
16+
/**
17+
* @type {import('../../stores/params').Sensor[]}
18+
*/
19+
export let sensors;
20+
21+
export let prop = 'sensorName';
22+
23+
$: items = item && view ? view.data('values').filter((d) => d.time_value === item.time_value) : [];
24+
</script>
25+
26+
<div aria-label="tooltip" class="tooltip" class:hidden>
27+
<h5>{formatDateShortDayOfWeekAbbr(item.date_value)}</h5>
28+
<table>
29+
{#each items as i, index}
30+
<tr>
31+
<th>{i[prop]}</th>
32+
<td>
33+
<SensorValue sensor={sensors[index]} value={i.value} medium />
34+
</td>
35+
</tr>
36+
{/each}
37+
</table>
38+
</div>
39+
40+
<style>
41+
.hidden {
42+
display: none;
43+
}
44+
45+
h5 {
46+
margin: 0;
47+
padding: 0;
48+
}
49+
50+
th {
51+
text-align: left;
52+
max-width: 15em;
53+
}
54+
td {
55+
text-align: right;
56+
vertical-align: top;
57+
}
58+
</style>

src/modes/dashboard/widgets/RegionLineChartWidget.svelte

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
} from '../../../specs/lineSpec';
2121
import { formatDateISO, formatWeek } from '../../../formats';
2222
import { WidgetHighlight } from '../highlight';
23-
import isEqual from 'lodash-es/isEqual';
2423
import { createEventDispatcher } from 'svelte';
2524
import { EpiWeek } from '../../../data/EpiWeek';
2625
import { isComparableAcrossRegions } from '../../../data/sensor';
2726
import HistoryLineTooltip from '../../../blocks/HistoryLineTooltip.svelte';
2827
import Toggle from '../../../components/Toggle.svelte';
28+
import { highlightToDate, joinLabels, updateVegaHighlight } from './utils';
2929
3030
const dispatch = createEventDispatcher();
3131
@@ -73,13 +73,6 @@
7373
*/
7474
const fetcher = getContext('fetcher');
7575
76-
/**
77-
* @param {import('../highlight').WidgetHighlight | null} highlight
78-
*/
79-
function highlightToDate(highlight) {
80-
return highlight ? highlight.primaryDate : null;
81-
}
82-
8376
/**
8477
* @param {import('../../../stores/params').SensorParam} sensor
8578
* @param {import('../../../stores/params').RegionParam[]} regions
@@ -105,6 +98,7 @@
10598
paddingTop: 80,
10699
isWeeklySignal: isWeekly,
107100
compareField: 'displayName',
101+
legend: true,
108102
tooltip: true,
109103
};
110104
const names = regions.map((region) => region.displayName);
@@ -156,55 +150,19 @@
156150
157151
$: highlighted = highlight != null && highlight.matches(sensor.value, visibleRegions[0], timeFrame);
158152
159-
function updateVegaHighlight(highlight) {
160-
if (!vegaRef) {
161-
return;
162-
}
163-
const view = vegaRef.vegaDirectAccessor();
164-
if (!view) {
165-
return;
166-
}
167-
const value = highlightToDate(highlight);
168-
const values = value ? [value.getTime()] : null;
169-
const newValue = value
170-
? {
171-
unit: 'layer_1',
172-
fields: view.signal('highlight_tuple_fields'),
173-
values,
174-
}
175-
: null;
176-
const currentValues = (view.signal('highlight_tuple') || { values: [] }).values;
177-
const newValues = values || [];
178-
if (isEqual(currentValues, newValues)) {
179-
return;
180-
}
181-
view.signal('highlight_tuple', newValue);
182-
view.runAsync();
153+
function updateVegaHighlightImpl(highlight) {
154+
updateVegaHighlight(vegaRef, highlight);
183155
}
184156
$: {
185-
updateVegaHighlight(highlight);
186-
}
187-
188-
function joinLabels(regions) {
189-
if (regions.length === 0) {
190-
return 'Regions';
191-
}
192-
if (regions.length === 1) {
193-
return regions[0].displayName;
194-
}
195-
const r = regions
196-
.slice(0, regions.length - 1)
197-
.map((d) => d.displayName)
198-
.join(', ');
199-
return `${r} and ${regions[regions.length - 1].displayName}`;
157+
updateVegaHighlightImpl(highlight);
200158
}
201159
</script>
202160

203161
<WidgetCard
204162
{initialState}
205163
defaultState={DEFAULT_STATE}
206164
{highlighted}
207-
region={visibleRegions.length === 1 ? visibleRegions[0] : joinLabels(visibleRegions)}
165+
region={visibleRegions.length === 1 ? visibleRegions[0] : joinLabels(visibleRegions.map((d) => d.displayName))}
208166
{sensor}
209167
date={timeFrame}
210168
{id}

0 commit comments

Comments
 (0)