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
13 changes: 12 additions & 1 deletion Source/OxyPlot.Avalonia/Annotations/FunctionAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class FunctionAnnotation : PathAnnotation
/// <summary>
/// Identifies the <see cref="Resolution"/> dependency property.
/// </summary>
public static readonly StyledProperty<int> ResolutionProperty = AvaloniaProperty.Register<FunctionAnnotation, int>(nameof(Resolution), 400);
public static readonly StyledProperty<int> ResolutionProperty = AvaloniaProperty.Register<FunctionAnnotation, int>(nameof(Resolution), 400, validate: ValidateResolution);

/// <summary>
/// Initializes static members of the <see cref="FunctionAnnotation"/> class.
Expand All @@ -58,6 +58,17 @@ public FunctionAnnotation()
InternalAnnotation = new Annotations.FunctionAnnotation();
}

/// <summary>
/// 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.
/// </summary>
/// <param name="value">The number of points.</param>
/// <returns><c>true</c> if the value is valid.</returns>
private static bool ValidateResolution(int value)
{
return value >= 1;
}

/// <summary>
/// Gets or sets the equation.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions Source/OxyPlot.Avalonia/Annotations/PolygonAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PolygonAnnotation : ShapeAnnotation
/// <summary>
/// Identifies the <see cref="Points"/> dependency property.
/// </summary>
public static readonly StyledProperty<IList<DataPoint>> PointsProperty = AvaloniaProperty.Register<PolygonAnnotation, IList<DataPoint>>(nameof(Points), new List<DataPoint>());
public static readonly StyledProperty<IList<DataPoint>> PointsProperty = AvaloniaProperty.Register<PolygonAnnotation, IList<DataPoint>>(nameof(Points));

/// <summary>
/// Initializes static members of the <see cref="PolygonAnnotation"/> class.
Expand All @@ -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<DataPoint>());
}

/// <summary>
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions Source/OxyPlot.Avalonia/Annotations/PolylineAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class PolylineAnnotation : PathAnnotation
/// <summary>
/// Identifies the <see cref="Points"/> dependency property.
/// </summary>
public static readonly StyledProperty<IList<DataPoint>> PointsProperty = AvaloniaProperty.Register<PolylineAnnotation, IList<DataPoint>>(nameof(Points), new List<DataPoint>());
public static readonly StyledProperty<IList<DataPoint>> PointsProperty = AvaloniaProperty.Register<PolylineAnnotation, IList<DataPoint>>(nameof(Points));

/// <summary>
/// Initializes static members of the <see cref="PolylineAnnotation"/> class.
Expand All @@ -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<DataPoint>());
}

/// <summary>
Expand Down Expand Up @@ -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;
}
Expand Down
19 changes: 11 additions & 8 deletions Source/OxyPlot.Avalonia/Annotations/RectangleAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ public class RectangleAnnotation : ShapeAnnotation
/// <summary>
/// Identifies the <see cref="MaximumX"/> dependency property.
/// </summary>
public static readonly StyledProperty<double> MaximumXProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MaximumX), double.MaxValue);
public static readonly StyledProperty<double> MaximumXProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MaximumX), double.PositiveInfinity);

/// <summary>
/// Identifies the <see cref="MaximumY"/> dependency property.
/// </summary>
public static readonly StyledProperty<double> MaximumYProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MaximumY), double.MaxValue);
public static readonly StyledProperty<double> MaximumYProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MaximumY), double.PositiveInfinity);

/// <summary>
/// Identifies the <see cref="MinimumX"/> dependency property.
/// </summary>
public static readonly StyledProperty<double> MinimumXProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MinimumX), double.MinValue);
public static readonly StyledProperty<double> MinimumXProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MinimumX), double.NegativeInfinity);

/// <summary>
/// Identifies the <see cref="MinimumY"/> dependency property.
/// </summary>
public static readonly StyledProperty<double> MinimumYProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MinimumY), double.MinValue);
public static readonly StyledProperty<double> MinimumYProperty = AvaloniaProperty.Register<RectangleAnnotation, double>(nameof(MinimumY), double.NegativeInfinity);

/// <summary>
/// Initializes static members of the <see cref="RectangleAnnotation"/> class.
Expand Down Expand Up @@ -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;
}
}
}
7 changes: 4 additions & 3 deletions Source/OxyPlot.Avalonia/Axes/AngleAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ static AngleAxis()
{
MajorGridlineStyleProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata<LineStyle>(LineStyle.Solid));
MinorGridlineStyleProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata<LineStyle>(LineStyle.Solid));
PositionProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata<AxisPosition>(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>(AxisPosition.All));
TickStyleProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata<TickStyle>(TickStyle.None));
IsPanEnabledProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata<bool>(false));
IsZoomEnabledProperty.OverrideMetadata(typeof(AngleAxis), new StyledPropertyMetadata<bool>(false));
Expand All @@ -50,9 +51,9 @@ static AngleAxis()
/// </summary>
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;
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CategoryAxis : LinearAxis
/// <summary>
/// Identifies the <see cref="Labels"/> dependency property.
/// </summary>
public static readonly StyledProperty<IList<string>> LabelsProperty = AvaloniaProperty.Register<CategoryAxis, IList<string>>(nameof(Labels), new List<string>());
public static readonly StyledProperty<IList<string>> LabelsProperty = AvaloniaProperty.Register<CategoryAxis, IList<string>>(nameof(Labels));

/// <summary>
/// Initializes static members of the <see cref="CategoryAxis" /> class.
Expand All @@ -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<string>());
}

/// <summary>
Expand Down
17 changes: 15 additions & 2 deletions Source/OxyPlot.Avalonia/Axes/LogarithmicAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class LogarithmicAxis : Axis
/// Identifies the <see cref="Base"/> dependency property.
/// </summary>
/// <value>The logarithmic base.</value>
public static readonly StyledProperty<double> BaseProperty = AvaloniaProperty.Register<LogarithmicAxis, double>(nameof(Base), 10.0);
public static readonly StyledProperty<double> BaseProperty = AvaloniaProperty.Register<LogarithmicAxis, double>(nameof(Base), 10.0, validate: ValidateBase);

/// <summary>
/// Identifies the <see cref="PowerPadding"/> dependency property.
Expand All @@ -33,7 +33,6 @@ public class LogarithmicAxis : Axis
public LogarithmicAxis()
{
InternalAxis = new Axes.LogarithmicAxis();
FilterMinValue = 0;
}

/// <summary>
Expand Down Expand Up @@ -89,8 +88,22 @@ protected override void SynchronizeProperties()
a.PowerPadding = PowerPadding;
}

/// <summary>
/// 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.
/// </summary>
/// <param name="value">The base.</param>
/// <returns><c>true</c> if the value is valid.</returns>
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<LogarithmicAxis>(0.0);

BaseProperty.Changed.AddClassHandler<LogarithmicAxis>(DataChanged);
PowerPaddingProperty.Changed.AddClassHandler<LogarithmicAxis>(DataChanged);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/OxyPlot.Avalonia/Legends/Legend.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public partial class Legend : Control
/// <summary>
/// Identifies the <see cref="LegendFontSize"/> dependency property.
/// </summary>
public static readonly StyledProperty<double> LegendFontSizeProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendFontSize), 12.0);
public static readonly StyledProperty<double> LegendFontSizeProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendFontSize), double.NaN);

/// <summary>
/// Identifies the <see cref="LegendFontWeight"/> dependency property.
Expand Down Expand Up @@ -154,7 +154,7 @@ public partial class Legend : Control
/// <summary>
/// Identifies the <see cref="LegendTitleFontSize"/> dependency property.
/// </summary>
public static readonly StyledProperty<double> LegendTitleFontSizeProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendTitleFontSize), 12.0);
public static readonly StyledProperty<double> LegendTitleFontSizeProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendTitleFontSize), double.NaN);

/// <summary>
/// Identifies the <see cref="LegendTitleFontWeight"/> dependency property.
Expand Down
4 changes: 2 additions & 2 deletions Source/OxyPlot.Avalonia/Series/BarSeries/LinearBarSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class LinearBarSeries : DataPointSeries
/// <summary>
/// Identifies the <see cref="BarWidth" /> dependency property.
/// </summary>
public static readonly StyledProperty<double> BarWidthProperty = AvaloniaProperty.Register<LinearBarSeries, double>(nameof(BarWidth), 1.0);
public static readonly StyledProperty<double> BarWidthProperty = AvaloniaProperty.Register<LinearBarSeries, double>(nameof(BarWidth), 5.0);

/// <summary>
/// Identifies the <see cref="FillColor"/> dependency property.
Expand All @@ -36,7 +36,7 @@ public class LinearBarSeries : DataPointSeries
/// <summary>
/// Identifies the <see cref="StrokeThickness"/> dependency property.
/// </summary>
public static readonly StyledProperty<double> StrokeThicknessProperty = AvaloniaProperty.Register<LinearBarSeries, double>(nameof(StrokeThickness), 1.0);
public static readonly StyledProperty<double> StrokeThicknessProperty = AvaloniaProperty.Register<LinearBarSeries, double>(nameof(StrokeThickness), 0.0);

/// <summary>
/// Identifies the <see cref="NegativeFillColor"/> dependency property.
Expand Down