Skip to content

Commit

Permalink
Remove hover_mode (#1415)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored Sep 20, 2024
1 parent efeda78 commit ac5021b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
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 @@ -562,9 +560,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 @@ -587,7 +585,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 @@ -837,17 +834,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

0 comments on commit ac5021b

Please sign in to comment.