Skip to content

Commit 948a26f

Browse files
authored
Merge pull request #30096 from QuLogic/fix-offsetbox-pick
2 parents 9cf3990 + 731f454 commit 948a26f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,9 @@ def __init__(self, ref_artist, use_blit=False):
15041504
@staticmethod
15051505
def _picker(artist, mouseevent):
15061506
# A custom picker to prevent dragging on mouse scroll events
1507-
return (artist.contains(mouseevent) and mouseevent.name != "scroll_event"), {}
1507+
if mouseevent.name == "scroll_event":
1508+
return False, {}
1509+
return artist.contains(mouseevent)
15081510

15091511
# A property, not an attribute, to maintain picklability.
15101512
canvas = property(lambda self: self.ref_artist.get_figure(root=True).canvas)

lib/matplotlib/tests/test_offsetbox.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,13 @@ def test_draggable_in_subfigure():
460460
fig.canvas.draw() # Texts are non-pickable until the first draw.
461461
MouseEvent("button_press_event", fig.canvas, 1, 1)._process()
462462
assert ann._draggable.got_artist
463+
# Stop dragging the annotation.
464+
MouseEvent("button_release_event", fig.canvas, 1, 1)._process()
465+
assert not ann._draggable.got_artist
466+
# A scroll event should not initiate a drag.
467+
MouseEvent("scroll_event", fig.canvas, 1, 1)._process()
468+
assert not ann._draggable.got_artist
469+
# An event outside the annotation should not initiate a drag.
470+
bbox = ann.get_window_extent()
471+
MouseEvent("button_press_event", fig.canvas, bbox.x1+2, bbox.y1+2)._process()
472+
assert not ann._draggable.got_artist

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy