Skip to content

Commit

Permalink
Merge pull request #1371 from jgreywolf/1234-RefactorClassDiagramScaling
Browse files Browse the repository at this point in the history
1234 refactor class diagram scaling
  • Loading branch information
knsv authored Apr 26, 2020
2 parents 3aa5fc0 + 08e015a commit 0933268
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/diagrams/class/classRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import svgDraw from './svgDraw';
parser.yy = classDb;

let idCache = {};
const padding = 20;

const conf = {
dividerMargin: 10,
Expand Down Expand Up @@ -225,9 +226,22 @@ export const draw = function(text, id) {
}
});

diagram.attr('height', g.graph().height + 40);
diagram.attr('width', g.graph().width * 1.5 + 20);
diagram.attr('viewBox', '-10 -10 ' + (g.graph().width + 20) + ' ' + (g.graph().height + 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);
};

export default {
Expand Down

0 comments on commit 0933268

Please sign in to comment.