From aa8e46751feb68874573d2185f7d082387e8d4dc Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 4 Sep 2019 22:22:01 +0200 Subject: [PATCH] markers (-m) option to omit statistical markers Support leaving bars untouched for either aesthetical reasons or to avoid calculation (which may yet be(come) costly or buggy). String argument is only checked for emptiness, otherwise all positions are enabled. Effectively boolean but with future compatibility for more detailed customisation. --- graph | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/graph b/graph index 20ce299..312effe 100755 --- a/graph +++ b/graph @@ -6,10 +6,11 @@ use open qw( :std :utf8 ); our $VERSION = '1.00'; -use Getopt::Long '2.33'; +use Getopt::Long '2.33', qw( :config gnu_getopt ); sub podexit { require Pod::Usage; Pod::Usage::pod2usage(-exitval => 0, @_) } GetOptions(\my %opt, 'color|c!', + 'markers|m=s', 'width|w=i', 'usage|h' => sub { podexit() }, 'help' => sub { podexit(-verbose => 2) }, @@ -29,12 +30,14 @@ my $len = 1 + max map { length } @lines; # left padding my $size = ($maxval - $minval) && ($opt{width} - $lenval - $len) / ($maxval - $minval); # bar multiplication -sub orderpos { (($order[$_[0]] + $order[$_[0] + .5]) / 2 - $minval) * $size } my @barmark; -$barmark[ (sum(@order) / @order - $minval) * $size ] = '='; # average -$barmark[ orderpos($#order / 2) ] = '+'; # mean -$barmark[ -$minval * $size ] = '|' if $minval < 0; # zero -defined and $opt{color} and $_ = "\e[36m$_\e[0m" for @barmark; +if ($opt{markers} // 1) { + sub orderpos { (($order[$_[0]] + $order[$_[0] + .5]) / 2 - $minval) * $size } + $barmark[ (sum(@order) / @order - $minval) * $size ] = '='; # average + $barmark[ orderpos($#order / 2) ] = '+'; # mean + $barmark[ -$minval * $size ] = '|' if $minval < 0; # zero + defined and $opt{color} and $_ = "\e[36m$_\e[0m" for @barmark; +} for my $nr (0 .. $#lines) { my $val = $values[$nr]; @@ -74,6 +77,28 @@ Each line starting with a number is given a bar to visualise relative sizes. Disable colored output of values and bar markers. +=item -m, --markers= + +Statistical positions to indicate on bars. +Cannot be customized yet, +only disabled by providing an empty argument. + +Any value enables all marker characters: + +=over 2 + +=item B<=> + +Average: +the sum of all values divided by the number of counted lines. + +=item B<+> + +Median: +the middle value or average between middle values. + +=back + =item -w, --width= Override the maximum number of columns to use. -- 2.30.0