| 1 | package Chart::GGPlot::Scale; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # ABSTRACT: The role for scale | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 4 | ▶ | use Chart::GGPlot::Role qw(:pdl); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 4 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 4 | our $VERSION = '0.002003'; # VERSION | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 4 | ▶ | use PDL::Primitive qw(which); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 4 | ▶ | use Types::PDL qw(Piddle PiddleFromAny); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 4 | ▶ | use Types::Standard qw(Any ArrayRef CodeRef Maybe Str InstanceOf ConsumerOf); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 4 | ▶ | use Type::Params; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | ▶ | use Chart::GGPlot::Trans; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 4 | ▶ | use Chart::GGPlot::Types qw(:all); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 4 | ▶ | use Chart::GGPlot::Util qw(:all); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 4 | has aesthetics => ( | |||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||
| 22 | isa => ArrayRef->plus_coercions(ArrayRefFromAny), | ||||||||||||||||||||
| 23 | coerce => 1, | ||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | 4 | has scale_name => ( is => 'ro', isa => Str, required => 1 ); | |||||||||||||||||||
| 27 | 4 | has palette => ( is => 'rw', isa => Maybe [CodeRef] ); | |||||||||||||||||||
| 28 | 0 | ▶ | has range => ( is => 'rw', isa => Piddle, default => sub { null; } ); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | has limits => ( | ||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||
| 32 | 0 | ▶ | default => sub { null; }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 33 | 4 | ); | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 4 | has na_value => ( is => 'rw', default => "nan" ); | |||||||||||||||||||
| 36 | 4 | has expand => ( is => 'rw', default => undef ); | |||||||||||||||||||
| 37 | 4 | has name => ( is => 'rw', default => undef ); | |||||||||||||||||||
| 38 | 4 | has breaks => ( is => 'rw', default => undef ); | |||||||||||||||||||
| 39 | 4 | has labels => | |||||||||||||||||||
| 40 | ( is => 'rw', isa => Maybe [ Piddle | CodeRef ], default => undef ); | ||||||||||||||||||||
| 41 | 4 | has guide => ( is => 'ro', default => "legend" ); | |||||||||||||||||||
| 42 | 4 | has position => ( is => 'rw', isa => PositionEnum, default => "left" ); | |||||||||||||||||||
| 43 | 4 | has trans => ( is => 'rw', isa => InstanceOf ["Chart::GGPlot::Trans"] ); | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 4 | requires 'train'; # Train an individual scale from a vector of data. | |||||||||||||||||||
| 46 | 4 | requires 'transform'; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 4 | requires 'get_breaks_minor'; | |||||||||||||||||||
| 49 | 4 | requires 'get_labels'; | |||||||||||||||||||
| 50 | 4 | requires 'break_info'; | |||||||||||||||||||
| 51 | 4 | requires 'dimension'; | |||||||||||||||||||
| 52 | 4 | requires 'get_breaks'; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | #requires 'clone'; | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 2 | ▶ | method train_df ($df) { | ||||||||||||||||||
|
Subroutine
train_df: called CC=5 SCAR=16.5
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||
| 58 | 2 | ▶ | return if $df->isempty; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 2 | my $aesthetics = $self->aesthetics->intersect($df->names); | |||||||||||||||||||
| 61 | 2 | for my $aesthetic (@$aesthetics) { | |||||||||||||||||||
| 62 | 2 | $self->train( $df->at($aesthetic) ); | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | 4 | } | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 9 | ▶ | method reset () { | ||||||||||||||||||
|
Subroutine
reset: called CC=3 SCAR=11.3
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||
| 68 | 9 | $self->range->reset; | |||||||||||||||||||
| 69 | 4 | } | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 77 | ▶ | method isempty () { | ||||||||||||||||||
|
Subroutine
isempty: called CC=4 SCAR=14.0
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||
| 72 | 77 | ▶ | return ( $self->range->range->isempty and $self->limits->isempty ); | ||||||||||||||||||
|
Condition100%3/3
$self->range->range->isempty && $self->limits->isempty
MC/DC100%2/2
$self->range->range->isempty && $self->limits->isempty
$self->range->range->isempty
$self->limits->isempty
Truth table100%3/3
A && B
A= $self->range->range->isemptyB= $self->limits->isempty
| |||||||||||||||||||||
| 73 | 4 | } | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 13 | ▶ | method transform_df ($df) { | ||||||||||||||||||
|
Subroutine
transform_df: called CC=5 SCAR=16.6
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||
| 77 | 13 | ▶ | return if $df->isempty; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 13 | my $aesthetics = $self->aesthetics->intersect( $df->names ); | |||||||||||||||||||
| 80 | my @transformed = | ||||||||||||||||||||
| 81 | map { | ||||||||||||||||||||
| 82 | 13 | my $col_raw = $df->at($_); | |||||||||||||||||||
| 83 | ( | ||||||||||||||||||||
| 84 | 13 | ▶ | $_ => $self->transform($col_raw), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | ( !$df->exists("${_}_raw") ? ( "${_}_raw" => $col_raw ) : () ) | ||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||
| 87 | } @$aesthetics; | ||||||||||||||||||||
| 88 | 13 | return \@transformed; | |||||||||||||||||||
| 89 | 4 | } | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 2 | ▶ | method map_df ( $df, $i = undef ) { | ||||||||||||||||||
|
Subroutine
map_df: called CC=7 SCAR=20.5
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||
| 93 | 2 | ▶ | return if ( $df->isempty ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 2 | my $aesthetics = $self->aesthetics->intersect($df->names); | |||||||||||||||||||
| 96 | 2 | ▶ | return if ( $aesthetics->isempty ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | my @mapped = map { | ||||||||||||||||||||
| 99 | 2 | ▶ | my $col_raw = defined $i ? $df->at($_)->select_rows($i) : $df->at($_); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | ( | ||||||||||||||||||||
| 101 | 2 | ▶ | $_ => $self->map_to_limits($col_raw), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | ( !$df->exists("${_}_raw") ? ( "${_}_raw" => $col_raw ) : () ), | ||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||
| 104 | } ( $aesthetics->flatten ); | ||||||||||||||||||||
| 105 | 2 | return \@mapped; | |||||||||||||||||||
| 106 | 4 | } | |||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 4 | requires 'map_to_limits'; | |||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 56 | ▶ | method get_limits () { | ||||||||||||||||||
|
Subroutine
get_limits: called CC=5 SCAR=16.2
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||
| 111 | 56 | ▶ | return pdl( [ 0, 1 ] ) if $self->isempty; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 52 | ▶ | if ( !$self->limits->isempty ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 10 | my $limits = $self->limits->copy; | |||||||||||||||||||
| 115 | 10 | return ifelse( $limits->isgood, $limits, $self->range->range ); | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | else { | ||||||||||||||||||||
| 118 | 42 | return $self->range->range; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | 4 | } | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | # Here to make it possible for scales to modify the default titles | ||||||||||||||||||||
| 123 | 0 | ▶ | method make_title ($title) { $title; } | ||||||||||||||||||
|
Subroutine
make_title: not called CC=3 SCAR=22.8
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||
| 124 | 0 | ▶ | method make_sec_title ($title) { $title; } | ||||||||||||||||||
|
Subroutine
make_sec_title: not called CC=3 SCAR=22.8
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 4 | 1; | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||