Skip to content

Commit

Permalink
Merge pull request #1514 from mvphelps/master
Browse files Browse the repository at this point in the history
Fix repaints causing ThrowInfiniteSeparators.
  • Loading branch information
beto-rodriguez committed May 23, 2024
2 parents 02a848a + 950b82d commit 41439a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
15 changes: 10 additions & 5 deletions build/build-windows.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
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
dotnet build ./src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/LiveChartsCore.SkiaSharpView.Xamarin.Forms.csproj -c $configuration
dotnet build ./src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/LiveChartsCore.SkiaSharpView.Blazor.csproj -c $configuration
dotnet build ./src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/LiveChartsCore.SkiaSharpView.Eto.csproj -c $configuration
dotnet build ./src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.csproj -c $configuration

# DISABLE DOTNET BUILD FOR NOW
# LiveCharts requires VisualStudio 17.8
# but it seems that the current image installed is 17.6
# for now we are skiping msbuilds

# dotnet build ./src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.csproj -c $configuration
# but it seems that the current image installed is 17.6 (UPDATE NOT SURE WHICH VERSION IS INSTALLED AS TODAY)
# FOR NOW... DISABLE MSBUILD

# $msbuild = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe

Expand All @@ -23,4 +28,4 @@ dotnet build ./src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/LiveChartsCore.Ski
# & $msbuild `
# ./src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj `
# /p:configuration=$configuration `
# /restore
# /restore
16 changes: 6 additions & 10 deletions src/LiveChartsCore/CoreAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public abstract class CoreAxis<TDrawingContext, TTextGeometry, TLineGeometry>
private Align? _labelsAlignment;
private bool _inLineNamePlacement;
private IEnumerable<double>? _customSeparators;
private int _stepCount;
internal double? _logBase;

#endregion
Expand Down Expand Up @@ -307,8 +306,6 @@ public LvcColor? CrosshairLabelsBackground
/// <inheritdoc cref="ChartElement{TDrawingContext}.Invalidate(Chart{TDrawingContext})"/>
public override void Invalidate(Chart<TDrawingContext> chart)
{
_stepCount = 0;

var cartesianChart = (CartesianChart<TDrawingContext>)chart;

var controlSize = cartesianChart.ControlSize;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -810,6 +805,10 @@ private IEnumerable<double> 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;
}

Expand Down Expand Up @@ -891,8 +890,6 @@ public virtual LvcSize GetPossibleSize(Chart<TDrawingContext> 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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1456,8 +1451,9 @@ private string TryGetLabelOrLogError(Func<double, string> 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. " +
Expand Down

0 comments on commit 41439a5

Please sign in to comment.