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

Improved bokeh tabs padding #1085

Merged
merged 4 commits into from
Jan 30, 2017
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
4 changes: 2 additions & 2 deletions doc/Tutorials/Bokeh_Backend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@
},
"outputs": [],
"source": [
"%%opts Overlay [tabs=True width=600 height=600] RGB [width=600 height=600]\n",
"%%opts Overlay [tabs=True] Image [width=400 height=400]\n",
"x,y = np.mgrid[-50:51, -50:51] * 0.1\n",
"\n",
"img = hv.Image(np.sin(x**2+y**2), bounds=(-1,-1,1,1))\n",
"img.relabel('Low') * img.clone(img.data*2).relabel('High') + img"
"img.relabel('Low') * img.clone(img.data*2).relabel('High')"
]
},
{
Expand Down
15 changes: 6 additions & 9 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from ..plot import GenericElementPlot, GenericOverlayPlot
from ..util import dynamic_update, get_sources
from .plot import BokehPlot
from .util import (mpl_to_bokeh, convert_datetime, update_plot,
from .util import (mpl_to_bokeh, convert_datetime, update_plot, get_tab_title,
bokeh_version, mplcmap_to_palette, py2js_tickformatter)

if bokeh_version >= '0.12':
Expand Down Expand Up @@ -1112,20 +1112,17 @@ def initialize_plot(self, ranges=None, plot=None, plots=None):

panels = []
for key, subplot in self.subplots.items():
frame = None
if self.tabs: subplot.overlaid = False
child = subplot.initialize_plot(ranges, plot, plots)
if isinstance(element, CompositeOverlay):
frame = element.get(key, None)
subplot.current_frame = frame
if self.batched:
self.handles['plot'] = child
if self.tabs:
if self.hmap.type is Overlay:
title = ' '.join(key)
else:
title = ', '.join([d.pprint_value_string(k) for d, k in
zip(self.hmap.last.kdims, key)])
title = get_tab_title(key, frame, self.hmap.last)
panels.append(Panel(child=child, title=title))
if isinstance(element, CompositeOverlay):
frame = element.get(key, None)
subplot.current_frame = frame

if self.tabs:
self.handles['plot'] = Tabs(tabs=panels)
Expand Down
9 changes: 2 additions & 7 deletions holoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,9 @@ def initialize_plot(self, ranges=None):
if adjoined:
plots = layout_padding(plots)

# Determine the most appropriate composite plot type
# If the object cannot be displayed in a single layout
# it will be split into Tabs, for 1-row or 1-column
# Layouts we use the vplot and hplots.
# If there is a table and multiple rows and columns
# everything will be forced to a vertical layout
# Wrap in appropriate layout model
if self.tabs:
panels = [Panel(child=child, title=str(tab_titles.get(r, c)))
panels = [Panel(child=child, title=str(tab_titles.get((r, c))))
for r, row in enumerate(plots)
for c, child in enumerate(row)
if child is not None]
Expand Down
30 changes: 27 additions & 3 deletions holoviews/plotting/bokeh/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from bokeh.layouts import WidgetBox

from ...core.options import abbreviated_exception
from ...core.overlay import Overlay

# Conversion between matplotlib and bokeh markers
markers = {'s': {'marker': 'square'},
Expand Down Expand Up @@ -346,7 +347,7 @@ def update_plot(old, new):
old_r.data_source.data.update(emptied)


def pad_plots(plots, padding=0.85):
def pad_plots(plots, table_padding=0.85, tabs_padding=1.2):
"""
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 All @@ -360,10 +361,11 @@ def pad_plots(plots, padding=0.85):
width = np.max([p.width if isinstance(p, DataTable) else
t.child.plot_width for t in p.tabs])
for p in p.tabs:
p.width = int(padding*width)
p.width = width
width = int(tabs_padding*width)
elif isinstance(p, DataTable):
width = p.width
p.width = int(padding*width)
p.width = int(table_padding*width)
elif p:
width = p.plot_width
else:
Expand Down Expand Up @@ -402,3 +404,25 @@ def py2js_tickformatter(formatter, msg=''):
match = re.search('(function \(.*\))', jsfunc )
return jsfunc[:match.start()] + 'function ()' + jsfunc[match.end():]


def get_tab_title(key, frame, overlay):
"""
Computes a title for bokeh tabs from the key in the overlay, the
element and the containing (Nd)Overlay.
"""
if isinstance(overlay, Overlay):
if frame is not None:
title = []
if frame.label:
title.append(frame.label)
if frame.group != frame.params('group').default:
title.append(frame.group)
else:
title.append(frame.group)
else:
title = key
title = ' '.join(title)
else:
title = ' | '.join([d.pprint_value_string(k) for d, k in
zip(overlay.kdims, key)])
return title