Skip to content

perf(dashboard): limit stacked bar series by bar count - #3898

Open
karl-power wants to merge 2 commits into
mainfrom
stacked-bar-series-count
Open

karl-power wants to merge 2 commits into
mainfrom
stacked-bar-series-count

Conversation

@karl-power

@karl-power karl-power commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Caps stacked bar time charts by the number of bars drawn, so high-cardinality group-bys stay responsive, and makes the hidden-series notice account for every series the chart doesn't draw.

  • Stacked bars draw one rect per series per time bucket, so their cost scales with series × buckets. With no Series Limit set, a stacked bar chart now draws as many series as fit in 1,500 bars (10–100 series; 24 at 61 one-minute buckets) instead of 100. As with line charts, the rest stay in the legend and tooltip.
  • The limit is computed from the time range. An explicit Series Limit overrides it, and "load all" raises it to 100.
  • Over the draw cap, the chart now draws the series with the largest peak instead of the first in color order (alphabetical). A series' lines (one per value column, plus previous-period lines) are kept or dropped together, and kept lines stay in their original order so stacking and colors don't shift.
  • The hidden-series notice now also counts series loaded but past the 100-series draw cap. Previously a line chart with 101–250 series, or any chart with Series Limit 0, dropped series from the plot with no notice. "Load all" is only offered when it would show more: series were dropped, or a stacked bar chart can draw more, in which case it reads "Click to draw the top 100".
  • Display settings describe the stacked bar default ("Default (auto)", "as many as fit in 1,500 bars") instead of 250.

Screenshots or video

Screenshots not captured yet; to be added before review.

Screenshot 2026-12-03 at 17 59 02

How to reproduce

On main:

  1. Open Chart Explorer (/chart) and select the traces source.
  2. Set group by to concat('pod-', toString(cityHash64(TraceId) % 122)), select the stacked bar display, and click Run.
  3. The chart draws 100 series with no warning icon; rendering and hovering are slow. Switch to the line display: 100 lines are drawn out of ~122 with no warning.

On this branch:

  1. Repeat steps 1–2. The chart draws ~24 series and the toolbar shows a warning icon: "This query returned 122 series. 98 low-value series were hidden to keep the page responsive; showing the top 24 by peak value. Click to draw the top 100 (may be slow)."
  2. Click the warning icon. The chart draws 100 series.
  3. Switch to the line display. The warning reads "…22 low-value series were hidden…; showing the top 100 by peak value." and offers no "load all".
  4. Open Display settings. Series Limit shows the placeholder "Default (auto)" for stacked bars.

Note

Medium Risk
Changes core chart draw/cap logic and user-facing toolbar warnings across all time charts, but behavior is heavily unit-tested and scoped to rendering limits rather than data or auth.

Overview
Stacked bar charts now default to drawing only as many series as fit a 1,500-bar budget (getStackedBarSeriesCap from time range / granularity), instead of always using the 100-line draw cap. DBTimeChart passes maxDrawnLines and groupKeyByDataKey into MemoChart; explicit Series Limit, Series Limit 0, or “load all” still use the normal 100-line cap.

Over the draw limit, getVisibleLineData no longer keeps the first N lines in color order. It ranks whole series groups (value columns and previous-period lines stay together) by largest peak in graphResults, with an optional custom maxLines.

The hidden-series warning now includes series that are loaded but not drawn (undrawnSeriesCount). Copy and actions distinguish Load all vs Draw the top N when everything is already materialized. Display settings describe stacked bars as Default (auto) / “as many as fit in 1,500 bars.”

Reviewed by Cursor Bugbot for commit 8ab5d6c. Bugbot is set up for automated code reviews on this repo. Configure here.

Stacked bars draw one rect per series per time bucket, so 100 series
over 60 buckets renders 6,000 bars and takes ~4x longer than 25
series. The 100-series draw cap also kept the first series
alphabetically and dropped the rest with no notice.

- By default, draw as many stacked bar series as fit in 1,500 bars
  (10-100). An explicit seriesLimit or "load all" lifts it to 100.
- Keep the highest-peak series when the draw cap trims, preserving
  lineData order so stacking and colors don't shift.
- Count series past the draw cap in the hidden-series notice; only
  offer "load all" when it would show more.
- Describe the stacked bar default in the Series Limit setting.
@karl-power
karl-power requested a review from a team as a code owner December 3, 2026 17:01
@vercel

vercel Bot commented Dec 3, 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 Dec 3, 2026 5:38pm UTC
hyperdx-storybook Ready Ready Preview Dec 3, 2026 5:38pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8ab5d6c

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 commented Dec 3, 2026

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 109 in total (1.09%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

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

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Tier 3 — Standard

Introduces new logic, modifies core functionality, or touches areas with non-trivial risk.

Why this tier:

  • Diff size: 258 production lines changed (Tier 2 max: < 250)

Review process: Full human review — logic, architecture, edge cases.
SLA: First-pass feedback within 1 business day.

Stats
  • Production files changed: 8
  • Production lines changed: 258 (+ 385 in test files, excluded from tier calculation)
  • Branch: stacked-bar-series-count
  • Author: karl-power

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

(dateRange[1].getTime() - dateRange[0].getTime()) /
(convertGranularityToSeconds(granularity) * 1000),
);
return Math.min(

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.

🟡 P2 — maxDrawnSeries counts lines, but seriesLimit and the notice's counts are logical groups

Measure the draw cap in groups (or convert it), and make loadAllDrawCount in useChartToolbarItems.tsx use the same unit. Example: 2 value columns × 60 groups gives 120 lines. The notice offers "Draw all 60" because min(HARD_LINES_LIMIT, renderedSeriesCount) = 60 ≥ 60. After the click, only 100 lines (50 groups) are drawn, and the notice then reports 10 hidden groups with no further action. In the same way, an explicit seriesLimit: 40, which the SQL applies to groups, becomes a 40-line cap, so only 20 groups are drawn.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 8ab5d6c. The draw cap still bounds lines, but it now keeps or drops whole series, and the notice and "Draw the top N" count series. An explicit Series Limit lifts the stacked bar budget instead of becoming a line cap.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

3 finding(s): 🔴 0 P0/P1 · 🟡 3 P2 · 🔵 0 P3

2 posted as inline comment(s) on the changed lines. 1 listed below.

Findings outside the changed lines

  • 🟡 P2 packages/app/src/HDXMultiSeriesTimeChart/chartData.ts:315 — Draw-cap ranking re-implements the peak-per-group ranking already in formatResponseForTimeChart, and drops its current-period priority → formatResponseForTimeChart (packages/app/src/ChartUtils.tsx:1002-1047) already computes peakByGroup per groupKeyByDataKey group and ranks current-period groups ahead of previous-only groups. That way a series that only exists in the previous period can't push out a current one. The new getVisibleLineData repeats the peak scan but ranks all groups together. On a compare-to-previous-period line chart with more than 100 groups, a high-peak previous-only group can now replace a current-period series on the plot, even though the load cap keeps it. Fix: compute the ranked group order once in formatResponseForTimeChart, using the same current-first policy, return it next to groupKeyByDataKey, and have getVisibleLineData walk that list instead of rescanning.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This is a client-side chart-rendering/UX change (TypeScript/React, ~230 production lines, no auth/API/DB/persistence). The prior Cursor Bugbot "draw cap splits multi-aggregation groups" concern was independently verified as resolved: getVisibleLineData's group ranking and the drawnSeriesCount/undrawnSeriesCount notice counts both key off the same groupKeyByDataKey map, so a group's avg/max lines and its current/previous-period pair are now kept or dropped together. Core new behavior (getStackedBarSeriesCap clamping, group-together ranking, top-group-over-cap, label branches) is well covered by new unit tests.

🟡 P2 -- recommended

  • packages/app/src/components/charts/__tests__/HiddenSeriesIndicator.test.tsx:94 -- the default high-cardinality path (both hiddenSeriesCount > 0 and undrawnSeriesCount > 0) drives the new shown = renderedSeriesCount - undrawnSeriesCount and total - shown label math, but every test exercises only one of the two counts at a time, so a sign or off-by-one error in the combined copy would ship silently.
    • Fix: Add a case with both hiddenSeriesCount and undrawnSeriesCount non-zero and assert the exact "returned N series / M hidden / showing the top K" text.
🔵 P3 nitpicks (6)
  • packages/app/src/HDXMultiSeriesTimeChart/chartData.ts:160 -- the stacked-bar draw cap (as low as MIN_DEFAULT_STACKED_BAR_SERIES = 10) is applied to an already-selected set, so isolating or checkbox-selecting more series than the cap drops chosen series from the chart while the legend and pinned drill-down still list them, contradicting the function's "an explicitly chosen series always draws" contract.
    • Fix: Skip the group cap, or cap only at HARD_LINES_LIMIT, when hasSeriesSelection(selectedSeriesNames) is true.
    • correctness, adversarial
  • packages/app/src/components/DBTimeChart/DBTimeChart.tsx:503 -- drawnSeriesCount, undrawnSeriesCount, and the load-all gating are computed with selectedSeriesNames undefined, so while a legend selection is active the notice's "showing the top N by peak value" and hidden count describe the whole query rather than the smaller set actually drawn.
    • Fix: Pass the live selection into the count, or suppress the undrawn notice while a selection is active.
    • adversarial
  • packages/app/src/HDXMultiSeriesTimeChart/chartData.ts:171 -- getVisibleLineData ranks groups with a dense graphResults × selected loop (and drawnSeriesCount invokes it twice per recompute), where formatResponseForTimeChart already does the same per-group peak computation over only populated cells to stay sparse-friendly on the exact high-cardinality case this PR targets.
    • Fix: Rank by iterating each row's populated cells via groupKeyByDataKey, and compute the ranked groups once for both the lowered cap and the HARD_LINES_LIMIT count.
    • performance, kieran-typescript
  • packages/app/src/HDXMultiSeriesTimeChart/chartData.ts:168 -- the peak group-ranking is now implemented twice (materialize cap in ChartUtils.tsx vs draw cap here), and the draw-cap copy omits the current-period-priority the materialize cap applies, so the two can select different groups for comparison charts and will drift on future edits.
    • Fix: Extract one shared peak-ranking helper, or document why the draw cap intentionally omits current-period priority.
    • maintainability
  • packages/app/src/components/DBTimeChart/DBTimeChart.tsx:513 -- the group-identity expression groupKeyByDataKey.get(key) ?? currentPeriodKey is duplicated here and in getVisibleLineData, so a change to how a line maps to its group must be made in both places or the reported counts drift from what is drawn.
    • Fix: Export the groupOf helper from chartData.ts and call it at this count site.
    • maintainability
  • packages/app/src/HDXMultiSeriesTimeChart/chartData.ts:192 -- the "always keep the top group" branch can draw a single multi-value-column group whose line count exceeds the 1,500-bar budget, yielding undrawnSeriesCount = 0 and no notice, silently voiding the budget the PR exists to enforce.
    • Fix: Count the top group's lines against the budget, or surface a notice when the top group alone exceeds it.
    • adversarial

Reviewers (10): correctness, adversarial, kieran-typescript, performance, testing, maintainability, project-standards, previous-comments, agent-native, learnings-researcher.

Testing gaps:

  • No test clicks "Draw the top N" to confirm the stacked-bar cap lifts to HARD_LINES_LIMIT (the showAllSeries branch of maxDrawnLines).
  • The StackedBar + seriesLimit === 0 branch of maxDrawnLines is never reached (the seriesLimit: 0 test runs on a line chart).
  • getStackedBarSeriesCap with a negative bucket count, and getVisibleLineData with NaN/non-number graphResults values, are unasserted edge branches.

Note: the touched files (DBTimeChart.tsx, MemoChart.tsx, ChartDisplaySettingsDrawer.tsx) already exceed the project's 300-line guideline, but this is pre-existing and not introduced by the diff.

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e016889. Configure here.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 500 passed • 1 skipped • 1112s

Status Count
✅ Passed 500
❌ Failed 0
⚠️ Flaky 12
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

The draw cap ranked and counted individual lines, while the notice and
seriesLimit count series. On charts with several value columns this
split a series' lines, offered "Draw all N" for more series than fit,
and turned an explicit seriesLimit into a line cap.

- Rank series by peak and keep or drop all of a series' lines together,
  still bounded by the line cap.
- Lift the stacked bar budget for an explicit seriesLimit instead of
  capping lines to it.
- Count drawn and "load all" series in the notice's unit.
@karl-power

Copy link
Copy Markdown
Contributor Author

Review follow-up (8ab5d6c):

  • Group splitting with several value columns (Claude review P2, Bugbot, deep review): fixed. The draw cap now ranks and keeps whole series using the transform's groupKeyByDataKey, so its counts match the notice.
  • Sharing one ranking implementation with formatResponseForTimeChart: leaving that out of this PR, since it means refactoring the transform's materialize cap. Both rankings now use the same group key.
  • Peak scan running in both DBTimeChart and MemoChart: kept. It only runs over the cap and is O(buckets × loaded lines), with at most 250 series loaded by default.
  • Tests: added a getVisibleLineData case for a series with several value columns, and a DBTimeChart case checking the drawn and "load all" counts with two value columns. I didn't add a test for the maxDrawnLines prop forwarding to MemoChart.

@github-actions github-actions Bot added review/tier-3 Standard — full human review required and removed review/tier-2 Low risk — AI review + quick human skim labels Dec 3, 2026
@@ -283,8 +290,21 @@ export const MemoChart = memo(function MemoChart({
);

const visibleLineData = useMemo(

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.

🟡 P2 — The visible-line cap now scans every bucket × line on each selection change and runs up to three times per data change

Before this PR, getVisibleLineData was a slice. It now loops over graphResults × selected (up to 5,000 loaded series after "load all" × every bucket). It runs in MemoChart whenever selectedSeriesNames changes, for example on each keystroke in the legend table search. It also runs once or twice more in DBTimeChart's countDrawn (DBTimeChart.tsx:503-522), with the same unselected inputs MemoChart then repeats. The existing scan in ChartUtils.tsx:1002 avoids this by visiting only populated cells. Fix: precompute a peak rank per group once per result, as in the previous finding. The cap then becomes a linear walk, and DBTimeChart can pass the drawn set down instead of recomputing it.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

? `Maximum number of series rendered, keeping those with the largest values. Leave empty for the default (${MAX_RENDERED_TIME_CHART_SERIES}); set 0 for unlimited.`
: `Maximum number of series fetched for a group-by chart, keeping those with the largest values. Leave empty for the default (${MAX_RENDERED_TIME_CHART_SERIES}); set 0 for unlimited.`
? `Maximum number of series rendered, keeping those with the largest values. Leave empty for the default (${seriesLimitDefault}); set 0 for unlimited.`
: `Maximum number of series fetched for a group-by chart, keeping those with the largest values. Leave empty for the default (${seriesLimitDefault}); set 0 for unlimited.`

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.

🟡 P2 — Builder stacked-bar help text says the fetch default is "as many as fit in 1,500 bars", but the bar budget only limits drawing

For builder charts the description reads "Maximum number of series fetched… Leave empty for the default (as many as fit in 1,500 bars)". An empty limit still loads up to MAX_RENDERED_TIME_CHART_SERIES (250). The bar budget only limits what is drawn (DBTimeChart maxDrawnLines). Any explicit value, even 250, switches the draw limit back to 100. Fix: keep the fetch default as 250 in this sentence and add a separate clause that stacked bars draw only as many series as fit in 1,500 bars unless a limit is set.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 8ab5d6c5 Deployed Dec 3, 2026 by vercel[bot]
Preview – hyperdx-storybook — 8ab5d6c5 Deployed Dec 3, 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-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants