From 482d0b07878b961b61f8250384c8b9d7d45a1ba7 Mon Sep 17 00:00:00 2001 From: pswsm Date: Wed, 15 Feb 2023 16:20:45 +0100 Subject: [PATCH] Grpah works, but no lines on it --- src/components/graph.svelte | 131 +++++++++++++++------------ src/routes/+layout.svelte | 1 + src/routes/openmeteo/+page.server.ts | 13 +-- src/routes/openmeteo/+page.svelte | 4 +- src/routes/styles.css | 3 + 5 files changed, 84 insertions(+), 68 deletions(-) create mode 100644 src/routes/styles.css diff --git a/src/components/graph.svelte b/src/components/graph.svelte index e66035b..776c98a 100644 --- a/src/components/graph.svelte +++ b/src/components/graph.svelte @@ -1,73 +1,88 @@
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 1f7c859..b8f94d3 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,6 +1,7 @@ diff --git a/src/routes/openmeteo/+page.server.ts b/src/routes/openmeteo/+page.server.ts index 27fd9ce..f1935d7 100644 --- a/src/routes/openmeteo/+page.server.ts +++ b/src/routes/openmeteo/+page.server.ts @@ -15,14 +15,11 @@ export function load(): object { }) .then( (res) => { let forecastData: object = res.hourly; - let fmtForecastData: { labels: string[], datasets: Array } = { labels: forecastData.time, datasets: [] }; - let noTimeForecastData: object = Object.fromEntries(Object.entries(forecastData).filter( ([k]) => k !== 'time' )); - for (const label in noTimeForecastData) { - if (noTimeForecastData.hasOwnProperty(label)) { - const data = noTimeForecastData[label]; - fmtForecastData.datasets.push({label, data}) - } - } + let fmtForecastData: { title: string, data: [Date, number] | [] } = { title: 'Temps', data: [] }; + let regex: RegExp = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/ + forecastData.time.forEach( (elem, idx) => { + fmtForecastData.data.push([Date.parse(elem), forecastData.temperature_2m[idx]]) + }); return fmtForecastData; } ) diff --git a/src/routes/openmeteo/+page.svelte b/src/routes/openmeteo/+page.svelte index 69df30d..ecabdf9 100644 --- a/src/routes/openmeteo/+page.svelte +++ b/src/routes/openmeteo/+page.svelte @@ -5,7 +5,7 @@ let display: string = 'none'; let loading: boolean = false; - export let data: any; + export let data: { ubicacio: string, temps: any }; function toggleDisplay(): void { display = (display === 'none') ? 'block' : 'none'; @@ -21,7 +21,7 @@

UbicaciĆ³ actual: { data.ubicacio }

{ JSON.stringify(data) }
- +