React & D3 Drag with useReducer
This example shows three draggable circles connected by thick black lines in an SVG canvas. The circles and lines are rendered and updated using D3.js selectors and join operations, while React manages the application state. Dragging any circle dispatches a `drag` action to a `useReducer` hook, updating the circle’s x and y coordinates in the central state object. The D3 `drag` handler triggers the callback, and the Vue-like wrapper re-renders the visualization via the `viz.js` module. Animated interactivity is demonstrated through mouse hover effects and real-time position updates.
AI-generated descriptionA basic demonstration of d3-drag used with React to drag circles connected by lines.
This variant uses useReducer to avoid creating a new closure on each render.
Inspired by Observable: Drag (SVG).