From 3da173a2482a47e7a7d348a1ae4795be80aaa31e Mon Sep 17 00:00:00 2001 From: higsch Date: Tue, 20 Oct 2020 00:10:50 +0200 Subject: [PATCH] google trends chart implemented --- src/components/BackgroundChart.svelte | 6 ++ src/components/CoronaChart.svelte | 2 +- src/components/GoogleTrendsChart.svelte | 80 +++++++++++++++++++++++++ src/components/Visualization.svelte | 2 - src/utils/loadGoogleTrendsData.js | 6 +- 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/components/GoogleTrendsChart.svelte diff --git a/src/components/BackgroundChart.svelte b/src/components/BackgroundChart.svelte index 9d3d949..63a08d9 100644 --- a/src/components/BackgroundChart.svelte +++ b/src/components/BackgroundChart.svelte @@ -5,6 +5,7 @@ import { margin } from '../stores/dimensions'; import CoronaChart from './CoronaChart.svelte'; + import GoogleTrendsChart from './GoogleTrendsChart.svelte'; @@ -14,6 +15,11 @@ margin={$margin} showLegend={!$originalTimeDomain} /> {/if} + {#if (/^gt_/.test(dataset.id))} + + {/if} {/each} diff --git a/src/components/CoronaChart.svelte b/src/components/CoronaChart.svelte index 1131212..4baf464 100644 --- a/src/components/CoronaChart.svelte +++ b/src/components/CoronaChart.svelte @@ -25,7 +25,7 @@ $: if (data) { yScale = scaleLog() - .domain([1, max(data.map((d) => d.cases))]) + .domain([1, max(data, (d) => d.cases)]) .range([$panelHeight - margin.bottom, margin.top * 0.7]); area = (type, data) => d3area() diff --git a/src/components/GoogleTrendsChart.svelte b/src/components/GoogleTrendsChart.svelte new file mode 100644 index 0000000..a2dd354 --- /dev/null +++ b/src/components/GoogleTrendsChart.svelte @@ -0,0 +1,80 @@ + + +{#if (data)} + + + + + + +{/if} + + diff --git a/src/components/Visualization.svelte b/src/components/Visualization.svelte index d9a89ac..2edd40e 100644 --- a/src/components/Visualization.svelte +++ b/src/components/Visualization.svelte @@ -108,8 +108,6 @@ } ]; - console.log($contextData[1].data) - preloadImages(data); // apply filters from URL diff --git a/src/utils/loadGoogleTrendsData.js b/src/utils/loadGoogleTrendsData.js index e67ea88..53f3931 100644 --- a/src/utils/loadGoogleTrendsData.js +++ b/src/utils/loadGoogleTrendsData.js @@ -2,7 +2,11 @@ import { googleTrendsApiPath } from '../inputs/dataPaths'; const loadGoogleTrendsData = async (keyword) => { const response = await fetch(`${googleTrendsApiPath}${encodeURIComponent(keyword)}`); - return(response.json()); + const data = (await response.json()).map((d) => ({ + ...d, + date: new Date(d.time * 1000) + })); + return(data); }; export default loadGoogleTrendsData;