From 56c399722c523aaf19b87b2c99a65930a7ef9f63 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 20 May 2025 21:48:35 +0100 Subject: [PATCH] Migrate media image formats chart to Blazor.Bootstrap. --- .../Components/Pages/Statistics/Formats.razor | 5 ++- .../Pages/Statistics/Formats.razor.cs | 45 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Aaru.Server/Components/Pages/Statistics/Formats.razor b/Aaru.Server/Components/Pages/Statistics/Formats.razor index dde11c54..9bb186f2 100644 --- a/Aaru.Server/Components/Pages/Statistics/Formats.razor +++ b/Aaru.Server/Components/Pages/Statistics/Formats.razor @@ -1,6 +1,6 @@ @using Aaru.Server.Database @using Aaru.Server.Database.Models -@using Blazorise.Charts +@using BlazorBootstrap @using Blazorise.DataGrid @rendermode InteractiveServer @@ -16,7 +16,8 @@

All media image formats found...

- + \ No newline at end of file diff --git a/Aaru.Server/Components/Pages/Statistics/Formats.razor.cs b/Aaru.Server/Components/Pages/Statistics/Formats.razor.cs index b51f5d9d..03878d48 100644 --- a/Aaru.Server/Components/Pages/Statistics/Formats.razor.cs +++ b/Aaru.Server/Components/Pages/Statistics/Formats.razor.cs @@ -1,5 +1,5 @@ using Aaru.Server.Database.Models; -using Blazorise.Charts; +using BlazorBootstrap; using Microsoft.EntityFrameworkCore; using DbContext = Aaru.Server.Database.DbContext; @@ -7,9 +7,9 @@ namespace Aaru.Server.Components.Pages.Statistics; public partial class Formats { - PieChart? _formatsChart; - List _formatsCounts = []; - string[] _formatsLabels = []; + PieChart _formatsChart; + List _formatsCounts = []; + List _formatsLabels = []; bool _isAlreadyInitialized; List MediaImages { get; set; } = []; @@ -34,33 +34,40 @@ public partial class Formats _formatsLabels = await ctx.MediaFormats.OrderByDescending(static o => o.Count) .Take(10) .Select(static v => v.Name) - .ToArrayAsync(); + .ToListAsync(); _formatsCounts = await ctx.MediaFormats.OrderByDescending(static o => o.Count) .Take(10) - .Select(static x => x.Count) + .Select(static x => (double?)x.Count) .ToListAsync(); - if(_formatsLabels.Length >= 10) + if(_formatsLabels.Count >= 10) { _formatsLabels[9] = "Other"; _formatsCounts[9] = ctx.MediaFormats.Sum(static o => o.Count) - _formatsCounts.Take(9).Sum(); } + PieChartOptions pieChartOptions = new() + { + Responsive = true + }; -#pragma warning disable CS8604 // Possible null reference argument. - await Common.HandleRedrawAsync(_formatsChart, _formatsLabels, GetFormatsChartDataset); + pieChartOptions.Plugins.Title.Text = $"Top {_formatsLabels.Count} media image formats found"; + pieChartOptions.Plugins.Title.Display = true; -#pragma warning restore CS8604 // Possible null reference argument. + var chartData = new ChartData + { + Labels = _formatsLabels, + Datasets = + [ + new PieChartDataset + { + Data = _formatsCounts + } + ] + }; + + await _formatsChart.InitializeAsync(chartData, pieChartOptions); } - - PieChartDataset GetFormatsChartDataset() => new() - { - Label = $"Top {_formatsLabels.Length} media image formats found", - Data = _formatsCounts, - BackgroundColor = Common.BackgroundColors, - BorderColor = Common.BorderColors, - BorderWidth = 1 - }; } \ No newline at end of file