Skip to content

Commit

Permalink
Added the Draw linked stream class
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed May 15, 2017
1 parent 5637120 commit 4357700
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 19 additions & 1 deletion holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ...core import OrderedDict
from ...streams import (Stream, PointerXY, RangeXY, Selection1D, RangeX,
RangeY, PointerX, PointerY, Bounds, Tap, SingleTap,
DoubleTap, MouseEnter, MouseLeave, PlotSize)
DoubleTap, MouseEnter, MouseLeave, PlotSize, Draw)
from ...streams import PositionX, PositionY, PositionXY # Deprecated: remove in 2.0
from ..comms import JupyterCommJS
from .util import bokeh_version
Expand Down Expand Up @@ -538,6 +538,23 @@ class PointerYCallback(PointerXYCallback):
attributes = {'y': 'cb_obj.y'}


class DrawCallback(PointerXYCallback):
on_events = ['pan', 'panstart', 'panend']
models = ['plot', 'pan', 'box_zoom']
skip = ['pan.attributes.active', 'box_zoom.attributes.active']
attributes = {'x': 'cb_obj.x', 'y': 'cb_obj.y', 'event': 'cb_obj.event_name'}

def __init__(self, *args, **kwargs):
self.stroke_count = 0
super(DrawCallback, self).__init__(*args, **kwargs)

def _process_msg(self, msg):
event = msg.pop('event')
if event == 'panend':
self.stroke_count += 1
return dict(msg, stroke_count=self.stroke_count)


class TapCallback(PointerXYCallback):
"""
Returns the mouse x/y-position on tap event.
Expand Down Expand Up @@ -705,6 +722,7 @@ def _process_msg(self, msg):
callbacks[Bounds] = BoundsCallback
callbacks[Selection1D] = Selection1DCallback
callbacks[PlotSize] = PlotSizeCallback
callbacks[Draw] = DrawCallback

# Aliases for deprecated streams
callbacks[PositionXY] = PointerXYCallback
Expand Down
10 changes: 10 additions & 0 deletions holoviews/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ class PointerXY(LinkedStream):
Pointer position along the y-axis in data coordinates""")


class Draw(PointerXY):
"""
A series of updating x/y-positions when drawing, together with the
current stroke count
"""

stroke_count = param.Integer(default=0, constant=True, doc="""
The current drawing stroke count. Increments every time a new
stroke is started.""")

class SingleTap(PointerXY):
"""
The x/y-position of a single tap or click in data coordinates.
Expand Down

0 comments on commit 4357700

Please sign in to comment.