hv.RGB Hover Value RGBA

Hey,
While activating hover tool using hv.RGB(rgb_image_np_array).opts(tools=['hover']),
I would to like present the R G and B values instead - Is there a way to make it happen?
Thanks.

without some code I can only guess, but you can do something like this:

from bokeh.models import HoverTool
# Syntax: $. are 'special fields':  $x inserts the x-coordinate
#         @. are fields from the color data source:
#            provide an extra column of values and declare it's name as a vdim (or sue a pd.DataFrame)

data  = pd.DataFrame( { 'x': [1.1, 3.2, 5.8 ], 'state': ['NY', 'NJ', 'PA'], 'stuff': ['a','b','c']} )
hover = HoverTool(tooltips=[("error", "$x"),
                            ("state", "@state"),
                            ("stuff", "@stuff")
                           ])
hv.Scatter( data, kdims='x', vdims=['state', 'stuff']).opts(tools=[hover], size=10).redim.range(x=(0,7))

My solution, maybe there is a simpler way to do that -


from bokeh.models import HoverTool
from bokeh.models import CustomJSHover

custom_formatter = CustomJSHover(code="""
    var rgba = value;
    var r = (rgba >> 16) & 0xFF;
    var g = (rgba >> 8) & 0xFF;
    var b = rgba & 0xFF;
    return r + ", " + g + ", " + b;
""")
hover = HoverTool(
        tooltips=[("RGB", "@image{custom}")],
        formatters={'@image': custom_formatter}
    )

hv.RGB(rgb_image, bounds=(0, 0, 2720, 2080)).opts(
    invert_yaxis=False,
    tools=[hover],
    width=width,
    height=height,
    active_tools=['pan', 'box_zoom'])
2 Likes