Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ArrowPlot and added tests #3476

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions holoviews/plotting/bokeh/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def get_data(self, element, ranges, style):
return ({'label': label_data},
{'arrow': arrow_opts, 'label': label_mapping}, style)


def _init_glyph(self, plot, mapping, properties, key):
"""
Returns a Bokeh glyph object.
Expand All @@ -246,14 +247,15 @@ def _init_glyph(self, plot, mapping, properties, key):
arrow_start = mapping.pop('arrow_start')
start = arrow_start(**properties) if arrow_start else None
end = arrow_end(**properties) if arrow_end else None
glyph = Arrow(start=start, end=end, **dict(**mapping))
renderer = Arrow(start=start, end=end, **dict(**mapping))
glyph = renderer
else:
properties = {p if p == 'source' else 'text_'+p: v
for p, v in properties.items()}
glyph, _ = super(ArrowPlot, self)._init_glyph(
renderer, glyph = super(ArrowPlot, self)._init_glyph(
plot, mapping, properties, 'text_1')
plot.renderers.append(glyph)
return None, glyph
plot.renderers.append(renderer)
return renderer, glyph

def get_extents(self, element, ranges=None, range_type='combined'):
return None, None, None, None
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ def _init_glyphs(self, plot, element, ranges, source, data=None, mapping=None, s
with abbreviated_exception():
self._update_glyph(renderer, properties, mapping.get(key, {}), glyph,
source, source.data)
if self.colorbar:
if getattr(self, 'colorbar', False):
for k, v in list(self.handles.items()):
if not k.endswith('color_mapper'):
continue
Expand Down
40 changes: 38 additions & 2 deletions holoviews/tests/plotting/bokeh/testannotationplot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from holoviews.element import HLine, VLine, Text, Labels
from holoviews.element import HLine, VLine, Text, Labels, Arrow

from .testplot import TestBokehPlot, bokeh_renderer

Expand Down Expand Up @@ -55,14 +55,50 @@ def test_text_plot_rotation(self):
plot = bokeh_renderer.get_plot(text)
glyph = plot.handles['glyph']
self.assertEqual(glyph.angle, np.pi/2.)

def test_text_plot_rotation_style(self):
text = Text(0, 0, 'Test').options(angle=90)
plot = bokeh_renderer.get_plot(text)
glyph = plot.handles['glyph']
self.assertEqual(glyph.angle, np.pi/2.)


class TestArrowPlot(TestBokehPlot):

def _compare_arrow_plot(self, plot, start, end):
arrow_glyph = plot.handles['arrow_glyph']
label_glyph = plot.handles['label_glyph']
label_cds = plot.handles['label_source']
x0, y0 = start
x1, y1 = end
self.assertEqual(label_glyph.x, 'x')
self.assertEqual(label_glyph.y, 'y')
self.assertEqual(label_cds.data, {'x': [x0], 'y': [y0], 'text': ['Test']})
self.assertEqual(arrow_glyph.x_start, x0)
self.assertEqual(arrow_glyph.x_end, x1)
self.assertEqual(arrow_glyph.y_start, y0)
self.assertEqual(arrow_glyph.y_end, y1)

def test_arrow_plot_left(self):
arrow = Arrow(0, 0, 'Test')
plot = bokeh_renderer.get_plot(arrow)
self._compare_arrow_plot(plot, (1/6., 0), (0, 0))

def test_arrow_plot_up(self):
arrow = Arrow(0, 0, 'Test', '^')
plot = bokeh_renderer.get_plot(arrow)
self._compare_arrow_plot(plot, (0, -1/6.), (0, 0))

def test_arrow_plot_right(self):
arrow = Arrow(0, 0, 'Test', '>')
plot = bokeh_renderer.get_plot(arrow)
self._compare_arrow_plot(plot, (-1/6., 0), (0, 0))

def test_arrow_plot_down(self):
arrow = Arrow(0, 0, 'Test', 'v')
plot = bokeh_renderer.get_plot(arrow)
self._compare_arrow_plot(plot, (0, 1/6.), (0, 0))


class TestLabelsPlot(TestBokehPlot):

Expand Down