From ba050fb0df5892752ae2e1b40b2f6e406abe4f08 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Dec 2023 11:05:47 +0100 Subject: [PATCH] Fix displaying many countries --- .../+stats/video/video-stats.component.html | 2 +- .../app/+stats/video/video-stats.component.ts | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/client/src/app/+stats/video/video-stats.component.html b/client/src/app/+stats/video/video-stats.component.html index 242a5a7a2..18df800c7 100644 --- a/client/src/app/+stats/video/video-stats.component.html +++ b/client/src/app/+stats/video/video-stats.component.html @@ -45,7 +45,7 @@ -
+
+ plugins: Partial> data: ChartData<'line' | 'bar'> displayLegend: boolean @@ -136,6 +139,12 @@ export class VideoStatsComponent implements OnInit { onChartChange (newActive: ActiveGraphId) { this.activeGraphId = newActive + if (newActive === 'countries') { + this.chartHeight = `${Math.max(this.countries.length * 20, 300)}px` + } else { + this.chartHeight = '300px' + } + this.loadChart() } @@ -333,7 +342,7 @@ export class VideoStatsComponent implements OnInit { countries: (rawData: CountryData) => this.buildCountryChartOptions(rawData) } - const { type, data, displayLegend, plugins } = dataBuilders[graphId](this.chartIngestData[graphId]) + const { type, data, displayLegend, plugins, options } = dataBuilders[graphId](this.chartIngestData[graphId]) const self = this @@ -342,6 +351,8 @@ export class VideoStatsComponent implements OnInit { data, options: { + ...options, + responsive: true, scales: { @@ -366,7 +377,9 @@ export class VideoStatsComponent implements OnInit { : undefined, ticks: { - callback: value => this.formatYTick({ graphId, value }) + callback: function (value) { + return self.formatYTick({ graphId, value, scale: this }) + } } } }, @@ -489,6 +502,10 @@ export class VideoStatsComponent implements OnInit { return { type: 'bar' as 'bar', + options: { + indexAxis: 'y' + }, + displayLegend: true, plugins: { @@ -547,11 +564,14 @@ export class VideoStatsComponent implements OnInit { private formatYTick (options: { graphId: ActiveGraphId value: number | string + scale?: Scale }) { - const { graphId, value } = options + const { graphId, value, scale } = options if (graphId === 'retention') return value + ' %' if (graphId === 'aggregateWatchTime') return secondsToTime(+value) + if (graphId === 'countries' && scale) return scale.getLabelForValue(value as number) + return value.toLocaleString(this.localeId) }