diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/taggedRect.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/taggedRect.ts index d7af4699a..c360ea0ca 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/taggedRect.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/taggedRect.ts @@ -24,10 +24,10 @@ export const taggedRect = async (parent: SVGAElement, node: Node) => { const options = userNodeOverrides(node, {}); const rectPoints = [ - { x, y }, + { x: x - tagWidth, y }, { x: x + w, y }, { x: x + w, y: y + h }, - { x, y: y + h }, + { x: x - tagWidth, y: y + h }, ]; const tagPoints = [ @@ -48,8 +48,8 @@ export const taggedRect = async (parent: SVGAElement, node: Node) => { const tagNode = rc.path(tagPath, options); const taggedRect = shapeSvg.insert('g', ':first-child'); + taggedRect.insert(() => tagNode, ':first-child'); taggedRect.insert(() => rectNode, ':first-child'); - taggedRect.insert(() => tagNode); taggedRect.attr('class', 'basic label-container'); @@ -60,11 +60,12 @@ export const taggedRect = async (parent: SVGAElement, node: Node) => { if (nodeStyles) { taggedRect.attr('style', nodeStyles); } + taggedRect.attr('transform', `translate(${tagWidth / 2}, 0)`); updateNodeBounds(node, taggedRect); node.intersect = function (point) { - const pos = intersect.rect(node, point); + const pos = intersect.polygon(node, rectPoints, point); return pos; }; diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes/windowPane.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes/windowPane.ts index 6bd9c2c8e..9d59ff164 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes/windowPane.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes/windowPane.ts @@ -51,20 +51,20 @@ export const windowPane = async (parent: SVGAElement, node: Node) => { const innerSecondPath = createPathFromPoints(innerSecondPathPoints); const innerSecondNode = rc.path(innerSecondPath, options); - const taggedRect = shapeSvg.insert('g', ':first-child'); - taggedRect.insert(() => innerNode, ':first-child'); - taggedRect.insert(() => innerSecondNode, ':first-child'); - taggedRect.insert(() => outerNode, ':first-child'); - taggedRect.attr('transform', `translate(${rectOffset / 2}, ${rectOffset / 2})`); + const windowPane = shapeSvg.insert('g', ':first-child'); + windowPane.insert(() => innerNode, ':first-child'); + windowPane.insert(() => innerSecondNode, ':first-child'); + windowPane.insert(() => outerNode, ':first-child'); + windowPane.attr('transform', `translate(${rectOffset / 2}, ${rectOffset / 2})`); - taggedRect.attr('class', 'basic label-container'); + windowPane.attr('class', 'basic label-container'); if (cssStyles) { - taggedRect.attr('style', cssStyles); + windowPane.attr('style', cssStyles); } if (nodeStyles) { - taggedRect.attr('style', nodeStyles); + windowPane.attr('style', nodeStyles); } label.attr( @@ -72,7 +72,7 @@ export const windowPane = async (parent: SVGAElement, node: Node) => { `translate(${-(bbox.width / 2) + rectOffset / 2}, ${-(bbox.height / 2) + rectOffset / 2})` ); - updateNodeBounds(node, taggedRect); + updateNodeBounds(node, windowPane); node.intersect = function (point) { const pos = intersect.polygon(node, outerPathPoints, point);