New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a RangeSlider widget #18829
Create a RangeSlider widget #18829
Conversation
lib/matplotlib/widgets.py
Outdated
s1 = super()._format(val[0]) | ||
s2 = super()._format(val[1]) | ||
# fmt.get_offset is actually the multiplicative factor, if any. | ||
return (s1 + self._fmt.get_offset(), s2 + self._fmt.get_offset()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may need to pass both values to format_ticks
to ensure that the offset is consistent for both, though maybe this is okay due to self.slidermin
and self.slidermax
in the super class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is saved by the slidermin
and slidermax
. It would be nice to pass both values simultaneously to format_ticks
so I'll just make _format
not part of the superclass. There has to be same branching on self.valfmt
in RangeSlider anyway so theres not much loss in each slider implementing _format
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some docs are missing.
Is there any chance of this going into 3.4? |
It needs a second reviewer. |
I just noticed that vertical is not tested; could you add tests that also check the other orientation? Depending on how things works, it may just be sufficient to parameterize the test for both. |
Also add a test of the polygon points to make sure that the slider is being rendered correctly.
Good catch. I added a pytest parametrize to also test the vertical orientation, as well I added that the polygon's points are what we'd expect. |
Thanks for the contribution! 👍 |
PR Summary
Closes: #18563
Creates a SliderWidget that has a movable min and movable max. This enables doing things like this:
The
RangeSlider
is as analogous toSlider
with the major difference being thatval
is an array rather than a float. To accomplish this I made a new class_SliderBase
that both the sliders inherit their callback and other shared functionality from.PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).