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("brush", brushed);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(brush);
function brushed(event) {
if (!event.sourceEvent) return;
const d0 = event.selection.map(x.invert);
const d1 = d0.map(interval.round);
if (d1[0] >= d1[1]) {
d1[0] = interval.floor(d0[0]);
d1[1] = interval.offset(d1[0]);
}
d3.select(this).call(brush.move, d1.map(x));
}
return svg.node();
}