Skip to content

Commit

Permalink
Add sizing_mode plot option to bokeh backend
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Aug 20, 2017
1 parent d48fffd commit 137fff5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion holoviews/plotting/bokeh/element.py
Expand Up @@ -412,7 +412,8 @@ def _plot_properties(self, key, plot, element):
"""
size_multiplier = self.renderer.size/100.
plot_props = dict(plot_height=int(self.height*size_multiplier),
plot_width=int(self.width*size_multiplier))
plot_width=int(self.width*size_multiplier),
sizing_mode=self.sizing_mode)
if bokeh_version < '0.12':
plot_props.update(self._title_properties(key, plot, element))
if self.bgcolor:
Expand Down
40 changes: 32 additions & 8 deletions holoviews/plotting/bokeh/plot.py
Expand Up @@ -40,6 +40,28 @@ class BokehPlot(DimensionedPlot):
height = param.Integer(default=300, doc="""
Height of the plot in pixels""")

sizing_mode = param.ObjectSelector(default='fixed',
objects=['fixed', 'stretch_both', 'scale_width', 'scale_height',
'scale_both'], doc="""
How the item being displayed should size itself.
"stretch_both" plots will resize to occupy all available
space, even if this changes the aspect ratio of the element.
"fixed" plots are not responsive and will retain their
original width and height regardless of any subsequent browser
window resize events.
"scale_width" elements will responsively resize to fit to the
width available, while maintaining the original aspect ratio.
"scale_height" elements will responsively resize to fit to the
height available, while maintaining the original aspect ratio.
"scale_both" elements will responsively resize to for both the
width and height available, while maintaining the original
aspect ratio.""")

shared_datasource = param.Boolean(default=True, doc="""
Whether Elements drawing the data from the same object should
share their Bokeh data source allowing for linked brushing
Expand Down Expand Up @@ -415,6 +437,7 @@ def initialize_plot(self, ranges=None, plots=[]):
def _make_axes(self, plot):
width, height = self.renderer.get_size(plot)
x_axis, y_axis = None, None
kwargs = dict(sizing_mode=self.sizing_mode)
if self.xaxis:
flip = self.shared_xaxis
rotation = self.xrotation
Expand All @@ -441,15 +464,15 @@ def _make_axes(self, plot):
if self.shared_yaxis:
r1, r2 = r1[::-1], r2[::-1]
models = layout_padding([r1, r2], self.renderer)
plot = gridplot(models)
plot = gridplot(models, **kwargs)
elif y_axis:
models = [y_axis, plot]
if self.shared_yaxis: models = models[::-1]
plot = Row(*models)
plot = Row(*models, **kwargs)
elif x_axis:
models = [plot, x_axis]
if self.shared_xaxis: models = models[::-1]
plot = Column(*models)
plot = Column(*models, **kwargs)
return plot

@update_shared_sources
Expand Down Expand Up @@ -681,6 +704,7 @@ def initialize_plot(self, plots=None, ranges=None):
plots = layout_padding(plots, self.renderer)

# Wrap in appropriate layout model
kwargs = dict(sizing_mode=self.sizing_mode)
if self.tabs:
panels = [Panel(child=child, title=str(tab_titles.get((r, c))))
for r, row in enumerate(plots)
Expand All @@ -690,18 +714,18 @@ def initialize_plot(self, plots=None, ranges=None):
elif bokeh_version >= '0.12':
plots = filter_toolboxes(plots)
plots, width = pad_plots(plots)
layout_plot = gridplot(children=plots, width=width)
layout_plot = gridplot(children=plots, width=width, **kwargs)
elif len(plots) == 1 and not adjoined:
layout_plot = Column(children=[Row(children=plots[0])])
layout_plot = Column(children=[Row(children=plots[0])], **kwargs)
elif len(plots[0]) == 1:
layout_plot = Column(children=[p[0] for p in plots])
layout_plot = Column(children=[p[0] for p in plots], **kwargs)
else:
layout_plot = BokehGridPlot(children=plots)
layout_plot = BokehGridPlot(children=plots, **kwargs)

title = self._get_title(self.keys[-1])
if title:
self.handles['title'] = title
layout_plot = Column(title, layout_plot)
layout_plot = Column(title, layout_plot, **kwargs)

self._update_callbacks(layout_plot)
self.handles['plot'] = layout_plot
Expand Down

0 comments on commit 137fff5

Please sign in to comment.