I am trying to highlight selections in my D3 bar chart using the brush extent.
JSFiddle http://jsfiddle.net/Nyquist212/yys2mqkx/
I'm using crossfilter to reduceCount()
my data so I can plot score distribution. But this seems to be screwing with my x-scale. The effect is most noticeable when you drag the entire brush extent.
Online example with full dataset is here (takes a few secs to load).
I'm using linear scales but it appears as if the brush coordinates are out of sync with the bar chart coordinate space (see console logging).
My brush extent does not appear to be correctly binding to the rects
in front of it.
My problem appears to lie around line# 840 where I'm trying to do something like this,
var extent = brush.extent(),
lower = extent[0],
upper = extent[1];
d3.selectAll("rect")
.style("opacity", function(d) {
return d.key >= lower && d.key <= upper || brush.empty() ? "1" : ".4";
})
}
I'm trying to achieve this effect which highlights the selected bars and fades the unselected.
Can someone pls help me understand what I'm doing wrong?
Thanks.