Fix inconsistent spacing and label display in reading heatmap chart (#2099)

Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
ACX
2026-01-01 20:06:07 -07:00
committed by GitHub
co-authored by acx10
parent c8e10b5499
commit 5a251d182a
@@ -44,7 +44,7 @@ export class ReadingHeatmapChartComponent implements OnInit, OnDestroy {
maintainAspectRatio: false, maintainAspectRatio: false,
layout: { layout: {
padding: { padding: {
top: 30 top: 20
} }
}, },
plugins: { plugins: {
@@ -102,6 +102,7 @@ export class ReadingHeatmapChartComponent implements OnInit, OnDestroy {
}, },
y: { y: {
type: 'linear', type: 'linear',
offset: true,
ticks: { ticks: {
stepSize: 1, stepSize: 1,
callback: (value) => this.yearLabels[value as number] || '', callback: (value) => this.yearLabels[value as number] || '',
@@ -150,7 +151,6 @@ export class ReadingHeatmapChartComponent implements OnInit, OnDestroy {
private updateChartData(yearMonthData: YearMonthData[]): void { private updateChartData(yearMonthData: YearMonthData[]): void {
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
const currentMonth = new Date().getMonth();
const years = Array.from({length: 10}, (_, i) => currentYear - 9 + i); const years = Array.from({length: 10}, (_, i) => currentYear - 9 + i);
this.yearLabels = years.map(String); this.yearLabels = years.map(String);
@@ -159,9 +159,7 @@ export class ReadingHeatmapChartComponent implements OnInit, OnDestroy {
const heatmapData: MatrixDataPoint[] = []; const heatmapData: MatrixDataPoint[] = [];
years.forEach((year, yearIndex) => { years.forEach((year, yearIndex) => {
const maxMonth = year === currentYear ? currentMonth : 11; for (let month = 0; month <= 11; month++) {
for (let month = 0; month <= maxMonth; month++) {
const dataPoint = yearMonthData.find(d => d.year === year && d.month === month + 1); const dataPoint = yearMonthData.find(d => d.year === year && d.month === month + 1);
heatmapData.push({ heatmapData.push({
x: month, x: month,
@@ -172,7 +170,7 @@ export class ReadingHeatmapChartComponent implements OnInit, OnDestroy {
}); });
if (this.chartOptions?.scales?.['y']) { if (this.chartOptions?.scales?.['y']) {
(this.chartOptions.scales['y'] as any).max = years.length - 0.5; (this.chartOptions.scales['y'] as any).max = years.length - 1;
} }
this.chartDataSubject.next({ this.chartDataSubject.next({