Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug on GetDataLimits when plot is empty #1581

Merged
merged 3 commits into from
Jan 23, 2022
Merged

Conversation

EFeru
Copy link
Contributor

@EFeru EFeru commented Jan 21, 2022

When plot is empty meaning no plottable in GetPlottables() then the returned limits have the initial values:

double xMin = double.PositiveInfinity;
double xMax = double.NegativeInfinity;
double yMin = double.PositiveInfinity;
double yMax = double.NegativeInfinity;

Now, if the user calls:

AxisLimits limits = formsPlot1.Plot.GetDataLimits();
formsPlot1.Plot.SetOuterViewLimits(limits.XMin, limits.XMax, limits.YMin, limits.YMax);

if is not possible to interract with the plot anymore (zoom, pan, etc.) beacause the limits set are flipped. This PR fixes the returned limits to the correct ones.

@swharden
Copy link
Member

Good catch @EFeru!

Re-stating the problem to remind my future self, the GetDataLimits() method works by initially setting limits to extreme inverted values with the expectation that data points from plottables will pull them into an expected range

public AxisLimits GetDataLimits(int xAxisIndex = 0, int yAxisIndex = 0)
{
double xMin = double.PositiveInfinity;
double xMax = double.NegativeInfinity;
double yMin = double.PositiveInfinity;
double yMax = double.NegativeInfinity;

...but if there are no plottables with data, the returned limits are wacky and inverted.

This PR detects if the initial values were never changed (as they would be expected to by data) and sets them to the opposite value

@swharden swharden merged commit c4c1646 into ScottPlot:master Jan 23, 2022
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