diff --git a/MP.SPEC/Components/Chart/Doughnut.razor b/MP.SPEC/Components/Chart/Doughnut.razor new file mode 100644 index 00000000..7eddca28 --- /dev/null +++ b/MP.SPEC/Components/Chart/Doughnut.razor @@ -0,0 +1 @@ + diff --git a/MP.SPEC/Components/Chart/Doughnut.razor.cs b/MP.SPEC/Components/Chart/Doughnut.razor.cs new file mode 100644 index 00000000..04c95853 --- /dev/null +++ b/MP.SPEC/Components/Chart/Doughnut.razor.cs @@ -0,0 +1,160 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using MP.Data; + +namespace MP.SPEC.Components.Chart +{ + public partial class Doughnut + { + #region Public Properties + + [Parameter] + public double AspRatio { get; set; } = 0; + + [Parameter] + public List backColor { get; set; } = new List(); + + [Parameter] + public int 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 int Id { get; set; } = 0; + + #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 = "doughnut", + options = new + { + responsive = true, + //scales = new + //{ + // yAxes = new + // { + // display = true, + // position = "right", + // ticks = new + // { + // maxTicksLimit = 10 + // } + // }, + // 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 = 300, pointBorderColor = backColor, 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/ListODL.razor b/MP.SPEC/Components/ListODL.razor index 324958d1..9bcc651b 100644 --- a/MP.SPEC/Components/ListODL.razor +++ b/MP.SPEC/Components/ListODL.razor @@ -107,6 +107,7 @@ else } } + diff --git a/MP.SPEC/Components/ListODL.razor.cs b/MP.SPEC/Components/ListODL.razor.cs index f3a49651..dc8eaabb 100644 --- a/MP.SPEC/Components/ListODL.razor.cs +++ b/MP.SPEC/Components/ListODL.razor.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; +using MP.Data; using MP.Data.DatabaseModels; using MP.SPEC.Data; using Newtonsoft.Json.Linq; @@ -103,7 +104,7 @@ namespace MP.SPEC.Components #region Private Fields private ODLModel? currRecord = null; - + protected async Task selectRecord(ODLModel? currRec) { await Task.Delay(1); @@ -177,7 +178,16 @@ namespace MP.SPEC.Components } return answ; } - + private StatODLModel val2plot(int IdxStato) + { + StatODLModel answ = new StatODLModel(); + if (ListRecords != null) + { + answ = ListOdlStats + .Where(x => x.IdxStato == IdxStato).SingleOrDefault(); + } + return answ; + } #endregion Private Methods } } \ No newline at end of file diff --git a/MP.SPEC/Components/ODLPlot.razor b/MP.SPEC/Components/ODLPlot.razor index c67b5ae0..d2cd6d69 100644 --- a/MP.SPEC/Components/ODLPlot.razor +++ b/MP.SPEC/Components/ODLPlot.razor @@ -1,26 +1,63 @@ -@using MP.SPEC.Components -@using MP.Data -@using Microsoft.Extensions.Configuration; +@*//Chart.razor*@ +@*inject IJSRuntime JSRuntime@**@ -@inject IConfiguration Configuration; + -@if (!string.IsNullOrEmpty(SelectedODL)) -{ -
-
- @SelectedODL -
-
-
-
- @if (LevelVal == null || LevelVal.Count == 0) +@code { + + [Inject] + private IJSRuntime JSRuntime { get; set; } = null!; + + + public enum ChartType + { + Pie, + Bar + } + + [Parameter] + public string Id { get; set; } + + [Parameter] + public ChartType Type { get; set; } + + [Parameter] + public string[] Data { get; set; } + + [Parameter] + public string[] BackgroundColor { get; set; } + + [Parameter] + public string[] Labels { get; set; } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + var config = new + { + Type = Type.ToString().ToLower(), + Options = new { - - } - else + Responsive = true, + Scales = new + { + YAxes = new[] + { + new { Ticks = new { + BeginAtZero=true + } } + } + } + }, + Data = new { - + Datasets = new[] + { + new { Data = Data, BackgroundColor = BackgroundColor} + }, + Labels = Labels } -
-
-} + }; + + await JSRuntime.InvokeVoidAsync("setup", Id, config); + } +} \ No newline at end of file diff --git a/MP.SPEC/Components/ODLPlot.razor.cs b/MP.SPEC/Components/ODLPlot.razor.cs index ed3197ef..5f282702 100644 --- a/MP.SPEC/Components/ODLPlot.razor.cs +++ b/MP.SPEC/Components/ODLPlot.razor.cs @@ -1,153 +1 @@ -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 + \ No newline at end of file diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index fdbcc114..a2d3dd02 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2210.1009 + 6.16.2210.1013 @@ -14,6 +14,16 @@ + + + + + + + + + + @@ -21,10 +31,6 @@ - - - - diff --git a/MP.SPEC/Pages/_Layout.cshtml b/MP.SPEC/Pages/_Layout.cshtml index 9353216d..4b0f428f 100644 --- a/MP.SPEC/Pages/_Layout.cshtml +++ b/MP.SPEC/Pages/_Layout.cshtml @@ -32,6 +32,9 @@ + + + @*Gestione autoriconnessione: https://github.com/dotnet/aspnetcore/issues/38305 (vedere anche https://docs.microsoft.com/it-it/aspnet/core/blazor/fundamentals/signalr?view=aspnetcore-6.0#modify-the-reconnection-handler-blazor-server)*@