1234-RefactorDiagramScaling

Changed implementation to ensure that viewport is aligned correctly, rather than increasing size
This commit is contained in:
Justin Greywolf
2020-04-26 06:10:18 -07:00
parent ef17f4eacb
commit 08e015a951

View File

@@ -226,14 +226,21 @@ export const draw = function(text, id) {
} }
}); });
diagram.attr('height', g.graph().height + 40);
diagram.attr('width', g.graph().width * 1.5 + 20);
const svgBounds = diagram.node().getBBox(); const svgBounds = diagram.node().getBBox();
const width = svgBounds.width + padding * 2; const width = svgBounds.width + padding * 2;
const height = svgBounds.height + padding * 2; const height = svgBounds.height + padding * 2;
if (conf.useMaxWidth) {
diagram.attr('width', '100%');
diagram.attr('style', `max-width: ${width}px;`);
} else {
diagram.attr('height', height);
diagram.attr('width', width);
}
// Ensure the viewBox includes the whole svgBounds area with extra space for padding
const vBox = `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`; const vBox = `${svgBounds.x - padding} ${svgBounds.y - padding} ${width} ${height}`;
logger.debug(`viewBox ${vBox}`);
diagram.attr('viewBox', vBox); diagram.attr('viewBox', vBox);
}; };