From b47168b06403045e241f1081d77fb650d3981ccd Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Fri, 27 Sep 2024 13:40:32 +0200 Subject: [PATCH] Lean-right and question --- .../rendering-elements/shapes/leanRight.ts | 24 +++++++++++++++---- .../rendering-elements/shapes/question.ts | 18 +++++++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/leanRight.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/leanRight.ts index 03d75864f..d2f43f9d9 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/leanRight.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/leanRight.ts @@ -8,13 +8,29 @@ import { insertPolygonShape } from './insertPolygonShape.js'; export const lean_right = async (parent: SVGAElement, node: Node): Promise => { 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 * 3 : nodePadding; const labelPaddingY = node.look === 'neo' ? nodePadding * 1.5 : nodePadding; - 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; + if (node.width < 50) { + node.width = 50; + } + + node.height = node?.height ?? 0; + if (node.height < 50) { + node.height = 50; + } + const _dx = (3 * node.height) / 6; + node.height = node.height - labelPaddingY; + node.width = node.width - 2 * _dx; + } + + 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, node?.width ?? 0); + const points = [ { x: (-3 * h) / 6, y: 0 }, { x: w, y: 0 }, diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts index d571e4927..6d4934f96 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/question.ts @@ -19,10 +19,22 @@ export const createDecisionBoxPathD = (x: number, y: number, size: number): stri export const question = async (parent: SVGAElement, node: Node): Promise => { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; - const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); + const padding = node.padding ?? 0; + if (node.width || node.height) { + node.width = (node?.width ?? 0) - padding * 8; + if (node.width < 50) { + node.width = 50; + } - const w = bbox.width + node.padding; - const h = bbox.height + node.padding; + node.height = (node?.height ?? 0) - padding * 8; + if (node.height < 50) { + node.height = 50; + } + } + + const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); + const w = (Math.max(bbox.width, node?.width ?? 0) + padding * 8) / 2; + const h = w; const s = w + h; const points = [