Skip to content

Commit

Permalink
Merge pull request #1439 from ioam/batched_streams_fix
Browse files Browse the repository at this point in the history
Attach linked streams in batched mode
  • Loading branch information
jlstevens authored May 15, 2017
2 parents 6eed7ea + 0daeb70 commit 9909c29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 2 additions & 3 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,8 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
self._update_plot(key, plot, style_element)
self._update_ranges(style_element, ranges)

if not self.batched:
for cb in self.callbacks:
cb.initialize()
for cb in self.callbacks:
cb.initialize()

if not self.overlaid:
self._process_legend()
Expand Down
23 changes: 19 additions & 4 deletions tests/testplotinstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
try:
from holoviews.plotting.bokeh.util import bokeh_version
bokeh_renderer = Store.renderers['bokeh']
from holoviews.plotting.bokeh.callbacks import Callback
from holoviews.plotting.bokeh.callbacks import Callback, PointerXCallback
from bokeh.models import (
Div, ColumnDataSource, FactorRange, Range1d, Row, Column,
ToolbarBox, FixedTicker, FuncTickFormatter
Expand Down Expand Up @@ -97,7 +97,7 @@ def setUp(self):
self.default_comm = mpl_renderer.comms['default']
mpl_renderer.comms['default'] = (comms.Comm, '')

def teardown(self):
def tearDown(self):
mpl_renderer.comms['default'] = self.default_comm
Store.current_backend = self.previous_backend

Expand Down Expand Up @@ -324,10 +324,11 @@ def setUp(self):
self.default_comm = bokeh_renderer.comms['default']
bokeh_renderer.comms['default'] = (comms.Comm, '')

def teardown(self):
def tearDown(self):
Store.current_backend = self.previous_backend
Callback._comm_type = comms.JupyterCommJS
mpl_renderer.comms['default'] = self.default_comm
Callback._callbacks = {}

def test_overlay_legend(self):
overlay = Curve(range(10), label='A') * Curve(range(10), label='B')
Expand Down Expand Up @@ -404,6 +405,20 @@ def test_batched_curve_subscribers_correctly_attached(self):
self.assertIn(plot.refresh, posx.subscribers)
self.assertNotIn(list(plot.subplots.values())[0].refresh, posx.subscribers)

def test_batched_curve_subscribers_correctly_linked(self):
# Checks if a stream callback is created to link batched plot
# to the stream
posx = PointerX()
opts = {'NdOverlay': dict(plot=dict(legend_limit=0)),
'Curve': dict(style=dict(line_color=Cycle(values=['red', 'blue'])))}
overlay = DynamicMap(lambda x: NdOverlay({i: Curve([(i, j) for j in range(2)])
for i in range(2)})(opts), kdims=[],
streams=[posx])
plot = bokeh_renderer.get_plot(overlay)
self.assertEqual(len(Callback._callbacks), 1)
key = list(Callback._callbacks.keys())[0]
self.assertEqual(key, (id(plot.handles['plot']), id(PointerXCallback)))

def test_batched_points_size_and_color(self):
opts = {'NdOverlay': dict(plot=dict(legend_limit=0)),
'Points': dict(style=dict(size=Cycle(values=[1, 2])))}
Expand Down Expand Up @@ -1425,7 +1440,7 @@ def setUp(self):
plotly_renderer.comms['default'] = (comms.Comm, '')


def teardown(self):
def tearDown(self):
Store.current_backend = self.previous_backend
plotly_renderer.comms['default'] = self.default_comm

Expand Down

0 comments on commit 9909c29

Please sign in to comment.