diff --git a/MP.Stats/Components/ChartControlli.razor.cs b/MP.Stats/Components/ChartControlli.razor.cs index c4ba8ed0..32ba8fc7 100644 --- a/MP.Stats/Components/ChartControlli.razor.cs +++ b/MP.Stats/Components/ChartControlli.razor.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; using MP.Data; using MP.Stats.Data; +using System.Collections.Generic; +using System.Linq; namespace MP.Stats.Components { @@ -85,19 +83,68 @@ namespace MP.Stats.Components AspectRatio = 1 }; -#if false - protected PieChart PieVC = new PieChart(); - protected LineChart TimeSerieVC = new LineChart(); -#endif - #endregion Protected Fields + #region Private Properties + + private List DatiPareto + { + get => ParetoData.Select(x => x.value).ToList(); + } + + private List DatiPlot + { + 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(); + } + + #endregion Private Properties + #region Protected Properties protected SelectData _currFilter { get; set; } = new SelectData(); protected List _rawData { get; set; } = new List(); + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + 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"); + } + [Inject] protected MessageService MessageService { get; set; } @@ -132,27 +179,6 @@ namespace MP.Stats.Components #region Private Methods - private List DatiPareto - { - get => ParetoData.Select(x => x.value).ToList(); - } - - private List DatiPlot - { - 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) @@ -175,38 +201,6 @@ namespace MP.Stats.Components #region Protected Methods - - - /// - /// Genera colori sfondo 33% rosso / arancione / giallo - /// - /// - /// - 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 /// /// @@ -233,7 +227,6 @@ namespace MP.Stats.Components return answ; } - #endregion Protected Methods } } \ No newline at end of file diff --git a/MP.Stats/Components/ChartScarti.razor.cs b/MP.Stats/Components/ChartScarti.razor.cs index 7e4e1414..07112c66 100644 --- a/MP.Stats/Components/ChartScarti.razor.cs +++ b/MP.Stats/Components/ChartScarti.razor.cs @@ -8,79 +8,6 @@ namespace MP.Stats.Components { public partial class ChartScarti { - #region Protected Fields - - protected object barChartOptions = new - { - Scales = new - { - XAxes = new object[] - { - new { - Display = false - } - }, - YAxes = new object[] - { - new { - Display = true, - ticks= new { - suggestedMin = 0 - } - } - } - }, - Tooltips = new - { - Mode = "nearest", - Intersect = false - }, - Hover = new - { - Mode = "nearest", - Intersect = false - }, - Animation = false, - AspectRatio = 3.5 - }; - - protected object lineChartOptions = new - { - Scales = new - { - XAxes = new object[] - { - new { - Display = true, - //type = "time" - } - }, - YAxes = new object[] - { - new { - Display = true, - ticks= new { - suggestedMin = 0 - } - } - } - }, - Tooltips = new - { - Mode = "nearest", - Intersect = false - }, - Hover = new - { - Mode = "nearest", - Intersect = false - }, - Animation = false, - AspectRatio = 3.5 - }; - - #endregion Protected Fields - #region Private Properties private List DatiPareto diff --git a/MP.Stats/Components/ChartUserLog.razor b/MP.Stats/Components/ChartUserLog.razor index 53c4139c..d33c723e 100644 --- a/MP.Stats/Components/ChartUserLog.razor +++ b/MP.Stats/Components/ChartUserLog.razor @@ -1,4 +1,6 @@ -
+@using MP.Stats.Components.ChartJs + +
@if (RawData == null || RawData.Count == 0) {
@@ -21,10 +23,10 @@
- @* *@ +
-@* *@ +
diff --git a/MP.Stats/Components/ChartUserLog.razor.cs b/MP.Stats/Components/ChartUserLog.razor.cs index 5a2f1149..1bc1cbd8 100644 --- a/MP.Stats/Components/ChartUserLog.razor.cs +++ b/MP.Stats/Components/ChartUserLog.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,51 +132,10 @@ namespace MP.Stats.Components #region Private Methods -#if false - private PieChartDataset GetBarChartDataset() - { - var answ = new PieChartDataset - { - Label = "Numero Controlli", - Data = ParetoData.Select(x => x.value).ToList(), - BackgroundColor = backgroundColors(ParetoData.Count, 0.4f), - BorderColor = backgroundColors(ParetoData.Count, 1f), - HoverBorderWidth = 3 - }; - return answ; - } -#endif - - private List GetBarChartLabels() - { - var answ = ParetoData.Select(x => x.label).ToList(); - return answ; - } - -#if false - /// - /// Elenco 2 linee x controli KO /KO - /// - /// - private LineChartDataset GetLineChartDataset() - { - var answ = new LineChartDataset - { - Label = "Numero Azioni", - 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(); + var answ = TSData.Select(x => x.x.ToString("ddd dd.MM")).ToList(); return answ; } @@ -195,8 +151,8 @@ namespace MP.Stats.Components TSData = RawData .GroupBy(x => x.DataOraRif.Date) - .Select(y => new ChartTS() { TLabel = y.First().DataOraRif.Date, Value = y.Count() }) - .OrderBy(x => x.TLabel) + .Select(r => new chartJsData.chartJsTSerie() { x = r.First().DataOraRif.Date, y = r.Count() }) + .OrderBy(o => o.x) .ToList(); } } @@ -205,31 +161,29 @@ namespace MP.Stats.Components #region Protected Methods - /// + /// Genera colori sfondo 33% rosso / arancione / giallo /// /// /// - protected List backgroundColors(int numRecords, float alpha) + protected List semaphColors(int numRecords, string alpha) { List answ = new List(); -#if false - // verde... - for (int i = 0; i < numRecords / 3; i++) + + int numStep = 5; + // ciclo x numStep-1 + for (int j = 0; j < numStep; j++) { - answ.Add(ChartColor.FromRgba(54, 254, 86, alpha)); - } - // arancione - for (int i = 0; i < numRecords / 3; i++) - { - answ.Add(ChartColor.FromRgba(80, 254, 190, alpha)); + for (int i = 0; i < numRecords / numStep; i++) + { + answ.Add($"rgba({54 + (180 - 54) * j / numStep}, {254 + (180 - 254) * j / numStep}, {86 + (35 - 86) * j / numStep}, {alpha}"); + } } + // chiude while (answ.Count < numRecords) { - answ.Add(ChartColor.FromRgba(180, 180, 35, alpha)); - } -#endif - + answ.Add($"rgba(180, 180, 35, {alpha})"); + } return answ; } @@ -238,29 +192,61 @@ namespace MP.Stats.Components /// /// /// - protected List getLineColors(float alpha) + protected List solidColors(string alpha) { List answ = new List(); -#if false - answ.Add(ChartColor.FromRgba(54, 82, 254, alpha)); -#endif + answ.Add($"rgba(54, 162, 235, {alpha})"); return answ; } - protected async Task HandleRedraw() + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List bgColors { -#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 + 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"); + } + + private List DatiPareto + { + get => ParetoData.Select(x => x.value).ToList(); + } + + private List DatiPlot + { + 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(); } #endregion Protected Methods