I have a list of dates and i tried to have bins representing each days of the week, in order to plot an histogram. The result is somewhat what i wanted, but the last bin have x0=x1, and thus will always be empty. Why is the bin array of 8 elements while i wanted 7 ?
I tried to read the documentation but it seems there is the same issue in provided examples
Here is the code i used:
const monday = new Date(2021, 4, 3) // Monday 3 May 2021, midnight
const next_monday = new Date(2021, 4, 10)
const scale = d3.scaleTime()
.domain([monday, next_monday])
const bins = d3.histogram()
.domain(scale.domain())
.thresholds(scale.ticks(7))
console.log(
bins([
new Date(2021, 4, 3, 15), // 15h, monday
new Date(2021, 4, 9, 15) // 15h, sunday, end of week
])
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
What results looks like:
0: Array [ Date Mon May 03 2021 15:00:00 GMT+0200 (heure d’été d’Europe centrale) ]
x0: Date Mon May 03 2021 00:00:00 GMT+0200 (heure d’été d’Europe centrale)
x1: Date Tue May 04 2021 00:00:00 GMT+0200 (heure d’été d’Europe centrale)
1: Array []
2: Array []
3: Array []
4: Array []
5: Array []
6: Array [ Date Sun May 09 2021 15:00:00 GMT+0200 (heure d’été d’Europe centrale) ]
7: Array []
length: 0
x0: Date Mon May 10 2021 00:00:00 GMT+0200 (heure d’été d’Europe centrale)
x1: Date Mon May 10 2021 00:00:00 GMT+0200 (heure d’été d’Europe centrale)
!!! x1=x0 !!! Why is this bin added ?
<prototype>: Array []
length: 8