admin管理员组文章数量:1394228
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.
本文标签: javascriptHow to add a force drag event in D3 and make the node stay where i leave itStack Overflow
版权声明:本文标题:javascript - How to add a force drag event in D3 and make the node stay where i leave it? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744707285a2620915.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论