// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) 2014 OxyPlot contributors
//
//
// This is a Avalonia wrapper of OxyPlot.DateTimeAxis.
//
// --------------------------------------------------------------------------------------------------------------------
using Avalonia;
namespace OxyPlot.Avalonia
{
using OxyPlot.Axes;
using System;
using System.Globalization;
///
/// This is a Avalonia wrapper of OxyPlot.DateTimeAxis.
///
public class DateTimeAxis : Axis
{
///
/// Identifies the dependency property.
///
public static readonly StyledProperty CalendarWeekRuleProperty = AvaloniaProperty.Register(nameof(CalendarWeekRule), CalendarWeekRule.FirstFourDayWeek);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty FirstDateTimeProperty = AvaloniaProperty.Register(nameof(FirstDateTime), DateTime.MinValue);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty FirstDayOfWeekProperty = AvaloniaProperty.Register(nameof(FirstDayOfWeek), DayOfWeek.Monday);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty IntervalTypeProperty = AvaloniaProperty.Register(nameof(IntervalType), DateTimeIntervalType.Auto);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty LastDateTimeProperty = AvaloniaProperty.Register(nameof(LastDateTime), DateTime.MaxValue);
///
/// Identifies the dependency property.
///
public static readonly StyledProperty MinorIntervalTypeProperty = AvaloniaProperty.Register(nameof(MinorIntervalType), DateTimeIntervalType.Auto);
///
/// Initializes static members of the class.
///
static DateTimeAxis()
{
PositionProperty.OverrideDefaultValue(AxisPosition.Bottom);
PositionProperty.Changed.AddClassHandler(AppearanceChanged);
CalendarWeekRuleProperty.Changed.AddClassHandler(DataChanged);
FirstDayOfWeekProperty.Changed.AddClassHandler(DataChanged);
MinorIntervalTypeProperty.Changed.AddClassHandler(DataChanged);
}
///
/// Initializes a new instance of the class.
///
public DateTimeAxis()
{
InternalAxis = new Axes.DateTimeAxis();
}
///
/// Gets or sets CalendarWeekRule.
///
public CalendarWeekRule CalendarWeekRule
{
get
{
return GetValue(CalendarWeekRuleProperty);
}
set
{
SetValue(CalendarWeekRuleProperty, value);
}
}
///
/// Gets or sets FirstDateTime.
///
public DateTime FirstDateTime
{
get
{
return GetValue(FirstDateTimeProperty);
}
set
{
SetValue(FirstDateTimeProperty, value);
}
}
///
/// Gets or sets FirstDayOfWeek.
///
public DayOfWeek FirstDayOfWeek
{
get
{
return GetValue(FirstDayOfWeekProperty);
}
set
{
SetValue(FirstDayOfWeekProperty, value);
}
}
///
/// Gets or sets IntervalType.
///
public DateTimeIntervalType IntervalType
{
get
{
return GetValue(IntervalTypeProperty);
}
set
{
SetValue(IntervalTypeProperty, value);
}
}
///
/// Gets or sets LastDateTime.
///
public DateTime LastDateTime
{
get
{
return GetValue(LastDateTimeProperty);
}
set
{
SetValue(LastDateTimeProperty, value);
}
}
///
/// Gets or sets MinorIntervalType.
///
public DateTimeIntervalType MinorIntervalType
{
get
{
return GetValue(MinorIntervalTypeProperty);
}
set
{
SetValue(MinorIntervalTypeProperty, value);
}
}
///
/// Creates the internal model.
///
/// The internal axis.
public override Axes.Axis CreateModel()
{
SynchronizeProperties();
return InternalAxis;
}
///
/// Synchronizes the properties.
///
protected override void SynchronizeProperties()
{
base.SynchronizeProperties();
var a = (Axes.DateTimeAxis)InternalAxis;
a.IntervalType = IntervalType;
a.MinorIntervalType = MinorIntervalType;
a.FirstDayOfWeek = FirstDayOfWeek;
a.CalendarWeekRule = CalendarWeekRule;
if (FirstDateTime > DateTime.MinValue)
{
a.Minimum = Axes.DateTimeAxis.ToDouble(FirstDateTime);
}
if (LastDateTime < DateTime.MaxValue)
{
a.Maximum = Axes.DateTimeAxis.ToDouble(LastDateTime);
}
}
}
}