Add hover to default tools but not have it enabled

Is there a way to have the hover tool as an option on the toolbar, but having it disabled by default? So that the user can turn it on when they want to.

@dhruvbalwada

based on https://stackoverflow.com/a/56998899 the following code does the trick, but I’m not sure where the mapping of ‘tool’:‘toolbar.name’ {‘pan’: ‘active_drag’, ‘hover’:‘active_inspect’} is documented…

No active tools by default:

import holoviews as hv
error = np.random.rand(100, 3)
points = hv.Points(error)

def set_tools(plot, element):
    plot.state.toolbar.active_drag = None
    plot.state.toolbar.active_inspect = None
    
points.opts(tools=['hover'], hooks=[set_tools])
1 Like

Thanks, this sort of works. It definitely suppresses the hover tool by default.

However, when mixing this with Adjoint layouts:

import holoviews as hv
from holoviews import opts
from holoviews.streams import Stream
import param
import numpy as np

hv.extension('bokeh')
ls = np.linspace(0, 10, 200)
xx, yy = np.meshgrid(ls, ls)

def set_tools(plot, element):
    plot.state.toolbar.active_drag = None
    plot.state.toolbar.active_inspect = None
    
class Style(param.Parameterized):
    colormap = param.ObjectSelector(default='viridis', objects=['viridis', 'plasma', 'magma'])
    color_levels = param.Integer(default=255, bounds=(1, 255))
    xlim = param.Range(default=(0,1))
    rangexy = hv.streams.RangeXY()
    
    @param.depends('colormap','color_levels','xlim')
    def view(self):
        image = hv.Image(np.sin(xx)*np.cos(yy)).hist()
        self.rangexy.source = image
        
        image.opts(opts.Image(tools=['hover'], hooks=[set_tools]))
        
        return image.opts(opts.Image(colorbar=True, width=400, 
                       cmap=self.colormap, 
                       color_levels=self.color_levels, 
                       xlim=self.xlim,)
                      )
        
myplot = Style()
pn.panel(myplot.view)

there is some weird behavior. If you run this above code you will see that initially the hovertool is highlighted but not actually working, to make it work you need to click once to unhighlight and then click again to rehilight and then it works.

I think active_tools
http://holoviews.org/user_guide/Plotting_with_Bokeh.html

path = hv.Path([])
freehand = hv.streams.FreehandDraw(source=path, num_objects=3)

path.opts(
    opts.Path(active_tools=['freehand_draw'], height=400, line_width=10, width=400))

Hi @ahuang11 -

This does not work.
When I use the example you posted the freehand_draw tool is active. I want it to be there, but be inactive.

Also, noticed a weird behavior - I can’t add hover to active_tools and can’t add freehand_draw to tools.

The only way to get both is to do:

path = hv.Path([])
freehand = hv.streams.FreehandDraw(source=path, num_objects=3)

path.opts(
    opts.Path(active_tools = ['freehand_draw'], tools=['hover'],  height=400, line_width=10, width=400))

in which case both are active, and I don’t want that.