Devel/IPerl/Plugin/Chart/Plotly.pm

filter: Statementstmt 88.2% 45 / 51 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.6% 11 / 13 Podpod 33.3% 1 / 3 totaltotal 85.0% 57 / 67 CC 2 SCAR 2.5
CC
2
Cov
88%
register
2.0
iperl_data_representations
2.0
iperl_data_representations
2.0
CRAP 1.3
« Chart/Plotly/Adapter/Data/Table.pm ↑ Summary
1 package Devel::IPerl::Plugin::Chart::Plotly;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Module::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Chart::Plotly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.042'; # VERSION
12  
13 # ABSTRACT: Inline display of plotly charts in Jupyter notebooks using L<Devel::IPerl> kernel
14  
15 1 my $parameter_list = "(" . join( ", ", Chart::Plotly::plotlyjs_plot_function_parameters() ) . ")";
16 1 my $require_plotly = <<'EOJSFP';
17 <script>
18 //# sourceURL=iperl-devel-plugin-chart-plotly.js
19 $('#Plotly').each(function(i, e) { $(e).attr('id', 'plotly') });
20  
21 if (!window.Plotly) {
22 requirejs.config({
23 paths: {
24 plotly: ['https://cdn.plot.ly/plotly-latest.min']},
25 });
26 window.Plotly = {
27 EOJSFP
28  
29 1 $require_plotly .= Chart::Plotly::plotlyjs_plot_function() . " : function " . $parameter_list . "{\n";
30 1 $require_plotly .= <<'EOJSSP';
31 require(['plotly'], function(plotly) {
32 window.Plotly=plotly;
33 EOJSSP
34 1 $require_plotly .= "Plotly." . Chart::Plotly::plotlyjs_plot_function() . $parameter_list . ";";
35 1 $require_plotly .= <<'EOJSTP';
36 });
37 }
38 }
39 }
40 </script>
41 EOJSTP
42  
43 1 ▶sub register {
Subroutine register: called CC=2 SCAR=6.9
Pod documented
44  
45 # only works registering the plugin for each notebook
46 1 require Chart::Plotly::Plot;
47 1 require Role::Tiny;
48  
49 1 Role::Tiny->apply_roles_to_package( 'Chart::Plotly::Plot',
50 q(Devel::IPerl::Plugin::Chart::Plotly::Plot::IPerlRole) );
51 1 for my $module ( findsubmod('Chart::Plotly::Trace') ) {
52 48 Role::Tiny->apply_roles_to_package( $module, q(Devel::IPerl::Plugin::Chart::Plotly::Plot::Trace::IPerlRole) );
53 }
54 }
55  
56 {
57 package Devel::IPerl::Plugin::Chart::Plotly::Plot::IPerlRole;
58  
59 1 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 1 ▶ use Devel::IPerl::Display::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 0 ▶ sub iperl_data_representations {
Subroutine iperl_data_representations: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my ($plot) = @_;
65 0 Devel::IPerl::Display::HTML->new( $require_plotly . $plot->html( load_plotly_using_script_tag => 0 ) )
66 ->iperl_data_representations;
67 }
68  
69 }
70  
71 {
72 1 package Devel::IPerl::Plugin::Chart::Plotly::Plot::Trace::IPerlRole;
73  
74 1 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 1 ▶ use Devel::IPerl::Display::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 0 ▶ sub iperl_data_representations {
Subroutine iperl_data_representations: not called CC=1 SCAR=6.9
Pod undocumented
79 0 require Chart::Plotly::Plot;
80 0 my ($trace) = @_;
81 0 my $plot = Chart::Plotly::Plot->new( traces => [$trace] );
82 0 Devel::IPerl::Display::HTML->new( $require_plotly . $plot->html( load_plotly_using_script_tag => 0 ) )
83 ->iperl_data_representations;
84 }
85  
86 }
87  
88 1 1;
89  
90 __END__
« Chart/Plotly/Adapter/Data/Table.pm ↑ Summary