From de3ce0f1144c30c73bd83486081f54ab6fa8a057 Mon Sep 17 00:00:00 2001 From: "zaccaria.majid" Date: Mon, 10 Oct 2022 10:11:02 +0200 Subject: [PATCH] inizio odl Plot --- MP.SPEC/Components/Chart/Line.razor | 1 + MP.SPEC/Components/Chart/Line.razor.cs | 162 +++++++++++++++++++++++++ MP.SPEC/Components/ODLPlot.razor | 26 ++++ MP.SPEC/Components/ODLPlot.razor.cs | 153 +++++++++++++++++++++++ 4 files changed, 342 insertions(+) create mode 100644 MP.SPEC/Components/Chart/Line.razor create mode 100644 MP.SPEC/Components/Chart/Line.razor.cs create mode 100644 MP.SPEC/Components/ODLPlot.razor create mode 100644 MP.SPEC/Components/ODLPlot.razor.cs diff --git a/MP.SPEC/Components/Chart/Line.razor b/MP.SPEC/Components/Chart/Line.razor new file mode 100644 index 00000000..7eddca28 --- /dev/null +++ b/MP.SPEC/Components/Chart/Line.razor @@ -0,0 +1 @@ + diff --git a/MP.SPEC/Components/Chart/Line.razor.cs b/MP.SPEC/Components/Chart/Line.razor.cs new file mode 100644 index 00000000..746912b9 --- /dev/null +++ b/MP.SPEC/Components/Chart/Line.razor.cs @@ -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 backColor { get; set; } = new List(); + + [Parameter] + public string ChartId + { + get + { + return Id; + } + set + { + Id = value; + } + } + + [Parameter] + public List DataTS + { + get + { + return _DataTS; + } + + set + { + _DataTS = value; + //var pUpd = Task.Run(async () => await renderChart()); + //pUpd.Wait(); + } + } + + [Parameter] + public List Labels { get; set; } = new List(); + + [Parameter] + public List lineColor { get; set; } = new List(); + + [Parameter] + public int lTens { get; set; } = 0; + + [Parameter] + public string MaxValue { get; set; } = "0"; + + [Parameter] + public string MinValue { get; set; } = "0"; + + [Parameter] + public List pointColor { get; set; } = new List(); + + [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 + + /// + /// 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 + /// + /// + /// + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await renderChart(); + } + + /// + /// 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 + /// + /// + /// + 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 _DataTS { get; set; } = null!; + + [Inject] + private IJSRuntime JSRuntime { get; set; } = null!; + + #endregion Private Properties + } +} \ No newline at end of file diff --git a/MP.SPEC/Components/ODLPlot.razor b/MP.SPEC/Components/ODLPlot.razor new file mode 100644 index 00000000..c67b5ae0 --- /dev/null +++ b/MP.SPEC/Components/ODLPlot.razor @@ -0,0 +1,26 @@ +@using MP.SPEC.Components +@using MP.Data +@using Microsoft.Extensions.Configuration; + +@inject IConfiguration Configuration; + +@if (!string.IsNullOrEmpty(SelectedODL)) +{ +
+
+ @SelectedODL +
+
+
+
+ @if (LevelVal == null || LevelVal.Count == 0) + { + + } + else + { + + } +
+
+} diff --git a/MP.SPEC/Components/ODLPlot.razor.cs b/MP.SPEC/Components/ODLPlot.razor.cs new file mode 100644 index 00000000..ed3197ef --- /dev/null +++ b/MP.SPEC/Components/ODLPlot.razor.cs @@ -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 LevelVal = new List(); + protected Dictionary listMaxVal = new Dictionary(); + protected Dictionary listMinVal = new Dictionary(); + + #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 getFillColors(string alpha) + { + List answ = new List(); + answ.Add($"rgba(108, 214, 164, {alpha})"); + return answ; + } + + protected List getLineColors(string alpha) + { + List answ = new List(); + answ.Add($"rgba(54, 204, 82, {alpha})"); + return answ; + } + + protected List getPointColors(string alpha) + { + List answ = new List(); + 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? 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 + } +} \ No newline at end of file