markers (-m) option to omit statistical markers
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 4 Sep 2019 20:22:01 +0000 (22:22 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 5 Sep 2019 03:11:33 +0000 (05:11 +0200)
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

diff --git a/graph b/graph
index 20ce299d1121162cbcfdd480da2975d8ddb398a4..312effeff4f6d53a785a02aacd2e453af3a09300 100755 (executable)
--- 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=<columns>
 
 Override the maximum number of columns to use.