Skip to content

Commit 9edec54

Browse files
committed
Add tests
1 parent 7726efd commit 9edec54

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

holoviews/plotting/util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,8 @@ def _process(self, element, key=None):
13691369
except TypeError:
13701370
# Issue #5619, cudf.core.index.StringIndex is not iterable.
13711371
cats = list(hvds.data.dtypes[column].categories.to_pandas())
1372+
except AttributeError:
1373+
cats = list(unique_iterator(hvds.data[column]))
13721374
if cats == ['__UNKNOWN_CATEGORIES__']:
13731375
cats = list(hvds.data[column].cat.as_known().categories)
13741376
else:
@@ -1379,7 +1381,10 @@ def _process(self, element, key=None):
13791381
else:
13801382
shade_op = element.pipeline.find(shade, skip_nonlinked=False)
13811383
if shade_op is None:
1382-
colors = process_cmap(self.p.cmap, ncolors=len(cats), categorical=True)
1384+
if self.p.cmap is None:
1385+
colors = ds.colors.Sets1to3
1386+
else:
1387+
colors = process_cmap(self.p.cmap, ncolors=len(cats), categorical=True)
13831388
else:
13841389
colors = shade_op.color_key or ds.colors.Sets1to3
13851390
color_data = [(0, 0, cat) for cat in cats]

holoviews/tests/plotting/bokeh/test_rasterplot.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from bokeh.models import CustomJSHover, HoverTool
77

8-
from holoviews.element import RGB, Image, ImageStack, Raster
8+
from holoviews.element import RGB, Image, ImageStack, Points, Raster
99
from holoviews.plotting.bokeh.raster import ImageStackPlot
1010
from holoviews.plotting.bokeh.util import BOKEH_GE_3_4_0
1111

@@ -473,3 +473,36 @@ def setUp(self):
473473
self.ysize = 3
474474
self.xsize = 4
475475
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

Comments
 (0)