Skip to content

Fix DateTimeAutomatic tick generation for inverted axes#4900

Merged
swharden merged 3 commits intoScottPlot:mainfrom
manaruto:fix-datetimeautomatic-inverted-axes
Jun 18, 2025
Merged

Fix DateTimeAutomatic tick generation for inverted axes#4900
swharden merged 3 commits intoScottPlot:mainfrom
manaruto:fix-datetimeautomatic-inverted-axes

Conversation

@manaruto
Copy link
Contributor

@manaruto manaruto commented Apr 5, 2025

This pull request fixes an issue where no ticks are generated when using DateTimeAutomatic on an inverted axis.

Changes Made

DateTimeAutomatic.cs

  • DateTimeAutomatic::Regenerate(...) now uses range.Length instead of range.Span.
    
  • range.Span can be negative when the axis is inverted, which caused tick calculation logic to fail.
    
  • Using range.Length ensures a consistent, non-negative span for accurate tick generation regardless of axis orientation.
    

Before / After

Before: No ticks appeared on inverted DateTime axes.

After: Ticks render correctly even if the axis is inverted.
            var myPlot = formsPlot1.Plot;

            DateTime start = new(2025, 01, 01);
            TimeSpan tt = new TimeSpan(0, 20, 0);
            DateTime[] xs = Generate.ConsecutiveDateTimes(100, start, tt);
            double[] ys = Generate.RandomWalk(100);


            var sig = myPlot.Add.SignalXY(xs, ys);
            sig.Data.Rotated = true;

            myPlot.Axes.AutoScaler.InvertedY = true;
            myPlot.Axes.Left.TickGenerator = new ScottPlot.TickGenerators.DateTimeAutomatic();

inverted axes

@swharden
Copy link
Member

Great fix @manaruto, thanks so much! 🚀

@swharden swharden enabled auto-merge June 18, 2025 12:40
@swharden swharden merged commit 23f441d into ScottPlot:main Jun 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DateTime axes: improve support for inverted axes

2 participants