From 5e966d60b07fc01a59b4d104b3e8aa16815d8092 Mon Sep 17 00:00:00 2001 From: itsalam Date: Tue, 19 Sep 2023 10:10:27 -0700 Subject: [PATCH] Centered Title function and changed rendering order for Elk flowchart to find Boundingbox --- packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js | 1 + packages/mermaid/src/utils.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js b/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js index 10cf86072..ec9ae6af0 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js +++ b/packages/mermaid/src/diagrams/flowchart/elk/flowRenderer-elk.js @@ -949,6 +949,7 @@ export const draw = async function (text, id, _version, diagObj) { log.info('after layout', JSON.stringify(graph, null, 2)); const g = await elk.layout(graph); drawNodes(0, 0, g.children, svg, subGraphsEl, diagObj, 0); + utils.insertTitle(svg, 'flowchartTitleText', conf.titleTopMargin, diagObj.db.getDiagramTitle()); log.info('after layout', g); g.edges?.map((edge) => { insertEdge(edgesEl, edge, edge.edgeData, diagObj, parentLookupDb, id); diff --git a/packages/mermaid/src/utils.ts b/packages/mermaid/src/utils.ts index e706ef122..d6f16a08a 100644 --- a/packages/mermaid/src/utils.ts +++ b/packages/mermaid/src/utils.ts @@ -829,7 +829,7 @@ export const insertTitle = ( parent .append('text') .text(title) - .attr('x', bounds.x + bounds.width / 2) + .attr('x', '50%') .attr('y', -titleTopMargin) .attr('class', cssClass); };