Skip to content

Commit 24a6cba

Browse files
committed
Internal lib - Add method to place tag as div from svg point
1 parent 2d1196f commit 24a6cba

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/lib.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,24 @@ export function placeHTMLElementAtSVGCoordinates({ svgElement, x, y, offsetY = 0
22112211
};
22122212
}
22132213

2214+
export function placeXYTag({ svgElement, x, y, element, position}) {
2215+
if (!svgElement || ! element) return { top: 0, left: 0 };
2216+
2217+
const point = svgElement.createSVGPoint();
2218+
point.x = x;
2219+
point.y = y;
2220+
const t_point = point.matrixTransform(svgElement.getScreenCTM());
2221+
const { height, width } = element.getBoundingClientRect()
2222+
2223+
let _offsetX = position === 'right' ? 0 : -width;
2224+
let _offsetY = -(height / 2);
2225+
2226+
return {
2227+
top: t_point.y + _offsetY,
2228+
left: t_point.x + _offsetX
2229+
};
2230+
}
2231+
22142232
const lib = {
22152233
XMLNS,
22162234
abbreviate,
@@ -2277,6 +2295,7 @@ const lib = {
22772295
opacity,
22782296
palette,
22792297
placeHTMLElementAtSVGCoordinates,
2298+
placeXYTag,
22802299
rotateMatrix,
22812300
sanitizeArray,
22822301
setOpacity,

0 commit comments

Comments
 (0)