| 1 | package Chart::GGPlot::Geom::Path; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Class for path geom | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Chart::GGPlot::Class qw(:pdl); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use MooseX::Singleton; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 5 | our $VERSION = '0.002003'; # VERSION | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use List::AllUtils qw(reduce); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use PDL::Primitive qw(which); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Chart::GGPlot::Aes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Chart::GGPlot::Layer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use Chart::GGPlot::Util qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Chart::GGPlot::Util::Pod qw(layer_func_pod); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 5 | with qw(Chart::GGPlot::Geom); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | has '+non_missing_aes' => ( default => sub { [qw(size shape color)] } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | has '+default_aes' => ( | ||||||||||||||||||||||||||||
| 23 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | Chart::GGPlot::Aes->new( | |||||||||||||||||||||||||||
| 25 | color => PDL::SV->new( ['black'] ), | ||||||||||||||||||||||||||||
| 26 | size => pdl(0.5), | ||||||||||||||||||||||||||||
| 27 | linetype => PDL::SV->new( ['solid'] ), | ||||||||||||||||||||||||||||
| 28 | alpha => NA(), | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 5 | ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 4 | ▶ | classmethod required_aes () { [qw(x y)] } | ||||||||||||||||||||||||||
|
Subroutine
required_aes: called CC=3 SCAR=11.2
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | my $geom_path_pod = layer_func_pod(<<'EOT'); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | geom_path(:$mapping=undef, :$data=undef, :$stat='identity', | ||||||||||||||||||||||||||||
| 38 | :$position='identity', :$na_rm=false, :$show_legend=undef, | ||||||||||||||||||||||||||||
| 39 | :$inherit_aes=true, | ||||||||||||||||||||||||||||
| 40 | %rest) | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | The "path" geom connects the observations in the order in which they | ||||||||||||||||||||||||||||
| 43 | appear in the data. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =over 4 | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | %TMPL_COMMON_ARGS% | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =back | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | EOT | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $geom_path_code = fun ( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
Branch: 1 branch
Condition0%0/3
@_ > 0 and @_ % 2
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0
@_ % 2
Truth table0%0/3
A and B
A= @_ > 0B= @_ % 2
| |||||||||||||||||||||||||||||
| 54 | :$mapping = undef, :$data = undef, | ||||||||||||||||||||||||||||
| 55 | :$stat = 'identity', :$position = 'identity', | ||||||||||||||||||||||||||||
| 56 | :$na_rm = false, | ||||||||||||||||||||||||||||
| 57 | :$show_legend = undef, :$inherit_aes = true, | ||||||||||||||||||||||||||||
| 58 | %rest ) | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 60 | 0 | return Chart::GGPlot::Layer->new( | |||||||||||||||||||||||||||
| 61 | data => $data, | ||||||||||||||||||||||||||||
| 62 | mapping => $mapping, | ||||||||||||||||||||||||||||
| 63 | stat => $stat, | ||||||||||||||||||||||||||||
| 64 | position => $position, | ||||||||||||||||||||||||||||
| 65 | show_legend => $show_legend, | ||||||||||||||||||||||||||||
| 66 | inherit_aes => $inherit_aes, | ||||||||||||||||||||||||||||
| 67 | geom => 'path', | ||||||||||||||||||||||||||||
| 68 | params => { na_rm => $na_rm, %rest }, | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | 5 | }; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 5 | ▶ | classmethod ggplot_functions() { | ||||||||||||||||||||||||||
|
Subroutine
ggplot_functions: called CC=3 SCAR=11.3
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 73 | return [ | ||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | 5 | name => 'geom_path', | |||||||||||||||||||||||||||
| 76 | code => $geom_path_code, | ||||||||||||||||||||||||||||
| 77 | pod => $geom_path_pod, | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | ]; | ||||||||||||||||||||||||||||
| 80 | 5 | } | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | method handle_na ($data, $params) { | ||||||||||||||||||||||||||
|
Subroutine
handle_na: not called CC=6 SCAR=37.4
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # Drop missing values at the start or end of a line - can't drop in the | ||||||||||||||||||||||||||||
| 85 | # middle since you expect those to be shown by a break in the line | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # are each row all good or not? | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | state $complete_cases = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 89 | 0 | my @piddles = @_; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my @isgood = map { $_->badflag ? $_->isgood : () } @piddles; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ( @isgood == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | return PDL::Core::ones( $piddles[0]->length ); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return ( reduce { $a & $b } ( shift @isgood ), @isgood ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 0 | }; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # group by $grouping and average by $fun | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | state $ave = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 102 | 0 | my ( $x, $grouping, $fun ) = @_; | |||||||||||||||||||||||||||
| 103 | 0 | my $new = $x->copy; | |||||||||||||||||||||||||||
| 104 | 0 | for my $g ( $grouping->uniq->flatten ) { | |||||||||||||||||||||||||||
| 105 | 0 | my $sliced = $new->where( $x == $g ); | |||||||||||||||||||||||||||
| 106 | 0 | my $averaged = $fun->($sliced); | |||||||||||||||||||||||||||
| 107 | 0 | $sliced .= $averaged; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 0 | return $new; | |||||||||||||||||||||||||||
| 110 | 0 | }; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | my $complete = | ||||||||||||||||||||||||||||
| 113 | 0 | $complete_cases->( map { $data->at($_) } qw(x y size color linetype) ); | |||||||||||||||||||||||||||
| 114 | my $kept = $ave->( $complete, $data->at('group'), | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub { $self->_keep_mid_true(@_) } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ( not $kept->all and not $params->{na_rm} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$kept->all or $params->{"na_rm"}
MC/DC0%0/2
$kept->all or $params->{"na_rm"}
$kept->all
$params->{"na_rm"}
Truth table0%0/3
A or B
A= $kept->allB= $params->{"na_rm"}
| |||||||||||||||||||||||||||||
| 118 | 0 | warn sprintf( "Removed %s rows containing missing values (geom_path).", | |||||||||||||||||||||||||||
| 119 | ( !$kept )->sum ); | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return ( $kept->all ? $data : $data->select_rows( which($kept) ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 5 | } | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # Trim false values from left and right: keep all values from | ||||||||||||||||||||||||||||
| 126 | # first TRUE to last TRUE | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | classmethod _keep_mid_true ($x) { | ||||||||||||||||||||||||||
|
Subroutine
_keep_mid_true: not called CC=4 SCAR=30.0
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 128 | 0 | my $is_true = which($x); | |||||||||||||||||||||||||||
| 129 | 0 | ▶ | unless ( $is_true->length ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | return PDL::Core::zeros( $x->length ); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 0 | my $first = $is_true->at(0); | |||||||||||||||||||||||||||
| 133 | 0 | my $last = $is_true->at(-1); | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | return pdl( | |||||||||||||||||||||||||||
| 136 | ( (0) x $first ), | ||||||||||||||||||||||||||||
| 137 | ( (1) x ( $last - $first ) ), | ||||||||||||||||||||||||||||
| 138 | ( (0) x ( $x->length - $last ) ) | ||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||
| 140 | 5 | } | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 5 | 1; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||