Graph fixes
This commit is contained in:
@@ -47,14 +47,13 @@ const chart = computed(() => {
|
|||||||
const yOf = (v: number) => H - PAD - ((v - minV) / (maxV - minV || 1)) * (H - PAD * 2);
|
const yOf = (v: number) => H - PAD - ((v - minV) / (maxV - minV || 1)) * (H - PAD * 2);
|
||||||
const nowT = now.getTime();
|
const nowT = now.getTime();
|
||||||
const currentX = Math.max(PAD, Math.min(W - PAD, xOf(nowT)));
|
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);
|
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);
|
const fut = pts.filter(p => p.t >= nowT);
|
||||||
|
if(fut[0]?.t !== nearest.t) fut.unshift({t: nearest.t, v: nearest.v});
|
||||||
// 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);
|
|
||||||
const dot = {x: xOf(nearest.t), y: yOf(nearest.v as number), 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) =>
|
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(' ');
|
arr.map((p, i) => `${i===0?'M':'L'} ${xOf(p.t).toFixed(1)} ${yOf(p.v as number).toFixed(1)}`).join(' ');
|
||||||
|
|||||||
@@ -56,11 +56,22 @@ app.get('/api/current', async (req, res) => {
|
|||||||
const space = getCelestialCurrent(coords.latitude, coords.longitude)
|
const space = getCelestialCurrent(coords.latitude, coords.longitude)
|
||||||
const condition = getWeatherCondition(Object.assign(sensors, space))
|
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,
|
...condition,
|
||||||
...sensors,
|
...sensors,
|
||||||
...space,
|
...space,
|
||||||
}, fields))
|
}
|
||||||
|
|
||||||
|
res.json(filterFields(merged, fields))
|
||||||
})
|
})
|
||||||
|
|
||||||
// ── Hourly ────────────────────────────────────────────────────────────────────
|
// ── Hourly ────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user