Chart/GGPlot/Aes/Functions.pm

filter: Statementstmt 100% 75 / 75 Branchbran 70.8% 17 / 24 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 17 / 17 Podpod 50.0% 2 / 4 totaltotal 88.4% 115 / 130 CC 15 SCAR 10.0
CC
15
Cov
90%
aes_to_scale
5.0
_aes
4.0
aes
3.2
CRAP 2.7
« Chart/GGPlot/Backend.pm ↑ Summary Chart/GGPlot/Position/Dodge2.pm »
1 package Chart::GGPlot::Aes::Functions;
2  
3 # ABSTRACT: Function interface for aesthetics mappings
4  
5 13 ▶use Chart::GGPlot::Setup qw(:base :pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 our $VERSION = '0.002003'; # VERSION
8  
9 13 ▶use Eval::Quosure;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use List::AllUtils qw(pairmap);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use Type::Params;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use Types::Standard qw(ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 13 ▶use Chart::GGPlot::Aes;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 13 ▶use Chart::GGPlot::Types qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 13 ▶use Chart::GGPlot::Util qw(arraylike);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 13 ▶use parent qw(Exporter::Tiny);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 13 our @EXPORT_OK = qw(
22 aes aes_all aes_to_scale is_position_aes
23 );
24 13 our %EXPORT_TAGS = (
25 'all' => \@EXPORT_OK,
26 'ggplot' => [qw(aes aes_all)],
27 );
28  
29  
30 17 ▶fun aes (%mapping) { _aes( \%mapping ); }
Subroutine aes: called CC=3 SCAR=11.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun aes") 0 17 17
Condition33%1/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
0170
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table33%1/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
31  
32 13 my $aes_level_default = 3;
33  
34 18 ▶fun _aes ($mapping, $level=$aes_level_default) {
Subroutine _aes: called CC=4 SCAR=14.0
Branch: 3 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for fun _aes (expected 1, got ' . @_ . ')') 0 18 18
@_ > 2 and Function::Parameters::_croak('Too many arguments for fun _aes (expected 2, got ' . @_ . ')') 0 18 18
@_ < 2 and $level = $aes_level_default 17 1 18
35 34 ▶ my %params = pairmap {
Subroutine __ANON__: called CC=3 SCAR=11.0
36 34 my $val;
37  
38 # TODO: Shall we also support coderef sub { my ($df) = @_; } ?
39 # Thing is, is that really needed?
40  
41 34 ▶ if ( $b->$_DOES('Eval::Quosure') or arraylike($b)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b->$Chart::GGPlot::Aes::Functions::_DOES('Eval::Quosure') or arraylike($b)) { } 3 31 34
Condition66%2/3
$b->$Chart::GGPlot::Aes::Functions::_DOES("Eval::Quosure") or arraylike($b)
l!l&&r!l&&!r
3031
MC/DC50%1/2
$b->$Chart::GGPlot::Aes::Functions::_DOES("Eval::Quosure") or arraylike($b)
$b->$Chart::GGPlot::Aes::Functions::_DOES("Eval::Quosure") arraylike($b)
Truth table66%2/3
A or B
A= $b->$Chart::GGPlot::Aes::Functions::_DOES("Eval::Quosure")B= arraylike($b)
ABresult
1X1
011
000
42 3 $val = $b;
43 }
44 else {
45 31 $val = Eval::Quosure->new( $b . '', $level );
46 }
47 34 $a => $val;
48 }
49 18 %$mapping;
50 18 return Chart::GGPlot::Aes->new(%params);
51 13 }
52  
53 # Look up the scale that should be used for a given aesthetic
54 24 ▶fun aes_to_scale ($aesthetic) {
Subroutine aes_to_scale: called CC=5 SCAR=16.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for fun aes_to_scale (expected 1, got ' . @_ . ')') 0 24 24
@_ > 1 and Function::Parameters::_croak('Too many arguments for fun aes_to_scale (expected 1, got ' . @_ . ')') 0 24 24
55 24 $aesthetic = Chart::GGPlot::Aes->transform_key($aesthetic);
56 24 ▶ return 'x' if ( $aesthetic =~ /^x(?:|min|max|end|intercept)$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $aesthetic =~ /^x(?:|min|max|end|intercept)$/u 10 14 24
57 14 ▶ return 'y' if ( $aesthetic =~ /^y(?:|min|max|end|intercept)$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $aesthetic =~ /^y(?:|min|max|end|intercept)$/u 10 4 14
58 4 return $aesthetic;
59 13 }
60  
61 # Figure out if an aesthetic is a position aesthetic or not
62 1 ▶fun is_position_aes ($aes_names) {
Subroutine is_position_aes: called CC=3 SCAR=11.1
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for fun is_position_aes (expected 1, got ' . @_ . ')') 0 1 1
@_ > 1 and Function::Parameters::_croak('Too many arguments for fun is_position_aes (expected 1, got ' . @_ . ')') 0 1 1
63 1 my @new_names = map { aes_to_scale($_) } @$aes_names;
64 1 ▶ return ( List::AllUtils::all { $_ eq 'x' or $_ eq 'y' } @new_names );
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "x" or $_ eq "y" 1 1 2
65 13 }
66  
67  
68 1 ▶fun aes_all (@names) {
Subroutine aes_all: called CC=1 SCAR=0.0
Pod documented
69 1 return _aes( { map { $_ => $_ } @names }, $aes_level_default );
70 13 }
71  
72 13 1;
73  
74 __END__
« Chart/GGPlot/Backend.pm ↑ Summary Chart/GGPlot/Position/Dodge2.pm »