if ($opt{markers} and $size > 0) {
for my $markspec (split /\h/, $opt{markers}) {
my ($char, $func) = split //, $markspec, 2;
+ my $increment = $func =~ s/[+]\z//;
my @pos = eval {
- if ($func eq 'avg') {
- return sum(@order) / @order;
- }
- elsif ($func =~ /\A([0-9.]+)v\z/) {
- $1 <= 100 or die(
- "Invalid marker $char: percentile $1 out of bounds\n"
- );
- my $index = $#order * $1 / 100;
- return ($order[$index] + $order[$index + .5]) / 2;
- }
- elsif ($func =~ /\A-?[0-9.]+\z/) {
- return $func;
- }
- elsif ($func =~ /\A\/($float)\z/) {
+ if ($func =~ /\A\/($float)\z/) {
my @range = my $multiple = my $next = $1;
while ($next < $maxval) {
$multiple *= 10 if $opt{log};
}
return @range;
}
- else {
- die "Unknown marker $char: $func\n";
- }
- };
- @pos or do {
- warn $@ if $@;
+ return calc($func);
+ } or do {
+ warn "Invalid marker $char: $@" if $@;
next;
};
for my $pos (@pos) {
$pos -= $minval;
$pos &&= log $pos if $opt{log};
$pos >= 0 or next;
- color(36) for $barmark[$pos / $range * $size] = $char;
+ $increment ||= $minval && !$pos;
+ color(36) for $barmark[$pos / $range * $size + $increment + .5] = $char;
}
}
sub show_stat {
my %vars = (
+ partsum => undef,
count => int @order,
lines => int @lines,
);
return 1;
}
+sub calc {
+ my ($func) = @_;
+ if ($func eq 'avg') {
+ return sum(@order) / @order;
+ }
+ elsif ($func eq 'sum') {
+ return sum(@order);
+ }
+ elsif ($func =~ /\A([0-9.]+)v\z/) {
+ $1 <= 100 or die(
+ "percentile $1 out of bounds\n"
+ );
+ my $index = $#order * $1 / 100;
+ return ($order[$index] + $order[$index + .5]) / 2;
+ }
+ elsif ($func =~ /\A-?[0-9.]+\z/) {
+ return $func;
+ }
+ else {
+ die "$func unknown\n";
+ }
+}
+
sub varfmt {
my ($fmt, $vars) = @_;
$fmt =~ s[\$\{ \h*+ ((?: [^{}]++ | \{(?1)\} )+) \}]{
my ($name, $op, $cmd) = split /\s*([;:])/, $1, 2;
my $format = $name =~ s/\+// || $name !~ s/\#// && $opt{reformat};
- local $_ = $vars->{$name};
+ local $_ = exists $vars->{$name} ? $vars->{$name} : calc($name);
defined && do {
$_ = $opt{'value-format'}->($_) if $format;
if ($cmd and $op eq ':') {
Contents are concatenated similar to I<cat>,
but numbers are reformatted and a bar graph is appended to each line.
-Don't worry, barcat does not drink and divide.
It can has various options for input and output (re)formatting,
but remains limited to one-dimensional charts.
For more complex graphing needs
=item B<avg>
-Matches the average;
+Matches the average (arithmetic mean);
the sum of all values divided by the number of counted lines.
Indicated by default as C<=>.