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

add dimensioned streams to DynamicMap __mul__ clone #3658

Merged
merged 1 commit into from
Apr 28, 2019
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
6 changes: 3 additions & 3 deletions holoviews/core/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .dimension import Dimension, Dimensioned, ViewableElement, ViewableTree
from .ndmapping import UniformNdMapping
from .layout import Composable, Layout, AdjointLayout
from .util import config, sanitize_identifier, unique_array
from .util import config, sanitize_identifier, unique_array, dimensioned_streams


class Overlayable(object):
Expand All @@ -33,7 +33,7 @@ def dynamic_mul(*args, **kwargs):
callback = Callable(dynamic_mul, inputs=[self, other])
callback._is_overlay = True
return other.clone(shared_data=False, callback=callback,
streams=[])
streams=dimensioned_streams(other))
if isinstance(other, UniformNdMapping) and not isinstance(other, CompositeOverlay):
items = [(k, self * v) for (k, v) in other.items()]
return other.clone(items)
Expand Down Expand Up @@ -187,7 +187,7 @@ def dynamic_mul(*args, **kwargs):
callback = Callable(dynamic_mul, inputs=[self, other])
callback._is_overlay = True
return other.clone(shared_data=False, callback=callback,
streams=[])
streams=dimensioned_streams(other))
elif not isinstance(other, ViewableElement):
return NotImplemented
return Overlay([self, other])
Expand Down
4 changes: 3 additions & 1 deletion holoviews/core/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def dynamic_mul(*args, **kwargs):
callback = Callable(dynamic_mul, inputs=[self, other])
callback._is_overlay = True
return self.clone(shared_data=False, callback=callback,
streams=[])
streams=util.dimensioned_streams(self))
items = [(k, other * v) if reverse else (k, v * other)
for (k, v) in self.data.items()]
return self.clone(items, label=self._label, group=self._group)
Expand Down Expand Up @@ -1527,6 +1527,7 @@ def collate(self):

# Get stream mapping from callback
remapped_streams = []
self_dstreams = util.dimensioned_streams(self)
streams = self.callback.stream_mapping
for i, (k, v) in enumerate(initialized.last.data.items()):
vstreams = streams.get(i, [])
Expand Down Expand Up @@ -1576,6 +1577,7 @@ def collation_cb(*args, **kwargs):
selection_index=type_counter[type(v)],
selection_type=type(v)),
inputs=[self])
vstreams = list(util.unique_iterator(self_dstreams + vstreams))
vdmap = self.clone(callback=callback, shared_data=False,
streams=vstreams)
type_counter[type(v)] += 1
Expand Down
28 changes: 27 additions & 1 deletion holoviews/tests/plotting/bokeh/testlayoutplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from holoviews.core import (HoloMap, GridSpace, Layout, Empty, Dataset,
NdOverlay, DynamicMap, Dimension)
from holoviews.element import Curve, Image, Points
from holoviews.element import Curve, Image, Points, HLine, VLine, Path, Histogram
from holoviews.streams import Stream

from .testplot import TestBokehPlot, bokeh_renderer
Expand Down Expand Up @@ -271,3 +271,29 @@ def test_layout_axis_not_linked_mismatching_unit(self):
plot = bokeh_renderer.get_plot(layout)
p1, p2 = (sp.subplots['main'] for sp in plot.subplots.values())
self.assertIsNot(p1.handles['y_range'], p2.handles['y_range'])

def test_dimensioned_streams_with_dynamic_map_overlay_clone(self):
time = Stream.define('Time', time=-3.0)()
def crosshair(time):
return VLine(time) * HLine(time)
crosshair = DynamicMap(crosshair, kdims='time', streams=[time])
path = Path([])
t = crosshair * path
html, _ = bokeh_renderer(t)
self.assertIn('Bokeh Application', html)

def test_dimensioned_streams_with_dynamic_callback_returns_layout(self):
stream = Stream.define('aname', aname='a')()
def cb(aname):
x = np.linspace(0, 1, 10)
y = np.random.randn(10)
curve = Curve((x, y), group=aname)
hist = Histogram(y)
return (curve + hist).opts(shared_axes=False)
m = DynamicMap(cb, kdims=['aname'], streams=[stream])
p = bokeh_renderer.get_plot(m)
T = 'XYZT'
stream.event(aname=T)
self.assertIn('aname: ' + T, p.handles['title'].text, p.handles['title'].text)
p.cleanup()
self.assertEqual(stream._subscribers, [])