Adjustment for icon shape

This commit is contained in:
saurabhg772244 2024-09-06 20:08:27 +05:30
parent e6ce370cdd
commit 95bd5dfdab

View File

@ -21,19 +21,19 @@ export const icon = async (parent: SVG, node: Node) => {
const labelHeight = Math.max(bbox.height + halfPadding * 2, node?.height ?? 0);
const iconSize = Math.max(labelHeight - halfPadding, labelWidth - halfPadding, 48);
const width = Math.max(labelWidth, iconSize);
// const width = Math.max(labelWidth, iconSize);
const height = labelHeight + iconSize;
const dx = bbox.x;
const dy = bbox.y;
if (node.icon) {
const iconElem = shapeSvg.append('g');
iconElem.html(
`<g>${await getIconSVG(node.icon, { height: iconSize - 4 * halfPadding, fallbackPrefix: '' })}</g>`
);
const iconWidth = iconElem.node().getBBox().width;
const iconHeight = iconElem.node().getBBox().height;
iconElem.attr(
'transform',
`translate(${dx - width / 2 + halfPadding * 2}, ${dy - height / 2 + halfPadding * 2 + (topLabel ? labelHeight : 0)})`
`translate(${-iconWidth / 2}, ${-iconHeight / 2 - labelHeight / 2 + halfPadding + (topLabel ? labelHeight : 0)})`
);
}
@ -47,7 +47,7 @@ export const icon = async (parent: SVG, node: Node) => {
label.attr(
'transform',
`translate(${dx - width / 2 + halfPadding},${dy - height / 2 + iconSize + halfPadding - labelHeight / 2 - (topLabel ? iconSize : 0)})`
`translate(${-labelWidth / 2 + halfPadding - (bbox.x - (bbox.left ?? 0))},${-height / 2 + iconSize - (topLabel ? iconSize - halfPadding : 0) - (bbox.y - (bbox.top ?? 0))})`
);
updateNodeBounds(node, shapeSvg);