From 6a649d347d0f3d76bdc91c51271c0164aa0c59f8 Mon Sep 17 00:00:00 2001 From: omkarht Date: Tue, 24 Sep 2024 18:22:15 +0530 Subject: [PATCH] updated imageSquare shape --- packages/mermaid/src/diagrams/flowchart/flowDb.ts | 8 +++----- .../rendering-elements/shapes/imageSquare.ts | 10 +++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.ts index db43ecaae5..8d8245e677 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.ts @@ -161,11 +161,9 @@ export const addVertex = function ( if (!doc.label?.trim() && vertex.text === id) { vertex.text = ''; } - if (doc?.constraint) { - vertex.constraint = doc.constraint; - } else { - vertex.constraint = 'off'; - } + } + if (doc?.constraint) { + vertex.constraint = doc.constraint; } if (doc.w) { vertex.assetWidth = Number(doc.w); diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/imageSquare.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/imageSquare.ts index 9cd5da0078..4306cfc175 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/imageSquare.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/imageSquare.ts @@ -26,10 +26,18 @@ export const imageSquare = async ( const defaultWidth = flowchart?.wrappingWidth; node.defaultWidth = flowchart?.wrappingWidth; - const imageWidth = Math.max( + const imageRawWidth = Math.max( node.label ? (defaultWidth ?? 0) : 0, node?.assetWidth ?? imageNaturalWidth ); + + const imageWidth = + node.constraint === 'on' + ? node?.assetHeight + ? node.assetHeight * node.imageAspectRatio + : imageRawWidth + : imageRawWidth; + const imageHeight = node.constraint === 'on' ? imageWidth / node.imageAspectRatio