Skip to content

Commit 0c6ccf6

Browse files
Added handle position checks to test_widgets.py
1 parent 2566eaa commit 0c6ccf6

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,19 +1105,30 @@ def test_range_slider(orientation):
11051105
# Check initial value is set correctly
11061106
assert_allclose(slider.val, (0.1, 0.34))
11071107

1108+
def handle_positions(slider):
1109+
if orientation == "vertical":
1110+
return [h.get_ydata()[0] for h in slider._handles]
1111+
else:
1112+
return [h.get_xdata()[0] for h in slider._handles]
1113+
11081114
slider.set_val((0.2, 0.6))
11091115
assert_allclose(slider.val, (0.2, 0.6))
1116+
assert_allclose(handle_positions(slider), (0.2, 0.6))
1117+
11101118
box = slider.poly.get_extents().transformed(ax.transAxes.inverted())
11111119
assert_allclose(box.get_points().flatten()[idx], [0.2, .25, 0.6, .75])
11121120

11131121
slider.set_val((0.2, 0.1))
11141122
assert_allclose(slider.val, (0.1, 0.2))
1123+
assert_allclose(handle_positions(slider), (0.1, 0.2))
11151124

11161125
slider.set_val((-1, 10))
11171126
assert_allclose(slider.val, (0, 1))
1127+
assert_allclose(handle_positions(slider), (0, 1))
11181128

11191129
slider.reset()
1120-
assert_allclose(slider.val, [0.1, 0.34])
1130+
assert_allclose(slider.val, (0.1, 0.34))
1131+
assert_allclose(handle_positions(slider), (0.1, 0.34))
11211132

11221133

11231134
def check_polygon_selector(event_sequence, expected_result, selections_count,

lib/matplotlib/widgets.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,18 +838,16 @@ def _update(self, event):
838838
self._active_handle = None
839839
return
840840

841+
# determine which handle was grabbed
841842
if self.orientation == "vertical":
842-
# determine which handle was grabbed
843-
event_handle = np.argmin(
843+
handle_index = np.argmin(
844844
np.abs([h.get_ydata()[0] - event.ydata for h in self._handles])
845845
)
846-
handle = self._handles[event_handle]
847846
else:
848-
# determine which handle was grabbed
849-
event_handle = np.argmin(
847+
handle_index = np.argmin(
850848
np.abs([h.get_xdata()[0] - event.xdata for h in self._handles])
851849
)
852-
handle = self._handles[event_handle]
850+
handle = self._handles[handle_index]
853851

854852
# these checks ensure smooth behavior if the handles swap which one
855853
# has a higher value. i.e. if one is dragged over and past the other.

0 commit comments

Comments
 (0)