viewof focus = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, focusHeight])
.style("display", "block");
const brush = d3
.brushX()
.extent([
[margin.left, 0.5],
[width - margin.right, focusHeight - margin.bottom + 0.5]
])
.on("brush", brushed)
.on("end", brushended);
const defaultSelection = [
x(d3.utcYear.offset(x.domain()[1], -1)),
x.range()[1]
];
svg.append("g").call(xAxis, x, focusHeight);
svg
.append("path")
.datum(data)
.attr("fill", "steelblue")
.attr("d", area(x, y.copy().range([focusHeight - margin.bottom, 4])));
const gb = svg
.append("g")
.call(brush)
.call(brush.move, defaultSelection);
function brushed() {
if (d3.event.selection) {
svg.property(
"value",
d3.event.selection.map(x.invert, x).map(d3.utcDay.round)
);
svg.dispatch("input");
}
}
function brushended() {
if (!d3.event.selection) {
gb.call(brush.move, defaultSelection);
}
}
return svg.node();
}