Inizio customizzaizone grafici OEE
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<div class="row">
|
||||
@if (RawData == null || RawData.Count == 0)
|
||||
{
|
||||
<div class="col-12">
|
||||
<div class="alert alert-secondary text-center h4"><span class="oi oi-graph"></span> No Chart Data</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="col-2 pr-0" style="max-height: 10em; overflow:hidden; overflow-y: auto;">
|
||||
<ul class="list-group list-group-sm small">
|
||||
@foreach (var item in @ParetoData)
|
||||
{
|
||||
<li class="list-group-item p-1 d-flex justify-content-between align-items-center">
|
||||
@item.label
|
||||
<span class="badge badge-primary badge-pill">@item.value</span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-10">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<BarChart @ref="ParetoGuasti" TItem="double" OptionsObject="barChartOptions" />
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<LineChart @ref="NumGuasti" TItem="double" OptionsObject="lineChartOptions" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,238 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Blazorise.Charts;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MP.Stats.Data;
|
||||
|
||||
namespace MP.Stats.Components
|
||||
{
|
||||
public partial class ChartOEE
|
||||
{
|
||||
#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
|
||||
};
|
||||
|
||||
protected LineChart<double> NumGuasti;
|
||||
|
||||
protected BarChart<double> ParetoGuasti;
|
||||
|
||||
#endregion Protected Fields
|
||||
|
||||
#region Protected Properties
|
||||
|
||||
protected SelectData _currFilter { get; set; } = new SelectData();
|
||||
|
||||
protected List<MP.Data.DatabaseModels.ResScarti> _rawData { get; set; } = new List<MP.Data.DatabaseModels.ResScarti>();
|
||||
|
||||
[Inject]
|
||||
protected MessageService MessageService { get; set; }
|
||||
|
||||
protected List<ChartKV> ParetoData { get; set; } = new List<ChartKV>();
|
||||
|
||||
[Inject]
|
||||
protected MpStatsService StatService { get; set; }
|
||||
|
||||
protected List<ChartTS> TSData { get; set; } = new List<ChartTS>();
|
||||
|
||||
#endregion Protected Properties
|
||||
|
||||
#region Public Properties
|
||||
|
||||
[Parameter]
|
||||
public List<MP.Data.DatabaseModels.ResScarti> RawData
|
||||
{
|
||||
get => _rawData;
|
||||
set
|
||||
{
|
||||
// salvo valori
|
||||
_rawData = value;
|
||||
if (value != null)
|
||||
{
|
||||
// ricalcolo charting data
|
||||
recalcData();
|
||||
var dataReload = Task.Run(async () =>
|
||||
{
|
||||
await HandleRedraw();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private BarChartDataset<double> GetBarChartDataset()
|
||||
{
|
||||
var answ = new BarChartDataset<double>
|
||||
{
|
||||
Label = "Pareto Causali Scarto",
|
||||
Data = ParetoData.Select(x => x.value).ToList(),
|
||||
BackgroundColor = backgroundColors(ParetoData.Count, 0.4f),
|
||||
BorderColor = backgroundColors(ParetoData.Count, 1f),
|
||||
HoverBorderWidth = 5
|
||||
};
|
||||
return answ;
|
||||
}
|
||||
|
||||
private List<string> GetBarChartLabels()
|
||||
{
|
||||
var answ = ParetoData.Select(x => x.label).ToList();
|
||||
return answ;
|
||||
}
|
||||
|
||||
private LineChartDataset<double> GetLineChartDataset()
|
||||
{
|
||||
var answ = new LineChartDataset<double>
|
||||
{
|
||||
Label = "Numero Scarti Periodo",
|
||||
Data = TSData.Select(x => x.Value).ToList(),
|
||||
BorderColor = backgroundColors(1, 1f),
|
||||
Fill = true,
|
||||
PointRadius = 2,
|
||||
SteppedLine = true,
|
||||
BorderDash = new List<int> { }
|
||||
};
|
||||
return answ;
|
||||
}
|
||||
|
||||
private List<string> GetLineChartLabels()
|
||||
{
|
||||
var answ = TSData.Select(x => x.TLabel.ToString("ddd dd.MM")).ToList();
|
||||
return answ;
|
||||
}
|
||||
|
||||
private void recalcData()
|
||||
{
|
||||
if (RawData != null)
|
||||
{
|
||||
ParetoData = RawData
|
||||
.GroupBy(x => x.Causale)
|
||||
.Select(y => new ChartKV() { label = y.First().Descrizione, value = y.Sum(c => c.Qta) })
|
||||
.OrderByDescending(x => x.value)
|
||||
.ToList();
|
||||
|
||||
TSData = RawData
|
||||
.GroupBy(x => x.DataOraRif.Date)
|
||||
.Select(y => new ChartTS() { TLabel = y.First().DataOraRif.Date, Value = y.Sum(c => c.Qta) })
|
||||
.OrderBy(x => x.TLabel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
#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)
|
||||
{
|
||||
List<string> answ = new List<string>();
|
||||
// rosso...
|
||||
for (int i = 0; i < numRecords / 3; i++)
|
||||
{
|
||||
answ.Add(ChartColor.FromRgba(255, 99, 132, alpha));
|
||||
}
|
||||
// arancione
|
||||
for (int i = 0; i < numRecords / 3; i++)
|
||||
{
|
||||
answ.Add(ChartColor.FromRgba(255, 206, 86, alpha));
|
||||
}
|
||||
while (answ.Count < numRecords)
|
||||
{
|
||||
answ.Add(ChartColor.FromRgba(54, 82, 235, alpha));
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
protected async Task HandleRedraw()
|
||||
{
|
||||
if (ParetoGuasti != null)
|
||||
{
|
||||
await ParetoGuasti.Clear();
|
||||
await ParetoGuasti.AddLabelsDatasetsAndUpdate(GetBarChartLabels(), GetBarChartDataset());
|
||||
}
|
||||
if (NumGuasti != null)
|
||||
{
|
||||
await NumGuasti.Clear();
|
||||
await NumGuasti.AddLabelsDatasetsAndUpdate(GetLineChartLabels(), GetLineChartDataset());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,13 @@
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header table-primary p-1">
|
||||
<SelectionFilter SelFilter="currFilter" filterChanged="DoFilter" filterReset="ResetFilter" ChartEnabled="true" CommessaEnabled="false"></SelectionFilter>
|
||||
<SelectionFilter SelFilter="currFilter" filterChanged="DoFilter" filterReset="ResetFilter" chartVisible="ShowCharts" chartsToggle="ToggleChart" ChartEnabled="true"></SelectionFilter>
|
||||
</div>
|
||||
<div class="card-body py-0 px-1">
|
||||
@if (ShowCharts == true)
|
||||
{
|
||||
<ChartOEE RawData="SearchRecords"></ChartOEE>
|
||||
}
|
||||
@if (currRecord != null)
|
||||
{
|
||||
<DetailOee currRecord="@currRecord"></DetailOee>
|
||||
|
||||
@@ -34,9 +34,39 @@ namespace MP.Stats.Pages
|
||||
}
|
||||
}
|
||||
|
||||
private int currPage { get; set; } = 1;
|
||||
private int _currPage { get; set; } = 1;
|
||||
|
||||
private int _numRecord { get; set; } = 10;
|
||||
|
||||
private int currPage
|
||||
{
|
||||
get => _currPage;
|
||||
set
|
||||
{
|
||||
if (_currPage != value)
|
||||
{
|
||||
_currPage = value;
|
||||
var pUpd = Task.Run(async () => await reloadData());
|
||||
pUpd.Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
private bool isLoading { get; set; } = false;
|
||||
private int numRecord { get; set; } = 10;
|
||||
private int numRecord
|
||||
{
|
||||
get => _numRecord;
|
||||
set
|
||||
{
|
||||
if (_numRecord != value)
|
||||
{
|
||||
_numRecord = value;
|
||||
var pUpd = Task.Run(async () => await reloadData());
|
||||
pUpd.Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShowCharts { get; set; } = false;
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
@@ -92,16 +122,14 @@ namespace MP.Stats.Pages
|
||||
await reloadData();
|
||||
}
|
||||
|
||||
protected async Task ForceReload(int newNum)
|
||||
protected void ForceReload(int newNum)
|
||||
{
|
||||
numRecord = newNum;
|
||||
await reloadData();
|
||||
}
|
||||
|
||||
protected async Task ForceReloadPage(int newNum)
|
||||
protected void ForceReloadPage(int newNum)
|
||||
{
|
||||
currPage = newNum;
|
||||
await reloadData();
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
@@ -135,6 +163,14 @@ namespace MP.Stats.Pages
|
||||
currRecord = selRecord;
|
||||
}
|
||||
|
||||
protected async Task ToggleChart(bool doShow)
|
||||
{
|
||||
ShowCharts = !ShowCharts;
|
||||
if (ShowCharts)
|
||||
{
|
||||
await reloadData();
|
||||
}
|
||||
}
|
||||
protected async Task UpdateData()
|
||||
{
|
||||
currRecord = null;
|
||||
@@ -165,11 +201,19 @@ namespace MP.Stats.Pages
|
||||
MessageService.EA_SearchUpdated -= OnSeachUpdated;
|
||||
}
|
||||
|
||||
public void OnSeachUpdated()
|
||||
// public void OnSeachUpdated()
|
||||
// {
|
||||
// InvokeAsync(() =>
|
||||
// {
|
||||
// UpdateData();
|
||||
// StateHasChanged();
|
||||
// });
|
||||
// }
|
||||
public async void OnSeachUpdated()
|
||||
{
|
||||
InvokeAsync(() =>
|
||||
await InvokeAsync(() =>
|
||||
{
|
||||
UpdateData();
|
||||
Task task = UpdateData();
|
||||
StateHasChanged();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user