From 088ebde82b813570413bde2a9cc4e0096a3ac7a4 Mon Sep 17 00:00:00 2001 From: Michael Phelps Date: Fri, 17 May 2024 12:19:04 -0500 Subject: [PATCH 1/2] Fix repaints causing ThrowInfiniteSeparators. Include axis name in exception if available. --- src/LiveChartsCore/CoreAxis.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/LiveChartsCore/CoreAxis.cs b/src/LiveChartsCore/CoreAxis.cs index 848d59fd8..7921707d7 100644 --- a/src/LiveChartsCore/CoreAxis.cs +++ b/src/LiveChartsCore/CoreAxis.cs @@ -102,7 +102,6 @@ public abstract class CoreAxis private Align? _labelsAlignment; private bool _inLineNamePlacement; private IEnumerable? _customSeparators; - private int _stepCount; internal double? _logBase; #endregion @@ -307,8 +306,6 @@ public LvcColor? CrosshairLabelsBackground /// public override void Invalidate(Chart chart) { - _stepCount = 0; - var cartesianChart = (CartesianChart)chart; var controlSize = cartesianChart.ControlSize; @@ -607,8 +604,6 @@ NamePadding is not null || SeparatorsPaint is not null || LabelsPaint is not nul UpdateLabel(visualSeparator.Label, x, y + tyco, labelContent, hasRotation, r, UpdateMode.Update); if (hasActivePaint) _ = measured.Add(visualSeparator); - - if (_stepCount++ > 10000) ThrowInfiniteSeparators(); } foreach (var separatorValueKey in separators.ToArray()) @@ -810,6 +805,10 @@ private IEnumerable EnumerateSeparators(double start, double end, double } var relativeEnd = end - start; + if (relativeEnd / step > 10000) + { + ThrowInfiniteSeparators(); + } for (var i = 0d; i <= relativeEnd; i += step) yield return start + i; } @@ -891,8 +890,6 @@ public virtual LvcSize GetPossibleSize(Chart chart) var m = textGeometry.Measure(LabelsPaint); if (m.Width > w) w = m.Width; if (m.Height > h) h = m.Height; - - if (_stepCount++ > 10000) ThrowInfiniteSeparators(); } return new LvcSize(w, h); @@ -1046,8 +1043,6 @@ private LvcSize GetPossibleMaxLabelSize() maxLabelSize = new LvcSize( maxLabelSize.Width > m.Width ? maxLabelSize.Width : m.Width, maxLabelSize.Height > m.Height ? maxLabelSize.Height : m.Height); - - if (_stepCount++ > 10000) ThrowInfiniteSeparators(); } return maxLabelSize; @@ -1456,8 +1451,9 @@ private string TryGetLabelOrLogError(Func labeler, double value) private void ThrowInfiniteSeparators() { + var axisName = string.IsNullOrEmpty(Name) ? "" : $"named \"{Name}\" "; throw new Exception( - $"The {_orientation} axis has an excessive number of separators. " + + $"The {_orientation} axis {axisName}has an excessive number of separators. " + $"If you set the step manually, ensure the number of separators is less than 10,000. " + $"This could also be caused because you are zooming too deep, " + $"try to set a limit to the current chart zoom using the Axis.{nameof(MinZoomDelta)} property. " + From 6d7776b995aa09db1336370c6cf553ea4322d0b0 Mon Sep 17 00:00:00 2001 From: Michael Phelps Date: Wed, 22 May 2024 08:03:29 -0500 Subject: [PATCH 2/2] Reorder workload install since LiveChartsCore is targeting them. --- build/build-windows.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build/build-windows.ps1 b/build/build-windows.ps1 index a681c9c93..ccda63f9b 100644 --- a/build/build-windows.ps1 +++ b/build/build-windows.ps1 @@ -1,5 +1,10 @@ param([string]$configuration = "Release") +dotnet workload install macos +dotnet workload install ios +dotnet workload install maccatalyst +dotnet workload install android + dotnet build ./src/skiasharp/LiveChartsCore.SkiaSharp.Avalonia/LiveChartsCore.SkiaSharpView.Avalonia.csproj -c $configuration dotnet build ./src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj -c $configuration dotnet build ./src/skiasharp/LiveChartsCore.SkiaSharp.Wpf/LiveChartsCore.SkiaSharpView.Wpf.csproj -c $configuration @@ -15,12 +20,7 @@ $msbuild = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere. /p:configuration=$configuration ` /restore -dotnet workload install macos -dotnet workload install ios -dotnet workload install maccatalyst -dotnet workload install android - & $msbuild ` ./src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj ` /p:configuration=$configuration ` - /restore \ No newline at end of file + /restore