Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ private bool HasAnyGradientStops()
/// </summary>
private void RenderAllGradients(RenderTreeBuilder builder)
{
if (SvgRenderer is null || Series is null)
if (SeriesRenderer == null || !(SeriesRenderer.Series?.Visible ?? false))
{
return;
}
ChartLinearGradient? seriesLinear = Series.LinearGradient;
ChartLinearGradient? seriesLinear = Series?.LinearGradient;
if (seriesLinear?.RendererType is not null)
{
RenderLinearGradient(builder, seriesLinear, SvgRenderer);
}

ChartRadialGradient? seriesRadial = Series.RadialGradient;
ChartRadialGradient? seriesRadial = Series?.RadialGradient;
if (seriesRadial?.RendererType is not null)
{
RenderRadialGradient(builder, seriesRadial, SvgRenderer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private void CreatePixelStriplinePath(bool isUpdateDirection, string id)
string direction = CalculatePixelPathDirection();
direction = ChartHelper.AppendPathElements(Owner ?? null!, direction, id);

if (!isUpdateDirection && Stripline?.DashArray is not null)
if (!isUpdateDirection)
{
_striplinePath = new PathOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,14 @@ private void FinalizeSelection(Rect dragRect, bool isClose, List<PointXY> select
/// <param name="selectedPointValues">The list of selected point values.</param>
private void InvokeSelectionChangedEvent(List<PointXY> selectedPointValues)
{
_chartInstance?.OnSelectionChanged.Invoke(new SelectionCompleteEventArgs
if (_chartInstance?.OnSelectionChanged != null)
{
SelectedDataValues = selectedPointValues,
Name = Constants.OnSelectionChanged
});
_chartInstance?.OnSelectionChanged.Invoke(new SelectionCompleteEventArgs
{
SelectedDataValues = selectedPointValues,
Name = Constants.OnSelectionChanged
});
}

}

Expand Down
31 changes: 24 additions & 7 deletions src/Components/Charts/Chart/SfChart.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,12 +1098,29 @@ private bool IsRendererDisposed()
const string RENDERER = "_renderer";
const string DISPOSED = "_disposed";

FieldInfo field = GetType().BaseType?.BaseType?.BaseType?.BaseType?.BaseType?.GetField(RENDERHANDLE, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) ?? null!;
RenderHandle renderHandler = (RenderHandle)(field.GetValue(this) ?? null!);
FieldInfo rendererInfo = renderHandler.GetType().GetField(RENDERER, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) ?? null!;
object renderer = rendererInfo.GetValue(renderHandler) ?? null!;
FieldInfo diposedInfo = renderer.GetType().BaseType?.GetField(DISPOSED, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) ?? null!;
return diposedInfo is not null && (bool)(diposedInfo.GetValue(renderer) ?? false);
try
{
FieldInfo field = GetType().BaseType?.BaseType?.BaseType?.BaseType?.BaseType?.GetField(RENDERHANDLE, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
if (field == null) return false;

object renderHandlerObj = field.GetValue(this);
if (renderHandlerObj == null) return false;

RenderHandle renderHandler = (RenderHandle)renderHandlerObj;
FieldInfo rendererInfo = renderHandler.GetType().GetField(RENDERER, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
if (rendererInfo == null) return false;

object renderer = rendererInfo.GetValue(renderHandler);
if (renderer == null) return false;

FieldInfo disposedInfo = renderer.GetType().BaseType?.GetField(DISPOSED, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
return disposedInfo is not null && (bool)(disposedInfo.GetValue(renderer) ?? false);
}
catch
{
// In test environments (like BUnit), reflection might not work as expected
return false;
}
}

/// <summary>
Expand Down Expand Up @@ -1810,7 +1827,7 @@ internal async Task GetCharSizeListAsync(List<string> fontKeys)
}

string methodName = "getCharCollectionSize";
string result = await InvokeAsync<string>(_chartJsModule!, _chartJsInProcessModule!, methodName, [uniqueKeys]).ConfigureAwait(true);
string result = await InvokeAsync<string>(_chartJsModule!, _chartJsInProcessModule!, methodName, false, [uniqueKeys]).ConfigureAwait(true);
if (result is null)
{
return;
Expand Down
36 changes: 24 additions & 12 deletions src/Components/Charts/Common/ChartUtils/ChartHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Components;
using Syncfusion.Blazor.Toolkit.Internal;
using System.Collections.ObjectModel;
using System.Collections.Concurrent;

namespace Syncfusion.Blazor.Toolkit.Charts.Internal
{
Expand All @@ -30,7 +31,7 @@ public class ChartHelper
/// <summary>
/// Gets or sets a thread-safe cache of measured character sizes indexed by font characteristics.
/// </summary>
internal static Dictionary<string, Size> SizePerCharacter { get; set; } = new Dictionary<string, Size>();
internal static ConcurrentDictionary<string, Size> SizePerCharacter { get; set; } = new ConcurrentDictionary<string, Size>();

/// <summary>
/// Gets or sets a list of cached font keys used for performance optimization.
Expand Down Expand Up @@ -107,23 +108,34 @@ private static Size MeasureBreakText(string originalText, ChartFontOptions font)
/// <returns>The measured character size.</returns>
private static Size GetCharSize(char character, ChartFontOptions font)
{
Size? charSize = new Size();
string key = character + Constants.Underscore + font.FontWeight + Constants.Underscore + font.FontStyle + Constants.Underscore + font.FontFamily;

if (!SizePerCharacter.TryGetValue(key, out charSize))
try
{
if (SizePerCharacter.TryGetValue(key, out Size? charSize))
{
return charSize ?? null!;
}
double charWidth;
const double DEFAULT_CHAR_WIDTH = 7.0;
if (!FontWidthLookup.TryGetValue(character, out charWidth))
if (FontWidthLookup.TryGetValue(character, out charWidth))
{
charWidth = DEFAULT_CHAR_WIDTH;
// Create the new size for this character
Size newSize = new Size { Width = charWidth * 6.25, Height = 130 };
// Thread-safe add operation using GetOrAdd (available in all .NET versions)
Size result = SizePerCharacter.GetOrAdd(key, newSize);
return result ?? null!;
}
else
{
// Default size for characters not in Font dictionary
Size defaultSize = new Size { Width = 50, Height = 130 };
Size result = SizePerCharacter.GetOrAdd(key, defaultSize);
return result ?? null!;
}

SizePerCharacter[key] = new Size { Width = charWidth * 6.25, Height = 130 };
SizePerCharacter.TryGetValue(key, out charSize);
}

return charSize ?? null!;
catch
{
throw;
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
</ChartAnnotation>
</ChartAnnotations>

<ChartSeriesCollection>

<ChartSeries DataSource="@MedalDetails" XName="Country" YName="Gold" Type="ChartSeriesType.Column">
</ChartSeries>
</ChartSeriesCollection>

</SfChart>
</ComponentUnderTest>
</SfFixture>
Expand All @@ -40,12 +40,13 @@
var cut = fixture.GetComponentUnderTest<SfChart>();
await Task.Delay(200);
var annotation = cut.FindComponent<ChartAnnotation>();
var annotations = cut.FindComponent<ChartAnnotations>();
Assert.True(annotation.Instance.ContentTemplate != null);
Assert.True(annotation.Instance.Description == "chart annotation");
Assert.True(annotation.Instance.Region == Regions.Series);
Assert.Equal("Medal count", cut.Instance.AccessibilityDescription);
Assert.Equal("count", cut.Instance.AccessibilityRole);
Assert.False(cut.Instance.Focusable);
Assert.Equal("Medal count", annotations.Instance.AccessibilityDescription);
Assert.Equal("count", annotations.Instance.AccessibilityRole);
Assert.False(annotations.Instance.Focusable);
cut.SetParametersAndRender();
await annotation.Instance.DisposeAsync();
}
Expand Down Expand Up @@ -83,10 +84,10 @@
</ChartAnnotation>
</ChartAnnotations>

<ChartSeriesCollection>

<ChartSeries DataSource="@MedalDetails" XName="Country" YName="Gold" Type="ChartSeriesType.Column">
</ChartSeries>
</ChartSeriesCollection>

</SfChart>
</ComponentUnderTest>
</SfFixture>
Expand Down
Loading