mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Migrate media image formats chart to Blazor.Bootstrap.
This commit is contained in:
@@ -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 @@
|
||||
<p class="text-center" style="color: deeppink;">All media image formats found...</p>
|
||||
</h1>
|
||||
<PieChart @ref="_formatsChart" style="padding: 40px" TItem="long"/>
|
||||
<DataGrid Data="@MediaImages" FixedHeader FixedHeaderDataGridMaxHeight="300px" PageSize="int.MaxValue" TItem="MediaFormat">
|
||||
<DataGrid Data="@MediaImages" FixedHeader FixedHeaderDataGridMaxHeight="300px" PageSize="int.MaxValue"
|
||||
TItem="MediaFormat">
|
||||
<DataGridColumn Caption="Media image format" Field="@nameof(MediaFormat.Name)"/>
|
||||
<DataGridNumericColumn Caption="Times found" Field="@nameof(MediaFormat.Count)"/>
|
||||
</DataGrid>
|
||||
@@ -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<long>? _formatsChart;
|
||||
List<long> _formatsCounts = [];
|
||||
string[] _formatsLabels = [];
|
||||
PieChart _formatsChart;
|
||||
List<double?> _formatsCounts = [];
|
||||
List<string> _formatsLabels = [];
|
||||
bool _isAlreadyInitialized;
|
||||
List<MediaFormat> 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<long> GetFormatsChartDataset() => new()
|
||||
{
|
||||
Label = $"Top {_formatsLabels.Length} media image formats found",
|
||||
Data = _formatsCounts,
|
||||
BackgroundColor = Common.BackgroundColors,
|
||||
BorderColor = Common.BorderColors,
|
||||
BorderWidth = 1
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user