Skip to content
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

Implemented slicing semantics for bounded DynamicMaps #488

Merged
merged 2 commits into from Feb 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions holoviews/core/spaces.py
Expand Up @@ -551,6 +551,21 @@ def _cross_product(self, tuple_key, cache):
return self.clone(data)


def _slice_bounded(self, tuple_key):
"""
Slices bounded DynamicMaps by setting the soft_ranges on key dimensions.
"""
cloned = self.clone(self)
for i, slc in enumerate(tuple_key):
(start, stop) = slc.start, slc.stop
if start and start < cloned.kdims[i].range[0]:
raise Exception("Requested slice below defined dimension range.")
if stop and stop > cloned.kdims[i].range[1]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you check start is not None and stop is not None explicitly otherwise it'll fall through for zeros.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Fixed in the last commit.

raise Exception("Requested slice above defined dimension range.")
cloned.kdims[i].soft_range = (start, stop)
return cloned


def __getitem__(self, key):
"""
Return an element for any key chosen key (in'bounded mode') or
Expand All @@ -565,9 +580,14 @@ def __getitem__(self, key):
if key == slice(None, None, None):
return self.clone(self)

if any(isinstance(el, slice) for el in tuple_key):
raise Exception("Slices not supported by DynamicMap in bounded mode "
"except for the global slice [:] to create a clone.")
slices = [el for el in tuple_key if isinstance(el, slice)]
if any(el.step for el in slices):
raise Exception("Slices cannot have a step argument "
"in DynamicMap bounded mode ")
if len(slices) not in [0, len(tuple_key)]:
raise Exception("Slices must be used exclusively or not at all")
if slices:
return self._slice_bounded(tuple_key)

# Cache lookup
try:
Expand Down
3 changes: 2 additions & 1 deletion holoviews/plotting/widgets/__init__.py
Expand Up @@ -279,7 +279,8 @@ def get_widgets(self):
init_dim_vals.append(dim_vals[0])
else:
widget_type = 'slider'
dim_vals = list(dim.range)
dim_vals = [dim.soft_range[0] if dim.soft_range[0] else dim.range[0],
dim.soft_range[1] if dim.soft_range[1] else dim.range[1]]
dim_range = dim_vals[1] - dim_vals[0]
int_type = isinstance(dim.type, type) and issubclass(dim.type, int)
if isinstance(dim_range, int) or int_type:
Expand Down