Fix RadarChart drag reference point to use radar center (mouse & touch)#15
Conversation
Co-authored-by: Lotes <1525964+Lotes@users.noreply.github.com>
|
|
@copilot Make sure that drag & drop here also works using a touch device. Currently it does not work. |
Co-authored-by: Lotes <1525964+Lotes@users.noreply.github.com>
Fixed in 3b5e556. const sourceEv = event.sourceEvent;
const pointerEv = sourceEv.changedTouches?.[0] ?? sourceEv.touches?.[0] ?? sourceEv;
const [mouseX, mouseY] = d3.pointer(pointerEv, g.node());This falls through to the raw event for mouse, and uses the dragging finger's coordinates for touch. |
|
@copilot In Chrome for IPAD it still compares the touch point with the origin of the web page. What is wrong? It feels not natural to drag the points. When I drag a point to the center, it should be zero. And outside should be max points S. |
…dingClientRect Co-authored-by: Lotes <1525964+Lotes@users.noreply.github.com>
Fixed in 24dfad5. The root cause was that The fix bypasses const svgNode = g.node()?.ownerSVGElement;
if (!svgNode) return;
const rect = svgNode.getBoundingClientRect();
// Handle any CSS scaling on the SVG element
const scaleX = width / rect.width;
const scaleY = height / rect.height;
// Subtract radar center (the g element's translation)
const mouseX = (clientX - rect.left) * scaleX - width / 2;
const mouseY = (clientY - rect.top) * scaleY - height / 2;Dragging to the center now correctly yields 0, and dragging to the outer edge yields the max value, on both mouse and touch. |
|
@copilot when trying to drag a point/handle, it drops a few pixels later, as if the focus disappears immediately - I lose control, even on a Desktop browser. Can you fix this? I want to move the point along its axis in the radar without interuptions. |
…onto axis Co-authored-by: Lotes <1525964+Lotes@users.noreply.github.com>
Fixed in c2e1b88. The root cause was that every The fix:
Also added axis-projection so the handle now moves along its axis (dot-product of cursor onto the axis unit vector), clamped to |
D3 drag
event.x/event.yare in SVG coordinate space (origin at top-left), but the distance calculation treated(0, 0)as the radar center, causing incorrect value mapping when dragging property points. Additionally, touch-based drag did not work becaused3.pointerrelies onclientX/clientY, which aTouchEventdoesn't expose directly. On iPad Chrome,d3.pointer's internal use ofgetScreenCTM()caused coordinates to be measured from the page origin rather than the radar center.Changes
Fix coordinate origin: Compute coordinates via
getBoundingClientRect()(always viewport-relative, immune to thegetScreenCTM()scroll/zoom bug on mobile browsers), subtract the radar center offset and account for any CSS scaling.Fix touch support: Extract
clientX/clientYfromchangedTouches[0]for touch events, falling back to the raw event for mouse.Fix drag interruption: Previously, calling
onValueChangeon every drag event triggered a React state update → re-render →useEffect→svg.selectAll('*').remove(), destroying the active drag gesture mid-drag. The fix updates the SVG DOM directly during drag (moving the circle and redrawing the filled polygon) and callsonValueChangeonly once ondragendto commit the final value.Constrain point to axis: The cursor is projected onto the axis unit vector (dot-product), so the handle moves naturally along its axis line. Dragging to the center yields 0; dragging to the outer edge yields the max value.
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.