180 lines
4.7 KiB
C#
180 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using GWMS.UI.Data;
|
|
using GWMS.Data.DTO;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Blazorise.Charts;
|
|
using System.Threading;
|
|
|
|
namespace GWMS.UI.Components
|
|
{
|
|
public partial class PlantDetail
|
|
{
|
|
#region Protected Fields
|
|
|
|
protected PlantDTO _currItem = new PlantDTO();
|
|
|
|
protected LineChart<double> LevelVal = new LineChart<double>();
|
|
|
|
protected object lineChartOptions = new
|
|
{
|
|
Scales = new
|
|
{
|
|
XAxes = new object[]
|
|
{
|
|
new {
|
|
Display = true,
|
|
//type = "time"
|
|
}
|
|
},
|
|
YAxes = new object[]
|
|
{
|
|
new {
|
|
Display = true,
|
|
ticks= new {
|
|
suggestedMin = 0,
|
|
suggestedMax = 10000
|
|
}
|
|
}
|
|
}
|
|
},
|
|
Tooltips = new
|
|
{
|
|
Mode = "nearest",
|
|
Intersect = false
|
|
},
|
|
Hover = new
|
|
{
|
|
Mode = "nearest",
|
|
Intersect = false
|
|
},
|
|
Animation = false,
|
|
AspectRatio = 2
|
|
};
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private NavigationManager NavManager { get; set; }
|
|
|
|
private int SelPlantId
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (MessageService.Order_Filter != null)
|
|
{
|
|
answ = MessageService.Order_Filter.PlantId;
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
if (!MessageService.Order_Filter.PlantId.Equals(value))
|
|
{
|
|
MessageService.Order_Filter.PlantId = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected GWMSDataService DataService { get; set; }
|
|
|
|
[Inject]
|
|
protected MessageService MessageService { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public PlantDTO currItem
|
|
{
|
|
get
|
|
{
|
|
return _currItem;
|
|
}
|
|
set
|
|
{
|
|
_currItem = value;
|
|
if (value != null)
|
|
{
|
|
var dataReload = Task.Run(async () =>
|
|
{
|
|
// aggiunta delay o non riesce a disegnare
|
|
Thread.Sleep(50);
|
|
await HandleRedraw();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Private Methods
|
|
|
|
private LineChartDataset<double> GetLineChartDataset()
|
|
{
|
|
var answ = new LineChartDataset<double>
|
|
{
|
|
//Label = "Livello",
|
|
Data = _currItem.LevelTS.Select(x => x.ValDouble).ToList(),
|
|
BorderColor = getLineColors(1f),
|
|
Fill = true,
|
|
PointRadius = 3,
|
|
BorderWidth = 2,
|
|
LineTension = 0,
|
|
BorderDash = new List<int> { }
|
|
};
|
|
return answ;
|
|
}
|
|
|
|
private List<string> GetLineChartLabels()
|
|
{
|
|
var answ = _currItem.LevelTS.Select(x => x.DtEvent.ToString("dd.MM HH")).ToList();
|
|
return answ;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Genera colori sfondo 33% rosso / arancione / giallo
|
|
/// </summary>
|
|
/// <param name="numRecords"></param>
|
|
/// <returns></returns>
|
|
protected List<string> getLineColors(float alpha)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
answ.Add(ChartColor.FromRgba(54, 82, 254, alpha));
|
|
return answ;
|
|
}
|
|
|
|
protected async Task HandleRedraw()
|
|
{
|
|
if (LevelVal != null)
|
|
{
|
|
await LevelVal.Clear();
|
|
await LevelVal.AddLabelsDatasetsAndUpdate(GetLineChartLabels(), GetLineChartDataset());
|
|
}
|
|
}
|
|
|
|
protected void ShowOrders(int currPlantId)
|
|
{
|
|
SelPlantId = currPlantId;
|
|
// rimando...
|
|
NavManager.NavigateTo($"Orders");
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |