Repository navigation
docs(charts): show ChartGrid vertical grid lines on categorical and continuous x - #12547
Merged
Merged
Conversation
…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.
marie-lucas
requested review from
cixzhang,
imdreamrunner and
josephfarina
as code owners
November 18, 2026 01:54
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
AI review status for this pull request.
|
Contributor
There was a problem hiding this comment.
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
verticalin Playground: verified, the default args keepvertical: 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
hourwith 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
labelwith 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.
Contributor
PR Analysis Report🔎 Preview ·
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reader impact
People who open
Charts/Chrome/ChartGridto learn where vertical grid lines go saw an empty plot on Continuous X. That story drewbar()on a numeric x, and a bar draws nothing on a linear scale. The categorical case was visible only if you switchedverticalon 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 atxScale(d) + bandwidth / 2for each domain value. Otherwise they sit atxScale.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 nobandwidth.Correction
One intent: show how vertical grid lines are placed on categorical vs continuous x.
charts-chrome-chartgrid--continuous-x, export name unchanged):line('requests', {dots: true})on a numerichourkey instead ofbar('value').charts-chrome-chartgrid--categorical-x, placed before Continuous X):bar('requests')on thelabelkey withhorizontal: false, vertical: true. It gives Continuous X a contrast on the same rows.tickCounthas no effect on a band scale.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):
Continuous X (linear scale):
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.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):
controls.disableparameter shows a Controls tab with atickCountcontrol.tickCountfrom 5 to 2 changes the vertical grid from 5 lines to 3. The expected result forticks(2)on [0, 24] is step 10, so 0, 10, 20.Known current behavior, not changed here:
tickCountdoes not move the axis labels. ChartAxis has its owntickCount.Scope
Components: ChartGrid
Testing
pnpm exec prettier --checkandpnpm exec eslint --max-warnings=0on the changed file: pass.pnpm typecheck: pass.node .github/scripts/build-packages-and-storybook.mjs, thenpnpm exec vitest run --project node apps/storybook/.storybook/story-tree.test.ts: 5/5 pass.index.jsoncompared 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.