Skip to content

Commit

Permalink
fix: Don't clone Span in _init_tools (#6387)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Oct 7, 2024
1 parent 8c238ca commit d776362
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit d776362

Please sign in to comment.