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.
This commit is contained in:
+30
-18
@@ -712,6 +712,7 @@ def main(csv_paths, *,
|
|||||||
width=None,
|
width=None,
|
||||||
height=None,
|
height=None,
|
||||||
no_header=False,
|
no_header=False,
|
||||||
|
no_stats=False,
|
||||||
to_scale=None,
|
to_scale=None,
|
||||||
aspect_ratio=(1,1),
|
aspect_ratio=(1,1),
|
||||||
title=None,
|
title=None,
|
||||||
@@ -748,7 +749,10 @@ def main(csv_paths, *,
|
|||||||
width_ = shutil.get_terminal_size((80, 5))[0]
|
width_ = shutil.get_terminal_size((80, 5))[0]
|
||||||
|
|
||||||
if height is None:
|
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:
|
elif height:
|
||||||
height_ = height
|
height_ = height
|
||||||
else:
|
else:
|
||||||
@@ -849,7 +853,10 @@ def main(csv_paths, *,
|
|||||||
# create a canvas
|
# create a canvas
|
||||||
canvas = Canvas(
|
canvas = Canvas(
|
||||||
width_,
|
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,
|
color=color,
|
||||||
dots=dots,
|
dots=dots,
|
||||||
braille=braille)
|
braille=braille)
|
||||||
@@ -967,23 +974,24 @@ def main(csv_paths, *,
|
|||||||
canvas.label(*label__)
|
canvas.label(*label__)
|
||||||
|
|
||||||
# print some summary info
|
# print some summary info
|
||||||
if title:
|
|
||||||
title_ = punescape(title, tile.attrs)
|
|
||||||
if not no_header:
|
if not no_header:
|
||||||
stat = tile.stat()
|
if title:
|
||||||
stat_ = 'total %d, avg %d +-%dσ, min %d, max %d' % (
|
title_ = punescape(title, tile.attrs)
|
||||||
stat['total'],
|
if not no_stats:
|
||||||
stat['mean'], stat['stddev'],
|
stat = tile.stat()
|
||||||
stat['min'], stat['max'])
|
stat_ = 'total %d, avg %d +-%dσ, min %d, max %d' % (
|
||||||
if title and not no_header:
|
stat['total'],
|
||||||
print('%s%*s%s' % (
|
stat['mean'], stat['stddev'],
|
||||||
title_,
|
stat['min'], stat['max'])
|
||||||
max(width_-len(stat_)-len(title_), 0), ' ',
|
if title and not no_stats:
|
||||||
stat_))
|
print('%s%*s%s' % (
|
||||||
elif title:
|
title_,
|
||||||
print(title_)
|
max(width_-len(stat_)-len(title_), 0), ' ',
|
||||||
elif not no_header:
|
stat_))
|
||||||
print(stat_)
|
elif title:
|
||||||
|
print(title_)
|
||||||
|
elif not no_stats:
|
||||||
|
print(stat_)
|
||||||
|
|
||||||
# draw canvas
|
# draw canvas
|
||||||
for row in range(canvas.height//canvas.yscale):
|
for row in range(canvas.height//canvas.yscale):
|
||||||
@@ -1088,6 +1096,10 @@ if __name__ == "__main__":
|
|||||||
'-N', '--no-header',
|
'-N', '--no-header',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="Don't show the header.")
|
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(
|
parser.add_argument(
|
||||||
'--binary',
|
'--binary',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
|||||||
+10
-5
@@ -561,6 +561,7 @@ def main(csv_paths, output, *,
|
|||||||
width=None,
|
width=None,
|
||||||
height=None,
|
height=None,
|
||||||
no_header=False,
|
no_header=False,
|
||||||
|
no_stats=False,
|
||||||
to_scale=None,
|
to_scale=None,
|
||||||
aspect_ratio=(1,1),
|
aspect_ratio=(1,1),
|
||||||
title=None,
|
title=None,
|
||||||
@@ -703,7 +704,7 @@ def main(csv_paths, output, *,
|
|||||||
height__ = tile.height
|
height__ = tile.height
|
||||||
|
|
||||||
# create space for header
|
# 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)
|
y__ += mt.ceil(FONT_SIZE * 1.3)
|
||||||
height__ -= min(mt.ceil(FONT_SIZE * 1.3), height__)
|
height__ -= min(mt.ceil(FONT_SIZE * 1.3), height__)
|
||||||
|
|
||||||
@@ -789,16 +790,16 @@ def main(csv_paths, output, *,
|
|||||||
background=background_))
|
background=background_))
|
||||||
|
|
||||||
# create header
|
# 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('<text fill="%(color)s">' % dict(
|
f.write('<text fill="%(color)s">' % dict(
|
||||||
color='#ffffff' if dark else '#000000'))
|
color='#ffffff' if dark else '#000000'))
|
||||||
if not no_header:
|
if not no_stats:
|
||||||
stat = tile.stat()
|
stat = tile.stat()
|
||||||
if title:
|
if title:
|
||||||
f.write('<tspan x="3" y="1.1em">')
|
f.write('<tspan x="3" y="1.1em">')
|
||||||
f.write(punescape(title, tile.attrs))
|
f.write(punescape(title, tile.attrs))
|
||||||
f.write('</tspan>')
|
f.write('</tspan>')
|
||||||
if not no_header:
|
if not no_stats:
|
||||||
f.write('<tspan x="%(x)d" y="1.1em" '
|
f.write('<tspan x="%(x)d" y="1.1em" '
|
||||||
'text-anchor="end">' % dict(
|
'text-anchor="end">' % dict(
|
||||||
x=tile.width-3))
|
x=tile.width-3))
|
||||||
@@ -807,7 +808,7 @@ def main(csv_paths, output, *,
|
|||||||
stat['mean'], stat['stddev'],
|
stat['mean'], stat['stddev'],
|
||||||
stat['min'], stat['max']))
|
stat['min'], stat['max']))
|
||||||
f.write('</tspan>')
|
f.write('</tspan>')
|
||||||
else:
|
elif not no_stats:
|
||||||
f.write('<tspan x="3" y="1.1em">')
|
f.write('<tspan x="3" y="1.1em">')
|
||||||
f.write('total %d, avg %d +-%dσ, min %d, max %d' % (
|
f.write('total %d, avg %d +-%dσ, min %d, max %d' % (
|
||||||
stat['total'],
|
stat['total'],
|
||||||
@@ -955,6 +956,10 @@ if __name__ == "__main__":
|
|||||||
'-N', '--no-header',
|
'-N', '--no-header',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="Don't show the header.")
|
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(
|
parser.add_argument(
|
||||||
'--binary',
|
'--binary',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
|||||||
Reference in New Issue
Block a user