| 1 | package Chart::GGPlot::Aes::Functions; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Function interface for aesthetics mappings | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use Chart::GGPlot::Setup qw(:base :pdl); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 13 | our $VERSION = '0.002003'; # VERSION | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Eval::Quosure; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use List::AllUtils qw(pairmap); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Type::Params; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use Types::Standard qw(ArrayRef); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use Chart::GGPlot::Aes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 13 | ▶ | use Chart::GGPlot::Types qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 13 | ▶ | use Chart::GGPlot::Util qw(arraylike); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use parent qw(Exporter::Tiny); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 13 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 22 | aes aes_all aes_to_scale is_position_aes | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | 13 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 25 | 'all' => \@EXPORT_OK, | ||||||||||||||||||||||||||||
| 26 | 'ggplot' => [qw(aes aes_all)], | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 17 | ▶ | fun aes (%mapping) { _aes( \%mapping ); } | ||||||||||||||||||||||||||
|
Subroutine
aes: called CC=3 SCAR=11.8
Pod
documented
Branch: 1 branch
Condition33%1/3
@_ > 0 and @_ % 2
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0
@_ % 2
Truth table33%1/3
A and B
A= @_ > 0B= @_ % 2
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 13 | my $aes_level_default = 3; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 18 | ▶ | fun _aes ($mapping, $level=$aes_level_default) { | ||||||||||||||||||||||||||
|
Subroutine
_aes: called CC=4 SCAR=14.0
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 35 | 34 | ▶ | my %params = pairmap { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 36 | 34 | my $val; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # TODO: Shall we also support coderef sub { my ($df) = @_; } ? | ||||||||||||||||||||||||||||
| 39 | # Thing is, is that really needed? | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 34 | ▶ | if ( $b->$_DOES('Eval::Quosure') or arraylike($b)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$b->$Chart::GGPlot::Aes::Functions::_DOES("Eval::Quosure") or arraylike($b)
MC/DC50%1/2
$b->$Chart::GGPlot::Aes::Functions::_DOES("Eval::Quosure") or arraylike($b)
$b->$Chart::GGPlot::Aes::Functions::_DOES("Eval::Quosure")
arraylike($b)
Truth table66%2/3
A or B
A= $b->$Chart::GGPlot::Aes::Functions::_DOES("Eval::Quosure")B= arraylike($b)
| |||||||||||||||||||||||||||||
| 42 | 3 | $val = $b; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||
| 45 | 31 | $val = Eval::Quosure->new( $b . '', $level ); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 34 | $a => $val; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 18 | %$mapping; | |||||||||||||||||||||||||||
| 50 | 18 | return Chart::GGPlot::Aes->new(%params); | |||||||||||||||||||||||||||
| 51 | 13 | } | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # Look up the scale that should be used for a given aesthetic | ||||||||||||||||||||||||||||
| 54 | 24 | ▶ | fun aes_to_scale ($aesthetic) { | ||||||||||||||||||||||||||
|
Subroutine
aes_to_scale: called CC=5 SCAR=16.2
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 55 | 24 | $aesthetic = Chart::GGPlot::Aes->transform_key($aesthetic); | |||||||||||||||||||||||||||
| 56 | 24 | ▶ | return 'x' if ( $aesthetic =~ /^x(?:|min|max|end|intercept)$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 14 | ▶ | return 'y' if ( $aesthetic =~ /^y(?:|min|max|end|intercept)$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 4 | return $aesthetic; | |||||||||||||||||||||||||||
| 59 | 13 | } | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # Figure out if an aesthetic is a position aesthetic or not | ||||||||||||||||||||||||||||
| 62 | 1 | ▶ | fun is_position_aes ($aes_names) { | ||||||||||||||||||||||||||
|
Subroutine
is_position_aes: called CC=3 SCAR=11.1
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 63 | 1 | my @new_names = map { aes_to_scale($_) } @$aes_names; | |||||||||||||||||||||||||||
| 64 | 1 | ▶ | return ( List::AllUtils::all { $_ eq 'x' or $_ eq 'y' } @new_names ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 13 | } | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | ▶ | fun aes_all (@names) { | ||||||||||||||||||||||||||
|
Subroutine
aes_all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 1 | return _aes( { map { $_ => $_ } @names }, $aes_level_default ); | |||||||||||||||||||||||||||
| 70 | 13 | } | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 13 | 1; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||