diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/triangle.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/triangle.ts index fdb149023..ca35c2c70 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/triangle.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/triangle.ts @@ -8,15 +8,31 @@ import { createPathFromPoints } from './util.js'; import { evaluate } from '../../../diagrams/common/common.js'; import { getConfig } from '../../../diagram-api/diagramAPI.js'; +const MIN_HEIGHT = 25; +const MIN_WIDTH = 25; + export const triangle = async (parent: SVGAElement, node: Node): Promise => { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; + const nodePadding = node.padding ?? 0; + const labelPaddingX = node.look === 'neo' ? nodePadding * 2 : nodePadding; + + if (node.width || node.height) { + node.width = (node?.width ?? 0) - labelPaddingX * 4; + if (node.width < MIN_WIDTH) { + node.width = MIN_WIDTH; + } + + node.height = node?.height ?? 0; + if (node.height < MIN_HEIGHT) { + node.height = MIN_HEIGHT; + } + } + const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node)); const useHtmlLabels = evaluate(getConfig().flowchart?.htmlLabels); - const nodePadding = node.padding ?? 0; - const labelPaddingX = node.look === 'neo' ? nodePadding * 2 : nodePadding; - const w = Math.max(bbox.width + (labelPaddingX ?? 0), node?.width ?? 0); + const w = Math.max(bbox.width, node?.width ?? 0) + labelPaddingX; const h = Math.max(w + bbox.height, node?.height ?? 0); const tw = w + bbox.height;