diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/slopedRect.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/slopedRect.ts index 6f467f9e8..1a17c330f 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/slopedRect.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/slopedRect.ts @@ -7,12 +7,26 @@ import rough from 'roughjs'; export const slopedRect = async (parent: SVGAElement, node: Node) => { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; - const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node)); const nodePadding = node.padding ?? 0; const labelPaddingX = node.look === 'neo' ? nodePadding * 2 : nodePadding; const labelPaddingY = node.look === 'neo' ? nodePadding * 1 : nodePadding; - const w = Math.max(bbox.width + (labelPaddingX ?? 0) * 2, node?.width ?? 0); - const h = Math.max(bbox.height + (labelPaddingY ?? 0) * 2, node?.height ?? 0); + + // 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 = Math.max((node?.width ?? 0) - labelPaddingX * 2, 50); + node.height = Math.max((node?.height ?? 0) / 1.5 - labelPaddingY * 2, 50); + } + + const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node)); + + const totalWidth = Math.max(bbox.width, node?.width ?? 0) + labelPaddingX * 2; + const totalHeight = (Math.max(bbox.height, node?.height ?? 0) + labelPaddingY * 2) * 1.5; + + const w = totalWidth; + const h = totalHeight / 1.5; const x = -w / 2; const y = -h / 2;