From 4d878fc87a997d34caeafc38f1d28bd7072c311c Mon Sep 17 00:00:00 2001 From: Murdo R Ergeaux Date: Sun, 14 May 2023 15:28:57 +0100 Subject: [PATCH] Add example and fix for incorrect final tick on category axis (#1971) --- CHANGELOG.md | 1 + .../ExampleLibrary/Axes/CategoryAxisExamples.cs | 14 +++++++++++++- Source/OxyPlot/Axes/CategoryAxis.cs | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a6f6ad12..e1d7d2fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. - Example to Show/Hide Legend (#1470) - Example of BarSeries stacked and with labels (#1979) - Example of issue with AreaSeries tracker (#1982) +- Add example for CategoryAxis with custom MajorStep and uncentered ticks (#1971) ### Changed diff --git a/Source/Examples/ExampleLibrary/Axes/CategoryAxisExamples.cs b/Source/Examples/ExampleLibrary/Axes/CategoryAxisExamples.cs index 852f22d89..b00e80420 100644 --- a/Source/Examples/ExampleLibrary/Axes/CategoryAxisExamples.cs +++ b/Source/Examples/ExampleLibrary/Axes/CategoryAxisExamples.cs @@ -54,6 +54,18 @@ public static PlotModel ItemsSourceValues() [Example("MajorStep")] public static PlotModel MajorStepCategoryAxis() + { + var plotModel1 = new PlotModel { Title = "Major Step = 4, IsTickCentered = false" }; + var catAxis = new CategoryAxis { IsTickCentered = false, MajorStep = 4 }; + catAxis.Labels.AddRange(new[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }); + plotModel1.Axes.Add(catAxis); + var linearAxis = new LinearAxis { Position = AxisPosition.Left }; + plotModel1.Axes.Add(linearAxis); + return plotModel1; + } + + [Example("MajorStep, TickCentered")] + public static PlotModel MajorStepCategoryTickCenteredAxis() { var plotModel1 = new PlotModel { Title = "Major Step = 4, IsTickCentered = true" }; var catAxis = new CategoryAxis { IsTickCentered = true, MajorStep = 4 }; @@ -64,4 +76,4 @@ public static PlotModel MajorStepCategoryAxis() return plotModel1; } } -} \ No newline at end of file +} diff --git a/Source/OxyPlot/Axes/CategoryAxis.cs b/Source/OxyPlot/Axes/CategoryAxis.cs index 0494b3d72..3f5a74596 100644 --- a/Source/OxyPlot/Axes/CategoryAxis.cs +++ b/Source/OxyPlot/Axes/CategoryAxis.cs @@ -111,7 +111,7 @@ public override void GetTickValues( if (mv.Count > 0) { - var lastTick = mv[mv.Count - 1] + 1; + var lastTick = mv[mv.Count - 1] + this.MajorStep; if (lastTick < this.ClipMaximum + epsilon) { mv.Add(lastTick);