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

Skip to content

Commit 5650b88

Browse files
committed
Fix name coordinate handle: N and S were swapped
1 parent 8cad1b6 commit 5650b88

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

2825-
self._corner_order = ['NW', 'NE', 'SE', 'SW']
2825+
self._corner_order = ['SW', 'SE', 'NE', 'NW']
28262826
xc, yc = self.corners
28272827
self._corner_handles = ToolHandles(self.ax, xc, yc,
28282828
marker_props=self._handle_props,
28292829
useblit=self.useblit)
28302830

2831-
self._edge_order = ['W', 'N', 'E', 'S']
2831+
self._edge_order = ['W', 'S', 'E', 'N']
28322832
xe, ye = self.edge_centers
28332833
self._edge_handles = ToolHandles(self.ax, xe, ye, marker='s',
28342834
marker_props=self._handle_props,
@@ -2868,6 +2868,7 @@ def _press(self, event):
28682868
# button, ...
28692869
if self._interactive and self._selection_artist.get_visible():
28702870
self._set_active_handle(event)
2871+
self._extents_on_press = self.extents
28712872
else:
28722873
self._active_handle = None
28732874

@@ -2933,22 +2934,31 @@ def _release(self, event):
29332934

29342935
self.update()
29352936
self._active_handle = None
2937+
self._extents_on_press = None
29362938

29372939
return False
29382940

29392941
def _onmove(self, event):
29402942
"""Motion notify event handler."""
2943+
2944+
29412945
# resize an existing shape
29422946
if self._active_handle and self._active_handle != 'C':
29432947
x0, x1, y0, y1 = self._extents_on_press
2948+
# Switch variables so that only x1 and/or y1 are updated on move.
2949+
if self._active_handle in ['W', 'SW', 'NW']:
2950+
x0, x1 = x1, event.xdata
2951+
if self._active_handle in ['S', 'SW', 'SE']:
2952+
y0, y1 = y1, event.ydata
2953+
29442954
if self._active_handle in ['E', 'W'] + self._corner_order:
29452955
x1 = event.xdata
29462956
if self._active_handle in ['N', 'S'] + self._corner_order:
29472957
y1 = event.ydata
29482958

29492959
# move existing shape
2950-
elif (('move' in self._state or self._active_handle == 'C' or
2951-
(self.drag_from_anywhere and self._contains(event))) and
2960+
elif (self._active_handle == 'C' or
2961+
(self.drag_from_anywhere and self._contains(event)) and
29522962
self._extents_on_press is not None):
29532963
x0, x1, y0, y1 = self._extents_on_press
29542964
dx = event.xdata - self._eventpress.xdata
@@ -3086,7 +3096,6 @@ def _set_active_handle(self, event):
30863096

30873097
if 'move' in self._state:
30883098
self._active_handle = 'C'
3089-
self._extents_on_press = self.extents
30903099
# Set active handle as closest handle, if mouse click is close enough.
30913100
elif m_dist < self.grab_range * 2:
30923101
# Prioritise center handle over other handles
@@ -3097,7 +3106,6 @@ def _set_active_handle(self, event):
30973106
if self.drag_from_anywhere and self._contains(event):
30983107
# Check if we've clicked inside the region
30993108
self._active_handle = 'C'
3100-
self._extents_on_press = self.extents
31013109
else:
31023110
self._active_handle = None
31033111
return
@@ -3108,15 +3116,6 @@ def _set_active_handle(self, event):
31083116
# Closest to an edge handle
31093117
self._active_handle = self._edge_order[e_idx]
31103118

3111-
# Save coordinates of rectangle at the start of handle movement.
3112-
x0, x1, y0, y1 = self.extents
3113-
# Switch variables so that only x1 and/or y1 are updated on move.
3114-
if self._active_handle in ['W', 'SW', 'NW']:
3115-
x0, x1 = x1, event.xdata
3116-
if self._active_handle in ['N', 'NW', 'NE']:
3117-
y0, y1 = y1, event.ydata
3118-
self._extents_on_press = x0, x1, y0, y1
3119-
31203119
def _contains(self, event):
31213120
"""Return True if event is within the patch."""
31223121
return self._selection_artist.contains(event, radius=0)[0]

0 commit comments

Comments
 (0)