| 1 | package Chart::GGPlot::Geom; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | # ABSTRACT: The geom role | ||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | 6 | ▶ | use Chart::GGPlot::Role qw(:pdl); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 6 | ▶ | use namespace::autoclean; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | |||||||||||||||||||
| 8 | 6 | our $VERSION = '0.002003'; # VERSION | |||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 6 | ▶ | use Data::Frame::Util qw(guess_and_convert_to_pdl); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 6 | ▶ | use Types::Standard qw(ArrayRef CodeRef); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 6 | ▶ | use Chart::GGPlot::Aes; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 14 | 6 | ▶ | use Chart::GGPlot::Util qw(:all); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 6 | with qw( | |||||||||||||||||
| 17 | Chart::GGPlot::HasRequiredAes | ||||||||||||||||||
| 18 | Chart::GGPlot::HasDefaultAes | ||||||||||||||||||
| 19 | Chart::GGPlot::HasNonMissingAes | ||||||||||||||||||
| 20 | Chart::GGPlot::HasParams | ||||||||||||||||||
| 21 | Chart::GGPlot::HasCollectibleFunctions | ||||||||||||||||||
| 22 | ); | ||||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | 26 | ▶ | classmethod optional_aes() { [] } | ||||||||||||||||
|
Subroutine
optional_aes: called CC=3 SCAR=11.2
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | 3 | ▶ | method setup_data ($data, $params) { $data } | ||||||||||||||||
|
Subroutine
setup_data: called CC=3 SCAR=11.2
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | # Renders a single legend key. | ||||||||||||||||||
| 29 | 0 | ▶ | sub draw_key { return draw_key_point(@_) } | ||||||||||||||||
|
Subroutine
draw_key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | 0 | ▶ | method handle_na ( $data, $params ) { | ||||||||||||||||
|
Subroutine
handle_na: not called CC=3 SCAR=24.8
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||
| 32 | return remove_missing( | ||||||||||||||||||
| 33 | $data, | ||||||||||||||||||
| 34 | na_rm => $params->at('na_rm'), | ||||||||||||||||||
| 35 | 0 | vars => [ @{ $self->required_aes }, @{ $self->non_missing_aes } ], | |||||||||||||||||
| 36 | name => $self->name | ||||||||||||||||||
| 37 | ); | ||||||||||||||||||
| 38 | 6 | } | |||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | # Combine data with defaults and set aesthetics from parameters | ||||||||||||||||||
| 41 | 6 | ▶ | method use_defaults ( $data, $params = {} ) { | ||||||||||||||||
|
Subroutine
use_defaults: called CC=10 SCAR=26.7
Pod
undocumented
Branch: 3 branches
| |||||||||||||||||||
| 42 | 6 | ▶ | if ( $data->isempty ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | # create $data from $self->default_aes | ||||||||||||||||||
| 45 | #$data = $self->default_aes->get(); | ||||||||||||||||||
| 46 | } | ||||||||||||||||||
| 47 | else { | ||||||||||||||||||
| 48 | # Fill in missing aesthetics with their defaults | ||||||||||||||||||
| 49 | 6 | my $missing_aes = $self->default_aes->names->setdiff( $data->names ); | |||||||||||||||||
| 50 | |||||||||||||||||||
| 51 | 6 | for my $name ( sort @$missing_aes ) { | |||||||||||||||||
| 52 | 31 | my $default = $self->default_aes->at($name); | |||||||||||||||||
| 53 | 31 | ▶ | next unless defined $default; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 54 | 31 | $data->set( $name, $default ); | |||||||||||||||||
| 55 | } | ||||||||||||||||||
| 56 | } | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | # Override mappings with params | ||||||||||||||||||
| 59 | 6 | my $aes_names = $self->aesthetics->intersect( $params->keys ); | |||||||||||||||||
| 60 | 6 | my $aes_params = $params->hslice($aes_names); | |||||||||||||||||
| 61 | 6 | for my $aes (@$aes_names) { | |||||||||||||||||
| 62 | 0 | my $val = $aes_params->at($aes); | |||||||||||||||||
| 63 | 0 | ▶ | unless ($val->$_DOES('PDL')) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 64 | 0 | $val = guess_and_convert_to_pdl($val); | |||||||||||||||||
| 65 | 0 | $aes_params->set($aes, $val); | |||||||||||||||||
| 66 | } | ||||||||||||||||||
| 67 | } | ||||||||||||||||||
| 68 | 6 | Chart::GGPlot::Aes->check_aesthetics( $aes_params, $data->nrow ); | |||||||||||||||||
| 69 | 6 | for my $aes (@$aes_names) { | |||||||||||||||||
| 70 | 0 | $data->set($aes, $aes_params->at($aes)); | |||||||||||||||||
| 71 | } | ||||||||||||||||||
| 72 | 6 | return $data; | |||||||||||||||||
| 73 | 6 | } | |||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | 26 | ▶ | method aesthetics () { | ||||||||||||||||
|
Subroutine
aesthetics: called CC=3 SCAR=11.3
Pod
undocumented
Branch: 2 branches
| |||||||||||||||||||
| 76 | return [ | ||||||||||||||||||
| 77 | ( | ||||||||||||||||||
| 78 | 26 | $self->required_aes->union( $self->default_aes->keys )->flatten, | |||||||||||||||||
| 79 | $self->optional_aes->flatten, "group" | ||||||||||||||||||
| 80 | ) | ||||||||||||||||||
| 81 | ]; | ||||||||||||||||||
| 82 | 6 | } | |||||||||||||||||
| 83 | |||||||||||||||||||
| 84 | 6 | 1; | |||||||||||||||||
| 85 | |||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||