From 9e3bd1fb19daaec720e01d83b4c5a68c8c2dd09b Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Thu, 26 Sep 2024 15:33:02 +0200 Subject: [PATCH] Fix for text sizing calculations ans possibly insertion of a bug --- packages/mermaid/src/rendering-util/createText.ts | 3 ++- .../src/rendering-util/rendering-elements/shapes/text.ts | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/mermaid/src/rendering-util/createText.ts b/packages/mermaid/src/rendering-util/createText.ts index 4b6633493..9539fd164 100644 --- a/packages/mermaid/src/rendering-util/createText.ts +++ b/packages/mermaid/src/rendering-util/createText.ts @@ -38,7 +38,8 @@ async function addHtmlSpan(element, node, width, classes, addBackground = false) applyStyle(div, node.labelStyle); div.style('display', 'table-cell'); - div.style('white-space', 'nowrap'); + // KS: Why is this here? + // div.style('white-space', 'nowrap'); div.style('line-height', '1.5'); div.style('max-width', width + 'px'); div.style('text-align', 'center'); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/text.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/text.ts index abc5c17fe..40c59e3aa 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/text.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/text.ts @@ -9,8 +9,11 @@ export async function text(parent: SVGAElement, node: Node): Promise labelWidth + + // labelWidth > width + const totalWidth = node?.width ?? bbox.width; + const totalHeight = Math.max(bbox.height, node?.height ?? 0); const x = -totalWidth / 2; const y = -totalHeight / 2;