-
-
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
Widgets ignore dimension streams #860
Changes from 4 commits
47ccfe1
11fda8b
75e63cc
14e609b
51bb81d
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 |
---|---|---|
|
@@ -803,15 +803,23 @@ def dimensionless_contents(streams, kdims): | |
with any of the key dimensions. | ||
""" | ||
names = stream_parameters(streams) | ||
kdim_names = [kdim.name for kdim in kdims] | ||
return [name for name in names if name not in kdim_names] | ||
return [name for name in names if name not in kdims] | ||
|
||
|
||
def streamless_dimensions(streams, kdims): | ||
""" | ||
Return a list of dimensions that have not been associated with | ||
any streams. | ||
""" | ||
params = stream_parameters(streams) | ||
return [d for d in kdims if d not in params] | ||
|
||
|
||
def wrap_tuple_streams(unwrapped, kdims, streams): | ||
""" | ||
Fills in tuple keys with dimensioned stream values as appropriate. | ||
""" | ||
param_groups = [(s.params().keys(), s) for s in streams] | ||
param_groups = [(s.contents.keys(), s) for s in streams] | ||
pairs = [(name,s) for (group, s) in param_groups for name in group] | ||
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. Thanks! Made the same mistake twice! |
||
substituted = [] | ||
for pos,el in enumerate(wrap_tuple(unwrapped)): | ||
|
@@ -824,6 +832,16 @@ def wrap_tuple_streams(unwrapped, kdims, streams): | |
return tuple(substituted) | ||
|
||
|
||
def drop_streams(streams, keys, kdims): | ||
""" | ||
Drop any dimensionsed streams from the keys and kdims. | ||
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. Typo in 'dimensioned' and maybe add a line saying what it returns. 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. I still think it is a little odd to put the keys (typically a very long list) before the kdims (much shorter). The order that feels (slightly) more natural to me for the signature is Just a minor point that you may ignore if you wish! |
||
""" | ||
stream_params = stream_parameters(streams) | ||
inds, dims = zip(*[(ind, kdim) for ind, kdim in enumerate(kdims) | ||
if kdim not in stream_params]) | ||
return dims, [tuple(key[ind] for ind in inds) for key in keys] | ||
|
||
|
||
def itervalues(obj): | ||
"Get value iterator from dictionary for Python 2 and 3" | ||
return iter(obj.values()) if sys.version_info.major == 3 else obj.itervalues() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -484,10 +484,9 @@ def refresh(self, **kwargs): | |
the updated data if the plot has an associated Comm. | ||
""" | ||
traverse_setter(self, '_force', True) | ||
if self.current_key: | ||
self.update(self.current_key) | ||
else: | ||
self.update(0) | ||
key = self.current_key if self.current_key else self.keys[0] | ||
stream_key = util.wrap_tuple_streams(key, self.dimensions, self.streams) | ||
self.update(stream_key) | ||
if self.comm is not None: | ||
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. It is a relief to see how simple this bit turned out to be. |
||
self.push() | ||
|
||
|
@@ -573,6 +572,7 @@ def __init__(self, element, keys=None, ranges=None, dimensions=None, | |
**dict(params, **plot_opts)) | ||
if top_level: | ||
self.comm = self.init_comm(element) | ||
self.streams = self.hmap.streams if isinstance(self.hmap, DynamicMap) else [] | ||
|
||
# Update plot and style options for batched plots | ||
if self.batched: | ||
|
@@ -920,6 +920,9 @@ def __init__(self, layout, keys=None, dimensions=None, **params): | |
**params) | ||
if top_level: | ||
self.comm = self.init_comm(layout) | ||
self.streams = [s for streams in layout.traverse(lambda x: x.streams, | ||
[DynamicMap]) | ||
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. The wrapping is a bit weird. I would put |
||
for s in streams] | ||
|
||
|
||
def _get_frame(self, key): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
from ...core import OrderedDict, NdMapping | ||
from ...core.options import Store | ||
from ...core.util import (dimension_sanitizer, safe_unicode, | ||
unique_array, unicode, isnumeric) | ||
unique_array, unicode, isnumeric, | ||
wrap_tuple_streams, drop_streams) | ||
from ...core.traversal import hierarchical | ||
|
||
def escape_vals(vals, escape_numerics=True): | ||
|
@@ -106,9 +107,8 @@ def __init__(self, plot, renderer=None, **params): | |
super(NdWidget, self).__init__(**params) | ||
self.id = plot.comm.target if plot.comm else uuid.uuid4().hex | ||
self.plot = plot | ||
self.dimensions = plot.dimensions | ||
self.keys = plot.keys | ||
|
||
dims, keys = drop_streams(plot.streams, plot.keys, plot.dimensions) | ||
self.dimensions, self.keys = dims, keys | ||
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. As the variables self.dimensions, self.keys = drop_streams(plot.streams,
plot.keys,
plot.dimensions) |
||
self.json_data = {} | ||
if self.plot.dynamic: self.embed = False | ||
if renderer is None: | ||
|
@@ -194,7 +194,9 @@ def _plot_figure(self, idx): | |
|
||
|
||
def update(self, key): | ||
return self._plot_figure(key) | ||
self.plot.update(key) | ||
self.plot.push() | ||
return 'Complete' | ||
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.
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. Currently part of the protocol, which will change as soon as we use comms for everything. |
||
|
||
|
||
|
||
|
@@ -370,4 +372,10 @@ def update(self, key): | |
if self.plot.dynamic: | ||
key = tuple(dim.values[k] if dim.values else k | ||
for dim, k in zip(self.mock_obj.kdims, tuple(key))) | ||
return self._plot_figure(key) | ||
key = [key[self.dimensions.index(kdim)] if kdim in self.dimensions else None | ||
for kdim in self.plot.dimensions] | ||
key = wrap_tuple_streams(tuple(key), self.plot.dimensions, | ||
self.plot.streams) | ||
self.plot.update(key) | ||
self.plot.push() | ||
return 'Complete' |
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 feel we need a better word for
streamless_dimensions
. These used to be simply 'key dimensions' before streams came along!In other words, I would like a way to define these things in terms of what they are instead of what they are not. I can't say I have any great suggestions right now 'widget_dimensions', 'requested_dimensions', 'unbound_dimensions'? Got any ideas?