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

Method _onmove

lib/matplotlib/widgets.py:4265–4301  ·  view source on GitHub ↗

Cursor move event handler.

(self, event)

Source from the content-addressed store, hash-verified

4263 return True
4264
4265 def _onmove(self, event):
4266 """Cursor move event handler."""
4267 # Move the active vertex (ToolHandle).
4268 if self._active_handle_idx >= 0:
4269 idx = self._active_handle_idx
4270 self._xys[idx] = (event.xdata, event.ydata)
4271 # Also update the end of the polygon line if the first vertex is
4272 # the active handle and the polygon is completed.
4273 if idx == 0 and self._selection_completed:
4274 self._xys[-1] = (event.xdata, event.ydata)
4275
4276 # Move all vertices.
4277 elif 'move_all' in self._state and self._eventpress:
4278 dx = event.xdata - self._eventpress.xdata
4279 dy = event.ydata - self._eventpress.ydata
4280 for k in range(len(self._xys)):
4281 x_at_press, y_at_press = self._xys_at_press[k]
4282 self._xys[k] = x_at_press + dx, y_at_press + dy
4283
4284 # Do nothing if completed or waiting for a move.
4285 elif (self._selection_completed
4286 or 'move_vertex' in self._state or 'move_all' in self._state):
4287 return
4288
4289 # Position pending vertex.
4290 else:
4291 # Calculate distance to the start vertex.
4292 x0, y0 = \
4293 self._selection_artist.get_transform().transform(self._xys[0])
4294 v0_dist = np.hypot(x0 - event.x, y0 - event.y)
4295 # Lock on to the start vertex if near it and ready to complete.
4296 if len(self._xys) > 3 and v0_dist < self.grab_range:
4297 self._xys[-1] = self._xys[0]
4298 else:
4299 self._xys[-1] = (event.xdata, event.ydata)
4300
4301 self._draw_polygon()
4302
4303 def _on_key_press(self, event):
4304 """Key press event handler."""

Callers 1

onmoveMethod · 0.95

Calls 3

_draw_polygonMethod · 0.95
transformMethod · 0.45
get_transformMethod · 0.45

Tested by

no test coverage detected