| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# ABSTRACT: Export static images of Plotly charts using orca server |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use 5.010; |
|
5
|
1
|
|
|
1
|
|
14
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
16
|
|
|
7
|
1
|
|
|
1
|
|
4
|
|
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
28
|
|
|
8
|
|
|
|
|
|
|
use Path::Tiny; |
|
9
|
1
|
|
|
1
|
|
4
|
use LWP::UserAgent; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
10
|
1
|
|
|
1
|
|
501
|
use utf8; |
|
|
1
|
|
|
|
|
32675
|
|
|
|
1
|
|
|
|
|
32
|
|
|
11
|
1
|
|
|
1
|
|
9
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.042'; # VERSION |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %params = @_; |
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
|
|
0
|
1
|
|
my $plot = $params{plot}; |
|
17
|
|
|
|
|
|
|
my $file = path( $params{file} ); |
|
18
|
0
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
20
|
|
|
|
|
|
|
$ua->agent("Chart::Plotly::Image::Orca::Client/0.1"); |
|
21
|
0
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( POST => $params{server} ); |
|
23
|
|
|
|
|
|
|
$req->content_type('application/json'); |
|
24
|
0
|
|
|
|
|
|
$req->content( $plot->to_json_text ); |
|
25
|
0
|
|
|
|
|
|
my $res = $ua->request($req); |
|
26
|
0
|
|
|
|
|
|
if ( $res->is_success ) { |
|
27
|
0
|
|
|
|
|
|
path($file)->spew_raw( $res->content ); |
|
28
|
0
|
0
|
|
|
|
|
} else { |
|
29
|
0
|
|
|
|
|
|
die "Can't export the plot. Server returned: " . $res->status_line; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
0
|
|
|
|
|
|
return; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
0
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=encoding utf-8 |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Chart::Plotly::Image::Orca::Client - Export static images of Plotly charts using orca server |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 VERSION |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
version 0.042 |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#!/usr/bin/env perl |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use strict; |
|
54
|
|
|
|
|
|
|
use warnings; |
|
55
|
|
|
|
|
|
|
use utf8; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use Chart::Plotly::Plot; |
|
58
|
|
|
|
|
|
|
use Chart::Plotly::Trace::Scatter; |
|
59
|
|
|
|
|
|
|
use Chart::Plotly::Image::Orca::Client; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $plot = Chart::Plotly::Plot->new(traces => [ Chart::Plotly::Trace::Scatter->new( x => [ 1 .. 5 ], y => [ 1 .. 5 ] )]); |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Chart::Plotly::Image::Orca::Client::save_image(plot => $plot, file => "TestOrca.png", server => "http://[::]:9999"); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This module generate static images of Plotly charts without a browser using a |
|
68
|
|
|
|
|
|
|
L<Orca|https://github.com/plotly/orca> server. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The server must be up and running before using this module. You can get an Orca server |
|
71
|
|
|
|
|
|
|
using a docker image or just installing and running Orca yourself. There are some |
|
72
|
|
|
|
|
|
|
instructions in L<Chart::Plotly::Image::Orca> |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 save_image |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
save_image(plot => $plot, file => "TestOrca.png", server => "http://[::]:9999"); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Export L<Chart::Plotly::Plot> as a static image file. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=over 4 |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item plot |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Object to export |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item file |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Filename (with or without path) to export |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item server |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Url where the server is listening |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 BUGS |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Please report any bugs or feature requests via github: L<https://github.com/pablrod/p5-Chart-Plotly/issues> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 DISCLAIMER |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This is an unofficial Plotly Perl module. Currently I'm not affiliated in any way with Plotly. |
|
105
|
|
|
|
|
|
|
But I think plotly.js is a great library and I want to use it with perl. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
If you like plotly.js please consider supporting them purchasing a pro subscription: L<https://plot.ly/products/cloud/> |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L<Alien::Plotly::Orca> |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 AUTHOR |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Pablo Rodríguez González <pablo.rodriguez.gonzalez@gmail.com> |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Pablo Rodríguez González. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This is free software, licensed under: |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The MIT (X11) License |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |