scripts: treemap.py/codemap.py: Use parts of name for char defaults

So by default, instead of just using "." for tiles, we use interesting
parts of the tile's name:

- For treemap.py, we use the first character of the last by-field (so
  "lfs.c,lfsr_file_write,1234" -> "1").

- For codemap.py, we use the first character of the non-subsystem part
  of the function name (so "lfsr_file_write" -> "w").

This nice thing about this, is the resulting treemap is somewhat
understandable even without colors:

  $ ./scripts/codemap.py lfs.o lfs_util.o lfs.ci lfs_util.ci -W60 -H8
  code 35528 stack 2440 ctx 636
  ffffffoooffaaaaaaaaaaaacccccccccttttccccrrrrpgffmmrraifmmcss
  ffffffwwwttaaaaaaaaaaaacccccccccttttccccrprrpcscmmoommrrcepp
  ffffffwwwttaaaaaaaaalllcccccccccttttccccrpppccscmmsrmmrrrrss
  ccccssrrfclaaaaanneeasscccccccccgpppccccrpppsgsummstmmrrlfgf
  ccccssrrfccaaaaanneeaaaccccccsaagpppcccccrrrfrrcccrrfiiilucs
  ccccssrrtfcfffffaapplcccccccclssgnnllllcrrffrrrccccifssscmcm
  ccccssrrtrdfffffaapppapcccfffllsgnnllllcrrrffrrcccorfsssicnu

Ok, so maybe the word "somewhat" is doing a lot of heavy lifting...
This commit is contained in:
Christopher Haster
2025-03-11 03:24:32 -05:00
parent 3d53f5393d
commit 59ffbde3ad
2 changed files with 22 additions and 26 deletions

View File

@@ -20,7 +20,6 @@ import shutil
# we don't actually need that many chars/colors thanks to the
# 4-colorability of all 2d maps
CHARS = ['.']
COLORS = ['34', '31', '32', '35', '33', '36']
CHARS_DOTS = " .':"
@@ -754,7 +753,7 @@ def main(csv_paths, *,
chars_.extend((char[0], c) for c in psplit(char[1]))
else:
chars_.extend(psplit(char))
chars_ = Attr(chars_, defaults=CHARS)
chars_ = Attr(chars_)
colors_ = Attr(colors, defaults=COLORS)
@@ -836,7 +835,8 @@ def main(csv_paths, *,
# and chars/labels for bottom of tree
for i, t in enumerate(tile.leaves()):
t.char = punescape(chars_[i, t.key], t.attrs)[0] # limit to 1 char
if (i, t.key) in chars_:
t.char = punescape(chars_[i, t.key], t.attrs)[0] # limit to 1 char
if (i, t.key) in labels_:
t.label = punescape(labels_[i, t.key], t.attrs)
@@ -970,16 +970,11 @@ def main(csv_paths, *,
y__ = canvas.height - (y__+height__)
canvas.rect(x__, y__, width__, height__,
# default to first letter in each label/key
# default to first letter of the last part of the key
char=(True if braille or dots
else t.label[0]
if chars is None
and t.label is not None
else t.key[-1][0]
if chars is None
and t.key
and t.key[-1]
else t.char if t.char is not None else chars_[0]),
else t.char if getattr(t, 'char', None)
else t.key[len(by)-1][0] if t.key and t.key[len(by)-1]
else chars_[0]),
color=t.color if t.color is not None else colors_[0])
if label: