Next we need some data. I'm just using something that looks like a matrix:
let data = [
[0, 1],
[2, 4]
]
Then we decide how big it should be. If you're going to use this inside React, it's nice to make a named div and size the div correctly up front, so that the screen doesn't flicker.
To handle the user's selections, the chart lets you define a callback and you receive the min and max values, so you can call out to your code and do whatever you need.
function brushed() {
x.domain(brush.empty() ? x.domain() : brush.extent());
}
function brushend() {
if (self.props.facetHandler) {
self.props.facetHandler(brush.extent()[0], brush.extent[1]);
}
}
The callback gets run every time the user drags, not just when they are finished. One simple way to resolve this is to debounce the callback:
let _ = require('lodash');
let facetHandler = _.debounce(this.props.facetHandler, 250);