Public
Edited
Dec 13, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
const brush = d3.brush()
// set the space that the brush can take up
.extent([[0, 0], [width, height]])
// handle events
.on('brush', onBrush)
.on('end', onEnd);
g.append('g')
.call(brush);
function onBrush(event) {
// event.selection gives us the coordinates of the
// top left and bottom right of the brush box
const [[x1, y1], [x2, y2]] = event.selection;
// return true if the dot is in the brush box, false otherwise
function isBrushed(d) {
const cx = xScale((d.x0 + d.x1) / 2);
return cx >= x1 && cx <= x2
}
// style the dots
bars.attr('fill', d => isBrushed(d) ? recipeDistColor(d.quartiles[2]) : 'gray');
// update the data that appears in the comboArr variable
svg.property('value', comboArrAvgRecipeDist.filter(isBrushed)).dispatch('input');
}

const initialValue = comboArrAvgRecipeDist;
function onEnd(event) {
// if the brush is cleared
if (event.selection === null) {
// reset the color of all of the dots
bars.attr('fill', d => recipeDistColor(d.quartiles[2]));
svg.property('value', initialValue).dispatch('input');
}
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more