Chart/GGPlot/Coord/Cartesian.pm

filter: Statementstmt 70.2% 66 / 94 Branchbran 30.0% 12 / 40 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 76.4% 13 / 17 Podpod 0.0% 0 / 6 totaltotal 56.7% 92 / 162 CC 22 SCAR 18.8
CC
22
Cov
58%
distance
12.0
transform
12.0
__ANON__
12.0
CRAP 6.6
« Chart/GGPlot/Theme/Defaults.pm ↑ Summary Chart/GGPlot/Guide.pm »
1 package Chart::GGPlot::Coord::Cartesian;
2  
3 # ABSTRACT: The Cartesian coordinate system
4  
5 5 ▶use Chart::GGPlot::Class qw(:pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 our $VERSION = '0.002003'; # VERSION
9  
10 5 ▶use Types::PDL qw(Piddle1D PiddleFromAny);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Types::Standard qw(Maybe);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use Chart::GGPlot::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 5 has [qw(xlim ylim)] => (
17 is => 'ro',
18 isa => Maybe [ Piddle1D->plus_coercions(PiddleFromAny) ],
19 coerce => 1,
20 );
21  
22 5 has limits =>
23 ( is => 'ro', lazy => 1, builder => '_build_limits', init_arg => undef );
24  
25 6 ▶sub _build_limits {
Subroutine _build_limits: called CC=1 SCAR=0.0
26 6 my $self = shift;
27 6 return { x => $self->xlim, y => $self->ylim };
28 }
29  
30  
31 12 ▶has expand => ( is => 'ro', default => sub { true } );
Subroutine __ANON__: called CC=1 SCAR=0.0
32  
33  
34 6 ▶has default => (is => 'ro', default => sub { false } );
Subroutine __ANON__: called CC=1 SCAR=0.0
35  
36 5 with qw(
37 Chart::GGPlot::Coord
38 Chart::GGPlot::HasCollectibleFunctions
39 );
40  
41 5 my $coord_cartesian_pod = <<'=cut';
42  
43 coord_cartesian(:$xlim=undef, :$ylim=undef, :$expand=true)
44  
45 The Cartesian coordinate system is the most familiar, and common, type of
46 coordinate system.
47 Setting limits on the coordinate system will zoom the plot (like you're
48 looking at it with a magnifying glass), and will not change the underlying
49 data like setting limits on a scale will.
50  
51 Arguments:
52  
53 =over 4
54  
55 * $xlim, $ylim
56  
57 Limits for the x and y axes.
58  
59 * $expand
60  
61 If true, the default, adds a small expansion factor to the limits to ensure
62 that data and axes don't overlap.
63 If false, limits are taken exactly from the data or C<$xlim>/C<$ylim>.
64  
65 =back
66  
67 =cut
68  
69 8 ▶my $coord_cartesian_code = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
70 8 return __PACKAGE__->new(@_);
71 5 };
72  
73 3 ▶classmethod ggplot_functions () {
Subroutine ggplot_functions: called CC=3 SCAR=11.3
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for classmethod ggplot_functions (expected 1, got ' . @_ . ')') 0 3 3
@_ > 1 and Function::Parameters::_croak('Too many arguments for classmethod ggplot_functions (expected 1, got ' . @_ . ')') 0 3 3
74 return [
75 {
76 3 name => 'coord_cartesian',
77 code => $coord_cartesian_code,
78 pod => $coord_cartesian_pod,
79 }
80 ];
81 5 }
82  
83 0 ▶classmethod is_linear() { true }
Subroutine is_linear: not called CC=3 SCAR=22.6
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for classmethod is_linear (expected 1, got ' . @_ . ')') 0 0 0
@_ > 1 and Function::Parameters::_croak('Too many arguments for classmethod is_linear (expected 1, got ' . @_ . ')') 0 0 0
84  
85 0 ▶method distance ($x, $y, $panel_params) {
Subroutine distance: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 4 and Function::Parameters::_croak('Too few arguments for method distance (expected 4, got ' . @_ . ')') 0 0 0
@_ > 4 and Function::Parameters::_croak('Too many arguments for method distance (expected 4, got ' . @_ . ')') 0 0 0
86 0 my $max_dist = dist_euclidean( $panel_params->at('x_range'),
87 $panel_params->at('y_range') );
88 0 return dist_euclidean( $x, $y ) / $max_dist;
89 5 }
90  
91 0 ▶method transform ($data, $panel_params) {
Subroutine transform: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method transform (expected 3, got ' . @_ . ')') 0 0 0
@_ > 3 and Function::Parameters::_croak('Too many arguments for method transform (expected 3, got ' . @_ . ')') 0 0 0
92 my ( $rescale_x, $rescale_y ) = map {
93 0 ▶ fun($data) { rescale( $data, $panel_params->at($_) ) };
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for fun (anon) (expected 1, got ' . @_ . ')') 0 0 0
@_ > 1 and Function::Parameters::_croak('Too many arguments for fun (anon) (expected 1, got ' . @_ . ')') 0 0 0
94 } qw(x_range y_range);
95 0 $data = transform_position( $data, $rescale_x, $rescale_y );
96 0 return transform_position( $data, squish_infinite(), squish_infiniate() );
97 5 }
98  
99 6 ▶method setup_panel_params ($scale_x, $scale_y, $params = {}) {
Subroutine setup_panel_params: called CC=4 SCAR=14.1
Pod undocumented
Branch: 3 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method setup_panel_params (expected 3, got ' . @_ . ')') 0 6 6
@_ > 4 and Function::Parameters::_croak('Too many arguments for method setup_panel_params (expected 4, got ' . @_ . ')') 0 6 6
@_ < 3 and $params = {} 0 6 6
100 12 ▶ my $train_cartesian = fun( $scale, $limits, $xy ) {
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 2 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for fun (anon) (expected 3, got ' . @_ . ')') 0 12 12
@_ > 3 and Function::Parameters::_croak('Too many arguments for fun (anon) (expected 3, got ' . @_ . ')') 0 12 12
101 12 my $range = $self->scale_range( $scale, $limits, $self->expand );
102 12 my $out = $scale->break_info($range);
103 12 $out->set('arrange', $scale->axis_order);
104 12 return $out->rename({ map { $_ => "${xy}.$_" } @{$out->names} });
105 6 };
106  
107 return {
108 6 $train_cartesian->( $scale_x, $self->limits->at('x'), 'x' )->flatten,
109 $train_cartesian->( $scale_y, $self->limits->at('y'), 'y' )->flatten,
110 };
111 5 }
112  
113 12 ▶method scale_range ($scale, $limits=undef, $expand=true) {
Subroutine scale_range: called CC=7 SCAR=23.0
Pod undocumented
Branch: 3 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method scale_range (expected 2, got ' . @_ . ')') 0 12 12
@_ > 4 and Function::Parameters::_croak('Too many arguments for method scale_range (expected 4, got ' . @_ . ')') 0 12 12
@_ < 3 and $expand = &true() 0 12 12
114 12 ▶ my $expansion = $expand ? $self->expand_default($scale) : pdl([ 0, 0 ]);
Branch: 1 branch
BranchTrueFalseTotal
$expand ? : 12 0 12
115  
116 12 ▶ if ( not defined $limits or $limits->isempty ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $limits or $limits->isempty) { } 12 0 12
Condition33%1/3
not defined $limits or $limits->isempty
l!l&&r!l&&!r
1200
MC/DC0%0/2
not defined $limits or $limits->isempty
not defined $limits $limits->isempty
Truth table33%1/3
not(A) or B
A= not defined $limitsB= $limits->isempty
ABresult
1X1
011
000
117 12 return $scale->dimension($expansion);
118 }
119 else {
120 0 my $range = range_( $scale->transform($limits) );
121 0 return expand_range( $range, $expansion->at(0), $expansion->at(1) );
122 }
123 5 }
124  
125 5 __PACKAGE__->meta->make_immutable;
126  
127 5 1;
128  
129 __END__
« Chart/GGPlot/Theme/Defaults.pm ↑ Summary Chart/GGPlot/Guide.pm »