Chart/GGPlot/Stat.pm

filter: Statementstmt 92.7% 103 / 111 Branchbran 43.3% 13 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 18 / 20 Podpod 0.0% 0 / 7 totaltotal 79.7% 134 / 168 CC 17 SCAR 11.5
CC
17
Cov
82%
compute_group
9.8
compute_panel
5.0
setup_data
3.1
CRAP 3.2
« Chart/GGPlot/Trans.pm ↑ Summary Chart/GGPlot/Coord/Polar.pm »
1 package Chart::GGPlot::Stat;
2  
3 # ABSTRACT: The stat role
4  
5 7 ▶use Chart::GGPlot::Role qw(:pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 our $VERSION = '0.002003'; # VERSION
9  
10 7 ▶use List::AllUtils qw(reduce pairmap);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Types::Standard qw(ArrayRef CodeRef Str InstanceOf Bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Types::PDL -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 7 ▶use Data::Frame;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use Chart::GGPlot::Trans;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use Chart::GGPlot::Types qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use Chart::GGPlot::Util qw(remove_missing stat);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 7 has retransform => ( is => 'ro' );
20  
21 7 with qw(
22 Chart::GGPlot::HasRequiredAes
23 Chart::GGPlot::HasDefaultAes
24 Chart::GGPlot::HasNonMissingAes
25 Chart::GGPlot::HasParams
26 Chart::GGPlot::HasCollectibleFunctions
27 );
28  
29 5 ▶method setup_data ( $data, $params ) { $data }
Subroutine setup_data: called CC=3 SCAR=11.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method setup_data (expected 3, got ' . @_ . ')') 0 5 5
@_ > 3 and Function::Parameters::_croak('Too many arguments for method setup_data (expected 3, got ' . @_ . ')') 0 5 5
30  
31 4 ▶method setup_params ( $data, $params ) { $params }
Subroutine setup_params: called CC=3 SCAR=11.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method setup_params (expected 3, got ' . @_ . ')') 0 4 4
@_ > 3 and Function::Parameters::_croak('Too many arguments for method setup_params (expected 3, got ' . @_ . ')') 0 4 4
32  
33 2 ▶method compute_layer ( $data, $params, $layout ) {
Subroutine compute_layer: called CC=3 SCAR=11.1
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 4 and Function::Parameters::_croak('Too few arguments for method compute_layer (expected 4, got ' . @_ . ')') 0 2 2
@_ > 4 and Function::Parameters::_croak('Too many arguments for method compute_layer (expected 4, got ' . @_ . ')') 0 2 2
34 $self->check_required_aes(
35 2 [ @{ $data->names }, @{ $params->names } ] );
36  
37 $data = remove_missing(
38 $data,
39 na_rm => $params->at('na_rm'),
40 2 vars => [ @{ $self->required_aes }, @{ $self->non_missing_aes } ],
41 name => ref($self),
42 finite => true,
43 );
44  
45 # Trim off extra parameters
46 2 my $params =
47 $params->slice( $params->names->intersect($self->parameters) );
48  
49 2 my $splitted = $data->split( $data->at('PANEL') );
50 return (
51 0 ▶ reduce { $a->cbind($b) } $splitted->keys->map(
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 2 my ($panel_id) = @_;
54 2 my $d = $splitted->{$panel_id};
55  
56 2 my $scales = $layout->get_scales( $d->at('PANEL')->at(0) );
57  
58 2 try {
59 2 return $self->compute_panel( $d, $scales, $params );
60 }
61 catch ($e) {
62 0 die sprintf( "Computation failed in '%s': $e", ref($self) );
63 }
64 }
65 2 )->flatten
66 );
67 7 }
68  
69 2 ▶method compute_panel ( $data, $scales, $params ) {
Subroutine compute_panel: called CC=5 SCAR=16.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 4 and Function::Parameters::_croak('Too few arguments for method compute_panel (expected 4, got ' . @_ . ')') 0 2 2
@_ > 4 and Function::Parameters::_croak('Too many arguments for method compute_panel (expected 4, got ' . @_ . ')') 0 2 2
70 2 ▶ return Data::Frame->new() if ( $data->isempty );
Branch: 1 branch
BranchTrueFalseTotal
if $data->isempty 0 2 2
71  
72 2 my $groups = $data->split( $data->at('group') );
73 my $stats = {
74 14 ▶ pairmap { $a => $self->compute_group( $b, $scales, $params ); }
Subroutine __ANON__: called CC=1 SCAR=0.0
75 2 %$groups
76 };
77  
78 # cbind the result of compute_group() with splitted df,
79 # and also rbind to form one df that corresponds to the $data.
80 $stats = [
81 map { # $_ is group id
82 14 my $new_df = $stats->{$_};
83 14 my $old_df = $groups->{$_};
84 14 my $missing = $old_df->names->setdiff($new_df->names);
85 14 for my $colname (@$missing) {
86 56 $new_df->set( $colname,
87 $old_df->at($colname)->slice( pdl( [0] ) ) );
88 }
89 14 $new_df;
90 2 } sort { $a <=> $b } @{ $stats->keys }
91 ];
92  
93 2 ▶ return reduce { $a->rbind($b) } @$stats;
Subroutine __ANON__: called CC=1 SCAR=0.0
94 7 }
95  
96 0 ▶method compute_group ( $data, $scales ) { ... }
Subroutine compute_group: not called CC=3 SCAR=22.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method compute_group (expected 3, got ' . @_ . ')') 0 0 0
@_ > 3 and Function::Parameters::_croak('Too many arguments for method compute_group (expected 3, got ' . @_ . ')') 0 0 0
97  
98 6 ▶method finish_layer ( $data, $param ) { $data }
Subroutine finish_layer: called CC=3 SCAR=11.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method finish_layer (expected 3, got ' . @_ . ')') 0 6 6
@_ > 3 and Function::Parameters::_croak('Too many arguments for method finish_layer (expected 3, got ' . @_ . ')') 0 6 6
99  
100 10 ▶method aesthetics () {
Subroutine aesthetics: called CC=3 SCAR=11.1
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method aesthetics (expected 1, got ' . @_ . ')') 0 10 10
@_ > 1 and Function::Parameters::_croak('Too many arguments for method aesthetics (expected 1, got ' . @_ . ')') 0 10 10
101 10 my @names = List::AllUtils::uniq( @{ $self->required_aes },
102 10 @{ $self->default_aes->names }, 'group' );
103 10 return \@names;
104 7 }
105  
106 7 1;
107  
108 __END__
« Chart/GGPlot/Trans.pm ↑ Summary Chart/GGPlot/Coord/Polar.pm »