updated waveRectangle shape

This commit is contained in:
omkarht
2024-09-27 19:20:29 +05:30
parent c7a2023661
commit 82e8eb97cc

View File

@@ -13,30 +13,31 @@ import rough from 'roughjs';
export const waveRectangle = async (parent: SVGAElement, node: Node) => { export const waveRectangle = async (parent: SVGAElement, node: Node) => {
const { labelStyles, nodeStyles } = styles2String(node); const { labelStyles, nodeStyles } = styles2String(node);
node.labelStyle = labelStyles; node.labelStyle = labelStyles;
const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
const minWidth = 100; // Minimum width
const minHeight = 50; // Minimum height
const nodePadding = node.padding ?? 0; const nodePadding = node.padding ?? 0;
const labelPaddingX = node.look === 'neo' ? nodePadding * 2 : nodePadding; const labelPaddingX = node.look === 'neo' ? nodePadding * 2 : nodePadding;
const labelPaddingY = node.look === 'neo' ? nodePadding * 1 : nodePadding; const labelPaddingY = node.look === 'neo' ? nodePadding * 1.5 : nodePadding;
const baseWidth = Math.max(bbox.width + labelPaddingX * 2, node?.width ?? 0);
const baseHeight = Math.max(bbox.height + labelPaddingY * 2, node?.height ?? 0);
const aspectRatio = baseWidth / baseHeight; if (node.width || node.height) {
node.width = node?.width ?? 0;
if (node.width < 100) {
node.width = 100;
}
let w = baseWidth; node.height = node?.height ?? 0;
let h = baseHeight; if (node.height < 50) {
node.height = 50;
}
if (w > h * aspectRatio) { // Adjust for wave amplitude
h = w / aspectRatio; const waveAmplitude = Math.min(node.height * 0.2, node.height / 4);
} else { node.height = Math.ceil(node.height - labelPaddingY - waveAmplitude * (20 / 9));
w = h * aspectRatio; node.width = node.width - labelPaddingX * 2;
} }
w = Math.max(w, minWidth); const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
h = Math.max(h, minHeight);
const w = Math.max(bbox.width, node?.width ?? 0) + labelPaddingX * 2;
const h = Math.max(bbox.height, node?.height ?? 0) + labelPaddingY;
const waveAmplitude = Math.min(h * 0.2, h / 4); const waveAmplitude = Math.min(h * 0.2, h / 4);
const finalH = h + waveAmplitude * 2; const finalH = h + waveAmplitude * 2;
@@ -73,6 +74,9 @@ export const waveRectangle = async (parent: SVGAElement, node: Node) => {
waveRect.selectAll('path').attr('style', nodeStyles); waveRect.selectAll('path').attr('style', nodeStyles);
} }
node.width = w;
node.height = finalH;
updateNodeBounds(node, waveRect); updateNodeBounds(node, waveRect);
node.intersect = function (point) { node.intersect = function (point) {
const pos = intersect.polygon(node, points, point); const pos = intersect.polygon(node, points, point);