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

Set OHLC x-axis tooltip to datetime format #1493

Merged
merged 8 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 3 additions & 2 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2631,14 +2631,15 @@ def ohlc(self, x=None, y=None, data=None):
tools = seg_cur_opts.pop('tools', [])
if 'hover' in tools:
tools[tools.index('hover')] = HoverTool(
formatters={f'@{x}': 'datetime'},
Azaya89 marked this conversation as resolved.
Show resolved Hide resolved
tooltips=[
(x, f'@{x}'),
(x, f'@{x}{{%F}}'),
('Open', f'@{o}'),
('High', f'@{h}'),
('Low', f'@{l}'),
('Close', f'@{c}'),
]
+ [(hc, f'@{hc}') for hc in vdims[4:]]
+ [(hc, f'@{hc}') for hc in vdims[4:]],
)
seg_cur_opts['tools'] = tools
seg_cur_opts['color'] = self.kwds.get('line_color', 'black')
Expand Down
12 changes: 12 additions & 0 deletions hvplot/tests/plotting/testohlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ def test_ohlc_hover_cols_all():
tooltips = segments.opts.get('plot').kwargs['tools'][0].tooltips
assert len(tooltips) == len(df.columns) + 1
assert tooltips[-1] == ('Volume', '@Volume')


def test_ohlc_date_tooltip_format():
maximlt marked this conversation as resolved.
Show resolved Hide resolved
plot = df.hvplot.ohlc(y=ohlc_cols)
segments = plot.Segments.I
hover_tool = segments.opts.get('plot').kwargs['tools'][0]
tooltips = hover_tool.tooltips
x_label, x_tooltip = tooltips[0]
assert '{%F}' in x_tooltip
formatter_key = '@' + x_label
formatter = hover_tool.formatters
assert formatter.get(formatter_key) == 'datetime'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert formatter.get(formatter_key) == 'datetime'
assert formatter[formatter_key] == 'datetime'

Loading