Migrate filters chart to Blazor.Bootstrap.

This commit is contained in:
2025-05-20 21:43:28 +01:00
parent 1184d1357f
commit 1b9dd25b0c
3 changed files with 36 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
@using Aaru.Server.Database
@using Aaru.Server.Database.Models
@using Blazorise.Charts
@using BlazorBootstrap
@using Blazorise.DataGrid
@rendermode InteractiveServer

View File

@@ -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 Filters
{
PieChart<long>? _filtersChart;
List<long> _filtersCounts = [];
string[] _filtersLabels = [];
bool _isAlreadyInitialized;
List<Filter> FiltersList { get; set; } = [];
PieChart _filtersChart;
List<double?> _filtersCounts = [];
List<string> _filtersLabels = [];
bool _isAlreadyInitialized;
List<Filter> FiltersList { get; set; } = [];
/// <inheritdoc />
protected override async Task OnInitializedAsync()
@@ -34,32 +34,40 @@ public partial class Filters
_filtersLabels = await ctx.Filters.OrderByDescending(static o => o.Count)
.Take(10)
.Select(static v => v.Name)
.ToArrayAsync();
.ToListAsync();
_filtersCounts = await ctx.Filters.OrderByDescending(static o => o.Count)
.Take(10)
.Select(static x => x.Count)
.Select(static x => (double?)x.Count)
.ToListAsync();
if(_filtersLabels.Length >= 10)
if(_filtersLabels.Count >= 10)
{
_filtersLabels[9] = "Other";
_filtersCounts[9] = ctx.Filters.Sum(static o => o.Count) - _filtersCounts.Take(9).Sum();
}
#pragma warning disable CS8604 // Possible null reference argument.
await Common.HandleRedrawAsync(_filtersChart, _filtersLabels, GetFiltersChartDataset);
#pragma warning restore CS8604 // Possible null reference argument.
PieChartOptions pieChartOptions = new()
{
Responsive = true
};
pieChartOptions.Plugins.Title.Text = $"Top {_filtersLabels.Count} filters found";
pieChartOptions.Plugins.Title.Display = true;
var chartData = new ChartData
{
Labels = _filtersLabels,
Datasets =
[
new PieChartDataset
{
Data = _filtersCounts
}
]
};
await _filtersChart.InitializeAsync(chartData, pieChartOptions);
}
PieChartDataset<long> GetFiltersChartDataset() => new()
{
Label = $"Top {_filtersLabels.Length} filters found",
Data = _filtersCounts,
BackgroundColor = Common.BackgroundColors,
BorderColor = Common.BorderColors,
BorderWidth = 1
};
}

View File

@@ -33,22 +33,22 @@
<Filters/>
</TabPanel>
<TabPanel Name="formats">
<Formats/>
<!-- <Formats/>-->
</TabPanel>
<TabPanel Name="partitions">
<Partitions/>
<!-- <Partitions/>-->
</TabPanel>
<TabPanel Name="filesystems">
<Filesystems/>
<!-- <Filesystems/>-->
</TabPanel>
<TabPanel Name="virtualMedias">
<VirtualMedias/>
</TabPanel>
<TabPanel Name="realMedias">
<RealMedias/>
<!-- <RealMedias/>-->
</TabPanel>
<TabPanel Name="devices">
<Devices/>
<!-- <Devices/>-->
</TabPanel>
</Content>
</Tabs>