mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 16:59:48 +02:00
Merge pull request #1371 from jgreywolf/1234-RefactorClassDiagramScaling
1234 refactor class diagram scaling
This commit is contained in:
@@ -9,6 +9,7 @@ import svgDraw from './svgDraw';
|
|||||||
parser.yy = classDb;
|
parser.yy = classDb;
|
||||||
|
|
||||||
let idCache = {};
|
let idCache = {};
|
||||||
|
const padding = 20;
|
||||||
|
|
||||||
const conf = {
|
const conf = {
|
||||||
dividerMargin: 10,
|
dividerMargin: 10,
|
||||||
@@ -225,9 +226,22 @@ export const draw = function(text, id) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
diagram.attr('height', g.graph().height + 40);
|
const svgBounds = diagram.node().getBBox();
|
||||||
diagram.attr('width', g.graph().width * 1.5 + 20);
|
const width = svgBounds.width + padding * 2;
|
||||||
diagram.attr('viewBox', '-10 -10 ' + (g.graph().width + 20) + ' ' + (g.graph().height + 20));
|
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 {
|
export default {
|
||||||
|
Reference in New Issue
Block a user