mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
Add a `compareBaseline` prop to HealthChart and MoodChart that, when set to "lastMonth" or "lastYear", overlays the prior-period series as a dimmed dashed line beneath the current data. The shift is computed in-memory by `shiftDailySeriesForward` — the chart already fetches the full measurement history so no extra API call is needed. The tooltip switches its delta line from "vs. your normal" to "vs. last month / last year" when comparison is active and a prior value exists for the hovered day, and adds a second row with the prior absolute value so both numbers are visible. The chart header gains a "vs. last month / last year" caption (or an "unavailable — no data yet" fallback when the prior period has no overlap). The dashboard page and the insights page both read the persisted preference from `User.dashboardWidgetsJson.comparisonBaseline` so a single toggle flip in Settings → Dashboard updates every chart on both surfaces atomically. Pure shift helper lives at `src/lib/charts/comparison-shift.ts` with 11 unit tests pinning the day-exact forward shift, the average helper, and the delta computation (null-safe). Regression guard: when comparisonBaseline is "none" (default), the chart renders exactly as before — no extra paint, no caption, no tooltip change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>