Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
203e84a
Update Avalonia to 12.1.4
izakusilov Oct 25, 2026
a5b6a49
Remove unused fields from PlotBase
izakusilov Oct 24, 2026
9c754f1
Fix TrackerControl corner radius and border updates
izakusilov Oct 24, 2026
70663aa
Apply default styles to derived plot controls
izakusilov Oct 24, 2026
8ef26c0
Use black text in the tracker template
izakusilov Oct 24, 2026
d960f8c
Fix zoom rectangle border thickness
izakusilov Oct 24, 2026
924f5fe
Skip shapes with non-finite coordinates
izakusilov Oct 24, 2026
76fe1cf
Measure text without size limit
izakusilov Oct 24, 2026
66034a6
Fix image cropping in CanvasRenderContext
izakusilov Oct 24, 2026
678bfa8
Compute anti-aliasing mode once per line
izakusilov Oct 24, 2026
af5a7c9
Dispose bitmap after exporting to PNG
izakusilov Oct 24, 2026
61392eb
Validate model and size in SaveBitmap and ToBitmap
izakusilov Oct 24, 2026
5e97232
Catch clipboard errors in SetClipboardText
izakusilov Oct 24, 2026
407ec59
Use the control dispatcher in PlotBase
izakusilov Oct 24, 2026
3e30762
Clear the plot when the model is removed
izakusilov Oct 24, 2026
0eaec9e
Make PlotBase focusable
izakusilov Oct 24, 2026
aaa337b
Fix mouse wheel delta for touchpads
izakusilov Oct 24, 2026
09ac948
Fix context menu and pointer capture handling
izakusilov Oct 24, 2026
105bd17
Synchronize the model when InvalidatePlot is called on a plot
izakusilov Oct 24, 2026
0bdc909
Fix logical tree and model update when plot elements change
izakusilov Oct 24, 2026
ac59f7e
Apply TitleHorizontalAlignment to the model
izakusilov Oct 24, 2026
88bd67a
Accept any brush as PlotAreaBackground
izakusilov Oct 24, 2026
2c37317
Refresh data when properties that affect data change
izakusilov Oct 24, 2026
ec27cda
Add missing property change handlers
izakusilov Oct 24, 2026
bdb4383
Remove duplicate property change handlers
izakusilov Oct 24, 2026
15cc8c7
Do not override plot text color and font with inherited series values
izakusilov Oct 24, 2026
eb07888
Match default values of legend, linear bar series and angle axis with…
izakusilov Oct 24, 2026
70c6ba6
Use infinite default bounds for RectangleAnnotation
izakusilov Oct 24, 2026
89eea0b
Set default values in metadata instead of constructors
izakusilov Oct 24, 2026
f44a118
Validate LogarithmicAxis.Base and FunctionAnnotation.Resolution
izakusilov Oct 24, 2026
224eaa5
Create default lists per instance
izakusilov Oct 24, 2026
58a4b37
Fix LinearColorAxis palette generation
izakusilov Oct 24, 2026
e9405c2
Fix Axis.MaximumMargin and ExtraGridlines registration
izakusilov Oct 24, 2026
11d550b
Fix property owners in area series
izakusilov Oct 24, 2026
5407cc9
Remove unused HeatMapSeries colors and forward ColorAxisKey
izakusilov Oct 24, 2026
20ae3bf
Type ScatterSeries.Mapping and make ColorAxisKey a styled property
izakusilov Oct 24, 2026
c70c75d
Forward secondary line styles of two and three color line series
izakusilov Oct 24, 2026
4339fbc
Forward BoxWidth and MedianThickness to BoxPlotSeries
izakusilov Oct 24, 2026
a916382
Keep marker and outlier outlines null instead of empty arrays
izakusilov Oct 24, 2026
6b52cc8
Ignore foreign items in bar and box plot series
izakusilov Oct 24, 2026
5f5a125
Do not override text alignment of TextAnnotation
izakusilov Oct 24, 2026
5de3b08
Add headless test project
izakusilov Oct 24, 2026
4507e2e
Add plot tests
izakusilov Oct 24, 2026
b47ea29
Add axis tests
izakusilov Oct 24, 2026
ef4f045
Add annotation tests
izakusilov Oct 24, 2026
4c43925
Add series tests
izakusilov Oct 24, 2026
70c77ef
Add tracker tests
izakusilov Oct 24, 2026
0959ad3
Add input tests
izakusilov Oct 24, 2026
7851fea
Add export tests
izakusilov Oct 24, 2026
9c8219f
Add render context tests
izakusilov Oct 24, 2026
1d60b6d
Run tests in CI
izakusilov Oct 24, 2026
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
2 changes: 1 addition & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<AvaloniaVersion>12.0.2</AvaloniaVersion>
<AvaloniaVersion>12.1.4</AvaloniaVersion>
<OxyPlotCoreVersion>2.2.0</OxyPlotCoreVersion>
</PropertyGroup>
</Project>
168 changes: 168 additions & 0 deletions Source/OxyPlot.Avalonia.Tests/AnnotationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
using Avalonia.Headless.XUnit;
using Avalonia.Media;
using OxyPlot;
using OxyPlot.Avalonia;
using AvaloniaHorizontalAlignment = Avalonia.Layout.HorizontalAlignment;
using AvaloniaVerticalAlignment = Avalonia.Layout.VerticalAlignment;
using CoreAnnotations = OxyPlot.Annotations;
using CoreAxes = OxyPlot.Axes;
using ShapePath = Avalonia.Controls.Shapes.Path;

namespace OxyPlot.Avalonia.Tests;

/// <summary>
/// Tests of the annotation controls: default values, copying to the core and rendering without failures.
/// </summary>
public class AnnotationTests
{
[AvaloniaFact]
public void RectangleAnnotation_HorizontalBand_DrawsAcrossPlotArea()
{
var plot = PlotWithAxes();
plot.Annotations.Add(new RectangleAnnotation { MinimumY = 4, MaximumY = 6 });

// Show used to throw InvalidOperationException from Measure: the rectangle went to infinity
var window = Ui.Show(plot);

var plotArea = plot.ActualModel.PlotArea;
var band = Assert.Single(
Ui.PlotCanvas(plot).Children.OfType<ShapePath>(),
p => p.Fill != null && p.Data is RectangleGeometry);
var rect = ((RectangleGeometry)band.Data!).Rect;
Assert.Equal(plotArea.Width, rect.Width, 3);
Assert.True(rect.Height > 0 && rect.Height < plotArea.Height);
window.Close();
}

[AvaloniaFact]
public void RectangleAnnotation_Defaults_AreInfiniteAsInCore()
{
var annotation = new RectangleAnnotation();

Assert.Equal(double.NegativeInfinity, annotation.MinimumX);
Assert.Equal(double.PositiveInfinity, annotation.MaximumX);
Assert.Equal(double.NegativeInfinity, annotation.MinimumY);
Assert.Equal(double.PositiveInfinity, annotation.MaximumY);
}

[AvaloniaFact]
public void RectangleAnnotation_LegacyMinMaxValues_BecomeInfiniteInModel()
{
// the previous values double.MinValue/MaxValue still mean "no bound"
var annotation = new RectangleAnnotation
{
MinimumX = double.MinValue,
MaximumX = double.MaxValue,
MinimumY = 1,
MaximumY = 2,
};

var model = Assert.IsType<CoreAnnotations.RectangleAnnotation>(annotation.CreateModel());

Assert.Equal(double.NegativeInfinity, model.MinimumX);
Assert.Equal(double.PositiveInfinity, model.MaximumX);
Assert.Equal(1, model.MinimumY);
Assert.Equal(2, model.MaximumY);
}

[AvaloniaFact]
public void EllipseAnnotation_WithoutSize_DoesNotBreakLayout()
{
var plot = PlotWithAxes();
plot.Annotations.Add(new EllipseAnnotation { X = 5, Y = 5 });

var window = Ui.Show(plot);

Assert.True(plot.ActualModel.PlotArea.Width > 0);
window.Close();
}

[AvaloniaFact]
public void TextAnnotation_WithoutPosition_DoesNotBreakLayout()
{
var plot = PlotWithAxes();
plot.Annotations.Add(new TextAnnotation { Text = "label" });

var window = Ui.Show(plot);

Assert.True(plot.ActualModel.PlotArea.Width > 0);
window.Close();
}

[AvaloniaFact]
public void PlotView_CoreEllipseAnnotationWithoutSize_DoesNotBreakLayout()
{
// the core itself builds an ellipse with a NaN size, so the protection is needed in the render context
var model = Ui.ModelWithAxes();
model.Annotations.Add(new CoreAnnotations.EllipseAnnotation { X = 5, Y = 5 });
var view = new PlotView { Model = model };

var window = Ui.Show(view);

Assert.True(model.PlotArea.Width > 0);
window.Close();
}

[AvaloniaTheory]
[InlineData(0)]
[InlineData(-1)]
public void FunctionAnnotation_NonPositiveResolution_Throws(int value)
{
// the core divides the range by Resolution and steps to the bound: the loop would never end
Assert.Throws<ArgumentException>(() => new FunctionAnnotation { Resolution = value });
}

[AvaloniaFact]
public void PolygonAnnotation_TwoInstances_HaveSeparatePointLists()
{
var first = new PolygonAnnotation();
var second = new PolygonAnnotation();

first.Points.Add(new DataPoint(1, 1));

Assert.NotSame(first.Points, second.Points);
Assert.Empty(second.Points);
}

[AvaloniaFact]
public void PolylineAnnotation_TwoInstances_HaveSeparatePointLists()
{
var first = new PolylineAnnotation();
var second = new PolylineAnnotation();

first.Points.Add(new DataPoint(1, 1));

Assert.NotSame(first.Points, second.Points);
Assert.Empty(second.Points);
}

[AvaloniaFact]
public void TextAnnotation_TextAlignment_ReachesModelInsteadOfLayoutAlignment()
{
// the layout alignment of the control must not replace the text alignment
var annotation = new TextAnnotation
{
Text = "label",
TextHorizontalAlignment = AvaloniaHorizontalAlignment.Left,
TextVerticalAlignment = AvaloniaVerticalAlignment.Bottom,
HorizontalAlignment = AvaloniaHorizontalAlignment.Right,
VerticalAlignment = AvaloniaVerticalAlignment.Top,
};

var model = Assert.IsType<CoreAnnotations.TextAnnotation>(annotation.CreateModel());

Assert.Equal(HorizontalAlignment.Left, model.TextHorizontalAlignment);
Assert.Equal(VerticalAlignment.Bottom, model.TextVerticalAlignment);
}

/// <summary>
/// A plot with linear axes 0..10 on which the annotations get screen coordinates.
/// </summary>
private static Plot PlotWithAxes()
{
var plot = new Plot();
plot.Axes.Add(new LinearAxis { Position = CoreAxes.AxisPosition.Bottom, Minimum = 0, Maximum = 10 });
plot.Axes.Add(new LinearAxis { Position = CoreAxes.AxisPosition.Left, Minimum = 0, Maximum = 10 });
return plot;
}
}
188 changes: 188 additions & 0 deletions Source/OxyPlot.Avalonia.Tests/AxisTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
using Avalonia;
using Avalonia.Headless.XUnit;
using Avalonia.Media;
using Avalonia.Styling;
using OxyPlot;
using OxyPlot.Avalonia;
using CoreAxes = OxyPlot.Axes;

namespace OxyPlot.Avalonia.Tests;

/// <summary>
/// Tests of the axis controls: default values, value validation and copying to the axes of the core.
/// </summary>
public class AxisTests
{
[AvaloniaFact]
public void AngleAxis_Default_PositionAllAsInCore()
{
var axis = new AngleAxis();

// with None the axis does not reserve margins and the angle labels are clipped
Assert.Equal(new CoreAxes.AngleAxis().Position, axis.CreateModel().Position);
Assert.Equal(CoreAxes.AxisPosition.All, axis.Position);
}

[AvaloniaFact]
public void AngleAxis_Default_SolidGridlines()
{
var axis = new AngleAxis();

Assert.Equal(LineStyle.Solid, axis.MajorGridlineStyle);
Assert.Equal(LineStyle.Solid, axis.MinorGridlineStyle);
}

[AvaloniaFact]
public void AngleAxis_StyleSetter_OverridesGridlineStyle()
{
var angle = new AngleAxis();
var plot = new Plot { PlotType = PlotType.Polar };
plot.Styles.Add(new Style(x => x.OfType<AngleAxis>())
{
Setters = { new Setter(Axis.MajorGridlineStyleProperty, LineStyle.Dot) },
});
plot.Axes.Add(angle);
plot.Axes.Add(new MagnitudeAxis());

var window = Ui.Show(plot);

// the value from the constructor was a local one and overrode the style
Assert.Equal(LineStyle.Dot, angle.MajorGridlineStyle);
window.Close();
}

[AvaloniaFact]
public void LogarithmicAxis_Default_FilterMinValueZero()
{
Assert.Equal(0.0, new LogarithmicAxis().FilterMinValue);
}

[AvaloniaFact]
public void LogarithmicAxis_StyleSetter_OverridesFilterMinValue()
{
var axis = new LogarithmicAxis { Position = CoreAxes.AxisPosition.Left };
var plot = new Plot();
plot.Styles.Add(new Style(x => x.OfType<LogarithmicAxis>())
{
Setters = { new Setter(Axis.FilterMinValueProperty, -5.0) },
});
plot.Axes.Add(axis);

var window = Ui.Show(plot);

Assert.Equal(-5.0, axis.FilterMinValue);
window.Close();
}

[AvaloniaTheory]
[InlineData(1.0)]
[InlineData(0.0)]
[InlineData(-2.0)]
[InlineData(double.NaN)]
[InlineData(double.PositiveInfinity)]
public void LogarithmicAxis_InvalidBase_Throws(double value)
{
// with such a base the core cannot compute the ticks and rendering hangs
Assert.Throws<ArgumentException>(() => new LogarithmicAxis { Base = value });
}

[AvaloniaFact]
public void LogarithmicAxis_BaseTwo_ReachesModel()
{
var model = Assert.IsType<CoreAxes.LogarithmicAxis>(new LogarithmicAxis { Base = 2 }.CreateModel());

Assert.Equal(2, model.Base);
}

[AvaloniaFact]
public void Axis_MarginsAndExtraGridlines_ReachModel()
{
var axis = new LinearAxis { MinimumMargin = 3, MaximumMargin = 7, ExtraGridlines = new[] { 1.0, 2.0 } };

var model = axis.CreateModel();

// MaximumMargin used to receive the value of MinimumMargin
Assert.Equal(3, model.MinimumMargin);
Assert.Equal(7, model.MaximumMargin);
Assert.Equal(new[] { 1.0, 2.0 }, model.ExtraGridlines);

// the name of the Avalonia property matches the name of the CLR property, otherwise the attribute in markup is not found
Assert.Same(Axis.ExtraGridlinesProperty, AvaloniaPropertyRegistry.Instance.FindRegistered(axis, nameof(Axis.ExtraGridlines)));
}

[AvaloniaFact]
public void LinearColorAxis_TwoStops_InterpolatesRequestedPaletteSize()
{
var axis = new LinearColorAxis { PaletteSize = 5 };
axis.GradientStops.Add(new GradientStop(Colors.Black, 0));
axis.GradientStops.Add(new GradientStop(Colors.White, 1));

var palette = ((CoreAxes.LinearColorAxis)axis.CreateModel()).Palette.Colors;

Assert.Equal(5, palette.Count);
Assert.Equal(OxyColors.Black, palette[0]);
Assert.Equal(OxyColors.White, palette[4]);
}

[AvaloniaFact]
public void LinearColorAxis_PaletteSizeOne_GivesSingleColor()
{
var axis = new LinearColorAxis { PaletteSize = 1 };
axis.GradientStops.Add(new GradientStop(Colors.Black, 0));
axis.GradientStops.Add(new GradientStop(Colors.White, 1));

var palette = ((CoreAxes.LinearColorAxis)axis.CreateModel()).Palette.Colors;

Assert.Single(palette);
}

[AvaloniaFact]
public void LinearColorAxis_StopsAtSameOffset_KeepsPaletteSize()
{
var axis = new LinearColorAxis { PaletteSize = 4 };
axis.GradientStops.Add(new GradientStop(Colors.Red, 0.5));
axis.GradientStops.Add(new GradientStop(Colors.Blue, 0.5));

var palette = ((CoreAxes.LinearColorAxis)axis.CreateModel()).Palette.Colors;

Assert.Equal(4, palette.Count);
}

[AvaloniaFact]
public void LinearColorAxis_OneStop_GivesPaletteOfThatColor()
{
var axis = new LinearColorAxis { PaletteSize = 3 };
axis.GradientStops.Add(new GradientStop(Colors.Red, 0.2));

var palette = ((CoreAxes.LinearColorAxis)axis.CreateModel()).Palette.Colors;

Assert.Equal(3, palette.Count);
Assert.All(palette, c => Assert.Equal(OxyColors.Red, c));
}

[AvaloniaFact]
public void LinearColorAxis_NoStops_KeepsCorePalette()
{
var palette = ((CoreAxes.LinearColorAxis)new LinearColorAxis().CreateModel()).Palette.Colors;

Assert.Equal(new CoreAxes.LinearColorAxis().Palette.Colors, palette);
}

[AvaloniaFact]
public void LinearColorAxis_PaletteSizeZero_Throws()
{
Assert.Throws<ArgumentException>(() => new LinearColorAxis { PaletteSize = 0 });
}

[AvaloniaFact]
public void CategoryAxis_TwoInstances_HaveSeparateLabelLists()
{
var first = new CategoryAxis();
var second = new CategoryAxis();

first.Labels.Add("a");

Assert.NotSame(first.Labels, second.Labels);
Assert.Empty(second.Labels);
}
}
Loading