From 08e015a9518e1fa6d8600835e9eb4ad4b0ce8af0 Mon Sep 17 00:00:00 2001 From: Justin Greywolf Date: Sun, 26 Apr 2020 06:10:18 -0700 Subject: [PATCH] 1234-RefactorDiagramScaling Changed implementation to ensure that viewport is aligned correctly, rather than increasing size --- src/diagrams/class/classRenderer.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/diagrams/class/classRenderer.js b/src/diagrams/class/classRenderer.js index acff7bab2..b59788740 100644 --- a/src/diagrams/class/classRenderer.js +++ b/src/diagrams/class/classRenderer.js @@ -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 width = svgBounds.width + 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}`; + logger.debug(`viewBox ${vBox}`); diagram.attr('viewBox', vBox); };