From 0ce762b580e4628a1f2bb9f762d424637c6bbccb Mon Sep 17 00:00:00 2001 From: Alice BRENON <alice.brenon@ens-lyon.fr> Date: Tue, 28 May 2024 19:43:44 +0200 Subject: [PATCH] Remove trailing punctuation blocks from shortened legends --- GEODE/Visualisation/Legend.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/GEODE/Visualisation/Legend.py b/GEODE/Visualisation/Legend.py index 9403bc2..11b2e91 100644 --- a/GEODE/Visualisation/Legend.py +++ b/GEODE/Visualisation/Legend.py @@ -1,6 +1,3 @@ -from GEODE.Functional import curry - -@curry def take(maxWidth, shards): result = [] budget = maxWidth @@ -14,10 +11,16 @@ def take(maxWidth, shards): i += 1 return tuple(result) +def removeTrailingPunctuation(l): + i = len(l)-1 + while i > 0 and all([not c.isalnum() for c in l[i]]): + i -= 1 + return l[:i+1] + def trim(labels, maxWidth=10): if maxWidth is None: return labels else: shards = [label.split(' ') for label in labels] - prefixes = [*map(take(maxWidth), shards)] + prefixes = [removeTrailingPunctuation(take(maxWidth, s)) for s in shards] return [' '.join(prefix) for prefix in prefixes] -- GitLab