implemented neo-fication for multiRect, slopedRect, waveEdgedRectangle shapes

This commit is contained in:
omkarht
2024-09-02 21:00:12 +05:30
parent 5673dd7ebc
commit 83493f26b7
3 changed files with 17 additions and 8 deletions

View File

@@ -11,8 +11,11 @@ export const multiRect = async (parent: SVGAElement, node: Node) => {
const { labelStyles, nodeStyles } = styles2String(node); const { labelStyles, nodeStyles } = styles2String(node);
node.labelStyle = labelStyles; node.labelStyle = labelStyles;
const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(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 nodePadding = node.padding ?? 0;
const h = Math.max(bbox.height + (node.padding ?? 0) * 2, node?.height ?? 0); const labelPaddingX = node.look === 'neo' ? nodePadding * 2 : nodePadding;
const labelPaddingY = node.look === 'neo' ? nodePadding * 1 : nodePadding;
const w = Math.max(bbox.width + (labelPaddingX ?? 0) * 2, node?.width ?? 0);
const h = Math.max(bbox.height + (labelPaddingY ?? 0) * 2, node?.height ?? 0);
const rectOffset = 5; const rectOffset = 5;
const x = -w / 2; const x = -w / 2;
const y = -h / 2; const y = -h / 2;

View File

@@ -11,8 +11,11 @@ export const slopedRect = async (parent: SVGAElement, node: Node) => {
const { labelStyles, nodeStyles } = styles2String(node); const { labelStyles, nodeStyles } = styles2String(node);
node.labelStyle = labelStyles; node.labelStyle = labelStyles;
const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(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 nodePadding = node.padding ?? 0;
const h = Math.max(bbox.height + (node.padding ?? 0) * 2, node?.height ?? 0); const labelPaddingX = node.look === 'neo' ? nodePadding * 2 : nodePadding;
const labelPaddingY = node.look === 'neo' ? nodePadding * 1 : nodePadding;
const w = Math.max(bbox.width + (labelPaddingX ?? 0) * 2, node?.width ?? 0);
const h = Math.max(bbox.height + (labelPaddingY ?? 0) * 2, node?.height ?? 0);
const x = -w / 2; const x = -w / 2;
const y = -h / 2; const y = -h / 2;
@@ -51,7 +54,7 @@ export const slopedRect = async (parent: SVGAElement, node: Node) => {
polygon.attr('transform', `translate(0, ${h / 4})`); polygon.attr('transform', `translate(0, ${h / 4})`);
label.attr( label.attr(
'transform', 'transform',
`translate(${-w / 2 + (node.padding ?? 0) - (bbox.x - (bbox.left ?? 0))}, ${-h / 4 + (node.padding ?? 0) - (bbox.y - (bbox.top ?? 0))})` `translate(${-w / 2 + (labelPaddingX ?? 0) - (bbox.x - (bbox.left ?? 0))}, ${-h / 4 + (labelPaddingY ?? 0) - (bbox.y - (bbox.top ?? 0))})`
); );
updateNodeBounds(node, polygon); updateNodeBounds(node, polygon);

View File

@@ -14,8 +14,11 @@ export const waveEdgedRectangle = async (parent: SVGAElement, node: Node) => {
const { labelStyles, nodeStyles } = styles2String(node); const { labelStyles, nodeStyles } = styles2String(node);
node.labelStyle = labelStyles; node.labelStyle = labelStyles;
const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(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 nodePadding = node.padding ?? 0;
const h = Math.max(bbox.height + (node.padding ?? 0) * 2, node?.height ?? 0); const labelPaddingX = node.look === 'neo' ? nodePadding * 2 : nodePadding;
const labelPaddingY = node.look === 'neo' ? nodePadding * 1 : nodePadding;
const w = Math.max(bbox.width + (labelPaddingX ?? 0) * 2, node?.width ?? 0);
const h = Math.max(bbox.height + (labelPaddingY ?? 0) * 2, node?.height ?? 0);
const waveAmplitude = h / 4; const waveAmplitude = h / 4;
const finalH = h + waveAmplitude; const finalH = h + waveAmplitude;
const { cssStyles } = node; const { cssStyles } = node;
@@ -54,7 +57,7 @@ export const waveEdgedRectangle = async (parent: SVGAElement, node: Node) => {
waveEdgeRect.attr('transform', `translate(0,${-waveAmplitude / 2})`); waveEdgeRect.attr('transform', `translate(0,${-waveAmplitude / 2})`);
label.attr( label.attr(
'transform', '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 + (labelPaddingX ?? 0) - (bbox.x - (bbox.left ?? 0))},${-h / 2 + (labelPaddingY ?? 0) - waveAmplitude / 2 - (bbox.y - (bbox.top ?? 0))})`
); );
updateNodeBounds(node, waveEdgeRect); updateNodeBounds(node, waveEdgeRect);