Skip to content

Commit

Permalink
Ensure CDSStream.data is initialized correctly (#2321)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Feb 8, 2018
1 parent 9e04789 commit 0bed1c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,11 @@ class CDSCallback(Callback):
models = ['source']
on_changes = ['data']

def initialize(self):
super(CDSCallback, self).initialize()
for stream in self.streams:
stream.update(data=self.plot_handles['source'].data)

def _process_msg(self, msg):
for col, values in msg['data'].items():
if isinstance(values, dict):
Expand Down Expand Up @@ -945,6 +950,9 @@ def initialize(self):
plot.state.tools.append(box_tool)
self.plot.state.renderers.remove(plot.handles['glyph_renderer'])
super(BoxEditCallback, self).initialize()
for stream in self.streams:
stream.update(data=self._process_msg({'data': data})['data'])


def _process_msg(self, msg):
data = super(BoxEditCallback, self)._process_msg(msg)['data']
Expand Down
15 changes: 15 additions & 0 deletions tests/plotting/bokeh/testcallbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def test_point_draw_callback(self):
callback.on_msg({'data': data})
self.assertEqual(point_draw.element, Points(data))

def test_point_draw_callback_initialize(self):
points = Points([(0, 1)])
point_draw = PointDraw(source=points)
plot = bokeh_renderer.get_plot(points)
self.assertIsInstance(plot.callbacks[0], PointDrawCallback)
data = {'x': [0], 'y': [1]}
self.assertEqual(point_draw.element, points)

def test_point_draw_callback_with_vdims(self):
points = Points([(0, 1, 'A')], vdims=['A'])
point_draw = PointDraw(source=points)
Expand Down Expand Up @@ -75,6 +83,13 @@ def test_poly_draw_callback_with_vdims(self):
{'x': [3, 4, 5], 'y': [3, 4, 5], 'A': 2}], vdims=['A'])
self.assertEqual(poly_draw.element, element)

def test_box_edit_callback(self):
boxes = Polygons([Box(0, 0, 1)])
box_edit = BoxEdit(source=boxes)
plot = bokeh_renderer.get_plot(boxes)
self.assertIsInstance(plot.callbacks[0], BoxEditCallback)
self.assertEqual(box_edit.element, boxes)

def test_box_edit_callback(self):
boxes = Polygons([Box(0, 0, 1)])
box_edit = BoxEdit(source=boxes)
Expand Down

0 comments on commit 0bed1c0

Please sign in to comment.