Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix OffsetBox custom picker #30096

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,9 @@ def __init__(self, ref_artist, use_blit=False):
@staticmethod
def _picker(artist, mouseevent):
# A custom picker to prevent dragging on mouse scroll events
return (artist.contains(mouseevent) and mouseevent.name != "scroll_event"), {}
if mouseevent.name == "scroll_event":
return False, {}
return artist.contains(mouseevent)

# A property, not an attribute, to maintain picklability.
canvas = property(lambda self: self.ref_artist.get_figure(root=True).canvas)
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,13 @@ def test_draggable_in_subfigure():
fig.canvas.draw() # Texts are non-pickable until the first draw.
MouseEvent("button_press_event", fig.canvas, 1, 1)._process()
assert ann._draggable.got_artist
# Stop dragging the annotation.
MouseEvent("button_release_event", fig.canvas, 1, 1)._process()
assert not ann._draggable.got_artist
# A scroll event should not initiate a drag.
MouseEvent("scroll_event", fig.canvas, 1, 1)._process()
assert not ann._draggable.got_artist
# An event outside the annotation should not initiate a drag.
bbox = ann.get_window_extent()
MouseEvent("button_press_event", fig.canvas, bbox.x1+2, bbox.y1+2)._process()
assert not ann._draggable.got_artist
Loading