Skip to content

Commit ab99a1d

Browse files
authored
Merge pull request #572 from apexcharts/update-apexcharts-4.4.0
Update to apexcharts 4.0.0
2 parents e23e11f + a648955 commit ab99a1d

File tree

8 files changed

+92
-19
lines changed

8 files changed

+92
-19
lines changed

src/Blazor-ApexCharts/ApexChart.razor

+12-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@
66
<CascadingValue Value="(ApexChart<TItem>)this" Name="Chart">
77
@ChildContent
88

9-
@if (ApexPointTooltip != null)
9+
<ApexCharts.Internal.ApexChartTooltip ApexTooltip="ApexPointTooltip" Data="tooltipData" TItem="TItem" JsApexchart="blazor_apexchart" ChartId="@chartId" />
10+
11+
@* @if (ApexPointTooltip != null)
1012
{
11-
<span id="apex-tooltip-@ChartId">
12-
@if (tooltipData != null)
13-
{
14-
@ApexPointTooltip(tooltipData)
15-
}
13+
<span id="apex-tooltip-@ChartId" style="display:none">
14+
<span>
15+
@if (tooltipData != null)
16+
{
17+
@ApexPointTooltip(tooltipData)
18+
}
19+
</span>
20+
1621
</span>
17-
}
22+
} *@
1823

1924
</CascadingValue>

src/Blazor-ApexCharts/ApexChart.razor.cs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using System.Text.Json;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011

1112
namespace ApexCharts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@namespace ApexCharts.Internal
2+
@typeparam TItem
3+
4+
@if (ApexTooltip != null)
5+
{
6+
<span style="display:none">
7+
<span id="tooltip_source_@ChartId">
8+
@if (Data != null)
9+
{
10+
@ApexTooltip(Data)
11+
}
12+
</span>
13+
</span>
14+
}
15+
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.AspNetCore.Components;
2+
using Microsoft.JSInterop;
3+
using System.Threading.Tasks;
4+
5+
namespace ApexCharts.Internal
6+
{
7+
public partial class ApexChartTooltip<TItem> where TItem : class
8+
{
9+
/// <inheritdoc cref="ChartId"/>
10+
[Parameter] public string ChartId { get; set; }
11+
12+
/// <inheritdoc cref="Tooltip"/>
13+
[Parameter] public RenderFragment<HoverData<TItem>> ApexTooltip { get; set; }
14+
15+
/// <inheritdoc cref="HoverData{TItem}"/>
16+
[Parameter] public HoverData<TItem> Data { get; set; }
17+
18+
/// <inheritdoc cref="IJSObjectReference"/>
19+
[Parameter] public IJSObjectReference JsApexchart { get; set; }
20+
21+
22+
/// <inheritdoc cref="OnAfterRenderAsync(bool)"/>
23+
protected override async Task OnAfterRenderAsync(bool firstRender)
24+
{
25+
if (JsApexchart != null)
26+
{
27+
await JsApexchart.InvokeVoidAsync("blazor_apexchart.copyTooltipContent", ChartId);
28+
}
29+
}
30+
}
31+
}

src/Blazor-ApexCharts/Internal/JSLoader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal static class JSLoader
1212
{
1313
internal static async Task<IJSObjectReference> LoadAsync(IJSRuntime jsRuntime, string path = null)
1414
{
15-
var javascriptPath = "./_content/Blazor-ApexCharts/js/blazor-apexcharts.js?ver=4";
15+
var javascriptPath = "./_content/Blazor-ApexCharts/js/blazor-apexcharts.js?ver=5";
1616
if (!string.IsNullOrWhiteSpace(path)) { javascriptPath = path; }
1717

1818
// load Module ftom ES6 script

src/Blazor-ApexCharts/Internal/Models/JSDataPointSelection.cs

+1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ internal class JSDataPointSelection
2121
/// The index of the data series being selected
2222
/// </summary>
2323
public int SeriesIndex { get; set; }
24+
2425
}
2526
}

src/Blazor-ApexCharts/wwwroot/js/apexcharts.esm.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Blazor-ApexCharts/wwwroot/js/blazor-apexcharts.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ApexCharts from './apexcharts.esm.js?ver=4.3.0'
1+
import ApexCharts from './apexcharts.esm.js?ver=4.4.0'
22

33
// export function for Blazor to point to the window.blazor_apexchart. To be compatible with the most JS Interop calls the window will be return.
44
export function get_apexcharts() {
@@ -275,6 +275,20 @@ window.blazor_apexchart = {
275275
}
276276
},
277277

278+
copyTooltipContent(chartId) {
279+
280+
var sourceId = "tooltip_source_" + chartId;
281+
var targetId = "tooltip_target_" + chartId;
282+
283+
var sourceElement = document.getElementById(sourceId);
284+
var targetElement = document.getElementById(targetId);
285+
286+
if (sourceElement && targetElement) {
287+
targetElement.innerHTML = sourceElement.innerHTML;
288+
}
289+
290+
},
291+
278292
dotNetRefs: new Map(),
279293

280294
renderChart(dotNetObject, container, options, events) {
@@ -294,14 +308,19 @@ window.blazor_apexchart = {
294308
seriesIndex: seriesIndex
295309
};
296310

297-
dotNetObject.invokeMethodAsync('RazorTooltip', selection);
311+
var targetId = "tooltip_target_" + w.globals.chartID;
312+
var el = document.getElementById(targetId);
298313

299-
var sourceId = 'apex-tooltip-' + w.globals.chartID;
300-
var source = document.getElementById(sourceId);
301-
if (source) {
302-
return source;
314+
if (el === null) {
315+
el = document.createElement("DIV");
316+
el.id = targetId;
303317
}
304-
return '...'
318+
319+
dotNetObject.invokeMethodAsync('RazorTooltip', selection);
320+
321+
return el;
322+
323+
305324
};
306325
}
307326

0 commit comments

Comments
 (0)