nick
July 18, 2019, 8:56pm
1
I have a multi-indexed data source, and I would like to get the index value for each part on hover.
def _create_hover_tools():
hover = HoverTool(
tooltips=[
('index','@y')
]
)
return hover
On hover, this returns something like this:
index: (index_a_value,really_long_b_value_that_should_have_own_line,index_c_value)
I would like to be able to index the values of y, and put them on their own line, similar to this idea that doesn’t work:
tooltips=[
('index_a','@y[0]'),
('index_b','@y[1]'),
('index_c','@y[2]'),
]
Thank you for your time.
Bryan
July 18, 2019, 10:16pm
2
The built in hover tool formatter does not function in this way, it only show the full column value, as-is. You will have to use a CustomJSHover
which will allow you to supply a snippet of JavaScript to pick out sub-parts and format them how you like.
There is also a full example in the repo:
from bokeh.io import output_file, show
from bokeh.models import CustomJSHover, HoverTool
from bokeh.plotting import figure
output_file("customjs_hover.html")
# range bounds supplied in web mercator coordinates
p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000),
x_axis_type="mercator", y_axis_type="mercator")
p.add_tile("CartoDB Positron")
p.circle(x=[0, 2000000, 4000000], y=[4000000, 2000000, 0], size=30)
code = """
const projections = Bokeh.require("core/util/projections");
const x = special_vars.x
const y = special_vars.y
const coords = projections.wgs84_mercator.invert(x, y)
return coords[%d].toFixed(2)
"""
This file has been truncated. show original