From fb03e27baf8c4a4f16befb1589e8b3bb3ee582ad Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 7 Mar 2025 02:10:26 -0600 Subject: [PATCH] scripts: Added --no-stats to treemap.py/treemapd3.py The previous behavior of -N/--no-header still rendering a header when --title is also provided was confusing. I think this is a better API, at the minor cost of needing to pass one more flag if you don't want stats in the header. --- scripts/treemap.py | 48 +++++++++++++++++++++++++++----------------- scripts/treemapd3.py | 15 +++++++++----- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/scripts/treemap.py b/scripts/treemap.py index 4de63c4a..dc316fad 100755 --- a/scripts/treemap.py +++ b/scripts/treemap.py @@ -712,6 +712,7 @@ def main(csv_paths, *, width=None, height=None, no_header=False, + no_stats=False, to_scale=None, aspect_ratio=(1,1), title=None, @@ -748,7 +749,10 @@ def main(csv_paths, *, width_ = shutil.get_terminal_size((80, 5))[0] if height is None: - height_ = 2 if title is not None or not no_header else 1 + height_ = (2 + if not no_header + and (title is not None or not no_stats) + else 1) elif height: height_ = height else: @@ -849,7 +853,10 @@ def main(csv_paths, *, # create a canvas canvas = Canvas( width_, - height_ - (1 if title or not no_header else 0), + height_ - (1 + if not no_header + and (title is not None or not no_stats) + else 0), color=color, dots=dots, braille=braille) @@ -967,23 +974,24 @@ def main(csv_paths, *, canvas.label(*label__) # print some summary info - if title: - title_ = punescape(title, tile.attrs) if not no_header: - stat = tile.stat() - stat_ = 'total %d, avg %d +-%dσ, min %d, max %d' % ( - stat['total'], - stat['mean'], stat['stddev'], - stat['min'], stat['max']) - if title and not no_header: - print('%s%*s%s' % ( - title_, - max(width_-len(stat_)-len(title_), 0), ' ', - stat_)) - elif title: - print(title_) - elif not no_header: - print(stat_) + if title: + title_ = punescape(title, tile.attrs) + if not no_stats: + stat = tile.stat() + stat_ = 'total %d, avg %d +-%dσ, min %d, max %d' % ( + stat['total'], + stat['mean'], stat['stddev'], + stat['min'], stat['max']) + if title and not no_stats: + print('%s%*s%s' % ( + title_, + max(width_-len(stat_)-len(title_), 0), ' ', + stat_)) + elif title: + print(title_) + elif not no_stats: + print(stat_) # draw canvas for row in range(canvas.height//canvas.yscale): @@ -1088,6 +1096,10 @@ if __name__ == "__main__": '-N', '--no-header', action='store_true', help="Don't show the header.") + parser.add_argument( + '--no-stats', + action='store_true', + help="Don't show data stats in the header.") parser.add_argument( '--binary', action='store_true', diff --git a/scripts/treemapd3.py b/scripts/treemapd3.py index 73e3c946..441457ef 100755 --- a/scripts/treemapd3.py +++ b/scripts/treemapd3.py @@ -561,6 +561,7 @@ def main(csv_paths, output, *, width=None, height=None, no_header=False, + no_stats=False, to_scale=None, aspect_ratio=(1,1), title=None, @@ -703,7 +704,7 @@ def main(csv_paths, output, *, height__ = tile.height # create space for header - if title is not None or not no_header: + if not no_header and (title is not None or not no_stats): y__ += mt.ceil(FONT_SIZE * 1.3) height__ -= min(mt.ceil(FONT_SIZE * 1.3), height__) @@ -789,16 +790,16 @@ def main(csv_paths, output, *, background=background_)) # create header - if title is not None or not no_header: + if not no_header and (title is not None or not no_stats): f.write('' % dict( color='#ffffff' if dark else '#000000')) - if not no_header: + if not no_stats: stat = tile.stat() if title: f.write('') f.write(punescape(title, tile.attrs)) f.write('') - if not no_header: + if not no_stats: f.write('' % dict( x=tile.width-3)) @@ -807,7 +808,7 @@ def main(csv_paths, output, *, stat['mean'], stat['stddev'], stat['min'], stat['max'])) f.write('') - else: + elif not no_stats: f.write('') f.write('total %d, avg %d +-%dσ, min %d, max %d' % ( stat['total'], @@ -955,6 +956,10 @@ if __name__ == "__main__": '-N', '--no-header', action='store_true', help="Don't show the header.") + parser.add_argument( + '--no-stats', + action='store_true', + help="Don't show data stats in the header.") parser.add_argument( '--binary', action='store_true',