// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) 2014 OxyPlot contributors
//
//
// This is a Avalonia wrapper of OxyPlot.CategoryAxis.
//
// --------------------------------------------------------------------------------------------------------------------
using Avalonia;
namespace OxyPlot.Avalonia
{
using System.Collections;
using System.Collections.Generic;
///
/// This is a Avalonia wrapper of OxyPlot.CategoryAxis.
///
public class CategoryAxis : LinearAxis
{
///
/// Identifies the dependency property.
///
public static readonly StyledProperty GapWidthProperty = AvaloniaProperty.Register(nameof(GapWidth), 1.0);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty IsTickCenteredProperty = AvaloniaProperty.Register(nameof(IsTickCentered), false);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty ItemsProperty = AvaloniaProperty.Register(nameof(Items), null);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty LabelFieldProperty = AvaloniaProperty.Register(nameof(LabelField), null);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty> LabelsProperty = AvaloniaProperty.Register>(nameof(Labels), new List());
///
/// Initializes static members of the class.
///
static CategoryAxis()
{
PositionProperty.OverrideMetadata(typeof(CategoryAxis), new StyledPropertyMetadata(Axes.AxisPosition.Bottom));
MinimumPaddingProperty.OverrideMetadata(typeof(CategoryAxis), new StyledPropertyMetadata(0.0));
MaximumPaddingProperty.OverrideMetadata(typeof(CategoryAxis), new StyledPropertyMetadata(0.0));
MajorStepProperty.OverrideMetadata(typeof(CategoryAxis), new StyledPropertyMetadata(1.0));
IsTickCenteredProperty.Changed.AddClassHandler(DataChanged);
ItemsProperty.Changed.AddClassHandler(DataChanged);
LabelFieldProperty.Changed.AddClassHandler(DataChanged);
LabelsProperty.Changed.AddClassHandler(DataChanged);
PositionProperty.Changed.AddClassHandler(DataChanged);
MinimumPaddingProperty.Changed.AddClassHandler(DataChanged);
MaximumPaddingProperty.Changed.AddClassHandler(DataChanged);
MajorStepProperty.Changed.AddClassHandler(DataChanged);
}
///
/// Initializes a new instance of the class.
///
public CategoryAxis()
{
InternalAxis = new Axes.CategoryAxis();
}
///
/// Gets or sets the gap width.
///
/// The width of the gap.
public double GapWidth
{
get
{
return GetValue(GapWidthProperty);
}
set
{
SetValue(GapWidthProperty, value);
}
}
///
/// Gets or sets a value indicating whether IsTickCentered.
///
public bool IsTickCentered
{
get
{
return GetValue(IsTickCenteredProperty);
}
set
{
SetValue(IsTickCenteredProperty, value);
}
}
///
/// Gets or sets ItemsSource.
///
public IEnumerable Items
{
get
{
return GetValue(ItemsProperty);
}
set
{
SetValue(ItemsProperty, value);
}
}
///
/// Gets or sets LabelField.
///
public string LabelField
{
get
{
return GetValue(LabelFieldProperty);
}
set
{
SetValue(LabelFieldProperty, value);
}
}
///
/// Gets or sets Labels.
///
public IList Labels
{
get
{
return GetValue(LabelsProperty);
}
set
{
SetValue(LabelsProperty, value);
}
}
///
/// Creates the internal axis.
///
/// The internal axis.
public override Axes.Axis CreateModel()
{
SynchronizeProperties();
return InternalAxis;
}
///
/// Synchronizes the properties.
///
protected override void SynchronizeProperties()
{
base.SynchronizeProperties();
var a = (Axes.CategoryAxis)InternalAxis;
a.IsTickCentered = IsTickCentered;
a.ItemsSource = Items;
a.LabelField = LabelField;
a.GapWidth = GapWidth;
if (Labels != null && Items == null)
{
a.Labels.Clear();
a.Labels.AddRange(Labels);
}
}
}
}