Tuesday, 15 April 2014

javascript - Computing average value of d3 force layout node's co-ordinates -



javascript - Computing average value of d3 force layout node's co-ordinates -

i still newbie javascript , d3. wanted compute average value of d3 forcefulness layout node's co-ordinates (remember these nodes flexible, i.e. can moved around mouse drag). saw usage of .map in 1 of answers , tried using there seems problem. right code snippet looks this:

function tick() { var positions = finalnodeset.map(function(d) { homecoming [d.x, d.y]; }); var x1 = 0; var y1 = 0; for(var i=0; i<positions.length; i++){ x1+=positions[[i][0]]; y1+=positions[[i][1]]; }

it seems positions of type object , contains co-ordinates of nodes every 'tick'. want store final values of coordinates , average value of co-ordinates. can help me out this?

link.attr("x1", function (d) { homecoming d.source.x; }) .attr("y1", function (d) { homecoming d.source.y; }) .attr("x2", function (d) { homecoming d.target.x; }) .attr("y2", function (d) { homecoming d.target.y; }); node.each(collide(.5)) .attr("cx", function (d) { homecoming d.x; }) .attr("cy", function (d) { homecoming d.y; }); }

this did me: not require x, y coordinates of lastly 2 nodes(as have fixed value) , exclusion.

var positions = finalnodeset.map(function(d) { homecoming [d.x, d.y]; }); var x1 = 0; var y1 = 0; var xbar=0; var ybar=0; for(var i=0; i<positions.length-2 ; i++){ x1+=positions[[i]][0]; y1+=positions[[i]][1]; var xbar=x1/positions.length-2; var ybar=y1/positions.length-2; } ax1=positions[positions.length-2][0]; ay1=positions[positions.length-2][1]; ax2=positions[positions.length-1][0]; ay1=positions[positions.length-1][1];

javascript d3.js force-layout

No comments:

Post a Comment