Files
HealthLog/src/components/charts/mini-window.ts
T
Marc-André Bombeck 240c15ff15 Label the chart range tabs as the day windows they are
The range selector said points — 7 pts, Last 7 data points — while the
fetch has always treated the value as a calendar-day window. Someone
who weighs in twice a week picked 7 pts and saw two, and read that as
a broken chart; the labels were the broken part. The tabs now say 7d /
30d / 90d / All across all six locales.

Behaviour is unified on the same reading everywhere. The measurement
chart's visible slice becomes a real day-window filter — the old
slice(-N) was a no-op on the self-fetched path but silently meant
last N readings on the dashboard's preloaded batch slice, so the same
tab meant two different things depending on the mount path. The mood
chart sliced the last N logged days out of the whole history and now
windows by days like its siblings. The header chip reads the same
grain decision the chart and the data table use instead of re-deriving
it in a second memo.

Component fixtures move to now-anchored dates: the windows are anchored
on now, so absolute-dated fixtures age out of the window and would have
exercised only the empty states. The span-dependent cases (weekly chip,
bucketed-caption table) mount the All range, which is now the only
range that can span past 90 days.
2026-08-26 17:55:56 +02:00

38 lines
1.3 KiB
TypeScript

/**
* v1.4.16 phase B5c — shared chart-mini window vocabulary.
*
* The Oura-style RecommendationCard (B5c) embeds a mini-chart that
* pins to the recommendation's `rationale.dataWindow`. This helper
* maps the rationale enum onto the calendar-day window used by the
* existing chart wrappers.
*
* last7days → 7-day window
* last30days → 30-day window
* last90days → 90-day window
* allTime → 0 (HealthChart treats 0 as "no window — show all")
*
* The values mirror the existing `TIME_RANGES_KEYS` definition in
* `health-chart.tsx`; the helper is a pure function so unit tests
* pin the contract without depending on Recharts internals. The
* exported name keeps the historical `rangePoints` vocabulary because
* it feeds the chart state/preference field of that name (a persisted
* wire field) — the VALUE has always been calendar days.
*/
export type DataWindow = "last7days" | "last30days" | "last90days" | "allTime";
const DAYS_BY_WINDOW: Record<DataWindow, number> = {
last7days: 7,
last30days: 30,
last90days: 90,
allTime: 0,
};
/**
* Returns the day-window value the chart wrapper expects for a given
* rationale dataWindow enum value.
*/
export function resolveMiniRangePoints(window: DataWindow): number {
return DAYS_BY_WINDOW[window];
}