From 2f824c1de0499aca277b76225a3295f4feb841c0 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Tue, 23 Jun 2015 21:35:23 +0100 Subject: [PATCH] Further improved OptionTree repr --- holoviews/core/options.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/holoviews/core/options.py b/holoviews/core/options.py index 1ed50a3617..ee2517db93 100644 --- a/holoviews/core/options.py +++ b/holoviews/core/options.py @@ -501,24 +501,28 @@ def __repr__(self): esep, gspecs = (",\n"+(tab*2)), [] for group in groups.keys(): - especs = [] + especs, accumulator = [], [] if groups[group].kwargs != {}: - especs.append(('.', groups[group].kwargs)) + accumulator.append(('.', groups[group].kwargs)) for t, v in sorted(self.items()): kwargs = v.groups[group].kwargs - if group=='norm' and (kwargs == dict(axiswise=False,framewise=False)): + accumulator.append(('.'.join(t), kwargs)) + + for (t, kws) in accumulator: + if group=='norm' and all(kws[k] is False for k in ['axiswise','framewise']): continue - if kwargs: - especs.append(('.'.join(t), kwargs)) + elif kws: + especs.append((t, kws)) if especs: format_kws = [(t,'dict(%s)' % ', '.join('%s=%r' % (k,v) for k,v in sorted(kws.items()))) for t,kws in especs] ljust = max(len(t) for t,_ in format_kws) - entries = (tab*2) + esep.join([(tab*2)+'%r : %s' % (t.ljust(ljust),v) for t,v in format_kws]) - gspecs.append('%s%s={\n%s}' % (tab,group, entries)) + sep = (tab*2) if len(format_kws) >1 else '' + entries = sep + esep.join([sep+'%r : %s' % (t.ljust(ljust),v) for t,v in format_kws]) + gspecs.append(('%s%s={\n%s}' if len(format_kws)>1 else '%s%s={%s}') % (tab,group, entries)) return 'OptionTree(groups=%s,\n%s\n)' % (groups.keys(), gsep.join(gspecs))