#!/usr/bin/env perl use utf8; ############################################################################### # This program draws a histogram graph. # # Copyright © 2020 Richard Lesh. All rights reserved. ############################################################################### use POSIX qw(floor); use Utils; use strict; use warnings; our $MAX_BAR_SIZE = 50.; MAIN: { binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); binmode(STDIN, ":utf8"); my $buffer = []; my $line; while ($line = ) { chomp($line); push(@{$buffer}, $line); } my $labels = []; my $freqs = []; my $max_freq = 0.0; my $is_first = 1; foreach my $data (@$buffer) { if ($is_first) { $is_first = 0; next; } my $POS = index($data, "\t"); if ($POS > 0) { my $LABEL = substr($data, 0, $POS - 0); my $FREQ = Utils::stodWithDefault(substr($data, $POS + 1), 0.0) * 100.; push(@{$labels}, $LABEL); push(@{$freqs}, $FREQ); if ($FREQ > $max_freq) { $max_freq = $FREQ; } } } for (my $i = 0; $i < scalar(@{$labels}); ++$i) { my $BAR_SIZE = int(floor($freqs->[$i] / $max_freq * $MAX_BAR_SIZE + 0.5)); print Utils::messageFormat("\{0:>18.18s\} \{1:8.4f\}\% \{2:s\}", $labels->[$i], $freqs->[$i], "=" x ($BAR_SIZE)), "\n"; } }