Skip to content

Commit

Permalink
Merge b5f9033 into d408876
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 9, 2017
2 parents d408876 + b5f9033 commit 9470e48
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions holoviews/core/dimension.py
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
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
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
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

0 comments on commit 9470e48

Please sign in to comment.