-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Slider class for JupyterViz
This provides API parity with the previous Tornado viz.
- Loading branch information
Showing
4 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class UserParam: | ||
_ERROR_MESSAGE = "Missing or malformed inputs for '{}' Option '{}'" | ||
|
||
def maybe_raise_error(self, param_type, valid): | ||
if valid: | ||
return | ||
msg = self._ERROR_MESSAGE.format(param_type, self.label) | ||
raise ValueError(msg) | ||
|
||
|
||
class Slider(UserParam): | ||
""" | ||
A number-based slider input with settable increment. | ||
Example: | ||
slider_option = Slider("My Slider", value=123, min=10, max=200, step=0.1) | ||
""" | ||
|
||
def __init__( | ||
self, | ||
label="", | ||
value=None, | ||
min=None, | ||
max=None, | ||
step=1, | ||
): | ||
self.label = label | ||
self.value = value | ||
self.min = min | ||
self.max = max | ||
self.step = step | ||
|
||
# Validate option type to make sure values are supplied properly | ||
valid = not (self.value is None or self.min is None or self.max is None) | ||
self.maybe_raise_error("slider", valid) | ||
|
||
self.is_float_slider = any( | ||
isinstance(n, float) for n in (value, min, max, step) | ||
) | ||
|
||
def get(self, attr): | ||
return getattr(self, attr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .jupyter_viz import JupyterViz, make_text # noqa | ||
from .jupyter_viz import JupyterViz, make_text, Slider # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters