File Coverage

blib/lib/Chart/Graph/Xmgrace/Axis_Options.pm
Criterion Covered Total %
statement 88 144 61.1
branch 17 26 65.3
condition 10 12 83.3
subroutine 11 17 64.7
pod n/a
total 126 199 63.3


line stmt bran cond sub pod time code
1             #
2             # Chart::Graph::Xmgrace::Axis_Options.pm contains all the fundamental options
3             # for an axis.
4             #
5             # Options included:
6             # 1) Chart::Graph::Xmgrace::Bar_Options
7             # 2) Chart::Graph::Xmgrace::Label_Options
8             # 3) Chart::Graph::Xmgrace::Tickmark
9             # 4) Chart::Graph::Xmgrace::Tick_Options
10             # 5) Chart::Graph::Xmgrace::Ticklabel_Options
11             #
12             ## This software product is developed by Esmond Lee and David Moore,
13             ## and copyrighted(C) 1998 by the University of California, San Diego
14             ## (UCSD), with all rights reserved. UCSD administers the CAIDA grant,
15             ## NCR-9711092, under which part of this code was developed.
16             ##
17             ## There is no charge for this software. You can redistribute it and/or
18             ## modify it under the terms of the GNU General Public License, v. 2 dated
19             ## June 1991 which is incorporated by reference herein. This software is
20             ## distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF MERCHANTABILITY
21             ## OR FITNESS FOR A PARTICULAR PURPOSE or that the use of it will not
22             ## infringe on any third party's intellectual property rights.
23             ##
24             ## You should have received a copy of the GNU GPL along with this program.
25             ##
26             ##
27             ## IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
28             ## PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
29             ## DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS
30             ## SOFTWARE, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF
31             ## THE POSSIBILITY OF SUCH DAMAGE.
32             ##
33             ## THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE
34             ## UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
35             ## SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. THE UNIVERSITY
36             ## OF CALIFORNIA MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES
37             ## OF ANY KIND, EITHER IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED
38             ## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
39             ## PARTICULAR PURPOSE, OR THAT THE USE OF THE SOFTWARE WILL NOT INFRINGE
40             ## ANY PATENT, TRADEMARK OR OTHER RIGHTS.
41             ##
42             ##
43             ## Contact: graph-dev@caida.org
44             ##
45             ##
46              
47             $VERSION = 3.2;
48              
49 4     4   2620 use Chart::Graph::Xmgrace::Axis_Option;
  4         11  
  4         116  
50 4     4   24 use Carp;
  4         6  
  4         15644  
51              
52             package Chart::Graph::Xmgrace::Bar_Options;
53             @ISA = qw(Chart::Graph::Xmgrace::Axis_Option); # derived from Axis_Option
54              
55             sub _init {
56 12     12   11 my $self = shift;
57 12         23 $self->{name} = "bar";
58 12         35 $self->{print_order} = ["status","color","linestyle","linewidth"];
59 12         16 $self->{length} = 4;
60 12         42 $self->{options} = {
61             "status" => "on",
62             "color" => "1",
63             "linestyle" => "1",
64             "linewidth" => "1.0",
65             };
66             }
67              
68             package Chart::Graph::Xmgrace::Label_Options;
69             @ISA = qw(Chart::Graph::Xmgrace::Axis_Option);
70              
71             sub _init {
72 12     12   13 my $self = shift;
73 12         24 $self->{name} = "label";
74 12         26 $self->{print_order} = ["label","layout","place","char size",
75             "font", "color", "place"];
76 12         23 $self->{length} = 4;
77 12         57 $self->{options} = {
78             "label" => "",
79             "layout" => "para",
80             "place" => "auto",
81             "char size" => "1.000000",
82             "font" => "0",
83             "color" => "1",
84             "place" => "auto",
85             };
86             }
87              
88             sub char_size ($$) {
89 0     0   0 $self = shift;
90 0         0 $val = shift;
91 0         0 $self->{options}->{"char size"} = $val;
92 0         0 return 1;
93             }
94              
95             sub print ($$$ ) {
96 2     2   4 my $self = shift;
97 2         10 my ($handle, $name) = @_;
98 2         3 my $string = "";
99 2         3 my $substr = "";
100            
101 2         4 foreach $option (@{ $self->{"print_order"} }) {
  2         6  
102 14         17 my $option_ref = $self->{"options"};
103            
104 14 100       28 if ($option eq "label") {
105 2         7 $string = "$name $option \"$option_ref->{$option}\"\n";
106             } else {
107             # if ($option eq "place") {
108             # if (ref($option_ref->{$option} eq ARRAY) {
109             # print $handle "$name $self->{name} $option spec\n";
110             # $substr = join (", ", (@{ $option_ref->{$option} }));
111             # $string = "$name $self->{name} $option "
112             # }
113             # }
114            
115             # print function handles both scalars and lists
116 12 50       24 if (ref($option_ref->{$option}) eq ARRAY) {
117 0 0       0 if ($option eq "place") {
118 0         0 $self->_printline($handle,"$name $self->{name} $option spec\n", $self->{"length"});
119             }
120              
121 0         0 $substr = join (", ", (@{ $option_ref->{$option} }));
  0         0  
122 0         0 $string = "$name $self->{name} $option $substr\n";
123             } else {
124 12         32 $string = "$name $self->{name} $option $option_ref->{$option}\n";
125             }
126             }
127 14         43 $self->_printline($handle, $string, $self->{"length"});
128             }
129             }
130              
131             package Chart::Graph::Xmgrace::Tickmark;
132             @ISA = qw(Chart::Graph::Xmgrace::Axis_Option);
133              
134             sub _init {
135 24     24   23 my $self = shift;
136 24         24 my $type_of_mark = shift; # major or minor
137 24         53 $self->{name} = "$type_of_mark";
138 24         46 $self->{print_order} = ["size","color","linewidth","linestyle",
139             "grid"];
140 24         26 $self->{length} = 4;
141 24         102 $self->{options} = {
142             "size" => "1",
143             "color" => "1",
144             "linewidth" => "1.0",
145             "linestyle" => "1.000000",
146             "grid" => "off",
147             };
148             }
149              
150             sub print ($$$$ ) {
151 4     4   6 my $self = shift;
152 4         7 my ($handle, $name, $subname) = @_;
153 4         6 my $string = "";
154 4         5 my $substr = "";
155            
156 4         5 foreach $option (@{ $self->{"print_order"} }) {
  4         10  
157 20         25 my $option_ref = $self->{"options"};
158            
159             # print function handles both scalars and lists
160 20 50       202 if (!ref($option_ref->{$option})) {
    0          
161 20         46 $string = "$name $subname $self->{name} $option $option_ref->{$option}\n";
162 20         47 $self->_printline($handle, $string, $self->{"length"});
163             } elsif (ref($option_ref->{$option}) eq ARRAY) {
164 0         0 $substr = join (", ", (@{ $option_ref->{$option} }));
  0         0  
165 0         0 $string = "$name $subname $self->{name} $option $substr\n";
166 0         0 $self->_printline($handle, $string, $self->{"length"});
167             } else { # a blessed object, uses Axis Option printline
168 0         0 print "shouldn't be in here\n";
169             }
170             }
171             }
172              
173             package Chart::Graph::Xmgrace::Tick_Options;
174             @ISA = qw(Chart::Graph::Xmgrace::Axis_Option);
175              
176             sub _init {
177 12     12   12 my $self = shift;
178 12         21 $self->{name} = "tick";
179 12         27 $self->{print_order} = ["status","default","place rounded","major",
180             "minor","in_out_status","place","type"];
181 12         15 $self->{length} = 4;
182 12         49 $self->{options} = {
183             "status" => "on",
184             "default" => "6",
185             "place rounded" => "true",
186             "major" => new Chart::Graph::Xmgrace::Tickmark("major"),
187             "minor" => new Chart::Graph::Xmgrace::Tickmark("minor"),
188             "in_out_status" => "in",
189             "place" => "both",
190             "type" => "auto",
191             };
192             }
193              
194             sub place_rounded ($$) {
195 0     0   0 $self = shift;
196 0         0 $val = shift;
197 0         0 $self->{options}->{"place rounded"} = $val;
198 0         0 return 1;
199             }
200              
201             sub print ($$$$ ) {
202 2     2   4 my $self = shift;
203 2         4 my ($handle, $name) = @_;
204 2         4 my $string = "";
205 2         2 my $substr = "";
206            
207 2         3 foreach $option (@{ $self->{"print_order"} }) {
  2         6  
208 16         20 my $option_ref = $self->{"options"};
209             # special case for "status" and "in_out_status"
210 16 100 100     55 if ($option eq "status" or $option eq "in_out_status") {
211 4         12 $string = "$name $self->{name} $option_ref->{$option}\n";
212 4         15 $self->_printline($handle, $string, $self->{"length"});
213             } else {
214              
215             # print function handles both scalars and lists
216 12 100       30 if (!ref($option_ref->{$option})) {
    50          
217 8         19 $string = "$name $self->{name} $option $option_ref->{$option}\n";
218 8         51 $self->_printline($handle, $string, $self->{"length"});
219             } elsif (ref($option_ref->{$option}) eq ARRAY) {
220 0         0 $substr = join (", ", (@{ $option_ref->{$option} }));
  0         0  
221 0         0 $string = "$name $self->{name} $option $substr\n";
222 0         0 $self->_printline($handle, $string, $self->{"length"});
223             } else { # a blessed object, uses Tickmark print
224 4         19 $option_ref->{$option}->print($handle, $name, $self->{name});
225             }
226             }
227             }
228             }
229              
230              
231              
232             package Chart::Graph::Xmgrace::Ticklabel_Options;
233             @ISA = qw(Chart::Graph::Xmgrace::Axis_Option);
234              
235             sub _init {
236 12     12   14 my $self = shift;
237 12         23 $self->{name} = "ticklabel";
238 12         15 $self->{ticklabels} = undef; # user can put in a ref of array of arrays of ticklabels
239             # i.e. [ ["small\\nfoo", 10], ["medium\\nfoo", 20], ["large\\nfoo", 30] ]
240 12         34 $self->{print_order} = ["status", "prec", "format", "append", "prepend",
241             "angle", "skip", "stagger", "place", "offset",
242             "sign", "start type", "start", "stop type", "stop",
243             "char size", "font", "color", "type"];
244 12         14 $self->{length} = 4;
245 12         125 $self->{options} = {
246             "status" => "on",
247             "prec" => "5",
248             "format" => "general",
249             "append" => "",
250             "prepend" => "",
251             "angle" => "0",
252             "skip" => "0",
253             "stagger" => "0",
254             "place" => "normal",
255             "offset" => ["0.000000", "0.000000"],
256             "sign" => "normal",
257             "start type" => "auto",
258             "start" => "0.000000",
259             "stop type" => "auto",
260             "stop" => "0.000000",
261             "char size" => "1.000000",
262             "font" => "0",
263             "color" => "1",
264             "type" => "auto",
265             };
266             }
267              
268             sub ticklabels ($$) {
269 0     0   0 $self = shift;
270 0         0 $val = shift;
271 0         0 $self->{ticklabels} = $val;
272 0         0 return 1;
273             }
274              
275             sub char_size ($$) {
276 0     0   0 $self = shift;
277 0         0 $val = shift;
278 0         0 $self->{options}->{"char size"} = $val;
279 0         0 return 1;
280             }
281              
282             sub start_type ($$) {
283 0     0   0 $self = shift;
284 0         0 $val = shift;
285 0         0 $self->{options}->{"start type"} = $val;
286 0         0 return 1;
287             }
288              
289             sub stop_type ($$) {
290 0     0   0 $self = shift;
291 0         0 $val = shift;
292 0         0 $self->{options}->{"stop type"} = $val;
293 0         0 return 1;
294             }
295              
296             sub print ($$$ ) {
297 2     2   3 my $self = shift;
298 2         5 my ($handle, $name) = @_;
299 2         2 my $string = "";
300 2         3 my $substr = "";
301            
302 2         3 foreach $option (@{ $self->{"print_order"} }) {
  2         6  
303 38         46 my $option_ref = $self->{"options"};
304              
305 38 100 66     183 if ($option eq "status" or $option eq "in_out_status") {
    50 66        
306            
307             # we first check the status of the option, whether it's on/off
308             # if it's off, we don't print it out
309 2 50       6 if ($option_ref->{"status"} eq "off") {
310 0         0 $string = "$name $self->{name} $option_ref->{$option}\n";
311 0         0 $self->_printline($handle, $string, $self->{"length"});
312 0         0 last;
313             }
314 2         8 $string = "$name $self->{name} $option_ref->{$option}\n";
315 2         9 $self->_printline($handle, $string, $self->{"length"});
316              
317             } elsif ($option eq "type" and $self->{ticklabels}) {
318              
319 0         0 $string = "$name $self->{name} $option $option_ref->{$option}\n";
320 0         0 $self->_printline($handle, $string, $self->{"length"});
321 0         0 my @ticks = @{$self->{"ticklabels"}};
  0         0  
322 0         0 my $index;
323 0         0 my $count = $#ticks+1;
324 0         0 $string = "$name tick spec $count\n";
325 0         0 $self->_printline($handle, $string, $self->{"length"});
326             # print out the tick labels
327 0         0 foreach $index (0..$#ticks) {
328 0         0 my ($label, $value) = @{$ticks[$index]};
  0         0  
329 0         0 my $ticklabel = "$name tick major $index,\t\t$value\n";
330 0         0 $self->_printline($handle, $ticklabel, $self->{"length"});
331 0         0 $ticklabel = "$name $self->{name} $index, \"$label\"\n";
332 0         0 $self->_printline($handle, $ticklabel, $self->{"length"});
333             }
334             } else {
335 36 100 100     119 if ($option eq "append" or $option eq "prepend") {
336 4         10 $string = "$name $self->{name} $option \"$option_ref->{$option}\"\n";
337             } else {
338             # print function handles both scalars and lists
339 32 100       65 if (ref($option_ref->{$option}) eq ARRAY) {
340 2         3 $substr = join (", ", (@{ $option_ref->{$option} }));
  2         6  
341 2         5 $string = "$name $self->{name} $option $substr\n";
342             } else {
343 30         65 $string = "$name $self->{name} $option $option_ref->{$option}\n";
344             }
345             }
346 36         93 $self->_printline($handle, $string, $self->{"length"});
347             }
348             }
349             }
350              
351             1;
352              
353