From e39baab8d7926b10610d23a453dd593df0d16b65 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 7 Sep 2016 21:48:26 +0100 Subject: [PATCH] Fixed updating of bokeh tables --- holoviews/plotting/bokeh/tabular.py | 40 +++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/holoviews/plotting/bokeh/tabular.py b/holoviews/plotting/bokeh/tabular.py index ca823e607f..f13f6a13ed 100644 --- a/holoviews/plotting/bokeh/tabular.py +++ b/holoviews/plotting/bokeh/tabular.py @@ -2,9 +2,11 @@ import param -from .plot import BokehPlot +from ...core import Dataset +from ...element import ItemTable from ..plot import GenericElementPlot - +from .plot import BokehPlot +from .util import bokeh_version class TablePlot(BokehPlot, GenericElementPlot): @@ -15,6 +17,15 @@ class TablePlot(BokehPlot, GenericElementPlot): style_opts = ['row_headers', 'selectable', 'editable', 'sortable', 'fit_columns', 'width', 'height'] + _update_handles = ['source', 'glyph'] + + def __init__(self, element, plot=None, show_labels=['x', 'y'], **params): + super(TablePlot, self).__init__(element, **params) + self.handles = {} if plot is None else self.handles['plot'] + element_ids = self.hmap.traverse(lambda x: id(x), [Dataset, ItemTable]) + self.static = len(set(element_ids)) == 1 and len(self.keys) == len(self.hmap) + + def get_data(self, element, ranges=None, empty=False): dims = element.dimensions() return ({d.name: [] if empty else element.dimension_values(d) for d in dims}, @@ -48,6 +59,31 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None): return table + @property + def current_handles(self): + """ + Returns a list of the plot objects to update. + """ + handles = [] + if self.static and not self.dynamic: + return handles + + previous_id = self.handles.get('previous_id', None) + current_id = id(self.current_frame.data) if self.current_frame else None + for handle in self._update_handles: + if (handle == 'source' and self.dynamic and + current_id == previous_id): + continue + if handle in self.handles: + handles.append(self.handles[handle]) + + # Cache frame object id to skip updating if unchanged + if self.dynamic: + self.handles['previous_id'] = current_id + + return handles + + def update_frame(self, key, ranges=None, plot=None): """ Updates an existing plot with data corresponding