From e4f2b3c4521fccceee7aeca34d27fc9fc3266770 Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Tue, 5 Oct 2021 18:03:05 +0100 Subject: [PATCH 01/20] Add legends/erm XAML stuff --- .../ExampleBrowser/ExampleBrowser.csproj | 4 +- .../Annotations/Annotation.cs | 23 + Source/OxyPlot.Avalonia/Axes/Axis.cs | 23 + .../OxyPlot.Avalonia/OxyPlot.Avalonia.csproj | 2 +- Source/OxyPlot.Avalonia/Plot.Properties.cs | 621 +----------------- Source/OxyPlot.Avalonia/Plot.cs | 44 +- Source/OxyPlot.Avalonia/Series/Series.cs | 23 + 7 files changed, 106 insertions(+), 634 deletions(-) diff --git a/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj b/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj index 3800346..4af3ce5 100644 --- a/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj +++ b/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/Source/OxyPlot.Avalonia/Annotations/Annotation.cs b/Source/OxyPlot.Avalonia/Annotations/Annotation.cs index 1dc4a7d..6ac13aa 100644 --- a/Source/OxyPlot.Avalonia/Annotations/Annotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/Annotation.cs @@ -34,6 +34,11 @@ public abstract class Annotation : Control /// public static readonly StyledProperty YAxisKeyProperty = AvaloniaProperty.Register(nameof(YAxisKey), null); + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty EdgeRenderingModeProperty = AvaloniaProperty.Register(nameof(EdgeRenderingMode), EdgeRenderingMode.Automatic); + /// /// Gets or sets the rendering layer of the annotation. The default value is . /// @@ -82,6 +87,22 @@ public string YAxisKey } } + /// + /// Gets or sets the for the annotation. + /// + public EdgeRenderingMode EdgeRenderingMode + { + get + { + return GetValue(EdgeRenderingModeProperty); + } + + set + { + SetValue(EdgeRenderingModeProperty, value); + } + } + /// /// Gets or sets the internal annotation object. /// @@ -102,6 +123,7 @@ public virtual void SynchronizeProperties() a.Layer = Layer; a.XAxisKey = XAxisKey; a.YAxisKey = YAxisKey; + a.EdgeRenderingMode = EdgeRenderingMode; } /// @@ -137,6 +159,7 @@ static Annotation() LayerProperty.Changed.AddClassHandler(AppearanceChanged); XAxisKeyProperty.Changed.AddClassHandler(AppearanceChanged); YAxisKeyProperty.Changed.AddClassHandler(AppearanceChanged); + EdgeRenderingModeProperty.Changed.AddClassHandler(AppearanceChanged); } } } \ No newline at end of file diff --git a/Source/OxyPlot.Avalonia/Axes/Axis.cs b/Source/OxyPlot.Avalonia/Axes/Axis.cs index 460feb1..7815e01 100644 --- a/Source/OxyPlot.Avalonia/Axes/Axis.cs +++ b/Source/OxyPlot.Avalonia/Axes/Axis.cs @@ -330,6 +330,11 @@ public abstract class Axis : Control /// public static readonly StyledProperty UseSuperExponentialFormatProperty = AvaloniaProperty.Register(nameof(UseSuperExponentialFormat), false); + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty EdgeRenderingModeProperty = AvaloniaProperty.Register(nameof(EdgeRenderingMode), EdgeRenderingMode.Automatic); + /// /// Gets or sets the internal axis. /// @@ -1338,6 +1343,22 @@ public bool UseSuperExponentialFormat } } + /// + /// Gets or sets the for the axis. + /// + public EdgeRenderingMode EdgeRenderingMode + { + get + { + return GetValue(EdgeRenderingModeProperty); + } + + set + { + SetValue(EdgeRenderingModeProperty, value); + } + } + /// /// Creates the model. /// @@ -1474,6 +1495,7 @@ protected virtual void SynchronizeProperties() a.Unit = Unit; a.UseSuperExponentialFormat = UseSuperExponentialFormat; a.LabelFormatter = LabelFormatter; + a.EdgeRenderingMode = EdgeRenderingMode; } static Axis() @@ -1538,6 +1560,7 @@ static Axis() TitleProperty.Changed.AddClassHandler(AppearanceChanged); UnitProperty.Changed.AddClassHandler(AppearanceChanged); UseSuperExponentialFormatProperty.Changed.AddClassHandler(AppearanceChanged); + EdgeRenderingModeProperty.Changed.AddClassHandler(AppearanceChanged); } } } \ No newline at end of file diff --git a/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj b/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj index 4586e45..c179fe2 100644 --- a/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj +++ b/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj @@ -16,6 +16,6 @@ - + diff --git a/Source/OxyPlot.Avalonia/Plot.Properties.cs b/Source/OxyPlot.Avalonia/Plot.Properties.cs index 5e72e7b..9d900cf 100644 --- a/Source/OxyPlot.Avalonia/Plot.Properties.cs +++ b/Source/OxyPlot.Avalonia/Plot.Properties.cs @@ -34,111 +34,6 @@ public partial class Plot /// public static readonly StyledProperty IsLegendVisibleProperty = AvaloniaProperty.Register(nameof(IsLegendVisible), true); - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendBackgroundProperty = AvaloniaProperty.Register(nameof(LegendBackground), MoreColors.Undefined); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendBorderProperty = AvaloniaProperty.Register(nameof(LegendBorder), MoreColors.Undefined); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendBorderThicknessProperty = AvaloniaProperty.Register(nameof(LegendBorderThickness), 1.0); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendFontProperty = AvaloniaProperty.Register(nameof(LegendFont), null); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendFontSizeProperty = AvaloniaProperty.Register(nameof(LegendFontSize), 12.0); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendFontWeightProperty = AvaloniaProperty.Register(nameof(LegendFontWeight), FontWeight.Normal); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendItemAlignmentProperty = AvaloniaProperty.Register(nameof(LegendItemAlignment), global::Avalonia.Layout.HorizontalAlignment.Left); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendItemOrderProperty = AvaloniaProperty.Register(nameof(LegendItemOrder), LegendItemOrder.Normal); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendItemSpacingProperty = AvaloniaProperty.Register(nameof(LegendItemSpacing), 24.0); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendLineSpacingProperty = AvaloniaProperty.Register(nameof(LegendLineSpacing), 0d); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendMarginProperty = AvaloniaProperty.Register(nameof(LegendMargin), 8.0); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendMaxHeightProperty = AvaloniaProperty.Register(nameof(LegendMaxHeight), double.NaN); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendMaxWidthProperty = AvaloniaProperty.Register(nameof(LegendMaxWidth), double.NaN); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendOrientationProperty = AvaloniaProperty.Register(nameof(LegendOrientation), LegendOrientation.Vertical); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendColumnSpacingProperty = AvaloniaProperty.Register(nameof(LegendColumnSpacing), 8.0); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendPaddingProperty = AvaloniaProperty.Register(nameof(LegendPadding), 8.0); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendPlacementProperty = AvaloniaProperty.Register(nameof(LegendPlacement), LegendPlacement.Inside); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendPositionProperty = AvaloniaProperty.Register(nameof(LegendPosition), LegendPosition.RightTop); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendSymbolLengthProperty = AvaloniaProperty.Register(nameof(LegendSymbolLength), 16.0); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendSymbolMarginProperty = AvaloniaProperty.Register(nameof(LegendSymbolMargin), 4.0); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendSymbolPlacementProperty = AvaloniaProperty.Register(nameof(LegendSymbolPlacement), LegendSymbolPlacement.Left); - /// /// Identifies the dependency property. /// @@ -197,36 +92,6 @@ public partial class Plot /// public static readonly StyledProperty AxisTierDistanceProperty = AvaloniaProperty.Register(nameof(AxisTierDistance), 4d); - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendTextColorProperty = AvaloniaProperty.Register(nameof(LegendTextColor), MoreColors.Automatic); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendTitleProperty = AvaloniaProperty.Register(nameof(LegendTitle), null); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendTitleColorProperty = AvaloniaProperty.Register(nameof(LegendTitleColor), MoreColors.Automatic); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendTitleFontProperty = AvaloniaProperty.Register(nameof(LegendTitleFont), null); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendTitleFontSizeProperty = AvaloniaProperty.Register(nameof(LegendTitleFontSize), 12.0); - - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty LegendTitleFontWeightProperty = AvaloniaProperty.Register(nameof(LegendTitleFontWeight), FontWeight.Bold); - /// /// Identifies the dependency property. /// @@ -321,27 +186,6 @@ static Plot() PaddingProperty.Changed.AddClassHandler(AppearanceChanged); CultureProperty.Changed.AddClassHandler(AppearanceChanged); IsLegendVisibleProperty.Changed.AddClassHandler(AppearanceChanged); - LegendBackgroundProperty.Changed.AddClassHandler(AppearanceChanged); - LegendBorderProperty.Changed.AddClassHandler(AppearanceChanged); - LegendBorderThicknessProperty.Changed.AddClassHandler(AppearanceChanged); - LegendFontProperty.Changed.AddClassHandler(AppearanceChanged); - LegendFontSizeProperty.Changed.AddClassHandler(AppearanceChanged); - LegendFontWeightProperty.Changed.AddClassHandler(AppearanceChanged); - LegendItemAlignmentProperty.Changed.AddClassHandler(AppearanceChanged); - LegendItemOrderProperty.Changed.AddClassHandler(AppearanceChanged); - LegendItemSpacingProperty.Changed.AddClassHandler(AppearanceChanged); - LegendLineSpacingProperty.Changed.AddClassHandler(AppearanceChanged); - LegendMarginProperty.Changed.AddClassHandler(AppearanceChanged); - LegendMaxHeightProperty.Changed.AddClassHandler(AppearanceChanged); - LegendMaxWidthProperty.Changed.AddClassHandler(AppearanceChanged); - LegendOrientationProperty.Changed.AddClassHandler(AppearanceChanged); - LegendColumnSpacingProperty.Changed.AddClassHandler(AppearanceChanged); - LegendPaddingProperty.Changed.AddClassHandler(AppearanceChanged); - LegendPlacementProperty.Changed.AddClassHandler(AppearanceChanged); - LegendPositionProperty.Changed.AddClassHandler(AppearanceChanged); - LegendSymbolLengthProperty.Changed.AddClassHandler(AppearanceChanged); - LegendSymbolMarginProperty.Changed.AddClassHandler(AppearanceChanged); - LegendSymbolPlacementProperty.Changed.AddClassHandler(AppearanceChanged); SelectionColorProperty.Changed.AddClassHandler(AppearanceChanged); RenderingDecoratorProperty.Changed.AddClassHandler(AppearanceChanged); SubtitleFontProperty.Changed.AddClassHandler(AppearanceChanged); @@ -351,12 +195,6 @@ static Plot() DefaultFontSizeProperty.Changed.AddClassHandler(AppearanceChanged); DefaultColorsProperty.Changed.AddClassHandler(AppearanceChanged); AxisTierDistanceProperty.Changed.AddClassHandler(AppearanceChanged); - LegendTextColorProperty.Changed.AddClassHandler(AppearanceChanged); - LegendTitleProperty.Changed.AddClassHandler(AppearanceChanged); - LegendTitleColorProperty.Changed.AddClassHandler(AppearanceChanged); - LegendTitleFontProperty.Changed.AddClassHandler(AppearanceChanged); - LegendTitleFontSizeProperty.Changed.AddClassHandler(AppearanceChanged); - LegendTitleFontWeightProperty.Changed.AddClassHandler(AppearanceChanged); PlotAreaBackgroundProperty.Changed.AddClassHandler(AppearanceChanged); PlotAreaBorderColorProperty.Changed.AddClassHandler(AppearanceChanged); PlotAreaBorderThicknessProperty.Changed.AddClassHandler(AppearanceChanged); @@ -391,6 +229,11 @@ static Plot() /// private readonly ObservableCollection series; + /// + /// The legends. + /// + private readonly ObservableCollection legends; + /// /// Gets the axes. /// @@ -435,364 +278,6 @@ public bool IsLegendVisible } } - /// - /// Gets or sets LegendBackground. - /// - public Color LegendBackground - { - get - { - return GetValue(LegendBackgroundProperty); - } - - set - { - SetValue(LegendBackgroundProperty, value); - } - } - - /// - /// Gets or sets LegendBorder. - /// - public Color LegendBorder - { - get - { - return GetValue(LegendBorderProperty); - } - - set - { - SetValue(LegendBorderProperty, value); - } - } - - /// - /// Gets or sets LegendBorderThickness. - /// - public double LegendBorderThickness - { - get - { - return GetValue(LegendBorderThicknessProperty); - } - - set - { - SetValue(LegendBorderThicknessProperty, value); - } - } - - /// - /// Gets or sets the spacing between columns of legend items (only for vertical orientation). - /// - /// The spacing in device independent units. - public double LegendColumnSpacing - { - get - { - return GetValue(LegendColumnSpacingProperty); - } - - set - { - SetValue(LegendColumnSpacingProperty, value); - } - } - - /// - /// Gets or sets LegendFont. - /// - public string LegendFont - { - get - { - return GetValue(LegendFontProperty); - } - - set - { - SetValue(LegendFontProperty, value); - } - } - - /// - /// Gets or sets LegendFontSize. - /// - public double LegendFontSize - { - get - { - return GetValue(LegendFontSizeProperty); - } - - set - { - SetValue(LegendFontSizeProperty, value); - } - } - - /// - /// Gets or sets LegendFontWeight. - /// - public FontWeight LegendFontWeight - { - get - { - return GetValue(LegendFontWeightProperty); - } - - set - { - SetValue(LegendFontWeightProperty, value); - } - } - - /// - /// Gets or sets LegendItemAlignment. - /// - public global::Avalonia.Layout.HorizontalAlignment LegendItemAlignment - { - get - { - return GetValue(LegendItemAlignmentProperty); - } - - set - { - SetValue(LegendItemAlignmentProperty, value); - } - } - - /// - /// Gets or sets LegendItemOrder. - /// - public LegendItemOrder LegendItemOrder - { - get - { - return GetValue(LegendItemOrderProperty); - } - - set - { - SetValue(LegendItemOrderProperty, value); - } - } - - /// - /// Gets or sets the horizontal spacing between legend items when the orientation is horizontal. - /// - /// The horizontal distance between items in device independent units. - public double LegendItemSpacing - { - get - { - return GetValue(LegendItemSpacingProperty); - } - - set - { - SetValue(LegendItemSpacingProperty, value); - } - } - - /// - /// Gets or sets the vertical spacing between legend items. - /// - /// The spacing in device independent units. - public double LegendLineSpacing - { - get - { - return GetValue(LegendLineSpacingProperty); - } - - set - { - SetValue(LegendLineSpacingProperty, value); - } - } - - /// - /// Gets or sets the max height of the legend. - /// - /// The max width of the legends. - public double LegendMaxHeight - { - get - { - return GetValue(LegendMaxHeightProperty); - } - - set - { - SetValue(LegendMaxHeightProperty, value); - } - } - - /// - /// Gets or sets the max width of the legend. - /// - /// The max width of the legends. - public double LegendMaxWidth - { - get - { - return GetValue(LegendMaxWidthProperty); - } - - set - { - SetValue(LegendMaxWidthProperty, value); - } - } - - /// - /// Gets or sets LegendMargin. - /// - public double LegendMargin - { - get - { - return GetValue(LegendMarginProperty); - } - - set - { - SetValue(LegendMarginProperty, value); - } - } - - /// - /// Gets or sets LegendOrientation. - /// - public LegendOrientation LegendOrientation - { - get - { - return GetValue(LegendOrientationProperty); - } - - set - { - SetValue(LegendOrientationProperty, value); - } - } - - /// - /// Gets or sets the legend padding. - /// - public double LegendPadding - { - get - { - return GetValue(LegendPaddingProperty); - } - - set - { - SetValue(LegendPaddingProperty, value); - } - } - - /// - /// Gets or sets LegendPlacement. - /// - public LegendPlacement LegendPlacement - { - get - { - return GetValue(LegendPlacementProperty); - } - - set - { - SetValue(LegendPlacementProperty, value); - } - } - - /// - /// Gets or sets the legend position. - /// - /// The legend position. - public LegendPosition LegendPosition - { - get - { - return GetValue(LegendPositionProperty); - } - - set - { - SetValue(LegendPositionProperty, value); - } - } - - /// - /// Gets or sets LegendSymbolLength. - /// - public double LegendSymbolLength - { - get - { - return GetValue(LegendSymbolLengthProperty); - } - - set - { - SetValue(LegendSymbolLengthProperty, value); - } - } - - /// - /// Gets or sets LegendSymbolMargin. - /// - public double LegendSymbolMargin - { - get - { - return GetValue(LegendSymbolMarginProperty); - } - - set - { - SetValue(LegendSymbolMarginProperty, value); - } - } - - /// - /// Gets or sets LegendSymbolPlacement. - /// - public LegendSymbolPlacement LegendSymbolPlacement - { - get - { - return GetValue(LegendSymbolPlacementProperty); - } - - set - { - SetValue(LegendSymbolPlacementProperty, value); - } - } - - /// - /// Gets or sets LegendTitleFont. - /// - public string LegendTitleFont - { - get - { - return GetValue(LegendTitleFontProperty); - } - - set - { - SetValue(LegendTitleFontProperty, value); - } - } - /// /// Gets or sets the default font. /// @@ -841,54 +326,6 @@ public IList DefaultColors } } - /// - /// Gets or sets the text color of the legends. - /// - public Color LegendTextColor - { - get - { - return GetValue(LegendTextColorProperty); - } - - set - { - SetValue(LegendTextColorProperty, value); - } - } - - /// - /// Gets or sets the legend title. - /// - public string LegendTitle - { - get - { - return GetValue(LegendTitleProperty); - } - - set - { - SetValue(LegendTitleProperty, value); - } - } - - /// - /// Gets or sets color of the legend title. - /// - public Color LegendTitleColor - { - get - { - return GetValue(LegendTitleColorProperty); - } - - set - { - SetValue(LegendTitleColorProperty, value); - } - } - /// /// Gets or sets the axis tier distance. /// @@ -901,7 +338,7 @@ public double AxisTierDistance set { - SetValue(LegendTitleFontProperty, value); + SetValue(AxisTierDistanceProperty, value); } } @@ -917,7 +354,7 @@ public Color SelectionColor set { - SetValue(LegendTitleFontProperty, value); + SetValue(SelectionColorProperty, value); } } @@ -969,22 +406,6 @@ public Color TitleColor } } - /// - /// Gets or sets the font size of the legend titles. - /// - public double LegendTitleFontSize - { - get - { - return GetValue(LegendTitleFontSizeProperty); - } - - set - { - SetValue(LegendTitleFontSizeProperty, value); - } - } - /// /// Gets or sets the color of the subtitles. /// @@ -1001,22 +422,6 @@ public Color SubtitleColor } } - /// - /// Gets or sets the font weight of the legend titles. - /// - public FontWeight LegendTitleFontWeight - { - get - { - return GetValue(LegendTitleFontWeightProperty); - } - - set - { - SetValue(LegendTitleFontWeightProperty, value); - } - } - /// /// Gets or sets the background brush of the Plot area. /// @@ -1114,6 +519,18 @@ public Collection Series } } + /// + /// Gets the legends. + /// + /// The legends. + public Collection Legends + { + get + { + return legends; + } + } + /// /// Gets or sets the subtitle. /// diff --git a/Source/OxyPlot.Avalonia/Plot.cs b/Source/OxyPlot.Avalonia/Plot.cs index 28ba47e..bc727fb 100644 --- a/Source/OxyPlot.Avalonia/Plot.cs +++ b/Source/OxyPlot.Avalonia/Plot.cs @@ -40,10 +40,12 @@ public Plot() series = new ObservableCollection(); axes = new ObservableCollection(); annotations = new ObservableCollection(); + legends = new ObservableCollection(); series.CollectionChanged += OnSeriesChanged; axes.CollectionChanged += OnAxesChanged; annotations.CollectionChanged += OnAnnotationsChanged; + legends.CollectionChanged += this.OnAnnotationsChanged; defaultController = new PlotController(); internalModel = new PlotModel(); @@ -96,6 +98,7 @@ protected override void UpdateModel(bool updateData = true) SynchronizeSeries(); SynchronizeAxes(); SynchronizeAnnotations(); + SynchronizeLegends(); base.UpdateModel(updateData); } @@ -220,35 +223,6 @@ private void SynchronizeProperties() m.AxisTierDistance = AxisTierDistance; m.IsLegendVisible = IsLegendVisible; - m.LegendTextColor = LegendTextColor.ToOxyColor(); - m.LegendTitle = LegendTitle; - m.LegendTitleColor = LegendTitleColor.ToOxyColor(); - m.LegendTitleFont = LegendTitleFont; - m.LegendTitleFontSize = LegendTitleFontSize; - m.LegendTitleFontWeight = (int)LegendTitleFontWeight; - m.LegendFont = LegendFont; - m.LegendFontSize = LegendFontSize; - m.LegendFontWeight = (int)LegendFontWeight; - m.LegendSymbolLength = LegendSymbolLength; - m.LegendSymbolMargin = LegendSymbolMargin; - m.LegendPadding = LegendPadding; - m.LegendColumnSpacing = LegendColumnSpacing; - m.LegendItemSpacing = LegendItemSpacing; - m.LegendLineSpacing = LegendLineSpacing; - m.LegendMargin = LegendMargin; - m.LegendMaxHeight = LegendMaxHeight; - m.LegendMaxWidth = LegendMaxWidth; - - m.LegendBackground = LegendBackground.ToOxyColor(); - m.LegendBorder = LegendBorder.ToOxyColor(); - m.LegendBorderThickness = LegendBorderThickness; - - m.LegendPlacement = LegendPlacement; - m.LegendPosition = LegendPosition; - m.LegendOrientation = LegendOrientation; - m.LegendItemOrder = LegendItemOrder; - m.LegendItemAlignment = LegendItemAlignment.ToHorizontalAlignment(); - m.LegendSymbolPlacement = LegendSymbolPlacement; m.PlotAreaBackground = PlotAreaBackground.ToOxyColor(); m.PlotAreaBorderColor = PlotAreaBorderColor.ToOxyColor(); @@ -290,5 +264,17 @@ private void SynchronizeSeries() internalModel.Series.Add(s.CreateModel()); } } + + /// + /// Synchronizes the legends in the internal model. + /// + private void SynchronizeLegends() + { + internalModel.Legends.Clear(); + foreach (var l in Legends) + { + internalModel.Legends.Add(l.CreateModel()); + } + } } } diff --git a/Source/OxyPlot.Avalonia/Series/Series.cs b/Source/OxyPlot.Avalonia/Series/Series.cs index 9cea9cf..1c7cf11 100644 --- a/Source/OxyPlot.Avalonia/Series/Series.cs +++ b/Source/OxyPlot.Avalonia/Series/Series.cs @@ -47,6 +47,11 @@ public abstract class Series : ItemsControl /// public static readonly StyledProperty TrackerKeyProperty = AvaloniaProperty.Register(nameof(TrackerKey), null); + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty EdgeRenderingModeProperty = AvaloniaProperty.Register(nameof(EdgeRenderingMode), EdgeRenderingMode.Automatic); + /// /// The event listener used to subscribe to ItemSource.CollectionChanged events /// @@ -64,6 +69,7 @@ static Series() RenderInLegendProperty.Changed.AddClassHandler(AppearanceChanged); TrackerFormatStringProperty.Changed.AddClassHandler(AppearanceChanged); TrackerKeyProperty.Changed.AddClassHandler(AppearanceChanged); + EdgeRenderingModeProperty.Changed.AddClassHandler(AppearanceChanged); } /// @@ -159,6 +165,22 @@ public string TrackerKey } } + /// + /// Gets or sets the for the series. + /// + public EdgeRenderingMode EdgeRenderingMode + { + get + { + return GetValue(EdgeRenderingModeProperty); + } + + set + { + SetValue(EdgeRenderingModeProperty, value); + } + } + /// /// Creates the model. /// @@ -243,6 +265,7 @@ protected virtual void SynchronizeProperties(OxyPlot.Series.Series s) s.IsVisible = IsVisible; s.Font = FontFamily.ToString(); s.TextColor = Foreground.ToOxyColor(); + s.EdgeRenderingMode = EdgeRenderingMode; } /// From f1bb63a4dfda71993a65c620cc269cf68a40d444 Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Tue, 5 Oct 2021 20:25:15 +0100 Subject: [PATCH 02/20] Update most stuff to 2.1.0 --- .../Examples/BarSeriesDemo/MainWindow.xaml | 5 +- .../Examples/BarSeriesDemo/MainWindow.xaml.cs | 4 +- .../BoxPlotSeriesDemo/MainWindow.xaml | 8 +- .../BoxPlotSeriesDemo/MainWindow.xaml.cs | 4 +- .../Examples/ColumnSeriesDemo/MainWindow.xaml | 25 --- .../ColumnSeriesDemo/MainWindow.xaml.cs | 67 ------- .../Examples/LegendsDemo/MainViewModel.cs | 7 + .../Annotations/PathAnnotation.cs | 23 --- Source/OxyPlot.Avalonia/Axes/Axis.cs | 92 +++++++++ .../OxyPlot.Avalonia/CanvasRenderContext.cs | 176 ++++++++---------- Source/OxyPlot.Avalonia/PlotBase.cs | 4 +- Source/OxyPlot.Avalonia/PngExporter.cs | 2 +- .../Series/BarSeries/BarSeriesBase.cs | 4 +- .../Series/BarSeries/ColumnSeries.cs | 67 ------- 14 files changed, 199 insertions(+), 289 deletions(-) delete mode 100644 Source/Examples/Avalonia/AvaloniaExamples/Examples/ColumnSeriesDemo/MainWindow.xaml delete mode 100644 Source/Examples/Avalonia/AvaloniaExamples/Examples/ColumnSeriesDemo/MainWindow.xaml.cs delete mode 100644 Source/OxyPlot.Avalonia/Series/BarSeries/ColumnSeries.cs diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml index 6b50d2b..d310fd4 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml @@ -9,7 +9,10 @@ - + + + + diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs index 768cef1..f977141 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs @@ -17,6 +17,7 @@ namespace AvaloniaExamples.Examples.BarSeriesDemo using OxyPlot.Series; using AvaloniaExamples; + using OxyPlot.Legends; /// /// Interaction logic for MainWindow.xaml @@ -37,7 +38,8 @@ public MainWindow() }; // Create the plot model - var tmp = new PlotModel { Title = "Bar series", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical }; + var tmp = new PlotModel { Title = "Bar series" }; + tmp.Legends.Add(new Legend { LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical }); // Add the axes, note that MinimumPadding and AbsoluteMinimum should be set on the value axis. tmp.Axes.Add(new CategoryAxis { Position = AxisPosition.Left, ItemsSource = items, LabelField = "Label" }); diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BoxPlotSeriesDemo/MainWindow.xaml b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BoxPlotSeriesDemo/MainWindow.xaml index 05f5ba6..0535f82 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BoxPlotSeriesDemo/MainWindow.xaml +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BoxPlotSeriesDemo/MainWindow.xaml @@ -11,10 +11,10 @@ - + + + + /// Interaction logic for MainWindow.xaml @@ -43,7 +44,8 @@ public MainWindow() }; // Create the plot model - var tmp = new PlotModel { Title = "BoxPlot series", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical }; + var tmp = new PlotModel { Title = "BoxPlot series" }; + tmp.Legends.Add(new Legend { LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical }); // Add the axes, note that MinimumPadding and AbsoluteMinimum should be set on the value axis. tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0.3, MaximumPadding = 0.3, AbsoluteMinimum = 0 }); diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/ColumnSeriesDemo/MainWindow.xaml b/Source/Examples/Avalonia/AvaloniaExamples/Examples/ColumnSeriesDemo/MainWindow.xaml deleted file mode 100644 index 947ba8b..0000000 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/ColumnSeriesDemo/MainWindow.xaml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/ColumnSeriesDemo/MainWindow.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/ColumnSeriesDemo/MainWindow.xaml.cs deleted file mode 100644 index 0cae0c2..0000000 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/ColumnSeriesDemo/MainWindow.xaml.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2014 OxyPlot contributors -// -// -// Interaction logic for MainWindow.xaml -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace AvaloniaExamples.Examples.ColumnSeriesDemo -{ - using System.Collections.ObjectModel; - using System.Windows; - - using OxyPlot; - using OxyPlot.Axes; - using OxyPlot.Series; - - using AvaloniaExamples; - - /// - /// Interaction logic for MainWindow.xaml - /// - [Example("Shows column series.")] - public partial class MainWindow : Avalonia.Controls.Window - { - public MainWindow() - { - this.InitializeComponent(); - - // Create some data - var items = new Collection - { - new Item {Label = "Apples", Value1 = 37, Value2 = 12, Value3 = 19}, - new Item {Label = "Pears", Value1 = 7, Value2 = 21, Value3 = 9}, - new Item {Label = "Bananas", Value1 = 23, Value2 = 2, Value3 = 29} - }; - - // Create the plot model - var tmp = new PlotModel { Title = "Column series", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical }; - - // Add the axes, note that MinimumPadding and AbsoluteMinimum should be set on the value axis. - tmp.Axes.Add(new CategoryAxis { ItemsSource = items, LabelField = "Label" }); - tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, AbsoluteMinimum = 0 }); - - // Add the series, note that the BarSeries are using the same ItemsSource as the CategoryAxis. - tmp.Series.Add(new ColumnSeries { Title = "2009", ItemsSource = items, ValueField = "Value1" }); - tmp.Series.Add(new ColumnSeries { Title = "2010", ItemsSource = items, ValueField = "Value2" }); - tmp.Series.Add(new ColumnSeries { Title = "2011", ItemsSource = items, ValueField = "Value3" }); - - this.DataContext = new { Model1 = tmp, Items = items }; - } - - private void InitializeComponent() - { - Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(this); - } - } - - public class Item : ColumnItem - { - public string Label { get; set; } - public double Value1 { get; set; } - public double Value2 { get; set; } - public double Value3 { get; set; } - } -} \ No newline at end of file diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/LegendsDemo/MainViewModel.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/LegendsDemo/MainViewModel.cs index b4890ce..3bf5caa 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/LegendsDemo/MainViewModel.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/LegendsDemo/MainViewModel.cs @@ -16,6 +16,7 @@ namespace AvaloniaExamples.Examples.LegendsDemo using AvaloniaExamples; using HorizontalAlignment = OxyPlot.HorizontalAlignment; + using OxyPlot.Legends; public class MainViewModel : NotifyPropertyChangedBase { @@ -158,6 +159,10 @@ private PlotModel CreateModel(int n) var newModel = new PlotModel { Title = "LineSeries", + }; + + var legend = new Legend() + { LegendBorder = OxyColors.Black, LegendBackground = OxyColor.FromAColor(200, OxyColors.White), LegendPosition = this.LegendPosition, @@ -170,6 +175,8 @@ private PlotModel CreateModel(int n) LegendMaxHeight = this.LegendMaxHeight }; + newModel.Legends.Add(legend); + for (int i = 1; i <= n; i++) { var s = new LineSeries { Title = "Series " + i }; diff --git a/Source/OxyPlot.Avalonia/Annotations/PathAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/PathAnnotation.cs index de145be..6d77966 100644 --- a/Source/OxyPlot.Avalonia/Annotations/PathAnnotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/PathAnnotation.cs @@ -35,11 +35,6 @@ public abstract class PathAnnotation : TextualAnnotation /// public static readonly StyledProperty ClipByYAxisProperty = AvaloniaProperty.Register(nameof(ClipByYAxis), true); - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty ClipTextProperty = AvaloniaProperty.Register(nameof(ClipText), true); - /// /// Identifies the dependency property. /// @@ -104,23 +99,6 @@ public bool ClipByYAxis } } - /// - /// Gets or sets a value indicating whether the text should be clipped within the plot area. - /// - /// true if text should be clipped; otherwise, false. - public bool ClipText - { - get - { - return GetValue(ClipTextProperty); - } - - set - { - SetValue(ClipTextProperty, value); - } - } - /// /// Gets or sets the annotation color. /// @@ -271,7 +249,6 @@ public override void SynchronizeProperties() a.TextLinePosition = TextLinePosition; a.TextOrientation = TextOrientation; a.TextMargin = TextMargin; - a.ClipText = ClipText; } static PathAnnotation() diff --git a/Source/OxyPlot.Avalonia/Axes/Axis.cs b/Source/OxyPlot.Avalonia/Axes/Axis.cs index 7815e01..73d2658 100644 --- a/Source/OxyPlot.Avalonia/Axes/Axis.cs +++ b/Source/OxyPlot.Avalonia/Axes/Axis.cs @@ -190,6 +190,16 @@ public abstract class Axis : Control /// public static readonly StyledProperty MaximumPaddingProperty = AvaloniaProperty.Register(nameof(MaximumPadding), 0.01); + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty MaximumMarginProperty = AvaloniaProperty.Register(nameof(MaximumMargin), 0.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty MaximumDataMarginProperty = AvaloniaProperty.Register(nameof(MaximumDataMargin), 0.0); + /// /// Identifies the dependency property. /// @@ -205,6 +215,16 @@ public abstract class Axis : Control /// public static readonly StyledProperty MinimumPaddingProperty = AvaloniaProperty.Register(nameof(MinimumPadding), 0.01); + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty MinimumMarginProperty = AvaloniaProperty.Register(nameof(MinimumMargin), 0.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty MinimumDataMarginProperty = AvaloniaProperty.Register(nameof(MinimumDataMargin), 0.0); + /// /// Identifies the dependency property. /// @@ -905,6 +925,38 @@ public double MaximumPadding } } + /// + /// Gets or sets Margin. + /// + public double MaximumMargin + { + get + { + return GetValue(MaximumMarginProperty); + } + + set + { + SetValue(MaximumMarginProperty, value); + } + } + + /// + /// Gets or sets DataMargin. + /// + public double MaximumDataMargin + { + get + { + return GetValue(MaximumDataMarginProperty); + } + + set + { + SetValue(MaximumDataMarginProperty, value); + } + } + /// /// Gets or sets MaximumRange. /// @@ -953,6 +1005,38 @@ public double MinimumPadding } } + /// + /// Gets or sets Margin. + /// + public double MinimumMargin + { + get + { + return GetValue(MinimumMarginProperty); + } + + set + { + SetValue(MinimumMarginProperty, value); + } + } + + /// + /// Gets or sets DataMargin. + /// + public double MinimumDataMargin + { + get + { + return GetValue(MinimumDataMarginProperty); + } + + set + { + SetValue(MinimumDataMarginProperty, value); + } + } + /// /// Gets or sets MinimumRange. /// @@ -1475,6 +1559,10 @@ protected virtual void SynchronizeProperties() a.MaximumRange = MaximumRange; a.MinimumPadding = MinimumPadding; a.MaximumPadding = MaximumPadding; + a.MinimumMargin = MinimumMargin; + a.MaximumMargin = MinimumMargin; + a.MinimumDataMargin = MinimumDataMargin; + a.MaximumDataMargin = MaximumDataMargin; a.Position = Position; a.PositionTier = PositionTier; a.PositionAtZeroCrossing = PositionAtZeroCrossing; @@ -1532,9 +1620,13 @@ static Axis() MajorStepProperty.Changed.AddClassHandler(AppearanceChanged); MajorTickSizeProperty.Changed.AddClassHandler(AppearanceChanged); MaximumPaddingProperty.Changed.AddClassHandler(AppearanceChanged); + MaximumMarginProperty.Changed.AddClassHandler(AppearanceChanged); + MaximumDataMarginProperty.Changed.AddClassHandler(AppearanceChanged); MaximumProperty.Changed.AddClassHandler(AppearanceChanged); MaximumRangeProperty.Changed.AddClassHandler(AppearanceChanged); MinimumPaddingProperty.Changed.AddClassHandler(AppearanceChanged); + MinimumMarginProperty.Changed.AddClassHandler(AppearanceChanged); + MinimumDataMarginProperty.Changed.AddClassHandler(AppearanceChanged); MinimumProperty.Changed.AddClassHandler(AppearanceChanged); MinimumRangeProperty.Changed.AddClassHandler(AppearanceChanged); MinorGridlineColorProperty.Changed.AddClassHandler(AppearanceChanged); diff --git a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs index 6f1e442..924289e 100644 --- a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs +++ b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs @@ -26,7 +26,7 @@ namespace OxyPlot.Avalonia /// /// Implements for . /// - public class CanvasRenderContext : IRenderContext + public class CanvasRenderContext : ClippingRenderContext { /// /// The maximum number of figures per geometry. @@ -97,23 +97,15 @@ public CanvasRenderContext(Canvas canvas) /// The XamlWriter does not serialize StreamGeometry, so set this to false if you want to export to XAML. Using stream geometry seems to be slightly faster than using path geometry. public bool UseStreamGeometry { get; set; } - /// - /// Gets or sets a value indicating whether the context renders to screen. - /// - /// true if the context renders to screen; otherwise, false. - public bool RendersToScreen { get; set; } - - /// - /// Draws an ellipse. - /// - /// The rectangle. - /// The fill color. If set to OxyColors.Undefined, the ellipse will not be filled. - /// The stroke color. If set to OxyColors.Undefined, the ellipse will not be stroked. - /// The thickness (in device independent units, 1/96 inch). - public void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness) + /// + public void DrawEllipse(OxyRect rect, + OxyColor fill, + OxyColor stroke, + double thickness, + EdgeRenderingMode edgeRenderingMode) { var e = CreateAndAdd(rect.Left, rect.Top); - SetStroke(e, stroke, thickness); + SetStroke(e, stroke, thickness, edgeRenderingMode); if (fill.IsVisible()) { e.Fill = GetCachedBrush(fill); @@ -125,48 +117,38 @@ public void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thi Canvas.SetTop(e, rect.Top); } - /// - /// Draws a collection of ellipses, where all have the same stroke and fill. - /// This performs better than calling DrawEllipse multiple times. - /// - /// The rectangles. - /// The fill color. If set to OxyColors.Undefined, the ellipses will not be filled. - /// The stroke color. If set to OxyColors.Undefined, the ellipses will not be stroked. - /// The stroke thickness (in device independent units, 1/96 inch). - public void DrawEllipses(IList rectangles, OxyColor fill, OxyColor stroke, double thickness) + /// + public void DrawEllipses(IList rectangles, + OxyColor fill, + OxyColor stroke, + double thickness, + EdgeRenderingMode edgeRenderingMode) { foreach (var rect in rectangles) { - DrawEllipse(rect, fill, stroke, thickness); + DrawEllipse(rect, fill, stroke, thickness, edgeRenderingMode); } } - /// - /// Draws a polyline. - /// - /// The points. - /// The stroke color. - /// The stroke thickness (in device independent units, 1/96 inch). - /// The dash array (in device independent units, 1/96 inch). Use null to get a solid line. - /// The line join type. - /// if set to true the shape will be aliased. - public void DrawLine( + /// + public override void DrawLine( IList points, OxyColor stroke, double thickness, + EdgeRenderingMode edgeRenderingMode, double[] dashArray, - LineJoin lineJoin, - bool aliased) + LineJoin lineJoin) { if (thickness < BalancedLineDrawingThicknessLimit) { - DrawLineBalanced(points, stroke, thickness, dashArray, lineJoin, aliased); + DrawLineBalanced(points, stroke, thickness, edgeRenderingMode, dashArray, lineJoin); return; } var e = CreateAndAdd(); - SetStroke(e, stroke, thickness, lineJoin, dashArray, 0, aliased); + SetStroke(e, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); + bool aliased = ShouldUseAntiAliasingForLine(edgeRenderingMode, points); e.Points = ToPointCollection(points, aliased); } @@ -179,21 +161,23 @@ public void DrawLine( /// The stroke thickness (in device independent units, 1/96 inch). /// The dash array (in device independent units, 1/96 inch). /// The line join type. - /// if set to true the shape will be aliased. + /// The edge rendering mode. public void DrawLineSegments( IList points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, - bool aliased) + EdgeRenderingMode edgeRenderingMode) { if (UseStreamGeometry) { - DrawLineSegmentsByStreamGeometry(points, stroke, thickness, dashArray, lineJoin, aliased); + DrawLineSegmentsByStreamGeometry(points, stroke, thickness, edgeRenderingMode, dashArray, lineJoin); return; } + bool aliased = edgeRenderingMode == EdgeRenderingMode.PreferSpeed; + Path path = null; PathGeometry pathGeometry = null; @@ -204,7 +188,7 @@ public void DrawLineSegments( if (path == null) { path = CreateAndAdd(); - SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased); + SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); pathGeometry = new PathGeometry(); } @@ -229,55 +213,37 @@ public void DrawLineSegments( } } - /// - /// Draws a polygon. - /// - /// The points. - /// The fill color. If set to OxyColors.Undefined, the polygon will not be filled. - /// The stroke color. If set to OxyColors.Undefined, the polygon will not be stroked. - /// The stroke thickness (in device independent units, 1/96 inch). - /// The dash array (in device independent units, 1/96 inch). - /// The line join type. - /// If set to true the polygon will be aliased. - public void DrawPolygon( + /// + public override void DrawPolygon( IList points, OxyColor fill, OxyColor stroke, double thickness, + EdgeRenderingMode edgeRenderingMode, double[] dashArray, - LineJoin lineJoin, - bool aliased) + LineJoin lineJoin) { var e = CreateAndAdd(); - SetStroke(e, stroke, thickness, lineJoin, dashArray, 0, aliased); + SetStroke(e, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); if (!fill.IsUndefined()) { e.Fill = GetCachedBrush(fill); } + bool aliased = edgeRenderingMode == EdgeRenderingMode.PreferSpeed; e.Points = ToPointCollection(points, aliased); } - /// - /// Draws a collection of polygons, where all polygons have the same stroke and fill. - /// This performs better than calling DrawPolygon multiple times. - /// - /// The polygons. - /// The fill color. If set to OxyColors.Undefined, the polygons will not be filled. - /// The stroke color. If set to OxyColors.Undefined, the polygons will not be stroked. - /// The stroke thickness (in device independent units, 1/96 inch). - /// The dash array (in device independent units, 1/96 inch). - /// The line join type. - /// if set to true the shape will be aliased. - public void DrawPolygons( + /// + public override void DrawPolygons( IList> polygons, OxyColor fill, OxyColor stroke, double thickness, + EdgeRenderingMode edgeRenderingMode, double[] dashArray, - LineJoin lineJoin, - bool aliased) + LineJoin lineJoin) { var usg = UseStreamGeometry; Path path = null; @@ -291,7 +257,7 @@ public void DrawPolygons( if (path == null) { path = CreateAndAdd(); - SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased); + SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); if (!fill.IsUndefined()) { path.Fill = GetCachedBrush(fill); @@ -309,6 +275,8 @@ public void DrawPolygons( } } + bool aliased = edgeRenderingMode == EdgeRenderingMode.PreferSpeed; + PathFigure figure = null; var first = true; foreach (var p in polygon) @@ -387,10 +355,14 @@ public void DrawPolygons( /// The fill color. If set to OxyColors.Undefined, the rectangle will not be filled. /// The stroke color. If set to OxyColors.Undefined, the rectangle will not be stroked. /// The stroke thickness (in device independent units, 1/96 inch). - public void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness) + public override void DrawRectangle(OxyRect rect, + OxyColor fill, + OxyColor stroke, + double thickness, + EdgeRenderingMode edgeRenderingMode) { var e = CreateAndAdd(rect.Left, rect.Top); - SetStroke(e, stroke, thickness, LineJoin.Miter, null, 0, true); + SetStroke(e, stroke, thickness, edgeRenderingMode, LineJoin.Miter, null, 0); if (!fill.IsUndefined()) { @@ -411,11 +383,15 @@ public void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double t /// The fill color. If set to OxyColors.Undefined, the rectangles will not be filled. /// The stroke color. If set to OxyColors.Undefined, the rectangles will not be stroked. /// The stroke thickness (in device independent units, 1/96 inch). - public void DrawRectangles(IList rectangles, OxyColor fill, OxyColor stroke, double thickness) + public override void DrawRectangles(IList rectangles, + OxyColor fill, + OxyColor stroke, + double thickness, + EdgeRenderingMode edgeRenderingMode) { foreach (var rect in rectangles) { - DrawRectangle(rect, fill, stroke, thickness); + DrawRectangle(rect, fill, stroke, thickness, edgeRenderingMode); } } @@ -432,7 +408,7 @@ public void DrawRectangles(IList rectangles, OxyColor fill, OxyColor st /// The horizontal alignment. /// The vertical alignment. /// The maximum size of the text (in device independent units, 1/96 inch). - public void DrawText( + public override void DrawText( ScreenPoint p, string text, OxyColor fill, @@ -532,7 +508,10 @@ public void DrawText( /// /// The size of the text (in device independent units, 1/96 inch). /// - public OxySize MeasureText(string text, string fontFamily, double fontSize, double fontWeight) + public override OxySize MeasureText(string text, + string fontFamily, + double fontSize, + double fontWeight) { if (string.IsNullOrEmpty(text)) { @@ -643,16 +622,15 @@ public void DrawImage( /// /// The clipping rectangle. /// true if the clip rectangle was set. - public bool SetClip(OxyRect clippingRect) + protected override void SetClip(OxyRect clippingRect) { clip = ToRect(clippingRect); - return true; } /// /// Resets the clip rectangle. /// - public void ResetClip() + protected override void ResetClip() { clip = null; } @@ -661,7 +639,7 @@ public void ResetClip() /// Cleans up resources not in use. /// /// This method is called at the end of each rendering. - public void CleanUp() + public override void CleanUp() { // Find the images in the cache that has not been used since last call to this method var imagesToRelease = imageCache.Keys.Where(i => !imagesInUse.Contains(i)).ToList(); @@ -731,17 +709,19 @@ private void ApplyToolTip(global::Avalonia.Controls.Control element) /// The points. /// The stroke color. /// The thickness. + /// The edge rendering mode. /// The dash array. Use null to get a solid line. /// The line join. - /// Draw aliased line if set to true . private void DrawLineSegmentsByStreamGeometry( IList points, OxyColor stroke, double thickness, + EdgeRenderingMode edgeRenderingMode, double[] dashArray, - LineJoin lineJoin, - bool aliased) + LineJoin lineJoin) { + bool aliased = edgeRenderingMode == EdgeRenderingMode.PreferSpeed; + StreamGeometry streamGeometry = null; StreamGeometryContext streamGeometryContext = null; @@ -765,7 +745,7 @@ private void DrawLineSegmentsByStreamGeometry( { streamGeometryContext.Dispose(); var path = CreateAndAdd(); - SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased); + SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); path.Data = streamGeometry; streamGeometry = null; count = 0; @@ -776,7 +756,7 @@ private void DrawLineSegmentsByStreamGeometry( { streamGeometryContext.Dispose(); var path = CreateAndAdd(); - SetStroke(path, stroke, thickness, lineJoin, null, 0, aliased); + SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, null, 0); path.Data = streamGeometry; } } @@ -809,18 +789,18 @@ private IBrush GetCachedBrush(OxyColor color) /// The shape. /// The stroke color. /// The thickness. + /// The edge rendering mode. /// The line join. /// The dash array. Use null to get a solid line. /// The dash offset. - /// The aliased. private void SetStroke( Shape shape, OxyColor stroke, double thickness, + EdgeRenderingMode edgeRenderingMode, LineJoin lineJoin = LineJoin.Miter, IEnumerable dashArray = null, - double dashOffset = 0, - bool aliased = false) + double dashOffset = 0) { if (!stroke.IsUndefined() && thickness > 0) { @@ -849,6 +829,11 @@ private void SetStroke( shape.StrokeDashOffset = dashOffset; } } + + if (edgeRenderingMode == EdgeRenderingMode.PreferSpeed) + { + // TODO: use alised lines + } } /// @@ -888,17 +873,17 @@ private IBitmap GetImageSource(OxyImage image) /// The points. /// The stroke color. /// The thickness. + /// The edge rendering mode. /// The dash array. Use null to get a solid line. /// The line join. - /// Render aliased if set to true. /// See discussion. - private void DrawLineBalanced(IList points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) + private void DrawLineBalanced(IList points, OxyColor stroke, double thickness, EdgeRenderingMode edgeRenderingMode, double[] dashArray, LineJoin lineJoin) { // balance the number of points per polyline and the number of polylines var numPointsPerPolyline = Math.Max(points.Count / MaxPolylinesPerLine, MinPointsPerPolyline); var polyline = CreateAndAdd(); - SetStroke(polyline, stroke, thickness, lineJoin, dashArray, 0, aliased); + SetStroke(polyline, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); var pc = new List(numPointsPerPolyline); var n = points.Count; @@ -907,6 +892,7 @@ private void DrawLineBalanced(IList points, OxyColor stroke, double var last = new Point(); for (int i = 0; i < n; i++) { + bool aliased = !this.ShouldUseAntiAliasingForLine(edgeRenderingMode, points); var p = aliased ? ToPixelAlignedPoint(points[i]) : ToPoint(points[i]); pc.Add(p); @@ -939,7 +925,7 @@ private void DrawLineBalanced(IList points, OxyColor stroke, double // start a new polyline at last point so there is no gap (it is not necessary to use the % operator) var dashOffset = dashPatternLength > 0 ? lineLength / thickness : 0; polyline = CreateAndAdd(); - SetStroke(polyline, stroke, thickness, lineJoin, dashArray, dashOffset, aliased); + SetStroke(polyline, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, dashOffset); pc = new List(numPointsPerPolyline) { pc.Last() }; } } diff --git a/Source/OxyPlot.Avalonia/PlotBase.cs b/Source/OxyPlot.Avalonia/PlotBase.cs index dc407d7..043904f 100644 --- a/Source/OxyPlot.Avalonia/PlotBase.cs +++ b/Source/OxyPlot.Avalonia/PlotBase.cs @@ -504,7 +504,7 @@ private void UpdateVisuals() panel.Children.RemoveAt(idx); } - ((IPlotModel)ActualModel).Render(renderContext, canvas.Bounds.Width, canvas.Bounds.Height); + ((IPlotModel)ActualModel).Render(renderContext, new OxyRect(0, 0, canvas.Bounds.Width, canvas.Bounds.Height)); // reinsert the canvas again if (idx != -1) @@ -514,7 +514,7 @@ private void UpdateVisuals() } else { - ((IPlotModel)ActualModel).Render(renderContext, canvas.Bounds.Width, canvas.Bounds.Height); + ((IPlotModel)ActualModel).Render(renderContext, new OxyRect(0, 0, canvas.Bounds.Width, canvas.Bounds.Height)); } } } diff --git a/Source/OxyPlot.Avalonia/PngExporter.cs b/Source/OxyPlot.Avalonia/PngExporter.cs index 9b9304f..cf3361e 100644 --- a/Source/OxyPlot.Avalonia/PngExporter.cs +++ b/Source/OxyPlot.Avalonia/PngExporter.cs @@ -113,7 +113,7 @@ public IBitmap ExportToBitmap(IPlotModel model) var rc = new CanvasRenderContext(canvas) { RendersToScreen = false }; model.Update(true); - model.Render(rc, canvas.Width, canvas.Height); + model.Render(rc, new OxyRect(0, 0, canvas.Width, canvas.Height)); canvas.Measure(new Size(canvas.Width, canvas.Height)); canvas.Arrange(new Rect(0, 0, canvas.Width, canvas.Height)); diff --git a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs index df0765e..a5b1ba1 100644 --- a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs +++ b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs @@ -85,7 +85,7 @@ public class BarSeriesBase : CategorizedSeries /// static BarSeriesBase() { - TrackerFormatStringProperty.OverrideMetadata(typeof(BarSeriesBase), new StyledPropertyMetadata(OxyPlot.Series.BarSeriesBase.DefaultTrackerFormatString)); + TrackerFormatStringProperty.OverrideMetadata(typeof(BarSeriesBase), new StyledPropertyMetadata(OxyPlot.Series.BarSeries.DefaultTrackerFormatString)); BaseValueProperty.Changed.AddClassHandler(AppearanceChanged); ColorFieldProperty.Changed.AddClassHandler(DataChanged); FillColorProperty.Changed.AddClassHandler(AppearanceChanged); @@ -316,7 +316,7 @@ public override OxyPlot.Series.Series CreateModel() protected override void SynchronizeProperties(OxyPlot.Series.Series series) { base.SynchronizeProperties(series); - var s = (OxyPlot.Series.BarSeriesBase)series; + var s = (OxyPlot.Series.BarSeries)series; s.BaseValue = BaseValue; s.ColorField = ColorField; s.FillColor = FillColor.ToOxyColor(); diff --git a/Source/OxyPlot.Avalonia/Series/BarSeries/ColumnSeries.cs b/Source/OxyPlot.Avalonia/Series/BarSeries/ColumnSeries.cs deleted file mode 100644 index 2b586c6..0000000 --- a/Source/OxyPlot.Avalonia/Series/BarSeries/ColumnSeries.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2014 OxyPlot contributors -// -// -// This is a Avalonia wrapper of OxyPlot.BarSeries -// -// -------------------------------------------------------------------------------------------------------------------- - -using Avalonia; - -namespace OxyPlot.Avalonia -{ - - using OxyPlot.Series; - - /// - /// This is a Avalonia wrapper of OxyPlot.BarSeries - /// - public class ColumnSeries : BarSeriesBase - { - /// - /// Identifies the dependency property. - /// - public static readonly StyledProperty ColumnWidthProperty = AvaloniaProperty.Register(nameof(ColumnWidth), 1.0); - - /// - /// Initializes a new instance of the class. - /// - public ColumnSeries() - { - InternalSeries = new OxyPlot.Series.ColumnSeries(); - } - - /// - /// Gets or sets ColumnWidth. - /// - public double ColumnWidth - { - get - { - return GetValue(ColumnWidthProperty); - } - - set - { - SetValue(ColumnWidthProperty, value); - } - } - - /// - /// Synchronizes the properties. - /// - /// The series. - protected override void SynchronizeProperties(OxyPlot.Series.Series series) - { - base.SynchronizeProperties(series); - var s = (OxyPlot.Series.ColumnSeries)series; - s.ColumnWidth = ColumnWidth; - } - - static ColumnSeries() - { - ColumnWidthProperty.Changed.AddClassHandler(AppearanceChanged); - } - } -} \ No newline at end of file From 49b69e9a9a7e7ccfc02d68fe5b57861919dded22 Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Fri, 15 Oct 2021 16:28:53 +0100 Subject: [PATCH 03/20] Fix --- .../AvaloniaExamples/Examples/AreaDemo/MainWindow.xaml | 3 +++ Source/OxyPlot.Avalonia/CanvasRenderContext.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/AreaDemo/MainWindow.xaml b/Source/Examples/Avalonia/AvaloniaExamples/Examples/AreaDemo/MainWindow.xaml index cf263bc..6b974c6 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/AreaDemo/MainWindow.xaml +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/AreaDemo/MainWindow.xaml @@ -6,6 +6,9 @@ Title="AreaDemo" Height="480" Width="640"> + + + diff --git a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs index 924289e..b821e39 100644 --- a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs +++ b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs @@ -148,7 +148,7 @@ public override void DrawLine( var e = CreateAndAdd(); SetStroke(e, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); - bool aliased = ShouldUseAntiAliasingForLine(edgeRenderingMode, points); + bool aliased = !ShouldUseAntiAliasingForLine(edgeRenderingMode, points); e.Points = ToPointCollection(points, aliased); } From 138f95c6c468e3b97f7cb3adfa4a843b1aee0abc Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Sat, 16 Oct 2021 17:55:45 +0100 Subject: [PATCH 04/20] Bug comments --- Source/OxyPlot.Avalonia/PlotBase.cs | 1 + Source/OxyPlot.Avalonia/Series/ItemsSeries.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/Source/OxyPlot.Avalonia/PlotBase.cs b/Source/OxyPlot.Avalonia/PlotBase.cs index 043904f..3189f86 100644 --- a/Source/OxyPlot.Avalonia/PlotBase.cs +++ b/Source/OxyPlot.Avalonia/PlotBase.cs @@ -241,6 +241,7 @@ public void InvalidatePlot(bool updateData = true) return; } + // TODO: legend on/off crash (issue with Legend hit-test implementation, really) UpdateModel(updateData); if (Interlocked.CompareExchange(ref isPlotInvalidated, 1, 0) == 0) diff --git a/Source/OxyPlot.Avalonia/Series/ItemsSeries.cs b/Source/OxyPlot.Avalonia/Series/ItemsSeries.cs index 19df4a9..7b0220c 100644 --- a/Source/OxyPlot.Avalonia/Series/ItemsSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/ItemsSeries.cs @@ -22,6 +22,7 @@ protected override void SynchronizeProperties(OxyPlot.Series.Series series) { base.SynchronizeProperties(series); var s = (OxyPlot.Series.ItemsSeries)series; + // TODO: BarSeriesManager gets very unhappy when this is not initialised (i.e. empty collection): easier to fix in Core? s.ItemsSource = Items; } } From 9dbe0f42d745b6fa9030745c56cdbb651af4f789 Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Sun, 19 Dec 2021 11:21:17 +0000 Subject: [PATCH 05/20] Add legend code --- .../Examples/BarSeriesDemo/MainWindow.xaml.cs | 4 +- .../Legends/Legend.Properties.cs | 639 ++++++++++++++++++ Source/OxyPlot.Avalonia/Legends/Legend.cs | 151 +++++ .../OxyPlot.Avalonia/OxyPlot.Avalonia.csproj | 5 +- Source/OxyPlot.Avalonia/Plot.cs | 1 + 5 files changed, 797 insertions(+), 3 deletions(-) create mode 100644 Source/OxyPlot.Avalonia/Legends/Legend.Properties.cs create mode 100644 Source/OxyPlot.Avalonia/Legends/Legend.cs diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs index f977141..1dc7dd3 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs @@ -27,8 +27,6 @@ public partial class MainWindow : Avalonia.Controls.Window { public MainWindow() { - this.InitializeComponent(); - // Create some data var items = new Collection { @@ -52,6 +50,8 @@ public MainWindow() this.DataContext = new { Model1 = tmp, Items = items }; + this.InitializeComponent(); + App.AttachDevTools(this); } diff --git a/Source/OxyPlot.Avalonia/Legends/Legend.Properties.cs b/Source/OxyPlot.Avalonia/Legends/Legend.Properties.cs new file mode 100644 index 0000000..188bab8 --- /dev/null +++ b/Source/OxyPlot.Avalonia/Legends/Legend.Properties.cs @@ -0,0 +1,639 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2020 OxyPlot contributors +// +// +// Represents a control that displays a . +// +// -------------------------------------------------------------------------------------------------------------------- + +using Avalonia; + +namespace OxyPlot.Avalonia +{ + using global::Avalonia.Controls; + using global::Avalonia.Media; + using OxyPlot.Legends; + + /// + /// Represents a control that displays a . + /// + /// This file contains dependency properties used for defining the Plot in XAML. These properties are only used when Model is null. In this case an internal PlotModel is created and the dependency properties are copied from the control to the internal Legend. + public partial class Legend : Control + { + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty IsLegendVisibleProperty = AvaloniaProperty.Register(nameof(IsLegendVisible), true); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendBackgroundProperty = AvaloniaProperty.Register(nameof(LegendBackground), MoreColors.Undefined); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendBorderProperty = AvaloniaProperty.Register(nameof(LegendBorder), MoreColors.Undefined); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendBorderThicknessProperty = AvaloniaProperty.Register(nameof(LegendBorderThickness), 1.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendFontProperty = AvaloniaProperty.Register(nameof(LegendFont), null); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendFontSizeProperty = AvaloniaProperty.Register(nameof(LegendFontSize), 12.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendFontWeightProperty = AvaloniaProperty.Register(nameof(LegendFontWeight), FontWeight.Normal); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendItemAlignmentProperty = AvaloniaProperty.Register(nameof(LegendItemAlignment), global::Avalonia.Layout.HorizontalAlignment.Left); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendItemOrderProperty = AvaloniaProperty.Register(nameof(LegendItemOrder), LegendItemOrder.Normal); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendItemSpacingProperty = AvaloniaProperty.Register(nameof(LegendItemSpacing), 24.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendLineSpacingProperty = AvaloniaProperty.Register(nameof(LegendLineSpacing), 0d); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendMarginProperty = AvaloniaProperty.Register(nameof(LegendMargin), 8.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendMaxHeightProperty = AvaloniaProperty.Register(nameof(LegendMaxHeight), double.NaN); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendMaxWidthProperty = AvaloniaProperty.Register(nameof(LegendMaxWidth), double.NaN); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendOrientationProperty = AvaloniaProperty.Register(nameof(LegendOrientation), LegendOrientation.Vertical); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendColumnSpacingProperty = AvaloniaProperty.Register(nameof(LegendColumnSpacing), 8.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendPaddingProperty = AvaloniaProperty.Register(nameof(LegendPadding), 8.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendPlacementProperty = AvaloniaProperty.Register(nameof(LegendPlacement), LegendPlacement.Inside); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendPositionProperty = AvaloniaProperty.Register(nameof(LegendPosition), LegendPosition.RightTop); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendSymbolLengthProperty = AvaloniaProperty.Register(nameof(LegendSymbolLength), 16.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendSymbolMarginProperty = AvaloniaProperty.Register(nameof(LegendSymbolMargin), 4.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendSymbolPlacementProperty = AvaloniaProperty.Register(nameof(LegendSymbolPlacement), LegendSymbolPlacement.Left); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendTextColorProperty = AvaloniaProperty.Register(nameof(LegendTextColor), MoreColors.Automatic); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendTitleProperty = AvaloniaProperty.Register(nameof(LegendTitle), null); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendTitleColorProperty = AvaloniaProperty.Register(nameof(LegendTitleColor), MoreColors.Automatic); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendTitleFontProperty = AvaloniaProperty.Register(nameof(LegendTitleFont), null); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendTitleFontSizeProperty = AvaloniaProperty.Register(nameof(LegendTitleFontSize), 12.0); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty LegendTitleFontWeightProperty = AvaloniaProperty.Register(nameof(LegendTitleFontWeight), FontWeight.Bold); + + /// + /// Identifies the dependency property. + /// + public static readonly StyledProperty EdgeRenderingModeProperty = AvaloniaProperty.Register(nameof(EdgeRenderingMode), EdgeRenderingMode.Automatic); + + /// + /// Gets or sets LegendBackground. + /// + public Color LegendBackground + { + get + { + return GetValue(LegendBackgroundProperty); + } + + set + { + SetValue(LegendBackgroundProperty, value); + } + } + + /// + /// Gets or sets LegendBorder. + /// + public Color LegendBorder + { + get + { + return GetValue(LegendBorderProperty); + } + + set + { + SetValue(LegendBorderProperty, value); + } + } + + /// + /// Gets or sets LegendBorderThickness. + /// + public double LegendBorderThickness + { + get + { + return GetValue(LegendBorderThicknessProperty); + } + + set + { + SetValue(LegendBorderThicknessProperty, value); + } + } + + /// + /// Gets or sets the spacing between columns of legend items (only for vertical orientation). + /// + /// The spacing in device independent units. + public double LegendColumnSpacing + { + get + { + return GetValue(LegendColumnSpacingProperty); + } + + set + { + SetValue(LegendColumnSpacingProperty, value); + } + } + + /// + /// Gets or sets LegendFont. + /// + public string LegendFont + { + get + { + return GetValue(LegendFontProperty); + } + + set + { + SetValue(LegendFontProperty, value); + } + } + + /// + /// Gets or sets LegendFontSize. + /// + public double LegendFontSize + { + get + { + return GetValue(LegendFontSizeProperty); + } + + set + { + SetValue(LegendFontSizeProperty, value); + } + } + + /// + /// Gets or sets LegendFontWeight. + /// + public FontWeight LegendFontWeight + { + get + { + return GetValue(LegendFontWeightProperty); + } + + set + { + SetValue(LegendFontWeightProperty, value); + } + } + + /// + /// Gets or sets LegendItemAlignment. + /// + public global::Avalonia.Layout.HorizontalAlignment LegendItemAlignment + { + get + { + return GetValue(LegendItemAlignmentProperty); + } + + set + { + SetValue(LegendItemAlignmentProperty, value); + } + } + + /// + /// Gets or sets LegendItemOrder. + /// + public LegendItemOrder LegendItemOrder + { + get + { + return GetValue(LegendItemOrderProperty); + } + + set + { + SetValue(LegendItemOrderProperty, value); + } + } + + /// + /// Gets or sets the horizontal spacing between legend items when the orientation is horizontal. + /// + /// The horizontal distance between items in device independent units. + public double LegendItemSpacing + { + get + { + return GetValue(LegendItemSpacingProperty); + } + + set + { + SetValue(LegendItemSpacingProperty, value); + } + } + + /// + /// Gets or sets the vertical spacing between legend items. + /// + /// The spacing in device independent units. + public double LegendLineSpacing + { + get + { + return GetValue(LegendLineSpacingProperty); + } + + set + { + SetValue(LegendLineSpacingProperty, value); + } + } + + /// + /// Gets or sets the max height of the legend. + /// + /// The max width of the legends. + public double LegendMaxHeight + { + get + { + return GetValue(LegendMaxHeightProperty); + } + + set + { + SetValue(LegendMaxHeightProperty, value); + } + } + + /// + /// Gets or sets the max width of the legend. + /// + /// The max width of the legends. + public double LegendMaxWidth + { + get + { + return GetValue(LegendMaxWidthProperty); + } + + set + { + SetValue(LegendMaxWidthProperty, value); + } + } + + /// + /// Gets or sets LegendMargin. + /// + public double LegendMargin + { + get + { + return GetValue(LegendMarginProperty); + } + + set + { + SetValue(LegendMarginProperty, value); + } + } + + /// + /// Gets or sets LegendOrientation. + /// + public LegendOrientation LegendOrientation + { + get + { + return GetValue(LegendOrientationProperty); + } + + set + { + SetValue(LegendOrientationProperty, value); + } + } + + /// + /// Gets or sets the legend padding. + /// + public double LegendPadding + { + get + { + return GetValue(LegendPaddingProperty); + } + + set + { + SetValue(LegendPaddingProperty, value); + } + } + + /// + /// Gets or sets LegendPlacement. + /// + public LegendPlacement LegendPlacement + { + get + { + return GetValue(LegendPlacementProperty); + } + + set + { + SetValue(LegendPlacementProperty, value); + } + } + + /// + /// Gets or sets the legend position. + /// + /// The legend position. + public LegendPosition LegendPosition + { + get + { + return GetValue(LegendPositionProperty); + } + + set + { + SetValue(LegendPositionProperty, value); + } + } + + /// + /// Gets or sets LegendSymbolLength. + /// + public double LegendSymbolLength + { + get + { + return GetValue(LegendSymbolLengthProperty); + } + + set + { + SetValue(LegendSymbolLengthProperty, value); + } + } + + /// + /// Gets or sets LegendSymbolMargin. + /// + public double LegendSymbolMargin + { + get + { + return GetValue(LegendSymbolMarginProperty); + } + + set + { + SetValue(LegendSymbolMarginProperty, value); + } + } + + /// + /// Gets or sets LegendSymbolPlacement. + /// + public LegendSymbolPlacement LegendSymbolPlacement + { + get + { + return GetValue(LegendSymbolPlacementProperty); + } + + set + { + SetValue(LegendSymbolPlacementProperty, value); + } + } + + /// + /// Gets or sets LegendTitleFont. + /// + public string LegendTitleFont + { + get + { + return GetValue(LegendTitleFontProperty); + } + + set + { + SetValue(LegendTitleFontProperty, value); + } + } + + /// + /// Gets or sets the text color of the legends. + /// + public Color LegendTextColor + { + get + { + return GetValue(LegendTextColorProperty); + } + + set + { + SetValue(LegendTextColorProperty, value); + } + } + + /// + /// Gets or sets the legend title. + /// + public string LegendTitle + { + get + { + return GetValue(LegendTitleProperty); + } + + set + { + SetValue(LegendTitleProperty, value); + } + } + + /// + /// Gets or sets color of the legend title. + /// + public Color LegendTitleColor + { + get + { + return GetValue(LegendTitleColorProperty); + } + + set + { + SetValue(LegendTitleColorProperty, value); + } + } + + /// + /// Gets or sets the font size of the legend titles. + /// + public double LegendTitleFontSize + { + get + { + return GetValue(LegendTitleFontSizeProperty); + } + + set + { + SetValue(LegendTitleFontSizeProperty, value); + } + } + + /// + /// Gets or sets the font weight of the legend titles. + /// + public FontWeight LegendTitleFontWeight + { + get + { + return GetValue(LegendTitleFontWeightProperty); + } + + set + { + SetValue(LegendTitleFontWeightProperty, value); + } + } + + /// + /// Gets or sets a value indicating whether the legend is visible. + /// + public bool IsLegendVisible + { + get + { + return GetValue(IsLegendVisibleProperty); + } + + set + { + SetValue(IsLegendVisibleProperty, value); + } + } + + /// + /// Gets or sets the for the legend. + /// + public EdgeRenderingMode EdgeRenderingMode + { + get + { + return GetValue(EdgeRenderingModeProperty); + } + + set + { + SetValue(EdgeRenderingModeProperty, value); + } + } + } +} \ No newline at end of file diff --git a/Source/OxyPlot.Avalonia/Legends/Legend.cs b/Source/OxyPlot.Avalonia/Legends/Legend.cs new file mode 100644 index 0000000..7be7b4f --- /dev/null +++ b/Source/OxyPlot.Avalonia/Legends/Legend.cs @@ -0,0 +1,151 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 OxyPlot contributors +// +// +// Represents a control that displays a . +// +// -------------------------------------------------------------------------------------------------------------------- + +using Avalonia; + +namespace OxyPlot.Avalonia +{ + using global::Avalonia.Controls; + + /// + /// Represents a control that displays a . + /// + public partial class Legend : Control + { + /// + /// The internal model. + /// + private readonly OxyPlot.Legends.Legend InternalLegend; + + /// + /// Initializes static members of the class. + /// + public Legend() + { + this.InternalLegend = new OxyPlot.Legends.Legend(); + } + + /// + /// Synchronize properties in the internal Plot model + /// + private void SynchronizeProperties() + { + var m = this.InternalLegend; + + m.LegendTextColor = this.LegendTextColor.ToOxyColor(); + m.LegendTitle = this.LegendTitle; + m.LegendTitleColor = this.LegendTitleColor.ToOxyColor(); + m.LegendTitleFont = this.LegendTitleFont; + m.LegendTitleFontSize = this.LegendTitleFontSize; + m.LegendTitleFontWeight = (int)this.LegendTitleFontWeight; + m.LegendFont = this.LegendFont; + m.LegendFontSize = this.LegendFontSize; + m.LegendFontWeight = (int)this.LegendFontWeight; + m.LegendSymbolLength = this.LegendSymbolLength; + m.LegendSymbolMargin = this.LegendSymbolMargin; + m.LegendPadding = this.LegendPadding; + m.LegendColumnSpacing = this.LegendColumnSpacing; + m.LegendItemSpacing = this.LegendItemSpacing; + m.LegendLineSpacing = this.LegendLineSpacing; + m.LegendMargin = this.LegendMargin; + m.LegendMaxHeight = this.LegendMaxHeight; + m.LegendMaxWidth = this.LegendMaxWidth; + + m.LegendBackground = this.LegendBackground.ToOxyColor(); + m.LegendBorder = this.LegendBorder.ToOxyColor(); + m.LegendBorderThickness = this.LegendBorderThickness; + + m.LegendPlacement = this.LegendPlacement; + m.LegendPosition = this.LegendPosition; + m.LegendOrientation = this.LegendOrientation; + m.LegendItemOrder = this.LegendItemOrder; + m.LegendItemAlignment = this.LegendItemAlignment.ToHorizontalAlignment(); + m.LegendSymbolPlacement = this.LegendSymbolPlacement; + + m.IsLegendVisible = this.IsLegendVisible; + m.EdgeRenderingMode = this.EdgeRenderingMode; + } + + /// + /// Handles changes in appearance. + /// + /// The sender. + /// The instance containing the event data. + protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) + { + var pc = ((Legend)d).Parent as IPlotView; + if (pc != null) + { + pc.InvalidatePlot(false); + } + } + + /// + /// Handles changes in data. + /// + /// The sender. + /// The instance containing the event data. + protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) + { + var pc = ((Legend)d).Parent as IPlotView; + if (pc != null) + { + pc.InvalidatePlot(); + } + } + + static Legend() + { + IsLegendVisibleProperty.Changed.AddClassHandler(AppearanceChanged); + + LegendTextColorProperty.Changed.AddClassHandler(AppearanceChanged); + LegendTitleProperty.Changed.AddClassHandler(AppearanceChanged); + LegendTitleColorProperty.Changed.AddClassHandler(AppearanceChanged); + LegendTitleFontProperty.Changed.AddClassHandler(AppearanceChanged); + LegendTitleFontSizeProperty.Changed.AddClassHandler(AppearanceChanged); + LegendTitleFontWeightProperty.Changed.AddClassHandler(AppearanceChanged); + LegendFontProperty.Changed.AddClassHandler(AppearanceChanged); + LegendFontSizeProperty.Changed.AddClassHandler(AppearanceChanged); + LegendFontWeightProperty.Changed.AddClassHandler(AppearanceChanged); + LegendSymbolLengthProperty.Changed.AddClassHandler(AppearanceChanged); + LegendSymbolMarginProperty.Changed.AddClassHandler(AppearanceChanged); + LegendPaddingProperty.Changed.AddClassHandler(AppearanceChanged); + LegendColumnSpacingProperty.Changed.AddClassHandler(AppearanceChanged); + LegendItemSpacingProperty.Changed.AddClassHandler(AppearanceChanged); + LegendLineSpacingProperty.Changed.AddClassHandler(AppearanceChanged); + LegendMarginProperty.Changed.AddClassHandler(AppearanceChanged); + LegendMaxHeightProperty.Changed.AddClassHandler(AppearanceChanged); + LegendMaxWidthProperty.Changed.AddClassHandler(AppearanceChanged); + + LegendBackgroundProperty.Changed.AddClassHandler(AppearanceChanged); + LegendBorderProperty.Changed.AddClassHandler(AppearanceChanged); + LegendBorderThicknessProperty.Changed.AddClassHandler(AppearanceChanged); + + LegendPlacementProperty.Changed.AddClassHandler(AppearanceChanged); + LegendPositionProperty.Changed.AddClassHandler(AppearanceChanged); + LegendOrientationProperty.Changed.AddClassHandler(AppearanceChanged); + LegendItemOrderProperty.Changed.AddClassHandler(AppearanceChanged); + LegendItemAlignmentProperty.Changed.AddClassHandler(AppearanceChanged); + LegendSymbolPlacementProperty.Changed.AddClassHandler(AppearanceChanged); + + IsLegendVisibleProperty.Changed.AddClassHandler(AppearanceChanged); + EdgeRenderingModeProperty.Changed.AddClassHandler(AppearanceChanged); + } + + /// + /// Creates the internal legend. + /// + /// The internal legend. + public OxyPlot.Legends.Legend CreateModel() + { + this.SynchronizeProperties(); + return this.InternalLegend; + } + } +} diff --git a/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj b/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj index c179fe2..17fc6e6 100644 --- a/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj +++ b/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj @@ -16,6 +16,9 @@ - + + + + diff --git a/Source/OxyPlot.Avalonia/Plot.cs b/Source/OxyPlot.Avalonia/Plot.cs index bc727fb..b6d7914 100644 --- a/Source/OxyPlot.Avalonia/Plot.cs +++ b/Source/OxyPlot.Avalonia/Plot.cs @@ -108,6 +108,7 @@ protected override void UpdateModel(bool updateData = true) /// protected void OnAppearanceChanged() { + UpdateModel(false); InvalidatePlot(false); } From 18c4285415c2eae0790a98c16d98289213250f86 Mon Sep 17 00:00:00 2001 From: BobLD Date: Sun, 19 Dec 2021 13:20:26 +0000 Subject: [PATCH 06/20] Update Avalonia to 0.10.11-rc.2, restore reference to OxyPlot 2.1.0 NuGet package and remove local ref --- .../Avalonia/AvaloniaExamples/AvaloniaExamples.csproj | 4 ++-- .../Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj | 4 ++-- Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj | 4 ++-- Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj | 4 ++-- Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj | 7 ++----- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Source/Examples/Avalonia/AvaloniaExamples/AvaloniaExamples.csproj b/Source/Examples/Avalonia/AvaloniaExamples/AvaloniaExamples.csproj index c26ff98..af78460 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/AvaloniaExamples.csproj +++ b/Source/Examples/Avalonia/AvaloniaExamples/AvaloniaExamples.csproj @@ -12,7 +12,7 @@ - - + + \ No newline at end of file diff --git a/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj b/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj index 4af3ce5..245e351 100644 --- a/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj +++ b/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj b/Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj index c26ff98..af78460 100644 --- a/Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj +++ b/Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj @@ -12,7 +12,7 @@ - - + + \ No newline at end of file diff --git a/Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj b/Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj index 1bc2ceb..59b93ff 100644 --- a/Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj +++ b/Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj @@ -13,7 +13,7 @@ - - + + \ No newline at end of file diff --git a/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj b/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj index 17fc6e6..a443b8e 100644 --- a/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj +++ b/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj @@ -15,10 +15,7 @@ - - - - - + + From 2a829b8d8406845f740756e24f91d805f0cff63e Mon Sep 17 00:00:00 2001 From: BobLD Date: Sun, 19 Dec 2021 16:14:20 +0000 Subject: [PATCH 07/20] Tidy up code, fix issue with Bar series in Xaml with hack --- .../Avalonia/AvaloniaExamples/Example.cs | 4 +- .../AvaloniaExamples/ExampleAttribute.cs | 4 +- .../Examples/BarSeriesDemo/MainWindow.xaml | 1 + .../Examples/BarSeriesDemo/MainWindow.xaml.cs | 20 +-- .../CoupledAxesDemo/MainWindow.xaml.cs | 25 ++-- .../CustomTrackerDemo/MainWindow.xaml | 2 +- .../CustomTrackerDemo/MainWindow.xaml.cs | 17 +-- .../Examples/OverlayDemo/MainWindow.xaml.cs | 21 ++- .../NotifyPropertyChangedBase.cs | 2 +- .../Annotations/Annotation.cs | 6 +- .../Annotations/EllipseAnnotation.cs | 4 +- .../Annotations/PointAnnotation.cs | 1 - .../Annotations/TextAnnotation.cs | 2 +- Source/OxyPlot.Avalonia/Axes/AngleAxis.cs | 1 - Source/OxyPlot.Avalonia/Axes/Axis.cs | 18 +-- Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs | 4 +- .../OxyPlot.Avalonia/Axes/LinearColorAxis.cs | 2 +- Source/OxyPlot.Avalonia/Axes/TimeSpanAxis.cs | 5 +- .../OxyPlot.Avalonia/CanvasRenderContext.cs | 35 +++-- .../Converters/OxyColorConverter.cs | 10 +- .../Converters/ThicknessConverter.cs | 9 +- .../Extensions/DataPointExtension.cs | 2 +- Source/OxyPlot.Avalonia/Legends/Legend.cs | 14 +- Source/OxyPlot.Avalonia/Plot.cs | 2 +- .../OxyPlot.Avalonia/PlotBase.Properties.cs | 3 +- Source/OxyPlot.Avalonia/PlotBase.cs | 33 ++--- Source/OxyPlot.Avalonia/PlotView.cs | 1 - Source/OxyPlot.Avalonia/PngExporter.cs | 4 +- .../Series/BarSeries/BarSeries.cs | 1 - .../Series/BarSeries/BarSeriesBase.cs | 1 - .../OxyPlot.Avalonia/Series/HeatMapSeries.cs | 14 +- .../Series/ScatterErrorSeries.cs | 3 +- Source/OxyPlot.Avalonia/Series/Series.cs | 12 +- .../Series/TwoColorAreaSeries.cs | 10 +- .../OxyPlot.Avalonia/Series/XYAxisSeries.cs | 1 - Source/OxyPlot.Avalonia/SvgExporter.cs | 1 - .../Tracker/TrackerControl.cs | 120 ++++++++---------- .../Tracker/TrackerDefinition.cs | 1 - .../Utilities/ConverterExtensions.cs | 5 +- Source/OxyPlot.Avalonia/Utilities/Keyboard.cs | 4 +- 40 files changed, 171 insertions(+), 254 deletions(-) diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Example.cs b/Source/Examples/Avalonia/AvaloniaExamples/Example.cs index 355ccd1..7ce542a 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Example.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Example.cs @@ -34,9 +34,9 @@ public Example(Type mainWindowType, string title = null, string description = nu } } - public string Title { get; private set; } + public string Title { get; } public string Description { get; set; } - private Type MainWindowType { get; set; } + private Type MainWindowType { get; } public IBitmap Thumbnail { get; set; } diff --git a/Source/Examples/Avalonia/AvaloniaExamples/ExampleAttribute.cs b/Source/Examples/Avalonia/AvaloniaExamples/ExampleAttribute.cs index be263cb..dc5ccfa 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/ExampleAttribute.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/ExampleAttribute.cs @@ -21,8 +21,8 @@ public ExampleAttribute(string title, string description) this.Description = description; } - public string Title { get; private set; } + public string Title { get; } - public string Description { get; private set; } + public string Description { get; } } } \ No newline at end of file diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml index d310fd4..29e1b4d 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml @@ -21,6 +21,7 @@ + diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs index 1dc7dd3..e7b290a 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml.cs @@ -7,17 +7,15 @@ // // -------------------------------------------------------------------------------------------------------------------- -using System.Collections.ObjectModel; -using System.Windows; using OxyPlot; +using System.Collections.ObjectModel; namespace AvaloniaExamples.Examples.BarSeriesDemo { - using OxyPlot.Axes; - using OxyPlot.Series; - using AvaloniaExamples; + using OxyPlot.Axes; using OxyPlot.Legends; + using OxyPlot.Series; /// /// Interaction logic for MainWindow.xaml @@ -29,11 +27,11 @@ public MainWindow() { // Create some data var items = new Collection - { - new Item {Label = "Apples", Value1 = 37, Value2 = 12, Value3 = 19}, - new Item {Label = "Pears", Value1 = 7, Value2 = 21, Value3 = 9}, - new Item {Label = "Bananas", Value1 = 23, Value2 = 2, Value3 = 29} - }; + { + new Item { Label = "Apples", Value1 = 37, Value2 = 12, Value3 = 19, Value4 = 42}, + new Item { Label = "Pears", Value1 = 7, Value2 = 21, Value3 = 9, Value4 = 21}, + new Item { Label = "Bananas", Value1 = 23, Value2 = 2, Value3 = 29, Value4 = 10} + }; // Create the plot model var tmp = new PlotModel { Title = "Bar series" }; @@ -47,6 +45,7 @@ public MainWindow() tmp.Series.Add(new BarSeries { Title = "2009", ItemsSource = items, ValueField = "Value1" }); tmp.Series.Add(new BarSeries { Title = "2010", ItemsSource = items, ValueField = "Value2" }); tmp.Series.Add(new BarSeries { Title = "2011", ItemsSource = items, ValueField = "Value3" }); + tmp.Series.Add(new BarSeries { Title = "2012", ItemsSource = items, ValueField = "Value4" }); this.DataContext = new { Model1 = tmp, Items = items }; @@ -67,5 +66,6 @@ public class Item : BarItem public double Value1 { get; set; } public double Value2 { get; set; } public double Value3 { get; set; } + public double Value4 { get; set; } } } \ No newline at end of file diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/CoupledAxesDemo/MainWindow.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/CoupledAxesDemo/MainWindow.xaml.cs index b85afc3..3c36fef 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/CoupledAxesDemo/MainWindow.xaml.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/CoupledAxesDemo/MainWindow.xaml.cs @@ -9,14 +9,11 @@ namespace AvaloniaExamples.Examples.CoupledAxesDemo { - using System; - using System.Windows; - + using AvaloniaExamples; using OxyPlot; using OxyPlot.Axes; using OxyPlot.Series; - - using AvaloniaExamples; + using System; /// /// Interaction logic for MainWindow.xaml @@ -40,17 +37,17 @@ public MainWindow() bool isInternalChange = false; axis1.AxisChanged += (s, e) => + { + if (isInternalChange) { - if (isInternalChange) - { - return; - } + return; + } - isInternalChange = true; - axis2.Zoom(axis1.ActualMinimum, axis1.ActualMaximum); - this.Model2.InvalidatePlot(false); - isInternalChange = false; - }; + isInternalChange = true; + axis2.Zoom(axis1.ActualMinimum, axis1.ActualMaximum); + this.Model2.InvalidatePlot(false); + isInternalChange = false; + }; axis2.AxisChanged += (s, e) => { diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/CustomTrackerDemo/MainWindow.xaml b/Source/Examples/Avalonia/AvaloniaExamples/Examples/CustomTrackerDemo/MainWindow.xaml index 21501be..d384b1e 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/CustomTrackerDemo/MainWindow.xaml +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/CustomTrackerDemo/MainWindow.xaml @@ -10,7 +10,7 @@ - + diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/CustomTrackerDemo/MainWindow.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/CustomTrackerDemo/MainWindow.xaml.cs index 1b3f803..8796fd2 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/CustomTrackerDemo/MainWindow.xaml.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/CustomTrackerDemo/MainWindow.xaml.cs @@ -7,19 +7,15 @@ // // -------------------------------------------------------------------------------------------------------------------- - namespace AvaloniaExamples.Examples.CustomTrackerDemo { - using System.Collections.Generic; - using System.Windows; - - using OxyPlot; - using OxyPlot.Series; - + using Avalonia.Markup.Xaml; using AvaloniaExamples; + using OxyPlot; using OxyPlot.Avalonia.Converters; + using OxyPlot.Series; using System; - using Avalonia.Markup.Xaml; + using System.Collections.Generic; /// /// Interaction logic for MainWindow.xaml @@ -37,10 +33,10 @@ public MainWindow() private void InitializeComponent() { - Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(this); + AvaloniaXamlLoader.Load(this); } - class Context + private class Context { public PlotModel Model { @@ -53,7 +49,6 @@ public PlotModel Model } } } - } public class NullExtension : MarkupExtension diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/OverlayDemo/MainWindow.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/OverlayDemo/MainWindow.xaml.cs index 1e6b100..a2b7ffe 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/OverlayDemo/MainWindow.xaml.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/OverlayDemo/MainWindow.xaml.cs @@ -9,30 +9,27 @@ namespace AvaloniaExamples.Examples.OverlayDemo { - using System; using Avalonia; using Avalonia.Controls; + using Avalonia.Controls.Shapes; using Avalonia.Media; - + using AvaloniaExamples; using OxyPlot; using OxyPlot.Axes; - - using AvaloniaExamples; - using Avalonia.Controls.Shapes; + using System; /// /// Interaction logic for MainWindow.xaml /// [Example("Avalonia overlays.")] - public partial class MainWindow : Avalonia.Controls.Window + public partial class MainWindow : Window { - private LinearAxis horizontalAxis; + private readonly LinearAxis horizontalAxis; - private LinearAxis verticalAxis; + private readonly LinearAxis verticalAxis; - private PlotModel model; - - private Avalonia.Controls.Shapes.Rectangle rect; + private readonly PlotModel model; + private readonly Rectangle rect; private OxyPlot.Avalonia.PlotView plot1; private Canvas canvas1; @@ -72,7 +69,7 @@ private void InitializeComponent() canvas1 = this.Get(nameof(canvas1)); } - void HandleTransformChanged(object sender, EventArgs e) + private void HandleTransformChanged(object sender, EventArgs e) { // Transform to screen coordinates var p1 = this.horizontalAxis.Transform(0, 0, this.verticalAxis); diff --git a/Source/Examples/Avalonia/AvaloniaExamples/NotifyPropertyChangedBase.cs b/Source/Examples/Avalonia/AvaloniaExamples/NotifyPropertyChangedBase.cs index 3fc1451..62bb2ea 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/NotifyPropertyChangedBase.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/NotifyPropertyChangedBase.cs @@ -24,7 +24,7 @@ protected void SetValue(ref T prop, T value, Expression> ignored protected void RaisePropertyChanged(Expression> ignored, [CallerMemberName] string propertyName = null) => OnPropertyChanged(propertyName); - + protected void SetValue(ref T prop, T value, [CallerMemberName] string propertyName = null) { prop = value; diff --git a/Source/OxyPlot.Avalonia/Annotations/Annotation.cs b/Source/OxyPlot.Avalonia/Annotations/Annotation.cs index 6ac13aa..4461f76 100644 --- a/Source/OxyPlot.Avalonia/Annotations/Annotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/Annotation.cs @@ -133,8 +133,7 @@ public virtual void SynchronizeProperties() /// The instance containing the event data. protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - var pc = ((Annotation)d).Parent as IPlotView; - if (pc != null) + if (((Annotation)d).Parent is IPlotView pc) { pc.InvalidatePlot(false); } @@ -147,8 +146,7 @@ protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChange /// The instance containing the event data. protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - var pc = ((Annotation)d).Parent as IPlotView; - if (pc != null) + if (((Annotation)d).Parent is IPlotView pc) { pc.InvalidatePlot(); } diff --git a/Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs index cf00b33..d2e20e1 100644 --- a/Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs @@ -47,7 +47,7 @@ public EllipseAnnotation() } /// - /// Gets or sets the X. + /// Gets or sets the X. /// public double X { @@ -63,7 +63,7 @@ public double X } /// - /// Gets or sets the Y. + /// Gets or sets the Y. /// public double Y { diff --git a/Source/OxyPlot.Avalonia/Annotations/PointAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/PointAnnotation.cs index d55bd37..d3750e5 100644 --- a/Source/OxyPlot.Avalonia/Annotations/PointAnnotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/PointAnnotation.cs @@ -53,7 +53,6 @@ static PointAnnotation() TextVerticalAlignmentProperty.OverrideDefaultValue(VerticalAlignment.Top); TextVerticalAlignmentProperty.Changed.AddClassHandler(AppearanceChanged); - XProperty.Changed.AddClassHandler(DataChanged); YProperty.Changed.AddClassHandler(DataChanged); SizeProperty.Changed.AddClassHandler(AppearanceChanged); diff --git a/Source/OxyPlot.Avalonia/Annotations/TextAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/TextAnnotation.cs index d756ce4..7f19a3e 100644 --- a/Source/OxyPlot.Avalonia/Annotations/TextAnnotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/TextAnnotation.cs @@ -27,7 +27,7 @@ public class TextAnnotation : TextualAnnotation /// /// Identifies the dependency property. /// - public static readonly StyledProperty OffsetProperty = AvaloniaProperty.Register(nameof(Offset), default(Vector)); + public static readonly StyledProperty OffsetProperty = AvaloniaProperty.Register(nameof(Offset), default); /// /// Identifies the dependency property. diff --git a/Source/OxyPlot.Avalonia/Axes/AngleAxis.cs b/Source/OxyPlot.Avalonia/Axes/AngleAxis.cs index 7668105..b81521c 100644 --- a/Source/OxyPlot.Avalonia/Axes/AngleAxis.cs +++ b/Source/OxyPlot.Avalonia/Axes/AngleAxis.cs @@ -11,7 +11,6 @@ namespace OxyPlot.Avalonia { - using OxyPlot.Axes; /// diff --git a/Source/OxyPlot.Avalonia/Axes/Axis.cs b/Source/OxyPlot.Avalonia/Axes/Axis.cs index 73d2658..05d67d2 100644 --- a/Source/OxyPlot.Avalonia/Axes/Axis.cs +++ b/Source/OxyPlot.Avalonia/Axes/Axis.cs @@ -289,7 +289,7 @@ public abstract class Axis : Control /// Identifies the dependency property. /// public static readonly StyledProperty TextColorProperty = AvaloniaProperty.Register(nameof(TextColor), MoreColors.Automatic); - + /// /// Identifies the dependency property. /// @@ -1474,8 +1474,7 @@ protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEvent /// protected void OnDataChanged() { - var pc = Parent as IPlotView; - if (pc != null) + if (Parent is IPlotView pc) { pc.InvalidatePlot(); } @@ -1488,13 +1487,9 @@ protected void OnDataChanged() protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e) { base.OnPropertyChanged(e); - if (e.Property.OwnerType == GetType()) + if (e.Property.OwnerType == GetType() && Parent is IPlotView plot) { - var plot = Parent as IPlotView; - if (plot != null) - { - plot.InvalidatePlot(); - } + plot.InvalidatePlot(); } } @@ -1503,8 +1498,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs /// protected void OnVisualChanged() { - var pc = Parent as IPlotView; - if (pc != null) + if (Parent is IPlotView pc) { pc.InvalidatePlot(false); } @@ -1577,7 +1571,7 @@ protected virtual void SynchronizeProperties() a.TitleFontWeight = (int)TitleFontWeight; a.TitleFormatString = TitleFormatString; a.Title = Title; - a.ToolTip = ToolTip.GetTip(this) != null ? ToolTip.GetTip(this).ToString() : null; + a.ToolTip = (ToolTip.GetTip(this)?.ToString()); a.TickStyle = TickStyle; a.TitlePosition = TitlePosition; a.Unit = Unit; diff --git a/Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs b/Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs index cd0a4b9..1cca98d 100644 --- a/Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs +++ b/Source/OxyPlot.Avalonia/Axes/CategoryAxis.cs @@ -156,7 +156,7 @@ public IList Labels /// Creates the internal axis. /// /// The internal axis. - public override OxyPlot.Axes.Axis CreateModel() + public override Axes.Axis CreateModel() { SynchronizeProperties(); return InternalAxis; @@ -168,7 +168,7 @@ public override OxyPlot.Axes.Axis CreateModel() protected override void SynchronizeProperties() { base.SynchronizeProperties(); - var a = (OxyPlot.Axes.CategoryAxis)InternalAxis; + var a = (Axes.CategoryAxis)InternalAxis; a.IsTickCentered = IsTickCentered; a.ItemsSource = Items; a.LabelField = LabelField; diff --git a/Source/OxyPlot.Avalonia/Axes/LinearColorAxis.cs b/Source/OxyPlot.Avalonia/Axes/LinearColorAxis.cs index aa1987a..5546b82 100644 --- a/Source/OxyPlot.Avalonia/Axes/LinearColorAxis.cs +++ b/Source/OxyPlot.Avalonia/Axes/LinearColorAxis.cs @@ -19,7 +19,7 @@ namespace OxyPlot.Avalonia using System.Linq; /// - /// Provides a Avalonia wrapper for the . + /// Provides a Avalonia wrapper for the . /// public class LinearColorAxis : Axis { diff --git a/Source/OxyPlot.Avalonia/Axes/TimeSpanAxis.cs b/Source/OxyPlot.Avalonia/Axes/TimeSpanAxis.cs index 0e090a1..b9c7a8c 100644 --- a/Source/OxyPlot.Avalonia/Axes/TimeSpanAxis.cs +++ b/Source/OxyPlot.Avalonia/Axes/TimeSpanAxis.cs @@ -38,9 +38,8 @@ public override Axes.Axis CreateModel() protected override void SynchronizeProperties() { base.SynchronizeProperties(); - // ReSharper disable once UnusedVariable - var a = (Axes.TimeSpanAxis)InternalAxis; - //// Currently no values to synchronize + // var a = (Axes.TimeSpanAxis)InternalAxis; + // Currently no values to synchronize } } } \ No newline at end of file diff --git a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs index b821e39..e7d2b8d 100644 --- a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs +++ b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs @@ -18,13 +18,10 @@ namespace OxyPlot.Avalonia using System.Collections.Generic; using System.IO; using System.Linq; - using FontWeights = OxyPlot.FontWeights; - using HorizontalAlignment = OxyPlot.HorizontalAlignment; using Path = global::Avalonia.Controls.Shapes.Path; - using VerticalAlignment = OxyPlot.VerticalAlignment; /// - /// Implements for . + /// Implements for . /// public class CanvasRenderContext : ClippingRenderContext { @@ -57,11 +54,11 @@ public class CanvasRenderContext : ClippingRenderContext /// The brush cache. /// private readonly Dictionary brushCache = new Dictionary(); - + /// /// The canvas. /// - private readonly global::Avalonia.Controls.Canvas canvas; + private readonly Canvas canvas; /// /// The clip rectangle. @@ -72,7 +69,7 @@ public class CanvasRenderContext : ClippingRenderContext /// The current tool tip /// private string currentToolTip; - + /// /// Initializes a new instance of the class. /// @@ -98,7 +95,7 @@ public CanvasRenderContext(Canvas canvas) public bool UseStreamGeometry { get; set; } /// - public void DrawEllipse(OxyRect rect, + public override void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness, @@ -118,7 +115,7 @@ public void DrawEllipse(OxyRect rect, } /// - public void DrawEllipses(IList rectangles, + public override void DrawEllipses(IList rectangles, OxyColor fill, OxyColor stroke, double thickness, @@ -437,7 +434,7 @@ public override void DrawText( { tb.FontWeight = GetFontWeight(fontWeight); } - + double dx = 0; double dy = 0; @@ -519,7 +516,7 @@ public override OxySize MeasureText(string text, } var tb = new TextBlock { Text = text }; - + if (fontFamily != null) { tb.FontFamily = fontFamily; @@ -544,7 +541,7 @@ public override OxySize MeasureText(string text, /// Sets the tool tip for the following items. /// /// The text in the tool tip. - public void SetToolTip(string text) + public override void SetToolTip(string text) { currentToolTip = text; } @@ -563,7 +560,7 @@ public void SetToolTip(string text) /// The height of the drawn image. /// The opacity. /// interpolate if set to true. - public void DrawImage( + public override void DrawImage( OxyImage source, double srcX, double srcY, @@ -599,7 +596,7 @@ public void DrawImage( image.Width = destWidth; image.Height = destHeight; image.Stretch = Stretch.Fill; - + // Set the position of the image Canvas.SetLeft(image, destX); Canvas.SetTop(image, destY); @@ -677,7 +674,7 @@ private static FontWeight GetFontWeight(double fontWeight) if (clip != null) { - element.Clip = new global::Avalonia.Media.RectangleGeometry( + element.Clip = new RectangleGeometry( new Rect( clip.Value.X - clipOffsetX, clip.Value.Y - clipOffsetY, @@ -695,7 +692,7 @@ private static FontWeight GetFontWeight(double fontWeight) /// Applies the current tool tip to the specified element. /// /// The element. - private void ApplyToolTip(global::Avalonia.Controls.Control element) + private void ApplyToolTip(Control element) { if (!string.IsNullOrEmpty(currentToolTip)) { @@ -773,8 +770,7 @@ private IBrush GetCachedBrush(OxyColor color) return null; } - IBrush brush; - if (!brushCache.TryGetValue(color, out brush)) + if (!brushCache.TryGetValue(color, out IBrush brush)) { brush = new SolidColorBrush(color.ToColor()); brushCache.Add(color, brush); @@ -853,8 +849,7 @@ private IBitmap GetImageSource(OxyImage image) imagesInUse.Add(image); } - IBitmap src; - if (imageCache.TryGetValue(image, out src)) + if (imageCache.TryGetValue(image, out var src)) { return src; } diff --git a/Source/OxyPlot.Avalonia/Converters/OxyColorConverter.cs b/Source/OxyPlot.Avalonia/Converters/OxyColorConverter.cs index 3aa2ae9..9d40765 100644 --- a/Source/OxyPlot.Avalonia/Converters/OxyColorConverter.cs +++ b/Source/OxyPlot.Avalonia/Converters/OxyColorConverter.cs @@ -10,7 +10,6 @@ namespace OxyPlot.Avalonia.Converters { using global::Avalonia.Data.Converters; - using global::Avalonia.Markup; using global::Avalonia.Media; using System; using System.Globalization; @@ -30,9 +29,8 @@ public class OxyColorConverter : IValueConverter /// A converted value. If the method returns null, the valid null value is used. public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is OxyColor) + if (value is OxyColor color) { - var color = (OxyColor)value; if (targetType == typeof(Color)) { return color.ToColor(); @@ -59,14 +57,12 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu { if (targetType == typeof(OxyColor)) { - if (value is Color) + if (value is Color color) { - var color = (Color)value; return OxyColor.FromArgb(color.A, color.R, color.G, color.B); } - var brush = value as SolidColorBrush; - if (brush != null) + if (value is SolidColorBrush brush) { return OxyColor.FromArgb(brush.Color.A, brush.Color.R, brush.Color.G, brush.Color.B); } diff --git a/Source/OxyPlot.Avalonia/Converters/ThicknessConverter.cs b/Source/OxyPlot.Avalonia/Converters/ThicknessConverter.cs index 52f8b77..c194020 100644 --- a/Source/OxyPlot.Avalonia/Converters/ThicknessConverter.cs +++ b/Source/OxyPlot.Avalonia/Converters/ThicknessConverter.cs @@ -11,7 +11,6 @@ namespace OxyPlot.Avalonia.Converters { using global::Avalonia; using global::Avalonia.Data.Converters; - using global::Avalonia.Markup; using System; using System.Globalization; @@ -34,13 +33,9 @@ public class ThicknessConverter : IValueConverter /// A converted value. If the method returns null, the valid null value is used. public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is Thickness) + if (value is Thickness t && targetType == typeof(double)) { - var t = (Thickness)value; - if (targetType == typeof(double)) - { - return Math.Max(Math.Max(t.Left, t.Right), Math.Max(t.Top, t.Bottom)); - } + return Math.Max(Math.Max(t.Left, t.Right), Math.Max(t.Top, t.Bottom)); } return value; diff --git a/Source/OxyPlot.Avalonia/Extensions/DataPointExtension.cs b/Source/OxyPlot.Avalonia/Extensions/DataPointExtension.cs index 6337982..e01db7c 100644 --- a/Source/OxyPlot.Avalonia/Extensions/DataPointExtension.cs +++ b/Source/OxyPlot.Avalonia/Extensions/DataPointExtension.cs @@ -7,8 +7,8 @@ // // -------------------------------------------------------------------------------------------------------------------- -using System; using Avalonia.Markup.Xaml; +using System; namespace OxyPlot.Avalonia { diff --git a/Source/OxyPlot.Avalonia/Legends/Legend.cs b/Source/OxyPlot.Avalonia/Legends/Legend.cs index 7be7b4f..c9d5744 100644 --- a/Source/OxyPlot.Avalonia/Legends/Legend.cs +++ b/Source/OxyPlot.Avalonia/Legends/Legend.cs @@ -14,21 +14,21 @@ namespace OxyPlot.Avalonia using global::Avalonia.Controls; /// - /// Represents a control that displays a . + /// Represents a control that displays a . /// public partial class Legend : Control { /// /// The internal model. /// - private readonly OxyPlot.Legends.Legend InternalLegend; + private readonly Legends.Legend InternalLegend; /// /// Initializes static members of the class. /// public Legend() { - this.InternalLegend = new OxyPlot.Legends.Legend(); + this.InternalLegend = new Legends.Legend(); } /// @@ -79,8 +79,7 @@ private void SynchronizeProperties() /// The instance containing the event data. protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - var pc = ((Legend)d).Parent as IPlotView; - if (pc != null) + if (((Legend)d).Parent is IPlotView pc) { pc.InvalidatePlot(false); } @@ -93,8 +92,7 @@ protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChange /// The instance containing the event data. protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - var pc = ((Legend)d).Parent as IPlotView; - if (pc != null) + if (((Legend)d).Parent is IPlotView pc) { pc.InvalidatePlot(); } @@ -142,7 +140,7 @@ static Legend() /// Creates the internal legend. /// /// The internal legend. - public OxyPlot.Legends.Legend CreateModel() + public Legends.Legend CreateModel() { this.SynchronizeProperties(); return this.InternalLegend; diff --git a/Source/OxyPlot.Avalonia/Plot.cs b/Source/OxyPlot.Avalonia/Plot.cs index b6d7914..cbe276d 100644 --- a/Source/OxyPlot.Avalonia/Plot.cs +++ b/Source/OxyPlot.Avalonia/Plot.cs @@ -9,7 +9,6 @@ namespace OxyPlot.Avalonia { - using global::Avalonia; using global::Avalonia.Controls; using global::Avalonia.LogicalTree; using global::Avalonia.VisualTree; @@ -176,6 +175,7 @@ private void SyncLogicalTree(NotifyCollectionChangedEventArgs e) { item.SetParent(null); } + foreach (var item in e.OldItems) { LogicalChildren.Remove((ILogical)item); diff --git a/Source/OxyPlot.Avalonia/PlotBase.Properties.cs b/Source/OxyPlot.Avalonia/PlotBase.Properties.cs index bcd48e5..92dd5a8 100644 --- a/Source/OxyPlot.Avalonia/PlotBase.Properties.cs +++ b/Source/OxyPlot.Avalonia/PlotBase.Properties.cs @@ -13,7 +13,6 @@ namespace OxyPlot.Avalonia { - /// /// Represents a control that displays a . /// @@ -94,7 +93,7 @@ public bool IsMouseWheelEnabled /// Gets or sets the pan cursor. /// /// The pan cursor. - public global::Avalonia.Input.Cursor PanCursor + public Cursor PanCursor { get { diff --git a/Source/OxyPlot.Avalonia/PlotBase.cs b/Source/OxyPlot.Avalonia/PlotBase.cs index 3189f86..9d8febc 100644 --- a/Source/OxyPlot.Avalonia/PlotBase.cs +++ b/Source/OxyPlot.Avalonia/PlotBase.cs @@ -99,7 +99,7 @@ protected PlotBase() trackerDefinitions = new ObservableCollection(); this.GetObservable(TransformedBoundsProperty).Subscribe(bounds => OnSizeChanged(this, bounds?.Bounds.Size ?? new Size())); } - + /// /// Gets or sets a value indicating whether to disconnect the canvas while updating. /// @@ -195,10 +195,7 @@ public void HideZoomRectangle() /// The delta. public void PanAllAxes(Vector delta) { - if (ActualModel != null) - { - ActualModel.PanAllAxes(delta.X, delta.Y); - } + ActualModel?.PanAllAxes(delta.X, delta.Y); InvalidatePlot(false); } @@ -209,10 +206,7 @@ public void PanAllAxes(Vector delta) /// The zoom factor. public void ZoomAllAxes(double factor) { - if (ActualModel != null) - { - ActualModel.ZoomAllAxes(factor); - } + ActualModel?.ZoomAllAxes(factor); InvalidatePlot(false); } @@ -222,10 +216,7 @@ public void ZoomAllAxes(double factor) /// public void ResetAllAxes() { - if (ActualModel != null) - { - ActualModel.ResetAllAxes(); - } + ActualModel?.ResetAllAxes(); InvalidatePlot(false); } @@ -256,7 +247,7 @@ public void InvalidatePlot(bool updateData = true) /// /// When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) - /// call . In simplest terms, this means the method is called + /// call . In simplest terms, this means the method is called /// just before a UI element displays in an application. For more information, see Remarks. /// /// Event data for applying the template. @@ -370,7 +361,7 @@ public void ShowZoomRectangle(OxyRect r) /// The text. public async void SetClipboardText(string text) { - await AvaloniaLocator.Current.GetService().SetTextAsync(text); + await AvaloniaLocator.Current.GetService().SetTextAsync(text).ConfigureAwait(true); } /// @@ -417,7 +408,7 @@ protected bool IsVisibleToUser() /// Determines whether the specified element is currently visible to the user. /// /// The element. - /// true if if the specified element is currently visible to the user; otherwise, false. + /// true if the specified element is currently visible to the user; otherwise, false. private static bool IsUserVisible(Control element) { return element.IsEffectivelyVisible && element.TransformedBounds.HasValue; @@ -432,7 +423,7 @@ private void OnSizeChanged(object sender, Size size) { if (size.Height > 0 && size.Width > 0) { - InvalidatePlot(false); + InvalidatePlot(sender is Plot); // TODO: this is a hack, need to improve } } @@ -447,14 +438,12 @@ private Control GetRelevantParent(IVisual obj) { var container = obj.VisualParent; - var contentPresenter = container as ContentPresenter; - if (contentPresenter != null) + if (container is ContentPresenter contentPresenter) { container = GetRelevantParent(contentPresenter); } - var panel = container as Panel; - if (panel != null) + if (container is Panel panel) { container = GetRelevantParent(panel); } @@ -485,7 +474,7 @@ private void UpdateVisuals() // Clear the canvas canvas.Children.Clear(); - if (ActualModel != null && ActualModel.Background.IsVisible()) + if (ActualModel?.Background.IsVisible() == true) { canvas.Background = ActualModel.Background.ToBrush(); } diff --git a/Source/OxyPlot.Avalonia/PlotView.cs b/Source/OxyPlot.Avalonia/PlotView.cs index 3c761b8..67ec9f2 100644 --- a/Source/OxyPlot.Avalonia/PlotView.cs +++ b/Source/OxyPlot.Avalonia/PlotView.cs @@ -11,7 +11,6 @@ namespace OxyPlot.Avalonia { - /// /// Represents a control that displays a . /// diff --git a/Source/OxyPlot.Avalonia/PngExporter.cs b/Source/OxyPlot.Avalonia/PngExporter.cs index cf3361e..d92775e 100644 --- a/Source/OxyPlot.Avalonia/PngExporter.cs +++ b/Source/OxyPlot.Avalonia/PngExporter.cs @@ -88,7 +88,7 @@ public static IBitmap ExportToBitmap( } /// - /// Exports the specified to the specified . + /// Exports the specified to the specified . /// /// The model. /// The output stream. @@ -111,7 +111,7 @@ public IBitmap ExportToBitmap(IPlotModel model) canvas.Arrange(new Rect(0, 0, canvas.Width, canvas.Height)); var rc = new CanvasRenderContext(canvas) { RendersToScreen = false }; - + model.Update(true); model.Render(rc, new OxyRect(0, 0, canvas.Width, canvas.Height)); diff --git a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeries.cs b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeries.cs index 23be195..8ab0ea5 100644 --- a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeries.cs @@ -11,7 +11,6 @@ namespace OxyPlot.Avalonia { - using OxyPlot.Series; /// diff --git a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs index a5b1ba1..ff50438 100644 --- a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs +++ b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs @@ -12,7 +12,6 @@ namespace OxyPlot.Avalonia { using global::Avalonia.Media; - using OxyPlot.Series; /// diff --git a/Source/OxyPlot.Avalonia/Series/HeatMapSeries.cs b/Source/OxyPlot.Avalonia/Series/HeatMapSeries.cs index cfe653f..6e752ee 100644 --- a/Source/OxyPlot.Avalonia/Series/HeatMapSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/HeatMapSeries.cs @@ -26,37 +26,37 @@ public class HeatMapSeries : XYAxisSeries /// /// Identifies this dependency property. /// - public static readonly StyledProperty X0Property = AvaloniaProperty.Register(nameof(X0), default(double)); + public static readonly StyledProperty X0Property = AvaloniaProperty.Register(nameof(X0), default); /// /// Identifies this dependency property. /// - public static readonly StyledProperty X1Property = AvaloniaProperty.Register(nameof(X1), default(double)); + public static readonly StyledProperty X1Property = AvaloniaProperty.Register(nameof(X1), default); /// /// Identifies this dependency property. /// - public static readonly StyledProperty Y0Property = AvaloniaProperty.Register(nameof(Y0), default(double)); + public static readonly StyledProperty Y0Property = AvaloniaProperty.Register(nameof(Y0), default); /// /// Identifies this dependency property. /// - public static readonly StyledProperty Y1Property = AvaloniaProperty.Register(nameof(Y1), default(double)); + public static readonly StyledProperty Y1Property = AvaloniaProperty.Register(nameof(Y1), default); /// /// Identifies this dependency property. /// - public static readonly StyledProperty ColorAxisKeyProperty = AvaloniaProperty.Register(nameof(ColorAxisKey), default(string)); + public static readonly StyledProperty ColorAxisKeyProperty = AvaloniaProperty.Register(nameof(ColorAxisKey), default); /// /// Identifies this dependency property. /// - public static readonly StyledProperty LowColorProperty = AvaloniaProperty.Register(nameof(LowColor), default(Color)); + public static readonly StyledProperty LowColorProperty = AvaloniaProperty.Register(nameof(LowColor), default); /// /// Identifies this dependency property. /// - public static readonly StyledProperty HighColorProperty = AvaloniaProperty.Register(nameof(HighColor), default(Color)); + public static readonly StyledProperty HighColorProperty = AvaloniaProperty.Register(nameof(HighColor), default); /// /// Initializes static members of the class. diff --git a/Source/OxyPlot.Avalonia/Series/ScatterErrorSeries.cs b/Source/OxyPlot.Avalonia/Series/ScatterErrorSeries.cs index d045ca8..c4fe250 100644 --- a/Source/OxyPlot.Avalonia/Series/ScatterErrorSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/ScatterErrorSeries.cs @@ -12,7 +12,6 @@ namespace OxyPlot.Avalonia { using global::Avalonia.Media; - using OxyPlot.Series; /// @@ -119,7 +118,7 @@ public double ErrorBarStrokeThickness } /// - /// Gets or sets the minimum size (relative to ) of the error bars to be shown. + /// Gets or sets the minimum size (relative to ) of the error bars to be shown. /// public double MinimumErrorSize { diff --git a/Source/OxyPlot.Avalonia/Series/Series.cs b/Source/OxyPlot.Avalonia/Series/Series.cs index 1c7cf11..49072c4 100644 --- a/Source/OxyPlot.Avalonia/Series/Series.cs +++ b/Source/OxyPlot.Avalonia/Series/Series.cs @@ -120,7 +120,7 @@ public string Title /// /// Gets or sets a value indicating whether the series should be rendered in the legend. /// - public bool RenderInLegend + public bool RenderInLegend { get { @@ -212,8 +212,7 @@ protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEvent /// protected void OnDataChanged() { - var pc = Parent as IPlotView; - if (pc != null) + if (Parent is IPlotView pc) { pc.InvalidatePlot(); } @@ -223,7 +222,6 @@ protected void OnDataChanged() /// The on items source changed. /// /// Event args - /// protected override void ItemsChanged(AvaloniaPropertyChangedEventArgs e) { base.ItemsChanged(e); @@ -236,8 +234,7 @@ protected override void ItemsChanged(AvaloniaPropertyChangedEventArgs e) /// protected void OnVisualChanged() { - var pc = Parent as IPlotView; - if (pc != null) + if (Parent is IPlotView pc) { pc.InvalidatePlot(false); } @@ -275,8 +272,7 @@ protected virtual void SynchronizeProperties(OxyPlot.Series.Series s) /// The new ItemsSource private void SubscribeToCollectionChanged(IEnumerable oldValue, IEnumerable newValue) { - var collection = oldValue as INotifyCollectionChanged; - if (collection != null) + if (oldValue is INotifyCollectionChanged collection) { WeakSubscriptionManager.Unsubscribe(collection, "CollectionChanged", eventListener); } diff --git a/Source/OxyPlot.Avalonia/Series/TwoColorAreaSeries.cs b/Source/OxyPlot.Avalonia/Series/TwoColorAreaSeries.cs index e58150e..5c0223c 100644 --- a/Source/OxyPlot.Avalonia/Series/TwoColorAreaSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/TwoColorAreaSeries.cs @@ -7,8 +7,8 @@ // // -------------------------------------------------------------------------------------------------------------------- -using System.Linq; using Avalonia; +using System.Linq; namespace OxyPlot.Avalonia { @@ -23,7 +23,7 @@ public class TwoColorAreaSeries : AreaSeries /// Identifies the dependency property. /// public static readonly StyledProperty Dashes2Property = AvaloniaProperty.Register(nameof(Dashes2)); - + /// /// Identifies the dependency property. /// @@ -43,7 +43,7 @@ public class TwoColorAreaSeries : AreaSeries /// Identifies the dependency property. /// public static readonly AvaloniaProperty LimitProperty = AvaloniaProperty.Register(nameof(Limit)); - + /// /// Identifies the dependency property. /// @@ -140,7 +140,7 @@ public Color MarkerStroke2 SetValue(MarkerStroke2Property, value); } } - + /// /// Gets or sets the line style for the part of the line that is below the limit. /// @@ -180,7 +180,7 @@ public double Limit protected override void SynchronizeProperties(OxyPlot.Series.Series series) { base.SynchronizeProperties(series); - var s = (OxyPlot.Series.TwoColorAreaSeries)series; + var s = (OxyPlot.Series.TwoColorAreaSeries)series; s.Fill = Fill.ToOxyColor(); s.Fill2 = Fill2.ToOxyColor(); s.MarkerFill2 = MarkerFill2.ToOxyColor(); diff --git a/Source/OxyPlot.Avalonia/Series/XYAxisSeries.cs b/Source/OxyPlot.Avalonia/Series/XYAxisSeries.cs index 40d7232..269429e 100644 --- a/Source/OxyPlot.Avalonia/Series/XYAxisSeries.cs +++ b/Source/OxyPlot.Avalonia/Series/XYAxisSeries.cs @@ -11,7 +11,6 @@ namespace OxyPlot.Avalonia { - /// /// Abstract base class for series that use X and Y axes. /// diff --git a/Source/OxyPlot.Avalonia/SvgExporter.cs b/Source/OxyPlot.Avalonia/SvgExporter.cs index edf788e..027f61b 100644 --- a/Source/OxyPlot.Avalonia/SvgExporter.cs +++ b/Source/OxyPlot.Avalonia/SvgExporter.cs @@ -11,7 +11,6 @@ namespace OxyPlot.Avalonia { - /// /// Provides functionality to export plots to scalable vector graphics using text measuring in Avalonia. /// diff --git a/Source/OxyPlot.Avalonia/Tracker/TrackerControl.cs b/Source/OxyPlot.Avalonia/Tracker/TrackerControl.cs index 7ccd341..692362e 100644 --- a/Source/OxyPlot.Avalonia/Tracker/TrackerControl.cs +++ b/Source/OxyPlot.Avalonia/Tracker/TrackerControl.cs @@ -50,7 +50,7 @@ public class TrackerControl : ContentControl /// Identifies the dependency property. /// public static readonly StyledProperty> LineDashArrayProperty = AvaloniaProperty.Register>(nameof(LineDashArray)); - + /// /// Identifies the dependency property. /// @@ -326,7 +326,6 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) verticalLine = e.NameScope.Find(PartVerticalLine); UpdatePositionAndBorder(); - } /// @@ -441,10 +440,8 @@ private void UpdatePositionAndBorder() var dx = ha == HorizontalAlignment.Center ? -0.5 : ha == HorizontalAlignment.Left ? 0 : -1; var dy = va == VerticalAlignment.Center ? -0.5 : va == VerticalAlignment.Top ? 0 : -1; - Thickness margin; - path.Data = ShowPointer - ? CreatePointerBorderGeometry(ha, va, contentWidth, contentHeight, out margin) - : CreateBorderGeometry(ha, va, contentWidth, contentHeight, out margin); + path.Data = ShowPointer ? CreatePointerBorderGeometry(ha, va, contentWidth, contentHeight, out var margin) + : CreateBorderGeometry(ha, va, contentWidth, contentHeight, out margin); content.Margin = margin; @@ -452,10 +449,10 @@ private void UpdatePositionAndBorder() var contentSize = contentContainer.DesiredSize; contentContainer.RenderTransform = new TranslateTransform - { - X = dx * contentSize.Width, - Y = dy * contentSize.Height - }; + { + X = dx * contentSize.Width, + Y = dy * contentSize.Height + }; if (horizontalLine != null) { @@ -511,65 +508,55 @@ private Geometry CreatePointerBorderGeometry( if (ha == HorizontalAlignment.Center && va == VerticalAlignment.Bottom) { - double x0 = 0; var x1 = width; - var x2 = (x0 + x1) / 2; - double y0 = 0; + var x2 = x1 / 2; var y1 = height; margin = new Thickness(0, 0, 0, m); points = new[] - { - new Point(x0, y0), new Point(x1, y0), new Point(x1, y1), new Point(x2 + (m / 2), y1), - new Point(x2, y1 + m), new Point(x2 - (m / 2), y1), new Point(x0, y1) - }; + { + new Point(0, 0), new Point(x1, 0), new Point(x1, y1), new Point(x2 + (m / 2), y1), + new Point(x2, y1 + m), new Point(x2 - (m / 2), y1), new Point(0, y1) + }; } - - if (ha == HorizontalAlignment.Center && va == VerticalAlignment.Top) + else if (ha == HorizontalAlignment.Center && va == VerticalAlignment.Top) { - double x0 = 0; var x1 = width; - var x2 = (x0 + x1) / 2; + var x2 = x1 / 2; var y0 = m; var y1 = m + height; margin = new Thickness(0, m, 0, 0); points = new[] - { - new Point(x0, y0), new Point(x2 - (m / 2), y0), new Point(x2, 0), new Point(x2 + (m / 2), y0), - new Point(x1, y0), new Point(x1, y1), new Point(x0, y1) - }; + { + new Point(0, y0), new Point(x2 - (m / 2), y0), new Point(x2, 0), new Point(x2 + (m / 2), y0), + new Point(x1, y0), new Point(x1, y1), new Point(0, y1) + }; } - - if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Center) + else if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Center) { var x0 = m; var x1 = m + width; - double y0 = 0; var y1 = height; - var y2 = (y0 + y1) / 2; + var y2 = y1 / 2; margin = new Thickness(m, 0, 0, 0); points = new[] - { - new Point(0, y2), new Point(x0, y2 - (m / 2)), new Point(x0, y0), new Point(x1, y0), - new Point(x1, y1), new Point(x0, y1), new Point(x0, y2 + (m / 2)) - }; + { + new Point(0, y2), new Point(x0, y2 - (m / 2)), new Point(x0, 0), new Point(x1, 0), + new Point(x1, y1), new Point(x0, y1), new Point(x0, y2 + (m / 2)) + }; } - - if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Center) + else if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Center) { - double x0 = 0; var x1 = width; - double y0 = 0; var y1 = height; - var y2 = (y0 + y1) / 2; + var y2 = y1 / 2; margin = new Thickness(0, 0, m, 0); points = new[] - { - new Point(x1 + m, y2), new Point(x1, y2 + (m / 2)), new Point(x1, y1), new Point(x0, y1), - new Point(x0, y0), new Point(x1, y0), new Point(x1, y2 - (m / 2)) - }; + { + new Point(x1 + m, y2), new Point(x1, y2 + (m / 2)), new Point(x1, y1), new Point(0, y1), + new Point(0, 0), new Point(x1, 0), new Point(x1, y2 - (m / 2)) + }; } - - if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Top) + else if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Top) { m *= 0.67; var x0 = m; @@ -578,55 +565,48 @@ private Geometry CreatePointerBorderGeometry( var y1 = m + height; margin = new Thickness(m, m, 0, 0); points = new[] - { - new Point(0, 0), new Point(m * 2, y0), new Point(x1, y0), new Point(x1, y1), new Point(x0, y1), - new Point(x0, m * 2) - }; + { + new Point(0, 0), new Point(m * 2, y0), new Point(x1, y0), new Point(x1, y1), new Point(x0, y1), + new Point(x0, m * 2) + }; } - - if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Top) + else if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Top) { m *= 0.67; - double x0 = 0; var x1 = width; var y0 = m; var y1 = m + height; margin = new Thickness(0, m, m, 0); points = new[] - { - new Point(x1 + m, 0), new Point(x1, y0 + m), new Point(x1, y1), new Point(x0, y1), - new Point(x0, y0), new Point(x1 - m, y0) - }; + { + new Point(x1 + m, 0), new Point(x1, y0 + m), new Point(x1, y1), new Point(0, y1), + new Point(0, y0), new Point(x1 - m, y0) + }; } - - if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Bottom) + else if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Bottom) { m *= 0.67; var x0 = m; var x1 = m + width; - double y0 = 0; var y1 = height; margin = new Thickness(m, 0, 0, m); points = new[] - { - new Point(0, y1 + m), new Point(x0, y1 - m), new Point(x0, y0), new Point(x1, y0), - new Point(x1, y1), new Point(x0 + m, y1) - }; + { + new Point(0, y1 + m), new Point(x0, y1 - m), new Point(x0, 0), new Point(x1, 0), + new Point(x1, y1), new Point(x0 + m, y1) + }; } - - if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Bottom) + else if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Bottom) { m *= 0.67; - double x0 = 0; var x1 = width; - double y0 = 0; var y1 = height; margin = new Thickness(0, 0, m, m); points = new[] - { - new Point(x1 + m, y1 + m), new Point(x1 - m, y1), new Point(x0, y1), new Point(x0, y0), - new Point(x1, y0), new Point(x1, y1 - m) - }; + { + new Point(x1 + m, y1 + m), new Point(x1 - m, y1), new Point(0, y1), new Point(0, 0), + new Point(x1, 0), new Point(x1, y1 - m) + }; } if (points == null) diff --git a/Source/OxyPlot.Avalonia/Tracker/TrackerDefinition.cs b/Source/OxyPlot.Avalonia/Tracker/TrackerDefinition.cs index 523d369..351cf46 100644 --- a/Source/OxyPlot.Avalonia/Tracker/TrackerDefinition.cs +++ b/Source/OxyPlot.Avalonia/Tracker/TrackerDefinition.cs @@ -12,7 +12,6 @@ namespace OxyPlot.Avalonia { - /// /// Represents a tracker definition. /// diff --git a/Source/OxyPlot.Avalonia/Utilities/ConverterExtensions.cs b/Source/OxyPlot.Avalonia/Utilities/ConverterExtensions.cs index 30755f4..f8c2f65 100644 --- a/Source/OxyPlot.Avalonia/Utilities/ConverterExtensions.cs +++ b/Source/OxyPlot.Avalonia/Utilities/ConverterExtensions.cs @@ -127,8 +127,7 @@ public static OxyColor ToOxyColor(this Color color) /// An . public static OxyColor ToOxyColor(this IBrush brush) { - var scb = brush as SolidColorBrush; - return scb != null ? scb.Color.ToOxyColor() : OxyColors.Undefined; + return brush is SolidColorBrush scb ? scb.Color.ToOxyColor() : OxyColors.Undefined; } /// @@ -443,7 +442,7 @@ public static OxyMouseWheelEventArgs ToMouseWheelEventArgs(this PointerWheelEven public static OxyMouseDownEventArgs ToMouseDownEventArgs(this PointerPressedEventArgs e, IInputElement relativeTo) { var point = e.GetCurrentPoint(relativeTo); - + return new OxyMouseDownEventArgs { ChangedButton = point.Properties.PointerUpdateKind.Convert(), diff --git a/Source/OxyPlot.Avalonia/Utilities/Keyboard.cs b/Source/OxyPlot.Avalonia/Utilities/Keyboard.cs index e83ddf0..bda2744 100644 --- a/Source/OxyPlot.Avalonia/Utilities/Keyboard.cs +++ b/Source/OxyPlot.Avalonia/Utilities/Keyboard.cs @@ -33,7 +33,6 @@ public Keyboard() /// A value. public OxyModifierKeys GetModifierKeys() { - var modifiers = OxyModifierKeys.None; if ((currentModifiers & RawInputModifiers.Shift) != 0) { @@ -60,9 +59,8 @@ public OxyModifierKeys GetModifierKeys() private void ProcessModifierKeys(RawInputEventArgs args) { - if (args is RawKeyEventArgs) + if (args is RawKeyEventArgs keyArgs) { - var keyArgs = (RawKeyEventArgs)args; currentModifiers = keyArgs.Modifiers; } } From 62333a32433e7b14bdee9c98376b7a3fe6281c9e Mon Sep 17 00:00:00 2001 From: BobLD Date: Sun, 19 Dec 2021 20:36:45 +0000 Subject: [PATCH 08/20] Fix missing series in BarSeriesBase and remove hack --- Source/OxyPlot.Avalonia/PlotBase.cs | 2 +- Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/OxyPlot.Avalonia/PlotBase.cs b/Source/OxyPlot.Avalonia/PlotBase.cs index 9d8febc..872206e 100644 --- a/Source/OxyPlot.Avalonia/PlotBase.cs +++ b/Source/OxyPlot.Avalonia/PlotBase.cs @@ -423,7 +423,7 @@ private void OnSizeChanged(object sender, Size size) { if (size.Height > 0 && size.Width > 0) { - InvalidatePlot(sender is Plot); // TODO: this is a hack, need to improve + InvalidatePlot(false); } } diff --git a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs index ff50438..6440597 100644 --- a/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs +++ b/Source/OxyPlot.Avalonia/Series/BarSeries/BarSeriesBase.cs @@ -96,7 +96,7 @@ static BarSeriesBase() StackGroupProperty.Changed.AddClassHandler(AppearanceChanged); StrokeColorProperty.Changed.AddClassHandler(AppearanceChanged); StrokeThicknessProperty.Changed.AddClassHandler(AppearanceChanged); - ValueFieldProperty.Changed.AddClassHandler(AppearanceChanged); + ValueFieldProperty.Changed.AddClassHandler(DataChanged); TrackerFormatStringProperty.Changed.AddClassHandler(AppearanceChanged); } From b551f0678cdbc1b6ac9fa0891acff37f1f431672 Mon Sep 17 00:00:00 2001 From: BobLD Date: Mon, 20 Dec 2021 02:17:20 +0000 Subject: [PATCH 09/20] Update CanvasRenderContext for performance --- .../OxyPlot.Avalonia/CanvasRenderContext.cs | 350 +++++++++++------- Source/OxyPlot.Avalonia/PlotBase.cs | 3 - 2 files changed, 209 insertions(+), 144 deletions(-) diff --git a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs index e7d2b8d..6779bab 100644 --- a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs +++ b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs @@ -77,7 +77,7 @@ public class CanvasRenderContext : ClippingRenderContext public CanvasRenderContext(Canvas canvas) { this.canvas = canvas; - UseStreamGeometry = false; // Temporarily disabled because of Avalonia bug + UseStreamGeometry = true; RendersToScreen = true; BalancedLineDrawingThicknessLimit = 3.5; } @@ -101,17 +101,13 @@ public override void DrawEllipse(OxyRect rect, double thickness, EdgeRenderingMode edgeRenderingMode) { - var e = CreateAndAdd(rect.Left, rect.Top); - SetStroke(e, stroke, thickness, edgeRenderingMode); - if (fill.IsVisible()) + var path = CreateAndAdd(); + SetStroke(path, stroke, thickness, edgeRenderingMode); + if (!fill.IsUndefined()) { - e.Fill = GetCachedBrush(fill); + path.Fill = GetCachedBrush(fill); } - - e.Width = rect.Width; - e.Height = rect.Height; - Canvas.SetLeft(e, rect.Left); - Canvas.SetTop(e, rect.Top); + path.Data = new EllipseGeometry(ToRect(rect)); } /// @@ -149,6 +145,65 @@ public override void DrawLine( e.Points = ToPointCollection(points, aliased); } + #region DrawLineSegments + /// + /// Draws the line segments by stream geometry. + /// + /// The points. + /// The stroke color. + /// The thickness. + /// The edge rendering mode. + /// The dash array. Use null to get a solid line. + /// The line join. + private void DrawLineSegmentsByStreamGeometry( + IList points, + OxyColor stroke, + double thickness, + EdgeRenderingMode edgeRenderingMode, + double[] dashArray, + LineJoin lineJoin) + { + bool aliased = edgeRenderingMode == EdgeRenderingMode.PreferSpeed; + + StreamGeometry streamGeometry = null; + StreamGeometryContext streamGeometryContext = null; + + var count = 0; + + for (int i = 0; i + 1 < points.Count; i += 2) + { + if (streamGeometry == null) + { + streamGeometry = new StreamGeometry(); + streamGeometryContext = streamGeometry.Open(); + } + + streamGeometryContext.BeginFigure(ToPoint(points[i], aliased), false); + streamGeometryContext.LineTo(ToPoint(points[i + 1], aliased)); + + count++; + + // Must limit the number of figures, otherwise drawing errors... + if (count > MaxFiguresPerGeometry || dashArray != null) + { + streamGeometryContext.Dispose(); + var path = CreateAndAdd(); + SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); + path.Data = streamGeometry; + streamGeometry = null; + count = 0; + } + } + + if (streamGeometry != null) + { + streamGeometryContext.Dispose(); + var path = CreateAndAdd(); + SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, null, 0); + path.Data = streamGeometry; + } + } + /// /// Draws line segments defined by points (0,1) (2,3) (4,5) etc. /// This should have better performance than calling DrawLine for each segment. @@ -209,7 +264,9 @@ public void DrawLineSegments( path.Data = pathGeometry; } } + #endregion + #region DrawPolygon(s) /// public override void DrawPolygon( IList points, @@ -232,8 +289,7 @@ public override void DrawPolygon( e.Points = ToPointCollection(points, aliased); } - /// - public override void DrawPolygons( + private void DrawPolygonsByStreamGeometry( IList> polygons, OxyColor fill, OxyColor stroke, @@ -242,72 +298,150 @@ public override void DrawPolygons( double[] dashArray, LineJoin lineJoin) { - var usg = UseStreamGeometry; Path path = null; StreamGeometry streamGeometry = null; StreamGeometryContext sgc = null; - PathGeometry pathGeometry = null; var count = 0; + Func toPointFunc; + if (edgeRenderingMode == EdgeRenderingMode.PreferSpeed) // aliased + { + toPointFunc = ToPixelAlignedPoint; + } + else + { + toPointFunc = ToPoint; + } + + bool isDefined = !fill.IsUndefined(); + IBrush cachedBrush = null; + if (isDefined) + { + cachedBrush = GetCachedBrush(fill); + } + foreach (var polygon in polygons) { if (path == null) { path = CreateAndAdd(); SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); - if (!fill.IsUndefined()) + if (isDefined) { - path.Fill = GetCachedBrush(fill); + path.Fill = cachedBrush; } - if (usg) + streamGeometry = new StreamGeometry(); + sgc = streamGeometry.Open(); + sgc.SetFillRule(FillRule.NonZero); + } + + var first = true; + foreach (var p in polygon) + { + if (first) { - streamGeometry = new StreamGeometry(); - sgc = streamGeometry.Open(); - sgc.SetFillRule(FillRule.NonZero); + sgc.BeginFigure(toPointFunc(p), isDefined); + first = false; } else { - pathGeometry = new PathGeometry { FillRule = FillRule.NonZero }; + sgc.LineTo(toPointFunc(p)); } } - bool aliased = edgeRenderingMode == EdgeRenderingMode.PreferSpeed; + sgc.EndFigure(true); + + count++; + + // Must limit the number of figures, otherwise drawing errors... + if (count > MaxFiguresPerGeometry) + { + sgc.Dispose(); + path.Data = streamGeometry; + path = null; + count = 0; + } + } + + if (path != null) + { + sgc.Dispose(); + path.Data = streamGeometry; + } + } + + /// + public override void DrawPolygons( + IList> polygons, + OxyColor fill, + OxyColor stroke, + double thickness, + EdgeRenderingMode edgeRenderingMode, + double[] dashArray, + LineJoin lineJoin) + { + if (UseStreamGeometry) + { + DrawPolygonsByStreamGeometry(polygons, fill, stroke, thickness, edgeRenderingMode, dashArray, lineJoin); + return; + } + + Path path = null; + StreamGeometryContext sgc = null; + PathGeometry pathGeometry = null; + var count = 0; + + Func toPointFunc; + if (edgeRenderingMode == EdgeRenderingMode.PreferSpeed) // aliased + { + toPointFunc = ToPixelAlignedPoint; + } + else + { + toPointFunc = ToPoint; + } + + bool isDefined = !fill.IsUndefined(); + IBrush cachedBrush = null; + if (isDefined) + { + cachedBrush = GetCachedBrush(fill); + } + + foreach (var polygon in polygons) + { + if (path == null) + { + path = CreateAndAdd(); + SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); + if (isDefined) + { + path.Fill = cachedBrush; + } + + pathGeometry = new PathGeometry { FillRule = FillRule.NonZero }; + } PathFigure figure = null; var first = true; foreach (var p in polygon) { - var point = aliased ? ToPixelAlignedPoint(p) : ToPoint(p); if (first) { - if (usg) + figure = new PathFigure { - sgc.BeginFigure(point, !fill.IsUndefined()); - } - else - { - figure = new PathFigure - { - StartPoint = point, - IsFilled = !fill.IsUndefined(), - IsClosed = true - }; - pathGeometry.Figures.Add(figure); - } + StartPoint = toPointFunc(p), + IsFilled = isDefined, + IsClosed = true + }; + pathGeometry.Figures.Add(figure); first = false; } else { - if (usg) - { - sgc.LineTo(point); - } - else - { - figure.Segments.Add(new LineSegment { Point = point }); - } + sgc.LineTo(toPointFunc(p)); } } @@ -316,16 +450,7 @@ public override void DrawPolygons( // Must limit the number of figures, otherwise drawing errors... if (count > MaxFiguresPerGeometry) { - if (usg) - { - sgc.Dispose(); - path.Data = streamGeometry; - } - else - { - path.Data = pathGeometry; - } - + path.Data = pathGeometry; path = null; count = 0; } @@ -333,17 +458,10 @@ public override void DrawPolygons( if (path != null) { - if (usg) - { - sgc.Dispose(); - path.Data = streamGeometry; - } - else - { - path.Data = pathGeometry; - } + path.Data = pathGeometry; } } + #endregion /// /// Draws a rectangle. @@ -358,18 +476,13 @@ public override void DrawRectangle(OxyRect rect, double thickness, EdgeRenderingMode edgeRenderingMode) { - var e = CreateAndAdd(rect.Left, rect.Top); - SetStroke(e, stroke, thickness, edgeRenderingMode, LineJoin.Miter, null, 0); - + var path = CreateAndAdd(); + SetStroke(path, stroke, thickness, edgeRenderingMode); if (!fill.IsUndefined()) { - e.Fill = GetCachedBrush(fill); + path.Fill = GetCachedBrush(fill); } - - e.Width = rect.Width; - e.Height = rect.Height; - Canvas.SetLeft(e, rect.Left); - Canvas.SetTop(e, rect.Top); + path.Data = new RectangleGeometry(ToRect(rect)); } /// @@ -386,10 +499,8 @@ public override void DrawRectangles(IList rectangles, double thickness, EdgeRenderingMode edgeRenderingMode) { - foreach (var rect in rectangles) - { - DrawRectangle(rect, fill, stroke, thickness, edgeRenderingMode); - } + var polys = rectangles.Select(r => (IList)RectangleToPolygon(r)).ToList(); + DrawPolygons(polys, fill, stroke, thickness, edgeRenderingMode, null, LineJoin.Miter); } /// @@ -639,10 +750,8 @@ protected override void ResetClip() public override void CleanUp() { // Find the images in the cache that has not been used since last call to this method - var imagesToRelease = imageCache.Keys.Where(i => !imagesInUse.Contains(i)).ToList(); - // Remove the images from the cache - foreach (var i in imagesToRelease) + foreach (var i in imageCache.Keys.Where(i => !imagesInUse.Contains(i)).ToList()) { imageCache.Remove(i); } @@ -667,7 +776,7 @@ private static FontWeight GetFontWeight(double fontWeight) /// The clip offset executable. /// The clip offset asynchronous. /// The element. - private T CreateAndAdd(double clipOffsetX = 0, double clipOffsetY = 0) where T : global::Avalonia.Controls.Control, new() + private T CreateAndAdd(double clipOffsetX = 0, double clipOffsetY = 0) where T : Control, new() { // TODO: here we can reuse existing elements in the canvas.Children collection var element = new T(); @@ -700,64 +809,6 @@ private void ApplyToolTip(Control element) } } - /// - /// Draws the line segments by stream geometry. - /// - /// The points. - /// The stroke color. - /// The thickness. - /// The edge rendering mode. - /// The dash array. Use null to get a solid line. - /// The line join. - private void DrawLineSegmentsByStreamGeometry( - IList points, - OxyColor stroke, - double thickness, - EdgeRenderingMode edgeRenderingMode, - double[] dashArray, - LineJoin lineJoin) - { - bool aliased = edgeRenderingMode == EdgeRenderingMode.PreferSpeed; - - StreamGeometry streamGeometry = null; - StreamGeometryContext streamGeometryContext = null; - - var count = 0; - - for (int i = 0; i + 1 < points.Count; i += 2) - { - if (streamGeometry == null) - { - streamGeometry = new StreamGeometry(); - streamGeometryContext = streamGeometry.Open(); - } - - streamGeometryContext.BeginFigure(ToPoint(points[i], aliased), false); - streamGeometryContext.LineTo(ToPoint(points[i + 1], aliased)); - - count++; - - // Must limit the number of figures, otherwise drawing errors... - if (count > MaxFiguresPerGeometry || dashArray != null) - { - streamGeometryContext.Dispose(); - var path = CreateAndAdd(); - SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); - path.Data = streamGeometry; - streamGeometry = null; - count = 0; - } - } - - if (streamGeometry != null) - { - streamGeometryContext.Dispose(); - var path = CreateAndAdd(); - SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, null, 0); - path.Data = streamGeometry; - } - } - /// /// Gets the cached brush. /// @@ -798,7 +849,7 @@ private void SetStroke( IEnumerable dashArray = null, double dashOffset = 0) { - if (!stroke.IsUndefined() && thickness > 0) + if (thickness > 0 && !stroke.IsUndefined()) { shape.Stroke = GetCachedBrush(stroke); @@ -811,7 +862,7 @@ private void SetStroke( shape.StrokeJoin = PenLineJoin.Bevel; break; - // The default StrokeLineJoin is Miter + // The default StrokeLineJoin is Miter } if (thickness > 0) @@ -819,8 +870,9 @@ private void SetStroke( shape.StrokeThickness = thickness; } - if (dashArray != null) + if (dashArray != null) // what happens if thickness is 0? { + // ?????? shape.StrokeDashArray = new global::Avalonia.Collections.AvaloniaList(dashArray.Select(dash => dash)); shape.StrokeDashArray = new global::Avalonia.Collections.AvaloniaList(dashArray); shape.StrokeDashOffset = dashOffset; } @@ -1002,5 +1054,21 @@ private static List ToPointCollection(IEnumerable points, bo { return new List(aliased ? points.Select(ToPixelAlignedPoint) : points.Select(ToPoint)); } + + /// + /// Converts an to an array of . + /// + /// The rectangle. + /// A . + private static ScreenPoint[] RectangleToPolygon(OxyRect rect) + { + return new ScreenPoint[] + { + rect.BottomLeft, + rect.TopLeft, + rect.TopRight, + rect.BottomRight, + }; + } } } \ No newline at end of file diff --git a/Source/OxyPlot.Avalonia/PlotBase.cs b/Source/OxyPlot.Avalonia/PlotBase.cs index 872206e..0017c03 100644 --- a/Source/OxyPlot.Avalonia/PlotBase.cs +++ b/Source/OxyPlot.Avalonia/PlotBase.cs @@ -7,8 +7,6 @@ // // -------------------------------------------------------------------------------------------------------------------- -using Avalonia.Media; - namespace OxyPlot.Avalonia { using global::Avalonia; @@ -23,7 +21,6 @@ namespace OxyPlot.Avalonia using System.Collections.ObjectModel; using System.Linq; using System.Threading; - using CursorType = OxyPlot.CursorType; /// /// Represents a control that displays a . From 2189d5e529f4ad1227ae1d473a439bd1d6d2f98c Mon Sep 17 00:00:00 2001 From: BobLD Date: Mon, 20 Dec 2021 02:38:41 +0000 Subject: [PATCH 10/20] Minor update --- Source/OxyPlot.Avalonia/CanvasRenderContext.cs | 4 ++-- Source/OxyPlot.Avalonia/PlotBase.Events.cs | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs index 6779bab..9b732b2 100644 --- a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs +++ b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs @@ -499,7 +499,7 @@ public override void DrawRectangles(IList rectangles, double thickness, EdgeRenderingMode edgeRenderingMode) { - var polys = rectangles.Select(r => (IList)RectangleToPolygon(r)).ToList(); + var polys = rectangles.Select(r => RectangleToPolygon(r)).ToList(); DrawPolygons(polys, fill, stroke, thickness, edgeRenderingMode, null, LineJoin.Miter); } @@ -1060,7 +1060,7 @@ private static List ToPointCollection(IEnumerable points, bo /// /// The rectangle. /// A . - private static ScreenPoint[] RectangleToPolygon(OxyRect rect) + private static IList RectangleToPolygon(OxyRect rect) { return new ScreenPoint[] { diff --git a/Source/OxyPlot.Avalonia/PlotBase.Events.cs b/Source/OxyPlot.Avalonia/PlotBase.Events.cs index a33e2a6..d5840bf 100644 --- a/Source/OxyPlot.Avalonia/PlotBase.Events.cs +++ b/Source/OxyPlot.Avalonia/PlotBase.Events.cs @@ -141,8 +141,6 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e) return; } - var releasedArgs = (PointerReleasedEventArgs)e; - e.Pointer.Capture(null); if (e.Pointer.Type == PointerType.Touch) @@ -166,7 +164,7 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e) } else { - e.Handled = ActualController.HandleMouseUp(this, releasedArgs.ToMouseReleasedEventArgs(this)); + e.Handled = ActualController.HandleMouseUp(this, e.ToMouseReleasedEventArgs(this)); // Open the context menu var p = e.GetPosition(this).ToScreenPoint(); @@ -174,7 +172,7 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e) if (ContextMenu != null) { - if (Math.Abs(d) < 1e-8 && releasedArgs.InitialPressMouseButton == MouseButton.Right) + if (Math.Abs(d) < 1e-8 && e.InitialPressMouseButton == MouseButton.Right) { ContextMenu.DataContext = DataContext; ContextMenu.IsVisible = true; From 87c9d1a528c203ee2f496e0f5d981aa08dd9f4f1 Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Tue, 21 Dec 2021 10:16:09 +0000 Subject: [PATCH 11/20] Refit update mechanism --- Source/OxyPlot.Avalonia/IPlot.cs | 24 ++++++++++++++++++++++++ Source/OxyPlot.Avalonia/Plot.cs | 22 ++++++++++++++++++++-- Source/OxyPlot.Avalonia/PlotBase.cs | 2 +- Source/OxyPlot.Avalonia/Series/Series.cs | 14 ++++++-------- 4 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 Source/OxyPlot.Avalonia/IPlot.cs diff --git a/Source/OxyPlot.Avalonia/IPlot.cs b/Source/OxyPlot.Avalonia/IPlot.cs new file mode 100644 index 0000000..13b547d --- /dev/null +++ b/Source/OxyPlot.Avalonia/IPlot.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OxyPlot.Avalonia +{ + /// + /// Represents a control that displays a . + /// + public interface IPlot + { + /// + /// Signals that the appearance of an element has changed. + /// + /// The element whose appearance has changed. + void ElementAppearanceChanged(object element); + + /// + /// Signals that the data of an element has changed. + /// + /// The element whose data has changed. + void ElementDataChanged(object element); + } +} diff --git a/Source/OxyPlot.Avalonia/Plot.cs b/Source/OxyPlot.Avalonia/Plot.cs index cbe276d..bcccd8b 100644 --- a/Source/OxyPlot.Avalonia/Plot.cs +++ b/Source/OxyPlot.Avalonia/Plot.cs @@ -19,7 +19,7 @@ namespace OxyPlot.Avalonia /// /// Represents a control that displays a . /// - public partial class Plot : PlotBase + public partial class Plot : PlotBase, IPlot { /// /// The internal model. @@ -91,7 +91,7 @@ public override IPlotController ActualController /// Updates the model. If Model==null, an internal model will be created. The ActualModel.Update will be called (updates all series data). /// /// if set to true , all data collections will be updated. - protected override void UpdateModel(bool updateData = true) + protected new void UpdateModel(bool updateData = true) { SynchronizeProperties(); SynchronizeSeries(); @@ -99,6 +99,7 @@ protected override void UpdateModel(bool updateData = true) SynchronizeAnnotations(); SynchronizeLegends(); + // TODO: does this achieve anything? we always call InvalidatePlot after UpdateModel base.UpdateModel(updateData); } @@ -111,6 +112,21 @@ protected void OnAppearanceChanged() InvalidatePlot(false); } + void IPlot.ElementAppearanceChanged(object element) + { + // TODO: determine type of element to perform a more fine-grained update + this.UpdateModel(false); + base.InvalidatePlot(false); + } + + void IPlot.ElementDataChanged(object element) + { + // TODO: determine type of element to perform a more fine-grained update + this.UpdateModel(true); + base.InvalidatePlot(true); + } + + /// /// Called when the visual appearance is changed. /// @@ -182,6 +198,8 @@ private void SyncLogicalTree(NotifyCollectionChangedEventArgs e) VisualChildren.Remove((IVisual)item); } } + + this.OnAppearanceChanged(); } /// diff --git a/Source/OxyPlot.Avalonia/PlotBase.cs b/Source/OxyPlot.Avalonia/PlotBase.cs index 0017c03..08d5b28 100644 --- a/Source/OxyPlot.Avalonia/PlotBase.cs +++ b/Source/OxyPlot.Avalonia/PlotBase.cs @@ -384,7 +384,7 @@ protected override Size ArrangeOverride(Size finalSize) /// Updates the model. /// /// The update Data. - protected virtual void UpdateModel(bool updateData = true) + protected void UpdateModel(bool updateData = true) { if (ActualModel != null) { diff --git a/Source/OxyPlot.Avalonia/Series/Series.cs b/Source/OxyPlot.Avalonia/Series/Series.cs index 49072c4..3f2d342 100644 --- a/Source/OxyPlot.Avalonia/Series/Series.cs +++ b/Source/OxyPlot.Avalonia/Series/Series.cs @@ -78,6 +78,10 @@ static Series() protected Series() { eventListener = new EventListener(OnCollectionChanged); + + // Set Items to null for consistency with WPF behaviour in Oxyplot-Contrib + // Works around issue with BarSeriesManager throwing on empty Items collection in OxyPlot.Core 2.1 + Items = null; } /// @@ -212,10 +216,7 @@ protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEvent /// protected void OnDataChanged() { - if (Parent is IPlotView pc) - { - pc.InvalidatePlot(); - } + (((Series)this).Parent as IPlot)?.ElementDataChanged(this); } /// @@ -234,10 +235,7 @@ protected override void ItemsChanged(AvaloniaPropertyChangedEventArgs e) /// protected void OnVisualChanged() { - if (Parent is IPlotView pc) - { - pc.InvalidatePlot(false); - } + (((Series)this).Parent as IPlot)?.ElementAppearanceChanged(this); } protected override void OnAttachedToLogicalTree(global::Avalonia.LogicalTree.LogicalTreeAttachmentEventArgs e) From 9eb7947ebe0260aa9274c3b3acc29a468fd56896 Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Tue, 21 Dec 2021 10:22:38 +0000 Subject: [PATCH 12/20] Refit for Annotations, Axes, and Legends --- .../Annotations/Annotation.cs | 26 +++++++++++++------ Source/OxyPlot.Avalonia/Axes/Axis.cs | 24 +++++++---------- Source/OxyPlot.Avalonia/Legends/Legend.cs | 26 +++++++++++++------ Source/OxyPlot.Avalonia/Series/Series.cs | 20 +++++++------- 4 files changed, 55 insertions(+), 41 deletions(-) diff --git a/Source/OxyPlot.Avalonia/Annotations/Annotation.cs b/Source/OxyPlot.Avalonia/Annotations/Annotation.cs index 4461f76..29a45d1 100644 --- a/Source/OxyPlot.Avalonia/Annotations/Annotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/Annotation.cs @@ -133,10 +133,15 @@ public virtual void SynchronizeProperties() /// The instance containing the event data. protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - if (((Annotation)d).Parent is IPlotView pc) - { - pc.InvalidatePlot(false); - } + ((Annotation)d).OnVisualChanged(); + } + + /// + /// The on visual changed handler. + /// + protected void OnVisualChanged() + { + (this.Parent as IPlot)?.ElementAppearanceChanged(this); } /// @@ -146,10 +151,15 @@ protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChange /// The instance containing the event data. protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - if (((Annotation)d).Parent is IPlotView pc) - { - pc.InvalidatePlot(); - } + ((Annotation)d).OnDataChanged(); + } + + /// + /// The on data changed handler. + /// + protected void OnDataChanged() + { + (this.Parent as IPlot)?.ElementDataChanged(this); } static Annotation() diff --git a/Source/OxyPlot.Avalonia/Axes/Axis.cs b/Source/OxyPlot.Avalonia/Axes/Axis.cs index 05d67d2..5106169 100644 --- a/Source/OxyPlot.Avalonia/Axes/Axis.cs +++ b/Source/OxyPlot.Avalonia/Axes/Axis.cs @@ -1459,6 +1459,14 @@ protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChange ((Axis)d).OnVisualChanged(); } + /// + /// The on visual changed handler. + /// + protected void OnVisualChanged() + { + (this.Parent as IPlot)?.ElementAppearanceChanged(this); + } + /// /// The data changed. /// @@ -1474,10 +1482,7 @@ protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEvent /// protected void OnDataChanged() { - if (Parent is IPlotView pc) - { - pc.InvalidatePlot(); - } + (this.Parent as IPlot)?.ElementDataChanged(this); } /// @@ -1493,17 +1498,6 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs } } - /// - /// Handles changed visuals. - /// - protected void OnVisualChanged() - { - if (Parent is IPlotView pc) - { - pc.InvalidatePlot(false); - } - } - /// /// Synchronizes the properties. /// diff --git a/Source/OxyPlot.Avalonia/Legends/Legend.cs b/Source/OxyPlot.Avalonia/Legends/Legend.cs index c9d5744..a6761f6 100644 --- a/Source/OxyPlot.Avalonia/Legends/Legend.cs +++ b/Source/OxyPlot.Avalonia/Legends/Legend.cs @@ -79,10 +79,15 @@ private void SynchronizeProperties() /// The instance containing the event data. protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - if (((Legend)d).Parent is IPlotView pc) - { - pc.InvalidatePlot(false); - } + ((Legend)d).OnVisualChanged(); + } + + /// + /// The on visual changed handler. + /// + protected void OnVisualChanged() + { + (this.Parent as IPlot)?.ElementAppearanceChanged(this); } /// @@ -92,10 +97,15 @@ protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChange /// The instance containing the event data. protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - if (((Legend)d).Parent is IPlotView pc) - { - pc.InvalidatePlot(); - } + ((Legend)d).OnDataChanged(); + } + + /// + /// The on data changed handler. + /// + protected void OnDataChanged() + { + (this.Parent as IPlot)?.ElementDataChanged(this); } static Legend() diff --git a/Source/OxyPlot.Avalonia/Series/Series.cs b/Source/OxyPlot.Avalonia/Series/Series.cs index 3f2d342..06e7b98 100644 --- a/Source/OxyPlot.Avalonia/Series/Series.cs +++ b/Source/OxyPlot.Avalonia/Series/Series.cs @@ -201,6 +201,14 @@ protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChange ((Series)d).OnVisualChanged(); } + /// + /// The on visual changed handler. + /// + protected void OnVisualChanged() + { + (this.Parent as IPlot)?.ElementAppearanceChanged(this); + } + /// /// The data changed. /// @@ -212,11 +220,11 @@ protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEvent } /// - /// The on data changed. + /// The on data changed handler. /// protected void OnDataChanged() { - (((Series)this).Parent as IPlot)?.ElementDataChanged(this); + (this.Parent as IPlot)?.ElementDataChanged(this); } /// @@ -230,14 +238,6 @@ protected override void ItemsChanged(AvaloniaPropertyChangedEventArgs e) OnDataChanged(); } - /// - /// The on visual changed. - /// - protected void OnVisualChanged() - { - (((Series)this).Parent as IPlot)?.ElementAppearanceChanged(this); - } - protected override void OnAttachedToLogicalTree(global::Avalonia.LogicalTree.LogicalTreeAttachmentEventArgs e) { base.OnAttachedToLogicalTree(e); From 4c4622eba4cfc41abc8d96d37181da49e29969f4 Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Tue, 21 Dec 2021 11:29:31 +0000 Subject: [PATCH 13/20] Fix EllipseAnnotation --- .../AvaloniaExamples/Examples/AnnotationDemo/MainWindow.xaml | 4 +++- Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/AnnotationDemo/MainWindow.xaml b/Source/Examples/Avalonia/AvaloniaExamples/Examples/AnnotationDemo/MainWindow.xaml index f2d57bf..acf27ba 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/AnnotationDemo/MainWindow.xaml +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/AnnotationDemo/MainWindow.xaml @@ -24,7 +24,9 @@ - + + + diff --git a/Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs index d2e20e1..1250aae 100644 --- a/Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs @@ -36,6 +36,8 @@ static EllipseAnnotation() XProperty.Changed.AddClassHandler(DataChanged); YProperty.Changed.AddClassHandler(DataChanged); + WidthProperty.Changed.AddClassHandler(DataChanged); + HeightProperty.Changed.AddClassHandler(DataChanged); } /// From 5e986d0c2c1094bf5eb68261de0c06f974954f07 Mon Sep 17 00:00:00 2001 From: BobLD Date: Tue, 21 Dec 2021 11:46:46 +0000 Subject: [PATCH 14/20] Fix polyline annotation issue --- .../Examples/Avalonia/AvaloniaExamples/App.xaml.cs | 1 - .../Examples/AnnotationDemo/MainWindow.xaml.cs | 14 +++++--------- .../Avalonia/ExampleBrowser/MainWindow.xaml | 6 +++--- .../Annotations/PolylineAnnotation.cs | 1 + 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Source/Examples/Avalonia/AvaloniaExamples/App.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/App.xaml.cs index 82d23f0..3d40e69 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/App.xaml.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/App.xaml.cs @@ -9,7 +9,6 @@ namespace AvaloniaExamples { public class App : Application { - public override void Initialize() { AvaloniaXamlLoader.Load(this); diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/AnnotationDemo/MainWindow.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/AnnotationDemo/MainWindow.xaml.cs index 61c1cbf..f8366aa 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/AnnotationDemo/MainWindow.xaml.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/AnnotationDemo/MainWindow.xaml.cs @@ -9,12 +9,9 @@ namespace AvaloniaExamples.Examples.AnnotationDemo { - using System.Collections.Generic; - using System.Windows; - - using OxyPlot; - using AvaloniaExamples; + using OxyPlot; + using System.Collections.Generic; /// /// Interaction logic for MainWindow.xaml @@ -29,13 +26,12 @@ public MainWindow() { this.InitializeComponent(); this.Points = new List - { - new DataPoint(10, 10), new DataPoint(80, 30), new DataPoint(60, 70) - }; + { + new DataPoint(10, 10), new DataPoint(80, 30), new DataPoint(60, 70) + }; this.DataContext = new { Points }; } - private void InitializeComponent() { Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(this); diff --git a/Source/Examples/Avalonia/ExampleBrowser/MainWindow.xaml b/Source/Examples/Avalonia/ExampleBrowser/MainWindow.xaml index 248fc84..7248c80 100644 --- a/Source/Examples/Avalonia/ExampleBrowser/MainWindow.xaml +++ b/Source/Examples/Avalonia/ExampleBrowser/MainWindow.xaml @@ -20,16 +20,16 @@ - + - + - + diff --git a/Source/OxyPlot.Avalonia/Annotations/PolylineAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/PolylineAnnotation.cs index 9af4acc..33772d0 100644 --- a/Source/OxyPlot.Avalonia/Annotations/PolylineAnnotation.cs +++ b/Source/OxyPlot.Avalonia/Annotations/PolylineAnnotation.cs @@ -47,6 +47,7 @@ static PolylineAnnotation() TextVerticalAlignmentProperty.Changed.AddClassHandler(AppearanceChanged); InterpolationAlgorithmProperty.Changed.AddClassHandler(DataChanged); + PointsProperty.Changed.AddClassHandler(DataChanged); } /// From 8b36ba90d5906b3b7154d59ab270a9ae95f2a6c2 Mon Sep 17 00:00:00 2001 From: BobLD Date: Tue, 21 Dec 2021 12:03:04 +0000 Subject: [PATCH 15/20] Fix Setting Foreground on PieSeries breaking its text --- .../Examples/PieDemo/MainWindow.xaml | 4 +- .../Examples/PieDemo/MainWindow.xaml.cs | 2 +- .../Utilities/ConverterExtensions.cs | 93 ++++++++++--------- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/PieDemo/MainWindow.xaml b/Source/Examples/Avalonia/AvaloniaExamples/Examples/PieDemo/MainWindow.xaml index 92f1874..49ff513 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/PieDemo/MainWindow.xaml +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/PieDemo/MainWindow.xaml @@ -17,7 +17,9 @@ Stroke="Black" StrokeThickness="1" StartAngle="0" AngleSpan="360" Items="{Binding Continents}" - LabelField="Name" ValueField="PopulationInMillions" IsExplodedField="IsExploded" /> + LabelField="Name" ValueField="PopulationInMillions" + IsExplodedField="IsExploded" + Foreground="BlueViolet"/> diff --git a/Source/Examples/Avalonia/AvaloniaExamples/Examples/PieDemo/MainWindow.xaml.cs b/Source/Examples/Avalonia/AvaloniaExamples/Examples/PieDemo/MainWindow.xaml.cs index f6add99..f91a980 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/PieDemo/MainWindow.xaml.cs +++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/PieDemo/MainWindow.xaml.cs @@ -31,7 +31,7 @@ public MainWindow() // http://en.wikipedia.org/wiki/Continent var plotModel = new PlotModel { Title = "World population by continent" }; - var pieSeries = new PieSeries(); + var pieSeries = new PieSeries() { TextColor = OxyColors.BlueViolet }; pieSeries.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = true }); pieSeries.Slices.Add(new PieSlice("Americas", 929) { IsExploded = true }); pieSeries.Slices.Add(new PieSlice("Asia", 4157)); diff --git a/Source/OxyPlot.Avalonia/Utilities/ConverterExtensions.cs b/Source/OxyPlot.Avalonia/Utilities/ConverterExtensions.cs index f8c2f65..df18cd3 100644 --- a/Source/OxyPlot.Avalonia/Utilities/ConverterExtensions.cs +++ b/Source/OxyPlot.Avalonia/Utilities/ConverterExtensions.cs @@ -12,9 +12,8 @@ namespace OxyPlot.Avalonia using global::Avalonia; using global::Avalonia.Input; using global::Avalonia.Media; + using global::Avalonia.Media.Immutable; using System; - using HorizontalAlignment = OxyPlot.HorizontalAlignment; - using VerticalAlignment = OxyPlot.VerticalAlignment; /// /// Extension method used to convert to/from Windows/Windows.Media classes. @@ -127,7 +126,15 @@ public static OxyColor ToOxyColor(this Color color) /// An . public static OxyColor ToOxyColor(this IBrush brush) { - return brush is SolidColorBrush scb ? scb.Color.ToOxyColor() : OxyColors.Undefined; + if (brush is ImmutableSolidColorBrush iscb) + { + return iscb.Color.ToOxyColor(); + } + else if (brush is SolidColorBrush scb) + { + return scb.Color.ToOxyColor(); + } + return OxyColors.Undefined; } /// @@ -484,51 +491,51 @@ public static OxyMouseEventArgs ToMouseEventArgs(this PointerEventArgs e, IInput }; } - /** Touch Events currently not supported in Avalonia - /// - /// Converts to for a touch started event. - /// - /// The instance containing the event data. - /// The that the event is relative to. - /// A containing the converted event arguments. - public static OxyTouchEventArgs ToTouchEventArgs(this ManipulationStartedEventArgs e, UIElement relativeTo) - { - return new OxyTouchEventArgs + /** Touch Events currently not supported in Avalonia + /// + /// Converts to for a touch started event. + /// + /// The instance containing the event data. + /// The that the event is relative to. + /// A containing the converted event arguments. + public static OxyTouchEventArgs ToTouchEventArgs(this ManipulationStartedEventArgs e, UIElement relativeTo) { - Position = e.ManipulationOrigin.ToScreenPoint(), - }; - } + return new OxyTouchEventArgs + { + Position = e.ManipulationOrigin.ToScreenPoint(), + }; + } - /// - /// Converts to for a touch delta event. - /// - /// The instance containing the event data. - /// The that the event is relative to. - /// A containing the converted event arguments. - public static OxyTouchEventArgs ToTouchEventArgs(this ManipulationDeltaEventArgs e, UIElement relativeTo) - { - return new OxyTouchEventArgs + /// + /// Converts to for a touch delta event. + /// + /// The instance containing the event data. + /// The that the event is relative to. + /// A containing the converted event arguments. + public static OxyTouchEventArgs ToTouchEventArgs(this ManipulationDeltaEventArgs e, UIElement relativeTo) { - Position = e.ManipulationOrigin.ToScreenPoint(), - DeltaTranslation = e.DeltaManipulation.Translation.ToScreenVector(), - DeltaScale = e.DeltaManipulation.Scale.ToScreenVector() - }; - } + return new OxyTouchEventArgs + { + Position = e.ManipulationOrigin.ToScreenPoint(), + DeltaTranslation = e.DeltaManipulation.Translation.ToScreenVector(), + DeltaScale = e.DeltaManipulation.Scale.ToScreenVector() + }; + } - /// - /// Converts to for a touch completed event. - /// - /// The instance containing the event data. - /// The that the event is relative to. - /// A containing the converted event arguments. - public static OxyTouchEventArgs ToTouchEventArgs(this ManipulationCompletedEventArgs e, UIElement relativeTo) - { - return new OxyTouchEventArgs + /// + /// Converts to for a touch completed event. + /// + /// The instance containing the event data. + /// The that the event is relative to. + /// A containing the converted event arguments. + public static OxyTouchEventArgs ToTouchEventArgs(this ManipulationCompletedEventArgs e, UIElement relativeTo) { - Position = e.ManipulationOrigin.ToScreenPoint() - }; - } + return new OxyTouchEventArgs + { + Position = e.ManipulationOrigin.ToScreenPoint() + }; + } - */ + */ } } \ No newline at end of file From 914662e846007234866b5611330e35767d3309ae Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Tue, 21 Dec 2021 13:36:11 +0000 Subject: [PATCH 16/20] Target Avalonia 0.10.11 --- Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj b/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj index a443b8e..44b7f8c 100644 --- a/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj +++ b/Source/OxyPlot.Avalonia/OxyPlot.Avalonia.csproj @@ -15,7 +15,7 @@ - + From 2d639bf5d85271cbffe57f78ce056f17a7af9991 Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Tue, 21 Dec 2021 15:40:39 +0000 Subject: [PATCH 17/20] Target Avalonia 0.10.11 in examples --- .../Avalonia/AvaloniaExamples/AvaloniaExamples.csproj | 4 ++-- Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj | 4 ++-- Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj | 4 ++-- Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Examples/Avalonia/AvaloniaExamples/AvaloniaExamples.csproj b/Source/Examples/Avalonia/AvaloniaExamples/AvaloniaExamples.csproj index af78460..c00236a 100644 --- a/Source/Examples/Avalonia/AvaloniaExamples/AvaloniaExamples.csproj +++ b/Source/Examples/Avalonia/AvaloniaExamples/AvaloniaExamples.csproj @@ -12,7 +12,7 @@ - - + + \ No newline at end of file diff --git a/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj b/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj index 245e351..c684f30 100644 --- a/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj +++ b/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj b/Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj index af78460..c00236a 100644 --- a/Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj +++ b/Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj @@ -12,7 +12,7 @@ - - + + \ No newline at end of file diff --git a/Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj b/Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj index 59b93ff..ff70a6a 100644 --- a/Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj +++ b/Source/Examples/Avalonia/SimpleDemo/SimpleDemo.csproj @@ -13,7 +13,7 @@ - - + + \ No newline at end of file From 88f037969431655658b0fb16893dcef39a56aa4c Mon Sep 17 00:00:00 2001 From: BobLD Date: Tue, 21 Dec 2021 16:28:57 +0000 Subject: [PATCH 18/20] Fix issue in DrawPolygons() when UseStreamGeometry is false --- Source/OxyPlot.Avalonia/CanvasRenderContext.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs index 9b732b2..31a3311 100644 --- a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs +++ b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs @@ -388,7 +388,6 @@ public override void DrawPolygons( } Path path = null; - StreamGeometryContext sgc = null; PathGeometry pathGeometry = null; var count = 0; @@ -441,7 +440,7 @@ public override void DrawPolygons( } else { - sgc.LineTo(toPointFunc(p)); + figure.Segments.Add(new LineSegment { Point = toPointFunc(p) }); } } From 6d5be4c0b1a8ecf1d15da45f57f0005c25ae93fb Mon Sep 17 00:00:00 2001 From: BobLD Date: Thu, 23 Dec 2021 18:04:03 +0000 Subject: [PATCH 19/20] Fix CanvasRenderContext's issue with DrawLineSegments() not overriden --- Source/OxyPlot.Avalonia/CanvasRenderContext.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs index 31a3311..89f56b0 100644 --- a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs +++ b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs @@ -211,16 +211,16 @@ private void DrawLineSegmentsByStreamGeometry( /// The points. /// The stroke color. /// The stroke thickness (in device independent units, 1/96 inch). + /// The edge rendering mode. /// The dash array (in device independent units, 1/96 inch). /// The line join type. - /// The edge rendering mode. - public void DrawLineSegments( + public override void DrawLineSegments( IList points, OxyColor stroke, double thickness, + EdgeRenderingMode edgeRenderingMode, double[] dashArray, - LineJoin lineJoin, - EdgeRenderingMode edgeRenderingMode) + LineJoin lineJoin) { if (UseStreamGeometry) { From 00c683fdb0960b3ffa5845e4cbd07520ce5585ce Mon Sep 17 00:00:00 2001 From: BobLD Date: Thu, 23 Dec 2021 20:42:04 +0000 Subject: [PATCH 20/20] Add DrawEllipsesByStreamGeometry and replace isDefined by isSolid --- .../OxyPlot.Avalonia/CanvasRenderContext.cs | 104 ++++++++++++++++-- 1 file changed, 96 insertions(+), 8 deletions(-) diff --git a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs index 89f56b0..476755d 100644 --- a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs +++ b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs @@ -94,6 +94,7 @@ public CanvasRenderContext(Canvas canvas) /// The XamlWriter does not serialize StreamGeometry, so set this to false if you want to export to XAML. Using stream geometry seems to be slightly faster than using path geometry. public bool UseStreamGeometry { get; set; } + #region DrawEllipse(s) /// public override void DrawEllipse(OxyRect rect, OxyColor fill, @@ -110,6 +111,86 @@ public override void DrawEllipse(OxyRect rect, path.Data = new EllipseGeometry(ToRect(rect)); } + private void DrawEllipsesByStreamGeometry( + IList rects, + OxyColor fill, + OxyColor stroke, + double thickness, + EdgeRenderingMode edgeRenderingMode, + double[] dashArray, + LineJoin lineJoin) + { + const double ratio = 0.55228475; // (Math.Sqrt(2) - 1.0) * 4.0 / 3.0; + + Path path = null; + StreamGeometry streamGeometry = null; + StreamGeometryContext sgc = null; + var count = 0; + + bool isSolid = !fill.IsUndefined(); + IBrush cachedBrush = null; + if (isSolid) + { + cachedBrush = GetCachedBrush(fill); + } + + foreach (var rect in rects) + { + if (path == null) + { + path = CreateAndAdd(); + SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); + if (isSolid) + { + path.Fill = cachedBrush; + } + + streamGeometry = new StreamGeometry(); + sgc = streamGeometry.Open(); + sgc.SetFillRule(FillRule.NonZero); + } + + var a = rect.Width / 2.0; + var b = rect.Height / 2.0; + + var x0 = rect.Center.X - a; + var x1 = rect.Center.X - a * ratio; + var x2 = rect.Center.X; + var x3 = rect.Center.X + a * ratio; + var x4 = rect.Center.X + a; + + var y0 = rect.Center.Y - b; + var y1 = rect.Center.Y - b * ratio; + var y2 = rect.Center.Y; + var y3 = rect.Center.Y + b * ratio; + var y4 = rect.Center.Y + b; + + sgc.BeginFigure(new Point(x2, y0), isSolid); + sgc.CubicBezierTo(new Point(x3, y0), new Point(x4, y1), new Point(x4, y2)); + sgc.CubicBezierTo(new Point(x4, y3), new Point(x3, y4), new Point(x2, y4)); + sgc.CubicBezierTo(new Point(x1, y4), new Point(x0, y3), new Point(x0, y2)); + sgc.CubicBezierTo(new Point(x0, y1), new Point(x1, y0), new Point(x2, y0)); + sgc.EndFigure(true); + + count++; + + // Must limit the number of figures, otherwise drawing errors... + if (count > MaxFiguresPerGeometry) + { + sgc.Dispose(); + path.Data = streamGeometry; + path = null; + count = 0; + } + } + + if (path != null) + { + sgc.Dispose(); + path.Data = streamGeometry; + } + } + /// public override void DrawEllipses(IList rectangles, OxyColor fill, @@ -117,11 +198,18 @@ public override void DrawEllipses(IList rectangles, double thickness, EdgeRenderingMode edgeRenderingMode) { + if (UseStreamGeometry) + { + DrawEllipsesByStreamGeometry(rectangles, fill, stroke, thickness, edgeRenderingMode, null, LineJoin.Miter); + return; + } + foreach (var rect in rectangles) { DrawEllipse(rect, fill, stroke, thickness, edgeRenderingMode); } } + #endregion /// public override void DrawLine( @@ -313,9 +401,9 @@ private void DrawPolygonsByStreamGeometry( toPointFunc = ToPoint; } - bool isDefined = !fill.IsUndefined(); + bool isSolid = !fill.IsUndefined(); IBrush cachedBrush = null; - if (isDefined) + if (isSolid) { cachedBrush = GetCachedBrush(fill); } @@ -326,7 +414,7 @@ private void DrawPolygonsByStreamGeometry( { path = CreateAndAdd(); SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); - if (isDefined) + if (isSolid) { path.Fill = cachedBrush; } @@ -341,7 +429,7 @@ private void DrawPolygonsByStreamGeometry( { if (first) { - sgc.BeginFigure(toPointFunc(p), isDefined); + sgc.BeginFigure(toPointFunc(p), isSolid); first = false; } else @@ -401,9 +489,9 @@ public override void DrawPolygons( toPointFunc = ToPoint; } - bool isDefined = !fill.IsUndefined(); + bool isSolid = !fill.IsUndefined(); IBrush cachedBrush = null; - if (isDefined) + if (isSolid) { cachedBrush = GetCachedBrush(fill); } @@ -414,7 +502,7 @@ public override void DrawPolygons( { path = CreateAndAdd(); SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); - if (isDefined) + if (isSolid) { path.Fill = cachedBrush; } @@ -431,7 +519,7 @@ public override void DrawPolygons( figure = new PathFigure { StartPoint = toPointFunc(p), - IsFilled = isDefined, + IsFilled = isSolid, IsClosed = true }; pathGeometry.Figures.Add(figure);