// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2014 OxyPlot contributors // // // This is a Avalonia wrapper of OxyPlot.LineSeries // // -------------------------------------------------------------------------------------------------------------------- using Avalonia; namespace OxyPlot.Avalonia { using global::Avalonia.Media; using OxyPlot.Series; using System; using System.Collections.Generic; using System.Linq; /// /// This is a Avalonia wrapper of OxyPlot.LineSeries /// public class LineSeries : DataPointSeries { /// /// Identifies the dependency property. /// public static readonly StyledProperty BrokenLineColorProperty = AvaloniaProperty.Register(nameof(BrokenLineColor), MoreColors.Undefined); /// /// Identifies the dependency property. /// public static readonly StyledProperty BrokenLineStyleProperty = AvaloniaProperty.Register(nameof(BrokenLineStyle), LineStyle.Solid); /// /// Identifies the dependency property. /// public static readonly StyledProperty BrokenLineThicknessProperty = AvaloniaProperty.Register(nameof(BrokenLineThickness), 0d); /// /// Identifies the dependency property. /// public static readonly StyledProperty DashesProperty = AvaloniaProperty.Register(nameof(Dashes), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty, List>> DecimatorProperty = AvaloniaProperty.Register, List>>(nameof(Decimator), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty LabelFormatStringProperty = AvaloniaProperty.Register(nameof(LabelFormatString)); /// /// Identifies the dependency property. /// public static readonly StyledProperty LabelMarginProperty = AvaloniaProperty.Register(nameof(LabelMargin), 6.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty LineJoinProperty = AvaloniaProperty.Register(nameof(LineJoin), LineJoin.Bevel); /// /// Identifies the dependency property. /// public static readonly StyledProperty LineLegendPositionProperty = AvaloniaProperty.Register(nameof(LineLegendPosition), LineLegendPosition.None); /// /// Identifies the dependency property. /// public static readonly StyledProperty LineStyleProperty = AvaloniaProperty.Register(nameof(LineStyle), LineStyle.Automatic); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerFillProperty = AvaloniaProperty.Register(nameof(MarkerFill), MoreColors.Automatic); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerOutlineProperty = AvaloniaProperty.Register(nameof(MarkerOutline), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerResolutionProperty = AvaloniaProperty.Register(nameof(MarkerResolution), 0); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerSizeProperty = AvaloniaProperty.Register(nameof(MarkerSize), 3.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerStrokeProperty = AvaloniaProperty.Register(nameof(MarkerStroke), MoreColors.Automatic); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerStrokeThicknessProperty = AvaloniaProperty.Register(nameof(MarkerStrokeThickness), 1.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty MarkerTypeProperty = AvaloniaProperty.Register(nameof(MarkerType), MarkerType.None); /// /// Identifies the dependency property. /// public static readonly StyledProperty MinimumSegmentLengthProperty = AvaloniaProperty.Register(nameof(MinimumSegmentLength), 2.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty InterpolationAlgorithmProperty = AvaloniaProperty.Register(nameof(InterpolationAlgorithm), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty StrokeThicknessProperty = AvaloniaProperty.Register(nameof(StrokeThickness), 2.0); /// /// Initializes static members of the class. /// static LineSeries() { CanTrackerInterpolatePointsProperty.OverrideMetadata(typeof(LineSeries), new StyledPropertyMetadata(true)); BrokenLineColorProperty.Changed.AddClassHandler(AppearanceChanged); BrokenLineStyleProperty.Changed.AddClassHandler(AppearanceChanged); BrokenLineThicknessProperty.Changed.AddClassHandler(AppearanceChanged); DashesProperty.Changed.AddClassHandler(AppearanceChanged); DecimatorProperty.Changed.AddClassHandler(AppearanceChanged); LineJoinProperty.Changed.AddClassHandler(AppearanceChanged); LineStyleProperty.Changed.AddClassHandler(AppearanceChanged); MarkerFillProperty.Changed.AddClassHandler(AppearanceChanged); MarkerOutlineProperty.Changed.AddClassHandler(AppearanceChanged); MarkerResolutionProperty.Changed.AddClassHandler(AppearanceChanged); MarkerSizeProperty.Changed.AddClassHandler(AppearanceChanged); MarkerStrokeProperty.Changed.AddClassHandler(AppearanceChanged); MarkerStrokeThicknessProperty.Changed.AddClassHandler(AppearanceChanged); MarkerTypeProperty.Changed.AddClassHandler(AppearanceChanged); MinimumSegmentLengthProperty.Changed.AddClassHandler(AppearanceChanged); StrokeThicknessProperty.Changed.AddClassHandler(AppearanceChanged); CanTrackerInterpolatePointsProperty.Changed.AddClassHandler(AppearanceChanged); } /// /// Initializes a new instance of the class. /// public LineSeries() { this.InternalSeries = new OxyPlot.Series.LineSeries(); } /// /// Gets or sets the broken line color. /// public Color BrokenLineColor { get { return GetValue(BrokenLineColorProperty); } set { SetValue(BrokenLineColorProperty, value); } } /// /// Gets or sets the broken line style. /// public LineStyle BrokenLineStyle { get { return GetValue(BrokenLineStyleProperty); } set { SetValue(BrokenLineStyleProperty, value); } } /// /// Gets or sets the broken line thickness. /// public double BrokenLineThickness { get { return GetValue(BrokenLineThicknessProperty); } set { SetValue(BrokenLineThicknessProperty, value); } } /// /// Gets or sets Dashes. /// public double[] Dashes { get { return GetValue(DashesProperty); } set { SetValue(DashesProperty, value); } } /// /// Gets or sets the decimator. /// /// /// The decimator. /// public Action, List> Decimator { get { return GetValue(DecimatorProperty); } set { SetValue(DecimatorProperty, value); } } /// /// Gets or sets the label format string. /// /// The label format string. public string LabelFormatString { get { return GetValue(LabelFormatStringProperty); } set { SetValue(LabelFormatStringProperty, value); } } /// /// Gets or sets the label margin. /// /// The label margin. public double LabelMargin { get { return GetValue(LabelMarginProperty); } set { SetValue(LabelMarginProperty, value); } } /// /// Gets or sets LineJoin. /// public LineJoin LineJoin { get { return GetValue(LineJoinProperty); } set { SetValue(LineJoinProperty, value); } } /// /// Gets or sets LineLegendPosition. /// public LineLegendPosition LineLegendPosition { get { return GetValue(LineLegendPositionProperty); } set { SetValue(LineLegendPositionProperty, value); } } /// /// Gets or sets LineStyle. /// public LineStyle LineStyle { get { return GetValue(LineStyleProperty); } set { SetValue(LineStyleProperty, value); } } /// /// Gets or sets MarkerFill. /// public Color MarkerFill { get { return GetValue(MarkerFillProperty); } set { SetValue(MarkerFillProperty, value); } } /// /// Gets or sets MarkerOutline. /// public Point[] MarkerOutline { get { return GetValue(MarkerOutlineProperty); } set { SetValue(MarkerOutlineProperty, value); } } /// /// Gets or sets the marker resolution. /// /// The marker resolution. public int MarkerResolution { get { return GetValue(MarkerResolutionProperty); } set { SetValue(MarkerResolutionProperty, value); } } /// /// Gets or sets the marker size. /// public double MarkerSize { get { return GetValue(MarkerSizeProperty); } set { SetValue(MarkerSizeProperty, value); } } /// /// Gets or sets MarkerStroke. /// public Color MarkerStroke { get { return GetValue(MarkerStrokeProperty); } set { SetValue(MarkerStrokeProperty, value); } } /// /// Gets or sets MarkerStrokeThickness. /// public double MarkerStrokeThickness { get { return GetValue(MarkerStrokeThicknessProperty); } set { SetValue(MarkerStrokeThicknessProperty, value); } } /// /// Gets or sets MarkerType. /// public MarkerType MarkerType { get { return GetValue(MarkerTypeProperty); } set { SetValue(MarkerTypeProperty, value); } } /// /// Gets or sets MinimumSegmentLength. /// public double MinimumSegmentLength { get { return GetValue(MinimumSegmentLengthProperty); } set { SetValue(MinimumSegmentLengthProperty, value); } } /// /// Gets or sets a value the interpolation algorithm. /// /// Interpolation algorithm. public IInterpolationAlgorithm InterpolationAlgorithm { get { return this.GetValue(InterpolationAlgorithmProperty); } set { this.SetValue(InterpolationAlgorithmProperty, value); } } /// /// Gets or sets StrokeThickness. /// public double StrokeThickness { get { return GetValue(StrokeThicknessProperty); } set { SetValue(StrokeThicknessProperty, 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.LineSeries)series; s.Color = Color.ToOxyColor(); s.StrokeThickness = StrokeThickness; s.LineStyle = LineStyle; s.MarkerResolution = MarkerResolution; s.MarkerSize = MarkerSize; s.MarkerStroke = MarkerStroke.ToOxyColor(); s.MarkerType = MarkerType; s.MarkerStrokeThickness = MarkerStrokeThickness; s.Dashes = Dashes; s.LineJoin = LineJoin; s.MarkerFill = MarkerFill.ToOxyColor(); s.MarkerOutline = (MarkerOutline ?? Enumerable.Empty()).Select(point => point.ToScreenPoint()).ToArray(); s.MinimumSegmentLength = MinimumSegmentLength; s.LabelFormatString = LabelFormatString; s.LabelMargin = LabelMargin; s.LineLegendPosition = LineLegendPosition; s.BrokenLineColor = BrokenLineColor.ToOxyColor(); s.BrokenLineStyle = BrokenLineStyle; s.BrokenLineThickness = BrokenLineThickness; s.Decimator = Decimator; s.InterpolationAlgorithm = this.InterpolationAlgorithm; } } }