Attempt to improve responsiveness of dashboard

dhcp-server
Pat Hartl 2023-08-28 18:55:15 -05:00
parent 1def1ce0e8
commit 6399f1750c
4 changed files with 69 additions and 50 deletions

View File

@ -3,7 +3,9 @@
@using AntDesign.Charts; @using AntDesign.Charts;
@using System.Collections.Concurrent; @using System.Collections.Concurrent;
<Area @ref="Chart" Config="Config" /> <Spin Spinning="Loading">
<Area @ref="Chart" Config="Config" />
</Spin>
@code { @code {
[Parameter] public int TimerHistory { get; set; } [Parameter] public int TimerHistory { get; set; }
@ -11,6 +13,7 @@
IChartComponent? Chart; IChartComponent? Chart;
System.Timers.Timer Timer; System.Timers.Timer Timer;
bool Loading = true;
Dictionary<string, double[]> Data = new Dictionary<string, double[]>(); Dictionary<string, double[]> Data = new Dictionary<string, double[]>();
@ -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) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
if (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); await Chart.UpdateChart(Config, null, null, JsConfig);
Timer.Start(); Timer.Start();
Loading = false;
StateHasChanged();
} }
} }

View File

@ -3,7 +3,9 @@
@using AntDesign.Charts; @using AntDesign.Charts;
@using System.Collections.Concurrent; @using System.Collections.Concurrent;
<Area @ref="Chart" Config="Config" /> <Spin Spinning="Loading">
<Area @ref="Chart" Config="Config" />
</Spin>
@code { @code {
[Parameter] public int TimerHistory { get; set; } [Parameter] public int TimerHistory { get; set; }
@ -11,6 +13,7 @@
IChartComponent? Chart; IChartComponent? Chart;
System.Timers.Timer Timer; System.Timers.Timer Timer;
bool Loading = true;
Dictionary<string, double[]> Data = new Dictionary<string, double[]>(); Dictionary<string, double[]> Data = new Dictionary<string, double[]>();
@ -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) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
if (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); await Chart.UpdateChart(Config, null, null, JsConfig);
Timer.Start(); Timer.Start();
Loading = false;
StateHasChanged();
} }
} }

View File

@ -2,13 +2,16 @@
@using LANCommander.Extensions; @using LANCommander.Extensions;
@using AntDesign.Charts; @using AntDesign.Charts;
<Area @ref="Chart" Config="Config" /> <Spin Spinning="Loading">
<Area @ref="Chart" Config="Config" />
</Spin>
@code { @code {
[Parameter] public int TimerHistory { get; set; } [Parameter] public int TimerHistory { get; set; }
[Parameter] public int TimerInterval { get; set; } [Parameter] public int TimerInterval { get; set; }
IChartComponent? Chart; IChartComponent? Chart;
System.Timers.Timer Timer; System.Timers.Timer Timer;
bool Loading = true;
double[] Data; 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) protected override async Task OnAfterRenderAsync(bool firstRender)
{ {
if (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); await Chart.UpdateChart(Config, null, null, JsConfig);
Timer.Start(); Timer.Start();
Loading = false;
StateHasChanged();
} }
} }

View File

@ -1,16 +1,20 @@
@using AntDesign.Charts @using AntDesign.Charts
@using ByteSizeLib @using ByteSizeLib
<Pie Data="Data" Config="Config" JsConfig="@JsConfig" /> <Spin Spinning="Loading">
<Pie Data="Data" Config="Config" JsConfig="@JsConfig" />
</Spin>
@code { @code {
object[] Data; object[] Data;
bool Loading = true;
string JsConfig = @"{ string JsConfig = @"{
meta: { meta: {
value: { value: {
alias: 'Data Usage', alias: 'Data Usage',
formatter: (v) => humanFileSize(v, true) formatter: (v) => Uploader.GetHumanFileSize(v, true, 1)
} }
}, },
label: { label: {
@ -58,6 +62,8 @@
} }
}; };
Loading = false;
StateHasChanged(); StateHasChanged();
} }
} }