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

Bokeh 3.3 support #5923

Merged
merged 4 commits into from
Oct 11, 2023
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
14 changes: 9 additions & 5 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from bokeh.models import (
CustomJS, FactorRange, DatetimeAxis, Range1d, DataRange1d,
PolyDrawTool, PolyEditTool, FreehandDrawTool,
PointDrawTool
PointDrawTool, BoxEditTool
)
from panel.io.state import state

Expand All @@ -25,7 +25,8 @@
BoxEdit, PointDraw, PolyDraw, PolyEdit, CDSStream, FreehandDraw,
CurveEdit, SelectionXY, Lasso, SelectMode
)
from .util import convert_timestamp
from .util import bokeh33, convert_timestamp
from ...util.warnings import warn


class Callback:
Expand Down Expand Up @@ -1212,9 +1213,12 @@ def initialize(self, plot_id=None):
renderer = self._path_initialize()
if stream.styles:
self._create_style_callback(cds, renderer.glyph)
# BoxEditTool does not support Quad type only Rect
# box_tool = BoxEditTool(renderers=[renderer], **kwargs)
# self.plot.state.tools.append(box_tool)
if bokeh33:
# First version with Quad support
box_tool = BoxEditTool(renderers=[renderer], **kwargs)
self.plot.state.tools.append(box_tool)
else:
warn("BoxEditTool requires Bokeh >= 3.3")
self._update_cds_vdims(cds.data)
super(CDSCallback, self).initialize()

Expand Down
2 changes: 2 additions & 0 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ def _axis_props(self, plots, subplots, element, ranges, pos, *, dim=None,
else not util.isfinite(el) for el in [v0, v1]
):
dim_range = range_type()
elif issubclass(range_type, FactorRange):
dim_range = range_type(name=dim.name if dim else None)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philippjfr, do you have any fear about this change? By not setting start and end on FactorRange.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None, whatsoever. Looks fine.

else:
dim_range = range_type(start=v0, end=v1, name=dim.name if dim else None)

Expand Down
1 change: 1 addition & 0 deletions holoviews/plotting/bokeh/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

bokeh_version = Version(bokeh.__version__)
bokeh32 = bokeh_version >= Version("3.2")
bokeh33 = bokeh_version >= Version("3.3")

TOOL_TYPES = {
'pan': tools.PanTool,
Expand Down
41 changes: 21 additions & 20 deletions holoviews/tests/plotting/bokeh/test_annotationplot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

import numpy as np
import pandas as pd

import holoviews as hv
from holoviews.element import (
Expand Down Expand Up @@ -53,21 +54,21 @@ def test_hspan_invert_axes(self):
plot = bokeh_renderer.get_plot(hspan)
span = plot.handles['glyph']

self.assertEqual(span.left, 1.1)
self.assertEqual(span.right, 1.5)
self.assertEqual(span.bottom, None)
self.assertEqual(span.top, None)
self.assertEqual(span.visible, True)
assert span.left == 1.1
assert span.right == 1.5
assert pd.isna(span.bottom)
assert pd.isna(span.top)
assert span.visible

def test_hspan_plot(self):
hspan = HSpan(1.1, 1.5)
plot = bokeh_renderer.get_plot(hspan)
span = plot.handles['glyph']
self.assertEqual(span.left, None)
self.assertEqual(span.right, None)
self.assertEqual(span.bottom, 1.1)
self.assertEqual(span.top, 1.5)
self.assertEqual(span.visible, True)
assert pd.isna(span.left)
assert pd.isna(span.right)
assert span.bottom == 1.1
assert span.top == 1.5
assert span.visible

def test_hspan_empty(self):
vline = HSpan(None)
Expand All @@ -79,21 +80,21 @@ def test_vspan_invert_axes(self):
vspan = VSpan(1.1, 1.5).opts(invert_axes=True)
plot = bokeh_renderer.get_plot(vspan)
span = plot.handles['glyph']
self.assertEqual(span.left, None)
self.assertEqual(span.right, None)
self.assertEqual(span.bottom, 1.1)
self.assertEqual(span.top, 1.5)
self.assertEqual(span.visible, True)
assert pd.isna(span.left)
assert pd.isna(span.right)
assert span.bottom == 1.1
assert span.top == 1.5
assert span.visible

def test_vspan_plot(self):
vspan = VSpan(1.1, 1.5)
plot = bokeh_renderer.get_plot(vspan)
span = plot.handles['glyph']
self.assertEqual(span.left, 1.1)
self.assertEqual(span.right, 1.5)
self.assertEqual(span.bottom, None)
self.assertEqual(span.top, None)
self.assertEqual(span.visible, True)
assert span.left == 1.1
assert span.right == 1.5
assert pd.isna(span.bottom)
assert pd.isna(span.top)
assert span.visible

def test_vspan_empty(self):
vline = VSpan(None)
Expand Down