Skip to content

Commit

Permalink
Add unit test and add scalebar to handles
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Dec 22, 2023
1 parent 699466f commit e53fd68
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,7 @@ def _draw_scalebar(self, plot):
label=self.scalebar_label,
**opts,
)
self.handles['scalebar'] = scale_bar
plot.add_layout(scale_bar)

class CompositeElementPlot(ElementPlot):
Expand Down
58 changes: 57 additions & 1 deletion holoviews/tests/plotting/bokeh/test_elementplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
tools,
)

from holoviews.core import DynamicMap, HoloMap, NdOverlay
from holoviews.core import Dimension, DynamicMap, HoloMap, NdOverlay
from holoviews.core.util import dt_to_int
from holoviews.element import Curve, HeatMap, Image, Labels, Scatter
from holoviews.plotting.bokeh.util import bokeh33
from holoviews.plotting.util import process_cmap
from holoviews.streams import PointDraw, Stream
from holoviews.util import render
Expand Down Expand Up @@ -793,6 +794,61 @@ def test_element_backend_opts_model_not_resolved(self):
"WARNING", "cb model could not be"
)


@pytest.mark.usefixtures("bokeh_backend")
@pytest.mark.skipif(not bokeh33, reason="requires Bokeh >= 3.3")
class TestScalebarPlot:

def get_scalebar(self, element):
plot = bokeh_renderer.get_plot(element)
return plot.handles.get('scalebar')

def test_scalebar(self):
curve = Curve([1, 2, 3]).opts(scalebar=True)
scalebar = self.get_scalebar(curve)
assert scalebar.visible
assert scalebar.location == 'bottom_right'
assert scalebar.background_fill_alpha == 0.8
assert scalebar.unit == "m"

def test_no_scalebar(self):
curve = Curve([1, 2, 3])
scalebar = self.get_scalebar(curve)
assert scalebar is None

def test_scalebar_unit(self):
curve = Curve([1, 2, 3]).opts(scalebar=True, scalebar_unit='cm')
scalebar = self.get_scalebar(curve)
assert scalebar.visible
assert scalebar.unit == "cm"

def test_dim_unit(self):
dim = Dimension("dim", unit="cm")
curve = Curve([1, 2, 3], kdims=dim).opts(scalebar=True)
scalebar = self.get_scalebar(curve)
assert scalebar.visible
assert scalebar.unit == "cm"

def test_scalebar_wrong_unit(self):
curve = Curve([1, 2, 3]).opts(scalebar=True, scalebar_unit='xx')

msg = "Only the following units are supported"
with pytest.raises(ValueError, match=msg):
self.get_scalebar(curve)

def test_scalebar_custom_opts(self):
curve = Curve([1, 2, 3]).opts(scalebar=True, scalebar_opts={'background_fill_alpha': 1})
scalebar = self.get_scalebar(curve)
assert scalebar.visible
assert scalebar.background_fill_alpha == 1

def test_scalebar_label(self):
curve = Curve([1, 2, 3]).opts(scalebar=True, scalebar_label='Test')
scalebar = self.get_scalebar(curve)
assert scalebar.visible
assert scalebar.label == 'Test'


class TestColorbarPlot(LoggingComparisonTestCase, TestBokehPlot):

def test_colormapper_symmetric(self):
Expand Down

0 comments on commit e53fd68

Please sign in to comment.