histogram = (g) => {
const hist = d3
.histogram()
.value((d) => d[0])
.domain(x.domain())
.thresholds(x.ticks(80));
let bins = hist(data);
const yHeight = y.range()[0] - y.range()[1];
const yHist = d3
.scaleLinear()
.range([yHeight, 0])
.domain([0, d3.max(bins, (d) => d.length)]);
return g
.selectAll(".histRect")
.data(bins)
.join("rect")
.attr("class", "histRect")
.attr("x", 1)
.attr("transform", function (d) {
return (
"translate(" + x(d.x0) + "," + (yHist(d.length) + margin.top) + ")"
);
})
.attr("width", function (d) {
return x(d.x1) - x(d.x0);
})
.attr("height", function (d) {
return yHeight - yHist(d.length);
})
.style("fill", color)
.style("stroke", "white");
}