MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _onmove

Method _onmove

lib/matplotlib/widgets.py:3583–3722  ·  view source on GitHub ↗

Motion notify event handler. This can do one of four things: - Translate - Rotate - Re-size - Continue the creation of a new shape

(self, event)

Source from the content-addressed store, hash-verified

3581
3582
3583 def _onmove(self, event):
3584 """
3585 Motion notify event handler.
3586
3587 This can do one of four things:
3588 - Translate
3589 - Rotate
3590 - Re-size
3591 - Continue the creation of a new shape
3592 """
3593 eventpress = self._eventpress
3594 # The calculations are done for rotation at zero: we apply inverse
3595 # transformation to events except when we rotate and move
3596 state = self._state
3597 action = self._get_action()
3598
3599 xdata, ydata = event.xdata, event.ydata
3600 if action == _RectangleSelectorAction.RESIZE:
3601 inv_tr = self._get_rotation_transform().inverted()
3602 xdata, ydata = inv_tr.transform([xdata, ydata])
3603 eventpress.xdata, eventpress.ydata = inv_tr.transform(
3604 (eventpress.xdata, eventpress.ydata))
3605
3606 dx = xdata - eventpress.xdata
3607 dy = ydata - eventpress.ydata
3608 # refmax is used when moving the corner handle with the square state
3609 # and is the maximum between refx and refy
3610 refmax = None
3611 if self._use_data_coordinates:
3612 refx, refy = dx, dy
3613 else:
3614 # Get dx/dy in display coordinates
3615 refx = event.x - eventpress.x
3616 refy = event.y - eventpress.y
3617
3618 x0, x1, y0, y1 = self._extents_on_press
3619 # rotate an existing shape
3620 if action == _RectangleSelectorAction.ROTATE:
3621 # calculate angle abc
3622 a = (eventpress.xdata, eventpress.ydata)
3623 b = self.center
3624 c = (xdata, ydata)
3625 angle = (np.arctan2(c[1]-b[1], c[0]-b[0]) -
3626 np.arctan2(a[1]-b[1], a[0]-b[0]))
3627 self.rotation = np.rad2deg(self._rotation_on_press + angle)
3628
3629 elif action == _RectangleSelectorAction.RESIZE:
3630 size_on_press = [x1 - x0, y1 - y0]
3631 center = (x0 + size_on_press[0] / 2, y0 + size_on_press[1] / 2)
3632
3633 # Keeping the center fixed
3634 if 'center' in state:
3635 # hh, hw are half-height and half-width
3636 if 'square' in state:
3637 # when using a corner, find which reference to use
3638 if self._active_handle in self._corner_order:
3639 refmax = max(refx, refy, key=abs)
3640 if self._active_handle in ['E', 'W'] or refmax == refx:

Callers

nothing calls this directly

Calls 5

_get_actionMethod · 0.95
signMethod · 0.80
invertedMethod · 0.45
transformMethod · 0.45

Tested by

no test coverage detected