diff --git a/Source/OxyPlot.Avalonia/Annotations/FunctionAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/FunctionAnnotation.cs
index c22a010..9007744 100644
--- a/Source/OxyPlot.Avalonia/Annotations/FunctionAnnotation.cs
+++ b/Source/OxyPlot.Avalonia/Annotations/FunctionAnnotation.cs
@@ -33,7 +33,7 @@ public class FunctionAnnotation : PathAnnotation
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty ResolutionProperty = AvaloniaProperty.Register(nameof(Resolution), 400);
+ public static readonly StyledProperty ResolutionProperty = AvaloniaProperty.Register(nameof(Resolution), 400, validate: ValidateResolution);
///
/// Initializes static members of the class.
@@ -58,6 +58,17 @@ public FunctionAnnotation()
InternalAnnotation = new Annotations.FunctionAnnotation();
}
+ ///
+ /// Validates the number of points of the function. The core divides the range by this number and steps
+ /// to the bound: with zero or a negative value the loop never ends.
+ ///
+ /// The number of points.
+ /// true if the value is valid.
+ private static bool ValidateResolution(int value)
+ {
+ return value >= 1;
+ }
+
///
/// Gets or sets the equation.
///
diff --git a/Source/OxyPlot.Avalonia/Annotations/PolygonAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/PolygonAnnotation.cs
index 7482425..b8c9de4 100644
--- a/Source/OxyPlot.Avalonia/Annotations/PolygonAnnotation.cs
+++ b/Source/OxyPlot.Avalonia/Annotations/PolygonAnnotation.cs
@@ -31,7 +31,7 @@ public class PolygonAnnotation : ShapeAnnotation
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty> PointsProperty = AvaloniaProperty.Register>(nameof(Points), new List());
+ public static readonly StyledProperty> PointsProperty = AvaloniaProperty.Register>(nameof(Points));
///
/// Initializes static members of the class.
@@ -52,6 +52,9 @@ static PolygonAnnotation()
public PolygonAnnotation()
{
InternalAnnotation = new Annotations.PolygonAnnotation();
+
+ // Every instance has its own list of points, otherwise points leak between annotations
+ SetCurrentValue(PointsProperty, new List());
}
///
@@ -121,7 +124,10 @@ public override void SynchronizeProperties()
base.SynchronizeProperties();
var a = (Annotations.PolygonAnnotation)InternalAnnotation;
a.Points.Clear();
- a.Points.AddRange(Points);
+ if (Points != null)
+ {
+ a.Points.AddRange(Points);
+ }
a.LineStyle = LineStyle;
a.LineJoin = LineJoin;
diff --git a/Source/OxyPlot.Avalonia/Annotations/PolylineAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/PolylineAnnotation.cs
index 33772d0..a214c90 100644
--- a/Source/OxyPlot.Avalonia/Annotations/PolylineAnnotation.cs
+++ b/Source/OxyPlot.Avalonia/Annotations/PolylineAnnotation.cs
@@ -32,7 +32,7 @@ public class PolylineAnnotation : PathAnnotation
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty> PointsProperty = AvaloniaProperty.Register>(nameof(Points), new List());
+ public static readonly StyledProperty> PointsProperty = AvaloniaProperty.Register>(nameof(Points));
///
/// Initializes static members of the class.
@@ -56,6 +56,9 @@ static PolylineAnnotation()
public PolylineAnnotation()
{
this.InternalAnnotation = new Annotations.PolylineAnnotation();
+
+ // Every instance has its own list of points, otherwise points leak between annotations
+ SetCurrentValue(PointsProperty, new List());
}
///
@@ -116,7 +119,11 @@ public override void SynchronizeProperties()
var a = (Annotations.PolylineAnnotation)this.InternalAnnotation;
a.Points.Clear();
- a.Points.AddRange(this.Points);
+ if (this.Points != null)
+ {
+ a.Points.AddRange(this.Points);
+ }
+
a.InterpolationAlgorithm = this.InterpolationAlgorithm;
a.MinimumSegmentLength = this.MinimumSegmentLength;
}
diff --git a/Source/OxyPlot.Avalonia/Annotations/RectangleAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/RectangleAnnotation.cs
index 6c9f0a1..8570db0 100644
--- a/Source/OxyPlot.Avalonia/Annotations/RectangleAnnotation.cs
+++ b/Source/OxyPlot.Avalonia/Annotations/RectangleAnnotation.cs
@@ -19,22 +19,22 @@ public class RectangleAnnotation : ShapeAnnotation
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty MaximumXProperty = AvaloniaProperty.Register(nameof(MaximumX), double.MaxValue);
+ public static readonly StyledProperty MaximumXProperty = AvaloniaProperty.Register(nameof(MaximumX), double.PositiveInfinity);
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty MaximumYProperty = AvaloniaProperty.Register(nameof(MaximumY), double.MaxValue);
+ public static readonly StyledProperty MaximumYProperty = AvaloniaProperty.Register(nameof(MaximumY), double.PositiveInfinity);
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty MinimumXProperty = AvaloniaProperty.Register(nameof(MinimumX), double.MinValue);
+ public static readonly StyledProperty MinimumXProperty = AvaloniaProperty.Register(nameof(MinimumX), double.NegativeInfinity);
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty MinimumYProperty = AvaloniaProperty.Register(nameof(MinimumY), double.MinValue);
+ public static readonly StyledProperty MinimumYProperty = AvaloniaProperty.Register(nameof(MinimumY), double.NegativeInfinity);
///
/// Initializes static members of the class.
@@ -140,10 +140,13 @@ public override void SynchronizeProperties()
base.SynchronizeProperties();
var a = (Annotations.RectangleAnnotation)InternalAnnotation;
- a.MinimumX = MinimumX;
- a.MaximumX = MaximumX;
- a.MinimumY = MinimumY;
- a.MaximumY = MaximumY;
+ // OxyPlot core 2.2.0 treats a bound as open only when it is infinite or NaN.
+ // The previous defaults double.MinValue/MaxValue are converted to infinity,
+ // otherwise the rectangle ends up in infinite screen coordinates.
+ a.MinimumX = MinimumX <= double.MinValue ? double.NegativeInfinity : MinimumX;
+ a.MaximumX = MaximumX >= double.MaxValue ? double.PositiveInfinity : MaximumX;
+ a.MinimumY = MinimumY <= double.MinValue ? double.NegativeInfinity : MinimumY;
+ a.MaximumY = MaximumY >= double.MaxValue ? double.PositiveInfinity : MaximumY;
}
}
}
\ No newline at end of file
diff --git a/Source/OxyPlot.Avalonia/Axes/AngleAxis.cs b/Source/OxyPlot.Avalonia/Axes/AngleAxis.cs
index b81521c..f345e52 100644
--- a/Source/OxyPlot.Avalonia/Axes/AngleAxis.cs
+++ b/Source/OxyPlot.Avalonia/Axes/AngleAxis.cs
@@ -35,7 +35,8 @@ static AngleAxis()
{
MajorGridlineStyleProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata(LineStyle.Solid));
MinorGridlineStyleProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata(LineStyle.Solid));
- PositionProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata(AxisPosition.None));
+ // Same as in the core: with None the axis does not reserve margins and the angle labels are clipped
+ PositionProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata(AxisPosition.All));
TickStyleProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata(TickStyle.None));
IsPanEnabledProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata(false));
IsZoomEnabledProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata(false));
@@ -50,9 +51,9 @@ static AngleAxis()
///
public AngleAxis()
{
+ // The gridline styles are set by OverrideMetadata above. An assignment here would become a local
+ // value and would override the style setters.
InternalAxis = new Axes.AngleAxis();
- MajorGridlineStyle = LineStyle.Solid;
- MinorGridlineStyle = LineStyle.Solid;
}
///
diff --git a/Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs b/Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs
index 1cca98d..3c98199 100644
--- a/Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs
+++ b/Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs
@@ -42,7 +42,7 @@ public class CategoryAxis : LinearAxis
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty> LabelsProperty = AvaloniaProperty.Register>(nameof(Labels), new List());
+ public static readonly StyledProperty> LabelsProperty = AvaloniaProperty.Register>(nameof(Labels));
///
/// Initializes static members of the class.
@@ -69,6 +69,9 @@ static CategoryAxis()
public CategoryAxis()
{
InternalAxis = new Axes.CategoryAxis();
+
+ // The list is created per instance: the default value in Avalonia is shared by all axes.
+ SetCurrentValue(LabelsProperty, new List());
}
///
diff --git a/Source/OxyPlot.Avalonia/Axes/LogarithmicAxis.cs b/Source/OxyPlot.Avalonia/Axes/LogarithmicAxis.cs
index bff3605..27a2e8b 100644
--- a/Source/OxyPlot.Avalonia/Axes/LogarithmicAxis.cs
+++ b/Source/OxyPlot.Avalonia/Axes/LogarithmicAxis.cs
@@ -20,7 +20,7 @@ public class LogarithmicAxis : Axis
/// Identifies the dependency property.
///
/// The logarithmic base.
- public static readonly StyledProperty BaseProperty = AvaloniaProperty.Register(nameof(Base), 10.0);
+ public static readonly StyledProperty BaseProperty = AvaloniaProperty.Register(nameof(Base), 10.0, validate: ValidateBase);
///
/// Identifies the dependency property.
@@ -33,7 +33,6 @@ public class LogarithmicAxis : Axis
public LogarithmicAxis()
{
InternalAxis = new Axes.LogarithmicAxis();
- FilterMinValue = 0;
}
///
@@ -89,8 +88,22 @@ protected override void SynchronizeProperties()
a.PowerPadding = PowerPadding;
}
+ ///
+ /// Validates the logarithm base. With a base that is not greater than one or is not a number
+ /// the core cannot compute the axis ticks and rendering hangs.
+ ///
+ /// The base.
+ /// true if the value is valid.
+ private static bool ValidateBase(double value)
+ {
+ return double.IsFinite(value) && value > 1;
+ }
+
static LogarithmicAxis()
{
+ // A default value instead of an assignment in the constructor: a local value would override styles
+ FilterMinValueProperty.OverrideDefaultValue(0.0);
+
BaseProperty.Changed.AddClassHandler(DataChanged);
PowerPaddingProperty.Changed.AddClassHandler(DataChanged);
}
diff --git a/Source/OxyPlot.Avalonia/Legends/Legend.Properties.cs b/Source/OxyPlot.Avalonia/Legends/Legend.Properties.cs
index 188bab8..3c94003 100644
--- a/Source/OxyPlot.Avalonia/Legends/Legend.Properties.cs
+++ b/Source/OxyPlot.Avalonia/Legends/Legend.Properties.cs
@@ -49,7 +49,7 @@ public partial class Legend : Control
///
/// Identifies the dependency property.
///
- public static readonly StyledProperty LegendFontSizeProperty = AvaloniaProperty.Register