Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8229572

Browse filesBrowse files
committed
Cleaner logic in _onmove
1 parent 09942f0 commit 8229572
Copy full SHA for 8229572

File tree

1 file changed

+17
-9
lines changed
Filter options

1 file changed

+17
-9
lines changed

‎lib/matplotlib/widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/widgets.py
+17-9Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,6 +2985,7 @@ def _press(self, event):
29852985
self.update()
29862986

29872987
if self._active_handle is None and not self.ignore_event_outside:
2988+
# Start drawing a new rectangle
29882989
x = event.xdata
29892990
y = event.ydata
29902991
self.visible = False
@@ -3051,17 +3052,26 @@ def _release(self, event):
30513052
return False
30523053

30533054
def _onmove(self, event):
3054-
"""Motion notify event handler."""
3055+
"""
3056+
Motion notify event handler.
30553057
3056-
state = self._state
3057-
rotate = ('rotate' in state and
3058-
self._active_handle in self._corner_order)
3058+
This can do one of four things:
3059+
- Translate
3060+
- Rotate
3061+
- Re-size
3062+
- Contine the creation of a new shape
3063+
"""
30593064
xy = np.array([event.xdata, event.ydata])
30603065
xy_press = np.array([self._eventpress.xdata, self._eventpress.ydata])
30613066

30623067
# The calculations are done for rotation at zero: we apply inverse
30633068
# transformation to events except when we rotate and move
3069+
state = self._state
3070+
rotate = ('rotate' in state and
3071+
self._active_handle in self._corner_order)
30643072
move = self._active_handle == 'C'
3073+
resize = self._active_handle and not move
3074+
30653075
if not move and not rotate:
30663076
inv_tr = self._get_rotation_transform().inverted()
30673077
xy = inv_tr.transform(xy)
@@ -3089,8 +3099,7 @@ def _onmove(self, event):
30893099
np.arctan2(a[1]-b[1], a[0]-b[0]))
30903100
self.rotation = np.rad2deg(self._rotation_on_press + angle)
30913101

3092-
# resize an existing shape
3093-
elif self._active_handle and self._active_handle != 'C':
3102+
elif resize:
30943103
size_on_press = [x1 - x0, y1 - y0]
30953104
center = [x0 + size_on_press[0] / 2, y0 + size_on_press[1] / 2]
30963105

@@ -3143,16 +3152,15 @@ def _onmove(self, event):
31433152
x1 = x0 + sign * abs(y1 - y0) * \
31443153
self._aspect_ratio_correction
31453154

3146-
# move existing shape
3147-
elif self._active_handle == 'C':
3155+
elif move:
31483156
x0, x1, y0, y1 = self._extents_on_press
31493157
x0 += dxy[0]
31503158
x1 += dxy[0]
31513159
y0 += dxy[1]
31523160
y1 += dxy[1]
31533161

3154-
# new shape
31553162
else:
3163+
# Create a new shape
31563164
self._rotation = 0
31573165
# Don't create a new rectangle if there is already one when
31583166
# ignore_event_outside=True

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.