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

Change viewBox.py #2540

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Change viewBox.py #2540

wants to merge 2 commits into from

Conversation

aksy2512
Copy link
Contributor

Detail the reasoning behind the code change. If there is an associated issue that this PR will resolve add

Fixes #2415

I wrote the following code inside the updateViewRange function
image

change some mistake
@bbc131
Copy link
Contributor

bbc131 commented Dec 16, 2022

Hi @aksy2512,
I just had a look at your PR and also tested it quickly.

It solves the problem partly ;)
I took my example from #2415 and observe the following:
Making the region larger correctly triggers the right plot at some point to increase its x-range.
But if you make the region than smaller again, this will decrease the right plots x-range also! This definitely shouldn't be the case.
I just looked around in the updateViewRange method and saw, that one might have to adjust self.state['targetRange']?!
I hadn't the time to look closer into it, this is just a wild guess.

Another remark on formatting:
I suggest you to use black [1] to get a nice formatting.
For example I don't like the brackets at the "if"s and black would also normalize all whitespaces.
[1] https://pypi.org/project/black/

@j9ac9k
Copy link
Member

j9ac9k commented Dec 20, 2022

Hi @aksy2512

Sorry I haven't reviewed this yet. I had a long stint of being sick and this time of year it's difficult to allocate time for pyqtgraph work due to family time and so on.

generally speaking I'm not big on a bunch of if-statements like this, but if it works it works. ViewBox.py is a very sensitive to changes so even though the implementation looks right, I'm going to try and break this a few times.

I am fairly confident this PR (or a variant of this PR that fixes the same issue) will be merged before the next release.

@aksy2512
Copy link
Contributor Author

@j9ac9k I have rewritten the code and used "for" loop instead of the if statements. Please have a look.
Thanks

@@ -1573,6 +1572,14 @@ def updateViewRange(self, forceX=False, forceY=False):
maxRng[axis] = min(maxRng[axis], limits[axis][1] - limits[axis][0])
else:
maxRng[axis] = limits[axis][1] - limits[axis][0]
for axis in [0,1]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this line be removed and incorporate the logic added into the for loop above?

@j9ac9k
Copy link
Member

j9ac9k commented Jan 19, 2023

Hi @aksy2512

Sorry for the really long wait for feedback... ViewBox.py is among the most fragile parts of the library, so naturally I gravitate towards avoiding changes to it unless absolutely necessary.

There is an issue I'm a bit hung up on that I posted in the channel, why should the second limit be adjusted and not the first limit as this PR does.

I was going to suggest adding a test, but I can see we already skip the viewbox limits/resize test already as it's not working, so that would not be a reasonable request for a newcomer to the library :)

@j9ac9k
Copy link
Member

j9ac9k commented Jan 20, 2023

@bbc131 made a good point in this post here #2415 (comment)

They point out that the current logic in this PR makes no attempt to compare the computed upper bound of the range against xMax/yMax, so there could be a situation where the newly computed upper bound is outside of the specified limits. If that occurs, the lower bounds should likely be adjusted when the upper bound is placed at the xMax or yMax limit.

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.

ViewBox.setLimits() doesn't trigger update if view range not within new limits
3 participants