Skip to content
SprecherEast
Issue 681

feat: Charts show as a small thumbnail that a reader can click or tap to enlarge in a modal dialog

Back to our plan
Done
enhancementfrontendvisualizationuxpriority: high

Problem

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.tsx is a server component: a figure with title, summary, the adapter's drawing, a swatch Legend, a Caption, then a Disclosure "Show the numbers" with the one ChartDataTable. The drawing's aria-labelledby and the bar chart's hatch pattern id come from useId() in Chart, so drawing the chart twice on one page would duplicate ids.
  • The drawing's width is set inside the adapters: max-w-md in adapters/visx/BarChartSvg.tsx (viewBox 320 wide, barLayout.ts), max-w-sm in adapters/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-dialog 1.1.15, already a dependency), a full-screen sheet with focus trap, Escape, scroll lock, page behind hidden from assistive tech, and focus return to its trigger. Used by the mobile hamburger menu and the gallery. No native <dialog> is used in src/. docs/ui/component-set.md names Radix as the kit's dialog behaviour.
  • Tabs.client.tsx renders every panel on the server (forceMount); the scripted: 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 from src/app/(frontend)/globals.css (#616).
  • The Chart block (chartBlockConfig.ts, chartBaseFields.ts), the spec (ChartSpec, CHART_LIMITS in src/platform/lib/chart/spec.ts) and the Markdown tag (chartMarkdown.ts, used by factTabsTag.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.

  1. One size, defined once. Add --chart-small-width: 20rem and --chart-large-width: 40rem to globals.css, with CHART_SMALL_WIDTH and CHART_LARGE_WIDTH in layoutSizes.ts. 20rem is the drawing's own 320-unit viewBox at 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 own max-w-* and draw w-full; Chart sets the width. The adapter contract test checks that no adapter sets a max width.
  2. ChartZoom.client.tsx in src/platform/ui/chart/ (the only new client code). It receives the server-rendered chart as children, 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 same children inside the shared Dialog and leaves an empty, aria-hidden box 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 only Dialog, Button and an icon, so no chart library, zod or visx reaches the browser.
  3. Chart uses it by default for the svg and html adapters. The text adapter 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.
  4. 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. Chart gets an internal zoom prop (default on) for the gallery and tests only.
  5. 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.
  6. Reduced motion: the dialog opens with no movement; any fade is motion-safe: only, as is the existing chart-reveal.
  7. 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 units kind 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 id while 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 svg or HTML, with titles, numbers and labels as real text (a test asserts no img, canvas or background-image in the chart).
  • Not done: The small and large widths are defined once (globals.css + layoutSizes.ts); no adapter sets its own max-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 text adapter and zoom={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 a text chart without it.
  • Not done: A row for ChartZoom and the updated Chart row in docs/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 (FactCard with variant="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

See it on GitHub, opens in a new tab