mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 14:59:53 +02:00
updated waveEdgedRectangle shape
This commit is contained in:
@@ -16,10 +16,15 @@ export const waveEdgedRectangle = async (parent: SVGAElement, node: Node) => {
|
||||
const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node));
|
||||
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 waveAmplitude = h / 4;
|
||||
const waveAmplitude = h / 8;
|
||||
const finalH = h + waveAmplitude;
|
||||
const { cssStyles } = node;
|
||||
|
||||
// To maintain minimum width
|
||||
const minWidth = 70;
|
||||
const widthDif = minWidth - w;
|
||||
const extraW = widthDif > 0 ? widthDif / 2 : 0;
|
||||
|
||||
// @ts-ignore - rough is not typed
|
||||
const rc = rough.svg(shapeSvg);
|
||||
const options = userNodeOverrides(node, {});
|
||||
@@ -30,10 +35,17 @@ export const waveEdgedRectangle = async (parent: SVGAElement, node: Node) => {
|
||||
}
|
||||
|
||||
const points = [
|
||||
{ x: -w / 2, y: finalH / 2 },
|
||||
...generateFullSineWavePoints(-w / 2, finalH / 2, w / 2, finalH / 2, waveAmplitude, 0.8),
|
||||
{ x: w / 2, y: -finalH / 2 },
|
||||
{ x: -w / 2, y: -finalH / 2 },
|
||||
{ x: -w / 2 - extraW, y: finalH / 2 },
|
||||
...generateFullSineWavePoints(
|
||||
-w / 2 - extraW,
|
||||
finalH / 2,
|
||||
w / 2 + extraW,
|
||||
finalH / 2,
|
||||
waveAmplitude,
|
||||
0.8
|
||||
),
|
||||
{ x: w / 2 + extraW, y: -finalH / 2 },
|
||||
{ x: -w / 2 - extraW, y: -finalH / 2 },
|
||||
];
|
||||
|
||||
const waveEdgeRectPath = createPathFromPoints(points);
|
||||
@@ -54,7 +66,7 @@ export const waveEdgedRectangle = async (parent: SVGAElement, node: Node) => {
|
||||
waveEdgeRect.attr('transform', `translate(0,${-waveAmplitude / 2})`);
|
||||
label.attr(
|
||||
'transform',
|
||||
`translate(${-w / 2 + (node.padding ?? 0) - (bbox.x - (bbox.left ?? 0))},${-h / 2 + (node.padding ?? 0) - waveAmplitude / 2 - (bbox.y - (bbox.top ?? 0))})`
|
||||
`translate(${-w / 2 + (node.padding ?? 0) - (bbox.x - (bbox.left ?? 0))},${-h / 2 + (node.padding ?? 0) - waveAmplitude - (bbox.y - (bbox.top ?? 0))})`
|
||||
);
|
||||
|
||||
updateNodeBounds(node, waveEdgeRect);
|
||||
|
Reference in New Issue
Block a user