diff --git a/cypress/integration/rendering/flowchart.spec.js b/cypress/integration/rendering/flowchart.spec.js index 08cd977f5..a44b87bf7 100644 --- a/cypress/integration/rendering/flowchart.spec.js +++ b/cypress/integration/rendering/flowchart.spec.js @@ -2,7 +2,7 @@ import { imgSnapshotTest } from '../../helpers/util'; describe('Flowcart', () => { - it('should render a simple flowchart no htmlLabels', () => { + it('1: should render a simple flowchart no htmlLabels', () => { imgSnapshotTest( `graph TD A[Christmas] -->|Get money| B(Go shopping) @@ -14,7 +14,7 @@ describe('Flowcart', () => { { flowchart: { htmlLabels: false } } ); }); - it('should render a simple flowchart with htmlLabels', () => { + it('2: should render a simple flowchart with htmlLabels', () => { imgSnapshotTest( `graph TD A[Christmas] -->|Get money| B(Go shopping) @@ -26,7 +26,7 @@ describe('Flowcart', () => { { flowchart: { htmlLabels: true } } ); }); - it('should render a simple flowchart with line breaks', () => { + it('3: should render a simple flowchart with line breaks', () => { imgSnapshotTest( ` graph TD @@ -40,7 +40,7 @@ describe('Flowcart', () => { ); }); - it('should render a simple flowchart with trapezoid and inverse trapezoid vertex options.', () => { + it('4: should render a simple flowchart with trapezoid and inverse trapezoid vertex options.', () => { imgSnapshotTest( ` graph TD @@ -55,7 +55,7 @@ describe('Flowcart', () => { ); }); - it('should style nodes via a class.', () => { + it('4: should style nodes via a class.', () => { imgSnapshotTest( ` graph TD @@ -71,7 +71,7 @@ describe('Flowcart', () => { ); }); - it('should render a flowchart full of circles', () => { + it('5: should render a flowchart full of circles', () => { imgSnapshotTest( ` graph LR @@ -99,7 +99,7 @@ describe('Flowcart', () => { {} ); }); - it('should render a flowchart full of icons', () => { + it('6: should render a flowchart full of icons', () => { imgSnapshotTest( ` graph TD @@ -170,7 +170,7 @@ describe('Flowcart', () => { ); }); - it('should render labels with numbers at the start', () => { + it('7: should render labels with numbers at the start', () => { imgSnapshotTest( ` graph TB;subgraph "number as labels";1;end; @@ -178,7 +178,7 @@ describe('Flowcart', () => { {} ); }); - it('should render subgraphs', () => { + it('8: should render subgraphs', () => { imgSnapshotTest( ` graph TB @@ -190,7 +190,7 @@ describe('Flowcart', () => { ); }); - it('should render subgraphs with a title startign with a digit', () => { + it('9: should render subgraphs with a title startign with a digit', () => { imgSnapshotTest( ` graph TB @@ -202,7 +202,7 @@ describe('Flowcart', () => { ); }); - it('should render styled subgraphs', () => { + it('10: should render styled subgraphs', () => { imgSnapshotTest( ` graph TB @@ -237,7 +237,7 @@ describe('Flowcart', () => { ); }); - it('should render a flowchart with ling sames and class definitoins', () => { + it('11: should render a flowchart with ling sames and class definitoins', () => { imgSnapshotTest( `graph LR sid-B3655226-6C29-4D00-B685-3D5C734DC7E1[" @@ -339,7 +339,7 @@ describe('Flowcart', () => { ); }); - it('should render color of styled nodes', () => { + it('12: should render color of styled nodes', () => { imgSnapshotTest( ` graph LR diff --git a/cypress/platform/e2e.html b/cypress/platform/e2e.html index 8c1511781..4384fd0ec 100644 --- a/cypress/platform/e2e.html +++ b/cypress/platform/e2e.html @@ -1,7 +1,7 @@
- + diff --git a/src/diagrams/flowchart/flowRenderer.js b/src/diagrams/flowchart/flowRenderer.js index f290beeeb..95f9c2174 100644 --- a/src/diagrams/flowchart/flowRenderer.js +++ b/src/diagrams/flowchart/flowRenderer.js @@ -4,7 +4,12 @@ import * as d3 from 'd3'; import flowDb from './flowDb'; import flow from './parser/flow'; import { getConfig } from '../../config'; + +const newDagreD3 = true; import dagreD3 from 'dagre-d3'; +// const newDagreD3 = false; +// import dagreD3 from '../../../../dagre-d3-renderer/dist/dagre-d3.core.js'; + import addHtmlLabel from 'dagre-d3/lib/label/add-html-label.js'; import { logger } from '../../logger'; import { interpolateToCurve } from '../../utils'; @@ -271,7 +276,7 @@ export const getClasses = function(text) { * @param text * @param id */ -export const draw = function(text, id) { +export const draw = function (text, id) { logger.info('Drawing flowchart'); flowDb.clear(); const parser = flow.parser; @@ -291,18 +296,35 @@ export const draw = function(text, id) { } // Create the input mermaid.graph - const g = new graphlib.Graph({ - multigraph: true, - compound: true - }) - .setGraph({ - rankdir: dir, - marginx: 20, - marginy: 20 + let g; + // Todo remove newDagreD3 when properly verified + if (newDagreD3) { + g = new graphlib.Graph({ + multigraph: true, + compound: true }) - .setDefaultEdgeLabel(function() { - return {}; - }); + .setGraph({ + rankdir: dir, + marginx: 8, + marginy: 8 + }) + .setDefaultEdgeLabel(function () { + return {}; + }); + } else { + g = new graphlib.Graph({ + multigraph: true, + compound: true + }) + .setGraph({ + rankdir: dir, + marginx: 20, + marginy: 20 + }) + .setDefaultEdgeLabel(function () { + return {}; + }); + } let subG; const subGraphs = flowDb.getSubGraphs(); @@ -381,13 +403,31 @@ export const draw = function(text, id) { const element = d3.select('#' + id + ' g'); render(element, g); - element.selectAll('g.node').attr('title', function() { + element.selectAll('g.node').attr('title', function () { return flowDb.getTooltip(this.id); }); const conf = getConfig().flowchart; - const padding = 8; + // Todo remove newDagreD3 when properly verified + if (newDagreD3) { + const svgBounds = svg.node().getBBox(); + const width = svgBounds.width + padding * 2; + const height = svgBounds.height + padding * 2; + logger.debug(`new ViewBox 0 0 ${width} ${height}`, `translate(${padding - g._label.marginx}, ${padding - g._label.marginy})`); + + if (conf.useMaxWidth) { + svg.attr('width', '100%'); + svg.attr('style', `max-width: ${width}px;`); + } else { + svg.attr('height', height); + svg.attr('width', width); + } + + svg.attr('viewBox', `0 0 ${width} ${height}`); + svg.select('g').attr('transform', `translate(${padding - g._label.marginx}, ${padding - svgBounds.y})`); + +} else { const width = g.maxX - g.minX + padding * 2; const height = g.maxY - g.minY + padding * 2; @@ -399,9 +439,12 @@ export const draw = function(text, id) { svg.attr('width', width); } + logger.debug(`Org ViewBox 0 0 ${width} ${height}`, `translate(${padding - g.minX}, ${padding - g.minY})\n${location.href}`) + svg.attr('viewBox', `0 0 ${width} ${height}`); svg.select('g').attr('transform', `translate(${padding - g.minX}, ${padding - g.minY})`); - + // svg.select('g').attr('transform', `translate(${padding - minX}, ${padding - minY})`); +} // Index nodes flowDb.indexNodes('subGraph' + i); diff --git a/src/diagrams/state/shapes.js b/src/diagrams/state/shapes.js index b4e3cf5be..cf22fef38 100644 --- a/src/diagrams/state/shapes.js +++ b/src/diagrams/state/shapes.js @@ -416,7 +416,7 @@ export const drawEdge = function(elem, path, relation) { const rows = getRows(relation.title); - console.warn(rows); + // console.warn(rows); let titleHeight = 0; const titleRows = []; @@ -431,7 +431,6 @@ export const drawEdge = function(elem, path, relation) { if (titleHeight === 0) { const titleBox = title.node().getBBox(); titleHeight = titleBox.height; - console.warn('apa', rows.length * titleHeight); } titleRows.push(title); }