|
54 | 54 |
|
55 | 55 | type Align = 'start' | 'center' | 'end'; |
56 | 56 |
|
57 | | - function alignValue(value: number, align: Align, tooltipSize: number) { |
| 57 | + function alignValue(value: number, align: Align, addlOffset: number, tooltipSize: number) { |
58 | 58 | 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; |
60 | 60 | } |
61 | 61 |
|
62 | 62 | $: if ($tooltip?.data) { |
|
109 | 109 | } |
110 | 110 |
|
111 | 111 | 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), |
114 | 114 | // set below |
115 | 115 | bottom: 0, |
116 | 116 | right: 0, |
|
121 | 121 | // Check if outside of container and swap align side accordingly |
122 | 122 | if (contained === 'container') { |
123 | 123 | if ((xAlign === 'start' || xAlign === 'center') && rect.right > $containerWidth) { |
124 | | - rect.left = alignValue(xValue, 'end', tooltipWidth); |
| 124 | + rect.left = alignValue(xValue, 'end', xOffset, tooltipWidth); |
125 | 125 | } |
126 | 126 | if ((xAlign === 'end' || xAlign === 'center') && rect.left < $padding.left) { |
127 | | - rect.left = alignValue(xValue, 'start', tooltipWidth); |
| 127 | + rect.left = alignValue(xValue, 'start', xOffset, tooltipWidth); |
128 | 128 | } |
129 | 129 | rect.right = rect.left + tooltipWidth; |
130 | 130 |
|
131 | 131 | if ((yAlign === 'start' || yAlign === 'center') && rect.bottom > $containerHeight) { |
132 | | - rect.top = alignValue(yValue, 'end', tooltipHeight); |
| 132 | + rect.top = alignValue(yValue, 'end', yOffset, tooltipHeight); |
133 | 133 | } |
134 | 134 | if ((yAlign === 'end' || yAlign === 'center') && rect.top < $padding.top) { |
135 | | - rect.top = alignValue(yValue, 'start', tooltipHeight); |
| 135 | + rect.top = alignValue(yValue, 'start', yOffset, tooltipHeight); |
136 | 136 | } |
137 | 137 | rect.bottom = rect.top + tooltipHeight; |
138 | 138 | } |
|
0 commit comments