Skip to content

Commit

Permalink
Allowed nesting of GridSpace types in bokeh LayoutPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 6, 2017
1 parent bf71bc3 commit 4055716
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
8 changes: 3 additions & 5 deletions holoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ def sync_tools(self, subplots):

def initialize_plot(self, ranges=None, plots=[]):
ranges = self.compute_ranges(self.layout, self.keys[-1], None)
plots = [[] for r in range(self.cols)]
passed_plots = list(plots)
plots = [[] for r in range(self.cols)]
for i, coord in enumerate(self.layout.keys(full_grid=True)):
r = i % self.cols
subplot = self.subplots.get(wrap_tuple(coord), None)
Expand Down Expand Up @@ -421,8 +421,6 @@ def _create_subplots(self, layout, positions, layout_dimensions, ranges, num=0):

subplot_opts = dict(adjoined=main_plot)
# Options common for any subplot
if type(element) in (NdLayout, Layout):
raise SkipRendering("Cannot plot nested Layouts.")
vtype = element.type if isinstance(element, HoloMap) else element.__class__
plot_type = Store.registry[self.renderer.backend].get(vtype, None)
plotopts = self.lookup_options(element, 'plot').options
Expand Down Expand Up @@ -468,10 +466,10 @@ def _create_subplots(self, layout, positions, layout_dimensions, ranges, num=0):
return subplots, adjoint_clone


def initialize_plot(self, ranges=None):
def initialize_plot(self, plots=None, ranges=None):
ranges = self.compute_ranges(self.layout, self.keys[-1], None)
passed_plots = [] if plots is None else plots
plots = [[] for _ in range(self.rows)]
passed_plots = []
tab_titles = {}
insert_rows, insert_cols = [], []
adjoined = False
Expand Down
15 changes: 10 additions & 5 deletions holoviews/plotting/bokeh/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,31 +348,36 @@ def update_plot(old, new):
old_r.data_source.data.update(emptied)


def pad_width(model):
def pad_width(model, table_padding=0.85, tabs_padding=1.2):
"""
Computes the width of a model and sets up appropriate padding
for Tabs and DataTable types.
"""
if isinstance(model, Row):
width = np.max([pad_width(child) for child in model.children])
vals = [pad_width(child) for child in model.children]
width = np.max([v for v in vals if v is not None])
elif isinstance(model, Column):
width = np.sum([pad_width(child) for child in model.children])
vals = [pad_width(child) for child in model.children]
width = np.sum([v for v in vals if v is not None])
elif isinstance(model, Tabs):
width = np.max([pad_width(t) for t in model.tabs])
vals = [pad_width(t) for t in model.tabs]
width = np.max([v for v in vals if v is not None])
for model in model.tabs:
model.width = width
width = int(tabs_padding*width)
elif isinstance(model, DataTable):
width = model.width
model.width = int(table_padding*width)
elif isinstance(model, WidgetBox):
width = model.width
elif model:
width = model.plot_width
else:
width = 0
return width


def pad_plots(plots, table_padding=0.85, tabs_padding=1.2):
def pad_plots(plots):
"""
Accepts a grid of bokeh plots in form of a list of lists and
wraps any DataTable or Tabs in a WidgetBox with appropriate
Expand Down
3 changes: 2 additions & 1 deletion tests/testplotinstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
from holoviews.plotting.bokeh.callbacks import Callback
from bokeh.models import (
Div, ColumnDataSource, FactorRange, Range1d, Row, Column,
ToolbarBox, Figure, Spacer
ToolbarBox, Spacer
)
from bokeh.models.mappers import LinearColorMapper, LogColorMapper
from bokeh.models.tools import HoverTool
from bokeh.plotting import Figure
except:
bokeh_renderer = None

Expand Down

0 comments on commit 4055716

Please sign in to comment.