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) { if (!doc.label?.trim() && vertex.text === id) {
vertex.text = ''; vertex.text = '';
} }
vertex.constrainedImage = !!doc.constrainedImage; if (doc?.constraint) {
vertex.constraint = doc.constraint;
} else {
vertex.constraint = 'off';
}
} }
if (doc.w) { if (doc.w) {
vertex.assetWidth = Number(doc.w); vertex.assetWidth = Number(doc.w);
@ -900,9 +904,7 @@ const addNodeFromVertex = (
img: vertex.img, img: vertex.img,
assetWidth: vertex.assetWidth, assetWidth: vertex.assetWidth,
assetHeight: vertex.assetHeight, assetHeight: vertex.assetHeight,
imageAspectRatio: vertex.imageAspectRatio, constraint: vertex.constraint,
defaultWidth: vertex.defaultWidth,
constrainedImage: vertex.constrainedImage,
}); });
} }
}; };

View File

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

View File

@ -30,7 +30,8 @@ export const imageSquare = async (
node.label ? (defaultWidth ?? 0) : 0, node.label ? (defaultWidth ?? 0) : 0,
node?.assetWidth ?? imageNaturalWidth node?.assetWidth ?? imageNaturalWidth
); );
const imageHeight = node.constrainedImage const imageHeight =
node.constraint === 'on'
? imageWidth / node.imageAspectRatio ? imageWidth / node.imageAspectRatio
: (node?.assetHeight ?? imageNaturalHeight); : (node?.assetHeight ?? imageNaturalHeight);
node.width = Math.max(imageWidth, defaultWidth ?? 0); node.width = Math.max(imageWidth, defaultWidth ?? 0);

View File

@ -71,7 +71,7 @@ export interface Node {
assetHeight?: number; assetHeight?: number;
defaultWidth?: number; defaultWidth?: number;
imageAspectRatio?: number; imageAspectRatio?: number;
constrainedImage?: boolean; constraint?: 'on' | 'off';
} }
// Common properties for any edge in the system // Common properties for any edge in the system

View File

@ -7,7 +7,7 @@ export interface NodeMetaData {
img?: string; img?: string;
w?: string; w?: string;
h?: string; h?: string;
constrainedImage?: boolean; constraint?: 'on' | 'off';
} }
import type { MermaidConfig } from './config.type.js'; import type { MermaidConfig } from './config.type.js';