Skip to content

fix(app): keep stacked chart Y-axis labels distinct - #3701

Closed
alex-fedotyev wants to merge 1 commit into
mainfrom
alex/HDX-6064-stacked-axis-duplicate-labels
Closed

alex-fedotyev wants to merge 1 commit into
mainfrom
alex/HDX-6064-stacked-axis-duplicate-labels

Conversation

@alex-fedotyev

Copy link
Copy Markdown
Contributor

Stacked bar and stacked line charts could give two Y-axis ticks the same label, for example two 2k ticks on a stacked area tile. Only the labels were wrong; the plotted data and the tooltips were right.

Summary

computeYAxisBounds returned 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, and formatAxisTick rounds 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, labeled 0, 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, so getExpandableYAxisTicks picks the ticks and adds a decimal when labels would repeat. The same stack now reads 0, 500, 1k, 1.5k, 2k.

Why

  • Stack total, not the largest series. During fix: keep Y-axis ticks evenly spaced when Recharts thins them for overlap #3172's review, sizing stacked charts from each series' own max clipped stacks (60 + 40 drawn as 100 under a 63 axis), so that PR left stacked charts to Recharts. Summing the drawn series at each timestamp gives the height Recharts renders, so the axis still covers the whole stack.
  • Selection and fit-to-data don't change a stack's axis. A legend selection only narrows which series are drawn and summed, and Fit Y-Axis to Data applies to line charts only. A stack stays pinned at zero in both cases, as before.
  • Negative values and reference lines keep the Recharts default. Where a negative value lands in a stack depends on Recharts' 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:

Before After
before stacked line light after stacked line light
before stacked bar dark after stacked bar dark
before stacked line dark narrow after stacked line dark narrow

How to reproduce

Starting point: yarn app:dev:local connected to the demo server (onboarding, then Connect to Demo Server), or the Vercel preview on this PR.

On main:

  1. Open Chart explorer and pick the Demo Logs source.
  2. Keep Count of Events, set Where (SQL) to ServiceName IN ('email', 'payment', 'currency'), set Group By to ServiceName, and pick 1 Minute Granularity.
  3. Open Display Settings, move Decimals to 0, and click Apply.
  4. Click Run, then switch the chart to Display as stacked line chart (or stacked bar).
  5. Two Y-axis ticks read 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:

  1. Same steps. The ticks read 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:

  1. Open the preview route. If the Welcome to ClickStack dialog appears, click Connect to Demo Server, then open the preview route again.
  2. Wait for the stacked line chart of Demo Logs event counts grouped by ServiceName to render.
  3. Verify that no two Y-axis tick labels have the same text.

Test plan

  • unit: scanStackedYAxisValueRange sums 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 ones
  • unit: computeYAxisBounds sizes a 60 + 40 stack to 100 with and without a selection or fit-to-data, gives the reported stack 0, 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 on main
  • full app unit suite, app ci:lint (eslint, tsc, stylelint), ratchet, dupes, knip
  • manual, local stack with seeded logs: stacked line and stacked bar, light and dark, wide and narrow viewport, before and after; isolating two series from the legend also keeps the labels distinct
  • States: an empty or all-zero stack falls back to the Recharts default axis as before; the chart's loading and error rendering is untouched

References

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>
@alex-fedotyev
alex-fedotyev requested a review from a team as a code owner November 17, 2026 21:30
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 17, 2026 9:33pm UTC
hyperdx-storybook Ready Ready Preview Nov 17, 2026 9:33pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 846433d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

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

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 1
  • Production lines changed: 54 (+ 176 in test files, excluded from tier calculation)
  • Branch: alex/HDX-6064-stacked-axis-duplicate-labels
  • Author: alex-fedotyev

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

Copy link
Copy Markdown
Contributor

PR Review

✅ No issues found.

@github-actions

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 108 in total (1.17%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. The change is well-scoped and well-tested: visibleLineData is exactly the set Recharts stacks (all series share stackId="1"), so scanStackedYAxisValueRange summing those series matches the rendered stack height, and the negative/reference-line/all-zero/empty fallbacks all resolve to the Recharts default as intended.

🟡 P2 — recommended

  • packages/app/src/HDXMultiSeriesTimeChart.tsx:1517 — Stacked charts now commit an explicit numeric Y-domain ([0, max*1.05]) that Recharts will not widen, but scanStackedYAxisValueRange skips null/NaN cells while stacked Areas render with connectNulls, so a stacked-line series with an interior null at the stack's peak bucket can interpolate a rendered stack top above the fixed domain and clip the area.
    • Fix: Confirm whether Recharts treats an intra-series null as 0 in the stacked baseline or interpolates it, and if it interpolates, fall back to DEFAULT_Y_AXIS_BOUNDS for stacked lines containing interior nulls (or account for the bridged contribution when scanning); add a regression test for that case.
    • adversarial
🔵 P3 nitpicks (1)
  • packages/app/src/HDXMultiSeriesTimeChart.tsx:1141 — New scanStackedYAxisValueRange types graphResults as Record<string, unknown>[] while the sibling scanYAxisValueRange and the shared computeYAxisBounds caller keep any[], so the stricter annotation adds no real boundary safety and implies a difference that does not exist.
    • Fix: Use one element type across scanYAxisValueRange, scanStackedYAxisValueRange, and computeYAxisBounds, preferring the stricter Record<string, unknown>[].
    • maintainability, kieran-typescript

Reviewers (5): correctness, adversarial, testing, maintainability, kieran-typescript.

Testing gaps:

  • No test for a stacked line with interior nulls + connectNulls asserting the rendered stack top never exceeds the computed explicit domain (ties to the P2 above).
  • No test where the top-contributing series differs across timestamps, to lock in that the domain tracks the per-timestamp stack maximum rather than a single series.

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

@github-actions

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 466 passed • 1 skipped • 1174s

Status Count
✅ Passed 466
❌ Failed 0
⚠️ Flaky 2
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@alex-fedotyev

Copy link
Copy Markdown
Contributor Author

Deep review: no code change for either finding.

  • P2 (interior nulls with connectNulls): not reachable with Recharts 3.9.1. Stacking reads each cell as Number(getValueByDataKey(d, key, 0)), so a null stacks as 0, and with connectNulls a stacked point only breaks when its stacked value is null (computeArea). The null bucket is drawn at the series' base, which is what scanStackedYAxisValueRange counts. A NaN cell does get bridged, but only between that series' neighboring points, whose stack heights are already in the scanned max, and the monotone, linear and step curves don't overshoot them. Recharts also widens a numeric domain to fit the stacked data while allowDataOverflow is off (extendDomain in parseNumericalUserDomain), so a short max would cost a top tick, not clip the area.
  • P3 (Record<string, unknown>[] vs any[]): keeping the stricter type on the new function; retyping scanYAxisValueRange, computeYAxisBounds and the graphResults prop they read from is a separate cleanup outside this fix.
  • Testing gap, top series changing across timestamps: covered by sums the series it is given at each timestamp, where b leads the first bucket and a the second; summing each series' max would give 70 instead of 50.

@alex-fedotyev

Copy link
Copy Markdown
Contributor Author

Closing in favor of #3699, which landed the same fix and also handles stacks with negative values, which this PR left to Recharts.

@alex-fedotyev
alex-fedotyev deleted the alex/HDX-6064-stacked-axis-duplicate-labels branch November 17, 2026 23:12

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 846433d7 Deployed Nov 17, 2026 by vercel[bot]
Preview – hyperdx-storybook — 846433d7 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant