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

Allow Table to use finalize_hooks #1708

Closed
jordansamuels opened this issue Jul 10, 2017 · 2 comments
Closed

Allow Table to use finalize_hooks #1708

jordansamuels opened this issue Jul 10, 2017 · 2 comments
Assignees
Milestone

Comments

@jordansamuels
Copy link
Contributor

Currently, it doesn't look like Table and TablePlot are wired to use finalize_hooks. Using them would allow things like wiring HTMLTemplateFormatter for cells. The below is a way to do this without modifying HoloViews, and so the feature would be to incorporate the few lines of wiring into TablePlot instead of overriding here.

from holoviews.plotting.bokeh.tabular import TablePlot
from holoviews.element.tabular import Table
class TableWithHooks(Table):
    pass
class TableWithHooksPlot(TablePlot):
    finalize_hooks = param.HookList(default=[])

    def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
        super(TableWithHooksPlot, self).initialize_plot(ranges, plot, plots, source)
        self._execute_hooks(self.hmap.last)

    def _execute_hooks(self, element):
        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))
    
hv.Store.register({TableWithHooks: TableWithHooksPlot}, 'bokeh')


name = ['homepage', 'github']
link = ['http://holoviews.org', 'https://github.com/ioam/holoviews']
table = TableWithHooks({'Name':name, 'Link':link},  vdims = ['Name', 'Link'],  kdims=[])

from bokeh.models import HTMLTemplateFormatter
def apply_format(plot, element):
    plot.handles['plot'].columns[1].formatter=HTMLTemplateFormatter(template='<a href="<%= value %>"><%= value %></a>')

table.opts(plot=dict(finalize_hooks=[apply_format]))

image

jordansamuels pushed a commit to jordansamuels/holoviews that referenced this issue Jul 10, 2017
jlstevens pushed a commit that referenced this issue Jul 14, 2017
* #1708

* Minor tweak to notebook

* add additional URL
* committing mostly to test failing Travis build

* move file to new directory per @jlstevens suggestion
@philippjfr philippjfr added this to the v1.9 milestone Sep 23, 2017
@philippjfr philippjfr self-assigned this Sep 23, 2017
@philippjfr
Copy link
Member

Looks like this was merged a while back.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants