feat: add i18n translations for stats, pdf reader, magic shelf, and remaining components (en/es) (#2742)

This commit is contained in:
ACX
2026-02-14 00:18:26 -07:00
committed by GitHub
parent ffd2adb032
commit 9fa7b0736c
102 changed files with 3177 additions and 991 deletions
@@ -1,15 +1,16 @@
<ng-container *transloco="let t; prefix: 'statsLibrary.authorUniverse'">
<div class="author-universe-container">
<div class="chart-header">
<div class="chart-title">
<h3>
<i class="pi pi-globe author-title-icon"></i>
Author Universe
{{ t('title') }}
</h3>
<p class="chart-description">Explore your authors by books, ratings, and reading progress</p>
<p class="chart-description">{{ t('description') }}</p>
</div>
@if (totalAuthors > 0) {
<div class="author-count-badge">
{{ totalAuthors }} authors
{{ t('authorsBadge', { count: totalAuthors }) }}
</div>
}
</div>
@@ -18,7 +19,7 @@
<div class="chart-legend-info">
<span class="legend-note">
<i class="pi pi-info-circle"></i>
Bubble size = total pages &bull; Position = books vs rating &bull; Color = completion %
{{ t('legendNote') }}
</span>
</div>
@@ -47,7 +48,8 @@
@if (totalAuthors === 0) {
<div class="no-data-message">
<i class="pi pi-info-circle"></i>
<p>No author data available. Authors need at least 2 books to appear.</p>
<p>{{ t('noData') }}</p>
</div>
}
</div>
</ng-container>
@@ -8,6 +8,7 @@ import {LibraryFilterService} from '../../service/library-filter.service';
import {BookService} from '../../../../../book/service/book.service';
import {BookState} from '../../../../../book/model/state/book-state.model';
import {Book, ReadStatus} from '../../../../../book/model/book.model';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface AuthorStats {
name: string;
@@ -41,13 +42,14 @@ const COMPLETION_COLORS = {
@Component({
selector: 'app-author-universe-chart',
standalone: true,
imports: [CommonModule, BaseChartDirective],
imports: [CommonModule, BaseChartDirective, TranslocoDirective],
templateUrl: './author-universe-chart.component.html',
styleUrls: ['./author-universe-chart.component.scss']
})
export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
private readonly bookService = inject(BookService);
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
public readonly chartType = 'bubble' as const;
@@ -104,7 +106,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
x: {
title: {
display: true,
text: 'Books in Library',
text: this.t.translate('statsLibrary.authorUniverse.axisBooks'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -130,7 +132,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
y: {
title: {
display: true,
text: 'Average Rating',
text: this.t.translate('statsLibrary.authorUniverse.axisRating'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -349,7 +351,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
if (highCompletion.length > 0) {
datasets.push({
label: '75-100% Read',
label: this.t.translate('statsLibrary.authorUniverse.legend75to100'),
data: highCompletion,
backgroundColor: this.hexToRgba(COMPLETION_COLORS.high, 0.6),
borderColor: COMPLETION_COLORS.high,
@@ -361,7 +363,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
if (mediumCompletion.length > 0) {
datasets.push({
label: '50-74% Read',
label: this.t.translate('statsLibrary.authorUniverse.legend50to74'),
data: mediumCompletion,
backgroundColor: this.hexToRgba(COMPLETION_COLORS.medium, 0.6),
borderColor: COMPLETION_COLORS.medium,
@@ -373,7 +375,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
if (lowCompletion.length > 0) {
datasets.push({
label: '25-49% Read',
label: this.t.translate('statsLibrary.authorUniverse.legend25to49'),
data: lowCompletion,
backgroundColor: this.hexToRgba(COMPLETION_COLORS.low, 0.6),
borderColor: COMPLETION_COLORS.low,
@@ -385,7 +387,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
if (minimalCompletion.length > 0) {
datasets.push({
label: '1-24% Read',
label: this.t.translate('statsLibrary.authorUniverse.legend1to24'),
data: minimalCompletion,
backgroundColor: this.hexToRgba(COMPLETION_COLORS.minimal, 0.6),
borderColor: COMPLETION_COLORS.minimal,
@@ -397,7 +399,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
if (unread.length > 0) {
datasets.push({
label: 'Unread',
label: this.t.translate('statsLibrary.authorUniverse.legendUnread'),
data: unread,
backgroundColor: this.hexToRgba(COMPLETION_COLORS.unread, 0.6),
borderColor: COMPLETION_COLORS.unread,
@@ -421,20 +423,20 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
// Most prolific author
const mostProlific = authorStats[0];
if (mostProlific) {
insights.push(`Most collected: ${mostProlific.name} with ${mostProlific.bookCount} books`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightMostCollected', {name: mostProlific.name, count: mostProlific.bookCount}));
}
// Highest rated author (with at least 2 books)
const ratedAuthors = authorStats.filter(a => a.avgRating > 0);
if (ratedAuthors.length > 0) {
const highestRated = ratedAuthors.reduce((a, b) => a.avgRating > b.avgRating ? a : b);
insights.push(`Highest rated: ${highestRated.name} (${highestRated.avgRating.toFixed(1)}★)`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightHighestRated', {name: highestRated.name, rating: `${highestRated.avgRating.toFixed(1)}\u2605`}));
}
// Most pages by author
const mostPages = authorStats.reduce((a, b) => a.totalPages > b.totalPages ? a : b);
if (mostPages.totalPages > 0) {
insights.push(`Most pages: ${mostPages.name} (${mostPages.totalPages.toLocaleString()} pages)`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightMostPages', {name: mostPages.name, count: mostPages.totalPages.toLocaleString()}));
}
// Best completion rate (with at least 3 books)
@@ -444,7 +446,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
a.completionRate > b.completionRate ? a : b
);
if (bestCompletion.completionRate > 0) {
insights.push(`Most read: ${bestCompletion.name} (${Math.round(bestCompletion.completionRate)}% complete)`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightMostRead', {name: bestCompletion.name, percent: Math.round(bestCompletion.completionRate)}));
}
}
@@ -452,7 +454,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
const hiddenGems = ratedAuthors.filter(a => a.bookCount <= 3 && a.avgRating >= 4.0);
if (hiddenGems.length > 0) {
const gem = hiddenGems.reduce((a, b) => a.avgRating > b.avgRating ? a : b);
insights.push(`Hidden gem: ${gem.name} (${gem.avgRating.toFixed(1)}★ across ${gem.bookCount} books)`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightHiddenGem', {name: gem.name, rating: `${gem.avgRating.toFixed(1)}\u2605`, count: gem.bookCount}));
}
// Biggest backlog - author with most unread books
@@ -463,7 +465,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
);
const unreadCount = biggestBacklog.bookCount - biggestBacklog.readCount;
if (unreadCount >= 2) {
insights.push(`Biggest backlog: ${biggestBacklog.name} (${unreadCount} unread books)`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightBiggestBacklog', {name: biggestBacklog.name, count: unreadCount}));
}
}
@@ -473,7 +475,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
const top3Books = authorStats.slice(0, 3).reduce((sum, a) => sum + a.bookCount, 0);
const concentration = Math.round((top3Books / totalBooks) * 100);
if (concentration >= 25) {
insights.push(`Top 3 concentration: ${concentration}% of your collection`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightTop3Concentration', {percent: concentration}));
}
}
@@ -485,7 +487,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
);
const avgPages = Math.round(longestReads.totalPages / longestReads.bookCount);
if (avgPages >= 300) {
insights.push(`Longest reads: ${longestReads.name} (avg ${avgPages} pages/book)`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightLongestReads', {name: longestReads.name, pages: avgPages}));
}
}
@@ -495,14 +497,14 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
const mostVersatile = versatileAuthors.reduce((a, b) =>
a.categories.length > b.categories.length ? a : b
);
insights.push(`Most versatile: ${mostVersatile.name} (${mostVersatile.categories.length} genres)`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightMostVersatile', {name: mostVersatile.name, count: mostVersatile.categories.length}));
}
// Completely unread - authors with 0% completion but multiple books
const completelyUnread = authorStats.filter(a => a.completionRate === 0 && a.bookCount >= 2);
if (completelyUnread.length > 0) {
const topUnread = completelyUnread.reduce((a, b) => a.bookCount > b.bookCount ? a : b);
insights.push(`Untouched author: ${topUnread.name} (${topUnread.bookCount} unread books)`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightUntouchedAuthor', {name: topUnread.name, count: topUnread.bookCount}));
}
// Total reading commitment
@@ -510,7 +512,7 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
const totalRead = authorStats.reduce((sum, a) => sum + (a.totalPages * a.completionRate / 100), 0);
if (totalPages > 0) {
const overallProgress = Math.round((totalRead / totalPages) * 100);
insights.push(`Overall progress: ${overallProgress}% pages read across all authors`);
insights.push(this.t.translate('statsLibrary.authorUniverse.insightOverallProgress', {percent: overallProgress}));
}
return insights;
@@ -557,19 +559,24 @@ export class AuthorUniverseChartComponent implements OnInit, OnDestroy {
const stats = raw.authorStats;
const ratingText = stats.avgRating > 0
? `${stats.avgRating.toFixed(2)} ★`
: 'No ratings';
? `${stats.avgRating.toFixed(2)} \u2605`
: this.t.translate('statsLibrary.authorUniverse.tooltipNoRatings');
const categoriesHtml = stats.categories.length > 0
? `<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">Genres: ${stats.categories.slice(0, 3).join(', ')}</div>`
? `<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">${this.t.translate('statsLibrary.authorUniverse.tooltipGenres', {genres: stats.categories.slice(0, 3).join(', ')})}</div>`
: '';
const booksLine = this.t.translate('statsLibrary.authorUniverse.tooltipBooks', {count: stats.bookCount});
const pagesLine = this.t.translate('statsLibrary.authorUniverse.tooltipTotalPages', {count: stats.totalPages.toLocaleString()});
const ratingLine = this.t.translate('statsLibrary.authorUniverse.tooltipAvgRating', {rating: ratingText});
const readLine = this.t.translate('statsLibrary.authorUniverse.tooltipRead', {read: stats.readCount, total: stats.bookCount, percent: Math.round(stats.completionRate)});
tooltipEl.innerHTML = `
<div style="color:#fff;font-size:14px;font-weight:700;margin-bottom:6px">${stats.name}</div>
<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">Books: ${stats.bookCount}</div>
<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">Total Pages: ${stats.totalPages.toLocaleString()}</div>
<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">Avg Rating: ${ratingText}</div>
<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">Read: ${stats.readCount}/${stats.bookCount} (${Math.round(stats.completionRate)}%)</div>
<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">${booksLine}</div>
<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">${pagesLine}</div>
<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">${ratingLine}</div>
<div style="color:rgba(255,255,255,0.9);font-size:12px;line-height:1.6">${readLine}</div>
${categoriesHtml}
`;
@@ -1,11 +1,12 @@
<ng-container *transloco="let t; prefix: 'statsLibrary.bookFormats'">
<div class="book-formats-container">
<div class="chart-header">
<div class="chart-title">
<h3>
<i class="pi pi-file formats-title-icon"></i>
Book Formats
{{ t('title') }}
</h3>
<p class="chart-description">Distribution of file types in your library</p>
<p class="chart-description">{{ t('description') }}</p>
</div>
</div>
@@ -22,7 +23,8 @@
@if (totalBooks === 0) {
<div class="no-data-message">
<i class="pi pi-info-circle"></i>
<p>No books available.</p>
<p>{{ t('noData') }}</p>
</div>
}
</div>
</ng-container>
@@ -8,6 +8,7 @@ import {LibraryFilterService} from '../../service/library-filter.service';
import {BookService} from '../../../../../book/service/book.service';
import {BookState} from '../../../../../book/model/state/book-state.model';
import {Book} from '../../../../../book/model/book.model';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface FormatStats {
format: string;
@@ -29,13 +30,14 @@ const FORMAT_COLORS: Record<string, string> = {
@Component({
selector: 'app-book-formats-chart',
standalone: true,
imports: [CommonModule, BaseChartDirective],
imports: [CommonModule, BaseChartDirective, TranslocoDirective],
templateUrl: './book-formats-chart.component.html',
styleUrls: ['./book-formats-chart.component.scss']
})
export class BookFormatsChartComponent implements OnInit, OnDestroy {
private readonly bookService = inject(BookService);
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
public readonly chartType = 'pie' as const;
@@ -79,7 +81,7 @@ export class BookFormatsChartComponent implements OnInit, OnDestroy {
const value = context.parsed;
const total = context.dataset.data.reduce((a: number, b: number) => a + b, 0);
const percentage = ((value / total) * 100).toFixed(1);
return `${context.label}: ${value} books (${percentage}%)`;
return this.t.translate('statsLibrary.bookFormats.tooltipLabel', {label: context.label, value, percentage});
}
}
},
@@ -1,11 +1,12 @@
<ng-container *transloco="let t; prefix: 'statsLibrary.language'">
<div class="language-chart-container">
<div class="chart-header">
<div class="chart-title">
<h3>
<i class="pi pi-globe language-title-icon"></i>
Languages
{{ t('title') }}
</h3>
<p class="chart-description">Languages represented in your collection</p>
<p class="chart-description">{{ t('description') }}</p>
</div>
</div>
@@ -22,7 +23,8 @@
@if (booksWithLanguage === 0) {
<div class="no-data-message">
<i class="pi pi-info-circle"></i>
<p>No language data available.</p>
<p>{{ t('noData') }}</p>
</div>
}
</div>
</ng-container>
@@ -8,6 +8,7 @@ import {LibraryFilterService} from '../../service/library-filter.service';
import {BookService} from '../../../../../book/service/book.service';
import {BookState} from '../../../../../book/model/state/book-state.model';
import {Book} from '../../../../../book/model/book.model';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface LanguageStats {
language: string;
@@ -131,13 +132,14 @@ const LANGUAGE_NAMES: Record<string, string> = {
@Component({
selector: 'app-language-chart',
standalone: true,
imports: [CommonModule, BaseChartDirective],
imports: [CommonModule, BaseChartDirective, TranslocoDirective],
templateUrl: './language-chart.component.html',
styleUrls: ['./language-chart.component.scss']
})
export class LanguageChartComponent implements OnInit, OnDestroy {
private readonly bookService = inject(BookService);
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
public readonly chartType = 'pie' as const;
@@ -182,7 +184,7 @@ export class LanguageChartComponent implements OnInit, OnDestroy {
const value = context.parsed;
const total = context.dataset.data.reduce((a: number, b: number) => a + b, 0);
const percentage = ((value / total) * 100).toFixed(1);
return `${context.label}: ${value} books (${percentage}%)`;
return this.t.translate('statsLibrary.language.tooltipLabel', {label: context.label, value, percentage});
}
}
},
@@ -1,11 +1,12 @@
<ng-container *transloco="let t; prefix: 'statsLibrary.metadataScore'">
<div class="metadata-score-container">
<div class="chart-header">
<div class="chart-title">
<h3>
<i class="pi pi-check-circle score-title-icon"></i>
Metadata Score
{{ t('title') }}
</h3>
<p class="chart-description">Quality of book metadata in your library</p>
<p class="chart-description">{{ t('description') }}</p>
</div>
</div>
@@ -22,7 +23,8 @@
@if (totalBooks === 0) {
<div class="no-data-message">
<i class="pi pi-info-circle"></i>
<p>No metadata score data available.</p>
<p>{{ t('noData') }}</p>
</div>
}
</div>
</ng-container>
@@ -8,6 +8,7 @@ import {LibraryFilterService} from '../../service/library-filter.service';
import {BookService} from '../../../../../book/service/book.service';
import {BookState} from '../../../../../book/model/state/book-state.model';
import {Book} from '../../../../../book/model/book.model';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface ScoreRange {
label: string;
@@ -25,24 +26,27 @@ interface ScoreStats {
type ScoreChartData = ChartData<'doughnut', number[], string>;
const SCORE_RANGES: ScoreRange[] = [
{label: 'Excellent (90-100%)', min: 90, max: 100, color: '#16A34A'},
{label: 'Good (70-89%)', min: 70, max: 89, color: '#22C55E'},
{label: 'Fair (50-69%)', min: 50, max: 69, color: '#F59E0B'},
{label: 'Poor (25-49%)', min: 25, max: 49, color: '#F97316'},
{label: 'Very Poor (0-24%)', min: 0, max: 24, color: '#DC2626'}
const SCORE_RANGE_KEYS = ['excellent', 'good', 'fair', 'poor', 'veryPoor'] as const;
const SCORE_RANGE_DEFS: { key: typeof SCORE_RANGE_KEYS[number]; min: number; max: number; color: string }[] = [
{key: 'excellent', min: 90, max: 100, color: '#16A34A'},
{key: 'good', min: 70, max: 89, color: '#22C55E'},
{key: 'fair', min: 50, max: 69, color: '#F59E0B'},
{key: 'poor', min: 25, max: 49, color: '#F97316'},
{key: 'veryPoor', min: 0, max: 24, color: '#DC2626'}
];
@Component({
selector: 'app-metadata-score-chart',
standalone: true,
imports: [CommonModule, BaseChartDirective],
imports: [CommonModule, BaseChartDirective, TranslocoDirective],
templateUrl: './metadata-score-chart.component.html',
styleUrls: ['./metadata-score-chart.component.scss']
})
export class MetadataScoreChartComponent implements OnInit, OnDestroy {
private readonly bookService = inject(BookService);
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
public readonly chartType = 'doughnut' as const;
@@ -89,7 +93,7 @@ export class MetadataScoreChartComponent implements OnInit, OnDestroy {
const value = context.parsed;
const total = context.dataset.data.reduce((a: number, b: number) => a + b, 0);
const percentage = ((value / total) * 100).toFixed(1);
return `${value} books (${percentage}%)`;
return this.t.translate('statsLibrary.metadataScore.tooltipLabel', {value, percentage});
}
}
},
@@ -182,15 +186,15 @@ export class MetadataScoreChartComponent implements OnInit, OnDestroy {
private calculateScoreStats(books: Book[]): ScoreStats[] {
const rangeCounts = new Map<string, { count: number, color: string }>();
SCORE_RANGES.forEach(range => {
rangeCounts.set(range.label, {count: 0, color: range.color});
SCORE_RANGE_DEFS.forEach(range => {
rangeCounts.set(range.key, {count: 0, color: range.color});
});
books.forEach(book => {
const score = book.metadataMatchScore!;
for (const range of SCORE_RANGES) {
for (const range of SCORE_RANGE_DEFS) {
if (score >= range.min && score <= range.max) {
const data = rangeCounts.get(range.label)!;
const data = rangeCounts.get(range.key)!;
data.count++;
break;
}
@@ -198,11 +202,11 @@ export class MetadataScoreChartComponent implements OnInit, OnDestroy {
});
const total = books.length;
return SCORE_RANGES
return SCORE_RANGE_DEFS
.map(range => {
const data = rangeCounts.get(range.label)!;
const data = rangeCounts.get(range.key)!;
return {
range: range.label,
range: this.t.translate(`statsLibrary.metadataScore.${range.key}`),
count: data.count,
percentage: (data.count / total) * 100,
color: data.color
@@ -1,11 +1,12 @@
<ng-container *transloco="let t; prefix: 'statsLibrary.pageCount'">
<div class="page-count-container">
<div class="chart-header">
<div class="chart-title">
<h3>
<i class="pi pi-book page-title-icon"></i>
Page Count Distribution
{{ t('title') }}
</h3>
<p class="chart-description">Distribution of book lengths in your library</p>
<p class="chart-description">{{ t('description') }}</p>
</div>
</div>
@@ -22,7 +23,8 @@
@if (totalBooks === 0) {
<div class="no-data-message">
<i class="pi pi-info-circle"></i>
<p>No page count data available.</p>
<p>{{ t('noData') }}</p>
</div>
}
</div>
</ng-container>
@@ -8,6 +8,7 @@ import {LibraryFilterService} from '../../service/library-filter.service';
import {BookService} from '../../../../../book/service/book.service';
import {BookState} from '../../../../../book/model/state/book-state.model';
import {Book} from '../../../../../book/model/book.model';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface PageRange {
label: string;
@@ -37,13 +38,14 @@ const PAGE_RANGES: PageRange[] = [
@Component({
selector: 'app-page-count-chart',
standalone: true,
imports: [CommonModule, BaseChartDirective],
imports: [CommonModule, BaseChartDirective, TranslocoDirective],
templateUrl: './page-count-chart.component.html',
styleUrls: ['./page-count-chart.component.scss']
})
export class PageCountChartComponent implements OnInit, OnDestroy {
private readonly bookService = inject(BookService);
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
public readonly chartType = 'bar' as const;
@@ -69,10 +71,12 @@ export class PageCountChartComponent implements OnInit, OnDestroy {
titleFont: {size: 13, weight: 'bold'},
bodyFont: {size: 11},
callbacks: {
title: (context) => `${context[0].label} pages`,
title: (context) => this.t.translate('statsLibrary.pageCount.tooltipTitle', {label: context[0].label}),
label: (context) => {
const value = context.parsed.y;
return `${value} book${value === 1 ? '' : 's'}`;
return value === 1
? this.t.translate('statsLibrary.pageCount.tooltipLabel', {value})
: this.t.translate('statsLibrary.pageCount.tooltipLabelPlural', {value});
}
}
},
@@ -82,7 +86,7 @@ export class PageCountChartComponent implements OnInit, OnDestroy {
x: {
title: {
display: true,
text: 'Page Count',
text: this.t.translate('statsLibrary.pageCount.axisPageCount'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -102,7 +106,7 @@ export class PageCountChartComponent implements OnInit, OnDestroy {
y: {
title: {
display: true,
text: 'Books',
text: this.t.translate('statsLibrary.pageCount.axisBooks'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -1,15 +1,16 @@
<ng-container *transloco="let t; prefix: 'statsLibrary.publicationTimeline'">
<div class="publication-timeline-container">
<div class="chart-header">
<div class="chart-title">
<h3>
<i class="pi pi-calendar timeline-title-icon"></i>
Publication Timeline
{{ t('title') }}
</h3>
<p class="chart-description">When were your books originally published?</p>
<p class="chart-description">{{ t('description') }}</p>
</div>
@if (totalBooks > 0) {
<div class="books-count-badge">
{{ totalBooks }} books with dates
{{ t('booksWithDates', { count: totalBooks }) }}
</div>
}
</div>
@@ -28,21 +29,21 @@
<div class="insights-row">
@if (insights.oldestBook) {
<div class="insight-item oldest">
<span class="insight-label">Oldest</span>
<span class="insight-label">{{ t('insightOldest') }}</span>
<span class="insight-value">{{ insights.oldestBook.year }}</span>
<span class="insight-detail" [title]="insights.oldestBook.title">{{ insights.oldestBook.title }}</span>
</div>
}
<div class="insight-item average">
<span class="insight-label">Average Year</span>
<span class="insight-label">{{ t('insightAverageYear') }}</span>
<span class="insight-value">{{ insights.averageYear }}</span>
<span class="insight-detail">Median: {{ insights.medianYear }}</span>
<span class="insight-detail">{{ t('insightMedian', { year: insights.medianYear }) }}</span>
</div>
@if (insights.newestBook) {
<div class="insight-item newest">
<span class="insight-label">Newest</span>
<span class="insight-label">{{ t('insightNewest') }}</span>
<span class="insight-value">{{ insights.newestBook.year }}</span>
<span class="insight-detail" [title]="insights.newestBook.title">{{ insights.newestBook.title }}</span>
</div>
@@ -51,21 +52,21 @@
<div class="insights-row secondary">
<div class="insight-item timespan">
<span class="insight-label">Time Span</span>
<span class="insight-label">{{ t('insightTimeSpan') }}</span>
<span class="insight-value">{{ insights.timeSpan }}</span>
<span class="insight-detail">years of literature</span>
<span class="insight-detail">{{ t('insightYearsOfLiterature') }}</span>
</div>
<div class="insight-item peak">
<span class="insight-label">Peak Decade</span>
<span class="insight-label">{{ t('insightPeakDecade') }}</span>
<span class="insight-value">{{ insights.peakDecade }}</span>
<span class="insight-detail">{{ insights.peakDecadeCount }} books</span>
<span class="insight-detail">{{ t('insightPeakDecadeBooks', { count: insights.peakDecadeCount }) }}</span>
</div>
<div class="insight-item decades">
<span class="insight-label">Decades Covered</span>
<span class="insight-label">{{ t('insightDecadesCovered') }}</span>
<span class="insight-value">{{ insights.decadesCovered }}</span>
<span class="insight-detail">different eras</span>
<span class="insight-detail">{{ t('insightDifferentEras') }}</span>
</div>
</div>
</div>
@@ -75,7 +76,8 @@
@if (totalBooks === 0) {
<div class="no-data-message">
<i class="pi pi-info-circle"></i>
<p>No publication date data available.</p>
<p>{{ t('noData') }}</p>
</div>
}
</div>
</ng-container>
@@ -8,6 +8,7 @@ import {LibraryFilterService} from '../../service/library-filter.service';
import {BookService} from '../../../../../book/service/book.service';
import {BookState} from '../../../../../book/model/state/book-state.model';
import {Book} from '../../../../../book/model/book.model';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface DecadeStats {
decade: string;
@@ -52,13 +53,14 @@ const DECADE_COLORS: Record<string, string> = {
@Component({
selector: 'app-publication-timeline-chart',
standalone: true,
imports: [CommonModule, BaseChartDirective],
imports: [CommonModule, BaseChartDirective, TranslocoDirective],
templateUrl: './publication-timeline-chart.component.html',
styleUrls: ['./publication-timeline-chart.component.scss']
})
export class PublicationTimelineChartComponent implements OnInit, OnDestroy {
private readonly bookService = inject(BookService);
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
public readonly chartType = 'bar' as const;
@@ -128,7 +130,7 @@ export class PublicationTimelineChartComponent implements OnInit, OnDestroy {
border: {display: false},
title: {
display: true,
text: 'Number of Books',
text: this.t.translate('statsLibrary.publicationTimeline.axisNumberOfBooks'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -169,8 +171,9 @@ export class PublicationTimelineChartComponent implements OnInit, OnDestroy {
callbacks: {
label: (context) => {
const value = context.parsed.x;
const bookText = value === 1 ? 'book' : 'books';
return `${value} ${bookText}`;
return value === 1
? this.t.translate('statsLibrary.publicationTimeline.tooltipBook', {value})
: this.t.translate('statsLibrary.publicationTimeline.tooltipBooks', {value});
}
}
},
@@ -1,11 +1,12 @@
<ng-container *transloco="let t; prefix: 'statsLibrary.publicationTrend'">
<div class="publication-trend-container">
<div class="chart-header">
<div class="chart-title">
<h3>
<i class="pi pi-chart-line trend-title-icon"></i>
Publication Trend
{{ t('title') }}
</h3>
<p class="chart-description">Books by publication year showing collection trends</p>
<p class="chart-description">{{ t('description') }}</p>
</div>
@if (totalBooks > 0 && yearRange) {
<div class="year-range-badge">
@@ -27,49 +28,49 @@
<div class="insights-section">
<div class="insights-row">
<div class="insight-item peak">
<span class="insight-label">Peak Year</span>
<span class="insight-label">{{ t('insightPeakYear') }}</span>
<span class="insight-value">{{ insights.peakYear }}</span>
<span class="insight-detail">{{ insights.peakYearCount }} books</span>
<span class="insight-detail">{{ t('insightPeakYearBooks', { count: insights.peakYearCount }) }}</span>
</div>
<div class="insight-item recent">
<span class="insight-label">Last 10 Years</span>
<span class="insight-label">{{ t('insightLast10Years') }}</span>
<span class="insight-value">{{ insights.booksLast10YearsPercent }}%</span>
<span class="insight-detail">{{ insights.booksLast10Years }} books</span>
<span class="insight-detail">{{ t('insightLast10YearsBooks', { count: insights.booksLast10Years }) }}</span>
</div>
<div class="insight-item average">
<span class="insight-label">Avg per Year</span>
<span class="insight-label">{{ t('insightAvgPerYear') }}</span>
<span class="insight-value">{{ insights.averageBooksPerYear }}</span>
<span class="insight-detail">books/year</span>
<span class="insight-detail">{{ t('insightBooksPerYear') }}</span>
</div>
<div class="insight-item productive">
<span class="insight-label">Best 5-Year Span</span>
<span class="insight-label">{{ t('insightBest5YearSpan') }}</span>
<span class="insight-value">{{ insights.mostProductiveSpan }}</span>
<span class="insight-detail">most books published</span>
<span class="insight-detail">{{ t('insightMostBooksPublished') }}</span>
</div>
<div class="insight-item timespan">
<span class="insight-label">Time Span</span>
<span class="insight-label">{{ t('insightTimeSpan') }}</span>
<span class="insight-value">{{ insights.timeSpan }}</span>
<span class="insight-detail">years covered</span>
<span class="insight-detail">{{ t('insightYearsCovered') }}</span>
</div>
<div class="insight-item century21">
<span class="insight-label">21st Century</span>
<span class="insight-label">{{ t('insightCentury21') }}</span>
<span class="insight-value">{{ insights.century21Percent }}%</span>
<span class="insight-detail">{{ insights.century21Books }} books</span>
<span class="insight-detail">{{ t('insightCentury21Books', { count: insights.century21Books }) }}</span>
</div>
<div class="insight-item classics">
<span class="insight-label">Classics</span>
<span class="insight-label">{{ t('insightClassics') }}</span>
<span class="insight-value">{{ insights.classicBooksPercent }}%</span>
<span class="insight-detail">{{ insights.classicBooks }} pre-1970</span>
<span class="insight-detail">{{ t('insightClassicsPre1970', { count: insights.classicBooks }) }}</span>
</div>
<div class="insight-item unique">
<span class="insight-label">Unique Years</span>
<span class="insight-label">{{ t('insightUniqueYears') }}</span>
<span class="insight-value">{{ insights.uniqueYears }}</span>
<span class="insight-detail">{{ insights.oldestDecade }} - {{ insights.newestDecade }}</span>
</div>
@@ -81,7 +82,8 @@
@if (totalBooks === 0) {
<div class="no-data-message">
<i class="pi pi-info-circle"></i>
<p>No publication date data available.</p>
<p>{{ t('noData') }}</p>
</div>
}
</div>
</ng-container>
@@ -8,6 +8,7 @@ import {LibraryFilterService} from '../../service/library-filter.service';
import {BookService} from '../../../../../book/service/book.service';
import {BookState} from '../../../../../book/model/state/book-state.model';
import {Book} from '../../../../../book/model/book.model';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface TrendInsights {
peakYear: number;
@@ -32,13 +33,14 @@ type TrendChartData = ChartData<'line', number[], string>;
@Component({
selector: 'app-publication-trend-chart',
standalone: true,
imports: [CommonModule, BaseChartDirective],
imports: [CommonModule, BaseChartDirective, TranslocoDirective],
templateUrl: './publication-trend-chart.component.html',
styleUrls: ['./publication-trend-chart.component.scss']
})
export class PublicationTrendChartComponent implements OnInit, OnDestroy {
private readonly bookService = inject(BookService);
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
public readonly chartType = 'line' as const;
@@ -109,7 +111,7 @@ export class PublicationTrendChartComponent implements OnInit, OnDestroy {
border: {display: false},
title: {
display: true,
text: 'Publication Year',
text: this.t.translate('statsLibrary.publicationTrend.axisPublicationYear'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -135,7 +137,7 @@ export class PublicationTrendChartComponent implements OnInit, OnDestroy {
border: {display: false},
title: {
display: true,
text: 'Books',
text: this.t.translate('statsLibrary.publicationTrend.axisBooks'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -161,11 +163,12 @@ export class PublicationTrendChartComponent implements OnInit, OnDestroy {
titleFont: {size: 13, weight: 'bold'},
bodyFont: {size: 11},
callbacks: {
title: (context) => `Year ${context[0].label}`,
title: (context) => this.t.translate('statsLibrary.publicationTrend.tooltipTitle', {year: context[0].label}),
label: (context) => {
const value = context.parsed.y;
const bookText = value === 1 ? 'book' : 'books';
return `${value} ${bookText} published`;
return value === 1
? this.t.translate('statsLibrary.publicationTrend.tooltipBook', {value})
: this.t.translate('statsLibrary.publicationTrend.tooltipBooks', {value});
}
}
},
@@ -1,11 +1,12 @@
<ng-container *transloco="let t; prefix: 'statsLibrary.readingJourney'">
<div class="reading-journey-container">
<div class="chart-header">
<div class="chart-title">
<h3>
<i class="pi pi-directions journey-title-icon"></i>
Reading Journey
{{ t('title') }}
</h3>
<p class="chart-description">Books added vs finished over time - the gap is your backlog</p>
<p class="chart-description">{{ t('description') }}</p>
</div>
@if (dateRange) {
<div class="date-range-badge">
@@ -26,51 +27,51 @@
<div class="insights-section">
<div class="insights-row">
<div class="insight-item backlog">
<span class="insight-label">Current Backlog</span>
<span class="insight-label">{{ t('insightCurrentBacklog') }}</span>
<span class="insight-value">{{ insights.currentBacklog }}</span>
<span class="insight-detail">{{ insights.backlogPercent }}% unread</span>
<span class="insight-detail">{{ t('insightBacklogPercent', { percent: insights.backlogPercent }) }}</span>
</div>
<div class="insight-item time-to-read">
<span class="insight-label">Avg Time to Finish</span>
<span class="insight-label">{{ t('insightAvgTimeToFinish') }}</span>
<span class="insight-value">{{ insights.avgTimeToFinishDays }}</span>
<span class="insight-detail">days after adding</span>
<span class="insight-detail">{{ t('insightDaysAfterAdding') }}</span>
</div>
<div class="insight-item productive">
<span class="insight-label">Best Reading Month</span>
<span class="insight-label">{{ t('insightBestReadingMonth') }}</span>
<span class="insight-value">{{ insights.mostProductiveCount }}</span>
<span class="insight-detail">{{ insights.mostProductiveMonth }}</span>
</div>
<div class="insight-item acquisition">
<span class="insight-label">Peak Acquisition</span>
<span class="insight-label">{{ t('insightPeakAcquisition') }}</span>
<span class="insight-value">{{ insights.busiestAcquisitionCount }}</span>
<span class="insight-detail">{{ insights.busiestAcquisitionMonth }}</span>
</div>
<div class="insight-item finish-rate">
<span class="insight-label">Finish Rate</span>
<span class="insight-label">{{ t('insightFinishRate') }}</span>
<span class="insight-value">{{ insights.finishRate }}</span>
<span class="insight-detail">books/month avg</span>
<span class="insight-detail">{{ t('insightBooksPerMonthAvg') }}</span>
</div>
<div class="insight-item streak">
<span class="insight-label">Longest Streak</span>
<span class="insight-label">{{ t('insightLongestStreak') }}</span>
<span class="insight-value">{{ insights.longestStreak }}</span>
<span class="insight-detail">consecutive months</span>
<span class="insight-detail">{{ t('insightConsecutiveMonths') }}</span>
</div>
<div class="insight-item recent">
<span class="insight-label">Last 3 Months</span>
<span class="insight-label">{{ t('insightLast3Months') }}</span>
<span class="insight-value">{{ insights.recentActivity }}</span>
<span class="insight-detail">recently finished</span>
<span class="insight-detail">{{ t('insightRecentlyFinished') }}</span>
</div>
<div class="insight-item total">
<span class="insight-label">Completion</span>
<span class="insight-label">{{ t('insightCompletion') }}</span>
<span class="insight-value">{{ insights.totalFinished }}/{{ insights.totalAdded }}</span>
<span class="insight-detail">books finished</span>
<span class="insight-detail">{{ t('insightBooksFinished') }}</span>
</div>
</div>
</div>
@@ -79,8 +80,9 @@
@if (totalBooks === 0 || !insights) {
<div class="no-data-message">
<i class="pi pi-info-circle"></i>
<p>No reading journey data available.</p>
<small>Books need addedOn or dateFinished dates to appear here.</small>
<p>{{ t('noData') }}</p>
<small>{{ t('noDataHint') }}</small>
</div>
}
</div>
</ng-container>
@@ -8,6 +8,7 @@ import {LibraryFilterService} from '../../service/library-filter.service';
import {BookService} from '../../../../../book/service/book.service';
import {BookState} from '../../../../../book/model/state/book-state.model';
import {Book, ReadStatus} from '../../../../../book/model/book.model';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface MonthlyData {
month: string;
@@ -38,13 +39,14 @@ type JourneyChartData = ChartData<'line', number[], string>;
@Component({
selector: 'app-reading-journey-chart',
standalone: true,
imports: [CommonModule, BaseChartDirective],
imports: [CommonModule, BaseChartDirective, TranslocoDirective],
templateUrl: './reading-journey-chart.component.html',
styleUrls: ['./reading-journey-chart.component.scss']
})
export class ReadingJourneyChartComponent implements OnInit, OnDestroy {
private readonly bookService = inject(BookService);
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
public readonly chartType = 'line' as const;
@@ -115,7 +117,7 @@ export class ReadingJourneyChartComponent implements OnInit, OnDestroy {
border: {display: false},
title: {
display: true,
text: 'Month',
text: this.t.translate('statsLibrary.readingJourney.axisMonth'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -140,7 +142,7 @@ export class ReadingJourneyChartComponent implements OnInit, OnDestroy {
border: {display: false},
title: {
display: true,
text: 'Cumulative Books',
text: this.t.translate('statsLibrary.readingJourney.axisCumulativeBooks'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -183,7 +185,7 @@ export class ReadingJourneyChartComponent implements OnInit, OnDestroy {
const addedValue = context[0].chart.data.datasets[0].data[dataIndex] as number;
const finishedValue = context[0].chart.data.datasets[1].data[dataIndex] as number;
const backlog = addedValue - finishedValue;
return [`\nBacklog: ${backlog} books`];
return [`\n${this.t.translate('statsLibrary.readingJourney.tooltipBacklog', {count: backlog})}`];
}
}
},
@@ -415,7 +417,9 @@ export class ReadingJourneyChartComponent implements OnInit, OnDestroy {
}
}
}
const recentActivity = recentFinished > 0 ? `${recentFinished} books` : 'No activity';
const recentActivity = recentFinished > 0
? this.t.translate('statsLibrary.readingJourney.recentActivityBooks', {count: recentFinished})
: this.t.translate('statsLibrary.readingJourney.recentActivityNone');
// Longest reading streak (consecutive months with finished books)
let longestStreak = 0;
@@ -459,7 +463,7 @@ export class ReadingJourneyChartComponent implements OnInit, OnDestroy {
labels,
datasets: [
{
label: 'Books Added',
label: this.t.translate('statsLibrary.readingJourney.legendBooksAdded'),
data: addedData,
borderColor: '#3b82f6',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
@@ -469,7 +473,7 @@ export class ReadingJourneyChartComponent implements OnInit, OnDestroy {
order: 2
},
{
label: 'Books Finished',
label: this.t.translate('statsLibrary.readingJourney.legendBooksFinished'),
data: finishedData,
borderColor: '#10b981',
backgroundColor: 'rgba(16, 185, 129, 0.2)',
@@ -1,11 +1,12 @@
<ng-container *transloco="let t; prefix: 'statsLibrary.topItems'">
<div class="top-items-container">
<div class="chart-header">
<div class="chart-title">
<h3>
<i class="pi" [ngClass]="selectedDataType.icon" [style.color]="selectedDataType.color"></i>
Top 15 {{ selectedDataType.label }}
{{ t('titlePrefix') }} {{ selectedDataType.label }}
</h3>
<p class="chart-description">Most represented {{ selectedDataType.label.toLowerCase() }} in your library</p>
<p class="chart-description">{{ t('descriptionPrefix') }} {{ selectedDataType.label.toLowerCase() }} {{ t('descriptionSuffix') }}</p>
</div>
<div class="header-controls">
<p-select
@@ -34,7 +35,7 @@
@if (totalItems > 0) {
<div class="stats-badge">
<span class="badge-value">{{ totalItems }}</span>
<span class="badge-label">shown</span>
<span class="badge-label">{{ t('shown') }}</span>
</div>
}
</div>
@@ -67,8 +68,9 @@
@if (totalItems === 0) {
<div class="no-data-message">
<i class="pi pi-info-circle"></i>
<p>No {{ selectedDataType.label.toLowerCase() }} data available.</p>
<small>Make sure your books have {{ selectedDataType.label.toLowerCase() }} metadata.</small>
<p>{{ t('noDataPrefix') }} {{ selectedDataType.label.toLowerCase() }} {{ t('noDataSuffix') }}</p>
<small>{{ t('noDataHintPrefix') }} {{ selectedDataType.label.toLowerCase() }} {{ t('noDataHintSuffix') }}</small>
</div>
}
</div>
</ng-container>
@@ -10,6 +10,7 @@ import {LibraryFilterService} from '../../service/library-filter.service';
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 {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface ItemStats {
name: string;
@@ -27,25 +28,37 @@ interface DataTypeOption {
type DataType = 'authors' | 'categories' | 'publishers' | 'tags' | 'moods' | 'series';
type ItemChartData = ChartData<'bar', number[], string>;
const DATA_TYPE_OPTIONS: DataTypeOption[] = [
{label: 'Authors', value: 'authors', icon: 'pi-th-large', color: '#2563EB'},
{label: 'Categories', value: 'categories', icon: 'pi-user', color: '#0D9488'},
{label: 'Series', value: 'series', icon: 'pi-tag', color: '#DB2777'},
{label: 'Publishers', value: 'publishers', icon: 'pi-building', color: '#7C3AED'},
{label: 'Tags', value: 'tags', icon: 'pi-bookmark', color: '#EAB308'},
{label: 'Moods', value: 'moods', icon: 'pi-heart', color: '#EA580C'}
const DATA_TYPE_DEFS: { key: string; value: DataType; icon: string; color: string }[] = [
{key: 'authors', value: 'authors', icon: 'pi-th-large', color: '#2563EB'},
{key: 'categories', value: 'categories', icon: 'pi-user', color: '#0D9488'},
{key: 'series', value: 'series', icon: 'pi-tag', color: '#DB2777'},
{key: 'publishers', value: 'publishers', icon: 'pi-building', color: '#7C3AED'},
{key: 'tags', value: 'tags', icon: 'pi-bookmark', color: '#EAB308'},
{key: 'moods', value: 'moods', icon: 'pi-heart', color: '#EA580C'}
];
const READ_STATUS_CONFIG: Record<ReadStatus, { label: string; color: string }> = {
[ReadStatus.READ]: {label: 'Read', color: '#22c55e'},
[ReadStatus.READING]: {label: 'Reading', color: '#3b82f6'},
[ReadStatus.RE_READING]: {label: 'Re-reading', color: '#8b5cf6'},
[ReadStatus.UNREAD]: {label: 'Unread', color: '#6b7280'},
[ReadStatus.PARTIALLY_READ]: {label: 'Partially Read', color: '#f59e0b'},
[ReadStatus.PAUSED]: {label: 'Paused', color: '#eab308'},
[ReadStatus.WONT_READ]: {label: "Won't Read", color: '#ef4444'},
[ReadStatus.ABANDONED]: {label: 'Abandoned', color: '#dc2626'},
[ReadStatus.UNSET]: {label: 'Not Set', color: '#9ca3af'}
const READ_STATUS_KEYS: Record<ReadStatus, string> = {
[ReadStatus.READ]: 'read',
[ReadStatus.READING]: 'reading',
[ReadStatus.RE_READING]: 'reReading',
[ReadStatus.UNREAD]: 'unread',
[ReadStatus.PARTIALLY_READ]: 'partiallyRead',
[ReadStatus.PAUSED]: 'paused',
[ReadStatus.WONT_READ]: 'wontRead',
[ReadStatus.ABANDONED]: 'abandoned',
[ReadStatus.UNSET]: 'notSet'
};
const READ_STATUS_COLORS: Record<ReadStatus, string> = {
[ReadStatus.READ]: '#22c55e',
[ReadStatus.READING]: '#3b82f6',
[ReadStatus.RE_READING]: '#8b5cf6',
[ReadStatus.UNREAD]: '#6b7280',
[ReadStatus.PARTIALLY_READ]: '#f59e0b',
[ReadStatus.PAUSED]: '#eab308',
[ReadStatus.WONT_READ]: '#ef4444',
[ReadStatus.ABANDONED]: '#dc2626',
[ReadStatus.UNSET]: '#9ca3af'
};
const READ_STATUS_ORDER: ReadStatus[] = [
@@ -63,7 +76,7 @@ const READ_STATUS_ORDER: ReadStatus[] = [
@Component({
selector: 'app-top-items-chart',
standalone: true,
imports: [CommonModule, FormsModule, BaseChartDirective, Select],
imports: [CommonModule, FormsModule, BaseChartDirective, Select, TranslocoDirective],
templateUrl: './top-items-chart.component.html',
styleUrls: ['./top-items-chart.component.scss']
})
@@ -73,8 +86,8 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
public readonly chartType = 'bar' as const;
public readonly chartData$: Observable<ItemChartData>;
public chartOptions: ChartConfiguration<'bar'>['options'];
public dataTypeOptions = DATA_TYPE_OPTIONS;
public selectedDataType: DataTypeOption = DATA_TYPE_OPTIONS[0];
public dataTypeOptions: DataTypeOption[];
public selectedDataType: DataTypeOption;
public totalItems = 0;
public totalBooks = 0;
@@ -82,12 +95,20 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
private readonly bookService = inject(BookService);
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
private readonly chartDataSubject: BehaviorSubject<ItemChartData>;
private lastCalculatedStats: ItemStats[] = [];
private allBooks: Book[] = [];
constructor() {
this.dataTypeOptions = DATA_TYPE_DEFS.map(def => ({
label: this.t.translate(`statsLibrary.topItems.dataTypes.${def.key}`),
value: def.value,
icon: def.icon,
color: def.color
}));
this.selectedDataType = this.dataTypeOptions[0];
this.chartDataSubject = new BehaviorSubject<ItemChartData>({
labels: [],
datasets: []
@@ -98,7 +119,7 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
ngOnInit(): void {
if (this.initialDataType) {
const initialOption = DATA_TYPE_OPTIONS.find(opt => opt.value === this.initialDataType);
const initialOption = this.dataTypeOptions.find(opt => opt.value === this.initialDataType);
if (initialOption) {
this.selectedDataType = initialOption;
this.initChartOptions();
@@ -162,7 +183,7 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
border: {display: false},
title: {
display: true,
text: 'Number of Books',
text: this.t.translate('statsLibrary.topItems.axisNumberOfBooks'),
color: '#ffffff',
font: {
family: "'Inter', sans-serif",
@@ -264,12 +285,13 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
const datasets = READ_STATUS_ORDER
.filter(status => stats.some(s => s.statusBreakdown[status] > 0))
.map(status => {
const config = READ_STATUS_CONFIG[status];
const statusKey = READ_STATUS_KEYS[status];
const color = READ_STATUS_COLORS[status];
return {
label: config.label,
label: this.t.translate(`statsLibrary.topItems.readStatus.${statusKey}`),
data: stats.map(s => s.statusBreakdown[status]),
backgroundColor: config.color,
borderColor: config.color,
backgroundColor: color,
borderColor: color,
borderWidth: 1,
borderRadius: 4,
barPercentage: 0.85,
@@ -295,14 +317,13 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
if (stats.length === 0) return;
const typeName = this.selectedDataType.label.toLowerCase().slice(0, -1); // Remove 's' for singular
const typeNamePlural = this.selectedDataType.label.toLowerCase();
// 1. Top item
const top = stats[0];
this.insights.push({
icon: 'pi-trophy',
label: `Top ${typeName}`,
value: `${top.name} (${top.count} books)`
label: this.t.translate('statsLibrary.topItems.insightTop', {type: typeName}),
value: this.t.translate('statsLibrary.topItems.insightTopValue', {name: top.name, count: top.count})
});
// 2. Most completed - highest read percentage
@@ -317,8 +338,8 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
if (readPct > 0) {
this.insights.push({
icon: 'pi-check-circle',
label: 'Most completed',
value: `${mostRead.name} (${readPct}% read)`
label: this.t.translate('statsLibrary.topItems.insightMostCompleted'),
value: this.t.translate('statsLibrary.topItems.insightMostCompletedValue', {name: mostRead.name, percent: readPct})
});
}
}
@@ -331,8 +352,8 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
const concentration = Math.round((top5Books / totalAllBooks) * 100);
this.insights.push({
icon: 'pi-chart-pie',
label: 'Top 5 coverage',
value: `${concentration}% of library`
label: this.t.translate('statsLibrary.topItems.insightTop5Coverage'),
value: this.t.translate('statsLibrary.topItems.insightTop5CoverageValue', {percent: concentration})
});
}
}
@@ -342,8 +363,8 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
const avgBooks = (this.totalBooks / stats.length).toFixed(1);
this.insights.push({
icon: 'pi-book',
label: `Avg per ${typeName}`,
value: `${avgBooks} books`
label: this.t.translate('statsLibrary.topItems.insightAvgPer', {type: typeName}),
value: this.t.translate('statsLibrary.topItems.insightAvgPerValue', {avg: avgBooks})
});
}
}
@@ -445,10 +466,10 @@ export class TopItemsChartComponent implements OnInit, OnDestroy {
return '';
}
const statusLabel = context.dataset.label || 'Books';
const bookText = value === 1 ? 'book' : 'books';
return `${statusLabel}: ${value} ${bookText}`;
const statusLabel = context.dataset.label || this.t.translate('statsLibrary.pageCount.axisBooks');
return value === 1
? this.t.translate('statsLibrary.topItems.tooltipBook', {status: statusLabel, value})
: this.t.translate('statsLibrary.topItems.tooltipBooks', {status: statusLabel, value});
}
private truncateTitle(title: string, maxLength: number): string {
@@ -1,9 +1,10 @@
<ng-container *transloco="let t; prefix: 'statsLibrary'">
<div class="library-stats-container">
<div class="header-card">
<div class="filter-section">
<div class="library-filter">
<div class="select-row">
<label for="library-dropdown">Library Statistics</label>
<label for="library-dropdown">{{ t('main.title') }}</label>
<div class="dropdown-row">
<p-select
fluid
@@ -12,7 +13,7 @@
[(ngModel)]="selectedLibrary"
optionLabel="name"
size="small"
placeholder="Select a library"
[placeholder]="t('main.selectLibrary')"
(onChange)="onLibraryChange()"
appendTo="body"
[style]="{'min-width': '200px'}"
@@ -29,33 +30,33 @@
</div>
<div class="library-totals" role="status" aria-live="polite">
<div class="total-item total-books" title="Total books">
<div class="total-item total-books" [title]="t('main.totalBooks')">
<i class="pi pi-book"></i>
<span class="total-label">Books</span>
<span class="total-label">{{ t('main.books') }}</span>
<span class="total-value">{{ totalBooks$ | async }}</span>
</div>
<div class="total-item total-authors" title="Total authors">
<div class="total-item total-authors" [title]="t('main.totalAuthors')">
<i class="pi pi-users"></i>
<span class="total-label">Authors</span>
<span class="total-label">{{ t('main.authors') }}</span>
<span class="total-value">{{ totalAuthors$ | async }}</span>
</div>
<div class="total-item total-series" title="Total series">
<div class="total-item total-series" [title]="t('main.totalSeries')">
<i class="pi pi-bookmark"></i>
<span class="total-label">Series</span>
<span class="total-label">{{ t('main.series') }}</span>
<span class="total-value">{{ totalSeries$ | async }}</span>
</div>
<div class="total-item total-publishers" title="Total publishers">
<div class="total-item total-publishers" [title]="t('main.totalPublishers')">
<i class="pi pi-building"></i>
<span class="total-label">Publishers</span>
<span class="total-label">{{ t('main.publishers') }}</span>
<span class="total-value">{{ totalPublishers$ | async }}</span>
</div>
<div class="total-item total-size" title="Total size">
<div class="total-item total-size" [title]="t('main.totalSize')">
<i class="pi pi-file"></i>
<span class="total-label">Library Size</span>
<span class="total-label">{{ t('main.librarySize') }}</span>
<span class="total-value">{{ totalSize$ | async }}</span>
</div>
</div>
@@ -67,28 +68,28 @@
<div class="config-modal-overlay" (click)="closeConfigPanel()">
<div class="config-modal" (click)="$event.stopPropagation()">
<div class="config-modal-header">
<h3><i class="pi pi-cog"></i> Chart Configuration</h3>
<button type="button" class="close-btn" (click)="closeConfigPanel()" title="Close">
<h3><i class="pi pi-cog"></i> {{ t('config.title') }}</h3>
<button type="button" class="close-btn" (click)="closeConfigPanel()" [title]="t('config.close')">
<i class="pi pi-times"></i>
</button>
</div>
<div class="config-modal-actions">
<button type="button" class="config-action-btn enable-all" (click)="enableAllCharts()">
<i class="pi pi-check"></i> Enable All
<i class="pi pi-check"></i> {{ t('config.enableAll') }}
</button>
<button type="button" class="config-action-btn disable-all" (click)="disableAllCharts()">
<i class="pi pi-times"></i> Disable All
<i class="pi pi-times"></i> {{ t('config.disableAll') }}
</button>
<button type="button" class="config-action-btn reset-order" (click)="resetChartOrder()">
<i class="pi pi-refresh"></i> Reset Order
<i class="pi pi-refresh"></i> {{ t('config.resetOrder') }}
</button>
</div>
<div class="config-modal-content">
<div class="config-categories">
<div class="config-category">
<h4>Small Charts</h4>
<h4>{{ t('config.smallCharts') }}</h4>
<div class="chart-toggles">
@for (chart of getChartsByCategory('small'); track chart.id) {
<div class="chart-toggle">
@@ -104,7 +105,7 @@
</div>
<div class="config-category">
<h4>Large Charts</h4>
<h4>{{ t('config.largeCharts') }}</h4>
<div class="chart-toggles">
@for (chart of getChartsByCategory('large'); track chart.id) {
<div class="chart-toggle">
@@ -120,7 +121,7 @@
</div>
<div class="config-category">
<h4>Extra Large Charts</h4>
<h4>{{ t('config.xlargeCharts') }}</h4>
<div class="chart-toggles">
@for (chart of getChartsByCategory('xlarge'); track chart.id) {
<div class="chart-toggle">
@@ -152,7 +153,7 @@
[cdkDragData]="chartConfig"
[class]="'chart-section ' + chartConfig.category">
<div class="drag-handle" cdkDragHandle title="Drag to reorder">
<div class="drag-handle" cdkDragHandle [title]="t('main.dragToReorder')">
<i class="pi pi-bars"></i>
</div>
@@ -192,14 +193,15 @@
@if (isLoading) {
<div class="loading-message">
Loading statistics...
{{ t('main.loading') }}
</div>
}
@if (!isLoading && !hasData) {
<div class="no-data-message">
No data available.
<small>Make sure your library contains books with metadata.</small>
{{ t('main.noData') }}
<small>{{ t('main.noDataHint') }}</small>
</div>
}
</div>
</ng-container>
@@ -17,6 +17,7 @@ import {PublicationTrendChartComponent} from './charts/publication-trend-chart/p
import {ReadingJourneyChartComponent} from './charts/reading-journey-chart/reading-journey-chart.component';
import {LibrariesSummaryService} from './service/libraries-summary.service';
import {LibraryFilterService, LibraryOption} from './service/library-filter.service';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
interface ChartConfig {
id: string;
@@ -42,7 +43,8 @@ interface ChartConfig {
AuthorUniverseChartComponent,
PublicationTimelineChartComponent,
PublicationTrendChartComponent,
ReadingJourneyChartComponent
ReadingJourneyChartComponent,
TranslocoDirective
],
templateUrl: './library-stats.component.html',
styleUrls: ['./library-stats.component.scss']
@@ -50,6 +52,7 @@ interface ChartConfig {
export class LibraryStatsComponent implements OnInit, OnDestroy {
private readonly libraryFilterService = inject(LibraryFilterService);
private readonly librariesSummaryService = inject(LibrariesSummaryService);
private readonly t = inject(TranslocoService);
private readonly destroy$ = new Subject<void>();
public isLoading = true;
@@ -59,17 +62,7 @@ export class LibraryStatsComponent implements OnInit, OnDestroy {
public selectedLibrary: LibraryOption | null = null;
public showConfigPanel = false;
public chartsConfig: ChartConfig[] = [
{id: 'bookFormats', name: 'Book Formats', enabled: true, category: 'small'},
{id: 'languageDistribution', name: 'Languages', enabled: true, category: 'small'},
{id: 'metadataScore', name: 'Metadata Score', enabled: true, category: 'small'},
{id: 'pageCountDistribution', name: 'Page Count', enabled: true, category: 'small'},
{id: 'publicationTimeline', name: 'Publication Timeline', enabled: true, category: 'large'},
{id: 'readingJourney', name: 'Reading Journey', enabled: true, category: 'large'},
{id: 'topItems', name: 'Top Items (Authors/Categories/etc.)', enabled: true, category: 'large'},
{id: 'authorUniverse', name: 'Author Universe', enabled: true, category: 'large'},
{id: 'publicationTrend', name: 'Publication Trend', enabled: true, category: 'xlarge'}
];
public chartsConfig: ChartConfig[] = this.buildChartsConfig();
booksSummary$ = this.librariesSummaryService.getBooksSummary().pipe(
catchError(error => {
@@ -184,16 +177,20 @@ export class LibraryStatsComponent implements OnInit, OnDestroy {
}
public resetChartOrder(): void {
this.chartsConfig = [
{id: 'bookFormats', name: 'Book Formats', enabled: true, category: 'small'},
{id: 'languageDistribution', name: 'Languages', enabled: true, category: 'small'},
{id: 'metadataScore', name: 'Metadata Score', enabled: true, category: 'small'},
{id: 'pageCountDistribution', name: 'Page Count', enabled: true, category: 'small'},
{id: 'publicationTimeline', name: 'Publication Timeline', enabled: true, category: 'large'},
{id: 'readingJourney', name: 'Reading Journey', enabled: true, category: 'large'},
{id: 'topItems', name: 'Top Items (Authors/Categories/etc.)', enabled: true, category: 'large'},
{id: 'authorUniverse', name: 'Author Universe', enabled: true, category: 'large'},
{id: 'publicationTrend', name: 'Publication Trend', enabled: true, category: 'xlarge'}
this.chartsConfig = this.buildChartsConfig();
}
private buildChartsConfig(): ChartConfig[] {
return [
{id: 'bookFormats', name: this.t.translate('statsLibrary.chartNames.bookFormats'), enabled: true, category: 'small'},
{id: 'languageDistribution', name: this.t.translate('statsLibrary.chartNames.languages'), enabled: true, category: 'small'},
{id: 'metadataScore', name: this.t.translate('statsLibrary.chartNames.metadataScore'), enabled: true, category: 'small'},
{id: 'pageCountDistribution', name: this.t.translate('statsLibrary.chartNames.pageCount'), enabled: true, category: 'small'},
{id: 'publicationTimeline', name: this.t.translate('statsLibrary.chartNames.publicationTimeline'), enabled: true, category: 'large'},
{id: 'readingJourney', name: this.t.translate('statsLibrary.chartNames.readingJourney'), enabled: true, category: 'large'},
{id: 'topItems', name: this.t.translate('statsLibrary.chartNames.topItems'), enabled: true, category: 'large'},
{id: 'authorUniverse', name: this.t.translate('statsLibrary.chartNames.authorUniverse'), enabled: true, category: 'large'},
{id: 'publicationTrend', name: this.t.translate('statsLibrary.chartNames.publicationTrend'), enabled: true, category: 'xlarge'}
];
}
}
@@ -2,6 +2,7 @@ import {inject, Injectable} from '@angular/core';
import {BehaviorSubject, combineLatest, map, Observable} from 'rxjs';
import {BookService} from '../../../../book/service/book.service';
import {LibraryService} from '../../../../book/service/library.service';
import {TranslocoService} from '@jsverse/transloco';
export interface LibraryOption {
id: number | null;
@@ -26,6 +27,7 @@ export class LibraryFilterService {
private bookService = inject(BookService);
private libraryService = inject(LibraryService);
private t = inject(TranslocoService);
getLibraryOptions(): Observable<LibraryOption[]> {
return combineLatest([
@@ -34,24 +36,24 @@ export class LibraryFilterService {
]).pipe(
map(([bookState, libraryState]) => {
if (!bookState.loaded || !bookState.books || bookState.books.length === 0) {
return [{id: null, name: 'All Libraries'}];
return [{id: null, name: this.t.translate('statsLibrary.libraryFilter.allLibraries')}];
}
if (!libraryState.loaded || !libraryState.libraries) {
return [{id: null, name: 'All Libraries'}];
return [{id: null, name: this.t.translate('statsLibrary.libraryFilter.allLibraries')}];
}
const libraryMap = new Map<number, string>();
bookState.books.forEach(book => {
if (!libraryMap.has(book.libraryId)) {
const library = libraryState.libraries?.find(lib => lib.id === book.libraryId);
const libraryName = library?.name || `Library ${book.libraryId}`;
const libraryName: string = library?.name || this.t.translate('statsLibrary.libraryFilter.libraryFallback', {id: book.libraryId}) as string;
libraryMap.set(book.libraryId, libraryName);
}
});
const options: LibraryOption[] = [
{id: null, name: 'All Libraries'},
{id: null, name: this.t.translate('statsLibrary.libraryFilter.allLibraries')},
...Array.from(libraryMap.entries()).map(([id, name]) => ({id, name}))
];