Skip to content

Commit

Permalink
Miscellaneous plot fixes (#2404)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored and jlstevens committed Mar 6, 2018
1 parent 42cf21e commit 2b08fa1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
8 changes: 6 additions & 2 deletions holoviews/plotting/bokeh/annotation.py
Expand Up @@ -35,9 +35,13 @@ def get_data(self, element, ranges, style):
data = dict(x=[element.x], y=[element.y])
self._categorize_data(data, ('x', 'y'), element.dimensions())
data['text'] = [element.text]
style['text_align'] = element.halign
if 'text_align' not in style:
style['text_align'] = element.halign
baseline = 'middle' if element.valign == 'center' else element.valign
style['text_baseline'] = baseline
if 'text_baseline' not in style:
style['text_baseline'] = baseline
if 'text_font_size' not in style:
style['text_font_size'] = '%dPt' % element.fontsize
if 'color' in style:
style['text_color'] = style.pop('color')
return (data, mapping, style)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/util.py
Expand Up @@ -106,7 +106,7 @@ def mpl_to_bokeh(properties):
new_properties['size'] = v
elif k == 'marker':
new_properties.update(markers.get(v, {'marker': v}))
elif k == 'color' or k.endswith('_color') and not isinstance(v, dict):
elif (k == 'color' or k.endswith('_color')) and not isinstance(v, dict):
with abbreviated_exception():
v = colors.ColorConverter.colors.get(v, v)
if isinstance(v, tuple):
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/plot.py
Expand Up @@ -1007,7 +1007,7 @@ def get_extents(self, overlay, ranges):
break
if not found:
layer = None
if layer and subplot.apply_ranges:
if layer is not None and subplot.apply_ranges:
if isinstance(layer, CompositeOverlay):
sp_ranges = ranges
else:
Expand Down
17 changes: 16 additions & 1 deletion tests/plotting/bokeh/testannotationplot.py
@@ -1,4 +1,4 @@
from holoviews.element import HLine, VLine
from holoviews.element import HLine, VLine, Text

from .testplot import TestBokehPlot, bokeh_renderer

Expand Down Expand Up @@ -32,3 +32,18 @@ def test_vline_plot(self):
span = plot.handles['glyph']
self.assertEqual(span.dimension, 'height')
self.assertEqual(span.location, 1.1)


class TestTextPlot(TestBokehPlot):

def test_text_plot(self):
text = Text(0, 0, 'Test')
plot = bokeh_renderer.get_plot(text)
source = plot.handles['source']
self.assertEqual(source.data, {'x': [0], 'y': [0], 'text': ['Test']})

def test_text_plot_fontsize(self):
text = Text(0, 0, 'Test', fontsize=18)
plot = bokeh_renderer.get_plot(text)
glyph = plot.handles['glyph']
self.assertEqual(glyph.text_font_size, '18Pt')
6 changes: 6 additions & 0 deletions tests/plotting/bokeh/testoverlayplot.py
Expand Up @@ -140,3 +140,9 @@ def test_points_errorbars_text_ndoverlay_categorical_xaxis_invert_axes(self):
self.assertIsInstance(x_range, Range1d)
self.assertIsInstance(y_range, FactorRange)
self.assertEqual(y_range.factors, ['A', 'B', 'C', 'D', 'E'])

def test_overlay_empty_element_extent(self):
overlay = Curve([]).redim.range(x=(-10, 10)) * Points([]).redim.range(y=(-20, 20))
plot = bokeh_renderer.get_plot(overlay)
extents = plot.get_extents(overlay, {})
self.assertEqual(extents, (-10, -20, 10, 20))
6 changes: 6 additions & 0 deletions tests/plotting/matplotlib/testoverlayplot.py
Expand Up @@ -24,3 +24,9 @@ def test_overlay_empty_layers(self):
overlay = Curve(range(10)) * NdOverlay()
plot = mpl_renderer.get_plot(overlay)
self.assertEqual(len(plot.subplots), 1)

def test_overlay_empty_element_extent(self):
overlay = Curve([]).redim.range(x=(-10, 10)) * Scatter([]).redim.range(y=(-20, 20))
plot = mpl_renderer.get_plot(overlay)
extents = plot.get_extents(overlay, {})
self.assertEqual(extents, (-10, -20, 10, 20))

0 comments on commit 2b08fa1

Please sign in to comment.