From d06971606876c2a2446de3b87629720cf8a47fca Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Mon, 20 Apr 2026 15:07:52 +0200 Subject: [PATCH] fix: clamp stats tooltip within viewport on mobile --- site/src/components/StatsView.svelte | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/site/src/components/StatsView.svelte b/site/src/components/StatsView.svelte index 78b052d..5c9386a 100644 --- a/site/src/components/StatsView.svelte +++ b/site/src/components/StatsView.svelte @@ -74,10 +74,14 @@ function updatePos(e: MouseEvent) { const vw = window.innerWidth; const vh = window.innerHeight; - tooltipPos = { - x: e.clientX > vw - 310 ? e.clientX - 305 : e.clientX + 14, - y: Math.min(e.clientY - 8, vh - 260), - }; + const tw = 280; // matches w-[280px] + const th = 260; // approximate tooltip height + const gap = 14; + let x = e.clientX + gap; + if (x + tw > vw) x = e.clientX - gap - tw; + x = Math.max(4, Math.min(x, vw - tw - 4)); + const y = Math.max(4, Math.min(e.clientY - 8, vh - th - 4)); + tooltipPos = { x, y }; } function onCellEnter(date: string, e: MouseEvent) {