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
|
||||||
@using Aaru.Server.Database.Models
|
@using Aaru.Server.Database.Models
|
||||||
@using Blazorise.Charts
|
@using BlazorBootstrap
|
||||||
@using Blazorise.DataGrid
|
@using Blazorise.DataGrid
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
@@ -16,7 +16,8 @@
|
|||||||
<p class="text-center" style="color: deeppink;">All media image formats found...</p>
|
<p class="text-center" style="color: deeppink;">All media image formats found...</p>
|
||||||
</h1>
|
</h1>
|
||||||
<PieChart @ref="_formatsChart" style="padding: 40px" TItem="long"/>
|
<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)"/>
|
<DataGridColumn Caption="Media image format" Field="@nameof(MediaFormat.Name)"/>
|
||||||
<DataGridNumericColumn Caption="Times found" Field="@nameof(MediaFormat.Count)"/>
|
<DataGridNumericColumn Caption="Times found" Field="@nameof(MediaFormat.Count)"/>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using Aaru.Server.Database.Models;
|
using Aaru.Server.Database.Models;
|
||||||
using Blazorise.Charts;
|
using BlazorBootstrap;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using DbContext = Aaru.Server.Database.DbContext;
|
using DbContext = Aaru.Server.Database.DbContext;
|
||||||
|
|
||||||
@@ -7,9 +7,9 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
|||||||
|
|
||||||
public partial class Formats
|
public partial class Formats
|
||||||
{
|
{
|
||||||
PieChart<long>? _formatsChart;
|
PieChart _formatsChart;
|
||||||
List<long> _formatsCounts = [];
|
List<double?> _formatsCounts = [];
|
||||||
string[] _formatsLabels = [];
|
List<string> _formatsLabels = [];
|
||||||
bool _isAlreadyInitialized;
|
bool _isAlreadyInitialized;
|
||||||
List<MediaFormat> MediaImages { get; set; } = [];
|
List<MediaFormat> MediaImages { get; set; } = [];
|
||||||
|
|
||||||
@@ -34,33 +34,40 @@ public partial class Formats
|
|||||||
_formatsLabels = await ctx.MediaFormats.OrderByDescending(static o => o.Count)
|
_formatsLabels = await ctx.MediaFormats.OrderByDescending(static o => o.Count)
|
||||||
.Take(10)
|
.Take(10)
|
||||||
.Select(static v => v.Name)
|
.Select(static v => v.Name)
|
||||||
.ToArrayAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
_formatsCounts = await ctx.MediaFormats.OrderByDescending(static o => o.Count)
|
_formatsCounts = await ctx.MediaFormats.OrderByDescending(static o => o.Count)
|
||||||
.Take(10)
|
.Take(10)
|
||||||
.Select(static x => x.Count)
|
.Select(static x => (double?)x.Count)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
if(_formatsLabels.Length >= 10)
|
if(_formatsLabels.Count >= 10)
|
||||||
{
|
{
|
||||||
_formatsLabels[9] = "Other";
|
_formatsLabels[9] = "Other";
|
||||||
|
|
||||||
_formatsCounts[9] = ctx.MediaFormats.Sum(static o => o.Count) - _formatsCounts.Take(9).Sum();
|
_formatsCounts[9] = ctx.MediaFormats.Sum(static o => o.Count) - _formatsCounts.Take(9).Sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PieChartOptions pieChartOptions = new()
|
||||||
#pragma warning disable CS8604 // Possible null reference argument.
|
|
||||||
await Common.HandleRedrawAsync(_formatsChart, _formatsLabels, GetFormatsChartDataset);
|
|
||||||
|
|
||||||
#pragma warning restore CS8604 // Possible null reference argument.
|
|
||||||
}
|
|
||||||
|
|
||||||
PieChartDataset<long> GetFormatsChartDataset() => new()
|
|
||||||
{
|
{
|
||||||
Label = $"Top {_formatsLabels.Length} media image formats found",
|
Responsive = true
|
||||||
Data = _formatsCounts,
|
|
||||||
BackgroundColor = Common.BackgroundColors,
|
|
||||||
BorderColor = Common.BorderColors,
|
|
||||||
BorderWidth = 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pieChartOptions.Plugins.Title.Text = $"Top {_formatsLabels.Count} media image formats found";
|
||||||
|
pieChartOptions.Plugins.Title.Display = true;
|
||||||
|
|
||||||
|
var chartData = new ChartData
|
||||||
|
{
|
||||||
|
Labels = _formatsLabels,
|
||||||
|
Datasets =
|
||||||
|
[
|
||||||
|
new PieChartDataset
|
||||||
|
{
|
||||||
|
Data = _formatsCounts
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
await _formatsChart.InitializeAsync(chartData, pieChartOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user