mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-06 00:56:42 +02:00
#1033 Fix for diagram bounds and viewbox
This commit is contained in:
@@ -89,17 +89,34 @@ export const draw = function(text, id) {
|
||||
const rootDoc = stateDb.getRootDoc();
|
||||
renderDoc(rootDoc, diagram);
|
||||
|
||||
const padding = conf.padding;
|
||||
const bounds = diagram.node().getBBox();
|
||||
|
||||
diagram.attr('height', '100%');
|
||||
diagram.attr('style', `width: ${bounds.width * 3 + conf.padding * 2};`);
|
||||
console.warn(bounds);
|
||||
|
||||
const width = bounds.width + padding * 2;
|
||||
const height = bounds.height + padding * 2;
|
||||
|
||||
// diagram.attr('height', '100%');
|
||||
// diagram.attr('style', `width: ${bounds.width * 3 + conf.padding * 2};`);
|
||||
// diagram.attr('height', height);
|
||||
|
||||
// Zoom in a bit
|
||||
diagram.attr('width', width * 2);
|
||||
// diagram.attr('height', bounds.height * 3 + conf.padding * 2);
|
||||
diagram.attr(
|
||||
'viewBox',
|
||||
`${conf.padding * -1} ${conf.padding * -1} ` +
|
||||
(bounds.width * 1.5 + conf.padding * 2) +
|
||||
' ' +
|
||||
(bounds.height + conf.padding * 5)
|
||||
`${bounds.x - conf.padding} ${bounds.y - conf.padding} ` + width + ' ' + height
|
||||
);
|
||||
// diagram.attr('transform', `translate(, 0)`);
|
||||
|
||||
// diagram.attr(
|
||||
// 'viewBox',
|
||||
// `${conf.padding * -1} ${conf.padding * -1} ` +
|
||||
// (bounds.width * 1.5 + conf.padding * 2) +
|
||||
// ' ' +
|
||||
// (bounds.height + conf.padding * 5)
|
||||
// );
|
||||
};
|
||||
const getLabelWidth = text => {
|
||||
return text ? text.length * conf.fontSizeFactor : 1;
|
||||
|
Reference in New Issue
Block a user