Skip to content
Draft
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
65 changes: 42 additions & 23 deletions holoviews/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ def define(cls, name, **kwargs):
# Dynamic class creation using type
return type(name, (Stream,), params)

@classmethod
def from_param(cls, **params):
stream = cls(**params)
param_names = list(set(params) & set(cls.param))
stream.param.watch(stream._sync__params, param_names)
for _, ref in stream._param__private.refs.items():
for p in param.parameterized.resolve_ref(ref):
p.owner.param.watch(lambda e: cls.trigger([stream]), p.name)
return stream

@classmethod
def trigger(cls, streams):
Expand Down Expand Up @@ -190,6 +199,13 @@ def trigger(cls, streams):
def _on_trigger(self):
"""Called when a stream has been triggered"""

def _sync__params(self, *events):
for e in events:
if e.name not in self._param__private.refs:
continue
ref = self._param__private.refs[e.name]
if isinstance(ref, param.Parameter):
setattr(ref.owner, ref.name, e.new)

@classmethod
def _process_streams(cls, streams):
Expand Down Expand Up @@ -423,8 +439,9 @@ def _set_stream_parameters(self, **kwargs):
Sets the stream parameters which are expected to be declared
constant.
"""
with util.disable_constant(self):
self.param.update(**kwargs)
with param.parameterized._syncing(self, list(kwargs)):
with util.disable_constant(self):
self.param.update(**kwargs)

def event(self, **kwargs):
"""
Expand Down Expand Up @@ -1302,11 +1319,11 @@ class PointerXY(LinkedStream):
"""

x = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the x-axis in data coordinates""")

y = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the y-axis in data coordinates""")


Expand Down Expand Up @@ -1345,23 +1362,25 @@ class Tap(PointerXY):
The x/y-position of a tap or click in data coordinates.
"""
x = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the x-axis in data coordinates""")

y = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the y-axis in data coordinates""")

def _event(self, *events):
self.trigger([self])

class MultiAxisTap(LinkedStream):
"""
The x/y-positions of a tap or click in data coordinates.
"""

xs = param.Dict(default=None, constant=True, doc="""
xs = param.Dict(default=None, constant=True, allow_refs=True, doc="""
Pointer positions along the x-axes in data coordinates""")

ys = param.Dict(default=None, constant=True, doc="""
ys = param.Dict(default=None, constant=True, allow_refs=True, doc="""
Pointer positions along the y-axes in data coordinates""")


Expand All @@ -1370,34 +1389,34 @@ class DoubleTap(PointerXY):
The x/y-position of a double-tap or -click in data coordinates.
"""
x = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the x-axis in data coordinates""")

y = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the y-axis in data coordinates""")

class PressUp(PointerXY):
"""
The x/y position of a mouse pressup event in data coordinates.
"""
x = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the x-axis in data coordinates""")

y = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the y-axis in data coordinates""")

class PanEnd(PointerXY):
"""The x/y position of a the end of a pan event in data coordinates.
"""
x = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the x-axis in data coordinates""")

y = param.ClassSelector(class_=pointer_types, default=None,
constant=True, doc="""
constant=True, allow_refs=True, doc="""
Pointer position along the y-axis in data coordinates""")

class MouseEnter(PointerXY):
Expand Down Expand Up @@ -1460,10 +1479,10 @@ class RangeXY(LinkedStream):
Axis ranges along x- and y-axis in data coordinates.
"""

x_range = param.Tuple(default=None, length=2, constant=True, doc="""
x_range = param.Tuple(default=None, length=2, constant=True, allow_refs=True, doc="""
Range of the x-axis of a plot in data coordinates""")

y_range = param.Tuple(default=None, length=2, constant=True, doc="""
y_range = param.Tuple(default=None, length=2, constant=True, allow_refs=True, doc="""
Range of the y-axis of a plot in data coordinates""")


Expand All @@ -1472,7 +1491,7 @@ class RangeX(LinkedStream):
Axis range along x-axis in data coordinates.
"""

x_range = param.Tuple(default=None, length=2, constant=True, doc="""
x_range = param.Tuple(default=None, length=2, constant=True, allow_refs=True, doc="""
Range of the x-axis of a plot in data coordinates""")

def _set_stream_parameters(self, **kwargs):
Expand All @@ -1485,7 +1504,7 @@ class RangeY(LinkedStream):
Axis range along y-axis in data coordinates.
"""

y_range = param.Tuple(default=None, length=2, constant=True, doc="""
y_range = param.Tuple(default=None, length=2, constant=True, allow_refs=True, doc="""
Range of the y-axis of a plot in data coordinates""")

def _set_stream_parameters(self, **kwargs):
Expand All @@ -1500,7 +1519,7 @@ class BoundsXY(LinkedStream):
"""

bounds = param.Tuple(default=None, constant=True, length=4,
allow_None=True, doc="""
allow_None=True, allow_refs=True, doc="""
Bounds defined as (left, bottom, right, top) tuple.""")


Expand All @@ -1522,7 +1541,7 @@ class SelectionXY(BoundsXY):
"""

bounds = param.Tuple(default=None, constant=True, length=4,
allow_None=True, doc="""
allow_None=True, allow_refs=True, doc="""
Bounds defined as (left, bottom, right, top) tuple.""")

x_selection = param.ClassSelector(class_=(tuple, list), allow_None=True,
Expand All @@ -1543,7 +1562,7 @@ class BoundsX(LinkedStream):
"""

boundsx = param.Tuple(default=None, constant=True, length=2,
allow_None=True, doc="""
allow_None=True, allow_refs=True, doc="""
Bounds defined as (left, right) tuple.""")


Expand All @@ -1554,7 +1573,7 @@ class BoundsY(LinkedStream):
"""

boundsy = param.Tuple(default=None, constant=True, length=2,
allow_None=True, doc="""
allow_None=True, allow_refs=True, doc="""
Bounds defined as (bottom, top) tuple.""")


Expand All @@ -1563,7 +1582,7 @@ class Selection1D(LinkedStream):
A stream representing a 1D selection of objects by their index.
"""

index = param.List(default=[], allow_None=True, constant=True, doc="""
index = param.List(default=[], allow_None=True, constant=True, allow_refs=True, doc="""
Indices into a 1D datastructure.""")


Expand Down