// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2014 OxyPlot contributors // // // Provides a base class for scatter series. // // -------------------------------------------------------------------------------------------------------------------- using Avalonia; namespace OxyPlot.Avalonia { using global::Avalonia.Media; using OxyPlot.Series; using System; /// /// Provides a base class for scatter series. /// /// The type of the points. public abstract class ScatterSeries : XYAxisSeries where T : ScatterPoint { /// /// Identifies the dependency property. /// public static readonly StyledProperty BinSizeProperty = AvaloniaProperty.Register, int>(nameof(BinSize), 0); /// /// Identifies the dependency property. /// public static readonly StyledProperty DataFieldSizeProperty = AvaloniaProperty.Register, string>(nameof(DataFieldSize), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty DataFieldTagProperty = AvaloniaProperty.Register, string>(nameof(DataFieldTag), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty DataFieldValueProperty = AvaloniaProperty.Register, string>(nameof(DataFieldValue), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty DataFieldXProperty = AvaloniaProperty.Register, string>(nameof(DataFieldX), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty DataFieldYProperty = AvaloniaProperty.Register, string>(nameof(DataFieldY), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty> MappingProperty = AvaloniaProperty.Register, Func>(nameof(Mapping), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerFillProperty = AvaloniaProperty.Register, Color>(nameof(MarkerFill), MoreColors.Automatic); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerOutlineProperty = AvaloniaProperty.Register, ScreenPoint[]>(nameof(MarkerOutline), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerSizeProperty = AvaloniaProperty.Register, double>(nameof(MarkerSize), 5.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerStrokeProperty = AvaloniaProperty.Register, Color>(nameof(MarkerStroke), MoreColors.Automatic); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerStrokeThicknessProperty = AvaloniaProperty.Register, double>(nameof(MarkerStrokeThickness), 1.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerTypeProperty = AvaloniaProperty.Register, MarkerType>(nameof(MarkerType), MarkerType.Square); /// /// Initializes a new instance of the class. /// protected ScatterSeries() { InternalSeries = new OxyPlot.Series.ScatterSeries(); } /// /// Gets or sets bin size. /// public int BinSize { get { return GetValue(BinSizeProperty); } set { SetValue(BinSizeProperty, value); } } /// /// Gets or sets size data field. /// public string DataFieldSize { get { return GetValue(DataFieldSizeProperty); } set { SetValue(DataFieldSizeProperty, value); } } /// /// Gets or sets tag data field. /// public string DataFieldTag { get { return GetValue(DataFieldTagProperty); } set { SetValue(DataFieldTagProperty, value); } } /// /// Gets or sets value (color) data field. /// public string DataFieldValue { get { return GetValue(DataFieldValueProperty); } set { SetValue(DataFieldValueProperty, value); } } /// /// Gets or sets X data field. /// public string DataFieldX { get { return GetValue(DataFieldXProperty); } set { SetValue(DataFieldXProperty, value); } } /// /// Gets or sets Y data field. /// public string DataFieldY { get { return GetValue(DataFieldYProperty); } set { SetValue(DataFieldYProperty, value); } } /// /// Gets or sets mapping function. /// public Func Mapping { get { return (Func)GetValue(MappingProperty); } set { SetValue(MappingProperty, value); } } /// /// Gets or sets fill color of the markers. /// public Color MarkerFill { get { return GetValue(MarkerFillProperty); } set { SetValue(MarkerFillProperty, value); } } /// /// Gets or sets custom outline of the markers. /// public ScreenPoint[] MarkerOutline { get { return GetValue(MarkerOutlineProperty); } set { SetValue(MarkerOutlineProperty, value); } } /// /// Gets or sets the size of the markers. /// public double MarkerSize { get { return GetValue(MarkerSizeProperty); } set { SetValue(MarkerSizeProperty, value); } } /// /// Gets or sets color of the marker strokes. /// public Color MarkerStroke { get { return GetValue(MarkerStrokeProperty); } set { SetValue(MarkerStrokeProperty, value); } } /// /// Gets or sets thickness of the marker strokes. /// public double MarkerStrokeThickness { get { return GetValue(MarkerStrokeThicknessProperty); } set { SetValue(MarkerStrokeThicknessProperty, value); } } /// /// Gets or sets type of the markers. /// public MarkerType MarkerType { get { return GetValue(MarkerTypeProperty); } set { SetValue(MarkerTypeProperty, value); } } /// /// Gets or sets the color axis key. /// /// The color axis key. public string ColorAxisKey { get; set; } /// /// Creates the internal series. /// /// The series. public override OxyPlot.Series.Series CreateModel() { SynchronizeProperties(InternalSeries); return InternalSeries; } /// /// Synchronizes the properties. /// /// The series. protected override void SynchronizeProperties(OxyPlot.Series.Series series) { base.SynchronizeProperties(series); var s = (OxyPlot.Series.ScatterSeries)series; s.MarkerFill = MarkerFill.ToOxyColor(); s.MarkerStroke = MarkerStroke.ToOxyColor(); s.MarkerStrokeThickness = MarkerStrokeThickness; s.MarkerType = MarkerType; s.MarkerSize = MarkerSize; s.DataFieldX = DataFieldX; s.DataFieldY = DataFieldY; s.DataFieldSize = DataFieldSize; s.DataFieldValue = DataFieldValue; s.DataFieldTag = DataFieldTag; s.ItemsSource = Items; s.BinSize = BinSize; s.Mapping = Mapping; s.MarkerOutline = MarkerOutline; s.ColorAxisKey = ColorAxisKey; } static ScatterSeries() { BinSizeProperty.Changed.AddClassHandler>(AppearanceChanged); DataFieldSizeProperty.Changed.AddClassHandler>(DataChanged); DataFieldTagProperty.Changed.AddClassHandler>(DataChanged); DataFieldValueProperty.Changed.AddClassHandler>(DataChanged); DataFieldXProperty.Changed.AddClassHandler>(DataChanged); DataFieldYProperty.Changed.AddClassHandler>(DataChanged); MappingProperty.Changed.AddClassHandler>(DataChanged); MarkerFillProperty.Changed.AddClassHandler>(AppearanceChanged); MarkerOutlineProperty.Changed.AddClassHandler>(AppearanceChanged); MarkerSizeProperty.Changed.AddClassHandler>(AppearanceChanged); MarkerStrokeProperty.Changed.AddClassHandler>(AppearanceChanged); MarkerStrokeThicknessProperty.Changed.AddClassHandler>(AppearanceChanged); MarkerTypeProperty.Changed.AddClassHandler>(AppearanceChanged); } } }