From 2e024e1f2cd64bf0e506724da489188c173a9869 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Mon, 13 Feb 2017 00:23:29 +0000 Subject: [PATCH] Handle inheriting old paths in Layout path resolution --- holoviews/core/layout.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/holoviews/core/layout.py b/holoviews/core/layout.py index 7a3c1a134c..d88efcdc2a 100644 --- a/holoviews/core/layout.py +++ b/holoviews/core/layout.py @@ -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 @@ -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