From b52b54086e3d63946141b8d799ea23b552ea8453 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Thu, 3 Oct 2024 07:59:55 +0200 Subject: [PATCH] Fixed sizing of diamond shape --- packages/mermaid/src/rendering-util/createText.ts | 3 ++- .../rendering-util/rendering-elements/shapes/question.ts | 8 ++++---- .../src/rendering-util/rendering-elements/shapes/util.js | 5 ++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/mermaid/src/rendering-util/createText.ts b/packages/mermaid/src/rendering-util/createText.ts index ae02f2cfd..4eb8a275b 100644 --- a/packages/mermaid/src/rendering-util/createText.ts +++ b/packages/mermaid/src/rendering-util/createText.ts @@ -18,8 +18,9 @@ function applyStyle(dom, styleFn) { } } -async function addHtmlSpan(element, node, width, classes, addBackground = false) { +async function addHtmlSpan(element, node, _width, classes, addBackground = false) { const fo = element.append('foreignObject'); + const width = _width < 0 ? 0 : _width; // This is not the final width but used in order to make sure the foreign // object in firefox gets a width at all. The final width is fetched from the div fo.attr('width', `${10 * width}px`); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts index 76b175e29..8899564ce 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts @@ -21,15 +21,15 @@ export const question = async (parent: SVGAElement, node: Node): Promise { let text; text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), { useHtmlLabels, - width: node.width || getConfig().flowchart.wrappingWidth, + width: node.width < 0 ? 0 : node.width || getConfig().flowchart.wrappingWidth, cssClasses: 'markdown-node-label', style: node.labelStyle, addSvgBackground: !!node.icon || !!node.img, @@ -88,11 +88,10 @@ export const labelHelper = async (parent, node, _classes) => { ) ); } - bbox = div.getBoundingClientRect(); dv.attr('width', bbox.width); if (node.height && node.height < bbox.height) { - bbox.height = node.height; + bbox.height = node.height < 0 ? 0 : node.height; } dv.attr('height', bbox.height); }