commit a1b51733633a7abac329ccfe6ac4458427cb4978
parent 03ce3885c36aa238d977658284b275702a0aba0c
Author: René Wagner <rwagner@rw-net.de>
Date: Fri, 9 Oct 2020 14:00:23 +0200
WIP: initial column joining
Diffstat:
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/phosta.pl b/phosta.pl
@@ -402,12 +402,26 @@ sub result_to_graph
my $barwidth = POSIX::lround(($opt_W - 17) * 0.7);
my $titlewidth = POSIX::lround(($opt_W - 17) * 0.3);
my $chartformat = '%'.$titlewidth.'.'.$titlewidth.'s |%-'.$barwidth.'s| %5s (%s)';
-
+
my $countcolumn = @$headers - 2;
my $percentcolumn = @$headers - 1;
foreach (@$rows)
{
+ # join columns for display before the chart
+ if ( @$headers >= 4)
+ {
+ # TODO: give remaining columns more room if first columns are shorter
+ # TODO: remove trailing whitespace
+ my $titlecolumns = @$headers - 2;
+ my $columnwidth = POSIX::lround($titlewidth / $titlecolumns);
+ my $title = '';
+ for (my $i = 0; $i < $titlecolumns; $i++)
+ {
+ $title = $title . ((length(@$_[$i]) > $columnwidth) ? substr(@$_[$i], 0, $columnwidth-1).'~ ' : @$_[$i] . ' ');
+ }
+ @$_[0] = $title;
+ }
say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[$countcolumn]), @$_[$percentcolumn], @$_[$countcolumn]);
}
}