| 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
| |||||||||||||||||||
| 30 | 8 | ▶ | if ( is_discrete($p) ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 39 | 26 | ▶ | return pdl( [ 0, 1 ] ) if ( $self->isempty ); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 40 | 26 | ▶ | return ( $self->limits->isempty ? $self->range->range : $self->limits ); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 41 | 2 | } | |||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | 42 | ▶ | method isempty () { | ||||||||||||||||
|
Subroutine
isempty: called CC=3 SCAR=11.2
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 55 | return ( | ||||||||||||||||||
| 56 | 12 | ▶ | is_discrete($p) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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__ | ||||||||||||||||||