From 040e03f74e8aa4caafae05c6fdeca100ea34a98e Mon Sep 17 00:00:00 2001 From: Oystein Bjorke Date: Wed, 24 Aug 2016 22:47:54 +0200 Subject: [PATCH 1/5] Add examples --- .../Axes/DateTimeAxisExamples.cs | 87 ++++++++++++------- .../ExampleLibrary/Axes/LinearAxisExamples.cs | 32 +++++++ .../Axes/TimeSpanAxisExamples.cs | 17 +++- 3 files changed, 101 insertions(+), 35 deletions(-) diff --git a/Source/Examples/ExampleLibrary/Axes/DateTimeAxisExamples.cs b/Source/Examples/ExampleLibrary/Axes/DateTimeAxisExamples.cs index c739cd2a3..650b3015b 100644 --- a/Source/Examples/ExampleLibrary/Axes/DateTimeAxisExamples.cs +++ b/Source/Examples/ExampleLibrary/Axes/DateTimeAxisExamples.cs @@ -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() { @@ -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; } @@ -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; } diff --git a/Source/Examples/ExampleLibrary/Axes/LinearAxisExamples.cs b/Source/Examples/ExampleLibrary/Axes/LinearAxisExamples.cs index e030c842a..9c45e25db 100644 --- a/Source/Examples/ExampleLibrary/Axes/LinearAxisExamples.cs +++ b/Source/Examples/ExampleLibrary/Axes/LinearAxisExamples.cs @@ -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() { diff --git a/Source/Examples/ExampleLibrary/Axes/TimeSpanAxisExamples.cs b/Source/Examples/ExampleLibrary/Axes/TimeSpanAxisExamples.cs index d92d34afc..3111ca7f0 100644 --- a/Source/Examples/ExampleLibrary/Axes/TimeSpanAxisExamples.cs +++ b/Source/Examples/ExampleLibrary/Axes/TimeSpanAxisExamples.cs @@ -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); @@ -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); From 571c79a8cb1bf9f93794abcd589f7cc6266c611c Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 10 Aug 2016 12:22:54 +1000 Subject: [PATCH 2/5] Changed the default axis string format to "g" instead of "g6". "g6" was throwing System.FormatException when calling string.Format() in FormatValueOverride() in TimeSpanAxis.cs. --- Source/OxyPlot/Axes/Axis.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/OxyPlot/Axes/Axis.cs b/Source/OxyPlot/Axes/Axis.cs index 7f9d357d7..494cd417a 100644 --- a/Source/OxyPlot/Axes/Axis.cs +++ b/Source/OxyPlot/Axes/Axis.cs @@ -1272,7 +1272,7 @@ internal virtual void UpdateIntervals(OxyRect plotArea) if (this.ActualStringFormat == null) { - this.ActualStringFormat = "g6"; + this.ActualStringFormat = "g"; } } From cd29a9f6b5c11593364fcb485dae89c94860e29c Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 10 Aug 2016 12:39:45 +1000 Subject: [PATCH 3/5] Added to changelog and contributors. --- CHANGELOG.md | 1 + CONTRIBUTORS | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e66d4f84..362aa3fc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 axis format string to "g" instead of "g6" (#951) ### Removed - StyleCop tasks (#556) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 894989334..2546fe0a9 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -63,6 +63,7 @@ Levi Botelho Linquize lsowen Luka B +Matt Williams Matthew Leibowitz Memphisch Mendel Monteiro-Beckerman From 7ae95ff0634af64107996931ddfe8daeecbe6a76 Mon Sep 17 00:00:00 2001 From: Oystein Bjorke Date: Wed, 24 Aug 2016 22:48:33 +0200 Subject: [PATCH 4/5] Add virtual Axis.GetDefaultStringFormat() method --- Source/OxyPlot/Axes/Axis.cs | 17 +++++++++++------ Source/OxyPlot/Axes/DateTimeAxis.cs | 11 +++++++++++ Source/OxyPlot/Axes/TimeSpanAxis.cs | 11 +++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Source/OxyPlot/Axes/Axis.cs b/Source/OxyPlot/Axes/Axis.cs index 494cd417a..002e043e1 100644 --- a/Source/OxyPlot/Axes/Axis.cs +++ b/Source/OxyPlot/Axes/Axis.cs @@ -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 = "g"; - } + this.ActualStringFormat = this.StringFormat ?? this.GetDefaultStringFormat(); } /// @@ -1339,6 +1334,16 @@ protected internal virtual void ResetCurrentValues() { } + /// + /// Gets the default format string. + /// + /// A format string. + /// This format string is used if the StringFormat is not set. + protected virtual string GetDefaultStringFormat() + { + return "g6"; + } + /// /// Applies a transformation after the inverse transform of the value. /// diff --git a/Source/OxyPlot/Axes/DateTimeAxis.cs b/Source/OxyPlot/Axes/DateTimeAxis.cs index 08482c20a..c0ad2f8df 100644 --- a/Source/OxyPlot/Axes/DateTimeAxis.cs +++ b/Source/OxyPlot/Axes/DateTimeAxis.cs @@ -258,6 +258,17 @@ internal override void UpdateIntervals(OxyRect plotArea) } } + /// + /// Gets the default string format. + /// + /// + /// The format string. + /// + protected override string GetDefaultStringFormat() + { + return null; + } + /// /// Formats the value to be used on the axis. /// diff --git a/Source/OxyPlot/Axes/TimeSpanAxis.cs b/Source/OxyPlot/Axes/TimeSpanAxis.cs index c774582c0..6832660a1 100644 --- a/Source/OxyPlot/Axes/TimeSpanAxis.cs +++ b/Source/OxyPlot/Axes/TimeSpanAxis.cs @@ -51,6 +51,17 @@ public override object GetValue(double x) return TimeSpan.FromSeconds(x); } + /// + /// Gets the default format string. + /// + /// + /// The default format string. + /// + protected override string GetDefaultStringFormat() + { + return null; + } + /// /// Formats the value to be used on the axis. /// From c03223b860f86c811afc9b689bb109583945d905 Mon Sep 17 00:00:00 2001 From: Oystein Bjorke Date: Wed, 24 Aug 2016 22:51:49 +0200 Subject: [PATCH 5/5] Update the change log --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 362aa3fc7..0a71d9824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,7 +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 axis format string to "g" instead of "g6" (#951) +- Change the default format string to `null` for TimeSpanAxis and DateTimeAxis (#951) ### Removed - StyleCop tasks (#556)