Merge branch 'knsv/new-shapes' of github.com:mermaid-js/mermaid into neo-new-shapes

This commit is contained in:
Ashish Jain
2024-09-24 11:12:00 +02:00
7 changed files with 21 additions and 14 deletions

View File

@@ -2,7 +2,7 @@
> >
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. > ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
> >
> ## Please edit the corresponding file in [/packages/mermaid/src/docs/adding-new-shape/Readme.md](../../packages/mermaid/src/docs/adding-new-shape/Readme.md). > ## Please edit the corresponding file in [/packages/mermaid/src/docs/adding-new-shape.md](../packages/mermaid/src/docs/adding-new-shape.md).
# Custom SVG Shapes Library # Custom SVG Shapes Library
@@ -126,7 +126,9 @@ To add a new shape:
const shapes = { const shapes = {
..., ...,
myNewShape, 'my-new-shape': myNewShape,
// Shortened alias (if any).
'm-nsh': myNewShape
}; };
``` ```

View File

@@ -133,7 +133,7 @@ export const addVertex = function (
} }
// console.log('yamlData', yamlData); // console.log('yamlData', yamlData);
const doc = yaml.load(yamlData, { schema: yaml.JSON_SCHEMA }) as NodeMetaData; const doc = yaml.load(yamlData, { schema: yaml.JSON_SCHEMA }) as NodeMetaData;
if (doc.shape && doc.shape !== doc.shape.toLowerCase()) { if (doc.shape && (doc.shape !== doc.shape.toLowerCase() || doc.shape.includes('_'))) {
throw new Error(`No such shape: ${doc.shape}. Shape names should be lowercase.`); throw new Error(`No such shape: ${doc.shape}. Shape names should be lowercase.`);
} }
@@ -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);
@@ -901,9 +905,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

@@ -120,7 +120,9 @@ To add a new shape:
const shapes = { const shapes = {
..., ...,
myNewShape, 'my-new-shape': myNewShape,
// Shortened alias (if any).
'm-nsh': myNewShape
}; };
``` ```

View File

@@ -30,9 +30,10 @@ 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 =
? imageWidth / node.imageAspectRatio node.constraint === 'on'
: (node?.assetHeight ?? imageNaturalHeight); ? imageWidth / node.imageAspectRatio
: (node?.assetHeight ?? imageNaturalHeight);
node.width = Math.max(imageWidth, defaultWidth ?? 0); node.width = Math.max(imageWidth, defaultWidth ?? 0);
const { shapeSvg, bbox, label } = await labelHelper(parent, node, 'image-shape default'); const { shapeSvg, bbox, label } = await labelHelper(parent, node, 'image-shape default');

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

@@ -10,7 +10,7 @@ export interface NodeMetaData {
img?: string; img?: string;
w?: string; w?: string;
h?: string; h?: string;
constrainedImage?: boolean; constraint?: 'on' | 'off';
} }
export interface Point { export interface Point {