Skip to content

Commit

Permalink
Further refactoring of Layouth path processing
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 12, 2017
1 parent aa2e2f9 commit 8084606
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions holoviews/core/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,17 @@ def collate(cls, data, kdims=None, key_dimensions=None):


@classmethod
def new_path(cls, path, item, paths, counts):
def _sanitize_path(cls, path):
sanitizers = [group_sanitizer, label_sanitizer]
capitalize = lambda x: x[0].upper() + x[1:]
path = tuple(capitalize(fn(p)) for (p, fn) in zip(path, sanitizers))
return tuple(capitalize(fn(p)) for (p, fn) in zip(path, sanitizers))


@classmethod
def new_path(cls, path, item, paths, counts):
while path in paths:
path = path[:2]
pl = len(path)
count = counts[path[:-1]]
counts[path[:-1]] += 1
count = counts[path]
counts[path] += 1
path = path + (int_to_roman(count),)
if len(path) == 1:
path = path + (int_to_roman(counts.get(path, 1)),)
Expand All @@ -358,6 +360,7 @@ def _unpack_paths(cls, objs, paths, items, counts):
cls._unpack_paths(v, paths, items, counts)
continue
path = (v.group, v.label) if v.label else (v.group,)
path = cls._sanitize_path(path)
new_path = cls.new_path(path, v, paths, counts)
paths.append(new_path)
items.append((new_path, v))
Expand All @@ -367,14 +370,12 @@ def _unpack_paths(cls, objs, paths, items, counts):
def _initial_paths(cls, vals, paths=None):
if paths is None:
paths = []
capitalize = lambda x: x[0].upper() + x[1:]
for v in vals:
if type(v) is cls:
cls._initial_paths(v.values(), paths)
continue
path = (capitalize(group_sanitizer(v.group)),)
if v.label:
path = path + (capitalize(label_sanitizer(v.label)),)
path = (v.group, v.label) if v.label else (v.group,)
path = cls._sanitize_path(path)
paths.append(path)
return paths

Expand Down

0 comments on commit 8084606

Please sign in to comment.