Add more user-specific charts (#1991)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
<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
|
||||
</h3>
|
||||
<p class="chart-description">Monthly book completion statistics</p>
|
||||
</div>
|
||||
<div class="year-selector">
|
||||
<button type="button"
|
||||
class="year-nav-btn"
|
||||
(click)="changeYear(-1)"
|
||||
title="Previous year">
|
||||
<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">
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
.completion-timeline-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
gap: 1rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.year-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.year-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 0.6rem 0.6rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-color: rgba(255, 255, 255, 0.3);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.current-year {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
min-width: 4.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.completion-title-icon {
|
||||
font-size: 1.5rem;
|
||||
color: rgba(251, 191, 36, 1);
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
position: relative;
|
||||
height: 350px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
|
||||
.year-selector {
|
||||
justify-content: center;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.year-selector {
|
||||
.current-year {
|
||||
font-size: 1rem;
|
||||
min-width: 4rem;
|
||||
}
|
||||
|
||||
.year-nav-btn {
|
||||
padding: 0.6rem 0.6rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
import {Component, inject, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {BaseChartDirective} from 'ng2-charts';
|
||||
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';
|
||||
|
||||
type CompletionChartData = ChartData<'bar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-completion-timeline-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective],
|
||||
templateUrl: './completion-timeline-chart.component.html',
|
||||
styleUrls: ['./completion-timeline-chart.component.scss']
|
||||
})
|
||||
export class CompletionTimelineChartComponent implements OnInit, OnDestroy {
|
||||
@Input() initialYear: number = new Date().getFullYear();
|
||||
|
||||
public currentYear: number = new Date().getFullYear();
|
||||
public readonly chartType = 'bar' as const;
|
||||
public readonly chartData$: Observable<CompletionChartData>;
|
||||
public readonly chartOptions: ChartConfiguration['options'];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<CompletionChartData>;
|
||||
|
||||
private readonly monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
constructor() {
|
||||
this.chartDataSubject = new BehaviorSubject<CompletionChartData>({
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
this.chartData$ = this.chartDataSubject.asObservable();
|
||||
|
||||
this.chartOptions = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
layout: {
|
||||
padding: {top: 10, bottom: 10, left: 10, right: 10}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'top',
|
||||
labels: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
boxWidth: 12,
|
||||
padding: 10
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#ffffff',
|
||||
borderWidth: 1,
|
||||
cornerRadius: 6,
|
||||
displayColors: true,
|
||||
padding: 12,
|
||||
titleFont: {size: 14, weight: 'bold'},
|
||||
bodyFont: {size: 13},
|
||||
callbacks: {
|
||||
label: (context) => {
|
||||
const label = context.dataset.label || '';
|
||||
const value = context.parsed.y;
|
||||
return `${label}: ${value} book${value !== 1 ? 's' : ''}`;
|
||||
}
|
||||
}
|
||||
},
|
||||
datalabels: {display: false}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Month',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 13,
|
||||
weight: 'bold'
|
||||
}
|
||||
},
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11}
|
||||
},
|
||||
grid: {display: false},
|
||||
border: {display: false}
|
||||
},
|
||||
y: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Number of Books',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 13,
|
||||
weight: 'bold'
|
||||
}
|
||||
},
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
stepSize: 1
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
},
|
||||
border: {display: false}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.currentYear = this.initialYear;
|
||||
this.loadCompletionTimeline(this.currentYear);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
public changeYear(delta: number): void {
|
||||
this.currentYear += delta;
|
||||
this.loadCompletionTimeline(this.currentYear);
|
||||
}
|
||||
|
||||
private loadCompletionTimeline(year: number): void {
|
||||
this.userStatsService.getCompletionTimelineForYear(year)
|
||||
.pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError((error) => {
|
||||
console.error('Error loading completion timeline:', error);
|
||||
return EMPTY;
|
||||
})
|
||||
)
|
||||
.subscribe((data) => {
|
||||
this.updateChartData(data);
|
||||
});
|
||||
}
|
||||
|
||||
private updateChartData(timeline: CompletionTimelineResponse[]): void {
|
||||
const monthlyData = new Map<number, CompletionTimelineResponse>();
|
||||
timeline.forEach(item => {
|
||||
monthlyData.set(item.month, item);
|
||||
});
|
||||
|
||||
const labels = this.monthNames;
|
||||
|
||||
const completedBooks = this.monthNames.map((_, index) => {
|
||||
const monthData = monthlyData.get(index + 1);
|
||||
if (!monthData) return 0;
|
||||
const read = monthData.statusBreakdown['READ'] || 0;
|
||||
const partiallyRead = monthData.statusBreakdown['PARTIALLY_READ'] || 0;
|
||||
return read + partiallyRead;
|
||||
});
|
||||
|
||||
const activeReading = this.monthNames.map((_, index) => {
|
||||
const monthData = monthlyData.get(index + 1);
|
||||
if (!monthData) return 0;
|
||||
const reading = monthData.statusBreakdown['READING'] || 0;
|
||||
const reReading = monthData.statusBreakdown['RE_READING'] || 0;
|
||||
return reading + reReading;
|
||||
});
|
||||
|
||||
const pausedBooks = this.monthNames.map((_, index) => {
|
||||
const monthData = monthlyData.get(index + 1);
|
||||
return monthData?.statusBreakdown['PAUSED'] || 0;
|
||||
});
|
||||
|
||||
const discontinuedBooks = this.monthNames.map((_, index) => {
|
||||
const monthData = monthlyData.get(index + 1);
|
||||
if (!monthData) return 0;
|
||||
const abandoned = monthData.statusBreakdown['ABANDONED'] || 0;
|
||||
const wontRead = monthData.statusBreakdown['WONT_READ'] || 0;
|
||||
return abandoned + wontRead;
|
||||
});
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Completed',
|
||||
data: completedBooks,
|
||||
backgroundColor: 'rgba(106, 176, 76, 0.8)',
|
||||
borderColor: 'rgba(106, 176, 76, 1)',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4,
|
||||
barPercentage: 0.8,
|
||||
categoryPercentage: 0.6
|
||||
},
|
||||
{
|
||||
label: 'Active Reading',
|
||||
data: activeReading,
|
||||
backgroundColor: 'rgba(59, 130, 246, 0.8)',
|
||||
borderColor: 'rgba(59, 130, 246, 1)',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4,
|
||||
barPercentage: 0.8,
|
||||
categoryPercentage: 0.6
|
||||
},
|
||||
{
|
||||
label: 'Paused',
|
||||
data: pausedBooks,
|
||||
backgroundColor: 'rgba(255, 193, 7, 0.8)',
|
||||
borderColor: 'rgba(255, 193, 7, 1)',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4,
|
||||
barPercentage: 0.8,
|
||||
categoryPercentage: 0.6
|
||||
},
|
||||
{
|
||||
label: 'Discontinued',
|
||||
data: discontinuedBooks,
|
||||
backgroundColor: 'rgba(239, 68, 68, 0.8)',
|
||||
borderColor: 'rgba(239, 68, 68, 1)',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4,
|
||||
barPercentage: 0.8,
|
||||
categoryPercentage: 0.6
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<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
|
||||
</h3>
|
||||
<p class="chart-description">Reading sessions and duration by day of the week</p>
|
||||
</div>
|
||||
<div class="filter-controls">
|
||||
<p-select
|
||||
[options]="yearOptions"
|
||||
[(ngModel)]="selectedYear"
|
||||
(onChange)="onFilterChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Year"
|
||||
[style]="{'min-width': '90px'}">
|
||||
</p-select>
|
||||
<p-select
|
||||
[options]="monthOptions"
|
||||
[(ngModel)]="selectedMonth"
|
||||
(onChange)="onFilterChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Month"
|
||||
[style]="{'min-width': '120px'}">
|
||||
</p-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
.favorite-days-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
gap: 1rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.favorite-days-icon {
|
||||
font-size: 1.5rem;
|
||||
color: rgba(139, 92, 246, 1);
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
position: relative;
|
||||
height: 350px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.filter-controls {
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
::ng-deep p-select {
|
||||
width: 100%;
|
||||
|
||||
.p-select {
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
import {Component, inject, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {BaseChartDirective} from 'ng2-charts';
|
||||
import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {FavoriteDaysResponse, UserStatsService} from '../../../settings/user-management/user-stats.service';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
type FavoriteDaysChartData = ChartData<'bar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-favorite-days-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Select, FormsModule],
|
||||
templateUrl: './favorite-days-chart.component.html',
|
||||
styleUrls: ['./favorite-days-chart.component.scss']
|
||||
})
|
||||
export class FavoriteDaysChartComponent implements OnInit, OnDestroy {
|
||||
public readonly chartType = 'bar' as const;
|
||||
public readonly chartData$: Observable<FavoriteDaysChartData>;
|
||||
public readonly chartOptions: ChartConfiguration['options'];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<FavoriteDaysChartData>;
|
||||
|
||||
private readonly allDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||
|
||||
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 }
|
||||
];
|
||||
|
||||
constructor() {
|
||||
this.chartDataSubject = new BehaviorSubject<FavoriteDaysChartData>({
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
this.chartData$ = this.chartDataSubject.asObservable();
|
||||
|
||||
this.chartOptions = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
layout: {
|
||||
padding: {top: 10, bottom: 10, left: 10, right: 10}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'top',
|
||||
labels: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
boxWidth: 12,
|
||||
padding: 10
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#ffffff',
|
||||
borderWidth: 1,
|
||||
cornerRadius: 6,
|
||||
displayColors: true,
|
||||
padding: 12,
|
||||
titleFont: {size: 14, weight: 'bold'},
|
||||
bodyFont: {size: 13},
|
||||
callbacks: {
|
||||
label: (context) => {
|
||||
const label = context.dataset.label || '';
|
||||
const value = context.parsed.y;
|
||||
if (label === 'Sessions') {
|
||||
return `${label}: ${value} session${value !== 1 ? 's' : ''}`;
|
||||
} else {
|
||||
const hours = Math.floor(value / 3600);
|
||||
const minutes = Math.floor((value % 3600) / 60);
|
||||
return `${label}: ${hours}h ${minutes}m`;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
datalabels: {display: false}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Day of Week',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 13,
|
||||
weight: 'bold'
|
||||
}
|
||||
},
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11}
|
||||
},
|
||||
grid: {display: false},
|
||||
border: {display: false}
|
||||
},
|
||||
y: {
|
||||
type: 'linear',
|
||||
display: true,
|
||||
position: 'left',
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Number of Sessions',
|
||||
color: 'rgba(139, 92, 246, 1)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 13,
|
||||
weight: 'bold'
|
||||
}
|
||||
},
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
stepSize: 1
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
},
|
||||
border: {display: false}
|
||||
},
|
||||
y1: {
|
||||
type: 'linear',
|
||||
display: true,
|
||||
position: 'right',
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Duration (hours)',
|
||||
color: 'rgba(236, 72, 153, 1)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 13,
|
||||
weight: 'bold'
|
||||
}
|
||||
},
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
callback: function(value) {
|
||||
return (typeof value === 'number' ? value.toFixed(1) : '0.0') + 'h';
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
drawOnChartArea: false
|
||||
},
|
||||
border: {display: false}
|
||||
}
|
||||
}
|
||||
};
|
||||
this.initializeYearOptions();
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadFavoriteDays();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private initializeYearOptions(): void {
|
||||
const currentYear = new Date().getFullYear();
|
||||
this.yearOptions = [{ label: 'All Years', value: null }];
|
||||
for (let year = currentYear; year >= currentYear - 10; year--) {
|
||||
this.yearOptions.push({ label: year.toString(), value: year });
|
||||
}
|
||||
}
|
||||
|
||||
public onFilterChange(): void {
|
||||
this.loadFavoriteDays();
|
||||
}
|
||||
|
||||
private loadFavoriteDays(): void {
|
||||
const year = this.selectedYear ?? undefined;
|
||||
const month = this.selectedMonth ?? undefined;
|
||||
|
||||
this.userStatsService.getFavoriteDays(year, month)
|
||||
.pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError((error) => {
|
||||
console.error('Error loading favorite days:', error);
|
||||
return EMPTY;
|
||||
})
|
||||
)
|
||||
.subscribe((data) => {
|
||||
this.updateChartData(data);
|
||||
});
|
||||
}
|
||||
|
||||
private updateChartData(favoriteDays: FavoriteDaysResponse[]): void {
|
||||
const dayMap = new Map<number, FavoriteDaysResponse>();
|
||||
favoriteDays.forEach(item => {
|
||||
dayMap.set(item.dayOfWeek, item);
|
||||
});
|
||||
|
||||
const labels = this.allDays;
|
||||
const sessionCounts = this.allDays.map((_, index) => {
|
||||
const dayData = dayMap.get(index);
|
||||
return dayData?.sessionCount || 0;
|
||||
});
|
||||
|
||||
const durations = this.allDays.map((_, index) => {
|
||||
const dayData = dayMap.get(index);
|
||||
return dayData ? dayData.totalDurationSeconds / 3600 : 0; // Convert to hours
|
||||
});
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Sessions',
|
||||
data: sessionCounts,
|
||||
backgroundColor: 'rgba(139, 92, 246, 0.8)',
|
||||
borderColor: 'rgba(139, 92, 246, 1)',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4,
|
||||
barPercentage: 0.8,
|
||||
categoryPercentage: 0.6,
|
||||
yAxisID: 'y'
|
||||
},
|
||||
{
|
||||
label: 'Duration (hours)',
|
||||
data: durations,
|
||||
backgroundColor: 'rgba(236, 72, 153, 0.8)',
|
||||
borderColor: 'rgba(236, 72, 153, 1)',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4,
|
||||
barPercentage: 0.8,
|
||||
categoryPercentage: 0.6,
|
||||
yAxisID: 'y1'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<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
|
||||
</h3>
|
||||
<p class="chart-description">Top genres by total reading time</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
.genre-stats-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 1.5rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.genre-title-icon {
|
||||
font-size: 1.5rem;
|
||||
color: rgba(34, 197, 94, 1);
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
position: relative;
|
||||
height: 350px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
import {Component, inject, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {BaseChartDirective} from 'ng2-charts';
|
||||
import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {GenreStatsResponse, UserStatsService} from '../../../settings/user-management/user-stats.service';
|
||||
|
||||
type GenreChartData = ChartData<'bar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-genre-stats-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective],
|
||||
templateUrl: './genre-stats-chart.component.html',
|
||||
styleUrls: ['./genre-stats-chart.component.scss']
|
||||
})
|
||||
export class GenreStatsChartComponent implements OnInit, OnDestroy {
|
||||
@Input() maxGenres: number = 35;
|
||||
|
||||
public readonly chartType = 'bar' as const;
|
||||
public readonly chartData$: Observable<GenreChartData>;
|
||||
public readonly chartOptions: ChartConfiguration['options'];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
private readonly chartDataSubject: BehaviorSubject<GenreChartData>;
|
||||
|
||||
constructor() {
|
||||
this.chartDataSubject = new BehaviorSubject<GenreChartData>({
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
this.chartData$ = this.chartDataSubject.asObservable();
|
||||
|
||||
this.chartOptions = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
layout: {
|
||||
padding: {top: 10, bottom: 10, left: 10, right: 10}
|
||||
},
|
||||
plugins: {
|
||||
legend: {display: false},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#ffffff',
|
||||
borderWidth: 1,
|
||||
cornerRadius: 6,
|
||||
displayColors: true,
|
||||
padding: 12,
|
||||
titleFont: {size: 14, weight: 'bold'},
|
||||
bodyFont: {size: 13},
|
||||
callbacks: {
|
||||
label: (context) => {
|
||||
const dataIndex = context.dataIndex;
|
||||
const dataset = context.dataset;
|
||||
const label = context.chart.data.labels?.[dataIndex] as string;
|
||||
const minutes = Math.floor((dataset.data[dataIndex] as number) / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const mins = minutes % 60;
|
||||
|
||||
const timeStr = hours > 0
|
||||
? `${hours}h ${mins}m`
|
||||
: `${mins}m`;
|
||||
|
||||
return `${label}: ${timeStr}`;
|
||||
}
|
||||
}
|
||||
},
|
||||
datalabels: {display: false}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Genres',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 12
|
||||
}
|
||||
},
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
maxRotation: 90,
|
||||
minRotation: 90,
|
||||
callback: (value, index) => {
|
||||
const label = this.chartDataSubject.value.labels?.[index] as string;
|
||||
const maxLength = 12;
|
||||
if (label && label.length > maxLength) {
|
||||
return label.substring(0, maxLength) + '...';
|
||||
}
|
||||
return label;
|
||||
}
|
||||
},
|
||||
grid: {display: false},
|
||||
border: {display: false}
|
||||
},
|
||||
y: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Time Read',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 12
|
||||
}
|
||||
},
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
callback: (value) => {
|
||||
const seconds = value as number;
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const days = Math.floor(hours / 24);
|
||||
|
||||
if (days > 0) {
|
||||
const remainingHours = hours % 24;
|
||||
if (remainingHours > 0) {
|
||||
return `${days} ${days === 1 ? 'day' : 'days'} ${remainingHours} ${remainingHours === 1 ? 'hr' : 'hrs'}`;
|
||||
}
|
||||
return `${days} ${days === 1 ? 'day' : 'days'}`;
|
||||
} else if (hours > 0) {
|
||||
const remainingMinutes = minutes % 60;
|
||||
if (remainingMinutes > 0) {
|
||||
return `${hours} ${hours === 1 ? 'hr' : 'hrs'} ${remainingMinutes} min`;
|
||||
}
|
||||
return `${hours} ${hours === 1 ? 'hr' : 'hrs'}`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes} min`;
|
||||
}
|
||||
return `${seconds} sec`;
|
||||
},
|
||||
stepSize: undefined,
|
||||
maxTicksLimit: 8
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
},
|
||||
border: {display: false}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadGenreStats();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private loadGenreStats(): void {
|
||||
this.userStatsService.getGenreStats()
|
||||
.pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError((error) => {
|
||||
console.error('Error loading genre stats:', error);
|
||||
return EMPTY;
|
||||
})
|
||||
)
|
||||
.subscribe((data) => {
|
||||
this.updateChartData(data);
|
||||
});
|
||||
}
|
||||
|
||||
private updateChartData(genreStats: GenreStatsResponse[]): void {
|
||||
const sortedStats = [...genreStats]
|
||||
.sort((a, b) => b.totalDurationSeconds - a.totalDurationSeconds)
|
||||
.slice(0, this.maxGenres);
|
||||
|
||||
const labels = sortedStats.map(stat => stat.genre);
|
||||
const durations = sortedStats.map(stat => stat.totalDurationSeconds);
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Reading Time',
|
||||
data: durations,
|
||||
backgroundColor: 'rgba(34, 197, 94, 0.8)',
|
||||
borderColor: 'rgba(34, 197, 94, 1)',
|
||||
borderWidth: 1,
|
||||
borderRadius: 4,
|
||||
barPercentage: 0.8,
|
||||
categoryPercentage: 0.6
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<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
|
||||
</h3>
|
||||
<p class="chart-description">Reading activity by hour of the day</p>
|
||||
</div>
|
||||
<div class="filter-controls">
|
||||
<p-select
|
||||
[options]="yearOptions"
|
||||
[(ngModel)]="selectedYear"
|
||||
(onChange)="onFilterChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Year"
|
||||
[style]="{'min-width': '100px'}">
|
||||
</p-select>
|
||||
<p-select
|
||||
[options]="monthOptions"
|
||||
[(ngModel)]="selectedMonth"
|
||||
(onChange)="onFilterChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Month"
|
||||
[style]="{'min-width': '130px'}">
|
||||
</p-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
.peak-hours-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
gap: 1rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.peak-hours-icon {
|
||||
font-size: 1.5rem;
|
||||
color: rgba(34, 197, 94, 1);
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
position: relative;
|
||||
height: 350px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
|
||||
.filter-controls {
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
::ng-deep p-select {
|
||||
width: 100%;
|
||||
|
||||
.p-select {
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {BaseChartDirective} from 'ng2-charts';
|
||||
import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, takeUntil} from 'rxjs/operators';
|
||||
import {PeakHoursResponse, UserStatsService} from '../../../settings/user-management/user-stats.service';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
type PeakHoursChartData = ChartData<'line', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-peak-hours-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective, Select, FormsModule],
|
||||
templateUrl: './peak-hours-chart.component.html',
|
||||
styleUrls: ['./peak-hours-chart.component.scss']
|
||||
})
|
||||
export class PeakHoursChartComponent implements OnInit, OnDestroy {
|
||||
public readonly chartType = 'line' as const;
|
||||
public readonly chartData$: Observable<PeakHoursChartData>;
|
||||
public readonly chartOptions: ChartConfiguration['options'];
|
||||
|
||||
private readonly userStatsService = inject(UserStatsService);
|
||||
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 }
|
||||
];
|
||||
|
||||
constructor() {
|
||||
this.chartDataSubject = new BehaviorSubject<PeakHoursChartData>({
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
this.chartData$ = this.chartDataSubject.asObservable();
|
||||
|
||||
this.chartOptions = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
layout: {
|
||||
padding: {top: 10, bottom: 10, left: 10, right: 10}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'top',
|
||||
labels: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
boxWidth: 12,
|
||||
padding: 10
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#ffffff',
|
||||
borderWidth: 1,
|
||||
cornerRadius: 6,
|
||||
displayColors: true,
|
||||
padding: 12,
|
||||
titleFont: {size: 14, weight: 'bold'},
|
||||
bodyFont: {size: 13},
|
||||
callbacks: {
|
||||
label: (context) => {
|
||||
const label = context.dataset.label || '';
|
||||
const value = context.parsed.y;
|
||||
if (label === 'Sessions') {
|
||||
return `${label}: ${value} session${value !== 1 ? 's' : ''}`;
|
||||
} else {
|
||||
const hours = Math.floor(value / 3600);
|
||||
const minutes = Math.floor((value % 3600) / 60);
|
||||
return `${label}: ${hours}h ${minutes}m`;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
datalabels: {display: false}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Hour of Day',
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 13,
|
||||
weight: 'bold'
|
||||
}
|
||||
},
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11}
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
},
|
||||
border: {display: false}
|
||||
},
|
||||
y: {
|
||||
type: 'linear',
|
||||
display: true,
|
||||
position: 'left',
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Number of Sessions',
|
||||
color: 'rgba(34, 197, 94, 0.9)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 13,
|
||||
weight: 'bold'
|
||||
}
|
||||
},
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
stepSize: 1
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
},
|
||||
border: {display: false}
|
||||
},
|
||||
y1: {
|
||||
type: 'linear',
|
||||
display: true,
|
||||
position: 'right',
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Duration (minutes)',
|
||||
color: 'rgba(251, 191, 36, 0.9)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 13,
|
||||
weight: 'bold'
|
||||
}
|
||||
},
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
color: '#ffffff',
|
||||
font: {family: "'Inter', sans-serif", size: 11},
|
||||
callback: function (value) {
|
||||
return (typeof value === 'number' ? Math.round(value) : '0') + 'm';
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
drawOnChartArea: false
|
||||
},
|
||||
border: {display: false}
|
||||
}
|
||||
}
|
||||
};
|
||||
this.initializeYearOptions();
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadPeakHours();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private initializeYearOptions(): void {
|
||||
const currentYear = new Date().getFullYear();
|
||||
this.yearOptions = [{ label: 'All Years', value: null }];
|
||||
for (let year = currentYear; year >= currentYear - 10; year--) {
|
||||
this.yearOptions.push({ label: year.toString(), value: year });
|
||||
}
|
||||
}
|
||||
|
||||
public onFilterChange(): void {
|
||||
this.loadPeakHours();
|
||||
}
|
||||
|
||||
private loadPeakHours(): void {
|
||||
const year = this.selectedYear ?? undefined;
|
||||
const month = this.selectedMonth ?? undefined;
|
||||
|
||||
this.userStatsService.getPeakHours(year, month)
|
||||
.pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError((error) => {
|
||||
console.error('Error loading peak hours:', error);
|
||||
return EMPTY;
|
||||
})
|
||||
)
|
||||
.subscribe((data) => {
|
||||
this.updateChartData(data);
|
||||
});
|
||||
}
|
||||
|
||||
private updateChartData(peakHours: PeakHoursResponse[]): void {
|
||||
const hourMap = new Map<number, PeakHoursResponse>();
|
||||
peakHours.forEach(item => {
|
||||
hourMap.set(item.hourOfDay, item);
|
||||
});
|
||||
|
||||
const allHours = Array.from({length: 24}, (_, i) => i);
|
||||
const labels = allHours.map(h => this.formatHour(h));
|
||||
|
||||
const sessionCounts = allHours.map(hour => {
|
||||
const hourData = hourMap.get(hour);
|
||||
return hourData?.sessionCount || 0;
|
||||
});
|
||||
|
||||
const durations = allHours.map(hour => {
|
||||
const hourData = hourMap.get(hour);
|
||||
return hourData ? hourData.totalDurationSeconds / 60 : 0; // Convert to minutes
|
||||
});
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels,
|
||||
datasets: [
|
||||
{
|
||||
label: 'Sessions',
|
||||
data: sessionCounts,
|
||||
borderColor: 'rgba(34, 197, 94, 0.9)',
|
||||
backgroundColor: 'rgba(34, 197, 94, 0.1)',
|
||||
borderWidth: 2,
|
||||
tension: 0.4,
|
||||
fill: true,
|
||||
pointRadius: 4,
|
||||
pointHoverRadius: 6,
|
||||
pointBackgroundColor: 'rgba(34, 197, 94, 0.9)',
|
||||
pointBorderColor: '#ffffff',
|
||||
pointBorderWidth: 2,
|
||||
yAxisID: 'y'
|
||||
},
|
||||
{
|
||||
label: 'Duration (minutes)',
|
||||
data: durations,
|
||||
borderColor: 'rgba(251, 191, 36, 0.9)',
|
||||
backgroundColor: 'rgba(251, 191, 36, 0.1)',
|
||||
borderWidth: 2,
|
||||
tension: 0.4,
|
||||
fill: true,
|
||||
pointRadius: 4,
|
||||
pointHoverRadius: 6,
|
||||
pointBackgroundColor: 'rgba(251, 191, 36, 0.9)',
|
||||
pointBorderColor: '#ffffff',
|
||||
pointBorderWidth: 2,
|
||||
yAxisID: 'y1'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
private formatHour(hour: number): string {
|
||||
if (hour === 0) return '12 AM';
|
||||
if (hour === 12) return '12 PM';
|
||||
if (hour < 12) return `${hour} AM`;
|
||||
return `${hour - 12} PM`;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<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
|
||||
</h3>
|
||||
<p class="chart-description">Your unique reading personality across 8 key dimensions</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
</div>
|
||||
@if (personalityInsights.length > 0) {
|
||||
<div class="personality-insights">
|
||||
<h4>Your Reading Personality Traits</h4>
|
||||
<div class="insights-grid">
|
||||
@for (insight of personalityInsights; track insight.trait) {
|
||||
<div class="insight-card">
|
||||
<div class="insight-header">
|
||||
<span class="insight-trait">{{ insight.trait }}</span>
|
||||
<span class="insight-score" [style.color]="insight.color">{{ insight.score.toFixed(0) }}%</span>
|
||||
</div>
|
||||
<div class="insight-progress">
|
||||
<div class="progress-bar" [style.width.%]="insight.score" [style.background-color]="insight.color"></div>
|
||||
</div>
|
||||
<p class="insight-description">{{ insight.description }}</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
.reading-dna-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.reading-dna-icon {
|
||||
font-size: 1.5rem;
|
||||
color: rgba(79, 195, 247, 1);
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
position: relative;
|
||||
height: 450px;
|
||||
width: 100%;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.personality-insights {
|
||||
margin-top: 2rem;
|
||||
|
||||
h4 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.1rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 1rem 0;
|
||||
}
|
||||
|
||||
.insights-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.insight-card {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 8px;
|
||||
padding: 1rem;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
.insight-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.insight-trait {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-weight: 500;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.insight-score {
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.insight-progress {
|
||||
height: 6px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.progress-bar {
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.insight-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.85rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-wrapper {
|
||||
height: 350px;
|
||||
}
|
||||
|
||||
.personality-insights {
|
||||
.insights-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
+551
@@ -0,0 +1,551 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {BaseChartDirective} from 'ng2-charts';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, filter, first, takeUntil} from 'rxjs/operators';
|
||||
import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {Book, ReadStatus} from '../../../book/model/book.model';
|
||||
|
||||
interface ReadingDNAProfile {
|
||||
adventurous: number;
|
||||
perfectionist: number;
|
||||
intellectual: number;
|
||||
emotional: number;
|
||||
patient: number;
|
||||
social: number;
|
||||
nostalgic: number;
|
||||
ambitious: number;
|
||||
}
|
||||
|
||||
interface PersonalityInsight {
|
||||
trait: string;
|
||||
score: number;
|
||||
description: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
type ReadingDNAChartData = ChartData<'radar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-reading-dna-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective],
|
||||
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 destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'radar' as const;
|
||||
|
||||
public readonly chartOptions: ChartConfiguration<'radar'>['options'] = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
scales: {
|
||||
r: {
|
||||
beginAtZero: true,
|
||||
min: 0,
|
||||
max: 100,
|
||||
ticks: {
|
||||
stepSize: 20,
|
||||
color: 'rgba(255, 255, 255, 0.6)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 12
|
||||
},
|
||||
backdropColor: 'transparent',
|
||||
showLabelBackdrop: false
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.2)',
|
||||
circular: true
|
||||
},
|
||||
angleLines: {
|
||||
color: 'rgba(255, 255, 255, 0.3)'
|
||||
},
|
||||
pointLabels: {
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.95)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#4fc3f7',
|
||||
borderWidth: 2,
|
||||
cornerRadius: 8,
|
||||
padding: 16,
|
||||
titleFont: {size: 14, weight: 'bold'},
|
||||
bodyFont: {size: 12},
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const label = context[0]?.label || '';
|
||||
return `${label} Personality`;
|
||||
},
|
||||
label: (context) => {
|
||||
const score = context.parsed.r;
|
||||
const insight = this.personalityInsights.find(i => i.trait === context.label);
|
||||
|
||||
return [
|
||||
`Score: ${score.toFixed(1)}/100`,
|
||||
'',
|
||||
insight ? insight.description : 'Your reading personality trait'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
interaction: {
|
||||
intersect: false,
|
||||
mode: 'point'
|
||||
},
|
||||
elements: {
|
||||
line: {
|
||||
borderWidth: 3,
|
||||
tension: 0.1
|
||||
},
|
||||
point: {
|
||||
radius: 5,
|
||||
hoverRadius: 8,
|
||||
borderWidth: 3,
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.8)'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private readonly chartDataSubject = new BehaviorSubject<ReadingDNAChartData>({
|
||||
labels: [
|
||||
'Adventurous', 'Perfectionist', 'Intellectual', 'Emotional',
|
||||
'Patient', 'Social', 'Nostalgic', 'Ambitious'
|
||||
],
|
||||
datasets: []
|
||||
});
|
||||
|
||||
public readonly chartData$: Observable<ReadingDNAChartData> = this.chartDataSubject.asObservable();
|
||||
public personalityInsights: PersonalityInsight[] = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookService.bookState$
|
||||
.pipe(
|
||||
filter(state => state.loaded),
|
||||
first(),
|
||||
catchError((error) => {
|
||||
console.error('Error processing reading DNA data:', error);
|
||||
return EMPTY;
|
||||
}),
|
||||
takeUntil(this.destroy$)
|
||||
)
|
||||
.subscribe(() => {
|
||||
const profile = this.calculateReadingDNAData();
|
||||
this.updateChartData(profile);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private updateChartData(profile: ReadingDNAProfile | null): void {
|
||||
try {
|
||||
if (!profile) {
|
||||
this.chartDataSubject.next({
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
this.personalityInsights = [];
|
||||
return;
|
||||
}
|
||||
|
||||
const data = [
|
||||
profile.adventurous,
|
||||
profile.perfectionist,
|
||||
profile.intellectual,
|
||||
profile.emotional,
|
||||
profile.patient,
|
||||
profile.social,
|
||||
profile.nostalgic,
|
||||
profile.ambitious
|
||||
];
|
||||
|
||||
const gradientColors = [
|
||||
'#ff6b9d', '#45aaf2', '#96f7d2', '#feca57',
|
||||
'#ff9ff3', '#54a0ff', '#5f27cd', '#00d2d3'
|
||||
];
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels: [
|
||||
'Adventurous', 'Perfectionist', 'Intellectual', 'Emotional',
|
||||
'Patient', 'Social', 'Nostalgic', 'Ambitious'
|
||||
],
|
||||
datasets: [{
|
||||
label: 'Reading DNA Profile',
|
||||
data,
|
||||
backgroundColor: 'rgba(79, 195, 247, 0.2)',
|
||||
borderColor: '#4fc3f7',
|
||||
borderWidth: 3,
|
||||
pointBackgroundColor: gradientColors,
|
||||
pointBorderColor: '#ffffff',
|
||||
pointBorderWidth: 3,
|
||||
pointRadius: 5,
|
||||
pointHoverRadius: 8,
|
||||
fill: true
|
||||
}]
|
||||
});
|
||||
|
||||
this.personalityInsights = this.convertToPersonalityInsights(profile);
|
||||
} catch (error) {
|
||||
console.error('Error updating reading DNA chart data:', error);
|
||||
}
|
||||
}
|
||||
|
||||
private calculateReadingDNAData(): ReadingDNAProfile | null {
|
||||
const currentState = this.bookService.getCurrentBookState();
|
||||
|
||||
if (!this.isValidBookState(currentState)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.analyzeReadingDNA(currentState.books!);
|
||||
}
|
||||
|
||||
private isValidBookState(state: any): boolean {
|
||||
return state?.loaded && state?.books && Array.isArray(state.books) && state.books.length > 0;
|
||||
}
|
||||
|
||||
private analyzeReadingDNA(books: Book[]): ReadingDNAProfile {
|
||||
if (books.length === 0) {
|
||||
return this.getDefaultProfile();
|
||||
}
|
||||
|
||||
return {
|
||||
adventurous: this.calculateAdventurousScore(books),
|
||||
perfectionist: this.calculatePerfectionistScore(books),
|
||||
intellectual: this.calculateIntellectualScore(books),
|
||||
emotional: this.calculateEmotionalScore(books),
|
||||
patient: this.calculatePatienceScore(books),
|
||||
social: this.calculateSocialScore(books),
|
||||
nostalgic: this.calculateNostalgicScore(books),
|
||||
ambitious: this.calculateAmbitiousScore(books)
|
||||
};
|
||||
}
|
||||
|
||||
private calculateAdventurousScore(books: Book[]): number {
|
||||
const genres = new Set<string>();
|
||||
const languages = new Set<string>();
|
||||
const formats = new Set<string>();
|
||||
|
||||
books.forEach(book => {
|
||||
book.metadata?.categories?.forEach(cat => genres.add(cat.toLowerCase()));
|
||||
if (book.metadata?.language) languages.add(book.metadata.language);
|
||||
formats.add(book.bookType);
|
||||
});
|
||||
|
||||
const genreScore = Math.min(60, genres.size * 4);
|
||||
const languageScore = Math.min(20, languages.size * 10);
|
||||
const formatScore = Math.min(20, formats.size * 7);
|
||||
|
||||
return genreScore + languageScore + formatScore;
|
||||
}
|
||||
|
||||
private calculatePerfectionistScore(books: Book[]): number {
|
||||
const completedBooks = books.filter(b => b.readStatus === ReadStatus.READ);
|
||||
const completionRate = completedBooks.length / books.length;
|
||||
|
||||
const qualityBooks = books.filter(book => {
|
||||
const metadata = book.metadata;
|
||||
if (!metadata) return false;
|
||||
return (metadata.goodreadsRating && metadata.goodreadsRating >= 4.0) ||
|
||||
(metadata.amazonRating && metadata.amazonRating >= 4.0) ||
|
||||
(book.personalRating && book.personalRating >= 4);
|
||||
});
|
||||
|
||||
const qualityRate = qualityBooks.length / books.length;
|
||||
const completionScore = completionRate * 60;
|
||||
const qualityScore = qualityRate * 40;
|
||||
|
||||
return Math.min(100, completionScore + qualityScore);
|
||||
}
|
||||
|
||||
private calculateIntellectualScore(books: Book[]): number {
|
||||
const intellectualGenres = [
|
||||
'philosophy', 'science', 'history', 'biography', 'politics',
|
||||
'psychology', 'sociology', 'economics', 'technology', 'mathematics',
|
||||
'physics', 'chemistry', 'medicine', 'law', 'education',
|
||||
'anthropology', 'archaeology', 'astronomy', 'biology', 'geology',
|
||||
'linguistics', 'neuroscience', 'quantum physics', 'engineering',
|
||||
'computer science', 'artificial intelligence', 'data science',
|
||||
'research', 'academic', 'scholarly', 'theoretical', 'scientific',
|
||||
'analytical', 'critical thinking', 'logic', 'rhetoric',
|
||||
'cultural studies', 'international relations', 'diplomacy',
|
||||
'public policy', 'governance', 'constitutional law', 'ethics',
|
||||
'moral philosophy', 'epistemology', 'metaphysics', 'theology',
|
||||
'religious studies', 'comparative religion', 'apologetics'
|
||||
];
|
||||
|
||||
const intellectualBooks = books.filter(book => {
|
||||
if (!book.metadata?.categories) return false;
|
||||
return book.metadata.categories.some(cat =>
|
||||
intellectualGenres.some(genre => cat.toLowerCase().includes(genre))
|
||||
);
|
||||
});
|
||||
|
||||
const longBooks = books.filter(book =>
|
||||
book.metadata?.pageCount && book.metadata.pageCount > 400
|
||||
);
|
||||
|
||||
const intellectualRate = intellectualBooks.length / books.length;
|
||||
const longBookRate = longBooks.length / books.length;
|
||||
|
||||
return Math.min(100, (intellectualRate * 70) + (longBookRate * 30));
|
||||
}
|
||||
|
||||
private calculateEmotionalScore(books: Book[]): number {
|
||||
const emotionalGenres = [
|
||||
'fiction', 'romance', 'drama', 'literary', 'contemporary',
|
||||
'memoir', 'poetry', 'young adult', 'coming of age', 'family',
|
||||
'love story', 'relationships', 'emotional', 'heartbreak',
|
||||
'healing', 'self-help', 'personal development', 'inspirational',
|
||||
'motivational', 'spiritual', 'mindfulness', 'meditation',
|
||||
'grief', 'loss', 'trauma', 'recovery', 'therapy',
|
||||
'women\'s fiction', 'chick lit', 'new adult', 'teen',
|
||||
'childhood', 'parenting', 'motherhood', 'fatherhood',
|
||||
'friendship', 'betrayal', 'forgiveness', 'redemption',
|
||||
'slice of life', 'domestic fiction', 'family saga',
|
||||
'generational saga', 'multicultural', 'immigrant stories',
|
||||
'lgbtq+', 'queer fiction', 'feminist', 'gender studies',
|
||||
'social issues', 'mental health', 'addiction', 'wellness',
|
||||
'autobiography', 'personal narrative', 'diary', 'journal'
|
||||
];
|
||||
|
||||
const emotionalBooks = books.filter(book => {
|
||||
if (!book.metadata?.categories) return false;
|
||||
return book.metadata.categories.some(cat =>
|
||||
emotionalGenres.some(genre => cat.toLowerCase().includes(genre))
|
||||
);
|
||||
});
|
||||
|
||||
const personallyRatedBooks = books.filter(book => book.personalRating);
|
||||
|
||||
const emotionalRate = emotionalBooks.length / books.length;
|
||||
const ratingEngagement = personallyRatedBooks.length / books.length;
|
||||
|
||||
return Math.min(100, (emotionalRate * 60) + (ratingEngagement * 40));
|
||||
}
|
||||
|
||||
private calculatePatienceScore(books: Book[]): number {
|
||||
const longBooks = books.filter(book =>
|
||||
book.metadata?.pageCount && book.metadata.pageCount > 500
|
||||
);
|
||||
|
||||
const seriesBooks = books.filter(book =>
|
||||
book.metadata?.seriesName && book.metadata?.seriesNumber
|
||||
);
|
||||
|
||||
const progressBooks = books.filter(book => {
|
||||
const progress = Math.max(
|
||||
book.epubProgress?.percentage || 0,
|
||||
book.pdfProgress?.percentage || 0,
|
||||
book.cbxProgress?.percentage || 0,
|
||||
book.koreaderProgress?.percentage || 0,
|
||||
book.koboProgress?.percentage || 0
|
||||
);
|
||||
return progress > 50;
|
||||
});
|
||||
|
||||
const longBookRate = longBooks.length / books.length;
|
||||
const seriesRate = seriesBooks.length / books.length;
|
||||
const progressRate = progressBooks.length / books.length;
|
||||
|
||||
return Math.min(100, (longBookRate * 40) + (seriesRate * 35) + (progressRate * 25));
|
||||
}
|
||||
|
||||
private calculateSocialScore(books: Book[]): number {
|
||||
const popularBooks = books.filter(book => {
|
||||
const metadata = book.metadata;
|
||||
if (!metadata) return false;
|
||||
return (metadata.goodreadsReviewCount && metadata.goodreadsReviewCount > 1000) ||
|
||||
(metadata.amazonReviewCount && metadata.amazonReviewCount > 500);
|
||||
});
|
||||
|
||||
const mainstreamGenres = [
|
||||
'thriller', 'mystery', 'romance', 'fantasy', 'science fiction',
|
||||
'horror', 'adventure', 'bestseller', 'contemporary', 'popular',
|
||||
'crime', 'detective', 'suspense', 'action', 'espionage',
|
||||
'spy', 'police procedural', 'cozy mystery', 'psychological thriller',
|
||||
'domestic thriller', 'legal thriller', 'medical thriller',
|
||||
'urban fantasy', 'paranormal', 'supernatural', 'magic',
|
||||
'dystopian', 'post-apocalyptic', 'cyberpunk', 'space opera',
|
||||
'military science fiction', 'hard science fiction', 'steampunk',
|
||||
'alternate history', 'time travel', 'vampire', 'werewolf',
|
||||
'zombie', 'ghost', 'gothic', 'dark fantasy', 'epic fantasy',
|
||||
'sword and sorcery', 'high fantasy', 'historical romance',
|
||||
'regency romance', 'western', 'sports', 'celebrity',
|
||||
'entertainment', 'pop culture', 'reality tv', 'social media',
|
||||
'true crime', 'celebrity biography', 'gossip', 'lifestyle',
|
||||
'fashion', 'beauty', 'cooking', 'travel', 'humor',
|
||||
'comedy', 'satire', 'graphic novel', 'manga', 'comic'
|
||||
];
|
||||
|
||||
const mainstreamBooks = books.filter(book => {
|
||||
if (!book.metadata?.categories) return false;
|
||||
return book.metadata.categories.some(cat =>
|
||||
mainstreamGenres.some(genre => cat.toLowerCase().includes(genre))
|
||||
);
|
||||
});
|
||||
|
||||
const popularRate = popularBooks.length / books.length;
|
||||
const mainstreamRate = mainstreamBooks.length / books.length;
|
||||
|
||||
return Math.min(100, (popularRate * 50) + (mainstreamRate * 50));
|
||||
}
|
||||
|
||||
private calculateNostalgicScore(books: Book[]): number {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const classicThreshold = currentYear - 30;
|
||||
|
||||
const oldBooks = books.filter(book => {
|
||||
if (!book.metadata?.publishedDate) return false;
|
||||
const pubYear = new Date(book.metadata.publishedDate).getFullYear();
|
||||
return pubYear < classicThreshold;
|
||||
});
|
||||
|
||||
const classicGenres = [
|
||||
'classic', 'literature', 'historical', 'vintage', 'traditional',
|
||||
'heritage', 'timeless', 'canonical', 'masterpiece', 'landmark',
|
||||
'seminal', 'influential', 'groundbreaking', 'pioneering',
|
||||
'classical literature', 'world literature', 'nobel prize',
|
||||
'pulitzer prize', 'booker prize', 'national book award',
|
||||
'literary fiction', 'modernist', 'post-modernist', 'realist',
|
||||
'naturalist', 'romantic', 'victorian', 'edwardian',
|
||||
'renaissance', 'enlightenment', 'ancient', 'medieval',
|
||||
'colonial', 'antebellum', 'gilded age', 'jazz age',
|
||||
'lost generation', 'beat generation', 'harlem renaissance',
|
||||
'golden age', 'silver age', 'folk tales', 'fairy tales',
|
||||
'mythology', 'legends', 'folklore', 'oral tradition',
|
||||
'epic poetry', 'sonnets', 'ballads', 'odes',
|
||||
'dramatic works', 'shakespearean', 'greek tragedy',
|
||||
'roman literature', 'biblical', 'religious classics',
|
||||
'philosophical classics', 'historical classics'
|
||||
];
|
||||
|
||||
const oldBookRate = oldBooks.length / books.length;
|
||||
const classicRate = classicGenres.length / books.length;
|
||||
|
||||
return Math.min(100, (oldBookRate * 60) + (classicRate * 40));
|
||||
}
|
||||
|
||||
private calculateAmbitiousScore(books: Book[]): number {
|
||||
const totalBooks = books.length;
|
||||
const volumeScore = Math.min(40, totalBooks * 2);
|
||||
|
||||
const challengingBooks = books.filter(book =>
|
||||
book.metadata?.pageCount && book.metadata.pageCount > 600
|
||||
);
|
||||
|
||||
const completedChallenging = challengingBooks.filter(book =>
|
||||
book.readStatus === ReadStatus.READ
|
||||
);
|
||||
|
||||
const challengingRate = challengingBooks.length / books.length;
|
||||
const completionRate = challengingBooks.length > 0 ?
|
||||
completedChallenging.length / challengingBooks.length : 0;
|
||||
|
||||
const challengingScore = challengingRate * 35;
|
||||
const completionBonus = completionRate * 25;
|
||||
|
||||
return Math.min(100, volumeScore + challengingScore + completionBonus);
|
||||
}
|
||||
|
||||
private getDefaultProfile(): ReadingDNAProfile {
|
||||
return {
|
||||
adventurous: 50,
|
||||
perfectionist: 50,
|
||||
intellectual: 50,
|
||||
emotional: 50,
|
||||
patient: 50,
|
||||
social: 50,
|
||||
nostalgic: 50,
|
||||
ambitious: 50
|
||||
};
|
||||
}
|
||||
|
||||
private convertToPersonalityInsights(profile: ReadingDNAProfile): PersonalityInsight[] {
|
||||
return [
|
||||
{
|
||||
trait: 'Adventurous',
|
||||
score: profile.adventurous,
|
||||
description: 'You explore diverse genres and experimental content',
|
||||
color: '#ff6b9d'
|
||||
},
|
||||
{
|
||||
trait: 'Perfectionist',
|
||||
score: profile.perfectionist,
|
||||
description: 'You prefer high-quality books and finish what you start',
|
||||
color: '#45aaf2'
|
||||
},
|
||||
{
|
||||
trait: 'Intellectual',
|
||||
score: profile.intellectual,
|
||||
description: 'You gravitate toward complex, educational material',
|
||||
color: '#96f7d2'
|
||||
},
|
||||
{
|
||||
trait: 'Emotional',
|
||||
score: profile.emotional,
|
||||
description: 'You connect emotionally with fiction and personal stories',
|
||||
color: '#feca57'
|
||||
},
|
||||
{
|
||||
trait: 'Patient',
|
||||
score: profile.patient,
|
||||
description: 'You tackle long books and complete series',
|
||||
color: '#ff9ff3'
|
||||
},
|
||||
{
|
||||
trait: 'Social',
|
||||
score: profile.social,
|
||||
description: 'You enjoy popular, widely-discussed books',
|
||||
color: '#54a0ff'
|
||||
},
|
||||
{
|
||||
trait: 'Nostalgic',
|
||||
score: profile.nostalgic,
|
||||
description: 'You appreciate classic literature and older works',
|
||||
color: '#5f27cd'
|
||||
},
|
||||
{
|
||||
trait: 'Ambitious',
|
||||
score: profile.ambitious,
|
||||
description: 'You challenge yourself with volume and difficulty',
|
||||
color: '#00d2d3'
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<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
|
||||
</h3>
|
||||
<p class="chart-description">Your behavioral reading patterns across 8 key dimensions</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
[data]="(chartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="chartOptions"
|
||||
[type]="chartType">
|
||||
</canvas>
|
||||
</div>
|
||||
@if (habitInsights.length > 0) {
|
||||
<div class="habit-insights">
|
||||
<h4>Your Reading Habit Patterns</h4>
|
||||
<div class="insights-grid">
|
||||
@for (insight of habitInsights; track insight.habit) {
|
||||
<div class="insight-card">
|
||||
<div class="insight-header">
|
||||
<span class="insight-trait">{{ insight.habit }}</span>
|
||||
<span class="insight-score" [style.color]="insight.color">{{ insight.score.toFixed(0) }}%</span>
|
||||
</div>
|
||||
<div class="insight-progress">
|
||||
<div class="progress-bar" [style.width.%]="insight.score" [style.background-color]="insight.color"></div>
|
||||
</div>
|
||||
<p class="insight-description">{{ insight.description }}</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
.reading-habits-container {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 0.5rem 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.reading-habits-icon {
|
||||
font-size: 1.5rem;
|
||||
color: rgba(156, 39, 176, 1);
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
position: relative;
|
||||
height: 450px;
|
||||
width: 100%;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.habit-insights {
|
||||
margin-top: 2rem;
|
||||
|
||||
h4 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.1rem;
|
||||
font-weight: 500;
|
||||
margin: 0 0 1rem 0;
|
||||
}
|
||||
|
||||
.insights-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.insight-card {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 8px;
|
||||
padding: 1rem;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
.insight-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.insight-trait {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-weight: 500;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.insight-score {
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.insight-progress {
|
||||
height: 6px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 0.5rem;
|
||||
|
||||
.progress-bar {
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.insight-description {
|
||||
color: var(--text-secondary-color);
|
||||
font-size: 0.85rem;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-wrapper {
|
||||
height: 350px;
|
||||
}
|
||||
|
||||
.habit-insights {
|
||||
.insights-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chart-wrapper {
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
+577
@@ -0,0 +1,577 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {BaseChartDirective} from 'ng2-charts';
|
||||
import {BehaviorSubject, EMPTY, Observable, Subject} from 'rxjs';
|
||||
import {catchError, filter, first, takeUntil} from 'rxjs/operators';
|
||||
import {ChartConfiguration, ChartData} from 'chart.js';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {Book, ReadStatus} from '../../../book/model/book.model';
|
||||
|
||||
interface ReadingHabitsProfile {
|
||||
consistency: number;
|
||||
multitasking: number;
|
||||
completionism: number;
|
||||
exploration: number;
|
||||
organization: number;
|
||||
intensity: number;
|
||||
methodology: number;
|
||||
momentum: number;
|
||||
}
|
||||
|
||||
interface HabitInsight {
|
||||
habit: string;
|
||||
score: number;
|
||||
description: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
type ReadingHabitsChartData = ChartData<'radar', number[], string>;
|
||||
|
||||
@Component({
|
||||
selector: 'app-reading-habits-chart',
|
||||
standalone: true,
|
||||
imports: [CommonModule, BaseChartDirective],
|
||||
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 destroy$ = new Subject<void>();
|
||||
|
||||
public readonly chartType = 'radar' as const;
|
||||
|
||||
public readonly chartOptions: ChartConfiguration<'radar'>['options'] = {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
scales: {
|
||||
r: {
|
||||
beginAtZero: true,
|
||||
min: 0,
|
||||
max: 100,
|
||||
ticks: {
|
||||
stepSize: 20,
|
||||
color: 'rgba(255, 255, 255, 0.6)',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
size: 12
|
||||
},
|
||||
backdropColor: 'transparent',
|
||||
showLabelBackdrop: false
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.2)',
|
||||
circular: true
|
||||
},
|
||||
angleLines: {
|
||||
color: 'rgba(255, 255, 255, 0.3)'
|
||||
},
|
||||
pointLabels: {
|
||||
color: '#ffffff',
|
||||
font: {
|
||||
family: "'Inter', sans-serif",
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
},
|
||||
tooltip: {
|
||||
enabled: true,
|
||||
backgroundColor: 'rgba(0, 0, 0, 0.95)',
|
||||
titleColor: '#ffffff',
|
||||
bodyColor: '#ffffff',
|
||||
borderColor: '#9c27b0',
|
||||
borderWidth: 2,
|
||||
cornerRadius: 8,
|
||||
padding: 16,
|
||||
titleFont: {size: 14, weight: 'bold'},
|
||||
bodyFont: {size: 12},
|
||||
callbacks: {
|
||||
title: (context) => {
|
||||
const label = context[0]?.label || '';
|
||||
return `${label} Habit`;
|
||||
},
|
||||
label: (context) => {
|
||||
const score = context.parsed.r;
|
||||
const insight = this.habitInsights.find(i => i.habit === context.label);
|
||||
|
||||
return [
|
||||
`Score: ${score.toFixed(1)}/100`,
|
||||
'',
|
||||
insight ? insight.description : 'Your reading habit pattern'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
interaction: {
|
||||
intersect: false,
|
||||
mode: 'point'
|
||||
},
|
||||
elements: {
|
||||
line: {
|
||||
borderWidth: 3,
|
||||
tension: 0.1
|
||||
},
|
||||
point: {
|
||||
radius: 5,
|
||||
hoverRadius: 8,
|
||||
borderWidth: 3,
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.8)'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private readonly chartDataSubject = new BehaviorSubject<ReadingHabitsChartData>({
|
||||
labels: [
|
||||
'Consistency', 'Multitasking', 'Completionism', 'Exploration',
|
||||
'Organization', 'Intensity', 'Methodology', 'Momentum'
|
||||
],
|
||||
datasets: []
|
||||
});
|
||||
|
||||
public readonly chartData$: Observable<ReadingHabitsChartData> = this.chartDataSubject.asObservable();
|
||||
public habitInsights: HabitInsight[] = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.bookService.bookState$
|
||||
.pipe(
|
||||
filter(state => state.loaded),
|
||||
first(),
|
||||
catchError((error) => {
|
||||
console.error('Error processing reading habits data:', error);
|
||||
return EMPTY;
|
||||
}),
|
||||
takeUntil(this.destroy$)
|
||||
)
|
||||
.subscribe(() => {
|
||||
const profile = this.calculateReadingHabitsData();
|
||||
this.updateChartData(profile);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
private updateChartData(profile: ReadingHabitsProfile | null): void {
|
||||
try {
|
||||
if (!profile) {
|
||||
this.chartDataSubject.next({
|
||||
labels: [],
|
||||
datasets: []
|
||||
});
|
||||
this.habitInsights = [];
|
||||
return;
|
||||
}
|
||||
|
||||
const data = [
|
||||
profile.consistency,
|
||||
profile.multitasking,
|
||||
profile.completionism,
|
||||
profile.exploration,
|
||||
profile.organization,
|
||||
profile.intensity,
|
||||
profile.methodology,
|
||||
profile.momentum
|
||||
];
|
||||
|
||||
const habitColors = [
|
||||
'#9c27b0', '#e91e63', '#ff5722', '#ff9800',
|
||||
'#ffc107', '#4caf50', '#2196f3', '#673ab7'
|
||||
];
|
||||
|
||||
this.chartDataSubject.next({
|
||||
labels: [
|
||||
'Consistency', 'Multitasking', 'Completionism', 'Exploration',
|
||||
'Organization', 'Intensity', 'Methodology', 'Momentum'
|
||||
],
|
||||
datasets: [{
|
||||
label: 'Reading Habits Profile',
|
||||
data,
|
||||
backgroundColor: 'rgba(156, 39, 176, 0.2)',
|
||||
borderColor: '#9c27b0',
|
||||
borderWidth: 3,
|
||||
pointBackgroundColor: habitColors,
|
||||
pointBorderColor: '#ffffff',
|
||||
pointBorderWidth: 3,
|
||||
pointRadius: 5,
|
||||
pointHoverRadius: 8,
|
||||
fill: true
|
||||
}]
|
||||
});
|
||||
|
||||
this.habitInsights = this.convertToHabitInsights(profile);
|
||||
} catch (error) {
|
||||
console.error('Error updating reading habits chart data:', error);
|
||||
}
|
||||
}
|
||||
|
||||
private calculateReadingHabitsData(): ReadingHabitsProfile | null {
|
||||
const currentState = this.bookService.getCurrentBookState();
|
||||
|
||||
if (!this.isValidBookState(currentState)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.analyzeReadingHabits(currentState.books!);
|
||||
}
|
||||
|
||||
private isValidBookState(state: any): boolean {
|
||||
return state?.loaded && state?.books && Array.isArray(state.books) && state.books.length > 0;
|
||||
}
|
||||
|
||||
private analyzeReadingHabits(books: Book[]): ReadingHabitsProfile {
|
||||
if (books.length === 0) {
|
||||
return this.getDefaultProfile();
|
||||
}
|
||||
|
||||
return {
|
||||
consistency: this.calculateConsistencyScore(books),
|
||||
multitasking: this.calculateMultitaskingScore(books),
|
||||
completionism: this.calculateCompletionismScore(books),
|
||||
exploration: this.calculateExplorationScore(books),
|
||||
organization: this.calculateOrganizationScore(books),
|
||||
intensity: this.calculateIntensityScore(books),
|
||||
methodology: this.calculateMethodologyScore(books),
|
||||
momentum: this.calculateMomentumScore(books)
|
||||
};
|
||||
}
|
||||
|
||||
private calculateConsistencyScore(books: Book[]): number {
|
||||
// ...existing code from service...
|
||||
const booksWithDates = books.filter(book => book.dateFinished || book.addedOn);
|
||||
if (booksWithDates.length === 0) return 30;
|
||||
|
||||
const completedBooks = books.filter(book => book.readStatus === ReadStatus.READ && book.dateFinished);
|
||||
if (completedBooks.length < 2) return 25;
|
||||
|
||||
let consistencyScore = 50;
|
||||
|
||||
const inProgress = books.filter(book =>
|
||||
book.readStatus === ReadStatus.READING || book.readStatus === ReadStatus.RE_READING
|
||||
);
|
||||
const progressRate = inProgress.length / books.length;
|
||||
consistencyScore += progressRate * 30;
|
||||
|
||||
const sortedByCompletion = completedBooks
|
||||
.sort((a, b) => new Date(a.dateFinished!).getTime() - new Date(b.dateFinished!).getTime());
|
||||
|
||||
if (sortedByCompletion.length >= 3) {
|
||||
consistencyScore += 20;
|
||||
}
|
||||
|
||||
return Math.min(100, consistencyScore);
|
||||
}
|
||||
|
||||
private calculateMultitaskingScore(books: Book[]): number {
|
||||
// ...existing code from service...
|
||||
const currentlyReading = books.filter(book => book.readStatus === ReadStatus.READING);
|
||||
const reReading = books.filter(book => book.readStatus === ReadStatus.RE_READING);
|
||||
const activeBooks = currentlyReading.length + reReading.length;
|
||||
|
||||
const booksWithProgress = books.filter(book => {
|
||||
const progress = Math.max(
|
||||
book.epubProgress?.percentage || 0,
|
||||
book.pdfProgress?.percentage || 0,
|
||||
book.cbxProgress?.percentage || 0,
|
||||
book.koreaderProgress?.percentage || 0,
|
||||
book.koboProgress?.percentage || 0
|
||||
);
|
||||
return progress > 0 && progress < 100;
|
||||
});
|
||||
|
||||
const multitaskingScore = Math.min(60, activeBooks * 15);
|
||||
const progressScore = Math.min(40, (booksWithProgress.length / books.length) * 80);
|
||||
|
||||
return Math.min(100, multitaskingScore + progressScore);
|
||||
}
|
||||
|
||||
private calculateCompletionismScore(books: Book[]): number {
|
||||
// ...existing code from service...
|
||||
const completed = books.filter(book => book.readStatus === ReadStatus.READ);
|
||||
const abandoned = books.filter(book => book.readStatus === ReadStatus.ABANDONED);
|
||||
const unfinished = books.filter(book => book.readStatus === ReadStatus.UNREAD || book.readStatus === ReadStatus.UNSET);
|
||||
|
||||
const completionRate = completed.length / (books.length - unfinished.length);
|
||||
const abandonmentRate = abandoned.length / books.length;
|
||||
|
||||
const completionScore = completionRate * 70;
|
||||
const abandonmentPenalty = abandonmentRate * 30;
|
||||
|
||||
return Math.max(0, Math.min(100, completionScore - abandonmentPenalty + 30));
|
||||
}
|
||||
|
||||
private calculateExplorationScore(books: Book[]): number {
|
||||
// ...existing code from service...
|
||||
const authors = new Set<string>();
|
||||
const authorCounts = new Map<string, number>();
|
||||
|
||||
books.forEach(book => {
|
||||
book.metadata?.authors?.forEach(author => {
|
||||
const authorName = author.toLowerCase();
|
||||
authors.add(authorName);
|
||||
authorCounts.set(authorName, (authorCounts.get(authorName) || 0) + 1);
|
||||
});
|
||||
});
|
||||
|
||||
const authorDiversityScore = Math.min(50, authors.size * 2);
|
||||
const maxBooksPerAuthor = Math.max(...Array.from(authorCounts.values()));
|
||||
const concentrationPenalty = Math.max(0, (maxBooksPerAuthor - 3) * 5);
|
||||
|
||||
const years = new Set<number>();
|
||||
books.forEach(book => {
|
||||
if (book.metadata?.publishedDate) {
|
||||
years.add(new Date(book.metadata.publishedDate).getFullYear());
|
||||
}
|
||||
});
|
||||
const temporalScore = Math.min(30, years.size * 2);
|
||||
|
||||
const languages = new Set<string>();
|
||||
books.forEach(book => {
|
||||
if (book.metadata?.language) languages.add(book.metadata.language);
|
||||
});
|
||||
const languageScore = Math.min(20, (languages.size - 1) * 10);
|
||||
|
||||
return Math.max(10, Math.min(100, authorDiversityScore + temporalScore + languageScore - concentrationPenalty));
|
||||
}
|
||||
|
||||
private calculateOrganizationScore(books: Book[]): number {
|
||||
// ...existing code from service...
|
||||
const seriesBooks = books.filter(book => book.metadata?.seriesName && book.metadata?.seriesNumber);
|
||||
const seriesScore = (seriesBooks.length / books.length) * 40;
|
||||
|
||||
const wellOrganizedBooks = books.filter(book => {
|
||||
const metadata = book.metadata;
|
||||
if (!metadata) return false;
|
||||
|
||||
const hasBasicInfo = metadata.title && metadata.authors && metadata.authors.length > 0;
|
||||
const hasDetailedInfo = metadata.publishedDate || metadata.publisher || metadata.isbn10;
|
||||
const hasCategories = metadata.categories && metadata.categories.length > 0;
|
||||
|
||||
return hasBasicInfo && (hasDetailedInfo || hasCategories);
|
||||
});
|
||||
|
||||
const metadataScore = (wellOrganizedBooks.length / books.length) * 35;
|
||||
|
||||
const ratedBooks = books.filter(book => book.personalRating);
|
||||
const ratingScore = (ratedBooks.length / books.length) * 25;
|
||||
|
||||
return Math.min(100, seriesScore + metadataScore + ratingScore);
|
||||
}
|
||||
|
||||
private calculateIntensityScore(books: Book[]): number {
|
||||
// ...existing code from service...
|
||||
const booksWithPages = books.filter(book => book.metadata?.pageCount && book.metadata.pageCount > 0);
|
||||
if (booksWithPages.length === 0) return 40;
|
||||
|
||||
const averagePages = booksWithPages.reduce((sum, book) => sum + (book.metadata?.pageCount || 0), 0) / booksWithPages.length;
|
||||
const intensityFromLength = Math.min(50, averagePages / 8);
|
||||
|
||||
const highProgressBooks = books.filter(book => {
|
||||
const progress = Math.max(
|
||||
book.epubProgress?.percentage || 0,
|
||||
book.pdfProgress?.percentage || 0,
|
||||
book.cbxProgress?.percentage || 0,
|
||||
book.koreaderProgress?.percentage || 0
|
||||
);
|
||||
return progress > 75;
|
||||
});
|
||||
|
||||
const progressScore = (highProgressBooks.length / books.length) * 30;
|
||||
|
||||
const completedSeriesBooks = books.filter(book =>
|
||||
book.metadata?.seriesName && book.readStatus === ReadStatus.READ
|
||||
);
|
||||
const seriesIntensityScore = (completedSeriesBooks.length / books.length) * 20;
|
||||
|
||||
return Math.min(100, intensityFromLength + progressScore + seriesIntensityScore);
|
||||
}
|
||||
|
||||
private calculateMethodologyScore(books: Book[]): number {
|
||||
// ...existing code from service...
|
||||
const seriesBooks = books.filter(book => book.metadata?.seriesName);
|
||||
const seriesGroups = new Map<string, Book[]>();
|
||||
|
||||
seriesBooks.forEach(book => {
|
||||
const seriesName = book.metadata!.seriesName!.toLowerCase();
|
||||
if (!seriesGroups.has(seriesName)) {
|
||||
seriesGroups.set(seriesName, []);
|
||||
}
|
||||
seriesGroups.get(seriesName)!.push(book);
|
||||
});
|
||||
|
||||
let systematicSeriesScore = 0;
|
||||
seriesGroups.forEach(books => {
|
||||
if (books.length > 1) {
|
||||
const orderedBooks = books.filter(book => book.metadata?.seriesNumber).sort((a, b) =>
|
||||
(a.metadata?.seriesNumber || 0) - (b.metadata?.seriesNumber || 0)
|
||||
);
|
||||
if (orderedBooks.length >= 2) {
|
||||
systematicSeriesScore += 20;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const authorBooks = new Map<string, Book[]>();
|
||||
books.forEach(book => {
|
||||
book.metadata?.authors?.forEach(author => {
|
||||
const authorName = author.toLowerCase();
|
||||
if (!authorBooks.has(authorName)) {
|
||||
authorBooks.set(authorName, []);
|
||||
}
|
||||
authorBooks.get(authorName)!.push(book);
|
||||
});
|
||||
});
|
||||
|
||||
const systematicAuthors = Array.from(authorBooks.values()).filter(books => books.length >= 2).length;
|
||||
const authorMethodologyScore = Math.min(30, systematicAuthors * 5);
|
||||
|
||||
const categoryBooks = new Map<string, number>();
|
||||
books.forEach(book => {
|
||||
book.metadata?.categories?.forEach(category => {
|
||||
const cat = category.toLowerCase();
|
||||
categoryBooks.set(cat, (categoryBooks.get(cat) || 0) + 1);
|
||||
});
|
||||
});
|
||||
|
||||
const majorCategories = Array.from(categoryBooks.values()).filter(count => count >= 3).length;
|
||||
const categoryMethodologyScore = Math.min(25, majorCategories * 8);
|
||||
|
||||
const baseMethodologyScore = books.length >= 10 ? 15 : Math.max(5, books.length);
|
||||
|
||||
return Math.min(100, systematicSeriesScore + authorMethodologyScore + categoryMethodologyScore + baseMethodologyScore);
|
||||
}
|
||||
|
||||
private calculateMomentumScore(books: Book[]): number {
|
||||
// ...existing code from service...
|
||||
const completedBooks = books.filter(book => book.readStatus === ReadStatus.READ && book.dateFinished);
|
||||
|
||||
if (completedBooks.length === 0) {
|
||||
const activeBooks = books.filter(book =>
|
||||
book.readStatus === ReadStatus.READING || book.readStatus === ReadStatus.RE_READING
|
||||
);
|
||||
return Math.min(40, activeBooks.length * 10);
|
||||
}
|
||||
|
||||
const sortedBooks = completedBooks.sort((a, b) =>
|
||||
new Date(a.dateFinished!).getTime() - new Date(b.dateFinished!).getTime()
|
||||
);
|
||||
|
||||
let momentumScore = 20;
|
||||
|
||||
const sixMonthsAgo = new Date();
|
||||
sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
|
||||
|
||||
const recentCompletions = sortedBooks.filter(book =>
|
||||
new Date(book.dateFinished!) > sixMonthsAgo
|
||||
);
|
||||
|
||||
momentumScore += Math.min(40, recentCompletions.length * 5);
|
||||
|
||||
const currentlyReading = books.filter(book =>
|
||||
book.readStatus === ReadStatus.READING || book.readStatus === ReadStatus.RE_READING
|
||||
);
|
||||
|
||||
momentumScore += Math.min(25, currentlyReading.length * 8);
|
||||
|
||||
const highProgressBooks = books.filter(book => {
|
||||
const progress = Math.max(
|
||||
book.epubProgress?.percentage || 0,
|
||||
book.pdfProgress?.percentage || 0,
|
||||
book.cbxProgress?.percentage || 0,
|
||||
book.koreaderProgress?.percentage || 0
|
||||
);
|
||||
return progress > 50 && progress < 100;
|
||||
});
|
||||
|
||||
momentumScore += Math.min(15, highProgressBooks.length * 3);
|
||||
|
||||
return Math.min(100, momentumScore);
|
||||
}
|
||||
|
||||
private getDefaultProfile(): ReadingHabitsProfile {
|
||||
return {
|
||||
consistency: 40,
|
||||
multitasking: 30,
|
||||
completionism: 50,
|
||||
exploration: 45,
|
||||
organization: 35,
|
||||
intensity: 40,
|
||||
methodology: 35,
|
||||
momentum: 30
|
||||
};
|
||||
}
|
||||
|
||||
private convertToHabitInsights(profile: ReadingHabitsProfile): HabitInsight[] {
|
||||
return [
|
||||
{
|
||||
habit: 'Consistency',
|
||||
score: profile.consistency,
|
||||
description: 'You maintain regular reading patterns and schedules',
|
||||
color: '#9c27b0'
|
||||
},
|
||||
{
|
||||
habit: 'Multitasking',
|
||||
score: profile.multitasking,
|
||||
description: 'You juggle multiple books simultaneously',
|
||||
color: '#e91e63'
|
||||
},
|
||||
{
|
||||
habit: 'Completionism',
|
||||
score: profile.completionism,
|
||||
description: 'You finish books rather than abandon them',
|
||||
color: '#ff5722'
|
||||
},
|
||||
{
|
||||
habit: 'Exploration',
|
||||
score: profile.exploration,
|
||||
description: 'You actively seek out new authors and genres',
|
||||
color: '#ff9800'
|
||||
},
|
||||
{
|
||||
habit: 'Organization',
|
||||
score: profile.organization,
|
||||
description: 'You maintain systematic book tracking and metadata',
|
||||
color: '#ffc107'
|
||||
},
|
||||
{
|
||||
habit: 'Intensity',
|
||||
score: profile.intensity,
|
||||
description: 'You prefer longer, immersive reading sessions',
|
||||
color: '#4caf50'
|
||||
},
|
||||
{
|
||||
habit: 'Methodology',
|
||||
score: profile.methodology,
|
||||
description: 'You follow systematic approaches to book selection',
|
||||
color: '#2196f3'
|
||||
},
|
||||
{
|
||||
habit: 'Momentum',
|
||||
score: profile.momentum,
|
||||
description: 'You maintain active reading streaks and continuity',
|
||||
color: '#673ab7'
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -3,7 +3,7 @@
|
||||
<div class="chart-title">
|
||||
<h3>
|
||||
<i class="pi pi-calendar heatmap-title-icon"></i>
|
||||
{{ getTitle() }}
|
||||
Reading Session Activity
|
||||
</h3>
|
||||
<p class="chart-description">Daily overview of your reading sessions across the year</p>
|
||||
</div>
|
||||
@@ -22,6 +22,7 @@
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="header-spacer"></div>
|
||||
</div>
|
||||
<div class="chart-wrapper">
|
||||
<canvas baseChart
|
||||
|
||||
+59
-43
@@ -3,15 +3,13 @@
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
gap: 1rem;
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
@@ -26,47 +24,51 @@
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.year-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.year-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
.year-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
justify-self: center;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-color: rgba(255, 255, 255, 0.3);
|
||||
transform: translateY(-1px);
|
||||
.year-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 0.6rem 0.6rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-color: rgba(255, 255, 255, 0.3);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
.current-year {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
min-width: 4.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.current-year {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
min-width: 4.5rem;
|
||||
text-align: center;
|
||||
.header-spacer {
|
||||
// Empty spacer for grid layout balance
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,19 +86,33 @@
|
||||
|
||||
.heatmap-title-icon {
|
||||
font-size: 1.5rem;
|
||||
color: var(--primary-color);
|
||||
color: rgba(59, 130, 246, 1);
|
||||
vertical-align: middle;
|
||||
margin-right: 0.25em;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.chart-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.75rem;
|
||||
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
|
||||
.year-selector {
|
||||
justify-self: stretch;
|
||||
justify-content: center;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.header-spacer {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,11 +121,11 @@
|
||||
.chart-header {
|
||||
.chart-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.chart-description {
|
||||
font-size: 0.85rem;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +137,7 @@
|
||||
}
|
||||
|
||||
.year-nav-btn {
|
||||
padding: 0.4rem 0.6rem;
|
||||
padding: 0.6rem 0.6rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-9
@@ -28,7 +28,6 @@ type SessionHeatmapChartData = ChartData<'matrix', MatrixDataPoint[], string>;
|
||||
})
|
||||
export class ReadingSessionHeatmapComponent implements OnInit, OnDestroy {
|
||||
@Input() initialYear: number = new Date().getFullYear();
|
||||
@Input() userName: string = '';
|
||||
|
||||
public currentYear: number = new Date().getFullYear();
|
||||
public readonly chartType = 'matrix' as const;
|
||||
@@ -212,8 +211,8 @@ export class ReadingSessionHeatmapComponent implements OnInit, OnDestroy {
|
||||
if (!point?.v) return 'rgba(255, 255, 255, 0.05)';
|
||||
|
||||
const intensity = point.v / this.maxSessionCount;
|
||||
const alpha = Math.max(0.2, Math.min(1.0, intensity * 0.8 + 0.2));
|
||||
return `rgba(106, 176, 76, ${alpha})`;
|
||||
const alpha = Math.max(0.3, Math.min(0.9, intensity * 0.6 + 0.3));
|
||||
return `rgba(59, 130, 246, ${alpha})`;
|
||||
},
|
||||
borderColor: 'rgba(255, 255, 255, 0.1)',
|
||||
borderWidth: 1
|
||||
@@ -226,10 +225,4 @@ export class ReadingSessionHeatmapComponent implements OnInit, OnDestroy {
|
||||
date.setDate(date.getDate() + (week * 7) - date.getDay());
|
||||
return date;
|
||||
}
|
||||
|
||||
public getTitle(): string {
|
||||
return this.userName
|
||||
? `${this.userName}'s Reading Session Activity`
|
||||
: 'Reading Session Activity';
|
||||
}
|
||||
}
|
||||
|
||||
+23
-3
@@ -3,18 +3,18 @@
|
||||
<div class="header-title">
|
||||
<h3>
|
||||
<i class="pi pi-clock timeline-title-icon"></i>
|
||||
{{ getTitle() }}
|
||||
Reading Session Timeline
|
||||
</h3>
|
||||
<p class="timeline-subtitle">Weekly overview of your reading sessions and patterns</p>
|
||||
</div>
|
||||
<div class="week-selector">
|
||||
<div class="week-info">
|
||||
<button type="button"
|
||||
class="week-nav-btn"
|
||||
(click)="changeWeek(-1)"
|
||||
title="Previous week">
|
||||
<i class="pi pi-chevron-left"></i>
|
||||
</button>
|
||||
<div class="week-info">
|
||||
<div class="week-display">
|
||||
<span class="week-label">Week {{ currentWeek }}</span>
|
||||
<span class="week-dates">{{ getWeekDateRange() }}</span>
|
||||
</div>
|
||||
@@ -25,6 +25,26 @@
|
||||
<i class="pi pi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="filter-controls">
|
||||
<p-select
|
||||
[options]="yearOptions"
|
||||
[(ngModel)]="currentYear"
|
||||
(onChange)="onYearChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Year"
|
||||
[style]="{'min-width': '120px'}">
|
||||
</p-select>
|
||||
<p-select
|
||||
[options]="weekOptions"
|
||||
[(ngModel)]="currentWeek"
|
||||
(onChange)="onWeekChange()"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="Select Week"
|
||||
[style]="{'min-width': '120px'}">
|
||||
</p-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="timeline-content">
|
||||
|
||||
+173
-42
@@ -3,15 +3,13 @@
|
||||
}
|
||||
|
||||
.timeline-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
gap: 1rem;
|
||||
|
||||
.header-title {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
color: var(--text-color, #ffffff);
|
||||
font-size: 1.25rem;
|
||||
@@ -27,17 +25,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
.week-selector {
|
||||
.week-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
flex-shrink: 0;
|
||||
justify-self: center;
|
||||
|
||||
.week-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
padding: 0.6rem 0.6rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
@@ -60,26 +57,96 @@
|
||||
}
|
||||
}
|
||||
|
||||
.week-info {
|
||||
.week-display {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
min-width: 100px;
|
||||
min-width: 120px;
|
||||
|
||||
.week-label {
|
||||
font-size: 1.125rem;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
white-space: nowrap;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.week-dates {
|
||||
font-size: 0.8rem;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary-color);
|
||||
white-space: nowrap;
|
||||
margin-top: 0.1rem;
|
||||
line-height: 1.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
justify-self: end;
|
||||
}
|
||||
}
|
||||
|
||||
.week-info-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
padding: 0.75rem;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
|
||||
.week-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 6px;
|
||||
padding: 0.6rem 6rem;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-color: rgba(255, 255, 255, 0.3);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.week-display {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
min-width: 150px;
|
||||
|
||||
.week-label {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: #ffffff;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.week-dates {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-secondary-color);
|
||||
white-space: nowrap;
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.timeline-content {
|
||||
@@ -153,7 +220,7 @@
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
border-radius: 4px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
min-height: 40px;
|
||||
min-height: 35px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,29 +255,32 @@
|
||||
box-sizing: border-box;
|
||||
|
||||
&.book-type-epub, &.book-type-default {
|
||||
background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
|
||||
box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
|
||||
background: rgba(59, 130, 246, 0.8);
|
||||
border: 1px solid rgba(59, 130, 246, 1);
|
||||
box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(74, 144, 226, 0.5);
|
||||
box-shadow: 0 4px 8px rgba(59, 130, 246, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
&.book-type-pdf {
|
||||
background: linear-gradient(135deg, #e24a4a 0%, #bd3535 100%);
|
||||
box-shadow: 0 2px 8px rgba(226, 74, 74, 0.3);
|
||||
background: rgba(239, 68, 68, 0.8);
|
||||
border: 1px solid rgba(239, 68, 68, 1);
|
||||
box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(226, 74, 74, 0.5);
|
||||
box-shadow: 0 4px 8px rgba(239, 68, 68, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
&.book-type-cbx {
|
||||
background: linear-gradient(135deg, #e2b74a 0%, #bd9635 100%);
|
||||
box-shadow: 0 2px 8px rgba(226, 183, 74, 0.3);
|
||||
background: rgba(255, 193, 7, 0.8);
|
||||
border: 1px solid rgba(255, 193, 7, 1);
|
||||
box-shadow: 0 2px 4px rgba(255, 193, 7, 0.3);
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 4px 16px rgba(226, 183, 74, 0.5);
|
||||
box-shadow: 0 4px 8px rgba(255, 193, 7, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +381,7 @@
|
||||
|
||||
i {
|
||||
font-size: 1.1rem;
|
||||
color: #4a90e2;
|
||||
color: rgba(239, 68, 68, 1);
|
||||
}
|
||||
|
||||
.tooltip-title {
|
||||
@@ -384,22 +454,77 @@
|
||||
|
||||
.timeline-title-icon {
|
||||
font-size: 1.5rem;
|
||||
color: var(--primary-color);
|
||||
color: rgba(239, 68, 68, 1);
|
||||
vertical-align: middle;
|
||||
margin-right: 0.25em;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.timeline-header {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.75rem;
|
||||
|
||||
.header-title {
|
||||
grid-column: 1;
|
||||
}
|
||||
|
||||
.week-info {
|
||||
grid-column: 1;
|
||||
justify-self: stretch;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
grid-column: 1;
|
||||
justify-self: stretch;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0.5rem;
|
||||
|
||||
::ng-deep p-select {
|
||||
width: 100%;
|
||||
|
||||
.p-select {
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.timeline-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
.header-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.week-selector {
|
||||
justify-content: center;
|
||||
margin-top: 0.5rem;
|
||||
.timeline-subtitle {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
}
|
||||
|
||||
.week-info {
|
||||
min-width: 120px;
|
||||
.week-info {
|
||||
padding: 0.6rem 0.6rem;
|
||||
|
||||
.week-display {
|
||||
min-width: 100px;
|
||||
|
||||
.week-label {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.week-dates {
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
}
|
||||
|
||||
.week-nav-btn {
|
||||
padding: 0.35rem 0.5rem;
|
||||
|
||||
i {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -467,24 +592,30 @@
|
||||
.timeline-header {
|
||||
.header-title {
|
||||
h3 {
|
||||
font-size: 1.1rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.timeline-subtitle {
|
||||
font-size: 0.85rem;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.week-selector {
|
||||
.filter-controls {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.week-info {
|
||||
.week-label {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
.week-display {
|
||||
min-width: 90px;
|
||||
|
||||
.week-nav-btn {
|
||||
padding: 0.4rem 0.6rem;
|
||||
.week-label {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.week-dates {
|
||||
font-size: 0.65rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+64
-13
@@ -3,6 +3,10 @@ import {CommonModule} from '@angular/common';
|
||||
import {ReadingSessionTimelineResponse, UserStatsService} from '../../../settings/user-management/user-stats.service';
|
||||
import {UrlHelperService} from '../../../../shared/service/url-helper.service';
|
||||
import {BookType} from '../../../book/model/book.model';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {of} from 'rxjs';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
interface ReadingSession {
|
||||
startTime: Date;
|
||||
@@ -37,14 +41,13 @@ interface DayTimeline {
|
||||
@Component({
|
||||
selector: 'app-reading-session-timeline',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, Select, FormsModule],
|
||||
templateUrl: './reading-session-timeline.component.html',
|
||||
styleUrls: ['./reading-session-timeline.component.scss']
|
||||
})
|
||||
export class ReadingSessionTimelineComponent implements OnInit {
|
||||
@Input() initialYear: number = new Date().getFullYear();
|
||||
@Input() weekNumber: number = this.getCurrentWeekNumber();
|
||||
@Input() userName: string = '';
|
||||
|
||||
private userStatsService = inject(UserStatsService);
|
||||
private urlHelperService = inject(UrlHelperService);
|
||||
@@ -54,14 +57,52 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
public timelineData: DayTimeline[] = [];
|
||||
public currentYear: number = new Date().getFullYear();
|
||||
public currentWeek: number = this.getCurrentWeekNumber();
|
||||
public currentMonth: number = new Date().getMonth() + 1;
|
||||
|
||||
public yearOptions: { label: string; value: number }[] = [];
|
||||
public weekOptions: { label: string; value: number }[] = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.currentYear = this.initialYear;
|
||||
this.currentWeek = this.weekNumber;
|
||||
this.updateCurrentMonth();
|
||||
this.initializeYearOptions();
|
||||
this.updateWeekOptions();
|
||||
this.initializeHourLabels();
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
private initializeYearOptions(): void {
|
||||
const currentYear = new Date().getFullYear();
|
||||
this.yearOptions = [];
|
||||
for (let year = currentYear; year >= currentYear - 10; year--) {
|
||||
this.yearOptions.push({ label: year.toString(), value: year });
|
||||
}
|
||||
}
|
||||
|
||||
private updateWeekOptions(): void {
|
||||
const weeksInYear = this.getWeeksInYear(this.currentYear);
|
||||
this.weekOptions = [];
|
||||
for (let week = 1; week <= weeksInYear; week++) {
|
||||
this.weekOptions.push({ label: `Week ${week}`, value: week });
|
||||
}
|
||||
}
|
||||
|
||||
public onYearChange(): void {
|
||||
this.updateWeekOptions();
|
||||
const maxWeeks = this.getWeeksInYear(this.currentYear);
|
||||
if (this.currentWeek > maxWeeks) {
|
||||
this.currentWeek = maxWeeks;
|
||||
}
|
||||
this.updateCurrentMonth();
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
public onWeekChange(): void {
|
||||
this.updateCurrentMonth();
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
private initializeHourLabels(): void {
|
||||
for (let i = 0; i < 24; i++) {
|
||||
const hour = i === 0 ? 12 : i > 12 ? i - 12 : i;
|
||||
@@ -71,15 +112,17 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
}
|
||||
|
||||
private loadReadingSessions(): void {
|
||||
this.userStatsService.getTimelineForWeek(this.currentYear, this.currentWeek)
|
||||
this.userStatsService.getTimelineForWeek(this.currentYear, this.currentMonth, this.currentWeek)
|
||||
.pipe(
|
||||
catchError((error) => {
|
||||
console.error('Error loading reading sessions:', error);
|
||||
return of([]);
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
const sessions = this.convertResponseToSessions(response);
|
||||
this.processSessionData(sessions);
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Error loading reading sessions:', error);
|
||||
this.processSessionData([]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -119,14 +162,28 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
if (this.currentWeek > weeksInYear) {
|
||||
this.currentWeek = 1;
|
||||
this.currentYear++;
|
||||
this.updateWeekOptions();
|
||||
} else if (this.currentWeek < 1) {
|
||||
this.currentYear--;
|
||||
this.currentWeek = this.getWeeksInYear(this.currentYear);
|
||||
this.updateWeekOptions();
|
||||
}
|
||||
|
||||
this.updateCurrentMonth();
|
||||
this.loadReadingSessions();
|
||||
}
|
||||
|
||||
private updateCurrentMonth(): void {
|
||||
const startOfYear = new Date(this.currentYear, 0, 1);
|
||||
const daysToAdd = (this.currentWeek - 1) * 7;
|
||||
const weekStart = new Date(startOfYear.getTime() + daysToAdd * 24 * 60 * 60 * 1000);
|
||||
|
||||
const dayOfWeek = weekStart.getDay();
|
||||
weekStart.setDate(weekStart.getDate() - dayOfWeek);
|
||||
|
||||
this.currentMonth = weekStart.getMonth() + 1;
|
||||
}
|
||||
|
||||
private getWeeksInYear(year: number): number {
|
||||
const lastDay = new Date(year, 11, 31);
|
||||
const startOfYear = new Date(year, 0, 1);
|
||||
@@ -325,10 +382,4 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
public getCoverUrl(bookId: number): string {
|
||||
return this.urlHelperService.getThumbnailUrl1(bookId);
|
||||
}
|
||||
|
||||
public getTitle(): string {
|
||||
return this.userName
|
||||
? `${this.userName}'s Reading Session Timeline`
|
||||
: 'Reading Session Timeline';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,70 +328,6 @@
|
||||
</canvas>
|
||||
</div>
|
||||
}
|
||||
@case ('readingDNA') {
|
||||
<h3>Your Reading DNA Profile</h3>
|
||||
<div class="chart-description">
|
||||
Discover your unique reading personality based on behavioral patterns and preferences
|
||||
</div>
|
||||
<div class="chart-wrapper reading-dna-chart">
|
||||
<canvas baseChart
|
||||
[data]="(readingDNAChartService.readingDNAChartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="readingDNAChartService.readingDNAChartOptions"
|
||||
[type]="readingDNAChartService.readingDNAChartType">
|
||||
</canvas>
|
||||
</div>
|
||||
<div class="dna-insights">
|
||||
@if ((readingDNAChartService.readingDNAChartData$ | async)?.datasets?.[0]?.data?.length) {
|
||||
<div class="insights-grid">
|
||||
@for (insight of readingDNAChartService.getPersonalityInsights(); track trackByTrait($index, insight)) {
|
||||
<div class="insight-card">
|
||||
<div class="insight-header">
|
||||
<div class="trait-dot" [style.background-color]="insight.color"></div>
|
||||
<span class="trait-name">{{ insight.trait }}</span>
|
||||
<span class="trait-score">{{ insight.score.toFixed(0) }}%</span>
|
||||
</div>
|
||||
<div class="insight-bar">
|
||||
<div class="insight-fill" [style.width.%]="insight.score" [style.background-color]="insight.color"></div>
|
||||
</div>
|
||||
<p class="insight-description">{{ insight.description }}</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@case ('readingHabits') {
|
||||
<h3>Reading Habits Analysis</h3>
|
||||
<div class="chart-description">
|
||||
Analyze your behavioral reading patterns, routines, and systematic approaches
|
||||
</div>
|
||||
<div class="chart-wrapper reading-habits-chart">
|
||||
<canvas baseChart
|
||||
[data]="(readingHabitsChartService.readingHabitsChartData$ | async) ?? {labels: [], datasets: []}"
|
||||
[options]="readingHabitsChartService.readingHabitsChartOptions"
|
||||
[type]="readingHabitsChartService.readingHabitsChartType">
|
||||
</canvas>
|
||||
</div>
|
||||
<div class="dna-insights">
|
||||
@if ((readingHabitsChartService.readingHabitsChartData$ | async)?.datasets?.[0]?.data?.length) {
|
||||
<div class="insights-grid">
|
||||
@for (habit of readingHabitsChartService.getHabitInsights(); track trackByHabit($index, habit)) {
|
||||
<div class="insight-card">
|
||||
<div class="insight-header">
|
||||
<div class="trait-dot" [style.background-color]="habit.color"></div>
|
||||
<span class="trait-name">{{ habit.habit }}</span>
|
||||
<span class="trait-score">{{ habit.score.toFixed(0) }}%</span>
|
||||
</div>
|
||||
<div class="insight-bar">
|
||||
<div class="insight-fill" [style.width.%]="habit.score" [style.background-color]="habit.color"></div>
|
||||
</div>
|
||||
<p class="insight-description">{{ habit.description }}</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -715,7 +715,7 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
gap: 0.5rem;
|
||||
|
||||
.year-nav-btn {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
@@ -908,7 +908,7 @@
|
||||
&.publisher-chart,
|
||||
&.author-rating-chart,
|
||||
&.book-size-chart {
|
||||
height: 350px;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
&.year-chart,
|
||||
|
||||
@@ -28,8 +28,6 @@ import {BookSizeChartService} from '../service/book-size-chart.service';
|
||||
import {ReadingVelocityTimelineChartService} from '../service/reading-velocity-timeline-chart.service';
|
||||
import {MonthlyReadingPatternsChartService} from '../service/monthly-reading-patterns-chart.service';
|
||||
import {TopSeriesChartService} from '../service/top-series-chart.service';
|
||||
import {ReadingDNAChartService} from '../service/reading-dna-chart.service';
|
||||
import {ReadingHabitsChartService} from '../service/reading-habits-chart.service';
|
||||
import {ChartConfig, ChartConfigService} from '../service/chart-config.service';
|
||||
|
||||
@Component({
|
||||
@@ -67,8 +65,6 @@ export class StatsComponent implements OnInit, OnDestroy {
|
||||
protected readonly readingVelocityTimelineChartService = inject(ReadingVelocityTimelineChartService);
|
||||
protected readonly monthlyReadingPatternsChartService = inject(MonthlyReadingPatternsChartService);
|
||||
protected readonly topSeriesChartService = inject(TopSeriesChartService);
|
||||
protected readonly readingDNAChartService = inject(ReadingDNAChartService);
|
||||
protected readonly readingHabitsChartService = inject(ReadingHabitsChartService);
|
||||
protected readonly chartConfigService = inject(ChartConfigService);
|
||||
private readonly pageTitle = inject(PageTitleService);
|
||||
|
||||
|
||||
@@ -1,11 +1,99 @@
|
||||
<div class="user-stats-container">
|
||||
<div class="charts-container">
|
||||
<div class="chart-card">
|
||||
<app-reading-session-heatmap [initialYear]="currentYear" [userName]="userName"></app-reading-session-heatmap>
|
||||
</div>
|
||||
|
||||
<div class="chart-card">
|
||||
<app-reading-session-timeline [initialYear]="currentYear" [userName]="userName"></app-reading-session-timeline>
|
||||
<div class="header-section">
|
||||
<div class="header-content">
|
||||
<div class="greeting">
|
||||
<i class="pi pi-chart-line"></i>
|
||||
<h2>{{ userName }}'s Reading Statistics</h2>
|
||||
</div>
|
||||
<button class="config-toggle-btn" (click)="toggleConfigPanel()">
|
||||
<i class="pi pi-cog"></i>
|
||||
<span>Customize Layout</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-dialog
|
||||
[(visible)]="showConfigPanel"
|
||||
[modal]="true"
|
||||
[draggable]="false"
|
||||
[resizable]="false"
|
||||
[style]="{width: '600px', maxWidth: '90vw'}"
|
||||
styleClass="config-dialog"
|
||||
header="Chart Configuration">
|
||||
|
||||
<div class="config-dialog-content">
|
||||
<div class="config-list" cdkDropList (cdkDropListDropped)="drop($event)">
|
||||
@for (chart of charts; track chart.id) {
|
||||
<div class="config-item" cdkDrag>
|
||||
<div class="drag-handle" cdkDragHandle>
|
||||
<i class="pi pi-bars"></i>
|
||||
</div>
|
||||
<span class="chart-title">{{ chart.title }}</span>
|
||||
<button
|
||||
class="visibility-toggle"
|
||||
(click)="toggleChart(chart.id)"
|
||||
[class.disabled]="!chart.enabled">
|
||||
<i [class]="chart.enabled ? 'pi pi-eye' : 'pi pi-eye-slash'"></i>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template pTemplate="footer">
|
||||
<p-button class="reset-btn" (click)="resetLayout()" severity="danger">
|
||||
<i class="pi pi-refresh"></i>
|
||||
<span>Reset Layout</span>
|
||||
</p-button>
|
||||
<p-button class="hide-all-btn" (click)="hideAllCharts()" severity="secondary">
|
||||
<i class="pi pi-eye-slash"></i>
|
||||
<span>Hide All</span>
|
||||
</p-button>
|
||||
<p-button class="show-all-btn" (click)="showAllCharts()" severity="secondary">
|
||||
<i class="pi pi-eye"></i>
|
||||
<span>Show All</span>
|
||||
</p-button>
|
||||
<p-button class="close-btn" (click)="toggleConfigPanel()" severity="secondary">
|
||||
<span>Close</span>
|
||||
</p-button>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
|
||||
<!-- Charts Container -->
|
||||
<div class="charts-container" cdkDropList (cdkDropListDropped)="drop($event)">
|
||||
@for (chart of visibleCharts; track chart.id) {
|
||||
<div class="chart-card" [class]="chart.sizeClass" cdkDrag>
|
||||
<div class="chart-drag-handle" cdkDragHandle>
|
||||
<i class="pi pi-arrows-alt"></i>
|
||||
</div>
|
||||
|
||||
@switch (chart.id) {
|
||||
@case ('heatmap') {
|
||||
<app-reading-session-heatmap [initialYear]="currentYear"></app-reading-session-heatmap>
|
||||
}
|
||||
@case ('timeline') {
|
||||
<app-reading-session-timeline [initialYear]="currentYear"></app-reading-session-timeline>
|
||||
}
|
||||
@case ('genre-stats') {
|
||||
<app-genre-stats-chart></app-genre-stats-chart>
|
||||
}
|
||||
@case ('completion-timeline') {
|
||||
<app-completion-timeline-chart [initialYear]="currentYear"></app-completion-timeline-chart>
|
||||
}
|
||||
@case ('favorite-days') {
|
||||
<app-favorite-days-chart></app-favorite-days-chart>
|
||||
}
|
||||
@case ('peak-hours') {
|
||||
<app-peak-hours-chart></app-peak-hours-chart>
|
||||
}
|
||||
@case ('reading-dna') {
|
||||
<app-reading-dna-chart></app-reading-dna-chart>
|
||||
}
|
||||
@case ('reading-habits') {
|
||||
<app-reading-habits-chart></app-reading-habits-chart>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+317
-11
@@ -9,16 +9,12 @@
|
||||
.header-section {
|
||||
background: var(--card-background);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
padding: 1rem;
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 2rem;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
transition: all 0.3s ease;
|
||||
width: fit-content;
|
||||
max-width: 100%;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
@@ -27,16 +23,19 @@
|
||||
|
||||
.header-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
gap: 2rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
|
||||
i {
|
||||
font-size: 1.5rem;
|
||||
@@ -51,12 +50,147 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.config-header {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 1.25rem;
|
||||
background: var(--card-background);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
color: var(--text-color);
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
font-size: 0.9rem;
|
||||
white-space: nowrap;
|
||||
|
||||
&:hover {
|
||||
background: var(--p-primary-color);
|
||||
color: white;
|
||||
border-color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
i {
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
// Dialog styles
|
||||
::ng-deep .config-dialog {
|
||||
.p-dialog-header {
|
||||
border-bottom: 1px solid var(--p-content-border-color);
|
||||
}
|
||||
|
||||
.p-dialog-content {
|
||||
background: var(--card-background);
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.p-dialog-footer {
|
||||
border-top: 1px solid var(--p-content-border-color);
|
||||
padding: 1rem 1.5rem;
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
justify-content: flex-end;
|
||||
|
||||
.reset-btn {
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.hide-all-btn,
|
||||
.show-all-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.config-dialog-content {
|
||||
.config-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.config-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem 1.25rem;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 8px;
|
||||
cursor: move;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
.drag-handle {
|
||||
cursor: grab;
|
||||
color: var(--text-color-secondary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
&:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
}
|
||||
|
||||
.chart-title {
|
||||
flex: 1;
|
||||
color: var(--text-color);
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.visibility-toggle {
|
||||
padding: 0.5rem;
|
||||
background: transparent;
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
border-radius: 6px;
|
||||
color: var(--p-primary-color);
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: var(--p-primary-color);
|
||||
color: white;
|
||||
border-color: var(--p-primary-color);
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
color: var(--text-color-secondary);
|
||||
opacity: 0.5;
|
||||
|
||||
&:hover {
|
||||
background: transparent;
|
||||
color: var(--text-color-secondary);
|
||||
border-color: var(--p-content-border-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.charts-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(12, 1fr);
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
@@ -67,11 +201,77 @@
|
||||
border: 1px solid var(--p-content-border-color);
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
||||
|
||||
.chart-drag-handle {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.chart-drag-handle {
|
||||
position: absolute;
|
||||
top: 0.5rem;
|
||||
right: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
border-radius: 6px;
|
||||
cursor: grab;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease;
|
||||
z-index: 10;
|
||||
color: var(--text-color);
|
||||
|
||||
&:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
&.chart-small-square {
|
||||
grid-column: span 3;
|
||||
}
|
||||
|
||||
&.chart-small {
|
||||
grid-column: span 4;
|
||||
}
|
||||
|
||||
&.chart-medium {
|
||||
grid-column: span 6;
|
||||
}
|
||||
|
||||
&.chart-large {
|
||||
grid-column: span 8;
|
||||
}
|
||||
|
||||
&.chart-wide {
|
||||
grid-column: span 9;
|
||||
}
|
||||
|
||||
&.chart-full {
|
||||
grid-column: span 12;
|
||||
}
|
||||
}
|
||||
|
||||
.cdk-drag-preview {
|
||||
opacity: 0.8;
|
||||
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.cdk-drag-placeholder {
|
||||
opacity: 0.3;
|
||||
border: 2px dashed var(--p-primary-color);
|
||||
}
|
||||
|
||||
.cdk-drag-animating {
|
||||
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
@@ -79,10 +279,60 @@
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
span {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
::ng-deep .config-dialog {
|
||||
.p-dialog-content {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.p_dialog_footer {
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
|
||||
.reset-btn {
|
||||
margin-right: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.config-panel {
|
||||
padding: 1rem;
|
||||
|
||||
.config-panel-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 1rem;
|
||||
|
||||
.reset-btn {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.header-section {
|
||||
padding: 1rem;
|
||||
|
||||
.header-content {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
position: static;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
position: static;
|
||||
transform: none;
|
||||
|
||||
i {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
@@ -94,8 +344,36 @@
|
||||
}
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
margin-left: 0;
|
||||
|
||||
span {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
|
||||
.charts-container {
|
||||
grid-template-columns: repeat(6, 1fr);
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
padding: 1rem;
|
||||
|
||||
.chart-drag-handle {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
&.chart-small-square,
|
||||
&.chart-small,
|
||||
&.chart-medium,
|
||||
&.chart-large,
|
||||
&.chart-wide,
|
||||
&.chart-full {
|
||||
grid-column: span 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +382,20 @@
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.config-toggle-btn {
|
||||
padding: 0.5rem 0.75rem;
|
||||
}
|
||||
|
||||
::ng-deep .config-dialog {
|
||||
.p-dialog-content {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.config-panel {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.header-section {
|
||||
padding: 0.75rem;
|
||||
|
||||
@@ -121,7 +413,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
.charts-container {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
padding: 0.75rem;
|
||||
|
||||
&.chart-small-square,
|
||||
&.chart-small,
|
||||
&.chart-medium,
|
||||
&.chart-large,
|
||||
&.chart-wide,
|
||||
&.chart-full {
|
||||
grid-column: span 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,38 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {Subject} from 'rxjs';
|
||||
import {CdkDragDrop, DragDropModule} from '@angular/cdk/drag-drop';
|
||||
import {DialogModule} from 'primeng/dialog';
|
||||
import {ButtonModule} from 'primeng/button';
|
||||
import {ReadingSessionHeatmapComponent} from '../reading-session-heatmap/reading-session-heatmap.component';
|
||||
import {ReadingSessionTimelineComponent} from '../reading-session-timeline/reading-session-timeline.component';
|
||||
import {GenreStatsChartComponent} from '../genre-stats-chart/genre-stats-chart.component';
|
||||
import {CompletionTimelineChartComponent} from '../completion-timeline-chart/completion-timeline-chart.component';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
|
||||
interface UserChartConfig {
|
||||
id: string;
|
||||
component: any;
|
||||
enabled: boolean;
|
||||
order: number;
|
||||
}
|
||||
import {FavoriteDaysChartComponent} from '../favorite-days-chart/favorite-days-chart.component';
|
||||
import {PeakHoursChartComponent} from '../peak-hours-chart/peak-hours-chart.component';
|
||||
import {ReadingDNAChartComponent} from '../reading-dna-chart/reading-dna-chart.component';
|
||||
import {ReadingHabitsChartComponent} from '../reading-habits-chart/reading-habits-chart.component';
|
||||
import {UserChartConfig, UserChartConfigService} from '../../service/user-chart-config.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-stats',
|
||||
standalone: true,
|
||||
imports: [CommonModule, ReadingSessionHeatmapComponent, ReadingSessionTimelineComponent],
|
||||
imports: [
|
||||
CommonModule,
|
||||
DragDropModule,
|
||||
DialogModule,
|
||||
ButtonModule,
|
||||
ReadingSessionHeatmapComponent,
|
||||
ReadingSessionTimelineComponent,
|
||||
GenreStatsChartComponent,
|
||||
CompletionTimelineChartComponent,
|
||||
FavoriteDaysChartComponent,
|
||||
PeakHoursChartComponent,
|
||||
ReadingDNAChartComponent,
|
||||
ReadingHabitsChartComponent
|
||||
],
|
||||
templateUrl: './user-stats.component.html',
|
||||
styleUrls: ['./user-stats.component.scss']
|
||||
})
|
||||
@@ -24,10 +40,22 @@ export class UserStatsComponent implements OnInit, OnDestroy {
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
|
||||
private userService = inject(UserService);
|
||||
private chartConfigService = inject(UserChartConfigService);
|
||||
|
||||
public currentYear = new Date().getFullYear();
|
||||
public userName: string = '';
|
||||
public showConfigPanel = false;
|
||||
public charts: UserChartConfig[] = [];
|
||||
public visibleCharts: UserChartConfig[] = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.chartConfigService.charts$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(charts => {
|
||||
this.charts = charts;
|
||||
this.visibleCharts = this.chartConfigService.getVisibleCharts();
|
||||
});
|
||||
|
||||
this.userService.userState$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(state => {
|
||||
@@ -41,4 +69,36 @@ export class UserStatsComponent implements OnInit, OnDestroy {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
}
|
||||
|
||||
toggleChart(chartId: string): void {
|
||||
this.chartConfigService.toggleChart(chartId);
|
||||
}
|
||||
|
||||
drop(event: CdkDragDrop<UserChartConfig[]>): void {
|
||||
this.chartConfigService.reorderCharts(event.previousIndex, event.currentIndex);
|
||||
}
|
||||
|
||||
toggleConfigPanel(): void {
|
||||
this.showConfigPanel = !this.showConfigPanel;
|
||||
}
|
||||
|
||||
resetLayout(): void {
|
||||
this.chartConfigService.resetLayout();
|
||||
}
|
||||
|
||||
hideAllCharts(): void {
|
||||
this.charts.forEach(chart => {
|
||||
if (chart.enabled) {
|
||||
this.chartConfigService.toggleChart(chart.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
showAllCharts(): void {
|
||||
this.charts.forEach(chart => {
|
||||
if (!chart.enabled) {
|
||||
this.chartConfigService.toggleChart(chart.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user