Skip to content

Commit

Permalink
Merge pull request #5183 from rowanfr/origin/3258_Flowchart_nodeSpaci…
Browse files Browse the repository at this point in the history
…ng_Subgraph

Flowchart: Apply `nodeSpacing`/`rankSpacing` config to subgraphs
  • Loading branch information
sidharthv96 authored Mar 23, 2024
2 parents 223f339 + dbb69ad commit 12bf139
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cypress/integration/rendering/flowchart-v2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,51 @@ A ~~~ B
);
});

it('3258: Should render subgraphs with main graph nodeSpacing and rankSpacing', () => {
imgSnapshotTest(
`---
title: Subgraph nodeSpacing and rankSpacing example
---
flowchart LR
X --> Y
subgraph X
direction LR
A
C
end
subgraph Y
B
D
end
`,
{ flowchart: { nodeSpacing: 1, rankSpacing: 1 } }
);
});

it('3258: Should render subgraphs with large nodeSpacing and rankSpacing', () => {
imgSnapshotTest(
`---
title: Subgraph nodeSpacing and rankSpacing example
config:
flowchart:
nodeSpacing: 250
rankSpacing: 250
---
flowchart LR
X --> Y
subgraph X
direction LR
A
C
end
subgraph Y
B
D
end
`
);
});

describe('Markdown strings flowchart (#4220)', () => {
describe('html labels', () => {
it('With styling and classes', () => {
Expand Down
27 changes: 27 additions & 0 deletions demos/flowchart.html
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,33 @@ <h3>flowchart</h3>
</pre>
<hr />

<pre class="mermaid">
---
title: Subgraph nodeSpacing and rankSpacing example
config:
flowchart:
nodeSpacing: 1
rankSpacing: 1
---

flowchart LR

X --> Y

subgraph X
direction LR
A
C
end

subgraph Y
direction LR
B
D
end
</pre>
<hr />

<h1 id="link-clicked">Anchor for "link-clicked" test</h1>

<script type="module">
Expand Down
8 changes: 8 additions & 0 deletions packages/mermaid/src/dagre-wrapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit
if (node && node.clusterNode) {
// const children = graph.children(v);
log.info('Cluster identified', v, node.width, graph.node(v));
// `node.graph.setGraph` applies the graph configurations such as nodeSpacing to subgraphs as without this the default values would be used
// We override only the `ranksep` and `nodesep` configurations to allow for setting subgraph spacing while avoiding overriding other properties
const { ranksep, nodesep } = graph.graph();
node.graph.setGraph({
...node.graph.graph(),
ranksep,
nodesep,
});
const o = await recursiveRender(
nodes,
node.graph,
Expand Down

0 comments on commit 12bf139

Please sign in to comment.