Skip to content

Commit

Permalink
Implement ref syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 28, 2024
1 parent 04e07fc commit e647bb6
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 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 pname, 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,14 @@ def trigger(cls, streams):
def _on_trigger(self):
"""Called when a stream has been triggered"""

def _sync__params(self, *events):
updates = {}
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 +440,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 +1320,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

0 comments on commit e647bb6

Please sign in to comment.