diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.ts index c94dffa49..db43ecaae 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.ts @@ -161,7 +161,11 @@ export const addVertex = function ( if (!doc.label?.trim() && vertex.text === id) { vertex.text = ''; } - vertex.constrainedImage = !!doc.constrainedImage; + if (doc?.constraint) { + vertex.constraint = doc.constraint; + } else { + vertex.constraint = 'off'; + } } if (doc.w) { vertex.assetWidth = Number(doc.w); @@ -900,9 +904,7 @@ const addNodeFromVertex = ( img: vertex.img, assetWidth: vertex.assetWidth, assetHeight: vertex.assetHeight, - imageAspectRatio: vertex.imageAspectRatio, - defaultWidth: vertex.defaultWidth, - constrainedImage: vertex.constrainedImage, + constraint: vertex.constraint, }); } }; diff --git a/packages/mermaid/src/diagrams/flowchart/types.ts b/packages/mermaid/src/diagrams/flowchart/types.ts index c60b1e8c1..770ee24b4 100644 --- a/packages/mermaid/src/diagrams/flowchart/types.ts +++ b/packages/mermaid/src/diagrams/flowchart/types.ts @@ -19,7 +19,7 @@ export interface FlowVertex { assetHeight?: number; defaultWidth?: number; imageAspectRatio?: number; - constrainedImage?: boolean; + constraint?: 'on' | 'off'; } export interface FlowText { 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 0a9932f06..9cd5da007 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/imageSquare.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/imageSquare.ts @@ -30,9 +30,10 @@ export const imageSquare = async ( node.label ? (defaultWidth ?? 0) : 0, node?.assetWidth ?? imageNaturalWidth ); - const imageHeight = node.constrainedImage - ? imageWidth / node.imageAspectRatio - : (node?.assetHeight ?? imageNaturalHeight); + const imageHeight = + node.constraint === 'on' + ? imageWidth / node.imageAspectRatio + : (node?.assetHeight ?? imageNaturalHeight); node.width = Math.max(imageWidth, defaultWidth ?? 0); const { shapeSvg, bbox, label } = await labelHelper(parent, node, 'image-shape default'); diff --git a/packages/mermaid/src/rendering-util/types.ts b/packages/mermaid/src/rendering-util/types.ts index 25a616fb7..ec4e49b2a 100644 --- a/packages/mermaid/src/rendering-util/types.ts +++ b/packages/mermaid/src/rendering-util/types.ts @@ -71,7 +71,7 @@ export interface Node { assetHeight?: number; defaultWidth?: number; imageAspectRatio?: number; - constrainedImage?: boolean; + constraint?: 'on' | 'off'; } // Common properties for any edge in the system diff --git a/packages/mermaid/src/types.ts b/packages/mermaid/src/types.ts index 37590fa2b..fe8f71375 100644 --- a/packages/mermaid/src/types.ts +++ b/packages/mermaid/src/types.ts @@ -7,7 +7,7 @@ export interface NodeMetaData { img?: string; w?: string; h?: string; - constrainedImage?: boolean; + constraint?: 'on' | 'off'; } import type { MermaidConfig } from './config.type.js';