Chart/GGPlot/Limits.pm

filter: Statementstmt 75.8% 88 / 116 Branchbran 33.3% 12 / 36 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 75.0% 18 / 24 Podpod 100% 5 / 5 totaltotal 63.2% 124 / 196 CC 22 SCAR 17.3
CC
22
Cov
63%
lims
12.0
_limits_factor
12.0
_limits_date
12.0
CRAP 5.6
« Chart/GGPlot/Theme/ElementTree.pm ↑ Summary Chart/GGPlot/Range/Discrete.pm »
1 package Chart::GGPlot::Limits;
2  
3 # ABSTRACT: Functions for applying limits to the scales
4  
5 3 ▶use Chart::GGPlot::Setup qw(:base :pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.002003'; # VERSION
8  
9 3 ▶use Data::Frame;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use List::AllUtils qw(pairmap);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Type::Params;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Types::Standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Types::PDL qw(Piddle1D PiddleFromAny);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use Chart::GGPlot::Aes::Functions qw(aes_all);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Chart::GGPlot::Geom::Blank;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Chart::GGPlot::Scale::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Chart::GGPlot::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Chart::GGPlot::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 ▶use parent qw(Exporter::Tiny);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 my @export_ggplot = qw(
24 lims xlim ylim limits expand_limits );
25 3 our @EXPORT_OK = @export_ggplot;
26 3 our %EXPORT_TAGS = (
27 all => \@EXPORT_OK,
28 ggplot => \@export_ggplot,
29 );
30  
31  
32 0 ▶fun lims (%pairs) {
Subroutine lims: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun lims") 0 0 0
Condition0%0/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
000
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table0%0/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
33 0 ▶ my @mapped = pairmap { limits( $a => $b ) } ( %pairs );
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 return \@mapped;
35 3 }
36  
37  
38 1 ▶fun xlim (@v) { limits( x => \@v ); }
Subroutine xlim: called CC=1 SCAR=0.0
Pod documented
39 0 ▶fun ylim (@v) { limits( y => \@v ); }
Subroutine ylim: not called CC=1 SCAR=3.5
Pod documented
40  
41  
42 1 ▶fun limits ( $var, $lims ) {
Subroutine limits: called CC=5 SCAR=17.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for fun limits (expected 2, got ' . @_ . ')') 0 1 1
@_ > 2 and Function::Parameters::_croak('Too many arguments for fun limits (expected 2, got ' . @_ . ')') 0 1 1
43 1 state $check =
44 Type::Params::compile( Piddle1D->plus_coercions(PiddleFromAny) );
45 1 ($lims) = $check->($lims);
46  
47 1 ▶ if (is_discrete($lims)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_discrete($lims)) { } 0 1 1
elsif ($lims->$Chart::GGPlot::Limits::_DOES('PDL::DateTime')) { } 0 1 1
48 0 return _limits_factor( $var, $lims );
49 }
50 elsif ( $lims->$_DOES('PDL::DateTime') ) {
51 0 return _limits_date( $var, $lims );
52 }
53 else {
54 1 return _limits_numeric( $var, $lims );
55 }
56 3 }
57  
58 1 ▶fun _check_limits_size ( $lims, $expected_size = 2 ) {
Subroutine _check_limits_size: called CC=5 SCAR=18.1
Branch: 3 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for fun _check_limits_size (expected 1, got ' . @_ . ')') 0 1 1
@_ > 2 and Function::Parameters::_croak('Too many arguments for fun _check_limits_size (expected 2, got ' . @_ . ')') 0 1 1
@_ < 2 and $expected_size = 2 1 0 1
59 1 ▶ unless ( $lims->length == $expected_size ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lims->length == $expected_size) 0 1 1
60 0 croak "size of limits is not 2";
61 }
62 3 }
63  
64 1 ▶fun _limits_numeric ( $var, $lims ) {
Subroutine _limits_numeric: called CC=5 SCAR=17.1
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for fun _limits_numeric (expected 2, got ' . @_ . ')') 0 1 1
@_ > 2 and Function::Parameters::_croak('Too many arguments for fun _limits_numeric (expected 2, got ' . @_ . ')') 0 1 1
65 1 state $check = Type::Params::compile(
66 Piddle1D->plus_coercions(PiddleFromAny)
67 );
68 1 ($lims) = $check->($lims);
69  
70 1 _check_limits_size($lims);
71  
72 1 ▶ my $trans =
Branch: 1 branch
BranchTrueFalseTotal
$lims->nbad == 0 && $lims->at(0) > $lims->at(1) ? : 0 1 1
Condition33%1/3
$lims->nbad == 0 and $lims->at(0) > $lims->at(1)
!ll&&!rl&&r
010
MC/DC0%0/2
$lims->nbad == 0 and $lims->at(0) > $lims->at(1)
$lims->nbad == 0 $lims->at(0) > $lims->at(1)
Truth table33%1/3
A and B
A= $lims->nbad == 0B= $lims->at(0) > $lims->at(1)
ABresult
0X0
100
111
73 ( $lims->nbad == 0 && $lims->at(0) > $lims->at(1) )
74 ? "reverse"
75 : "identity";
76 1 return _make_scale( "continuous", $var, limits => $lims, trans => $trans );
77 3 }
78  
79 0 ▶fun _limits_factor ( $var, $lims ) {
Subroutine _limits_factor: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for fun _limits_factor (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for fun _limits_factor (expected 2, got ' . @_ . ')') 0 0 0
80 0 return _make_scale( "discrete", $var, limits => $lims );
81 3 }
82  
83 0 ▶fun _limits_date ( $var, $lims ) {
Subroutine _limits_date: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for fun _limits_date (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for fun _limits_date (expected 2, got ' . @_ . ')') 0 0 0
84 0 _check_limits_size($lims);
85  
86 0 return _make_scale( "discrete", $var, limits => $lims );
87 3 }
88  
89 1 ▶fun _make_scale ( $type, $var, @rest ) {
Subroutine _make_scale: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for fun _make_scale (expected 2, got ' . @_ . ')') 0 1 1
90 1 my $scale_name = "scale_${var}_${type}";
91 1 my $scale_f;
92 {
93 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
94 1 $scale_f = \&{"Chart::GGPlot::Scale::Functions::$scale_name"};
95 }
96 1 return $scale_f->(@rest);
97 3 }
98  
99  
100 0 ▶fun expand_limits (%params) {
Subroutine expand_limits: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 0 and @_ % 2 and Function::Parameters::_croak("Odd number of paired arguments for fun expand_limits") 0 0 0
Condition0%0/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
000
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table0%0/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
101 0 my $data = Data::Frame->new( columns => \%params );
102 0 return Chart::GGPlot::Geom::Blank->new(
103 mapping => aes_all( $data->names ),
104 data => $data,
105 inherit_aes => false,
106 );
107 3 }
108  
109 3 1;
110  
111 __END__
« Chart/GGPlot/Theme/ElementTree.pm ↑ Summary Chart/GGPlot/Range/Discrete.pm »