Last active
August 29, 2015 14:01
-
-
Save stormpython/d068802b05cd2eb8b1b7 to your computer and use it in GitHub Desktop.
Brush code for histogram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brush = d3.svg.brush() | |
.x(xScale) | |
.on('brushend', brushend); | |
if (dispatch.on('brush')) { | |
svg.append('g') | |
.attr('class', 'brush') | |
.call(brush) | |
.selectAll('rect') | |
.attr('height', height); | |
} | |
function brushend() { | |
var selected, start, lastVal, end, selectedRange; | |
selected = xScale.domain().filter(function(d) { | |
return (brush.extent()[0] <= xScale(d)) && (xScale(d) <= brush.extent()[1]); | |
}); | |
start = selected[0]; | |
lastVal = selected.length - 1; | |
end = selected[lastVal]; | |
selectedRange = [start, end]; | |
return brush.extent()[0] instanceof Date ? | |
dispatch.brush({ | |
range: brush.extent(), | |
config: args, | |
e: d3.event, | |
data: latestData, | |
}) : | |
dispatch.brush({ | |
range: selectedRange, | |
config: args, | |
e: d3.event, | |
data: latestData, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment