spark values for minimum and maximum
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 23 Sep 2019 23:22:36 +0000 (01:22 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 24 Sep 2019 00:08:51 +0000 (02:08 +0200)
Special case first and last matches like colors.

barcat

diff --git a/barcat b/barcat
index 804b3b074b8c54ba005c61ffdd1ffb32c73b01a4..c5b7e0af73580e4a1015feed224d281dcdb9ef84 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -50,7 +50,7 @@ GetOptions(\%opt,
                $opt{'graph-format'} = substr $_[1], 0, 1;
        },
        'spark:s' => sub {
-               $opt{spark} = [split //, $_[1] || '▁▂▃▄▅▆▇█'];
+               $opt{spark} = [split //, $_[1] || ' ▁▂▃▄▅▆▇█'];
        },
        'palette=s' => sub {
                $opt{palette} = {
@@ -238,8 +238,13 @@ while ($nr <= $#lines) {
        my $rel = length $val && ($val - $minval) / ($maxval - $minval);
 
        if ($opt{spark}) {
-               print color($opt{palette}->[ $rel * $#{$opt{palette}} ]) if $opt{palette};
-               print $opt{spark}->[ $rel * $#{$opt{spark}} ];
+               print $opt{spark}->[
+                       !$val ? 0 : # blank
+                       $val == $order[0] ? -1 : # max
+                       $val == $order[-1] ? 1 : # min
+                       $#{$opt{spark}} < 3 ? 1 :
+                       $rel * ($#{$opt{spark}} - 3) + 2.5
+               ];
                next;
        }