Skip to content

Commit

Permalink
Merge pull request #1040 from ioam/bokeh_finalize_hooks
Browse files Browse the repository at this point in the history
Add support for finalize_hooks to bokeh backend
  • Loading branch information
jlstevens committed Jan 9, 2017
2 parents 4be931a + af87db7 commit 6bd8ae4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class ElementPlot(BokehPlot, GenericElementPlot):
border = param.Number(default=10, doc="""
Minimum border around plot.""")

finalize_hooks = param.HookList(default=[], doc="""
Optional list of hooks called when finalizing an axis.
The hook is passed the plot object and the displayed
object, other plotting handles can be accessed via plot.handles.""")

fontsize = param.Parameter(default={'title': '12pt'}, allow_None=True, doc="""
Specifies various fontsizes of the displayed text.
Expand Down Expand Up @@ -548,6 +553,16 @@ def _update_glyph(self, glyph, properties, mapping):
glyph.update(**{k: v for k, v in merged.items()
if k in allowed_properties})

def _execute_hooks(self, element):
"""
Executes finalize hooks
"""
for hook in self.finalize_hooks:
try:
hook(self, element)
except Exception as e:
self.warning("Plotting hook %r could not be applied:\n\n %s" % (hook, e))


def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
"""
Expand Down Expand Up @@ -606,6 +621,8 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):

if not self.overlaid:
self._process_legend()
self._execute_hooks(element)

self.drawn = True

return plot
Expand Down Expand Up @@ -666,6 +683,8 @@ def update_frame(self, key, ranges=None, plot=None, element=None, empty=False):
self._update_ranges(style_element, ranges)
self._update_plot(key, plot, style_element)

self._execute_hooks(element)


@property
def current_handles(self):
Expand Down Expand Up @@ -1107,6 +1126,8 @@ def initialize_plot(self, ranges=None, plot=None, plots=None):
for cb in self.callbacks:
cb.initialize()

self._execute_hooks(element)

return self.handles['plot']


Expand Down Expand Up @@ -1154,3 +1175,5 @@ def update_frame(self, key, ranges=None, element=None, empty=False):
if element and not self.overlaid and not self.tabs and not self.batched:
self._update_ranges(element, ranges)
self._update_plot(key, self.handles['plot'], element)

self._execute_hooks(element)

0 comments on commit 6bd8ae4

Please sign in to comment.