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("end", brushended);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(brush);
function brushended(event) {
const selection = event.selection;
if (!event.sourceEvent || !selection) return;
const [x0, x1] = selection.map(d => interval.round(x.invert(d)));
d3.select(this).transition().call(brush.move, x1 > x0 ? [x0, x1].map(x) : null);
}
return svg.node();
}