Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Javascript D3 visualization quadtree

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.

like image 282
highBandWidth Avatar asked Sep 14 '11 16:09

highBandWidth


1 Answers

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.

like image 120
mbostock Avatar answered Sep 22 '22 13:09

mbostock