Skip to content

Commit cd9d8b7

Browse files
committed
[Tooltip] Fix xOffset usage after recent refactor
1 parent be23243 commit cd9d8b7

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

.changeset/silent-hounds-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'layerchart': patch
3+
---
4+
5+
[Tooltip] Fix xOffset usage after recent refactor

packages/layerchart/src/lib/components/Tooltip.svelte

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
5555
type Align = 'start' | 'center' | 'end';
5656
57-
function alignValue(value: number, align: Align, tooltipSize: number) {
57+
function alignValue(value: number, align: Align, addlOffset: number, tooltipSize: number) {
5858
const alignOffset = align === 'center' ? tooltipSize / 2 : align === 'end' ? tooltipSize : 0;
59-
return value + (align === 'end' ? -yOffset : yOffset) - alignOffset;
59+
return value + (align === 'end' ? -addlOffset : addlOffset) - alignOffset;
6060
}
6161
6262
$: if ($tooltip?.data) {
@@ -109,8 +109,8 @@
109109
}
110110
111111
const rect = {
112-
top: alignValue(yValue, yAlign, tooltipHeight),
113-
left: alignValue(xValue, xAlign, tooltipWidth),
112+
top: alignValue(yValue, yAlign, yOffset, tooltipHeight),
113+
left: alignValue(xValue, xAlign, xOffset, tooltipWidth),
114114
// set below
115115
bottom: 0,
116116
right: 0,
@@ -121,18 +121,18 @@
121121
// Check if outside of container and swap align side accordingly
122122
if (contained === 'container') {
123123
if ((xAlign === 'start' || xAlign === 'center') && rect.right > $containerWidth) {
124-
rect.left = alignValue(xValue, 'end', tooltipWidth);
124+
rect.left = alignValue(xValue, 'end', xOffset, tooltipWidth);
125125
}
126126
if ((xAlign === 'end' || xAlign === 'center') && rect.left < $padding.left) {
127-
rect.left = alignValue(xValue, 'start', tooltipWidth);
127+
rect.left = alignValue(xValue, 'start', xOffset, tooltipWidth);
128128
}
129129
rect.right = rect.left + tooltipWidth;
130130
131131
if ((yAlign === 'start' || yAlign === 'center') && rect.bottom > $containerHeight) {
132-
rect.top = alignValue(yValue, 'end', tooltipHeight);
132+
rect.top = alignValue(yValue, 'end', yOffset, tooltipHeight);
133133
}
134134
if ((yAlign === 'end' || yAlign === 'center') && rect.top < $padding.top) {
135-
rect.top = alignValue(yValue, 'start', tooltipHeight);
135+
rect.top = alignValue(yValue, 'start', yOffset, tooltipHeight);
136136
}
137137
rect.bottom = rect.top + tooltipHeight;
138138
}

0 commit comments

Comments
 (0)