From 2ce57e4cf4c98bb661a1b4397895b85199531ca0 Mon Sep 17 00:00:00 2001 From: Per Brolin Date: Mon, 30 Sep 2024 10:45:52 +0200 Subject: [PATCH] Fix default size if width/height not provided --- .../rendering-elements/shapes/stateEnd.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/stateEnd.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/stateEnd.ts index 70adc3f7a..3b342bd8f 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/stateEnd.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/stateEnd.ts @@ -14,6 +14,29 @@ export const stateEnd = ( node.labelStyle = labelStyles; const { cssStyles } = node; const { lineColor, stateBorder, nodeBorder } = themeVariables; + + // 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) { + if ((node.width ?? 0) < 50) { + node.width = 50; + } + + if ((node.height ?? 0) < 50) { + node.height = 50; + } + } + + if (!node.width) { + node.width = 50; + } + + if (!node.height) { + node.width = 50; + } + const shapeSvg = parent .insert('g') .attr('class', 'node default')