Skip to content

Commit

Permalink
Merge pull request #341 from apexcharts/fix-renderchart
Browse files Browse the repository at this point in the history
Moved renderchart back to component
  • Loading branch information
joadan authored Nov 19, 2023
2 parents 629945e + 5242a06 commit 6138368
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else
@code {
private ApexChart<TimeSeries> chart;
private List<int> points = new List<int> { 0, 100, 1000, 5000, 10000, 15000, 20000 };
private int pointsToLoad = 0;
private int pointsToLoad = 100;
private List<TimeSeries> timeSeries = new TimeSeriesGenerator(25000).TimeSeries;
private string message;
private List<DataPoint<TimeSeries>> data;
Expand Down
27 changes: 25 additions & 2 deletions src/Blazor-ApexCharts/ApexChart.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)


isReady = true;
JSHandler = new JSHandler<TItem>(this, ChartContainer, blazor_apexchart);
JSHandler = new JSHandler<TItem>(this);
}

if (isReady && forceRender)
Expand Down Expand Up @@ -914,7 +914,30 @@ private async Task RenderChartAsync()
await Task.Yield();
forceRender = false;
PrepareChart();
await JSHandler.RenderChartAsync();

await InvokeVoidJsAsync("blazor_apexchart.renderChart", JSHandler.ObjectReference, ChartContainer, JsonSerializer.Serialize(Options, ChartSerializer.GetOptions<TItem>()), new JSEvents()
{
HasDataPointSelection = OnDataPointSelection.HasDelegate,
HasDataPointEnter = OnDataPointEnter.HasDelegate || ApexPointTooltip != null,
HasDataPointLeave = OnDataPointLeave.HasDelegate,
HasLegendClick = OnLegendClicked.HasDelegate,
HasMarkerClick = OnMarkerClick.HasDelegate,
HasXAxisLabelClick = OnXAxisLabelClick.HasDelegate,
HasSelection = OnSelection.HasDelegate,
HasBrushScrolled = OnBrushScrolled.HasDelegate,
HasZoomed = OnZoomed.HasDelegate,
HasAnimationEnd = OnAnimationEnd.HasDelegate,
HasBeforeMount = OnBeforeMount.HasDelegate,
HasMounted = OnMounted.HasDelegate,
HasUpdated = OnUpdated.HasDelegate,
HasMouseLeave = OnMouseLeave.HasDelegate,
HasMouseMove = OnMouseMove.HasDelegate,
HasClick = OnClick.HasDelegate,
HasBeforeZoom = OnBeforeZoom != null,
HasBeforeResetZoom = OnBeforeResetZoom != null,
HasScrolled = OnScrolled.HasDelegate
});

await OnRendered.InvokeAsync();
}

Expand Down
37 changes: 2 additions & 35 deletions src/Blazor-ApexCharts/Internal/JSHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ namespace ApexCharts.Internal
internal sealed class JSHandler<TItem> : IDisposable where TItem : class
{
private readonly ApexChart<TItem> ChartReference;
private readonly DotNetObjectReference<JSHandler<TItem>> ObjectReference;
private readonly ElementReference ChartContainer;
private IJSObjectReference blazor_apexchart;
internal readonly DotNetObjectReference<JSHandler<TItem>> ObjectReference;

internal JSHandler(ApexChart<TItem> chartReference, ElementReference chartContainer, IJSObjectReference blazor_apexchart)
internal JSHandler(ApexChart<TItem> chartReference)
{
ObjectReference = DotNetObjectReference.Create(this);
ChartContainer = chartContainer;
ChartReference = chartReference;
this.blazor_apexchart = blazor_apexchart;
}

/// <inheritdoc/>
Expand All @@ -34,35 +30,6 @@ public void Dispose()
ObjectReference.Dispose();
}

/// <summary>
/// Invokes the JS renderChart method
/// </summary>
public async Task RenderChartAsync()
{
await blazor_apexchart.InvokeVoidAsync("blazor_apexchart.renderChart", ObjectReference, ChartContainer, JsonSerializer.Serialize(ChartReference.Options, ChartSerializer.GetOptions<TItem>()), new JSEvents()
{
HasDataPointSelection = ChartReference.OnDataPointSelection.HasDelegate,
HasDataPointEnter = ChartReference.OnDataPointEnter.HasDelegate || ChartReference.ApexPointTooltip != null,
HasDataPointLeave = ChartReference.OnDataPointLeave.HasDelegate,
HasLegendClick = ChartReference.OnLegendClicked.HasDelegate,
HasMarkerClick = ChartReference.OnMarkerClick.HasDelegate,
HasXAxisLabelClick = ChartReference.OnXAxisLabelClick.HasDelegate,
HasSelection = ChartReference.OnSelection.HasDelegate,
HasBrushScrolled = ChartReference.OnBrushScrolled.HasDelegate,
HasZoomed = ChartReference.OnZoomed.HasDelegate,
HasAnimationEnd = ChartReference.OnAnimationEnd.HasDelegate,
HasBeforeMount = ChartReference.OnBeforeMount.HasDelegate,
HasMounted = ChartReference.OnMounted.HasDelegate,
HasUpdated = ChartReference.OnUpdated.HasDelegate,
HasMouseLeave = ChartReference.OnMouseLeave.HasDelegate,
HasMouseMove = ChartReference.OnMouseMove.HasDelegate,
HasClick = ChartReference.OnClick.HasDelegate,
HasBeforeZoom = ChartReference.OnBeforeZoom != null,
HasBeforeResetZoom = ChartReference.OnBeforeResetZoom != null,
HasScrolled = ChartReference.OnScrolled.HasDelegate
});
}

/// <summary>
/// Callback from JavaScript to get a formatted Y-axis value
/// </summary>
Expand Down

0 comments on commit 6138368

Please sign in to comment.