Trying to build a stock candlestick chart in holoviews using rectangles + segments. I am running into trouble when trying to turn on the vline/hline hit behavior in the hover tool for rectangles.
Passing rectangles.opts(tools=[‘hover’]) works just fine and I get tooltips when hovering over the rectangle. However, using tools=[‘vline’] as in the documentation turns off hover behavior completely. Test it out with a separately instantiated HoverTool instance, same thing.
I noticed in the segments chart this works fine. However, I would really like to have the vline behavior work with rectangles much like any charting software so the user does not have to move the mouse over each candle to see tooltips.
Code:
xs = np.arange(100)
ys = np.random.randn(101).cumsum()
O = ys[1:]
C = ys[:-1]
H = np.max([O, C], axis=0) + np.random.rand(100)
L = np.min([O, C], axis=0) - np.random.rand(100)
# Color boxes where price decreased red and where price increased green
color_exp = (dim('y0')>dim('y1')).categorize({True: 'green', False: 'red'})
# Draw open & close prices, candles without wicks
boxes = hv.Rectangles((xs-0.25, O, xs+0.25, C))
boxes.opts(width=1000, color=color_exp, xlabel='Time', ylabel='Price', tools=['hover'])
# Draw high & low prices, candle wicks
segments = hv.Segments((xs, L, xs, H))
segments.opts(color='black')
# Working in Spyder so using pn.serve for output
dash = segments * boxes
serve(dash)
Scenarios:
-
Base scenario (default code), result = hover info available on rectangle mouseover
-
Activate “vline” hit test behavior on rectangles
boxes.opts(... tools=['vline'])
result = hover behavior disabled completely on rectangles
-
Activate vline hit test behavior on segments
segments.opts(... tools=['vline'])
result = hover vline behavior works on segments
Packages:
Holoviews: == 1.14.4
Bokeh == 2.3.2
I expect vline/hline options to work just fine for rectangles. It’s a bit easier to hover over them versus segments due to glyph line width.
Cheers,
Amer