Chart/GGPlot/Scale.pm

filter: Statementstmt 88.6% 109 / 123 Branchbran 46.0% 23 / 50 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 78.9% 15 / 19 Podpod 50.0% 4 / 8 totaltotal 76.1% 156 / 205 CC 28 SCAR 16.0
CC
28
Cov
77%
make_title
9.8
make_sec_title
9.8
map_df
7.8
CRAP 5.0
« Chart/GGPlot/Range/Discrete.pm ↑ Summary Chart/GGPlot/Scale/ContinuousDateTime.pm »
1 package Chart::GGPlot::Scale;
2  
3 # ABSTRACT: The role for scale
4  
5 4 ▶use Chart::GGPlot::Role qw(:pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '0.002003'; # VERSION
9  
10 4 ▶use PDL::Primitive qw(which);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Types::PDL qw(Piddle PiddleFromAny);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Types::Standard qw(Any ArrayRef CodeRef Maybe Str InstanceOf ConsumerOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Type::Params;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use Chart::GGPlot::Trans;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Chart::GGPlot::Types qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Chart::GGPlot::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 4 has aesthetics => (
21 is => 'ro',
22 isa => ArrayRef->plus_coercions(ArrayRefFromAny),
23 coerce => 1,
24 required => 1,
25 );
26 4 has scale_name => ( is => 'ro', isa => Str, required => 1 );
27 4 has palette => ( is => 'rw', isa => Maybe [CodeRef] );
28 0 ▶has range => ( is => 'rw', isa => Piddle, default => sub { null; } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
29  
30 has limits => (
31 is => 'rw',
32 0 ▶ default => sub { null; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 4 );
34  
35 4 has na_value => ( is => 'rw', default => "nan" );
36 4 has expand => ( is => 'rw', default => undef );
37 4 has name => ( is => 'rw', default => undef );
38 4 has breaks => ( is => 'rw', default => undef );
39 4 has labels =>
40 ( is => 'rw', isa => Maybe [ Piddle | CodeRef ], default => undef );
41 4 has guide => ( is => 'ro', default => "legend" );
42 4 has position => ( is => 'rw', isa => PositionEnum, default => "left" );
43 4 has trans => ( is => 'rw', isa => InstanceOf ["Chart::GGPlot::Trans"] );
44  
45 4 requires 'train'; # Train an individual scale from a vector of data.
46 4 requires 'transform';
47  
48 4 requires 'get_breaks_minor';
49 4 requires 'get_labels';
50 4 requires 'break_info';
51 4 requires 'dimension';
52 4 requires 'get_breaks';
53  
54 #requires 'clone';
55  
56  
57 2 ▶method train_df ($df) {
Subroutine train_df: called CC=5 SCAR=16.5
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method train_df (expected 2, got ' . @_ . ')') 0 2 2
@_ > 2 and Function::Parameters::_croak('Too many arguments for method train_df (expected 2, got ' . @_ . ')') 0 2 2
58 2 ▶ return if $df->isempty;
Branch: 1 branch
BranchTrueFalseTotal
if $df->isempty 0 2 2
59  
60 2 my $aesthetics = $self->aesthetics->intersect($df->names);
61 2 for my $aesthetic (@$aesthetics) {
62 2 $self->train( $df->at($aesthetic) );
63 }
64 4 }
65  
66  
67 9 ▶method reset () {
Subroutine reset: called CC=3 SCAR=11.3
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method reset (expected 1, got ' . @_ . ')') 0 9 9
@_ > 1 and Function::Parameters::_croak('Too many arguments for method reset (expected 1, got ' . @_ . ')') 0 9 9
68 9 $self->range->reset;
69 4 }
70  
71 77 ▶method isempty () {
Subroutine isempty: called CC=4 SCAR=14.0
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method isempty (expected 1, got ' . @_ . ')') 0 77 77
@_ > 1 and Function::Parameters::_croak('Too many arguments for method isempty (expected 1, got ' . @_ . ')') 0 77 77
72 77 ▶ return ( $self->range->range->isempty and $self->limits->isempty );
Condition100%3/3
$self->range->range->isempty && $self->limits->isempty
!ll&&!rl&&r
54158
MC/DC100%2/2
$self->range->range->isempty && $self->limits->isempty
$self->range->range->isempty $self->limits->isempty
Truth table100%3/3
A && B
A= $self->range->range->isemptyB= $self->limits->isempty
ABresult
0X0
100
111
73 4 }
74  
75  
76 13 ▶method transform_df ($df) {
Subroutine transform_df: called CC=5 SCAR=16.6
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method transform_df (expected 2, got ' . @_ . ')') 0 13 13
@_ > 2 and Function::Parameters::_croak('Too many arguments for method transform_df (expected 2, got ' . @_ . ')') 0 13 13
77 13 ▶ return if $df->isempty;
Branch: 1 branch
BranchTrueFalseTotal
if $df->isempty 0 13 13
78  
79 13 my $aesthetics = $self->aesthetics->intersect( $df->names );
80 my @transformed =
81 map {
82 13 my $col_raw = $df->at($_);
83 (
84 13 ▶ $_ => $self->transform($col_raw),
Branch: 1 branch
BranchTrueFalseTotal
!$df->exists("${_}_raw") ? : 13 0 13
85 ( !$df->exists("${_}_raw") ? ( "${_}_raw" => $col_raw ) : () )
86 );
87 } @$aesthetics;
88 13 return \@transformed;
89 4 }
90  
91  
92 2 ▶method map_df ( $df, $i = undef ) {
Subroutine map_df: called CC=7 SCAR=20.5
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method map_df (expected 2, got ' . @_ . ')') 0 2 2
@_ > 3 and Function::Parameters::_croak('Too many arguments for method map_df (expected 3, got ' . @_ . ')') 0 2 2
93 2 ▶ return if ( $df->isempty );
Branch: 1 branch
BranchTrueFalseTotal
if $df->isempty 0 2 2
94  
95 2 my $aesthetics = $self->aesthetics->intersect($df->names);
96 2 ▶ return if ( $aesthetics->isempty );
Branch: 1 branch
BranchTrueFalseTotal
if $aesthetics->isempty 0 2 2
97  
98 my @mapped = map {
99 2 ▶ my $col_raw = defined $i ? $df->at($_)->select_rows($i) : $df->at($_);
Branch: 1 branch
BranchTrueFalseTotal
defined $i ? : 0 2 2
100 (
101 2 ▶ $_ => $self->map_to_limits($col_raw),
Branch: 1 branch
BranchTrueFalseTotal
!$df->exists("${_}_raw") ? : 0 2 2
102 ( !$df->exists("${_}_raw") ? ( "${_}_raw" => $col_raw ) : () ),
103 );
104 } ( $aesthetics->flatten );
105 2 return \@mapped;
106 4 }
107  
108 4 requires 'map_to_limits';
109  
110 56 ▶method get_limits () {
Subroutine get_limits: called CC=5 SCAR=16.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method get_limits (expected 1, got ' . @_ . ')') 0 56 56
@_ > 1 and Function::Parameters::_croak('Too many arguments for method get_limits (expected 1, got ' . @_ . ')') 0 56 56
111 56 ▶ return pdl( [ 0, 1 ] ) if $self->isempty;
Branch: 1 branch
BranchTrueFalseTotal
if $self->isempty 4 52 56
112  
113 52 ▶ if ( !$self->limits->isempty ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->limits->isempty) { } 10 42 52
114 10 my $limits = $self->limits->copy;
115 10 return ifelse( $limits->isgood, $limits, $self->range->range );
116 }
117 else {
118 42 return $self->range->range;
119 }
120 4 }
121  
122 # Here to make it possible for scales to modify the default titles
123 0 ▶method make_title ($title) { $title; }
Subroutine make_title: not called CC=3 SCAR=22.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method make_title (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for method make_title (expected 2, got ' . @_ . ')') 0 0 0
124 0 ▶method make_sec_title ($title) { $title; }
Subroutine make_sec_title: not called CC=3 SCAR=22.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method make_sec_title (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for method make_sec_title (expected 2, got ' . @_ . ')') 0 0 0
125  
126 4 1;
127  
128 __END__
« Chart/GGPlot/Range/Discrete.pm ↑ Summary Chart/GGPlot/Scale/ContinuousDateTime.pm »