问题
I am trying to use and understand the D3 visualization library (http://mbostock.github.com/d3/), and I am looking at their force directed code and it seems they are using a quadtree to calculate the force on a particle. The code is
var k = kc * quad.count * dn * dn;
node.px -= dx * k;
node.py -= dy * k;
where it seems thay quad.count is the number of particles in the quadtree node. But looking at their quadtree code in https://github.com/mbostock/d3/blob/master/d3.geom.js#L696, I can't find any reference to count
, and how it is being calculated. I ask because I want to modify some things to perhaps change the "weight" or "charge" of each node.
回答1:
Take a look at the d3_layout_forceAccumulate
method:
https://github.com/mbostock/d3/blob/master/src/layout/force.js#L294-324
The quadtree by itself doesn't compute the center of charge for its particles (because the quadtree only knows about particle positions, and doesn’t make any assumptions about their charges). After the quadtree is generated, the force layout recursively computes the center of charge for each quadrant.
来源:https://stackoverflow.com/questions/7419893/understanding-javascript-d3-visualization-quadtree