stats: zero-fill by_hour gaps; fix chart blank labels + unnecessary rebuilds
Closes #52, closes #55. Follow-ups from the #47 review round. #52: by_hour_of_day was already zero-filled across 0-23 (deliberately, so a quiet hour doesn't misread as missing data) but by_hour — the continuous timeline — wasn't. The client renders it on a categorical axis, so closed hours between two festival nights collapsed to nothing and the last hour of one night sat directly next to the first hour of the next. Now zero-filled between the first and last real bucket, same reasoning as by_hour_of_day. #55, two fixes: - DayChart's x scale is now explicitly ordinal (distr: 2). The prior default (linear) let uPlot's tick generator pick fractional increments on a short series, and the index-based label lookup misses on a non-integer tick, rendering a blank label. - The four per-day/per-hour chart data preps in Stats.tsx now produce a single memoized {labels, series} object each, instead of building fresh labels/series array literals inline in JSX on every render. DayChart's effect is keyed on those props by reference, so the old code destroyed and recreated every uPlot instance on any unrelated Dashboard re-render (e.g. the isAdmin check resolving after data already loaded). Both sides build/typecheck clean. Manually verified the zero-fill against a seeded DB with a 3-hour gap between two transactions — by_hour correctly returned 4 buckets (2 real, 2 zero-filled) in order.
This commit is contained in:
parent
6c2a938b91
commit
f576fbde3e
3 changed files with 73 additions and 23 deletions
|
|
@ -32,7 +32,12 @@ export function DayChart({ labels, series }: { labels: string[]; series: ChartSe
|
|||
height: 220,
|
||||
legend: { show: series.length > 1 },
|
||||
cursor: { drag: { x: false, y: false } },
|
||||
scales: { x: { time: false } },
|
||||
// distr: 2 (ordinal) — the default (1, linear) lets uPlot's tick
|
||||
// generator pick fractional increments on a short/sparse series,
|
||||
// and the label lookup below (`labels[v]`) misses on a non-integer
|
||||
// v, rendering a blank tick. Ordinal forces whole-number splits,
|
||||
// which is what an index-based x-axis always wants anyway (#55).
|
||||
scales: { x: { time: false, distr: 2 } },
|
||||
axes: [
|
||||
{ stroke: '#888', grid: { stroke: '#333' }, values: (_u, vals) => vals.map(v => labels[v] ?? '') },
|
||||
{ stroke: '#888', grid: { stroke: '#333' } },
|
||||
|
|
|
|||
Loading…
Reference in a new issue