Introduce three new analytical charts: Taste Ratings, Reading Backlog, and Series Progress (#2383)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+81
@@ -0,0 +1,81 @@
|
||||
<div class="rating-taste-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-chart-scatter rating-taste-icon"></i>
|
||||
Rating Taste Comparison
|
||||
</h3>
|
||||
<p class="chart-description">Compare your personal ratings against external ratings (Goodreads, Amazon, etc.)</p>
|
||||
</div>
|
||||
@if (totalRatedBooks > 0) {
|
||||
<div class="stats-badge">
|
||||
<span class="badge-value">{{ totalRatedBooks }}</span>
|
||||
<span class="badge-label">books analyzed</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
<div class="quadrant-labels">
|
||||
<div class="quadrant-label top-left">Hidden Gems 💎</div>
|
||||
<div class="quadrant-label top-right">Popular Favorites ⭐</div>
|
||||
<div class="quadrant-label bottom-left">Agreed Misses 👎</div>
|
||||
<div class="quadrant-label bottom-right">Overrated 📉</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (quadrants.length > 0) {
|
||||
<div class="taste-insights">
|
||||
<div class="insights-header">
|
||||
<h4>Your Taste Profile</h4>
|
||||
@if (averageDeviation > 0) {
|
||||
<div class="deviation-badge" [class.unique]="averageDeviation > 1" [class.mainstream]="averageDeviation <= 0.5">
|
||||
<span class="deviation-label">Avg. deviation:</span>
|
||||
<span class="deviation-value">{{ averageDeviation.toFixed(2) }} ★</span>
|
||||
<span class="deviation-desc">
|
||||
@if (averageDeviation > 1) {
|
||||
(Unique taste)
|
||||
} @else if (averageDeviation <= 0.5) {
|
||||
(Mainstream)
|
||||
} @else {
|
||||
(Balanced)
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="quadrants-grid">
|
||||
@for (quadrant of quadrants; track quadrant.name) {
|
||||
<div class="quadrant-card" [style.border-left-color]="quadrant.color">
|
||||
<div class="quadrant-header">
|
||||
<span class="quadrant-icon">{{ quadrant.icon }}</span>
|
||||
<span class="quadrant-name">{{ quadrant.name }}</span>
|
||||
<span class="quadrant-count" [style.background-color]="quadrant.color">{{ quadrant.count }}</span>
|
||||
</div>
|
||||
<p class="quadrant-description">{{ quadrant.description }}</p>
|
||||
<div class="quadrant-bar">
|
||||
<div class="bar-fill"
|
||||
[style.width.%]="(quadrant.count / totalRatedBooks) * 100"
|
||||
[style.background-color]="quadrant.color">
|
||||
</div>
|
||||
</div>
|
||||
<span class="quadrant-percentage">{{ ((quadrant.count / totalRatedBooks) * 100).toFixed(0) }}%</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (totalRatedBooks === 0) {
|
||||
<div class="no-data-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<p>No books with both personal and external ratings found.</p>
|
||||
<small>Rate your books and ensure they have external ratings from Goodreads, Amazon, etc.</small>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+336
@@ -0,0 +1,336 @@
|
||||
.rating-taste-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 1rem;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
.stats-badge {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
background: rgba(156, 39, 176, 0.15);
|
||||
border: 1px solid rgba(156, 39, 176, 0.3);
|
||||
border-radius: 8px;
|
||||
padding: 0.5rem 1rem;
|
||||
|
||||
.badge-value {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
color: #9c27b0;
|
||||
}
|
||||
|
||||
.badge-label {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.rating-taste-icon {
|
||||
font-size: 1.5rem;
|
||||
color: rgba(156, 39, 176, 1);
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
position: relative;
|
||||
height: 400px;
|
||||
width: 100%;
|
||||
margin-bottom: 1.5rem;
|
||||
|
||||
.quadrant-labels {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
pointer-events: none;
|
||||
|
||||
.quadrant-label {
|
||||
position: absolute;
|
||||
font-size: 0.7rem;
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
font-weight: 500;
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
|
||||
&.top-left {
|
||||
top: 60px;
|
||||
left: 60px;
|
||||
}
|
||||
|
||||
&.top-right {
|
||||
top: 60px;
|
||||
right: 30px;
|
||||
}
|
||||
|
||||
&.bottom-left {
|
||||
bottom: 60px;
|
||||
left: 60px;
|
||||
}
|
||||
|
||||
&.bottom-right {
|
||||
bottom: 60px;
|
||||
right: 30px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.taste-insights {
|
||||
margin-top: 1.5rem;
|
||||
|
||||
.insights-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
|
||||
h4 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.1rem;
|
||||
font-weight: 500;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.deviation-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.4rem 0.75rem;
|
||||
border-radius: 20px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
font-size: 0.85rem;
|
||||
|
||||
.deviation-label {
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
|
||||
.deviation-value {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.deviation-desc {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
&.unique {
|
||||
background: rgba(156, 39, 176, 0.2);
|
||||
border: 1px solid rgba(156, 39, 176, 0.3);
|
||||
|
||||
.deviation-value {
|
||||
color: #9c27b0;
|
||||
}
|
||||
}
|
||||
|
||||
&.mainstream {
|
||||
background: rgba(76, 175, 80, 0.2);
|
||||
border: 1px solid rgba(76, 175, 80, 0.3);
|
||||
|
||||
.deviation-value {
|
||||
color: #4caf50;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.quadrants-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.quadrant-card {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 8px;
|
||||
padding: 1rem;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-left: 4px solid;
|
||||
position: relative;
|
||||
|
||||
.quadrant-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.quadrant-icon {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.quadrant-name {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-weight: 500;
|
||||
font-size: 0.95rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.quadrant-count {
|
||||
font-weight: 600;
|
||||
font-size: 0.85rem;
|
||||
color: #ffffff;
|
||||
padding: 0.15rem 0.5rem;
|
||||
border-radius: 12px;
|
||||
min-width: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.quadrant-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.8rem;
|
||||
margin: 0 0 0.75rem 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.quadrant-bar {
|
||||
height: 4px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 0.25rem;
|
||||
|
||||
.bar-fill {
|
||||
height: 100%;
|
||||
border-radius: 2px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.quadrant-percentage {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.no-data-message {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem;
|
||||
text-align: center;
|
||||
color: var(--text-secondary-color);
|
||||
|
||||
i {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 1rem;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1rem;
|
||||
margin: 0 0 0.5rem 0;
|
||||
color: var(--text-color, #ffffff);
|
||||
}
|
||||
|
||||
small {
|
||||
font-size: 0.85rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-wrapper {
|
||||
height: 350px;
|
||||
|
||||
.quadrant-labels {
|
||||
.quadrant-label {
|
||||
font-size: 0.6rem;
|
||||
padding: 0.15rem 0.35rem;
|
||||
|
||||
&.top-left {
|
||||
top: 50px;
|
||||
left: 40px;
|
||||
}
|
||||
|
||||
&.top-right {
|
||||
top: 50px;
|
||||
right: 15px;
|
||||
}
|
||||
|
||||
&.bottom-left {
|
||||
bottom: 50px;
|
||||
left: 40px;
|
||||
}
|
||||
|
||||
&.bottom-right {
|
||||
bottom: 50px;
|
||||
right: 15px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.taste-insights {
|
||||
.quadrants-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
.stats-badge {
|
||||
.badge-value {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
.taste-insights {
|
||||
.insights-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
}
|
||||
+370
@@ -0,0 +1,370 @@
|
||||
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, switchMap, takeUntil} from 'rxjs/operators';
|
||||
import {ChartConfiguration, ChartData, ScatterDataPoint} from 'chart.js';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {Book} from '../../../book/model/book.model';
|
||||
import {BookState} from '../../../book/model/state/book-state.model';
|
||||
import {LibraryFilterService} from '../../service/library-filter.service';
|
||||
|
||||
interface TasteQuadrant {
|
||||
name: string;
|
||||
description: string;
|
||||
count: number;
|
||||
color: string;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
interface BookDataPoint extends ScatterDataPoint {
|
||||
bookTitle: string;
|
||||
personalRating: number;
|
||||
personalRatingNormalized: number;
|
||||
externalRating: number;
|
||||
quadrant: string;
|
||||
}
|
||||
|
||||
type RatingTasteChartData = ChartData<'scatter', BookDataPoint[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-rating-taste-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective],
|
||||
templateUrl: './rating-taste-chart.component.html',
|
||||
styleUrls: ['./rating-taste-chart.component.scss']
|
||||
})
|
||||
export class RatingTasteChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly libraryFilterService = inject(LibraryFilterService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'scatter' as const;
|
||||
public quadrants: TasteQuadrant[] = [];
|
||||
public totalRatedBooks = 0;
|
||||
public averageDeviation = 0;
|
||||
|
||||
public readonly chartOptions: ChartConfiguration<'scatter'>['options'] = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
layout: {
|
||||
padding: {top: 20, right: 20, bottom: 10, left: 10}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
min: 0,
|
||||
max: 5,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'External Rating (1-5 scale)',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 12,
|
||||
weight: 500
|
||||
}
|
||||
},
|
||||
ticks: {
|
||||
color: 'rgba(255, 255, 255, 0.8)',
|
||||
stepSize: 1,
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 11
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)',
|
||||
drawTicks: true
|
||||
}
|
||||
},
|
||||
y: {
|
||||
min: 0,
|
||||
max: 5,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Your Personal Rating (normalized from 1-10)',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 12,
|
||||
weight: 500
|
||||
}
|
||||
},
|
||||
ticks: {
|
||||
color: 'rgba(255, 255, 255, 0.8)',
|
||||
stepSize: 1,
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 11
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)',
|
||||
drawTicks: true
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'top',
|
||||
labels: {
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 11
|
||||
},
|
||||
usePointStyle: true,
|
||||
pointStyle: 'circle',
|
||||
padding: 15
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.95)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#9c27b0',
|
||||
borderWidth: 2,
|
||||
cornerRadius: 8,
|
||||
padding: 12,
|
||||
titleFont: {size: 13, weight: 'bold'},
|
||||
bodyFont: {size: 11},
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const point = context[0].raw as BookDataPoint;
|
||||
return point.bookTitle || 'Unknown Book';
|
||||
},
|
||||
label: (context) => {
|
||||
const point = context.raw as BookDataPoint;
|
||||
const diff = point.personalRatingNormalized - point.externalRating;
|
||||
const diffText = diff > 0 ? `+${diff.toFixed(1)}` : diff.toFixed(1);
|
||||
return [
|
||||
`Your Rating: ${point.personalRating}/10 (${point.personalRatingNormalized.toFixed(1)}/5)`,
|
||||
`External Rating: ${point.externalRating.toFixed(1)}/5`,
|
||||
`Difference: ${diffText} (on 5-point scale)`,
|
||||
`Category: ${point.quadrant}`
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
elements: {
|
||||
point: {
|
||||
radius: 6,
|
||||
hoverRadius: 9,
|
||||
borderWidth: 2
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private readonly chartDataSubject = new BehaviorSubject<RatingTasteChartData>({
|
||||
datasets: []
|
||||
});
|
||||
|
||||
public readonly chartData$: Observable<RatingTasteChartData> = this.chartDataSubject.asObservable();
|
||||
|
||||
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 rating taste data:', error);
|
||||
return EMPTY;
|
||||
})
|
||||
)
|
||||
.subscribe(() => {
|
||||
this.calculateAndUpdateChart();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private calculateAndUpdateChart(): void {
|
||||
const currentState = this.bookService.getCurrentBookState();
|
||||
const selectedLibraryId = this.libraryFilterService.getCurrentSelectedLibrary();
|
||||
|
||||
if (!this.isValidBookState(currentState)) {
|
||||
this.chartDataSubject.next({datasets: []});
|
||||
this.quadrants = [];
|
||||
return;
|
||||
}
|
||||
|
||||
const filteredBooks = this.filterBooksByLibrary(currentState.books!, selectedLibraryId);
|
||||
const ratedBooks = this.getBooksWithBothRatings(filteredBooks);
|
||||
|
||||
if (ratedBooks.length === 0) {
|
||||
this.chartDataSubject.next({datasets: []});
|
||||
this.quadrants = [];
|
||||
this.totalRatedBooks = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this.totalRatedBooks = ratedBooks.length;
|
||||
const dataPoints = this.categorizeBooks(ratedBooks);
|
||||
this.updateChartData(dataPoints);
|
||||
this.calculateStatistics(dataPoints);
|
||||
}
|
||||
|
||||
private isValidBookState(state: unknown): state is BookState {
|
||||
return (
|
||||
typeof state === 'object' &&
|
||||
state !== null &&
|
||||
'loaded' in state &&
|
||||
typeof (state as {loaded: boolean}).loaded === 'boolean' &&
|
||||
'books' in state &&
|
||||
Array.isArray((state as {books: unknown}).books) &&
|
||||
(state as {books: Book[]}).books.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
private filterBooksByLibrary(books: Book[], selectedLibraryId: string | number | null): Book[] {
|
||||
return selectedLibraryId
|
||||
? books.filter(book => book.libraryId === selectedLibraryId)
|
||||
: books;
|
||||
}
|
||||
|
||||
private getBooksWithBothRatings(books: Book[]): Book[] {
|
||||
return books.filter(book => {
|
||||
const hasPersonalRating = book.personalRating && book.personalRating > 0;
|
||||
const hasExternalRating = this.getExternalRating(book) > 0;
|
||||
return hasPersonalRating && hasExternalRating;
|
||||
});
|
||||
}
|
||||
|
||||
private getExternalRating(book: Book): number {
|
||||
const ratings: number[] = [];
|
||||
|
||||
if (book.metadata?.goodreadsRating) ratings.push(book.metadata.goodreadsRating);
|
||||
if (book.metadata?.amazonRating) ratings.push(book.metadata.amazonRating);
|
||||
if (book.metadata?.hardcoverRating) ratings.push(book.metadata.hardcoverRating);
|
||||
if (book.metadata?.lubimyczytacRating) ratings.push(book.metadata.lubimyczytacRating);
|
||||
if (book.metadata?.ranobedbRating) ratings.push(book.metadata.ranobedbRating);
|
||||
|
||||
if (ratings.length > 0) {
|
||||
return ratings.reduce((sum, rating) => sum + rating, 0) / ratings.length;
|
||||
}
|
||||
|
||||
if (book.metadata?.rating) return book.metadata.rating;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private categorizeBooks(books: Book[]): Map<string, BookDataPoint[]> {
|
||||
const categories = new Map<string, BookDataPoint[]>([
|
||||
['Hidden Gems', []],
|
||||
['Popular Favorites', []],
|
||||
['Overrated', []],
|
||||
['Agreed Misses', []]
|
||||
]);
|
||||
|
||||
books.forEach(book => {
|
||||
const personalRating = book.personalRating!;
|
||||
// Normalize personal rating from 1-10 to 1-5 scale for comparison
|
||||
const personalRatingNormalized = personalRating / 2;
|
||||
const externalRating = this.getExternalRating(book);
|
||||
const bookTitle = book.metadata?.title || book.fileName || 'Unknown';
|
||||
|
||||
// Use normalized rating (3 is midpoint on 1-5 scale) for quadrant calculation
|
||||
let quadrant: string;
|
||||
if (personalRatingNormalized >= 3 && externalRating >= 3) {
|
||||
quadrant = 'Popular Favorites';
|
||||
} else if (personalRatingNormalized >= 3 && externalRating < 3) {
|
||||
quadrant = 'Hidden Gems';
|
||||
} else if (personalRatingNormalized < 3 && externalRating >= 3) {
|
||||
quadrant = 'Overrated';
|
||||
} else {
|
||||
quadrant = 'Agreed Misses';
|
||||
}
|
||||
|
||||
const dataPoint: BookDataPoint = {
|
||||
x: externalRating,
|
||||
y: personalRatingNormalized,
|
||||
bookTitle,
|
||||
personalRating,
|
||||
personalRatingNormalized,
|
||||
externalRating,
|
||||
quadrant
|
||||
};
|
||||
|
||||
categories.get(quadrant)!.push(dataPoint);
|
||||
});
|
||||
|
||||
return categories;
|
||||
}
|
||||
|
||||
private updateChartData(dataPoints: Map<string, BookDataPoint[]>): void {
|
||||
const quadrantColors: Record<string, {bg: string, border: string}> = {
|
||||
'Popular Favorites': {bg: 'rgba(76, 175, 80, 0.7)', border: '#4caf50'},
|
||||
'Hidden Gems': {bg: 'rgba(156, 39, 176, 0.7)', border: '#9c27b0'},
|
||||
'Overrated': {bg: 'rgba(255, 152, 0, 0.7)', border: '#ff9800'},
|
||||
'Agreed Misses': {bg: 'rgba(158, 158, 158, 0.7)', border: '#9e9e9e'}
|
||||
};
|
||||
|
||||
const datasets = Array.from(dataPoints.entries())
|
||||
.filter(([_, points]) => points.length > 0)
|
||||
.map(([label, points]) => ({
|
||||
label: `${label} (${points.length})`,
|
||||
data: points,
|
||||
backgroundColor: quadrantColors[label].bg,
|
||||
borderColor: quadrantColors[label].border,
|
||||
pointRadius: 6,
|
||||
pointHoverRadius: 9,
|
||||
pointBorderWidth: 2
|
||||
}));
|
||||
|
||||
this.chartDataSubject.next({datasets});
|
||||
}
|
||||
|
||||
private calculateStatistics(dataPoints: Map<string, BookDataPoint[]>): void {
|
||||
const quadrantInfo: Record<string, {description: string, icon: string, color: string}> = {
|
||||
'Popular Favorites': {
|
||||
description: 'Books you and the public both love',
|
||||
icon: '⭐',
|
||||
color: '#4caf50'
|
||||
},
|
||||
'Hidden Gems': {
|
||||
description: 'Books you rate higher than the public',
|
||||
icon: '💎',
|
||||
color: '#9c27b0'
|
||||
},
|
||||
'Overrated': {
|
||||
description: 'Popular books that disappointed you',
|
||||
icon: '📉',
|
||||
color: '#ff9800'
|
||||
},
|
||||
'Agreed Misses': {
|
||||
description: 'Books neither you nor public enjoyed',
|
||||
icon: '👎',
|
||||
color: '#9e9e9e'
|
||||
}
|
||||
};
|
||||
|
||||
this.quadrants = Array.from(dataPoints.entries()).map(([name, points]) => ({
|
||||
name,
|
||||
description: quadrantInfo[name].description,
|
||||
count: points.length,
|
||||
color: quadrantInfo[name].color,
|
||||
icon: quadrantInfo[name].icon
|
||||
}));
|
||||
|
||||
// Calculate average deviation from external ratings (using normalized personal rating)
|
||||
let totalDeviation = 0;
|
||||
let totalPoints = 0;
|
||||
dataPoints.forEach(points => {
|
||||
points.forEach(point => {
|
||||
totalDeviation += Math.abs(point.personalRatingNormalized - point.externalRating);
|
||||
totalPoints++;
|
||||
});
|
||||
});
|
||||
this.averageDeviation = totalPoints > 0 ? totalDeviation / totalPoints : 0;
|
||||
}
|
||||
}
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
<div class="backlog-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-clock backlog-icon"></i>
|
||||
Reading Backlog Analysis
|
||||
</h3>
|
||||
<p class="chart-description">Track how long books sit in your library and your reading patterns over time</p>
|
||||
</div>
|
||||
@if (stats) {
|
||||
<div class="health-score" [class]="getHealthScoreClass()">
|
||||
<div class="score-circle">
|
||||
<span class="score-value">{{ stats.backlogHealthScore }}</span>
|
||||
</div>
|
||||
<div class="score-info">
|
||||
<span class="score-label">Backlog Health</span>
|
||||
<span class="score-status">{{ getHealthScoreLabel() }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (stats) {
|
||||
<div class="stats-overview">
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon books-icon">
|
||||
<i class="pi pi-book"></i>
|
||||
</div>
|
||||
<div class="stat-content">
|
||||
<span class="stat-value">{{ stats.totalBooks }}</span>
|
||||
<span class="stat-label">Total Books</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon unread-icon">
|
||||
<i class="pi pi-inbox"></i>
|
||||
</div>
|
||||
<div class="stat-content">
|
||||
<span class="stat-value">{{ stats.unreadBooks }}</span>
|
||||
<span class="stat-label">In Backlog</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon age-icon">
|
||||
<i class="pi pi-calendar"></i>
|
||||
</div>
|
||||
<div class="stat-content">
|
||||
<span class="stat-value">{{ formatDays(stats.avgBacklogAge) }}</span>
|
||||
<span class="stat-label">Avg. Library Age</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon velocity-icon">
|
||||
<i class="pi pi-bolt"></i>
|
||||
</div>
|
||||
<div class="stat-content">
|
||||
<span class="stat-value">{{ stats.readingVelocity }}</span>
|
||||
<span class="stat-label">Completed (6mo)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
@if (stats) {
|
||||
<div class="insights-section">
|
||||
<h4>Key Insights</h4>
|
||||
<div class="insights-grid">
|
||||
@if (stats.quickestRead) {
|
||||
<div class="insight-card quickest">
|
||||
<div class="insight-icon">
|
||||
<i class="pi pi-forward"></i>
|
||||
</div>
|
||||
<div class="insight-content">
|
||||
<span class="insight-title">Quickest Read</span>
|
||||
<span class="insight-book">{{ stats.quickestRead.title }}</span>
|
||||
<span class="insight-detail">Read in {{ formatDays(stats.quickestRead.daysToComplete!) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (stats.longestWait) {
|
||||
<div class="insight-card longest">
|
||||
<div class="insight-icon">
|
||||
<i class="pi pi-hourglass"></i>
|
||||
</div>
|
||||
<div class="insight-content">
|
||||
<span class="insight-title">Longest Wait</span>
|
||||
<span class="insight-book">{{ stats.longestWait.title }}</span>
|
||||
<span class="insight-detail">Waited {{ formatDays(stats.longestWait.daysToComplete!) }} to read</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (stats.oldestUnread) {
|
||||
<div class="insight-card oldest">
|
||||
<div class="insight-icon">
|
||||
<i class="pi pi-history"></i>
|
||||
</div>
|
||||
<div class="insight-content">
|
||||
<span class="insight-title">Oldest Unread</span>
|
||||
<span class="insight-book">{{ stats.oldestUnread.title }}</span>
|
||||
<span class="insight-detail">Waiting for {{ formatDays(stats.oldestUnread.daysInLibrary) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (stats.avgDaysToRead > 0) {
|
||||
<div class="insight-card average">
|
||||
<div class="insight-icon">
|
||||
<i class="pi pi-chart-line"></i>
|
||||
</div>
|
||||
<div class="insight-content">
|
||||
<span class="insight-title">Average Time to Read</span>
|
||||
<span class="insight-value-large">{{ formatDays(stats.avgDaysToRead) }}</span>
|
||||
<span class="insight-detail">From acquisition to completion</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bucket-details">
|
||||
<h4>Backlog Breakdown</h4>
|
||||
<div class="bucket-list">
|
||||
@for (bucket of buckets; track bucket.label) {
|
||||
@if (bucket.unread + bucket.reading + bucket.completed > 0) {
|
||||
<div class="bucket-item">
|
||||
<div class="bucket-header">
|
||||
<span class="bucket-label">{{ bucket.label }}</span>
|
||||
<span class="bucket-range">{{ bucket.range }}</span>
|
||||
<span class="bucket-total">{{ bucket.unread + bucket.reading + bucket.completed }} books</span>
|
||||
</div>
|
||||
<div class="bucket-bars">
|
||||
<div class="bucket-bar-container">
|
||||
@if (bucket.unread > 0) {
|
||||
<div class="bucket-bar unread"
|
||||
[style.flex]="bucket.unread"
|
||||
[title]="bucket.unread + ' unread'">
|
||||
{{ bucket.unread }}
|
||||
</div>
|
||||
}
|
||||
@if (bucket.reading > 0) {
|
||||
<div class="bucket-bar reading"
|
||||
[style.flex]="bucket.reading"
|
||||
[title]="bucket.reading + ' reading'">
|
||||
{{ bucket.reading }}
|
||||
</div>
|
||||
}
|
||||
@if (bucket.completed > 0) {
|
||||
<div class="bucket-bar completed"
|
||||
[style.flex]="bucket.completed"
|
||||
[title]="bucket.completed + ' completed'">
|
||||
{{ bucket.completed }}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@if (bucket.avgDaysToRead !== null) {
|
||||
<span class="bucket-avg">Avg. {{ formatDays(bucket.avgDaysToRead) }} to read</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!stats) {
|
||||
<div class="no-data-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<p>No books with addition dates found.</p>
|
||||
<small>Backlog analysis requires books with "Added On" dates in your library.</small>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+485
@@ -0,0 +1,485 @@
|
||||
.backlog-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 1.5rem;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
min-width: 250px;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
.health-score {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 12px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 2px solid;
|
||||
|
||||
&.healthy {
|
||||
border-color: rgba(76, 175, 80, 0.5);
|
||||
background: rgba(76, 175, 80, 0.1);
|
||||
|
||||
.score-circle {
|
||||
background: linear-gradient(135deg, #4caf50, #81c784);
|
||||
}
|
||||
}
|
||||
|
||||
&.moderate {
|
||||
border-color: rgba(255, 193, 7, 0.5);
|
||||
background: rgba(255, 193, 7, 0.1);
|
||||
|
||||
.score-circle {
|
||||
background: linear-gradient(135deg, #ffc107, #ffca28);
|
||||
}
|
||||
}
|
||||
|
||||
&.unhealthy {
|
||||
border-color: rgba(239, 83, 80, 0.5);
|
||||
background: rgba(239, 83, 80, 0.1);
|
||||
|
||||
.score-circle {
|
||||
background: linear-gradient(135deg, #ef5350, #e57373);
|
||||
}
|
||||
}
|
||||
|
||||
.score-circle {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
.score-value {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
|
||||
.score-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.score-label {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.score-status {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color, #ffffff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.backlog-icon {
|
||||
font-size: 1.5rem;
|
||||
color: #2196f3;
|
||||
}
|
||||
|
||||
.stats-overview {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
||||
gap: 1rem;
|
||||
margin-bottom: 1.5rem;
|
||||
|
||||
.stat-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
padding: 1rem;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 10px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
.stat-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 1.1rem;
|
||||
|
||||
&.books-icon {
|
||||
background: rgba(33, 150, 243, 0.2);
|
||||
color: #2196f3;
|
||||
}
|
||||
|
||||
&.unread-icon {
|
||||
background: rgba(239, 83, 80, 0.2);
|
||||
color: #ef5350;
|
||||
}
|
||||
|
||||
&.age-icon {
|
||||
background: rgba(156, 39, 176, 0.2);
|
||||
color: #9c27b0;
|
||||
}
|
||||
|
||||
&.velocity-icon {
|
||||
background: rgba(76, 175, 80, 0.2);
|
||||
color: #4caf50;
|
||||
}
|
||||
}
|
||||
|
||||
.stat-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color, #ffffff);
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
height: 280px;
|
||||
width: 100%;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.insights-section {
|
||||
margin-bottom: 1.5rem;
|
||||
|
||||
h4 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 1rem 0;
|
||||
}
|
||||
|
||||
.insights-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.insight-card {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
padding: 1rem;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 10px;
|
||||
border-left: 3px solid;
|
||||
|
||||
&.quickest {
|
||||
border-left-color: #4caf50;
|
||||
|
||||
.insight-icon {
|
||||
color: #4caf50;
|
||||
background: rgba(76, 175, 80, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
&.longest {
|
||||
border-left-color: #ff9800;
|
||||
|
||||
.insight-icon {
|
||||
color: #ff9800;
|
||||
background: rgba(255, 152, 0, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
&.oldest {
|
||||
border-left-color: #ef5350;
|
||||
|
||||
.insight-icon {
|
||||
color: #ef5350;
|
||||
background: rgba(239, 83, 80, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
&.average {
|
||||
border-left-color: #2196f3;
|
||||
|
||||
.insight-icon {
|
||||
color: #2196f3;
|
||||
background: rgba(33, 150, 243, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
.insight-icon {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.insight-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
|
||||
.insight-title {
|
||||
font-size: 0.7rem;
|
||||
color: var(--text-secondary-color);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.insight-book {
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color, #ffffff);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.insight-value-large {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color, #ffffff);
|
||||
}
|
||||
|
||||
.insight-detail {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
margin-top: 0.15rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.bucket-details {
|
||||
h4 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 1rem 0;
|
||||
}
|
||||
|
||||
.bucket-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.bucket-item {
|
||||
padding: 0.75rem 1rem;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
|
||||
.bucket-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.bucket-label {
|
||||
font-weight: 500;
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.bucket-range {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
padding: 0.15rem 0.5rem;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.bucket-total {
|
||||
margin-left: auto;
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
.bucket-bars {
|
||||
.bucket-bar-container {
|
||||
display: flex;
|
||||
height: 24px;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.bucket-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
color: #ffffff;
|
||||
min-width: 24px;
|
||||
transition: flex 0.3s ease;
|
||||
|
||||
&.unread {
|
||||
background: rgba(239, 83, 80, 0.8);
|
||||
}
|
||||
|
||||
&.reading {
|
||||
background: rgba(255, 193, 7, 0.8);
|
||||
}
|
||||
|
||||
&.completed {
|
||||
background: rgba(76, 175, 80, 0.8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.bucket-avg {
|
||||
display: block;
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.no-data-message {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 3rem;
|
||||
text-align: center;
|
||||
color: var(--text-secondary-color);
|
||||
|
||||
i {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 1rem;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1rem;
|
||||
margin: 0 0 0.5rem 0;
|
||||
color: var(--text-color, #ffffff);
|
||||
}
|
||||
|
||||
small {
|
||||
font-size: 0.85rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-header {
|
||||
.health-score {
|
||||
.score-circle {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
|
||||
.score-value {
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.stats-overview {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
|
||||
.stat-card {
|
||||
.stat-content {
|
||||
.stat-value {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
.insights-section {
|
||||
.insights-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.stats-overview {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.75rem;
|
||||
|
||||
.stat-card {
|
||||
padding: 0.75rem;
|
||||
|
||||
.stat-icon {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
height: 220px;
|
||||
}
|
||||
|
||||
.bucket-details {
|
||||
.bucket-item {
|
||||
.bucket-header {
|
||||
flex-wrap: wrap;
|
||||
|
||||
.bucket-total {
|
||||
width: 100%;
|
||||
margin-left: 0;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+470
@@ -0,0 +1,470 @@
|
||||
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, switchMap, 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';
|
||||
import {BookState} from '../../../book/model/state/book-state.model';
|
||||
import {LibraryFilterService} from '../../service/library-filter.service';
|
||||
|
||||
interface BacklogBucket {
|
||||
label: string;
|
||||
range: string;
|
||||
unread: number;
|
||||
reading: number;
|
||||
completed: number;
|
||||
avgDaysToRead: number | null;
|
||||
books: BookBacklogInfo[];
|
||||
}
|
||||
|
||||
interface BookBacklogInfo {
|
||||
title: string;
|
||||
addedOn: Date;
|
||||
daysInLibrary: number;
|
||||
daysToComplete: number | null;
|
||||
status: ReadStatus;
|
||||
}
|
||||
|
||||
interface BacklogStats {
|
||||
totalBooks: number;
|
||||
unreadBooks: number;
|
||||
avgBacklogAge: number;
|
||||
avgDaysToRead: number;
|
||||
oldestUnread: BookBacklogInfo | null;
|
||||
quickestRead: BookBacklogInfo | null;
|
||||
longestWait: BookBacklogInfo | null;
|
||||
readingVelocity: number;
|
||||
backlogHealthScore: number;
|
||||
}
|
||||
|
||||
type BacklogChartData = ChartData<'bar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-reading-backlog-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective],
|
||||
templateUrl: './reading-backlog-chart.component.html',
|
||||
styleUrls: ['./reading-backlog-chart.component.scss']
|
||||
})
|
||||
export class ReadingBacklogChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly libraryFilterService = inject(LibraryFilterService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'bar' as const;
|
||||
public buckets: BacklogBucket[] = [];
|
||||
public stats: BacklogStats | null = null;
|
||||
|
||||
public readonly chartOptions: ChartConfiguration<'bar'>['options'] = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
indexAxis: 'y',
|
||||
layout: {
|
||||
padding: {top: 10, right: 20, bottom: 10, left: 10}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
stacked: true,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Number of Books',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 12,
|
||||
weight: 500
|
||||
}
|
||||
},
|
||||
ticks: {
|
||||
color: 'rgba(255, 255, 255, 0.8)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 11
|
||||
},
|
||||
stepSize: 1
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
stacked: true,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Time in Library',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 12,
|
||||
weight: 500
|
||||
}
|
||||
},
|
||||
ticks: {
|
||||
color: 'rgba(255, 255, 255, 0.8)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 11
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'top',
|
||||
labels: {
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 11
|
||||
},
|
||||
usePointStyle: true,
|
||||
pointStyle: 'rect',
|
||||
padding: 15
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.95)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#2196f3',
|
||||
borderWidth: 2,
|
||||
cornerRadius: 8,
|
||||
padding: 12,
|
||||
titleFont: {size: 13, weight: 'bold'},
|
||||
bodyFont: {size: 11},
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const bucket = this.buckets[context[0].dataIndex];
|
||||
return bucket ? `${bucket.label} (${bucket.range})` : '';
|
||||
},
|
||||
afterBody: (context) => {
|
||||
const bucket = this.buckets[context[0].dataIndex];
|
||||
if (!bucket) return [];
|
||||
const lines = [];
|
||||
if (bucket.avgDaysToRead !== null) {
|
||||
lines.push(`Avg. days to read: ${bucket.avgDaysToRead.toFixed(0)}`);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private readonly chartDataSubject = new BehaviorSubject<BacklogChartData>({
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
|
||||
public readonly chartData$: Observable<BacklogChartData> = this.chartDataSubject.asObservable();
|
||||
|
||||
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 backlog data:', error);
|
||||
return EMPTY;
|
||||
})
|
||||
)
|
||||
.subscribe(() => {
|
||||
this.calculateAndUpdateChart();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private calculateAndUpdateChart(): void {
|
||||
const currentState = this.bookService.getCurrentBookState();
|
||||
const selectedLibraryId = this.libraryFilterService.getCurrentSelectedLibrary();
|
||||
|
||||
if (!this.isValidBookState(currentState)) {
|
||||
this.chartDataSubject.next({labels: [], datasets: []});
|
||||
this.buckets = [];
|
||||
this.stats = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const filteredBooks = this.filterBooksByLibrary(currentState.books!, selectedLibraryId);
|
||||
const booksWithDates = this.getBooksWithAddedDate(filteredBooks);
|
||||
|
||||
if (booksWithDates.length === 0) {
|
||||
this.chartDataSubject.next({labels: [], datasets: []});
|
||||
this.buckets = [];
|
||||
this.stats = null;
|
||||
return;
|
||||
}
|
||||
|
||||
this.buckets = this.calculateBacklogBuckets(booksWithDates);
|
||||
this.stats = this.calculateBacklogStats(booksWithDates);
|
||||
this.updateChartData();
|
||||
}
|
||||
|
||||
private isValidBookState(state: unknown): state is BookState {
|
||||
return (
|
||||
typeof state === 'object' &&
|
||||
state !== null &&
|
||||
'loaded' in state &&
|
||||
typeof (state as {loaded: boolean}).loaded === 'boolean' &&
|
||||
'books' in state &&
|
||||
Array.isArray((state as {books: unknown}).books) &&
|
||||
(state as {books: Book[]}).books.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
private filterBooksByLibrary(books: Book[], selectedLibraryId: string | number | null): Book[] {
|
||||
return selectedLibraryId
|
||||
? books.filter(book => book.libraryId === selectedLibraryId)
|
||||
: books;
|
||||
}
|
||||
|
||||
private getBooksWithAddedDate(books: Book[]): Book[] {
|
||||
return books.filter(book => book.addedOn);
|
||||
}
|
||||
|
||||
private calculateBacklogBuckets(books: Book[]): BacklogBucket[] {
|
||||
const now = new Date();
|
||||
const bucketDefs = [
|
||||
{label: 'Fresh', range: '< 1 week', minDays: 0, maxDays: 7},
|
||||
{label: 'Recent', range: '1-4 weeks', minDays: 7, maxDays: 30},
|
||||
{label: 'Settling', range: '1-3 months', minDays: 30, maxDays: 90},
|
||||
{label: 'Established', range: '3-6 months', minDays: 90, maxDays: 180},
|
||||
{label: 'Seasoned', range: '6-12 months', minDays: 180, maxDays: 365},
|
||||
{label: 'Vintage', range: '1-2 years', minDays: 365, maxDays: 730},
|
||||
{label: 'Archive', range: '2+ years', minDays: 730, maxDays: Infinity}
|
||||
];
|
||||
|
||||
return bucketDefs.map(def => {
|
||||
const bucketBooks: BookBacklogInfo[] = [];
|
||||
let unread = 0;
|
||||
let reading = 0;
|
||||
let completed = 0;
|
||||
let totalDaysToRead = 0;
|
||||
let completedCount = 0;
|
||||
|
||||
books.forEach(book => {
|
||||
const addedDate = new Date(book.addedOn!);
|
||||
const daysInLibrary = Math.floor((now.getTime() - addedDate.getTime()) / (1000 * 60 * 60 * 24));
|
||||
|
||||
if (daysInLibrary >= def.minDays && daysInLibrary < def.maxDays) {
|
||||
let daysToComplete: number | null = null;
|
||||
|
||||
if (book.dateFinished) {
|
||||
const finishedDate = new Date(book.dateFinished);
|
||||
daysToComplete = Math.floor((finishedDate.getTime() - addedDate.getTime()) / (1000 * 60 * 60 * 24));
|
||||
if (daysToComplete < 0) daysToComplete = 0;
|
||||
}
|
||||
|
||||
const bookInfo: BookBacklogInfo = {
|
||||
title: book.metadata?.title || book.fileName || 'Unknown',
|
||||
addedOn: addedDate,
|
||||
daysInLibrary,
|
||||
daysToComplete,
|
||||
status: book.readStatus || ReadStatus.UNSET
|
||||
};
|
||||
|
||||
bucketBooks.push(bookInfo);
|
||||
|
||||
switch (book.readStatus) {
|
||||
case ReadStatus.READING:
|
||||
case ReadStatus.RE_READING:
|
||||
reading++;
|
||||
break;
|
||||
case ReadStatus.READ:
|
||||
completed++;
|
||||
if (daysToComplete !== null) {
|
||||
totalDaysToRead += daysToComplete;
|
||||
completedCount++;
|
||||
}
|
||||
break;
|
||||
case ReadStatus.UNREAD:
|
||||
case ReadStatus.UNSET:
|
||||
case ReadStatus.PAUSED:
|
||||
case ReadStatus.WONT_READ:
|
||||
case ReadStatus.ABANDONED:
|
||||
case ReadStatus.PARTIALLY_READ:
|
||||
default:
|
||||
unread++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
label: def.label,
|
||||
range: def.range,
|
||||
unread,
|
||||
reading,
|
||||
completed,
|
||||
avgDaysToRead: completedCount > 0 ? totalDaysToRead / completedCount : null,
|
||||
books: bucketBooks
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private calculateBacklogStats(books: Book[]): BacklogStats {
|
||||
const now = new Date();
|
||||
let totalDaysInLibrary = 0;
|
||||
let totalDaysToRead = 0;
|
||||
let completedWithDates = 0;
|
||||
let unreadBooks = 0;
|
||||
let oldestUnread: BookBacklogInfo | null = null;
|
||||
let quickestRead: BookBacklogInfo | null = null;
|
||||
let longestWait: BookBacklogInfo | null = null;
|
||||
let recentlyCompleted = 0;
|
||||
|
||||
const sixMonthsAgo = new Date();
|
||||
sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
|
||||
|
||||
books.forEach(book => {
|
||||
const addedDate = new Date(book.addedOn!);
|
||||
const daysInLibrary = Math.floor((now.getTime() - addedDate.getTime()) / (1000 * 60 * 60 * 24));
|
||||
totalDaysInLibrary += daysInLibrary;
|
||||
|
||||
let daysToComplete: number | null = null;
|
||||
if (book.dateFinished) {
|
||||
const finishedDate = new Date(book.dateFinished);
|
||||
daysToComplete = Math.floor((finishedDate.getTime() - addedDate.getTime()) / (1000 * 60 * 60 * 24));
|
||||
if (daysToComplete < 0) daysToComplete = 0;
|
||||
|
||||
if (finishedDate > sixMonthsAgo) {
|
||||
recentlyCompleted++;
|
||||
}
|
||||
}
|
||||
|
||||
const bookInfo: BookBacklogInfo = {
|
||||
title: book.metadata?.title || book.fileName || 'Unknown',
|
||||
addedOn: addedDate,
|
||||
daysInLibrary,
|
||||
daysToComplete,
|
||||
status: book.readStatus || ReadStatus.UNSET
|
||||
};
|
||||
|
||||
const isUnread = book.readStatus === ReadStatus.UNREAD ||
|
||||
book.readStatus === ReadStatus.UNSET ||
|
||||
book.readStatus === ReadStatus.PAUSED ||
|
||||
!book.readStatus;
|
||||
|
||||
if (isUnread) {
|
||||
unreadBooks++;
|
||||
if (!oldestUnread || daysInLibrary > oldestUnread.daysInLibrary) {
|
||||
oldestUnread = bookInfo;
|
||||
}
|
||||
}
|
||||
|
||||
if (book.readStatus === ReadStatus.READ && daysToComplete !== null) {
|
||||
totalDaysToRead += daysToComplete;
|
||||
completedWithDates++;
|
||||
|
||||
if (!quickestRead || daysToComplete < (quickestRead.daysToComplete || Infinity)) {
|
||||
quickestRead = bookInfo;
|
||||
}
|
||||
if (!longestWait || daysToComplete > (longestWait.daysToComplete || 0)) {
|
||||
longestWait = bookInfo;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const avgBacklogAge = books.length > 0 ? totalDaysInLibrary / books.length : 0;
|
||||
const avgDaysToRead = completedWithDates > 0 ? totalDaysToRead / completedWithDates : 0;
|
||||
const readingVelocity = recentlyCompleted; // Books completed in last 6 months
|
||||
|
||||
// Backlog health score (0-100)
|
||||
// Lower unread percentage = better
|
||||
// Lower avg backlog age = better
|
||||
// Higher reading velocity = better
|
||||
const unreadPercentage = books.length > 0 ? (unreadBooks / books.length) * 100 : 0;
|
||||
const ageScore = Math.max(0, 100 - (avgBacklogAge / 365) * 50); // Penalize old backlogs
|
||||
const velocityScore = Math.min(100, readingVelocity * 10); // Reward active reading
|
||||
const completionScore = 100 - unreadPercentage;
|
||||
|
||||
const backlogHealthScore = Math.round((ageScore * 0.3 + velocityScore * 0.3 + completionScore * 0.4));
|
||||
|
||||
return {
|
||||
totalBooks: books.length,
|
||||
unreadBooks,
|
||||
avgBacklogAge,
|
||||
avgDaysToRead,
|
||||
oldestUnread,
|
||||
quickestRead,
|
||||
longestWait,
|
||||
readingVelocity,
|
||||
backlogHealthScore: Math.min(100, Math.max(0, backlogHealthScore))
|
||||
};
|
||||
}
|
||||
|
||||
private updateChartData(): void {
|
||||
const labels = this.buckets.map(b => b.label);
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Unread',
|
||||
data: this.buckets.map(b => b.unread),
|
||||
backgroundColor: 'rgba(239, 83, 80, 0.8)',
|
||||
borderColor: '#ef5350',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4
|
||||
},
|
||||
{
|
||||
label: 'Reading',
|
||||
data: this.buckets.map(b => b.reading),
|
||||
backgroundColor: 'rgba(255, 193, 7, 0.8)',
|
||||
borderColor: '#ffc107',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4
|
||||
},
|
||||
{
|
||||
label: 'Completed',
|
||||
data: this.buckets.map(b => b.completed),
|
||||
backgroundColor: 'rgba(76, 175, 80, 0.8)',
|
||||
borderColor: '#4caf50',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
getHealthScoreClass(): string {
|
||||
if (!this.stats) return '';
|
||||
if (this.stats.backlogHealthScore >= 70) return 'healthy';
|
||||
if (this.stats.backlogHealthScore >= 40) return 'moderate';
|
||||
return 'unhealthy';
|
||||
}
|
||||
|
||||
getHealthScoreLabel(): string {
|
||||
if (!this.stats) return '';
|
||||
if (this.stats.backlogHealthScore >= 70) return 'Healthy';
|
||||
if (this.stats.backlogHealthScore >= 40) return 'Moderate';
|
||||
return 'Needs Attention';
|
||||
}
|
||||
|
||||
formatDays(days: number): string {
|
||||
const roundedDays = Math.round(days);
|
||||
if (roundedDays < 7) return `${roundedDays} day${roundedDays !== 1 ? 's' : ''}`;
|
||||
const weeks = Math.round(roundedDays / 7);
|
||||
if (roundedDays < 30) return `${weeks} week${weeks !== 1 ? 's' : ''}`;
|
||||
const months = Math.round(roundedDays / 30);
|
||||
if (roundedDays < 365) return `${months} month${months !== 1 ? 's' : ''}`;
|
||||
const years = Math.round((roundedDays / 365) * 10) / 10; // Round to 1 decimal
|
||||
return `${years} year${years >= 2 ? 's' : ''}`;
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
<div class="series-progress-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-list series-icon"></i>
|
||||
Series Progress Tracker
|
||||
</h3>
|
||||
<p class="chart-description">Track your reading progress across book series</p>
|
||||
</div>
|
||||
@if (stats) {
|
||||
<div class="series-summary">
|
||||
<span class="summary-item completed">
|
||||
<i class="pi pi-check-circle"></i>
|
||||
{{ stats.completedSeries }}
|
||||
</span>
|
||||
<span class="summary-item in-progress">
|
||||
<i class="pi pi-spinner"></i>
|
||||
{{ stats.inProgressSeries }}
|
||||
</span>
|
||||
<span class="summary-item not-started">
|
||||
<i class="pi pi-clock"></i>
|
||||
{{ stats.notStartedSeries }}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (stats) {
|
||||
<div class="stats-row">
|
||||
<div class="stat-pill">
|
||||
<span class="pill-value">{{ stats.totalSeries }}</span>
|
||||
<span class="pill-label">Series</span>
|
||||
</div>
|
||||
<div class="stat-pill">
|
||||
<span class="pill-value">{{ stats.avgSeriesCompletion }}%</span>
|
||||
<span class="pill-label">Avg. Completion</span>
|
||||
</div>
|
||||
@if (stats.highestRatedSeries) {
|
||||
<div class="stat-pill highlight">
|
||||
<span class="pill-value">{{ stats.highestRatedSeries.avgPersonalRating?.toFixed(1) }}</span>
|
||||
<span class="pill-label">Top Rated</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
@if (seriesList.length > 0) {
|
||||
<div class="series-details">
|
||||
<div class="details-header">
|
||||
<h4>Series Breakdown</h4>
|
||||
<span class="series-count">{{ filteredSeriesList.length }} of {{ seriesList.length }}</span>
|
||||
</div>
|
||||
|
||||
<div class="controls-row">
|
||||
<div class="search-box">
|
||||
<i class="pi pi-search"></i>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search series..."
|
||||
[value]="searchTerm"
|
||||
(input)="onSearchChange($any($event.target).value)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="filter-controls">
|
||||
<select class="filter-select" [value]="filterStatus" (change)="onFilterChange($any($event.target).value)">
|
||||
<option value="all">All Status</option>
|
||||
<option value="in-progress">In Progress</option>
|
||||
<option value="completed">Completed</option>
|
||||
<option value="not-started">Not Started</option>
|
||||
</select>
|
||||
|
||||
<select class="sort-select" [value]="sortBy" (change)="onSortChange($any($event.target).value)">
|
||||
<option value="progress">Sort by Progress</option>
|
||||
<option value="rating">Sort by Rating</option>
|
||||
<option value="books">Sort by Books</option>
|
||||
<option value="name">Sort by Name</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="series-list">
|
||||
@for (series of displayedSeries; track series.name) {
|
||||
<div class="series-card" [class]="series.status">
|
||||
<div class="series-main">
|
||||
<div class="series-status-icon" [style.color]="getStatusColor(series.status)">
|
||||
<i [class]="'pi ' + getStatusIcon(series.status)"></i>
|
||||
</div>
|
||||
<div class="series-info">
|
||||
<span class="series-name">{{ series.name }}</span>
|
||||
<div class="series-meta">
|
||||
<span class="books-count">
|
||||
{{ series.booksRead }}/{{ series.booksOwned }} read
|
||||
@if (series.totalInSeries) {
|
||||
<span class="total-hint">({{ series.totalInSeries }} in series)</span>
|
||||
}
|
||||
</span>
|
||||
@if (series.avgPersonalRating) {
|
||||
<span class="rating">
|
||||
<i class="pi pi-star-fill"></i>
|
||||
{{ series.avgPersonalRating.toFixed(1) }}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="series-progress">
|
||||
<div class="progress-bar-container">
|
||||
<div class="progress-bar read" [style.width.%]="series.completionPercentage"></div>
|
||||
@if (series.booksReading > 0) {
|
||||
<div class="progress-bar reading"
|
||||
[style.width.%]="(series.booksReading / series.booksOwned) * 100"
|
||||
[style.left.%]="series.completionPercentage">
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<span class="progress-text">{{ series.completionPercentage }}%</span>
|
||||
</div>
|
||||
@if (series.nextUnread && series.status !== 'completed') {
|
||||
<div class="next-up">
|
||||
<span class="next-label">Next:</span>
|
||||
<span class="next-title">{{ series.nextUnread }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (filteredSeriesList.length === 0 && searchTerm) {
|
||||
<div class="no-results">
|
||||
<i class="pi pi-search"></i>
|
||||
<span>No series matching "{{ searchTerm }}"</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (getTotalPages() > 1) {
|
||||
<div class="pagination">
|
||||
<button
|
||||
class="page-btn"
|
||||
[disabled]="!hasPrevPage()"
|
||||
(click)="prevPage()">
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<span class="page-info">
|
||||
Page {{ currentPage + 1 }} of {{ getTotalPages() }}
|
||||
</span>
|
||||
<button
|
||||
class="page-btn"
|
||||
[disabled]="!hasNextPage()"
|
||||
(click)="nextPage()">
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!stats) {
|
||||
<div class="no-data-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<p>No series found in your library.</p>
|
||||
<small>Books need series metadata to appear here.</small>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+545
@@ -0,0 +1,545 @@
|
||||
.series-progress-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 1rem;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
min-width: 200px;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
.series-summary {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
|
||||
.summary-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding: 0.35rem 0.6rem;
|
||||
border-radius: 16px;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
|
||||
i {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
&.completed {
|
||||
background: rgba(76, 175, 80, 0.2);
|
||||
color: #4caf50;
|
||||
}
|
||||
|
||||
&.in-progress {
|
||||
background: rgba(255, 193, 7, 0.2);
|
||||
color: #ffc107;
|
||||
}
|
||||
|
||||
&.not-started {
|
||||
background: rgba(158, 158, 158, 0.2);
|
||||
color: #9e9e9e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.series-icon {
|
||||
font-size: 1.5rem;
|
||||
color: #673ab7;
|
||||
}
|
||||
|
||||
.stats-row {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.stat-pill {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 0.85rem;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 20px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
.pill-value {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color, #ffffff);
|
||||
}
|
||||
|
||||
.pill-label {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
|
||||
&.highlight {
|
||||
background: rgba(103, 58, 183, 0.15);
|
||||
border-color: rgba(103, 58, 183, 0.3);
|
||||
|
||||
.pill-value {
|
||||
color: #673ab7;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
height: 220px;
|
||||
width: 100%;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.series-details {
|
||||
.details-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.75rem;
|
||||
|
||||
h4 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 0.95rem;
|
||||
font-weight: 500;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.series-count {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
padding: 0.25rem 0.5rem;
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.controls-row {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.search-box {
|
||||
flex: 1;
|
||||
min-width: 150px;
|
||||
max-width: 250px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.4rem 0.65rem;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 6px;
|
||||
|
||||
i {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
input {
|
||||
flex: 1;
|
||||
background: transparent;
|
||||
border: none;
|
||||
outline: none;
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 0.8rem;
|
||||
font-family: inherit;
|
||||
|
||||
&::placeholder {
|
||||
color: var(--text-secondary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
|
||||
.filter-select,
|
||||
.sort-select {
|
||||
padding: 0.4rem 0.5rem;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 6px;
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 0.75rem;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
|
||||
option {
|
||||
background: #1e1e1e;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
&:focus {
|
||||
border-color: #673ab7;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.series-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.no-results {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
padding: 1.5rem;
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.85rem;
|
||||
|
||||
i {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.pagination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.75rem;
|
||||
margin-top: 0.75rem;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
||||
|
||||
.page-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 6px;
|
||||
color: var(--text-color, #ffffff);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
i {
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background: rgba(103, 58, 183, 0.3);
|
||||
border-color: #673ab7;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.page-info {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
min-width: 80px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.series-card {
|
||||
padding: 0.65rem 0.85rem;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
border-left: 3px solid;
|
||||
|
||||
&.completed {
|
||||
border-left-color: #4caf50;
|
||||
}
|
||||
|
||||
&.in-progress {
|
||||
border-left-color: #ffc107;
|
||||
}
|
||||
|
||||
&.not-started {
|
||||
border-left-color: #9e9e9e;
|
||||
}
|
||||
|
||||
&.abandoned {
|
||||
border-left-color: #ef5350;
|
||||
}
|
||||
|
||||
.series-main {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.6rem;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.series-status-icon {
|
||||
font-size: 0.9rem;
|
||||
margin-top: 0.1rem;
|
||||
}
|
||||
|
||||
.series-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.series-name {
|
||||
display: block;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-color, #ffffff);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.series-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-top: 0.2rem;
|
||||
|
||||
.books-count {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
|
||||
.total-hint {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
.rating {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.2rem;
|
||||
font-size: 0.75rem;
|
||||
color: #ffc107;
|
||||
|
||||
i {
|
||||
font-size: 0.65rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.series-progress {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
.progress-bar-container {
|
||||
flex: 1;
|
||||
height: 6px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
|
||||
.progress-bar {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
transition: width 0.3s ease;
|
||||
|
||||
&.read {
|
||||
left: 0;
|
||||
background: linear-gradient(90deg, #4caf50, #66bb6a);
|
||||
}
|
||||
|
||||
&.reading {
|
||||
background: #ffc107;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-color, #ffffff);
|
||||
min-width: 32px;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
|
||||
.next-up {
|
||||
margin-top: 0.5rem;
|
||||
padding-top: 0.4rem;
|
||||
border-top: 1px dashed rgba(255, 255, 255, 0.1);
|
||||
font-size: 0.7rem;
|
||||
|
||||
.next-label {
|
||||
color: var(--text-secondary-color);
|
||||
margin-right: 0.35rem;
|
||||
}
|
||||
|
||||
.next-title {
|
||||
color: #673ab7;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.no-data-message {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2.5rem;
|
||||
text-align: center;
|
||||
color: var(--text-secondary-color);
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
margin-bottom: 0.75rem;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 0.95rem;
|
||||
margin: 0 0 0.35rem 0;
|
||||
color: var(--text-color, #ffffff);
|
||||
}
|
||||
|
||||
small {
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-header {
|
||||
.series-summary {
|
||||
width: 100%;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.stats-row {
|
||||
.stat-pill {
|
||||
flex: 1;
|
||||
min-width: 80px;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
height: 180px;
|
||||
}
|
||||
|
||||
.series-details {
|
||||
.controls-row {
|
||||
flex-direction: column;
|
||||
|
||||
.search-box {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
width: 100%;
|
||||
|
||||
.filter-select,
|
||||
.sort-select {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
.series-summary {
|
||||
.summary-item {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.stats-row {
|
||||
gap: 0.5rem;
|
||||
|
||||
.stat-pill {
|
||||
padding: 0.4rem 0.6rem;
|
||||
|
||||
.pill-value {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.pill-label {
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.series-details {
|
||||
.series-card {
|
||||
padding: 0.5rem 0.65rem;
|
||||
|
||||
.series-main {
|
||||
.series-info {
|
||||
.series-name {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+599
@@ -0,0 +1,599 @@
|
||||
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, switchMap, 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';
|
||||
import {BookState} from '../../../book/model/state/book-state.model';
|
||||
import {LibraryFilterService} from '../../service/library-filter.service';
|
||||
|
||||
interface SeriesInfo {
|
||||
name: string;
|
||||
booksOwned: number;
|
||||
booksRead: number;
|
||||
booksReading: number;
|
||||
booksPartiallyRead: number;
|
||||
booksPaused: number;
|
||||
booksAbandoned: number;
|
||||
booksWontRead: number;
|
||||
booksUnread: number;
|
||||
totalInSeries: number | null;
|
||||
completionPercentage: number;
|
||||
avgPersonalRating: number | null;
|
||||
avgExternalRating: number | null;
|
||||
nextUnread: string | null;
|
||||
status: 'completed' | 'in-progress' | 'not-started' | 'abandoned' | 'paused';
|
||||
}
|
||||
|
||||
interface SeriesStats {
|
||||
totalSeries: number;
|
||||
completedSeries: number;
|
||||
inProgressSeries: number;
|
||||
notStartedSeries: number;
|
||||
avgSeriesCompletion: number;
|
||||
mostReadSeries: SeriesInfo | null;
|
||||
highestRatedSeries: SeriesInfo | null;
|
||||
}
|
||||
|
||||
type SeriesChartData = ChartData<'bar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-series-progress-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective],
|
||||
templateUrl: './series-progress-chart.component.html',
|
||||
styleUrls: ['./series-progress-chart.component.scss']
|
||||
})
|
||||
export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly libraryFilterService = inject(LibraryFilterService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'bar' as const;
|
||||
public seriesList: SeriesInfo[] = [];
|
||||
public filteredSeriesList: SeriesInfo[] = [];
|
||||
public stats: SeriesStats | null = null;
|
||||
public displayedSeries: SeriesInfo[] = [];
|
||||
public chartSeries: SeriesInfo[] = [];
|
||||
|
||||
// Pagination & filtering
|
||||
public searchTerm = '';
|
||||
public currentPage = 0;
|
||||
public readonly PAGE_SIZE = 10;
|
||||
public readonly CHART_DISPLAY_COUNT = 8;
|
||||
public sortBy: 'progress' | 'rating' | 'books' | 'name' = 'progress';
|
||||
public filterStatus: 'all' | 'completed' | 'in-progress' | 'not-started' | 'paused' | 'abandoned' = 'all';
|
||||
|
||||
public readonly chartOptions: ChartConfiguration<'bar'>['options'] = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
indexAxis: 'y',
|
||||
layout: {
|
||||
padding: {top: 10, right: 20, bottom: 10, left: 10}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
stacked: true,
|
||||
max: 100,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Completion %',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 11,
|
||||
weight: 500
|
||||
}
|
||||
},
|
||||
ticks: {
|
||||
color: 'rgba(255, 255, 255, 0.8)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 10
|
||||
},
|
||||
callback: (value) => `${value}%`
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
stacked: true,
|
||||
ticks: {
|
||||
color: 'rgba(255, 255, 255, 0.8)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 10
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
display: false
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'top',
|
||||
labels: {
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 10
|
||||
},
|
||||
usePointStyle: true,
|
||||
pointStyle: 'rect',
|
||||
padding: 12
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.95)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#673ab7',
|
||||
borderWidth: 2,
|
||||
cornerRadius: 8,
|
||||
padding: 12,
|
||||
titleFont: {size: 12, weight: 'bold'},
|
||||
bodyFont: {size: 10},
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const series = this.chartSeries[context[0].dataIndex];
|
||||
return series ? series.name : '';
|
||||
},
|
||||
afterBody: (context) => {
|
||||
const series = this.chartSeries[context[0].dataIndex];
|
||||
if (!series) return [];
|
||||
const lines = [
|
||||
`Read: ${series.booksRead}/${series.booksOwned} owned`
|
||||
];
|
||||
if (series.totalInSeries) {
|
||||
lines.push(`Series total: ${series.totalInSeries} books`);
|
||||
}
|
||||
if (series.avgPersonalRating) {
|
||||
lines.push(`Your rating: ${series.avgPersonalRating.toFixed(1)}/10`);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private readonly chartDataSubject = new BehaviorSubject<SeriesChartData>({
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
|
||||
public readonly chartData$: Observable<SeriesChartData> = this.chartDataSubject.asObservable();
|
||||
|
||||
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 series data:', error);
|
||||
return EMPTY;
|
||||
})
|
||||
)
|
||||
.subscribe(() => {
|
||||
this.calculateAndUpdateChart();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
onSearchChange(term: string): void {
|
||||
this.searchTerm = term.toLowerCase().trim();
|
||||
this.currentPage = 0;
|
||||
this.applyFiltersAndSort();
|
||||
}
|
||||
|
||||
onSortChange(sortBy: 'progress' | 'rating' | 'books' | 'name'): void {
|
||||
this.sortBy = sortBy;
|
||||
this.currentPage = 0;
|
||||
this.applyFiltersAndSort();
|
||||
}
|
||||
|
||||
onFilterChange(status: 'all' | 'completed' | 'in-progress' | 'not-started' | 'paused' | 'abandoned'): void {
|
||||
this.filterStatus = status;
|
||||
this.currentPage = 0;
|
||||
this.applyFiltersAndSort();
|
||||
}
|
||||
|
||||
nextPage(): void {
|
||||
if (this.hasNextPage()) {
|
||||
this.currentPage++;
|
||||
this.updateDisplayedSeries();
|
||||
}
|
||||
}
|
||||
|
||||
prevPage(): void {
|
||||
if (this.hasPrevPage()) {
|
||||
this.currentPage--;
|
||||
this.updateDisplayedSeries();
|
||||
}
|
||||
}
|
||||
|
||||
hasNextPage(): boolean {
|
||||
return (this.currentPage + 1) * this.PAGE_SIZE < this.filteredSeriesList.length;
|
||||
}
|
||||
|
||||
hasPrevPage(): boolean {
|
||||
return this.currentPage > 0;
|
||||
}
|
||||
|
||||
getTotalPages(): number {
|
||||
return Math.ceil(this.filteredSeriesList.length / this.PAGE_SIZE);
|
||||
}
|
||||
|
||||
private applyFiltersAndSort(): void {
|
||||
let filtered = [...this.seriesList];
|
||||
|
||||
// Apply search filter
|
||||
if (this.searchTerm) {
|
||||
filtered = filtered.filter(s =>
|
||||
s.name.toLowerCase().includes(this.searchTerm)
|
||||
);
|
||||
}
|
||||
|
||||
// Apply status filter
|
||||
if (this.filterStatus !== 'all') {
|
||||
filtered = filtered.filter(s => s.status === this.filterStatus);
|
||||
}
|
||||
|
||||
// Apply sorting
|
||||
filtered.sort((a, b) => {
|
||||
switch (this.sortBy) {
|
||||
case 'progress':
|
||||
return b.completionPercentage - a.completionPercentage;
|
||||
case 'rating':
|
||||
return (b.avgPersonalRating || 0) - (a.avgPersonalRating || 0);
|
||||
case 'books':
|
||||
return b.booksOwned - a.booksOwned;
|
||||
case 'name':
|
||||
return a.name.localeCompare(b.name);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
this.filteredSeriesList = filtered;
|
||||
this.updateDisplayedSeries();
|
||||
this.updateChartSeries();
|
||||
this.updateChartData();
|
||||
}
|
||||
|
||||
private calculateAndUpdateChart(): void {
|
||||
const currentState = this.bookService.getCurrentBookState();
|
||||
const selectedLibraryId = this.libraryFilterService.getCurrentSelectedLibrary();
|
||||
|
||||
if (!this.isValidBookState(currentState)) {
|
||||
this.chartDataSubject.next({labels: [], datasets: []});
|
||||
this.seriesList = [];
|
||||
this.displayedSeries = [];
|
||||
this.stats = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const filteredBooks = this.filterBooksByLibrary(currentState.books!, selectedLibraryId);
|
||||
const seriesBooks = this.getBooksInSeries(filteredBooks);
|
||||
|
||||
if (seriesBooks.length === 0) {
|
||||
this.chartDataSubject.next({labels: [], datasets: []});
|
||||
this.seriesList = [];
|
||||
this.filteredSeriesList = [];
|
||||
this.displayedSeries = [];
|
||||
this.chartSeries = [];
|
||||
this.stats = null;
|
||||
return;
|
||||
}
|
||||
|
||||
this.seriesList = this.calculateSeriesInfo(seriesBooks);
|
||||
this.stats = this.calculateSeriesStats(this.seriesList);
|
||||
this.currentPage = 0;
|
||||
this.applyFiltersAndSort();
|
||||
}
|
||||
|
||||
private isValidBookState(state: unknown): state is BookState {
|
||||
return (
|
||||
typeof state === 'object' &&
|
||||
state !== null &&
|
||||
'loaded' in state &&
|
||||
typeof (state as {loaded: boolean}).loaded === 'boolean' &&
|
||||
'books' in state &&
|
||||
Array.isArray((state as {books: unknown}).books) &&
|
||||
(state as {books: Book[]}).books.length > 0
|
||||
);
|
||||
}
|
||||
|
||||
private filterBooksByLibrary(books: Book[], selectedLibraryId: string | number | null): Book[] {
|
||||
return selectedLibraryId
|
||||
? books.filter(book => book.libraryId === selectedLibraryId)
|
||||
: books;
|
||||
}
|
||||
|
||||
private getBooksInSeries(books: Book[]): Book[] {
|
||||
return books.filter(book => book.metadata?.seriesName);
|
||||
}
|
||||
|
||||
private calculateSeriesInfo(books: Book[]): SeriesInfo[] {
|
||||
const seriesMap = new Map<string, Book[]>();
|
||||
|
||||
books.forEach(book => {
|
||||
const seriesName = book.metadata!.seriesName!;
|
||||
if (!seriesMap.has(seriesName)) {
|
||||
seriesMap.set(seriesName, []);
|
||||
}
|
||||
seriesMap.get(seriesName)!.push(book);
|
||||
});
|
||||
|
||||
const seriesInfoList: SeriesInfo[] = [];
|
||||
|
||||
seriesMap.forEach((seriesBooks, seriesName) => {
|
||||
const booksOwned = seriesBooks.length;
|
||||
let booksRead = 0;
|
||||
let booksReading = 0;
|
||||
let booksPartiallyRead = 0;
|
||||
let booksPaused = 0;
|
||||
let booksAbandoned = 0;
|
||||
let booksWontRead = 0;
|
||||
let booksUnread = 0;
|
||||
let totalRating = 0;
|
||||
let ratedCount = 0;
|
||||
let totalExternalRating = 0;
|
||||
let externalRatedCount = 0;
|
||||
let totalInSeries: number | null = null;
|
||||
let nextUnread: string | null = null;
|
||||
|
||||
// Sort by series number for finding next unread
|
||||
const sortedBooks = [...seriesBooks].sort((a, b) => {
|
||||
const numA = a.metadata?.seriesNumber || 999;
|
||||
const numB = b.metadata?.seriesNumber || 999;
|
||||
return numA - numB;
|
||||
});
|
||||
|
||||
sortedBooks.forEach(book => {
|
||||
// Track series total
|
||||
if (book.metadata?.seriesTotal && (!totalInSeries || book.metadata.seriesTotal > totalInSeries)) {
|
||||
totalInSeries = book.metadata.seriesTotal;
|
||||
}
|
||||
|
||||
// Count by status - handle ALL ReadStatus values
|
||||
switch (book.readStatus) {
|
||||
case ReadStatus.READ:
|
||||
booksRead++;
|
||||
break;
|
||||
case ReadStatus.READING:
|
||||
case ReadStatus.RE_READING:
|
||||
booksReading++;
|
||||
break;
|
||||
case ReadStatus.PARTIALLY_READ:
|
||||
booksPartiallyRead++;
|
||||
if (!nextUnread) {
|
||||
nextUnread = book.metadata?.title || book.fileName || null;
|
||||
}
|
||||
break;
|
||||
case ReadStatus.PAUSED:
|
||||
booksPaused++;
|
||||
if (!nextUnread) {
|
||||
nextUnread = book.metadata?.title || book.fileName || null;
|
||||
}
|
||||
break;
|
||||
case ReadStatus.ABANDONED:
|
||||
booksAbandoned++;
|
||||
break;
|
||||
case ReadStatus.WONT_READ:
|
||||
booksWontRead++;
|
||||
break;
|
||||
case ReadStatus.UNREAD:
|
||||
case ReadStatus.UNSET:
|
||||
default:
|
||||
booksUnread++;
|
||||
if (!nextUnread) {
|
||||
nextUnread = book.metadata?.title || book.fileName || null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Personal rating
|
||||
if (book.personalRating && book.personalRating > 0) {
|
||||
totalRating += book.personalRating;
|
||||
ratedCount++;
|
||||
}
|
||||
|
||||
// External rating
|
||||
const extRating = this.getExternalRating(book);
|
||||
if (extRating > 0) {
|
||||
totalExternalRating += extRating;
|
||||
externalRatedCount++;
|
||||
}
|
||||
});
|
||||
|
||||
// Calculate completion percentage based on what we own (excluding won't read/abandoned)
|
||||
const relevantBooks = booksOwned - booksWontRead - booksAbandoned;
|
||||
const completionPercentage = relevantBooks > 0 ? Math.round((booksRead / relevantBooks) * 100) : 0;
|
||||
|
||||
// Determine series status based on comprehensive analysis
|
||||
let status: 'completed' | 'in-progress' | 'not-started' | 'abandoned' | 'paused';
|
||||
if (booksRead === relevantBooks && relevantBooks > 0) {
|
||||
status = 'completed';
|
||||
} else if (booksReading > 0) {
|
||||
status = 'in-progress';
|
||||
} else if (booksPaused > 0 && booksRead > 0) {
|
||||
status = 'paused';
|
||||
} else if (booksRead > 0 || booksPartiallyRead > 0) {
|
||||
status = 'in-progress';
|
||||
} else if ((booksAbandoned > 0 || booksWontRead > 0) && booksRead === 0 && booksReading === 0) {
|
||||
status = 'abandoned';
|
||||
} else {
|
||||
status = 'not-started';
|
||||
}
|
||||
|
||||
seriesInfoList.push({
|
||||
name: seriesName,
|
||||
booksOwned,
|
||||
booksRead,
|
||||
booksReading,
|
||||
booksPartiallyRead,
|
||||
booksPaused,
|
||||
booksAbandoned,
|
||||
booksWontRead,
|
||||
booksUnread,
|
||||
totalInSeries,
|
||||
completionPercentage,
|
||||
avgPersonalRating: ratedCount > 0 ? totalRating / ratedCount : null,
|
||||
avgExternalRating: externalRatedCount > 0 ? totalExternalRating / externalRatedCount : null,
|
||||
nextUnread,
|
||||
status
|
||||
});
|
||||
});
|
||||
|
||||
// Sort by: in-progress first, then by completion %, then by books owned
|
||||
return seriesInfoList.sort((a, b) => {
|
||||
// Priority: in-progress > not-started > completed > abandoned
|
||||
const statusOrder = {'in-progress': 0, 'paused': 1, 'not-started': 2, 'completed': 3, 'abandoned': 4};
|
||||
const statusDiff = statusOrder[a.status] - statusOrder[b.status];
|
||||
if (statusDiff !== 0) return statusDiff;
|
||||
|
||||
// Then by books owned (more books = more interesting)
|
||||
return b.booksOwned - a.booksOwned;
|
||||
});
|
||||
}
|
||||
|
||||
private getExternalRating(book: Book): number {
|
||||
const ratings: number[] = [];
|
||||
if (book.metadata?.goodreadsRating) ratings.push(book.metadata.goodreadsRating);
|
||||
if (book.metadata?.amazonRating) ratings.push(book.metadata.amazonRating);
|
||||
if (book.metadata?.hardcoverRating) ratings.push(book.metadata.hardcoverRating);
|
||||
|
||||
if (ratings.length > 0) {
|
||||
return ratings.reduce((sum, r) => sum + r, 0) / ratings.length;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private calculateSeriesStats(seriesList: SeriesInfo[]): SeriesStats {
|
||||
const completedSeries = seriesList.filter(s => s.status === 'completed').length;
|
||||
const inProgressSeries = seriesList.filter(s => s.status === 'in-progress').length;
|
||||
const notStartedSeries = seriesList.filter(s => s.status === 'not-started').length;
|
||||
|
||||
const totalCompletion = seriesList.reduce((sum, s) => sum + s.completionPercentage, 0);
|
||||
const avgSeriesCompletion = seriesList.length > 0 ? Math.round(totalCompletion / seriesList.length) : 0;
|
||||
|
||||
const mostReadSeries = [...seriesList].sort((a, b) => b.booksRead - a.booksRead)[0] || null;
|
||||
|
||||
const ratedSeries = seriesList.filter(s => s.avgPersonalRating !== null);
|
||||
const highestRatedSeries = ratedSeries.length > 0
|
||||
? [...ratedSeries].sort((a, b) => (b.avgPersonalRating || 0) - (a.avgPersonalRating || 0))[0]
|
||||
: null;
|
||||
|
||||
return {
|
||||
totalSeries: seriesList.length,
|
||||
completedSeries,
|
||||
inProgressSeries,
|
||||
notStartedSeries,
|
||||
avgSeriesCompletion,
|
||||
mostReadSeries,
|
||||
highestRatedSeries
|
||||
};
|
||||
}
|
||||
|
||||
private updateDisplayedSeries(): void {
|
||||
const start = this.currentPage * this.PAGE_SIZE;
|
||||
const end = start + this.PAGE_SIZE;
|
||||
this.displayedSeries = this.filteredSeriesList.slice(start, end);
|
||||
}
|
||||
|
||||
private updateChartSeries(): void {
|
||||
// For chart, show top series by in-progress first, then by books owned
|
||||
const chartData = [...this.seriesList]
|
||||
.sort((a, b) => {
|
||||
const statusOrder = {'in-progress': 0, 'paused': 1, 'not-started': 2, 'completed': 3, 'abandoned': 4};
|
||||
const statusDiff = statusOrder[a.status] - statusOrder[b.status];
|
||||
if (statusDiff !== 0) return statusDiff;
|
||||
return b.booksOwned - a.booksOwned;
|
||||
})
|
||||
.slice(0, this.CHART_DISPLAY_COUNT);
|
||||
|
||||
this.chartSeries = chartData;
|
||||
}
|
||||
|
||||
private updateChartData(): void {
|
||||
const labels = this.chartSeries.map(s =>
|
||||
s.name.length > 25 ? s.name.substring(0, 22) + '...' : s.name
|
||||
);
|
||||
|
||||
const readPercentages = this.chartSeries.map(s => s.completionPercentage);
|
||||
const readingPercentages = this.chartSeries.map(s =>
|
||||
s.booksOwned > 0 ? Math.round((s.booksReading / s.booksOwned) * 100) : 0
|
||||
);
|
||||
const unreadPercentages = this.chartSeries.map(s =>
|
||||
100 - s.completionPercentage - (s.booksOwned > 0 ? Math.round((s.booksReading / s.booksOwned) * 100) : 0)
|
||||
);
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Read',
|
||||
data: readPercentages,
|
||||
backgroundColor: 'rgba(76, 175, 80, 0.85)',
|
||||
borderColor: '#4caf50',
|
||||
borderWidth: 1,
|
||||
borderRadius: 2
|
||||
},
|
||||
{
|
||||
label: 'Reading',
|
||||
data: readingPercentages,
|
||||
backgroundColor: 'rgba(255, 193, 7, 0.85)',
|
||||
borderColor: '#ffc107',
|
||||
borderWidth: 1,
|
||||
borderRadius: 2
|
||||
},
|
||||
{
|
||||
label: 'Unread',
|
||||
data: unreadPercentages,
|
||||
backgroundColor: 'rgba(158, 158, 158, 0.4)',
|
||||
borderColor: '#9e9e9e',
|
||||
borderWidth: 1,
|
||||
borderRadius: 2
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
getStatusIcon(status: string): string {
|
||||
switch (status) {
|
||||
case 'completed': return 'pi-check-circle';
|
||||
case 'in-progress': return 'pi-spinner';
|
||||
case 'not-started': return 'pi-clock';
|
||||
case 'paused': return 'pi-pause';
|
||||
case 'abandoned': return 'pi-times-circle';
|
||||
default: return 'pi-question-circle';
|
||||
}
|
||||
}
|
||||
|
||||
getStatusColor(status: string): string {
|
||||
switch (status) {
|
||||
case 'completed': return '#4caf50';
|
||||
case 'in-progress': return '#ffc107';
|
||||
case 'not-started': return '#9e9e9e';
|
||||
case 'paused': return '#2196f3';
|
||||
case 'abandoned': return '#ef5350';
|
||||
default: return '#9e9e9e';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,15 @@
|
||||
@case ('read-status') {
|
||||
<app-read-status-chart></app-read-status-chart>
|
||||
}
|
||||
@case ('rating-taste') {
|
||||
<app-rating-taste-chart></app-rating-taste-chart>
|
||||
}
|
||||
@case ('reading-backlog') {
|
||||
<app-reading-backlog-chart></app-reading-backlog-chart>
|
||||
}
|
||||
@case ('series-progress') {
|
||||
<app-series-progress-chart></app-series-progress-chart>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ import {ReadingHeatmapChartComponent} from '../reading-heatmap-chart/reading-hea
|
||||
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';
|
||||
import {RatingTasteChartComponent} from '../rating-taste-chart/rating-taste-chart.component';
|
||||
import {ReadingBacklogChartComponent} from '../reading-backlog-chart/reading-backlog-chart.component';
|
||||
import {SeriesProgressChartComponent} from '../series-progress-chart/series-progress-chart.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-stats',
|
||||
@@ -39,7 +42,10 @@ import {ReadStatusChartComponent} from '../read-status-chart/read-status-chart.c
|
||||
ReadingHeatmapChartComponent,
|
||||
PersonalRatingChartComponent,
|
||||
ReadingProgressChartComponent,
|
||||
ReadStatusChartComponent
|
||||
ReadStatusChartComponent,
|
||||
RatingTasteChartComponent,
|
||||
ReadingBacklogChartComponent,
|
||||
SeriesProgressChartComponent
|
||||
],
|
||||
templateUrl: './user-stats.component.html',
|
||||
styleUrls: ['./user-stats.component.scss']
|
||||
|
||||
@@ -12,6 +12,9 @@ import {ReadingHeatmapChartComponent} from '../component/reading-heatmap-chart/r
|
||||
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';
|
||||
import {RatingTasteChartComponent} from '../component/rating-taste-chart/rating-taste-chart.component';
|
||||
import {ReadingBacklogChartComponent} from '../component/reading-backlog-chart/reading-backlog-chart.component';
|
||||
import {SeriesProgressChartComponent} from '../component/series-progress-chart/series-progress-chart.component';
|
||||
|
||||
export interface UserChartConfig {
|
||||
id: string;
|
||||
@@ -41,6 +44,9 @@ export class UserChartConfigService {
|
||||
{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},
|
||||
{id: 'rating-taste', title: 'Rating Taste Comparison', component: RatingTasteChartComponent, enabled: true, sizeClass: 'chart-medium', order: 12},
|
||||
{id: 'series-progress', title: 'Series Progress Tracker', component: SeriesProgressChartComponent, enabled: true, sizeClass: 'chart-medium', order: 13},
|
||||
{id: 'reading-backlog', title: 'Reading Backlog Analysis', component: ReadingBacklogChartComponent, enabled: true, sizeClass: 'chart-full', order: 14},
|
||||
];
|
||||
|
||||
private chartsSubject = new BehaviorSubject<UserChartConfig[]>(this.loadChartConfig());
|
||||
|
||||
Reference in New Issue
Block a user