-
-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for dynamic operations and overlaying #588
Changes from 1 commit
15b3474
2a41e03
c449d3d
ed86730
b53a296
0fd852c
0c15545
f3a74c5
0aedb52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,18 @@ | |
from functools import reduce | ||
import param | ||
|
||
try: | ||
from itertools import izip as zip | ||
except: | ||
pass | ||
|
||
from .dimension import ViewableElement | ||
from .element import Element, HoloMap, GridSpace, Collator | ||
from .layout import Layout | ||
from .overlay import NdOverlay, Overlay | ||
from .spaces import DynamicMap | ||
from .traversal import unique_dimkeys | ||
|
||
from . import util | ||
|
||
|
||
class Operation(param.ParameterizedFunction): | ||
|
@@ -74,6 +80,10 @@ class ElementOperation(Operation): | |
ElementOperation may turn overlays in new elements or vice versa. | ||
""" | ||
|
||
dynamic = param.Boolean(default=False, doc=""" | ||
Whether the operation should be applied dynamically | ||
when a specific frame is requested.""") | ||
|
||
input_ranges = param.ClassSelector(default={}, | ||
class_=(dict, tuple), doc=""" | ||
Ranges to be used for input normalization (if applicable) in a | ||
|
@@ -115,19 +125,41 @@ def __call__(self, element, **params): | |
kdims=element.kdims) | ||
# Populate the axis layout | ||
for pos, cell in element.items(): | ||
processed[pos] = self(cell, **params) | ||
if self.p.dynamic and isinstance(cell, HoloMap): | ||
def dynamic_operation(key): | ||
return self(element[pos][key], **params) | ||
processed_cell = self._make_dynamic(cell, dynamic_operation) | ||
else: | ||
processed_cell = self(cell, **params) | ||
processed[pos] = processed_cell | ||
elif isinstance(element, HoloMap): | ||
mapped_items = [(k, self._process(el, key=k)) | ||
for k, el in element.items()] | ||
refval = mapped_items[0][1] | ||
processed = element.clone(mapped_items, | ||
group=refval.group, | ||
label=refval.label) | ||
if self.p.dynamic: | ||
def dynamic_operation(key): | ||
return self(element[key], **params) | ||
processed = self._make_dynamic(element, dynamic_operation) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion: I might consider using the signature This is a very mild preference and if you prefer to leave it as it is, I don't mind either. |
||
else: | ||
mapped_items = [(k, self._process(el, key=k)) | ||
for k, el in element.items()] | ||
refval = mapped_items[0][1] | ||
processed = element.clone(mapped_items, | ||
group=refval.group, | ||
label=refval.label) | ||
else: | ||
raise ValueError("Cannot process type %r" % type(element).__name__) | ||
return processed | ||
|
||
|
||
def _make_dynamic(self, hmap, dynamic_fn): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, how about making this a general utility to turn |
||
""" | ||
Accepts a HoloMap and a dynamic callback function creating | ||
an equivalent DynamicMap from the HoloMap. | ||
""" | ||
dim_values = zip(*hmap.data.keys()) | ||
params = util.get_param_values(hmap) | ||
kdims = [d(values=list(values)) for d, values in zip(hmap.kdims, dim_values)] | ||
return DynamicMap(dynamic_fn, **dict(params, kdims=kdims)) | ||
|
||
|
||
|
||
class MapOperation(param.ParameterizedFunction): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this approach.