From c08fad648728daf82119e8923fc1b4de012e5a5e Mon Sep 17 00:00:00 2001 From: saurabhg772244 Date: Mon, 26 Aug 2024 18:45:34 +0530 Subject: [PATCH] updated shapes --- .../shapes/invertedTrapezoid.ts | 41 ++++++++++--------- .../rendering-elements/shapes/leanLeft.ts | 33 ++++----------- .../rendering-elements/shapes/leanRight.ts | 32 ++++----------- .../shapes/shadedProcess.ts | 13 ++++-- .../rendering-elements/shapes/trapezoid.ts | 40 +++++++++--------- 5 files changed, 67 insertions(+), 92 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/invertedTrapezoid.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/invertedTrapezoid.ts index 37f415247..ba788bbfc 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/invertedTrapezoid.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/invertedTrapezoid.ts @@ -1,4 +1,4 @@ -import { labelHelper, updateNodeBounds, getNodeClasses } from './util.js'; +import { labelHelper, updateNodeBounds, getNodeClasses, createPathFromPoints } from './util.js'; import intersect from '../intersect/index.js'; import type { Node } from '$root/rendering-util/types.d.ts'; import { @@ -8,20 +8,20 @@ import { import rough from 'roughjs'; import { insertPolygonShape } from './insertPolygonShape.js'; -export const createInvertedTrapezoidPathD = ( - x: number, - y: number, - width: number, - height: number -): string => { - return [ - `M${x + height / 6},${y}`, - `L${x + width - height / 6},${y}`, - `L${x + width + (2 * height) / 6},${y - height}`, - `L${x - (2 * height) / 6},${y - height}`, - 'Z', - ].join(' '); -}; +// export const createInvertedTrapezoidPathD = ( +// x: number, +// y: number, +// width: number, +// height: number +// ): string => { +// return [ +// `M${x + height / 6},${y}`, +// `L${x + width - height / 6},${y}`, +// `L${x + width + (2 * height) / 6},${y - height}`, +// `L${x - (2 * height) / 6},${y - height}`, +// 'Z', +// ].join(' '); +// }; export const inv_trapezoid = async (parent: SVGAElement, node: Node): Promise => { const { labelStyles, nodeStyles } = styles2String(node); @@ -31,10 +31,10 @@ export const inv_trapezoid = async (parent: SVGAElement, node: Node): Promise; @@ -44,7 +44,8 @@ export const inv_trapezoid = async (parent: SVGAElement, node: Node): Promise { - return [ - `M${x + (2 * height) / 6},${y}`, - `L${x + width + height / 6},${y}`, - `L${x + width - (2 * height) / 6},${y - height}`, - `L${x - height / 6},${y - height}`, - 'Z', - ].join(' '); -}; - export const lean_left = async (parent: SVGAElement, node: Node): Promise => { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); - - const w = bbox.width + node.padding; - const h = bbox.height + node.padding; + const w = Math.max(bbox.width + (node.padding ?? 0), node?.width ?? 0); + const h = Math.max(bbox.height + (node.padding ?? 0), node?.height ?? 0); const points = [ - { x: (2 * h) / 6, y: 0 }, - { x: w + h / 6, y: 0 }, - { x: w - (2 * h) / 6, y: -h }, - { x: -h / 6, y: -h }, + { x: 0, y: 0 }, + { x: w + (3 * h) / 6, y: 0 }, + { x: w, y: -h }, + { x: -(3 * h) / 6, y: -h }, ]; let polygon: d3.Selection; @@ -44,7 +28,8 @@ export const lean_left = async (parent: SVGAElement, node: Node): Promise { - return [ - `M${x - (2 * height) / 6},${y}`, - `L${x + width - height / 6},${y}`, - `L${x + width + (2 * height) / 6},${y - height}`, - `L${x + height / 6},${y - height}`, - 'Z', - ].join(' '); -}; - export const lean_right = async (parent: SVGAElement, node: Node): Promise => { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); - - const w = bbox.width + node.padding; - const h = bbox.height + node.padding; + const w = Math.max(bbox.width + (node.padding ?? 0), node?.width ?? 0); + const h = Math.max(bbox.height + (node.padding ?? 0), node?.height ?? 0); const points = [ - { x: (-2 * h) / 6, y: 0 }, - { x: w - h / 6, y: 0 }, - { x: w + (2 * h) / 6, y: -h }, - { x: h / 6, y: -h }, + { x: (-3 * h) / 6, y: 0 }, + { x: w, y: 0 }, + { x: w + (3 * h) / 6, y: -h }, + { x: 0, y: -h }, ]; let polygon: d3.Selection; @@ -44,7 +28,7 @@ export const lean_right = async (parent: SVGAElement, node: Node): Promise { const { labelStyles, nodeStyles } = styles2String(node); node.labelStyle = labelStyles; - const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); - const halfPadding = (node?.padding || 0) / 2; - const w = bbox.width + node.padding; - const h = bbox.height + node.padding; + const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node)); + const halfPadding = node?.padding ?? 0; + const w = Math.max(bbox.width + (node.padding ?? 0) * 2, node?.width ?? 0); + const h = Math.max(bbox.height + (node.padding ?? 0) * 2, node?.height ?? 0); const x = -bbox.width / 2 - halfPadding; const y = -bbox.height / 2 - halfPadding; @@ -43,6 +43,11 @@ export const shadedProcess = async (parent: SVGAElement, node: Node) => { rect.selectAll('path').attr('style', nodeStyles); } + label.attr( + 'transform', + `translate(${-w / 2 + 4 + (node.padding ?? 0) - (bbox.x - (bbox.left ?? 0))},${-h / 2 + (node.padding ?? 0) - (bbox.y - (bbox.top ?? 0))})` + ); + updateNodeBounds(node, rect); node.intersect = function (point) { diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoid.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoid.ts index b2013097a..00fb29b2f 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoid.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/trapezoid.ts @@ -1,4 +1,4 @@ -import { labelHelper, updateNodeBounds, getNodeClasses } from './util.js'; +import { labelHelper, updateNodeBounds, getNodeClasses, createPathFromPoints } from './util.js'; import intersect from '../intersect/index.js'; import type { Node } from '$root/rendering-util/types.d.ts'; import { @@ -8,20 +8,20 @@ import { import rough from 'roughjs'; import { insertPolygonShape } from './insertPolygonShape.js'; -export const createTrapezoidPathD = ( - x: number, - y: number, - width: number, - height: number -): string => { - return [ - `M${x - (2 * height) / 6},${y}`, - `L${x + width + (2 * height) / 6},${y}`, - `L${x + width - height / 6},${y - height}`, - `L${x + height / 6},${y - height}`, - 'Z', - ].join(' '); -}; +// export const createTrapezoidPathD = ( +// x: number, +// y: number, +// width: number, +// height: number +// ): string => { +// return [ +// `M${x - (2 * height) / 6},${y}`, +// `L${x + width + (2 * height) / 6},${y}`, +// `L${x + width - height / 6},${y - height}`, +// `L${x + height / 6},${y - height}`, +// 'Z', +// ].join(' '); +// }; export const trapezoid = async (parent: SVGAElement, node: Node): Promise => { const { labelStyles, nodeStyles } = styles2String(node); @@ -31,10 +31,10 @@ export const trapezoid = async (parent: SVGAElement, node: Node): Promise; @@ -44,7 +44,7 @@ export const trapezoid = async (parent: SVGAElement, node: Node): Promise