Skip to content
Snippets Groups Projects
Commit 0ce762b5 authored by Alice Brenon's avatar Alice Brenon
Browse files

Remove trailing punctuation blocks from shortened legends

parent 6ae31c0f
No related branches found
No related tags found
No related merge requests found
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]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment