Accepted answer

You simply need to set the origin() function accordingly. In the second case this is straightforward, in the first case somewhat more difficult because you are using coordinates as well as a transform. The basic pattern (for the second case) looks like this:

 .origin(function() { 
        var t =;
        return {x: t.attr("x"), y: t.attr("y")};

Updated jsfiddle here.


group element has no x/y attributes - no problem! create ones:

var node = svg.append("g")
            .attr("transform","translate(" + x_1 + ", " + y_1 +")")

when, the .origin function from Lars will work

and dont forget to update x,y attributes, while dragging:

function dragged() {"transform","translate(" + d3.event.x + ", " + d3.event.y +")");"x",d3.event.x);"y",d3.event.y);

Related Query