Skip to content

docs(charts): show ChartGrid vertical grid lines on categorical and continuous x - #12547

Merged
marie-lucas merged 1 commit into
mainfrom
charts/continuous-x-grid-story
Nov 18, 2026
Merged

marie-lucas merged 1 commit into
mainfrom
charts/continuous-x-grid-story

Conversation

@marie-lucas

Copy link
Copy Markdown
Contributor

Reader impact

People who open Charts/Chrome/ChartGrid to learn where vertical grid lines go saw an empty plot on Continuous X. That story drew bar() on a numeric x, and a bar draws nothing on a linear scale. The categorical case was visible only if you switched vertical on in Playground.

Now the page shows one fixed pair on the same rows. Categorical X puts a vertical grid line on each band center, so every bar has one. Continuous X puts the lines on d3 ticks, which need not match the data points.

Source of truth

The code. The ChartGrid component record is authority: draft, so it does not decide behavior.

  • packages/charts/src/ChartGrid.tsx: on a band x scale, vertical lines sit at xScale(d) + bandwidth / 2 for each domain value. Otherwise they sit at xScale.ticks(tickCount).
  • packages/charts/src/layout.ts: an all-number x gives a linear scale with .nice(). Any other x gives a band scale with padding 0.2.
  • packages/charts/src/marks/bar.tsx: bar() returns no points when the x scale has no bandwidth.

Correction

One intent: show how vertical grid lines are placed on categorical vs continuous x.

  • Continuous X (charts-chrome-chartgrid--continuous-x, export name unchanged):
    • Draws line('requests', {dots: true}) on a numeric hour key instead of bar('value').
    • Title: "Continuous x: grid on d3 ticks". Its controls still work.
  • Categorical X (new, charts-chrome-chartgrid--categorical-x, placed before Continuous X):
    • Draws bar('requests') on the label key with horizontal: false, vertical: true. It gives Continuous X a contrast on the same rows.
    • Controls are disabled. The story shows one fixed state, and tickCount has no effect on a band scale.
  • Data: both stories share one synthetic dataset, requests per minute in the 24 hours after a launch, sampled every 4 hours (7 rows). Each row has a label key and a numeric key. The old continuous fixture is removed. Playground (data, args, id) is unchanged.

Evidence

Headless Chrome against a production Storybook build of 51b209f, at 1280 px and 390 px, light and dark, DPR 2. Before each capture I asserted the theme, viewport and story title.

The expected positions are worked out by hand from the data and d3's scale definitions, not read from the chart code. The plot width is W = SVG width − 48 − 24 (the chart margins). At 1280 px the SVG is 1248 px wide, so W = 1176. At 390 px it is 358, so W = 286. I measured element centers with getBoundingClientRect, with a tolerance of 0.5 px.

Categorical X (band scale: 7 bands, inner and outer padding 0.2, centered):

  • Step = W / 7.2. Center of band i = 48 + step × (i + 0.6). Bar width = 0.8 × step.
  • 1280 px:
    • Expected grid lines: 146, 309.333, 472.667, 636, 799.333, 962.667, 1126.
    • Measured grid lines: the same 7 values.
    • The 7 bars are centered on the same values. Bar width 130.667, as expected.
  • 390 px: expected and measured grid lines run from 71.833 to 310.167 (7 lines). Bar width 31.778, as expected.
  • Bar heights are proportional to the values within 1%, and in value order.

Continuous X (linear scale):

  • The domain is the data extent, [0, 24]. nice() keeps it, because the nice step is 2 and both ends are multiples of 2.
  • ticks(5) has a step of 5, so the ticks are 0, 5, 10, 15, 20. 24 is not a tick. x = 48 + value / 24 × W.
  • 1280 px:
    • Expected grid lines: 48, 293, 538, 783, 1028. Measured: the same.
    • Expected dots: 48, 244, 440, 636, 832, 1028, 1224. Measured: the same.
  • 390 px:
    • Expected grid lines: 48, 107.583, 167.167, 226.75, 286.333. Measured: the same.
    • Expected dots: 48, 95.667, 143.333, 191, 238.667, 286.333, 334. Measured: the same.
  • The dots' vertical order follows the values. There is one line path and no horizontal grid lines.

Before (production build of 2ff1afc, main before this change): Continuous X draws 6 vertical grid lines and 0 data marks in all four states. The same checks fail there.

Controls (Storybook manager, same build):

  • Categorical X: the addon panel shows only Actions and Interactions, with no Controls tab. A build without the controls.disable parameter shows a Controls tab with a tickCount control.
  • Continuous X: the Controls tab works. Moving tickCount from 5 to 2 changes the vertical grid from 5 lines to 3. The expected result for ticks(2) on [0, 24] is step 10, so 0, 10, 20.

Known current behavior, not changed here:

  • On Continuous X, the dots at 0 h and 24 h are half-clipped, because marks clip to the plot area.
  • At 390 px, the axis thins Categorical X's labels to 0, 8, 16 and 24 h, while the grid keeps all 7 lines.
  • Changing the grid's tickCount does not move the axis labels. ChartAxis has its own tickCount.

Scope

Components: ChartGrid

  • This PR changes documentation only, or names every necessary generated artifact.
  • Runtime, API, visual, and policy changes were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm exec prettier --check and pnpm exec eslint --max-warnings=0 on the changed file: pass.
  • pnpm typecheck: pass.
  • node .github/scripts/build-packages-and-storybook.mjs, then pnpm exec vitest run --project node apps/storybook/.storybook/story-tree.test.ts: 5/5 pass.
  • The built index.json compared with main's: exactly one id added (charts-chrome-chartgrid--categorical-x), none removed, none changed.
  • pnpm specs:for --diff origin/main: no record links to the changed path.
  • pnpm check:changesets: pass. No changeset: this is a Storybook-only change.
  • Rendered checks: the Evidence section above.

…he same data

The Continuous X story drew bar() on a numeric x. A bar draws only on a
band scale, so the plot showed vertical grid lines and no data. It now
draws a line with dots at the data's x values on the linear scale, over
the vertical grid lines at the d3 ticks.

A new Categorical X story draws bars from the same rows, keyed by label,
so its vertical grid lines sit on the band centers. Read together, the
two stories show that a categorical grid falls on every data point and a
continuous grid falls on the d3 ticks, which need not match the data
points. The rows are requests per minute in the 24 hours after a launch.

Categorical X disables its controls: it shows one fixed state, and the
tick count has no effect on a band scale. The Continuous X export name,
and so its story id, does not change.
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 18, 2026 2:04am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 18, 2026, 2:18 AM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 18, 2026

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Continuous X now draws data on its numeric x, and the new Categorical X story gives the band-center contrast on the same rows. The rendered guide, bar and dot positions match what ChartGrid computes for both scales, at both widths and in both modes. Nothing to change.

Claims and files checked

Review mode: full; reason: no-earlier-review

Claims:

  • The old Continuous X story drew bars on a numeric x and showed no data: verified, bar() returns no points without a band scale (packages/charts/src/marks/bar.tsx:128-130), and the previous story renders 6 guides and no mark.
  • Vertical guides on a categorical x were only reachable by turning on vertical in Playground: verified, the default args keep vertical: false (apps/storybook/stories/charts/ChartGrid.stories.tsx:27-31) and no other story showed them.
  • On a band x, guides sit on each band center; otherwise on ticks(tickCount): verified (packages/charts/src/ChartGrid.tsx:84-93).
  • An all-number x gets a linear scale with .nice(), any other x a band scale with padding 0.2: verified for the path these stories use (packages/charts/src/layout.ts:113-139).
  • Continuous X draws a dotted line on hour with the new title and keeps its export name and controls: verified (ChartGrid.stories.tsx:94-116; story id unchanged).
  • Categorical X is new, sits before Continuous X, draws bars on label with vertical guides only, and disables controls: verified (ChartGrid.stories.tsx:64-87; story order).
  • Both stories share one seven-row dataset, the old fixture is gone, and Playground is unchanged: verified (ChartGrid.stories.tsx:13-21; Playground renders pixel-identical).
  • Categorical X guide and bar positions and bar widths at 1280 px and 390 px, with heights proportional to the values: verified by rendering, every value matches.
  • Continuous X keeps the domain 0 to 24, ticks at 0 to 20, and the stated guide and dot positions at both widths: verified by rendering.
  • The previous Continuous X draws 6 guides and no data mark in all four states: verified by rendering the base.
  • Categorical X has no Controls panel, and a tick count of 2 on Continuous X gives guides at 0, 10 and 20: verified (ChartGrid.stories.tsx:86; rendered with a tick count of 2).
  • The listed existing behaviours (edge dots clipped at the plot edge, narrow category labels thinned to 0, 8, 16 and 24 h, grid tick count not moving axis labels): verified (packages/charts/src/Chart.tsx:426-436; rendered).
  • Documentation-only change with no runtime or API change and no internal context: verified (one story file; no public API rows).
  • Formatting, lint, typecheck, story-tree test, story index (one id added, none removed or changed), spec lookup and changeset check pass: verified (rerun for this review; typecheck from the CI typecheck job).

Files:

  • apps/storybook/stories/charts/ChartGrid.stories.tsx: clear.

Automated review (maintainer link)

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 51b209f

Storybook · Sandbox · built from this PR's head

Not run on this PR: add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@marie-lucas
marie-lucas merged commit 6e1aaca into main Nov 18, 2026
83 checks passed
@github-actions
github-actions Bot deleted the charts/continuous-x-grid-story branch November 18, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 51b209f7 Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant