File Coverage

blib/lib/Chart/Graph/Xmgrace/Graph_Options.pm
Criterion Covered Total %
statement 88 159 55.3
branch 9 14 64.2
condition n/a
subroutine 15 30 50.0
pod n/a
total 112 203 55.1


line stmt bran cond sub pod time code
1             #
2             # Graph_Options.pm contains all the different options (objects) for a particular graph
3             #
4             # options included:
5             # 1) Chart::Graph::Xmgrace::Graph_Global_Options
6             # 2) Chart::Graph::Xmgrace::Global_Options
7             # 3) Chart::Graph::Xmgrace::Stack_Options
8             # 4) Chart::Graph::Xmgrace::View_Options
9             # 5) Chart::Graph::Xmgrace::Title_Options
10             # 6) Chart::Graph::Xmgrace::Subtitle_Options
11             # 7) Chart::Graph::Xmgrace::Legend_Options
12             # 8) Chart::Graph::Xmgrace::Frame_Options
13             # 9) Chart::Graph::Xmgrace::Extra_Options
14             #
15             ## This software product is developed by Esmond Lee and David Moore,
16             ## and copyrighted(C) 1998 by the University of California, San Diego
17             ## (UCSD), with all rights reserved. UCSD administers the CAIDA grant,
18             ## NCR-9711092, under which part of this code was developed.
19             ##
20             ## There is no charge for this software. You can redistribute it and/or
21             ## modify it under the terms of the GNU General Public License, v. 2 dated
22             ## June 1991 which is incorporated by reference herein. This software is
23             ## distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF MERCHANTABILITY
24             ## OR FITNESS FOR A PARTICULAR PURPOSE or that the use of it will not
25             ## infringe on any third party's intellectual property rights.
26             ##
27             ## You should have received a copy of the GNU GPL along with this program.
28             ##
29             ##
30             ## IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
31             ## PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
32             ## DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
33             ## SOFTWARE, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF
34             ## THE POSSIBILITY OF SUCH DAMAGE.
35             ##
36             ## THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE
37             ## UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
38             ## SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. THE UNIVERSITY
39             ## OF CALIFORNIA MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES
40             ## OF ANY KIND, EITHER IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED
41             ## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
42             ## PARTICULAR PURPOSE, OR THAT THE USE OF THE SOFTWARE WILL NOT INFRINGE
43             ## ANY PATENT, TRADEMARK OR OTHER RIGHTS.
44             ##
45             ##
46             ## Contact: graph-dev@caida.org
47             ##
48             ##
49              
50             $VERSION = 3.2;
51              
52 4     4   2784 use Chart::Graph::Xmgrace::Base_Option;
  4         13  
  4         112  
53 4     4   23 use Carp;
  4         6  
  4         9295  
54             package Chart::Graph::Xmgrace::Graph_Global_Options;
55             @ISA = qw(Chart::Graph::Xmgrace::Base_Option);
56              
57             sub _init {
58 3     3   5 my $self = shift;
59 3         4 my $graph_number = shift;
60              
61 3         11 $self->{name} = $graph_number;
62 3         15 $self->{print_order} = ["stacked","hidden","type","bar hgap","fixedpoint",
63             "fixedpoint type","fixedpoint xy","fixedpoint format",
64             "fixedpoint prec","with"];
65 3         6 $self->{length} = 0;
66 3         28 $self->{options} = {
67             "stacked" => "false",
68             "hidden" => "false",
69             "type" => "XY",
70             "bar hgap" => '0.000000',
71             "fixedpoint" => "off",
72             "fixedpoint type" => "0",
73             "fixedpoint xy" => ["0.000000","0.000000"],
74             "fixedpoint format" => "general general",
75             "fixedpoint prec" => ["6","6"],
76             "with" => $graph_number,
77             };
78             }
79              
80             sub print($$ ) {
81 1     1   2 my $self = shift;
82 1         2 my $handle = shift;
83 1         2 my $string = "";
84 1         2 my $substr = ""; # for making arrays into a string
85              
86 1         2 foreach $option (@{ $self->{"print_order"} }) {
  1         4  
87 10         190 my $option_ref = $self->{"options"};
88              
89             # print function handles both scalars and lists
90 10 50       671 if ($self->{name}) {
91 10 100       207 if (ref($option_ref->{$option}) eq ARRAY) {
    100          
92 2         177 $substr = join (", ", (@{ $option_ref->{$option} }));
  2         179  
93 2         10 $string = "$self->{name} $option $substr\n";
94             } elsif ($option eq "with") {
95 1         5 $string = "$option $option_ref->{$option}\n";
96             } else {
97 7         1275 $string = "$self->{name} $option $option_ref->{$option}\n";
98             }
99             } else { # global options don't have a name field
100 0 0       0 if (ref($option_ref->{$option}) eq ARRAY) {
101 0         0 $substr = join (", ", (@{ $option_ref->{$option} }));
  0         0  
102 0         0 $string = "$option $substr\n";
103             } else {
104 0         0 $string = "$option $option_ref->{$option}\n";
105             }
106             }
107 10         1061 $self->_printline($handle, $string, $self->{"length"});
108             }
109             }
110              
111              
112             package Chart::Graph::Xmgrace::Global_Options;
113             @ISA = qw(Chart::Graph::Xmgrace::Base_Option);
114              
115             sub _init {
116 3     3   4 my $self = shift;
117 3         16 $self->{print_order} = ["version","page size","page scroll","page inout",
118             "link page","reference date","date wrap",
119             "date wrap year"];
120 3         4 $self->{length} = 0;
121 3         26 $self->{options} = {
122             "version" => "50005",
123             "page size" => ["640", "480"],
124             "page scroll" => "5\%",
125             "page inout" => "5\%",
126             "link page" => "off",
127             "reference date" => "0",
128             "date wrap" => "off",
129             "date wrap year" => "1950",
130             };
131             }
132              
133             sub page_size ($$) {
134 0     0   0 $self = shift;
135 0         0 $val = shift;
136 0         0 $self->{options}->{"page size"} = $val;
137 0         0 return 1;
138             }
139              
140             sub page_scroll ($$) {
141 0     0   0 $self = shift;
142 0         0 $val = shift;
143 0         0 $self->{options}->{"page size"} = $val;
144 0         0 return 1;
145             }
146              
147             sub page_inout ($$) {
148 0     0   0 $self = shift;
149 0         0 $val = shift;
150 0         0 $self->{options}->{"page size"} = $val;
151 0         0 return 1;
152             }
153              
154             sub link_page ($$) {
155 0     0   0 $self = shift;
156 0         0 $val = shift;
157 0         0 $self->{options}->{"link page"} = $val;
158 0         0 return 1;
159             }
160              
161             sub reference_date ($$) {
162 0     0   0 $self = shift;
163 0         0 $val = shift;
164 0         0 $self->{options}->{"reference date"} = $val;
165 0         0 return 1;
166             }
167              
168             sub date_wrap ($$) {
169 0     0   0 $self = shift;
170 0         0 $val = shift;
171 0         0 $self->{options}->{"date wrap"} = $val;
172 0         0 return 1;
173             }
174              
175             sub date_wrap_year ($$) {
176 0     0   0 $self = shift;
177 0         0 $val = shift;
178 0         0 $self->{options}->{"date wrap year"} = $val;
179 0         0 return 1;
180             }
181              
182             package Chart::Graph::Xmgrace::World_Options;
183             @ISA = qw(Chart::Graph::Xmgrace::Base_Option);
184              
185             my %def_world_options = (
186             );
187              
188             sub _init {
189 3     3   4 my $self = shift;
190 3         10 $self->{name} = "world";
191 3         7 $self->{print_order} = ["xmin","xmax","ymin","ymax"];
192 3         5 $self->{length} = 4;
193 3         14 $self->{options} = {
194             "xmin" => "0",
195             "xmax" => "1",
196             "ymin" => "0",
197             "ymax" => "1",
198             };
199             }
200              
201             package Chart::Graph::Xmgrace::Stack_Options;
202             @ISA = qw(Chart::Graph::Xmgrace::Base_Option);
203              
204             my %def_stack_options = (
205            
206             );
207              
208             sub _init {
209 3     3   5 my $self = shift;
210 3         11 $self->{name} = "stack";
211 3         6 $self->{print_order} = ["world"];
212 3         6 $self->{length} = 4;
213 3         12 $self->{options} = {
214             "world" => ["0","0","0","0"],
215             };
216             }
217              
218             package Chart::Graph::Xmgrace::View_Options;
219             @ISA = qw(Chart::Graph::Xmgrace::Base_Option);
220              
221             sub _init {
222 3     3   4 my $self = shift;
223 3         9 $self->{name} = "view";
224 3         7 $self->{print_order} = ["xmin","xmax","ymin","ymax"];
225 3         6 $self->{length} = 4;
226 3         12 $self->{options} = {
227             "xmin" => "0.150000",
228             "xmax" => "1.150000",
229             "ymin" => "0.150000",
230             "ymax" => "0.850000",
231             };
232             }
233              
234             package Chart::Graph::Xmgrace::Title_Options;
235             @ISA = qw(Chart::Graph::Xmgrace::Base_Option);
236              
237             sub _init {
238 3     3   4 my $self = shift;
239 3         12 $self->{name} = "title";
240 3         10 $self->{print_order} = ["title","font","size","color"];
241 3         4 $self->{length} = 4;
242 3         14 $self->{options} = {
243             "title" => '""',
244             "font" => "0",
245             "size" => "1.250000",
246             "color" => "1",
247             };
248             }
249              
250             sub print($$ ) {
251 2     2   4 my $self = shift;
252 2         4 my $handle = shift;
253 2         3 my $string = "";
254 2         3 my $substr = ""; # for making arrays into a string
255              
256 2         13 foreach $option (@{ $self->{"print_order"} }) {
  2         6  
257 8         14 my $option_ref = $self->{"options"};
258            
259 8 100       17 if ($option eq "title") {
260 2         8 $string = "$self->{name} \"$option_ref->{$option}\"\n";
261             } else {
262             # print function handles both scalars and lists
263 6 50       18 if (ref($option_ref->{$option}) eq ARRAY) {
264 0         0 $substr = join (", ", (@{ $option_ref->{$option} }));
  0         0  
265 0         0 $string = "$self->{name} $option $substr\n";
266             } else {
267 6         18 $string = "$self->{name} $option $option_ref->{$option}\n";
268             }
269             }
270 8         41 $self->_printline($handle, $string, $self->{"length"});
271             }
272             }
273              
274             package Chart::Graph::Xmgrace::Subtitle_Options;
275             @ISA = qw(Chart::Graph::Xmgrace::Title_Options);
276              
277             sub _init {
278 3     3   12 my $self = shift;
279 3         12 $self->{name} = "subtitle";
280 3         8 $self->{print_order} = ["title","font","size","color"];
281 3         5 $self->{length} = 4;
282 3         13 $self->{options} = {
283             "title" => '""',
284             "font" => "0",
285             "size" => "1.000000",
286             "color" => "1",
287             };
288             }
289              
290             package Chart::Graph::Xmgrace::Legend_Options;
291             @ISA = qw(Chart::Graph::Xmgrace::Base_Option);
292              
293             sub _init {
294 3     3   4 my $self = shift;
295 3         11 $self->{name} = "legend";
296 3         13 $self->{print_order} = ["status","loctype","x1","y1","box color",
297             "box pattern","box linewidth","box linestyle",
298             "box fill color","box fill pattern","font",
299             "char size","color","length","vgap","hgap",
300             "invert"];
301 3         7 $self->{length} = 4;
302 3         46 $self->{options} = {
303             "status" => "on",
304             "loctype" => "view",
305             "x1" => "0.85",
306             "y1" => "0.8",
307             "box color" => "1",
308             "box pattern" => "1",
309             "box linewidth" => "1.0",
310             "box linestyle" => "1",
311             "box fill color" => "0",
312             "box fill pattern" => "1",
313             "font" => "0",
314             "char size" => "1.000000",
315             "color" => "1",
316             "length" => "4",
317             "vgap" => "1",
318             "hgap" => "1",
319             "invert" => "false",
320             };
321             }
322              
323             sub box_color ($$) {
324 0     0   0 $self = shift;
325 0         0 $val = shift;
326 0         0 $self->{options}->{"box color"} = $val;
327 0         0 return 1;
328             }
329              
330             sub box_linewidth ($$) {
331 0     0   0 $self = shift;
332 0         0 $val = shift;
333 0         0 $self->{options}->{"box linewidth"} = $val;
334 0         0 return 1;
335             }
336              
337             sub box_linestyle ($$) {
338 0     0   0 $self = shift;
339 0         0 $val = shift;
340 0         0 $self->{options}->{"box linestyle"} = $val;
341 0         0 return 1;
342             }
343              
344             sub box_fill_color ($$) {
345 0     0   0 $self = shift;
346 0         0 $val = shift;
347 0         0 $self->{options}->{"box fill color"} = $val;
348 0         0 return 1;
349             }
350              
351             sub box_fill_pattern ($$) {
352 0     0   0 $self = shift;
353 0         0 $val = shift;
354 0         0 $self->{options}->{"box fill pattern"} = $val;
355 0         0 return 1;
356             }
357              
358             sub char_size ($$) {
359 0     0   0 $self = shift;
360 0         0 $val = shift;
361 0         0 $self->{options}->{"char size"} = $val;
362 0         0 return 1;
363             }
364              
365             package Chart::Graph::Xmgrace::Frame_Options;
366             @ISA = qw(Chart::Graph::Xmgrace::Base_Option);
367              
368             sub _init {
369 3     3   5 my $self = shift;
370 3         10 $self->{name} = "frame";
371 3         10 $self->{print_order} = ["type","linestyle","linewidth","color",
372             "pattern","background color","background pattern"];
373 3         5 $self->{length} = 4;
374 3         17 $self->{options} = {
375             "type" => "0",
376             "linestyle" => "1",
377             "linewidth" => "1.0",
378             "color" => "1",
379             "pattern" => "1",
380             "background color" => "0",
381             "background pattern" => "0",
382             };
383             }
384              
385             sub background_color ($$) {
386 0     0   0 $self = shift;
387 0         0 $val = shift;
388 0         0 $self->{options}->{"background color"} = $val;
389 0         0 return 1;
390             }
391              
392             sub background_pattern ($$) {
393 0     0   0 $self = shift;
394 0         0 $val = shift;
395 0         0 $self->{options}->{"background pattern"} = $val;
396 0         0 return 1;
397             }
398              
399              
400             package Chart::Graph::Xmgrace::Extra_Options;
401             @ISA = qw(Chart::Graph::Xmgrace::Base_Option);
402              
403             sub _init {
404 3     3   4 my $self = shift;
405 3         11 $self->{name} = "extra options";
406 3         5 $self->{length} = 4;
407 3         16 $self->{options} = {"extras" => undef,}; # extra options are \n delimited
408             }
409              
410              
411             # just dumps, verbatim, whatever the user inputs
412             sub print($$ ) {
413 1     1   3 my $self = shift;
414 1         3 my $handle = shift;
415 1         1 my $string = "";
416 1         2 my @xtra_opts;
417 1         4 my $pre_sub = $self->{options}->{extras};
418 1 50       8 if ($pre_sub) {
419 0           @xtra_opts = split(/;\n*\s*/, $pre_sub);
420            
421 0           foreach $option (@xqtra_opts) {
422 0           $self->_printline($handle, "$option\n", $self->{"length"});
423             }
424             }
425             }
426              
427             1;