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();
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;
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);
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/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 4882dbf..6b17fcf 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
@@ -262,24 +261,28 @@ 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();
+ s.OutlierOutline = OutlierOutline.ToScreenPointArray();
s.ShowBox = ShowBox;
s.ShowMedianAsDot = ShowMedianAsDot;
s.Stroke = Stroke.ToOxyColor();
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);
}
}
}
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
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;
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
/// 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
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/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();
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()