feat: Charts show as a small thumbnail that a reader can click or tap to enlarge in a modal dialog
Back to our planProblem
In short: a chart in a Fact tab panel is drawn big, so the first tab runs past the bottom of the screen. The owner wants each chart shown small, with its one-line takeaway beside it, and a reader can click or tap the chart to see it enlarged. The chart must stay real text and shapes (never a picture file), and the numbers stay readable under "Show the numbers".
The owner (Amine, 2026-11-04, voice session with Claude; paraphrased from the voice notes, not verbatim): in the content body of each Fact tab (the area that opens when a tab is picked, not the four tab cards) he wants a relatively small chart with a one-line explanation that a reader can click or tap to enlarge; charts must stay real text and shapes, never raster images, so text, numbers and labels stay searchable; build it "build once, reuse everywhere" so any Chart can use it; and he wants to see real screenshots of the small and enlarged versions before anything goes live. The tab cards stay as they are.
Measured today at 1920x1080: with one bar chart the first panel ends about 90px below the fold; with two charts about 1,000px below.
Names used: "thumbnail" (the small chart in the page) and "modal dialog" (the enlarged view; a lightbox). These are the standard names.
Size: M. Impact: shared component (Chart is used by every chart on the site, and the change reuses the shared Dialog): the PR gets the shared-component label and checks every page that draws a chart.
Details
What exists today (read at ba990bb):
src/platform/ui/chart/Chart.tsxis a server component: afigurewith title, summary, the adapter's drawing, a swatchLegend, aCaption, then aDisclosure"Show the numbers" with the oneChartDataTable. The drawing'saria-labelledbyand the bar chart's hatch pattern id come fromuseId()inChart, so drawing the chart twice on one page would duplicate ids.- The drawing's width is set inside the adapters:
max-w-mdinadapters/visx/BarChartSvg.tsx(viewBox 320 wide,barLayout.ts),max-w-sminadapters/css/UnitGrid.tsx. So "how big a chart is" lives in two places, not one. - A modal dialog already exists:
src/platform/ui/Dialog.client.tsx(Radix@radix-ui/react-dialog1.1.15, already a dependency), a full-screensheetwith focus trap, Escape, scroll lock, page behind hidden from assistive tech, and focus return to itstrigger. Used by the mobile hamburger menu and the gallery. No native<dialog>is used insrc/.docs/ui/component-set.mdnames Radix as the kit's dialog behaviour. Tabs.client.tsxrenders every panel on the server (forceMount); thescripted:variant (@media (scripting: enabled),src/platform/theme/tailwind.css) shows tabs only with scripting on; with it off every panel shows stacked.- Shared sizes live once in
src/platform/ui/layoutSizes.ts, reading variables fromsrc/app/(frontend)/globals.css(#616). - The Chart block (
chartBlockConfig.ts,chartBaseFields.ts), the spec (ChartSpec,CHART_LIMITSinsrc/platform/lib/chart/spec.ts) and the Markdown tag (chartMarkdown.ts, used byfactTabsTag.ts) have no size option today.
Proposed fix
Native first: reuse what is in the tree. Radix Dialog is already our dialog and gives every behaviour asked for, so no native <dialog> and no new library. A CSS-only zoom can't trap focus or hide the page behind.
- One size, defined once. Add
--chart-small-width: 20remand--chart-large-width: 40remtoglobals.css, withCHART_SMALL_WIDTHandCHART_LARGE_WIDTHinlayoutSizes.ts. 20rem is the drawing's own 320-unitviewBoxat 1:1, so its 13px and 12px labels are drawn at their designed size and stay legible. The enlarged view is about twice that. Adapters stop setting their ownmax-w-*and draww-full;Chartsets the width. The adapter contract test checks that no adapter sets a max width. ChartZoom.client.tsxinsrc/platform/ui/chart/(the only new client code). It receives the server-rendered chart aschildren, with the chart's title for the dialog's accessible name. It renders a visible Enlarge button (icon and the word, at least 44px,aria-label"Enlarge chart: <title>") next to the chart, outside the content that moves, then the chart. When opened, it renders the samechildreninside the sharedDialogand leaves an empty,aria-hiddenbox of the same height in the page, so the chart is in the page once at any moment: one drawing, one set of ids, one data table (the "Show the numbers" table moves with it, so it's there in both sizes). Nothing is drawn twice, and no raster image is made. A click or tap on the drawing itself also opens it (a pointer shortcut; the button is the keyboard path). It imports onlyDialog,Buttonand an icon, so no chart library, zod or visx reaches the browser.Chartuses it by default for thesvgandhtmladapters. Thetextadapter is already words, so it gets no Enlarge button. In the page the chart is a thumbnail: where the chart's container is at least about 40rem wide (a container query, so it works the same in a Fact tab panel and a plain post body), the drawing sits on the left at the small width and the title, takeaway, legend and caption sit beside it; narrower, they stack. "Show the numbers" stays full width under both. In the modal dialog the drawing grows to the large width and the layout stacks.- No new editor field or Markdown prop. Every chart behaves the same, editors and agents have nothing to choose, and there's no schema migration.
Chartgets an internalzoomprop (default on) for the gallery and tests only. - Scripting off: the Enlarge button is hidden (
hidden scripted:inline-flex). The reader gets the chart at its small, 1:1 readable size with the table under "Show the numbers", and can still zoom the page, which stays sharp because it is vector. - Reduced motion: the dialog opens with no movement; any fade is
motion-safe:only, as is the existingchart-reveal. - Phones (320, 430): the dialog is the shared full-screen sheet, with the close button in its top bar.
Open decisions for the owner (do not build until settled):
- The "one-line explanation": the plan uses the chart's existing takeaway (
summary, up to 400 characters, shown in full and never cut off), with editors asked to keep it to one line in Fact tabs. Is that what he meant, or does he mean a short hint such as "Tap to enlarge"? - Charts in a plain post body: do they also start as thumbnails (the default above), or only in Fact tabs?
- Phones: at 320 to 430 the thumbnail is already nearly full width, so the enlarged view mostly isolates the chart; it doesn't make it much bigger. Is that acceptable?
- Two-group grids (the
unitskind with two groups side by side) at 20rem draw small squares. Should they get double the small width?
Acceptance criteria
- Not done: Tests first (Vitest, Testing Library): the Enlarge button opens the modal dialog; Enter and Space open it; Escape and the close button close it; focus moves into the dialog, is trapped, and returns to the Enlarge button; the dialog's accessible name is the chart's title.
- Not done: One chart in the DOM at any moment: one drawing, unique ids (no duplicate
idwhile open or closed), and exactly one data table under "Show the numbers", available in both sizes. - Not done: No raster: in both sizes the drawing is the same
svgor HTML, with titles, numbers and labels as real text (a test asserts noimg,canvasorbackground-imagein the chart). - Not done: The small and large widths are defined once (
globals.css+layoutSizes.ts); no adapter sets its ownmax-w-*(adapter contract test). - Not done: No chart library, zod or visx in any client chunk (the existing chart lint test plus a check of the built client chunks).
- Not done: The
textadapter andzoom={false}show no Enlarge button. - Not done: Scripting off: no Enlarge button, the chart shows at its small size, "Show the numbers" works. Screenshot on the PR.
- Not done:
prefers-reduced-motion: reduce: nothing moves on open or close. - Not done: Works in a Fact tab panel (with tab switching before and after enlarging) and in a plain post body.
- Not done: An axe check passes, closed and open, light and dark.
- Not done: Screenshots at 320, 430, 768, 1024, 1280 and 1920, light and dark, of the thumbnail and of the open modal dialog (full-screen sheet at 320 and 430).
- Not done: One-screen measurement with the Fact tabs fixture (
factTabsFixtures.ts) at 1920x1080: report where the first panel ends (px from the top of the page and relative to the 1080 fold) for the one-chart panel and the two-chart panel, before and after. Target: the one-chart panel ends above the fold. - Not done: A gallery entry (
ChartGallery.tsx) showing a bar, stacked and units chart as thumbnails with Enlarge, and atextchart without it. - Not done: A row for
ChartZoomand the updatedChartrow indocs/ui/component-set.md(the sizes, the default, scripting off). - Not done: Screenshots of the small and enlarged versions are on the PR and sent to the owner, and he has seen them before it merges or goes live.
- Not done: The tab cards (
FactCardwithvariant="tab") are unchanged by this issue (they follow #678).
Area
frontend, ux, visualization
Priority
high: the 2027 budget post (#645, due 2026-11-09) uses Fact tabs with charts.
Generated by Claude Code, opens in a new tab