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

fix: Don't clone Span in _init_tools #6387

Merged
merged 3 commits into from
Oct 7, 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
4 changes: 3 additions & 1 deletion holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
GlyphRenderer,
Legend,
Renderer,
Span,
Title,
tools,
)
Expand Down Expand Up @@ -577,10 +578,11 @@ def _init_tools(self, element, callbacks=None):
tool_list.append(tool)

copied_tools = []
skip_models = (Span,)
for tool in tool_list:
if isinstance(tool, tools.Tool):
properties = {
p: v.clone() if isinstance(v, Model) else v
p: v.clone() if isinstance(v, Model) and not isinstance(v, skip_models) else v
for p, v in tool.properties_with_values(include_defaults=False).items()
}
tool = type(tool)(**properties)
Expand Down
16 changes: 16 additions & 0 deletions holoviews/tests/plotting/bokeh/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import pyviz_comms as comms
from bokeh.models import (
ColumnDataSource,
CrosshairTool,
CustomJS,
HoverTool,
LinearColorMapper,
LogColorMapper,
Span,
)
from param import concrete_descendents

Expand Down Expand Up @@ -124,3 +126,17 @@ def test_sync_three_plots():
assert v[0].code == "dst.muted = src.muted"
assert isinstance(v[1], CustomJS)
assert v[1].code == "dst.muted = src.muted"


def test_span_not_cloned_crosshair():
# See https://github.com/holoviz/holoviews/issues/6386
height = Span(dimension="height")
cht = CrosshairTool(overlay=height)

layout = Curve([]).opts(tools=[cht]) + Curve([]).opts(tools=[cht])

(fig1, *_), (fig2, *_) = bokeh_renderer.get_plot(layout).handles["plot"].children
tool1 = next(t for t in fig1.tools if isinstance(t, CrosshairTool))
tool2 = next(t for t in fig2.tools if isinstance(t, CrosshairTool))

assert tool1.overlay is tool2.overlay