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

Dropping support for Bokeh 2 #5891

Merged
merged 8 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
19 changes: 1 addition & 18 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
BoxEdit, PointDraw, PolyDraw, PolyEdit, CDSStream, FreehandDraw,
CurveEdit, SelectionXY, Lasso, SelectMode
)
from .util import bokeh3, convert_timestamp
from .util import convert_timestamp


class Callback:
Expand Down Expand Up @@ -617,23 +617,6 @@ class RangeXYCallback(Callback):
'y1': 'cb_obj.y1',
}

_js_on_event = """
if (this._updating)
return
const plot = this.origin
const plots = plot.x_range.plots.concat(plot.y_range.plots)
for (const p of plots) {
const event = new this.constructor(p.x_range.start, p.x_range.end, p.y_range.start, p.y_range.end)
event._updating = true
p.trigger_event(event)
}
"""

def set_callback(self, handle):
super().set_callback(handle)
if not bokeh3:
handle.js_on_event('rangesupdate', CustomJS(code=self._js_on_event))

def _process_msg(self, msg):
if self.plot.state.x_range is not self.plot.handles['x_range']:
x_range = self.plot.handles['x_range']
Expand Down
40 changes: 13 additions & 27 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
)
from .tabular import TablePlot
from .util import (
TOOL_TYPES, bokeh_version, bokeh3, bokeh32, date_to_integer,
TOOL_TYPES, bokeh_version, bokeh32, date_to_integer,
decode_bytes, get_tab_title, glyph_order, py2js_tickformatter,
recursive_model_update, theme_attr_json, cds_column_replace,
hold_policy, match_dim_specs, compute_layout_properties,
Expand All @@ -58,12 +58,8 @@
get_scale, get_axis_class
)

if bokeh3:
from bokeh.models.formatters import CustomJSTickFormatter
from bokeh.models.layouts import TabPanel
else:
from bokeh.models.formatters import FuncTickFormatter as CustomJSTickFormatter
from bokeh.models.layouts import Panel as TabPanel
from bokeh.models.formatters import CustomJSTickFormatter
from bokeh.models.layouts import TabPanel

try:
TOOLS_MAP = Tool._known_aliases
Expand Down Expand Up @@ -629,10 +625,7 @@ def _init_plot(self, key, element, plots, ranges=None):

properties.update(**self._plot_properties(key, element))

if bokeh3:
figure = bokeh.plotting.figure
else:
figure = bokeh.plotting.Figure
figure = bokeh.plotting.figure

with warnings.catch_warnings():
# Bokeh raises warnings about duplicate tools but these
Expand Down Expand Up @@ -1633,18 +1626,13 @@ def _update_glyph(self, renderer, properties, mapping, glyph, source, data):
server = self.renderer.mode == 'server'
with hold_policy(self.document, 'collect', server=server):
empty_data = {c: [] for c in columns}
if bokeh3:
event = ModelChangedEvent(
document=self.document,
model=source,
attr='data',
new=empty_data,
setter='empty'
)
else:
event = ModelChangedEvent(
self.document, source, 'data', source.data, empty_data, empty_data, setter='empty'
)
event = ModelChangedEvent(
document=self.document,
model=source,
attr='data',
new=empty_data,
setter='empty'
)
self.document.callbacks._held_events.append(event)

if legend is not None:
Expand Down Expand Up @@ -2474,7 +2462,7 @@ def _process_legend(self, plot=None):
or not self.show_legend):
legend.items[:] = []
else:
if bokeh3 and self.legend_cols:
if self.legend_cols:
plot.legend.nrows = self.legend_cols
else:
plot.legend.orientation = 'horizontal' if self.legend_cols else 'vertical'
Expand Down Expand Up @@ -2576,8 +2564,6 @@ def _process_legend(self, overlay):
options[k] = v

pos = self.legend_position
if not bokeh3:
options['orientation'] = 'horizontal' if self.legend_cols else 'vertical'
if pos in ['top', 'bottom'] and not self.legend_cols:
options['orientation'] = 'horizontal'

Expand All @@ -2587,7 +2573,7 @@ def _process_legend(self, overlay):

options.update(self._fontsize('legend', 'label_text_font_size'))
options.update(self._fontsize('legend_title', 'title_text_font_size'))
if bokeh3 and self.legend_cols:
if self.legend_cols:
options.update({"ncols": self.legend_cols})
legend.update(**options)

Expand Down
3 changes: 0 additions & 3 deletions holoviews/plotting/bokeh/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
base_properties, line_properties, fill_properties, text_properties,
rgba_tuple
)
from .util import bokeh3


class GraphPlot(GraphMixin, CompositeElementPlot, ColorbarPlot, LegendPlot):
Expand Down Expand Up @@ -185,8 +184,6 @@ def get_data(self, element, ranges, style):
index = nodes.astype(np.int32)
layout = {k: (y, x) if self.invert_axes else (x, y)
for k, (x, y) in zip(index, node_positions)}
if not bokeh3:
layout = {str(k): v for k, v in layout.items()}

point_data = {'index': index}

Expand Down
14 changes: 2 additions & 12 deletions holoviews/plotting/bokeh/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

from bokeh.models import CustomJS
from bokeh.models.tools import RangeTool
from bokeh.models import Toolbar

from .util import bokeh3
from ...core.util import isscalar
from ..links import (
Link, RectanglesTableLink, DataLink, RangeToolLink,
SelectionLink, VertexTableLink
)
from ..plot import GenericElementPlot, GenericOverlayPlot

if bokeh3:
from bokeh.models import Toolbar
else:
from bokeh.models import ToolbarBox as Toolbar # Not completely correct


class LinkCallback:

Expand Down Expand Up @@ -158,11 +153,8 @@ def __init__(self, root_model, link, source_plot, target_plot):

tool = RangeTool(**axes)
source_plot.state.add_tools(tool)
if bokeh3 and toolbars:
if toolbars:
toolbars[0].tools.append(tool)
elif toolbars:
toolbar = toolbars[0].toolbar
toolbar.tools.append(tool)


class DataLinkCallback(LinkCallback):
Expand Down Expand Up @@ -206,8 +198,6 @@ def __init__(self, root_model, link, source_plot, target_plot):
renderer.update(data_source=src_cds)
else:
renderer.update(source=src_cds)
if not bokeh3 and hasattr(renderer, 'view'):
renderer.view.update(source=src_cds)
target_plot.handles['source'] = src_cds
target_plot.handles['cds'] = src_cds
for callback in target_plot.callbacks:
Expand Down
22 changes: 8 additions & 14 deletions holoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@
from ..util import attach_streams, displayable, collate
from .links import LinkCallback
from .util import (
bokeh3, filter_toolboxes, make_axis, sync_legends, update_shared_sources, empty_plot,
filter_toolboxes, make_axis, sync_legends, update_shared_sources, empty_plot,
decode_bytes, theme_attr_json, cds_column_replace, get_default, merge_tools, select_legends
)

if bokeh3:
from bokeh.models.layouts import TabPanel
else:
from bokeh.models.layouts import Panel as TabPanel
from bokeh.models.layouts import TabPanel


class BokehPlot(DimensionedPlot, CallbackPlot):
Expand Down Expand Up @@ -271,10 +268,9 @@ def _get_title_div(self, key, default_fontsize='15pt', width=450):

if 'title' in self.handles:
title_div = self.handles['title']
elif bokeh3:
title_div = Div(width=width, styles={"white-space": "nowrap"}) # so it won't wrap long titles easily
else:
title_div = Div(width=width, style={"white-space": "nowrap"}) # so it won't wrap long titles easily
# so it won't wrap long titles easily
title_div = Div(width=width, styles={"white-space": "nowrap"})
title_div.text = title_tags

return title_div
Expand Down Expand Up @@ -310,8 +306,6 @@ def sync_sources(self):
renderer.update(data_source=new_source)
else:
renderer.update(source=new_source)
if not bokeh3 and hasattr(renderer, 'view'):
renderer.view.update(source=new_source)
plot.handles['source'] = plot.handles['cds'] = new_source
plots.append(plot)
shared_sources.append(new_source)
Expand Down Expand Up @@ -592,7 +586,7 @@ def initialize_plot(self, ranges=None, plots=[]):
if self.sync_legends:
sync_legends(plot)
plot = self._make_axes(plot)
if bokeh3 and hasattr(plot, "toolbar") and self.merge_tools:
if hasattr(plot, "toolbar") and self.merge_tools:
plot.toolbar = merge_tools(plots)

title = self._get_title_div(self.keys[-1])
Expand Down Expand Up @@ -645,7 +639,7 @@ def _make_axes(self, plot):
x_axis.margin = (0, 0, 0, 50)
r1, r2 = r1[::-1], r2[::-1]
plot = gridplot([r1, r2], merge_tools=False)
if bokeh3 and self.merge_tools:
if self.merge_tools:
plot.toolbar = merge_tools([r1, r2])
elif y_axis:
models = [y_axis, plot]
Expand Down Expand Up @@ -952,7 +946,7 @@ def initialize_plot(self, plots=None, ranges=None):
merge_tools=False,
toolbar_location=self.toolbar,
sizing_mode=sizing_mode)
if bokeh3 and self.merge_tools:
if self.merge_tools:
grid.toolbar = merge_tools(children)
tab_plots.append((title, grid))
continue
Expand Down Expand Up @@ -994,7 +988,7 @@ def initialize_plot(self, plots=None, ranges=None):
)
if self.sync_legends:
sync_legends(layout_plot)
if bokeh3 and self.merge_tools:
if self.merge_tools:
layout_plot.toolbar = merge_tools(plot_grid)

title = self._get_title_div(self.keys[-1])
Expand Down
16 changes: 1 addition & 15 deletions holoviews/plotting/bokeh/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .element import ColorbarPlot, LegendPlot
from .selection import BokehOverlaySelectionDisplay
from .styles import base_properties, fill_properties, line_properties, mpl_to_bokeh
from .util import bokeh3, colormesh
from .util import colormesh


class RasterPlot(ColorbarPlot):
Expand Down Expand Up @@ -102,10 +102,6 @@ def get_data(self, element, ranges, style):
l, b, r, t = b, l, t, r

dh, dw = t-b, r-l
if self.invert_xaxis and not bokeh3:
l, r = r, l
if self.invert_yaxis and not bokeh3:
b, t = t, b
data = dict(x=[l], y=[b], dw=[dw], dh=[dh])

for i, vdim in enumerate(element.vdims, 2):
Expand All @@ -118,10 +114,6 @@ def get_data(self, element, ranges, style):
img = np.array([[np.NaN]])
if self.invert_axes ^ (type(element) is Raster):
img = img.T
if self.invert_xaxis and not bokeh3:
img = img[:, ::-1]
if self.invert_yaxis and not bokeh3:
img = img[::-1]
key = 'image' if i == 2 else dimension_sanitizer(vdim.name)
data[key] = [img]

Expand Down Expand Up @@ -212,12 +204,6 @@ def get_data(self, element, ranges, style):
l, b, r, t = b, l, t, r

dh, dw = t-b, r-l
if self.invert_xaxis and not bokeh3:
l, r = r, l
img = img[:, ::-1]
if self.invert_yaxis and not bokeh3:
img = img[::-1]
b, t = t, b

if 0 in img.shape:
img = np.zeros((1, 1), dtype=np.uint32)
Expand Down
Loading