// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2014 OxyPlot contributors // // // Provides an abstract base class for annotations that contains text. // // -------------------------------------------------------------------------------------------------------------------- using Avalonia; namespace OxyPlot.Avalonia { using global::Avalonia.Layout; using global::Avalonia.Media; /// /// Provides an abstract base class for annotations that contains text. /// public abstract class TextualAnnotation : Annotation { /// /// Identifies the dependency property. /// public static readonly StyledProperty TextProperty = AvaloniaProperty.Register(nameof(Text), null); /// /// Identifies the dependency property. /// public static readonly StyledProperty TextPositionProperty = AvaloniaProperty.Register(nameof(TextPosition), DataPoint.Undefined); /// /// Identifies the dependency property. /// public static readonly StyledProperty TextRotationProperty = AvaloniaProperty.Register(nameof(TextRotation), 0.0); /// /// Identifies the dependency property. /// public static readonly StyledProperty TextColorProperty = AvaloniaProperty.Register(nameof(TextColor), Colors.Blue); /// /// Identifies the dependency property. /// public static readonly StyledProperty TextHorizontalAlignmentProperty = AvaloniaProperty.Register(nameof(TextHorizontalAlignment), HorizontalAlignment.Center); /// /// Identifies the dependency property. /// public static readonly StyledProperty TextVerticalAlignmentProperty = AvaloniaProperty.Register(nameof(TextVerticalAlignment), VerticalAlignment.Center); /// /// Gets or sets the text. /// public string Text { get { return GetValue(TextProperty); } set { SetValue(TextProperty, value); } } /// /// Gets or sets the color of the text. /// public Color TextColor { get { return GetValue(TextColorProperty); } set { SetValue(TextColorProperty, value); } } /// /// Gets or sets the text position. /// /// If the value is DataPoint.Undefined, the centroid of the polygon will be used. public DataPoint TextPosition { get { return GetValue(TextPositionProperty); } set { SetValue(TextPositionProperty, value); } } /// /// Gets or sets the text horizontal alignment. /// /// The text horizontal alignment. public HorizontalAlignment TextHorizontalAlignment { get { return GetValue(TextHorizontalAlignmentProperty); } set { SetValue(TextHorizontalAlignmentProperty, value); } } /// /// Gets or sets the vertical alignment of text (above or below the line). /// public VerticalAlignment TextVerticalAlignment { get { return GetValue(TextVerticalAlignmentProperty); } set { SetValue(TextVerticalAlignmentProperty, value); } } /// /// Gets or sets the rotation angle (degrees). /// public double TextRotation { get { return GetValue(TextRotationProperty); } set { SetValue(TextRotationProperty, value); } } /// /// Synchronizes the properties. /// public override void SynchronizeProperties() { base.SynchronizeProperties(); var a = (Annotations.TextualAnnotation)InternalAnnotation; a.TextColor = TextColor.ToOxyColor(); a.Text = Text; a.TextPosition = TextPosition; a.TextRotation = TextRotation; a.TextHorizontalAlignment = TextHorizontalAlignment.ToHorizontalAlignment(); a.TextVerticalAlignment = TextVerticalAlignment.ToVerticalAlignment(); } static TextualAnnotation() { TextProperty.Changed.AddClassHandler(AppearanceChanged); TextPositionProperty.Changed.AddClassHandler(AppearanceChanged); TextRotationProperty.Changed.AddClassHandler(AppearanceChanged); TextColorProperty.Changed.AddClassHandler(AppearanceChanged); TextHorizontalAlignmentProperty.Changed.AddClassHandler(AppearanceChanged); TextVerticalAlignmentProperty.Changed.AddClassHandler(AppearanceChanged); } } }