Combining semantic zooming and quadtree brushing in D3

543 views Asked by At

I am trying to combine the implementation of a semantic zoom with a brush selection tool with a quadtree on a scatterplot in D3. The idea is that the zoom is active by default. On input selection, A brush is created and the mousedown event of the zoom is deactivated. To speed the brushing, I would like to organize the data that is visible (i.e. the data that has been zoomed on) in a quadtree (c.f. http://bl.ocks.org/mbostock/4343214). But I have no idea how to create the quad tree from the zoom extent only.

I tried creating the quadtree as such:

var scaleX = d3.scale.linear()
        .domain(...)
        .range(...);
var scaleY = d3.scale.linear()
        .domain(...)
        .range(...);
// var data is an array of Objects containing the coordinates (x,y)
var dataCoords = data.map(function(d){return [scaleX(d.x) scaleY(d.y)];});

 /******
Define d3.zoom.extent which does not exist (contrary to d3.brush.extent())
*******/
var s= d3.event.scale;
var t = d3.event.translate;
//top left corner
var tl = ...;
//bottom right corner
var br = ...;
d3Zoom.extent = [tl, br];

/******
Create quadtree from extent
*******/
var quadtree = d3.geom.quadtree()
            .extent(d3Zoom.extent)(dataCoords);

But it does not work. The only way I managed to get a quadtree was to pre-create it using the full svg as extent, before I zoom:

var quadtree = d3.geom.quadtree()
            .extent([[-1, -1], [size + 1, size + 1]])(dataCoords);

When I pre-create the quadtree before zooming on the entire data, and zoom afterward, the quadtree desynchronizes with the newly zoomed data because the values in data depend on the axes scale which are updated during the zoom event (semantic zooming).

I haven't been able to combine http://bl.ocks.org/mbostock/4343214 and Zooming and brushing in d3 force directed graph, and I haven't found anything relevant in http://techslides.com/over-2000-d3-js-examples-and-demos or http://bl.ocks.org or SO.

Could someone please give me a fiddle that shows how to brush on a quadtree that contains only the subset of the data that is zoomed upon?

0

There are 0 answers