line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Term::Vspark; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
49470
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
59
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
46
|
|
5
|
2
|
|
|
2
|
|
786
|
use POSIX; |
|
2
|
|
|
|
|
8806
|
|
|
2
|
|
|
|
|
9
|
|
6
|
2
|
|
|
2
|
|
3190
|
use Carp qw{ croak }; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
59
|
|
7
|
2
|
|
|
2
|
|
942
|
use utf8; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
|
|
14
|
use Sub::Exporter -setup => { |
10
|
|
|
|
|
|
|
'exports' => [ 'show_bar', 'show_graph', ], |
11
|
2
|
|
|
2
|
|
952
|
}; |
|
2
|
|
|
|
|
13117
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.31; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub show_bar { |
18
|
6
|
|
100
|
6
|
0
|
10
|
my $num = shift || 0; |
19
|
6
|
|
50
|
|
|
8
|
my $max = shift || 0; |
20
|
6
|
|
50
|
|
|
8
|
my $columns = shift || 0; |
21
|
|
|
|
|
|
|
|
22
|
6
|
|
|
|
|
24
|
my @graph = qw{ ▏ ▎ ▍ ▌ ▋ ▊ ▉ █ }; |
23
|
6
|
|
|
|
|
29
|
my $bar_num = ceil( $num * ( scalar(@graph) * $columns ) ) / $max; |
24
|
|
|
|
|
|
|
|
25
|
6
|
|
|
|
|
11
|
my $str = $graph[-1] x ( int($bar_num / scalar(@graph) ) ); |
26
|
6
|
|
|
|
|
13
|
$str .= $graph[ ceil($bar_num % (scalar(@graph) ) ) ]; |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
8
|
return $str; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub show_graph { |
32
|
1
|
|
|
1
|
1
|
17
|
my %args = @_; |
33
|
|
|
|
|
|
|
|
34
|
1
|
50
|
|
|
|
5
|
if ( ref $args{'values'} ne 'ARRAY' ) { |
35
|
0
|
|
|
|
|
0
|
croak 'values is not an ArrayRef'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
1
|
50
|
33
|
|
|
10
|
if ( $args{'labels'} && ( ref $args{'labels'} ne 'ARRAY' ) ) { |
39
|
0
|
|
|
|
|
0
|
croak 'labels is not an ArrayRef'; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
50
|
|
|
3
|
my $max = $args{'max'} || 1; |
43
|
1
|
|
50
|
|
|
3
|
my $columns = $args{'columns'} || 1; |
44
|
1
|
50
|
|
|
|
2
|
my @labels = @{ $args{'labels'} || [] }; |
|
1
|
|
|
|
|
4
|
|
45
|
1
|
|
|
|
|
1
|
my @values = @{ $args{'values'} }; |
|
1
|
|
|
|
|
2
|
|
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
33
|
|
|
6
|
if ( $args{'labels'} && ( scalar @labels != scalar @values ) ) { |
48
|
0
|
|
|
|
|
0
|
croak 'the number of labels and values must be equal'; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
4
|
my $label_width = max_label_width( @labels ); |
52
|
1
|
|
|
|
|
3
|
my $bar_width = $columns - $label_width - 2; |
53
|
1
|
|
|
|
|
1
|
my $str = q{}; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
2
|
for my $value (@values) { |
56
|
6
|
|
|
|
|
6
|
my $label = shift @labels; |
57
|
6
|
|
|
|
|
8
|
my $bar = show_bar($value, $max, $bar_width); |
58
|
|
|
|
|
|
|
|
59
|
6
|
50
|
|
|
|
19
|
$str .= sprintf('%' . $label_width . "s ", $label) if defined $label; |
60
|
6
|
|
|
|
|
11
|
$str .= $bar . "\n"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
3
|
return $str; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub max_label_width { |
67
|
1
|
|
|
1
|
0
|
2
|
my @labels = @_; |
68
|
1
|
50
|
|
|
|
4
|
return 0 if scalar @labels == 0; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
3
|
my $max_width = (sort { $a <=> $b } map { length($_) } @labels)[-1]; |
|
9
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
14
|
|
71
|
1
|
|
|
|
|
4
|
return $max_width + 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
__END__ |