diff --git a/client/src/components/GraphModal.vue b/client/src/components/GraphModal.vue index 4b95428..8353462 100644 --- a/client/src/components/GraphModal.vue +++ b/client/src/components/GraphModal.vue @@ -47,14 +47,13 @@ const chart = computed(() => { const yOf = (v: number) => H - PAD - ((v - minV) / (maxV - minV || 1)) * (H - PAD * 2); const nowT = now.getTime(); const currentX = Math.max(PAD, Math.min(W - PAD, xOf(nowT))); + const nearest = pts.reduce((a, b) => Math.abs(a.t - nowT) < Math.abs(b.t - nowT) ? a : b); const hist = pts.filter(p => p.t <= nowT); + if(hist.at(-1)?.t !== nearest.t) hist.push({t: nearest.t, v: nearest.v}); const fut = pts.filter(p => p.t >= nowT); - - // stitch current point into both paths so lines meet - const nearest = pts.reduce((a, b) => Math.abs(a.t - nowT) < Math.abs(b.t - nowT) ? a : b); + if(fut[0]?.t !== nearest.t) fut.unshift({t: nearest.t, v: nearest.v}); const dot = {x: xOf(nearest.t), y: yOf(nearest.v as number), v: nearest.v}; - hist.push({t: nearest.t, v: nearest.v}); const toPath = (arr: typeof pts) => arr.map((p, i) => `${i===0?'M':'L'} ${xOf(p.t).toFixed(1)} ${yOf(p.v as number).toFixed(1)}`).join(' '); diff --git a/server/src/server.mjs b/server/src/server.mjs index 61b881e..159f9e1 100644 --- a/server/src/server.mjs +++ b/server/src/server.mjs @@ -56,11 +56,22 @@ app.get('/api/current', async (req, res) => { const space = getCelestialCurrent(coords.latitude, coords.longitude) const condition = getWeatherCondition(Object.assign(sensors, space)) - res.json(filterFields({ + console.time(); + const forecast = await getForecast(); + console.timeEnd(); + console.log(forecast); + const merged = { + ...(forecast?.summary ? { + precipitation_chance: forecast.summary.precipitation_chance, + temperature_max: forecast.summary.temperature_max, + temperature_min: forecast.summary.temperature_min, + } : {}), ...condition, ...sensors, ...space, - }, fields)) + } + + res.json(filterFields(merged, fields)) }) // ── Hourly ────────────────────────────────────────────────────────────────────