Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,25 @@ def test_check_button_props(fig_test, fig_ref):
cb.set_check_props({**check_props, 's': (24 / 2)**2})


@pytest.mark.parametrize("widget", [widgets.RadioButtons, widgets.CheckButtons])
def test__buttons_callbacks(ax, widget):
"""Tests what https://github.com/matplotlib/matplotlib/pull/31031 fixed"""
on_clicked = mock.Mock(spec=noop, return_value=None)
button = widget(ax, ["Test Button"])
button.on_clicked(on_clicked)
MouseEvent._from_ax_coords(
"button_press_event",
ax,
ax.transData.inverted().transform(ax.transAxes.transform(
# (x, y) of the 0th button defined at
# `{Check,Radio}Buttons._init_props`
(0.15, 0.5),
)),
1,
)._process()
on_clicked.assert_called_once()


def test_slider_slidermin_slidermax_invalid():
fig, ax = plt.subplots()
# test min/max with floats
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,11 +1110,11 @@ def _clicked(self, event):
if self.ignore(event) or event.button != 1 or not self.ax.contains(event)[0]:
return
idxs = [ # Indices of frames and of texts that contain the event.
*self._frames.contains(event)[1]["ind"],
*self._buttons.contains(event)[1]["ind"],
*[i for i, text in enumerate(self.labels) if text.contains(event)[0]]]
if idxs:
coords = self._frames.get_offset_transform().transform(
self._frames.get_offsets())
coords = self._buttons.get_offset_transform().transform(
self._buttons.get_offsets())
self.set_active( # Closest index, only looking in idxs.
idxs[(((event.x, event.y) - coords[idxs]) ** 2).sum(-1).argmin()])

Expand Down
Loading