chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const brush = d3.brushX()
.extent([[margin.left, margin.top], [width - margin.right, height - margin.bottom]])
.on("start brush end", brushed);
const circle = svg.append("g")
.attr("fill-opacity", 0.2)
.selectAll("circle")
.data(Float64Array.from({length: 800}, rx))
.join("circle")
.attr("transform", d => `translate(${x(d)},${ry()})`)
.attr("r", 3.5);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(brush)
.call(brush.move, [0, 5].map(x));
svg.select('.overlay').remove();
svg.select('.selection').style('pointer-events', 'none');
svg.select('.handle--w').style('pointer-events', 'none');
function brushed() {
const selection = d3.event.selection;
if (selection === null) {
circle.attr("stroke", null);
} else {
const [x0, x1] = selection.map(x.invert);
circle.attr("stroke", d => x0 <= d && d <= x1 ? "red" : null);
}
}
return svg.node();
}