| 1 | package Chart::GGPlot::Limits; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Functions for applying limits to the scales | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Chart::GGPlot::Setup qw(:base :pdl); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.002003'; # VERSION | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Data::Frame; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use List::AllUtils qw(pairmap); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Type::Params; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Types::Standard; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Types::PDL qw(Piddle1D PiddleFromAny); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Chart::GGPlot::Aes::Functions qw(aes_all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Chart::GGPlot::Geom::Blank; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Chart::GGPlot::Scale::Functions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Chart::GGPlot::Types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Chart::GGPlot::Util qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use parent qw(Exporter::Tiny); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | my @export_ggplot = qw( | |||||||||||||||||||||||||||
| 24 | lims xlim ylim limits expand_limits ); | ||||||||||||||||||||||||||||
| 25 | 3 | our @EXPORT_OK = @export_ggplot; | |||||||||||||||||||||||||||
| 26 | 3 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 27 | all => \@EXPORT_OK, | ||||||||||||||||||||||||||||
| 28 | ggplot => \@export_ggplot, | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | fun lims (%pairs) { | ||||||||||||||||||||||||||
|
Subroutine
lims: not called CC=3 SCAR=24.8
Pod
documented
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
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my @mapped = pairmap { limits( $a => $b ) } ( %pairs ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 34 | 0 | return \@mapped; | |||||||||||||||||||||||||||
| 35 | 3 | } | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | fun xlim (@v) { limits( x => \@v ); } | ||||||||||||||||||||||||||
|
Subroutine
xlim: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | fun ylim (@v) { limits( y => \@v ); } | ||||||||||||||||||||||||||
|
Subroutine
ylim: not called CC=1 SCAR=3.5
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | fun limits ( $var, $lims ) { | ||||||||||||||||||||||||||
|
Subroutine
limits: called CC=5 SCAR=17.8
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 43 | 1 | state $check = | |||||||||||||||||||||||||||
| 44 | Type::Params::compile( Piddle1D->plus_coercions(PiddleFromAny) ); | ||||||||||||||||||||||||||||
| 45 | 1 | ($lims) = $check->($lims); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | if (is_discrete($lims)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 48 | 0 | return _limits_factor( $var, $lims ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | elsif ( $lims->$_DOES('PDL::DateTime') ) { | ||||||||||||||||||||||||||||
| 51 | 0 | return _limits_date( $var, $lims ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||
| 54 | 1 | return _limits_numeric( $var, $lims ); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 3 | } | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | fun _check_limits_size ( $lims, $expected_size = 2 ) { | ||||||||||||||||||||||||||
|
Subroutine
_check_limits_size: called CC=5 SCAR=18.1
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 59 | 1 | ▶ | unless ( $lims->length == $expected_size ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | croak "size of limits is not 2"; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 3 | } | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | fun _limits_numeric ( $var, $lims ) { | ||||||||||||||||||||||||||
|
Subroutine
_limits_numeric: called CC=5 SCAR=17.1
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 65 | 1 | state $check = Type::Params::compile( | |||||||||||||||||||||||||||
| 66 | Piddle1D->plus_coercions(PiddleFromAny) | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | 1 | ($lims) = $check->($lims); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | _check_limits_size($lims); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | ▶ | my $trans = | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$lims->nbad == 0 and $lims->at(0) > $lims->at(1)
MC/DC0%0/2
$lims->nbad == 0 and $lims->at(0) > $lims->at(1)
$lims->nbad == 0
$lims->at(0) > $lims->at(1)
Truth table33%1/3
A and B
A= $lims->nbad == 0B= $lims->at(0) > $lims->at(1)
| |||||||||||||||||||||||||||||
| 73 | ( $lims->nbad == 0 && $lims->at(0) > $lims->at(1) ) | ||||||||||||||||||||||||||||
| 74 | ? "reverse" | ||||||||||||||||||||||||||||
| 75 | : "identity"; | ||||||||||||||||||||||||||||
| 76 | 1 | return _make_scale( "continuous", $var, limits => $lims, trans => $trans ); | |||||||||||||||||||||||||||
| 77 | 3 | } | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | fun _limits_factor ( $var, $lims ) { | ||||||||||||||||||||||||||
|
Subroutine
_limits_factor: not called CC=3 SCAR=24.8
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 80 | 0 | return _make_scale( "discrete", $var, limits => $lims ); | |||||||||||||||||||||||||||
| 81 | 3 | } | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | fun _limits_date ( $var, $lims ) { | ||||||||||||||||||||||||||
|
Subroutine
_limits_date: not called CC=3 SCAR=24.8
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 84 | 0 | _check_limits_size($lims); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | return _make_scale( "discrete", $var, limits => $lims ); | |||||||||||||||||||||||||||
| 87 | 3 | } | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | fun _make_scale ( $type, $var, @rest ) { | ||||||||||||||||||||||||||
|
Subroutine
_make_scale: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 1 | my $scale_name = "scale_${var}_${type}"; | |||||||||||||||||||||||||||
| 91 | 1 | my $scale_f; | |||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 1 | $scale_f = \&{"Chart::GGPlot::Scale::Functions::$scale_name"}; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 1 | return $scale_f->(@rest); | |||||||||||||||||||||||||||
| 97 | 3 | } | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | fun expand_limits (%params) { | ||||||||||||||||||||||||||
|
Subroutine
expand_limits: not called CC=3 SCAR=24.8
Pod
documented
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
| |||||||||||||||||||||||||||||
| 101 | 0 | my $data = Data::Frame->new( columns => \%params ); | |||||||||||||||||||||||||||
| 102 | 0 | return Chart::GGPlot::Geom::Blank->new( | |||||||||||||||||||||||||||
| 103 | mapping => aes_all( $data->names ), | ||||||||||||||||||||||||||||
| 104 | data => $data, | ||||||||||||||||||||||||||||
| 105 | inherit_aes => false, | ||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||
| 107 | 3 | } | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 3 | 1; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||