updated constraint property for node shape

This commit is contained in:
omkarht 2024-09-24 13:42:54 +05:30
parent 1c8c95367d
commit fd372941c7
5 changed files with 13 additions and 10 deletions

View File

@ -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,
});
}
};

View File

@ -19,7 +19,7 @@ export interface FlowVertex {
assetHeight?: number;
defaultWidth?: number;
imageAspectRatio?: number;
constrainedImage?: boolean;
constraint?: 'on' | 'off';
}
export interface FlowText {

View File

@ -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');

View File

@ -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

View File

@ -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';