viewof selection = {
let selection = data;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.property("value", selection);
const rect = svg.append("g")
.attr("fill", "#d3d3d3")
.selectAll("rect")
.data(bins)
.join("rect")
.attr("x", d => x(d.x0) + 1)
.attr("width", d => Math.max(0, x(d.x1) - x(d.x0) - 1) - 3)
.attr("y", d => y(d.length))
.attr("height", d => y(0) - y(d.length))
.on("click", (event, d) => {
if (selection === d) {
selection = data;
} else {
selection = d;
}
rect.attr("fill", d => selection === d ? "#004F5B" : null);
svg.property("value", selection).dispatch("input");
});
svg.append("g")
.call(xAxis)
svg.append("g")
.call(yAxis);
return svg.node();
}