Skip to content

fix(state): apply state config spacing to dagre layout#7490

Open
adi-rajput wants to merge 2 commits intomermaid-js:developfrom
adi-rajput:fix-state-diagram-spacing
Open

fix(state): apply state config spacing to dagre layout#7490
adi-rajput wants to merge 2 commits intomermaid-js:developfrom
adi-rajput:fix-state-diagram-spacing

Conversation

@adi-rajput
Copy link

Summary

Fix excessive spacing in state diagram layouts so state.nodeSpacing and state.rankSpacing are respected by the Dagre layout engine.

Currently, state diagrams may render with unnecessarily large gaps between nodes, producing long arrows and oversized diagrams. This change ensures the spacing configuration defined in state is applied when constructing the Dagre graph layout.

Safe defaults are used when values are undefined and spacing values are clamped to avoid extreme layouts.

Resolves #7381

Design Decisions

  • Apply state.nodeSpacing and state.rankSpacing to the Dagre graph layout.
  • Support both legacy and v2 state diagram renderers.
  • Use a fallback default spacing of 30 when configuration values are not provided.
  • Clamp spacing values between 10 and 200 to prevent invalid or extreme layouts.
  • Ensure nested states and loops continue to render correctly without overlapping nodes.

Tasks

Make sure you

  • 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.
  • 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:.

@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

⚠️ No Changeset found

Latest commit: b849bc0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Mar 15, 2026

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit b849bc0
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/69b6ffdcab5eac0008108027
😎 Deploy Preview https://deploy-preview-7490--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

pkg-pr-new bot commented Mar 15, 2026

Open in StackBlitz

@mermaid-js/examples

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

mermaid

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

@mermaid-js/layout-elk

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

@mermaid-js/layout-tidy-tree

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

@mermaid-js/mermaid-zenuml

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

@mermaid-js/parser

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

@mermaid-js/tiny

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

commit: b849bc0

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 0% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 3.51%. Comparing base (277c496) to head (b849bc0).

Files with missing lines Patch % Lines
...aid/src/diagrams/state/stateRenderer-v3-unified.ts 0.00% 30 Missing ⚠️
...ckages/mermaid/src/diagrams/state/stateRenderer.js 0.00% 19 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #7490      +/-   ##
==========================================
- Coverage     3.52%   3.51%   -0.01%     
==========================================
  Files          509     509              
  Lines        49790   49832      +42     
  Branches       785     785              
==========================================
  Hits          1754    1754              
- Misses       48036   48078      +42     
Flag Coverage Δ
unit 3.51% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...ckages/mermaid/src/diagrams/state/stateRenderer.js 0.00% <0.00%> (ø)
...aid/src/diagrams/state/stateRenderer-v3-unified.ts 0.00% <0.00%> (ø)
🚀 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.

@argos-ci
Copy link

argos-ci bot commented Mar 15, 2026

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

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 75 changed Mar 15, 2026, 7:01 PM

@adi-rajput
Copy link
Author

If the tests are required for the patch then i will add some tests.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HOW] stateDiagram rendering optimization

1 participant