Skip to content

Commit ea665e9

Browse files
committed
Rename marker_props to handle_props and maxdist to handle_grab_distance for RectangleSelector
1 parent 9385642 commit ea665e9

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def onselect(epress, erelease):
9898
pass
9999

100100
tool = widgets.EllipseSelector(ax, onselect=onselect,
101-
maxdist=10, interactive=True)
101+
handle_grab_distance=10, interactive=True)
102102
tool.extents = (100, 150, 100, 150)
103103

104104
# drag the rectangle
@@ -152,8 +152,9 @@ def onselect(epress, erelease):
152152
pass
153153

154154
tool = widgets.RectangleSelector(ax, onselect=onselect,
155-
maxdist=10, interactive=True,
156-
marker_props={'markerfacecolor': 'r',
155+
handle_grab_distance=10,
156+
interactive=True,
157+
handle_props={'markerfacecolor': 'r',
157158
'markeredgecolor': 'b'})
158159
tool.extents = (100, 150, 100, 150)
159160

lib/matplotlib/widgets.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,7 @@ def on_select(min: float, max: float) -> Any
20272027
20282028
span_stays : bool, default: False
20292029
If True, the span stays visible after the mouse is released.
2030-
Deprecated, use interactive instead.
2030+
Deprecated, use *interactive* instead.
20312031
20322032
interactive : bool, default: False
20332033
Whether to draw a set of handles that allow interaction with the
@@ -2511,12 +2511,14 @@ class RectangleSelector(_SelectorWidget):
25112511

25122512
_shape_klass = Rectangle
25132513

2514+
@_api.rename_parameter("3.5", "maxdist", "handle_grab_distance")
2515+
@_api.rename_parameter("3.5", "marker_props", "handle_props")
25142516
@_api.delete_parameter("3.5", "drawtype")
25152517
@_api.delete_parameter("3.5", "lineprops")
25162518
def __init__(self, ax, onselect, drawtype='box',
25172519
minspanx=0, minspany=0, useblit=False,
25182520
lineprops=None, rectprops=None, spancoords='data',
2519-
button=None, maxdist=10, marker_props=None,
2521+
button=None, handle_grab_distance=10, handle_props=None,
25202522
interactive=False, state_modifier_keys=None,
25212523
drag_from_anywhere=False):
25222524
r"""
@@ -2568,10 +2570,19 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
25682570
Button(s) that trigger rectangle selection.
25692571
25702572
maxdist : float, default: 10
2573+
Distance in pixels within which the interactive tool handles can be
2574+
activated. Deprecated, use *handle_grab_distance* instead.
2575+
2576+
handle_grab_distance : float, default: 10
25712577
Distance in pixels within which the interactive tool handles can be
25722578
activated.
25732579
25742580
marker_props : dict
2581+
Properties with which the interactive handles are drawn. Currently
2582+
not implemented and ignored. Deprecated, use *handle_props*
2583+
instead.
2584+
2585+
handle_props : dict
25752586
Properties with which the interactive handles are drawn. Currently
25762587
not implemented and ignored.
25772588
@@ -2643,13 +2654,13 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
26432654
self.spancoords = spancoords
26442655
self._drawtype = drawtype
26452656

2646-
self.maxdist = maxdist
2657+
self.handle_grab_distance = handle_grab_distance
26472658

26482659
if rectprops is None:
26492660
props = dict(markeredgecolor='r')
26502661
else:
26512662
props = dict(markeredgecolor=rectprops.get('edgecolor', 'r'))
2652-
props.update(cbook.normalize_kwargs(marker_props, Line2D._alias_map))
2663+
props.update(cbook.normalize_kwargs(handle_props, Line2D._alias_map))
26532664
self._corner_order = ['NW', 'NE', 'SE', 'SW']
26542665
xc, yc = self.corners
26552666
self._corner_handles = ToolHandles(self.ax, xc, yc, marker_props=props,
@@ -2899,10 +2910,11 @@ def _set_active_handle(self, event):
28992910
self._active_handle = 'C'
29002911
self._extents_on_press = self.extents
29012912
# Set active handle as closest handle, if mouse click is close enough.
2902-
elif m_dist < self.maxdist * 2:
2913+
elif m_dist < self.handle_grab_distance * 2:
29032914
# Prioritise center handle over other handles
29042915
self._active_handle = 'C'
2905-
elif c_dist > self.maxdist and e_dist > self.maxdist:
2916+
elif (c_dist > self.handle_grab_distance and
2917+
e_dist > self.handle_grab_distance):
29062918
# Not close to any handles
29072919
if self.drag_from_anywhere and self._contains(event):
29082920
# Check if we've clicked inside the region

0 commit comments

Comments
 (0)