diff --git a/Aaru.Server/Components/Pages/Statistics/Commands.razor b/Aaru.Server/Components/Pages/Statistics/Commands.razor index d8f9154e..1ad16342 100644 --- a/Aaru.Server/Components/Pages/Statistics/Commands.razor +++ b/Aaru.Server/Components/Pages/Statistics/Commands.razor @@ -1,6 +1,6 @@ @using Aaru.Server.Database @using Aaru.Server.Database.Models -@using Blazorise.Charts +@using BlazorBootstrap @using Blazorise.DataGrid @rendermode InteractiveServer diff --git a/Aaru.Server/Components/Pages/Statistics/Commands.razor.cs b/Aaru.Server/Components/Pages/Statistics/Commands.razor.cs index cef4d502..e51745a5 100644 --- a/Aaru.Server/Components/Pages/Statistics/Commands.razor.cs +++ b/Aaru.Server/Components/Pages/Statistics/Commands.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,11 +7,11 @@ namespace Aaru.Server.Components.Pages.Statistics; public partial class Commands { - PieChart? _commandsChart; - List _commandsCounts = []; - string[] _commandsLabels = []; - bool _isAlreadyInitialized; - List CommandsList { get; set; } = []; + PieChart _commandsChart; + List _commandsCounts = []; + List _commandsLabels = []; + bool _isAlreadyInitialized; + List CommandsList { get; set; } = []; /// protected override async Task OnInitializedAsync() @@ -35,31 +35,40 @@ public partial class Commands _commandsLabels = await ctx.Commands.OrderByDescending(static o => o.Count) .Take(10) .Select(static v => v.Name) - .ToArrayAsync(); + .ToListAsync(); _commandsCounts = await ctx.Commands.OrderByDescending(static o => o.Count) .Take(10) - .Select(static x => x.Count) + .Select(static x => (double?)x.Count) .ToListAsync(); - if(_commandsLabels.Length >= 10) + if(_commandsLabels.Count >= 10) { _commandsLabels[9] = "Other"; _commandsCounts[9] = ctx.Commands.Sum(static o => o.Count) - _commandsCounts.Take(9).Sum(); } -#pragma warning disable CS8604 // Possible null reference argument. - await Common.HandleRedrawAsync(_commandsChart, _commandsLabels, GetCommandsChartDataset); -#pragma warning restore CS8604 // Possible null reference argument. - } + PieChartOptions pieChartOptions = new() + { + Responsive = true + }; - PieChartDataset GetCommandsChartDataset() => new() - { - Label = $"Top {_commandsLabels.Length} used commands", - Data = _commandsCounts, - BackgroundColor = Common.BackgroundColors, - BorderColor = Common.BorderColors, - BorderWidth = 1 - }; + pieChartOptions.Plugins.Title.Text = $"Top {_commandsLabels.Count} used commands"; + pieChartOptions.Plugins.Title.Display = true; + + var chartData = new ChartData + { + Labels = _commandsLabels, + Datasets = + [ + new PieChartDataset + { + Data = _commandsCounts + } + ] + }; + + await _commandsChart.InitializeAsync(chartData, pieChartOptions); + } } \ No newline at end of file