From: Mischa POSLAWSKY Date: Wed, 4 Sep 2019 18:29:09 +0000 (+0200) Subject: floating point value support X-Git-Tag: v1.01~12 X-Git-Url: http://git.shiar.nl/barcat.git/commitdiff_plain/21e2b568838b102ee7be38af599a3f7a6ab61b77 floating point value support Include numbers after decimal point; perl will handle it no problem. Replace stupid digit calculation without number reformatting by simple string length, also fixing log error on 0 values. --- diff --git a/graph b/graph index 01f6846..2212926 100755 --- a/graph +++ b/graph @@ -19,12 +19,12 @@ $opt{color} //= 1; my @lines = readline or exit; chomp for @lines; -my @values = map { s/^\h*(-?[0-9]*)// and $1 } @lines; +my @values = map { s/^\h* ( -? [0-9]* (?:\.[0-9]+)? )//x and $1 } @lines; my @order = sort { $b <=> $a } @values; my $maxval = max $order[0], -$order[-1]; -my $lenval = 1 + ($order[-1] < 0) + int log($maxval || 1) / log 10; # max string length +my $lenval = max map { length } @order; my $len = 1 + max map { length } @lines; # left padding -my $size = ($opt{width} - $lenval - $len) / $maxval; # bar multiplication +my $size = $maxval && ($opt{width} - $lenval - $len) / $maxval; # bar multiplication sub orderpos { ($order[$_[0]] + $order[$_[0] + .5]) / 2 * $size } my @barmark;