Understanding Javascript D3 visualization quadtree

≡放荡痞女 提交于 2019-12-23 10:48:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!