Skip to content

Commit

Permalink
Handle inheriting old paths in Layout path resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 14, 2017
1 parent b2365ac commit 2e024e1
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions holoviews/core/layout.py
Expand Up @@ -331,15 +331,19 @@ def collate(cls, data, kdims=None, key_dimensions=None):

@classmethod
def _get_path(cls, item):
path = (item.group, item.label) if item.label else (item.group,)
sanitizers = [group_sanitizer, label_sanitizer]
capitalize = lambda x: x[0].upper() + x[1:]
if isinstance(item, tuple):
path, item = item
new_path = cls._get_path(item)
path = path[:2] if item.label and path[1] == new_path[1] else path[:1]
else:
path = (item.group, item.label) if item.label else (item.group,)
return tuple(capitalize(fn(p)) for (p, fn) in zip(path, sanitizers))


@classmethod
def new_path(cls, item, paths, counts):
path = cls._get_path(item)
def new_path(cls, path, paths, counts):
while path in paths:
count = counts[path]
counts[path] += 1
Expand All @@ -356,25 +360,28 @@ def _unpack_paths(cls, objs, paths, items, counts):
into the supplied list of items.
"""
if type(objs) is cls:
objs = objs.values()
for v in objs:
if type(v) is cls:
cls._unpack_paths(v, paths, items, counts)
objs = objs.items()
for item in objs:
path, obj = item if isinstance(item, tuple) else (None, item)
if type(obj) is cls:
cls._unpack_paths(obj, paths, items, counts)
continue
new_path = cls.new_path(v, paths, counts)
path = cls._get_path(item)
new_path = cls.new_path(path, paths, counts)
paths.append(new_path)
items.append((new_path, v))
items.append((new_path, obj))


@classmethod
def _initial_paths(cls, vals, paths=None):
def _initial_paths(cls, items, paths=None):
if paths is None:
paths = []
for v in vals:
if type(v) is cls:
cls._initial_paths(v.values(), paths)
for item in items:
path, item = item if isinstance(item, tuple) else (None, item)
if type(item) is cls:
cls._initial_paths(item.items(), paths)
continue
paths.append(cls._get_path(v))
paths.append(cls._get_path(item))
return paths


Expand Down

0 comments on commit 2e024e1

Please sign in to comment.