From 80846062e0662d3930bc1daed3c7689637ea689e Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Sun, 12 Feb 2017 03:00:23 +0000
Subject: [PATCH] Further refactoring of Layouth path processing
---
holoviews/core/layout.py | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/holoviews/core/layout.py b/holoviews/core/layout.py
index 983e48920b..825afea87d 100644
--- a/holoviews/core/layout.py
+++ b/holoviews/core/layout.py
@@ -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)),)
@@ -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))
@@ -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