Skip to content

bug/7477_fix_subgraph_direction#7479

Open
nabila401 wants to merge 1 commit intomermaid-js:developfrom
nabila401:bug/7477_fix_direction
Open

bug/7477_fix_subgraph_direction#7479
nabila401 wants to merge 1 commit intomermaid-js:developfrom
nabila401:bug/7477_fix_direction

Conversation

@nabila401
Copy link

Fixes the issue where subgraph direction is not honored correctly in flowcharts.

Previously, setting direction TB would render the subgraph horizontally. This fix ensures that the subgraph respects the specified direction (TB or LR).

I introduced a heuristic in mermaid-graphlib.js so that unlinked clusters will gracefully invert their rankdir payload so you and other users will visually get the Left-to-Right orientation expected natively.

Resolves #7477

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

⚠️ No Changeset found

Latest commit: 6e39e0e

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 13, 2026

Deploy Preview for mermaid-js ready!

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

@github-actions github-actions bot added the Type: Bug / Error Something isn't working or is incorrect label Mar 13, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 13, 2026

Open in StackBlitz

@mermaid-js/examples

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

mermaid

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

@mermaid-js/layout-elk

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

@mermaid-js/layout-tidy-tree

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

@mermaid-js/mermaid-zenuml

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

@mermaid-js/parser

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

@mermaid-js/tiny

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

commit: 6840b83

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 3.53%. Comparing base (304bdf9) to head (6e39e0e).

Files with missing lines Patch % Lines
...g-util/layout-algorithms/dagre/mermaid-graphlib.js 0.00% 17 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #7479      +/-   ##
==========================================
- Coverage     3.53%   3.53%   -0.01%     
==========================================
  Files          496     496              
  Lines        49223   49240      +17     
  Branches       772     772              
==========================================
  Hits          1741    1741              
- Misses       47482   47499      +17     
Flag Coverage Δ
unit 3.53% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...g-util/layout-algorithms/dagre/mermaid-graphlib.js 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 13, 2026

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

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 28 changed Mar 13, 2026, 12:21 AM

@nour0205
Copy link
Member

nour0205 commented Mar 13, 2026

@nabila401 Thanks for working on this. 😊😊

I tested the PR locally and it does improve the reported TB / LR behavior for edge-less subgraphs. However, after trying several variations I think this may still be compensating for a layout limitation rather than addressing the root cause.

Findings

  • Subgraphs with internal edges already render correctly.
  • The issue appears only when a subgraph has no internal edges.
  • In those cases Dagre seems to place all nodes on a single rank, so the visual layout follows same-rank placement rather than the declared direction.
  • This PR works around that by inverting rankdir for edge-less clusters.

While that improves the visual result for the reported case, it changes the requested direction instead of addressing why the cluster collapses into a single rank. In my tests, directions like BT and RL also do not appear to behave as true inverses.

Possible direction for a fix

Instead of swapping rankdir, it may be more robust to keep the declared direction and add temporary layout-only ordering constraints for edge-less clusters.

For example, if a subgraph contains:
A B C D

the layout graph could temporarily include:
A -> B -> C -> D

These edges would exist only for layout, helping Dagre distribute nodes across ranks according to the intended direction instead of collapsing them into one rank.

Tests that might help

It would also be useful to add regression coverage for:

  • TB, BT, LR, RL
  • subgraphs with and without internal edges
  • nested subgraphs

The PR definitely improves the behavior, but I wanted to share these observations in case we want to address the underlying layout issue rather than compensating for it.

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.

Flowchart subgraph direction TB and LR are swapped

2 participants