From bd2892e9ac962e545be28a8fb83cf26c6e802ea3 Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:01 +0000 Subject: [PATCH 01/10] Fix LinearColorAxis palette generation --- .../OxyPlot.Avalonia/Axes/LinearColorAxis.cs | 74 +++++++++++++------ 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/Source/OxyPlot.Avalonia/Axes/LinearColorAxis.cs b/Source/OxyPlot.Avalonia/Axes/LinearColorAxis.cs index 2ff5afe..b1b2c12 100644 --- a/Source/OxyPlot.Avalonia/Axes/LinearColorAxis.cs +++ b/Source/OxyPlot.Avalonia/Axes/LinearColorAxis.cs @@ -7,7 +7,6 @@ // // -------------------------------------------------------------------------------------------------------------------- -using System.Diagnostics.Contracts; using Avalonia; namespace OxyPlot.Avalonia @@ -44,13 +43,21 @@ public class LinearColorAxis : Axis /// public static readonly StyledProperty PaletteSizeProperty = AvaloniaProperty.Register(nameof(PaletteSize), 20, validate: ValidatePaletteSize); + /// + /// The default palette of the core. It is returned when there are no gradient stops. + /// + private readonly OxyPalette defaultPalette; + /// /// Initializes a new instance of the class. /// public LinearColorAxis() { InternalAxis = new Axes.LinearColorAxis(); - GradientStops = new List(); + defaultPalette = ((Axes.LinearColorAxis)InternalAxis).Palette; + + // The value is set as the current one so that it does not override style setters. + SetCurrentValue(GradientStopsProperty, new List()); } /// @@ -136,13 +143,25 @@ public override Axes.Axis CreateModel() protected override void SynchronizeProperties() { base.SynchronizeProperties(); - var axis = InternalAxis as Axes.LinearColorAxis; - Contract.Requires(axis != null); - if (GradientStops != null) + if (InternalAxis is not Axes.LinearColorAxis axis) { - axis.Palette = GradientStops.Count > 2 - ? Interpolate(GradientStops.ToList(), PaletteSize) - : new OxyPalette(); + throw new InvalidOperationException("The internal axis must be of type LinearColorAxis."); + } + + if (GradientStops != null && GradientStops.Count >= 2) + { + axis.Palette = Interpolate(GradientStops.ToList(), PaletteSize); + } + else if (GradientStops != null && GradientStops.Count == 1) + { + // A single stop: a palette of one color, but of the requested size. + axis.Palette = new OxyPalette( + Enumerable.Repeat(GradientStops[0].Color.ToOxyColor(), Math.Max(1, PaletteSize)).ToList()); + } + else + { + // No stops: return the palette of the core, otherwise the map would become monochrome. + axis.Palette = defaultPalette; } axis.HighColor = HighColor.ToOxyColor(); @@ -168,26 +187,39 @@ private static OxyPalette Interpolate(List stops, int paletteSize) Debug.Assert(stops.Count >= 2, "Can't interpolate less than 2 gradient stops."); Debug.Assert(paletteSize > 0, "Palette size must be non-zero positive number."); - var palette = new List(); stops.Sort((x1, x2) => x1.Offset.CompareTo(x2.Offset)); - var palettePositions = stops[0].Offset; - var step = (double)stops.Count / paletteSize; + var first = stops[0].Offset; + var last = stops[stops.Count - 1].Offset; + var range = last - first; + + // All stops are at one point or a single color is needed: there is nothing to interpolate, + // but the requested palette size must still be honored. + if (range <= 0 || paletteSize < 2) + { + return new OxyPalette( + Enumerable.Repeat(stops[0].Color.ToOxyColor(), Math.Max(1, paletteSize)).ToList()); + } + + var palette = new List(paletteSize); + var segment = 0; - for (int i = 0; i < stops.Count - 1; i++) + for (int i = 0; i < paletteSize; i++) { - var start = stops[i]; - var end = stops[i + 1]; + var position = first + (range * i / (paletteSize - 1)); - while (palettePositions <= end.Offset) + while (segment < stops.Count - 2 && position > stops[segment + 1].Offset) { - palette.Add( - OxyColor.Interpolate( - start.Color.ToOxyColor(), - end.Color.ToOxyColor(), - (palettePositions - start.Offset) / (end.Offset - start.Offset))); - palettePositions += step; + segment++; } + + var start = stops[segment]; + var end = stops[segment + 1]; + var span = end.Offset - start.Offset; + // Stops with the same offset: take the start color, no division by zero. + var t = span > 0 ? (position - start.Offset) / span : 0.0; + + palette.Add(OxyColor.Interpolate(start.Color.ToOxyColor(), end.Color.ToOxyColor(), t)); } return new OxyPalette(palette); From c91d4a5bf7fbf93c92ba24081f19d1f1c91f6502 Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:01 +0000 Subject: [PATCH 02/10] Fix Axis.MaximumMargin and ExtraGridlines registration --- Source/OxyPlot.Avalonia/Axes/Axis.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/OxyPlot.Avalonia/Axes/Axis.cs b/Source/OxyPlot.Avalonia/Axes/Axis.cs index a2c595a..7b4eaff 100644 --- a/Source/OxyPlot.Avalonia/Axes/Axis.cs +++ b/Source/OxyPlot.Avalonia/Axes/Axis.cs @@ -93,7 +93,7 @@ public abstract class Axis : Control /// /// Identifies the dependency property. /// - public static readonly StyledProperty ExtraGridlinesProperty = AvaloniaProperty.Register("ExtraGridLines", null); + public static readonly StyledProperty ExtraGridlinesProperty = AvaloniaProperty.Register(nameof(ExtraGridlines), null); /// /// Identifies the dependency property. @@ -589,7 +589,7 @@ public double ExtraGridlineThickness } /// - /// Gets or sets ExtraGridLines. + /// Gets or sets ExtraGridlines. /// public double[] ExtraGridlines { @@ -1548,7 +1548,7 @@ protected virtual void SynchronizeProperties() a.MinimumPadding = MinimumPadding; a.MaximumPadding = MaximumPadding; a.MinimumMargin = MinimumMargin; - a.MaximumMargin = MinimumMargin; + a.MaximumMargin = MaximumMargin; a.MinimumDataMargin = MinimumDataMargin; a.MaximumDataMargin = MaximumDataMargin; a.Position = Position; From 73d92ded9862bbada1fba559de06c720beb1affd Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:01 +0000 Subject: [PATCH 03/10] Fix property owners in area series --- Source/OxyPlot.Avalonia/Series/AreaSeries.cs | 2 +- .../Series/TwoColorAreaSeries.cs | 22 ------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/Source/OxyPlot.Avalonia/Series/AreaSeries.cs b/Source/OxyPlot.Avalonia/Series/AreaSeries.cs index 9064411..cfaa019 100644 --- a/Source/OxyPlot.Avalonia/Series/AreaSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/AreaSeries.cs @@ -21,7 +21,7 @@ public class AreaSeries : LineSeries /// /// Identifies the dependency property. /// - public static readonly StyledProperty Color2Property = AvaloniaProperty.Register(nameof(Color2), MoreColors.Automatic); + public static readonly StyledProperty Color2Property = AvaloniaProperty.Register(nameof(Color2), MoreColors.Automatic); /// /// Identifies the dependency property. diff --git a/Source/OxyPlot.Avalonia/Series/TwoColorAreaSeries.cs b/Source/OxyPlot.Avalonia/Series/TwoColorAreaSeries.cs index 5c0223c..0fd0c91 100644 --- a/Source/OxyPlot.Avalonia/Series/TwoColorAreaSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/TwoColorAreaSeries.cs @@ -24,11 +24,6 @@ public class TwoColorAreaSeries : AreaSeries /// public static readonly StyledProperty Dashes2Property = AvaloniaProperty.Register(nameof(Dashes2)); - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty FillProperty = AvaloniaProperty.Register(nameof(Fill), MoreColors.Automatic); - /// /// Identifies the dependency property. /// @@ -77,22 +72,6 @@ public double[] Dashes2 } } - /// - /// Gets or sets Fill above the limit line. - /// - public Color Fill - { - get - { - return GetValue(FillProperty); - } - - set - { - SetValue(FillProperty, value); - } - } - /// /// Gets or sets Fill below the limit line. /// @@ -181,7 +160,6 @@ protected override void SynchronizeProperties(OxyPlot.Series.Series series) { base.SynchronizeProperties(series); var s = (OxyPlot.Series.TwoColorAreaSeries)series; - s.Fill = Fill.ToOxyColor(); s.Fill2 = Fill2.ToOxyColor(); s.MarkerFill2 = MarkerFill2.ToOxyColor(); s.MarkerStroke2 = MarkerStroke2.ToOxyColor(); From fb0c34e85ce951aa8624fc5e4c6f784dbe4a19e4 Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:01 +0000 Subject: [PATCH 04/10] Remove unused HeatMapSeries colors and forward ColorAxisKey --- .../OxyPlot.Avalonia/Series/HeatMapSeries.cs | 45 +------------------ 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/Source/OxyPlot.Avalonia/Series/HeatMapSeries.cs b/Source/OxyPlot.Avalonia/Series/HeatMapSeries.cs index 6e752ee..e244c8c 100644 --- a/Source/OxyPlot.Avalonia/Series/HeatMapSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/HeatMapSeries.cs @@ -11,8 +11,6 @@ namespace OxyPlot.Avalonia { - using global::Avalonia.Media; - /// /// HeatMapSeries Avalonia wrapper /// @@ -48,16 +46,6 @@ public class HeatMapSeries : XYAxisSeries /// public static readonly StyledProperty ColorAxisKeyProperty = AvaloniaProperty.Register(nameof(ColorAxisKey), default); - /// - /// Identifies this dependency property. - /// - public static readonly StyledProperty LowColorProperty = AvaloniaProperty.Register(nameof(LowColor), default); - - /// - /// Identifies this dependency property. - /// - public static readonly StyledProperty HighColorProperty = AvaloniaProperty.Register(nameof(HighColor), default); - /// /// Initializes static members of the class. /// @@ -81,38 +69,6 @@ public HeatMapSeries() InternalSeries = new OxyPlot.Series.HeatMapSeries { Data = Data }; } - /// - /// Gets or sets LowColor - /// - public Color LowColor - { - get - { - return GetValue(LowColorProperty); - } - - set - { - SetValue(LowColorProperty, value); - } - } - - /// - /// Gets or sets HighColor - /// - public Color HighColor - { - get - { - return GetValue(LowColorProperty); - } - - set - { - SetValue(LowColorProperty, value); - } - } - /// /// Gets or sets ColorAxisKey property. /// @@ -237,6 +193,7 @@ protected override void SynchronizeProperties(OxyPlot.Series.Series series) s.X1 = X1; s.Y0 = Y0; s.Y1 = Y1; + s.ColorAxisKey = ColorAxisKey; } } } \ No newline at end of file From 5f00a643399055b28b93f89e20e3045b657ea756 Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:02 +0000 Subject: [PATCH 05/10] Type ScatterSeries.Mapping and make ColorAxisKey a styled property --- .../Series/ScatterSeries{T}.cs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Source/OxyPlot.Avalonia/Series/ScatterSeries{T}.cs b/Source/OxyPlot.Avalonia/Series/ScatterSeries{T}.cs index 981a1be..757f53c 100644 --- a/Source/OxyPlot.Avalonia/Series/ScatterSeries{T}.cs +++ b/Source/OxyPlot.Avalonia/Series/ScatterSeries{T}.cs @@ -54,7 +54,7 @@ public abstract class ScatterSeries : XYAxisSeries where T : ScatterPoint /// /// Identifies the dependency property. /// - public static readonly StyledProperty> MappingProperty = AvaloniaProperty.Register, Func>(nameof(Mapping), null); + public static readonly StyledProperty> MappingProperty = AvaloniaProperty.Register, Func>(nameof(Mapping), null); /// /// Identifies the dependency property. @@ -86,6 +86,11 @@ public abstract class ScatterSeries : XYAxisSeries where T : ScatterPoint /// public static readonly StyledProperty MarkerTypeProperty = AvaloniaProperty.Register, MarkerType>(nameof(MarkerType), MarkerType.Square); + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty ColorAxisKeyProperty = AvaloniaProperty.Register, string>(nameof(ColorAxisKey), null); + /// /// Initializes a new instance of the class. /// @@ -197,7 +202,7 @@ public Func Mapping { get { - return (Func)GetValue(MappingProperty); + return GetValue(MappingProperty); } set @@ -306,7 +311,18 @@ public MarkerType MarkerType /// Gets or sets the color axis key. /// /// The color axis key. - public string ColorAxisKey { get; set; } + public string ColorAxisKey + { + get + { + return GetValue(ColorAxisKeyProperty); + } + + set + { + SetValue(ColorAxisKeyProperty, value); + } + } /// /// Creates the internal series. @@ -358,6 +374,7 @@ static ScatterSeries() MarkerStrokeProperty.Changed.AddClassHandler>(AppearanceChanged); MarkerStrokeThicknessProperty.Changed.AddClassHandler>(AppearanceChanged); MarkerTypeProperty.Changed.AddClassHandler>(AppearanceChanged); + ColorAxisKeyProperty.Changed.AddClassHandler>(AppearanceChanged); } } } \ No newline at end of file From f89c622d480b2677b98ff168be6b9d1c54b7164a Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:02 +0000 Subject: [PATCH 06/10] Forward secondary line styles of two and three color line series --- Source/OxyPlot.Avalonia/Series/ThreeColorLineSeries.cs | 2 ++ Source/OxyPlot.Avalonia/Series/TwoColorLineSeries.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/Source/OxyPlot.Avalonia/Series/ThreeColorLineSeries.cs b/Source/OxyPlot.Avalonia/Series/ThreeColorLineSeries.cs index a6ef45f..dfbb529 100644 --- a/Source/OxyPlot.Avalonia/Series/ThreeColorLineSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/ThreeColorLineSeries.cs @@ -164,6 +164,8 @@ protected override void SynchronizeProperties(OxyPlot.Series.Series series) s.ColorLo = ColorLo.ToOxyColor(); s.LimitHi = LimitHi; s.ColorHi = ColorHi.ToOxyColor(); + s.LineStyleLo = LineStyleLo; + s.LineStyleHi = LineStyleHi; } static ThreeColorLineSeries() diff --git a/Source/OxyPlot.Avalonia/Series/TwoColorLineSeries.cs b/Source/OxyPlot.Avalonia/Series/TwoColorLineSeries.cs index 6e23e57..5685c7b 100644 --- a/Source/OxyPlot.Avalonia/Series/TwoColorLineSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/TwoColorLineSeries.cs @@ -99,6 +99,7 @@ protected override void SynchronizeProperties(OxyPlot.Series.Series series) var s = (OxyPlot.Series.TwoColorLineSeries)series; s.Limit = Limit; s.Color2 = Color2.ToOxyColor(); + s.LineStyle2 = LineStyle2; } static TwoColorLineSeries() From c851605ae487e78b444513abbb56074d279b585f Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:02 +0000 Subject: [PATCH 07/10] Forward BoxWidth and MedianThickness to BoxPlotSeries --- Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs b/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs index 4882dbf..f14ec3c 100644 --- a/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs @@ -262,9 +262,11 @@ protected override void SynchronizeProperties(OxyPlot.Series.Series series) base.SynchronizeProperties(series); var s = (OxyPlot.Series.BoxPlotSeries)series; + s.BoxWidth = BoxWidth; s.Fill = Fill.ToOxyColor(); s.LineStyle = LineStyle; s.MedianPointSize = MedianPointSize; + s.MedianThickness = MedianThickness; s.OutlierSize = OutlierSize; s.OutlierType = OutlierType; s.OutlierOutline = (OutlierOutline ?? Enumerable.Empty()).Select(point => point.ToScreenPoint()).ToArray(); From f2765d6c6f85b605e6164f241dfa7762cd68db94 Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:02 +0000 Subject: [PATCH 08/10] Keep marker and outlier outlines null instead of empty arrays --- Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs | 3 +-- Source/OxyPlot.Avalonia/Series/LineSeries.cs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs b/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs index f14ec3c..70ffe3d 100644 --- a/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs @@ -12,7 +12,6 @@ namespace OxyPlot.Avalonia { using global::Avalonia.Media; - using System.Linq; /// /// This is a Avalonia wrapper of OxyPlot.BoxPlotSeries @@ -269,7 +268,7 @@ protected override void SynchronizeProperties(OxyPlot.Series.Series series) s.MedianThickness = MedianThickness; s.OutlierSize = OutlierSize; s.OutlierType = OutlierType; - s.OutlierOutline = (OutlierOutline ?? Enumerable.Empty()).Select(point => point.ToScreenPoint()).ToArray(); + s.OutlierOutline = OutlierOutline.ToScreenPointArray(); s.ShowBox = ShowBox; s.ShowMedianAsDot = ShowMedianAsDot; s.Stroke = Stroke.ToOxyColor(); diff --git a/Source/OxyPlot.Avalonia/Series/LineSeries.cs b/Source/OxyPlot.Avalonia/Series/LineSeries.cs index 93d436d..caa2528 100644 --- a/Source/OxyPlot.Avalonia/Series/LineSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/LineSeries.cs @@ -15,7 +15,6 @@ namespace OxyPlot.Avalonia using OxyPlot.Series; using System; using System.Collections.Generic; - using System.Linq; /// /// This is a Avalonia wrapper of OxyPlot.LineSeries @@ -497,7 +496,7 @@ protected override void SynchronizeProperties(OxyPlot.Series.Series series) s.Dashes = Dashes; s.LineJoin = LineJoin; s.MarkerFill = MarkerFill.ToOxyColor(); - s.MarkerOutline = (MarkerOutline ?? Enumerable.Empty()).Select(point => point.ToScreenPoint()).ToArray(); + s.MarkerOutline = MarkerOutline.ToScreenPointArray(); s.MinimumSegmentLength = MinimumSegmentLength; s.LabelFormatString = LabelFormatString; s.LabelMargin = LabelMargin; From 8d5abeecf3783dca614a863ed2a25790776a23d6 Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:02 +0000 Subject: [PATCH 09/10] Ignore foreign items in bar and box plot series --- .../Series/BarSeries/BarSeriesBase{T}.cs | 12 +++++++----- Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase{T}.cs b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase{T}.cs index 96391e3..6e578c6 100644 --- a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase{T}.cs +++ b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase{T}.cs @@ -23,13 +23,15 @@ public class BarSeriesBase : BarSeriesBase protected override void SynchronizeProperties(OxyPlot.Series.Series series) { base.SynchronizeProperties(series); - if (Items != null) + var s = (OxyPlot.Series.BarSeriesBase)series; + s.Items.Clear(); + + // Items can contain foreign objects if ItemsSource is set together with ValueField or ColorField + foreach (var item in Items) { - var s = (OxyPlot.Series.BarSeriesBase)series; - s.Items.Clear(); - foreach (T item in Items) + if (item is T typed) { - s.Items.Add(item); + s.Items.Add(typed); } } } diff --git a/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs b/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs index 70ffe3d..6b17fcf 100644 --- a/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/BoxPlotSeries.cs @@ -275,12 +275,14 @@ protected override void SynchronizeProperties(OxyPlot.Series.Series series) s.StrokeThickness = StrokeThickness; s.WhiskerWidth = WhiskerWidth; - if (Items != null) + s.Items.Clear(); + + // Items can contain foreign objects if ItemsSource is set + foreach (var item in Items) { - s.Items.Clear(); - foreach (var item in Items) + if (item is OxyPlot.Series.BoxPlotItem boxItem) { - s.Items.Add((OxyPlot.Series.BoxPlotItem)item); + s.Items.Add(boxItem); } } } From 7c9f3faf56c7c1be86fbf5207d3efdfbee2cd0f3 Mon Sep 17 00:00:00 2001 From: izakusilov Date: Sat, 24 Oct 2026 13:49:02 +0000 Subject: [PATCH 10/10] Do not override text alignment of TextAnnotation --- Source/OxyPlot.Avalonia/Annotations/TextAnnotation.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/OxyPlot.Avalonia/Annotations/TextAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/TextAnnotation.cs index 7f19a3e..1cff05a 100644 --- a/Source/OxyPlot.Avalonia/Annotations/TextAnnotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/TextAnnotation.cs @@ -168,11 +168,9 @@ public override void SynchronizeProperties() { base.SynchronizeProperties(); var a = (Annotations.TextAnnotation)InternalAnnotation; - a.TextHorizontalAlignment = HorizontalAlignment.ToHorizontalAlignment(); a.Background = Background.ToOxyColor(); a.Offset = Offset.ToScreenVector(); - a.TextVerticalAlignment = VerticalAlignment.ToVerticalAlignment(); a.Padding = Padding.ToOxyThickness(); a.Stroke = Stroke.ToOxyColor();