scripts: Fixed codemap[d3].py ignoring tiling flags

Not sure how this was missed. Fortunately it's just a small tweak to
make the internal partition function accept tiling args, matching
treemap[d3].py.
This commit is contained in:
Christopher Haster
2025-03-11 15:48:38 -05:00
parent 313696ecf9
commit f033a55cc5
2 changed files with 30 additions and 29 deletions
+13 -12
View File
@@ -17,6 +17,7 @@ import itertools as it
import json import json
import math as mt import math as mt
import re import re
import shlex
import shutil import shutil
import subprocess as sp import subprocess as sp
@@ -1002,7 +1003,7 @@ def main(paths, *,
/ yscale) / yscale)
# our general purpose partition function # our general purpose partition function
def partition(tile, scheme): def partition(tile, **args):
if tile.depth == 0: if tile.depth == 0:
# apply top padding # apply top padding
tile.x += padding tile.x += padding
@@ -1032,23 +1033,23 @@ def main(paths, *,
# partition via requested scheme # partition via requested scheme
if tile.children: if tile.children:
if scheme == 'binary': if args.get('binary'):
partition_binary(tile.children, tile.value, partition_binary(tile.children, tile.value,
x__, y__, width__, height__) x__, y__, width__, height__)
elif (scheme == 'slice' elif (args.get('slice')
or (scheme == 'slice_and_dice' and (tile.depth & 1) == 0) or (args.get('slice_and_dice') and (tile.depth & 1) == 0)
or (scheme == 'dice_and_slice' and (tile.depth & 1) == 1)): or (args.get('dice_and_slice') and (tile.depth & 1) == 1)):
partition_slice(tile.children, tile.value, partition_slice(tile.children, tile.value,
x__, y__, width__, height__) x__, y__, width__, height__)
elif (scheme == 'dice' elif (args.get('dice')
or (scheme == 'slice_and_dice' and (tile.depth & 1) == 1) or (args.get('slice_and_dice') and (tile.depth & 1) == 1)
or (scheme == 'dice_and_slice' and (tile.depth & 1) == 0)): or (args.get('dice_and_slice') and (tile.depth & 1) == 0)):
partition_dice(tile.children, tile.value, partition_dice(tile.children, tile.value,
x__, y__, width__, height__) x__, y__, width__, height__)
elif scheme == 'squarify': elif args.get('squarify'):
partition_squarify(tile.children, tile.value, partition_squarify(tile.children, tile.value,
x__, y__, width__, height__) x__, y__, width__, height__)
elif scheme == 'rectify': elif args.get('rectify'):
partition_squarify(tile.children, tile.value, partition_squarify(tile.children, tile.value,
x__, y__, width__, height__, x__, y__, width__, height__,
aspect_ratio=(width_, height_)) aspect_ratio=(width_, height_))
@@ -1059,7 +1060,7 @@ def main(paths, *,
# recursively partition # recursively partition
for t in tile.children: for t in tile.children:
partition(t, scheme) partition(t, **args)
# create a canvas # create a canvas
canvas = Canvas( canvas = Canvas(
@@ -1075,7 +1076,7 @@ def main(paths, *,
code.y = 0 code.y = 0
code.width = canvas.width code.width = canvas.width
code.height = canvas.height code.height = canvas.height
partition(code, 'binary') partition(code, **args)
# align to pixel boundaries # align to pixel boundaries
code.align() code.align()
+17 -17
View File
@@ -867,9 +867,9 @@ def main(paths, output, *,
ctxs = co.OrderedDict() ctxs = co.OrderedDict()
for k, f in functions.items(): for k, f in functions.items():
if f.get('args'): if f.get('args'):
args = f['args'] args_ = f['args']
else: else:
args = [{ args_ = [{
'name': k, 'name': k,
'subsystem': f['subsystem'], 'subsystem': f['subsystem'],
'ctx': f.get('ctx', 0), 'ctx': f.get('ctx', 0),
@@ -879,7 +879,7 @@ def main(paths, output, *,
Tile( (a['name'],), Tile( (a['name'],),
a.get('ctx', 0), a.get('ctx', 0),
attrs=a) attrs=a)
for a in args) for a in args_)
# assign colors/labels to ctx tiles # assign colors/labels to ctx tiles
for i, t in enumerate(ctxs[k].leaves()): for i, t in enumerate(ctxs[k].leaves()):
@@ -932,7 +932,7 @@ def main(paths, output, *,
height_ = mt.ceil((total_value * to_scale) / width_) height_ = mt.ceil((total_value * to_scale) / width_)
# our general purpose partition function # our general purpose partition function
def partition(tile, scheme): def partition(tile, **args):
if tile.depth == 0: if tile.depth == 0:
# apply top padding # apply top padding
tile.x += padding tile.x += padding
@@ -962,23 +962,23 @@ def main(paths, output, *,
# partition via requested scheme # partition via requested scheme
if tile.children: if tile.children:
if scheme == 'binary': if args.get('binary'):
partition_binary(tile.children, tile.value, partition_binary(tile.children, tile.value,
x__, y__, width__, height__) x__, y__, width__, height__)
elif (scheme == 'slice' elif (args.get('slice')
or (scheme == 'slice_and_dice' and (tile.depth & 1) == 0) or (args.get('slice_and_dice') and (tile.depth & 1) == 0)
or (scheme == 'dice_and_slice' and (tile.depth & 1) == 1)): or (args.get('dice_and_slice') and (tile.depth & 1) == 1)):
partition_slice(tile.children, tile.value, partition_slice(tile.children, tile.value,
x__, y__, width__, height__) x__, y__, width__, height__)
elif (scheme == 'dice' elif (args.get('dice')
or (scheme == 'slice_and_dice' and (tile.depth & 1) == 1) or (args.get('slice_and_dice') and (tile.depth & 1) == 1)
or (scheme == 'dice_and_slice' and (tile.depth & 1) == 0)): or (args.get('dice_and_slice') and (tile.depth & 1) == 0)):
partition_dice(tile.children, tile.value, partition_dice(tile.children, tile.value,
x__, y__, width__, height__) x__, y__, width__, height__)
elif scheme == 'squarify': elif args.get('squarify'):
partition_squarify(tile.children, tile.value, partition_squarify(tile.children, tile.value,
x__, y__, width__, height__) x__, y__, width__, height__)
elif scheme == 'rectify': elif args.get('rectify'):
partition_squarify(tile.children, tile.value, partition_squarify(tile.children, tile.value,
x__, y__, width__, height__, x__, y__, width__, height__,
aspect_ratio=(width_, height_)) aspect_ratio=(width_, height_))
@@ -989,7 +989,7 @@ def main(paths, output, *,
# recursively partition # recursively partition
for t in tile.children: for t in tile.children:
partition(t, scheme) partition(t, **args)
# create space for header # create space for header
x__ = 0 x__ = 0
@@ -1012,7 +1012,7 @@ def main(paths, output, *,
code.y = y__ code.y = y__
code.width = code_split code.width = code_split
code.height = height__ code.height = height__
partition(code, 'binary') partition(code, **args)
# align to pixel boundaries # align to pixel boundaries
code.align() code.align()
@@ -1044,7 +1044,7 @@ def main(paths, output, *,
ctx.y = y__ ctx.y = y__
ctx.width = width__ - ctx.x ctx.width = width__ - ctx.x
ctx.height = ctx_split ctx.height = ctx_split
partition(ctx, 'slice') partition(ctx, slice=True)
# align to pixel boundaries # align to pixel boundaries
ctx.align() ctx.align()
@@ -1055,7 +1055,7 @@ def main(paths, output, *,
stack.y = ctx.y + ctx.height + 2 if ctx_split > 0 else y__ stack.y = ctx.y + ctx.height + 2 if ctx_split > 0 else y__
stack.width = width__ - stack.x stack.width = width__ - stack.x
stack.height = height___ - (stack.y - y__) stack.height = height___ - (stack.y - y__)
partition(stack, 'dice') partition(stack, dice=True)
# align to pixel boundaries # align to pixel boundaries
stack.align() stack.align()