mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Adjustment for icon shape
This commit is contained in:
parent
e6ce370cdd
commit
95bd5dfdab
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user