mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 08:19:43 +02:00
diagram adjusts with legend width changes
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
This commit is contained in:
@@ -13,10 +13,12 @@ export const setConf = function (cnf) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const actors = {};
|
const actors = {};
|
||||||
|
let maxWidth = 0;
|
||||||
|
|
||||||
/** @param diagram - The diagram to draw to. */
|
/** @param diagram - The diagram to draw to. */
|
||||||
function drawActorLegend(diagram) {
|
function drawActorLegend(diagram) {
|
||||||
const conf = getConfig().journey;
|
const conf = getConfig().journey;
|
||||||
|
maxWidth = 0;
|
||||||
// Draw the actors
|
// Draw the actors
|
||||||
let yPos = 60;
|
let yPos = 60;
|
||||||
Object.keys(actors).forEach((person) => {
|
Object.keys(actors).forEach((person) => {
|
||||||
@@ -39,14 +41,19 @@ function drawActorLegend(diagram) {
|
|||||||
text: person,
|
text: person,
|
||||||
textMargin: conf.boxTextMargin | 5,
|
textMargin: conf.boxTextMargin | 5,
|
||||||
};
|
};
|
||||||
svgDraw.drawText(diagram, labelData);
|
|
||||||
|
|
||||||
|
const textElement = svgDraw.drawText(diagram, labelData);
|
||||||
|
const bbox = textElement.node().getBBox();
|
||||||
|
const textLength = bbox.width;
|
||||||
|
if (textLength > maxWidth) {
|
||||||
|
maxWidth = textLength;
|
||||||
|
}
|
||||||
yPos += 20;
|
yPos += 20;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// TODO: Cleanup?
|
// TODO: Cleanup?
|
||||||
const conf = getConfig().journey;
|
const conf = getConfig().journey;
|
||||||
const LEFT_MARGIN = conf.leftMargin;
|
let LEFT_MARGIN = 0;
|
||||||
export const draw = function (text, id, version, diagObj) {
|
export const draw = function (text, id, version, diagObj) {
|
||||||
const conf = getConfig().journey;
|
const conf = getConfig().journey;
|
||||||
|
|
||||||
@@ -84,6 +91,7 @@ export const draw = function (text, id, version, diagObj) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
drawActorLegend(diagram);
|
drawActorLegend(diagram);
|
||||||
|
LEFT_MARGIN = conf.leftMargin + maxWidth - 80;
|
||||||
bounds.insert(0, 0, LEFT_MARGIN, Object.keys(actors).length * 50);
|
bounds.insert(0, 0, LEFT_MARGIN, Object.keys(actors).length * 50);
|
||||||
drawTasks(diagram, tasks, 0);
|
drawTasks(diagram, tasks, 0);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user