// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2014 OxyPlot contributors // // // This is a Avalonia wrapper of OxyPlot.ArrowAnnotation // // -------------------------------------------------------------------------------------------------------------------- using Avalonia; namespace OxyPlot.Avalonia { using global::Avalonia.Media; /// /// This is a Avalonia wrapper of OxyPlot.ArrowAnnotation /// public class ArrowAnnotation : TextualAnnotation { /// /// Identifies the dependency property. /// public static readonly StyledProperty ArrowDirectionProperty = AvaloniaProperty.Register(nameof(ArrowDirection)); /// /// Identifies the dependency property. /// public static readonly StyledProperty ColorProperty = AvaloniaProperty.Register(nameof(Color), Colors.Blue); /// /// Identifies the dependency property. /// public static readonly StyledProperty EndPointProperty = AvaloniaProperty.Register(nameof(EndPoint)); /// /// Identifies the dependency property. /// public static readonly StyledProperty HeadLengthProperty = AvaloniaProperty.Register(nameof(HeadLength), 10.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty HeadWidthProperty = AvaloniaProperty.Register(nameof(HeadWidth), 3.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty LineJoinProperty = AvaloniaProperty.Register(nameof(LineJoin), LineJoin.Miter); /// /// Identifies the dependency property. /// public static readonly StyledProperty LineStyleProperty = AvaloniaProperty.Register(nameof(LineStyle), LineStyle.Solid); /// /// Identifies the dependency property. /// public static readonly StyledProperty StartPointProperty = AvaloniaProperty.Register(nameof(StartPoint)); /// /// Identifies the dependency property. /// public static readonly StyledProperty StrokeThicknessProperty = AvaloniaProperty.Register(nameof(StrokeThickness), 2.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty VeenessProperty = AvaloniaProperty.Register(nameof(Veeness), 0.0); /// /// Initializes static members of the class. /// static ArrowAnnotation() { TextColorProperty.OverrideDefaultValue(MoreColors.Automatic); TextColorProperty.Changed.AddClassHandler(AppearanceChanged); ArrowDirectionProperty.Changed.AddClassHandler(DataChanged); ColorProperty.Changed.AddClassHandler(AppearanceChanged); EndPointProperty.Changed.AddClassHandler(DataChanged); HeadLengthProperty.Changed.AddClassHandler(AppearanceChanged); HeadWidthProperty.Changed.AddClassHandler(AppearanceChanged); LineJoinProperty.Changed.AddClassHandler(AppearanceChanged); LineStyleProperty.Changed.AddClassHandler(AppearanceChanged); StartPointProperty.Changed.AddClassHandler(DataChanged); StrokeThicknessProperty.Changed.AddClassHandler(AppearanceChanged); VeenessProperty.Changed.AddClassHandler(AppearanceChanged); } /// /// Initializes a new instance of the class. /// public ArrowAnnotation() { InternalAnnotation = new Annotations.ArrowAnnotation(); } /// /// Gets or sets the arrow direction. /// public ScreenVector ArrowDirection { get { return GetValue(ArrowDirectionProperty); } set { SetValue(ArrowDirectionProperty, value); } } /// /// Gets or sets the color. /// public Color Color { get { return GetValue(ColorProperty); } set { SetValue(ColorProperty, value); } } /// /// Gets or sets the end point. /// public DataPoint EndPoint { get { return GetValue(EndPointProperty); } set { SetValue(EndPointProperty, value); } } /// /// Gets or sets the length of the head (relative to the stroke thickness). /// /// The length of the head. public double HeadLength { get { return GetValue(HeadLengthProperty); } set { SetValue(HeadLengthProperty, value); } } /// /// Gets or sets the width of the head (relative to the stroke thickness). /// /// The width of the head. public double HeadWidth { get { return GetValue(HeadWidthProperty); } set { SetValue(HeadWidthProperty, value); } } /// /// Gets or sets the line join. /// /// The line join. public LineJoin LineJoin { get { return GetValue(LineJoinProperty); } set { SetValue(LineJoinProperty, value); } } /// /// Gets or sets LineStyle. /// public LineStyle LineStyle { get { return GetValue(LineStyleProperty); } set { SetValue(LineStyleProperty, value); } } /// /// Gets or sets the start point. /// /// This property is overridden by the ArrowDirection property, if set. public DataPoint StartPoint { get { return GetValue(StartPointProperty); } set { SetValue(StartPointProperty, value); } } /// /// Gets or sets the stroke thickness. /// public double StrokeThickness { get { return GetValue(StrokeThicknessProperty); } set { SetValue(StrokeThicknessProperty, value); } } /// /// Gets or sets the 'veeness' of the arrow head (relative to thickness). /// public double Veeness { get { return GetValue(VeenessProperty); } set { SetValue(VeenessProperty, value); } } /// /// Creates the internal annotation object. /// /// The annotation. public override Annotations.Annotation CreateModel() { SynchronizeProperties(); return InternalAnnotation; } /// /// Synchronizes the properties. /// public override void SynchronizeProperties() { base.SynchronizeProperties(); var a = (Annotations.ArrowAnnotation)InternalAnnotation; a.StartPoint = StartPoint; a.EndPoint = EndPoint; a.ArrowDirection = ArrowDirection; a.HeadLength = HeadLength; a.HeadWidth = HeadWidth; a.Veeness = Veeness; a.Color = Color.ToOxyColor(); a.StrokeThickness = StrokeThickness; a.LineStyle = LineStyle; a.LineJoin = LineJoin; } } }