From 1ef4c42bcf390676bdff1dfc8adedb08e9cbb708 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Fri, 27 Sep 2024 11:59:05 +0200 Subject: [PATCH] Updating odd shape --- .../shapes/rectLeftInvArrow.ts | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/rectLeftInvArrow.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/rectLeftInvArrow.ts index 7522d1eb4..2adb9a795 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/rectLeftInvArrow.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/rectLeftInvArrow.ts @@ -10,22 +10,34 @@ export const rect_left_inv_arrow = async ( ): Promise => { 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 * 3 : node.padding; - const labelPaddingY = node.look === 'neo' ? nodePadding * 1.5 : node.padding; + const labelPaddingX = node.look === 'neo' ? nodePadding * 3 : (node.padding ?? 0); + const labelPaddingY = node.look === 'neo' ? nodePadding * 1.5 : (node.padding ?? 0); - const w = Math.max(bbox.width + labelPaddingY, node?.width ?? 0); - const h = Math.max(bbox.height + labelPaddingX, node?.height ?? 0); + 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, label } = await labelHelper(parent, node, getNodeClasses(node)); + const w = Math.max(bbox.width, node?.width ?? 0) + labelPaddingX * 2; + const h = Math.max(bbox.height, node?.height ?? 0) + labelPaddingY * 2; const x = -w / 2; const y = -h / 2; - const notch = y / 2; + const notch = -y / 2; const points = [ - { x: x + notch, y }, - { x: x, y: 0 }, - { x: x + notch, y: -y }, + { x: x, y }, + { x: x + notch, y: 0 }, + { x: x, y: -y }, { x: -x, y: -y }, { x: -x, y }, ]; @@ -58,7 +70,7 @@ export const rect_left_inv_arrow = async ( label.attr( 'transform', - `translate(${-notch / 2 - bbox.width / 2 - (bbox.x - (bbox.left ?? 0))}, ${-(bbox.height / 2) - (bbox.y - (bbox.top ?? 0))})` + `translate(${bbox.x - bbox.width / 2}, ${-(bbox.height / 2) - (bbox.y - (bbox.top ?? 0))})` ); updateNodeBounds(node, polygon);