Skip to content

#3397 Resovles broken Axes labels and ticks on inverted axes#3401

Merged
swharden merged 9 commits intoScottPlot:mainfrom
BrianAtZetica:#3397
Mar 6, 2024
Merged

#3397 Resovles broken Axes labels and ticks on inverted axes#3401
swharden merged 9 commits intoScottPlot:mainfrom
BrianAtZetica:#3397

Conversation

@BrianAtZetica
Copy link
Contributor

This pull request resolves issue #3397
The issue stems from the use of terms Min and Max, which are not numerically minimum and maximum values when axes are inverted.

The fix was to find where the assumptions were in correct and locally calculate a "trueMin" or "trueMax" value.

I believe the proper fix would be to have IAxes retain Min and Max properties, but make them a true numeric minimum and maximum. This woul dbe augmented by an "Inverted" property.
Meanwhile, IXAxis would inherit Min, Max and Inverted, and could add Left and Right properties for convenience.
Similarly, IYAxis would inherit Min, Max and Inverted properties, but could add Top and Bottom peroperties for convenience.

Unfortunately that change would require extensive changes and careful planning and woud likely introduce breaking code changes for some users.

I believe my changes are safe for existing code.

Note that this pull request is dependant on pull request #3400 (I needed the inverted axes to be functioning to test all four scenarios (X/Y axes inverted with rotation)

Test code below.

using System;
using System.Linq;
using System.Windows;
using ScottPlot;

namespace Sandbox.WPF;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        double[] Xs = Enumerable.Range(1, 5000).Select(i => (double)i).ToArray();
        var signal = WpfPlot1.Plot.Add.SignalXY(Xs, Generate.Sin(count: 5000, oscillations: 4));
        //Test with normal X axis
        //WpfPlot1.Plot.Axes.SetLimitsX(left: 100.1, right: 5100);

        //Test with reversed X axis
        WpfPlot1.Plot.Axes.SetLimitsX(left: 5100, right: 100.1);

        //Test with rotated SignalXY plot on normal Y axis
        //signal.Data.Rotated = true;
        //WpfPlot1.Plot.Axes.SetLimitsY(bottom: 100.1, top: 5100);

        //Test with rotated SignalXY plot on reversed Y axis
        //signal.Data.Rotated = true;
        //WpfPlot1.Plot.Axes.SetLimitsY(bottom: 5100, top: 100.1);

        //test with generic data type (not double) on normal X axis
        //int[] Xs = Enumerable.Range(1, 5000).Select(i => (int)i).ToArray();
        //int[] Ys = Enumerable.Range(1, 5000).Select(i => (int)i).ToArray();
        //var signal = WpfPlot1.Plot.Add.SignalXY(Xs,Ys);
        //WpfPlot1.Plot.Axes.SetLimitsX(left: 100.1, right: 5100);

        //test with generic data type (not double) on reversed X axis
        //int[] Xs = Enumerable.Range(1, 5000).Select(i => (int)i).ToArray();
        //int[] Ys = Enumerable.Range(1, 5000).Select(i => (int)i).ToArray();
        //var signal = WpfPlot1.Plot.Add.SignalXY(Xs,Ys);
        //WpfPlot1.Plot.Axes.SetLimitsX(left: 5100, right: 100.1);

    }
}

…rvals

This is necessary because inverted axes have a negatve span
…true minimum and maximum values

This is necessary because inverted axes have a Min value larger than the Max value.
… values.

This is necessary becase inverted axes have a Min larger than the Max.
…set on teh AutoScaler.

This didn't seem to be necessary to resovle ScottPlot#3397, but seems appropriate.
…values are not Infinity.

(caught by unit tests)
@swharden
Copy link
Member

swharden commented Mar 6, 2024

Unfortunately that change would require extensive changes and careful planning and woud likely introduce breaking code changes for some users.

You made some great observations, and I'm really happy with the implementation you suggested in this PR - thanks so much!

To be honest I didn't even realize that the cookbook example on https://scottplot.net/cookbook/5.0/AdvancedAxis/InvertedAxis/ was currently broken 🤦 Thanks for identifying the issue and fixing it!

Current recipe Recipe after this PR
image image

@swharden swharden enabled auto-merge March 6, 2024 13:31
@swharden swharden disabled auto-merge March 6, 2024 13:31
@swharden swharden merged commit 31be01c into ScottPlot:main Mar 6, 2024
@BrianAtZetica BrianAtZetica deleted the #3397 branch March 7, 2024 00:39
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.

2 participants