From 4a04ccd96c4c6c361953810d8c8c79b46a8565cb Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 29 Jun 2020 15:05:08 +1000 Subject: [PATCH] move tooltip away from edges --- ts/src/stats/tooltip.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ts/src/stats/tooltip.ts b/ts/src/stats/tooltip.ts index afc80082d..21eac059c 100644 --- a/ts/src/stats/tooltip.ts +++ b/ts/src/stats/tooltip.ts @@ -12,9 +12,14 @@ function showTooltipInner(msg: string, x: number, y: number): void { document.body.appendChild(tooltipDiv); } tooltipDiv.innerHTML = msg; - tooltipDiv.style.right = `${document.body.clientWidth - x + 10}px`; - tooltipDiv.style.top = `${y + 20}px`; + // move tooltip away from edge as user approaches right side + const shiftLeftAmount = Math.round( + tooltipDiv.clientWidth * 1.2 * (x / document.body.clientWidth) + ); + + tooltipDiv.style.left = `${x + 40 - shiftLeftAmount}px`; + tooltipDiv.style.top = `${y + 40}px`; tooltipDiv.style.opacity = "1"; }