From 3609a50dd2dceb01eca048f9292a7bf5d7cc3ed3 Mon Sep 17 00:00:00 2001 From: joren Date: Mon, 30 Mar 2026 01:22:30 +0200 Subject: [PATCH] fix: volume slider click position using element getBoundingClientRect - Rewrote applyVolumeAtMouse to use hitarea element's screen rect directly - Works correctly regardless of zoom/pan level - Made hitarea taller (18px) for easier grabbing --- frontend/src/components/GraphCanvas.svelte | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/GraphCanvas.svelte b/frontend/src/components/GraphCanvas.svelte index 391bf72..85532cb 100644 --- a/frontend/src/components/GraphCanvas.svelte +++ b/frontend/src/components/GraphCanvas.svelte @@ -236,12 +236,14 @@ function applyVolumeAtMouse(e: MouseEvent, nodeId: number) { const nd = graphNodes.find(n => n.id === nodeId); if (!nd || !svgEl) return; - const volX = nd.x + 8; - const volW = nd.width - 36; - const svgRect = svgEl.getBoundingClientRect(); - // Convert mouse X to SVG coordinate - const mouseSvgX = viewBox.x + (e.clientX - svgRect.left) * viewBox.w / svgRect.width; - const ratio = (mouseSvgX - volX) / volW; + + // Get the hitarea SVG element's screen rect directly + const hitarea = svgEl.querySelector(`.node-group[data-node-id="${nodeId}"] .vol-hitarea`); + if (!hitarea) return; + const rect = (hitarea as SVGElement).getBoundingClientRect(); + + // Ratio from left edge of hitarea + const ratio = (e.clientX - rect.left) / rect.width; const clamped = Math.max(0, Math.min(1, ratio)); setNodeVolume(nodeId, clamped); } @@ -656,7 +658,7 @@ - +