line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# ABSTRACT: Export static images of Plotly charts |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use strict; |
5
|
1
|
|
|
1
|
|
528
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
6
|
1
|
|
|
1
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
7
|
|
|
|
|
|
|
use utf8; |
8
|
1
|
|
|
1
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.042'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Chart::Plotly::Image::Orca; |
12
|
1
|
|
|
1
|
|
308
|
use Chart::Plotly::Image::Orca::Client; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
13
|
1
|
|
|
1
|
|
296
|
use Exporter qw(import); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
34
|
|
14
|
1
|
|
|
1
|
|
7
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
103
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw(save_image); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %params = @_; |
18
|
|
|
|
|
|
|
my $engine = ( delete $params{engine} ) || 'auto'; |
19
|
2
|
|
|
2
|
1
|
162852
|
|
20
|
2
|
|
50
|
|
|
9
|
my @supported_engines = qw(kaleido orca); |
21
|
|
|
|
|
|
|
unless ( grep { $_ eq $engine } ( 'auto', @supported_engines ) ) { |
22
|
2
|
|
|
|
|
12
|
die "Unsupported engine: $engine"; |
23
|
2
|
50
|
|
|
|
5
|
} |
|
6
|
|
|
|
|
15
|
|
24
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
if ( $params{orca_server} ) { |
26
|
|
|
|
|
|
|
_save_image_orca_client(%params); |
27
|
2
|
50
|
|
|
|
7
|
} |
28
|
0
|
|
|
|
|
0
|
|
29
|
|
|
|
|
|
|
if ( $engine eq 'auto' ) { |
30
|
|
|
|
|
|
|
for my $candidate (qw(kaleido orca)) { |
31
|
2
|
100
|
|
|
|
6
|
my $func_has = "_has_$candidate"; |
32
|
1
|
|
|
|
|
6
|
no strict 'refs'; ## no critic |
33
|
1
|
|
|
|
|
4
|
if ( $func_has->() ) { |
34
|
1
|
|
|
1
|
|
6
|
$engine = $candidate; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
91
|
|
35
|
1
|
50
|
|
|
|
17
|
last; |
36
|
1
|
|
|
|
|
11
|
} |
37
|
1
|
|
|
|
|
9
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
if ( $engine eq 'auto' ) { |
40
|
|
|
|
|
|
|
die "None of @{[join(', ', @supported_engines)]} are available. " |
41
|
2
|
50
|
|
|
|
15
|
. "Please install Chart::Kaleido::Plotly (recommended) or Alien::Plotly::Orca. "; |
42
|
0
|
|
|
|
|
0
|
} |
|
0
|
|
|
|
|
0
|
|
43
|
|
|
|
|
|
|
my $func_save = "_save_image_$engine"; |
44
|
|
|
|
|
|
|
no strict 'refs'; ## no critic |
45
|
2
|
|
|
|
|
7
|
return $func_save->(%params); |
46
|
1
|
|
|
1
|
|
6
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
268
|
|
47
|
2
|
|
|
|
|
12
|
|
48
|
|
|
|
|
|
|
eval { |
49
|
|
|
|
|
|
|
require Chart::Kaleido::Plotly; |
50
|
|
|
|
|
|
|
Chart::Kaleido::Plotly->VERSION(0.005); |
51
|
4
|
|
|
4
|
|
14
|
}; |
52
|
4
|
|
|
|
|
429
|
return !$@; |
53
|
4
|
|
|
|
|
213709
|
} |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
16
|
my $has_orca; |
56
|
|
|
|
|
|
|
eval { $has_orca = Chart::Plotly::Image::Orca::orca_available }; |
57
|
|
|
|
|
|
|
return $has_orca; |
58
|
|
|
|
|
|
|
} |
59
|
1
|
|
|
1
|
|
3
|
|
60
|
1
|
|
|
|
|
2
|
my %params = @_; |
|
1
|
|
|
|
|
4
|
|
61
|
1
|
|
|
|
|
3
|
|
62
|
|
|
|
|
|
|
_has_kaleido(); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Chart::Kaleido::Plotly's interface uses plotlyjs not plotly |
65
|
2
|
|
|
2
|
|
7
|
if ( my $plotlyjs_via_plotly_param = delete $params{plotly} ) { |
66
|
|
|
|
|
|
|
$params{plotlyjs} ||= $plotlyjs_via_plotly_param; |
67
|
2
|
|
|
|
|
8
|
} |
68
|
|
|
|
|
|
|
my %kaleido_params = |
69
|
|
|
|
|
|
|
map { exists $params{$_} ? ( $_ => delete $params{$_} ) : () } @{ Chart::Kaleido::Plotly->scope_flags }; |
70
|
2
|
50
|
|
|
|
7
|
my $kaleido = Chart::Kaleido::Plotly->new(%kaleido_params); |
71
|
0
|
|
0
|
|
|
0
|
$kaleido->save(%params); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
2
|
50
|
|
|
|
4
|
my %params = @_; |
|
8
|
|
|
|
|
24
|
|
|
2
|
|
|
|
|
7
|
|
75
|
2
|
|
|
|
|
39
|
|
76
|
2
|
|
|
|
|
7574
|
Chart::Plotly::Image::Orca::orca(%params); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my %params = @_; |
80
|
0
|
|
|
0
|
|
|
|
81
|
|
|
|
|
|
|
$params{server} = delete $params{orca_server}; |
82
|
0
|
|
|
|
|
|
Chart::Plotly::Image::Orca::Client::save_image(%params); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
0
|
|
|
0
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
=pod |
89
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=encoding UTF-8 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Chart::Plotly::Image - Export static images of Plotly charts |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 VERSION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
version 0.042 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SYNOPSIS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
use Chart::Plotly::Plot; |
103
|
|
|
|
|
|
|
use Chart::Plotly::Trace::Scatter; |
104
|
|
|
|
|
|
|
use Chart::Plotly::Image qw(save_image); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $plot = Chart::Plotly::Plot->new( |
107
|
|
|
|
|
|
|
traces => [ |
108
|
|
|
|
|
|
|
Chart::Plotly::Trace::Scatter->new( x => [ 1 .. 5 ], y => [ 1 .. 5 ] ) |
109
|
|
|
|
|
|
|
] |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
save_image(file => 'TestOrca.png', plot => $plot, |
112
|
|
|
|
|
|
|
width => 1024, height => 768, |
113
|
|
|
|
|
|
|
engine => 'auto'); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This module generate static images of Plotly charts. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
It internally uses either of below modules, |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over 4 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L<Chart::Kaleido::Plotly>'s save() method. |
126
|
|
|
|
|
|
|
Note that you will need to explicitly install L<Chart::Kaleido::Plotly> |
127
|
|
|
|
|
|
|
for kaleido to work. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item * |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L<Chart::Plotly::Image::Orca>'s orca() function |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item * |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
L<Chart::Plotly::Image::Orca::Client>'s save_image() function |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=back |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 FUNCTIONS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 save_image |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
save_image(file => $file, plot => $plot, |
144
|
|
|
|
|
|
|
width => $width, height => $height, |
145
|
|
|
|
|
|
|
engine => $engine, |
146
|
|
|
|
|
|
|
%rest) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Parameters |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=over 4 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * file |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Image file path. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * engine |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
One of "auto", "kaleido", "orca". |
159
|
|
|
|
|
|
|
Default is "auto", it tries in this order: kaleido, orca. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * orca_server |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
If this parameter is specified it will use L<Chart::Plotly::Image::Orca::Client>. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
For example, |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
save_image(file => $file, plot => $plot, |
168
|
|
|
|
|
|
|
width => $width, height => $height, |
169
|
|
|
|
|
|
|
orca_server => 'http://localhost:9999') |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * %rest |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Rest parameters are passed through to the lower-level functions. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 BUGS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Please report any bugs or feature requests via github: L<https://github.com/pablrod/p5-Chart-Plotly/issues> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 DISCLAIMER |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This is an unofficial Plotly Perl module. Currently I'm not affiliated in any way with Plotly. |
184
|
|
|
|
|
|
|
But I think plotly.js is a great library and I want to use it with perl. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
If you like plotly.js please consider supporting them purchasing a pro subscription: L<https://plot.ly/products/cloud/> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SEE ALSO |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L<Chart::Kaleido::Plotly>, |
191
|
|
|
|
|
|
|
L<Chart::Plotly::Image::Orca>, |
192
|
|
|
|
|
|
|
L<Chart::Plotly::Image::Orca::Client>, |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 AUTHOR |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Pablo Rodríguez González <pablo.rodriguez.gonzalez@gmail.com> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Pablo Rodríguez González. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This is free software, licensed under: |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
The MIT (X11) License |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |