-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Adds option for Slider to snap to discrete values #9137
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
Conversation
…iples of 'valstep' (and valmax, if closedmax is True).
makes the value take on integer multiples of parameter valstep.
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 a few small comments. Otherwise, this looks good. This will need a whats_new section, but if you hurry, it could get into v2.1 (cut is tonight, hopefully!)
lib/matplotlib/widgets.py
Outdated
slidermax=None, dragging=True, **kwargs): | ||
def __init__(self, ax, label, valmin, valmax, valstep=None, valinit=0.5, | ||
valfmt='%1.2f', closedmin=True, closedmax=True, | ||
slidermin=None, slidermax=None, dragging=True, **kwargs): |
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.
Don't change the order of the arguments in an existing function, even if they are keyword arguments.
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.
What's the proper place to put them, before kwargs?
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.
yes
lib/matplotlib/widgets.py
Outdated
@@ -368,6 +372,8 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f', | |||
|
|||
def _value_in_bounds(self, val): | |||
""" Makes sure self.val is with given bounds.""" | |||
if self.valstep: | |||
val = round(val/self.valstep)*self.valstep |
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.
should use np.round()
to get consistent behavior in python 2.7 and py3k.
I am 50/50 on rushing this for 2.1. |
Before setting it in stone, a few questions about expected behavior:
|
Personally, I think it should track the cursor. It provides visual feedback to the user that the slider is active. However, is it possible to implement without it reporting non-valid numbers? For the second point, that's a toughie. I think I like the first option better. |
@WeatherGod I tried a version with the tracking cursor, but I don't think it 'feels' right. Even with some tick marks as a guide, it feels like the UI is just being laggy. You can try it here. |
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.
Nice new feature! Just a small formatting comment, but otherwise this looks good to me.
@@ -0,0 +1,8 @@ | |||
Slider UI widget can snap to discrete values | |||
-------------------------- |
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.
These dashes should be exactly the same length as the title
By the way, in doing this PR noticed that the slider widget doesn't implement blitting like most of the other widgets do. Is that something worth looking into? |
Blitting makes sense for things like drawing a rubber band, but I doubt
it'll really be useful for sliders. If people find that there is room for
performance improvements, then possibly. For now, I'd leave that off.
…On Tue, Sep 5, 2017 at 4:49 PM, J. ***@***.***> wrote:
^BTW, I noticed that the slider widget doesn't implement blitting like
most of the other widgets do. Is that something worth looking into?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9137 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-HqRZ8t_Zq6Yvu_qpt-tqxx_rd2Fks5sfbPugaJpZM4PJI1p>
.
|
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.
Thank you for your patience. This looks good!
PR Summary
Addresses #9129, allows the slider UI widget to snap to multiples of optional kwarg
valstep
.PR Checklist