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

Remove hover_mode #1415

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 5 additions & 7 deletions doc/user_guide/Customization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,20 @@
" Whether to flip the axis left to right or up and down respectively\n",
" grid (default=False): boolean\n",
" Whether to show a grid\n",
" hover : boolean\n",
" hover: boolean or Literal[\"vline\", \"hline\"]\n",
" Whether to show hover tooltips, default is True unless datashade is\n",
" True in which case hover is False by default\n",
" True in which case hover is False by default. Can also set\n",
" `vline` for hitbox across a vertical line or `hline` for hitbox across a horizontal line.\n",
" hover_cols (default=[]): list or str\n",
" Additional columns to add to the hover tool or 'all' which will\n",
" includes all columns (including indexes if use_index is True).\n",
" hover_formatters:\n",
" A dict of formatting options for the hover tooltip.\n",
" hover_tooltips list[str] or list[tuple]:\n",
" A list of dimensions to be displayed in the hover tooltip. See\n",
" [HoloViews docs](https://holoviews.org/user_guide/Plotting_with_Bokeh.html#hover-tools)\n",
" or [Bokeh docs](https://docs.bokeh.org/en/latest/docs/user_guide/interaction/tools.html#hovertool)\n",
" for more info on structuring.\n",
" hover_formatters:\n",
" A dict of formatting options for the hover tooltip.\n",
" hover_mode (default='mouse'):\n",
" The hover mode determines how the hover tool is activated;\n",
" select from 'mouse', 'vline', or 'hline'.\n",
" invert (default=False): boolean\n",
" Swaps x- and y-axis\n",
" frame_width/frame_height: int\n",
Expand Down
29 changes: 12 additions & 17 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,10 @@ class HoloViewsConverter:
hover_cols (default=[]): list or str
Additional columns to add to the hover tool or 'all' which will
includes all columns (including indexes if use_index is True).
hover_tooltips list[str] or list[tuple]:
A list of dimensions to be displayed in the hover tooltip.
hover_formatters:
A dict of formatting options for the hover tooltip.
hover_mode (default='mouse'):
The hover mode determines how the hover tool is activated.
hover_tooltips list[str] or list[tuple]:
A list of dimensions to be displayed in the hover tooltip.
invert (default=False): boolean
Swaps x- and y-axis
frame_width/frame_height: int
Expand Down Expand Up @@ -561,9 +559,9 @@ def __init__(
logy=None,
loglog=None,
hover=None,
hover_tooltips=None,
hover_cols=[],
hover_formatters=None,
hover_mode=None,
hover_tooltips=None,
subplots=False,
label=None,
invert=False,
Expand All @@ -586,7 +584,6 @@ def __init__(
flip_xaxis=None,
flip_yaxis=None,
dynspread=False,
hover_cols=[],
x_sampling=None,
y_sampling=None,
project=False,
Expand Down Expand Up @@ -833,17 +830,15 @@ def __init__(
if hover and not any(
t for t in tools if isinstance(t, HoverTool) or t in ['hover', 'vline', 'hline']
):
if hover in ['vline', 'hline']:
tools.append(hover)
else:
tools.append('hover')
if hover in {'vline', 'hline'}:
plot_opts['hover_mode'] = hover
tools.append('hover')
if 'hover' in tools:
if hover_tooltips:
plot_opts['hover_tooltips'] = hover_tooltips
if hover_formatters:
plot_opts['hover_formatters'] = hover_formatters
plot_opts['tools'] = tools
if hover_tooltips:
plot_opts['hover_tooltips'] = hover_tooltips
if hover_formatters:
plot_opts['hover_formatters'] = hover_formatters
if hover_mode:
plot_opts['hover_mode'] = hover_mode

if self.crs and global_extent:
plot_opts['global_extent'] = global_extent
Expand Down
25 changes: 25 additions & 0 deletions hvplot/tests/testcharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,31 @@ def test_errorbars_no_hover(self):
bkplot = Store.renderers['bokeh'].get_plot(plot)
assert not bkplot.tools

@parameterized.expand(['vline', 'hline'])
def test_hover_line(self, hover_mode):
plot = self.df.hvplot('x', 'y', hover=hover_mode)
opts = Store.lookup_options('bokeh', plot, 'plot')
self.assertEqual(opts.kwargs['hover_mode'], hover_mode)

def test_hover_tooltips(self):
plot = self.df.hvplot('x', 'y', hover_tooltips=['x'])
opts = Store.lookup_options('bokeh', plot, 'plot')
self.assertEqual(opts.kwargs['hover_tooltips'], ['x'])

def test_hover_formatter(self):
plot = self.df.hvplot('x', 'y', hover_formatters={'x': 'datetime'})
opts = Store.lookup_options('bokeh', plot, 'plot')
self.assertEqual(opts.kwargs['hover_formatters'], {'x': 'datetime'})

def test_hover_disabled(self):
plot = self.df.hvplot(
'x', 'y', hover_tooltips=['x'], hover_formatters={'x': 'datetime'}, hover=False
)
opts = Store.lookup_options('bokeh', plot, 'plot')
self.assertEqual(opts.kwargs['tools'], [])
assert 'hover_formatters' not in opts.kwargs
assert 'hover_tooltips' not in opts.kwargs

def test_labels_format(self):
plot = self.df.hvplot('x', 'y', text='({x}, {y})', kind='labels')
assert list(plot.dimensions()) == [Dimension('x'), Dimension('y'), Dimension('label')]
Expand Down
Loading