// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) 2014 OxyPlot contributors
//
//
// This is a Avalonia wrapper of OxyPlot.BoxPlotSeries
//
// --------------------------------------------------------------------------------------------------------------------
using Avalonia;
namespace OxyPlot.Avalonia
{
using global::Avalonia.Media;
using System.Linq;
///
/// This is a Avalonia wrapper of OxyPlot.BoxPlotSeries
///
public class BoxPlotSeries : XYAxisSeries
{
///
/// Identifies this dependency property.
///
public static readonly StyledProperty BoxWidthProperty = AvaloniaProperty.Register(nameof(BoxWidth), 0.3);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty FillProperty = AvaloniaProperty.Register(nameof(Fill), MoreColors.Automatic);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty LineStyleProperty = AvaloniaProperty.Register(nameof(LineStyle), LineStyle.Solid);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty MedianPointSizeProperty = AvaloniaProperty.Register(nameof(MedianPointSize), 2.0);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty MedianThicknessProperty = AvaloniaProperty.Register(nameof(MedianThickness), 2.0);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty OutlierSizeProperty = AvaloniaProperty.Register(nameof(OutlierSize), 2.0);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty OutlierTypeProperty = AvaloniaProperty.Register(nameof(OutlierType), MarkerType.Circle);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty OutlierOutlineProperty = AvaloniaProperty.Register(nameof(OutlierOutline), null);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty ShowBoxProperty = AvaloniaProperty.Register(nameof(ShowBox), true);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty ShowMedianAsDotProperty = AvaloniaProperty.Register(nameof(ShowMedianAsDot), false);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty StrokeProperty = AvaloniaProperty.Register(nameof(Stroke), Colors.Black);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty StrokeThicknessProperty = AvaloniaProperty.Register(nameof(StrokeThickness), 1.0);
///
/// Identifies this dependency property.
///
public static readonly StyledProperty WhiskerWidthProperty = AvaloniaProperty.Register(nameof(WhiskerWidth), 0.5);
///
/// Initializes static members of the class.
///
static BoxPlotSeries()
{
TrackerFormatStringProperty.OverrideMetadata(typeof(BoxPlotSeries), new StyledPropertyMetadata(OxyPlot.Series.BoxPlotSeries.DefaultTrackerFormatString));
BoxWidthProperty.Changed.AddClassHandler(AppearanceChanged);
FillProperty.Changed.AddClassHandler(AppearanceChanged);
LineStyleProperty.Changed.AddClassHandler(AppearanceChanged);
MedianPointSizeProperty.Changed.AddClassHandler(AppearanceChanged);
MedianThicknessProperty.Changed.AddClassHandler(AppearanceChanged);
OutlierSizeProperty.Changed.AddClassHandler(AppearanceChanged);
OutlierTypeProperty.Changed.AddClassHandler(AppearanceChanged);
OutlierOutlineProperty.Changed.AddClassHandler(AppearanceChanged);
ShowBoxProperty.Changed.AddClassHandler(AppearanceChanged);
ShowMedianAsDotProperty.Changed.AddClassHandler(AppearanceChanged);
StrokeProperty.Changed.AddClassHandler(AppearanceChanged);
StrokeThicknessProperty.Changed.AddClassHandler(AppearanceChanged);
WhiskerWidthProperty.Changed.AddClassHandler(AppearanceChanged);
TrackerFormatStringProperty.Changed.AddClassHandler(AppearanceChanged);
}
///
/// Initializes a new instance of the class.
///
public BoxPlotSeries()
{
InternalSeries = new OxyPlot.Series.BoxPlotSeries();
}
///
/// Gets or sets the width of the boxes (specified in x-axis units).
///
/// The width of the boxes.
public double BoxWidth
{
get { return GetValue(BoxWidthProperty); }
set { SetValue(BoxWidthProperty, value); }
}
///
/// Gets or sets the fill color. If null, this color will be automatically set.
///
/// The fill color.
public Color Fill
{
get { return GetValue(FillProperty); }
set { SetValue(FillProperty, value); }
}
///
/// Gets or sets the line style.
///
/// The line style.
public LineStyle LineStyle
{
get { return GetValue(LineStyleProperty); }
set { SetValue(LineStyleProperty, value); }
}
///
/// Gets or sets the size of the median point.
///
/// This property is only used when MedianStyle = Dot.
public double MedianPointSize
{
get { return GetValue(MedianPointSizeProperty); }
set { SetValue(MedianPointSizeProperty, value); }
}
///
/// Gets or sets the median thickness, relative to the StrokeThickness.
///
/// The median thickness.
public double MedianThickness
{
get { return GetValue(MedianThicknessProperty); }
set { SetValue(MedianThicknessProperty, value); }
}
///
/// Gets or sets the diameter of the outlier circles (specified in points).
///
/// The size of the outlier.
public double OutlierSize
{
get { return GetValue(OutlierSizeProperty); }
set { SetValue(OutlierSizeProperty, value); }
}
///
/// Gets or sets the type of the outliers.
///
/// The type of the outliers.
/// MarkerType.Custom is currently not supported.
public MarkerType OutlierType
{
get { return GetValue(OutlierTypeProperty); }
set { SetValue(OutlierTypeProperty, value); }
}
///
/// Gets or sets the a custom polygon outline for the outlier markers. Set to to use this property.
///
/// A polyline. The default is null.
public Point[] OutlierOutline
{
get { return GetValue(OutlierOutlineProperty); }
set { SetValue(OutlierOutlineProperty, value); }
}
///
/// Gets or sets a value indicating whether to show the boxes.
///
public bool ShowBox
{
get { return GetValue(ShowBoxProperty); }
set { SetValue(ShowBoxProperty, value); }
}
///
/// Gets or sets a value indicating whether to show the median as a dot.
///
public bool ShowMedianAsDot
{
get { return GetValue(ShowMedianAsDotProperty); }
set { SetValue(ShowMedianAsDotProperty, value); }
}
///
/// Gets or sets the stroke color.
///
/// The stroke color.
public Color Stroke
{
get { return GetValue(StrokeProperty); }
set { SetValue(StrokeProperty, value); }
}
///
/// Gets or sets the stroke thickness.
///
/// The stroke thickness.
public double StrokeThickness
{
get { return GetValue(StrokeThicknessProperty); }
set { SetValue(StrokeThicknessProperty, value); }
}
///
/// Gets or sets the width of the whiskers (relative to the BoxWidth).
///
/// The width of the whiskers.
public double WhiskerWidth
{
get { return GetValue(WhiskerWidthProperty); }
set { SetValue(WhiskerWidthProperty, value); }
}
///
/// Creates the internal series.
///
/// The internal 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.BoxPlotSeries)series;
s.Fill = Fill.ToOxyColor();
s.LineStyle = LineStyle;
s.MedianPointSize = MedianPointSize;
s.OutlierSize = OutlierSize;
s.OutlierType = OutlierType;
s.OutlierOutline = (OutlierOutline ?? Enumerable.Empty()).Select(point => point.ToScreenPoint()).ToArray();
s.ShowBox = ShowBox;
s.ShowMedianAsDot = ShowMedianAsDot;
s.Stroke = Stroke.ToOxyColor();
s.StrokeThickness = StrokeThickness;
s.WhiskerWidth = WhiskerWidth;
if (Items != null)
{
s.Items.Clear();
foreach (var item in Items)
{
s.Items.Add((OxyPlot.Series.BoxPlotItem)item);
}
}
}
}
}