Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect hover_cols for OHLC #1216

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ 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])
ds = Dataset(data, [x], [o, h, l, c] + self.hover_cols)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked if this works when hover_cols="all"?

if ds.data[x].dtype.kind in 'SUO':
rects = Rectangles(ds, [x, o, x, c])
else:
Expand All @@ -2078,9 +2078,9 @@ def ohlc(self, x=None, y=None, data=None):
tools = seg_cur_opts.pop('tools', [])
if 'hover' in tools:
tools[tools.index('hover')] = HoverTool(tooltips=[
(x, '@{%s}' % x), ('Open', '@{%s}' % o), ('High', '@{%s}' % h),
('Low', '@{%s}' % l), ('Close', '@{%s}' % c)
])
(x, f'@{x}'), ('Open', f'@{o}'), ('High', f'@{h}'),
('Low', f'@{l}'), ('Close', f'@{c}')
] + [(hc, f'@{hc}') for hc in self.hover_cols])
seg_cur_opts['tools'] = tools
seg_cur_opts ['color'] = self.kwds.get('line_color', 'black')
if 'xlabel' not in seg_cur_opts:
Expand Down
21 changes: 21 additions & 0 deletions hvplot/tests/plotting/testohlc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pandas as pd
import hvplot.pandas # noqa


df = pd.DataFrame({
'Open': [100.00, 101.25, 102.75],
'High': [104.10, 105.50, 110.00],
'Low': [94.00, 97.10, 99.20],
'Close': [101.15, 99.70, 109.50],
'Volume': [10012, 5000, 18000],
}, index=[pd.Timestamp('2022-08-01'), pd.Timestamp('2022-08-03'), pd.Timestamp('2022-08-04')])

ohlc_cols = ['Open', 'High', 'Low', 'Close']


def test_ohlc_hover_cols():
plot = df.hvplot.ohlc(y=ohlc_cols, hover_cols=['Volume'])
segments = plot.Segments.I
assert 'Volume' in segments
tooltips = segments.opts.get('plot').kwargs['tools'][0].tooltips
assert ('Volume', '@Volume') in tooltips