Chart/GGPlot/Scale/DiscretePosition.pm

filter: Statementstmt 97.1% 69 / 71 Branchbran 61.9% 26 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 6 totaltotal 81.8% 108 / 132 CC 22 SCAR 14.7
CC
22
Cov
84%
dimension
7.8
get_limits
5.2
map_to_limits
5.2
CRAP 4.4
« Chart/GGPlot/Scale/ContinuousPosition.pm ↑ Summary Chart/GGPlot/Position.pm »
1 package Chart::GGPlot::Scale::DiscretePosition;
2  
3 # ABSTRACT: Discrete position scale
4  
5 2 ▶use Chart::GGPlot::Class qw(:pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.002003'; # VERSION
9  
10 2 ▶use Types::PDL qw(Piddle PiddleFromAny);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Types::Standard qw(Any InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use Chart::GGPlot::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 extends qw(
16 Chart::GGPlot::Scale::Discrete
17 );
18  
19 2 with qw(
20 Chart::GGPlot::Scale::Positional
21 );
22  
23 has '+limits' => (
24 isa => ( InstanceOf ["PDL::SV"] )
25 1 ▶ ->plus_coercions( Any, sub { PDL::SV->new($_) } ),
Subroutine __ANON__: called CC=1 SCAR=0.0
26 coerce => 1,
27 );
28  
29 8 ▶method train ($p) {
Subroutine train: called CC=4 SCAR=14.0
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method train (expected 2, got ' . @_ . ')') 0 8 8
@_ > 2 and Function::Parameters::_croak('Too many arguments for method train (expected 2, got ' . @_ . ')') 0 8 8
30 8 ▶ if ( is_discrete($p) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_discrete($p)) { } 2 6 8
31 2 return $self->range->train( $p, $self->drop, !$self->na_translate );
32 }
33 else {
34 6 return $self->range_c->train($p);
35 }
36 2 }
37  
38 26 ▶method get_limits () {
Subroutine get_limits: called CC=5 SCAR=16.6
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method get_limits (expected 1, got ' . @_ . ')') 0 26 26
@_ > 1 and Function::Parameters::_croak('Too many arguments for method get_limits (expected 1, got ' . @_ . ')') 0 26 26
39 26 ▶ return pdl( [ 0, 1 ] ) if ( $self->isempty );
Branch: 1 branch
BranchTrueFalseTotal
if $self->isempty 0 26 26
40 26 ▶ return ( $self->limits->isempty ? $self->range->range : $self->limits );
Branch: 1 branch
BranchTrueFalseTotal
$self->limits->isempty ? : 16 10 26
41 2 }
42  
43 42 ▶method isempty () {
Subroutine isempty: called CC=3 SCAR=11.2
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method isempty (expected 1, got ' . @_ . ')') 0 42 42
@_ > 1 and Function::Parameters::_croak('Too many arguments for method isempty (expected 1, got ' . @_ . ')') 0 42 42
44 60 ▶ return List::AllUtils::all { $_->isempty }
Subroutine __ANON__: called CC=1 SCAR=0.0
45 42 ( $self->range->range, $self->limits, $self->range_c->range );
46 2 }
47  
48 2 ▶method reset () {
Subroutine reset: called CC=3 SCAR=11.3
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method reset (expected 1, got ' . @_ . ')') 0 2 2
@_ > 1 and Function::Parameters::_croak('Too many arguments for method reset (expected 1, got ' . @_ . ')') 0 2 2
49  
50 # Can't reset discrete scale because no way to recover values
51 2 $self->range_c->reset();
52 2 }
53  
54 12 ▶method map_to_limits ( $p, $limits = $self->get_limits ) {
Subroutine map_to_limits: called CC=5 SCAR=16.6
Pod undocumented
Branch: 3 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method map_to_limits (expected 2, got ' . @_ . ')') 0 12 12
@_ > 3 and Function::Parameters::_croak('Too many arguments for method map_to_limits (expected 3, got ' . @_ . ')') 0 12 12
@_ < 2 and $limits = $self->get_limits 12 0 12
55 return (
56 12 ▶ is_discrete($p)
Branch: 1 branch
BranchTrueFalseTotal
is_discrete($p) ? : 6 6 12
57 ? pdl( [ 0 .. $limits->length - 1 ] )
58 ->slice( match( $p, $limits ) )
59 : $p
60 );
61 2 }
62  
63 3 ▶method dimension ( $expand = pdl([0, 0, 0, 0]) ) {
Subroutine dimension: called CC=7 SCAR=20.5
Pod undocumented
Branch: 3 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method dimension (expected 1, got ' . @_ . ')') 0 3 3
@_ > 2 and Function::Parameters::_croak('Too many arguments for method dimension (expected 2, got ' . @_ . ')') 0 3 3
@_ < 1 and $expand = pdl([0, 0, 0, 0]) 1 2 3
64 3 my $c_range = $self->range_c->range;
65 3 my $d_range = $self->get_limits();
66  
67 3 ▶ if ( $self->isempty ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->isempty) { } 0 3 3
elsif ($self->range->range->isempty) { } 1 2 3
elsif ($c_range->isempty) { } 0 2 2
68 0 return pdl([ 0, 1 ]);
69 }
70 elsif ( $self->range->range->isempty ) { # only continuous
71 1 return expand_range4( $c_range, $expand );
72 }
73 elsif ( $c_range->isempty ) { # only discrete
74 0 return expand_range4( [ 0, $d_range->length - 1 ], $expand );
75 }
76 else { # both
77 2 return range_(
78 $c_range->glue(
79 0, expand_range4( [ 0, $d_range->length - 1 ], $expand )
80 )
81 );
82 }
83 2 }
84  
85 2 __PACKAGE__->meta->make_immutable;
86  
87 2 1;
88  
89 __END__
« Chart/GGPlot/Scale/ContinuousPosition.pm ↑ Summary Chart/GGPlot/Position.pm »