From fe6c8c10b314a0928a65d84d17e4ce7d5d0b1651 Mon Sep 17 00:00:00 2001 From: Jordan Samuels Date: Mon, 10 Jul 2017 17:43:00 -0500 Subject: [PATCH 1/3] https://github.com/ioam/holoviews/issues/1708 --- .../demos/bokeh/table_hooks_example.ipynb | 77 +++++++++++++++++++ holoviews/plotting/bokeh/tabular.py | 17 ++++ 2 files changed, 94 insertions(+) create mode 100644 examples/gallery/demos/bokeh/table_hooks_example.ipynb diff --git a/examples/gallery/demos/bokeh/table_hooks_example.ipynb b/examples/gallery/demos/bokeh/table_hooks_example.ipynb new file mode 100644 index 0000000000..8430948d16 --- /dev/null +++ b/examples/gallery/demos/bokeh/table_hooks_example.ipynb @@ -0,0 +1,77 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import holoviews as hv\n", + "from bokeh.models import HTMLTemplateFormatter\n", + "hv.extension('bokeh')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Declare Data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "name = ['homepage', 'github']\n", + "link = ['http://holoviews.org', 'https://github.com/ioam/holoviews']\n", + "table = hv.Table({'Name':name, 'Link':link}, vdims = ['Name', 'Link'], kdims=[])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%opts Table [width=500]\n", + "def apply_format(plot, element):\n", + " plot.handles['plot'].columns[1].formatter=HTMLTemplateFormatter(template='\"><%= value %>')\n", + "\n", + "table.opts(plot=dict(finalize_hooks=[apply_format]))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/holoviews/plotting/bokeh/tabular.py b/holoviews/plotting/bokeh/tabular.py index b2cf0eb1af..a755ac8e41 100644 --- a/holoviews/plotting/bokeh/tabular.py +++ b/holoviews/plotting/bokeh/tabular.py @@ -17,6 +17,11 @@ class TablePlot(BokehPlot, GenericElementPlot): style_opts = ['row_headers', 'selectable', 'editable', 'sortable', 'fit_columns', 'width', 'height'] + finalize_hooks = param.HookList(default=[], doc=""" + Optional list of hooks called when finalizing a column. + The hook is passed the plot object and the displayed + object, and other plotting handles can be accessed via plot.handles.""") + _update_handles = ['source', 'glyph'] def __init__(self, element, plot=None, **params): @@ -27,6 +32,17 @@ def __init__(self, element, plot=None, **params): self.callbacks = [] # Callback support on tables not implemented + 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 get_data(self, element, ranges=None, empty=False): dims = element.dimensions() data = {d: np.array([]) if empty else element.dimension_values(d) @@ -59,6 +75,7 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None): width=self.width, **properties) self.handles['plot'] = table self.handles['glyph_renderer'] = table + self._execute_hooks(element) self.drawn = True return table From 5de6f80cf3343ec69fd86c2ff4ea56c479dbd51c Mon Sep 17 00:00:00 2001 From: Jordan Samuels Date: Tue, 11 Jul 2017 07:34:40 -0500 Subject: [PATCH 2/3] Minor tweak to notebook * add additional URL * committing mostly to test failing Travis build --- examples/gallery/demos/bokeh/table_hooks_example.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/demos/bokeh/table_hooks_example.ipynb b/examples/gallery/demos/bokeh/table_hooks_example.ipynb index 8430948d16..87f7cdc5b8 100644 --- a/examples/gallery/demos/bokeh/table_hooks_example.ipynb +++ b/examples/gallery/demos/bokeh/table_hooks_example.ipynb @@ -27,8 +27,8 @@ }, "outputs": [], "source": [ - "name = ['homepage', 'github']\n", - "link = ['http://holoviews.org', 'https://github.com/ioam/holoviews']\n", + "name = ['homepage', 'github', 'chat']\n", + "link = ['http://holoviews.org', 'https://github.com/ioam/holoviews', 'https://gitter.im/ioam/holoviews']\n", "table = hv.Table({'Name':name, 'Link':link}, vdims = ['Name', 'Link'], kdims=[])" ] }, From 66dd354261b3654b99b0c5104f7e97116774b95a Mon Sep 17 00:00:00 2001 From: Jordan Samuels Date: Fri, 14 Jul 2017 07:46:02 -0500 Subject: [PATCH 3/3] move file to new directory per @jlstevens suggestion --- .../demos => reference/features}/bokeh/table_hooks_example.ipynb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{gallery/demos => reference/features}/bokeh/table_hooks_example.ipynb (100%) diff --git a/examples/gallery/demos/bokeh/table_hooks_example.ipynb b/examples/reference/features/bokeh/table_hooks_example.ipynb similarity index 100% rename from examples/gallery/demos/bokeh/table_hooks_example.ipynb rename to examples/reference/features/bokeh/table_hooks_example.ipynb