Fix grafici controlli

This commit is contained in:
Samuele Locatelli
2022-02-26 14:18:47 +01:00
parent a3a8c0ffaf
commit f0fa776829
7 changed files with 77 additions and 93 deletions
+6 -4
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,12 +23,12 @@
<div class="col-10">
<div class="row">
<div class="col-2">
<PieChart @ref="PieVC" TItem="double" OptionsObject="pieChartOptions" />
<PieChart Id="PieControlli" AspRatio="1" LegendPos="bottom" Data="@DatiPareto" Labels="@LabelPareto" lineColor="@lineColors" backColor="@bgColors" Title="Esito Controlli"></PieChart>
</div>
<div class="col-10">
<LineChart @ref="TimeSerieVC" TItem="double" OptionsObject="lineChartOptions" />
<Line Id="NumControlli" AspRatio="6" DataTS="@DatiPlot" Labels="@LabelPlot" lineColor="@lineColor" backColor="@lineColor" lTens="0" Title="Num Controlli"></Line>
</div>
</div>
</div>
}
</div>*@
</div>
+57 -82
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,54 +132,27 @@ namespace MP.Stats.Components
#region Private Methods
#if false
private PieChartDataset<double> GetBarChartDataset()
private List<double> DatiPareto
{
var answ = new PieChartDataset<double>
{
Label = "Numero Controlli",
Data = ParetoData.Select(x => x.value).ToList(),
BackgroundColor = getPieColors(0.4f),
BorderColor = getPieColors(1f),
HoverBorderWidth = 3
};
return answ;
}
#endif
private List<string> GetBarChartLabels()
{
var answ = ParetoData.Select(x => x.label).ToList();
return answ;
get => ParetoData.Select(x => x.value).ToList();
}
#if false
/// <summary>
/// Elenco 2 linee x controli KO /KO
/// </summary>
/// <returns></returns>
private LineChartDataset<double> GetLineChartDataset()
private List<chartJsData.chartJsTSerie> DatiPlot
{
var answ = new LineChartDataset<double>
{
Label = "Numero controlli",
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();
return answ;
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)
@@ -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
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> getLineColors(float alpha)
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>
/// <returns></returns>
protected List<string> semaphColors(int numRecords, string alpha)
{
List<string> answ = new List<string>();
#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
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> getPieColors(float alpha)
protected List<string> solidColors(string alpha)
{
List<string> answ = new List<string>();
#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
}
+10 -3
View File
@@ -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<double> Data { get; set; } = new List<double>();
@@ -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
{
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>6.14.2202.2613</Version>
<Version>6.14.2202.2614</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 6.14.2202.2613</h4>
<h4>Versione: 6.14.2202.2614</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
6.14.2202.2613
6.14.2202.2614
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.14.2202.2613</version>
<version>6.14.2202.2614</version>
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>