I am trying to pre-compute the positions of a stable power oriented graph using igraph and transfer them to my d3.js. This is due to the size of the data set that I will use, which means that I cannot rely on the client so that it does not freeze if the calculation of the total force is performed on the client side. I have positions in JSON format and use linear scales to make them useful in d3.js.
var positions = {"positions": [{"x":"-68.824367374", "y": "-6.10824525755"}, {"x":"-80.8080803911", "y": "-3.38997541264"}, {"x":"6.75334817585", "y": "-49.6040729697"}, {"x":"14.6608797291", "y": "-81.8897019921"}, .... var force = d3.layout.force() .charge(-100) .linkDistance(3) .size([width, height]) .nodes(data.nodes) .links(data.links) .start(); var posX = d3.scale.linear() .range([0,960]) .domain([-125,120]); var posY = d3.scale.linear() .range([0,500]) .domain([-125,125]);
And so I tried to do it. I experimented with px and py, but the results are the same. As if this code never ran. If I close console.log as shown below, the value will not be printed. This is regardless of where I put this code, whether before or after the launch of the force.
force.on("start", function() { node .data(positions.positions) .attr("cx", function(d) { console.log(posX(dx)); return posX(dx); }) .attr("cy", function(d) { return posY(dy); }) });
Why doesn't the on start event set the starting positions of my nodes? It seems that they were initialized randomly. Alternatively, what is a good way to pre-calculate the stable state of the directional force graph d3.js? I took a look at this at Phantomjs, but gave up.
Thanks for taking the time to read my question!
EDIT
The following is an example: https://jsfiddle.net/xp0zgqes/ If you run it several times and pay attention to the starting positions of the nodes, you can see that they are accidentally initialized.