const brush = d3.brush()
.extent([[0, 0], [width, height]])
.on('brush', onBrush)
.on('end', onEnd);
g.append('g')
.call(brush);
function onBrush(event) {
const [[x1, y1], [x2, y2]] = event.selection;
function isBrushed(d) {
const cx = xScale((d.x0 + d.x1) / 2);
return cx >= x1 && cx <= x2
}
bars.attr('fill', d => isBrushed(d) ? recipeDistColor(d.quartiles[2]) : 'gray');
svg.property('value', comboArrAvgRecipeDist.filter(isBrushed)).dispatch('input');
}
const initialValue = comboArrAvgRecipeDist;
function onEnd(event) {
if (event.selection === null) {
bars.attr('fill', d => recipeDistColor(d.quartiles[2]));
svg.property('value', initialValue).dispatch('input');
}
}