brushableChart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.property("value", []);
const brush = d3.brush()
.on("start brush end", brushed);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
svg.append("g")
.call(grid);
svg.append("g")
.call(legend);
const dot = svg.append("g")
.selectAll("circle")
.data(mpg)
.join("circle")
.attr("cx", d => x(d.x))
.attr("cy", d => y(d.y))
.attr("r", 3)
.attr("fill", d => color(d.origin))
svg.append("g")
.call(brush);
function brushed({selection}) {
let value = [];
if (selection) {
const [[x0, y0], [x1, y1]] = selection;
value = dot
.attr("fill", "gray")
.filter(d => x0 <= x(d.x) && x(d.x) < x1 && y0 <= y(d.y) && y(d.y) < y1)
.attr("fill", d => color(d.origin))
}
else{
dot.attr("fill", d => color(d.origin));
}
}
return svg.node();
}