Skip to content

Commit 09bd87f

Browse files
committed
Add Mouse over
1 parent 33f482e commit 09bd87f

4 files changed

Lines changed: 34 additions & 17 deletions

File tree

src/Chart.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@inject IJSRuntime JSRuntime
22

33
<div id="@("chartcontainer" + Config.CanvasId)" class="chart-container @Class"
4-
style="height:@Height; width:@Width; @(Style)">
4+
style="height:@Height; width:@Width; @(Style)" @onmouseout="async (args) => await OnMouseOut(args)">
55
<canvas id="@Config.CanvasId" style="@(Height != null ? $"height:{Height}" : "") @(Width != null ? $"width:{Width};" : "")"></canvas>
66
</div>

src/Chart.razor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore.Components;
33
using Microsoft.JSInterop;
44
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Components.Web;
56

67
namespace PSC.Blazor.Components.Chartjs
78
{
@@ -105,6 +106,14 @@ public void Dispose()
105106
this.oldReference?.Dispose();
106107
}
107108

109+
private ValueTask OnMouseOut(MouseEventArgs mouseEventArgs)
110+
{
111+
if (Config.Options is Options { OnMouseOutAsync: { } } options)
112+
return options.OnMouseOutAsync(mouseEventArgs);
113+
else
114+
return ValueTask.CompletedTask;
115+
}
116+
108117
#region JavaScript invokable functions
109118

110119
[JSInvokable]

src/Models/Common/OnHoverContext.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Models/Common/Options.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using Microsoft.AspNetCore.Components.Web;
2+
using System.Threading.Tasks;
23

34
namespace PSC.Blazor.Components.Chartjs.Models.Common
45
{
@@ -7,6 +8,28 @@ namespace PSC.Blazor.Components.Chartjs.Models.Common
78
/// </summary>
89
public class Options : IOptions
910
{
11+
#region Events
12+
13+
/// <summary>
14+
/// Gets or sets the on hover asynchronous.
15+
/// </summary>
16+
/// <value>
17+
/// The on hover asynchronous.
18+
/// </value>
19+
[JsonIgnore]
20+
public Func<HoverContext, ValueTask>? OnHoverAsync { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets the on mouse out asynchronous.
24+
/// </summary>
25+
/// <value>
26+
/// The on mouse out asynchronous.
27+
/// </value>
28+
[JsonIgnore]
29+
public Func<MouseEventArgs, ValueTask>? OnMouseOutAsync { get; set; }
30+
31+
#endregion Events
32+
1033
/// <summary>
1134
/// Gets or sets the elements.
1235
/// </summary>
@@ -55,15 +78,6 @@ public class Options : IOptions
5578
[JsonPropertyName("maintainAspectRatio")]
5679
public bool MaintainAspectRatio { get; set; } = false;
5780

58-
/// <summary>
59-
/// Gets or sets the on hover asynchronous.
60-
/// </summary>
61-
/// <value>
62-
/// The on hover asynchronous.
63-
/// </value>
64-
[JsonIgnore]
65-
public Func<HoverContext, ValueTask>? OnHoverAsync { get; set; }
66-
6781
/// <summary>
6882
/// Gets or sets the plugins.
6983
/// </summary>

0 commit comments

Comments
 (0)