From 81757317e5b941c83ccd84604257bc7241e0bb65 Mon Sep 17 00:00:00 2001 From: acx10 Date: Sat, 27 Dec 2025 11:53:53 -0700 Subject: [PATCH] Some chart shuffles --- .../favorite-days-chart.component.scss | 2 +- .../genre-stats-chart.component.scss | 2 +- .../genre-stats-chart.component.ts | 2 +- .../peak-hours-chart.component.scss | 2 +- .../personal-rating-chart.component.html | 19 ++ .../personal-rating-chart.component.scss | 70 +++++ .../personal-rating-chart.component.ts} | 145 ++++++----- .../read-status-chart.component.html | 18 ++ .../read-status-chart.component.scss | 71 ++++++ .../read-status-chart.component.ts} | 65 +++-- .../reading-dna-chart.component.ts | 3 + .../reading-habits-chart.component.ts | 3 + .../reading-heatmap-chart.component.html | 19 ++ .../reading-heatmap-chart.component.scss | 70 +++++ .../reading-heatmap-chart.component.ts | 239 ++++++++++++++++++ .../reading-progress-chart.component.html | 18 ++ .../reading-progress-chart.component.scss | 71 ++++++ .../reading-progress-chart.component.ts} | 197 +++++++-------- .../reading-session-timeline.component.scss | 4 +- .../stats/component/stats-component.html | 30 --- .../stats/component/stats-component.scss | 3 - .../stats/component/stats-component.ts | 14 - .../user-stats/user-stats.component.html | 12 + .../user-stats/user-stats.component.scss | 69 ++++- .../user-stats/user-stats.component.ts | 10 +- .../stats/service/chart-config.service.ts | 19 +- .../service/user-chart-config.service.ts | 81 ++---- 27 files changed, 919 insertions(+), 339 deletions(-) create mode 100644 booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.html create mode 100644 booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.scss rename booklore-ui/src/app/features/stats/{service/personal-rating-chart.service.ts => component/personal-rating-chart/personal-rating-chart.component.ts} (61%) create mode 100644 booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.html create mode 100644 booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.scss rename booklore-ui/src/app/features/stats/{service/read-status-chart.service.ts => component/read-status-chart/read-status-chart.component.ts} (78%) create mode 100644 booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.html create mode 100644 booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.scss create mode 100644 booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.ts create mode 100644 booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.html create mode 100644 booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.scss rename booklore-ui/src/app/features/stats/{service/reading-progress-chart-service.ts => component/reading-progress-chart/reading-progress-chart.component.ts} (51%) diff --git a/booklore-ui/src/app/features/stats/component/favorite-days-chart/favorite-days-chart.component.scss b/booklore-ui/src/app/features/stats/component/favorite-days-chart/favorite-days-chart.component.scss index ef2fc6ec3..0693efef4 100644 --- a/booklore-ui/src/app/features/stats/component/favorite-days-chart/favorite-days-chart.component.scss +++ b/booklore-ui/src/app/features/stats/component/favorite-days-chart/favorite-days-chart.component.scss @@ -45,7 +45,7 @@ .chart-wrapper { position: relative; - height: 350px; + height: 300px; width: 100%; } diff --git a/booklore-ui/src/app/features/stats/component/genre-stats-chart/genre-stats-chart.component.scss b/booklore-ui/src/app/features/stats/component/genre-stats-chart/genre-stats-chart.component.scss index 6881f034b..8dbb9cf4e 100644 --- a/booklore-ui/src/app/features/stats/component/genre-stats-chart/genre-stats-chart.component.scss +++ b/booklore-ui/src/app/features/stats/component/genre-stats-chart/genre-stats-chart.component.scss @@ -37,7 +37,7 @@ .chart-wrapper { position: relative; - height: 350px; + height: 300px; width: 100%; } diff --git a/booklore-ui/src/app/features/stats/component/genre-stats-chart/genre-stats-chart.component.ts b/booklore-ui/src/app/features/stats/component/genre-stats-chart/genre-stats-chart.component.ts index 3f51e23fd..2e0011968 100644 --- a/booklore-ui/src/app/features/stats/component/genre-stats-chart/genre-stats-chart.component.ts +++ b/booklore-ui/src/app/features/stats/component/genre-stats-chart/genre-stats-chart.component.ts @@ -37,7 +37,7 @@ export class GenreStatsChartComponent implements OnInit, OnDestroy { responsive: true, maintainAspectRatio: false, layout: { - padding: {top: 10, bottom: 10, left: 10, right: 10} + padding: {top: 10} }, plugins: { legend: {display: false}, diff --git a/booklore-ui/src/app/features/stats/component/peak-hours-chart/peak-hours-chart.component.scss b/booklore-ui/src/app/features/stats/component/peak-hours-chart/peak-hours-chart.component.scss index a2672e615..30599dc61 100644 --- a/booklore-ui/src/app/features/stats/component/peak-hours-chart/peak-hours-chart.component.scss +++ b/booklore-ui/src/app/features/stats/component/peak-hours-chart/peak-hours-chart.component.scss @@ -45,7 +45,7 @@ .chart-wrapper { position: relative; - height: 350px; + height: 300px; width: 100%; } diff --git a/booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.html b/booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.html new file mode 100644 index 000000000..95dd53258 --- /dev/null +++ b/booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.html @@ -0,0 +1,19 @@ +
+
+
+

+ + Personal Rating Distribution +

+

Books by your rating (1–10)

+
+
+
+ + +
+
+ diff --git a/booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.scss b/booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.scss new file mode 100644 index 000000000..db4010523 --- /dev/null +++ b/booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.scss @@ -0,0 +1,70 @@ +.personal-rating-container { + width: 100%; + overflow-x: auto; +} + +.chart-header { + display: flex; + justify-content: space-between; + align-items: flex-start; + margin-bottom: 0.5rem; + + .chart-title { + flex: 1; + + h3 { + color: var(--text-color, #ffffff); + font-size: 1.25rem; + font-weight: 500; + margin: 0 0 0.5rem 0; + display: flex; + align-items: center; + gap: 0.5rem; + } + + .chart-description { + color: var(--text-secondary-color); + font-size: 0.9rem; + margin: 0; + line-height: 1.4; + } + } +} + +.personal-rating-icon { + font-size: 1.5rem; + color: #FACC15; +} + +.chart-wrapper { + position: relative; + height: 300px; + width: 100%; + min-width: 300px; +} + +@media (max-width: 768px) { + .chart-wrapper { + height: 300px; + min-width: 400px; + } +} + +@media (max-width: 480px) { + .chart-header { + .chart-title { + h3 { + font-size: 1rem; + } + + .chart-description { + font-size: 0.8rem; + } + } + } + + .chart-wrapper { + height: 300px; + min-width: 350px; + } +} diff --git a/booklore-ui/src/app/features/stats/service/personal-rating-chart.service.ts b/booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.ts similarity index 61% rename from booklore-ui/src/app/features/stats/service/personal-rating-chart.service.ts rename to booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.ts index 8ab033647..e59d406d3 100644 --- a/booklore-ui/src/app/features/stats/service/personal-rating-chart.service.ts +++ b/booklore-ui/src/app/features/stats/component/personal-rating-chart/personal-rating-chart.component.ts @@ -1,10 +1,11 @@ -import {inject, Injectable, OnDestroy} from '@angular/core'; +import {Component, inject, OnDestroy, OnInit} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {BaseChartDirective} from 'ng2-charts'; import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs'; -import {map, takeUntil, catchError, filter, first, switchMap} from 'rxjs/operators'; -import {LibraryFilterService} from './library-filter.service'; -import {BookService} from '../../book/service/book.service'; -import {Book} from '../../book/model/book.model'; -import {ChartConfiguration, ChartData, ChartType} from 'chart.js'; +import {catchError, filter, first, takeUntil} from 'rxjs/operators'; +import {ChartConfiguration, ChartData} from 'chart.js'; +import {BookService} from '../../../book/service/book.service'; +import {Book} from '../../../book/model/book.model'; interface RatingStats { ratingRange: string; @@ -42,44 +43,65 @@ const RATING_RANGES = [ {range: '7', min: 7.0, max: 7.0}, {range: '8', min: 8.0, max: 8.0}, {range: '9', min: 9.0, max: 9.0}, - {range: '10', min: 10.0, max: 10.0}, - {range: 'No Rating', min: 0, max: 0} + {range: '10', min: 10.0, max: 10.0} ] as const; type RatingChartData = ChartData<'bar', number[], string>; -@Injectable({ - providedIn: 'root' +@Component({ + selector: 'app-personal-rating-chart', + standalone: true, + imports: [CommonModule, BaseChartDirective], + templateUrl: './personal-rating-chart.component.html', + styleUrls: ['./personal-rating-chart.component.scss'] }) -export class PersonalRatingChartService implements OnDestroy { +export class PersonalRatingChartComponent implements OnInit, OnDestroy { private readonly bookService = inject(BookService); - private readonly libraryFilterService = inject(LibraryFilterService); private readonly destroy$ = new Subject(); - public readonly personalRatingChartType = 'bar' as const; + public readonly chartType = 'bar' as const; - public readonly personalRatingChartOptions: ChartConfiguration['options'] = { + public readonly chartOptions: ChartConfiguration['options'] = { responsive: true, maintainAspectRatio: false, + layout: { + padding: {top: 25} + }, plugins: { legend: {display: false}, tooltip: { - backgroundColor: 'rgba(0, 0, 0, 0.8)', + enabled: true, + backgroundColor: 'rgba(0, 0, 0, 0.9)', titleColor: '#ffffff', bodyColor: '#ffffff', - borderColor: '#666666', + borderColor: '#ffffff', borderWidth: 1, + cornerRadius: 6, + displayColors: true, + padding: 12, + titleFont: {size: 14, weight: 'bold'}, + bodyFont: {size: 13}, callbacks: { - title: (context) => `Personal Rating Range: ${context[0].label}`, + title: (context) => `Personal Rating: ${context[0].label}`, label: (context) => { const value = context.parsed.y; return `${value} book${value === 1 ? '' : 's'}`; } } - } + }, + datalabels: {display: false} }, scales: { x: { + title: { + display: true, + text: 'Personal Rating', + color: '#ffffff', + font: { + family: "'Inter', sans-serif", + size: 12 + } + }, ticks: { color: '#ffffff', font: { @@ -87,18 +109,19 @@ export class PersonalRatingChartService implements OnDestroy { size: 11 } }, - grid: {color: 'rgba(255, 255, 255, 0.1)'}, + grid: {display: false}, + border: {display: false} + }, + y: { title: { display: true, - text: 'Personal Rating Range', + text: 'Number of Books', color: '#ffffff', font: { family: "'Inter', sans-serif", - size: 11.5 + size: 12 } - } - }, - y: { + }, beginAtZero: true, ticks: { color: '#ffffff', @@ -106,23 +129,18 @@ export class PersonalRatingChartService implements OnDestroy { family: "'Inter', sans-serif", size: 11 }, - stepSize: 1 + stepSize: 1, + maxTicksLimit: 8 }, - grid: {color: 'rgba(255, 255, 255, 0.05)'}, - title: { - display: true, - text: 'Number of Books', - color: '#ffffff', - font: { - family: "'Inter', sans-serif", - size: 11.5 - } - } + grid: { + color: 'rgba(255, 255, 255, 0.1)' + }, + border: {display: false} } } }; - private readonly personalRatingChartDataSubject = new BehaviorSubject({ + private readonly chartDataSubject = new BehaviorSubject({ labels: [], datasets: [{ label: 'Books by Personal Rating', @@ -132,23 +150,18 @@ export class PersonalRatingChartService implements OnDestroy { }] }); - public readonly personalRatingChartData$: Observable = - this.personalRatingChartDataSubject.asObservable(); + public readonly chartData$: Observable = this.chartDataSubject.asObservable(); - constructor() { + ngOnInit(): void { this.bookService.bookState$ .pipe( filter(state => state.loaded), first(), - switchMap(() => - this.libraryFilterService.selectedLibrary$.pipe( - takeUntil(this.destroy$) - ) - ), catchError((error) => { - console.error('Error processing personal rating stats:', error); + console.error('Error processing personal rating data:', error); return EMPTY; - }) + }), + takeUntil(this.destroy$) ) .subscribe(() => { const stats = this.calculatePersonalRatingStats(); @@ -163,17 +176,25 @@ export class PersonalRatingChartService implements OnDestroy { private updateChartData(stats: RatingStats[]): void { try { - const labels = stats.map(s => s.ratingRange); - const dataValues = stats.map(s => s.count); - const colors = stats.map((_, index) => CHART_COLORS[index % CHART_COLORS.length]); + // Always show all rating labels from 1-10, even if there's no data + const allLabels = RATING_RANGES.map(r => r.range); + const dataValues = allLabels.map(label => { + const stat = stats.find(s => s.ratingRange === label); + return stat ? stat.count : 0; + }); + const colors = allLabels.map((_, index) => CHART_COLORS[index % CHART_COLORS.length]); - this.personalRatingChartDataSubject.next({ - labels, + this.chartDataSubject.next({ + labels: allLabels, datasets: [{ label: 'Books by Personal Rating', data: dataValues, backgroundColor: colors, - ...CHART_DEFAULTS + borderColor: colors.map(color => color), + borderWidth: 1, + borderRadius: 4, + barPercentage: 0.8, + categoryPercentage: 0.6 }] }); } catch (error) { @@ -183,26 +204,18 @@ export class PersonalRatingChartService implements OnDestroy { private calculatePersonalRatingStats(): RatingStats[] { const currentState = this.bookService.getCurrentBookState(); - const selectedLibraryId = this.libraryFilterService.getCurrentSelectedLibrary(); if (!this.isValidBookState(currentState)) { return []; } - const filteredBooks = this.filterBooksByLibrary(currentState.books!, selectedLibraryId); - return this.processPersonalRatingStats(filteredBooks); + return this.processPersonalRatingStats(currentState.books!); } private isValidBookState(state: any): boolean { return state?.loaded && state?.books && Array.isArray(state.books) && state.books.length > 0; } - private filterBooksByLibrary(books: Book[], selectedLibraryId: string | number | null): Book[] { - return selectedLibraryId - ? books.filter(book => book.libraryId === selectedLibraryId) - : books; - } - private processPersonalRatingStats(books: Book[]): RatingStats[] { const rangeCounts = new Map(); RATING_RANGES.forEach(range => rangeCounts.set(range.range, {count: 0, totalRating: 0})); @@ -210,12 +223,9 @@ export class PersonalRatingChartService implements OnDestroy { books.forEach(book => { const personalRating = book.personalRating; - if (!personalRating || personalRating === 0) { - const noRatingData = rangeCounts.get('No Rating')!; - noRatingData.count++; - } else { + if (personalRating && personalRating > 0) { for (const range of RATING_RANGES) { - if (range.range !== 'No Rating' && personalRating >= range.min && personalRating <= range.max) { + if (personalRating >= range.min && personalRating <= range.max) { const rangeData = rangeCounts.get(range.range)!; rangeData.count++; rangeData.totalRating += personalRating; @@ -225,6 +235,7 @@ export class PersonalRatingChartService implements OnDestroy { } }); + // Return all ratings, including those with 0 count return RATING_RANGES.map(range => { const data = rangeCounts.get(range.range)!; return { @@ -232,6 +243,6 @@ export class PersonalRatingChartService implements OnDestroy { count: data.count, averageRating: data.count > 0 ? data.totalRating / data.count : 0 }; - }).filter(stat => stat.ratingRange !== 'No Rating'); + }); } } diff --git a/booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.html b/booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.html new file mode 100644 index 000000000..c0cbfc5c9 --- /dev/null +++ b/booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.html @@ -0,0 +1,18 @@ +
+
+
+

+ + Reading Status Distribution +

+

Books by their reading status

+
+
+
+ + +
+
diff --git a/booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.scss b/booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.scss new file mode 100644 index 000000000..37e4d74d9 --- /dev/null +++ b/booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.scss @@ -0,0 +1,71 @@ +.read-status-container { + width: 100%; + overflow-x: auto; +} + +.chart-header { + display: flex; + justify-content: space-between; + align-items: flex-start; + margin-bottom: 0.5rem; + + .chart-title { + flex: 1; + + h3 { + color: var(--text-color, #ffffff); + font-size: 1.25rem; + font-weight: 500; + margin: 0 0 0.5rem 0; + display: flex; + align-items: center; + gap: 0.5rem; + } + + .chart-description { + color: var(--text-secondary-color); + font-size: 0.9rem; + margin: 0; + line-height: 1.4; + } + } +} + +.read-status-icon { + font-size: 1.5rem; + color: #17a2b8; +} + +.chart-wrapper { + position: relative; + height: 300px; + width: 100%; + min-width: 300px; +} + +@media (max-width: 768px) { + .chart-wrapper { + height: 300px; + min-width: 400px; + } +} + +@media (max-width: 480px) { + .chart-header { + .chart-title { + h3 { + font-size: 1rem; + } + + .chart-description { + font-size: 0.8rem; + } + } + } + + .chart-wrapper { + height: 300px; + min-width: 350px; + } +} + diff --git a/booklore-ui/src/app/features/stats/service/read-status-chart.service.ts b/booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.ts similarity index 78% rename from booklore-ui/src/app/features/stats/service/read-status-chart.service.ts rename to booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.ts index a8d7946b5..08c0daf01 100644 --- a/booklore-ui/src/app/features/stats/service/read-status-chart.service.ts +++ b/booklore-ui/src/app/features/stats/component/read-status-chart/read-status-chart.component.ts @@ -1,11 +1,11 @@ -import {inject, Injectable, OnDestroy} from '@angular/core'; +import {Component, inject, OnDestroy, OnInit} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {BaseChartDirective} from 'ng2-charts'; import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs'; -import {map, takeUntil, catchError, filter, first, switchMap} from 'rxjs/operators'; -import {ChartConfiguration, ChartData, ChartType} from 'chart.js'; - -import {LibraryFilterService} from './library-filter.service'; -import {BookService} from '../../book/service/book.service'; -import {Book, ReadStatus} from '../../book/model/book.model'; +import {catchError, filter, first, takeUntil} from 'rxjs/operators'; +import {ChartConfiguration, ChartData} from 'chart.js'; +import {BookService} from '../../../book/service/book.service'; +import {Book, ReadStatus} from '../../../book/model/book.model'; interface ReadingStatusStats { status: string; @@ -27,19 +27,25 @@ const CHART_DEFAULTS = { type StatusChartData = ChartData<'doughnut', number[], string>; -@Injectable({ - providedIn: 'root' +@Component({ + selector: 'app-read-status-chart', + standalone: true, + imports: [CommonModule, BaseChartDirective], + templateUrl: './read-status-chart.component.html', + styleUrls: ['./read-status-chart.component.scss'] }) -export class ReadStatusChartService implements OnDestroy { +export class ReadStatusChartComponent implements OnInit, OnDestroy { private readonly bookService = inject(BookService); - private readonly libraryFilterService = inject(LibraryFilterService); private readonly destroy$ = new Subject(); - public readonly statusChartType: ChartType = 'doughnut'; + public readonly chartType = 'doughnut' as const; - public readonly statusChartOptions: ChartConfiguration['options'] = { + public readonly chartOptions: ChartConfiguration['options'] = { responsive: true, maintainAspectRatio: false, + layout: { + padding: {top: 15} + }, plugins: { legend: { display: true, @@ -47,6 +53,11 @@ export class ReadStatusChartService implements OnDestroy { labels: { padding: 15, usePointStyle: true, + color: '#ffffff', + font: { + family: "'Inter', sans-serif", + size: 12 + }, generateLabels: this.generateLegendLabels.bind(this) } }, @@ -62,7 +73,6 @@ export class ReadStatusChartService implements OnDestroy { padding: 12, titleFont: {size: 14, weight: 'bold'}, bodyFont: {size: 13}, - position: 'nearest', callbacks: { title: (context) => context[0]?.label || '', label: this.formatTooltipLabel @@ -75,7 +85,7 @@ export class ReadStatusChartService implements OnDestroy { } }; - private readonly statusChartDataSubject = new BehaviorSubject({ + private readonly chartDataSubject = new BehaviorSubject({ labels: [], datasets: [{ data: [], @@ -84,22 +94,18 @@ export class ReadStatusChartService implements OnDestroy { }] }); - public readonly statusChartData$: Observable = this.statusChartDataSubject.asObservable(); + public readonly chartData$: Observable = this.chartDataSubject.asObservable(); - constructor() { + ngOnInit(): void { this.bookService.bookState$ .pipe( filter(state => state.loaded), first(), - switchMap(() => - this.libraryFilterService.selectedLibrary$.pipe( - takeUntil(this.destroy$) - ) - ), catchError((error) => { console.error('Error processing reading status stats:', error); return EMPTY; - }) + }), + takeUntil(this.destroy$) ) .subscribe(() => { const stats = this.calculateReadingStatusStats(); @@ -118,7 +124,7 @@ export class ReadStatusChartService implements OnDestroy { const dataValues = stats.map(s => s.count); const colors = this.getColorsForData(stats.length); - this.statusChartDataSubject.next({ + this.chartDataSubject.next({ labels, datasets: [{ data: dataValues, @@ -141,26 +147,18 @@ export class ReadStatusChartService implements OnDestroy { private calculateReadingStatusStats(): ReadingStatusStats[] { const currentState = this.bookService.getCurrentBookState(); - const selectedLibraryId = this.libraryFilterService.getCurrentSelectedLibrary(); if (!this.isValidBookState(currentState)) { return []; } - const filteredBooks = this.filterBooksByLibrary(currentState.books!, String(selectedLibraryId)); - return this.processReadingStatusStats(filteredBooks); + return this.processReadingStatusStats(currentState.books!); } private isValidBookState(state: any): boolean { return state?.loaded && state?.books && Array.isArray(state.books) && state.books.length > 0; } - private filterBooksByLibrary(books: Book[], selectedLibraryId: string | null): Book[] { - return selectedLibraryId && selectedLibraryId !== 'null' - ? books.filter(book => String(book.libraryId) === selectedLibraryId) - : books; - } - private processReadingStatusStats(books: Book[]): ReadingStatusStats[] { if (books.length === 0) { return []; @@ -248,3 +246,4 @@ export class ReadStatusChartService implements OnDestroy { return `${label}: ${value} books (${percentage}%)`; } } + diff --git a/booklore-ui/src/app/features/stats/component/reading-dna-chart/reading-dna-chart.component.ts b/booklore-ui/src/app/features/stats/component/reading-dna-chart/reading-dna-chart.component.ts index 3ec6f76e8..b1c796a54 100644 --- a/booklore-ui/src/app/features/stats/component/reading-dna-chart/reading-dna-chart.component.ts +++ b/booklore-ui/src/app/features/stats/component/reading-dna-chart/reading-dna-chart.component.ts @@ -43,6 +43,9 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy { public readonly chartOptions: ChartConfiguration<'radar'>['options'] = { responsive: true, maintainAspectRatio: false, + layout: { + padding: {top: 15} + }, scales: { r: { beginAtZero: true, diff --git a/booklore-ui/src/app/features/stats/component/reading-habits-chart/reading-habits-chart.component.ts b/booklore-ui/src/app/features/stats/component/reading-habits-chart/reading-habits-chart.component.ts index 0f08422cb..ef9e0e646 100644 --- a/booklore-ui/src/app/features/stats/component/reading-habits-chart/reading-habits-chart.component.ts +++ b/booklore-ui/src/app/features/stats/component/reading-habits-chart/reading-habits-chart.component.ts @@ -43,6 +43,9 @@ export class ReadingHabitsChartComponent implements OnInit, OnDestroy { public readonly chartOptions: ChartConfiguration<'radar'>['options'] = { responsive: true, maintainAspectRatio: false, + layout: { + padding: {top: 15} + }, scales: { r: { beginAtZero: true, diff --git a/booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.html b/booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.html new file mode 100644 index 000000000..e3d022a15 --- /dev/null +++ b/booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.html @@ -0,0 +1,19 @@ +
+
+
+

+ + Reading Activity Heatmap +

+

Monthly reading activity over the past 10 years

+
+
+
+ + +
+
+ diff --git a/booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.scss b/booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.scss new file mode 100644 index 000000000..eac578497 --- /dev/null +++ b/booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.scss @@ -0,0 +1,70 @@ +.reading-heatmap-container { + width: 100%; + overflow-x: auto; +} + +.chart-header { + display: flex; + justify-content: space-between; + align-items: flex-start; + margin-bottom: 0.5rem; + + .chart-title { + flex: 1; + + h3 { + color: var(--text-color, #ffffff); + font-size: 1.25rem; + font-weight: 500; + margin: 0 0 0.5rem 0; + display: flex; + align-items: center; + gap: 0.5rem; + } + + .chart-description { + color: var(--text-secondary-color); + font-size: 0.9rem; + margin: 0; + line-height: 1.4; + } + } +} + +.reading-heatmap-icon { + font-size: 1.5rem; + color: rgba(239, 71, 111, 1); +} + +.chart-wrapper { + position: relative; + height: 300px; + width: 100%; + min-width: 300px; +} + +@media (max-width: 768px) { + .chart-wrapper { + height: 300px; + min-width: 400px; + } +} + +@media (max-width: 480px) { + .chart-header { + .chart-title { + h3 { + font-size: 1rem; + } + + .chart-description { + font-size: 0.8rem; + } + } + } + + .chart-wrapper { + height: 250px; + min-width: 350px; + } +} diff --git a/booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.ts b/booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.ts new file mode 100644 index 000000000..41b483c82 --- /dev/null +++ b/booklore-ui/src/app/features/stats/component/reading-heatmap-chart/reading-heatmap-chart.component.ts @@ -0,0 +1,239 @@ +import {Component, inject, OnDestroy, OnInit} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {BaseChartDirective} from 'ng2-charts'; +import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs'; +import {catchError, filter, first, takeUntil} from 'rxjs/operators'; +import {ChartConfiguration, ChartData} from 'chart.js'; +import {BookService} from '../../../book/service/book.service'; +import {Book} from '../../../book/model/book.model'; + +interface MatrixDataPoint { + x: number; // month (0-11) + y: number; // year index + v: number; // book count +} + +interface YearMonthData { + year: number; + month: number; + count: number; +} + +const MONTH_NAMES = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + +type HeatmapChartData = ChartData<'matrix', MatrixDataPoint[], string>; + +@Component({ + selector: 'app-reading-heatmap-chart', + standalone: true, + imports: [CommonModule, BaseChartDirective], + templateUrl: './reading-heatmap-chart.component.html', + styleUrls: ['./reading-heatmap-chart.component.scss'] +}) +export class ReadingHeatmapChartComponent implements OnInit, OnDestroy { + private readonly bookService = inject(BookService); + private readonly destroy$ = new Subject(); + + public readonly chartType = 'matrix' as const; + + private yearLabels: string[] = []; + private maxBookCount = 1; + + public readonly chartOptions: ChartConfiguration['options'] = { + responsive: true, + maintainAspectRatio: false, + layout: { + padding: { + top: 30 + } + }, + plugins: { + legend: {display: false}, + tooltip: { + enabled: true, + backgroundColor: 'rgba(0, 0, 0, 0.95)', + titleColor: '#ffffff', + bodyColor: '#ffffff', + borderColor: '#ef476f', + borderWidth: 2, + cornerRadius: 8, + displayColors: false, + padding: 16, + titleFont: {size: 14, weight: 'bold'}, + bodyFont: {size: 13}, + callbacks: { + title: (context) => { + const point = context[0].raw as MatrixDataPoint; + const year = this.yearLabels[point.y]; + const month = MONTH_NAMES[point.x]; + return `${month} ${year}`; + }, + label: (context) => { + const point = context.raw as MatrixDataPoint; + return `${point.v} book${point.v === 1 ? '' : 's'} read`; + } + } + }, + datalabels: { + display: true, + color: '#ffffff', + font: { + family: "'Inter', sans-serif", + size: 10, + weight: 'bold' + }, + formatter: (value: MatrixDataPoint) => value.v > 0 ? value.v.toString() : '' + } + }, + scales: { + x: { + type: 'linear', + position: 'bottom', + ticks: { + stepSize: 1, + callback: (value) => MONTH_NAMES[value as number] || '', + color: '#ffffff', + font: { + family: "'Inter', sans-serif", + size: 11 + } + }, + grid: {display: false}, + }, + y: { + type: 'linear', + ticks: { + stepSize: 1, + callback: (value) => this.yearLabels[value as number] || '', + color: '#ffffff', + font: { + family: "'Inter', sans-serif", + size: 11 + } + }, + grid: {display: false}, + } + } + }; + + private readonly chartDataSubject = new BehaviorSubject({ + labels: [], + datasets: [{ + label: 'Books Read', + data: [] + }] + }); + + public readonly chartData$: Observable = this.chartDataSubject.asObservable(); + + ngOnInit(): void { + this.bookService.bookState$ + .pipe( + filter(state => state.loaded), + first(), + catchError((error) => { + console.error('Error processing reading heatmap data:', error); + return EMPTY; + }), + takeUntil(this.destroy$) + ) + .subscribe(() => { + const stats = this.calculateHeatmapData(); + this.updateChartData(stats); + }); + } + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + + private updateChartData(yearMonthData: YearMonthData[]): void { + const currentYear = new Date().getFullYear(); + const currentMonth = new Date().getMonth(); + const years = Array.from({length: 10}, (_, i) => currentYear - 9 + i); + + this.yearLabels = years.map(String); + this.maxBookCount = Math.max(1, ...yearMonthData.map(d => d.count)); + + const heatmapData: MatrixDataPoint[] = []; + + years.forEach((year, yearIndex) => { + const maxMonth = year === currentYear ? currentMonth : 11; + + for (let month = 0; month <= maxMonth; month++) { + const dataPoint = yearMonthData.find(d => d.year === year && d.month === month + 1); + heatmapData.push({ + x: month, + y: yearIndex, + v: dataPoint?.count || 0 + }); + } + }); + + if (this.chartOptions?.scales?.['y']) { + (this.chartOptions.scales['y'] as any).max = years.length - 0.5; + } + + this.chartDataSubject.next({ + labels: [], + datasets: [{ + label: 'Books Read', + data: heatmapData, + backgroundColor: (context) => { + const point = context.raw as MatrixDataPoint; + if (!point?.v) return 'rgba(255, 255, 255, 0.05)'; + + const intensity = point.v / this.maxBookCount; + const alpha = Math.max(0.2, Math.min(1.0, intensity * 0.8 + 0.2)); + return `rgba(239, 71, 111, ${alpha})`; + }, + borderColor: 'rgba(255, 255, 255, 0.2)', + borderWidth: 1, + width: ({chart}) => (chart.chartArea?.width || 0) / 12 - 1, + height: ({chart}) => (chart.chartArea?.height || 0) / years.length - 1 + }] + }); + } + + private calculateHeatmapData(): YearMonthData[] { + const currentState = this.bookService.getCurrentBookState(); + + if (!this.isValidBookState(currentState)) { + return []; + } + + return this.processHeatmapData(currentState.books!); + } + + private isValidBookState(state: any): boolean { + return state?.loaded && state?.books && Array.isArray(state.books) && state.books.length > 0; + } + + private processHeatmapData(books: Book[]): YearMonthData[] { + const yearMonthMap = new Map(); + const currentYear = new Date().getFullYear(); + const startYear = currentYear - 9; + + books + .filter(book => book.dateFinished) + .forEach(book => { + const finishedDate = new Date(book.dateFinished!); + const year = finishedDate.getFullYear(); + + if (year >= startYear && year <= currentYear) { + const month = finishedDate.getMonth() + 1; + const key = `${year}-${month}`; + yearMonthMap.set(key, (yearMonthMap.get(key) || 0) + 1); + } + }); + + return Array.from(yearMonthMap.entries()) + .map(([key, count]) => { + const [year, month] = key.split('-').map(Number); + return {year, month, count}; + }) + .sort((a, b) => a.year - b.year || a.month - b.month); + } +} + diff --git a/booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.html b/booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.html new file mode 100644 index 000000000..a99264abb --- /dev/null +++ b/booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.html @@ -0,0 +1,18 @@ +
+
+
+

+ + Reading Progress Distribution +

+

Books by reading completion status

+
+
+
+ + +
+
diff --git a/booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.scss b/booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.scss new file mode 100644 index 000000000..dde00c095 --- /dev/null +++ b/booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.scss @@ -0,0 +1,71 @@ +.reading-progress-container { + width: 100%; + overflow-x: auto; + +} + +.chart-header { + display: flex; + justify-content: space-between; + align-items: flex-start; + margin-bottom: 0.5rem; + + .chart-title { + flex: 1; + + h3 { + color: var(--text-color, #ffffff); + font-size: 1.25rem; + font-weight: 500; + margin: 0 0 0.5rem 0; + display: flex; + align-items: center; + gap: 0.5rem; + } + + .chart-description { + color: var(--text-secondary-color); + font-size: 0.9rem; + margin: 0; + line-height: 1.4; + } + } +} + +.reading-progress-icon { + font-size: 1.5rem; + color: #17a2b8; +} + +.chart-wrapper { + position: relative; + height: 300px; + width: 100%; + min-width: 300px; +} + +@media (max-width: 768px) { + .chart-wrapper { + height: 300px; + min-width: 400px; + } +} + +@media (max-width: 480px) { + .chart-header { + .chart-title { + h3 { + font-size: 1rem; + } + + .chart-description { + font-size: 0.8rem; + } + } + } + + .chart-wrapper { + height: 300px; + min-width: 350px; + } +} diff --git a/booklore-ui/src/app/features/stats/service/reading-progress-chart-service.ts b/booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.ts similarity index 51% rename from booklore-ui/src/app/features/stats/service/reading-progress-chart-service.ts rename to booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.ts index 907949333..af1be6053 100644 --- a/booklore-ui/src/app/features/stats/service/reading-progress-chart-service.ts +++ b/booklore-ui/src/app/features/stats/component/reading-progress-chart/reading-progress-chart.component.ts @@ -1,11 +1,11 @@ -import {inject, Injectable, OnDestroy} from '@angular/core'; +import {Component, inject, OnDestroy, OnInit} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {BaseChartDirective} from 'ng2-charts'; import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs'; -import {map, takeUntil, catchError, filter, first, switchMap} from 'rxjs/operators'; -import {ChartConfiguration, ChartData, ChartType} from 'chart.js'; - -import {LibraryFilterService} from './library-filter.service'; -import {BookService} from '../../book/service/book.service'; -import {Book} from '../../book/model/book.model'; +import {catchError, filter, first, takeUntil} from 'rxjs/operators'; +import {ChartConfiguration, ChartData} from 'chart.js'; +import {BookService} from '../../../book/service/book.service'; +import {Book} from '../../../book/model/book.model'; interface ReadingProgressStats { progressRange: string; @@ -33,78 +33,98 @@ const PROGRESS_RANGES = [ {range: '100%', min: 100, max: 100, desc: 'Completed'} ] as const; -type ProgressChartData = ChartData<'bar', number[], string>; +type ProgressChartData = ChartData<'doughnut', number[], string>; -@Injectable({ - providedIn: 'root' +@Component({ + selector: 'app-reading-progress-chart', + standalone: true, + imports: [CommonModule, BaseChartDirective], + templateUrl: './reading-progress-chart.component.html', + styleUrls: ['./reading-progress-chart.component.scss'] }) -export class ReadingProgressChartService implements OnDestroy { +export class ReadingProgressChartComponent implements OnInit, OnDestroy { private readonly bookService = inject(BookService); - private readonly libraryFilterService = inject(LibraryFilterService); private readonly destroy$ = new Subject(); - public readonly progressChartType: ChartType = 'bar'; + public readonly chartType = 'doughnut' as const; - public readonly progressChartOptions: ChartConfiguration['options'] = { + public readonly chartOptions: ChartConfiguration<'doughnut'>['options'] = { responsive: true, maintainAspectRatio: false, - plugins: { - legend: {display: false}, - tooltip: { - backgroundColor: 'rgba(0, 0, 0, 0.8)', - titleColor: '#ffffff', - bodyColor: '#ffffff', - borderColor: '#666666', - borderWidth: 1, - callbacks: { - title: (context) => context[0].label, - label: this.formatTooltipLabel - } - } + layout: { + padding: {top: 15} }, - scales: { - x: { - ticks: { + plugins: { + legend: { + display: true, + position: 'bottom', + labels: { color: '#ffffff', font: { family: "'Inter', sans-serif", - size: 11 - } - }, - grid: {color: 'rgba(255, 255, 255, 0.1)'}, - title: { - display: true, - text: 'Progress Range', - color: '#ffffff', - font: { - family: "'Inter', sans-serif", - size: 11.5 + size: 12 + }, + padding: 15, + usePointStyle: true, + pointStyle: 'circle', + generateLabels: (chart) => { + const data = chart.data; + if (data.labels?.length && data.datasets?.length) { + return data.labels.map((label, i) => { + const value = data.datasets[0].data[i] as number; + const isVisible = typeof chart.getDataVisibility === 'function' + ? chart.getDataVisibility(i) + : true; + + return { + text: `${label}: ${value}`, + fillStyle: (data.datasets[0].backgroundColor as string[])[i], + strokeStyle: '#ffffff', + lineWidth: 1, + hidden: !isVisible, + index: i, + fontColor: '#ffffff' + }; + }); + } + return []; } } }, - y: { - beginAtZero: true, - ticks: { - color: '#ffffff', font: { - family: "'Inter', sans-serif", - size: 11 - }, stepSize: 1 - }, - grid: {color: 'rgba(255, 255, 255, 0.05)'}, - title: { - display: true, - text: 'Number of Books', - color: '#ffffff', - font: { - family: "'Inter', sans-serif", - size: 11.5 + tooltip: { + enabled: true, + backgroundColor: 'rgba(0, 0, 0, 0.9)', + titleColor: '#ffffff', + bodyColor: '#ffffff', + borderColor: '#ffffff', + borderWidth: 1, + cornerRadius: 6, + displayColors: true, + padding: 12, + titleFont: {size: 14, weight: 'bold'}, + bodyFont: {size: 13}, + callbacks: { + title: (context) => context[0].label, + label: (context) => { + const value = context.parsed; + const total = (context.dataset.data as number[]).reduce((a, b) => a + b, 0); + const percentage = ((value / total) * 100).toFixed(1); + const label = context.label; + const rangeInfo = PROGRESS_RANGES.find(r => r.range === label); + const description = rangeInfo ? ` (${rangeInfo.desc})` : ''; + return `${value} book${value === 1 ? '' : 's'}${description} - ${percentage}%`; } } - } + }, + datalabels: {display: false} + }, + interaction: { + intersect: false, + mode: 'point' } }; - private readonly progressChartDataSubject = new BehaviorSubject({ + private readonly chartDataSubject = new BehaviorSubject({ labels: [], datasets: [{ label: 'Books by Progress', @@ -114,23 +134,18 @@ export class ReadingProgressChartService implements OnDestroy { }] }); - public readonly progressChartData$: Observable = - this.progressChartDataSubject.asObservable(); + public readonly chartData$: Observable = this.chartDataSubject.asObservable(); - constructor() { + ngOnInit(): void { this.bookService.bookState$ .pipe( filter(state => state.loaded), first(), - switchMap(() => - this.libraryFilterService.selectedLibrary$.pipe( - takeUntil(this.destroy$) - ) - ), catchError((error) => { - console.error('Error processing reading progress stats:', error); + console.error('Error processing reading progress data:', error); return EMPTY; - }) + }), + takeUntil(this.destroy$) ) .subscribe(() => { const stats = this.calculateReadingProgressStats(); @@ -148,56 +163,38 @@ export class ReadingProgressChartService implements OnDestroy { const labels = stats.map(s => s.progressRange); const dataValues = stats.map(s => s.count); - this.progressChartDataSubject.next({ + this.chartDataSubject.next({ labels, datasets: [{ label: 'Books by Progress', data: dataValues, backgroundColor: [...CHART_COLORS], - ...CHART_DEFAULTS + borderColor: '#ffffff', + borderWidth: 2, + hoverBorderWidth: 3, + hoverBorderColor: '#ffffff' }] }); } catch (error) { - console.error('Error updating chart data:', error); + console.error('Error updating reading progress chart data:', error); } } private calculateReadingProgressStats(): ReadingProgressStats[] { const currentState = this.bookService.getCurrentBookState(); - const selectedLibraryId = this.libraryFilterService.getCurrentSelectedLibrary(); if (!this.isValidBookState(currentState)) { return []; } - const filteredBooks = this.filterBooksByLibrary(currentState.books!, String(selectedLibraryId)); - return this.processReadingProgressStats(filteredBooks); - } - - public updateFromStats(stats: ReadingProgressStats[]): void { - this.updateChartData(stats); + return this.processReadingProgressStats(currentState.books!); } private isValidBookState(state: any): boolean { return state?.loaded && state?.books && Array.isArray(state.books) && state.books.length > 0; } - private filterBooksByLibrary(books: Book[], selectedLibraryId: string | null): Book[] { - return selectedLibraryId && selectedLibraryId !== 'null' - ? books.filter(book => String(book.libraryId) === selectedLibraryId) - : books; - } - private processReadingProgressStats(books: Book[]): ReadingProgressStats[] { - if (books.length === 0) { - return []; - } - - const rangeCounts = this.buildProgressMap(books); - return this.convertMapToStats(rangeCounts); - } - - private buildProgressMap(books: Book[]): Map { const rangeCounts = new Map(); PROGRESS_RANGES.forEach(range => rangeCounts.set(range.range, 0)); @@ -212,10 +209,6 @@ export class ReadingProgressChartService implements OnDestroy { } } - return rangeCounts; - } - - private convertMapToStats(rangeCounts: Map): ReadingProgressStats[] { return PROGRESS_RANGES.map(range => ({ progressRange: range.range, count: rangeCounts.get(range.range) || 0, @@ -231,12 +224,4 @@ export class ReadingProgressChartService implements OnDestroy { if (book.koboProgress?.percentage) return book.koboProgress.percentage; return 0; } - - private formatTooltipLabel(context: any): string { - const value = context.parsed.y; - const label = context.label; - const rangeInfo = PROGRESS_RANGES.find(r => r.range === label); - const description = rangeInfo ? ` (${rangeInfo.desc})` : ''; - return `${value} book${value === 1 ? '' : 's'}${description}`; - } } diff --git a/booklore-ui/src/app/features/stats/component/reading-session-timeline/reading-session-timeline.component.scss b/booklore-ui/src/app/features/stats/component/reading-session-timeline/reading-session-timeline.component.scss index 7ff6f9ddd..3335e88c6 100644 --- a/booklore-ui/src/app/features/stats/component/reading-session-timeline/reading-session-timeline.component.scss +++ b/booklore-ui/src/app/features/stats/component/reading-session-timeline/reading-session-timeline.component.scss @@ -6,7 +6,7 @@ display: grid; grid-template-columns: 1fr auto 1fr; align-items: flex-start; - margin-bottom: 1rem; + margin-bottom: 0.5rem; gap: 1rem; .header-title { @@ -184,7 +184,7 @@ .hour-label { display: none; - font-size: 0.7rem; + font-size: 0.75rem; color: rgba(255, 255, 255, 0.6); position: absolute; left: 0; diff --git a/booklore-ui/src/app/features/stats/component/stats-component.html b/booklore-ui/src/app/features/stats/component/stats-component.html index 1c87f1d22..bca91d9d0 100644 --- a/booklore-ui/src/app/features/stats/component/stats-component.html +++ b/booklore-ui/src/app/features/stats/component/stats-component.html @@ -177,16 +177,6 @@ @switch (chartConfig.id) { - @case ('readingStatus') { -

Reading Status

-
- - -
- } @case ('bookFormats') {

Book Formats

@@ -257,16 +247,6 @@
} - @case ('readingProgress') { -

Reading Progress

-
- - -
- } @case ('externalRating') {

External Rating Distribution

@@ -277,16 +257,6 @@
} - @case ('personalRating') { -

Personal Rating Distribution

-
- - -
- } @case ('pageCount') {

Page Count Distribution

diff --git a/booklore-ui/src/app/features/stats/component/stats-component.scss b/booklore-ui/src/app/features/stats/component/stats-component.scss index 3d46106e1..a45902419 100644 --- a/booklore-ui/src/app/features/stats/component/stats-component.scss +++ b/booklore-ui/src/app/features/stats/component/stats-component.scss @@ -497,7 +497,6 @@ &.progress-chart, &.rating-chart, - &.personal-rating-chart, &.page-count-chart, &.reading-speed-chart, &.quality-chart, @@ -894,7 +893,6 @@ &.progress-chart, &.rating-chart, - &.personal-rating-chart, &.page-count-chart, &.reading-speed-chart, &.quality-chart, @@ -983,7 +981,6 @@ &.progress-chart, &.rating-chart, - &.personal-rating-chart, &.page-count-chart, &.reading-speed-chart, &.quality-chart, diff --git a/booklore-ui/src/app/features/stats/component/stats-component.ts b/booklore-ui/src/app/features/stats/component/stats-component.ts index d7801c41c..c987ec0f5 100644 --- a/booklore-ui/src/app/features/stats/component/stats-component.ts +++ b/booklore-ui/src/app/features/stats/component/stats-component.ts @@ -13,12 +13,9 @@ import {MatrixController, MatrixElement} from 'chartjs-chart-matrix'; import {PageTitleService} from "../../../shared/service/page-title.service"; import {LibraryFilterService, LibraryOption} from '../service/library-filter.service'; import {LibrariesSummaryService} from '../service/libraries-summary.service'; -import {ReadStatusChartService} from '../service/read-status-chart.service'; import {BookTypeChartService} from '../service/book-type-chart.service'; -import {ReadingProgressChartService} from '../service/reading-progress-chart-service'; import {PageCountChartService} from '../service/page-count-chart.service'; import {BookRatingChartService} from '../service/book-rating-chart.service'; -import {PersonalRatingChartService} from '../service/personal-rating-chart.service'; import {PublicationYearChartService} from '../service/publication-year-chart-service'; import {AuthorPopularityChartService} from '../service/author-popularity-chart.service'; import {ReadingCompletionChartService} from '../service/reading-completion-chart.service'; @@ -50,12 +47,9 @@ export class StatsComponent implements OnInit, OnDestroy { private readonly libraryFilterService = inject(LibraryFilterService); private readonly librariesSummaryService = inject(LibrariesSummaryService); - protected readonly readStatusChartService = inject(ReadStatusChartService); protected readonly bookTypeChartService = inject(BookTypeChartService); - protected readonly readingProgressChartService = inject(ReadingProgressChartService); protected readonly pageCountChartService = inject(PageCountChartService); protected readonly bookRatingChartService = inject(BookRatingChartService); - protected readonly personalRatingChartService = inject(PersonalRatingChartService); protected readonly publicationYearChartService = inject(PublicationYearChartService); protected readonly authorPopularityChartService = inject(AuthorPopularityChartService); protected readonly readingCompletionChartService = inject(ReadingCompletionChartService); @@ -210,13 +204,5 @@ export class StatsComponent implements OnInit, OnDestroy { this.chartConfigService.resetPositions(); } - trackByTrait(index: number, insight: any): string { - return insight.trait; - } - - trackByHabit(index: number, habit: any): string { - return habit.habit; - } - protected readonly ChartDataLabels = ChartDataLabels; } diff --git a/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.html b/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.html index bfc8e2e43..0b7be4b8d 100644 --- a/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.html +++ b/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.html @@ -92,6 +92,18 @@ @case ('reading-habits') { } + @case ('reading-heatmap') { + + } + @case ('personal-rating') { + + } + @case ('reading-progress') { + + } + @case ('read-status') { + + } }
} diff --git a/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.scss b/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.scss index 9a48607bc..8329ce313 100644 --- a/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.scss +++ b/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.scss @@ -274,6 +274,61 @@ transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); } +@media (max-width: 1440px) { + .charts-container { + grid-template-columns: repeat(12, 1fr); + } + + .chart-card { + &.chart-small-square { + grid-column: span 4; + } + + &.chart-small { + grid-column: span 4; + } + + &.chart-medium { + grid-column: span 6; + } + + &.chart-large { + grid-column: span 8; + } + + &.chart-wide { + grid-column: span 12; + } + + &.chart-full { + grid-column: span 12; + } + } +} + +@media (max-width: 1024px) { + .charts-container { + grid-template-columns: repeat(6, 1fr); + } + + .chart-card { + &.chart-small-square, + &.chart-small { + grid-column: span 3; + } + + &.chart-medium { + grid-column: span 3; + } + + &.chart-large, + &.chart-wide, + &.chart-full { + grid-column: span 6; + } + } +} + @media (max-width: 768px) { .user-stats-container { padding: 1rem; @@ -355,7 +410,7 @@ } .charts-container { - grid-template-columns: repeat(6, 1fr); + grid-template-columns: repeat(2, 1fr); gap: 1rem; } @@ -367,12 +422,18 @@ } &.chart-small-square, - &.chart-small, - &.chart-medium, + &.chart-small { + grid-column: span 1; + } + + &.chart-medium { + grid-column: span 1; + } + &.chart-large, &.chart-wide, &.chart-full { - grid-column: span 6; + grid-column: span 2; } } } diff --git a/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.ts b/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.ts index ad8a9fbe2..906166f42 100644 --- a/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.ts +++ b/booklore-ui/src/app/features/stats/component/user-stats/user-stats.component.ts @@ -15,6 +15,10 @@ import {PeakHoursChartComponent} from '../peak-hours-chart/peak-hours-chart.comp import {ReadingDNAChartComponent} from '../reading-dna-chart/reading-dna-chart.component'; import {ReadingHabitsChartComponent} from '../reading-habits-chart/reading-habits-chart.component'; import {UserChartConfig, UserChartConfigService} from '../../service/user-chart-config.service'; +import {ReadingHeatmapChartComponent} from '../reading-heatmap-chart/reading-heatmap-chart.component'; +import {PersonalRatingChartComponent} from '../personal-rating-chart/personal-rating-chart.component'; +import {ReadingProgressChartComponent} from '../reading-progress-chart/reading-progress-chart.component'; +import {ReadStatusChartComponent} from '../read-status-chart/read-status-chart.component'; @Component({ selector: 'app-user-stats', @@ -31,7 +35,11 @@ import {UserChartConfig, UserChartConfigService} from '../../service/user-chart- FavoriteDaysChartComponent, PeakHoursChartComponent, ReadingDNAChartComponent, - ReadingHabitsChartComponent + ReadingHabitsChartComponent, + ReadingHeatmapChartComponent, + PersonalRatingChartComponent, + ReadingProgressChartComponent, + ReadStatusChartComponent ], templateUrl: './user-stats.component.html', styleUrls: ['./user-stats.component.scss'] diff --git a/booklore-ui/src/app/features/stats/service/chart-config.service.ts b/booklore-ui/src/app/features/stats/service/chart-config.service.ts index 1296b6b1b..df2199619 100644 --- a/booklore-ui/src/app/features/stats/service/chart-config.service.ts +++ b/booklore-ui/src/app/features/stats/service/chart-config.service.ts @@ -16,21 +16,18 @@ export class ChartConfigService { private readonly STORAGE_KEY = 'booklore-chart-config'; private readonly defaultCharts: ChartConfig[] = [ - {id: 'readingStatus', name: 'Reading Status', enabled: true, category: 'small', order: 0}, - {id: 'bookFormats', name: 'Book Formats', enabled: true, category: 'small', order: 1}, - {id: 'bookMetadataScore', name: 'Book Metadata Score', enabled: true, category: 'small', order: 2}, - {id: 'languageDistribution', name: 'Language Distribution', enabled: true, category: 'small', order: 3}, + {id: 'bookFormats', name: 'Book Formats', enabled: true, category: 'small', order: 0}, + {id: 'bookMetadataScore', name: 'Book Metadata Score', enabled: true, category: 'small', order: 1}, + {id: 'languageDistribution', name: 'Language Distribution', enabled: true, category: 'small', order: 2}, + {id: 'pageCount', name: 'Page Count Distribution', enabled: true, category: 'medium', order: 3}, {id: 'topAuthors', name: 'Top 25 Authors', enabled: true, category: 'large', order: 4}, {id: 'topCategories', name: 'Top 25 Categories', enabled: true, category: 'large', order: 5}, {id: 'monthlyReadingPatterns', name: 'Monthly Reading Patterns', enabled: true, category: 'large', order: 6}, {id: 'readingVelocityTimeline', name: 'Reading Velocity Timeline', enabled: true, category: 'large', order: 7}, - {id: 'readingProgress', name: 'Reading Progress', enabled: true, category: 'medium', order: 8}, - {id: 'externalRating', name: 'External Rating Distribution', enabled: true, category: 'medium', order: 9}, - {id: 'personalRating', name: 'Personal Rating Distribution', enabled: true, category: 'medium', order: 10}, - {id: 'pageCount', name: 'Page Count Distribution', enabled: true, category: 'medium', order: 11}, - {id: 'topBooksBySize', name: 'Top 20 Largest Books', enabled: true, category: 'large', order: 12}, - {id: 'topSeries', name: 'Top 20 Series', enabled: true, category: 'large', order: 13}, - {id: 'publicationYear', name: 'Publication Year Timeline', enabled: true, category: 'full-width', order: 14} + {id: 'topBooksBySize', name: 'Top 20 Largest Books', enabled: true, category: 'large', order: 8}, + {id: 'topSeries', name: 'Top 20 Series', enabled: true, category: 'large', order: 9}, + {id: 'publicationYear', name: 'Publication Year Timeline', enabled: true, category: 'full-width', order: 10}, + {id: 'externalRating', name: 'External Rating Distribution', enabled: true, category: 'medium', order: 11}, ]; private chartsConfigSubject = new BehaviorSubject(this.loadConfig()); diff --git a/booklore-ui/src/app/features/stats/service/user-chart-config.service.ts b/booklore-ui/src/app/features/stats/service/user-chart-config.service.ts index 973a91e5f..1ba346165 100644 --- a/booklore-ui/src/app/features/stats/service/user-chart-config.service.ts +++ b/booklore-ui/src/app/features/stats/service/user-chart-config.service.ts @@ -8,6 +8,10 @@ import {FavoriteDaysChartComponent} from '../component/favorite-days-chart/favor import {PeakHoursChartComponent} from '../component/peak-hours-chart/peak-hours-chart.component'; import {ReadingDNAChartComponent} from '../component/reading-dna-chart/reading-dna-chart.component'; import {ReadingHabitsChartComponent} from '../component/reading-habits-chart/reading-habits-chart.component'; +import {ReadingHeatmapChartComponent} from '../component/reading-heatmap-chart/reading-heatmap-chart.component'; +import {PersonalRatingChartComponent} from '../component/personal-rating-chart/personal-rating-chart.component'; +import {ReadingProgressChartComponent} from '../component/reading-progress-chart/reading-progress-chart.component'; +import {ReadStatusChartComponent} from '../component/read-status-chart/read-status-chart.component'; export interface UserChartConfig { id: string; @@ -23,71 +27,20 @@ export interface UserChartConfig { }) export class UserChartConfigService { private readonly STORAGE_KEY = 'userStatsChartConfig'; + private readonly defaultCharts: UserChartConfig[] = [ - { - id: 'heatmap', - title: 'Reading Session Heatmap', - component: ReadingSessionHeatmapComponent, - enabled: true, - sizeClass: 'chart-full', - order: 0 - }, - { - id: 'favorite-days', - title: 'Favorite Reading Days', - component: FavoriteDaysChartComponent, - enabled: true, - sizeClass: 'chart-medium', - order: 1 - }, - { - id: 'peak-hours', - title: 'Peak Reading Hours', - component: PeakHoursChartComponent, - enabled: true, - sizeClass: 'chart-medium', - order: 2 - }, - { - id: 'genre-stats', - title: 'Genre Statistics', - component: GenreStatsChartComponent, - enabled: true, - sizeClass: 'chart-medium', - order: 3 - }, - { - id: 'completion-timeline', - title: 'Completion Timeline', - component: CompletionTimelineChartComponent, - enabled: true, - sizeClass: 'chart-medium', - order: 4 - }, - { - id: 'reading-dna', - title: 'Reading DNA Profile', - component: ReadingDNAChartComponent, - enabled: true, - sizeClass: 'chart-medium', - order: 5 - }, - { - id: 'reading-habits', - title: 'Reading Habits Analysis', - component: ReadingHabitsChartComponent, - enabled: true, - sizeClass: 'chart-medium', - order: 6 - }, - { - id: 'timeline', - title: 'Reading Session Timeline', - component: ReadingSessionTimelineComponent, - enabled: true, - sizeClass: 'chart-full', - order: 7 - }, + {id: 'heatmap', title: 'Reading Session Heatmap', component: ReadingSessionHeatmapComponent, enabled: true, sizeClass: 'chart-full', order: 0}, + {id: 'favorite-days', title: 'Favorite Reading Days', component: FavoriteDaysChartComponent, enabled: true, sizeClass: 'chart-medium', order: 1}, + {id: 'peak-hours', title: 'Peak Reading Hours', component: PeakHoursChartComponent, enabled: true, sizeClass: 'chart-medium', order: 2}, + {id: 'timeline', title: 'Reading Session Timeline', component: ReadingSessionTimelineComponent, enabled: true, sizeClass: 'chart-full', order: 3}, + {id: 'reading-heatmap', title: 'Reading Activity Heatmap', component: ReadingHeatmapChartComponent, enabled: true, sizeClass: 'chart-small-square', order: 4}, + {id: 'personal-rating', title: 'Personal Rating Distribution', component: PersonalRatingChartComponent, enabled: true, sizeClass: 'chart-small-square', order: 5}, + {id: 'reading-progress', title: 'Reading Progress Distribution', component: ReadingProgressChartComponent, enabled: true, sizeClass: 'chart-small-square', order: 6}, + {id: 'read-status', title: 'Reading Status Distribution', component: ReadStatusChartComponent, enabled: true, sizeClass: 'chart-small-square', order: 7}, + {id: 'genre-stats', title: 'Genre Statistics', component: GenreStatsChartComponent, enabled: true, sizeClass: 'chart-medium', order: 8}, + {id: 'completion-timeline', title: 'Completion Timeline', component: CompletionTimelineChartComponent, enabled: true, sizeClass: 'chart-medium', order: 9}, + {id: 'reading-dna', title: 'Reading DNA Profile', component: ReadingDNAChartComponent, enabled: true, sizeClass: 'chart-medium', order: 10}, + {id: 'reading-habits', title: 'Reading Habits Analysis', component: ReadingHabitsChartComponent, enabled: true, sizeClass: 'chart-medium', order: 11}, ]; private chartsSubject = new BehaviorSubject(this.loadChartConfig());