Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Samuele Locatelli
2022-10-10 12:05:20 +02:00
4 changed files with 342 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
<canvas id="@Id"></canvas>
+162
View File
@@ -0,0 +1,162 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MP.Data;
namespace MP.SPEC.Components.Chart
{
public partial class Line
{
#region Public Properties
[Parameter]
public double AspRatio { get; set; } = 0;
[Parameter]
public List<string> backColor { get; set; } = new List<string>();
[Parameter]
public string ChartId
{
get
{
return Id;
}
set
{
Id = value;
}
}
[Parameter]
public List<chartJsData.chartJsTSerie> DataTS
{
get
{
return _DataTS;
}
set
{
_DataTS = value;
//var pUpd = Task.Run(async () => await renderChart());
//pUpd.Wait();
}
}
[Parameter]
public List<string> Labels { get; set; } = new List<string>();
[Parameter]
public List<string> lineColor { get; set; } = new List<string>();
[Parameter]
public int lTens { get; set; } = 0;
[Parameter]
public string MaxValue { get; set; } = "0";
[Parameter]
public string MinValue { get; set; } = "0";
[Parameter]
public List<string> pointColor { get; set; } = new List<string>();
[Parameter]
public string Title { get; set; } = "Demo Line";
#endregion Public Properties
#region Protected Properties
protected string Id { get; set; } = "CurrId";
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Inizializzazione rendering componente
///
/// partendo da qui: https://www.williamleme.com/posts/2020/003-chartjs-blazor/
/// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ https://www.tutorialsteacher.com/csharp/csharp-anonymous-type
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await renderChart();
}
/// <summary>
/// Inizializzazione rendering componente
///
/// partendo da qui: https://www.williamleme.com/posts/2020/003-chartjs-blazor/
/// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ https://www.tutorialsteacher.com/csharp/csharp-anonymous-type
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected async Task renderChart()
{
// creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js
var config = new
{
type = "line",
options = new
{
responsive = true,
scales = new
{
yAxes = new
{
display = true,
position = "right",
ticks = new
{
maxTicksLimit = 10
},
suggestedMin = MinValue != MaxValue ? MinValue : "auto",
suggestedMax = MinValue != MaxValue ? MaxValue : "auto"
},
xAxes = new
{
type = "time",
distribution = "linear",
}
},
plugins = new
{
legend = new
{
display = false
},
},
Animation = false,
AspectRatio = AspRatio == 0 ? "auto" : $"{AspRatio}"
},
data = new
{
labels = Labels,
datasets = new[]{new
{
data = DataTS, pointBorderColor = backColor, borderColor = lineColor, backgroundColor = backColor, fill = true, PointRadius = 2, BorderWidth = 1, lineTension = lTens, stepped = false, label = Title
}
}
}
}
;
await JSRuntime.InvokeVoidAsync("setup", Id, config);
}
#endregion Protected Methods
#region Private Properties
private List<chartJsData.chartJsTSerie> _DataTS { get; set; } = null!;
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
#endregion Private Properties
}
}
+26
View File
@@ -0,0 +1,26 @@
@using MP.SPEC.Components
@using MP.Data
@using Microsoft.Extensions.Configuration;
@inject IConfiguration Configuration;
@if (!string.IsNullOrEmpty(SelectedODL))
{
<div class="d-flex justify-content-between mb-2">
<div class="px-1 border border-info rounded">
<i class="fa-solid fa-tower-broadcast"></i> <b>@SelectedODL</b>
</div>
</div>
<div class="d-flex">
<div class="px-1 flex-fill">
@if (LevelVal == null || LevelVal.Count == 0)
{
<LoadingDataSmall></LoadingDataSmall>
}
else
{
<MP.SPEC.Components.Chart.Line ChartId="@ODLId" AspRatio="4" DataTS="@LevelVal" lineColor="@getLineColors("0.75")" backColor="@getFillColors("0.25")" pointColor="@getPointColors("1")" lTens="0" MinValue="@MinVal" MaxValue="@MaxVal"></MP.SPEC.Components.Chart.Line>
}
</div>
</div>
}
+153
View File
@@ -0,0 +1,153 @@
using Microsoft.AspNetCore.Components;
using MP.Data;
using MP.Data.DatabaseModels;
using MP.SPEC.Data;
namespace MP.SPEC.Components
{
public partial class ODLPlot
{
#region Public Properties
[Parameter]
public int MachineId { get; set; } = 1;
public string ODLId
{
get => _selODL;
}
[Parameter]
public string SelectedODL
{
get => _selODL;
set => _selODL = value;
}
[Parameter]
public SelectOdlParams SelFilter
{
get => _SelFilter;
set => _SelFilter = value;
}
#endregion Public Properties
#region Protected Fields
protected DateTime lastRec = DateTime.Now.AddMinutes(-1);
protected List<chartJsData.chartJsTSerie> LevelVal = new List<chartJsData.chartJsTSerie>();
protected Dictionary<string, string> listMaxVal = new Dictionary<string, string>();
protected Dictionary<string, string> listMinVal = new Dictionary<string, string>();
#endregion Protected Fields
#region Protected Properties
protected SelectOdlParams _SelFilter { get; set; } = new SelectOdlParams();
protected string _selODL { get; set; } = "";
protected string? MaxVal
{
get
{
string answ = "0";
if (listMaxVal != null && listMaxVal.Count > 0)
{
answ = listMaxVal[SelectedODL] ?? "0";
}
return answ;
}
}
protected string? MinVal
{
get
{
string answ = "0";
if (listMinVal != null && listMinVal.Count > 0)
{
answ = listMinVal[SelectedODL] ?? "0";
}
return answ;
}
}
#endregion Protected Properties
#region Protected Methods
protected List<string> getFillColors(string alpha)
{
List<string> answ = new List<string>();
answ.Add($"rgba(108, 214, 164, {alpha})");
return answ;
}
protected List<string> getLineColors(string alpha)
{
List<string> answ = new List<string>();
answ.Add($"rgba(54, 204, 82, {alpha})");
return answ;
}
protected List<string> getPointColors(string alpha)
{
List<string> answ = new List<string>();
answ.Add($"rgba(108, 158, 118, {alpha})");
return answ;
}
protected override async Task OnInitializedAsync()
{
//await ReloadData();
//await Task.Delay(1);
}
protected override async Task OnParametersSetAsync()
{
isLoading = true;
//await ReloadData();
await Task.Delay(1);
}
//protected async Task ReloadData()
//{
// isLoading = true;
// ListRecords = null;
// await Task.Delay(1);
// ListRecords = await MMDataService.DataLogDtoGetFilt(MachineId, DataLogType.Tools, SelectedODL, StartDate, EndDate);
// await Task.Delay(1);
// // converto in plotdata
// LevelVal = ListRecords.Select(l => new chartJsData.chartJsTSerie() { x = l.DtRif, y = l.ValNum }).ToList();
// await Task.Delay(1);
// isLoading = false;
//}
#endregion Protected Methods
#region Private Fields
private List<ODLModel>? ListRecords = null;
#endregion Private Fields
#region Private Properties
private DateTime EndDate
{
get => _SelFilter.DtEnd;
}
private bool isLoading { get; set; } = false;
private DateTime StartDate
{
get => _SelFilter.DtStart;
}
#endregion Private Properties
}
}