Skip to content

Commit 51a7a9b

Browse files
committed
Performance tests
1 parent a8b1b19 commit 51a7a9b

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

docs/BlazorApexCharts.Docs/Components/Features/Performance/Basic.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
@using System.Diagnostics
22
@using System.Text.Json
33

4+
<Checkbox Switch @bind-Value=unMarshalledJS Label="Use UnMarshalledJS" />
5+
46
<ItemSelect Label="Datapoints" Items=points @bind-SelectedValue=pointsToLoad Changed=LoadData />
57

68

79
<ApexChart TItem="TimeSeries"
810
Title="Value"
911
Height="150"
1012
XAxisType="XAxisType.Datetime"
13+
UnMarshalledJS=unMarshalledJS
1114
@ref=chart>
1215

1316

@@ -32,8 +35,7 @@ else
3235

3336

3437
@code {
35-
36-
38+
private bool unMarshalledJS = true;
3739
private ApexChart<TimeSeries> chart;
3840
private List<int> points = new List<int> { 100, 1000, 5000, 10000 };
3941
private int pointsToLoad = 100;

src/Blazor-ApexCharts/ApexChart.razor.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public partial class ApexChart<TItem> : IDisposable where TItem : class
2020
[Parameter] public string Title { get; set; }
2121
[Parameter] public XAxisType? XAxisType { get; set; }
2222
[Parameter] public bool Debug { get; set; }
23+
[Parameter] public bool UnMarshalledJS { get; set; }
2324
[Parameter] public object Width { get; set; }
2425
[Parameter] public object Height { get; set; }
2526
[Parameter] public EventCallback<SelectedData<TItem>> OnDataPointSelection { get; set; }
@@ -39,13 +40,16 @@ public partial class ApexChart<TItem> : IDisposable where TItem : class
3940
private string chartId;
4041
public string ChartId => ChartId;
4142
private IJSUnmarshalledRuntime jsUnmarshalled;
43+
private IJSInProcessRuntime jsInprocess;
44+
4245
private bool isWasm;
4346

4447
protected override void OnInitialized()
4548
{
46-
isWasm = this.JSRuntime is IJSInProcessRuntime;
49+
isWasm = JSRuntime is IJSInProcessRuntime;
4750
if (isWasm)
4851
{
52+
jsInprocess = (IJSInProcessRuntime)JSRuntime;
4953
jsUnmarshalled = (IJSUnmarshalledRuntime)ServiceProvider.GetService(typeof(IJSUnmarshalledRuntime));
5054
}
5155
}
@@ -361,11 +365,17 @@ public async Task UpdateSeriesAsync(bool animate = true)
361365
Console.WriteLine($"Serialize {sw.ElapsedMilliseconds}");
362366

363367

364-
if (jsUnmarshalled != null)
368+
if (jsUnmarshalled != null && UnMarshalledJS)
365369
{
366-
jsUnmarshalled.InvokeUnmarshalled<string, string, string, bool>("blazor_apexchart.testUnmarshalled", Options.Chart.Id, jsonSeries, animate.ToString());
370+
jsUnmarshalled.InvokeUnmarshalled<string, string, string, string>("blazor_apexchart.testUnmarshalled", Options.Chart.Id, jsonSeries, animate.ToString().ToLower());
367371
Console.WriteLine($"Invoke InvokeUnmarshalled {sw.ElapsedMilliseconds}");
368372

373+
}
374+
else if (jsInprocess != null)
375+
{
376+
jsInprocess.InvokeVoid("blazor_apexchart.updateSeries", Options.Chart.Id, jsonSeries, animate);
377+
Console.WriteLine($"Invoke Void {sw.ElapsedMilliseconds}");
378+
369379
}
370380
else
371381
{
@@ -377,7 +387,7 @@ public async Task UpdateSeriesAsync(bool animate = true)
377387
sw.Stop();
378388
}
379389

380-
390+
381391
/// <summary>
382392
/// For no axis charts only provide the seriesIndex value, set dataPointIndex to null
383393
/// </summary>

src/Blazor-ApexCharts/wwwroot/js/blazor-apex-charts.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
window.blazor_apexchart = {
2-
2+
33
testUnmarshalled(id, series, animate) {
4-
console.log("Test Unmarshalled")
5-
//console.log(series);
6-
const chartId = BINDING.conv_string(id);
7-
const data = BINDING.conv_string(series);
8-
console.log("Data processed")
9-
//const chartAnimate = BINDING.conv_bool(animate);
10-
this.updateSeries(chartId, data, false);
4+
//const chartId = BINDING.conv_string(id);
5+
//const data = BINDING.conv_string(series);
6+
//const animateString = BINDING.conv_string(animate);
7+
8+
var chartAnimate = (BINDING.conv_string(animate).toLowerCase() === 'true');
9+
10+
this.updateSeries(BINDING.conv_string(id), BINDING.conv_string(series), chartAnimate);
1111
},
1212

1313
getYAxisLabel(value, index, w) {

0 commit comments

Comments
 (0)