Chart/GGPlot/Position/Stack.pm

filter: Statementstmt 83.5% 61 / 73 Branchbran 38.2% 13 / 34 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 5 totaltotal 62.7% 86 / 137 CC 21 SCAR 24.8
CC
21
Cov
66%
setup_data
28.8
stack_var
7.2
compute_panel
6.8
CRAP 12.0
« Chart/GGPlot/Scale/SupportsSecondaryAxis.pm ↑ Summary Chart/GGPlot/Backend/Plotly/Geom/Bar.pm »
1 package Chart::GGPlot::Position::Stack;
2  
3 # ABSTRACT: Position for "stack"
4  
5 6 ▶use Chart::GGPlot::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 our $VERSION = '0.002003'; # VERSION
9  
10 6 ▶use PDL::Primitive qw(which);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶use Chart::GGPlot::Position::Util qw(collide pos_stack);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 6 has var => ( is => 'ro' );
16 6 has vjust => ( is => 'ro', default => 1 );
17 3 ▶has reverse => ( is => 'ro', default => sub { false } );
Subroutine __ANON__: called CC=1 SCAR=0.0
18  
19 6 with qw(Chart::GGPlot::Position);
20  
21 1 ▶sub fill { false }
Subroutine fill: called CC=1 SCAR=0.0
Pod undocumented
22  
23 1 ▶method setup_params ($data) {
Subroutine setup_params: called CC=4 SCAR=15.0
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method setup_params (expected 2, got ' . @_ . ')') 0 1 1
@_ > 2 and Function::Parameters::_croak('Too many arguments for method setup_params (expected 2, got ' . @_ . ')') 0 1 1
24 return {
25 1 ▶ var => ( $self->var // $self->stack_var($data) ),
Condition33%1/3
$self->var // $self->stack_var($data)
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->var // $self->stack_var($data)
$self->var $self->stack_var($data)
Truth table33%1/3
A // B
A= $self->varB= $self->stack_var($data)
ABresult
1X1
011
000
26 vjust => $self->vjust,
27 fill => $self->fill,
28 reverse => $self->reverse
29 };
30 6 }
31  
32 1 ▶method setup_data ($data, $params) {
Subroutine setup_data: called CC=9 SCAR=33.6
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method setup_data (expected 3, got ' . @_ . ')') 0 1 1
@_ > 3 and Function::Parameters::_croak('Too many arguments for method setup_data (expected 3, got ' . @_ . ')') 0 1 1
33 1 my $var = $params->at('var');
34 1 ▶ if ( defined $var and length($var) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $var and length $var) 1 0 1
Condition33%1/3
defined $var and length $var
!ll&&!rl&&r
001
MC/DC0%0/2
defined $var and length $var
defined $var length $var
Truth table33%1/3
A and B
A= defined $varB= length $var
ABresult
0X0
100
111
35 1 return $data;
36 }
37  
38 0 my $ymax;
39 0 ▶ if ( $var eq 'y' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($var eq 'y') { } 0 0 0
elsif ($var eq 'ymax' and ($data->at('ymax') == 0)->all) { } 0 0 0
40 0 $ymax = $data->at('y');
41 }
42 ▶ elsif ( $var eq 'ymax' and ( $data->at('ymax') == 0 )->all ) {
Condition0%0/3
$var eq "ymax" and ($data->at("ymax") == 0)->all
!ll&&!rl&&r
000
MC/DC0%0/2
$var eq "ymax" and ($data->at("ymax") == 0)->all
$var eq "ymax" ($data->at("ymax") == 0)->all
Truth table0%0/3
A and B
A= $var eq "ymax"B= ($data->at("ymax") == 0)->all
ABresult
0X0
100
111
43 0 $ymax = $data->at('ymin');
44 }
45 0 ▶ $data->set( 'ymax', $ymax ) if defined $ymax;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ymax 0 0 0
46  
47 0 remove_missing(
48 $data,
49 vars => [qw(x xmin xmax y)],
50 name => 'position_stack'
51 );
52 6 }
53  
54 1 ▶method compute_panel ($data, $params, $scales) {
Subroutine compute_panel: called CC=6 SCAR=19.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 4 and Function::Parameters::_croak('Too few arguments for method compute_panel (expected 4, got ' . @_ . ')') 0 1 1
@_ > 4 and Function::Parameters::_croak('Too many arguments for method compute_panel (expected 4, got ' . @_ . ')') 0 1 1
55 1 my $var = $params->at('var');
56 1 ▶ unless ($var) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($var) 0 1 1
57 0 return $data;
58 }
59  
60 1 my $negative = $data->at($var) < 0;
61 1 my $neg = $data->select_rows( which($negative) );
62 1 my $pos = $data->select_rows( which( !$negative ) );
63  
64 1 ▶ if ( $neg->nrow ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($neg->nrow) 0 1 1
65 $neg = collide( $neg, undef, 'position_stack', \&pos_stack,
66 0 map { $_ => $params->at($_) } qw(vjust fill reverse) );
67 }
68 1 ▶ if ( $pos->nrow ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos->nrow) 1 0 1
69 $pos = collide( $pos, undef, 'position_stack', \&pos_stack,
70 1 map { $_ => $params->at($_) } qw(vjust fill reverse) );
71 }
72  
73 1 return $neg->rbind($pos);
74 6 }
75  
76 1 ▶classmethod stack_var ($data) {
Subroutine stack_var: called CC=5 SCAR=19.7
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for classmethod stack_var (expected 2, got ' . @_ . ')') 0 1 1
@_ > 2 and Function::Parameters::_croak('Too many arguments for classmethod stack_var (expected 2, got ' . @_ . ')') 0 1 1
77 1 ▶ if ( $data->exists('ymax') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data->exists('ymax')) { } 1 0 1
elsif ($data->exists('y')) { } 0 0 0
78 1 return 'ymax';
79 }
80 elsif ( $data->exists('y') ) {
81 0 return 'y';
82 }
83  
84 0 warn "Stacking requires either ymin & ymax or y aesthetics";
85 0 return undef;
86 6 }
87  
88 6 __PACKAGE__->meta->make_immutable;
89  
90 6 1;
91  
92 __END__
« Chart/GGPlot/Scale/SupportsSecondaryAxis.pm ↑ Summary Chart/GGPlot/Backend/Plotly/Geom/Bar.pm »