line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use strict; |
3
|
1
|
|
|
1
|
|
552
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
4
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
513
|
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
use Module::Find; |
7
|
1
|
|
|
1
|
|
1055
|
use Chart::Plotly; |
|
1
|
|
|
|
|
1296
|
|
|
1
|
|
|
|
|
63
|
|
8
|
1
|
|
|
1
|
|
367
|
use namespace::autoclean; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
9
|
1
|
|
|
1
|
|
418
|
|
|
1
|
|
|
|
|
10067
|
|
|
1
|
|
|
|
|
3
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.042'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Inline display of plotly charts in Jupyter notebooks using L<Devel::IPerl> kernel |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $parameter_list = "(" . join( ", ", Chart::Plotly::plotlyjs_plot_function_parameters() ) . ")"; |
15
|
|
|
|
|
|
|
my $require_plotly = <<'EOJSFP'; |
16
|
|
|
|
|
|
|
<script> |
17
|
|
|
|
|
|
|
//# sourceURL=iperl-devel-plugin-chart-plotly.js |
18
|
|
|
|
|
|
|
$('#Plotly').each(function(i, e) { $(e).attr('id', 'plotly') }); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
if (!window.Plotly) { |
21
|
|
|
|
|
|
|
requirejs.config({ |
22
|
|
|
|
|
|
|
paths: { |
23
|
|
|
|
|
|
|
plotly: ['https://cdn.plot.ly/plotly-latest.min']}, |
24
|
|
|
|
|
|
|
}); |
25
|
|
|
|
|
|
|
window.Plotly = { |
26
|
|
|
|
|
|
|
EOJSFP |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$require_plotly .= Chart::Plotly::plotlyjs_plot_function() . " : function " . $parameter_list . "{\n"; |
29
|
|
|
|
|
|
|
$require_plotly .= <<'EOJSSP'; |
30
|
|
|
|
|
|
|
require(['plotly'], function(plotly) { |
31
|
|
|
|
|
|
|
window.Plotly=plotly; |
32
|
|
|
|
|
|
|
EOJSSP |
33
|
|
|
|
|
|
|
$require_plotly .= "Plotly." . Chart::Plotly::plotlyjs_plot_function() . $parameter_list . ";"; |
34
|
|
|
|
|
|
|
$require_plotly .= <<'EOJSTP'; |
35
|
|
|
|
|
|
|
}); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
</script> |
40
|
|
|
|
|
|
|
EOJSTP |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# only works registering the plugin for each notebook |
44
|
|
|
|
|
|
|
require Chart::Plotly::Plot; |
45
|
|
|
|
|
|
|
require Role::Tiny; |
46
|
1
|
|
|
1
|
1
|
848
|
|
47
|
1
|
|
|
|
|
11
|
Role::Tiny->apply_roles_to_package( 'Chart::Plotly::Plot', |
48
|
|
|
|
|
|
|
q(Devel::IPerl::Plugin::Chart::Plotly::Plot::IPerlRole) ); |
49
|
1
|
|
|
|
|
11
|
for my $module ( findsubmod('Chart::Plotly::Trace') ) { |
50
|
|
|
|
|
|
|
Role::Tiny->apply_roles_to_package( $module, q(Devel::IPerl::Plugin::Chart::Plotly::Plot::Trace::IPerlRole) ); |
51
|
1
|
|
|
|
|
467
|
} |
52
|
48
|
|
|
|
|
33158
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
use Moo::Role; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
use Devel::IPerl::Display::HTML; |
59
|
1
|
|
|
1
|
|
796
|
|
|
1
|
|
|
|
|
12070
|
|
|
1
|
|
|
|
|
5
|
|
60
|
|
|
|
|
|
|
my ($plot) = @_; |
61
|
1
|
|
|
1
|
|
1703
|
Devel::IPerl::Display::HTML->new( $require_plotly . $plot->html( load_plotly_using_script_tag => 0 ) ) |
|
1
|
|
|
|
|
29289
|
|
|
1
|
|
|
|
|
110
|
|
62
|
|
|
|
|
|
|
->iperl_data_representations; |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
0
|
0
|
|
|
65
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use Moo::Role; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Devel::IPerl::Display::HTML; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
require Chart::Plotly::Plot; |
73
|
|
|
|
|
|
|
my ($trace) = @_; |
74
|
1
|
|
|
1
|
|
18
|
my $plot = Chart::Plotly::Plot->new( traces => [$trace] ); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
75
|
|
|
|
|
|
|
Devel::IPerl::Display::HTML->new( $require_plotly . $plot->html( load_plotly_using_script_tag => 0 ) ) |
76
|
1
|
|
|
1
|
|
339
|
->iperl_data_representations; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
150
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
0
|
0
|
|
|
80
|
0
|
|
|
|
|
|
1; |
81
|
0
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=encoding UTF-8 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Devel::IPerl::Plugin::Chart::Plotly - Inline display of plotly charts in Jupyter notebooks using L<Devel::IPerl> kernel |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 VERSION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
version 0.042 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SYNOPSIS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# In notebook |
98
|
|
|
|
|
|
|
IPerl->load_plugin('Chart::Plotly'); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Trace objects get displayed automatically |
101
|
|
|
|
|
|
|
use Chart::Plotly::Trace::Scatter; |
102
|
|
|
|
|
|
|
my $scatter_trace = Chart::Plotly::Trace::Scatter->new( x => [ 1 .. 5 ], y => [ 1 .. 5 ] ); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# Also Plot objects |
105
|
|
|
|
|
|
|
use Chart::Plotly::Trace::Box; |
106
|
|
|
|
|
|
|
use Chart::Plotly::Plot; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $x = [ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3 ]; |
109
|
|
|
|
|
|
|
my $box1 = Chart::Plotly::Trace::Box->new( x => $x, y => [ map { rand() } ( 1 .. ( scalar(@$x) ) ) ], name => "box1" ); |
110
|
|
|
|
|
|
|
my $box2 = Chart::Plotly::Trace::Box->new( x => $x, y => [ map { rand() } ( 1 .. ( scalar(@$x) ) ) ], name => "box2" ); |
111
|
|
|
|
|
|
|
my $plot = Chart::Plotly::Plot->new( traces => [ $box1, $box2 ], layout => { boxmode => 'group' } ); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Plugin to display automatically L<Chart::Plotly> plot objects in Jupyter notebooks using kernel L<Devel::IPerl> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
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> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=for Pod::Coverage EVERYTHING |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 INSTANCE METHODS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 register |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This method is called automatically by L<Devel::IPerl>. You only need to load the plugin: |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
IPerl->load_plugin('Chart::Plotly'); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Pablo Rodríguez González <pablo.rodriguez.gonzalez@gmail.com> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Pablo Rodríguez González. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This is free software, licensed under: |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The MIT (X11) License |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |