I hacked together a way to make a small graph using Braille unicode codepoints by abusing unicodedata
:
def plot(timeline):
ret = []
for r1, r2 in zip(timeline[::2], timeline[1::2]):
character_name = "BRAILLE PATTERN DOTS-"
dots = [x for x, y in zip("7321", range(r1))]
dots += [x for x, y in zip("8654", range(r2))]
character_name += "".join(sorted(dots))
ret.append(unicodedata.lookup(character_name) if dots else " ")
return "".join(ret)
>>> print plot([random.randrange(0,4) for _ in range(100)])
⣆⣆⣶⣤⢠⡀⣦⡆⢀⡄⣰⣠⣦⣆⣰⢰⢠⢰⣄⡄ ⣀⣦⡆⣄⣶⣤⣠⡆⣠⣦⣆ ⣰⣴⡄⣤⣀ ⡀⣄⡀⣦⣶⣰⣶⣄⣴
Barring low-hanging incremental improvements such as memoizing the call to unicodedata.lookup
, what would be a more proper way to perform this lookup?