Skip to content

Commit

Permalink
Switched to BoxAnnotation type for bokeh HLine and VLine
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 16, 2015
1 parent be820f7 commit 0659263
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
5 changes: 5 additions & 0 deletions holoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,8 @@
options.Raster = Options('style', cmap='hot')
options.QuadMesh = Options('style', cmap='hot')
options.HeatMap = Options('style', cmap='RdYlBu_r', line_alpha=0)

# Annotations
options.HLine = Options('style', line_color='black', line_width=3, line_alpha=1)
options.VLine = Options('style', line_color='black', line_width=3, line_alpha=1)

34 changes: 20 additions & 14 deletions holoviews/plotting/bokeh/annotation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from bokeh.models import BoxAnnotation

from ...element import HLine, VLine
from .element import ElementPlot, text_properties, line_properties
Expand All @@ -23,24 +24,29 @@ def get_extents(self, element, ranges=None):
class LineAnnotationPlot(ElementPlot):

style_opts = line_properties
_plot_method = 'segment'

def get_data(self, element, ranges=None, empty=False):
plot = self.handles['plot']
if empty:
x0, y0, x1, y1 = [], [], [], []
elif isinstance(element, HLine):
x0 = [plot.x_range.start]
y0 = [element.data]
x1 = [plot.x_range.end]
y1 = [element.data]
data, mapping = {}, {}
if isinstance(element, HLine):
mapping['bottom'] = element.data
mapping['top'] = element.data
elif isinstance(element, VLine):
x0 = [element.data]
y0 = [plot.y_range.start]
x1 = [element.data]
y1 = [plot.y_range.end]
return (dict(x0=x0, y0=y0, x1=x1, y1=y1),
dict(x0='x0', y0='y0', x1='x1', y1='y1'))
mapping['left'] = element.data
mapping['right'] = element.data
return (data, mapping)


def _init_glyph(self, plot, mapping, properties):
"""
Returns a Bokeh glyph object.
"""
properties.pop('source')
properties.pop('legend')
box = BoxAnnotation(plot=plot, level='overlay',
**dict(mapping, **properties))
plot.renderers.append(box)
return box


def get_extents(self, element, ranges=None):
Expand Down

0 comments on commit 0659263

Please sign in to comment.