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

[Bug]: PolygonSelector should hide itself when zoom/pan is active #28165

Open
anntzer opened this issue May 3, 2024 · 6 comments
Open

[Bug]: PolygonSelector should hide itself when zoom/pan is active #28165

anntzer opened this issue May 3, 2024 · 6 comments
Labels
Good first issue Open a pull request against these issues if there are no active ones! topic: widgets/UI

Comments

@anntzer
Copy link
Contributor

anntzer commented May 3, 2024

Bug summary

When interactive zoom/pan is active, widgets.PolygonSelector correctly disables itself (i.e. clicking and dragging zooms or pans the axes without creating a selection), but the selector cursor (a big circular marker) stays drawn at its last position (prior to zoom/pan being turned on). It should instead be hidden.

Code for reproduction

from pylab import *
ls = mpl.widgets.PolygonSelector(gca(), print)
# Move the cursor around, then toggle zoom pan via the toolbar
# or by pressing "o"/"p"

Actual outcome

The PolygonSelector cursor stays drawn at an incorrect position.

Expected outcome

The cursor is temporarily hidden.

Additional information

Probably a good first issue? I suspect the fix is along the lines of

diff --git i/lib/matplotlib/widgets.py w/lib/matplotlib/widgets.py
index eaa35e2544..4cd48ab3c1 100644
--- i/lib/matplotlib/widgets.py
+++ w/lib/matplotlib/widgets.py
@@ -4000,11 +4000,15 @@ class PolygonSelector(_SelectorWidget):
         # needs to process the move callback even if there is no button press.
         # _SelectorWidget.onmove include logic to ignore move event if
         # _eventpress is None.
-        if not self.ignore(event):
+        if self.ignore(event):
+            if not self.canvas.widgetlock.available(self) and self._xys:
+                self._xys[-1] = (np.nan, np.nan)
+                self._draw_polygon()
+            return False
+        else:
             event = self._clean_event(event)
             self._onmove(event)
             return True
-        return False
 
     def _onmove(self, event):
         """Cursor move event handler."""

i.e. if something else is active, just hide the last point of the polygon. However this patch doesn't handle interaction with the various extra widget states (moving, etc.); likely it should only apply in the "position pending" mode (last else block of _onmove).

Operating system

No response

Matplotlib Version

3.10.0.dev125+g63156f2ca6

Matplotlib Backend

qtagg

Python version

3.12

Jupyter version

no

Installation

git checkout

@anntzer anntzer added topic: widgets/UI Good first issue Open a pull request against these issues if there are no active ones! labels May 3, 2024
Copy link

github-actions bot commented May 3, 2024

Good first issue - notes for new contributors

This issue is suited to new contributors because it does not require understanding of the
Matplotlib internals. To get started, please see our contributing
guide
.

We do not assign issues. Check the Development section in the sidebar for linked pull
requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please
collaborate on the work by reviewing it rather than duplicating it in a competing PR.

If something is unclear, please reach out on any of our communication
channels
.

@Kaustbh
Copy link

Kaustbh commented May 7, 2024

Hi there! I'm new to open source, but I'm eager to dive in and help out. I came across this issue and I think I can tackle it, can I work on it ?

@ksunden
Copy link
Member

ksunden commented May 7, 2024

Hi @Kaustbh,

We do not assign any issues, and anybody is free to work on anything. In general, we tend to give preference to the first person to open a PR (absent a clear technical reason to opt for a newer PR).

In this case, there are no PRs yet for this issue.

See also https://matplotlib.org/devdocs/devel/contribute.html#work-on-an-issue

@Kaustbh
Copy link

Kaustbh commented May 10, 2024

@anntzer , I tried to reproduce the issue , can you tell what is the problem . (backend = WebAgg) ,

demo.mp4

@Kaustbh
Copy link

Kaustbh commented May 12, 2024

@anntzer please reply .

@anntzer
Copy link
Contributor Author

anntzer commented May 12, 2024

Your movie doesn't play, and as noted in the report this is with qtagg (or likely tkagg should work too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Open a pull request against these issues if there are no active ones! topic: widgets/UI
Projects
None yet
Development

No branches or pull requests

3 participants