I'm having a problem in getting D3 to perform proper brushing when zooming is performed.
I have a jsFiddle created here http://jsfiddle.net/Gwp25/2/ showing the network with some dummy data I found elsewhere. The operation to follow is this. Zoom in (using mousewheel), then turn on brushing. After doing this, brush the nodes. The nodes that are selected are off - some out of the brush area. Here is the relevant part of the code dealing with the selecting of nodes within the brush extent.
.on("brush", function() {
var extent = d3.event.target.extent();
console.log(extent);
d3.selectAll(".node").select("circle").classed("selected", function(d) {
return d.selected = (extent[0][0] <= x_scale(d.x) && x_scale(d.x) < extent[1][0]
&& extent[0][1] <= d3.tran(d.y) && y_scale(d.y) < extent[1][1]);
});
})
Does anyone have an idea to fix this. I know it's to do with the nodes and their original position and x, but I'm not quite sure about how to get the node x and y with respect to their zoomed location.
Any ideas?