diff --git a/MP.Stats/Components/ChartControlli.razor b/MP.Stats/Components/ChartControlli.razor index 20f37cc0..889e933f 100644 --- a/MP.Stats/Components/ChartControlli.razor +++ b/MP.Stats/Components/ChartControlli.razor @@ -1,4 +1,6 @@ -@*
+@using MP.Stats.Components.ChartJs + +
@if (RawData == null || RawData.Count == 0) {
@@ -21,12 +23,12 @@
- +
- +
} -
*@ \ No newline at end of file +
\ No newline at end of file diff --git a/MP.Stats/Components/ChartControlli.razor.cs b/MP.Stats/Components/ChartControlli.razor.cs index 43770f10..c4ba8ed0 100644 --- a/MP.Stats/Components/ChartControlli.razor.cs +++ b/MP.Stats/Components/ChartControlli.razor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; +using MP.Data; using MP.Stats.Data; namespace MP.Stats.Components @@ -105,7 +106,7 @@ namespace MP.Stats.Components [Inject] protected MpStatsService StatService { get; set; } - protected List TSData { get; set; } = new List(); + protected List TSData { get; set; } = new List(); #endregion Protected Properties @@ -123,10 +124,6 @@ namespace MP.Stats.Components { // ricalcolo charting data recalcData(); - var dataReload = Task.Run(async () => - { - await HandleRedraw(); - }); } } } @@ -135,54 +132,27 @@ namespace MP.Stats.Components #region Private Methods -#if false - private PieChartDataset GetBarChartDataset() + private List DatiPareto { - var answ = new PieChartDataset - { - Label = "Numero Controlli", - Data = ParetoData.Select(x => x.value).ToList(), - BackgroundColor = getPieColors(0.4f), - BorderColor = getPieColors(1f), - HoverBorderWidth = 3 - }; - return answ; - } -#endif - - private List GetBarChartLabels() - { - var answ = ParetoData.Select(x => x.label).ToList(); - return answ; + get => ParetoData.Select(x => x.value).ToList(); } -#if false - /// - /// Elenco 2 linee x controli KO /KO - /// - /// - private LineChartDataset GetLineChartDataset() + private List DatiPlot { - var answ = new LineChartDataset - { - Label = "Numero controlli", - Data = TSData.Select(x => x.Value).ToList(), - BorderColor = getLineColors(1f), - Fill = true, - PointRadius = 2, - LineTension = 0, - BorderDash = new List { } - }; - return answ; - } -#endif - - private List GetLineChartLabels() - { - var answ = TSData.Select(x => x.TLabel.ToString("ddd dd.MM")).ToList(); - return answ; + get => TSData; } + private List LabelPareto + { + get => ParetoData.Select(x => x.label).ToList(); + } + + private List LabelPlot + { + get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList(); + } + + private void recalcData() { if (RawData != null) @@ -195,8 +165,8 @@ namespace MP.Stats.Components TSData = RawData .GroupBy(x => x.DataOra.Date) - .Select(y => new ChartTS() { TLabel = y.First().DataOra.Date, Value = y.Count() }) - .OrderBy(x => x.TLabel) + .Select(r => new chartJsData.chartJsTSerie() { x = r.First().DataOra.Date, y = r.Count() }) + .OrderBy(o => o.x) .ToList(); } } @@ -205,17 +175,49 @@ namespace MP.Stats.Components #region Protected Methods + + /// /// Genera colori sfondo 33% rosso / arancione / giallo /// /// /// - protected List getLineColors(float alpha) + protected List bgColors + { + get => semaphColors(ParetoData.Count, "0.3"); + } + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List lineColor + { + get => solidColors("1"); + } + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List lineColors + { + get => semaphColors(ParetoData.Count, "1"); + } + + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List semaphColors(int numRecords, string alpha) { List answ = new List(); -#if false - answ.Add(ChartColor.FromRgba(54, 82, 254, alpha)); -#endif + + // aggiungo verde/rosso + answ.Add($"rgba(54, 254, 82, {alpha})"); + answ.Add($"rgba(254, 82, 65, {alpha})"); return answ; } @@ -224,40 +226,13 @@ namespace MP.Stats.Components /// /// /// - protected List getPieColors(float alpha) + protected List solidColors(string alpha) { List answ = new List(); -#if false - foreach (var item in ParetoData) - { - if (item.label == EsitoOK) - { - answ.Add(ChartColor.FromRgba(54, 254, 82, alpha)); - } - else - { - answ.Add(ChartColor.FromRgba(254, 82, 65, alpha)); - } - } -#endif + answ.Add($"rgba(54, 162, 235, {alpha})"); return answ; } - protected async Task HandleRedraw() - { -#if false - if (PieVC != null) - { - await PieVC.Clear(); - await PieVC.AddLabelsDatasetsAndUpdate(GetBarChartLabels(), GetBarChartDataset()); - } - if (TimeSerieVC != null) - { - await TimeSerieVC.Clear(); - await TimeSerieVC.AddLabelsDatasetsAndUpdate(GetLineChartLabels(), GetLineChartDataset()); - } -#endif - } #endregion Protected Methods } diff --git a/MP.Stats/Components/ChartJs/PieChart.razor b/MP.Stats/Components/ChartJs/PieChart.razor index d1dab00f..f3d32801 100644 --- a/MP.Stats/Components/ChartJs/PieChart.razor +++ b/MP.Stats/Components/ChartJs/PieChart.razor @@ -7,6 +7,12 @@ [Parameter] public string Id { get; set; } = "MyTs"; + + [Parameter] + public string Title { get; set; } = "DEMO Pie Chart"; + + [Parameter] + public string LegendPos { get; set; } = "right"; [Parameter] public List Data { get; set; } = new List(); @@ -61,16 +67,17 @@ { legend = new { - position = "right" + position = LegendPos }, title = new { display = true, - text = "Chart.js Pie Chart" + text = Title } }, Animation = false, - AspectRatio = AspRatio == 0 ? "auto" : $"{AspRatio}" + AspectRatio = AspRatio == 0 ? "auto" : $"{AspRatio}", + HoverBorderWidth = 3 }, data = new { diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 20566bd4..f1397d70 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,7 +4,7 @@ net6.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 6.14.2202.2613 + 6.14.2202.2614 diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index 5a9b302d..b01f90e0 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 6.14.2202.2613

+

Versione: 6.14.2202.2614


Note di rilascio:
    diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index b0e6f6ae..e2efed23 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -6.14.2202.2613 +6.14.2202.2614 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index aa38f9fe..9328c8ef 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.14.2202.2613 + 6.14.2202.2614 https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false