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

Method _set_active_handle

lib/matplotlib/widgets.py:3837–3863  ·  view source on GitHub ↗

Set active handle based on the location of the mouse event.

(self, event)

Source from the content-addressed store, hash-verified

3835 self._selection_artist.set_angle(self.rotation)
3836
3837 def _set_active_handle(self, event):
3838 """Set active handle based on the location of the mouse event."""
3839 # Note: event.xdata/ydata in data coordinates, event.x/y in pixels
3840 c_idx, c_dist = self._corner_handles.closest(event.x, event.y)
3841 e_idx, e_dist = self._edge_handles.closest(event.x, event.y)
3842 m_idx, m_dist = self._center_handle.closest(event.x, event.y)
3843
3844 if 'move' in self._state:
3845 self._active_handle = 'C'
3846 # Set active handle as closest handle, if mouse click is close enough.
3847 elif m_dist < self.grab_range * 2:
3848 # Prioritise center handle over other handles
3849 self._active_handle = 'C'
3850 elif c_dist > self.grab_range and e_dist > self.grab_range:
3851 # Not close to any handles
3852 if self.drag_from_anywhere and self._contains(event):
3853 # Check if we've clicked inside the region
3854 self._active_handle = 'C'
3855 else:
3856 self._active_handle = None
3857 return
3858 elif c_dist < e_dist:
3859 # Closest to a corner handle
3860 self._active_handle = self._corner_order[c_idx]
3861 else:
3862 # Closest to an edge handle
3863 self._active_handle = self._edge_order[e_idx]
3864
3865 def _contains(self, event):
3866 """Return True if event is within the patch."""

Callers 1

_pressMethod · 0.95

Calls 2

_containsMethod · 0.95
closestMethod · 0.45

Tested by

no test coverage detected