Skip to content

Commit

Permalink
Fix active_tools to only be set for enabled tools (#5616)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Feb 9, 2023
1 parent 349d80a commit 8bc04d0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
run: |
conda activate test-environment
conda uninstall panel bokeh --force -y --offline || echo "packages already removed"
pip install "git+https://github.com/holoviz/panel.git@branch-1.0"
pip install "git+https://github.com/holoviz/panel.git"
- name: doit test_unit
run: |
conda activate test-environment
Expand Down
23 changes: 16 additions & 7 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@

class ElementPlot(BokehPlot, GenericElementPlot):

active_tools = param.List(default=['pan', 'wheel_zoom'], doc="""
active_tools = param.List(default=None, doc="""
Allows specifying which tools are active by default. Note
that only one tool per gesture type can be active, e.g.
both 'pan' and 'box_zoom' are drag tools, so if both are
listed only the last one will be active.""")
listed only the last one will be active. As a default 'pan'
and 'wheel_zoom' will be used if the tools are enabled.""")

align = param.ObjectSelector(default='start', objects=['start', 'center', 'end'], doc="""
Alignment (vertical or horizontal) of the plot in a layout.""")
Expand Down Expand Up @@ -570,15 +571,23 @@ def _set_active_tools(self, plot):
"Activates the list of active tools"
if plot is None:
return
for tool in self.active_tools:

if self.active_tools is None:
enabled_tools = set(self.default_tools + self.tools)
active_tools = {'pan', 'wheel_zoom'} & enabled_tools
else:
active_tools = self.active_tools

for tool in active_tools:
if isinstance(tool, str):
tool_type = TOOL_TYPES[tool]
tool_type = TOOL_TYPES.get(tool, type(None))
matching = [t for t in plot.toolbar.tools
if isinstance(t, tool_type)]
if not matching:
self.param.warning('Tool of type %r could not be found '
'and could not be activated by default.'
% tool)
self.param.warning(
f'Tool of type {tool!r} could not be found '
'and could not be activated by default.'
)
continue
tool = matching[0]
if isinstance(tool, tools.Drag):
Expand Down
2 changes: 1 addition & 1 deletion holoviews/tests/core/test_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ def callback(x): return Curve([1,2,3])
dmap.periodic(0.01, 100, param_fn=lambda i: {'x':i})
self.assertEqual(xval.x, 100)

@pytest.mark.flaky
@pytest.mark.flaky(max_runs=3)
def test_periodic_param_fn_non_blocking(self):
def callback(x): return Curve([1,2,3])
xval = Stream.define('x',x=0)()
Expand Down
2 changes: 1 addition & 1 deletion holoviews/tests/plotting/bokeh/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_box_edit_callback_initialized_server(self):
plot = bokeh_server_renderer.get_plot(boxes)
assert 'data' in plot.handles['cds']._callbacks

@pytest.mark.flaky
@pytest.mark.flaky(max_runs=3)
def test_poly_edit_callback(self):
polys = Polygons([[(0, 0), (2, 2), (4, 0)]])
poly_edit = PolyEdit(source=polys)
Expand Down
2 changes: 2 additions & 0 deletions holoviews/tests/plotting/bokeh/test_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time

import param
import pytest

from holoviews.core.spaces import DynamicMap
from holoviews.core.options import Store
Expand Down Expand Up @@ -123,6 +124,7 @@ def test_launch_server_with_stream(self):
self.assertEqual(cb.streams, [stream])
assert 'rangesupdate' in plot.state._event_callbacks

@pytest.mark.flaky(max_runs=3)
def test_launch_server_with_complex_plot(self):
dmap = DynamicMap(lambda x_range, y_range: Curve([]), streams=[RangeXY()])
overlay = dmap * HLine(0)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ commands = pytest holoviews --cov=./holoviews -vv
[_examples]
description = Test that default examples run
deps = .[examples_tests]
commands = pytest -n auto --dist loadscope --nbval-lax examples -k "not Plotting_with_Bokeh and not 17-Dashboards and not Plots_and_Renderers"
commands = pytest -n auto --dist loadscope --nbval-lax examples --force-flaky --max-runs=5 -k "not Plotting_with_Bokeh and not 17-Dashboards and not Plots_and_Renderers"
# 'Plotting_with_Bokeh' needs selenium, phantomjs, firefox and geckodriver to save a png picture.
# '17-Dashboards' can give a timeout error.
# 'Plots_and_Renderers' can give file not found here.
Expand Down

0 comments on commit 8bc04d0

Please sign in to comment.