viewof focus1 = {
const defaultExtent = [d3.isoParse("2019-11-01"), d3.isoParse("2020-12-01")];
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, focusHeight])
.style("display", "block");
const x = d3
.scaleTime()
.domain([
d3.utcParse("%Y-%m-%d")("2018-12-01"),
d3.utcParse("%Y-%m-%d")("2020-12-01")
])
.range([margin.left, width - margin.right]);
const y = d3
.scaleLinear()
.domain([0, 1])
.range([focusHeight - margin.bottom, margin.top]);
const xAxis = (g, x, height) =>
g.attr("transform", `translate(0,${height - margin.bottom})`).call(
d3
.axisBottom(x)
.ticks(width / 80)
.tickSizeOuter(0)
);
svg.append("g").call(xAxis, x, focusHeight);
const x2 = d3
.scaleBand()
.range([margin.left, width - margin.right], 0.01)
.padding(0.01)
.domain(datesForPlot);
const brush = d3
.brushX()
.extent([
[margin.left, margin.top],
[width - margin.right, focusHeight - margin.bottom]
])
.on("brush", brushed)
.on("end", brushended);
const bars = svg
.selectAll("rect")
.data(filledLineDataScrubber)
.enter()
.append("rect")
.attr("x", (d) => x2(d.date))
.attr("y", (d) => {
return y(1);
})
.attr("width", (d) => x2.bandwidth())
.attr("height", (d) => y(0) - y(1))
.attr("fill", (d) => sstaColors(d.value));
let previousS0, previousS1;
let gb = svg.append("g").call(brush);
if (defaultExtent) gb.call(brush.move, defaultExtent.map(x));
function brushed({ selection }) {
if (selection) {
var s = selection || x.range();
svg.property("value", selection.map(x.invert, x).map(d3.utcMonth.ceil));
svg.dispatch("input");
if (
((s[1] - s[0]) / width) * 120 > 30 ||
((s[1] - s[0]) / width) * 120 < 2
) {
gb.call(brush.move, [previousS0, previousS1]);
return;
}
previousS0 = s[0];
previousS1 = s[1];
}
}
function brushended({ selection }) {
if (!selection) {
gb.call(brush.move, [previousS0, previousS1]);
}
}
return svg.node();
}