Skip to content

Commit 72d0a12

Browse files
authored
fix: radio button intepretation (#285)
1 parent 10b1a27 commit 72d0a12

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

mpl_interactions/helpers.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -330,20 +330,6 @@ def changeify(val, update):
330330
update({"new": val})
331331

332332

333-
def changeify_radio(val, labels, update):
334-
r"""Convert matplotlib radio button callback into the expected dictionary form.
335-
336-
matplolib radio buttons don't keep track what index is selected. So this
337-
figures out what the index is
338-
made a whole function bc its easier to use with partial then.
339-
340-
There doesn't seem to be a good way to determine which one was clicked if the
341-
radio button has multiple identical values but that's wildly niche
342-
and also probably means they're doing something they shouldn't. So: ¯\_(ツ)_/¯
343-
"""
344-
update({"new": labels.index(val)})
345-
346-
347333
def create_mpl_controls_fig(kwargs):
348334
"""
349335
Create a figure to hold matplotlib widgets.
@@ -452,13 +438,8 @@ def process_mpl_widget(val, update):
452438
a widget like scatter_selector without having to create a control figure.
453439
"""
454440
if isinstance(val, mwidgets.RadioButtons):
455-
# gotta set it to the zeroth index bc there's no reasonable way to determine
456-
# the current value the only way the current value is stored is through
457-
# the color of the circles. so could query that an extract but
458-
# oh boy do I ever not want to
459-
val.set_active(0)
460-
cb = val.on_clicked(partial(changeify_radio, labels=val.labels, update=update))
461-
return val.labels[0], val, cb, hash(repr(val.labels))
441+
cb = val.on_clicked(partial(changeify, update=partial(update, values=None)))
442+
return val.value_selected, val, cb, hash(repr(val.labels))
462443
elif isinstance(val, (mwidgets.Slider, mwidgets.RangeSlider, RangeSlider)):
463444
# TODO: proper inherit matplotlib rand
464445
# potential future improvement:
@@ -542,7 +523,7 @@ def kwarg_to_mpl_widget(
542523
radio_ax = fig.add_axes([0.2, 0.9 - widget_y - radio_height * n, width, radio_height * n])
543524
widget_y += radio_height * n + gap_height
544525
radio_buttons = mwidgets.RadioButtons(radio_ax, val, active=0)
545-
cb = radio_buttons.on_clicked(partial(changeify_radio, labels=val, update=update))
526+
cb = radio_buttons.on_clicked(partial(changeify, update=partial(update, values=None)))
546527
return val[0], radio_buttons, cb, widget_y, hash(repr(val))
547528
elif isinstance(val, mwidgets.AxesWidget):
548529
val, widget, cb, hash_ = process_mpl_widget(val, update)

0 commit comments

Comments
 (0)