Skip to content

Commit 4b50a8f

Browse files
committed
Fix name coordinate handle: N and S were swapped
1 parent 3af610c commit 4b50a8f

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
@@ -2846,13 +2846,13 @@ def __init__(self, ax, onselect, drawtype='box',
28462846
'edgecolor', 'black'),
28472847
**cbook.normalize_kwargs(handle_props, Line2D)}
28482848

2849-
self._corner_order = ['NW', 'NE', 'SE', 'SW']
2849+
self._corner_order = ['SW', 'SE', 'NE', 'NW']
28502850
xc, yc = self.corners
28512851
self._corner_handles = ToolHandles(self.ax, xc, yc,
28522852
marker_props=self._handle_props,
28532853
useblit=self.useblit)
28542854

2855-
self._edge_order = ['W', 'N', 'E', 'S']
2855+
self._edge_order = ['W', 'S', 'E', 'N']
28562856
xe, ye = self.edge_centers
28572857
self._edge_handles = ToolHandles(self.ax, xe, ye, marker='s',
28582858
marker_props=self._handle_props,
@@ -2892,6 +2892,7 @@ def _press(self, event):
28922892
# button, ...
28932893
if self._interactive and self._selection_artist.get_visible():
28942894
self._set_active_handle(event)
2895+
self._extents_on_press = self.extents
28952896
else:
28962897
self._active_handle = None
28972898

@@ -2957,22 +2958,31 @@ def _release(self, event):
29572958

29582959
self.update()
29592960
self._active_handle = None
2961+
self._extents_on_press = None
29602962

29612963
return False
29622964

29632965
def _onmove(self, event):
29642966
"""Motion notify event handler."""
2967+
2968+
29652969
# resize an existing shape
29662970
if self._active_handle and self._active_handle != 'C':
29672971
x0, x1, y0, y1 = self._extents_on_press
2972+
# Switch variables so that only x1 and/or y1 are updated on move.
2973+
if self._active_handle in ['W', 'SW', 'NW']:
2974+
x0, x1 = x1, event.xdata
2975+
if self._active_handle in ['S', 'SW', 'SE']:
2976+
y0, y1 = y1, event.ydata
2977+
29682978
if self._active_handle in ['E', 'W'] + self._corner_order:
29692979
x1 = event.xdata
29702980
if self._active_handle in ['N', 'S'] + self._corner_order:
29712981
y1 = event.ydata
29722982

29732983
# move existing shape
2974-
elif (('move' in self._state or self._active_handle == 'C' or
2975-
(self.drag_from_anywhere and self._contains(event))) and
2984+
elif (self._active_handle == 'C' or
2985+
(self.drag_from_anywhere and self._contains(event)) and
29762986
self._extents_on_press is not None):
29772987
x0, x1, y0, y1 = self._extents_on_press
29782988
dx = event.xdata - self._eventpress.xdata
@@ -3110,7 +3120,6 @@ def _set_active_handle(self, event):
31103120

31113121
if 'move' in self._state:
31123122
self._active_handle = 'C'
3113-
self._extents_on_press = self.extents
31143123
# Set active handle as closest handle, if mouse click is close enough.
31153124
elif m_dist < self.grab_range * 2:
31163125
# Prioritise center handle over other handles
@@ -3121,7 +3130,6 @@ def _set_active_handle(self, event):
31213130
if self.drag_from_anywhere and self._contains(event):
31223131
# Check if we've clicked inside the region
31233132
self._active_handle = 'C'
3124-
self._extents_on_press = self.extents
31253133
else:
31263134
self._active_handle = None
31273135
return
@@ -3132,15 +3140,6 @@ def _set_active_handle(self, event):
31323140
# Closest to an edge handle
31333141
self._active_handle = self._edge_order[e_idx]
31343142

3135-
# Save coordinates of rectangle at the start of handle movement.
3136-
x0, x1, y0, y1 = self.extents
3137-
# Switch variables so that only x1 and/or y1 are updated on move.
3138-
if self._active_handle in ['W', 'SW', 'NW']:
3139-
x0, x1 = x1, event.xdata
3140-
if self._active_handle in ['N', 'NW', 'NE']:
3141-
y0, y1 = y1, event.ydata
3142-
self._extents_on_press = x0, x1, y0, y1
3143-
31443143
def _contains(self, event):
31453144
"""Return True if event is within the patch."""
31463145
return self._selection_artist.contains(event, radius=0)[0]

0 commit comments

Comments
 (0)