fix: fix sizing of sl-rect in fixed layout

This commit is contained in:
Alois Klink
2024-09-27 21:42:16 +09:00
parent aae4e6f048
commit 2566f1cab8

View File

@@ -7,12 +7,26 @@ import rough from 'roughjs';
export const slopedRect = async (parent: SVGAElement, node: Node) => { 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 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 : 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); // If incoming height & width are present, subtract the padding from them
// as labelHelper does not take padding into account
// also check if the width or height is less than minimum default values (50),
// if so set it to min value
if (node.width || node.height) {
node.width = Math.max((node?.width ?? 0) - labelPaddingX * 2, 50);
node.height = Math.max((node?.height ?? 0) / 1.5 - labelPaddingY * 2, 50);
}
const { shapeSvg, bbox, label } = await labelHelper(parent, node, getNodeClasses(node));
const totalWidth = Math.max(bbox.width, node?.width ?? 0) + labelPaddingX * 2;
const totalHeight = (Math.max(bbox.height, node?.height ?? 0) + labelPaddingY * 2) * 1.5;
const w = totalWidth;
const h = totalHeight / 1.5;
const x = -w / 2; const x = -w / 2;
const y = -h / 2; const y = -h / 2;