feat: add i18n translations for stats, pdf reader, magic shelf, and remaining components (en/es) (#2742)
This commit is contained in:
+8
-6
@@ -1,21 +1,22 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.bookLength'">
|
||||
<div class="book-length-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-book book-length-icon"></i>
|
||||
Book Length Sweet Spot
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Each dot is a book you've rated, plotted by its page count (X-axis) and your personal rating (Y-axis). Colors indicate read status: green = read, blue = reading, red = abandoned. The trend line shows whether you tend to rate longer or shorter books higher. The 'sweet spot' is the page-count range where your average rating is highest."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">How book length relates to your personal ratings</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
@if (totalRatedBooks > 0) {
|
||||
<div class="stats-badge">
|
||||
<span class="badge-value">{{ totalRatedBooks }}</span>
|
||||
<span class="badge-label">books analyzed</span>
|
||||
<span class="badge-label">{{ t('booksAnalyzed') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -24,11 +25,11 @@
|
||||
<div class="stats-row">
|
||||
<div class="stat-card">
|
||||
<span class="stat-value-sm">{{ sweetSpot }}</span>
|
||||
<span class="stat-label">Sweet Spot</span>
|
||||
<span class="stat-label">{{ t('sweetSpot') }}</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-value-sm">{{ highestRatedLength }}</span>
|
||||
<span class="stat-label">Highest Rated</span>
|
||||
<span class="stat-label">{{ t('highestRated') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -41,3 +42,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+44
-24
@@ -8,6 +8,7 @@ import {ChartConfiguration, ChartData, ScatterDataPoint} from 'chart.js';
|
||||
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 BookScatterPoint extends ScatterDataPoint {
|
||||
bookTitle: string;
|
||||
@@ -17,10 +18,10 @@ interface BookScatterPoint extends ScatterDataPoint {
|
||||
type LengthChartData = ChartData<'scatter', BookScatterPoint[], string>;
|
||||
|
||||
const STATUS_COLORS: Record<string, { bg: string; border: string }> = {
|
||||
'Read': {bg: 'rgba(76, 175, 80, 0.7)', border: '#4caf50'},
|
||||
'Reading': {bg: 'rgba(33, 150, 243, 0.7)', border: '#2196f3'},
|
||||
'Abandoned': {bg: 'rgba(244, 67, 54, 0.7)', border: '#f44336'},
|
||||
'Other': {bg: 'rgba(158, 158, 158, 0.7)', border: '#9e9e9e'}
|
||||
'read': {bg: 'rgba(76, 175, 80, 0.7)', border: '#4caf50'},
|
||||
'reading': {bg: 'rgba(33, 150, 243, 0.7)', border: '#2196f3'},
|
||||
'abandoned': {bg: 'rgba(244, 67, 54, 0.7)', border: '#f44336'},
|
||||
'other': {bg: 'rgba(158, 158, 158, 0.7)', border: '#9e9e9e'}
|
||||
};
|
||||
|
||||
const PAGE_RANGES = [
|
||||
@@ -35,12 +36,13 @@ const PAGE_RANGES = [
|
||||
@Component({
|
||||
selector: 'app-book-length-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './book-length-chart.component.html',
|
||||
styleUrls: ['./book-length-chart.component.scss']
|
||||
})
|
||||
export class BookLengthChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'scatter' as const;
|
||||
@@ -58,7 +60,7 @@ export class BookLengthChartComponent implements OnInit, OnDestroy {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Page Count',
|
||||
text: this.t.translate('statsUser.bookLength.axisPageCount'),
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 12, weight: 'bold'}
|
||||
},
|
||||
@@ -73,7 +75,7 @@ export class BookLengthChartComponent implements OnInit, OnDestroy {
|
||||
max: 10,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Personal Rating',
|
||||
text: this.t.translate('statsUser.bookLength.axisPersonalRating'),
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 12, weight: 'bold'}
|
||||
},
|
||||
@@ -111,14 +113,14 @@ export class BookLengthChartComponent implements OnInit, OnDestroy {
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const point = context[0].raw as BookScatterPoint;
|
||||
return point.bookTitle || 'Unknown Book';
|
||||
return point.bookTitle || this.t.translate('statsUser.bookLength.tooltipUnknownBook');
|
||||
},
|
||||
label: (context) => {
|
||||
const point = context.raw as BookScatterPoint;
|
||||
return [
|
||||
`Pages: ${point.x}`,
|
||||
`Rating: ${point.y}/10`,
|
||||
`Status: ${point.readStatus}`
|
||||
this.t.translate('statsUser.bookLength.tooltipPages', {count: point.x}),
|
||||
this.t.translate('statsUser.bookLength.tooltipRating', {rating: point.y}),
|
||||
this.t.translate('statsUser.bookLength.tooltipStatus', {status: point.readStatus})
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -169,12 +171,13 @@ export class BookLengthChartComponent implements OnInit, OnDestroy {
|
||||
this.totalRatedBooks = ratedBooks.length;
|
||||
if (this.totalRatedBooks === 0) return;
|
||||
|
||||
// Group by status
|
||||
const grouped = new Map<string, BookScatterPoint[]>();
|
||||
// Group by status key (for colors) and translated label (for display)
|
||||
const grouped = new Map<string, { label: string; points: BookScatterPoint[] }>();
|
||||
for (const book of ratedBooks) {
|
||||
const statusKey = this.getStatusKey(book.readStatus);
|
||||
const statusLabel = this.getStatusLabel(book.readStatus);
|
||||
if (!grouped.has(statusLabel)) grouped.set(statusLabel, []);
|
||||
grouped.get(statusLabel)!.push({
|
||||
if (!grouped.has(statusKey)) grouped.set(statusKey, {label: statusLabel, points: []});
|
||||
grouped.get(statusKey)!.points.push({
|
||||
x: book.metadata!.pageCount!,
|
||||
y: book.personalRating!,
|
||||
bookTitle: book.metadata?.title || book.fileName || 'Unknown',
|
||||
@@ -182,8 +185,8 @@ export class BookLengthChartComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
const datasets = Array.from(grouped.entries()).map(([label, points]) => {
|
||||
const colors = STATUS_COLORS[label] || STATUS_COLORS['Other'];
|
||||
const datasets = Array.from(grouped.entries()).map(([key, {label, points}]) => {
|
||||
const colors = STATUS_COLORS[key] || STATUS_COLORS['other'];
|
||||
return {
|
||||
label: `${label} (${points.length})`,
|
||||
data: points,
|
||||
@@ -200,7 +203,7 @@ export class BookLengthChartComponent implements OnInit, OnDestroy {
|
||||
const trend = this.computeTrendLine(allPoints);
|
||||
if (trend) {
|
||||
datasets.push({
|
||||
label: 'Trend',
|
||||
label: this.t.translate('statsUser.bookLength.trend'),
|
||||
data: trend as BookScatterPoint[],
|
||||
backgroundColor: 'transparent',
|
||||
borderColor: 'rgba(255, 255, 255, 0.4)',
|
||||
@@ -216,20 +219,37 @@ export class BookLengthChartComponent implements OnInit, OnDestroy {
|
||||
this.computeStats(ratedBooks);
|
||||
}
|
||||
|
||||
private getStatusLabel(status?: ReadStatus): string {
|
||||
if (!status) return 'Other';
|
||||
private getStatusKey(status?: ReadStatus): string {
|
||||
if (!status) return 'other';
|
||||
switch (status) {
|
||||
case ReadStatus.READ:
|
||||
case ReadStatus.PARTIALLY_READ:
|
||||
return 'Read';
|
||||
return 'read';
|
||||
case ReadStatus.READING:
|
||||
case ReadStatus.RE_READING:
|
||||
return 'Reading';
|
||||
return 'reading';
|
||||
case ReadStatus.ABANDONED:
|
||||
case ReadStatus.WONT_READ:
|
||||
return 'Abandoned';
|
||||
return 'abandoned';
|
||||
default:
|
||||
return 'Other';
|
||||
return 'other';
|
||||
}
|
||||
}
|
||||
|
||||
private getStatusLabel(status?: ReadStatus): string {
|
||||
if (!status) return this.t.translate('statsUser.bookLength.statusOther');
|
||||
switch (status) {
|
||||
case ReadStatus.READ:
|
||||
case ReadStatus.PARTIALLY_READ:
|
||||
return this.t.translate('statsUser.bookLength.statusRead');
|
||||
case ReadStatus.READING:
|
||||
case ReadStatus.RE_READING:
|
||||
return this.t.translate('statsUser.bookLength.statusReading');
|
||||
case ReadStatus.ABANDONED:
|
||||
case ReadStatus.WONT_READ:
|
||||
return this.t.translate('statsUser.bookLength.statusAbandoned');
|
||||
default:
|
||||
return this.t.translate('statsUser.bookLength.statusOther');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-13
@@ -1,29 +1,30 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.completionRace'">
|
||||
<div class="completion-race-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-flag completion-race-icon"></i>
|
||||
Reading Completion Race
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Each line represents a completed book's reading journey. The X-axis shows days since you started that book, and the Y-axis shows your progress from 0% to 100%. Steeper lines mean faster reads. Only books marked as 'Read' with tracked sessions are included."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Compare how quickly you finished different books</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<div class="year-selector">
|
||||
<button type="button"
|
||||
class="year-nav-btn"
|
||||
(click)="changeYear(-1)"
|
||||
title="Previous year">
|
||||
[title]="t('previousYear')">
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<span class="current-year">{{ currentYear }}</span>
|
||||
<button type="button"
|
||||
class="year-nav-btn"
|
||||
(click)="changeYear(1)"
|
||||
title="Next year">
|
||||
[title]="t('nextYear')">
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
@@ -33,29 +34,29 @@
|
||||
<div class="stats-row">
|
||||
<div class="stat-card">
|
||||
<span class="stat-value">{{ totalBooks }}</span>
|
||||
<span class="stat-label">Books</span>
|
||||
<span class="stat-label">{{ t('books') }}</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-value">{{ totalSessions }}</span>
|
||||
<span class="stat-label">Sessions</span>
|
||||
<span class="stat-label">{{ t('sessions') }}</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-value">{{ avgDaysToFinish }}d</span>
|
||||
<span class="stat-label">Avg Days</span>
|
||||
<span class="stat-label">{{ t('avgDays') }}</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-value">{{ medianDaysToFinish }}d</span>
|
||||
<span class="stat-label">Median Days</span>
|
||||
<span class="stat-label">{{ t('medianDays') }}</span>
|
||||
</div>
|
||||
<div class="stat-card fastest">
|
||||
<span class="stat-value">{{ fastestDays }}</span>
|
||||
<span class="stat-subtitle">{{ fastestTitle }}</span>
|
||||
<span class="stat-label">Fastest</span>
|
||||
<span class="stat-label">{{ t('fastest') }}</span>
|
||||
</div>
|
||||
<div class="stat-card slowest">
|
||||
<span class="stat-value">{{ slowestDays }}</span>
|
||||
<span class="stat-subtitle">{{ slowestTitle }}</span>
|
||||
<span class="stat-label">Slowest</span>
|
||||
<span class="stat-label">{{ t('slowest') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -71,8 +72,9 @@
|
||||
@if (totalBooks === 0) {
|
||||
<div class="no-data-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<p>No completed books with reading sessions found for {{ currentYear }}.</p>
|
||||
<small>Complete some books with tracked reading sessions to see your completion races.</small>
|
||||
<p>{{ t('noData', { year: currentYear }) }}</p>
|
||||
<small>{{ t('noDataHint') }}</small>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+6
-4
@@ -6,6 +6,7 @@ import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {CompletionRaceResponse, UserStatsService} from '../../../../../settings/user-management/user-stats.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface BookRace {
|
||||
bookId: number;
|
||||
@@ -25,7 +26,7 @@ const LINE_COLORS = [
|
||||
@Component({
|
||||
selector: 'app-completion-race-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './completion-race-chart.component.html',
|
||||
styleUrls: ['./completion-race-chart.component.scss']
|
||||
})
|
||||
@@ -47,6 +48,7 @@ export class CompletionRaceChartComponent implements OnInit, OnDestroy {
|
||||
public slowestTitle = '';
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<RaceChartData>;
|
||||
|
||||
@@ -89,7 +91,7 @@ export class CompletionRaceChartComponent implements OnInit, OnDestroy {
|
||||
label: (context) => {
|
||||
const progress = (context.parsed.y ?? 0).toFixed(1);
|
||||
const day = context.parsed.x;
|
||||
return `Day ${day}: ${progress}% progress`;
|
||||
return this.t.translate('statsUser.completionRace.tooltipDayProgress', {day, progress});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -100,7 +102,7 @@ export class CompletionRaceChartComponent implements OnInit, OnDestroy {
|
||||
type: 'linear',
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Days Since First Session',
|
||||
text: this.t.translate('statsUser.completionRace.axisDaysSinceFirstSession'),
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 12, weight: 'bold'}
|
||||
},
|
||||
@@ -117,7 +119,7 @@ export class CompletionRaceChartComponent implements OnInit, OnDestroy {
|
||||
max: 100,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Progress (%)',
|
||||
text: this.t.translate('statsUser.completionRace.axisProgress'),
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 12, weight: 'bold'}
|
||||
},
|
||||
|
||||
+6
-5
@@ -1,24 +1,25 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.completionTimeline'">
|
||||
<div class="completion-timeline-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-calendar completion-title-icon"></i>
|
||||
Reading Progress
|
||||
{{ t('title') }}
|
||||
</h3>
|
||||
<p class="chart-description">Monthly book completion statistics</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<div class="year-selector">
|
||||
<button type="button"
|
||||
class="year-nav-btn"
|
||||
(click)="changeYear(-1)"
|
||||
title="Previous year">
|
||||
[title]="t('previousYear')">
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<span class="current-year">{{ currentYear }}</span>
|
||||
<button type="button"
|
||||
class="year-nav-btn"
|
||||
(click)="changeYear(1)"
|
||||
title="Next year">
|
||||
[title]="t('nextYear')">
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
@@ -31,4 +32,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</ng-container>
|
||||
|
||||
+11
-8
@@ -5,13 +5,14 @@ import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {CompletionTimelineResponse, UserStatsService} from '../../../../../settings/user-management/user-stats.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
type CompletionChartData = ChartData<'bar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-completion-timeline-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective],
|
||||
imports: [CommonModule, BaseChartDirective, TranslocoDirective],
|
||||
templateUrl: './completion-timeline-chart.component.html',
|
||||
styleUrls: ['./completion-timeline-chart.component.scss']
|
||||
})
|
||||
@@ -24,6 +25,7 @@ export class CompletionTimelineChartComponent implements OnInit, OnDestroy {
|
||||
public readonly chartOptions: ChartConfiguration['options'];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<CompletionChartData>;
|
||||
|
||||
@@ -69,7 +71,8 @@ export class CompletionTimelineChartComponent implements OnInit, OnDestroy {
|
||||
label: (context) => {
|
||||
const label = context.dataset.label || '';
|
||||
const value = context.parsed.y;
|
||||
return `${label}: ${value} book${value !== 1 ? 's' : ''}`;
|
||||
const key = value !== 1 ? 'statsUser.completionTimeline.tooltipBooks' : 'statsUser.completionTimeline.tooltipBook';
|
||||
return this.t.translate(key, {label, value});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -79,7 +82,7 @@ export class CompletionTimelineChartComponent implements OnInit, OnDestroy {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Month',
|
||||
text: this.t.translate('statsUser.completionTimeline.axisMonth'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -97,7 +100,7 @@ export class CompletionTimelineChartComponent implements OnInit, OnDestroy {
|
||||
y: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Number of Books',
|
||||
text: this.t.translate('statsUser.completionTimeline.axisNumberOfBooks'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -190,7 +193,7 @@ export class CompletionTimelineChartComponent implements OnInit, OnDestroy {
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Completed',
|
||||
label: this.t.translate('statsUser.completionTimeline.completed'),
|
||||
data: completedBooks,
|
||||
backgroundColor: 'rgba(106, 176, 76, 0.8)',
|
||||
borderColor: 'rgba(106, 176, 76, 1)',
|
||||
@@ -200,7 +203,7 @@ export class CompletionTimelineChartComponent implements OnInit, OnDestroy {
|
||||
categoryPercentage: 0.6
|
||||
},
|
||||
{
|
||||
label: 'Active Reading',
|
||||
label: this.t.translate('statsUser.completionTimeline.activeReading'),
|
||||
data: activeReading,
|
||||
backgroundColor: 'rgba(59, 130, 246, 0.8)',
|
||||
borderColor: 'rgba(59, 130, 246, 1)',
|
||||
@@ -210,7 +213,7 @@ export class CompletionTimelineChartComponent implements OnInit, OnDestroy {
|
||||
categoryPercentage: 0.6
|
||||
},
|
||||
{
|
||||
label: 'Paused',
|
||||
label: this.t.translate('statsUser.completionTimeline.paused'),
|
||||
data: pausedBooks,
|
||||
backgroundColor: 'rgba(255, 193, 7, 0.8)',
|
||||
borderColor: 'rgba(255, 193, 7, 1)',
|
||||
@@ -220,7 +223,7 @@ export class CompletionTimelineChartComponent implements OnInit, OnDestroy {
|
||||
categoryPercentage: 0.6
|
||||
},
|
||||
{
|
||||
label: 'Discontinued',
|
||||
label: this.t.translate('statsUser.completionTimeline.discontinued'),
|
||||
data: discontinuedBooks,
|
||||
backgroundColor: 'rgba(239, 68, 68, 0.8)',
|
||||
borderColor: 'rgba(239, 68, 68, 1)',
|
||||
|
||||
+7
-5
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.favoriteDays'">
|
||||
<div class="favorite-days-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-calendar-plus favorite-days-icon"></i>
|
||||
Favorite Reading Days
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Bars show how many reading sessions and total reading time you logged on each day of the week. Filter by year and month to spot seasonal patterns. Helps you find your most productive reading days."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Reading sessions and duration by day of the week</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<div class="filter-controls">
|
||||
<p-select
|
||||
@@ -19,7 +20,7 @@
|
||||
(onChange)="onFilterChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Year"
|
||||
[placeholder]="t('selectYear')"
|
||||
[style]="{'min-width': '90px'}">
|
||||
</p-select>
|
||||
<p-select
|
||||
@@ -28,7 +29,7 @@
|
||||
(onChange)="onFilterChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Month"
|
||||
[placeholder]="t('selectMonth')"
|
||||
[style]="{'min-width': '120px'}">
|
||||
</p-select>
|
||||
</div>
|
||||
@@ -41,3 +42,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+19
-24
@@ -8,13 +8,14 @@ import {Select} from 'primeng/select';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {FavoriteDaysResponse, UserStatsService} from '../../../../../settings/user-management/user-stats.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
type FavoriteDaysChartData = ChartData<'bar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-favorite-days-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Select, FormsModule, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Select, FormsModule, Tooltip, TranslocoDirective],
|
||||
templateUrl: './favorite-days-chart.component.html',
|
||||
styleUrls: ['./favorite-days-chart.component.scss']
|
||||
})
|
||||
@@ -24,6 +25,7 @@ export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
public readonly chartOptions: ChartConfiguration['options'];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<FavoriteDaysChartData>;
|
||||
|
||||
@@ -32,21 +34,7 @@ export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
public selectedYear: number | null = null;
|
||||
public selectedMonth: number | null = null;
|
||||
public yearOptions: { label: string; value: number | null }[] = [];
|
||||
public monthOptions: { label: string; value: number | null }[] = [
|
||||
{label: 'All Months', value: null},
|
||||
{label: 'January', value: 1},
|
||||
{label: 'February', value: 2},
|
||||
{label: 'March', value: 3},
|
||||
{label: 'April', value: 4},
|
||||
{label: 'May', value: 5},
|
||||
{label: 'June', value: 6},
|
||||
{label: 'July', value: 7},
|
||||
{label: 'August', value: 8},
|
||||
{label: 'September', value: 9},
|
||||
{label: 'October', value: 10},
|
||||
{label: 'November', value: 11},
|
||||
{label: 'December', value: 12}
|
||||
];
|
||||
public monthOptions: { label: string; value: number | null }[] = [];
|
||||
|
||||
constructor() {
|
||||
this.chartDataSubject = new BehaviorSubject<FavoriteDaysChartData>({
|
||||
@@ -88,8 +76,10 @@ export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
label: (context) => {
|
||||
const label = context.dataset.label || '';
|
||||
const value = context.parsed.y;
|
||||
if (label === 'Sessions') {
|
||||
return `${label}: ${value} session${value !== 1 ? 's' : ''}`;
|
||||
const sessionsLabel = this.t.translate('statsUser.favoriteDays.sessions');
|
||||
if (label === sessionsLabel) {
|
||||
const key = value !== 1 ? 'statsUser.favoriteDays.tooltipSessionsPlural' : 'statsUser.favoriteDays.tooltipSessions';
|
||||
return this.t.translate(key, {label, value});
|
||||
} else {
|
||||
const hours = Math.floor(value);
|
||||
const minutes = Math.floor((value % 1) * 60);
|
||||
@@ -104,7 +94,7 @@ export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Day of Week',
|
||||
text: this.t.translate('statsUser.favoriteDays.axisDayOfWeek'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -125,7 +115,7 @@ export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
position: 'left',
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Number of Sessions',
|
||||
text: this.t.translate('statsUser.favoriteDays.axisNumberOfSessions'),
|
||||
color: 'rgba(139, 92, 246, 1)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -150,7 +140,7 @@ export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
position: 'right',
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Duration (hours)',
|
||||
text: this.t.translate('statsUser.favoriteDays.axisDurationHours'),
|
||||
color: 'rgba(236, 72, 153, 1)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -187,10 +177,15 @@ export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
|
||||
private initializeYearOptions(): void {
|
||||
const currentYear = new Date().getFullYear();
|
||||
this.yearOptions = [{label: 'All Years', value: null}];
|
||||
this.yearOptions = [{label: this.t.translate('statsUser.favoriteDays.allYears'), value: null}];
|
||||
for (let year = currentYear; year >= currentYear - 10; year--) {
|
||||
this.yearOptions.push({label: year.toString(), value: year});
|
||||
}
|
||||
const monthKeys = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
|
||||
this.monthOptions = [
|
||||
{label: this.t.translate('statsUser.favoriteDays.allMonths'), value: null},
|
||||
...monthKeys.map((key, i) => ({label: this.t.translate(`statsUser.favoriteDays.${key}`), value: i + 1}))
|
||||
];
|
||||
}
|
||||
|
||||
public onFilterChange(): void {
|
||||
@@ -235,7 +230,7 @@ export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Sessions',
|
||||
label: this.t.translate('statsUser.favoriteDays.sessions'),
|
||||
data: sessionCounts,
|
||||
backgroundColor: 'rgba(139, 92, 246, 0.8)',
|
||||
borderColor: 'rgba(139, 92, 246, 1)',
|
||||
@@ -246,7 +241,7 @@ export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
yAxisID: 'y'
|
||||
},
|
||||
{
|
||||
label: 'Duration (hours)',
|
||||
label: this.t.translate('statsUser.favoriteDays.durationHours'),
|
||||
data: durations,
|
||||
backgroundColor: 'rgba(236, 72, 153, 0.8)',
|
||||
borderColor: 'rgba(236, 72, 153, 1)',
|
||||
|
||||
+5
-3
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.genreStats'">
|
||||
<div class="genre-stats-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-chart-bar genre-title-icon"></i>
|
||||
Reading by Genre
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Ranks your top genres by total reading time. Each bar shows how many hours you've spent reading books in that genre, so you can see where most of your reading time actually goes."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Top genres by total reading time</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
@@ -21,3 +22,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+17
-10
@@ -6,13 +6,14 @@ import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {GenreStatsResponse, UserStatsService} from '../../../../../settings/user-management/user-stats.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
type GenreChartData = ChartData<'bar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-genre-stats-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './genre-stats-chart.component.html',
|
||||
styleUrls: ['./genre-stats-chart.component.scss']
|
||||
})
|
||||
@@ -24,6 +25,7 @@ export class GenreStatsChartComponent implements OnInit, OnDestroy {
|
||||
public readonly chartOptions: ChartConfiguration['options'];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<GenreChartData>;
|
||||
|
||||
@@ -77,7 +79,7 @@ export class GenreStatsChartComponent implements OnInit, OnDestroy {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Genres',
|
||||
text: this.t.translate('statsUser.genreStats.axisGenres'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -104,7 +106,7 @@ export class GenreStatsChartComponent implements OnInit, OnDestroy {
|
||||
y: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Time Read',
|
||||
text: this.t.translate('statsUser.genreStats.axisTimeRead'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -121,22 +123,27 @@ export class GenreStatsChartComponent implements OnInit, OnDestroy {
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const days = Math.floor(hours / 24);
|
||||
|
||||
const dayLabel = days === 1 ? this.t.translate('statsUser.genreStats.day') : this.t.translate('statsUser.genreStats.days');
|
||||
const hrLabel = (h: number) => h === 1 ? this.t.translate('statsUser.genreStats.hr') : this.t.translate('statsUser.genreStats.hrs');
|
||||
const minLabel = this.t.translate('statsUser.genreStats.min');
|
||||
const secLabel = this.t.translate('statsUser.genreStats.sec');
|
||||
|
||||
if (days > 0) {
|
||||
const remainingHours = hours % 24;
|
||||
if (remainingHours > 0) {
|
||||
return `${days} ${days === 1 ? 'day' : 'days'} ${remainingHours} ${remainingHours === 1 ? 'hr' : 'hrs'}`;
|
||||
return `${days} ${dayLabel} ${remainingHours} ${hrLabel(remainingHours)}`;
|
||||
}
|
||||
return `${days} ${days === 1 ? 'day' : 'days'}`;
|
||||
return `${days} ${dayLabel}`;
|
||||
} else if (hours > 0) {
|
||||
const remainingMinutes = minutes % 60;
|
||||
if (remainingMinutes > 0) {
|
||||
return `${hours} ${hours === 1 ? 'hr' : 'hrs'} ${remainingMinutes} min`;
|
||||
return `${hours} ${hrLabel(hours)} ${remainingMinutes} ${minLabel}`;
|
||||
}
|
||||
return `${hours} ${hours === 1 ? 'hr' : 'hrs'}`;
|
||||
return `${hours} ${hrLabel(hours)}`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes} min`;
|
||||
return `${minutes} ${minLabel}`;
|
||||
}
|
||||
return `${seconds} sec`;
|
||||
return `${seconds} ${secLabel}`;
|
||||
},
|
||||
stepSize: undefined,
|
||||
maxTicksLimit: 8
|
||||
@@ -185,7 +192,7 @@ export class GenreStatsChartComponent implements OnInit, OnDestroy {
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Reading Time',
|
||||
label: this.t.translate('statsUser.genreStats.readingTime'),
|
||||
data: durations,
|
||||
backgroundColor: 'rgba(34, 197, 94, 0.8)',
|
||||
borderColor: 'rgba(34, 197, 94, 1)',
|
||||
|
||||
+11
-9
@@ -1,31 +1,32 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.pageTurner'">
|
||||
<div class="page-turner-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-bolt page-turner-icon"></i>
|
||||
Page Turner Score
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Each book gets a 'grip score' (0-100) based on how your reading behavior changed over time. It measures whether your sessions got longer, whether gaps between sessions shrank, and whether you had a burst of reading near the end. Higher scores mean the book pulled you in more as you read."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">How gripping each book was based on your reading patterns</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stats-row">
|
||||
<div class="stat-item">
|
||||
<span class="stat-value" [title]="stats.mostGripping">{{ stats.mostGripping | slice:0:18 }}</span>
|
||||
<span class="stat-label">Most Gripping</span>
|
||||
<span class="stat-label">{{ t('mostGripping') }}</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-value">{{ stats.avgGripScore }}</span>
|
||||
<span class="stat-label">Avg Grip Score</span>
|
||||
<span class="stat-label">{{ t('avgGripScore') }}</span>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<span class="stat-value" [title]="stats.guiltyPleasure">{{ stats.guiltyPleasure | slice:0:18 }}</span>
|
||||
<span class="stat-label">Guilty Pleasure</span>
|
||||
<span class="stat-label">{{ t('guiltyPleasure') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -37,15 +38,15 @@
|
||||
<div class="book-info">
|
||||
<span class="book-name">{{ book.bookTitle | slice:0:30 }}</span>
|
||||
<div class="book-indicators">
|
||||
<span class="indicator" [title]="'Session duration trend'">
|
||||
<span class="indicator" [title]="t('sessionDurationTrend')">
|
||||
<i class="pi pi-clock"></i> {{ getAccelerationLabel(book.sessionAcceleration) }}
|
||||
</span>
|
||||
<span class="indicator" [title]="'Gap between sessions trend'">
|
||||
<span class="indicator" [title]="t('gapBetweenSessionsTrend')">
|
||||
<i class="pi pi-calendar"></i> {{ getGapLabel(book.gapReduction) }}
|
||||
</span>
|
||||
@if (book.finishBurst) {
|
||||
<span class="indicator burst">
|
||||
<i class="pi pi-forward"></i> Finish Burst
|
||||
<i class="pi pi-forward"></i> {{ t('finishBurst') }}
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
@@ -64,3 +65,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+15
-13
@@ -6,13 +6,14 @@ import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
import {PageTurnerScoreResponse, UserStatsService} from '../../../../../settings/user-management/user-stats.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
type PageTurnerChartData = ChartData<'bar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-page-turner-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './page-turner-chart.component.html',
|
||||
styleUrls: ['./page-turner-chart.component.scss']
|
||||
})
|
||||
@@ -25,6 +26,7 @@ export class PageTurnerChartComponent implements OnInit, OnDestroy {
|
||||
public topBooks: PageTurnerScoreResponse[] = [];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<PageTurnerChartData>;
|
||||
|
||||
@@ -61,7 +63,7 @@ export class PageTurnerChartComponent implements OnInit, OnDestroy {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Grip Score (0-100)',
|
||||
text: this.t.translate('statsUser.pageTurner.axisGripScore'),
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 13, weight: 'bold'}
|
||||
},
|
||||
@@ -145,12 +147,12 @@ export class PageTurnerChartComponent implements OnInit, OnDestroy {
|
||||
const item = top15[idx];
|
||||
if (!item) return '';
|
||||
const lines = [
|
||||
`Grip Score: ${item.gripScore}/100`,
|
||||
`Sessions: ${item.totalSessions}`,
|
||||
`Avg Session: ${Math.round(item.avgSessionDurationSeconds / 60)}min`,
|
||||
this.t.translate('statsUser.pageTurner.tooltipGripScore', {score: item.gripScore}),
|
||||
this.t.translate('statsUser.pageTurner.tooltipSessions', {count: item.totalSessions}),
|
||||
this.t.translate('statsUser.pageTurner.tooltipAvgSession', {minutes: Math.round(item.avgSessionDurationSeconds / 60)}),
|
||||
];
|
||||
if (item.personalRating) {
|
||||
lines.push(`Rating: ${item.personalRating}/10`);
|
||||
lines.push(this.t.translate('statsUser.pageTurner.tooltipRating', {rating: item.personalRating}));
|
||||
}
|
||||
return lines;
|
||||
};
|
||||
@@ -159,7 +161,7 @@ export class PageTurnerChartComponent implements OnInit, OnDestroy {
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
datasets: [{
|
||||
label: 'Grip Score',
|
||||
label: this.t.translate('statsUser.pageTurner.gripScore'),
|
||||
data: values,
|
||||
backgroundColor: bgColors,
|
||||
borderColor: bgColors.map(c => c.replace('0.85', '1')),
|
||||
@@ -172,14 +174,14 @@ export class PageTurnerChartComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
getAccelerationLabel(value: number): string {
|
||||
if (value > 5) return 'Increasing';
|
||||
if (value < -5) return 'Decreasing';
|
||||
return 'Steady';
|
||||
if (value > 5) return this.t.translate('statsUser.pageTurner.increasing');
|
||||
if (value < -5) return this.t.translate('statsUser.pageTurner.decreasing');
|
||||
return this.t.translate('statsUser.pageTurner.steady');
|
||||
}
|
||||
|
||||
getGapLabel(value: number): string {
|
||||
if (value < -2) return 'Shrinking';
|
||||
if (value > 2) return 'Growing';
|
||||
return 'Steady';
|
||||
if (value < -2) return this.t.translate('statsUser.pageTurner.shrinking');
|
||||
if (value > 2) return this.t.translate('statsUser.pageTurner.growing');
|
||||
return this.t.translate('statsUser.pageTurner.steady');
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.peakHours'">
|
||||
<div class="peak-hours-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-clock peak-hours-icon"></i>
|
||||
Peak Reading Hours
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Shows the number of reading sessions and total reading time for each hour of the day (midnight to 11pm). Filter by year and month to see how your habits shift over time. The peak hour highlights when you read the most."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Reading activity by hour of the day</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<div class="filter-controls">
|
||||
<p-select
|
||||
@@ -19,7 +20,7 @@
|
||||
(onChange)="onFilterChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Year"
|
||||
[placeholder]="t('selectYear')"
|
||||
[style]="{'min-width': '100px'}">
|
||||
</p-select>
|
||||
<p-select
|
||||
@@ -28,7 +29,7 @@
|
||||
(onChange)="onFilterChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Month"
|
||||
[placeholder]="t('selectMonth')"
|
||||
[style]="{'min-width': '130px'}">
|
||||
</p-select>
|
||||
</div>
|
||||
@@ -41,3 +42,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+20
-25
@@ -8,13 +8,14 @@ import {Select} from 'primeng/select';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {PeakHoursResponse, UserStatsService} from '../../../../../settings/user-management/user-stats.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
type PeakHoursChartData = ChartData<'line', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-peak-hours-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Select, FormsModule, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Select, FormsModule, Tooltip, TranslocoDirective],
|
||||
templateUrl: './peak-hours-chart.component.html',
|
||||
styleUrls: ['./peak-hours-chart.component.scss']
|
||||
})
|
||||
@@ -24,27 +25,14 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
|
||||
public readonly chartOptions: ChartConfiguration['options'];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<PeakHoursChartData>;
|
||||
|
||||
public selectedYear: number | null = null;
|
||||
public selectedMonth: number | null = null;
|
||||
public yearOptions: { label: string; value: number | null }[] = [];
|
||||
public monthOptions: { label: string; value: number | null }[] = [
|
||||
{label: 'All Months', value: null},
|
||||
{label: 'January', value: 1},
|
||||
{label: 'February', value: 2},
|
||||
{label: 'March', value: 3},
|
||||
{label: 'April', value: 4},
|
||||
{label: 'May', value: 5},
|
||||
{label: 'June', value: 6},
|
||||
{label: 'July', value: 7},
|
||||
{label: 'August', value: 8},
|
||||
{label: 'September', value: 9},
|
||||
{label: 'October', value: 10},
|
||||
{label: 'November', value: 11},
|
||||
{label: 'December', value: 12}
|
||||
];
|
||||
public monthOptions: { label: string; value: number | null }[] = [];
|
||||
|
||||
constructor() {
|
||||
this.chartDataSubject = new BehaviorSubject<PeakHoursChartData>({
|
||||
@@ -86,10 +74,12 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
|
||||
label: (context) => {
|
||||
const label = context.dataset.label || '';
|
||||
const value = context.parsed.y;
|
||||
if (label === 'Sessions') {
|
||||
return `${label}: ${value} session${value !== 1 ? 's' : ''}`;
|
||||
const sessionsLabel = this.t.translate('statsUser.peakHours.sessions');
|
||||
if (label === sessionsLabel) {
|
||||
const key = value !== 1 ? 'statsUser.peakHours.tooltipSessionsPlural' : 'statsUser.peakHours.tooltipSessions';
|
||||
return this.t.translate(key, {label, value});
|
||||
} else {
|
||||
return `${label}: ${value} min`;
|
||||
return this.t.translate('statsUser.peakHours.tooltipMin', {label, value});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,7 +90,7 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Hour of Day',
|
||||
text: this.t.translate('statsUser.peakHours.axisHourOfDay'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -123,7 +113,7 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
|
||||
position: 'left',
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Number of Sessions',
|
||||
text: this.t.translate('statsUser.peakHours.axisNumberOfSessions'),
|
||||
color: 'rgba(34, 197, 94, 0.9)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -148,7 +138,7 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
|
||||
position: 'right',
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Avg Duration (min)',
|
||||
text: this.t.translate('statsUser.peakHours.axisAvgDuration'),
|
||||
color: 'rgba(251, 191, 36, 0.9)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -185,10 +175,15 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
|
||||
|
||||
private initializeYearOptions(): void {
|
||||
const currentYear = new Date().getFullYear();
|
||||
this.yearOptions = [{label: 'All Years', value: null}];
|
||||
this.yearOptions = [{label: this.t.translate('statsUser.peakHours.allYears'), value: null}];
|
||||
for (let year = currentYear; year >= currentYear - 10; year--) {
|
||||
this.yearOptions.push({label: year.toString(), value: year});
|
||||
}
|
||||
const monthKeys = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
|
||||
this.monthOptions = [
|
||||
{label: this.t.translate('statsUser.peakHours.allMonths'), value: null},
|
||||
...monthKeys.map((key, i) => ({label: this.t.translate(`statsUser.peakHours.${key}`), value: i + 1}))
|
||||
];
|
||||
}
|
||||
|
||||
public onFilterChange(): void {
|
||||
@@ -239,7 +234,7 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Sessions',
|
||||
label: this.t.translate('statsUser.peakHours.sessions'),
|
||||
data: sessionCounts,
|
||||
borderColor: 'rgba(34, 197, 94, 0.9)',
|
||||
backgroundColor: 'rgba(34, 197, 94, 0.1)',
|
||||
@@ -254,7 +249,7 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
|
||||
yAxisID: 'y'
|
||||
},
|
||||
{
|
||||
label: 'Avg Duration (min)',
|
||||
label: this.t.translate('statsUser.peakHours.avgDurationMin'),
|
||||
data: avgDurations,
|
||||
borderColor: 'rgba(251, 191, 36, 0.9)',
|
||||
backgroundColor: 'rgba(251, 191, 36, 0.1)',
|
||||
|
||||
+5
-4
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.personalRating'">
|
||||
<div class="personal-rating-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-star-fill personal-rating-icon"></i>
|
||||
Personal Rating Distribution
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Shows how many books you've given each rating from 1 to 10. Helps you see whether you tend to rate generously, harshly, or cluster around a particular score. Only books with a personal rating are included."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Books by your rating (1–10)</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
@@ -21,4 +22,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</ng-container>
|
||||
|
||||
+10
-7
@@ -8,6 +8,7 @@ import {Tooltip} from 'primeng/tooltip';
|
||||
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 RatingStats {
|
||||
ratingRange: string;
|
||||
@@ -53,12 +54,13 @@ type RatingChartData = ChartData<'bar', number[], string>;
|
||||
@Component({
|
||||
selector: 'app-personal-rating-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './personal-rating-chart.component.html',
|
||||
styleUrls: ['./personal-rating-chart.component.scss']
|
||||
})
|
||||
export class PersonalRatingChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'bar' as const;
|
||||
@@ -84,10 +86,11 @@ export class PersonalRatingChartComponent implements OnInit, OnDestroy {
|
||||
titleFont: {size: 14, weight: 'bold'},
|
||||
bodyFont: {size: 13},
|
||||
callbacks: {
|
||||
title: (context) => `Personal Rating: ${context[0].label}`,
|
||||
title: (context) => this.t.translate('statsUser.personalRating.tooltipTitle', {label: context[0].label}),
|
||||
label: (context) => {
|
||||
const value = context.parsed.y;
|
||||
return `${value} book${value === 1 ? '' : 's'}`;
|
||||
const key = value === 1 ? 'statsUser.personalRating.tooltipBook' : 'statsUser.personalRating.tooltipBooks';
|
||||
return this.t.translate(key, {value});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -97,7 +100,7 @@ export class PersonalRatingChartComponent implements OnInit, OnDestroy {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Personal Rating',
|
||||
text: this.t.translate('statsUser.personalRating.axisPersonalRating'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -117,7 +120,7 @@ export class PersonalRatingChartComponent implements OnInit, OnDestroy {
|
||||
y: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Number of Books',
|
||||
text: this.t.translate('statsUser.personalRating.axisNumberOfBooks'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -145,7 +148,7 @@ export class PersonalRatingChartComponent implements OnInit, OnDestroy {
|
||||
private readonly chartDataSubject = new BehaviorSubject<RatingChartData>({
|
||||
labels: [],
|
||||
datasets: [{
|
||||
label: 'Books by Personal Rating',
|
||||
label: this.t.translate('statsUser.personalRating.booksByPersonalRating'),
|
||||
data: [],
|
||||
backgroundColor: [...CHART_COLORS],
|
||||
...CHART_DEFAULTS
|
||||
@@ -189,7 +192,7 @@ export class PersonalRatingChartComponent implements OnInit, OnDestroy {
|
||||
this.chartDataSubject.next({
|
||||
labels: allLabels,
|
||||
datasets: [{
|
||||
label: 'Books by Personal Rating',
|
||||
label: this.t.translate('statsUser.personalRating.booksByPersonalRating'),
|
||||
data: dataValues,
|
||||
backgroundColor: colors,
|
||||
borderColor: colors.map(color => color),
|
||||
|
||||
+15
-13
@@ -1,21 +1,22 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.ratingTaste'">
|
||||
<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
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Each dot is a book plotted by its external rating (X-axis, e.g. Goodreads/Amazon) versus your personal rating (Y-axis). Books on the diagonal mean you agree with the crowd. Above the line means you rated higher; below means you rated lower. Quadrants show your taste patterns."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Compare your personal ratings against external ratings (Goodreads, Amazon, etc.)</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
@if (totalRatedBooks > 0) {
|
||||
<div class="stats-badge">
|
||||
<span class="badge-value">{{ totalRatedBooks }}</span>
|
||||
<span class="badge-label">books analyzed</span>
|
||||
<span class="badge-label">{{ t('booksAnalyzed') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -27,28 +28,28 @@
|
||||
[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 class="quadrant-label top-left">{{ t('quadrantHiddenGems') }} 💎</div>
|
||||
<div class="quadrant-label top-right">{{ t('quadrantPopularFavorites') }} ⭐</div>
|
||||
<div class="quadrant-label bottom-left">{{ t('quadrantAgreedMisses') }} 👎</div>
|
||||
<div class="quadrant-label bottom-right">{{ t('quadrantOverrated') }} 📉</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (quadrants.length > 0) {
|
||||
<div class="taste-insights">
|
||||
<div class="insights-header">
|
||||
<h4>Your Taste Profile</h4>
|
||||
<h4>{{ t('tasteProfile') }}</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-label">{{ t('avgDeviation') }}</span>
|
||||
<span class="deviation-value">{{ averageDeviation.toFixed(2) }} ★</span>
|
||||
<span class="deviation-desc">
|
||||
@if (averageDeviation > 1) {
|
||||
(Unique taste)
|
||||
({{ t('uniqueTaste') }})
|
||||
} @else if (averageDeviation <= 0.5) {
|
||||
(Mainstream)
|
||||
({{ t('mainstream') }})
|
||||
} @else {
|
||||
(Balanced)
|
||||
({{ t('balanced') }})
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
@@ -76,3 +77,4 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+38
-28
@@ -9,6 +9,7 @@ import {BookService} from '../../../../../book/service/book.service';
|
||||
import {LibraryFilterService} from '../../../library-stats/service/library-filter.service';
|
||||
import {BookState} from '../../../../../book/model/state/book-state.model';
|
||||
import {Book} from '../../../../../book/model/book.model';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface TasteQuadrant {
|
||||
name: string;
|
||||
@@ -31,13 +32,14 @@ type RatingTasteChartData = ChartData<'scatter', BookDataPoint[], string>;
|
||||
@Component({
|
||||
selector: 'app-rating-taste-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
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 t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'scatter' as const;
|
||||
@@ -57,7 +59,7 @@ export class RatingTasteChartComponent implements OnInit, OnDestroy {
|
||||
max: 5,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'External Rating (1-5 scale)',
|
||||
text: this.t.translate('statsUser.ratingTaste.axisExternalRating'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -83,7 +85,7 @@ export class RatingTasteChartComponent implements OnInit, OnDestroy {
|
||||
max: 5,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Your Personal Rating (normalized from 1-10)',
|
||||
text: this.t.translate('statsUser.ratingTaste.axisPersonalRating'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -134,17 +136,17 @@ export class RatingTasteChartComponent implements OnInit, OnDestroy {
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const point = context[0].raw as BookDataPoint;
|
||||
return point.bookTitle || 'Unknown Book';
|
||||
return point.bookTitle || this.t.translate('statsUser.ratingTaste.tooltipUnknownBook');
|
||||
},
|
||||
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}`
|
||||
this.t.translate('statsUser.ratingTaste.tooltipYourRating', {rating: point.personalRating, normalized: point.personalRatingNormalized.toFixed(1)}),
|
||||
this.t.translate('statsUser.ratingTaste.tooltipExternalRating', {rating: point.externalRating.toFixed(1)}),
|
||||
this.t.translate('statsUser.ratingTaste.tooltipDifference', {diff: diffText}),
|
||||
this.t.translate('statsUser.ratingTaste.tooltipCategory', {category: point.quadrant})
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -261,10 +263,10 @@ export class RatingTasteChartComponent implements OnInit, OnDestroy {
|
||||
|
||||
private categorizeBooks(books: Book[]): Map<string, BookDataPoint[]> {
|
||||
const categories = new Map<string, BookDataPoint[]>([
|
||||
['Hidden Gems', []],
|
||||
['Popular Favorites', []],
|
||||
['Overrated', []],
|
||||
['Agreed Misses', []]
|
||||
[this.t.translate('statsUser.ratingTaste.quadrantHiddenGems'), []],
|
||||
[this.t.translate('statsUser.ratingTaste.quadrantPopularFavorites'), []],
|
||||
[this.t.translate('statsUser.ratingTaste.quadrantOverrated'), []],
|
||||
[this.t.translate('statsUser.ratingTaste.quadrantAgreedMisses'), []]
|
||||
]);
|
||||
|
||||
books.forEach(book => {
|
||||
@@ -277,13 +279,13 @@ export class RatingTasteChartComponent implements OnInit, OnDestroy {
|
||||
// Use normalized rating (3 is midpoint on 1-5 scale) for quadrant calculation
|
||||
let quadrant: string;
|
||||
if (personalRatingNormalized >= 3 && externalRating >= 3) {
|
||||
quadrant = 'Popular Favorites';
|
||||
quadrant = this.t.translate('statsUser.ratingTaste.quadrantPopularFavorites');
|
||||
} else if (personalRatingNormalized >= 3 && externalRating < 3) {
|
||||
quadrant = 'Hidden Gems';
|
||||
quadrant = this.t.translate('statsUser.ratingTaste.quadrantHiddenGems');
|
||||
} else if (personalRatingNormalized < 3 && externalRating >= 3) {
|
||||
quadrant = 'Overrated';
|
||||
quadrant = this.t.translate('statsUser.ratingTaste.quadrantOverrated');
|
||||
} else {
|
||||
quadrant = 'Agreed Misses';
|
||||
quadrant = this.t.translate('statsUser.ratingTaste.quadrantAgreedMisses');
|
||||
}
|
||||
|
||||
const dataPoint: BookDataPoint = {
|
||||
@@ -303,11 +305,15 @@ export class RatingTasteChartComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private updateChartData(dataPoints: Map<string, BookDataPoint[]>): void {
|
||||
const pf = this.t.translate('statsUser.ratingTaste.quadrantPopularFavorites');
|
||||
const hg = this.t.translate('statsUser.ratingTaste.quadrantHiddenGems');
|
||||
const or = this.t.translate('statsUser.ratingTaste.quadrantOverrated');
|
||||
const am = this.t.translate('statsUser.ratingTaste.quadrantAgreedMisses');
|
||||
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'}
|
||||
[pf]: {bg: 'rgba(76, 175, 80, 0.7)', border: '#4caf50'},
|
||||
[hg]: {bg: 'rgba(156, 39, 176, 0.7)', border: '#9c27b0'},
|
||||
[or]: {bg: 'rgba(255, 152, 0, 0.7)', border: '#ff9800'},
|
||||
[am]: {bg: 'rgba(158, 158, 158, 0.7)', border: '#9e9e9e'}
|
||||
};
|
||||
|
||||
const datasets = Array.from(dataPoints.entries())
|
||||
@@ -326,24 +332,28 @@ export class RatingTasteChartComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private calculateStatistics(dataPoints: Map<string, BookDataPoint[]>): void {
|
||||
const pfKey = this.t.translate('statsUser.ratingTaste.quadrantPopularFavorites');
|
||||
const hgKey = this.t.translate('statsUser.ratingTaste.quadrantHiddenGems');
|
||||
const orKey = this.t.translate('statsUser.ratingTaste.quadrantOverrated');
|
||||
const amKey = this.t.translate('statsUser.ratingTaste.quadrantAgreedMisses');
|
||||
const quadrantInfo: Record<string, { description: string, icon: string, color: string }> = {
|
||||
'Popular Favorites': {
|
||||
description: 'Books you and the public both love',
|
||||
[pfKey]: {
|
||||
description: this.t.translate('statsUser.ratingTaste.quadrantDescPopularFavorites'),
|
||||
icon: '⭐',
|
||||
color: '#4caf50'
|
||||
},
|
||||
'Hidden Gems': {
|
||||
description: 'Books you rate higher than the public',
|
||||
[hgKey]: {
|
||||
description: this.t.translate('statsUser.ratingTaste.quadrantDescHiddenGems'),
|
||||
icon: '💎',
|
||||
color: '#9c27b0'
|
||||
},
|
||||
'Overrated': {
|
||||
description: 'Popular books that disappointed you',
|
||||
[orKey]: {
|
||||
description: this.t.translate('statsUser.ratingTaste.quadrantDescOverrated'),
|
||||
icon: '📉',
|
||||
color: '#ff9800'
|
||||
},
|
||||
'Agreed Misses': {
|
||||
description: 'Books neither you nor public enjoyed',
|
||||
[amKey]: {
|
||||
description: this.t.translate('statsUser.ratingTaste.quadrantDescAgreedMisses'),
|
||||
icon: '👎',
|
||||
color: '#9e9e9e'
|
||||
}
|
||||
|
||||
+5
-3
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.readStatus'">
|
||||
<div class="read-status-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-book read-status-icon"></i>
|
||||
Reading Status Distribution
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Breaks down your entire library by reading status: read, reading, partially read, paused, abandoned, won't read, and unread. Gives you a quick snapshot of how much of your collection you've worked through."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Books by their reading status</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
@@ -21,3 +22,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+36
-34
@@ -3,28 +3,30 @@ import {CommonModule} from '@angular/common';
|
||||
import {BaseChartDirective} from 'ng2-charts';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, filter, first, takeUntil} from 'rxjs/operators';
|
||||
import {ChartConfiguration, ChartData, Chart, TooltipItem} from 'chart.js';
|
||||
import {ChartConfiguration, ChartData, Chart} from 'chart.js';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
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 ReadingStatusStats {
|
||||
status: string;
|
||||
rawStatus: ReadStatus;
|
||||
count: number;
|
||||
percentage: number;
|
||||
}
|
||||
|
||||
const STATUS_COLOR_MAP: Record<string, string> = {
|
||||
'Unread': '#6c757d', // Gray
|
||||
'Currently Reading': '#17a2b8', // Cyan
|
||||
'Re-reading': '#6f42c1', // Purple
|
||||
'Read': '#28a745', // Green
|
||||
'Partially Read': '#ffc107', // Yellow
|
||||
'Paused': '#fd7e14', // Orange
|
||||
"Won't Read": '#dc3545', // Red
|
||||
'Abandoned': '#e74c3c', // Light Red
|
||||
'No Status': '#343a40' // Dark Gray
|
||||
[ReadStatus.UNREAD]: '#6c757d',
|
||||
[ReadStatus.READING]: '#17a2b8',
|
||||
[ReadStatus.RE_READING]: '#6f42c1',
|
||||
[ReadStatus.READ]: '#28a745',
|
||||
[ReadStatus.PARTIALLY_READ]: '#ffc107',
|
||||
[ReadStatus.PAUSED]: '#fd7e14',
|
||||
[ReadStatus.WONT_READ]: '#dc3545',
|
||||
[ReadStatus.ABANDONED]: '#e74c3c',
|
||||
[ReadStatus.UNSET]: '#343a40'
|
||||
} as const;
|
||||
|
||||
const CHART_DEFAULTS = {
|
||||
@@ -39,12 +41,13 @@ type StatusChartData = ChartData<'doughnut', number[], string>;
|
||||
@Component({
|
||||
selector: 'app-read-status-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './read-status-chart.component.html',
|
||||
styleUrls: ['./read-status-chart.component.scss']
|
||||
})
|
||||
export class ReadStatusChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'doughnut' as const;
|
||||
@@ -84,7 +87,15 @@ export class ReadStatusChartComponent implements OnInit, OnDestroy {
|
||||
bodyFont: {size: 13},
|
||||
callbacks: {
|
||||
title: (context) => context[0]?.label || '',
|
||||
label: this.formatTooltipLabel
|
||||
label: (context) => {
|
||||
const dataIndex = context.dataIndex;
|
||||
const dataset = context.dataset;
|
||||
const value = dataset.data[dataIndex] as number;
|
||||
const label = context.chart.data.labels?.[dataIndex] || '';
|
||||
const total = (dataset.data as number[]).reduce((a: number, b: number) => a + b, 0);
|
||||
const percentage = ((value / total) * 100).toFixed(1);
|
||||
return this.t.translate('statsUser.readStatus.tooltipLabel', {label, value, percentage});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -131,7 +142,7 @@ export class ReadStatusChartComponent implements OnInit, OnDestroy {
|
||||
try {
|
||||
const labels = stats.map(s => s.status);
|
||||
const dataValues = stats.map(s => s.count);
|
||||
const colors = stats.map(s => STATUS_COLOR_MAP[s.status] || '#6c757d');
|
||||
const colors = stats.map(s => STATUS_COLOR_MAP[s.rawStatus] || '#6c757d');
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
@@ -196,6 +207,7 @@ export class ReadStatusChartComponent implements OnInit, OnDestroy {
|
||||
return Array.from(statusMap.entries())
|
||||
.map(([status, count]) => ({
|
||||
status: this.formatReadStatus(status),
|
||||
rawStatus: status,
|
||||
count,
|
||||
percentage: Number(((count / totalBooks) * 100).toFixed(1))
|
||||
}))
|
||||
@@ -204,19 +216,19 @@ export class ReadStatusChartComponent implements OnInit, OnDestroy {
|
||||
|
||||
private formatReadStatus(status: ReadStatus | null | undefined): string {
|
||||
const STATUS_MAPPING: Record<string, string> = {
|
||||
[ReadStatus.UNREAD]: 'Unread',
|
||||
[ReadStatus.READING]: 'Currently Reading',
|
||||
[ReadStatus.RE_READING]: 'Re-reading',
|
||||
[ReadStatus.READ]: 'Read',
|
||||
[ReadStatus.PARTIALLY_READ]: 'Partially Read',
|
||||
[ReadStatus.PAUSED]: 'Paused',
|
||||
[ReadStatus.WONT_READ]: "Won't Read",
|
||||
[ReadStatus.ABANDONED]: 'Abandoned',
|
||||
[ReadStatus.UNSET]: 'No Status'
|
||||
[ReadStatus.UNREAD]: this.t.translate('statsUser.readStatus.unread'),
|
||||
[ReadStatus.READING]: this.t.translate('statsUser.readStatus.currentlyReading'),
|
||||
[ReadStatus.RE_READING]: this.t.translate('statsUser.readStatus.reReading'),
|
||||
[ReadStatus.READ]: this.t.translate('statsUser.readStatus.read'),
|
||||
[ReadStatus.PARTIALLY_READ]: this.t.translate('statsUser.readStatus.partiallyRead'),
|
||||
[ReadStatus.PAUSED]: this.t.translate('statsUser.readStatus.paused'),
|
||||
[ReadStatus.WONT_READ]: this.t.translate('statsUser.readStatus.wontRead'),
|
||||
[ReadStatus.ABANDONED]: this.t.translate('statsUser.readStatus.abandoned'),
|
||||
[ReadStatus.UNSET]: this.t.translate('statsUser.readStatus.noStatus')
|
||||
};
|
||||
|
||||
if (!status) return 'No Status';
|
||||
return STATUS_MAPPING[status] ?? 'No Status';
|
||||
if (!status) return this.t.translate('statsUser.readStatus.noStatus');
|
||||
return STATUS_MAPPING[status] ?? this.t.translate('statsUser.readStatus.noStatus');
|
||||
}
|
||||
|
||||
private generateLegendLabels(chart: Chart) {
|
||||
@@ -244,14 +256,4 @@ export class ReadStatusChartComponent implements OnInit, OnDestroy {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private formatTooltipLabel(context: TooltipItem<any>): string {
|
||||
const dataIndex = context.dataIndex;
|
||||
const dataset = context.dataset;
|
||||
const value = dataset.data[dataIndex] as number;
|
||||
const label = context.chart.data.labels?.[dataIndex] || 'Unknown';
|
||||
const total = (dataset.data as number[]).reduce((a: number, b: number) => a + b, 0);
|
||||
const percentage = ((value / total) * 100).toFixed(1);
|
||||
return `${label}: ${value} books (${percentage}%)`;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-8
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.readingClock'">
|
||||
<div class="reading-clock-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-clock reading-clock-icon"></i>
|
||||
Reading Clock
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Each segment of the clock represents one hour of the day (12am-11pm). The size of each segment shows how many total minutes you've spent reading during that hour across all time. Warm colors indicate your busiest hours. You're classified as a Night Owl (most reading 8pm-2am), Early Bird (5am-11am), or Balanced."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">When do you read throughout the day</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -18,15 +19,15 @@
|
||||
<div class="stats-row">
|
||||
<div class="stat-card peak">
|
||||
<span class="stat-value">{{ peakHour }}</span>
|
||||
<span class="stat-label">Peak Hour</span>
|
||||
<span class="stat-label">{{ t('peakHour') }}</span>
|
||||
</div>
|
||||
<div class="stat-card total">
|
||||
<span class="stat-value">{{ totalHoursRead }}h</span>
|
||||
<span class="stat-label">Total Read</span>
|
||||
<span class="stat-label">{{ t('totalRead') }}</span>
|
||||
</div>
|
||||
<div class="stat-card type">
|
||||
<span class="stat-value">{{ readerType }}</span>
|
||||
<span class="stat-label">Reader Type</span>
|
||||
<span class="stat-label">{{ t('readerType') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -42,8 +43,9 @@
|
||||
@if (!hasData) {
|
||||
<div class="no-data-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<p>No reading session data found.</p>
|
||||
<small>Track your reading sessions to see your reading clock.</small>
|
||||
<p>{{ t('noData') }}</p>
|
||||
<small>{{ t('noDataHint') }}</small>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+8
-6
@@ -6,6 +6,7 @@ import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
import {PeakHoursResponse, UserStatsService} from '../../../../../settings/user-management/user-stats.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
type ClockChartData = ChartData<'polarArea', number[], string>;
|
||||
|
||||
@@ -19,12 +20,13 @@ const HOUR_LABELS = [
|
||||
@Component({
|
||||
selector: 'app-reading-clock-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './reading-clock-chart.component.html',
|
||||
styleUrls: ['./reading-clock-chart.component.scss']
|
||||
})
|
||||
export class ReadingClockChartComponent implements OnInit, OnDestroy {
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'polarArea' as const;
|
||||
@@ -59,9 +61,9 @@ export class ReadingClockChartComponent implements OnInit, OnDestroy {
|
||||
if (minutes >= 60) {
|
||||
const hrs = Math.floor(minutes / 60);
|
||||
const mins = Math.round(minutes % 60);
|
||||
return `${hrs}h ${mins}m of reading`;
|
||||
return this.t.translate('statsUser.readingClock.tooltipReading', {time: `${hrs}h ${mins}m`});
|
||||
}
|
||||
return `${Math.round(minutes)}m of reading`;
|
||||
return this.t.translate('statsUser.readingClock.tooltipReading', {time: `${Math.round(minutes)}m`});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -138,11 +140,11 @@ export class ReadingClockChartComponent implements OnInit, OnDestroy {
|
||||
const morningTotal = morningHours.reduce((sum, h) => sum + hourMinutes[h], 0);
|
||||
|
||||
if (nightTotal > morningTotal * 1.2) {
|
||||
this.readerType = 'Night Owl';
|
||||
this.readerType = this.t.translate('statsUser.readingClock.nightOwl');
|
||||
} else if (morningTotal > nightTotal * 1.2) {
|
||||
this.readerType = 'Early Bird';
|
||||
this.readerType = this.t.translate('statsUser.readingClock.earlyBird');
|
||||
} else {
|
||||
this.readerType = 'Balanced';
|
||||
this.readerType = this.t.translate('statsUser.readingClock.balanced');
|
||||
}
|
||||
|
||||
// Generate colors: cool blues for low, warm oranges for peak
|
||||
|
||||
+6
-4
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.readingDna'">
|
||||
<div class="reading-dna-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-chart-line reading-dna-icon"></i>
|
||||
Reading DNA Profile
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="A radar chart profiling your reading personality across 8 dimensions. Scores are computed from your library's genres, ratings, page counts, publication dates, and reading progress. Each trait uses non-overlapping criteria for accurate results."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Your unique reading personality across 8 dimensions</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
@@ -22,7 +23,7 @@
|
||||
</div>
|
||||
@if (personalityInsights.length > 0) {
|
||||
<div class="personality-insights">
|
||||
<h4>Your Reading Personality Traits</h4>
|
||||
<h4>{{ t('personalityTraits') }}</h4>
|
||||
<div class="insights-grid">
|
||||
@for (insight of personalityInsights; track insight.trait) {
|
||||
<div class="insight-card">
|
||||
@@ -40,3 +41,4 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+28
-90
@@ -8,6 +8,7 @@ import {Tooltip} from 'primeng/tooltip';
|
||||
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 ReadingDNAProfile {
|
||||
adventurous: number;
|
||||
@@ -32,12 +33,13 @@ type ReadingDNAChartData = ChartData<'radar', number[], string>;
|
||||
@Component({
|
||||
selector: 'app-reading-dna-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './reading-dna-chart.component.html',
|
||||
styleUrls: ['./reading-dna-chart.component.scss']
|
||||
})
|
||||
export class ReadingDNAChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'radar' as const;
|
||||
@@ -77,18 +79,12 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy {
|
||||
size: 12
|
||||
},
|
||||
padding: 25,
|
||||
callback: function (label: string) {
|
||||
const icons: Record<string, string> = {
|
||||
'Adventurous': '🌟',
|
||||
'Perfectionist': '💎',
|
||||
'Intellectual': '🧠',
|
||||
'Emotional': '💖',
|
||||
'Patient': '🕰️',
|
||||
'Social': '👥',
|
||||
'Nostalgic': '📚',
|
||||
'Ambitious': '🚀'
|
||||
};
|
||||
return [icons[label] || '', label];
|
||||
callback: (label: string) => {
|
||||
const traitKeys = ['adventurous', 'perfectionist', 'intellectual', 'emotional', 'patient', 'social', 'nostalgic', 'ambitious'];
|
||||
const icons = ['🌟', '💎', '🧠', '💖', '🕰️', '👥', '📚', '🚀'];
|
||||
const translatedLabels = traitKeys.map(k => this.t.translate(`statsUser.readingDna.traits.${k}`));
|
||||
const idx = translatedLabels.indexOf(label);
|
||||
return [idx >= 0 ? icons[idx] : '', label];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,16 +107,16 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy {
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const label = context[0]?.label || '';
|
||||
return `${label} Personality`;
|
||||
return this.t.translate('statsUser.readingDna.tooltipPersonality', {label});
|
||||
},
|
||||
label: (context) => {
|
||||
const score = context.parsed.r;
|
||||
const insight = this.personalityInsights.find(i => i.trait === context.label);
|
||||
|
||||
return [
|
||||
`Score: ${score}/100`,
|
||||
this.t.translate('statsUser.readingDna.tooltipScore', {score}),
|
||||
'',
|
||||
insight ? insight.description : 'Your reading personality trait'
|
||||
insight ? insight.description : this.t.translate('statsUser.readingDna.tooltipDefaultDescription')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -144,11 +140,10 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
};
|
||||
|
||||
private readonly traitKeys = ['adventurous', 'perfectionist', 'intellectual', 'emotional', 'patient', 'social', 'nostalgic', 'ambitious'];
|
||||
|
||||
private readonly chartDataSubject = new BehaviorSubject<ReadingDNAChartData>({
|
||||
labels: [
|
||||
'Adventurous', 'Perfectionist', 'Intellectual', 'Emotional',
|
||||
'Patient', 'Social', 'Nostalgic', 'Ambitious'
|
||||
],
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
|
||||
@@ -200,13 +195,12 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy {
|
||||
'#9c27b0', '#3f51b5', '#673ab7', '#009688'
|
||||
];
|
||||
|
||||
const translatedLabels = this.traitKeys.map(k => this.t.translate(`statsUser.readingDna.traits.${k}`));
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels: [
|
||||
'Adventurous', 'Perfectionist', 'Intellectual', 'Emotional',
|
||||
'Patient', 'Social', 'Nostalgic', 'Ambitious'
|
||||
],
|
||||
labels: translatedLabels,
|
||||
datasets: [{
|
||||
label: 'Reading DNA Profile',
|
||||
label: this.t.translate('statsUser.readingDna.readingDnaProfile'),
|
||||
data,
|
||||
backgroundColor: 'rgba(233, 30, 99, 0.2)',
|
||||
borderColor: '#e91e63',
|
||||
@@ -441,75 +435,19 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy {
|
||||
);
|
||||
}
|
||||
|
||||
private getTraitDescription(trait: string, score: number): string {
|
||||
const descriptions: Record<string, [string, string, string]> = {
|
||||
'Adventurous': [
|
||||
'You tend to stick to familiar genres and formats',
|
||||
'You enjoy a healthy mix of genres and styles',
|
||||
'You explore a wide variety of genres, languages, and formats'
|
||||
],
|
||||
'Perfectionist': [
|
||||
'You keep many books in progress or unfinished',
|
||||
'You finish most books and favor quality reads',
|
||||
'You almost always finish what you start and seek top-rated books'
|
||||
],
|
||||
'Intellectual': [
|
||||
'Your reading leans toward lighter subjects',
|
||||
'You balance entertainment with educational reading',
|
||||
'You gravitate heavily toward non-fiction and scholarly material'
|
||||
],
|
||||
'Emotional': [
|
||||
'You tend toward plot-driven or factual reading',
|
||||
'You enjoy a mix of emotional and analytical reads',
|
||||
'You connect deeply with memoirs, poetry, and emotionally rich stories'
|
||||
],
|
||||
'Patient': [
|
||||
'You prefer shorter, quicker reads',
|
||||
'You occasionally tackle longer works and series',
|
||||
'You regularly take on epic novels and multi-book series'
|
||||
],
|
||||
'Social': [
|
||||
'You prefer niche or lesser-known titles',
|
||||
'You read a mix of popular and niche titles',
|
||||
'Your library is packed with bestsellers and widely-discussed books'
|
||||
],
|
||||
'Nostalgic': [
|
||||
'You mostly read contemporary publications',
|
||||
'You appreciate a mix of classic and modern works',
|
||||
'You have a deep love for classic literature and older works'
|
||||
],
|
||||
'Ambitious': [
|
||||
'You read at a casual pace with shorter books',
|
||||
'You maintain a solid reading volume with some challenging picks',
|
||||
'You push yourself with large volumes of challenging, lengthy books'
|
||||
]
|
||||
};
|
||||
|
||||
const levels = descriptions[trait];
|
||||
if (!levels) return '';
|
||||
|
||||
if (score < 33) return levels[0];
|
||||
if (score < 67) return levels[1];
|
||||
return levels[2];
|
||||
private getTraitDescription(traitKey: string, score: number): string {
|
||||
const level = score < 33 ? 'low' : score < 67 ? 'mid' : 'high';
|
||||
return this.t.translate(`statsUser.readingDna.descriptions.${traitKey}.${level}`);
|
||||
}
|
||||
|
||||
private buildPersonalityInsights(profile: ReadingDNAProfile): PersonalityInsight[] {
|
||||
const traits: { key: keyof ReadingDNAProfile; trait: string; color: string }[] = [
|
||||
{key: 'adventurous', trait: 'Adventurous', color: '#e91e63'},
|
||||
{key: 'perfectionist', trait: 'Perfectionist', color: '#2196f3'},
|
||||
{key: 'intellectual', trait: 'Intellectual', color: '#00bcd4'},
|
||||
{key: 'emotional', trait: 'Emotional', color: '#ff9800'},
|
||||
{key: 'patient', trait: 'Patient', color: '#9c27b0'},
|
||||
{key: 'social', trait: 'Social', color: '#3f51b5'},
|
||||
{key: 'nostalgic', trait: 'Nostalgic', color: '#673ab7'},
|
||||
{key: 'ambitious', trait: 'Ambitious', color: '#009688'}
|
||||
];
|
||||
const traitColors = ['#e91e63', '#2196f3', '#00bcd4', '#ff9800', '#9c27b0', '#3f51b5', '#673ab7', '#009688'];
|
||||
|
||||
return traits.map(({key, trait, color}) => ({
|
||||
trait,
|
||||
score: profile[key],
|
||||
description: this.getTraitDescription(trait, profile[key]),
|
||||
color
|
||||
return this.traitKeys.map((key, i) => ({
|
||||
trait: this.t.translate(`statsUser.readingDna.traits.${key}`),
|
||||
score: profile[key as keyof ReadingDNAProfile],
|
||||
description: this.getTraitDescription(key, profile[key as keyof ReadingDNAProfile]),
|
||||
color: traitColors[i]
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.readingHabits'">
|
||||
<div class="reading-habits-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-chart-line reading-habits-icon"></i>
|
||||
Reading Habits Analysis
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="A radar chart analyzing your reading behavior across 8 dimensions. Consistency measures regularity of completions over time. Completionism tracks finish vs. abandonment rate. Methodology checks if you read series in order. Scores are derived from your reading activity, dates, and progress data."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Your behavioral reading patterns across 8 dimensions</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
@@ -22,7 +23,7 @@
|
||||
</div>
|
||||
@if (habitInsights.length > 0) {
|
||||
<div class="habit-insights">
|
||||
<h4>Your Reading Habit Patterns</h4>
|
||||
<h4>{{ t('habitPatterns') }}</h4>
|
||||
<div class="insights-grid">
|
||||
@for (insight of habitInsights; track insight.habit) {
|
||||
<div class="insight-card">
|
||||
@@ -40,3 +41,4 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+27
-90
@@ -8,6 +8,7 @@ import {Tooltip} from 'primeng/tooltip';
|
||||
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 ReadingHabitsProfile {
|
||||
consistency: number;
|
||||
@@ -32,14 +33,17 @@ type ReadingHabitsChartData = ChartData<'radar', number[], string>;
|
||||
@Component({
|
||||
selector: 'app-reading-habits-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './reading-habits-chart.component.html',
|
||||
styleUrls: ['./reading-habits-chart.component.scss']
|
||||
})
|
||||
export class ReadingHabitsChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
private readonly habitKeys = ['consistency', 'multitasking', 'completionism', 'exploration', 'organization', 'intensity', 'methodology', 'momentum'];
|
||||
|
||||
public readonly chartType = 'radar' as const;
|
||||
|
||||
public readonly chartOptions: ChartConfiguration<'radar'>['options'] = {
|
||||
@@ -77,18 +81,11 @@ export class ReadingHabitsChartComponent implements OnInit, OnDestroy {
|
||||
size: 12
|
||||
},
|
||||
padding: 25,
|
||||
callback: function (label: string) {
|
||||
const icons: Record<string, string> = {
|
||||
'Consistency': '📅',
|
||||
'Multitasking': '📚',
|
||||
'Completionism': '✅',
|
||||
'Exploration': '🔍',
|
||||
'Organization': '📋',
|
||||
'Intensity': '⚡',
|
||||
'Methodology': '🎯',
|
||||
'Momentum': '🔥'
|
||||
};
|
||||
return [icons[label] || '', label];
|
||||
callback: (label: string) => {
|
||||
const icons = ['📅', '📚', '✅', '🔍', '📋', '⚡', '🎯', '🔥'];
|
||||
const translatedLabels = this.habitKeys.map(k => this.t.translate(`statsUser.readingHabits.habits.${k}`));
|
||||
const idx = translatedLabels.indexOf(label);
|
||||
return [idx >= 0 ? icons[idx] : '', label];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,16 +108,16 @@ export class ReadingHabitsChartComponent implements OnInit, OnDestroy {
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const label = context[0]?.label || '';
|
||||
return `${label} Habit`;
|
||||
return this.t.translate('statsUser.readingHabits.tooltipHabit', {label});
|
||||
},
|
||||
label: (context) => {
|
||||
const score = context.parsed.r;
|
||||
const insight = this.habitInsights.find(i => i.habit === context.label);
|
||||
|
||||
return [
|
||||
`Score: ${score}/100`,
|
||||
this.t.translate('statsUser.readingHabits.tooltipScore', {score}),
|
||||
'',
|
||||
insight ? insight.description : 'Your reading habit pattern'
|
||||
insight ? insight.description : this.t.translate('statsUser.readingHabits.tooltipDefaultDescription')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -145,10 +142,7 @@ export class ReadingHabitsChartComponent implements OnInit, OnDestroy {
|
||||
};
|
||||
|
||||
private readonly chartDataSubject = new BehaviorSubject<ReadingHabitsChartData>({
|
||||
labels: [
|
||||
'Consistency', 'Multitasking', 'Completionism', 'Exploration',
|
||||
'Organization', 'Intensity', 'Methodology', 'Momentum'
|
||||
],
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
|
||||
@@ -200,13 +194,12 @@ export class ReadingHabitsChartComponent implements OnInit, OnDestroy {
|
||||
'#ffc107', '#4caf50', '#2196f3', '#673ab7'
|
||||
];
|
||||
|
||||
const translatedLabels = this.habitKeys.map(k => this.t.translate(`statsUser.readingHabits.habits.${k}`));
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels: [
|
||||
'Consistency', 'Multitasking', 'Completionism', 'Exploration',
|
||||
'Organization', 'Intensity', 'Methodology', 'Momentum'
|
||||
],
|
||||
labels: translatedLabels,
|
||||
datasets: [{
|
||||
label: 'Reading Habits Profile',
|
||||
label: this.t.translate('statsUser.readingHabits.readingHabitsProfile'),
|
||||
data,
|
||||
backgroundColor: 'rgba(156, 39, 176, 0.2)',
|
||||
borderColor: '#9c27b0',
|
||||
@@ -509,75 +502,19 @@ export class ReadingHabitsChartComponent implements OnInit, OnDestroy {
|
||||
);
|
||||
}
|
||||
|
||||
private getHabitDescription(habit: string, score: number): string {
|
||||
const descriptions: Record<string, [string, string, string]> = {
|
||||
'Consistency': [
|
||||
'Your reading is sporadic with long gaps between books',
|
||||
'You read at a fairly regular pace throughout the year',
|
||||
'You maintain a very steady, disciplined reading rhythm'
|
||||
],
|
||||
'Multitasking': [
|
||||
'You prefer focusing on one book at a time',
|
||||
'You occasionally juggle a couple of books at once',
|
||||
'You regularly read multiple books simultaneously'
|
||||
],
|
||||
'Completionism': [
|
||||
'You often set books aside before finishing them',
|
||||
'You finish most books you start, with a few exceptions',
|
||||
'You almost never abandon a book once you start it'
|
||||
],
|
||||
'Exploration': [
|
||||
'You tend to revisit favorite authors and familiar territory',
|
||||
'You balance familiar authors with occasional new discoveries',
|
||||
'You actively seek out new authors, eras, and languages'
|
||||
],
|
||||
'Organization': [
|
||||
'Your library could use more rating and status tracking',
|
||||
'You keep your library reasonably well curated',
|
||||
'You diligently rate, categorize, and track every book'
|
||||
],
|
||||
'Intensity': [
|
||||
'You lean toward shorter, lighter reads',
|
||||
'You read a mix of short and longer books',
|
||||
'You consistently tackle lengthy, immersive books'
|
||||
],
|
||||
'Methodology': [
|
||||
'You pick books spontaneously without a system',
|
||||
'You show some methodical patterns in your reading choices',
|
||||
'You systematically work through series, authors, and genres'
|
||||
],
|
||||
'Momentum': [
|
||||
'Your reading activity has been quiet recently',
|
||||
'You have a steady reading pace going',
|
||||
'You are on a strong active reading streak right now'
|
||||
]
|
||||
};
|
||||
|
||||
const levels = descriptions[habit];
|
||||
if (!levels) return '';
|
||||
|
||||
if (score < 33) return levels[0];
|
||||
if (score < 67) return levels[1];
|
||||
return levels[2];
|
||||
private getHabitDescription(habitKey: string, score: number): string {
|
||||
const level = score < 33 ? 'low' : score < 67 ? 'mid' : 'high';
|
||||
return this.t.translate(`statsUser.readingHabits.descriptions.${habitKey}.${level}`);
|
||||
}
|
||||
|
||||
private buildHabitInsights(profile: ReadingHabitsProfile): HabitInsight[] {
|
||||
const habits: { key: keyof ReadingHabitsProfile; habit: string; color: string }[] = [
|
||||
{key: 'consistency', habit: 'Consistency', color: '#9c27b0'},
|
||||
{key: 'multitasking', habit: 'Multitasking', color: '#e91e63'},
|
||||
{key: 'completionism', habit: 'Completionism', color: '#ff5722'},
|
||||
{key: 'exploration', habit: 'Exploration', color: '#ff9800'},
|
||||
{key: 'organization', habit: 'Organization', color: '#ffc107'},
|
||||
{key: 'intensity', habit: 'Intensity', color: '#4caf50'},
|
||||
{key: 'methodology', habit: 'Methodology', color: '#2196f3'},
|
||||
{key: 'momentum', habit: 'Momentum', color: '#673ab7'}
|
||||
];
|
||||
const habitColors = ['#9c27b0', '#e91e63', '#ff5722', '#ff9800', '#ffc107', '#4caf50', '#2196f3', '#673ab7'];
|
||||
|
||||
return habits.map(({key, habit, color}) => ({
|
||||
habit,
|
||||
score: profile[key],
|
||||
description: this.getHabitDescription(habit, profile[key]),
|
||||
color
|
||||
return this.habitKeys.map((key, i) => ({
|
||||
habit: this.t.translate(`statsUser.readingHabits.habits.${key}`),
|
||||
score: profile[key as keyof ReadingHabitsProfile],
|
||||
description: this.getHabitDescription(key, profile[key as keyof ReadingHabitsProfile]),
|
||||
color: habitColors[i]
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.readingHeatmap'">
|
||||
<div class="reading-heatmap-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-calendar reading-heatmap-icon"></i>
|
||||
Reading Activity Heatmap
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="A 10-year grid showing how many books were added to your library each month. Darker cells mean more books. Helps you visualize long-term acquisition trends and seasonal reading bursts."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Monthly reading activity over the past 10 years</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
@@ -21,4 +22,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</ng-container>
|
||||
|
||||
+7
-4
@@ -8,6 +8,7 @@ import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
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 MatrixDataPoint {
|
||||
x: number; // month (0-11)
|
||||
@@ -28,12 +29,13 @@ type HeatmapChartData = ChartData<'matrix', MatrixDataPoint[], string>;
|
||||
@Component({
|
||||
selector: 'app-reading-heatmap-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './reading-heatmap-chart.component.html',
|
||||
styleUrls: ['./reading-heatmap-chart.component.scss']
|
||||
})
|
||||
export class ReadingHeatmapChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'matrix' as const;
|
||||
@@ -72,7 +74,8 @@ export class ReadingHeatmapChartComponent implements OnInit, OnDestroy {
|
||||
},
|
||||
label: (context) => {
|
||||
const point = context.raw as MatrixDataPoint;
|
||||
return `${point.v} book${point.v === 1 ? '' : 's'} read`;
|
||||
const key = point.v === 1 ? 'statsUser.readingHeatmap.tooltipBook' : 'statsUser.readingHeatmap.tooltipBooks';
|
||||
return this.t.translate(key, {value: point.v});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -122,7 +125,7 @@ export class ReadingHeatmapChartComponent implements OnInit, OnDestroy {
|
||||
private readonly chartDataSubject = new BehaviorSubject<HeatmapChartData>({
|
||||
labels: [],
|
||||
datasets: [{
|
||||
label: 'Books Read',
|
||||
label: this.t.translate('statsUser.readingHeatmap.booksRead'),
|
||||
data: []
|
||||
}]
|
||||
});
|
||||
@@ -178,7 +181,7 @@ export class ReadingHeatmapChartComponent implements OnInit, OnDestroy {
|
||||
this.chartDataSubject.next({
|
||||
labels: [],
|
||||
datasets: [{
|
||||
label: 'Books Read',
|
||||
label: this.t.translate('statsUser.readingHeatmap.booksRead'),
|
||||
data: heatmapData,
|
||||
backgroundColor: (context) => {
|
||||
const point = context.raw as MatrixDataPoint;
|
||||
|
||||
+5
-3
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.readingProgress'">
|
||||
<div class="reading-progress-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-chart-bar reading-progress-icon"></i>
|
||||
Reading Progress Distribution
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Shows how many books fall into each progress bracket: not started (0%), just started (1-25%), halfway (26-50%), mostly done (51-75%), nearly finished (76-99%), and completed (100%). Progress is based on the furthest point reached across all reading sessions."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Books by reading completion status</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
@@ -21,3 +22,4 @@
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+13
-5
@@ -8,6 +8,7 @@ import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
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 ReadingProgressStats {
|
||||
progressRange: string;
|
||||
@@ -45,12 +46,13 @@ type ProgressChartData = ChartData<'doughnut', number[], string>;
|
||||
@Component({
|
||||
selector: 'app-reading-progress-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './reading-progress-chart.component.html',
|
||||
styleUrls: ['./reading-progress-chart.component.scss']
|
||||
})
|
||||
export class ReadingProgressChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'doughnut' as const;
|
||||
@@ -118,8 +120,14 @@ export class ReadingProgressChartComponent implements OnInit, OnDestroy {
|
||||
const percentage = ((value / total) * 100).toFixed(1);
|
||||
const label = context.label;
|
||||
const rangeInfo = PROGRESS_RANGES.find(r => r.range === label);
|
||||
const description = rangeInfo ? ` (${rangeInfo.desc})` : '';
|
||||
return `${value} book${value === 1 ? '' : 's'}${description} - ${percentage}%`;
|
||||
const descKeys: Record<string, string> = {
|
||||
'Not Started': 'notStarted', 'Just Started': 'justStarted',
|
||||
'Getting Into It': 'gettingIntoIt', 'Halfway Through': 'halfwayThrough',
|
||||
'Almost Finished': 'almostFinished', 'Completed': 'completed'
|
||||
};
|
||||
const description = rangeInfo ? this.t.translate(`statsUser.readingProgress.${descKeys[rangeInfo.desc] || 'notStarted'}`) : '';
|
||||
const plural = value === 1 ? '' : 's';
|
||||
return this.t.translate('statsUser.readingProgress.tooltipLabel', {value, plural, description, percentage});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -134,7 +142,7 @@ export class ReadingProgressChartComponent implements OnInit, OnDestroy {
|
||||
private readonly chartDataSubject = new BehaviorSubject<ProgressChartData>({
|
||||
labels: [],
|
||||
datasets: [{
|
||||
label: 'Books by Progress',
|
||||
label: this.t.translate('statsUser.readingProgress.booksByProgress'),
|
||||
data: [],
|
||||
backgroundColor: [...CHART_COLORS],
|
||||
...CHART_DEFAULTS
|
||||
@@ -173,7 +181,7 @@ export class ReadingProgressChartComponent implements OnInit, OnDestroy {
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
datasets: [{
|
||||
label: 'Books by Progress',
|
||||
label: this.t.translate('statsUser.readingProgress.booksByProgress'),
|
||||
data: dataValues,
|
||||
backgroundColor: [...CHART_COLORS],
|
||||
borderColor: '#ffffff',
|
||||
|
||||
+11
-9
@@ -1,29 +1,30 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.sessionHeatmap'">
|
||||
<div class="reading-session-heatmap-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-calendar heatmap-title-icon"></i>
|
||||
Reading Session Activity
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="A daily heatmap of your reading sessions for the selected year. Darker cells mean more sessions that day. Streak stats track consecutive reading days across all time. Milestones unlock as you hit streak or total-day thresholds."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Daily overview of your reading sessions across the year</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
<div class="year-selector">
|
||||
<button type="button"
|
||||
class="year-nav-btn"
|
||||
(click)="changeYear(-1)"
|
||||
title="Previous year">
|
||||
[title]="t('previousYear')">
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<span class="current-year">{{ currentYear }}</span>
|
||||
<button type="button"
|
||||
class="year-nav-btn"
|
||||
(click)="changeYear(1)"
|
||||
title="Next year">
|
||||
[title]="t('nextYear')">
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
@@ -42,16 +43,16 @@
|
||||
<div class="chart-footer">
|
||||
<div class="footer-pills left">
|
||||
<span class="pill current">
|
||||
<span class="pill-value">{{ currentStreak }}</span> Current Streak
|
||||
<span class="pill-value">{{ currentStreak }}</span> {{ t('currentStreak') }}
|
||||
</span>
|
||||
<span class="pill longest">
|
||||
<span class="pill-value">{{ longestStreak }}</span> Longest Streak
|
||||
<span class="pill-value">{{ longestStreak }}</span> {{ t('longestStreak') }}
|
||||
</span>
|
||||
<span class="pill total">
|
||||
<span class="pill-value">{{ totalReadingDays }}</span> Total Days
|
||||
<span class="pill-value">{{ totalReadingDays }}</span> {{ t('totalDays') }}
|
||||
</span>
|
||||
<span class="pill consistency">
|
||||
<span class="pill-value">{{ consistencyPercent }}%</span> Consistency
|
||||
<span class="pill-value">{{ consistencyPercent }}%</span> {{ t('consistency') }}
|
||||
</span>
|
||||
</div>
|
||||
@if (milestones.length > 0) {
|
||||
@@ -66,3 +67,4 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+11
-7
@@ -7,6 +7,7 @@ import {MatrixController, MatrixElement} from 'chartjs-chart-matrix';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {ReadingSessionHeatmapResponse, UserStatsService} from '../../../../../settings/user-management/user-stats.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
const DAY_NAMES = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
const MONTH_NAMES = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
@@ -31,7 +32,7 @@ type SessionHeatmapChartData = ChartData<'matrix', MatrixDataPoint[], string>;
|
||||
@Component({
|
||||
selector: 'app-reading-session-heatmap',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './reading-session-heatmap.component.html',
|
||||
styleUrls: ['./reading-session-heatmap.component.scss']
|
||||
})
|
||||
@@ -51,6 +52,7 @@ export class ReadingSessionHeatmapComponent implements OnInit, OnDestroy {
|
||||
public hasStreakData = false;
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly translocoService = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<SessionHeatmapChartData>;
|
||||
private maxSessionCount = 1;
|
||||
@@ -95,7 +97,9 @@ export class ReadingSessionHeatmapComponent implements OnInit, OnDestroy {
|
||||
},
|
||||
label: (context) => {
|
||||
const point = context.raw as MatrixDataPoint;
|
||||
return `${point.v} reading session${point.v === 1 ? '' : 's'}`;
|
||||
return point.v === 1
|
||||
? this.translocoService.translate('statsUser.sessionHeatmap.readingSession', {count: point.v})
|
||||
: this.translocoService.translate('statsUser.sessionHeatmap.readingSessions_plural', {count: point.v});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -312,11 +316,11 @@ export class ReadingSessionHeatmapComponent implements OnInit, OnDestroy {
|
||||
|
||||
// Milestones
|
||||
this.milestones = [
|
||||
{label: '7-Day Streak', icon: '\uD83D\uDD25', requirement: 7, type: 'streak', unlocked: this.longestStreak >= 7},
|
||||
{label: '30-Day Streak', icon: '\u26A1', requirement: 30, type: 'streak', unlocked: this.longestStreak >= 30},
|
||||
{label: '100 Reading Days', icon: '\uD83D\uDCDA', requirement: 100, type: 'total', unlocked: this.totalReadingDays >= 100},
|
||||
{label: '365 Reading Days', icon: '\uD83C\uDFC6', requirement: 365, type: 'total', unlocked: this.totalReadingDays >= 365},
|
||||
{label: 'Year of Reading', icon: '\uD83D\uDC51', requirement: 365, type: 'streak', unlocked: this.longestStreak >= 365},
|
||||
{label: this.translocoService.translate('statsUser.sessionHeatmap.milestone7DayStreak'), icon: '\uD83D\uDD25', requirement: 7, type: 'streak', unlocked: this.longestStreak >= 7},
|
||||
{label: this.translocoService.translate('statsUser.sessionHeatmap.milestone30DayStreak'), icon: '\u26A1', requirement: 30, type: 'streak', unlocked: this.longestStreak >= 30},
|
||||
{label: this.translocoService.translate('statsUser.sessionHeatmap.milestone100ReadingDays'), icon: '\uD83D\uDCDA', requirement: 100, type: 'total', unlocked: this.totalReadingDays >= 100},
|
||||
{label: this.translocoService.translate('statsUser.sessionHeatmap.milestone365ReadingDays'), icon: '\uD83C\uDFC6', requirement: 365, type: 'total', unlocked: this.totalReadingDays >= 365},
|
||||
{label: this.translocoService.translate('statsUser.sessionHeatmap.milestoneYearOfReading'), icon: '\uD83D\uDC51', requirement: 365, type: 'streak', unlocked: this.longestStreak >= 365},
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
+10
-8
@@ -1,32 +1,33 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.sessionTimeline'">
|
||||
<div class="timeline-container">
|
||||
<div class="timeline-header">
|
||||
<div class="header-title">
|
||||
<h3>
|
||||
<i class="pi pi-clock timeline-title-icon"></i>
|
||||
Reading Session Timeline
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Shows your reading sessions laid out across each day of the week. Each block represents a session, sized by duration. Hover to see book title, pages read, and time spent. Use the week navigator to browse your reading history week by week."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="timeline-subtitle">Weekly overview of your reading sessions and patterns</p>
|
||||
<p class="timeline-subtitle">{{ t('description') }}</p>
|
||||
</div>
|
||||
<div class="week-info">
|
||||
<button type="button"
|
||||
class="week-nav-btn"
|
||||
(click)="changeWeek(-1)"
|
||||
title="Previous week">
|
||||
[title]="t('previousWeek')">
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<div class="week-display">
|
||||
<span class="week-label">Week {{ currentWeek }}</span>
|
||||
<span class="week-label">{{ t('week', { number: currentWeek }) }}</span>
|
||||
<span class="week-dates">{{ getWeekDateRange() }}</span>
|
||||
</div>
|
||||
<button type="button"
|
||||
class="week-nav-btn"
|
||||
(click)="changeWeek(1)"
|
||||
title="Next week">
|
||||
[title]="t('nextWeek')">
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
@@ -37,7 +38,7 @@
|
||||
(onChange)="onYearChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Year"
|
||||
[placeholder]="t('selectYear')"
|
||||
[style]="{'min-width': '120px'}">
|
||||
</p-select>
|
||||
<p-select
|
||||
@@ -46,7 +47,7 @@
|
||||
(onChange)="onWeekChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Week"
|
||||
[placeholder]="t('selectWeek')"
|
||||
[style]="{'min-width': '120px'}">
|
||||
</p-select>
|
||||
</div>
|
||||
@@ -107,3 +108,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+9
-7
@@ -18,6 +18,7 @@ import {
|
||||
import {BookType} from '../../../../../book/model/book.model';
|
||||
import {ReadingSessionTimelineResponse, UserStatsService} from '../../../../../settings/user-management/user-stats.service';
|
||||
import {UrlHelperService} from '../../../../../../shared/service/url-helper.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface ReadingSession {
|
||||
startTime: Date;
|
||||
@@ -52,7 +53,7 @@ interface DayTimeline {
|
||||
@Component({
|
||||
selector: 'app-reading-session-timeline',
|
||||
standalone: true,
|
||||
imports: [CommonModule, Select, FormsModule, Tooltip],
|
||||
imports: [CommonModule, Select, FormsModule, Tooltip, TranslocoDirective],
|
||||
templateUrl: './reading-session-timeline.component.html',
|
||||
styleUrls: ['./reading-session-timeline.component.scss']
|
||||
})
|
||||
@@ -62,6 +63,7 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
|
||||
private userStatsService = inject(UserStatsService);
|
||||
private urlHelperService = inject(UrlHelperService);
|
||||
private translocoService = inject(TranslocoService);
|
||||
|
||||
public daysOfWeek = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
public hourLabels: string[] = [];
|
||||
@@ -96,7 +98,7 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
const weeksInYear = getISOWeeksInYear(this.currentDate);
|
||||
this.weekOptions = [];
|
||||
for (let week = 1; week <= weeksInYear; week++) {
|
||||
this.weekOptions.push({label: `Week ${week}`, value: week});
|
||||
this.weekOptions.push({label: this.translocoService.translate('statsUser.sessionTimeline.week', {number: week}), value: week});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,26 +384,26 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
<div class="session-tooltip-details">
|
||||
<div class="session-tooltip-header">
|
||||
<i class="pi pi-book"></i>
|
||||
<span class="session-tooltip-title">${session.bookTitle || 'Reading Session'}</span>
|
||||
<span class="session-tooltip-title">${session.bookTitle || this.translocoService.translate('statsUser.sessionTimeline.readingSession')}</span>
|
||||
</div>
|
||||
<div class="session-tooltip-divider"></div>
|
||||
<div class="session-tooltip-body">
|
||||
<div class="session-tooltip-row">
|
||||
<i class="pi pi-clock"></i>
|
||||
<span class="session-tooltip-label">Time:</span>
|
||||
<span class="session-tooltip-label">${this.translocoService.translate('statsUser.sessionTimeline.tooltipTime')}</span>
|
||||
<span class="session-tooltip-value">
|
||||
${this.formatTime(session.startHour, session.startMinute)} - ${this.formatTime(session.endHour, session.endMinute)}
|
||||
</span>
|
||||
</div>
|
||||
<div class="session-tooltip-row">
|
||||
<i class="pi pi-hourglass"></i>
|
||||
<span class="session-tooltip-label">Duration:</span>
|
||||
<span class="session-tooltip-label">${this.translocoService.translate('statsUser.sessionTimeline.tooltipDuration')}</span>
|
||||
<span class="session-tooltip-value">${this.formatDuration(session.duration)}</span>
|
||||
</div>
|
||||
<div class="session-tooltip-row">
|
||||
<i class="pi pi-file"></i>
|
||||
<span class="session-tooltip-label">Format:</span>
|
||||
<span class="session-tooltip-value">${session.bookType || 'Unknown'}</span>
|
||||
<span class="session-tooltip-label">${this.translocoService.translate('statsUser.sessionTimeline.tooltipFormat')}</span>
|
||||
<span class="session-tooltip-value">${session.bookType || this.translocoService.translate('statsUser.sessionTimeline.unknown')}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+11
-9
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.readingSurvival'">
|
||||
<div class="reading-survival-container">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-chart-line reading-survival-icon"></i>
|
||||
Reading Survival Curve
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Inspired by survival analysis: starting from all books you've begun reading, this curve shows what fraction made it to each progress milestone. A steep drop at a threshold reveals where you tend to abandon books. The 'danger zone' highlights the steepest single drop-off point."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Of books started, what percentage reached each progress threshold</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -18,20 +19,20 @@
|
||||
<div class="stats-row">
|
||||
<div class="stat-card">
|
||||
<span class="stat-value">{{ totalStarted }}</span>
|
||||
<span class="stat-label">Started</span>
|
||||
<span class="stat-label">{{ t('started') }}</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-value">{{ completionRate }}%</span>
|
||||
<span class="stat-label">Completion Rate</span>
|
||||
<span class="stat-label">{{ t('completionRate') }}</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span class="stat-value">{{ medianDropout }}</span>
|
||||
<span class="stat-label">Median Dropout</span>
|
||||
<span class="stat-label">{{ t('medianDropout') }}</span>
|
||||
</div>
|
||||
<div class="stat-card danger">
|
||||
<span class="stat-value">{{ dangerZoneRange }}</span>
|
||||
<span class="stat-subtitle">{{ dangerZoneDrop }}</span>
|
||||
<span class="stat-label">Danger Zone</span>
|
||||
<span class="stat-label">{{ t('dangerZone') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -47,8 +48,9 @@
|
||||
@if (totalStarted === 0) {
|
||||
<div class="no-data-message">
|
||||
<i class="pi pi-info-circle"></i>
|
||||
<p>No books with reading progress found.</p>
|
||||
<small>Start reading some books to see your survival curve.</small>
|
||||
<p>{{ t('noData') }}</p>
|
||||
<small>{{ t('noDataHint') }}</small>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+8
-6
@@ -8,6 +8,7 @@ import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
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';
|
||||
|
||||
type SurvivalChartData = ChartData<'line', number[], string>;
|
||||
|
||||
@@ -16,12 +17,13 @@ const THRESHOLDS = [0, 10, 25, 50, 75, 90, 100];
|
||||
@Component({
|
||||
selector: 'app-reading-survival-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
templateUrl: './reading-survival-chart.component.html',
|
||||
styleUrls: ['./reading-survival-chart.component.scss']
|
||||
})
|
||||
export class ReadingSurvivalChartComponent implements OnInit, OnDestroy {
|
||||
private readonly bookService = inject(BookService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'line' as const;
|
||||
@@ -51,8 +53,8 @@ export class ReadingSurvivalChartComponent implements OnInit, OnDestroy {
|
||||
titleFont: {size: 13, weight: 'bold'},
|
||||
bodyFont: {size: 12},
|
||||
callbacks: {
|
||||
title: (context) => `${context[0].label} progress`,
|
||||
label: (context) => `${(context.parsed.y ?? 0).toFixed(1)}% of books reached this point`
|
||||
title: (context) => this.t.translate('statsUser.readingSurvival.tooltipProgress', {label: context[0].label}),
|
||||
label: (context) => this.t.translate('statsUser.readingSurvival.tooltipSurvival', {value: (context.parsed.y ?? 0).toFixed(1)})
|
||||
}
|
||||
},
|
||||
datalabels: {display: false}
|
||||
@@ -61,7 +63,7 @@ export class ReadingSurvivalChartComponent implements OnInit, OnDestroy {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Progress Threshold',
|
||||
text: this.t.translate('statsUser.readingSurvival.axisProgressThreshold'),
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 12, weight: 'bold'}
|
||||
},
|
||||
@@ -77,7 +79,7 @@ export class ReadingSurvivalChartComponent implements OnInit, OnDestroy {
|
||||
max: 100,
|
||||
title: {
|
||||
display: true,
|
||||
text: '% of Books Surviving',
|
||||
text: this.t.translate('statsUser.readingSurvival.axisBooksSurviving'),
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 12, weight: 'bold'}
|
||||
},
|
||||
@@ -164,7 +166,7 @@ export class ReadingSurvivalChartComponent implements OnInit, OnDestroy {
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
datasets: [{
|
||||
label: 'Survival Rate',
|
||||
label: this.t.translate('statsUser.readingSurvival.survivalRate'),
|
||||
data: survivalValues,
|
||||
borderColor: '#e91e63',
|
||||
backgroundColor: 'rgba(233, 30, 99, 0.15)',
|
||||
|
||||
+26
-24
@@ -1,16 +1,17 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser.seriesProgress'">
|
||||
<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
|
||||
{{ t('title') }}
|
||||
<i class="pi pi-question-circle chart-info-icon"
|
||||
pTooltip="Shows each book series in your library as a stacked bar: read, reading, and unread volumes. Series are sorted by completion percentage. Use this to spot which series you've fallen behind on or are close to finishing."
|
||||
[pTooltip]="t('tooltip')"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="chart-info-tooltip"
|
||||
[appendTo]="'body'"></i>
|
||||
</h3>
|
||||
<p class="chart-description">Track your reading progress across book series</p>
|
||||
<p class="chart-description">{{ t('description') }}</p>
|
||||
</div>
|
||||
@if (stats) {
|
||||
<div class="series-summary">
|
||||
@@ -34,16 +35,16 @@
|
||||
<div class="stats-row">
|
||||
<div class="stat-pill">
|
||||
<span class="pill-value">{{ stats.totalSeries }}</span>
|
||||
<span class="pill-label">Series</span>
|
||||
<span class="pill-label">{{ t('series') }}</span>
|
||||
</div>
|
||||
<div class="stat-pill">
|
||||
<span class="pill-value">{{ stats.avgSeriesCompletion }}%</span>
|
||||
<span class="pill-label">Avg. Completion</span>
|
||||
<span class="pill-label">{{ t('avgCompletion') }}</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>
|
||||
<span class="pill-label">{{ t('topRated') }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -60,8 +61,8 @@
|
||||
@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>
|
||||
<h4>{{ t('seriesBreakdown') }}</h4>
|
||||
<span class="series-count">{{ t('ofTotal', { filtered: filteredSeriesList.length, total: seriesList.length }) }}</span>
|
||||
</div>
|
||||
|
||||
<div class="controls-row">
|
||||
@@ -69,7 +70,7 @@
|
||||
<i class="pi pi-search"></i>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search series..."
|
||||
[placeholder]="t('searchSeries')"
|
||||
[value]="searchTerm"
|
||||
(input)="onSearchChange($any($event.target).value)"
|
||||
/>
|
||||
@@ -77,17 +78,17 @@
|
||||
|
||||
<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>
|
||||
<option value="all">{{ t('allStatus') }}</option>
|
||||
<option value="in-progress">{{ t('inProgress') }}</option>
|
||||
<option value="completed">{{ t('completed') }}</option>
|
||||
<option value="not-started">{{ t('notStarted') }}</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>
|
||||
<option value="progress">{{ t('sortByProgress') }}</option>
|
||||
<option value="rating">{{ t('sortByRating') }}</option>
|
||||
<option value="books">{{ t('sortByBooks') }}</option>
|
||||
<option value="name">{{ t('sortByName') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -103,9 +104,9 @@
|
||||
<span class="series-name">{{ series.name }}</span>
|
||||
<div class="series-meta">
|
||||
<span class="books-count">
|
||||
{{ series.booksRead }}/{{ series.booksOwned }} read
|
||||
{{ t('booksRead', { read: series.booksRead, owned: series.booksOwned }) }}
|
||||
@if (series.totalInSeries) {
|
||||
<span class="total-hint">({{ series.totalInSeries }} in series)</span>
|
||||
<span class="total-hint">{{ t('inSeriesHint', { total: series.totalInSeries }) }}</span>
|
||||
}
|
||||
</span>
|
||||
@if (series.avgPersonalRating) {
|
||||
@@ -131,7 +132,7 @@
|
||||
</div>
|
||||
@if (series.nextUnread && series.status !== 'completed') {
|
||||
<div class="next-up">
|
||||
<span class="next-label">Next:</span>
|
||||
<span class="next-label">{{ t('next') }}</span>
|
||||
<span class="next-title">{{ series.nextUnread }}</span>
|
||||
</div>
|
||||
}
|
||||
@@ -141,7 +142,7 @@
|
||||
@if (filteredSeriesList.length === 0 && searchTerm) {
|
||||
<div class="no-results">
|
||||
<i class="pi pi-search"></i>
|
||||
<span>No series matching "{{ searchTerm }}"</span>
|
||||
<span>{{ t('noMatchingSearch', { term: searchTerm }) }}</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -155,7 +156,7 @@
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<span class="page-info">
|
||||
Page {{ currentPage + 1 }} of {{ getTotalPages() }}
|
||||
{{ t('pageInfo', { current: currentPage + 1, total: getTotalPages() }) }}
|
||||
</span>
|
||||
<button
|
||||
class="page-btn"
|
||||
@@ -171,8 +172,9 @@
|
||||
@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>
|
||||
<p>{{ t('noData') }}</p>
|
||||
<small>{{ t('noDataHint') }}</small>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+14
-12
@@ -9,6 +9,7 @@ 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 {LibraryFilterService} from '../../../library-stats/service/library-filter.service';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface SeriesInfo {
|
||||
name: string;
|
||||
@@ -43,13 +44,14 @@ type SeriesChartData = ChartData<'bar', number[], string>;
|
||||
@Component({
|
||||
selector: 'app-series-progress-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip],
|
||||
imports: [CommonModule, BaseChartDirective, Tooltip, TranslocoDirective],
|
||||
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 t = inject(TranslocoService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'bar' as const;
|
||||
@@ -80,7 +82,7 @@ export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
max: 100,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Completion %',
|
||||
text: this.t.translate('statsUser.seriesProgress.axisCompletion'),
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
@@ -149,13 +151,13 @@ export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
const series = this.chartSeries[context[0].dataIndex];
|
||||
if (!series) return [];
|
||||
const lines = [
|
||||
`Read: ${series.booksRead}/${series.booksOwned} owned`
|
||||
this.t.translate('statsUser.seriesProgress.tooltipRead', {read: series.booksRead, owned: series.booksOwned})
|
||||
];
|
||||
if (series.totalInSeries) {
|
||||
lines.push(`Series total: ${series.totalInSeries} books`);
|
||||
lines.push(this.t.translate('statsUser.seriesProgress.tooltipSeriesTotal', {total: series.totalInSeries}));
|
||||
}
|
||||
if (series.avgPersonalRating) {
|
||||
lines.push(`Your rating: ${series.avgPersonalRating.toFixed(1)}/10`);
|
||||
lines.push(this.t.translate('statsUser.seriesProgress.tooltipYourRating', {rating: series.avgPersonalRating.toFixed(1)}));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
@@ -563,7 +565,7 @@ export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Read',
|
||||
label: this.t.translate('statsUser.seriesProgress.read'),
|
||||
data: readPercentages,
|
||||
backgroundColor: 'rgba(76, 175, 80, 0.85)',
|
||||
borderColor: '#4caf50',
|
||||
@@ -571,7 +573,7 @@ export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
borderRadius: 2
|
||||
},
|
||||
{
|
||||
label: 'Reading',
|
||||
label: this.t.translate('statsUser.seriesProgress.reading'),
|
||||
data: readingPercentages,
|
||||
backgroundColor: 'rgba(255, 193, 7, 0.85)',
|
||||
borderColor: '#ffc107',
|
||||
@@ -579,7 +581,7 @@ export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
borderRadius: 2
|
||||
},
|
||||
{
|
||||
label: 'Partially Read',
|
||||
label: this.t.translate('statsUser.seriesProgress.partiallyRead'),
|
||||
data: partiallyReadPercentages,
|
||||
backgroundColor: 'rgba(255, 152, 0, 0.85)',
|
||||
borderColor: '#ff9800',
|
||||
@@ -587,7 +589,7 @@ export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
borderRadius: 2
|
||||
},
|
||||
{
|
||||
label: 'Paused',
|
||||
label: this.t.translate('statsUser.seriesProgress.paused'),
|
||||
data: pausedPercentages,
|
||||
backgroundColor: 'rgba(33, 150, 243, 0.85)',
|
||||
borderColor: '#2196f3',
|
||||
@@ -595,7 +597,7 @@ export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
borderRadius: 2
|
||||
},
|
||||
{
|
||||
label: 'Abandoned',
|
||||
label: this.t.translate('statsUser.seriesProgress.abandoned'),
|
||||
data: abandonedPercentages,
|
||||
backgroundColor: 'rgba(239, 83, 80, 0.85)',
|
||||
borderColor: '#ef5350',
|
||||
@@ -603,7 +605,7 @@ export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
borderRadius: 2
|
||||
},
|
||||
{
|
||||
label: 'Won\'t Read',
|
||||
label: this.t.translate('statsUser.seriesProgress.wontRead'),
|
||||
data: wontReadPercentages,
|
||||
backgroundColor: 'rgba(158, 158, 158, 0.6)',
|
||||
borderColor: '#9e9e9e',
|
||||
@@ -611,7 +613,7 @@ export class SeriesProgressChartComponent implements OnInit, OnDestroy {
|
||||
borderRadius: 2
|
||||
},
|
||||
{
|
||||
label: 'Unread',
|
||||
label: this.t.translate('statsUser.seriesProgress.unread'),
|
||||
data: unreadPercentages,
|
||||
backgroundColor: 'rgba(158, 158, 158, 0.3)',
|
||||
borderColor: '#9e9e9e',
|
||||
|
||||
+42
-1
@@ -1,5 +1,6 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
import {ReadingSessionHeatmapComponent} from '../charts/reading-session-heatmap/reading-session-heatmap.component';
|
||||
import {FavoriteDaysChartComponent} from '../charts/favorite-days-chart/favorite-days-chart.component';
|
||||
import {PeakHoursChartComponent} from '../charts/peak-hours-chart/peak-hours-chart.component';
|
||||
@@ -34,6 +35,29 @@ export interface UserChartConfig {
|
||||
})
|
||||
export class UserChartConfigService {
|
||||
private readonly STORAGE_KEY = 'userStatsChartConfig';
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
private readonly chartNameKeyMap: Record<string, string> = {
|
||||
'heatmap': 'statsUser.chartNames.heatmap',
|
||||
'favorite-days': 'statsUser.chartNames.favoriteDays',
|
||||
'peak-hours': 'statsUser.chartNames.peakHours',
|
||||
'timeline': 'statsUser.chartNames.timeline',
|
||||
'reading-heatmap': 'statsUser.chartNames.readingHeatmap',
|
||||
'personal-rating': 'statsUser.chartNames.personalRating',
|
||||
'reading-progress': 'statsUser.chartNames.readingProgress',
|
||||
'read-status': 'statsUser.chartNames.readStatus',
|
||||
'genre-stats': 'statsUser.chartNames.genreStats',
|
||||
'completion-timeline': 'statsUser.chartNames.completionTimeline',
|
||||
'reading-clock': 'statsUser.chartNames.readingClock',
|
||||
'page-turner': 'statsUser.chartNames.pageTurner',
|
||||
'completion-race': 'statsUser.chartNames.completionRace',
|
||||
'reading-survival': 'statsUser.chartNames.readingSurvival',
|
||||
'book-length': 'statsUser.chartNames.bookLength',
|
||||
'rating-taste': 'statsUser.chartNames.ratingTaste',
|
||||
'series-progress': 'statsUser.chartNames.seriesProgress',
|
||||
'reading-dna': 'statsUser.chartNames.readingDna',
|
||||
'reading-habits': 'statsUser.chartNames.readingHabits',
|
||||
};
|
||||
|
||||
private readonly defaultCharts: UserChartConfig[] = [
|
||||
{id: 'heatmap', title: 'Reading Session Heatmap', component: ReadingSessionHeatmapComponent, enabled: true, sizeClass: 'chart-full', order: 0},
|
||||
@@ -60,6 +84,23 @@ export class UserChartConfigService {
|
||||
private chartsSubject = new BehaviorSubject<UserChartConfig[]>(this.loadChartConfig());
|
||||
public charts$: Observable<UserChartConfig[]> = this.chartsSubject.asObservable();
|
||||
|
||||
constructor() {
|
||||
this.t.langChanges$.subscribe(() => {
|
||||
const charts = this.chartsSubject.value;
|
||||
this.translateChartTitles(charts);
|
||||
this.chartsSubject.next([...charts]);
|
||||
});
|
||||
}
|
||||
|
||||
private translateChartTitles(charts: UserChartConfig[]): void {
|
||||
charts.forEach(chart => {
|
||||
const key = this.chartNameKeyMap[chart.id];
|
||||
if (key) {
|
||||
chart.title = this.t.translate(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getVisibleCharts(): UserChartConfig[] {
|
||||
return this.chartsSubject.value.filter(chart => chart.enabled);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<ng-container *transloco="let t; prefix: 'statsUser'">
|
||||
<div class="user-stats-container">
|
||||
<div class="header-section">
|
||||
<div class="header-content">
|
||||
<div class="greeting">
|
||||
<i class="pi pi-chart-line"></i>
|
||||
<h2>{{ userName }}'s Reading Statistics</h2>
|
||||
<h2>{{ t('main.title', { name: userName }) }}</h2>
|
||||
</div>
|
||||
<button class="config-toggle-btn" (click)="toggleConfigPanel()">
|
||||
<i class="pi pi-cog"></i>
|
||||
<span>Customize Layout</span>
|
||||
<span>{{ t('main.customizeLayout') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -19,7 +20,7 @@
|
||||
[resizable]="false"
|
||||
[style]="{width: '600px', maxWidth: '90vw'}"
|
||||
class="config-dialog"
|
||||
header="Chart Configuration">
|
||||
[header]="t('main.chartConfig')">
|
||||
|
||||
<div class="config-dialog-content">
|
||||
<div class="config-list" cdkDropList (cdkDropListDropped)="drop($event)">
|
||||
@@ -43,18 +44,18 @@
|
||||
<ng-template pTemplate="footer">
|
||||
<p-button class="reset-btn" (click)="resetLayout()" severity="danger">
|
||||
<i class="pi pi-refresh"></i>
|
||||
<span>Reset Layout</span>
|
||||
<span>{{ t('main.resetLayout') }}</span>
|
||||
</p-button>
|
||||
<p-button class="hide-all-btn" (click)="hideAllCharts()" severity="secondary">
|
||||
<i class="pi pi-eye-slash"></i>
|
||||
<span>Hide All</span>
|
||||
<span>{{ t('main.hideAll') }}</span>
|
||||
</p-button>
|
||||
<p-button class="show-all-btn" (click)="showAllCharts()" severity="secondary">
|
||||
<i class="pi pi-eye"></i>
|
||||
<span>Show All</span>
|
||||
<span>{{ t('main.showAll') }}</span>
|
||||
</p-button>
|
||||
<p-button class="close-btn" (click)="toggleConfigPanel()" severity="secondary">
|
||||
<span>Close</span>
|
||||
<span>{{ t('main.close') }}</span>
|
||||
</p-button>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
@@ -130,3 +131,4 @@
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
@@ -6,6 +6,7 @@ import {DialogModule} from 'primeng/dialog';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
import {PeakHoursChartComponent} from './charts/peak-hours-chart/peak-hours-chart.component';
|
||||
import {FavoriteDaysChartComponent} from './charts/favorite-days-chart/favorite-days-chart.component';
|
||||
import {ReadingDNAChartComponent} from './charts/reading-dna-chart/reading-dna-chart.component';
|
||||
@@ -53,7 +54,8 @@ import {UserChartConfig, UserChartConfigService} from './service/user-chart-conf
|
||||
CompletionRaceChartComponent,
|
||||
ReadingSurvivalChartComponent,
|
||||
ReadingClockChartComponent,
|
||||
BookLengthChartComponent
|
||||
BookLengthChartComponent,
|
||||
TranslocoDirective
|
||||
],
|
||||
templateUrl: './user-stats.component.html',
|
||||
styleUrls: ['./user-stats.component.scss']
|
||||
|
||||
Reference in New Issue
Block a user