I am trying to dynamically modify my y-axis tick formatting and tooltip formatting based on what is selected in a Holoviews dropdown. I figured I could do this in finalize_hooks. Since I don't know how to test for what has been selected in the dropdown, I used the title value to determine that. This seems to work ok though I am sure there could be a more elegant solution that I am not aware of. Also, I am able to change the tick formatter but the hover value doesn't change based on the above method. See example code below. Tooltip always shows Value1, never Value 2 no matter which country I select. Please advise if there is a way to fix this.
%%opts Bars [show_grid=True width=1400 height=400 xrotation=0] {+framewise}
macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\t')
key_dimensions = [('year', 'Year'), ('country', 'Country')]
value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),
('gdp', 'GDP Growth'), ('trade', 'Trade')]
macro = hv.Table(macro_df, key_dimensions, value_dimensions)
hover = HoverTool(tooltips=[('year', '@year'),
('Value', '@unem{0.000%}')])
def apply_formatter(plot, element):
p = plot.handles['plot']
if 'Austria' in p.title.text:
plot.handles['yaxis'].formatter = NumeralTickFormatter(format="0")
p.hover[0].tooltips[1] = ('Value1', '@unem{0.0%}')
else:
plot.handles['yaxis'].formatter = NumeralTickFormatter(format="0.0%")
p.hover[0].tooltips[1] = ('Value2', '@unem{0.00%}')
bars = macro.to(hv.Bars, kdims='year', vdims=['unem']).opts(plot=dict(tools=[hover], finalize_hooks=[apply_formatter]))
bars