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

Skip to content

Commit f6c97b5

Browse files
committed
Fix name coordinate handle: N and S were swapped
1 parent 4cd2b20 commit f6c97b5

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

lib/matplotlib/widgets.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,13 +2778,13 @@ def __init__(self, ax, onselect, drawtype='box',
27782778
'markeredgecolor': (props or {}).get('edgecolor', 'black'),
27792779
**cbook.normalize_kwargs(handle_props, Line2D._alias_map)}
27802780

2781-
self._corner_order = ['NW', 'NE', 'SE', 'SW']
2781+
self._corner_order = ['SW', 'SE', 'NE', 'NW']
27822782
xc, yc = self.corners
27832783
self._corner_handles = ToolHandles(self.ax, xc, yc,
27842784
marker_props=handle_props,
27852785
useblit=self.useblit)
27862786

2787-
self._edge_order = ['W', 'N', 'E', 'S']
2787+
self._edge_order = ['W', 'S', 'E', 'N']
27882788
xe, ye = self.edge_centers
27892789
self._edge_handles = ToolHandles(self.ax, xe, ye, marker='s',
27902790
marker_props=handle_props,
@@ -2824,6 +2824,7 @@ def _press(self, event):
28242824
# button, ...
28252825
if self._interactive and self._to_draw.get_visible():
28262826
self._set_active_handle(event)
2827+
self._extents_on_press = self.extents
28272828
else:
28282829
self._active_handle = None
28292830

@@ -2889,22 +2890,31 @@ def _release(self, event):
28892890

28902891
self.update()
28912892
self._active_handle = None
2893+
self._extents_on_press = None
28922894

28932895
return False
28942896

28952897
def _onmove(self, event):
28962898
"""Motion notify event handler."""
2899+
2900+
28972901
# resize an existing shape
28982902
if self._active_handle and self._active_handle != 'C':
28992903
x0, x1, y0, y1 = self._extents_on_press
2904+
# Switch variables so that only x1 and/or y1 are updated on move.
2905+
if self._active_handle in ['W', 'SW', 'NW']:
2906+
x0, x1 = x1, event.xdata
2907+
if self._active_handle in ['S', 'SW', 'SE']:
2908+
y0, y1 = y1, event.ydata
2909+
29002910
if self._active_handle in ['E', 'W'] + self._corner_order:
29012911
x1 = event.xdata
29022912
if self._active_handle in ['N', 'S'] + self._corner_order:
29032913
y1 = event.ydata
29042914

29052915
# move existing shape
2906-
elif (('move' in self._state or self._active_handle == 'C' or
2907-
(self.drag_from_anywhere and self._contains(event))) and
2916+
elif (self._active_handle == 'C' or
2917+
(self.drag_from_anywhere and self._contains(event)) and
29082918
self._extents_on_press is not None):
29092919
x0, x1, y0, y1 = self._extents_on_press
29102920
dx = event.xdata - self._eventpress.xdata
@@ -3041,7 +3051,6 @@ def _set_active_handle(self, event):
30413051

30423052
if 'move' in self._state:
30433053
self._active_handle = 'C'
3044-
self._extents_on_press = self.extents
30453054
# Set active handle as closest handle, if mouse click is close enough.
30463055
elif m_dist < self.grab_range * 2:
30473056
# Prioritise center handle over other handles
@@ -3052,7 +3061,6 @@ def _set_active_handle(self, event):
30523061
if self.drag_from_anywhere and self._contains(event):
30533062
# Check if we've clicked inside the region
30543063
self._active_handle = 'C'
3055-
self._extents_on_press = self.extents
30563064
else:
30573065
self._active_handle = None
30583066
return
@@ -3063,15 +3071,6 @@ def _set_active_handle(self, event):
30633071
# Closest to an edge handle
30643072
self._active_handle = self._edge_order[e_idx]
30653073

3066-
# Save coordinates of rectangle at the start of handle movement.
3067-
x0, x1, y0, y1 = self.extents
3068-
# Switch variables so that only x1 and/or y1 are updated on move.
3069-
if self._active_handle in ['W', 'SW', 'NW']:
3070-
x0, x1 = x1, event.xdata
3071-
if self._active_handle in ['N', 'NW', 'NE']:
3072-
y0, y1 = y1, event.ydata
3073-
self._extents_on_press = x0, x1, y0, y1
3074-
30753074
def _contains(self, event):
30763075
"""Return True if event is within the patch."""
30773076
return self._to_draw.contains(event, radius=0)[0]

0 commit comments

Comments
 (0)