Dragging a rectangle
✓ Published0🌍 Public
RRobinL
Last edited May 11, 2013
Created on May 11, 2013
Two draggable rectangles—one blue and 100 pixels square, the other smaller—respond to mouse interaction in a D3.js scene. Each rectangle tracks its own `x` and `y` position in a separate data array, updated on the `drag` event via `d3.behavior.drag()`. As the mouse moves, `d3.event.x` and `d3.event.y` assign new coordinates, and a redraw function updates the SVG attributes with the new values. The example demonstrates custom drag behavior with explicit origin binding and event handling.
AI-generated description