hourDayChart = {
const spec = {
height: height,
y: {
grid: true,
tickFormat: "~s"
},
x: {
label: "Hour of the Day →",
domain: hourScaleDomain
},
marks: [
Plot.rectY(
data,
Plot.binX(
{ y: "count" },
{
x: (d) => hour(d),
filter: (d) =>
inDomain(d.distance, distDomain) &&
inDomain(delay(d), delayDomain) &&
inDomain(d.date, dateDomain)
}
)
),
Plot.ruleY([0])
]
};
let chart = Plot.plot(spec);
const x = chart.scale("x"),
[x1, x2] = x.range;
const y = chart.scale("y"),
[y1, y2] = y.range;
let domain = x.domain;
const wrapper = svg`<svg viewBox="${chart.getAttribute("viewBox")}">${chart}`;
const brush = d3
.brushX()
.extent([
[x1, y2],
[x2, y1]
])
.on("brush end", (event) => {
const { selection, sourceEvent } = event;
domain = selection && selection.map(x.invert);
mutable hourDomain = domain;
});
d3.select(wrapper).call(brush);
return wrapper;
}