mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Migrate versions chart to Blazor.Bootstrap.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
@using Aaru.CommonTypes.Metadata
|
||||
@using Aaru.Server.Database
|
||||
@using Blazorise.Charts
|
||||
@using BlazorBootstrap
|
||||
@using Blazorise.DataGrid
|
||||
@rendermode InteractiveServer
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
<p class="text-center" style="color: deeppink;">All Aaru versions...</p>
|
||||
</h1>
|
||||
<PieChart @ref="_versionsChart" style="padding: 40px" TItem="long"/>
|
||||
<DataGrid Data="@VersionsList" FixedHeader FixedHeaderDataGridMaxHeight="300px" PageSize="int.MaxValue" TItem="NameValueStats">
|
||||
<DataGrid Data="@VersionsList" FixedHeader FixedHeaderDataGridMaxHeight="300px" PageSize="int.MaxValue"
|
||||
TItem="NameValueStats">
|
||||
<DataGridColumn Caption="Version" Field="@nameof(NameValueStats.name)"/>
|
||||
<DataGridNumericColumn Caption="Times run" Field="@nameof(NameValueStats.Value)"/>
|
||||
</DataGrid>
|
||||
@@ -1,5 +1,5 @@
|
||||
using Aaru.CommonTypes.Metadata;
|
||||
using Blazorise.Charts;
|
||||
using BlazorBootstrap;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DbContext = Aaru.Server.Database.DbContext;
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
||||
public partial class Versions
|
||||
{
|
||||
bool _isAlreadyInitialized;
|
||||
PieChart<long>? _versionsChart;
|
||||
List<long> _versionsCounts = [];
|
||||
string[] _versionsLabels = [];
|
||||
PieChart _versionsChart;
|
||||
List<double?> _versionsCounts = [];
|
||||
List<string> _versionsLabels = [];
|
||||
List<NameValueStats> VersionsList { get; set; } = [];
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -40,31 +40,40 @@ public partial class Versions
|
||||
_versionsLabels = await ctx.Versions.OrderByDescending(static o => o.Count)
|
||||
.Take(10)
|
||||
.Select(static v => v.Name == "previous" ? "Previous than 3.4.99.0" : v.Name)
|
||||
.ToArrayAsync();
|
||||
.ToListAsync();
|
||||
|
||||
_versionsCounts = await ctx.Versions.OrderByDescending(static o => o.Count)
|
||||
.Take(10)
|
||||
.Select(static x => x.Count)
|
||||
.Select(static x => (double?)x.Count)
|
||||
.ToListAsync();
|
||||
|
||||
if(_versionsLabels.Length >= 10)
|
||||
if(_versionsLabels.Count >= 10)
|
||||
{
|
||||
_versionsLabels[9] = "Other";
|
||||
|
||||
_versionsCounts[9] = ctx.Versions.Sum(static o => o.Count) - _versionsCounts.Take(9).Sum();
|
||||
}
|
||||
|
||||
#pragma warning disable CS8604 // Possible null reference argument.
|
||||
await Common.HandleRedrawAsync(_versionsChart, _versionsLabels, GetVersionsChartDataset);
|
||||
#pragma warning restore CS8604 // Possible null reference argument.
|
||||
}
|
||||
PieChartOptions pieChartOptions = new()
|
||||
{
|
||||
Responsive = true
|
||||
};
|
||||
|
||||
PieChartDataset<long> GetVersionsChartDataset() => new()
|
||||
{
|
||||
Label = $"Top {_versionsLabels.Length} Aaru versions",
|
||||
Data = _versionsCounts,
|
||||
BackgroundColor = Common.BackgroundColors,
|
||||
BorderColor = Common.BorderColors,
|
||||
BorderWidth = 1
|
||||
};
|
||||
pieChartOptions.Plugins.Title.Text = $"Top {_versionsLabels.Count} Aaru versions";
|
||||
pieChartOptions.Plugins.Title.Display = true;
|
||||
|
||||
var chartData = new ChartData
|
||||
{
|
||||
Labels = _versionsLabels,
|
||||
Datasets =
|
||||
[
|
||||
new PieChartDataset
|
||||
{
|
||||
Data = _versionsCounts
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
await _versionsChart.InitializeAsync(chartData, pieChartOptions);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user