Skip to content
SprecherEast
Issue 639

feat: Chart port, visx server adapter, adapter contract test and the import lint

Back to our plan
Done
enhancementfrontendvisualizationpriority: highshared-component

Re-scoped 2026-11-03 for the 2027 budget post (#645): the owner (Amine, 2026-11-03, Claude in Chrome side panel, text) asked for more charts, diagrams and infographics so a neighbor who knows nothing about taxes can follow the 2027 budget post, and told us to be inventive and think unconventionally. Changes from the text below: (1) the share-of-$100 grid and tiles are plain HTML in a new css adapter (output: 'html'), not visx SVG: they need no measuring and stay sharp at any width; (2) the adapter contract checks one [data-chart-mark] per datum and runs the SVG-only checks (role="img", title and description) only for SVG output; (3) toWaffleCells becomes toUnitCells(data, cells) (exactly N cells, perHundred and each modes); (4) the data table is closed by default (values are printed on the marks); (5) the colors and CHART_PAIRS move to #659; (6) visx bar and stacked move to #663. This issue keeps: the spec and schema, toChartTable, toChartSummary, the port and registry, Chart.tsx, the text and css adapters, the contract test and the lint policy. Order: #659 and #662 first, then this, then #663, then #640, then #664.

Problem

In plain words: before any chart reaches a post, the site needs one chart component that every page uses, an established open-source library drawing behind it, and a test that proves the library can be swapped. If pages imported the library directly, changing it later would mean touching every page.

The owner (Amine, 2026-11-03, Claude Code session, text) asked for an established free, open-source charting library used behind an interface (ports and adapters), as one common component across the app, so the site isn't locked in.

Today (checked 2026-11-03):

  • No chart library or chart component. package.json has none, and src/platform/ui/ has no Chart.
  • Library chosen on #592. visx 4.0.0 (MIT, published 2026-06-11, peer React 18 or 19) renders as a React server component in a local react-server test, with 0 KB of client JavaScript. Not yet tried in next build.
  • Boundaries. eslint.boundaries.config.mjs already limits runtime Payload imports to data/ and cms/ (the PAYLOAD policy). The same pattern can limit chart libraries.
  • Chart tokens fail contrast. Light chart-2 is 2.30:1 on the background. Light chart-3 and chart-4 are about 2.9:1 on the surface. Dark chart-5 is 3.15:1 on the surface. themes.test.ts checks no chart pair.

Proposed fix

  • Spike first, in the PR's first commit. One visx bar chart as a server component on /dev/gallery. next build shows no @visx code in a client chunk. If it does, stop and report on #592 before going on.
  • src/platform/lib/chart/:
    • ChartSpec types and the zod schema (shapes on #592)
    • toChartTable(spec) and toChartSummary(spec)
    • toWaffleCells(rows), largest-remainder rounding to exactly 100
    • value formatting per unit (usd, percent, mills, count)
  • src/platform/ui/chart/:
    • the ChartAdapter interface and the registry
    • chartPalette.ts (fill-chart-N, stroke-chart-N, stroke-background gaps)
    • Chart.tsx (figure, title, summary, adapter output, ChartDataTable, sources and certainty)
    • exported from @/platform/ui
  • adapters/visx/: bar (horizontal, vertical), share (stacked bar, waffle), series (column, line) and parts (donut, treemap).
    • Compact and wide layouts, switched by sm: classes.
    • Labels in their own rows.
    • @visx/pattern as a second cue beyond 3 series.
  • adapters/text/: the summary and the table only. It is the fallback for a kind an adapter doesn't support.
  • chartAdapter.contract.tsx: describeChartAdapter(adapter), run by both adapters' tests. It checks, through react-dom/server:
    • the SVG and one mark per datum are in the markup
    • no style= and no hex, rgb( or hsl( values
    • only palette classes
    • labels and values as text
    • aria-labelledby points at the title and the description
    • axe passes
  • Lint: a CHART_LIBRARIES policy in eslint.boundaries.config.mjs (code on #592) allows @visx/*, d3-*, recharts, echarts and @nivo/* only in src/platform/ui/chart/adapters/**.
  • Tokens: adjust the chart values that fail, and add CHART_PAIRS to tokens.ts: each chart token against background, surface and card, at 3:1, in both modes. themes.test.ts checks them.
  • Dependencies: @visx/shape, scale, group, axis, pattern and hierarchy at exact 4.0.0 versions.
  • Docs: a decision record for visx behind the port, the docs/ui/component-set.md row, and the gallery entries.
  • Watch out: a new shared component in src/platform/ui/, and theme token values change. Check every page that uses chart-* (none today) and the theme contract test.

Native first, one line per step:

  1. Native: React server components and SVG. Next and Payload have no chart.
  2. Official plugins: none.
  3. Open source: visx 4.0.0, chosen on #592 (comparison there).
  4. Our code: the spec, the schema and table functions, the port, the two adapters' compositions, the waffle cell function, the lint policy and the tests.

Acceptance criteria

  • Not done: next build: no @visx module in any client chunk (output pasted in the PR).
  • Not done: describeChartAdapter passes for the visx and text adapters, for every kind each supports.
  • Not done: A lint fixture importing @visx/shape outside the adapters folder fails with the policy's message.
  • Not done: toWaffleCells always returns 100 cells, tested on the 2025 shares (47.3, 37.3, 12.2, 3.3) and on edge cases (one part, ties, 0).
  • Not done: themes.test.ts checks the chart pairs in light and dark mode, and they pass.
  • Not done: /dev/gallery shows every kind at 320, 430, 768, 1024, 1280 and 1920, light and dark, with no overflow. Screenshots are in the PR.

Area

frontend, visualization

Priority

high


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab