How To Add A Force Drag Event In D3 And Make The Node Stay Where I Leave It?
i have a D3 api which is showing some relationship between the nodes .I want to apply force.drag() event here where I will drag the node in a position and leave the node and it wil
Solution 1:
The solution involves setting the 'fixed' node property to true on dragstart.
var drag = force.drag()
.on("dragstart", dragstart);
var node = vis.selectAll("g.node").data(data.nodes).enter().append(
"svg:g").attr("class", "node").call(drag);
function dragstart(d) {
d.fixed = true;
}
See here: Sticky Force Layout
Updated Fiddle: http://jsfiddle.net/vuCAx/1/
Documentation: force.drag()
If you want dragged nodes to remain fixed after dragging, set the fixed attribute to true on dragstart, as in the sticky force layout example.
Post a Comment for "How To Add A Force Drag Event In D3 And Make The Node Stay Where I Leave It?"