fix(chart-ui): resolve glitches in chart rendering (#2290)

Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
ACX
2026-01-16 00:34:17 -07:00
committed by GitHub
co-authored by acx10
parent 69ad5787bb
commit 3a41e25aeb
5 changed files with 148 additions and 127 deletions
@@ -88,9 +88,7 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
if (label === 'Sessions') { if (label === 'Sessions') {
return `${label}: ${value} session${value !== 1 ? 's' : ''}`; return `${label}: ${value} session${value !== 1 ? 's' : ''}`;
} else { } else {
const hours = Math.floor(value / 3600); return `${label}: ${value} min`;
const minutes = Math.floor((value % 3600) / 60);
return `${label}: ${hours}h ${minutes}m`;
} }
} }
} }
@@ -149,7 +147,7 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
position: 'right', position: 'right',
title: { title: {
display: true, display: true,
text: 'Duration (minutes)', text: 'Avg Duration (min)',
color: 'rgba(251, 191, 36, 0.9)', color: 'rgba(251, 191, 36, 0.9)',
font: { font: {
family: "'Inter', sans-serif", family: "'Inter', sans-serif",
@@ -227,9 +225,13 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
return hourData?.sessionCount || 0; return hourData?.sessionCount || 0;
}); });
const durations = allHours.map(hour => { // Calculate average duration per session (in minutes) for each hour
const avgDurations = allHours.map(hour => {
const hourData = hourMap.get(hour); const hourData = hourMap.get(hour);
return hourData ? hourData.totalDurationSeconds / 60 : 0; // Convert to minutes if (hourData && hourData.sessionCount > 0) {
return Math.round(hourData.totalDurationSeconds / 60 / hourData.sessionCount);
}
return 0;
}); });
this.chartDataSubject.next({ this.chartDataSubject.next({
@@ -251,8 +253,8 @@ export class PeakHoursChartComponent implements OnInit, OnDestroy {
yAxisID: 'y' yAxisID: 'y'
}, },
{ {
label: 'Duration (minutes)', label: 'Avg Duration (min)',
data: durations, data: avgDurations,
borderColor: 'rgba(251, 191, 36, 0.9)', borderColor: 'rgba(251, 191, 36, 0.9)',
backgroundColor: 'rgba(251, 191, 36, 0.1)', backgroundColor: 'rgba(251, 191, 36, 0.1)',
borderWidth: 2, borderWidth: 2,
@@ -101,7 +101,7 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy {
backgroundColor: 'rgba(0, 0, 0, 0.95)', backgroundColor: 'rgba(0, 0, 0, 0.95)',
titleColor: '#ffffff', titleColor: '#ffffff',
bodyColor: '#ffffff', bodyColor: '#ffffff',
borderColor: '#4fc3f7', borderColor: '#e91e63',
borderWidth: 2, borderWidth: 2,
cornerRadius: 8, cornerRadius: 8,
padding: 16, padding: 16,
@@ -199,8 +199,8 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy {
]; ];
const gradientColors = [ const gradientColors = [
'#ff6b9d', '#45aaf2', '#96f7d2', '#feca57', '#e91e63', '#2196f3', '#00bcd4', '#ff9800',
'#ff9ff3', '#54a0ff', '#5f27cd', '#00d2d3' '#9c27b0', '#3f51b5', '#673ab7', '#009688'
]; ];
this.chartDataSubject.next({ this.chartDataSubject.next({
@@ -211,8 +211,8 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy {
datasets: [{ datasets: [{
label: 'Reading DNA Profile', label: 'Reading DNA Profile',
data, data,
backgroundColor: 'rgba(79, 195, 247, 0.2)', backgroundColor: 'rgba(233, 30, 99, 0.2)',
borderColor: '#4fc3f7', borderColor: '#e91e63',
borderWidth: 3, borderWidth: 3,
pointBackgroundColor: gradientColors, pointBackgroundColor: gradientColors,
pointBorderColor: '#ffffff', pointBorderColor: '#ffffff',
@@ -514,49 +514,49 @@ export class ReadingDNAChartComponent implements OnInit, OnDestroy {
trait: 'Adventurous', trait: 'Adventurous',
score: profile.adventurous, score: profile.adventurous,
description: 'You explore diverse genres and experimental content', description: 'You explore diverse genres and experimental content',
color: '#ff6b9d' color: '#e91e63'
}, },
{ {
trait: 'Perfectionist', trait: 'Perfectionist',
score: profile.perfectionist, score: profile.perfectionist,
description: 'You prefer high-quality books and finish what you start', description: 'You prefer high-quality books and finish what you start',
color: '#45aaf2' color: '#2196f3'
}, },
{ {
trait: 'Intellectual', trait: 'Intellectual',
score: profile.intellectual, score: profile.intellectual,
description: 'You gravitate toward complex, educational material', description: 'You gravitate toward complex, educational material',
color: '#96f7d2' color: '#00bcd4'
}, },
{ {
trait: 'Emotional', trait: 'Emotional',
score: profile.emotional, score: profile.emotional,
description: 'You connect emotionally with fiction and personal stories', description: 'You connect emotionally with fiction and personal stories',
color: '#feca57' color: '#ff9800'
}, },
{ {
trait: 'Patient', trait: 'Patient',
score: profile.patient, score: profile.patient,
description: 'You tackle long books and complete series', description: 'You tackle long books and complete series',
color: '#ff9ff3' color: '#9c27b0'
}, },
{ {
trait: 'Social', trait: 'Social',
score: profile.social, score: profile.social,
description: 'You enjoy popular, widely-discussed books', description: 'You enjoy popular, widely-discussed books',
color: '#54a0ff' color: '#3f51b5'
}, },
{ {
trait: 'Nostalgic', trait: 'Nostalgic',
score: profile.nostalgic, score: profile.nostalgic,
description: 'You appreciate classic literature and older works', description: 'You appreciate classic literature and older works',
color: '#5f27cd' color: '#673ab7'
}, },
{ {
trait: 'Ambitious', trait: 'Ambitious',
score: profile.ambitious, score: profile.ambitious,
description: 'You challenge yourself with volume and difficulty', description: 'You challenge yourself with volume and difficulty',
color: '#00d2d3' color: '#009688'
} }
]; ];
} }
@@ -77,7 +77,11 @@
[style.left.%]="session.left" [style.left.%]="session.left"
[style.width.%]="session.width" [style.width.%]="session.width"
[style.top]="session.totalLevels > 1 ? 'calc(' + session.level + ' / ' + session.totalLevels + ' * 100% + ' + session.level * 2 + 'px)' : '0'" [style.top]="session.totalLevels > 1 ? 'calc(' + session.level + ' / ' + session.totalLevels + ' * 100% + ' + session.level * 2 + 'px)' : '0'"
[style.height]="session.totalLevels > 1 ? 'calc((1 / ' + session.totalLevels + ' * 100%) - ' + (session.totalLevels - 1) * 2 / session.totalLevels + 'px)' : '100%'"> [style.height]="session.totalLevels > 1 ? 'calc((1 / ' + session.totalLevels + ' * 100%) - ' + (session.totalLevels - 1) * 2 / session.totalLevels + 'px)' : '100%'"
[pTooltip]="getTooltipContent(session)"
[escape]="false"
tooltipPosition="top"
[appendTo]="'body'">
@if (isDurationGreaterThanOneHour(session.duration)) { @if (isDurationGreaterThanOneHour(session.duration)) {
<div class="session-content"> <div class="session-content">
<span class="session-time"> <span class="session-time">
@@ -88,36 +92,6 @@
</span> </span>
</div> </div>
} }
<div class="session-tooltip">
<div class="tooltip-content">
<div class="tooltip-cover">
<img [src]="getCoverUrl(session.bookId)" alt="Book Cover">
</div>
<div class="tooltip-details">
<div class="tooltip-header">
<i class="pi pi-book"></i>
<span class="tooltip-title">{{ session.bookTitle || 'Reading Session' }}</span>
</div>
<div class="tooltip-divider"></div>
<div class="tooltip-body">
<div class="tooltip-row">
<i class="pi pi-clock"></i>
<span class="tooltip-label">Time:</span>
<span class="tooltip-value">
{{ formatTime(session.startHour, session.startMinute) }} -
{{ formatTime(session.endHour, session.endMinute) }}
</span>
</div>
<div class="tooltip-row">
<i class="pi pi-hourglass"></i>
<span class="tooltip-label">Duration:</span>
<span class="tooltip-value">{{ formatDuration(session.duration) }}</span>
</div>
</div>
</div>
</div>
</div>
</div> </div>
} }
</div> </div>
@@ -290,15 +290,39 @@
} }
} }
&.book-type-fb2 {
background: rgba(34, 197, 94, 0.8);
border: 1px solid rgba(34, 197, 94, 1);
box-shadow: 0 2px 4px rgba(34, 197, 94, 0.3);
&:hover {
box-shadow: 0 4px 8px rgba(34, 197, 94, 0.5);
}
}
&.book-type-mobi {
background: rgba(168, 85, 247, 0.8);
border: 1px solid rgba(168, 85, 247, 1);
box-shadow: 0 2px 4px rgba(168, 85, 247, 0.3);
&:hover {
box-shadow: 0 4px 8px rgba(168, 85, 247, 0.5);
}
}
&.book-type-azw3 {
background: rgba(236, 72, 153, 0.8);
border: 1px solid rgba(236, 72, 153, 1);
box-shadow: 0 2px 4px rgba(236, 72, 153, 0.3);
&:hover {
box-shadow: 0 4px 8px rgba(236, 72, 153, 0.5);
}
}
&:hover { &:hover {
transform: translateY(-2px); transform: translateY(-2px);
z-index: 10; z-index: 10;
.session-tooltip {
opacity: 1;
transform: translate(-50%, 0);
pointer-events: auto;
}
} }
.session-content { .session-content {
@@ -333,32 +357,33 @@
} }
} }
.session-tooltip { ::ng-deep .p-tooltip {
position: absolute; --p-tooltip-max-width: 300px;
bottom: calc(100% + 15px); --p-tooltip-background: rgba(30, 30, 30, 0.98);
left: 50%; --p-tooltip-color: #ffffff;
transform: translate(-50%, 10px); --p-tooltip-border-radius: 12px;
background: rgba(30, 30, 30, 0.98); --p-tooltip-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
border: 1px solid rgba(255, 255, 255, 0.2); --p-tooltip-padding: 0 !important;
border-radius: 8px; --p-tooltip-gutter: 12px;
padding: 0;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
z-index: 9999;
pointer-events: none;
min-width: 320px;
max-width: 350px;
backdrop-filter: blur(10px);
opacity: 0;
transition: opacity 0.2s ease, transform 0.2s ease;
white-space: normal;
.tooltip-content { backdrop-filter: blur(10px);
display: flex; border: 1px solid rgba(255, 255, 255, 0.2);
gap: 1rem; min-width: 320px;
padding: 1rem; padding: 0 !important;
.p-tooltip-text {
padding: 0 !important;
margin: 0 !important;
white-space: normal;
} }
.tooltip-cover { .session-tooltip-content {
display: flex;
gap: 1rem;
padding: 0.75rem;
}
.session-tooltip-cover {
flex-shrink: 0; flex-shrink: 0;
width: 80px; width: 80px;
height: 120px; height: 120px;
@@ -372,53 +397,50 @@
} }
} }
.tooltip-details { .session-tooltip-details {
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-width: 0; min-width: 0;
} }
.tooltip-header { .session-tooltip-header {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 0.75rem; gap: 0.75rem;
padding: 0; margin-bottom: 0.75rem;
background: none;
i { i {
font-size: 1.1rem; font-size: 1.1rem;
color: rgba(239, 68, 68, 1); color: rgba(239, 68, 68, 1);
} }
}
.tooltip-title { .session-tooltip-title {
color: #ffffff; color: #ffffff;
font-weight: 600; font-weight: 600;
font-size: 0.95rem; font-size: 0.95rem;
flex: 1;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
}
.tooltip-divider { .session-tooltip-divider {
height: 1px; height: 1px;
background: linear-gradient(90deg, background: linear-gradient(90deg,
transparent 0%, transparent 0%,
rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.1) 50%,
transparent 100%); transparent 100%);
margin: 0.75rem 0; margin-bottom: 0.75rem;
} }
.tooltip-body { .session-tooltip-body {
padding: 0;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 0.625rem; gap: 0.625rem;
} }
.tooltip-row { .session-tooltip-row {
display: grid; display: grid;
grid-template-columns: auto auto 1fr; grid-template-columns: auto auto 1fr;
align-items: center; align-items: center;
@@ -431,34 +453,20 @@
width: 16px; width: 16px;
text-align: center; text-align: center;
} }
}
.tooltip-label { .session-tooltip-label {
color: rgba(255, 255, 255, 0.7); color: rgba(255, 255, 255, 0.7);
font-weight: 500; font-weight: 500;
} }
.tooltip-value { .session-tooltip-value {
color: #ffffff; color: #ffffff;
text-align: right; text-align: right;
font-weight: 500; font-weight: 500;
} }
} }
&::after {
content: '';
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 0;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-top: 8px solid rgba(30, 30, 30, 0.98);
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}
}
.timeline-title-icon { .timeline-title-icon {
font-size: 1.5rem; font-size: 1.5rem;
color: rgba(239, 68, 68, 1); color: rgba(239, 68, 68, 1);
@@ -7,6 +7,7 @@ import {catchError} from 'rxjs/operators';
import {of} from 'rxjs'; import {of} from 'rxjs';
import {Select} from 'primeng/select'; import {Select} from 'primeng/select';
import {FormsModule} from '@angular/forms'; import {FormsModule} from '@angular/forms';
import {Tooltip} from 'primeng/tooltip';
import { import {
addWeeks, addWeeks,
endOfISOWeek, endOfISOWeek,
@@ -51,7 +52,7 @@ interface DayTimeline {
@Component({ @Component({
selector: 'app-reading-session-timeline', selector: 'app-reading-session-timeline',
standalone: true, standalone: true,
imports: [CommonModule, Select, FormsModule], imports: [CommonModule, Select, FormsModule, Tooltip],
templateUrl: './reading-session-timeline.component.html', templateUrl: './reading-session-timeline.component.html',
styleUrls: ['./reading-session-timeline.component.scss'] styleUrls: ['./reading-session-timeline.component.scss']
}) })
@@ -340,9 +341,9 @@ export class ReadingSessionTimelineComponent implements OnInit {
const secs = totalSeconds % 60; const secs = totalSeconds % 60;
const parts: string[] = []; const parts: string[] = [];
if (hours) parts.push(`${hours}H`); if (hours) parts.push(`${hours}h`);
if (mins || hours) parts.push(`${mins}M`); if (mins || hours) parts.push(`${mins}m`);
parts.push(`${secs}S`); parts.push(`${secs}s`);
return parts.join(' '); return parts.join(' ');
} }
@@ -365,4 +366,40 @@ export class ReadingSessionTimelineComponent implements OnInit {
public getCoverUrl(bookId: number): string { public getCoverUrl(bookId: number): string {
return this.urlHelperService.getThumbnailUrl1(bookId); return this.urlHelperService.getThumbnailUrl1(bookId);
} }
public getTooltipContent(session: TimelineSession): string {
return `
<div class="session-tooltip-content">
<div class="session-tooltip-cover">
<img src="${this.getCoverUrl(session.bookId)}" alt="Book Cover">
</div>
<div class="session-tooltip-details">
<div class="session-tooltip-header">
<i class="pi pi-book"></i>
<span class="session-tooltip-title">${session.bookTitle || 'Reading Session'}</span>
</div>
<div class="session-tooltip-divider"></div>
<div class="session-tooltip-body">
<div class="session-tooltip-row">
<i class="pi pi-clock"></i>
<span class="session-tooltip-label">Time:</span>
<span class="session-tooltip-value">
${this.formatTime(session.startHour, session.startMinute)} - ${this.formatTime(session.endHour, session.endMinute)}
</span>
</div>
<div class="session-tooltip-row">
<i class="pi pi-hourglass"></i>
<span class="session-tooltip-label">Duration:</span>
<span class="session-tooltip-value">${this.formatDuration(session.duration)}</span>
</div>
<div class="session-tooltip-row">
<i class="pi pi-file"></i>
<span class="session-tooltip-label">Format:</span>
<span class="session-tooltip-value">${session.bookType || 'Unknown'}</span>
</div>
</div>
</div>
</div>
`;
}
} }