Graph/Xmgrace/Axis_Options.pm

filter: Statementstmt 62.9% 95 / 151 Branchbran 65.3% 17 / 26 Conditioncond 83.3% 10 / 12 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 64.7% 11 / 17 Podpod n/a totaltotal 64.4% 138 / 214 CC 23 SCAR 20.7
CC
23
Cov
65%
print
18.3
print
6.2
print
6.1
CRAP 7.9
« Graph/Utils.pm ↑ Summary Graph/Xmgrace/Base_Option.pm »
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 4 $VERSION = 3.2;
48  
49 4 ▶use Chart::Graph::Xmgrace::Axis_Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 package Chart::Graph::Xmgrace::Bar_Options;
53 4 @ISA = qw(Chart::Graph::Xmgrace::Axis_Option); # derived from Axis_Option
54  
55 12 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
56 12 my $self = shift;
57 12 $self->{name} = "bar";
58 12 $self->{print_order} = ["status","color","linestyle","linewidth"];
59 12 $self->{length} = 4;
60 $self->{options} = {
61 12 "status" => "on",
62 "color" => "1",
63 "linestyle" => "1",
64 "linewidth" => "1.0",
65 };
66 }
67  
68 package Chart::Graph::Xmgrace::Label_Options;
69 4 @ISA = qw(Chart::Graph::Xmgrace::Axis_Option);
70  
71 12 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
72 12 my $self = shift;
73 12 $self->{name} = "label";
74 12 $self->{print_order} = ["label","layout","place","char size",
75 "font", "color", "place"];
76 12 $self->{length} = 4;
77 $self->{options} = {
78 12 "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 0 ▶sub char_size ($$) {
Subroutine char_size: not called CC=1 SCAR=6.9
89 0 $self = shift;
90 0 $val = shift;
91 0 $self->{options}->{"char size"} = $val;
92 0 return 1;
93 }
94  
95 2 ▶sub print ($$$ ) {
Subroutine print: called CC=5 SCAR=18.0
96 2 my $self = shift;
97 2 my ($handle, $name) = @_;
98 2 my $string = "";
99 2 my $substr = "";
100
101 2 foreach $option (@{ $self->{"print_order"} }) {
102 14 my $option_ref = $self->{"options"};
103
104 14 ▶ if ($option eq "label") {
Branch: 1 branch
BranchTrueFalseTotal
if ($option eq 'label') { } 2 12 14
105 2 $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 ▶ if (ref($option_ref->{$option}) eq ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $option_ref->{$option} eq 'ARRAY') { } 0 12 12
117 0 ▶ if ($option eq "place") {
Branch: 1 branch
BranchTrueFalseTotal
if ($option eq "place") 0 0 0
118 0 $self->_printline($handle,"$name $self->{name} $option spec\n", $self->{"length"});
119 }
120  
121 0 $substr = join (", ", (@{ $option_ref->{$option} }));
122 0 $string = "$name $self->{name} $option $substr\n";
123 } else {
124 12 $string = "$name $self->{name} $option $option_ref->{$option}\n";
125 }
126 }
127 14 $self->_printline($handle, $string, $self->{"length"});
128 }
129 }
130  
131 package Chart::Graph::Xmgrace::Tickmark;
132 4 @ISA = qw(Chart::Graph::Xmgrace::Axis_Option);
133  
134 24 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
135 24 my $self = shift;
136 24 my $type_of_mark = shift; # major or minor
137 24 $self->{name} = "$type_of_mark";
138 24 $self->{print_order} = ["size","color","linewidth","linestyle",
139 "grid"];
140 24 $self->{length} = 4;
141 $self->{options} = {
142 24 "size" => "1",
143 "color" => "1",
144 "linewidth" => "1.0",
145 "linestyle" => "1.000000",
146 "grid" => "off",
147 };
148 }
149  
150 4 ▶sub print ($$$$ ) {
Subroutine print: called CC=4 SCAR=16.5
151 4 my $self = shift;
152 4 my ($handle, $name, $subname) = @_;
153 4 my $string = "";
154 4 my $substr = "";
155
156 4 foreach $option (@{ $self->{"print_order"} }) {
157 20 my $option_ref = $self->{"options"};
158
159 # print function handles both scalars and lists
160 20 ▶ if (!ref($option_ref->{$option})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $option_ref->{$option}) { } 20 0 20
elsif (ref $option_ref->{$option} eq 'ARRAY') { } 0 0 0
161 20 $string = "$name $subname $self->{name} $option $option_ref->{$option}\n";
162 20 $self->_printline($handle, $string, $self->{"length"});
163 } elsif (ref($option_ref->{$option}) eq ARRAY) {
164 0 $substr = join (", ", (@{ $option_ref->{$option} }));
165 0 $string = "$name $subname $self->{name} $option $substr\n";
166 0 $self->_printline($handle, $string, $self->{"length"});
167 } else { # a blessed object, uses Axis Option printline
168 0 print "shouldn't be in here\n";
169 }
170 }
171 }
172  
173 package Chart::Graph::Xmgrace::Tick_Options;
174 4 @ISA = qw(Chart::Graph::Xmgrace::Axis_Option);
175  
176 12 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
177 12 my $self = shift;
178 12 $self->{name} = "tick";
179 12 $self->{print_order} = ["status","default","place rounded","major",
180 "minor","in_out_status","place","type"];
181 12 $self->{length} = 4;
182 $self->{options} = {
183 12 "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 0 ▶sub place_rounded ($$) {
Subroutine place_rounded: not called CC=1 SCAR=6.9
195 0 $self = shift;
196 0 $val = shift;
197 0 $self->{options}->{"place rounded"} = $val;
198 0 return 1;
199 }
200  
201 2 ▶sub print ($$$$ ) {
Subroutine print: called CC=6 SCAR=18.3
202 2 my $self = shift;
203 2 my ($handle, $name) = @_;
204 2 my $string = "";
205 2 my $substr = "";
206
207 2 foreach $option (@{ $self->{"print_order"} }) {
208 16 my $option_ref = $self->{"options"};
209 # special case for "status" and "in_out_status"
210 16 ▶ if ($option eq "status" or $option eq "in_out_status") {
Branch: 1 branch
BranchTrueFalseTotal
if ($option eq 'status' or $option eq 'in_out_status') { } 4 12 16
Condition100%3/3
$option eq "status" or $option eq "in_out_status"
l!l&&r!l&&!r
2212
MC/DC100%2/2
$option eq "status" or $option eq "in_out_status"
$option eq "status" $option eq "in_out_status"
Truth table100%3/3
A or B
A= $option eq "status"B= $option eq "in_out_status"
ABresult
1X1
011
000
211 4 $string = "$name $self->{name} $option_ref->{$option}\n";
212 4 $self->_printline($handle, $string, $self->{"length"});
213 } else {
214  
215 # print function handles both scalars and lists
216 12 ▶ if (!ref($option_ref->{$option})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $option_ref->{$option}) { } 8 4 12
elsif (ref $option_ref->{$option} eq 'ARRAY') { } 0 4 4
217 8 $string = "$name $self->{name} $option $option_ref->{$option}\n";
218 8 $self->_printline($handle, $string, $self->{"length"});
219 } elsif (ref($option_ref->{$option}) eq ARRAY) {
220 0 $substr = join (", ", (@{ $option_ref->{$option} }));
221 0 $string = "$name $self->{name} $option $substr\n";
222 0 $self->_printline($handle, $string, $self->{"length"});
223 } else { # a blessed object, uses Tickmark print
224 4 $option_ref->{$option}->print($handle, $name, $self->{name});
225 }
226 }
227 }
228 }
229  
230  
231  
232 package Chart::Graph::Xmgrace::Ticklabel_Options;
233 4 @ISA = qw(Chart::Graph::Xmgrace::Axis_Option);
234  
235 12 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
236 12 my $self = shift;
237 12 $self->{name} = "ticklabel";
238 12 $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 $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 $self->{length} = 4;
245 $self->{options} = {
246 12 "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 0 ▶sub ticklabels ($$) {
Subroutine ticklabels: not called CC=1 SCAR=6.9
269 0 $self = shift;
270 0 $val = shift;
271 0 $self->{ticklabels} = $val;
272 0 return 1;
273 }
274  
275 0 ▶sub char_size ($$) {
Subroutine char_size: not called CC=1 SCAR=6.9
276 0 $self = shift;
277 0 $val = shift;
278 0 $self->{options}->{"char size"} = $val;
279 0 return 1;
280 }
281  
282 0 ▶sub start_type ($$) {
Subroutine start_type: not called CC=1 SCAR=6.9
283 0 $self = shift;
284 0 $val = shift;
285 0 $self->{options}->{"start type"} = $val;
286 0 return 1;
287 }
288  
289 0 ▶sub stop_type ($$) {
Subroutine stop_type: not called CC=1 SCAR=6.9
290 0 $self = shift;
291 0 $val = shift;
292 0 $self->{options}->{"stop type"} = $val;
293 0 return 1;
294 }
295  
296 2 ▶sub print ($$$ ) {
Subroutine print: called CC=11 SCAR=29.1
297 2 my $self = shift;
298 2 my ($handle, $name) = @_;
299 2 my $string = "";
300 2 my $substr = "";
301
302 2 foreach $option (@{ $self->{"print_order"} }) {
303 38 my $option_ref = $self->{"options"};
304  
305 38 ▶ if ($option eq "status" or $option eq "in_out_status") {
Branch: 2 branches
BranchTrueFalseTotal
if ($option eq 'status' or $option eq 'in_out_status') { } 2 36 38
elsif ($option eq 'type' and $self->{'ticklabels'}) { } 0 36 36
Condition66%2/3
$option eq "status" or $option eq "in_out_status"
l!l&&r!l&&!r
2036
MC/DC50%1/2
$option eq "status" or $option eq "in_out_status"
$option eq "status" $option eq "in_out_status"
Truth table66%2/3
A or B
A= $option eq "status"B= $option eq "in_out_status"
ABresult
1X1
011
000
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 ▶ if ($option_ref->{"status"} eq "off") {
Branch: 1 branch
BranchTrueFalseTotal
if ($option_ref->{"status"} eq "off") 0 2 2
310 0 $string = "$name $self->{name} $option_ref->{$option}\n";
311 0 $self->_printline($handle, $string, $self->{"length"});
312 0 last;
313 }
314 2 $string = "$name $self->{name} $option_ref->{$option}\n";
315 2 $self->_printline($handle, $string, $self->{"length"});
316  
317 ▶ } elsif ($option eq "type" and $self->{ticklabels}) {
Condition66%2/3
$option eq "type" and $self->{"ticklabels"}
!ll&&!rl&&r
3420
MC/DC0%0/2
$option eq "type" and $self->{"ticklabels"}
$option eq "type" $self->{"ticklabels"}
Truth table66%2/3
A and B
A= $option eq "type"B= $self->{"ticklabels"}
ABresult
0X0
100
111
318  
319 0 $string = "$name $self->{name} $option $option_ref->{$option}\n";
320 0 $self->_printline($handle, $string, $self->{"length"});
321 0 my @ticks = @{$self->{"ticklabels"}};
322 0 my $index;
323 0 my $count = $#ticks+1;
324 0 $string = "$name tick spec $count\n";
325 0 $self->_printline($handle, $string, $self->{"length"});
326 # print out the tick labels
327 0 foreach $index (0..$#ticks) {
328 0 my ($label, $value) = @{$ticks[$index]};
329 0 my $ticklabel = "$name tick major $index,\t\t$value\n";
330 0 $self->_printline($handle, $ticklabel, $self->{"length"});
331 0 $ticklabel = "$name $self->{name} $index, \"$label\"\n";
332 0 $self->_printline($handle, $ticklabel, $self->{"length"});
333 }
334 } else {
335 36 ▶ if ($option eq "append" or $option eq "prepend") {
Branch: 1 branch
BranchTrueFalseTotal
if ($option eq 'append' or $option eq 'prepend') { } 4 32 36
Condition100%3/3
$option eq "append" or $option eq "prepend"
l!l&&r!l&&!r
2232
MC/DC100%2/2
$option eq "append" or $option eq "prepend"
$option eq "append" $option eq "prepend"
Truth table100%3/3
A or B
A= $option eq "append"B= $option eq "prepend"
ABresult
1X1
011
000
336 4 $string = "$name $self->{name} $option \"$option_ref->{$option}\"\n";
337 } else {
338 # print function handles both scalars and lists
339 32 ▶ if (ref($option_ref->{$option}) eq ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $option_ref->{$option} eq 'ARRAY') { } 2 30 32
340 2 $substr = join (", ", (@{ $option_ref->{$option} }));
341 2 $string = "$name $self->{name} $option $substr\n";
342 } else {
343 30 $string = "$name $self->{name} $option $option_ref->{$option}\n";
344 }
345 }
346 36 $self->_printline($handle, $string, $self->{"length"});
347 }
348 }
349 }
350  
351 4 1;
352  
353  
« Graph/Utils.pm ↑ Summary Graph/Xmgrace/Base_Option.pm »