Chart/GGPlot/Backend/Plotly/Geom/Path.pm

filter: Statementstmt 31.7% 20 / 63 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 5 totaltotal 22.8% 24 / 105 CC 15 SCAR 35.1
CC
15
Cov
22%
to_traces
72.0
scatter_line
30.0
split_on
9.6
CRAP 33.6
« Chart/GGPlot/Geom/Smooth.pm ↑ Summary Chart/GGPlot/Scale/Functions.pm »
1 package Chart::GGPlot::Backend::Plotly::Geom::Path;
2  
3 # ABSTRACT: Chart::GGPlot's Plotly implementation for Geom::Path
4  
5 1 ▶use Chart::GGPlot::Class qw(:pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.002003'; # VERSION
8  
9 1 with qw(Chart::GGPlot::Backend::Plotly::Geom);
10  
11 1 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Chart::GGPlot::Backend::Plotly::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 to_px to_rgb group_to_NA pdl_to_plotly
15 1 );
16 1 ▶use Chart::GGPlot::Util qw(ifelse);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶classmethod split_on () { [qw(fill color size)] }
Subroutine split_on: not called CC=3 SCAR=22.6
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for classmethod split_on (expected 1, got ' . @_ . ')') 0 0 0
@_ > 1 and Function::Parameters::_croak('Too many arguments for classmethod split_on (expected 1, got ' . @_ . ')') 0 0 0
19  
20 0 ▶sub mode {
Subroutine mode: not called CC=1 SCAR=6.9
Pod undocumented
21 0 return 'lines';
22 }
23  
24 0 ▶classmethod scatter_marker ($df, @rest) {
Subroutine scatter_marker: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for classmethod scatter_marker (expected 2, got ' . @_ . ')') 0 0 0
25 0 return;
26 1 }
27  
28 0 ▶classmethod scatter_line ($df, $params, $plot) {
Subroutine scatter_line: not called CC=5 SCAR=34.0
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 4 and Function::Parameters::_croak('Too few arguments for classmethod scatter_line (expected 4, got ' . @_ . ')') 0 0 0
@_ > 4 and Function::Parameters::_croak('Too many arguments for classmethod scatter_line (expected 4, got ' . @_ . ')') 0 0 0
29 0 my $use_webgl = $class->use_webgl($df);
30 0 ▶ my $plotly_trace_class =
Branch: 1 branch
BranchTrueFalseTotal
$use_webgl ? : 0 0 0
31 $use_webgl
32 ? 'Chart::Plotly::Trace::Scattergl'
33 : 'Chart::Plotly::Trace::Scatter';
34  
35 0 my $line_class = "${plotly_trace_class}::Line";
36 0 load $line_class;
37  
38 # TODO: plotly does not yet support gradient line color and width
39 # See https://github.com/plotly/plotly.js/issues/581
40  
41 0 my $color = to_rgb( $df->at('color'), $df->at('alpha') )->at(0);
42 0 my $size = to_px( $df->at('size')->slice( pdl(0) ) );
43 0 $size->where($size < 2) .= 2;
44  
45 # plotly supports solid, dashdot, dash, dot
46 0 my $linetype = $df->at('linetype')->at(0);
47  
48 0 ▶ return $line_class->new(
Branch: 1 branch
BranchTrueFalseTotal
$linetype ne 'solid' ? : 0 0 0
49 color => $color,
50 width => $size->at(0),
51 ( $linetype ne 'solid' ? ( dash => $linetype ) : () ),
52 );
53 1 }
54  
55 0 ▶classmethod to_traces ($df, $params, $plot) {
Subroutine to_traces: not called CC=8 SCAR=42.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 4 and Function::Parameters::_croak('Too few arguments for classmethod to_traces (expected 4, got ' . @_ . ')') 0 0 0
@_ > 4 and Function::Parameters::_croak('Too many arguments for classmethod to_traces (expected 4, got ' . @_ . ')') 0 0 0
56 0 $df = group_to_NA($df);
57  
58 0 my $use_webgl = $class->use_webgl($df);
59 0 ▶ my $plotly_trace_class =
Branch: 1 branch
BranchTrueFalseTotal
$use_webgl ? : 0 0 0
60 $use_webgl
61 ? 'Chart::Plotly::Trace::Scattergl'
62 : 'Chart::Plotly::Trace::Scatter';
63  
64 0 load $plotly_trace_class;
65  
66 0 ▶ if ( $log->is_debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Chart::GGPlot::Backend::Plotly::Geom::Path::log->is_debug) 0 0 0
67 0 ▶ $log->debug( $use_webgl ? "to use webgl" : "not to use webgl" );
Branch: 1 branch
BranchTrueFalseTotal
$use_webgl ? : 0 0 0
68 }
69  
70 0 my ( $x, $y ) = map { $df->at($_) } qw(x y);
71 0 my $mode = $class->mode;
72 0 ▶ my $marker =
Branch: 1 branch
BranchTrueFalseTotal
$mode eq 'markers' ? : 0 0 0
73 $mode eq 'markers'
74 ? $class->scatter_marker( $df, $params, $plot )
75 : undef;
76 0 ▶ my $line =
Branch: 1 branch
BranchTrueFalseTotal
$mode eq 'lines' ? : 0 0 0
77 $mode eq 'lines'
78 ? $class->scatter_line( $df, $params, $plot )
79 : undef;
80  
81 0 my $trace = $plotly_trace_class->new(
82 x => $x,
83 y => $y,
84 mode => $mode,
85 maybe
86 line => $line,
87 maybe
88 marker => $marker,
89 hovertext => pdl_to_plotly( $df->at('hovertext') ),
90 hoverinfo => 'text',
91 hoveron => $class->hover_on,
92 );
93 0 return [ $class->_adjust_trace_for_flip($trace, $plot) ];
94 1 }
95  
96 1 __PACKAGE__->meta->make_immutable;
97  
98 1 1;
99  
100 __END__
« Chart/GGPlot/Geom/Smooth.pm ↑ Summary Chart/GGPlot/Scale/Functions.pm »