Skip to content

Commit

Permalink
Support BoxAnnotation's new API Bokeh 3.3 (#5935)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Oct 12, 2023
1 parent 70477d1 commit 53f816e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
3 changes: 2 additions & 1 deletion holoviews/plotting/bokeh/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ class BoxAnnotationPlot(ElementPlot, AnnotationPlot):
selection_display = None

def get_data(self, element, ranges, style):
data, mapping = {}, {}
data = {}
mapping = {k: None for k in ('left', 'right', 'bottom', 'top')}
kwd_dim1 = 'left' if isinstance(element, VSpan) else 'bottom'
kwd_dim2 = 'right' if isinstance(element, VSpan) else 'top'
if self.invert_axes:
Expand Down
38 changes: 28 additions & 10 deletions holoviews/tests/plotting/bokeh/test_annotationplot.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import unittest

import numpy as np
import pandas as pd

import holoviews as hv
from holoviews.element import (
HLine, VLine, Text, Labels, Arrow, HSpan, VSpan, Slope,
HLines, VLines, HSpans, VSpans,
)
from holoviews.plotting.bokeh.util import bokeh32
from holoviews.plotting.bokeh.util import bokeh32, bokeh33

from .test_plot import TestBokehPlot, bokeh_renderer

if bokeh32:
from bokeh.models import VSpan as BkVSpan, HSpan as BkHSpan, VStrip as BkVStrip, HStrip as BkHStrip

if bokeh33:
from bokeh.models.coordinates import Node


class TestHVLinePlot(TestBokehPlot):

Expand Down Expand Up @@ -56,16 +58,24 @@ def test_hspan_invert_axes(self):

assert span.left == 1.1
assert span.right == 1.5
assert pd.isna(span.bottom)
assert pd.isna(span.top)
if bokeh33:
assert isinstance(span.bottom, Node)
assert isinstance(span.top, Node)
else:
assert span.bottom is None
assert span.top is None
assert span.visible

def test_hspan_plot(self):
hspan = HSpan(1.1, 1.5)
plot = bokeh_renderer.get_plot(hspan)
span = plot.handles['glyph']
assert pd.isna(span.left)
assert pd.isna(span.right)
if bokeh33:
assert isinstance(span.left, Node)
assert isinstance(span.right, Node)
else:
assert span.left is None
assert span.right is None
assert span.bottom == 1.1
assert span.top == 1.5
assert span.visible
Expand All @@ -80,8 +90,12 @@ 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']
assert pd.isna(span.left)
assert pd.isna(span.right)
if bokeh33:
assert isinstance(span.left, Node)
assert isinstance(span.right, Node)
else:
assert span.left is None
assert span.right is None
assert span.bottom == 1.1
assert span.top == 1.5
assert span.visible
Expand All @@ -92,8 +106,12 @@ def test_vspan_plot(self):
span = plot.handles['glyph']
assert span.left == 1.1
assert span.right == 1.5
assert pd.isna(span.bottom)
assert pd.isna(span.top)
if bokeh33:
assert isinstance(span.bottom, Node)
assert isinstance(span.top, Node)
else:
assert span.bottom is None
assert span.top is None
assert span.visible

def test_vspan_empty(self):
Expand Down

0 comments on commit 53f816e

Please sign in to comment.