Graph/Gnuplot.pm

filter: Statementstmt 60.8% 283 / 465 Branchbran 58.9% 198 / 336 Conditioncond 46.3% 19 / 41 MC/DCmcdc 33.3% 9 / 27 Subroutinesub 88.8% 16 / 18 Podpod 0.0% 0 / 1 totaltotal 59.1% 525 / 888 CC 187 SCAR 56.7
CC
187
Cov
59%
_gnuplot_date_utc_normalize
702.0
gnuplot
392.9
_gnuplot_date_utc
85.0
CRAP 290.5
« Graph/Xrt3d.pm ↑ Summary Graph/Xmgrace.pm »
1 ## Gnuplot.pm is a sub-module of Graph.pm. It has all the subroutines
2 ## needed for the gnuplot part of the package.
3 ##
4 ## $Id: Gnuplot.pm,v 1.48 2006/06/07 21:09:33 emile Exp $ $Name: $
5 ##
6 ## This software product is developed by Michael Young and David Moore,
7 ## and copyrighted(C) 1998 by the University of California, San Diego
8 ## (UCSD), with all rights reserved. UCSD administers the CAIDA grant,
9 ## NCR-9711092, under which part of this code was developed.
10 ##
11 ## There is no charge for this software. You can redistribute it and/or
12 ## modify it under the terms of the GNU General Public License, v. 2 dated
13 ## June 1991 which is incorporated by reference herein. This software is
14 ## distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF MERCHANTABILITY
15 ## OR FITNESS FOR A PARTICULAR PURPOSE or that the use of it will not
16 ## infringe on any third party's intellectual property rights.
17 ##
18 ## You should have received a copy of the GNU GPL along with this program.
19 ##
20 ##
21 ## IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
22 ## PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
23 ## DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
24 ## SOFTWARE, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF
25 ## THE POSSIBILITY OF SUCH DAMAGE.
26 ##
27 ## THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE
28 ## UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
29 ## SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. THE UNIVERSITY
30 ## OF CALIFORNIA MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES
31 ## OF ANY KIND, EITHER IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED
32 ## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
33 ## PARTICULAR PURPOSE, OR THAT THE USE OF THE SOFTWARE WILL NOT INFRINGE
34 ## ANY PATENT, TRADEMARK OR OTHER RIGHTS.
35 ##
36 ##
37 ## Contact: graph-dev@caida.org
38 ##
39 ##
40 package Chart::Graph::Gnuplot;
41 4 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 4 @ISA = qw(Exporter);
44 4 @EXPORT = qw();
45 4 @EXPORT_OK = qw(&gnuplot);
46  
47 4 ▶use Carp; # for carp() and croak()
Subroutine BEGIN: called CC=1 SCAR=0.0
48 4 ▶use Chart::Graph::Utils qw(:UTILS); # get global subs and variable
Subroutine BEGIN: called CC=1 SCAR=0.0
49 4 ▶use POSIX 'strftime';
Subroutine BEGIN: called CC=1 SCAR=0.0
50 4 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 4 $cvs_Id = '$Id: Gnuplot.pm,v 1.48 2006/06/07 21:09:33 emile Exp $';
53 4 $cvs_Author = '$Author: emile $';
54 4 $cvs_Name = '$Name: $';
55 4 $cvs_Revision = '$Revision: 1.48 $';
56  
57 4 $VERSION = 3.2;
58  
59 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 4 ▶use vars qw($show_year $show_seconds);
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 # these variables hold default options for gnuplot
64 4 my %def_gnu_global_opts = (
65 "title" => "untitled",
66 "output type" => "png",
67 "output file" => "untitled-gnuplot.png",
68 "x-axis label" => "x-axis",
69 "y-axis label" => "y-axis",
70 "x2-axis label" => undef,
71 "y2-axis label" => undef,
72 "logscale x" => "0",
73 "logscale y" => "0",
74 "logscale x2" => "0",
75 "logscale y2" => "0",
76 "xtics" => undef,
77 "ytics" => undef,
78 "x2tics" => undef,
79 "y2tics" => undef,
80 "xdata" => undef,
81 "ydata" => undef,
82 "x2data" => undef,
83 "y2data" => undef,
84 "timefmt" => undef,
85 "format" => undef,
86 "xrange" => undef,
87 "yrange" => undef,
88 "extra_opts" => undef,
89 "uts" => undef,
90 "uts_normalize" => undef,
91 "size"=> undef,
92 );
93  
94  
95 4 my %def_gnu_data_opts = (
96 "title" => "untitled data",
97 "style" => "points", # points, lines...
98 "axes" => "x1y1",
99 "type" => undef,
100 "using" => "1:2",
101 );
102  
103  
104  
105 #
106 #
107 # Subroutine: gnuplot()
108 #
109 # Description: this is the main function you will be calling from
110 # our scripts. please see
111 # www.caida.org/Tools/Graph/ for a full description
112 # and how-to of this subroutine
113 #
114  
115 48 ▶sub gnuplot {
Subroutine gnuplot: called CC=97 SCAR=59.7
Pod undocumented
116 48 my ($user_global_opts_ref, @data_sets) = @_;
117 48 my (%data_opts, %global_opts,);
118 48 my ($plottype, $output_file, $plot_file, $output_type, $data_set_ref);
119 # create a new filehandle to be used throughout package
120 48 my $handle = new FileHandle;
121  
122 # create tmpdir
123 48 _make_tmpdir("_Gnuplot_");
124  
125 # set paths for external programs
126 48 ▶ if (not _set_gnupaths()) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_set_gnupaths()) 1 47 48
127 1 _cleanup_tmpdir();
128 1 return 0;
129 }
130
131 # check first arg for hash
132 47 ▶ if (ref($user_global_opts_ref) ne "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $user_global_opts_ref ne "HASH") 0 47 47
133 0 carp "Global options must be a hash";
134 0 _cleanup_tmpdir();
135 0 return 0;
136 }
137  
138 # check for data sets
139 47 ▶ if (not @data_sets) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@data_sets) 0 47 47
140 0 carp "no data sets";
141 0 $handle->close;
142 0 _cleanup_tmpdir();
143 0 return 0;
144 }
145
146 # call to combine user options with default options
147 47 %global_opts = _mesh_opts($user_global_opts_ref, \%def_gnu_global_opts);
148
149 47 my $command_file = _make_tmpfile("command");
150  
151 #remember to close the file if we return
152 47 ▶ if (not $handle->open(">$command_file")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($handle->open(">$command_file")) 0 47 47
153 0 carp "could not open file: $command_file";
154 0 _cleanup_tmpdir();
155 0 return 0;
156 }
157  
158 # check if uts option is chosen and process first
159 47 ▶ if (my $value = $global_opts{uts}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $global_opts{"uts"}) 2 45 47
160 2 ▶ if (defined($value) and ref($value) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and ref $value eq 'ARRAY') { } 2 0 2
Condition33%1/3
defined $value and ref $value eq "ARRAY"
!ll&&!rl&&r
002
MC/DC0%0/2
defined $value and ref $value eq "ARRAY"
defined $value ref $value eq "ARRAY"
Truth table33%1/3
A and B
A= defined $valueB= ref $value eq "ARRAY"
ABresult
0X0
100
111
161 2 ▶ if (@{$value} < 2 || @{$value} > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$value;} < 2 or @{$value;} > 4) 0 2 2
Condition33%1/3
@{$value;} < 2 or @{$value;} > 4
l!l&&r!l&&!r
002
MC/DC0%0/2
@{$value;} < 2 or @{$value;} > 4
@{$value;} < 2 @{$value;} > 4
Truth table33%1/3
A or B
A= @{$value;} < 2B= @{$value;} > 4
ABresult
1X1
011
000
162 0 carp "out of range for 'uts': [start, end, <scale>, <use_local_timezone>]\n";
163 0 _cleanup_tmpdir();
164 0 return 0;
165 }
166 # set x tics to human readable time stamps
167 2 _gnuplot_date_utc($value->[0], $value->[1], $value->[2], $value->[3], \%global_opts);
168 } else {
169 0 carp "Invalid value for 'uts', give [start, end, <scale>, <use_local_timezone>]\n";
170 }
171 }
172  
173 # uts_normalize will be removed in a future version, so don't use it
174 47 ▶ if (my $value = $global_opts{uts_normalize}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $global_opts{"uts_normalize"}) 0 47 47
175 0 ▶ if (defined($value) and ref($value) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and ref $value eq 'ARRAY') { } 0 0 0
Condition0%0/3
defined $value and ref $value eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and ref $value eq "ARRAY"
defined $value ref $value eq "ARRAY"
Truth table0%0/3
A and B
A= defined $valueB= ref $value eq "ARRAY"
ABresult
0X0
100
111
176 0 ▶ if (@{$value} < 2 || @{$value} > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$value;} < 2 or @{$value;} > 3) 0 0 0
Condition0%0/3
@{$value;} < 2 or @{$value;} > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@{$value;} < 2 or @{$value;} > 3
@{$value;} < 2 @{$value;} > 3
Truth table0%0/3
A or B
A= @{$value;} < 2B= @{$value;} > 3
ABresult
1X1
011
000
177 0 carp "out of range for 'uts_normalize': [start, end, <scale> ]\n";
178 0 _cleanup_tmpdir();
179 0 return 0;
180 }
181 # set x tics to human readable time stamps
182 0 _gnuplot_date_utc_normalize($value->[0], $value->[1], $value->[2], \%global_opts);
183 } else {
184 0 carp "Invalid value for 'uts_normalize', give [start, end]";
185 }
186 }
187  
188 # Check if we have options for reading data as date/time formats
189 # these must be in command file before any others.
190 47 foreach my $time_set ("xdata", "ydata", "x2data", "y2data") {
191 188 ▶ if (defined($global_opts{$time_set})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $global_opts{$time_set}) 4 184 188
192 4 print $handle "set $time_set time\n";
193 }
194 }
195
196 # Set the format for reading data/time data. Only one format for all axes.
197 47 ▶ if (my $value = $global_opts{timefmt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value = $global_opts{"timefmt"}) 2 45 47
198 2 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 0 2
199 2 print $handle "set timefmt \"$value\"\n";
200 }
201 }
202  
203 # Now write remain global options to command file
204 47 ▶ while (my ($key, $value) = each %global_opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %global_opts) 1269 47 1316
205
206 ## Generic pass-thru, stuff random Gnuplot commands in this key
207 1269 ▶ if ($key eq "extra_opts") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "extra_opts") 47 1222 1269
208 47 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 4 43 47
209 4 ▶ if (ref($value) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 1 3 4
210 # arrayref
211 1 print $handle join("\n", @$value);
212 1 print $handle "\n";
213 } else {
214 # assume it's a string and user provided \n's
215 3 print $handle "$value\n";
216 }
217 }
218 }
219  
220 1269 ▶ if ($key eq "title") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "title") 47 1222 1269
221 47 print $handle "set title \"$value\"\n";
222 }
223
224 1269 ▶ if ($key eq "x-axis label") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "x-axis label") 47 1222 1269
225 47 print $handle "set xlabel \"$value\"\n";
226 }
227
228 1269 ▶ if ($key eq "y-axis label") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "y-axis label") 47 1222 1269
229 47 print $handle "set ylabel \"$value\"\n";
230 }
231
232 1269 ▶ if ($key eq "x2-axis label") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "x2-axis label") 47 1222 1269
233 47 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 4 43 47
234 4 print $handle "set x2label \"$value\"\n";
235 }
236 }
237
238 1269 ▶ if ($key eq "y2-axis label") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "y2-axis label") 47 1222 1269
239 47 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1 46 47
240 1 print $handle "set y2label \"$value\"\n";
241 }
242 }
243
244 1269 ▶ if ($key eq "logscale x") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "logscale x") 47 1222 1269
245 47 ▶ if ($value == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value == 1) 0 47 47
246 0 print $handle "set logscale x\n";
247 }
248 }
249
250 1269 ▶ if ($key eq "logscale y") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "logscale y") 47 1222 1269
251 47 ▶ if ($value == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value == 1) 3 44 47
252 3 print $handle "set logscale y\n";
253 }
254 }
255 1269 ▶ if ($key eq "logscale x2") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "logscale x2") 47 1222 1269
256 47 ▶ if ($value == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value == 1) 3 44 47
257 3 print $handle "set logscale x2\n";
258 }
259 }
260
261 1269 ▶ if ($key eq "logscale y2") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "logscale y2") 47 1222 1269
262 47 ▶ if ($value == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value == 1) 1 46 47
263 1 print $handle "set logscale y2\n";
264 }
265 }
266
267 # tics are not required so we can fall through if we want
268 1269 ▶ if ($key eq "xtics") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "xtics") 47 1222 1269
269 47 ▶ if (defined($value) and ref($value) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and ref $value eq "ARRAY") 6 41 47
Condition66%2/3
defined $value and ref $value eq "ARRAY"
!ll&&!rl&&r
4106
MC/DC50%1/2
defined $value and ref $value eq "ARRAY"
defined $value ref $value eq "ARRAY"
Truth table66%2/3
A and B
A= defined $valueB= ref $value eq "ARRAY"
ABresult
0X0
100
111
270 6 _print_tics($handle, $key, @{$value});
271 }
272 }
273  
274 1269 ▶ if ($key eq "ytics") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "ytics") 47 1222 1269
275 47 ▶ if (defined($value) and ref($value) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and ref $value eq "ARRAY") 5 42 47
Condition66%2/3
defined $value and ref $value eq "ARRAY"
!ll&&!rl&&r
4205
MC/DC50%1/2
defined $value and ref $value eq "ARRAY"
defined $value ref $value eq "ARRAY"
Truth table66%2/3
A and B
A= defined $valueB= ref $value eq "ARRAY"
ABresult
0X0
100
111
276 5 _print_tics($handle, $key, @{$value});
277 }
278 }
279
280 1269 ▶ if ($key eq "x2tics") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "x2tics") 47 1222 1269
281 47 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 45 47
282 2 ▶ if (ref($value) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 2 0 2
283 2 _print_tics($handle, $key, @{$value});
284 }
285 2 ▶ if ($value eq "on") {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq "on") 0 2 2
286 0 print $handle "set $key\n";
287 }
288 }
289 }
290 1269 ▶ if ($key eq "y2tics") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "y2tics") 47 1222 1269
291 47 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 45 47
292 2 ▶ if (ref($value) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 2 0 2
293 2 _print_tics($handle, $key, @{$value});
294 }
295 2 ▶ if ($value eq "on") {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq "on") 0 2 2
296 0 print $handle "set $key\n";
297 }
298 }
299 }
300 1269 ▶ if ($key eq 'xrange' || $key eq 'yrange' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "xrange" or $key eq "yrange") 94 1175 1269
Condition100%3/3
$key eq "xrange" or $key eq "yrange"
l!l&&r!l&&!r
47471175
MC/DC100%2/2
$key eq "xrange" or $key eq "yrange"
$key eq "xrange" $key eq "yrange"
Truth table100%3/3
A or B
A= $key eq "xrange"B= $key eq "yrange"
ABresult
1X1
011
000
301 94 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 7 87 94
302 7 ▶ if (ref($value) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 2 5 7
303 # arrayref
304 2 print $handle "set $key [$value->[0] : $value->[1]]\n";
305 } else {
306 # assume string
307 5 print $handle "set $key $value\n";
308 }
309 }
310 }
311 # The only time related Gnuplot code that doesn't need to be
312 # output first.
313 1269 ▶ if ($key eq "format") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "format") 47 1222 1269
314 47 ▶ if (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 45 47
315 2 ▶ if(ref($value) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 2 0 2
316 # Print value supplying quotes for time format.
317 2 print $handle "set $key ", $$value[0]," \"",
318 $$value[1], "\" \n";
319 } else {
320 0 carp "Invalid setting for format option";
321 }
322 }
323 }
324 # Date/Time and UTS keys which are processed first.
325 1269 ▶ if ($key eq "timefmt") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "timefmt") 47 1222 1269
326 # already processed
327 }
328 1269 ▶ if ($key eq "xdata") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "xdata") 47 1222 1269
329 # already processed
330 }
331 1269 ▶ if ($key eq "ydata") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "ydata") 47 1222 1269
332 # already processed
333 }
334 1269 ▶ if ($key eq "x2data") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "x2data") 47 1222 1269
335 # already processed
336 }
337 1269 ▶ if ($key eq "y2data") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "y2data") 47 1222 1269
338 # already processed
339 }
340 1269 ▶ if ($key eq "uts") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "uts") 47 1222 1269
341 # already been processed
342 }
343 1269 ▶ if ($key eq "uts_normalize") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "uts_normalize") 47 1222 1269
344 # already been processed
345 }
346 1269 ▶ if ($key eq "size" && defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "size" and defined $value) 1 1268 1269
Condition100%3/3
$key eq "size" and defined $value
!ll&&!rl&&r
1222461
MC/DC100%2/2
$key eq "size" and defined $value
$key eq "size" defined $value
Truth table100%3/3
A and B
A= $key eq "size"B= defined $value
ABresult
0X0
100
111
347 1 ▶ if (ref($value) eq 'ARRAY' && @{$value} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY' and @{$value;} == 2) { } 1 0 1
Condition33%1/3
ref $value eq "ARRAY" and @{$value;} == 2
!ll&&!rl&&r
001
MC/DC0%0/2
ref $value eq "ARRAY" and @{$value;} == 2
ref $value eq "ARRAY" @{$value;} == 2
Truth table33%1/3
A and B
A= ref $value eq "ARRAY"B= @{$value;} == 2
ABresult
0X0
100
111
348 1 print $handle "set $key ". @{$value}[0] . "," . @{$value}[1] . "\n";
349 }
350 else {
351
352 0 print STDERR "option `size' must be given a two element array\n";
353 }
354 }
355
356 1269 ▶ if ($key eq "output file") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "output file") 47 1222 1269
357 47 $output_file = $value;
358 }
359
360 1269 ▶ if ($key eq "output type") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "output type") 47 1222 1269
361 47 ▶ if (!($value =~ /^(pbm|gif|tgif|png|svg|eps(:? .*)?)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /^(pbm|gif|tgif|png|svg|eps(:? .*)?)$/) 0 47 47
362 0 carp "invalid output type: $value";
363 0 $handle->close();
364 0 _cleanup_tmpdir();
365 0 return 0;
366 }
367 47 $output_type = $value;
368 }
369 }
370  
371 # create the data file
372 47 ▶ if ($output_type =~ /^eps( .*)?$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($output_type =~ /^eps( .*)?$/) { } 2 45 47
elsif ($output_type eq 'pbm') { } 1 44 45
elsif ($output_type eq 'gif') { } 5 39 44
elsif ($output_type eq 'png') { } 38 1 39
elsif ($output_type eq 'tgif') { } 1 0 1
elsif ($output_type eq 'svg') { } 0 0 0
373 2 ▶ my $options = $1 || "";
Condition100%2/2
$1 || ''
l!l
11
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
374 2 ▶ if (defined $output_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_file) 0 2 2
375 0 $plot_file = _make_tmpfile("plot", "eps");
376 0 print $handle "set output \"$plot_file\"\n";
377 }
378 #print $handle "set terminal postscript eps color \"Arial\" 18\n";
379 2 print $handle "set terminal postscript eps $options\n";
380 } elsif ($output_type eq "pbm" ) {
381 1 ▶ if (defined $output_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_file) 0 1 1
382 0 $plot_file = _make_tmpfile("plot", "pbm");
383 0 print $handle "set output \"$plot_file\"\n";
384 }
385 1 print $handle "set terminal pbm small color\n";
386 } elsif ($output_type eq "gif") {
387 # always needs the tempfile because of conversion later on
388 5 $plot_file = _make_tmpfile("plot", "pbm");
389 5 print $handle "set output \"$plot_file\"\n";
390 5 print $handle "set terminal pbm small color\n";
391 } elsif ($output_type eq "png") {
392 38 ▶ if (defined $output_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_file) 1 37 38
393 1 $plot_file = _make_tmpfile("plot", "png");
394 1 print $handle "set output \"$plot_file\"\n";
395 }
396 38 print $handle "set terminal png small\n";
397 } elsif ($output_type eq "tgif") {
398 1 ▶ if (defined $output_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_file) 0 1 1
399 0 $plot_file = _make_tmpfile("plot", "obj");
400 0 print $handle "set output \"$plot_file\"\n";
401 }
402 1 print $handle "set terminal tgif\n";
403 } elsif ($output_type eq 'svg') {
404 0 ▶ if (defined $output_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output_file) 0 0 0
405 0 $plot_file = _make_tmpfile("plot", "svg");
406 0 print $handle "set output \"$plot_file\"\n";
407 }
408 0 print $handle "set terminal svg\n";
409 }
410  
411 # process data sets
412 47 print $handle "plot ";
413 47 ▶ while (@data_sets) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data_sets) 59 47 106
414
415 59 $data_set_ref = shift @data_sets;
416
417 59 ▶ if (ref($data_set_ref) ne "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data_set_ref ne "ARRAY") 0 59 59
418 0 carp "Data set must be an array";
419 0 $handle->close();
420 0 _cleanup_tmpdir();
421 0 return 0;
422 }
423
424 59 ▶ if (not _gnuplot_data_set($handle, @{$data_set_ref})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_gnuplot_data_set($handle, @{$data_set_ref;})) 0 59 59
425 ## already printed error message
426 0 $handle->close();
427 0 _cleanup_tmpdir();
428 0 return 0;
429 }
430
431 59 ▶ if (@data_sets) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data_sets) 12 47 59
432 12 print $handle ", ";
433 }
434 }
435
436 47 $handle->close();
437
438 # gnuplot and convert pbm file to gif
439 47 ▶ if (not _exec_gnuplot($command_file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_exec_gnuplot($command_file)) 47 0 47
440 47 _cleanup_tmpdir();
441 47 return 0;
442 }
443
444 0 ▶ if ($output_type eq "gif") {
Branch: 2 branches
BranchTrueFalseTotal
if ($output_type eq 'gif') { } 0 0 0
elsif (defined $output_file and $output_type =~ /^(pbm|eps(?: .*)?|png|tgif)$/) { } 0 0 0
445 0 ▶ if(not _exec_pbmtogif($plot_file, $output_file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_exec_pbmtogif($plot_file, $output_file)) 0 0 0
446 0 _cleanup_tmpdir();
447 0 return 0;
448 }
449 ▶ } elsif (defined $output_file && $output_type =~ /^(pbm|eps(?: .*)?|png|tgif)$/) {
Condition0%0/3
defined $output_file and $output_type =~ /^(pbm|eps(?: .*)?|png|tgif)$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $output_file and $output_type =~ /^(pbm|eps(?: .*)?|png|tgif)$/
defined $output_file $output_type =~ /^(pbm|eps(?: .*)?|png|tgif)$/
Truth table0%0/3
A and B
A= defined $output_fileB= $output_type =~ /^(pbm|eps(?: .*)?|png|tgif)$/
ABresult
0X0
100
111
450 #try to get rid of the ugly warnings when moving a file on freebsd
451 0 ▶ if ($^O eq 'freebsd') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "freebsd") 0 0 0
452 0 eval { #this is opportunistic, if it fails it doesn't really matter
453 0 my $gid = `/usr/bin/id -g`;
454 0 chomp($gid);
455 0 system('/usr/bin/chgrp',$gid,$plot_file);
456 };
457 }
458  
459 0 my $status = system("mv", "$plot_file", "$output_file");
460  
461 0 ▶ if (not _chk_status($status)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_chk_status($status)) 0 0 0
462 0 ▶ if ($Chart::Graph::debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Chart::Graph::debug) 0 0 0
463 0 print STDERR "Couldn't mv $plot_file to $output_file: $!\n";
464 }
465 0 _cleanup_tmpdir();
466 0 return 0;
467 }
468 }
469 0 _cleanup_tmpdir();
470 0 return 1;
471 }
472  
473 #
474 #
475 # Subroutine: gnuplot_data_set()
476 #
477 # Description: this functions processes the X number
478 # of data sets that a user gives as
479 # arguments to gnuplot(). Again, please
480 # see http://www.caida.org/Tools/Graph/
481 # for the format of the dataset.
482 #
483  
484  
485
486 59 ▶sub _gnuplot_data_set {
Subroutine _gnuplot_data_set: called CC=13 SCAR=26.3
487 59 my ($handle, $user_data_opts_ref, @data) = @_;
488 59 my (%data_opts);
489
490 # set these values with empty string because we print them out later
491 # we don't want perl to complain of uninitialized value.
492 59 my ($title, $style, $axes, $ranges, $type,) = ("", "", "", "", "");
493 59 my ($using) = ("");
494 59 my $result;
495 59 my $filename = _make_tmpfile("data");
496
497 ## check first arg for hash
498 59 ▶ if (ref($user_data_opts_ref) ne "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $user_data_opts_ref ne "HASH") 0 59 59
499 0 carp "Data options must be a hash.";
500 0 return 0;
501 }
502  
503 # call to combine user options with default options
504 59 %data_opts = _mesh_opts($user_data_opts_ref, \%def_gnu_data_opts);
505  
506 # write data options to command file
507 59 ▶ while (my ($key, $value) = each %data_opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %data_opts) 295 59 354
508
509 295 ▶ if ($key eq "using") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "using") 59 236 295
510 59 $using = "using $value";
511 }
512  
513 295 ▶ if ($key eq "title") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "title") 59 236 295
514 59 $title = "title \"$value\"";
515 }
516
517 295 ▶ if ($key eq "style") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "style") 59 236 295
518 59 $style = "with $value"
519 }
520
521 295 ▶ if ($key eq "axes") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "axes") 59 236 295
522 59 $axes = "axes $value";
523 }
524
525 295 ▶ if ($key eq "type") {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "type") 59 236 295
526 59 $type = $value;
527 }
528 }
529
530 59 ▶ if ($type eq "function") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'function') { } 1 58 59
531 #$ranges = "[t=:]"; # XXX ?
532 1 print $handle "$ranges " . $data[0] . " $axes $title $style";
533 1 return 1;
534 } else {
535 58 print $handle "$ranges \"$filename\" $using $axes $title $style";
536  
537 # we give the user 3 formats for supplying the data set
538 # 1) matrix
539 # 2) column
540 # 3) file
541 # please see the online docs for a description of these
542 # formats
543 58 ▶ if ($type eq "matrix") {
Branch: 4 branches
BranchTrueFalseTotal
if ($type eq 'matrix') { } 46 12 58
elsif ($type eq 'columns') { } 9 3 12
elsif ($type eq 'file') { } 3 0 3
elsif ($type eq '') { } 0 0 0
544 46 $result = _matrix_to_file($filename, @data);
545 } elsif ($type eq "columns") {
546 9 $result = _columns_to_file($filename, @data);
547 } elsif ($type eq "file") {
548 3 $result = _file_to_file($filename, @data);
549 } elsif ($type eq "") {
550 0 carp "Need to specify data set type";
551 0 return 0;
552 } else {
553 0 carp "Illegal data set type: $type";
554 0 return 0;
555 }
556 }
557 58 return $result;
558 }
559  
560 #
561 # Subroutine: set_gnupaths()
562 #
563 # Description: set paths for external programs required by gnuplot()
564 # if they are not defined already
565 #
566  
567 48 ▶sub _set_gnupaths {
Subroutine _set_gnupaths: called CC=5 SCAR=18.9
568  
569 48 ▶ if (not defined($gnuplot)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Chart::Graph::Gnuplot::gnuplot) 1 47 48
570 1 ▶ if (not $gnuplot = _get_path("gnuplot")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Chart::Graph::Gnuplot::gnuplot = _get_path("gnuplot")) 1 0 1
571 1 return 0;
572 }
573 }
574
575 47 ▶ if (not defined($ppmtogif)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Chart::Graph::Gnuplot::ppmtogif) 0 47 47
576 0 ▶ if (not $ppmtogif = _get_path("ppmtogif")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Chart::Graph::Gnuplot::ppmtogif = _get_path("ppmtogif")) 0 0 0
577 0 return 0;
578 }
579 }
580 47 return 1;
581 }
582  
583 #
584 #
585 # Subroutine: print_tics()
586 # Description: this subroutine takes an array
587 # of graph tic labels and prints
588 # them to the gnuplot command file.
589 # This subroutine is called by gnuplot().
590 #
591 # Arguments: $tic_type: which axis to print the tics on
592 # @tics: the array of tics to print to the file
593 #
594  
595 15 ▶sub _print_tics {
Subroutine _print_tics: called CC=5 SCAR=16.8
596 15 my ($handle, $tic_type, @tics) = @_;
597 15 my (@tic_array, $tics_formatted, $tic_label, $tic_index);
598
599 # no tic set found, user entered empty tic array
600 15 ▶ if (not @tics) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@tics) 0 15 15
601 0 carp "Warning: empty tic set found";
602 0 return 1;
603 }
604  
605 15 foreach my $tic (@tics) {
606 #tics can come in two formats
607 #this one is [["label1", 10], ["label2", 20],...]
608 154 ▶ if (ref($tic) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tic eq 'ARRAY') { } 127 27 154
609
610 127 ▶ if ($#{$tic} != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$tic;} != 1) 0 127 127
611 0 carp "invalid tic format";
612 0 return 0;
613 }
614 127 $tic_label = $tic->[0];
615 127 $tic_index = $tic->[1];
616 127 push (@tic_array, "\"$tic_label\" $tic_index");
617 # this one is [10, 20,...]
618 } else {
619 27 push (@tic_array, "$tic");
620 }
621 }
622 15 $tics_formatted = join(",", @tic_array);
623 15 print $handle "set $tic_type ($tics_formatted)\n";
624 15 return 1;
625 }
626  
627 #
628 #
629 # Subroutine: matrix_to_file()
630 #
631 # Description: converts the matrix data input into a the gnuplot
632 # data file format. See www for the specific on the
633 # matrix format
634 #
635 #
636 46 ▶sub _matrix_to_file {
Subroutine _matrix_to_file: called CC=5 SCAR=17.4
637 46 my ($file, $matrix_ref) = @_;
638 46 my $entry_ref;
639 my $matrix_len;
640
641 46 ▶ if (ref($matrix_ref) ne "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $matrix_ref ne "ARRAY") 0 46 46
642 0 carp "Matrix data must be a reference to an array";
643 0 return 0;
644 }
645
646 46 open (DATA, ">$file");
647
648 46 $matrix_len = @{$matrix_ref};
649 46 ▶ for (my $i = 0; $i < $matrix_len; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $matrix_len) 144 46 190
650 144 $entry_ref = $matrix_ref->[$i];
651
652 144 ▶ if (ref($entry_ref) ne "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry_ref ne "ARRAY") 0 144 144
653 0 carp "Matrix entry must be a reference to an array";
654 0 close DATA;
655 0 return 0;
656 }
657
658 # prints blank lines for blank entries, this allows
659 # the user to tell gnuplot to not connect lines between
660 # all points when displaying data with lines.
661 144 ▶ if (@{$entry_ref} == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$entry_ref;} == 0) { } 0 144 144
662 {
663 0 print DATA "\n";
664 }
665 else
666 {
667 144 if (0) {
668 # check that each entry ONLY has two entries
669 if (@{$entry_ref} != 2) {
670 carp "Each entry must be an array of size 2";
671 return 0;
672 }
673 print DATA $entry_ref->[0], "\t", $entry_ref->[1], "\n";
674 }
675 # XXX
676 144 print DATA join("\t", @{$entry_ref}), "\n";
677 }
678 }
679 46 close DATA;
680 46 return 1;
681 }
682  
683 #
684 #
685 # Subroutine: columns_to_file()
686 #
687 # Description: converts the column data input into a the gnuplot
688 # data file format. please see www page for specifics
689 # on this format.
690 #
691  
692 9 ▶sub _columns_to_file {
Subroutine _columns_to_file: called CC=7 SCAR=20.8
693 9 my ($file, @columns) = @_;
694  
695 9 foreach my $dataset ( @columns ) {
696 30 ▶ if (!(ref($dataset) eq "ARRAY")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $dataset eq "ARRAY") 0 30 30
697 0 carp "Column data must be a reference to an array";
698 0 return 0;
699 }
700
701 30 ▶ if ($#{$dataset} != $#{$columns[$[]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$dataset;} != $#{$columns[$[];}) 0 30 30
702 0 carp "All columns must be of same length";
703 0 return 0;
704 }
705 }
706  
707 9 ▶ if ($#{$columns[$[]} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$columns[$[];} == 0) 0 9 9
708 0 carp "Warning: Columns have no data!";
709 }
710  
711 9 open (DATA, ">$file");
712
713 9 ▶ for (my $i = 0; $i <= $#{$columns[$[]}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$columns[$[];}) 51 9 60
714 51 foreach my $dataset ( @columns ) {
715 174 print DATA "$dataset->[$i]\t";
716 }
717 51 print DATA "\n";
718 }
719  
720 9 close DATA;
721 9 return 1;
722 }
723  
724  
725 #
726 # Subroutine: file_to_file()
727 #
728 # Description: If a gnuplot data set was given in
729 # file format, we simply copy the data
730 # and read it into
731 #
732  
733 3 ▶sub _file_to_file {
Subroutine _file_to_file: called CC=4 SCAR=17.3
734 3 my ($file_out, $file_in) = @_;
735
736 3 ▶ if (not $file_in) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file_in) 0 3 3
737 0 carp "Data set file missing";
738 0 return 0;
739 }
740  
741 3 ▶ if (not -f $file_in) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file_in) 0 3 3
742 0 carp "Data set file, '$file_in', does not exist.";
743 0 return 0;
744 }
745
746 3 my $status = system("cp", "$file_in", "$file_out");
747
748 3 ▶ if (not _chk_status($status)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_chk_status($status)) 0 3 3
749 0 return 0;
750 }
751
752 3 return 1;
753 }
754  
755 #
756 # Subroutine: exec_gnuplot()
757 #
758 # Description: this executes gnuplot on the command file
759 # and data sets that we have generated.
760 #
761  
762 47 ▶sub _exec_gnuplot {
Subroutine _exec_gnuplot: called CC=2 SCAR=7.4
763 47 my ($command_file) = @_;
764 47 my $status = system("$gnuplot", "$command_file");
765
766 47 ▶ if (not _chk_status($status)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_chk_status($status)) 47 0 47
767 47 return 0;
768 }
769
770 0 return 1;
771 }
772  
773 #
774 # Subroutine: exec_pbmtogif()
775 #
776 # Description: convert pbm file that gnuplot makes into
777 # a gif. usually used for web pages
778 #
779 0 ▶sub _exec_pbmtogif {
Subroutine _exec_pbmtogif: not called CC=4 SCAR=30.0
780 0 my ($pbm_file, $gif_file) = @_;
781 0 my $status;
782 0 my $cmd = "$ppmtogif $pbm_file ";
783 0 ▶ if ($gif_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gif_file) 0 0 0
784 0 $cmd .= "> $gif_file ";
785 }
786 0 ▶ unless ($Chart::Graph::debug) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Chart::Graph::debug) 0 0 0
787 0 $cmd .= "2> /dev/null ";
788 }
789 0 $status = system($cmd);
790
791 0 ▶ if (not _chk_status($status)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_chk_status($status)) 0 0 0
792 0 return 0;
793 }
794
795 0 return 1;
796 }
797  
798 #
799 # Subroutine: gnuplot_date_utc()
800 #
801 # Description: wrapper function that handles UNIX
802 # time stamps as x values nicely
803 #
804 # Author: Ryan Koga - rkoga@caida.org
805 #
806  
807 2 ▶sub _gnuplot_date_utc {
Subroutine _gnuplot_date_utc: called CC=29 SCAR=44.4
808 2 my ($start, $end, $samp_scale, $use_local_tz, $global_options) = @_;
809  
810 2 my $min_len = 60;
811 2 my $hour_len = $min_len*60;
812 2 my $day_len = $hour_len*24;
813 2 my $interval = $end - $start;
814 2 my $min_samp;
815 my @tics;
816  
817 2 ▶ if (!defined($samp_scale)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $samp_scale) 2 0 2
818 2 $samp_scale = 1;
819 }
820  
821 2 ▶ if ($interval < 10) {
Branch: 19 branches
BranchTrueFalseTotal
if ($interval < 10) { } 0 2 2
elsif ($interval < 30) { } 0 2 2
elsif ($interval < $min_len) { } 0 2 2
elsif ($interval < 3 * $min_len) { } 0 2 2
elsif ($interval < 10 * $min_len) { } 0 2 2
elsif ($interval < $hour_len) { } 0 2 2
elsif ($interval < 2 * $hour_len) { } 0 2 2
elsif ($interval < 3 * $hour_len) { } 1 1 2
elsif ($interval < 4 * $hour_len) { } 0 1 1
elsif ($interval < 5 * $hour_len) { } 0 1 1
elsif ($interval < 12 * $hour_len) { } 0 1 1
elsif ($interval < $day_len) { } 0 1 1
elsif ($interval < 2 * $day_len) { } 0 1 1
elsif ($interval < 5 * $day_len) { } 0 1 1
elsif ($interval < 7 * $day_len) { } 0 1 1
elsif ($interval < 15 * $day_len) { } 0 1 1
elsif ($interval < 30 * $day_len) { } 0 1 1
elsif ($interval < 365 * $day_len) { } 0 1 1
elsif ($interval < 730 * $day_len) { } 0 1 1
822 0 $min_samp = 1;
823 } elsif ($interval < 30) {
824 0 $min_samp = 4;
825 } elsif ($interval < $min_len) {
826 0 $min_samp = 10;
827 } elsif ($interval < 3*$min_len) {
828 0 $min_samp = 30;
829 } elsif ($interval < 10*$min_len) {
830 0 $min_samp = $min_len;
831 } elsif ($interval < $hour_len) {
832 0 $min_samp = 5*$min_len;
833 } elsif ($interval < 2*$hour_len) {
834 0 $min_samp = 10*$min_len;
835 } elsif ($interval < 3*$hour_len) {
836 1 $min_samp = 15*$min_len;
837 } elsif ($interval < 4*$hour_len) {
838 0 $min_samp = 20*$min_len;
839 } elsif ($interval < 5*$hour_len) {
840 0 $min_samp = 30*$min_len;
841 } elsif ($interval < 12*$hour_len) {
842 0 $min_samp = $hour_len;
843 } elsif ($interval < $day_len) {
844 0 $min_samp = 2*$hour_len;
845 } elsif ($interval < 2*$day_len) {
846 0 $min_samp = 4*$hour_len;
847 } elsif ($interval < 5*$day_len) {
848 0 $min_samp = 12*$hour_len;
849 } elsif ($interval < 7*$day_len) {
850 0 $min_samp = $day_len;
851 } elsif ($interval < 15*$day_len) {
852 0 $min_samp = 2*$day_len;
853 } elsif ($interval < 30*$day_len) {
854 0 $min_samp = 7*$day_len;
855 } elsif ($interval < 365*$day_len) {
856 0 $min_samp = 30*$day_len;
857 } elsif ($interval < 2*365*$day_len) {
858 0 $min_samp = 60*$day_len;
859 } else {
860 1 $min_samp = 120*$day_len;
861 }
862 2 $min_samp /= $samp_scale;
863 2 my $start_min = int($start/$min_samp);
864 2 my $end_min = int($end/$min_samp);
865  
866 2 ▶ for (my $curr_min = $start_min; $curr_min <= $end_min; $curr_min++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curr_min <= $end_min) 108 2 110
867 108 my $bucket = $curr_min*$min_samp;
868 108 my ($bucket_str,@time_data);
869 108 ▶ if ( $use_local_tz ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_local_tz) { } 0 108 108
870 0 @time_data = localtime($bucket);
871 } else {
872 108 @time_data = gmtime($bucket);
873 }
874 108 $time_data[$#time_data] = -1; # unset dst data, broken strftime
875  
876 # keep compatibility with the undocumented 'utc_seconds' global var
877 108 $Chart::Graph::Gnuplot::show_seconds = $Chart::Graph::Gnuplot::utc_seconds;
878  
879 108 ▶ if ($min_samp >= $min_len && !$Chart::Graph::Gnuplot::show_seconds) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min_samp >= $min_len and not $Chart::Graph::Gnuplot::show_seconds) { } 108 0 108
Condition33%1/3
$min_samp >= $min_len and not $Chart::Graph::Gnuplot::show_seconds
!ll&&!rl&&r
00108
MC/DC0%0/2
$min_samp >= $min_len and not $Chart::Graph::Gnuplot::show_seconds
$min_samp >= $min_len not $Chart::Graph::Gnuplot::show_seconds
Truth table33%1/3
A and not(B)
A= $min_samp >= $min_lenB= not $Chart::Graph::Gnuplot::show_seconds
ABresult
0X0
100
111
880 108 $bucket_str = strftime("%H:%M", @time_data);
881 } else {
882 0 $bucket_str = strftime("%H:%M:%S", @time_data);
883 }
884 108 ▶ if ($bucket_str =~ /^00:00(:00)?$/ || $curr_min == $start_min + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bucket_str =~ /^00:00(:00)?$/ or $curr_min == $start_min + 1) 99 9 108
Condition100%3/3
$bucket_str =~ /^00:00(:00)?$/ or $curr_min == $start_min + 1
l!l&&r!l&&!r
9819
MC/DC100%2/2
$bucket_str =~ /^00:00(:00)?$/ or $curr_min == $start_min + 1
$bucket_str =~ /^00:00(:00)?$/ $curr_min == $start_min + 1
Truth table100%3/3
A or B
A= $bucket_str =~ /^00:00(:00)?$/B= $curr_min == $start_min + 1
ABresult
1X1
011
000
885 99 $bucket_str .= strftime('\n%m/%d', @time_data);
886 99 ▶ if ($Chart::Graph::Gnuplot::show_year) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Chart::Graph::Gnuplot::show_year) 0 99 99
887 0 $bucket_str .= strftime('\n%Y', @time_data);
888 }
889 }
890 108 push @tics, [ $bucket_str, $bucket ];
891 }
892  
893 # must check to see if xtics were previously set in the globals
894 # if they are, we'll append them to the time stamp tics
895 # note: collisions are handled by the user
896  
897 2 ▶ if (defined ($global_options->{"xtics"})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $global_options->{"xtics"}) 1 1 2
898 1 push @tics, @{$global_options->{"xtics"}};
899 }
900  
901 2 $global_options->{"xtics"} = \@tics;
902 2 return 1;
903 }
904  
905  
906 0 ▶sub _gnuplot_date_utc_normalize {
Subroutine _gnuplot_date_utc_normalize: not called CC=26 SCAR=65.5
907 0 my ($start, $end, $samp_scale, $global_options) = @_;
908 ### this code used to be used as a workaround for an old gnuplot bug
909 ### newer versions don't need it
910 0 carp "'uts_normalize' is going to be depreciated in a future release\n";
911  
912 0 my $min_len = 60;
913 0 my $hour_len = $min_len*60;
914 0 my $day_len = $hour_len*24;
915 0 my $interval = $end - $start;
916 0 my $min_samp;
917  
918 0 ▶ if (!defined($samp_scale)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $samp_scale) 0 0 0
919 0 $samp_scale = 1;
920 }
921  
922 0 ▶ if ($interval < 10) {
Branch: 17 branches
BranchTrueFalseTotal
if ($interval < 10) { } 0 0 0
elsif ($interval < 30) { } 0 0 0
elsif ($interval < $min_len) { } 0 0 0
elsif ($interval < 3 * $min_len) { } 0 0 0
elsif ($interval < 10 * $min_len) { } 0 0 0
elsif ($interval < $hour_len) { } 0 0 0
elsif ($interval < 2 * $hour_len) { } 0 0 0
elsif ($interval < 3 * $hour_len) { } 0 0 0
elsif ($interval < 4 * $hour_len) { } 0 0 0
elsif ($interval < 5 * $hour_len) { } 0 0 0
elsif ($interval < 12 * $hour_len) { } 0 0 0
elsif ($interval < $day_len) { } 0 0 0
elsif ($interval < 2 * $day_len) { } 0 0 0
elsif ($interval < 5 * $day_len) { } 0 0 0
elsif ($interval < 7 * $day_len) { } 0 0 0
elsif ($interval < 15 * $day_len) { } 0 0 0
elsif ($interval < 30 * $day_len) { } 0 0 0
923 0 $min_samp = 1;
924 } elsif ($interval < 30) {
925 0 $min_samp = 4;
926 } elsif ($interval < $min_len) {
927 0 $min_samp = 10;
928 } elsif ($interval < 3*$min_len) {
929 0 $min_samp = 30;
930 } elsif ($interval < 10*$min_len) {
931 0 $min_samp = $min_len;
932 } elsif ($interval < $hour_len) {
933 0 $min_samp = 5*$min_len;
934 } elsif ($interval < 2*$hour_len) {
935 0 $min_samp = 10*$min_len;
936 } elsif ($interval < 3*$hour_len) {
937 0 $min_samp = 15*$min_len;
938 } elsif ($interval < 4*$hour_len) {
939 0 $min_samp = 20*$min_len;
940 } elsif ($interval < 5*$hour_len) {
941 0 $min_samp = 30*$min_len;
942 } elsif ($interval < 12*$hour_len) {
943 0 $min_samp = $hour_len;
944 } elsif ($interval < $day_len) {
945 0 $min_samp = 2*$hour_len;
946 } elsif ($interval < 2*$day_len) {
947 0 $min_samp = 4*$hour_len;
948 } elsif ($interval < 5*$day_len) {
949 0 $min_samp = 12*$hour_len;
950 } elsif ($interval < 7*$day_len) {
951 0 $min_samp = $day_len;
952 } elsif ($interval < 15*$day_len) {
953 0 $min_samp = 2*$day_len;
954 } elsif ($interval < 30*$day_len) {
955 0 $min_samp = 3*$day_len;
956 } else {
957 0 $min_samp = 30*$day_len;
958 }
959 0 $min_samp /= $samp_scale;
960 0 my $start_min = int($start/$min_samp);
961 0 my $end_min = int($end/$min_samp);
962 0 my @tics;
963  
964 0 my $first_date_shown = 0;
965 0 ▶ for (my $curr_min = $start_min; $curr_min <= $end_min; $curr_min++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curr_min <= $end_min) 0 0 0
966 0 my $bucket = $curr_min*$min_samp;
967 0 my $bucket_str;
968 0 my @time_data = gmtime($bucket);
969 0 $time_data[$#time_data] = -1; # unset dst data, broken strftime
970 0 ▶ if ($min_samp >= $min_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min_samp >= $min_len) { } 0 0 0
971 0 $bucket_str = strftime('%H:%M', @time_data);
972 } else {
973 0 $bucket_str = strftime('%H:%M:%S', @time_data);
974 }
975 0 my $show_date = 0;
976 0 ▶ if ($bucket_str =~ /^00:00(:00)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bucket_str =~ /^00:00(:00)?$/) 0 0 0
977 0 $show_date = 1;
978 0 $first_date_shown = 1;
979 }
980 0 ▶ if ($curr_min == $start_min + 1 && !$first_date_shown) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curr_min == $start_min + 1 and not $first_date_shown) 0 0 0
Condition0%0/3
$curr_min == $start_min + 1 and not $first_date_shown
!ll&&!rl&&r
000
MC/DC0%0/2
$curr_min == $start_min + 1 and not $first_date_shown
$curr_min == $start_min + 1 not $first_date_shown
Truth table0%0/3
A and not(B)
A= $curr_min == $start_min + 1B= not $first_date_shown
ABresult
0X0
100
111
981 0 $show_date = 1;
982 }
983 0 ▶ if ($show_date) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show_date) 0 0 0
984 0 $bucket_str .= strftime('\n%m/%d', @time_data);
985 }
986 0 push @tics, [ $bucket_str, ($bucket - $start) / $end ];
987 }
988  
989 # must check to see if xtics were previously set in the globals
990 # if they are, we'll append them to the time stamp tics
991 # note: collisions are handled by the user
992  
993 0 ▶ if (defined ($global_options->{"xtics"})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $global_options->{"xtics"}) 0 0 0
994 0 push @tics, @{$global_options->{"xtics"}};
995 }
996
997 0 $global_options->{"xtics"} = \@tics;
998 0 return 1;
999 }
1000  
1001 4 1;
1002  
1003 __END__
« Graph/Xrt3d.pm ↑ Summary Graph/Xmgrace.pm »