javascript - Set only one node (root) note to be draggable in d3 force layout -


i'm working on d3 force layout graph, looks pretty this. want root node fixed not draggable. fixed root node in json file adding

"fixed": true 

but still draggable. in js file there code

var nodeenter = node.enter().append("g")     .attr("class", "node")     .on("click", click)     .call(force.drag); 

if remove last line of code, whole graph isn't draggable anymore. think 'force' global variable , determines, whole graph draggable. want root node not draggable , should draggable. how can that?

you have remove drag event node wish stay fixed.

here example : http://jsfiddle.net/qvco2ljy/112/

i have looped through data give first element fixed attribute , donotmove attribute when drag , let go, perhaps want node stay fixed (for children mean), using d.fixed here cause conflict :

graph.nodes.foreach(function(d, i) {   d.donotmove = false;   if (i == 0) {d.donotmove = true; d.fixed = true;} }) 

and when calling drag events, check donotmove attribute :

var drag = d3.behavior.drag()   .origin(function(d) {     return d;   })   .on("dragstart", function(d) {      if (d.donotmove) return;     dragstarted(d)   })   .on("drag", function(d) {      if (d.donotmove) return;     dragged(d)   })   .on("dragend", function(d) {      if (d.donotmove) return;     dragended(d)   }) 

hope helps :)


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -