问题描述
我已经实现了 http://jsbin.com/omokap/3/edit:
但是,我想取消图的动态行为(例如在dragend状态,但这仅适用于单个节点),并将节点放置在取自json的设置点中.
However, I would like to cancel the dynamic behavior of the graph (like in the dragend state, but that is only for the single node) and place the nodes in the set points, taken from json.
我看到了以下问题:在D3中移动固定节点和在D3强制控制布局中固定节点位置.在我的示例中,我不明白如何使用它们.
I've see this questions Moving fixed nodes in D3 and Fix Node Position in D3 Force-Directed Layout.I did not understand how to use them in my example.
有人可以帮我吗?
推荐答案
该解决方案是将x,y坐标和fixed:true像这样简单地插入节点对象
the solution is simple insert into the nodes object x,y coordinates and fixed:true like this
{ name: "Sara", id:"1", x:239.31191418045182, y:296.78520431471384, fixed:true},
{ name: "Raul", id:"2", x:261.1651006560272, y:200.78448049334696, fixed:true},
{ name: "Stefano", id:"3", fixed:false},
{ name: "Michele", id:"4", fixed:false}
这是一个有效的示例 http://jsbin.com/omokap/8/edit 请添加您自己的d3js库
this is a working example http://jsbin.com/omokap/8/edit please add yourself d3js library.
出于我的目的,效果很好.
for my purpose works fine.
这篇关于d3js使用固定节点创建强制布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!