Fix resizing ViewBox if aspect locked + apply ViewBox limits immediately#2799
Merged
j9ac9k merged 2 commits intopyqtgraph:masterfrom Oct 31, 2023
Merged
Fix resizing ViewBox if aspect locked + apply ViewBox limits immediately#2799j9ac9k merged 2 commits intopyqtgraph:masterfrom
j9ac9k merged 2 commits intopyqtgraph:masterfrom
Conversation
This commit fixes the following problems, whic occur if a `ViewBox` with locked aspect ratio is resized: 1. The visible range changes suddenly at some points. 2. The set limits are not taken into account.
Contributor
Author
|
I see, that the behaviour on resize is changed. |
The previous commit broke the behavior for locked aspect ratio and no limits on the view-range. The previous and thereby desired behavior is the following: Decreasing the size of a view keeps the view range constant, i.e. does implicitly zoom-out. If, afterwards, the size is increased again, the view range first stays constant (i.e. implicit zoom-in) until the previous range and zoom-level is reached again. Then, further increasing of the size extends the view range (i.e. keeping zoom-level constant).
Member
|
You've contributed enough to know that ViewBox.py is pretty complicated, and there is likely a lot of old/legacy codepaths there that are no longer relevant and just add to the confusion. One of my long-term goals was to greatly expand the test-code for ViewBox.py and then get to work on pruning out some of the more complex codepaths, in an attempt to simplify the class altogether. That, is clearly out of scope for this PR tho. Back to this PR, the fix you made looks good to me. Thanks for submitting it, and thank you @aksy2512 for the original PR that influenced this one. |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit fixes the following problems, whic occur if a
ViewBoxwith locked aspect ratio is resized:Note, this PR fixes also Issue #2415. (Thanks @aksy2512 for #2540, I took some ideas from your PR.)
You can reproduce this with the mwe below:
Run the script and then slowly decrease the window width.
You'll observe, that the minimum visible y value will go beyond -5, which is set as
yMinlimit.This is Issue 2.
If you continue to decrease the width, shortly after the y-axis labels 2 and -6 become visible, the y-range suddenly changes to around -4 ... 0, which is the above mentioned problem 1.
To improve traceability, I try to provide some info on why I changed what in the following:
This is, because my fix doesn't change one simple thing. Also I had some difficulties to understand the
updateViewRange()function and still doesn't understand everything, especially the part withinif aspect is not False ....viewRangetolimitsinupdateViewRange()is necessary to fix the limits issue (2).targetRange, when changingviewRangeis necessary shows me the mwe fromViewBox.setLimits()doesn't trigger update if view range not within new limits #2415:There, it all works fine if you increase the width of the
LinearRegionItem, i.e. the right plot gets updated if necessary.But if you then decrease the width of the
LinearRegionItemagain, the right plots x-range also decreases! This is prevented by updating thetargetRangehere.self._resetTarget()) since this causes the following problem:If you start decreasing the width of the
LinearRegionItemagain, you observe that the right plots x-range just slightly decreases before stopping!You might adjust the mwe and print the x-range on a change, i.e. add
p2.getViewBox().sigXRangeChanged.connect(lambda vb, range: print(range))to see this effect.This doesn't happen if we only adjust the
targetRangeparts whose correspondingviewRangeparts we changed.self._resetTarget(force=True)inresizeEvent(..), this fixes above described problem 1.self._resetTarget().It would be nice if we could get rid of this
if self.state['aspectLocked'] is Falsecompletely.Maybe someone knows a case, where this is needed?!
Minimum-working-example: