diff --git a/cypress/integration/rendering/flowchart-v2.spec.js b/cypress/integration/rendering/flowchart-v2.spec.js new file mode 100644 index 000000000..222f8d74c --- /dev/null +++ b/cypress/integration/rendering/flowchart-v2.spec.js @@ -0,0 +1,31 @@ +/* eslint-env jest */ +import { imgSnapshotTest } from '../../helpers/util'; + +describe('Flowchart v2', () => { + it('1: should render a simple flowchart', () => { + imgSnapshotTest( + `flowchart TD + A[Christmas] -->|Get money| B(Go shopping) + B --> C{Let me think} + C -->|One| D[Laptop] + C -->|Two| E[iPhone] + C -->|Three| F[fa:fa-car Car] + `, + {} + ); + }); + + it('2: should render a simple flowchart with diagramPadding set to 0', () => { + imgSnapshotTest( + `flowchart 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: { diagramPadding: 0 } } + ); + }); +}); diff --git a/cypress/integration/rendering/flowchart.spec.js b/cypress/integration/rendering/flowchart.spec.js index 4acccfc37..22f51fcca 100644 --- a/cypress/integration/rendering/flowchart.spec.js +++ b/cypress/integration/rendering/flowchart.spec.js @@ -671,4 +671,18 @@ describe('Flowchart', () => { { flowchart: { htmlLabels: false } } ); }); + + it('33: should render a simple flowchart with diagramPadding set to 0', () => { + 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: { diagramPadding: 0 } } + ); + }); }); diff --git a/docs/Setup.md b/docs/Setup.md index 15c10d91d..7156dd230 100644 --- a/docs/Setup.md +++ b/docs/Setup.md @@ -734,7 +734,7 @@ mermaidAPI.initialize({ provided a hidden div will be inserted in the body of the page instead. The element will be removed when rendering is completed. -## +## ## mermaidAPI configuration defaults @@ -749,6 +749,7 @@ mermaidAPI.initialize({ arrowMarkerAbsolute:false, flowchart:{ + diagramPadding:8, htmlLabels:true, curve:'linear', }, @@ -803,7 +804,7 @@ Returns **any** the siteConfig Obtains the current siteConfig base configuration -Returns **any** +Returns **any** ## setConfig diff --git a/src/config.js b/src/config.js index 5f254342c..ac09e77ca 100644 --- a/src/config.js +++ b/src/config.js @@ -118,6 +118,16 @@ const config = { * The object containing configurations specific for flowcharts */ flowchart: { + /** + *| Parameter | Description |Type | Required | Values| + *| --- | --- | --- | --- | --- | + *| diagramPadding | amount of padding around the diagram as a whole | Integer | Required | Any Positive Value | + * + ***Notes:**The amount of padding around the diagram as a whole so that embedded diagrams have margins, expressed in pixels + ***Default value: 8**. + */ + diagramPadding: 8, + /** *| Parameter | Description |Type | Required | Values| *| --- | --- | --- | --- | --- | diff --git a/src/diagrams/flowchart/flowRenderer-v2.js b/src/diagrams/flowchart/flowRenderer-v2.js index 3ffa4a0c1..b03991ec9 100644 --- a/src/diagrams/flowchart/flowRenderer-v2.js +++ b/src/diagrams/flowchart/flowRenderer-v2.js @@ -381,7 +381,7 @@ export const draw = function(text, id) { return flowDb.getTooltip(this.id); }); - const padding = 8; + const padding = conf.diagramPadding; const svgBounds = svg.node().getBBox(); const width = svgBounds.width + padding * 2; const height = svgBounds.height + padding * 2; diff --git a/src/diagrams/flowchart/flowRenderer.js b/src/diagrams/flowchart/flowRenderer.js index 76821993d..51ef4edd5 100644 --- a/src/diagrams/flowchart/flowRenderer.js +++ b/src/diagrams/flowchart/flowRenderer.js @@ -394,7 +394,7 @@ export const draw = function(text, id) { return flowDb.getTooltip(this.id); }); - const padding = 8; + const padding = conf.diagramPadding; const svgBounds = svg.node().getBBox(); const width = svgBounds.width + padding * 2; const height = svgBounds.height + padding * 2; diff --git a/src/mermaidAPI.js b/src/mermaidAPI.js index 6b0ce1808..a0eba8fa4 100644 --- a/src/mermaidAPI.js +++ b/src/mermaidAPI.js @@ -577,6 +577,7 @@ export default mermaidAPI; * arrowMarkerAbsolute:false, * * flowchart:{ + * diagramPadding:8, * htmlLabels:true, * curve:'linear', * },