Skip to content

Commit

Permalink
Merge pull request oxyplot#967 from objorke/dynamatt/bugfix-format-ex…
Browse files Browse the repository at this point in the history
…ception

Dynamatt/bugfix format exception
  • Loading branch information
objorke authored Aug 24, 2016
2 parents b923eba + c03223b commit ecd3e7f
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ All notable changes to this project will be documented in this file.
- Change default number format to "g6" in Axis base class (#841)
- Push packages to myget.org (#847)
- Improve tracker style (Windows Forms) (#106)
- Change the default format string to `null` for TimeSpanAxis and DateTimeAxis (#951)

### Removed
- StyleCop tasks (#556)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Levi Botelho <[email protected]>
Linquize
lsowen
Luka B
Matt Williams
Matthew Leibowitz <[email protected]>
Memphisch <[email protected]>
Mendel Monteiro-Beckerman
Expand Down
87 changes: 55 additions & 32 deletions Source/Examples/ExampleLibrary/Axes/DateTimeAxisExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ public class DateValue
public double Value { get; set; }
}

[Example("Default StringFormat")]
public static PlotModel DefaultValues()
{
return CreateExample(7, null);
}

[Example("StringFormat 'MMM dd\\nyyyy'")]
public static PlotModel StringFormat()
{
return CreateExample(7, "MMM dd\nyyyy");
}

private static PlotModel CreateExample(int days, string stringFormat)
{
var m = new PlotModel();
var startTime = new DateTime(2000, 1, 1);
var min = DateTimeAxis.ToDouble(startTime);
var max = min + days;
m.Axes.Add(new DateTimeAxis { Position = AxisPosition.Bottom, Minimum = min, Maximum = max, StringFormat = stringFormat });
m.Axes.Add(new DateTimeAxis { Position = AxisPosition.Left, Minimum = min, Maximum = max, StringFormat = stringFormat });
return m;
}

// [Example("DateTime Minimum bug")]
public static PlotModel Example1()
{
Expand Down Expand Up @@ -109,25 +132,25 @@ public static PlotModel DateTimeaxisPlotModel()

var plotModel1 = new PlotModel { Title = "DateTime axis" };
var dateTimeAxis1 = new DateTimeAxis
{
CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek,
FirstDayOfWeek = DayOfWeek.Monday,
Position = AxisPosition.Bottom
};
{
CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek,
FirstDayOfWeek = DayOfWeek.Monday,
Position = AxisPosition.Bottom
};
plotModel1.Axes.Add(dateTimeAxis1);
var linearAxis1 = new LinearAxis();
plotModel1.Axes.Add(linearAxis1);
var lineSeries1 = new LineSeries
{
Color = OxyColor.FromArgb(255, 78, 154, 6),
MarkerFill = OxyColor.FromArgb(255, 78, 154, 6),
MarkerStroke = OxyColors.ForestGreen,
MarkerType = MarkerType.Plus,
StrokeThickness = 1,
DataFieldX = "Date",
DataFieldY = "Value",
ItemsSource = data
};
{
Color = OxyColor.FromArgb(255, 78, 154, 6),
MarkerFill = OxyColor.FromArgb(255, 78, 154, 6),
MarkerStroke = OxyColors.ForestGreen,
MarkerType = MarkerType.Plus,
StrokeThickness = 1,
DataFieldX = "Date",
DataFieldY = "Value",
ItemsSource = data
};
plotModel1.Series.Add(lineSeries1);
return plotModel1;
}
Expand Down Expand Up @@ -179,27 +202,27 @@ public static PlotModel SunriseandsunsetinOslo()
var plotModel1 = new PlotModel { Title = "Sunrise and sunset in Oslo", Subtitle = "UTC time" };

var dateTimeAxis1 = new DateTimeAxis
{
CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek,
FirstDayOfWeek = DayOfWeek.Monday,
IntervalType = DateTimeIntervalType.Months,
MajorGridlineStyle = LineStyle.Solid,
Position = AxisPosition.Bottom,
StringFormat = "MMM"
};
{
CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek,
FirstDayOfWeek = DayOfWeek.Monday,
IntervalType = DateTimeIntervalType.Months,
MajorGridlineStyle = LineStyle.Solid,
Position = AxisPosition.Bottom,
StringFormat = "MMM"
};
plotModel1.Axes.Add(dateTimeAxis1);
var timeSpanAxis1 = new TimeSpanAxis { MajorGridlineStyle = LineStyle.Solid, Maximum = 86400, Minimum = 0, StringFormat = "h:mm" };
plotModel1.Axes.Add(timeSpanAxis1);
var areaSeries1 = new AreaSeries
{
ItemsSource = sunData,
DataFieldX = "Day",
DataFieldY = "Sunrise",
DataFieldX2 = "Day",
DataFieldY2 = "Sunset",
Fill = OxyColor.FromArgb(128, 255, 255, 0),
Color = OxyColors.Black
};
{
ItemsSource = sunData,
DataFieldX = "Day",
DataFieldY = "Sunrise",
DataFieldX2 = "Day",
DataFieldY2 = "Sunset",
Fill = OxyColor.FromArgb(128, 255, 255, 0),
Color = OxyColors.Black
};
plotModel1.Series.Add(areaSeries1);
return plotModel1;
}
Expand Down
32 changes: 32 additions & 0 deletions Source/Examples/ExampleLibrary/Axes/LinearAxisExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ namespace ExampleLibrary
[Examples("LinearAxis"), Tags("Axes")]
public static class LinearAxisExamples
{
[Example("Default StringFormat ('g6')")]
public static PlotModel StringFormat()
{
return CreateExample(1.2345678901234567890e5, 1.2345678901234567890e6, null);
}

[Example("StringFormat = 'g2'")]
public static PlotModel StringFormatG2()
{
return CreateExample(1.2345678901234567890e5, 1.2345678901234567890e6, "g2");
}

[Example("StringFormat = 'g10'")]
public static PlotModel StringFormatG10()
{
return CreateExample(1.2345678901234567890e5, 1.2345678901234567890e6, "g10");
}

[Example("StringFormat = 'f2'")]
public static PlotModel StringFormatF2()
{
return CreateExample(1.2345678901234567890e5, 1.2345678901234567890e6, "f2");
}

private static PlotModel CreateExample(double min, double max, string stringFormat)
{
var m = new PlotModel();
m.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Minimum = min, Maximum = max, StringFormat = stringFormat });
m.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Minimum = min, Maximum = max, StringFormat = stringFormat });
return m;
}

[Example("TickStyle: None")]
public static PlotModel TickStyleNone()
{
Expand Down
17 changes: 14 additions & 3 deletions Source/Examples/ExampleLibrary/Axes/TimeSpanAxisExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ public class TimeValue
public double Value { get; set; }
}

[Example("TimeSpan axis")]
public static PlotModel TimeSpanaxisPlotModel()
[Example("Default StringFormat")]
public static PlotModel TimeSpanaxisPlotModelDefault()
{
return TimeSpanaxisPlotModel(null);
}

[Example("StringFormat = 'h:mm'")]
public static PlotModel TimeSpanaxisPlotModel1()
{
return TimeSpanaxisPlotModel("h:mm");
}

private static PlotModel TimeSpanaxisPlotModel(string stringFormat)
{
var start = new TimeSpan(0, 0, 0, 0);
var end = new TimeSpan(0, 24, 0, 0);
Expand All @@ -40,7 +51,7 @@ public static PlotModel TimeSpanaxisPlotModel()
}

var plotModel1 = new PlotModel { Title = "TimeSpan axis" };
var timeSpanAxis1 = new TimeSpanAxis { Position = AxisPosition.Bottom, StringFormat = "h:mm" };
var timeSpanAxis1 = new TimeSpanAxis { Position = AxisPosition.Bottom, StringFormat = stringFormat };
plotModel1.Axes.Add(timeSpanAxis1);
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
plotModel1.Axes.Add(linearAxis1);
Expand Down
17 changes: 11 additions & 6 deletions Source/OxyPlot/Axes/Axis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,12 +1268,7 @@ internal virtual void UpdateIntervals(OxyRect plotArea)
this.ActualMinorStep = Math.Max(this.ActualMinorStep, this.MinimumMinorStep);
this.ActualMajorStep = Math.Max(this.ActualMajorStep, this.MinimumMajorStep);

this.ActualStringFormat = this.StringFormat;

if (this.ActualStringFormat == null)
{
this.ActualStringFormat = "g6";
}
this.ActualStringFormat = this.StringFormat ?? this.GetDefaultStringFormat();
}

/// <summary>
Expand Down Expand Up @@ -1339,6 +1334,16 @@ protected internal virtual void ResetCurrentValues()
{
}

/// <summary>
/// Gets the default format string.
/// </summary>
/// <returns>A format string.</returns>
/// <remarks>This format string is used if the StringFormat is not set.</remarks>
protected virtual string GetDefaultStringFormat()
{
return "g6";
}

/// <summary>
/// Applies a transformation after the inverse transform of the value.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions Source/OxyPlot/Axes/DateTimeAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ internal override void UpdateIntervals(OxyRect plotArea)
}
}

/// <summary>
/// Gets the default string format.
/// </summary>
/// <returns>
/// The format string.
/// </returns>
protected override string GetDefaultStringFormat()
{
return null;
}

/// <summary>
/// Formats the value to be used on the axis.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions Source/OxyPlot/Axes/TimeSpanAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ public override object GetValue(double x)
return TimeSpan.FromSeconds(x);
}

/// <summary>
/// Gets the default format string.
/// </summary>
/// <returns>
/// The default format string.
/// </returns>
protected override string GetDefaultStringFormat()
{
return null;
}

/// <summary>
/// Formats the value to be used on the axis.
/// </summary>
Expand Down

0 comments on commit ecd3e7f

Please sign in to comment.