Skip to content

Commit

Permalink
Merge pull request #1274 from ioam/stream_comm_attach
Browse files Browse the repository at this point in the history
Fixed comm creation and stream subscriber attachment
  • Loading branch information
jlstevens authored Apr 11, 2017
2 parents 255445e + be06b88 commit 0628872
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ...element import RGB
from ...streams import Stream, RangeXY, RangeX, RangeY
from ..plot import GenericElementPlot, GenericOverlayPlot
from ..util import dynamic_update, get_sources
from ..util import dynamic_update, get_sources, attach_streams
from .plot import BokehPlot, TOOLS
from .util import (mpl_to_bokeh, convert_datetime, update_plot, get_tab_title,
bokeh_version, mplcmap_to_palette, py2js_tickformatter,
Expand Down
16 changes: 12 additions & 4 deletions holoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,17 @@ class GridPlot(CompositePlot, GenericCompositePlot):
plot_size = param.Integer(default=120, doc="""
Defines the width and height of each plot in the grid""")

def __init__(self, layout, ranges=None, layout_num=1, **params):
def __init__(self, layout, ranges=None, layout_num=1, keys=None, **params):
if not isinstance(layout, GridSpace):
raise Exception("GridPlot only accepts GridSpace.")
super(GridPlot, self).__init__(layout=layout, layout_num=layout_num,
ranges=ranges, **params)
ranges=ranges, keys=keys, **params)
self.cols, self.rows = layout.shape
self.subplots, self.layout = self._create_subplots(layout, ranges)
top_level = keys is None
if top_level:
self.comm = self.init_comm()
self.traverse(lambda x: setattr(x, 'comm', self.comm))


def _create_subplots(self, layout, ranges):
Expand Down Expand Up @@ -478,9 +482,13 @@ class LayoutPlot(CompositePlot, GenericLayoutPlot):
tabs = param.Boolean(default=False, doc="""
Whether to display overlaid plots in separate panes""")

def __init__(self, layout, **params):
super(LayoutPlot, self).__init__(layout, **params)
def __init__(self, layout, keys=None, **params):
super(LayoutPlot, self).__init__(layout, keys=keys, **params)
self.layout, self.subplots, self.paths = self._init_layout(layout)
top_level = keys is None
if top_level:
self.comm = self.init_comm()
self.traverse(lambda x: setattr(x, 'comm', self.comm))


def _init_layout(self, layout):
Expand Down
16 changes: 12 additions & 4 deletions holoviews/plotting/mpl/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ class GridPlot(CompositePlot):
Rotation angle of the yticks.""")

def __init__(self, layout, axis=None, create_axes=True, ranges=None,
layout_num=1, **params):
layout_num=1, keys=None, **params):
if not isinstance(layout, GridSpace):
raise Exception("GridPlot only accepts GridSpace.")
super(GridPlot, self).__init__(layout, layout_num=layout_num,
ranges=ranges, **params)
ranges=ranges, keys=keys, **params)
# Compute ranges layoutwise
grid_kwargs = {}
if axis is not None:
Expand All @@ -316,6 +316,10 @@ def __init__(self, layout, axis=None, create_axes=True, ranges=None,
with mpl.rc_context(rc=self.fig_rcparams):
self.subplots, self.subaxes, self.layout = self._create_subplots(layout, axis,
ranges, create_axes)
top_level = keys is None
if top_level:
self.comm = self.init_comm()
self.traverse(lambda x: setattr(x, 'comm', self.comm))


def _get_size(self):
Expand Down Expand Up @@ -729,10 +733,14 @@ class LayoutPlot(GenericLayoutPlot, CompositePlot):
# Whether to enable fix for non-square figures
v17_layout_format = True

def __init__(self, layout, **params):
super(LayoutPlot, self).__init__(layout=layout, **params)
def __init__(self, layout, keys=None, **params):
super(LayoutPlot, self).__init__(layout=layout, keys=keys, **params)
with mpl.rc_context(rc=self.fig_rcparams):
self.subplots, self.subaxes, self.layout = self._compute_gridspec(layout)
top_level = keys is None
if top_level:
self.comm = self.init_comm()
self.traverse(lambda x: setattr(x, 'comm', self.comm))


def _compute_gridspec(self, layout):
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/mpl/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def __init__(self, layout, keys=None, dimensions=None, create_axes=False, ranges
dimensions, keys = traversal.unique_dimkeys(layout)
MPLPlot.__init__(self, dimensions=dimensions, keys=keys, **params)
if top_level:
self.comm = self.init_comm(layout)
self.comm = self.init_comm()

self.layout = layout
self.cyclic_index = 0
Expand Down
22 changes: 13 additions & 9 deletions holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,13 @@ def push(self):
self.comm.send(diff)


def init_comm(self, obj):
def init_comm(self):
"""
Initializes comm and attaches streams.
"""
comm = None
if self.dynamic or self.renderer.widget_mode == 'live':
comm = self.renderer.comms[self.renderer.mode][0](self)
attach_streams(self, obj)
return comm


Expand Down Expand Up @@ -589,12 +588,16 @@ def __init__(self, element, keys=None, ranges=None, dimensions=None,
super(GenericElementPlot, self).__init__(keys=keys, dimensions=dimensions,
dynamic=dynamic,
**dict(params, **plot_opts))
if top_level:
self.comm = self.init_comm(element)
streams = []
if isinstance(self.hmap, DynamicMap):
streams = get_nested_streams(self.hmap)
self.streams = streams
if top_level:
self.comm = self.init_comm()
self.traverse(lambda x: setattr(x, 'comm', self.comm))

if not self.overlaid:
attach_streams(self, self.hmap)

# Update plot and style options for batched plots
if self.batched:
Expand Down Expand Up @@ -790,15 +793,19 @@ class GenericOverlayPlot(GenericElementPlot):

_passed_handles = []

def __init__(self, overlay, ranges=None, batched=True, **params):
super(GenericOverlayPlot, self).__init__(overlay, ranges=ranges,
def __init__(self, overlay, ranges=None, batched=True, keys=None, **params):
super(GenericOverlayPlot, self).__init__(overlay, ranges=ranges, keys=keys,
batched=batched, **params)

# Apply data collapse
self.hmap = Compositor.collapse(self.hmap, None, mode='data')
self.hmap = self._apply_compositor(self.hmap, ranges, self.keys)
self.subplots = self._create_subplots(ranges)
self.traverse(lambda x: setattr(x, 'comm', self.comm))
top_level = keys is None
if top_level:
self.comm = self.init_comm()
self.traverse(lambda x: setattr(x, 'comm', self.comm))


def _apply_compositor(self, holomap, ranges=None, keys=None, dimensions=None):
Expand Down Expand Up @@ -955,9 +962,6 @@ def __init__(self, layout, keys=None, dimensions=None, **params):
dynamic=dynamic,
dimensions=dimensions,
**params)
if top_level:
self.comm = self.init_comm(layout)
self.traverse(lambda x: setattr(x, 'comm', self.comm))
nested_streams = layout.traverse(lambda x: get_nested_streams(x),
[DynamicMap])
self.streams = list(set([s for streams in nested_streams for s in streams]))
Expand Down
3 changes: 2 additions & 1 deletion holoviews/plotting/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ def attach_streams(plot, obj):
"""
def append_refresh(dmap):
for stream in get_nested_streams(dmap):
stream.add_subscriber(plot.refresh)
if plot.refresh not in stream._subscribers:
stream.add_subscriber(plot.refresh)
return obj.traverse(append_refresh, [DynamicMap])


Expand Down

0 comments on commit 0628872

Please sign in to comment.