123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- // --------------------------------------------------------------------------------------------------------------------
- // <copyright file="TextualAnnotation.cs" company="OxyPlot">
- // Copyright (c) 2014 OxyPlot contributors
- // </copyright>
- // <summary>
- // Provides an abstract base class for annotations that contains text.
- // </summary>
- // --------------------------------------------------------------------------------------------------------------------
- using Avalonia;
- namespace OxyPlot.Avalonia
- {
- using global::Avalonia.Layout;
- using global::Avalonia.Media;
- /// <summary>
- /// Provides an abstract base class for annotations that contains text.
- /// </summary>
- public abstract class TextualAnnotation : Annotation
- {
- /// <summary>
- /// Identifies the <see cref="Text"/> dependency property.
- /// </summary>
- public static readonly StyledProperty<string> TextProperty = AvaloniaProperty.Register<TextualAnnotation, string>(nameof(Text), null);
- /// <summary>
- /// Identifies the <see cref="TextPosition"/> dependency property.
- /// </summary>
- public static readonly StyledProperty<DataPoint> TextPositionProperty = AvaloniaProperty.Register<TextualAnnotation, DataPoint>(nameof(TextPosition), DataPoint.Undefined);
- /// <summary>
- /// Identifies the <see cref="TextRotation"/> dependency property.
- /// </summary>
- public static readonly StyledProperty<double> TextRotationProperty = AvaloniaProperty.Register<TextualAnnotation, double>(nameof(TextRotation), 0.0);
- /// <summary>
- /// Identifies the <see cref="TextColor"/> dependency property.
- /// </summary>
- public static readonly StyledProperty<Color> TextColorProperty = AvaloniaProperty.Register<TextualAnnotation, Color>(nameof(TextColor), Colors.Blue);
- /// <summary>
- /// Identifies the <see cref="TextHorizontalAlignment"/> dependency property.
- /// </summary>
- public static readonly StyledProperty<HorizontalAlignment> TextHorizontalAlignmentProperty = AvaloniaProperty.Register<TextualAnnotation, HorizontalAlignment>(nameof(TextHorizontalAlignment), HorizontalAlignment.Center);
- /// <summary>
- /// Identifies the <see cref="TextVerticalAlignment"/> dependency property.
- /// </summary>
- public static readonly StyledProperty<VerticalAlignment> TextVerticalAlignmentProperty = AvaloniaProperty.Register<TextualAnnotation, VerticalAlignment>(nameof(TextVerticalAlignment), VerticalAlignment.Center);
- /// <summary>
- /// Gets or sets the text.
- /// </summary>
- public string Text
- {
- get
- {
- return GetValue(TextProperty);
- }
- set
- {
- SetValue(TextProperty, value);
- }
- }
- /// <summary>
- /// Gets or sets the color of the text.
- /// </summary>
- public Color TextColor
- {
- get
- {
- return GetValue(TextColorProperty);
- }
- set
- {
- SetValue(TextColorProperty, value);
- }
- }
- /// <summary>
- /// Gets or sets the text position.
- /// </summary>
- /// <remarks>If the value is <c>DataPoint.Undefined</c>, the centroid of the polygon will be used.</remarks>
- public DataPoint TextPosition
- {
- get { return GetValue(TextPositionProperty); }
- set { SetValue(TextPositionProperty, value); }
- }
- /// <summary>
- /// Gets or sets the text horizontal alignment.
- /// </summary>
- /// <value>The text horizontal alignment.</value>
- public HorizontalAlignment TextHorizontalAlignment
- {
- get
- {
- return GetValue(TextHorizontalAlignmentProperty);
- }
- set
- {
- SetValue(TextHorizontalAlignmentProperty, value);
- }
- }
- /// <summary>
- /// Gets or sets the vertical alignment of text (above or below the line).
- /// </summary>
- public VerticalAlignment TextVerticalAlignment
- {
- get
- {
- return GetValue(TextVerticalAlignmentProperty);
- }
- set
- {
- SetValue(TextVerticalAlignmentProperty, value);
- }
- }
- /// <summary>
- /// Gets or sets the rotation angle (degrees).
- /// </summary>
- public double TextRotation
- {
- get
- {
- return GetValue(TextRotationProperty);
- }
- set
- {
- SetValue(TextRotationProperty, value);
- }
- }
- /// <summary>
- /// Synchronizes the properties.
- /// </summary>
- 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<TextualAnnotation>(AppearanceChanged);
- TextPositionProperty.Changed.AddClassHandler<TextualAnnotation>(AppearanceChanged);
- TextRotationProperty.Changed.AddClassHandler<TextualAnnotation>(AppearanceChanged);
- TextColorProperty.Changed.AddClassHandler<TextualAnnotation>(AppearanceChanged);
- TextHorizontalAlignmentProperty.Changed.AddClassHandler<TextualAnnotation>(AppearanceChanged);
- TextVerticalAlignmentProperty.Changed.AddClassHandler<TextualAnnotation>(AppearanceChanged);
- }
- }
- }
|