Skip to content

Commit

Permalink
Fixed resolving Selection1D in bokeh callback
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 20, 2018
1 parent cc41352 commit cf21047
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion holoviews/plotting/bokeh/callbacks.py
@@ -1,7 +1,7 @@
from collections import defaultdict

import param
from bokeh.models import (CustomJS, FactorRange, DatetimeAxis, ColumnDataSource)
from bokeh.models import (CustomJS, FactorRange, DatetimeAxis, ColumnDataSource, Selection)

from ...core import OrderedDict
from ...streams import (Stream, PointerXY, RangeXY, Selection1D, RangeX,
Expand Down Expand Up @@ -355,6 +355,9 @@ def resolve_attr_spec(cls, spec, cb_obj, model=None):
continue
if isinstance(resolved, dict):
resolved = resolved.get(p)
elif isinstance(resolved, Selection) and p in ['1d', 'indices']:
# Handle resolving bokeh Selection 1d indices
resolved = resolved[p]
else:
resolved = getattr(resolved, p, None)
return {'id': model.ref['id'], 'value': resolved}
Expand Down
8 changes: 7 additions & 1 deletion tests/testbokehcallbacks.py
Expand Up @@ -12,7 +12,7 @@
from holoviews.plotting.bokeh.util import bokeh_version

from bokeh.events import Tap
from bokeh.models import Range1d, Plot
from bokeh.models import Range1d, Plot, ColumnDataSource, Selection
bokeh_renderer = Store.renderers['bokeh']
except:
bokeh_renderer = None
Expand Down Expand Up @@ -81,6 +81,12 @@ def test_server_callback_resolve_attr_spec_range1d_end(self):
msg = Callback.resolve_attr_spec('x_range.attributes.end', range1d)
self.assertEqual(msg, {'id': range1d.ref['id'], 'value': 10})

def test_server_callback_resolve_attr_spec_source_selected(self):
source = ColumnDataSource()
source.selected = Selection(indices=[1, 2, 3])
msg = Callback.resolve_attr_spec('cb_obj.selected.1d.indices', source)
self.assertEqual(msg, {'id': source.ref['id'], 'value': [1, 2, 3]})

def test_server_callback_resolve_attr_spec_tap_event(self):
plot = Plot()
event = Tap(plot, x=42)
Expand Down

0 comments on commit cf21047

Please sign in to comment.