alignment and now

This commit is contained in:
Vincent van der Wal
2026-08-02 09:03:35 +02:00
parent 3fda55ddd2
commit ae50999c1c
5 changed files with 75 additions and 9 deletions
+8 -2
View File
@@ -130,6 +130,7 @@
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
import { formatZoned, getZonedHour } from '$lib/utils/date';
import { useNow } from '$lib/utils/now.svelte';
import { CHART_COLORS } from './data';
@@ -224,6 +225,10 @@
class: className = ''
}: Props = $props();
// Minute-resolution clock shared with the rest of the app; read in draw() so
// the current-time marker stays put as time passes.
const clock = useNow();
// ─── Constants ──────────────────────────────────────────────────────────────
const PAD_BOTTOM = 34;
@@ -1386,9 +1391,10 @@
}
}
// Current time marker
// Current time marker. Reading the shared clock (rather than Date.now())
// makes the enclosing draw effect re-run every minute, so the line moves.
if (showNow) {
const now = Date.now() / 1000;
const now = clock.current.getTime() / 1000;
if (now >= viewStart && now <= viewEnd) {
const x = xPix(now);
ctx.strokeStyle = CHART_COLORS.currentTimeLine;