You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(xychart): label each bar series with its own values when showDataLabel is true - #8521
With showDataLabel: true and two or more bar series, every series was
labelled with the first series' values. The root cause was a single labelData variable computed at the top of draw() from plots[0]:
// before, always reads the first plotconstlabelData=db.getXYChartData().plots[0].data.map((data)=>data[1]);
That variable was then used unconditionally for every rect shape, so bar-plot-1, bar-plot-2, … all showed plots[0]'s values.
Fix
labelData is now derived inside the case 'rect': block using the
bar-plot index extracted from shape.groupTexts (bar-plot-N), so each
series reads its own plot's data:
Two new e2e fixtures added under e2e/diagrams/xychart/pr-check/:
should-label-each-bar-series-independently.mmd, vertical orientation, two bar series with distinct values
should-label-each-bar-series-independently-horizontal.mmd, same for chartOrientation: horizontal
All existing xychart unit tests (78) pass unchanged.
Summary
Fixes XY chart data labels so each bar series uses its own values when showDataLabel is enabled. The renderer uses the plot index in each bar shape’s bar-plot-N group to select that plot’s data. If the index is missing or the plot is unavailable, it falls back to the first plot.
Adds vertical and horizontal regression fixtures with two bar series. Unit tests also cover a single bar series and a line plot before the bar plots. Label placement when bars overlap remains out of scope.
Test results: The PR description reports that all 78 existing XY chart unit tests pass. The supplied information does not report results for the new unit tests or the end-to-end fixtures.
…Label is true
With showDataLabel enabled, every bar series was labelled with the first
series' values because labelData was computed once from plots[0] at the
top of draw() and then reused for all shapes.
Fix: move labelData inside the rect-shape block and derive it from the
plot whose index matches the shape's bar-plot-N group text.
Closesmermaid-js#8475
Review was skipped as selected files did not have any reviewable changes.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 646799c3-a3ed-4055-a666-d4df7dea36f0
Commits
Reviewing files that changed from the base of the PR and between 6ca81e3 and 9b7e206.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The XY chart renderer now selects data labels from the plot that matches each bar shape. Tests and regression fixtures cover multiple bar series in vertical and horizontal charts.
Changes: XY chart bar-series labels
Layer / File(s)
Summary
Plot-indexed labels and regression fixtures packages/mermaid/src/diagrams/xychart/xychartRenderer.ts, packages/mermaid/src/diagrams/xychart/xychartRenderer.spec.ts, e2e/diagrams/xychart/pr-check/should-label-each-bar-series-independently*.mmd, .changeset/xychart-datalabel-each-bar-series.md
The renderer uses each bar shape’s bar-plot- group to select plot data for labels. It defaults to plot 0 and falls back to the first plot if the indexed plot is unavailable. Tests cover vertical and horizontal bar series, a line series before bars, and a single bar series. Fixtures cover vertical and horizontal charts. The changeset records the patch.
mermaid-js/mermaid#8489: Addresses the same bar-series label issue with plot-indexed label association.
Suggested reviewers:ashishjain0512
Merge Risk: Minimal · previous review 6ca81
Bar labels now use their own series’ values. No code-level blocker was established; run the required E2E suite after adding its gating label.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title clearly and concisely states the primary fix: labeling each XY chart bar series with its own values when showDataLabel is enabled.
Linked Issues check
Issue #8475 requires per-series labels, unchanged single-series behavior, and horizontal-chart support. xychartRenderer.ts selects the bar-plot-N group for each labeled bar and reads that plot's d…
Out of Scope Changes check
The changes are limited to per-series xychart data-label selection, focused unit coverage, vertical and horizontal regression fixtures, and a changeset. They do not change label placement for overlapp…
Description check
The description states the bug (every bar series showed the first series' values when showDataLabel is true), the root cause (a single labelData computed from plots[0]), the fix (per-series labelData …
Full details: Linked Issues check
Explanation
Issue #8475 requires per-series labels, unchanged single-series behavior, and horizontal-chart support. xychartRenderer.ts selects the bar-plot-N group for each labeled bar and reads that plot's data, with a fallback to plot 0. The added Vitest cases cover multiple vertical series, one series, a line plot before a bar plot, and multiple horizontal bar series. The two e2e fixtures also cover vertical and horizontal charts with distinct values.
Full details: Out of Scope Changes check
Explanation
The changes are limited to per-series xychart data-label selection, focused unit coverage, vertical and horizontal regression fixtures, and a changeset. They do not change label placement for overlapping bars, which issue #8475 excludes.
Full details: Description check
Explanation
The description states the bug (every bar series showed the first series' values when showDataLabel is true), the root cause (a single labelData computed from plots[0]), the fix (per-series labelData derived from the bar-plot-N group), and the tests added (two e2e fixtures, vertical and horizontal) and reports that the 78 existing xychart unit tests pass. It links issue #8475. Against the template, the Summary and Design Decisions content is present. The Tasks checklist is absent: it does not state whether the contribution guidelines were read, whether unit tests were added (the raw summary shows a spec file with 66 added lines, which the description does not mention), whether documentation was updated (not applicable to a bug fix, but not addressed), or whether a changeset was created (a .changeset file is in the diff, but the description does not mention it). The description does not mention the new Vitest unit tests in xychartRenderer.spec.ts; it mentions only the e2e fixtures.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.49%. Comparing base (6d8921f) to head (9b7e206). ⚠️ Report is 295 commits behind head on develop.
Verified this end to end and it holds up. The bar-plot-N group text is built from the plot's own index in chartData.plots (the plot component passes i straight through), so allPlots[plotIdx] matches the right series even in mixed charts.
What I ran:
Parsed and rendered a two-bar-series chart with showDataLabel through the real parser and renderer in jsdom. On the base commit the second series is labelled with the first series' values; on this branch each bar shows its own value.
Same check with a line plot first and a bar plot second: the bars still get their own labels.
The xychart unit specs pass on this branch (78 tests, 5 files).
I did not run the cypress/argos e2e, but the two new fixtures cover both orientations. Nice fix.
Thanks for verifying this end to end, @charan-rathore. Good to know the mixed-chart case also holds. Ready for a review pass from a maintainer whenever you have bandwidth.
The reason will be displayed to describe this comment to others. Learn more.
The fix works and gives the same output as #8489, but this PR has no test that can fail and no changeset, so I am leaving a comment rather than an approval.
What I ran, on develop 63333fd with this branch merged (dev server, headless Chromium, texts read from each bar-plot-N group):
The issue's chart (before [380, 210, 140], after [95, 60, 130], showDataLabel: true). develop: both groups read 380, 210, 140. This branch: 380, 210, 140 and 95, 60, 130. Same for xychart horizontal, for a chart with a line series first plus three bar series, and with showDataLabelOutsideBar: true.
SVG of the 48 existing xychart fixtures plus the two new ones and four charts of mine, develop against this branch: only the new multi-series cases change (6 of 54). The same set rendered on #8489 is byte-identical to this branch.
Findings:
No unit test. The two new .mmd files under e2e/diagrams/xychart/pr-check/ are rendered and compared by Argos, but nothing asserts the labels, so a regression only shows as a screenshot difference somebody has to accept. #8489 adds a jsdom spec that fails without the fix (2 of its 3 tests do).
No changeset in the diff (git diff upstream/develop... lists three files, none under .changeset/). Fixes that change the rendered output normally ship one.
The code: parseInt(barPlotGroup.replace('bar-plot-', ''), 10) and allPlots[plotIdx]?.data ?? allPlots[0].data are fine. A bar whose label value is missing still goes through labelData[i].toString() and would throw; #8489 skips such bars.
Suggestion if you want to keep this PR: add a changeset and a small spec like the one in #8489 (render two bar series through the parser, db and renderer in jsdom and read the texts of each bar-plot-N).
Compared with #8489: same cause, same fix idea, identical rendered output. I would pick #8489 because of the unit test, the changeset and the missing-label guard; this one would then be the duplicate.
Not checked: CI results for the head commit.
The PR description ends with a "Generated with Claude Code" footer; the project asks that PR descriptions carry no AI attribution (maintainers raised it on #7859), so you may want to drop it.
You also have several venn and commonDb PRs open (#8560, #8561, #8562, #8563); I am reviewing #8560 and #8562 separately.
…abel fix
Add a jsdom spec covering the multi-series label regression: 3 of 4 tests
fail on the original renderer (all bar groups read plots[0] values) and
pass with the fix. Also add the missing patch changeset.
Done in 6ca81e3a4: added xychartRenderer.spec.ts with 4 jsdom cases (3 fail without the fix -- both series read plots[0] labels; horizontal variant included) and .changeset/xychart-datalabel-each-bar-series.md. Verified with the original renderer to confirm 3 tests fail before the fix.
The reason will be displayed to describe this comment to others. Learn more.
Approving: the two things I asked for in my earlier review are now in the PR (head 6ca81e3).
What I re-ran, with this branch merged onto current develop (a0fd6b8): vitest run packages/mermaid/src/diagrams/xychart/xychartRenderer.spec.ts, 4 tests pass. With xychartRenderer.ts restored from develop, 3 of the 4 fail ("gives each bar series its own labels", "assigns correct labels when a line series precedes two bar series", "gives each horizontal bar series its own labels"), so the spec does guard the fix. The changeset is in the diff.
The rendered output is the same as #8489 in my earlier comparison, and that has not changed; #8489 remains a fine alternative, so only one of the two is needed. I did not rerun the browser renders on this head and did not run a mutation tool.
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
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.
What this fixes
Fixes #8475.
With
showDataLabel: trueand two or more bar series, every series waslabelled with the first series' values. The root cause was a single
labelDatavariable computed at the top ofdraw()fromplots[0]:That variable was then used unconditionally for every
rectshape, sobar-plot-1,bar-plot-2, … all showedplots[0]'s values.Fix
labelDatais now derived inside thecase 'rect':block using thebar-plot index extracted from
shape.groupTexts(bar-plot-N), so eachseries reads its own plot's data:
Tests
Two new e2e fixtures added under
e2e/diagrams/xychart/pr-check/:should-label-each-bar-series-independently.mmd, vertical orientation, two bar series with distinct valuesshould-label-each-bar-series-independently-horizontal.mmd, same forchartOrientation: horizontalAll existing xychart unit tests (78) pass unchanged.
Summary
Fixes XY chart data labels so each bar series uses its own values when
showDataLabelis enabled. The renderer uses the plot index in each bar shape’sbar-plot-Ngroup to select that plot’s data. If the index is missing or the plot is unavailable, it falls back to the first plot.Adds vertical and horizontal regression fixtures with two bar series. Unit tests also cover a single bar series and a line plot before the bar plots. Label placement when bars overlap remains out of scope.
Test results: The PR description reports that all 78 existing XY chart unit tests pass. The supplied information does not report results for the new unit tests or the end-to-end fixtures.