Skip to content

Commit

Permalink
Merge 3126c88 into fd324f9
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 9, 2018
2 parents fd324f9 + 3126c88 commit e45de60
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 26 deletions.
18 changes: 9 additions & 9 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,8 @@ class LinkCallback(param.Parameterized):
source_code = None
target_code = None

def __init__(self, root_plot, link, source_plot, target_plot=None):
self.root_plot = root_plot
def __init__(self, root_model, link, source_plot, target_plot=None):
self.root_model = root_model
self.link = link
self.source_plot = source_plot
self.target_plot = target_plot
Expand Down Expand Up @@ -1121,6 +1121,7 @@ def find_links(cls, root_plot):
for plot, links in source_links:
for link in links:
if link.target is None:
# If link has no target don't look further
found.append((link, plot, None))
continue
potentials = [cls.find_link(plot, link) for plot in plots]
Expand Down Expand Up @@ -1156,22 +1157,21 @@ class RangeToolLinkCallback(LinkCallback):
specified axes on the target plot
"""

def __init__(self, root_plot, link, source_plot, target_plot):
def __init__(self, root_model, link, source_plot, target_plot):
try:
from bokeh.models.tools import RangeTool
except:
raise Exception('RangeToolLink requires bokeh >= 0.13')
toolbar = [model for model in root_plot.state.children
if isinstance(model, ToolbarBox)]
toolbars = list(root_model.select({'type': ToolbarBox}))
axes = {}
if 'x' in link.axes:
axes['x_range'] = target_plot.handles['x_range']
if 'y' in link.axes:
axes['y_range'] = target_plot.handles['y_range']
tool = RangeTool(**axes)
source_plot.state.add_tools(tool)
if toolbar:
toolbar = toolbar[0].toolbar
if toolbars:
toolbar = toolbars[0].toolbar
toolbar.tools.append(tool)


Expand All @@ -1180,7 +1180,7 @@ class DataLinkCallback(LinkCallback):
Merges the source and target ColumnDataSource
"""

def __init__(self, root_plot, link, source_plot, target_plot):
def __init__(self, root_model, link, source_plot, target_plot):
src_cds = source_plot.handles['source']
tgt_cds = target_plot.handles['source']
src_len = [len(v) for v in src_cds.data.values()]
Expand Down Expand Up @@ -1214,7 +1214,7 @@ def __init__(self, root_plot, link, source_plot, target_plot):
renderer.view.update(source=src_cds)
target_plot.handles['source'] = src_cds
for callback in target_plot.callbacks:
callback.initialize(plot_id=root_plot.id)
callback.initialize(plot_id=root_model.ref['id'])


callbacks = Link._callbacks['bokeh']
Expand Down
17 changes: 14 additions & 3 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
self.handles['yaxis'] = plot.yaxis[0]
self.handles['y_range'] = plot.y_range
self.handles['plot'] = plot
if self.top_level and not self._root:
self.set_root(plot)

self._init_glyphs(plot, element, ranges, source)
if not self.overlaid:
Expand Down Expand Up @@ -1308,6 +1310,8 @@ class OverlayPlot(GenericOverlayPlot, LegendPlot):
'legend_cols', 'gridstyle', 'legend_muted', 'padding',
'xlim', 'ylim', 'zlim']

_passed_handles = ['root']

def _process_legend(self):
plot = self.handles['plot']
if not self.show_legend or len(plot.legend) == 0:
Expand Down Expand Up @@ -1471,7 +1475,13 @@ def initialize_plot(self, ranges=None, plot=None, plots=None):
if plot is None and not self.tabs and not self.batched:
plot = self._init_plot(key, element, ranges=ranges, plots=plots)
self._init_axes(plot)
self.handles['plot'] = plot

if self.tabs:
self.handles['plot'] = Tabs()
else:
self.handles['plot'] = plot
if self.top_level and not self._root:
self.set_root(self.handles['plot'])

if plot and not self.overlaid:
self._update_plot(key, plot, element)
Expand All @@ -1496,13 +1506,13 @@ def initialize_plot(self, ranges=None, plot=None, plots=None):
self._merge_tools(subplot)

if self.tabs:
self.handles['plot'] = Tabs(tabs=panels)
self.handles['plot'].tabs = panels

elif not self.overlaid:
self._process_legend()
self.drawn = True
self.handles['plots'] = plots

self._update_callbacks(self.handles['plot'])
if 'plot' in self.handles and not self.tabs:
plot = self.handles['plot']
self.handles['xaxis'] = plot.xaxis[0]
Expand All @@ -1514,6 +1524,7 @@ def initialize_plot(self, ranges=None, plot=None, plots=None):

if self.top_level:
self.init_links()
self._update_callbacks(self.handles['plot'])

self._execute_hooks(element)

Expand Down
33 changes: 23 additions & 10 deletions holoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,18 @@ class BokehPlot(DimensionedPlot):
def document(self):
return self._document


@property
def id(self):
return self.state.ref['id']
return self.root.ref['id'] if self.root else None

@property
def root(self):
if self._root:
return self._root
elif 'plot' in self.handles and self.top_level:
return self.state
else:
return None

@document.setter
def document(self, doc):
Expand All @@ -104,9 +111,12 @@ def document(self, doc):


def __init__(self, *args, **params):
root = params.pop('root', None)
super(BokehPlot, self).__init__(*args, **params)
self._document = None
self.root = None
self._root = root
if self._root:
self.handles['root'] = root


def get_data(self, element, ranges, style):
Expand Down Expand Up @@ -175,10 +185,10 @@ def push(self):

def set_root(self, root):
"""
Sets the current document on all subplots.
Sets the root model on all subplots.
"""
for plot in self.traverse(lambda x: x):
plot.root = root
plot._root = root


def _init_datasource(self, data):
Expand Down Expand Up @@ -338,7 +348,7 @@ def init_links(self):
callbacks = []
for link, src_plot, tgt_plot in links:
cb = Link._callbacks['bokeh'][type(link)]
callbacks.append(cb(self, link, src_plot, tgt_plot))
callbacks.append(cb(self.root, link, src_plot, tgt_plot))
return callbacks


Expand Down Expand Up @@ -535,7 +545,7 @@ def _create_subplots(self, layout, ranges):
else:
subplot = plotting_class(view, dimensions=self.dimensions,
show_title=False, subplot=True,
renderer=self.renderer,
renderer=self.renderer, root=self.root,
ranges=frame_ranges, uniform=self.uniform,
keys=self.keys, **dict(opts, **kwargs))
collapsed_layout[coord] = (subplot.layout
Expand Down Expand Up @@ -572,12 +582,13 @@ def initialize_plot(self, ranges=None, plots=[]):
self.handles['plot'] = plot
self.handles['plots'] = plots

self._update_callbacks(plot)
if self.shared_datasource:
self.sync_sources()

if self.top_level:
self.set_root(plot)
self.init_links()
self._update_callbacks(plot)

self.drawn = True

Expand Down Expand Up @@ -786,7 +797,7 @@ def _create_subplots(self, layout, positions, layout_dimensions, ranges, num=0):
layout_dimensions=layout_dimensions,
ranges=ranges, subplot=True,
uniform=self.uniform, layout_num=num,
renderer=self.renderer,
renderer=self.renderer, root=self.root,
**dict({'shared_axes': self.shared_axes},
**plotopts))
subplots[pos] = subplot
Expand Down Expand Up @@ -912,15 +923,17 @@ def initialize_plot(self, plots=None, ranges=None):
self.handles['title'] = title
layout_plot = Column(title, layout_plot, **kwargs)


self.handles['plot'] = layout_plot
self.handles['plots'] = plots

self._update_callbacks(layout_plot)
if self.shared_datasource:
self.sync_sources()

if self.top_level:
self.set_root(layout_plot)
self.init_links()
self._update_callbacks(layout_plot)

self.drawn = True

Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/bokeh/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _save_prefix(self_or_cls, ext):


@bothmethod
def get_plot(self_or_cls, obj, doc=None, renderer=None):
def get_plot(self_or_cls, obj, doc=None, renderer=None, **kwargs):
"""
Given a HoloViews Viewable return a corresponding plot instance.
Allows supplying a document attach the plot to, useful when
Expand All @@ -159,7 +159,7 @@ def get_plot(self_or_cls, obj, doc=None, renderer=None):
if self_or_cls.notebook_context:
curdoc().theme = self_or_cls.theme
doc.theme = self_or_cls.theme
plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer)
plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer, **kwargs)
plot.document = doc
return plot

Expand Down
5 changes: 3 additions & 2 deletions holoviews/plotting/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __init__(self, **params):


@bothmethod
def get_plot(self_or_cls, obj, renderer=None):
def get_plot(self_or_cls, obj, renderer=None, **kwargs):
"""
Given a HoloViews Viewable return a corresponding plot instance.
"""
Expand All @@ -193,7 +193,8 @@ def get_plot(self_or_cls, obj, renderer=None):
renderer = self_or_cls.instance()
if not isinstance(obj, Plot):
obj = Layout.from_values(obj) if isinstance(obj, AdjointLayout) else obj
plot_opts = self_or_cls.plot_options(obj, self_or_cls.size)
plot_opts = dict(self_or_cls.plot_options(obj, self_or_cls.size),
**kwargs)
plot = self_or_cls.plotting_class(obj)(obj, renderer=renderer,
**plot_opts)
defaults = [kd.default for kd in plot.dimensions]
Expand Down

0 comments on commit e45de60

Please sign in to comment.