Skip to content

Commit c73079c

Browse files
committed
Add custom URL functionality to various download buttons
1 parent af105da commit c73079c

File tree

7 files changed

+49
-9
lines changed

7 files changed

+49
-9
lines changed

src/blocks/HistoryLineChart.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
<Toggle bind:checked={singleRaw}>Raw Data</Toggle>
419419
{/if}
420420
<div class="spacer" />
421-
<DownloadMenu {fileName} {vegaRef} {data} {sensor} {raw} {stderr} />
421+
<DownloadMenu {fileName} {vegaRef} {data} {date} {region} {sensor} {raw} {stderr} />
422422
</div>
423423

424424
{#if showAgeStratifications}

src/blocks/RegionCountyMap.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
<DownloadMenu
6262
{vegaRef}
6363
{data}
64+
{date}
65+
{region}
6466
{sensor}
6567
absolutePos
6668
fileName="{sensor.name}_US Counties_{formatDateISO(date.value)}"

src/blocks/RegionHexMap.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,14 @@
153153
<div>Hex fill color: value at selected date</div>
154154
</div>
155155
<ColorLegend {sensor} level="state" gradientLength={$isMobileDevice ? 250 : 280}>
156-
<DownloadMenu fileName="{sensor.name}_US_States_{formatDateISO(date.value)}" data={dumpData} absolutePos {sensor} />
156+
<DownloadMenu
157+
fileName="{sensor.name}_US_States_{formatDateISO(date.value)}"
158+
data={dumpData}
159+
absolutePos
160+
{date}
161+
{region}
162+
{sensor}
163+
/>
157164
</ColorLegend>
158165
</div>
159166

src/blocks/RegionMap.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
on:click={onClickHandler}
119119
eventListeners={['click']}
120120
/>
121-
<DownloadMenu {vegaRef} {data} {sensor} absolutePos {fileName} />
121+
<DownloadMenu {vegaRef} {data} {date} {region} {sensor} absolutePos {fileName} />
122122
</div>
123123
</FullWidthWrapper>
124124

src/components/DownloadMenu.svelte

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { downloadUrl, scrollToTop } from '../util';
2+
import { downloadUrl } from '../util';
33
import { csvFormat } from 'd3-dsv';
44
import { formatDateISO } from '../formats';
55
import { modeByID } from '../modes';
@@ -13,6 +13,14 @@
1313
1414
export let data = null;
1515
16+
/**
17+
* @type {import("../stores/params").DateParam}
18+
*/
19+
export let date = null;
20+
/**
21+
* @type {import("../stores/params").RegionParam}
22+
*/
23+
export let region = null;
1624
/**
1725
* @type {import("../stores/params").SensorParam}
1826
*/
@@ -112,8 +120,24 @@
112120
function exportData() {
113121
// switch to export mode
114122
currentMode.set(modeByID.export);
115-
sensor.set(sensor.value, true);
116-
scrollToTop();
123+
}
124+
125+
let exportURL = '';
126+
$: {
127+
exportURL = '';
128+
if (sensor && sensor.key.split('-').length >= 2) {
129+
// Given a sensor key formatted "sensor-name-here-signal_name_here", split on the last dash
130+
let [last, ...rest] = sensor.key.split('-').reverse();
131+
rest = rest.reverse().join('-');
132+
exportURL += `data_source=${rest}&signal=${last}`;
133+
134+
if (region) {
135+
exportURL += `&geo_type=${region.level}&geo_value=${region.propertyId}`;
136+
}
137+
if (date) {
138+
exportURL += `&start_day=${formatDateISO(date.value)}&end_day=${formatDateISO(date.value)}`;
139+
}
140+
}
117141
}
118142
</script>
119143

@@ -140,7 +164,7 @@
140164
{#if advanced}
141165
<li class="uk-nav-divider" />
142166
<li>
143-
<a href="../{modeByID.export.id}" on:click|preventDefault={exportData}>Advanced Data Export</a>
167+
<a href={`../${modeByID.export.id}/?${exportURL}`} on:click={exportData}>Advanced Data Export</a>
144168
</li>
145169
{/if}
146170
</ul>

src/modes/indicator/GeoTable.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182

183183
<div class="uk-position-relative">
184184
<FancyHeader anchor="table">{title.title}</FancyHeader>
185-
<DownloadMenu {fileName} data={loadedData} absolutePos prepareRow={(row) => row.dump} />
185+
<DownloadMenu {fileName} data={loadedData} absolutePos prepareRow={(row) => row.dump} {date} {region} {sensor} />
186186
<p class="uk-text-center uk-text-italic ux-hint">
187187
<span class="inline-svg-icon">
188188
{@html mousePointerIcon}

src/modes/indicator/IndicatorAbout.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script>
2+
import { modeByID } from '..';
3+
import { currentMode } from '../../stores';
24
import { formatDateISO } from '../../formats';
35
import AboutSection from '../../components/AboutSection.svelte';
46
@@ -15,6 +17,11 @@
1517
*/
1618
export let sensor;
1719
20+
function exportData() {
21+
// switch to export mode
22+
currentMode.set(modeByID.export);
23+
}
24+
1825
let exportURL = '';
1926
$: {
2027
exportURL = '';
@@ -52,7 +59,7 @@
5259
</li>
5360
{/each}
5461
<li>
55-
<a href={`../export/?${exportURL}`}>Export Data</a>
62+
<a href={`../${modeByID.export.id}/?${exportURL}`} on:click={exportData}>Export Data</a>
5663
</li>
5764
</ul>
5865
{/if}

0 commit comments

Comments
 (0)