Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ All notable changes to this project will be documented in this file.

- Example to demonstrate how to create vertical BarSeries

### Added
- DateTimeAxis.ActualIntervalType and DateTimeAxis.ActualMinorIntervalType protected properties

### Fixed
- DateTimeAxis converting local time rather than UTC to TimeZone

Expand Down
76 changes: 42 additions & 34 deletions Source/OxyPlot/Axes/DateTimeAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,25 @@ public class DateTimeAxis : LinearAxis
private static readonly double MinDayValue = (DateTime.MinValue - TimeOrigin).TotalDays;

/// <summary>
/// The actual interval type.
/// Gets or sets the actual interval type.
/// </summary>
private DateTimeIntervalType actualIntervalType;
/// <remarks>
/// <see cref="ActualIntervalType"/> should be set in <see cref="CalculateActualInterval"/>.
/// The value should be based on the value of <see cref="IntervalType"/> and should not be
/// <see cref="DateTimeIntervalType.Auto"/>.
/// </remarks>
protected DateTimeIntervalType ActualIntervalType { get; set; }

/// <summary>
/// The actual minor interval type.
/// Gets or sets the actual minor interval type.
/// </summary>
private DateTimeIntervalType actualMinorIntervalType;
/// <remarks>
/// <see cref="ActualMinorIntervalType"/> should be set in
/// <see cref="CalculateActualInterval"/>. The value should be based on the value of
/// <see cref="MinorIntervalType"/> and should not be
/// <see cref="DateTimeIntervalType.Auto"/>.
/// </remarks>
protected DateTimeIntervalType ActualMinorIntervalType { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref = "DateTimeAxis" /> class.
Expand Down Expand Up @@ -204,9 +215,9 @@ public override void GetTickValues(
out IList<double> majorLabelValues, out IList<double> majorTickValues, out IList<double> minorTickValues)
{
minorTickValues = this.CreateDateTimeTickValues(
this.ClipMinimum, this.ClipMaximum, this.ActualMinorStep, this.actualMinorIntervalType);
this.ClipMinimum, this.ClipMaximum, this.ActualMinorStep, this.ActualMinorIntervalType);
majorTickValues = this.CreateDateTimeTickValues(
this.ClipMinimum, this.ClipMaximum, this.ActualMajorStep, this.actualIntervalType);
this.ClipMinimum, this.ClipMaximum, this.ActualMajorStep, this.ActualIntervalType);
majorLabelValues = majorTickValues;

minorTickValues = AxisUtilities.FilterRedundantMinorTicks(majorTickValues, minorTickValues);
Expand Down Expand Up @@ -237,27 +248,27 @@ public override object GetValue(double x)
internal override void UpdateIntervals(OxyRect plotArea)
{
base.UpdateIntervals(plotArea);
switch (this.actualIntervalType)
switch (this.ActualIntervalType)
{
case DateTimeIntervalType.Years:
this.ActualMinorStep = 31;
this.actualMinorIntervalType = DateTimeIntervalType.Years;
this.ActualMinorIntervalType = DateTimeIntervalType.Years;
if (this.StringFormat == null)
{
this.ActualStringFormat = "yyyy";
}

break;
case DateTimeIntervalType.Months:
this.actualMinorIntervalType = DateTimeIntervalType.Months;
this.ActualMinorIntervalType = DateTimeIntervalType.Months;
if (this.StringFormat == null)
{
this.ActualStringFormat = "yyyy-MM-dd";
}

break;
case DateTimeIntervalType.Weeks:
this.actualMinorIntervalType = DateTimeIntervalType.Days;
this.ActualMinorIntervalType = DateTimeIntervalType.Days;
this.ActualMajorStep = 7;
this.ActualMinorStep = 1;
if (this.StringFormat == null)
Expand Down Expand Up @@ -298,9 +309,6 @@ internal override void UpdateIntervals(OxyRect plotArea)
}

break;



case DateTimeIntervalType.Milliseconds:
this.ActualMinorStep = this.ActualMajorStep;
if (this.ActualStringFormat == null)
Expand All @@ -309,7 +317,7 @@ internal override void UpdateIntervals(OxyRect plotArea)
}

break;

case DateTimeIntervalType.Manual:
break;
case DateTimeIntervalType.Auto:
Expand Down Expand Up @@ -406,77 +414,77 @@ protected override double CalculateActualInterval(double availableSize, double m
interval = nextInterval;
}

this.actualIntervalType = this.IntervalType;
this.actualMinorIntervalType = this.MinorIntervalType;
this.ActualIntervalType = this.IntervalType;
this.ActualMinorIntervalType = this.MinorIntervalType;

if (this.IntervalType == DateTimeIntervalType.Auto)
{
this.actualIntervalType = DateTimeIntervalType.Milliseconds;
this.ActualIntervalType = DateTimeIntervalType.Milliseconds;

if (interval >= 1.0 / 24 / 60 / 60)
{
this.actualIntervalType = DateTimeIntervalType.Seconds;
this.ActualIntervalType = DateTimeIntervalType.Seconds;
}

if (interval >= 1.0 / 24 / 60)
{
this.actualIntervalType = DateTimeIntervalType.Minutes;
this.ActualIntervalType = DateTimeIntervalType.Minutes;
}

if (interval >= 1.0 / 24)
{
this.actualIntervalType = DateTimeIntervalType.Hours;
this.ActualIntervalType = DateTimeIntervalType.Hours;
}

if (interval >= 1)
{
this.actualIntervalType = DateTimeIntervalType.Days;
this.ActualIntervalType = DateTimeIntervalType.Days;
}

if (interval >= 30)
{
this.actualIntervalType = DateTimeIntervalType.Months;
this.ActualIntervalType = DateTimeIntervalType.Months;
}

if (range >= 365.25)
{
this.actualIntervalType = DateTimeIntervalType.Years;
this.ActualIntervalType = DateTimeIntervalType.Years;
}
}

if (this.actualIntervalType == DateTimeIntervalType.Months)
if (this.ActualIntervalType == DateTimeIntervalType.Months)
{
double monthsRange = range / 30.5;
interval = this.CalculateActualInterval(availableSize, maxIntervalSize, monthsRange, this.MinimumMajorIntervalCount, this.MaximumMajorIntervalCount);
}

if (this.actualIntervalType == DateTimeIntervalType.Years)
if (this.ActualIntervalType == DateTimeIntervalType.Years)
{
double yearsRange = range / 365.25;
interval = this.CalculateActualInterval(availableSize, maxIntervalSize, yearsRange, this.MinimumMajorIntervalCount, this.MaximumMajorIntervalCount);
}

if (this.actualMinorIntervalType == DateTimeIntervalType.Auto)
if (this.ActualMinorIntervalType == DateTimeIntervalType.Auto)
{
switch (this.actualIntervalType)
switch (this.ActualIntervalType)
{
case DateTimeIntervalType.Years:
this.actualMinorIntervalType = DateTimeIntervalType.Months;
this.ActualMinorIntervalType = DateTimeIntervalType.Months;
break;
case DateTimeIntervalType.Months:
this.actualMinorIntervalType = DateTimeIntervalType.Days;
this.ActualMinorIntervalType = DateTimeIntervalType.Days;
break;
case DateTimeIntervalType.Weeks:
this.actualMinorIntervalType = DateTimeIntervalType.Days;
this.ActualMinorIntervalType = DateTimeIntervalType.Days;
break;
case DateTimeIntervalType.Days:
this.actualMinorIntervalType = DateTimeIntervalType.Hours;
this.ActualMinorIntervalType = DateTimeIntervalType.Hours;
break;
case DateTimeIntervalType.Hours:
this.actualMinorIntervalType = DateTimeIntervalType.Minutes;
this.ActualMinorIntervalType = DateTimeIntervalType.Minutes;
break;
default:
this.actualMinorIntervalType = DateTimeIntervalType.Days;
this.ActualMinorIntervalType = DateTimeIntervalType.Days;
break;
}
}
Expand Down
Loading