From 9b269ecf3b308674317c39bc12efb8b29e93173d Mon Sep 17 00:00:00 2001 From: Ashish Jain Date: Sun, 29 Sep 2024 20:42:01 +0200 Subject: [PATCH] fix for trapezoidal pentagon --- .../shapes/trapezoidalPentagon.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts index 391a057b0..22f2df4cb 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoidalPentagon.ts @@ -7,15 +7,27 @@ import rough from 'roughjs'; export const trapezoidalPentagon = async (parent: SVGAElement, node: Node) => { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; - const { shapeSvg, bbox } = 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 minWidth = 60, minHeight = 20; - const w = Math.max(minWidth, bbox.width + (labelPaddingX ?? 0) * 2, node?.width ?? 0); - const h = Math.max(minHeight, bbox.height + (labelPaddingY ?? 0) * 2, node?.height ?? 0); + if (node.width || node.height) { + node.height = (node.height ?? 0) - labelPaddingY * 2; + if (node.height < minHeight) { + node.height = minHeight; + } + + node.width = (node.width ?? 0) - labelPaddingX * 2; + if (node.width < minWidth) { + node.width = minWidth; + } + } + + const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); + + const w = Math.max(minWidth, bbox.width, node?.width ?? 0) + (labelPaddingX ?? 0) * 2; + const h = Math.max(minHeight, bbox.height, node?.height ?? 0) + (labelPaddingY ?? 0) * 2; const { cssStyles } = node; // @ts-ignore - rough is not typed