d3js create a force layout with fixed nodes [closed]

怎甘沉沦 提交于 2019-12-19 17:37:10

问题


i've implemented this http://jsbin.com/omokap/3/edit:

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.

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.

can someone give me a help?


回答1:


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}

this is a working example http://jsbin.com/omokap/8/edit please add yourself d3js library.

for my purpose works fine.



来源:https://stackoverflow.com/questions/17656502/d3js-create-a-force-layout-with-fixed-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!