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

Skip to content

Update Slider docs and type check slidermin and slidermax. #8134

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 10 commits into from
Feb 25, 2017
Merged
Prev Previous commit
Next Next commit
Bounds check returns value.
  • Loading branch information
heathhenley committed Feb 24, 2017
commit dc55f80f31316c48811a82dbe9d1cd4de9cd8338
19 changes: 9 additions & 10 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,17 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f',
if slidermax is not None and not hasattr(slidermax, 'val'):
raise ValueError("Argument slidermax ({}) has no 'val'"
.format(type(slidermax)))

self.closedmin = closedmin
self.closedmax = closedmax
self.slidermin = slidermin
self.slidermax = slidermax
self.drag_active = False
self.valmin = valmin
self.valmax = valmax
valinit = self._value_in_bounds(valinit)
Copy link
Member

Choose a reason for hiding this comment

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

👍

self.val = valinit
self.valinit = valinit
self.poly = ax.axvspan(valmin, valinit, 0, 1, **kwargs)

self.vline = ax.axvline(valinit, 0, 1, color='r', lw=1)

self.valfmt = valfmt
Expand All @@ -361,12 +365,7 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f',
self.cnt = 0
self.observers = {}

self.closedmin = closedmin
self.closedmax = closedmax
self.slidermin = slidermin
self.slidermax = slidermax
self.drag_active = False
self._value_in_bounds(valinit)
self.set_val(valinit)

def _value_in_bounds(self, val):
""" Makes sure self.val is with given bounds."""
Expand All @@ -388,7 +387,7 @@ def _value_in_bounds(self, val):
if not self.closedmax:
return
val = self.slidermax.val
return val
return val

def _update(self, event):
"""update the slider position"""
Expand All @@ -412,7 +411,7 @@ def _update(self, event):
event.canvas.release_mouse(self.ax)
return
val = event.xdata
self._value_in_bounds(val)
self.set_val(self._value_in_bounds(val))

def set_val(self, val):
xy = self.poly.xy
Expand Down