Using the quadtree structure to search closest point (pointing in protovis)

1,089 views
Skip to first unread message

Ricardo

unread,
Jul 22, 2011, 12:13:18 PM7/22/11
to d3-js
I'm doing a scatter chart for which I would like to show point labels
as the mouse moves close to those points (same behavior as in
protovis). I could search for the minimum distance from the mouse to
all the points but that seems like a very intensive operation for
"mousemove". I'm assuming a quadtree will help here. Divide and
conquer.

After looking at the quadtree class https://github.com/mbostock/d3/blob/master/src/geom/quadtree.js
I can't find a very nice method such as quadtree.closest(x,y) that
returns a list of the closest nodes (a list because if there are
various nodes at the same location I would like to have them all).
Before embarking in doing this I would like to know if there is
already such function somewhere?

Danny Korenblum

unread,
Mar 14, 2013, 9:15:17 PM3/14/13
to d3...@googlegroups.com, rmar...@stanfordalumni.org
this example should help:


see the 
function search(quadtree, x0, y0, x3, y3) {
  quadtree.visit(function(node, x1, y1, x2, y2)
part of the code, the visit() function gets called recursively as described in
https://github.com/mbostock/d3/wiki/Quadtree-Geom
Reply all
Reply to author
Forward
0 new messages