|
5 | 5 | import pytest |
6 | 6 | from bokeh.models import CustomJSHover, HoverTool |
7 | 7 |
|
8 | | -from holoviews.element import RGB, Image, ImageStack, Raster |
| 8 | +from holoviews.element import RGB, Image, ImageStack, Points, Raster |
9 | 9 | from holoviews.plotting.bokeh.raster import ImageStackPlot |
10 | 10 | from holoviews.plotting.bokeh.util import BOKEH_GE_3_4_0 |
11 | 11 |
|
@@ -473,3 +473,36 @@ def setUp(self): |
473 | 473 | self.ysize = 3 |
474 | 474 | self.xsize = 4 |
475 | 475 | super().setUp() |
| 476 | + |
| 477 | + |
| 478 | +class TestSyntheticLegendPlot(TestBokehPlot): |
| 479 | + __test__ = True |
| 480 | + |
| 481 | + def setUp(self): |
| 482 | + try: |
| 483 | + import datashader as ds |
| 484 | + |
| 485 | + from holoviews.operation.datashader import datashade, rasterize |
| 486 | + except Exception as e: |
| 487 | + print(e) |
| 488 | + raise SkipTest('Datashader not available') |
| 489 | + points = Points([(0, 0, 'A'), (1, 1, 'B'), (2, 2, 'C')], vdims=['Label']) |
| 490 | + kwargs = dict(aggregator=ds.by('Label'), dynamic=False, width=10, height=10) |
| 491 | + self.img_stack = rasterize(points, **kwargs).opts(show_legend=True) |
| 492 | + self.rgb = datashade(points, **kwargs).opts(show_legend=True) |
| 493 | + |
| 494 | + def test_image_stack_legend(self): |
| 495 | + plot = bokeh_renderer.get_plot(self.img_stack) |
| 496 | + mapper = plot.handles['synthetic_color_mapper'] |
| 497 | + assert mapper.factors == ['A', 'B', 'C'] |
| 498 | + glyph = plot._legend_plot.handles['glyph'] |
| 499 | + assert glyph.fill_color.field == 'color' |
| 500 | + assert glyph.fill_color.transform is mapper |
| 501 | + |
| 502 | + def test_rgb_legend(self): |
| 503 | + plot = bokeh_renderer.get_plot(self.rgb) |
| 504 | + mapper = plot.handles['synthetic_color_mapper'] |
| 505 | + assert mapper.factors == ['A', 'B', 'C'] |
| 506 | + glyph = plot._legend_plot.handles['glyph'] |
| 507 | + assert glyph.fill_color.field == 'color' |
| 508 | + assert glyph.fill_color.transform is mapper |
0 commit comments