From 6399f1750ca9c692f7770eb8a648c27dcc3a4d68 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Mon, 28 Aug 2023 18:55:15 -0500 Subject: [PATCH] Attempt to improve responsiveness of dashboard --- .../Charts/NetworkDownloadRate.razor | 37 +++++++++++-------- .../Dashboard/Charts/NetworkUploadRate.razor | 36 ++++++++++-------- .../Charts/ProcessorUtilization.razor | 36 ++++++++++-------- .../Pages/Dashboard/Charts/StorageUsage.razor | 10 ++++- 4 files changed, 69 insertions(+), 50 deletions(-) diff --git a/LANCommander/Pages/Dashboard/Charts/NetworkDownloadRate.razor b/LANCommander/Pages/Dashboard/Charts/NetworkDownloadRate.razor index 488e315..665c16b 100644 --- a/LANCommander/Pages/Dashboard/Charts/NetworkDownloadRate.razor +++ b/LANCommander/Pages/Dashboard/Charts/NetworkDownloadRate.razor @@ -3,7 +3,9 @@ @using AntDesign.Charts; @using System.Collections.Concurrent; - + + + @code { [Parameter] public int TimerHistory { get; set; } @@ -11,6 +13,7 @@ IChartComponent? Chart; System.Timers.Timer Timer; + bool Loading = true; Dictionary Data = new Dictionary(); @@ -39,27 +42,29 @@ } }; - protected override async Task OnInitializedAsync() - { - if (Timer == null) - { - Timer = new System.Timers.Timer(); - - Timer.Interval = TimerInterval; - - Timer.Elapsed += async (s, e) => - { - await RefreshData(); - }; - } - } - protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { + if (Timer == null) + { + Timer = new System.Timers.Timer(); + + Timer.Interval = TimerInterval; + + Timer.Elapsed += async (s, e) => + { + await RefreshData(); + }; + } + await Chart.UpdateChart(Config, null, null, JsConfig); + Timer.Start(); + + Loading = false; + + StateHasChanged(); } } diff --git a/LANCommander/Pages/Dashboard/Charts/NetworkUploadRate.razor b/LANCommander/Pages/Dashboard/Charts/NetworkUploadRate.razor index 55498a2..5ed24a4 100644 --- a/LANCommander/Pages/Dashboard/Charts/NetworkUploadRate.razor +++ b/LANCommander/Pages/Dashboard/Charts/NetworkUploadRate.razor @@ -3,7 +3,9 @@ @using AntDesign.Charts; @using System.Collections.Concurrent; - + + + @code { [Parameter] public int TimerHistory { get; set; } @@ -11,6 +13,7 @@ IChartComponent? Chart; System.Timers.Timer Timer; + bool Loading = true; Dictionary Data = new Dictionary(); @@ -39,27 +42,28 @@ } }; - protected override async Task OnInitializedAsync() - { - if (Timer == null) - { - Timer = new System.Timers.Timer(); - - Timer.Interval = TimerInterval; - - Timer.Elapsed += async (s, e) => - { - await RefreshData(); - }; - } - } - protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { + if (Timer == null) + { + Timer = new System.Timers.Timer(); + + Timer.Interval = TimerInterval; + + Timer.Elapsed += async (s, e) => + { + await RefreshData(); + }; + } + await Chart.UpdateChart(Config, null, null, JsConfig); Timer.Start(); + + Loading = false; + + StateHasChanged(); } } diff --git a/LANCommander/Pages/Dashboard/Charts/ProcessorUtilization.razor b/LANCommander/Pages/Dashboard/Charts/ProcessorUtilization.razor index 774bdfd..c4ccf52 100644 --- a/LANCommander/Pages/Dashboard/Charts/ProcessorUtilization.razor +++ b/LANCommander/Pages/Dashboard/Charts/ProcessorUtilization.razor @@ -2,13 +2,16 @@ @using LANCommander.Extensions; @using AntDesign.Charts; - + + + @code { [Parameter] public int TimerHistory { get; set; } [Parameter] public int TimerInterval { get; set; } IChartComponent? Chart; System.Timers.Timer Timer; + bool Loading = true; double[] Data; @@ -42,27 +45,28 @@ } }; - protected override async Task OnInitializedAsync() - { - if (Timer == null) - { - Timer = new System.Timers.Timer(); - - Timer.Interval = TimerInterval; - - Timer.Elapsed += async (s, e) => - { - await RefreshData(); - }; - } - } - protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { + if (Timer == null) + { + Timer = new System.Timers.Timer(); + + Timer.Interval = TimerInterval; + + Timer.Elapsed += async (s, e) => + { + await RefreshData(); + }; + } + await Chart.UpdateChart(Config, null, null, JsConfig); Timer.Start(); + + Loading = false; + + StateHasChanged(); } } diff --git a/LANCommander/Pages/Dashboard/Charts/StorageUsage.razor b/LANCommander/Pages/Dashboard/Charts/StorageUsage.razor index 5752529..763abf8 100644 --- a/LANCommander/Pages/Dashboard/Charts/StorageUsage.razor +++ b/LANCommander/Pages/Dashboard/Charts/StorageUsage.razor @@ -1,16 +1,20 @@ @using AntDesign.Charts @using ByteSizeLib - + + + @code { object[] Data; + bool Loading = true; + string JsConfig = @"{ meta: { value: { alias: 'Data Usage', - formatter: (v) => humanFileSize(v, true) + formatter: (v) => Uploader.GetHumanFileSize(v, true, 1) } }, label: { @@ -58,6 +62,8 @@ } }; + Loading = false; + StateHasChanged(); } } \ No newline at end of file