From ac94266d93fe9a29528405a5e0955b0c0d83e75b Mon Sep 17 00:00:00 2001 From: SeppPenner Date: Thu, 5 Sep 2019 10:22:34 +0200 Subject: [PATCH 01/10] Updated to preview9. --- ChartJs.Blazor/ChartJS/ChartJsInterop.cs | 9 ++++----- .../DotNetInstanceClickHandler.cs | 6 +++--- .../OnHover/DotNetInstanceHoverHandler.cs | 6 +++--- ChartJs.Blazor/ChartJS/MomentJsInterop.cs | 17 +++-------------- ChartJs.Blazor/ChartJs.Blazor.csproj | 6 +++--- ChartJs.Blazor/ChartJs.Blazor.xml | 4 ++-- ChartJs.Blazor/Charts/ChartBase.cs | 10 +++++----- README.md | 6 +++--- WebCore/App.razor | 15 ++++++++------- WebCore/Pages/DoughnutExample.razor | 2 +- WebCore/Pages/LineLinearExample.razor | 4 ++-- WebCore/Pages/LineLogarithmicExample.razor | 2 +- WebCore/Pages/LineTimeExample.razor | 4 ++-- WebCore/Pages/PieExample.razor | 2 +- WebCore/Pages/SimpleLineLinearExample.razor | 5 ++--- WebCore/Pages/_Host.cshtml | 2 +- WebCore/Shared/NavMenu.razor | 4 ++-- WebCore/Startup.cs | 5 ----- WebCore/_Imports.razor | 13 +++++++------ 19 files changed, 53 insertions(+), 69 deletions(-) diff --git a/ChartJs.Blazor/ChartJS/ChartJsInterop.cs b/ChartJs.Blazor/ChartJS/ChartJsInterop.cs index b85cd94..12d12a5 100644 --- a/ChartJs.Blazor/ChartJS/ChartJsInterop.cs +++ b/ChartJs.Blazor/ChartJS/ChartJsInterop.cs @@ -10,13 +10,12 @@ using Newtonsoft.Json.Serialization; using System.Collections.Generic; using System.Linq; -using Newtonsoft.Json.Linq; namespace ChartJs.Blazor.ChartJS { public static class ChartJsInterop { - public static Task SetupChart(this IJSRuntime jsRuntime, ConfigBase chartConfig) + public static ValueTask SetupChart(this IJSRuntime jsRuntime, ConfigBase chartConfig) { try { @@ -29,7 +28,7 @@ public static Task SetupChart(this IJSRuntime jsRuntime, ConfigBase chartC Console.WriteLine($"Error while setting up chart: {exp.Message}"); } - return Task.FromResult(false); + return new ValueTask(false); } /// @@ -74,7 +73,7 @@ private static Dictionary RecursivelyConvertIDictToDict(IDiction } ); - public static Task UpdateChart(this IJSRuntime jsRuntime, ConfigBase chartConfig) + public static ValueTask UpdateChart(this IJSRuntime jsRuntime, ConfigBase chartConfig) { try { @@ -87,7 +86,7 @@ public static Task UpdateChart(this IJSRuntime jsRuntime, ConfigBase chart Console.WriteLine($"Error while updating chart: {exp.Message}"); } - return Task.FromResult(false); + return new ValueTask(false); } /// diff --git a/ChartJs.Blazor/ChartJS/Common/Legends/OnClickHandler/DotNetInstanceClickHandler.cs b/ChartJs.Blazor/ChartJS/Common/Legends/OnClickHandler/DotNetInstanceClickHandler.cs index b2b1364..787c603 100644 --- a/ChartJs.Blazor/ChartJS/Common/Legends/OnClickHandler/DotNetInstanceClickHandler.cs +++ b/ChartJs.Blazor/ChartJS/Common/Legends/OnClickHandler/DotNetInstanceClickHandler.cs @@ -18,9 +18,9 @@ public class DotNetInstanceClickHandler : ILegendClickHandler public delegate void InstanceClickHandler(object sender, object args); /// - /// The for the instance the delegate will be executed on. + /// The for the instance the delegate will be executed on. /// - public DotNetObjectRef InstanceRef { get; } + public DotNetObjectReference InstanceRef { get; } /// /// The name of the method behind the delegate @@ -56,7 +56,7 @@ public DotNetInstanceClickHandler(InstanceClickHandler clickHandler) //AssemblyName = assembly.GetName().Name; // clickHandler.Method.DeclaringType.Assembly.GetName().Name; - InstanceRef = DotNetObjectRef.Create(clickHandler.Target); + InstanceRef = DotNetObjectReference.Create(clickHandler.Target); MethodName = clickHandler.Method.Name; } } diff --git a/ChartJs.Blazor/ChartJS/Common/Legends/OnHover/DotNetInstanceHoverHandler.cs b/ChartJs.Blazor/ChartJS/Common/Legends/OnHover/DotNetInstanceHoverHandler.cs index 213642b..0ef6953 100644 --- a/ChartJs.Blazor/ChartJS/Common/Legends/OnHover/DotNetInstanceHoverHandler.cs +++ b/ChartJs.Blazor/ChartJS/Common/Legends/OnHover/DotNetInstanceHoverHandler.cs @@ -9,9 +9,9 @@ namespace ChartJs.Blazor.ChartJS.Common.Legends.OnHover public class DotNetInstanceHoverHandler : ILegendHoverHandler { /// - /// The for the instance the delegate will be executed on. + /// The for the instance the delegate will be executed on. /// - public DotNetObjectRef InstanceRef { get; } + public DotNetObjectReference InstanceRef { get; } /// /// The name of the method behind the delegate @@ -43,7 +43,7 @@ public DotNetInstanceHoverHandler(LegendItemOnHover legendItemOnHoverHandler) // The parameters and return type is taken care of by the delegate's definition - InstanceRef = DotNetObjectRef.Create(legendItemOnHoverHandler.Target); + InstanceRef = DotNetObjectReference.Create(legendItemOnHoverHandler.Target); MethodName = legendItemOnHoverHandler.Method.Name; } } diff --git a/ChartJs.Blazor/ChartJS/MomentJsInterop.cs b/ChartJs.Blazor/ChartJS/MomentJsInterop.cs index 838f13d..f1c95ba 100644 --- a/ChartJs.Blazor/ChartJS/MomentJsInterop.cs +++ b/ChartJs.Blazor/ChartJS/MomentJsInterop.cs @@ -1,27 +1,16 @@ using Microsoft.JSInterop; using System.Threading.Tasks; -using ChartJs.Blazor.ChartJS.Common; -using System; -using System.Dynamic; -using ChartJs.Blazor.ChartJS.Common.Legends.OnClickHandler; -using ChartJs.Blazor.ChartJS.Common.Legends.OnHover; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json.Linq; namespace ChartJs.Blazor.ChartJS { public static class MomentJsInterop { - public static Task GetAvailableLocales(this IJSRuntime jsRuntime) + public static ValueTask GetAvailableLocales(this IJSRuntime jsRuntime) { return jsRuntime.InvokeAsync("getAvailableMomentLocales"); } - public static Task ChangeLocale(this IJSRuntime jsRuntime, string locale) + public static ValueTask ChangeLocale(this IJSRuntime jsRuntime, string locale) { try { @@ -29,7 +18,7 @@ public static Task ChangeLocale(this IJSRuntime jsRuntime, string locale) } catch { - return Task.FromResult(false); + return new ValueTask(false); } } } diff --git a/ChartJs.Blazor/ChartJs.Blazor.csproj b/ChartJs.Blazor/ChartJs.Blazor.csproj index bf173af..5ac8767 100644 --- a/ChartJs.Blazor/ChartJs.Blazor.csproj +++ b/ChartJs.Blazor/ChartJs.Blazor.csproj @@ -46,9 +46,9 @@ Chart legend with custom handler for Item generation and events - Javascript and - - - + + + diff --git a/ChartJs.Blazor/ChartJs.Blazor.xml b/ChartJs.Blazor/ChartJs.Blazor.xml index 39cde9b..cf062b4 100644 --- a/ChartJs.Blazor/ChartJs.Blazor.xml +++ b/ChartJs.Blazor/ChartJs.Blazor.xml @@ -744,7 +744,7 @@ - The for the instance the delegate will be executed on. + The for the instance the delegate will be executed on. @@ -818,7 +818,7 @@ - The for the instance the delegate will be executed on. + The for the instance the delegate will be executed on. diff --git a/ChartJs.Blazor/Charts/ChartBase.cs b/ChartJs.Blazor/Charts/ChartBase.cs index 604beac..387bd51 100644 --- a/ChartJs.Blazor/Charts/ChartBase.cs +++ b/ChartJs.Blazor/Charts/ChartBase.cs @@ -10,17 +10,17 @@ public abstract class ChartBase : ComponentBase where TConfig : ConfigB { [Inject] protected IJSRuntime JsRuntime { get; set; } - [Parameter] protected TConfig Config { get; set; } + [Parameter] public TConfig Config { get; set; } - [Parameter] protected int Width { get; set; } = 400; + [Parameter] public int Width { get; set; } = 400; - [Parameter] protected int Height { get; set; } = 400; + [Parameter] public int Height { get; set; } = 400; - protected override void OnAfterRender() + protected override void OnAfterRender(bool firstRender) { try { - base.OnAfterRender(); + base.OnAfterRender(firstRender); JsRuntime.SetupChart(Config); } catch (Exception e) diff --git a/README.md b/README.md index 42bacae..7df3fb0 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ Don't know what Blazor is? Read [here](https://dotnet.microsoft.com/apps/aspnet/ The prerequisites are: -1. [Visual Studio 2019 16.3.0 preview 2.0](https://visualstudio.microsoft.com/de/vs/preview/) -2. [.Net core 3 preview8](https://dotnet.microsoft.com/download/dotnet-core/3.0) +1. [Visual Studio 2019 16.3.0 preview 3.0](https://visualstudio.microsoft.com/de/vs/preview/) +2. [.Net core 3 preview9](https://dotnet.microsoft.com/download/dotnet-core/3.0) ## Installation @@ -100,7 +100,7 @@ The example covers a few static options, how to use a simple point-dataset and h

Line Linear Chart

- + @code { diff --git a/WebCore/App.razor b/WebCore/App.razor index b913345..ab8cbd4 100644 --- a/WebCore/App.razor +++ b/WebCore/App.razor @@ -1,7 +1,8 @@ - - - -

Sorry, there's nothing at this address.

-
-
-
+ + + + + +

Sorry, there's nothing at this address.

+
+
diff --git a/WebCore/Pages/DoughnutExample.razor b/WebCore/Pages/DoughnutExample.razor index a63ea3a..784922e 100644 --- a/WebCore/Pages/DoughnutExample.razor +++ b/WebCore/Pages/DoughnutExample.razor @@ -5,7 +5,7 @@

Doughnut Chart

- + @code { private PieConfig config; diff --git a/WebCore/Pages/LineLinearExample.razor b/WebCore/Pages/LineLinearExample.razor index 2e30447..f9ceba9 100644 --- a/WebCore/Pages/LineLinearExample.razor +++ b/WebCore/Pages/LineLinearExample.razor @@ -12,8 +12,8 @@ @inject WeatherForecastService ForecastService

Line Linear Chart

- - + + @code { diff --git a/WebCore/Pages/LineLogarithmicExample.razor b/WebCore/Pages/LineLogarithmicExample.razor index ca3c32a..8a260dc 100644 --- a/WebCore/Pages/LineLogarithmicExample.razor +++ b/WebCore/Pages/LineLogarithmicExample.razor @@ -12,7 +12,7 @@ @inject WeatherForecastService ForecastService

Line Logarithmic Chart

- + @code { diff --git a/WebCore/Pages/LineTimeExample.razor b/WebCore/Pages/LineTimeExample.razor index de6ccbe..d0931b2 100644 --- a/WebCore/Pages/LineTimeExample.razor +++ b/WebCore/Pages/LineTimeExample.razor @@ -13,7 +13,7 @@ @inject IJSRuntime jsRuntime

Line Time Chart

- + @code { @@ -114,7 +114,7 @@ lineConfig.Data.Datasets.Add(tempDataSet); } - protected override async Task OnAfterRenderAsync() + protected override async Task OnAfterRenderAsync(bool firstRender) { await TryChangeLocale(); } diff --git a/WebCore/Pages/PieExample.razor b/WebCore/Pages/PieExample.razor index 719a5e1..020400a 100644 --- a/WebCore/Pages/PieExample.razor +++ b/WebCore/Pages/PieExample.razor @@ -5,7 +5,7 @@

Pie Chart

- + @code { private PieConfig config; diff --git a/WebCore/Pages/SimpleLineLinearExample.razor b/WebCore/Pages/SimpleLineLinearExample.razor index 4f407e2..9428465 100644 --- a/WebCore/Pages/SimpleLineLinearExample.razor +++ b/WebCore/Pages/SimpleLineLinearExample.razor @@ -7,12 +7,11 @@ @using ChartJs.Blazor.ChartJS.Common.Legends @using ChartJs.Blazor.ChartJS.LineChart @using ChartJs.Blazor.ChartJS.LineChart.Axes -@using ChartJs.Blazor.ChartJS.LineChart.Axes.Ticks @using ChartJs.Blazor.Util.Color

Line Linear Chart

- - + + @code { diff --git a/WebCore/Pages/_Host.cshtml b/WebCore/Pages/_Host.cshtml index c0a3d40..ce1d3ca 100644 --- a/WebCore/Pages/_Host.cshtml +++ b/WebCore/Pages/_Host.cshtml @@ -23,7 +23,7 @@ - @(await Html.RenderComponentAsync()) + @(await Html.RenderComponentAsync(RenderMode.ServerPrerendered)) diff --git a/WebCore/Shared/NavMenu.razor b/WebCore/Shared/NavMenu.razor index 9515ae5..fa086e2 100644 --- a/WebCore/Shared/NavMenu.razor +++ b/WebCore/Shared/NavMenu.razor @@ -1,11 +1,11 @@ -
+
-
From a700480dd67a9a4612319c987625eb14a35020e0 Mon Sep 17 00:00:00 2001 From: SeppPenner Date: Fri, 13 Sep 2019 15:37:12 +0200 Subject: [PATCH 03/10] Adjusted lists to arrays. --- WebCore/Pages/DoughnutExample.razor | 2 +- WebCore/Pages/PieExample.razor | 2 +- WebCore/Pages/PolarAreaExample.razor | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WebCore/Pages/DoughnutExample.razor b/WebCore/Pages/DoughnutExample.razor index e23d7cc..fb61a81 100644 --- a/WebCore/Pages/DoughnutExample.razor +++ b/WebCore/Pages/DoughnutExample.razor @@ -43,7 +43,7 @@ BorderColor = "#ffffff" }; - doughnutSet.Data.AddRange(new List { 4, 5, 6, 7 }); + doughnutSet.Data.AddRange(new[] { 4, 5, 6, 7 }); config.Data.Datasets.Add(doughnutSet); } }} diff --git a/WebCore/Pages/PieExample.razor b/WebCore/Pages/PieExample.razor index 19715db..0c580b1 100644 --- a/WebCore/Pages/PieExample.razor +++ b/WebCore/Pages/PieExample.razor @@ -44,7 +44,7 @@ BorderColor = "#ffffff", }; - pieSet.Data.AddRange(new List { 4, 5, 6, 7 }); + pieSet.Data.AddRange(new[] { 4, 5, 6, 7 }); config.Data.Datasets.Add(pieSet); } } diff --git a/WebCore/Pages/PolarAreaExample.razor b/WebCore/Pages/PolarAreaExample.razor index 3e0142e..b0f8dda 100644 --- a/WebCore/Pages/PolarAreaExample.razor +++ b/WebCore/Pages/PolarAreaExample.razor @@ -43,7 +43,7 @@ BorderColor = "#ffffff", }; - polarAreaSet.Data.AddRange(new List{ 4, 5, 6, 7 }); + polarAreaSet.Data.AddRange(new[] { 4, 5, 6, 7 }); config.Data.Datasets.Add(polarAreaSet); } } From 1c3cc4e61a5831924af57954de44ced7fae5c96e Mon Sep 17 00:00:00 2001 From: SeppPenner Date: Fri, 13 Sep 2019 16:28:07 +0200 Subject: [PATCH 04/10] Fixed issue that doubles couldn't be automatically detected. --- WebCore/Pages/DoughnutExample.razor | 2 +- WebCore/Pages/PieExample.razor | 2 +- WebCore/Pages/PolarAreaExample.razor | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WebCore/Pages/DoughnutExample.razor b/WebCore/Pages/DoughnutExample.razor index fb61a81..faa4480 100644 --- a/WebCore/Pages/DoughnutExample.razor +++ b/WebCore/Pages/DoughnutExample.razor @@ -43,7 +43,7 @@ BorderColor = "#ffffff" }; - doughnutSet.Data.AddRange(new[] { 4, 5, 6, 7 }); + doughnutSet.Data.AddRange(new[] { 4.0, 5.0, 6.0, 7.0 }); config.Data.Datasets.Add(doughnutSet); } }} diff --git a/WebCore/Pages/PieExample.razor b/WebCore/Pages/PieExample.razor index 0c580b1..5bf2f87 100644 --- a/WebCore/Pages/PieExample.razor +++ b/WebCore/Pages/PieExample.razor @@ -44,7 +44,7 @@ BorderColor = "#ffffff", }; - pieSet.Data.AddRange(new[] { 4, 5, 6, 7 }); + pieSet.Data.AddRange(new[] { 4.0, 5.0, 6.0, 7.0 }); config.Data.Datasets.Add(pieSet); } } diff --git a/WebCore/Pages/PolarAreaExample.razor b/WebCore/Pages/PolarAreaExample.razor index b0f8dda..5e30966 100644 --- a/WebCore/Pages/PolarAreaExample.razor +++ b/WebCore/Pages/PolarAreaExample.razor @@ -43,7 +43,7 @@ BorderColor = "#ffffff", }; - polarAreaSet.Data.AddRange(new[] { 4, 5, 6, 7 }); + polarAreaSet.Data.AddRange(new[] { 4.0, 5.0, 6.0, 7.0 }); config.Data.Datasets.Add(polarAreaSet); } } From db06fec69ca59462c53058d5bf9c9daf9baef4f3 Mon Sep 17 00:00:00 2001 From: SeppPenner Date: Fri, 13 Sep 2019 16:28:26 +0200 Subject: [PATCH 05/10] Adjusted NavMenu in example project. --- WebCore/Shared/NavMenu.razor | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WebCore/Shared/NavMenu.razor b/WebCore/Shared/NavMenu.razor index 1d647e2..5e19d06 100644 --- a/WebCore/Shared/NavMenu.razor +++ b/WebCore/Shared/NavMenu.razor @@ -14,22 +14,22 @@