Skip to content

fix(xychart): auto-flip point labels to avoid line collision#7551

Open
DominicBurkart wants to merge 6 commits intomermaid-js:developfrom
DominicBurkart:fix/7549_xychart-label-line-collision
Open

fix(xychart): auto-flip point labels to avoid line collision#7551
DominicBurkart wants to merge 6 commits intomermaid-js:developfrom
DominicBurkart:fix/7549_xychart-label-line-collision

Conversation

@DominicBurkart
Copy link
Copy Markdown

@DominicBurkart DominicBurkart commented Mar 29, 2026

📑 Summary

When a line chart has steep slopes, per-point text labels placed above a data point collide with the line segment. This adds collision detection that auto-flips the label to the opposite side of the point when an intersection is detected.

Stacked on #7550 — please merge #7550 first.

📋 Tasks

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

claude and others added 5 commits March 29, 2026 12:59
Allow annotating individual data points on xychart line plots with
custom text labels. The syntax extends the existing data array format:

  line [540 "PaLM", 65 "LLaMA", 34 "Llama 2", 7 "Mistral"]

Each number can optionally be followed by a quoted string label.
Labels are rendered above (vertical) or to the right (horizontal)
of the data point, using the line's stroke color.

Backward-compatible: existing syntax without labels works unchanged.

Addresses mermaid-js#5326.

https://claude.ai/code/session_01CgvREhkQ3tVYCagq1mHmjV
Document the new per-point text label syntax for line charts,
including syntax examples and rendering behavior notes.

https://claude.ai/code/session_01WErEVQAYaNmC3rpbevFwMg
…labels

- Add minor changeset for the new point labels feature
- Enhance xyChart.md docs with mermaid-example block for mixed labels
  and a note about fixed font size
- Add 4 Cypress e2e snapshot tests covering: all-labeled, mixed-labels,
  horizontal orientation, and multi-line scenarios
- Add MMLU to cspell dictionary

https://claude.ai/code/session_011g3A6y2kdJnZh8YB4uJaxD
When a line segment has a steep slope, labels placed above a data point
can collide with the line. This adds collision detection that estimates
each label's bounding box and checks for intersection with adjacent line
segments using y-range overlap. When a collision is detected, the label
is flipped to the opposite side of the point (below for vertical charts,
left for horizontal charts).

https://claude.ai/code/session_01UCV1QCaRsRtQjRspaVrqUp
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 29, 2026

🦋 Changeset detected

Latest commit: b0f93a3

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

This PR includes changesets to release 1 package
Name Type
mermaid Minor

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

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 29, 2026

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit b0f93a3
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/69d0cd223b95cb00088a5009
😎 Deploy Preview https://deploy-preview-7551--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 29, 2026

Open in StackBlitz

@mermaid-js/examples

npm i https://pkg.pr.new/@mermaid-js/examples@7551

mermaid

npm i https://pkg.pr.new/mermaid@7551

@mermaid-js/layout-elk

npm i https://pkg.pr.new/@mermaid-js/layout-elk@7551

@mermaid-js/layout-tidy-tree

npm i https://pkg.pr.new/@mermaid-js/layout-tidy-tree@7551

@mermaid-js/mermaid-zenuml

npm i https://pkg.pr.new/@mermaid-js/mermaid-zenuml@7551

@mermaid-js/parser

npm i https://pkg.pr.new/@mermaid-js/parser@7551

@mermaid-js/tiny

npm i https://pkg.pr.new/@mermaid-js/tiny@7551

commit: b0f93a3

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

❌ Patch coverage is 0% with 191 lines in your changes missing coverage. Please review.
✅ Project coverage is 3.33%. Comparing base (e9d4c11) to head (b0f93a3).
⚠️ Report is 68 commits behind head on develop.

Files with missing lines Patch % Lines
...s/xychart/chartBuilder/components/plot/linePlot.ts 0.00% 182 Missing ⚠️
packages/mermaid/src/diagrams/xychart/xychartDb.ts 0.00% 9 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #7551      +/-   ##
==========================================
- Coverage     3.34%   3.33%   -0.02%     
==========================================
  Files          524     524              
  Lines        55256   55578     +322     
  Branches       795     795              
==========================================
+ Hits          1850    1853       +3     
- Misses       53406   53725     +319     
Flag Coverage Δ
unit 3.33% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...id/src/diagrams/xychart/chartBuilder/interfaces.ts 10.00% <ø> (ø)
packages/mermaid/src/diagrams/xychart/xychartDb.ts 0.00% <0.00%> (ø)
...s/xychart/chartBuilder/components/plot/linePlot.ts 0.00% <0.00%> (ø)

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…padding

- Replace shouldFlipLabelVertical/Horizontal with computeLabelPlacement
  functions that verify both above and below positions before deciding
  where to place each point label
- Try increasing offsets (1x, 2x, 3x baseOffset) if both positions
  collide at the default offset — handles zigzag patterns
- Expand collision bounding boxes by strokeWidth/2 to account for the
  visual width of the rendered line
- Increase default labelOffset from 10 to 14 for more breathing room
- Add reviewer's exact failing example to e2e tests and demo page
@argos-ci
Copy link
Copy Markdown

argos-ci bot commented Apr 4, 2026

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 2 changed, 8 added Apr 4, 2026, 8:47 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug / Error Something isn't working or is incorrect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants