Skip to content

Commit

Permalink
updated constraint property for node shape
Browse files Browse the repository at this point in the history
  • Loading branch information
omkarht committed Sep 24, 2024
1 parent 1c8c953 commit fd37294
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
10 changes: 6 additions & 4 deletions packages/mermaid/src/diagrams/flowchart/flowDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/flowchart/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface FlowVertex {
assetHeight?: number;
defaultWidth?: number;
imageAspectRatio?: number;
constrainedImage?: boolean;
constraint?: 'on' | 'off';
}

export interface FlowText {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/rendering-util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit fd37294

Please sign in to comment.