What's preserving local offset in this d3.drag example?
When dragging any circle in this d3 example , what prevents the circle's center from snapping to the mouse? In other words: when you initiate a circle drag by clicking somewhere near the outer edges of the circle , what in the code preserves the offset (relative to the circle's center) that's implied at drag start? I see these .attr() calls: .attr("cx", d.x = d3.event.x) .attr("cy", d.y = d3.event.y) But I expect d3.event.x (and .y ) to be the coordinates of the mouse — without accounting for the offset — and therefore I would think that the circle's center would (incorrectly, from a UX point