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 will stay there.I have a working fiddle here,which is showing the relationship among the nodes.can anyone help me from here to do this event in this api? ..
this is the fiddle
var node = vis
.selectAll("g.node")
.data(data.nodes)
.enter()
.append("svg:g")
.attr("class", "node")
.call(force.drag);
/
I think the changes should be made here
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 will stay there.I have a working fiddle here,which is showing the relationship among the nodes.can anyone help me from here to do this event in this api? ..
this is the fiddle
var node = vis
.selectAll("g.node")
.data(data.nodes)
.enter()
.append("svg:g")
.attr("class", "node")
.call(force.drag);
http://jsfiddle/vuCAx/
I think the changes should be made here
Share Improve this question edited Dec 15, 2013 at 1:16 m59 43.8k14 gold badges121 silver badges139 bronze badges asked Dec 14, 2013 at 17:11 SubhoSubho 9235 gold badges25 silver badges49 bronze badges1 Answer
Reset to default 5The 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/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.