Skip to content

feat(charts): render the account daily activity chart through the parity flag (S5) (@fehmer) - #8627

Draft
fehmer wants to merge 9 commits into
integration/chartsfrom
feature/ts-charts-s5-daily-activity
Draft

fehmer wants to merge 9 commits into
integration/chartsfrom
feature/ts-charts-s5-daily-activity

Conversation

@fehmer

@fehmer fehmer commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

The account daily activity chart (per-day minutes bars + average-speed line + trendline) now also renders through TanStack Charts, switched by the dev-only parity flag. The legacy Chart.js half is kept as the Show fallback until S12.

 <DailyActivityChart> (components/pages/account/DailyActivityChart.tsx)
   <AsyncContent dataQuery>
+    <Show when={getUseTanstackCharts()}
+      fallback={<ChartJs name="DailyActivity" …/>}>   // stepping stone, removed in S12
+      <Chart definition={buildDailyActivityChartDefinition(…)} />
+    </Show>
-    <ChartJs name="DailyActivity" …/>
   </AsyncContent>

The TanStack definition mirrors the Chart.js datasets:

buildDailyActivityChartDefinition
  marks   continuousBarY  minutes/day        → left  `y`  scale
          lineY average wpm        → right `avgWpm` scale
          dot   average wpm points → right `avgWpm` scale
          trend linearRegressionY(ci 0) → left `y`, dotted, no band
  scales  x        scaleUtc, d MMM ticks, ±½-day padded domain (old offset: true)
          y        left  minutes,  beginAtZero
          avgWpm   right avg speed, beginAtZero
  tooltip focus "group-x" → per-day rows (time typing, tests, wpm, accuracy, …)

continuousBarY is a new shared mark (components/charts/continuous-bar-y.ts): the built-in barY sizes bars from 80% of the smallest data gap, which on a continuous (utc) x scale runs bars into empty days and centres the edge bars on the plot border. The mark replicates Chart.js' continuous-scale layout instead — bar width = 72% (categoryPercentage 0.8 × barPercentage 0.9) of the smallest adjacent-bar or adjacent-tick distance, resolved per render from the resolved scale — and the x domain is padded ±½ day (the old offset: true) so the edge bars sit inside the plot. Generic for any continuous (non-band) x scale, so future time-scale bar charts can reuse it.

Parity fixes folded in:

  • Bar width + edge inset as above — 90.4 px vs Chart.js' 89.9 px on the same sparse data, centres within 6 px.
  • beginAtZero via viewport: { domain: [0, max] }, skipped when the data is all-zero — a [0, 0] viewport throws in the library, so an all-zero history must fall back to the fitted scale.
  • x ticks use count: Math.min(8, daySpan); the utc scale snaps to nice day/month steps from that target, matching the old autoSkip density per filter window.
  • Trendline is dotted (strokeDasharray: "3 3" at 2 px) — a visual match for the Chart.js trendline plugin's dotted style (the plugin literally used setLineDash([2, 2]) at 3 px).

Evidence

  • pnpm vitest run __tests__/components/pages/account/DailyActivityChart.spec.tsx → 9 passed (±½-day domain padding, scale bindings, bar width/centre from the smallest bar-or-tick gap, beginAtZero viewport, all-zero guard, dotted trendline with no band, per-day group-x tooltip, flag switch both ways).
  • Full frontend suite: 134 files / 2020 passed; pnpm oxlint --type-aware --type-check: 0 errors in the PR's files (5 pre-existing no-unused-vars in Charts.tsx live on the integration branch — the file is byte-identical there and untouched here).
  • Browser parity on /account (dev flag on vs Chart.js): minutes bars (width + edge inset), average-speed line/dots, trendline, and x-tick density all match across filter windows; tooltip and theme reactivity verified.

Merge Danger

Door: two-way. The whole TanStack path sits behind the dev-only parity flag (getUseTanstackCharts), which is always false in production — production keeps the existing Chart.js chart. Reverting the commit (or flipping the flag off) restores the status quo.

Blast Radius: contained — dev-only; the production default (Chart.js) is untouched.

@monkeytypegeorge monkeytypegeorge added frontend User interface or web stuff docs Related to Markdown files and documentation labels Nov 26, 2026
@fehmer
fehmer added this pull request to stack #8625 November 26, 2026 12:16
@fehmer
fehmer force-pushed the feature/ts-charts-s5-daily-activity branch from 449c0f4 to 2b22832 Compare November 26, 2026 15:32
Base automatically changed from feature/ts-charts-s4-account-histogram to integration/charts November 30, 2026 10:07
…c scale (@fehmer)

The utc scale derives its tick interval from a *preferred* count rather than a
hard max, so the previous 55px spacing over-packed the axis to monthly ticks.
A preferred count of 8 resolves to the same ~3-month interval chart.js produces
with maxTicksLimit: 20 on a dense multi-month history.
@fehmer
fehmer force-pushed the feature/ts-charts-s5-daily-activity branch from f78961c to e751959 Compare November 30, 2026 10:07
…ale (@fehmer)

The built-in barY infers width from 80% of the smallest data gap only, so on
the daily activity's utc day axis the bars ran into empty days (and the edge
bars sat centred on the plot border, unlike chart.js' offset: true).

Add a continuous-scale bar mark (components/charts/continuous-bar-y) that
sizes each bar to chart.js' rule - 72% (categoryPercentage 0.8 x barPercentage
0.9) of the smallest adjacent-bar or adjacent-tick distance, resolved per
render from the resolved scale - and centre it on its x value. Pad the utc x
domain half a day each end to match the old offset: true so the edge bars sit
inside the plot.

Generic for any continuous (non-band) x scale, not daily-specific. Filename
avoids 'chartjs' because vitest 4 / vite 8 drops the exports of a source
module whose name contains it (the import reads as undefined).
@fehmer fehmer added the force-ci Force CI to run on draft PRs label Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Related to Markdown files and documentation force-ci Force CI to run on draft PRs frontend User interface or web stuff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants