Skip to content

Commit 636276c

Browse files
committed
Internal lib - Fix edge case in placeHTMLElementAtSVGCoordinates
1 parent 11ac60b commit 636276c

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/lib.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ export function placeHTMLElementAtSVGCoordinates({ svgElement, x, y, offsetY = 0
21852185
let _offsetY = 0;
21862186

21872187
if (t_point.x - rect.width / 2 < svgRect.left) {
2188-
_offsetX = rect.width
2188+
_offsetX = 0
21892189
} else if (t_point.x + rect.width > svgRect.right) {
21902190
_offsetX = -rect.width
21912191
} else {
@@ -2204,7 +2204,6 @@ export function placeHTMLElementAtSVGCoordinates({ svgElement, x, y, offsetY = 0
22042204
};
22052205
}
22062206

2207-
22082207
const lib = {
22092208
XMLNS,
22102209
abbreviate,

tests/lib.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,16 +2540,14 @@ describe("placeHTMLElementAtSVGCoordinates", () => {
25402540
const svgMock = createMockSVGElement();
25412541
const elementMock = createMockHTMLElement();
25422542
const result = placeHTMLElementAtSVGCoordinates({ svgElement: svgMock, x: 250, y: 250, element: elementMock });
2543-
2544-
console.log("✅ Centered Tooltip Debug Result:", result);
25452543
expect(result).toEqual({ top: 230, left: 225 });
25462544
});
25472545

25482546
test("shifts right if element overflows left boundary", () => {
25492547
const svgMock = createMockSVGElement();
25502548
const elementMock = createMockHTMLElement(100, 40);
25512549
const result = placeHTMLElementAtSVGCoordinates({ svgElement: svgMock, x: 0, y: 250, element: elementMock });
2552-
expect(result.left).toBe(100);
2550+
expect(result.left).toBe(0);
25532551
});
25542552

25552553
test("shifts left if element overflows right boundary", () => {

0 commit comments

Comments
 (0)