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 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(' ');
|
||||
|
||||
Reference in New Issue
Block a user