Skip to main content
100%

Dragging a rectangle,simple

✓ Published0🌍 Public
RRobinL
Last edited May 11, 2013
Created on May 11, 2013

Two blue squares are positioned in an SVG canvas, each bound to a data object with x and y coordinates. Dragging either square updates that object’s position in real time, and the rectangle is redrawn to follow the pointer. The code uses D3’s `d3.behavior.drag` with a drag event handler that reads `d3.event.x` and `d3.event.y`, then calls a `redraw1` function to update the square’s `x` and `y` attributes. The data starts as a simple array of two coordinate pairs, demonstrating a minimal drag-and-drop interaction without physics or constraints.

AI-generated description

Similar vizzes