Chart/GGPlot/Range/Discrete.pm

filter: Statementstmt 100% 37 / 37 Branchbran 71.4% 10 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 91.5% 54 / 59 CC 8 SCAR 16.3
CC
8
Cov
92%
train
8.2
BEGIN
1.0
BEGIN
1.0
CRAP 5.1
« Chart/GGPlot/Limits.pm ↑ Summary Chart/GGPlot/Scale.pm »
1 package Chart::GGPlot::Range::Discrete;
2  
3 # ABSTRACT: Discrete range
4  
5 8 ▶use Chart::GGPlot::Class qw(:pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 our $VERSION = '0.002003'; # VERSION
9  
10 8 with qw(Chart::GGPlot::Range);
11  
12 7 ▶sub _build_range { PDL::SV->new([]); }
Subroutine _build_range: called CC=1 SCAR=0.0
13  
14 8 ▶use List::AllUtils qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Types::PDL -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 8 ▶use Chart::GGPlot::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # See R scales package train_descrete() method
20 5 ▶method train($p, $drop = false, $na_rm = false ) {
Subroutine train: called CC=8 SCAR=21.0
Pod undocumented
Branch: 4 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method train (expected 2, got ' . @_ . ')') 0 5 5
@_ > 4 and Function::Parameters::_croak('Too many arguments for method train (expected 4, got ' . @_ . ')') 0 5 5
@_ < 3 and do { @_ < 2 and $drop = &false(); $na_rm = &false() } 2 3 5
@_ < 2 and $drop = &false() 2 0 2
21 5 ▶ return $self->range if $p->isempty;
Branch: 1 branch
BranchTrueFalseTotal
if $p->isempty 0 5 5
22  
23 5 ▶ unless (is_discrete($p)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_discrete($p)) 1 4 5
24 1 die "Continuous value supplied to discrete scale";
25 }
26
27 4 my @range = @{ $self->range->unpdl };
28 4 ▶ if ( $p->$_DOES('PDL::Factor') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->$Chart::GGPlot::Range::Discrete::_DOES('PDL::Factor')) { } 2 2 4
29 # TODO: This may be incorrect.
30 2 push @range, $p->levels->flatten;
31 2 $self->range( ref($p)->new( [ uniq(@range) ] ) );
32 }
33 else {
34 2 push @range, $p->flatten;
35 2 $self->range( ref($p)->new( [ sort(uniq(@range)) ] ) );
36 }
37  
38 4 return $self->range;
39 8 }
40  
41 8 __PACKAGE__->meta->make_immutable;
42  
43 8 1;
44  
45 __END__
« Chart/GGPlot/Limits.pm ↑ Summary Chart/GGPlot/Scale.pm »