mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-03 23:56:44 +02:00
#1152 add node spacing to flowchart configuration
This commit is contained in:
@@ -474,4 +474,30 @@ describe('Flowchart', () => {
|
|||||||
{ flowchart: { htmlLabels: false } }
|
{ flowchart: { htmlLabels: false } }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('22: Render a simple flowchart with nodeSpacing set to 100', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`graph TD
|
||||||
|
A[Christmas] -->|Get money| B(Go shopping)
|
||||||
|
B --> C{Let me think}
|
||||||
|
%% this is a comment
|
||||||
|
C -->|One| D[Laptop]
|
||||||
|
C -->|Two| E[iPhone]
|
||||||
|
C -->|Three| F[fa:fa-car Car]
|
||||||
|
`,
|
||||||
|
{ flowchart: { nodeSpacing: 50 } }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('23: Render a simple flowchart with rankSpacing set to 100', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`graph TD
|
||||||
|
A[Christmas] -->|Get money| B(Go shopping)
|
||||||
|
B --> C{Let me think}
|
||||||
|
%% this is a comment
|
||||||
|
C -->|One| D[Laptop]
|
||||||
|
C -->|Two| E[iPhone]
|
||||||
|
C -->|Three| F[fa:fa-car Car]
|
||||||
|
`,
|
||||||
|
{ flowchart: { rankSpacing: '100' } }
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -27,7 +27,6 @@ mermaid.initialize({
|
|||||||
**Example 2:**
|
**Example 2:**
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<script>
|
|
||||||
var config = {
|
var config = {
|
||||||
startOnLoad:true,
|
startOnLoad:true,
|
||||||
flowchart:{
|
flowchart:{
|
||||||
@@ -39,8 +38,6 @@ mermaid.initialize({
|
|||||||
securityLevel:'loose',
|
securityLevel:'loose',
|
||||||
};
|
};
|
||||||
mermaid.initialize(config);
|
mermaid.initialize(config);
|
||||||
</script>
|
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
A summary of all options and their defaults is found [here](https://github.com/knsv/mermaid/blob/master/docs/mermaidAPI.md#mermaidapi-configuration-defaults). A description of each option follows below.
|
A summary of all options and their defaults is found [here](https://github.com/knsv/mermaid/blob/master/docs/mermaidAPI.md#mermaidapi-configuration-defaults). A description of each option follows below.
|
||||||
|
|
||||||
@@ -105,6 +102,18 @@ Flag for setting whether or not a html tag should be used for rendering labels
|
|||||||
on the edges.
|
on the edges.
|
||||||
**Default value true**.
|
**Default value true**.
|
||||||
|
|
||||||
|
### nodeSpacing
|
||||||
|
|
||||||
|
Defines the spacing between nodes on the same level (meaning horizontal spacing for
|
||||||
|
TB or BT graphs, and the vertical spacing for LR as well as RL graphs).
|
||||||
|
**Default value 50**.
|
||||||
|
|
||||||
|
### rankSpacing
|
||||||
|
|
||||||
|
Defines the spacing between nodes on different levels (meaning vertical spacing for
|
||||||
|
TB or BT graphs, and the horizontal spacing for LR as well as RL graphs).
|
||||||
|
**Default value 50**.
|
||||||
|
|
||||||
### curve
|
### curve
|
||||||
|
|
||||||
How mermaid renders curves for flowcharts. Possible values are
|
How mermaid renders curves for flowcharts. Possible values are
|
||||||
|
@@ -291,6 +291,10 @@ export const draw = function(text, id) {
|
|||||||
dir = 'TD';
|
dir = 'TD';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const conf = getConfig().flowchart;
|
||||||
|
const nodeSpacing = conf.nodeSpacing || 50;
|
||||||
|
const rankSpacing = conf.rankSpacing || 50;
|
||||||
|
|
||||||
// Create the input mermaid.graph
|
// Create the input mermaid.graph
|
||||||
let g;
|
let g;
|
||||||
// Todo remove newDagreD3 when properly verified
|
// Todo remove newDagreD3 when properly verified
|
||||||
@@ -301,6 +305,8 @@ export const draw = function(text, id) {
|
|||||||
})
|
})
|
||||||
.setGraph({
|
.setGraph({
|
||||||
rankdir: dir,
|
rankdir: dir,
|
||||||
|
nodesep: nodeSpacing,
|
||||||
|
ranksep: rankSpacing,
|
||||||
marginx: 8,
|
marginx: 8,
|
||||||
marginy: 8
|
marginy: 8
|
||||||
})
|
})
|
||||||
@@ -314,6 +320,8 @@ export const draw = function(text, id) {
|
|||||||
})
|
})
|
||||||
.setGraph({
|
.setGraph({
|
||||||
rankdir: dir,
|
rankdir: dir,
|
||||||
|
nodesep: nodeSpacing,
|
||||||
|
ranksep: rankSpacing,
|
||||||
marginx: 20,
|
marginx: 20,
|
||||||
marginy: 20
|
marginy: 20
|
||||||
})
|
})
|
||||||
@@ -403,7 +411,6 @@ export const draw = function(text, id) {
|
|||||||
return flowDb.getTooltip(this.id);
|
return flowDb.getTooltip(this.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
const conf = getConfig().flowchart;
|
|
||||||
const padding = 8;
|
const padding = 8;
|
||||||
// Todo remove newDagreD3 when properly verified
|
// Todo remove newDagreD3 when properly verified
|
||||||
if (newDagreD3) {
|
if (newDagreD3) {
|
||||||
|
Reference in New Issue
Block a user