animateHeatmap = {
let currentMonthIndex = 0;
function update(month) {
console.log(`Updating heatmap for month: ${month}`);
const monthData = processedData.filter((d) => d.month === month);
console.log(`Data for month:`, monthData);
const svgElement = d3.select(svg);
svgElement
.selectAll("rect")
.data(monthData, (d) => d.dayOfWeek + ":" + d.hourOfDay)
.join(
(enter) => enter.append("rect"),
(update) => update,
(exit) => exit.remove()
)
.transition()
.duration(500)
.attr("fill", (d) => scales.colorScale(d.count))
.attr("x", (d) => scales.xScale(d.hourOfDay))
.attr("y", (d) => scales.yScale(d.dayOfWeek))
.attr("width", scales.xScale.bandwidth())
.attr("height", scales.yScale.bandwidth());
svgElement
.selectAll("text.month-display")
.data([month])
.join(
(enter) =>
enter
.append("text")
.attr("class", "month-display")
.attr("x", width / 2)
.attr("y", height + margin.bottom - 10)
.attr("dy", "1em")
.style("text-anchor", "middle")
.text((d) => `Month: ${d}`),
(update) => update.text((d) => `Month: ${d}`)
);
}
const interval = d3.interval(() => {
update(sortedMonths[currentMonthIndex]);
currentMonthIndex = (currentMonthIndex + 1) % sortedMonths.length;
}, 3000);
return () => interval.stop();
}