All examples By author By category About

micahstubbs

Multiple Shape Drag SVG

a SVG example that shows how to drag multiple shapes inside of another shape. notice that the red circles can be dragged independently. notice that the black rectangle can also be dragged, keeping it's red-circle children in the same relative positions.

you could also think about this problem as "how to create a hierarchy of draggable shapes?". the short answer is: do it in the dragSubject() function d3-drag docs on drag subjects

an iteration on this very helpful stackoverflow answer, porting it to d3v4 and converts it to es2015 with lebab

this collection of d3-drag experiments also exist in github repo form at micahstubbs/d3-drag-experiments