Skip to content

Commit

Permalink
Merge pull request #1191 from mermaid-js/develop
Browse files Browse the repository at this point in the history
Branch update
  • Loading branch information
klemmchr committed Jan 8, 2020
2 parents b0df245 + 7760e63 commit 3db5910
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 75 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Expand Up @@ -34,6 +34,12 @@ jobs:

- name: Run Build
run: yarn build

- name: Upload Build as Artifact
uses: actions/upload-artifact@v1
with:
name: dist
path: dist

- name: Run Unit Tests
run: |
Expand Down
106 changes: 31 additions & 75 deletions src/diagrams/flowchart/flowRenderer.js
Expand Up @@ -5,10 +5,7 @@ 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 addHtmlLabel from 'dagre-d3/lib/label/add-html-label.js';
import { logger } from '../../logger';
import { interpolateToCurve } from '../../utils';
Expand Down Expand Up @@ -296,39 +293,20 @@ export const draw = function(text, id) {
const rankSpacing = conf.rankSpacing || 50;

// Create the input mermaid.graph
let g;
// Todo remove newDagreD3 when properly verified
if (newDagreD3) {
g = new graphlib.Graph({
multigraph: true,
compound: true
})
.setGraph({
rankdir: dir,
nodesep: nodeSpacing,
ranksep: rankSpacing,
marginx: 8,
marginy: 8
})
.setDefaultEdgeLabel(function() {
return {};
});
} else {
g = new graphlib.Graph({
multigraph: true,
compound: true
const g = new graphlib.Graph({
multigraph: true,
compound: true
})
.setGraph({
rankdir: dir,
nodesep: nodeSpacing,
ranksep: rankSpacing,
marginx: 8,
marginy: 8
})
.setGraph({
rankdir: dir,
nodesep: nodeSpacing,
ranksep: rankSpacing,
marginx: 20,
marginy: 20
})
.setDefaultEdgeLabel(function() {
return {};
});
}
.setDefaultEdgeLabel(function() {
return {};
});

let subG;
const subGraphs = flowDb.getSubGraphs();
Expand Down Expand Up @@ -412,49 +390,27 @@ export const draw = function(text, id) {
});

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})`);
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 {
const width = g.maxX - g.minX + padding * 2;
const height = g.maxY - g.minY + padding * 2;

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('height', height);
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._label.marginx}, ${padding - svgBounds.y})`);

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);

Expand Down

0 comments on commit 3db5910

Please sign in to comment.