Repository navigation
fix(app): keep stacked chart Y-axis labels distinct - #3701
alex-fedotyev wants to merge 1 commit into
Conversation
Stacked bar and stacked line charts skipped the Y-axis tick logic that keeps labels distinct, so Recharts picked the ticks and a 0-decimal number format could give two of them the same label (1500 and 2000 both read "2k"). Size the stacked axis from the per-timestamp stack total and send it through the same zero-pinned tick path line charts use. A legend selection only narrows which series are summed and fit-to-data only applies to line charts, so neither changes a stack's axis. A stack holding a negative value, or a chart with a reference line, keeps Recharts' default domain as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 846433d The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
PR Review✅ No issues found. |
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
Deep Review✅ No critical issues found. The change is well-scoped and well-tested: 🟡 P2 — recommended
🔵 P3 nitpicks (1)
Reviewers (5): correctness, adversarial, testing, maintainability, kieran-typescript. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results✅ All tests passed • 466 passed • 1 skipped • 1174s
Tests ran across 4 shards in parallel. |
|
Deep review: no code change for either finding.
|
|
Closing in favor of #3699, which landed the same fix and also handles stacks with negative values, which this PR left to Recharts. |
Stacked bar and stacked line charts could give two Y-axis ticks the same label, for example two
2kticks on a stacked area tile. Only the labels were wrong; the plotted data and the tooltips were right.Summary
computeYAxisBoundsreturned Recharts' default domain ([0, 'auto']) for stacked charts before anything else ran, so they never reached the distinct-label tick logic from #3172. Recharts picked its own ticks, andformatAxisTickrounds abbreviated values to the format's decimals. With 0 decimals, a stack peaking at about 1,900 got ticks at 0, 500, 1000, 1500 and 2000, labeled0, 500, 1k, 2k, 2k.Stacked charts now size the axis from the stack total at each timestamp (new
scanStackedYAxisValueRange) and take the same zero-pinned branch line charts use, sogetExpandableYAxisTickspicks the ticks and adds a decimal when labels would repeat. The same stack now reads0, 500, 1k, 1.5k, 2k.Why
stackOffset, so a stack holding one keeps Recharts' own stacked domain. A reference line keeps deferring to Recharts, the same as in the line chart's zero-pinned branch.Screenshots or video
Same seeded data (three services stacking to a 1,877 per minute peak), Number format with 0 decimals, 1 minute granularity, at 1400px wide and at a narrow 560px viewport:
How to reproduce
Starting point:
yarn app:dev:localconnected to the demo server (onboarding, then Connect to Demo Server), or the Vercel preview on this PR.On
main:ServiceName IN ('email', 'payment', 'currency'), set Group By toServiceName, and pick 1 Minute Granularity.2k. On the demo data this stack peaks between about 1,850 and 2,400 per minute in most hours, which is where Recharts' ticks collide.On this branch:
0, 500, 1k, 1.5k, 2k, with no repeats.How to test on Vercel preview
Preview routes: /chart?config=%7B%22name%22%3A%22%22%2C%22source%22%3A%22Demo%20Logs%22%2C%22displayType%22%3A%22stacked_line%22%2C%22select%22%3A%5B%7B%22aggFn%22%3A%22count%22%2C%22aggCondition%22%3A%22%22%2C%22aggConditionLanguage%22%3A%22sql%22%2C%22valueExpression%22%3A%22%22%7D%5D%2C%22where%22%3A%22ServiceName%20IN%20('email'%2C%20'payment'%2C%20'currency')%22%2C%22whereLanguage%22%3A%22sql%22%2C%22groupBy%22%3A%22ServiceName%22%2C%22granularity%22%3A%221%20minute%22%2C%22numberFormat%22%3A%7B%22output%22%3A%22number%22%2C%22mantissa%22%3A0%7D%7D
Steps:
ServiceNameto render.Test plan
scanStackedYAxisValueRangesums only the series it's given, skips missing and non-numeric values, returns an empty range with no data, and sums negative values apart from positive onescomputeYAxisBoundssizes a 60 + 40 stack to 100 with and without a selection or fit-to-data, gives the reported stack0, 500, 1k, 1.5k, 2k, and keeps the Recharts default for a negative value, a reference line, and an all-zero stack; the 8 new behavior tests fail onmainci:lint(eslint, tsc, stylelint), ratchet, dupes, knipReferences