From 0f7e14ba708c9805bb022846bd294389a2e544fa Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Fri, 27 Sep 2024 16:59:37 +0200 Subject: [PATCH] Update for stadium shape --- .../rendering-elements/shapes/stadium.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/stadium.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/stadium.ts index 777a23b94..8f10d982c 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/stadium.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/stadium.ts @@ -56,15 +56,28 @@ export const stadium = async (parent: SVGAElement, node: Node) => { const nodePadding = node.padding ?? 0; const labelPaddingX = node.look === 'neo' ? nodePadding * 3 : nodePadding; const labelPaddingY = node.look === 'neo' ? nodePadding * 1.5 : nodePadding; - node.width = (node?.width ?? 0) - labelPaddingX; - node.height = (node?.height ?? 0) - labelPaddingY; - if (node.width < 100) { - node.width = 100; + // If incoming height & width are present, subtract the padding from them + // as labelHelper does not take padding into account + // also check if the width or height is less than minimum default values (50), + // if so set it to min value + if (node.width || node.height) { + node.width = (node?.width ?? 0) - labelPaddingX * 2; + if (node.width < 50) { + node.width = 50; + } + + node.height = (node?.height ?? 0) - labelPaddingY * 2; + if (node.height < 50) { + node.height = 50; + } } const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); - const h = Math.max(bbox.height, node?.height || 0) + labelPaddingY; - const w = Math.max(bbox.width + h / 4, node?.width || 0, 150) + labelPaddingX; + // const h = Math.max(bbox.height, node?.height || 0) + labelPaddingY; + // const w = Math.max(bbox.width + h / 4, node?.width || 0, 150) + labelPaddingX; + + const w = Math.max(bbox.width, node?.width || 0) + labelPaddingX * 2; + const h = Math.max(bbox.height, node?.height || 0) + labelPaddingY * 2; let rect; const { cssStyles } = node;