completato grafico anche x action: ora si passa a nuova pag

This commit is contained in:
Samuele Locatelli
2022-02-26 14:26:56 +01:00
parent f0fa776829
commit 3e5a36311c
4 changed files with 129 additions and 221 deletions
+57 -64
View File
@@ -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<double> PieVC = new PieChart<double>();
protected LineChart<double> TimeSerieVC = new LineChart<double>();
#endif
#endregion Protected Fields
#region Private Properties
private List<double> DatiPareto
{
get => ParetoData.Select(x => x.value).ToList();
}
private List<chartJsData.chartJsTSerie> DatiPlot
{
get => TSData;
}
private List<string> LabelPareto
{
get => ParetoData.Select(x => x.label).ToList();
}
private List<string> 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<MP.Data.DatabaseModels.ResControlli> _rawData { get; set; } = new List<MP.Data.DatabaseModels.ResControlli>();
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> bgColors
{
get => semaphColors(ParetoData.Count, "0.3");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> lineColor
{
get => solidColors("1");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> 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<double> DatiPareto
{
get => ParetoData.Select(x => x.value).ToList();
}
private List<chartJsData.chartJsTSerie> DatiPlot
{
get => TSData;
}
private List<string> LabelPareto
{
get => ParetoData.Select(x => x.label).ToList();
}
private List<string> 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
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> bgColors
{
get => semaphColors(ParetoData.Count, "0.3");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> lineColor
{
get => solidColors("1");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> lineColors
{
get => semaphColors(ParetoData.Count, "1");
}
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
@@ -233,7 +227,6 @@ namespace MP.Stats.Components
return answ;
}
#endregion Protected Methods
}
}
-73
View File
@@ -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<double> DatiPareto
+5 -3
View File
@@ -1,4 +1,6 @@
<div class="row">
@using MP.Stats.Components.ChartJs
<div class="row">
@if (RawData == null || RawData.Count == 0)
{
<div class="col-12">
@@ -21,10 +23,10 @@
<div class="col-10">
<div class="row">
<div class="col-2">
@* <PieChart @ref="PieVC" TItem="double" OptionsObject="pieChartOptions" />*@
<PieChart Id="PieAzioni" AspRatio="1" LegendPos="bottom" Data="@DatiPareto" Labels="@LabelPareto" lineColor="@lineColors" backColor="@bgColors" Title="Azioni"></PieChart>
</div>
<div class="col-10">
@* <LineChart @ref="TimeSerieVC" TItem="double" OptionsObject="lineChartOptions" />*@
<Line Id="PlotAzioni" AspRatio="6" DataTS="@DatiPlot" Labels="@LabelPlot" lineColor="@lineColor" backColor="@lineColor" lTens="0" Title="Azioni Utente"></Line>
</div>
</div>
</div>
+67 -81
View File
@@ -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<ChartTS> TSData { get; set; } = new List<ChartTS>();
protected List<chartJsData.chartJsTSerie> TSData { get; set; } = new List<chartJsData.chartJsTSerie>();
#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<double> GetBarChartDataset()
{
var answ = new PieChartDataset<double>
{
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<string> GetBarChartLabels()
{
var answ = ParetoData.Select(x => x.label).ToList();
return answ;
}
#if false
/// <summary>
/// Elenco 2 linee x controli KO /KO
/// </summary>
/// <returns></returns>
private LineChartDataset<double> GetLineChartDataset()
{
var answ = new LineChartDataset<double>
{
Label = "Numero Azioni",
Data = TSData.Select(x => x.Value).ToList(),
BorderColor = getLineColors(1f),
Fill = true,
PointRadius = 2,
LineTension = 0,
BorderDash = new List<int> { }
};
return answ;
}
#endif
private List<string> 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
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> backgroundColors(int numRecords, float alpha)
protected List<string> semaphColors(int numRecords, string alpha)
{
List<string> answ = new List<string>();
#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
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> getLineColors(float alpha)
protected List<string> solidColors(string alpha)
{
List<string> answ = new List<string>();
#if false
answ.Add(ChartColor.FromRgba(54, 82, 254, alpha));
#endif
answ.Add($"rgba(54, 162, 235, {alpha})");
return answ;
}
protected async Task HandleRedraw()
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> 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");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> lineColor
{
get => solidColors("1");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> lineColors
{
get => semaphColors(ParetoData.Count, "1");
}
private List<double> DatiPareto
{
get => ParetoData.Select(x => x.value).ToList();
}
private List<chartJsData.chartJsTSerie> DatiPlot
{
get => TSData;
}
private List<string> LabelPareto
{
get => ParetoData.Select(x => x.label).ToList();
}
private List<string> LabelPlot
{
get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList();
}
#endregion Protected Methods