Skip to content
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

Defined Dimension.step and used it for dynamic widgets #1257

Merged
merged 1 commit into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions holoviews/core/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ class Dimension(param.Parameterized):
may be an inbuilt constructor (such as int, str, float) or a
custom class object.""")

step = param.Number(default=None, doc="""
Optional floating point step specifying how frequently the
underlying space should be sampled. May be used to define a
discrete sampling of over the range.""")

unit = param.String(default=None, allow_None=True, doc="""
Optional unit string associated with the Dimension. For
instance, the string 'm' may be used represent units of meters
Expand Down
2 changes: 2 additions & 0 deletions holoviews/plotting/bokeh/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def create_widget(self, dim, holomap=None, editable=False):
int_type = isinstance(dim.type, type) and issubclass(dim.type, int)
if isinstance(dim_range, int) or int_type:
step = 1
elif dim.step is not None:
step = dim.step
else:
step = 10**((round(math.log10(dim_range))-3))
if editable:
Expand Down
2 changes: 2 additions & 0 deletions holoviews/plotting/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ def get_widgets(self):
int_type = isinstance(dim.type, type) and issubclass(dim.type, int)
if isinstance(dim_range, int) or int_type:
step = 1
elif dim.step is not None:
step = dim.step
else:
step = 10**(round(math.log10(dim_range))-3)
init_dim_vals.append(dim_vals[0])
Expand Down
13 changes: 13 additions & 0 deletions tests/testbokehwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ def test_bokeh_server_dynamic_range_float(self):
self.assertEqual(label.value, '3.1')
self.assertIs(mapping, None)

def test_bokeh_server_dynamic_range_float_step(self):
dim = Dimension('x', range=(3.1, 11.2), step=0.1)
widget, label, mapping = BokehServerWidgets.create_widget(dim, editable=True)
self.assertIsInstance(widget, Slider)
self.assertEqual(widget.value, 3.1)
self.assertEqual(widget.start, 3.1)
self.assertEqual(widget.end, 11.2)
self.assertEqual(widget.step, 0.1)
self.assertIsInstance(label, TextInput)
self.assertEqual(label.title, dim.pprint_label)
self.assertEqual(label.value, '3.1')
self.assertIs(mapping, None)

def test_bokeh_server_dynamic_range_not_editable(self):
dim = Dimension('x', range=(3.1, 11.2))
widget, label, mapping = BokehServerWidgets.create_widget(dim, editable=False)
Expand Down