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/AvaloniaExamples.csproj b/Source/Examples/Avalonia/AvaloniaExamples/AvaloniaExamples.csproj
index c26ff98..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/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/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/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/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/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml
index 6b50d2b..29e1b4d 100644
--- a/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml
+++ b/Source/Examples/Avalonia/AvaloniaExamples/Examples/BarSeriesDemo/MainWindow.xaml
@@ -9,7 +9,10 @@
-
+
+
+
+
@@ -18,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 768cef1..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,16 @@
//
// --------------------------------------------------------------------------------------------------------------------
-using System.Collections.ObjectModel;
-using System.Windows;
using OxyPlot;
+using System.Collections.ObjectModel;
namespace AvaloniaExamples.Examples.BarSeriesDemo
{
+ using AvaloniaExamples;
using OxyPlot.Axes;
+ using OxyPlot.Legends;
using OxyPlot.Series;
- using AvaloniaExamples;
-
///
/// Interaction logic for MainWindow.xaml
///
@@ -26,18 +25,17 @@ 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}
- };
+ {
+ 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", 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" });
@@ -47,9 +45,12 @@ 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 };
+ this.InitializeComponent();
+
App.AttachDevTools(this);
}
@@ -65,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/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/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/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/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
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/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/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj b/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj
index 3800346..c684f30 100644
--- a/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj
+++ b/Source/Examples/Avalonia/ExampleBrowser/ExampleBrowser.csproj
@@ -12,10 +12,10 @@
-
-
-
-
+
+
+
+
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/Examples/Avalonia/MemoryTest/MemoryTest.csproj b/Source/Examples/Avalonia/MemoryTest/MemoryTest.csproj
index c26ff98..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 1bc2ceb..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
diff --git a/Source/OxyPlot.Avalonia/Annotations/Annotation.cs b/Source/OxyPlot.Avalonia/Annotations/Annotation.cs
index 1dc4a7d..29a45d1 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;
}
///
@@ -111,11 +133,15 @@ 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)
- {
- pc.InvalidatePlot(false);
- }
+ ((Annotation)d).OnVisualChanged();
+ }
+
+ ///
+ /// The on visual changed handler.
+ ///
+ protected void OnVisualChanged()
+ {
+ (this.Parent as IPlot)?.ElementAppearanceChanged(this);
}
///
@@ -125,11 +151,15 @@ 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)
- {
- pc.InvalidatePlot();
- }
+ ((Annotation)d).OnDataChanged();
+ }
+
+ ///
+ /// The on data changed handler.
+ ///
+ protected void OnDataChanged()
+ {
+ (this.Parent as IPlot)?.ElementDataChanged(this);
}
static Annotation()
@@ -137,6 +167,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/Annotations/EllipseAnnotation.cs b/Source/OxyPlot.Avalonia/Annotations/EllipseAnnotation.cs
index cf00b33..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);
}
///
@@ -47,7 +49,7 @@ public EllipseAnnotation()
}
///
- /// Gets or sets the X.
+ /// Gets or sets the X.
///
public double X
{
@@ -63,7 +65,7 @@ public double X
}
///
- /// Gets or sets the Y.
+ /// Gets or sets the Y.
///
public double Y
{
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/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/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);
}
///
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 460feb1..5106169 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.
///
@@ -269,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.
///
@@ -330,6 +350,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.
///
@@ -900,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.
///
@@ -948,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.
///
@@ -1338,6 +1427,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.
///
@@ -1354,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.
///
@@ -1369,11 +1482,7 @@ protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEvent
///
protected void OnDataChanged()
{
- var pc = Parent as IPlotView;
- if (pc != null)
- {
- pc.InvalidatePlot();
- }
+ (this.Parent as IPlot)?.ElementDataChanged(this);
}
///
@@ -1383,25 +1492,9 @@ protected void OnDataChanged()
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
- if (e.Property.OwnerType == GetType())
- {
- var plot = Parent as IPlotView;
- if (plot != null)
- {
- plot.InvalidatePlot();
- }
- }
- }
-
- ///
- /// Handles changed visuals.
- ///
- protected void OnVisualChanged()
- {
- var pc = Parent as IPlotView;
- if (pc != null)
+ if (e.Property.OwnerType == GetType() && Parent is IPlotView plot)
{
- pc.InvalidatePlot(false);
+ plot.InvalidatePlot();
}
}
@@ -1454,6 +1547,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;
@@ -1468,12 +1565,13 @@ 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;
a.UseSuperExponentialFormat = UseSuperExponentialFormat;
a.LabelFormatter = LabelFormatter;
+ a.EdgeRenderingMode = EdgeRenderingMode;
}
static Axis()
@@ -1510,9 +1608,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);
@@ -1538,6 +1640,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/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 6f1e442..476755d 100644
--- a/Source/OxyPlot.Avalonia/CanvasRenderContext.cs
+++ b/Source/OxyPlot.Avalonia/CanvasRenderContext.cs
@@ -18,15 +18,12 @@ 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 : IRenderContext
+ public class CanvasRenderContext : ClippingRenderContext
{
///
/// The maximum number of figures per geometry.
@@ -57,11 +54,11 @@ public class CanvasRenderContext : IRenderContext
/// 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 : IRenderContext
/// The current tool tip
///
private string currentToolTip;
-
+
///
/// Initializes a new instance of the class.
///
@@ -80,7 +77,7 @@ public class CanvasRenderContext : IRenderContext
public CanvasRenderContext(Canvas canvas)
{
this.canvas = canvas;
- UseStreamGeometry = false; // Temporarily disabled because of Avalonia bug
+ UseStreamGeometry = true;
RendersToScreen = true;
BalancedLineDrawingThicknessLimit = 3.5;
}
@@ -97,79 +94,204 @@ 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; }
+ #region DrawEllipse(s)
+ ///
+ public override void DrawEllipse(OxyRect rect,
+ OxyColor fill,
+ OxyColor stroke,
+ double thickness,
+ EdgeRenderingMode edgeRenderingMode)
+ {
+ var path = CreateAndAdd();
+ SetStroke(path, stroke, thickness, edgeRenderingMode);
+ if (!fill.IsUndefined())
+ {
+ path.Fill = GetCachedBrush(fill);
+ }
+ path.Data = new EllipseGeometry(ToRect(rect));
+ }
- ///
- /// 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)
+ private void DrawEllipsesByStreamGeometry(
+ IList rects,
+ OxyColor fill,
+ OxyColor stroke,
+ double thickness,
+ EdgeRenderingMode edgeRenderingMode,
+ double[] dashArray,
+ LineJoin lineJoin)
{
- var e = CreateAndAdd(rect.Left, rect.Top);
- SetStroke(e, stroke, thickness);
- if (fill.IsVisible())
+ 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)
{
- e.Fill = GetCachedBrush(fill);
+ cachedBrush = GetCachedBrush(fill);
}
- e.Width = rect.Width;
- e.Height = rect.Height;
- Canvas.SetLeft(e, rect.Left);
- Canvas.SetTop(e, rect.Top);
+ 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;
+ }
}
- ///
- /// 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 override void DrawEllipses(IList rectangles,
+ OxyColor fill,
+ OxyColor stroke,
+ 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);
+ DrawEllipse(rect, fill, stroke, thickness, edgeRenderingMode);
}
}
+ #endregion
- ///
- /// 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);
}
+ #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.
@@ -177,23 +299,25 @@ public void DrawLine(
/// 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.
- /// if set to true the shape will be aliased.
- public void DrawLineSegments(
+ public override void DrawLineSegments(
IList points,
OxyColor stroke,
double thickness,
+ EdgeRenderingMode edgeRenderingMode,
double[] dashArray,
- LineJoin lineJoin,
- bool aliased)
+ LineJoin lineJoin)
{
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 +328,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();
}
@@ -228,121 +352,183 @@ public void DrawLineSegments(
path.Data = pathGeometry;
}
}
+ #endregion
- ///
- /// 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(
+ #region DrawPolygon(s)
+ ///
+ 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(
+ private void DrawPolygonsByStreamGeometry(
IList> polygons,
OxyColor fill,
OxyColor stroke,
double thickness,
+ EdgeRenderingMode edgeRenderingMode,
double[] dashArray,
- LineJoin lineJoin,
- bool aliased)
+ 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 isSolid = !fill.IsUndefined();
+ IBrush cachedBrush = null;
+ if (isSolid)
+ {
+ cachedBrush = GetCachedBrush(fill);
+ }
+
foreach (var polygon in polygons)
{
if (path == null)
{
path = CreateAndAdd();
- SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased);
- if (!fill.IsUndefined())
+ SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0);
+ if (isSolid)
{
- 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), isSolid);
+ first = false;
}
else
{
- pathGeometry = new PathGeometry { FillRule = FillRule.NonZero };
+ sgc.LineTo(toPointFunc(p));
}
}
+ 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;
+ PathGeometry pathGeometry = null;
+ var count = 0;
+
+ Func toPointFunc;
+ if (edgeRenderingMode == EdgeRenderingMode.PreferSpeed) // aliased
+ {
+ toPointFunc = ToPixelAlignedPoint;
+ }
+ else
+ {
+ toPointFunc = ToPoint;
+ }
+
+ bool isSolid = !fill.IsUndefined();
+ IBrush cachedBrush = null;
+ if (isSolid)
+ {
+ cachedBrush = GetCachedBrush(fill);
+ }
+
+ foreach (var polygon in polygons)
+ {
+ if (path == null)
+ {
+ path = CreateAndAdd();
+ SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0);
+ if (isSolid)
+ {
+ 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)
- {
- sgc.BeginFigure(point, !fill.IsUndefined());
- }
- else
+ figure = new PathFigure
{
- figure = new PathFigure
- {
- StartPoint = point,
- IsFilled = !fill.IsUndefined(),
- IsClosed = true
- };
- pathGeometry.Figures.Add(figure);
- }
+ StartPoint = toPointFunc(p),
+ IsFilled = isSolid,
+ IsClosed = true
+ };
+ pathGeometry.Figures.Add(figure);
first = false;
}
else
{
- if (usg)
- {
- sgc.LineTo(point);
- }
- else
- {
- figure.Segments.Add(new LineSegment { Point = point });
- }
+ figure.Segments.Add(new LineSegment { Point = toPointFunc(p) });
}
}
@@ -351,16 +537,7 @@ public 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;
}
@@ -368,17 +545,10 @@ public void DrawPolygons(
if (path != null)
{
- if (usg)
- {
- sgc.Dispose();
- path.Data = streamGeometry;
- }
- else
- {
- path.Data = pathGeometry;
- }
+ path.Data = pathGeometry;
}
}
+ #endregion
///
/// Draws a rectangle.
@@ -387,20 +557,19 @@ 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);
-
+ 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));
}
///
@@ -411,12 +580,14 @@ 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);
- }
+ var polys = rectangles.Select(r => RectangleToPolygon(r)).ToList();
+ DrawPolygons(polys, fill, stroke, thickness, edgeRenderingMode, null, LineJoin.Miter);
}
///
@@ -432,7 +603,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,
@@ -461,7 +632,7 @@ public void DrawText(
{
tb.FontWeight = GetFontWeight(fontWeight);
}
-
+
double dx = 0;
double dy = 0;
@@ -532,7 +703,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))
{
@@ -540,7 +714,7 @@ public OxySize MeasureText(string text, string fontFamily, double fontSize, doub
}
var tb = new TextBlock { Text = text };
-
+
if (fontFamily != null)
{
tb.FontFamily = fontFamily;
@@ -565,7 +739,7 @@ public OxySize MeasureText(string text, string fontFamily, double fontSize, doub
/// 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;
}
@@ -584,7 +758,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,
@@ -620,7 +794,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);
@@ -643,16 +817,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,13 +834,11 @@ 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();
-
// 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);
}
@@ -692,14 +863,14 @@ 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();
if (clip != null)
{
- element.Clip = new global::Avalonia.Media.RectangleGeometry(
+ element.Clip = new RectangleGeometry(
new Rect(
clip.Value.X - clipOffsetX,
clip.Value.Y - clipOffsetY,
@@ -717,7 +888,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))
{
@@ -725,62 +896,6 @@ private void ApplyToolTip(global::Avalonia.Controls.Control element)
}
}
- ///
- /// Draws the line segments by stream geometry.
- ///
- /// The points.
- /// The stroke color.
- /// The thickness.
- /// 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,
- double[] dashArray,
- LineJoin lineJoin,
- bool aliased)
- {
- 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, lineJoin, dashArray, 0, aliased);
- path.Data = streamGeometry;
- streamGeometry = null;
- count = 0;
- }
- }
-
- if (streamGeometry != null)
- {
- streamGeometryContext.Dispose();
- var path = CreateAndAdd();
- SetStroke(path, stroke, thickness, lineJoin, null, 0, aliased);
- path.Data = streamGeometry;
- }
- }
-
///
/// Gets the cached brush.
///
@@ -793,8 +908,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);
@@ -809,20 +923,20 @@ 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)
+ if (thickness > 0 && !stroke.IsUndefined())
{
shape.Stroke = GetCachedBrush(stroke);
@@ -835,7 +949,7 @@ private void SetStroke(
shape.StrokeJoin = PenLineJoin.Bevel;
break;
- // The default StrokeLineJoin is Miter
+ // The default StrokeLineJoin is Miter
}
if (thickness > 0)
@@ -843,12 +957,18 @@ 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;
}
}
+
+ if (edgeRenderingMode == EdgeRenderingMode.PreferSpeed)
+ {
+ // TODO: use alised lines
+ }
}
///
@@ -868,8 +988,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;
}
@@ -888,17 +1007,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 +1026,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 +1059,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() };
}
}
@@ -1021,5 +1141,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 IList 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/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/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/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