Skip to content

Commit

Permalink
Fixed issue with Selection1D on Table (#3267)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 9, 2018
1 parent b17886e commit 4f52bb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions holoviews/plotting/bokeh/tabular.py
Expand Up @@ -79,16 +79,16 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
self._execute_hooks(element)
self.drawn = True

for cb in self.callbacks:
cb.initialize()

title = self._get_title_div(self.keys[-1], '10pt')
if title:
plot = Column(title, table)
self.handles['title'] = title
else:
plot = table
self.handles['plot'] = plot

for cb in self.callbacks:
cb.initialize()
return plot

def _get_columns(self, element, data):
Expand Down
22 changes: 22 additions & 0 deletions holoviews/tests/plotting/bokeh/testcallbacks.py
Expand Up @@ -342,6 +342,16 @@ def test_selection1d_resolves(self):
resolved = callback.resolve_attr_spec(spec, selected, model=selected)
self.assertEqual(resolved, {'id': selected.ref['id'], 'value': [0, 2]})

def test_selection1d_resolves_table(self):
table = Table([1, 2, 3], 'x')
Selection1D(source=table)
plot = bokeh_server_renderer.get_plot(table)
selected = Selection(indices=[0, 2])
callback = plot.callbacks[0]
spec = callback.attributes['index']
resolved = callback.resolve_attr_spec(spec, selected, model=selected)
self.assertEqual(resolved, {'id': selected.ref['id'], 'value': [0, 2]})

def test_rangexy_resolves(self):
points = Points([1, 2, 3])
RangeXY(source=points)
Expand Down Expand Up @@ -427,3 +437,15 @@ def test_callback_on_ndoverlay_is_attached(self):
self.assertEqual(len(plot.callbacks), 1)
self.assertIsInstance(plot.callbacks[0], Selection1DCallback)
self.assertIn(selection, plot.callbacks[0].streams)


def test_callback_on_table_is_attached(self):
table = Table([1, 2, 3], 'x')
selection = Selection1D(source=table)
plot = bokeh_renderer.get_plot(table)
self.assertEqual(len(plot.callbacks), 1)
self.assertIsInstance(plot.callbacks[0], Selection1DCallback)
self.assertIn(selection, plot.callbacks[0].streams)
callbacks = plot.handles['selected'].js_property_callbacks
self.assertIn('change:indices', callbacks)
self.assertIn(plot.id, callbacks['change:indices'][0].code)

0 comments on commit 4f52bb6

Please sign in to comment.