Skip to content

Commit

Permalink
handle hover_cols set as 'all'
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt committed Dec 14, 2023
1 parent 11535ba commit 6087e8f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 6 additions & 2 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,11 @@ def ohlc(self, x=None, y=None, data=None):
o, h, l, c = y
neg, pos = self.kwds.get('neg_color', 'red'), self.kwds.get('pos_color', 'green')
color_exp = (dim(o)>dim(c)).categorize({True: neg, False: pos})
ds = Dataset(data, [x], [o, h, l, c] + self.hover_cols)
ohlc_cols = [o, h, l, c]
if x in self.hover_cols:
self.hover_cols.remove(x)
vdims = list(dict.fromkeys(ohlc_cols + self.hover_cols))
ds = Dataset(data, [x], vdims)
if ds.data[x].dtype.kind in 'SUO':
rects = Rectangles(ds, [x, o, x, c])
else:
Expand All @@ -2080,7 +2084,7 @@ def ohlc(self, x=None, y=None, data=None):
tools[tools.index('hover')] = HoverTool(tooltips=[
(x, f'@{x}'), ('Open', f'@{o}'), ('High', f'@{h}'),
('Low', f'@{l}'), ('Close', f'@{c}')
] + [(hc, f'@{hc}') for hc in self.hover_cols])
] + [(hc, f'@{hc}') for hc in vdims[4:]])
seg_cur_opts['tools'] = tools
seg_cur_opts ['color'] = self.kwds.get('line_color', 'black')
if 'xlabel' not in seg_cur_opts:
Expand Down
12 changes: 11 additions & 1 deletion hvplot/tests/plotting/testohlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ def test_ohlc_hover_cols():
segments = plot.Segments.I
assert 'Volume' in segments
tooltips = segments.opts.get('plot').kwargs['tools'][0].tooltips
assert ('Volume', '@Volume') in tooltips
assert len(tooltips) == len(df.columns) + 1
assert tooltips[-1] == ('Volume', '@Volume')


def test_ohlc_hover_cols_all():
plot = df.hvplot.ohlc(y=ohlc_cols, hover_cols='all')
segments = plot.Segments.I
assert 'Volume' in segments
tooltips = segments.opts.get('plot').kwargs['tools'][0].tooltips
assert len(tooltips) == len(df.columns) + 1
assert tooltips[-1] == ('Volume', '@Volume')

0 comments on commit 6087e8f

Please sign in to comment.