d3js create a force layout with fixed nodes

Scorpy86 picture Scorpy86 · Jul 15, 2013 · Viewed 14.2k times · Source

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

enter image description here

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?

Answer

Scorpy86 picture Scorpy86 · Jul 17, 2013

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.