Skip to content
Merged
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 @@ -1127,7 +1127,7 @@ private static bool IsRectType(string type)
/// <param name="series">The series whose Y range is applied.</param>
private void YAxisRange(ChartSeries series)
{
FindMinMax(series.Renderer.YMin, series.Renderer.YMax);
FindMinMax(series.Renderer?.YMin ?? 0, series.Renderer?.YMax ?? 0);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public virtual void AddRenderer(IChartElementRenderer renderer)
/// <param name="renderer">The renderer instance to remove.</param>
public void RemoveRenderer(IChartElementRenderer renderer)
{
if (Renderers.Contains(renderer))
if (renderer != null && Renderers.Contains(renderer))
{
ContainerPrerender = false;
RendererShouldRender = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ internal void Click(ChartInternalMouseEventArgs eventArgs, bool isMouseMove = fa
/// </summary>
internal void RefreshSeriesPosition()
{
Owner?._seriesContainer?.Renderers.ForEach(renderer => (renderer as ChartSeriesRenderer ?? null!).Position = (((renderer as ChartSeriesRenderer ?? null!).Series?.Visible ?? false) && (!(renderer as ChartSeriesRenderer ?? null!).Series?.Renderer.IsStackingSeries() ?? false)) ? double.NaN : (renderer as ChartSeriesRenderer ?? null!).Position);
Owner?._seriesContainer?.Renderers.ForEach(renderer => (renderer as ChartSeriesRenderer ?? null!).Position = (((renderer as ChartSeriesRenderer ?? null!).Series?.Visible ?? false) && (!(renderer as ChartSeriesRenderer ?? null!).Series?.Renderer?.IsStackingSeries() ?? false)) ? double.NaN : (renderer as ChartSeriesRenderer ?? null!).Position);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ protected virtual void RenderSeries()
RendererShouldRender = true;
FindClipRect();

if (Series?.Renderer.Container is not null && !Series.Renderer.Container.IsTrendLine)
if (Series?.Renderer?.Container is not null && !Series.Renderer.Container.IsTrendLine)
{
GetSeriesFocusIndex();
}
Expand Down Expand Up @@ -1448,7 +1448,7 @@ internal virtual double GetStackingStartValue(int pointIndex, int seriesIndex)
{
return Series is not null && !Series.Visible && Series._isLegendClicked && seriesIndex >= 0 && seriesIndex < Owner?._visibleSeriesRenderers.Count && Owner._visibleSeriesRenderers[seriesIndex].StackedValues is not null &&
pointIndex < Owner._visibleSeriesRenderers[seriesIndex].StackedValues?.StartValues?.Count && pointIndex < Owner._visibleSeriesRenderers[seriesIndex].StackedValues?.EndValues?.Count
? Index > 0 ? Owner._visibleSeriesRenderers[seriesIndex].StackedValues?.EndValues[pointIndex] ?? 0 : Series.Renderer.StackedValues?.StartValues[pointIndex] ?? 0
? Index > 0 ? Owner._visibleSeriesRenderers[seriesIndex].StackedValues?.EndValues[pointIndex] ?? 0 : Series.Renderer?.StackedValues?.StartValues[pointIndex] ?? 0
: 0;
}

Expand Down Expand Up @@ -1873,7 +1873,7 @@ internal Rect GetSeriesClipRect()
Height = ClipRect?.Height ?? 0
};

double plotOffset = Series?.Renderer.XAxisRenderer.Axis is not null ? Series.Renderer.XAxisRenderer.Axis.PlotOffset : 0;
double plotOffset = Series?.Renderer?.XAxisRenderer.Axis is not null ? Series.Renderer.XAxisRenderer.Axis.PlotOffset : 0;
double halfPlotOffset = plotOffset != 0 ? -(plotOffset / 2) : 0;

if (Owner is not null && Owner._requireInvertedAxis)
Expand Down Expand Up @@ -1920,7 +1920,7 @@ internal void PerformInitialAnimation(List<InitialAnimationInfo> animationInfo)
animationInfo.Add(new InitialAnimationInfo { Type = animationType, ElementId = options.Id, ClipPathId = ClipRectId(), Duration = duration, Delay = delay, IsInvertedAxis = Owner?._requireInvertedAxis ?? false });
int animationInfoIndex = animationInfo.Count - 1;
int count = Category() == SeriesCategories.Indicator ? 0 : 1;
List<Point> visiblePoints = ChartHelper.GetVisiblePoints(Series?.Renderer.Points ?? null!);
List<Point> visiblePoints = ChartHelper.GetVisiblePoints(Series?.Renderer?.Points ?? null!);
foreach (Point point in visiblePoints)
{
if (point.SymbolLocations.Count == 0)
Expand Down Expand Up @@ -2088,7 +2088,7 @@ internal virtual string CalCulateAccessibilityText(Point point)
/// specified, returns a DateTime object; otherwise, returns the original value.</returns>
internal virtual object GetPointXValue(object pointX, string dateFormat)
{
return Series?.Renderer.Container is not null && Series.Renderer.Container.IsTrendLine && !string.IsNullOrEmpty(dateFormat) ? DateTime.Parse(Intl.GetDateFormat(ChartHelper.GetDate(Convert.ToDouble(pointX, Culture)), string.Empty), CultureInfo.CurrentCulture) : pointX;
return Series?.Renderer?.Container is not null && Series.Renderer.Container.IsTrendLine && !string.IsNullOrEmpty(dateFormat) ? DateTime.Parse(Intl.GetDateFormat(ChartHelper.GetDate(Convert.ToDouble(pointX, Culture)), string.Empty), CultureInfo.CurrentCulture) : pointX;
}

/// <summary>
Expand All @@ -2100,7 +2100,7 @@ internal virtual object GetPointXValue(object pointX, string dateFormat)
/// series and its data points.</returns>
internal string GetSeriesDescriptionFormatText(List<Point> points)
{
return Series is not null && Series.AccessibilityDescription is not null ? Series.AccessibilityDescription : Series?.Name + (Series?.Renderer.Container is not null && Series.Renderer.Container.IsTrendLine ? ",Trendline " : ",") + Series?.Type + " series with " + points.Count + " data points";
return Series is not null && Series.AccessibilityDescription is not null ? Series.AccessibilityDescription : Series?.Name + (Series?.Renderer?.Container is not null && Series.Renderer.Container.IsTrendLine ? ",Trendline " : ",") + Series?.Type + " series with " + points.Count + " data points";
}

/// <summary>
Expand Down Expand Up @@ -2256,7 +2256,7 @@ internal virtual void GetChartData(Point point)
{
try
{
_ = ChartData?.Append(JsonSerializer.Serialize(Series?.Renderer.ChartPoints?[point.Index], _jsonOptions));
_ = ChartData?.Append(JsonSerializer.Serialize(Series?.Renderer?.ChartPoints?[point.Index], _jsonOptions));
_ = ChartData?.Append(',');
}
catch (Exception exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private DoubleRange UpdateSeriesGroupDoubleRange(DoubleRange doubleRange, double
/// <returns>Calculated <see cref="DoubleRange"/> representing the start and end offsets.</returns>
protected DoubleRange GetSideBySideInfo()
{
if (Series?.Container is not null && Series.Container.EnableSideBySidePlacement && (Series.Renderer.Position == 0 || double.IsNaN(Series.Renderer.Position)))
if (Series?.Container is not null && Series.Container.EnableSideBySidePlacement && (Series.Renderer?.Position == 0 || double.IsNaN(Series.Renderer?.Position ?? 0)))
{
GetSideBySidePositions();
}
Expand All @@ -308,7 +308,7 @@ protected DoubleRange GetSideBySideInfo()
return new DoubleRange(0, 0);
}

double rectCount = Series?.Container is not null && !Series.Container.EnableSideBySidePlacement ? 1 : Series?.Renderer.RectCount ?? 0;
double rectCount = Series?.Container is not null && !Series.Container.EnableSideBySidePlacement ? 1 : Series?.Renderer?.RectCount ?? 0;

if (Owner is not null && XAxisRenderer is null)
{
Expand All @@ -317,7 +317,7 @@ protected DoubleRange GetSideBySideInfo()

double minimumPointDelta = ChartHelper.GetMinPointsDelta(XAxisRenderer?.Axis ?? null!, Series?.Container?._seriesContainer?.Renderers.Cast<ChartSeriesRenderer>().ToList() ?? null!);
double width = GetColumnWidth(minimumPointDelta);
double location = ((Series?.Container is not null && !Series.Container.EnableSideBySidePlacement ? 0 : Series?.Renderer.Position ?? 0) / rectCount) - 0.5;
double location = ((Series?.Container is not null && !Series.Container.EnableSideBySidePlacement ? 0 : Series?.Renderer?.Position ?? 0) / rectCount) - 0.5;
DoubleRange doubleRange = new(location, location + (1 / rectCount));

if (!(double.IsNaN(doubleRange.Start) || double.IsNaN(doubleRange.End)))
Expand Down Expand Up @@ -523,16 +523,16 @@ internal Rect GetColumnWidthInPixelRect(Rect rectangle)
{
double columnWidth = Series.ColumnWidthInPixel;
bool isTransposed = Owner?.IsTransposed ?? false;
double halfColumnWidthAdjustment = columnWidth / 2 * (double.IsNaN(Series.Renderer.RectCount) ? 0 : Series.Renderer.RectCount);
double positionAdjustment = columnWidth * (double.IsNaN(Series.Renderer.Position) ? 0 : Series.Renderer.Position);
double halfColumnWidthAdjustment = columnWidth / 2 * (double.IsNaN(Series.Renderer?.RectCount ?? 0) ? 0 : Series.Renderer?.RectCount ?? 0);
double positionAdjustment = columnWidth * (double.IsNaN(Series.Renderer?.Position ?? 0) ? 0 : Series.Renderer?.Position ?? 0);

return Series.Type switch
{
ChartSeriesType.Bar or ChartSeriesType.StackingBar or ChartSeriesType.StackingBar100 => isTransposed
? new Rect(rectangle.X - (halfColumnWidthAdjustment - positionAdjustment), rectangle.Y, columnWidth, rectangle.Height)
: new Rect(rectangle.X, rectangle.Y - (halfColumnWidthAdjustment - (columnWidth * ((double.IsNaN(Series.Renderer.RectCount) ? 0 : Series.Renderer.RectCount) - (double.IsNaN(Series.Renderer.Position) ? 0 : Series.Renderer.Position) - 1))), rectangle.Width, columnWidth),
: new Rect(rectangle.X, rectangle.Y - (halfColumnWidthAdjustment - (columnWidth * ((double.IsNaN(Series.Renderer?.RectCount ?? 0) ? 0 : Series.Renderer.RectCount) - (double.IsNaN(Series.Renderer.Position) ? 0 : Series.Renderer.Position) - 1))), rectangle.Width, columnWidth),
ChartSeriesType.Column or ChartSeriesType.StackingColumn or ChartSeriesType.StackingColumn100 => isTransposed
? new Rect(rectangle.X, rectangle.Y - (halfColumnWidthAdjustment - (columnWidth * ((double.IsNaN(Series.Renderer.RectCount) ? 0 : Series.Renderer.RectCount) - (double.IsNaN(Series.Renderer.Position) ? 0 : Series.Renderer.Position) - 1))), rectangle.Width, columnWidth)
? new Rect(rectangle.X, rectangle.Y - (halfColumnWidthAdjustment - (columnWidth * ((double.IsNaN(Series.Renderer?.RectCount ?? 0) ? 0 : Series.Renderer.RectCount) - (double.IsNaN(Series.Renderer.Position) ? 0 : Series.Renderer.Position) - 1))), rectangle.Width, columnWidth)
: new Rect(rectangle.X - (halfColumnWidthAdjustment - positionAdjustment), rectangle.Y, columnWidth, rectangle.Height),
ChartSeriesType.Line => new Rect(),
ChartSeriesType.Area => new Rect(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ protected virtual void StorePointLocation(Point point, ChartSeries series, bool
(Owner is not null && Owner._zoomingModule is not null && Owner._zoomingModule.IsZoomed))
{
point?.SymbolLocations.Add(location);
series.Renderer.ChartPoints?[point?.Index ?? 0]?.SymbolLocations.Add(new IChartInternalLocation(Math.Round(location.X, 2), Math.Round(location.Y, 2)));
series.Renderer?.ChartPoints?[point?.Index ?? 0]?.SymbolLocations.Add(new IChartInternalLocation(Math.Round(location.X, 2), Math.Round(location.Y, 2)));
point?.Regions.Add(new Rect(point.SymbolLocations[0].X - markerWidth, point.SymbolLocations[0].Y - markerHeight, 2 * markerWidth, 2 * markerHeight));
series.Renderer.ChartPoints?[point?.Index ?? 0]?.Regions.Add(new IRect(Math.Round(point?.SymbolLocations[0].X ?? 0, 2) - markerWidth, Math.Round(point?.SymbolLocations[0].Y ?? 0, 2) - markerHeight, 2 * markerWidth, 2 * markerHeight));
series.Renderer?.ChartPoints?[point?.Index ?? 0]?.Regions.Add(new IRect(Math.Round(point?.SymbolLocations[0].X ?? 0, 2) - markerWidth, Math.Round(point?.SymbolLocations[0].Y ?? 0, 2) - markerHeight, 2 * markerWidth, 2 * markerHeight));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class MultiColoredBaseSeriesRenderer : AreaBaseSeriesRenderer
/// <param name="endValue">End axis value for clipping.</param>
/// <param name="index">Segment index (used for clip id).</param>
/// <param name="isX">Whether the segment axis is X.</param>
/// <param name="seriesIndex">Index of the series owning the segment.</param>
/// <returns>CSS url() clip-path reference string or <c>null</c> when not applicable.</returns>
private string CreateClipRect(RenderTreeBuilder builder, double startValue, double endValue, int index, bool isX, int seriesIndex)
{
Expand Down Expand Up @@ -209,15 +210,6 @@ internal List<ChartSegment> SortSegments(ChartSeries series, IList<ChartSegment>
return segments;
}

/// <summary>
/// Sets the fill/stroke color for the current point using the segment list or point color mapping.
/// </summary>
/// <param name="currentPoint">Point being colored.</param>
/// <param name="previous">Previous point for comparison when using point color mapping.</param>
/// <param name="series">Series metadata.</param>
/// <param name="isXSegment">Whether segmentation occurs on the X axis.</param>
/// <param name="segments">List of configured segments.</param>
/// <returns>True when color changed compared to the previous point (used for boundary detection).</returns>
/// <summary>
/// Sets the fill/stroke color for the current point using the segment list or point color mapping.
/// </summary>
Expand All @@ -230,7 +222,15 @@ public override string SetPointColor(Point point, string color)
}


/// <summary>
/// Sets the fill/stroke color for a point and reports whether it differs from the previous point.
/// </summary>
/// <param name="currentPoint">Point being colored.</param>
/// <param name="previous">Previous point for comparison.</param>
/// <param name="series">Series metadata.</param>
/// <param name="isXSegment">Whether segmentation occurs on the X axis.</param>
/// <param name="segments">Configured axis segments.</param>
/// <returns><see langword="true"/> when the point color differs from the previous point.</returns>
internal bool SetPointColor(Point currentPoint, Point previous, ChartSeries series, bool isXSegment, List<ChartSegment> segments)
{
if (string.IsNullOrEmpty(series.PointColorMapping))
Expand All @@ -240,7 +240,7 @@ internal bool SetPointColor(Point currentPoint, Point previous, ChartSeries seri
{
if (compareValue <= GetAxisValue(segments[i].Value, isXSegment ? XAxisRenderer.Axis ?? null! : YAxisRenderer.Axis ?? null!) || segments[i].Value is null)
{
if (series.Renderer.ChartPoints is not null)
if (series.Renderer?.ChartPoints is not null)
{
currentPoint.Interior = series.Renderer.ChartPoints[currentPoint.Index].Interior = segments[i].Color;
}
Expand Down Expand Up @@ -292,7 +292,7 @@ internal void ApplySegmentAxis(RenderTreeBuilder builder, ChartSeries series, Li
GetAxisValue(segment.Value, axis),
index,
series?.SegmentAxis == Segment.X,
series?.Renderer.Index ?? 0
series?.Renderer?.Index ?? 0
);

if (!string.IsNullOrEmpty(clipPath))
Expand Down
Loading
Loading