// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) 2014 OxyPlot contributors
//
//
// The annotation base class.
//
// --------------------------------------------------------------------------------------------------------------------
using Avalonia;
namespace OxyPlot.Avalonia
{
using global::Avalonia.Controls;
using OxyPlot.Annotations;
///
/// The annotation base class.
///
public abstract class Annotation : Control
{
///
/// Identifies the dependency property.
///
public static readonly StyledProperty LayerProperty = AvaloniaProperty.Register(nameof(Layer), AnnotationLayer.AboveSeries);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty XAxisKeyProperty = AvaloniaProperty.Register(nameof(XAxisKey), null);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty YAxisKeyProperty = AvaloniaProperty.Register(nameof(YAxisKey), null);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty EdgeRenderingModeProperty = AvaloniaProperty.Register(nameof(EdgeRenderingMode), EdgeRenderingMode.Automatic);
///
/// Gets or sets the rendering layer of the annotation. The default value is .
///
public AnnotationLayer Layer
{
get
{
return GetValue(LayerProperty);
}
set
{
SetValue(LayerProperty, value);
}
}
///
/// Gets or sets the X axis key.
///
public string XAxisKey
{
get
{
return GetValue(XAxisKeyProperty);
}
set
{
SetValue(XAxisKeyProperty, value);
}
}
///
/// Gets or sets the Y axis key.
///
public string YAxisKey
{
get
{
return GetValue(YAxisKeyProperty);
}
set
{
SetValue(YAxisKeyProperty, value);
}
}
///
/// Gets or sets the for the annotation.
///
public EdgeRenderingMode EdgeRenderingMode
{
get
{
return GetValue(EdgeRenderingModeProperty);
}
set
{
SetValue(EdgeRenderingModeProperty, value);
}
}
///
/// Gets or sets the internal annotation object.
///
public Annotations.Annotation InternalAnnotation { get; protected set; }
///
/// Creates the internal annotation object.
///
/// The annotation.
public abstract Annotations.Annotation CreateModel();
///
/// Synchronizes the properties.
///
public virtual void SynchronizeProperties()
{
var a = InternalAnnotation;
a.Layer = Layer;
a.XAxisKey = XAxisKey;
a.YAxisKey = YAxisKey;
a.EdgeRenderingMode = EdgeRenderingMode;
}
///
/// Handles changes in appearance.
///
/// The sender.
/// The instance containing the event data.
protected static void AppearanceChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
{
((Annotation)d).OnVisualChanged();
}
///
/// The on visual changed handler.
///
protected void OnVisualChanged()
{
(this.Parent as IPlot)?.ElementAppearanceChanged(this);
}
///
/// Handles changes in data.
///
/// The sender.
/// The instance containing the event data.
protected static void DataChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e)
{
((Annotation)d).OnDataChanged();
}
///
/// The on data changed handler.
///
protected void OnDataChanged()
{
(this.Parent as IPlot)?.ElementDataChanged(this);
}
static Annotation()
{
LayerProperty.Changed.AddClassHandler(AppearanceChanged);
XAxisKeyProperty.Changed.AddClassHandler(AppearanceChanged);
YAxisKeyProperty.Changed.AddClassHandler(AppearanceChanged);
EdgeRenderingModeProperty.Changed.AddClassHandler(AppearanceChanged);
}
}
}