mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-05 12:04:45 +01:00
fixed icon shape edges
This commit is contained in:
@@ -22,23 +22,18 @@ export const icon = async (parent: SVG, node: Node) => {
|
|||||||
|
|
||||||
const iconSize = Math.max(labelHeight - halfPadding, labelWidth - halfPadding, 48);
|
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 + halfPadding * 2;
|
const height = labelHeight + iconSize;
|
||||||
|
const dx = bbox.x;
|
||||||
const points = [
|
const dy = bbox.y;
|
||||||
{ x: 0, y: 0 },
|
|
||||||
{ x: 0, y: height },
|
|
||||||
{ x: width, y: height },
|
|
||||||
{ x: width, y: 0 },
|
|
||||||
];
|
|
||||||
|
|
||||||
if (node.icon) {
|
if (node.icon) {
|
||||||
const iconElem = shapeSvg.append('g');
|
const iconElem = shapeSvg.append('g');
|
||||||
iconElem.html(
|
iconElem.html(
|
||||||
`<g>${await getIconSVG(node.icon, { height: iconSize, width: iconSize, fallbackPrefix: '' })}</g>`
|
`<g>${await getIconSVG(node.icon, { height: iconSize - 4 * halfPadding, fallbackPrefix: '' })}</g>`
|
||||||
);
|
);
|
||||||
iconElem.attr(
|
iconElem.attr(
|
||||||
'transform',
|
'transform',
|
||||||
`translate(${0}, ${topLabel ? labelHeight - halfPadding : 0 + halfPadding * 2})`
|
`translate(${dx - width / 2 + halfPadding * 2}, ${dy - height / 2 + halfPadding * 2 + (topLabel ? labelHeight : 0)})`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,13 +47,13 @@ export const icon = async (parent: SVG, node: Node) => {
|
|||||||
|
|
||||||
label.attr(
|
label.attr(
|
||||||
'transform',
|
'transform',
|
||||||
`translate(${width / 2 - labelWidth / 2 + halfPadding - (bbox.x - (bbox.left ?? 0))},${(topLabel ? 0 : iconSize) + halfPadding * 2})`
|
`translate(${dx - width / 2 + halfPadding},${dy - height / 2 + iconSize + halfPadding - labelHeight / 2 - (topLabel ? iconSize : 0)})`
|
||||||
);
|
);
|
||||||
updateNodeBounds(node, shapeSvg);
|
updateNodeBounds(node, shapeSvg);
|
||||||
|
|
||||||
node.intersect = function (point) {
|
node.intersect = function (point) {
|
||||||
log.info('iconSquare intersect', node, point);
|
log.info('iconSquare intersect', node, point);
|
||||||
const pos = intersect.polygon(node, points, point);
|
const pos = intersect.rect(node, point);
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user