diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.ts index db43ecaae..8d8245e67 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 9cd5da007..4306cfc17 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