line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::IPerl::Plugin::Chart::Plotly; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
550
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
459
|
use utf8; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
401
|
use Module::Find; |
|
1
|
|
|
|
|
1163
|
|
|
1
|
|
|
|
|
54
|
|
8
|
1
|
|
|
1
|
|
326
|
use Chart::Plotly; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
9
|
1
|
|
|
1
|
|
384
|
use namespace::autoclean; |
|
1
|
|
|
|
|
9294
|
|
|
1
|
|
|
|
|
3
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.039'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ABSTRACT: Inline display of plotly charts in Jupyter notebooks using L<Devel::IPerl> kernel |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $parameter_list = "(" . join( ", ", Chart::Plotly::plotlyjs_plot_function_parameters() ) . ")"; |
16
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
$require_plotly .= Chart::Plotly::plotlyjs_plot_function() . " : function " . $parameter_list . "{\n"; |
30
|
|
|
|
|
|
|
$require_plotly .= <<'EOJSSP'; |
31
|
|
|
|
|
|
|
require(['plotly'], function(plotly) { |
32
|
|
|
|
|
|
|
window.Plotly=plotly; |
33
|
|
|
|
|
|
|
EOJSSP |
34
|
|
|
|
|
|
|
$require_plotly .= "Plotly." . Chart::Plotly::plotlyjs_plot_function() . $parameter_list . ";"; |
35
|
|
|
|
|
|
|
$require_plotly .= <<'EOJSTP'; |
36
|
|
|
|
|
|
|
}); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
</script> |
41
|
|
|
|
|
|
|
EOJSTP |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub register { |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# only works registering the plugin for each notebook |
46
|
1
|
|
|
1
|
1
|
426
|
require Chart::Plotly::Plot; |
47
|
1
|
|
|
|
|
9
|
require Role::Tiny; |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
10
|
Role::Tiny->apply_roles_to_package( 'Chart::Plotly::Plot', |
50
|
|
|
|
|
|
|
q(Devel::IPerl::Plugin::Chart::Plotly::Plot::IPerlRole) ); |
51
|
1
|
|
|
|
|
417
|
for my $module ( findsubmod('Chart::Plotly::Trace') ) { |
52
|
47
|
|
|
|
|
32029
|
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
|
|
|
1
|
|
668
|
use Moo::Role; |
|
1
|
|
|
|
|
10498
|
|
|
1
|
|
|
|
|
6
|
|
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
1
|
|
711
|
use Devel::IPerl::Display::HTML; |
|
1
|
|
|
|
|
24837
|
|
|
1
|
|
|
|
|
94
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub iperl_data_representations { |
64
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
package Devel::IPerl::Plugin::Chart::Plotly::Plot::Trace::IPerlRole; |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
1
|
|
7
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
|
296
|
use Devel::IPerl::Display::HTML; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
116
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub iperl_data_representations { |
79
|
0
|
|
|
0
|
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; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=pod |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=encoding UTF-8 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 NAME |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Devel::IPerl::Plugin::Chart::Plotly - Inline display of plotly charts in Jupyter notebooks using L<Devel::IPerl> kernel |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 VERSION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
version 0.039 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SYNOPSIS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# In notebook |
107
|
|
|
|
|
|
|
IPerl->load_plugin('Chart::Plotly'); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Trace objects get displayed automatically |
110
|
|
|
|
|
|
|
use Chart::Plotly::Trace::Scatter; |
111
|
|
|
|
|
|
|
my $scatter_trace = Chart::Plotly::Trace::Scatter->new( x => [ 1 .. 5 ], y => [ 1 .. 5 ] ); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# Also Plot objects |
114
|
|
|
|
|
|
|
use Chart::Plotly::Trace::Box; |
115
|
|
|
|
|
|
|
use Chart::Plotly::Plot; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $x = [ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3 ]; |
118
|
|
|
|
|
|
|
my $box1 = Chart::Plotly::Trace::Box->new( x => $x, y => [ map { rand() } ( 1 .. ( scalar(@$x) ) ) ], name => "box1" ); |
119
|
|
|
|
|
|
|
my $box2 = Chart::Plotly::Trace::Box->new( x => $x, y => [ map { rand() } ( 1 .. ( scalar(@$x) ) ) ], name => "box2" ); |
120
|
|
|
|
|
|
|
my $plot = Chart::Plotly::Plot->new( traces => [ $box1, $box2 ], layout => { boxmode => 'group' } ); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 DESCRIPTION |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Plugin to display automatically L<Chart::Plotly> plot objects in Jupyter notebooks using kernel L<Devel::IPerl> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
The example above can be viewed in L<nbviewer|http://nbviewer.jupyter.org/github/pablrod/p5-Devel-IPerl-Plugin-Chart-Plotly/blob/master/examples/PlotlyPlugin.ipynb> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=for Pod::Coverage EVERYTHING |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 INSTANCE METHODS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 register |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This method is called automatically by L<Devel::IPerl>. You only need to load the plugin: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
IPerl->load_plugin('Chart::Plotly'); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 AUTHOR |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Pablo RodrÃguez González <pablo.rodriguez.gonzalez@gmail.com> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Pablo RodrÃguez González. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This is free software, licensed under: |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The MIT (X11) License |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |