From b3f84d8ddb91c2a830fdef3a32c3ef1d4fe43886 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 15 Apr 2022 10:54:13 +0200 Subject: Include upper boundary on stats graph zoom --- client/src/app/+stats/video/video-stats.component.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'client/src') diff --git a/client/src/app/+stats/video/video-stats.component.ts b/client/src/app/+stats/video/video-stats.component.ts index 14db31ecf..8200661c3 100644 --- a/client/src/app/+stats/video/video-stats.component.ts +++ b/client/src/app/+stats/video/video-stats.component.ts @@ -316,7 +316,7 @@ export class VideoStatsComponent implements OnInit { const { min, max } = chart.scales.x const startDate = rawData.data[min].date - const endDate = rawData.data[max].date + const endDate = this.buildZoomEndDate(rawData.groupInterval, rawData.data[max].date) this.peertubeRouter.silentNavigate([], { startDate, endDate }) } @@ -449,4 +449,19 @@ export class VideoStatsComponent implements OnInit { } } } + + private buildZoomEndDate (groupInterval: string, last: string) { + const date = new Date(last) + + // Remove parts of the date we don't need + if (groupInterval.endsWith(' day') || groupInterval.endsWith(' days')) { + date.setHours(23, 59, 59) + } else if (groupInterval.endsWith(' hour') || groupInterval.endsWith(' hours')) { + date.setMinutes(59, 59) + } else { + date.setSeconds(59) + } + + return date.toISOString() + } } -- cgit v1.2.3