Skip to content

Fix scaling with locked aspect#3100

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
a17sol:locked-aspect-fix
Oct 13, 2024
Merged

Fix scaling with locked aspect#3100
j9ac9k merged 1 commit intopyqtgraph:masterfrom
a17sol:locked-aspect-fix

Conversation

@a17sol
Copy link
Copy Markdown
Contributor

@a17sol a17sol commented Jul 16, 2024

Summary

Fixes an undocumented (?) issue with scaling ViewBoxes with locked aspect ratio when the mouse is over the axes.

How to reproduce the issue

  1. Run the code:
import numpy as np
import pyqtgraph as pg

plot = pg.plot(np.random.normal(scale=10, size=100))
plot.disableAutoRange()
plot.setAspectLocked()

pg.exec()
  1. Position the mouse pointer on the vertical axis. Scroll the mouse wheel down a few clicks. The graph will zoom out.
  2. Move the mouse cursor to the horizontal axis and try scrolling the mouse wheel. The graph will jump back to its original state and stop responding.
  3. Move the mouse pointer to the graph and scroll the mouse wheel upwards a few clicks. The graph will jump back to the zoomed out state and start to zoom in.
  4. Move the mouse pointer to the horizontal axis and try scrolling the mouse wheel. The image will jump up and stop responding.

Bugs Found And Changes Made

  1. The ViewBox._resetTarget function had a wrong logic inside, which caused ViewBox to jump between different zoom states.
    Fixed by removing unnecessary if-condition.
    1.1 The function argument 'force' has become useless, so it has been removed from the signature and from calls using it.
  2. The ViewBox.scaleBy function treated x and y axes differently.
    A check has been added to determine which axis is the primary axis, and the secondary axis is scaled accordingly.

Results

When trying to reproduce the issue, there are no zoom jumps and mouse wheel works as expected.

@a17sol
Copy link
Copy Markdown
Contributor Author

a17sol commented Aug 6, 2024

Bump @j9ac9k

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 13, 2024

Thanks for your patience @a17sol the PR LGTM. ViewBox.py is a real fragile file to touch, and would likely benefit substantially from more tests so we can be more confident about making optimizations/refactors.

Merging!

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