Fix display grafico + date storico impianto

This commit is contained in:
Samuele Locatelli
2022-03-01 18:40:49 +01:00
parent 0728b898eb
commit 45f7f1d4e4
10 changed files with 201 additions and 73 deletions
+15 -1
View File
@@ -31,6 +31,9 @@
[Parameter]
public List<string> Labels { get; set; } = new List<string>();
[Parameter]
public List<string> pointColor { get; set; } = new List<string>();
[Parameter]
public List<string> lineColor { get; set; } = new List<string>();
@@ -89,6 +92,7 @@
yAxes = new
{
display = true,
position = "right",
ticks = new
{
maxTicksLimit = 10
@@ -102,6 +106,13 @@
distribution = "linear",
}
},
plugins = new
{
legend = new
{
display = false
},
},
Animation = false,
AspectRatio = AspRatio == 0 ? "auto" : $"{AspRatio}"
},
@@ -109,13 +120,16 @@
{
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
+124
View File
@@ -0,0 +1,124 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Rendering;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
namespace GWMS.UI.Components
{
/// <summary>
/// override calsse inputdate da
/// https://github.com/dotnet/aspnetcore/issues/18078
/// </summary>
/// <typeparam name="TValue"></typeparam>
public class InputDateTime<TValue> : InputDate<TValue>
{
#region Private Fields
private const string DateFormat = "yyyy-MM-ddTHH:mm:ss";
#endregion Private Fields
#region Private Methods
private static bool TryParseDateTime(string value, out TValue result)
{
var success = BindConverter.TryConvertToDateTime(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue);
if (success)
{
result = (TValue)(object)parsedValue;
return true;
}
else
{
result = default;
return false;
}
}
private static bool TryParseDateTimeOffset(string value, out TValue result)
{
var success = BindConverter.TryConvertToDateTimeOffset(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue);
if (success)
{
result = (TValue)(object)parsedValue;
return true;
}
else
{
result = default;
return false;
}
}
#endregion Private Methods
#region Protected Methods
/// <inheritdoc />
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "input");
builder.AddMultipleAttributes(1, AdditionalAttributes);
builder.AddAttribute(2, "type", "datetime-local");
builder.AddAttribute(3, "class", CssClass);
builder.AddAttribute(4, "value", BindConverter.FormatValue(CurrentValueAsString));
builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder<string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
builder.CloseElement();
}
/// <inheritdoc />
protected override string FormatValueAsString(TValue value)
{
switch (value)
{
case DateTime dateTimeValue:
return BindConverter.FormatValue(dateTimeValue, DateFormat, CultureInfo.InvariantCulture);
case DateTimeOffset dateTimeOffsetValue:
return BindConverter.FormatValue(dateTimeOffsetValue, DateFormat, CultureInfo.InvariantCulture);
default:
return string.Empty; // Handles null for Nullable<DateTime>, etc.
}
}
/// <inheritdoc />
protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage)
{
// Unwrap nullable types. We don't have to deal with receiving empty values for nullable
// types here, because the underlying InputBase already covers that.
var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue);
bool success;
if (targetType == typeof(DateTime))
{
success = TryParseDateTime(value, out result);
}
else if (targetType == typeof(DateTimeOffset))
{
success = TryParseDateTimeOffset(value, out result);
}
else
{
throw new InvalidOperationException($"The type '{targetType}' is not a supported date type.");
}
if (success)
{
validationErrorMessage = null;
return true;
}
else
{
validationErrorMessage = string.Format(ParsingErrorMessage, FieldIdentifier.FieldName);
return false;
}
}
#endregion Protected Methods
}
}
+1 -1
View File
@@ -103,7 +103,7 @@
}
else
{
<Line Id="@(currItem.PlantCode)" AspRatio="2" DataTS="@LevelVal" lineColor="@getLineColors("1")" backColor="@getFillColors("0.25")" lTens="0" Title="Livello" MinValue="0" MaxValue="30000"></Line>
<Line Id="@(currItem.PlantCode)" AspRatio="2" DataTS="@LevelVal" lineColor="@getLineColors("0.75")" backColor="@getFillColors("0.25")" pointColor="@getPointColors("1")" lTens="0" Title="Livello" MinValue="0" MaxValue="30000"></Line>
}
</div>
</div>
+33 -43
View File
@@ -1,13 +1,13 @@
using System;
using GWMS.Data;
using GWMS.Data.DTO;
using GWMS.UI.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration;
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 System.Threading;
using Microsoft.Extensions.Configuration;
using GWMS.Data;
using System.Threading.Tasks;
namespace GWMS.UI.Components
{
@@ -90,27 +90,13 @@ namespace GWMS.UI.Components
// aggiunta delay o non riesce a disegnare
int ChartWaitDelay = 150;
int.TryParse(Configuration["ChartWaitDelay"], out ChartWaitDelay);
Random rnd = new Random();
Thread.Sleep(ChartWaitDelay*rnd.Next(150));
Thread.Sleep(ChartWaitDelay);
await HandleRedraw();
});
}
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await HandleRedraw();
}
}
protected override async Task OnInitializedAsync()
{
await HandleRedraw();
}
public string headerStatus
{
get
@@ -148,27 +134,6 @@ namespace GWMS.UI.Components
redFact = answ;
}
#if false
private LineChartDataset<double> GetLineChartDataset()
{
fixRedFactor();
var answ = new LineChartDataset<double>
{
//Label = "Livello",
Data = _currItem.LevelTS.OrderByDescending(x => x.DtEvent).Where((cat, index) => index % redFact == 0).OrderBy(x => x.DtEvent).Select(x => x.ValDouble).ToList(),
BorderColor = getLineColors(1f),
BackgroundColor = getFillColors(0.25f),
Fill = true,
PointRadius = 3,
BorderWidth = 2,
LineTension = 0,
BorderDash = new List<int> { }
};
return answ;
}
#endif
#endregion Private Methods
#region Protected Methods
@@ -197,6 +162,18 @@ namespace GWMS.UI.Components
return answ;
}
/// <summary>
/// Genera colori punti
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> getPointColors(string alpha)
{
List<string> answ = new List<string>();
answ.Add($"rgba(108, 118, 158, {alpha})");
return answ;
}
protected async Task HandleRedraw()
{
fixRedFactor();
@@ -204,6 +181,19 @@ namespace GWMS.UI.Components
LevelVal = _currItem.LevelTS.OrderByDescending(x => x.DtEvent).Where((cat, index) => index % redFact == 0).OrderBy(x => x.DtEvent).Select(r => new chartJsData.chartJsTSerie() { x = r.DtEvent, y = r.ValDouble }).ToList();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await HandleRedraw();
}
}
protected override async Task OnInitializedAsync()
{
await HandleRedraw();
}
protected void ShowDetail(int currPlantId)
{
SelPlantId = currPlantId;
+1 -1
View File
@@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.2203.0117</Version>
<Version>1.0.2203.0118</Version>
<UserSecretsId>95c9f021-52d1-4390-a670-5810b7b777b0</UserSecretsId>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
+19 -19
View File
@@ -26,32 +26,32 @@
</div>
</div>
@*<div class="p-2">
@if (ShowAddNew)
{
<button class="btn btn-block btn-sm btn-success" @onclick="CreateNew" title="Aggiunta nuovo Ordine"><i class="far fa-calendar-plus"></i></button>
}
@if (ShowAddNew)
{
<button class="btn btn-block btn-sm btn-success" @onclick="CreateNew" title="Aggiunta nuovo Ordine"><i class="far fa-calendar-plus"></i></button>
}
</div>*@
</div>
</div>
<div class="col-12 col-lg-4 text-right">
<div class="d-flex justify-content-between">
<div class="p-2">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">inizio:</span>
<div class="d-flex justify-content-between">
<div class="p-2">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">inizio:</span>
</div>
<input class="form-control form-control-sm" type="date" @bind="@DateStart"></input>
</div>
</div>
<div class="p-2">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">fine:</span>
</div>
<input class="form-control form-control-sm" type="date" @bind="@DateEnd"></input>
</div>
<input class="form-control form-control-sm" TValue="DateTime?" Date="@DateStart" />
</div>
</div>
<div class="p-2">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">fine:</span>
</div>
<input class="form-control form-control-sm" TValue="DateTime?" Date="@DateEnd" />
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-4 text-right">
<div class="d-flex justify-content-between">
+5 -5
View File
@@ -2,15 +2,15 @@
window.setup = (id, config) => {
var ctx = document.getElementById(id).getContext('2d');
let currentDate = new Date();
console.log(currentDate + " - Calling setup...");
console.log(id);
//console.log(currentDate + " - Calling setup...");
//console.log(id);
if (window['chart-' + id] instanceof Chart) {
//window.myChart.destroy();
window['chart-' + id].destroy();
console.log("Chart " + id + " destroyed!");
//console.log("Chart " + id + " destroyed!");
}
window['chart-' + id] = new Chart(ctx, config);
console.log("Chart " + id + " created!");
console.log(window['chart-' + id]);
//console.log("Chart " + id + " created!");
//console.log(window['chart-' + id]);
}
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>GWMS - Gas Warehouse Management System</i>
<h4>Versione: 1.0.2203.0117</h4>
<h4>Versione: 1.0.2203.0118</h4>
<br /> Note di rilascio:
<ul>
<li>
+1 -1
View File
@@ -1 +1 @@
1.0.2203.0117
1.0.2203.0118
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.0.2203.0117</version>
<version>1.0.2203.0118</version>
<url>http://nexus.steamware.net/repository/SWS/GWMS/stable/0/GWMS.UI.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/GWMS/stable/0/ChangeLog.html</changelog>
<mandatory>false</mandatory>