|
|
@@ -280,8 +280,20 @@ const Elevation = (() => {
|
|
|
tooltip.innerHTML = formatTooltip(point, trackMeta);
|
|
|
tooltip.classList.add('visible');
|
|
|
const cRect = canvas.getBoundingClientRect();
|
|
|
- tooltip.style.left = Math.min(cx + 10, cRect.width - tooltip.offsetWidth - 4) + 'px';
|
|
|
- tooltip.style.top = Math.max(4, cy - tooltip.offsetHeight / 2) + 'px';
|
|
|
+ const tw = tooltip.offsetWidth;
|
|
|
+ const th = tooltip.offsetHeight;
|
|
|
+ const gap = 8;
|
|
|
+
|
|
|
+ // Prefer above cursor; fall back to below if not enough room
|
|
|
+ const topAbove = cy - th - gap;
|
|
|
+ const top = topAbove >= 0 ? topAbove : cy + gap;
|
|
|
+
|
|
|
+ // Prefer right of indicator; clamp to canvas bounds
|
|
|
+ const leftRight = cx + gap;
|
|
|
+ const left = Math.min(leftRight, cRect.width - tw - 4);
|
|
|
+
|
|
|
+ tooltip.style.left = Math.max(0, left) + 'px';
|
|
|
+ tooltip.style.top = top + 'px';
|
|
|
}
|
|
|
|
|
|
function hideTooltip() {
|