From 1ecb5a545f466ed87d5bd353bbd5bf927df59a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ben=C3=AD=C4=8Dek?= Date: Sun, 17 Dec 2023 18:09:39 +0100 Subject: [PATCH] Main Update - add RTD8TM Chart --- App.razor | 9 ++- Components/RTD8TMChanelComponent.razor | 8 +- Components/RTD8TMGraphComponent.razor | 79 +++++++++++++++++++ ...GraphModel.cs => RTD8TMGraphPointModel.cs} | 4 +- Pages/RTD8TMPage.razor | 11 ++- Services/RTD8TMService.cs | 53 +++++++++++-- UI_SequentMicrosystems.csproj | 1 + _Imports.razor | 2 +- wwwroot/css/Custom.css | 8 +- 9 files changed, 152 insertions(+), 23 deletions(-) create mode 100644 Components/RTD8TMGraphComponent.razor rename Models/{RTD8TMGraphModel.cs => RTD8TMGraphPointModel.cs} (52%) diff --git a/App.razor b/App.razor index bc45625..2019642 100644 --- a/App.razor +++ b/App.razor @@ -1,4 +1,5 @@ - + + @@ -11,4 +12,8 @@ - \ No newline at end of file + + +@code{ + +} \ No newline at end of file diff --git a/Components/RTD8TMChanelComponent.razor b/Components/RTD8TMChanelComponent.razor index c64fe9d..d08d7df 100644 --- a/Components/RTD8TMChanelComponent.razor +++ b/Components/RTD8TMChanelComponent.razor @@ -54,12 +54,16 @@ /// private void ChangeName(string NewName) { + if (NewName == "") + { + NewName = "----------"; + } RTD8tmService.SetChanelNames(StackID, ChanelID, NewName); } - private float RecalculateValues(float resistance, byte Type = 0) + public float RecalculateValues(float resistance, byte Type = 0) { if (Type == RTD8TMSensorTypes.PT100) { @@ -70,7 +74,7 @@ return resistance; } } - private string ValueType(byte Type) + public string ValueType(byte Type) { if (Type == RTD8TMSensorTypes.PT100) { diff --git a/Components/RTD8TMGraphComponent.razor b/Components/RTD8TMGraphComponent.razor new file mode 100644 index 0000000..87368cb --- /dev/null +++ b/Components/RTD8TMGraphComponent.razor @@ -0,0 +1,79 @@ +@using ApexCharts +@using UI_SequentMicrosystems.Components +@using UI_SequentMicrosystems.Services +@using UI_SequentMicrosystems.Models + +@inject RTD8TMService _RTD8TMService + + + + @foreach (byte stack in _RTD8TMService.GetActualData().Keys) + { + for (byte chanel = 0; chanel < 8; chanel++) + { + if (_RTD8TMService.GetChanelName(stack, chanel) != "----------") + { + + } + } + } + + +@code { + private ApexChart chart; + private ApexChartOptions chartOptions; + + + protected override void OnInitialized() + { + _RTD8TMService.EventUpdateGraph += UpdateChart; + + + chartOptions = new ApexChartOptions + { + Theme = new Theme + { + Mode = Mode.Dark, + }, + Legend = new Legend + { + Position = LegendPosition.Bottom, + FontSize = "20px", + HorizontalAlign = Align.Center + } + }; + } + + public async Task UpdateChart(object? o, bool b) + { + await InvokeAsync(() => + { + chart.UpdateSeriesAsync(false); + + StateHasChanged(); + + }); + } + + + + + + + + + + + + + +} diff --git a/Models/RTD8TMGraphModel.cs b/Models/RTD8TMGraphPointModel.cs similarity index 52% rename from Models/RTD8TMGraphModel.cs rename to Models/RTD8TMGraphPointModel.cs index 595b02b..68f9022 100644 --- a/Models/RTD8TMGraphModel.cs +++ b/Models/RTD8TMGraphPointModel.cs @@ -1,8 +1,8 @@ namespace UI_SequentMicrosystems.Models { - public class RTD8TMGraphModel + public class RTD8TMGraphPointModel { - public SortedList Data { get; set; } + public float Value { get; set; } public DateTime Time { get; set; } } } diff --git a/Pages/RTD8TMPage.razor b/Pages/RTD8TMPage.razor index cb6d3f3..1d5d82d 100644 --- a/Pages/RTD8TMPage.razor +++ b/Pages/RTD8TMPage.razor @@ -2,6 +2,7 @@ @using Blazored.Modal.Services @using UI_SequentMicrosystems.Components @using UI_SequentMicrosystems.Services +@using UI_SequentMicrosystems.Models @using Blazored.Modal @inject NavigationManager Navigator @@ -42,10 +43,11 @@
-
-
- 1 - Future Graph -
+
+ @if (_RTD8TMService.GraphData.Keys.Count != 0) + { + + }
@@ -86,6 +88,7 @@ }); } + diff --git a/Services/RTD8TMService.cs b/Services/RTD8TMService.cs index b3f4630..f6d7f35 100644 --- a/Services/RTD8TMService.cs +++ b/Services/RTD8TMService.cs @@ -1,4 +1,5 @@ using System.Timers; +using UI_SequentMicrosystems.Components; using UI_SequentMicrosystems.Models; using Wrapper_Api_SequentMicrosystems.RTD8TM; @@ -9,9 +10,9 @@ namespace UI_SequentMicrosystems.Services private SortedList ChanelNames = new SortedList(); private SortedList ActualValues = new SortedList(); private SortedList ValuesType = new SortedList(); - private List GraphData = new(); + public SortedList>> GraphData = new(); private byte GraphDataCounterCount = 10; - private byte GraphDataCounter = 0; + private byte GraphDataCounter = 9; private string? Address { get; set; } @@ -20,6 +21,7 @@ namespace UI_SequentMicrosystems.Services public delegate Task AsyncEventHandler(object? sender, TEventArgs? e); public event AsyncEventHandler? EventUpdateValues; + public event AsyncEventHandler? EventUpdateGraph; public RTD8TMService() { @@ -72,7 +74,13 @@ namespace UI_SequentMicrosystems.Services if (GraphDataCounter >= GraphDataCounterCount) { GraphDataCounter = 0; - GraphData.Add(new() { Data = ActualValues, Time = DateTime.Now }); + + ReadChartData(); + + if (EventUpdateGraph != null) + { + await EventUpdateGraph.Invoke(this, true); + } } else { @@ -227,19 +235,50 @@ namespace UI_SequentMicrosystems.Services //Graph Data + /// + /// Get Chart data + /// + public void ReadChartData() + { + DateTime time = DateTime.Now; + + foreach (byte stack in ActualValues.Keys) + { + if (!GraphData.ContainsKey(stack)) + { + GraphData.Add(stack, new()); + + for (int chanel = 0; chanel < 8; chanel++) + { + GraphData[stack].Add(new()); + } + } + + for (byte chanel = 0; chanel < 8; chanel++) + { + GraphData[stack][chanel].Add(new RTD8TMGraphPointModel() { Value = new RTD8TMChanelComponent().RecalculateValues(ActualValues[stack][chanel], GetValueType(stack, chanel)), Time = time }); + } + } + } + /// /// Get data for graph visualize /// - /// saved Graphn Data - public List GetGraphData() + /// saved chart chanel Data + public List GetChartData(byte StackID, byte Chanel) { - return GraphData; + if (!GraphData.ContainsKey(StackID)) + { + return new List(); + } + + return GraphData[StackID][Chanel]; } /// /// Clear data from Graph /// - public void ClearGraph() + public void ClearChart() { GraphData.Clear(); } diff --git a/UI_SequentMicrosystems.csproj b/UI_SequentMicrosystems.csproj index fd8339f..0f32045 100644 --- a/UI_SequentMicrosystems.csproj +++ b/UI_SequentMicrosystems.csproj @@ -8,6 +8,7 @@ + diff --git a/_Imports.razor b/_Imports.razor index 75740a0..ee471be 100644 --- a/_Imports.razor +++ b/_Imports.razor @@ -7,4 +7,4 @@ @using Microsoft.AspNetCore.Components.WebAssembly.Http @using Microsoft.JSInterop @using UI_SequentMicrosystems -@using UI_SequentMicrosystems.Layout +@using UI_SequentMicrosystems.Layout \ No newline at end of file diff --git a/wwwroot/css/Custom.css b/wwwroot/css/Custom.css index d008172..46ac6c6 100644 --- a/wwwroot/css/Custom.css +++ b/wwwroot/css/Custom.css @@ -3,13 +3,11 @@ color: white; } - -.graybg { - background: gray; - color: yellow; +.c-bg-black { + background: black; + color: white; } - .no-border { border: 0; box-shadow: none; /* You may want to include this as bootstrap applies these styles too */