Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to stop movement of force directed graph on force.start

I am using force directed graph to show topology data on graphical view. I have written below code:

var force = d3.layout.force()
        .charge(-120)
        .alpha(0)
        .linkDistance(65)
        .gravity(0.03)
        .size([width, height]);

force
      .nodes(data.nodes)
      .links(data.links)
      .start();

When i execute the code graph initialize with some movement which i need to stop. I want a graph display on static position without any movement and all links size should be same on graph initialization. if i will drag then it suppose to move. Any help would be much appreciated....!

like image 235
Maddy Chavda Avatar asked Dec 05 '13 07:12

Maddy Chavda


1 Answers

Here is an example of static force-directed layout initialization.

"Rather than updating the graph with each tick, we run the graph a fixed number of times, and then display it once."

force.start();
for (var i = n * n; i > 0; --i) force.tick();
force.stop();

This doesn't prevent you from setting draggable nodes the usual way:

.call(force.drag);

You can help the links get the settle down to the size you want by controlling the linkStrength

like image 164
Biovisualize Avatar answered Sep 24 '22 22:09

Biovisualize