Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 12 commits into from
Oct 17, 2017

Conversation

jcalbert
Copy link
Contributor

@jcalbert jcalbert commented Aug 31, 2017

PR Summary

Addresses #9129, allows the slider UI widget to snap to multiples of optional kwarg valstep.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@tacaswell tacaswell added this to the 2.2 (next next feature release) milestone Aug 31, 2017
Copy link
Member

@WeatherGod WeatherGod left a 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!)

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):
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@@ -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
Copy link
Member

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.

@tacaswell
Copy link
Member

I am 50/50 on rushing this for 2.1.

@jcalbert
Copy link
Contributor Author

Before setting it in stone, a few questions about expected behavior:

  1. Would it be preferable for the little blue bar to track the cursor while dragging, and then snap back to an allowed value on button_release?
  2. For valmin=.2, valmax=4.5, valstep=1.0 should the points go [0.2, 1.2, 2.2, 3.2, 4.2, 4.5] or [0.2, 1.0, 2.0, 3.0, 4.0, 4.5] ?

@WeatherGod
Copy link
Member

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.

@jcalbert
Copy link
Contributor Author

@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.

Copy link
Member

@dstansby dstansby left a 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
--------------------------
Copy link
Member

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

@jcalbert
Copy link
Contributor Author

jcalbert commented Sep 5, 2017

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?

@WeatherGod
Copy link
Member

WeatherGod commented Sep 5, 2017 via email

Copy link
Member

@WeatherGod WeatherGod left a 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!

@WeatherGod WeatherGod merged commit ffc20d4 into matplotlib:master Oct 17, 2017
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 13, 2018
@jcalbert jcalbert deleted the discrete_slider branch May 3, 2019 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants