viewof selection = {
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);
const dot = svg.append("g")
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.selectAll("circle")
.data(data)
.join("circle")
.attr("transform", d => `translate(${x(d.x)},${y(d.y)})`)
.attr("r", 3);
svg.call(brush);
function brushed({selection}) {
let value = [];
if (selection) {
const [[x0, y0], [x1, y1]] = selection;
value = dot
.style("stroke", "gray")
.filter(d => x0 <= x(d.x) && x(d.x) < x1 && y0 <= y(d.y) && y(d.y) < y1)
.style("stroke", "steelblue")
.data();
} else {
dot.style("stroke", "steelblue");
}
svg.property("value", value).dispatch("input");
}
return svg.node();
}