Skip to content

Commit

Permalink
Cleanup and renaming for linked_inputs support
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 17, 2017
1 parent f88b8f4 commit 048642f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 27 deletions.
8 changes: 6 additions & 2 deletions holoviews/core/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ class ElementOperation(Operation):
component is Normalization.keys. """)

link_inputs = param.Boolean(default=False, doc="""
Whether a plot created from the output of this operation
should be linked to the inputs of this operation.""")
If the operation is dynamic, whether or not linked streams
should be transferred from the operation inputs for backends
that support linked streams. For example if an operation is
applied to a DynamicMap with an RangeXY determines if the
output of the operation will update the stream on the input
with current axis ranges.""")

streams = param.List(default=[], doc="""
List of streams that are applied if dynamic=True, allowing
Expand Down
4 changes: 2 additions & 2 deletions holoviews/core/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def dynamic_mul(*args, **kwargs):
element = other[args]
return self * element
callback = Callable(dynamic_mul, inputs=[self, other])
callback._overlay = True
callback._is_overlay = True
return other.clone(shared_data=False, callback=callback,
streams=[])
if isinstance(other, UniformNdMapping) and not isinstance(other, CompositeOverlay):
Expand Down Expand Up @@ -142,7 +142,7 @@ def dynamic_mul(*args, **kwargs):
element = other[args]
return self * element
callback = Callable(dynamic_mul, inputs=[self, other])
callback._overlay = True
callback._is_overlay = True
return other.clone(shared_data=False, callback=callback,
streams=[])
elif not isinstance(other, ViewableElement):
Expand Down
23 changes: 15 additions & 8 deletions holoviews/core/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def dynamic_mul(*key, **kwargs):
pass
return Overlay(layers)
callback = Callable(dynamic_mul, inputs=[self, other])
callback._overlay = True
callback._is_overlay = True
if map_obj:
return map_obj.clone(callback=callback, shared_data=False,
kdims=dimensions, streams=[])
Expand Down Expand Up @@ -213,7 +213,7 @@ def dynamic_mul(*args, **kwargs):
element = self[args]
return element * other
callback = Callable(dynamic_mul, inputs=[self, other])
callback._overlay = True
callback._is_overlay = True
return self.clone(shared_data=False, callback=callback,
streams=[])
items = [(k, v * other) for (k, v) in self.data.items()]
Expand Down Expand Up @@ -421,9 +421,10 @@ class Callable(param.Parameterized):
callback. This is required for building interactive, linked
visualizations (for the backends that support them) when returning
Layouts, NdLayouts or GridSpace objects. When chaining multiple
DynamicMaps into a pipeline the link_inputs parameter declares
whether a plot created from the Callable owner is linked to objects
referenced in the inputs.
DynamicMaps into a pipeline, the link_inputs parameter declares
whether the visualization generated from this Callable will
inherit the linked streams. This parameter is used as a hint by
the applicable backend.
The mapping should map from an appropriate key to a list of
streams associated with the selected object. The appropriate key
Expand All @@ -440,8 +441,14 @@ class Callable(param.Parameterized):
to allow deep access to streams in chained Callables.""")

link_inputs = param.Boolean(default=True, doc="""
Whether a plot created from this Callable should be linked
to the declared inputs.""")
If the Callable wraps around other DynamicMaps in its inputs,
determines if linked streams attached to the inputs areb
transferred to the objects returned by the Callable.
For example if the Callable wraps a DynamicMap with an
RangeXY stream determines if the output of the Callable will
update the stream on the input with current axis ranges for
backends that support linked streams.""")

memoize = param.Boolean(default=True, doc="""
Whether the return value of the callable should be memoized
Expand All @@ -455,7 +462,7 @@ class Callable(param.Parameterized):
def __init__(self, callable, **params):
super(Callable, self).__init__(callable=callable, **params)
self._memoized = {}
self._overlay = False
self._is_overlay = False


@property
Expand Down
10 changes: 6 additions & 4 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ class shade(ElementOperation):
arguments.""")

link_inputs = param.Boolean(default=True, doc="""
Whether a plot created from the output of this operation
should be linked to the inputs of this operation.""")
By default, the link_inputs parameter is set to True so that
when applying shade, backends that support linked streams
update RangeXY streams on the inputs of the shade operation.""")

@classmethod
def concatenate(cls, overlay):
Expand Down Expand Up @@ -400,8 +401,9 @@ class dynspread(ElementOperation):
allowed.""")

link_inputs = param.Boolean(default=True, doc="""
Whether a plot created from the output of this operation
should be linked to the inputs of this operation.""")
By default, the link_inputs parameter is set to True so that
when applying dynspread, backends that support linked streams
update RangeXY streams on the inputs of the dynspread operation.""")

@classmethod
def uint8_to_uint32(cls, img):
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ..element import Table
from .util import (get_dynamic_mode, initialize_sampled, dim_axis_label,
attach_streams, traverse_setter, get_nested_streams,
linked_zorders)
compute_overlayable_zorders)


class Plot(param.Parameterized):
Expand Down Expand Up @@ -571,7 +571,7 @@ def __init__(self, element, keys=None, ranges=None, dimensions=None,
if overlaid:
self.stream_sources = stream_sources
else:
self.stream_sources = linked_zorders(self.hmap)
self.stream_sources = compute_overlayable_zorders(self.hmap)

plot_element = self.hmap.last
if self.batched and not isinstance(self, GenericOverlayPlot):
Expand Down
12 changes: 7 additions & 5 deletions holoviews/plotting/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ def isoverlay_fn(obj):
return isinstance(obj, DynamicMap) and (isinstance(obj.last, CompositeOverlay))


def linked_zorders(obj, path=[]):
def compute_overlayable_zorders(obj, path=[]):
"""
Traverses the Callables on DynamicMap to determine which objects
in the graph are associated with specific (Nd)Overlay layers.
Returns a mapping between the zorders of each layer and lists of
objects associated with each. This is required to determine which
subplots should be linked with Stream callbacks.
objects associated with each.
Used to determine which subplots should be linked with Stream
callbacks.
"""
path = path+[obj]
zorder_map = defaultdict(list)
Expand All @@ -102,7 +104,7 @@ def linked_zorders(obj, path=[]):
return zorder_map

isoverlay = isinstance(obj.last, CompositeOverlay)
isdynoverlay = obj.callback._overlay
isdynoverlay = obj.callback._is_overlay
found = any(isinstance(p, DynamicMap) and p.callback._overlay for p in path)
if obj not in zorder_map[0] and not isoverlay:
zorder_map[0].append(obj)
Expand All @@ -117,7 +119,7 @@ def linked_zorders(obj, path=[]):

# Recurse into DynamicMap.callback.inputs and update zorder_map
i = i if isdynoverlay else 0
dinputs = linked_zorders(inp, path=path)
dinputs = compute_overlayable_zorders(inp, path=path)
offset = max(zorder_map.keys())
for k, v in dinputs.items():
zorder_map[offset+k+i] = list(unique_iterator(zorder_map[offset+k+i]+v))
Expand Down
13 changes: 9 additions & 4 deletions holoviews/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ class Dynamic(param.ParameterizedFunction):
Keyword arguments passed to the function.""")

link_inputs = param.Boolean(default=True, doc="""
Whether a plot created from the output of this utility should
be linked to the inputs passed to this utility.""")
If Dynamic is applied to another DynamicMap, determines if
linked streams attached to its Callable inputs are
transferred to the output of the utility.
For example if the Dynamic utility is applied to a DynamicMap
with an RangeXY stream determines if the output of the
utility will update the stream on the input with current axis
ranges for backends that support linked streams.""")

shared_data = param.Boolean(default=False, doc="""
Whether the cloned DynamicMap will share the same cache.""")
Expand Down Expand Up @@ -85,8 +91,7 @@ def dynamic_operation(*key, **kwargs):
def dynamic_operation(*key, **kwargs):
self.p.kwargs.update(kwargs)
safe_key = () if not map_obj.kdims else key
el = map_obj[key]
return self._process(el, key)
return self._process(map_obj[key], key)
if isinstance(self.p.operation, ElementOperation):
return OperationCallable(dynamic_operation, inputs=[map_obj],
link_inputs=self.p.link_inputs,
Expand Down

0 comments on commit 048642f

Please sign in to comment.