Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple streams attached to the same plot model #904

Merged
merged 3 commits into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class Callback(object):
# Timeout if a comm message is swallowed
timeout = 20000

_callbacks = {}

def __init__(self, plot, streams, source, **params):
self.plot = plot
self.streams = streams
Expand Down Expand Up @@ -162,7 +164,8 @@ def on_msg(self, msg):
if any(v is None for v in msg.values()):
return
for stream in self.streams:
stream.update(**msg)
stream.update(trigger=False, **msg)
Stream.trigger(self.streams)


def _process_msg(self, msg):
Expand All @@ -188,7 +191,16 @@ def set_customjs(self, handle):
for plot in plots:
handles.update(plot.handles)
# Set callback
handle.callback = CustomJS(args=handles, code=code)
if id(handle.callback) in self._callbacks:
cb = self._callbacks[id(handle.callback)]
if isinstance(cb, type(self)):
cb.streams += self.streams
else:
handle.callback.code += code
else:
js_callback = CustomJS(args=handles, code=code)
self._callbacks[id(js_callback)] = self
handle.callback = js_callback



Expand Down
4 changes: 3 additions & 1 deletion holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,9 @@ def refresh(self, **kwargs):
"""
traverse_setter(self, '_force', True)
key = self.current_key if self.current_key else self.keys[0]
stream_params = stream_parameters(self.streams)
dim_streams = [stream for stream in self.streams
if any(c in self.dimensions for c in stream.contents)]
stream_params = stream_parameters(dim_streams)
key = tuple(None if d in stream_params else k
for d, k in zip(self.dimensions, key))
stream_key = util.wrap_tuple_streams(key, self.dimensions, self.streams)
Expand Down
12 changes: 9 additions & 3 deletions holoviews/util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import inspect

import param

from .core import DynamicMap, ViewableElement
from .core.operation import ElementOperation
from .core.util import Aliases
from .core import util

from .streams import Stream

class Dynamic(param.ParameterizedFunction):
"""
Expand Down Expand Up @@ -36,8 +38,12 @@ def __call__(self, map_obj, **params):
dmap = self._make_dynamic(map_obj, callback)
if isinstance(self.p.operation, ElementOperation):
streams = []
for s in self.p.streams:
stream = s()
for stream in self.p.streams:
if inspect.isclass(stream) and issubclass(stream, Stream):
stream = stream()
elif not isinstance(stream, Stream):
raise ValueError('Stream must only contain Stream '
'classes or instances')
stream.update(**{k: self.p.operation.p.get(k) for k, v in
stream.contents.items()})
streams.append(stream)
Expand Down