From 0eed38b771778f8c7c5cec299e178d65c616e450 Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 6 Jan 2025 14:32:10 -0600 Subject: [PATCH] Fix playback sessions num days listened in last year to be accurate for smaller screen sizes --- client/components/stats/Heatmap.vue | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/client/components/stats/Heatmap.vue b/client/components/stats/Heatmap.vue index 4e49162100..4fc8ca0483 100644 --- a/client/components/stats/Heatmap.vue +++ b/client/components/stats/Heatmap.vue @@ -63,9 +63,6 @@ export default { dayOfWeekToday() { return new Date().getDay() }, - firstWeekStart() { - return this.$addDaysToToday(-this.daysToShow) - }, dayLabels() { return [ { @@ -198,12 +195,25 @@ export default { let minValue = 0 const dates = [] - for (let i = 0; i < this.daysToShow + 1; i++) { - const date = i === 0 ? this.firstWeekStart : this.$addDaysToDate(this.firstWeekStart, i) + + const numDaysInTheLastYear = 52 * 7 + this.dayOfWeekToday + const firstDay = this.$addDaysToToday(-numDaysInTheLastYear) + for (let i = 0; i < numDaysInTheLastYear + 1; i++) { + const date = i === 0 ? firstDay : this.$addDaysToDate(firstDay, i) const dateString = this.$formatJsDate(date, 'yyyy-MM-dd') + + if (this.daysListening[dateString] > 0) { + this.daysListenedInTheLastYear++ + } + + const visibleDayIndex = i - (numDaysInTheLastYear - this.daysToShow) + if (visibleDayIndex < 0) { + continue + } + const dateObj = { - col: Math.floor(i / 7), - row: i % 7, + col: Math.floor(visibleDayIndex / 7), + row: visibleDayIndex % 7, date, dateString, datePretty: this.$formatJsDate(date, 'MMM d, yyyy'), @@ -215,7 +225,6 @@ export default { dates.push(dateObj) if (dateObj.value > 0) { - this.daysListenedInTheLastYear++ if (dateObj.value > maxValue) maxValue = dateObj.value if (!minValue || dateObj.value < minValue) minValue = dateObj.value }