Skip to content

Commit

Permalink
Merge pull request #1333 from spopida/bug/1327_flowchart_cutoff
Browse files Browse the repository at this point in the history
Prevent un-labelled edges that are left of the left-most vertex from being cut off the diagram
  • Loading branch information
GDFaber committed Apr 4, 2020
2 parents 933cc33 + 9d5303c commit 9f8a023
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 12 additions & 0 deletions cypress/integration/rendering/flowchart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,16 @@ describe('Flowchart', () => {
{ flowchart: { htmlLabels: false } }
);
});

it('31: should not slice off edges that are to the left of the left-most vertex', () => {
imgSnapshotTest(
`graph TD
work --> sleep
sleep --> work
eat --> sleep
work --> eat
`,
{ flowchart: { htmlLabels: false } }
);
});
});
12 changes: 4 additions & 8 deletions src/diagrams/flowchart/flowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,6 @@ export const draw = function(text, id) {
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%');
Expand All @@ -393,10 +389,10 @@ export const draw = function(text, id) {
svg.attr('width', width);
}

svg.attr('viewBox', `0 0 ${width} ${height}`);
svg
.select('g')
.attr('transform', `translate(${padding - g._label.marginx}, ${padding - svgBounds.y})`);
// Ensure the viewBox includes the whole svgBounds area with extra space for padding
const vBox = `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`;
logger.debug(`viewBox ${vBox}`);
svg.attr('viewBox', vBox);

// Index nodes
flowDb.indexNodes('subGraph' + i);
Expand Down

0 comments on commit 9f8a023

Please sign in to comment.