Diagram2D/Axis.pm

filter: Statementstmt 7.2% 14 / 192 Branchbran 0.0% 0 / 82 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 20.0% 4 / 20 Podpod 0.0% 0 / 16 totaltotal 5.5% 18 / 325 CC 45 SCAR 45.3
CC
45
Cov
5%
correct_if_necessary
306.0
set_logarithmic
30.0
value_to_coord
30.0
CRAP 93.2
« Diagram2D/Plot.pm ↑ Summary Diagram2D/NumberPrinter.pm »
1  
2 package LaTeX::PGF::Diagram2D::Axis;
3  
4 1 ▶use 5.000000;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @ISA = qw();
11  
12 1 our $VERSION = '1.00';
13  
14 sub new
15 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
16 0 my $self = undef;
17 0 ▶ if($#_ < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 0) { } 0 0 0
18 0 croak "Usage: LaTeX::PGF::Diagram2D::Axis->new(width,height)";
19 } else {
20 0 my $class = shift;
21 0 $self = {
22 'min' => 0.0, # Minimum value
23 'max' => 0.0, # Maximum value
24 't' => 0, # Type: 0=linear, 1=logarithmic
25 'ts' => -1.0, # Tic step
26 'gs' => -1.0, # Grid step
27 'bo' => -1.0, # Border
28 'to' => -1.0, # Tic offset
29 'lo' => -1.0, # Label offset
30 'l' => undef, # Label text
31 'u' => undef, # Unit text
32 'dg' => undef, # Diagram
33 'used' => 0, # Flag: used
34 'n' => '', # Name
35 'color' => undef, # Color
36 'omit' => 0, # Number of scale tics to omit for unit
37 };
38 0 bless($self, $class);
39 }
40 0 return $self;
41 }
42  
43  
44  
45 sub set_grid_step
46 0 ▶{
Subroutine set_grid_step: not called CC=2 SCAR=17.9
Pod undocumented
47 0 my $self = undef;
48 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
49 0 croak "Usage: \$axis->set_grid_step(value)";
50 } else {
51 0 $self = shift; $self->{'gs'} = shift;
52 }
53 0 return $self;
54 }
55  
56  
57  
58 sub set_tic_step
59 0 ▶{
Subroutine set_tic_step: not called CC=2 SCAR=17.9
Pod undocumented
60 0 my $self = undef;
61 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
62 0 croak "Usage: \$axis->set_tic_step(value)";
63 } else {
64 0 $self = shift; $self->{'ts'} = shift;
65 }
66 0 return $self;
67 }
68  
69  
70  
71 sub set_linear
72 0 ▶{
Subroutine set_linear: not called CC=3 SCAR=24.8
Pod undocumented
73 0 my $self = undef;
74 0 ▶ if($#_ < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 2) { } 0 0 0
75 0 croak "Usage: \$axis->set_linear(min,max)";
76 } else {
77 0 $self = shift;
78 0 $self->{'min'} = shift;
79 0 $self->{'max'} = shift;
80 0 $self->{'t'} = 0;
81 0 ▶ if($self->{'max'} <= $self->{'min'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max"} <= $self->{"min"}) 0 0 0
82 0 carp "Warning: Scale maximum should be larger than minimum!";
83 }
84 }
85 0 return $self;
86 }
87  
88  
89 sub set_logarithmic
90 0 ▶{
Subroutine set_logarithmic: not called CC=5 SCAR=34.0
Pod undocumented
91 0 my $self = undef;
92 0 ▶ if($#_ < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 2) { } 0 0 0
93 0 croak "Usage: \$axis->set_linear(min,max)";
94 } else {
95 0 $self = shift;
96 0 $self->{'min'} = shift;
97 0 $self->{'max'} = shift;
98 0 $self->{'t'} = 1;
99 0 ▶ if($self->{'min'} <= 0.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"min"} <= 0) 0 0 0
100 0 croak "ERROR: Only positive values allowed for logarithmic scales!";
101 }
102 0 ▶ if($self->{'max'} <= 0.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max"} <= 0) 0 0 0
103 0 croak "ERROR: Only positive values allowed for logarithmic scales!";
104 }
105 0 ▶ if($self->{'max'} <= $self->{'min'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max"} <= $self->{"min"}) 0 0 0
106 0 carp "Warning: Scale maximum should be larger than minimum!";
107 }
108 }
109 0 return $self;
110 }
111  
112  
113 sub set_omit
114 0 ▶{
Subroutine set_omit: not called CC=2 SCAR=17.9
Pod undocumented
115 0 my $self = undef;
116 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
117 0 croak "Usage \$axis->set_omit(number)";
118 } else {
119 0 $self = shift; $self->{'omit'} = shift;
120 }
121 0 return $self;
122 }
123  
124  
125  
126 sub correct_if_necessary
127 0 ▶{
Subroutine correct_if_necessary: not called CC=17 SCAR=57.2
Pod undocumented
128 0 my $self = undef;
129 0 my $debug = 0;
130 0 ▶ if($#_ < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 2) { } 0 0 0
131 0 croak "Usage: \$axis->correct_if_necessary(diagram,xyflag)";
132 } else {
133 0 $self = shift; my $dg = shift; my $xyflag = shift;
134 0 ▶ if($#_ >= 0) { $debug = shift; }
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ >= 0) 0 0 0
135 0 ▶ if($self->{'used'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'used'}) { } 0 0 0
136 0 ▶ if($self->{'to'} < 0.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"to"} < 0) 0 0 0
137 0 ▶ if($dg->{'units'} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dg->{'units'} == 1) { } 0 0 0
138 0 $self->{'to'} = 0.2 / 2.54;
139 } else {
140 0 ▶ if($dg->{'units'} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dg->{'units'} == 2) { } 0 0 0
141 0 $self->{'to'} = 0.2 * 72.0 / 2.54
142 } else {
143 0 $self->{'to'} = 0.2;
144 }
145 }
146 }
147 0 ▶ if($self->{'lo'} < 0.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lo"} < 0) 0 0 0
148 0 ▶ if($dg->{'units'} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dg->{'units'} == 1) { } 0 0 0
149 0 $self->{'lo'} = $self->{'to'} + 2.0 * $self->{'fs'} / 72.27;
150 } else {
151 0 ▶ if($dg->{'units'} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dg->{'units'} == 2) { } 0 0 0
152 $self->{'lo'} = $self->{'to'}
153 0 + 2.0 * 72.0 * $self->{'dg'}->{'fs'} / 72.27;
154 } else {
155 $self->{'lo'} = $self->{'to'}
156 0 + 2.0 * 2.54 * $self->{'dg'}->{'fs'} / 72.27;
157 }
158 }
159 }
160 0 ▶ if($self->{'bo'} < 0.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bo"} < 0) 0 0 0
161 0 ▶ if($dg->{'units'} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dg->{'units'} == 1) { } 0 0 0
162 0 $self->{'bo'} = $self->{'to'} + 3.0 * $self->{'fs'} / 72.27;
163 } else {
164 0 ▶ if($dg->{'units'} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dg->{'units'} == 2) { } 0 0 0
165 $self->{'bo'} = $self->{'to'}
166 0 + 3.0 * 72.0 * $self->{'dg'}->{'fs'} / 72.27;
167 } else {
168 $self->{'bo'} = $self->{'to'}
169 0 + 3.0 * 2.54 * $self->{'dg'}->{'fs'} / 72.27;
170 }
171 }
172 }
173 } else {
174 0 ▶ if($self->{'bo'} < 0.0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bo"} < 0) 0 0 0
175 0 ▶ if($dg->{'units'} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dg->{'units'} == 1) { } 0 0 0
176 0 $self->{'bo'} = 0.5 / 2.54;
177 } else {
178 0 ▶ if($dg->{'units'} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dg->{'units'} == 2) { } 0 0 0
179 0 $self->{'bo'} = 0.5 * 72.0 / 2.54;
180 } else {
181 0 $self->{'bo'} = 0.5;
182 }
183 }
184 }
185 }
186 }
187 0 ▶ if($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
188 0 print "DEBUG Axis->correct_if_necessary: " . $self->{'n'} . "\n";
189 0 print "DEBUG bo = " . $self->{'bo'} . "\n";
190 0 print "DEBUG to = " . $self->{'to'} . "\n";
191 0 print "DEBUG lo = " . $self->{'lo'} . "\n";
192 }
193 0 return $self;
194 }
195  
196  
197  
198 sub value_to_coord
199 0 ▶{
Subroutine value_to_coord: not called CC=5 SCAR=34.0
Pod undocumented
200 0 my $back = undef;
201 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
202 0 croak "Usage: \$axis->value_to_coord(value)";
203 } else {
204 0 my $self = shift;
205 0 my $value = shift;
206 0 my $xmin; my $xmax;
207 0 my $vmin = $self->{'min'}; my $vmax = $self->{'max'};
208 0 ▶ if(($self->{'n'} eq 'l') || ($self->{'n'} eq 'r')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'n'} eq 'l' or $self->{'n'} eq 'r') { } 0 0 0
Condition0%0/3
$self->{"n"} eq "l" or $self->{"n"} eq "r"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"n"} eq "l" or $self->{"n"} eq "r"
$self->{"n"} eq "l" $self->{"n"} eq "r"
Truth table0%0/3
A or B
A= $self->{"n"} eq "l"B= $self->{"n"} eq "r"
ABresult
1X1
011
000
209 0 $xmin = $self->{'dg'}->{'y3bp'};
210 0 $xmax = $self->{'dg'}->{'y4bp'};
211 } else {
212 0 $xmin = $self->{'dg'}->{'x3bp'};
213 0 $xmax = $self->{'dg'}->{'x4bp'};
214 }
215 0 ▶ if($self->{'t'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'t'}) { } 0 0 0
216 0 $back = $xmin
217 + ((($xmax - $xmin) * (log($value/$vmin))) / (log($vmax/$vmin)));
218 } else {
219 0 $back = $xmin + ((($xmax - $xmin) * ($value - $vmin)) / ($vmax - $vmin));
220 }
221 0 $back = $self->{'dg'}->rd($back, 5);
222 }
223 0 return $back;
224 }
225  
226  
227 # dx/dX or dy/dY
228  
229 sub value_to_derivative
230 0 ▶{
Subroutine value_to_derivative: not called CC=5 SCAR=34.0
Pod undocumented
231 0 my $back = undef;
232 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
233 0 croak "Usage: \$axis->value_to_derivative(value)";
234 } else {
235 0 my $self = shift;
236 0 my $value = shift;
237 0 my $xmin; my $xmax;
238 0 my $vmin = $self->{'min'}; my $vmax = $self->{'max'};
239 0 ▶ if(($self->{'n'} eq 'l') || ($self->{'n'} eq 'r')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'n'} eq 'l' or $self->{'n'} eq 'r') { } 0 0 0
Condition0%0/3
$self->{"n"} eq "l" or $self->{"n"} eq "r"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"n"} eq "l" or $self->{"n"} eq "r"
$self->{"n"} eq "l" $self->{"n"} eq "r"
Truth table0%0/3
A or B
A= $self->{"n"} eq "l"B= $self->{"n"} eq "r"
ABresult
1X1
011
000
240 0 $xmin = $self->{'dg'}->{'y3bp'};
241 0 $xmax = $self->{'dg'}->{'y4bp'};
242 } else {
243 0 $xmin = $self->{'dg'}->{'x3bp'};
244 0 $xmax = $self->{'dg'}->{'x4bp'};
245 }
246 0 ▶ if($self->{'t'}) { # logarithmic
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'t'}) { } 0 0 0
247 0 $back = ($xmax - $xmin) / ($value * log($vmax/$vmin));
248 } else { # linear
249 0 $back = (($xmax - $xmin) / ($vmax - $vmin));
250 }
251 0 $back = $self->{'dg'}->rd($back, 5);
252 }
253 0 return $back;
254 }
255  
256  
257  
258 sub coord_to_value
259 0 ▶{
Subroutine coord_to_value: not called CC=5 SCAR=34.0
Pod undocumented
260 0 my $back = undef;
261 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
262 0 croak "Usage: \$axis->coord_to_value(coord)";
263 } else {
264 0 my $self = shift; my $coord = shift;
265 0 my $xmin; my $xmax;
266 0 my $vmin = $self->{'min'}; my $vmax = $self->{'max'};
267 0 ▶ if(($self->{'n'} eq 'l') || ($self->{'n'} eq 'r')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'n'} eq 'l' or $self->{'n'} eq 'r') { } 0 0 0
Condition0%0/3
$self->{"n"} eq "l" or $self->{"n"} eq "r"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"n"} eq "l" or $self->{"n"} eq "r"
$self->{"n"} eq "l" $self->{"n"} eq "r"
Truth table0%0/3
A or B
A= $self->{"n"} eq "l"B= $self->{"n"} eq "r"
ABresult
1X1
011
000
268 0 $xmin = $self->{'y3bp'}; $xmax = $self->{'y4bp'};
269 } else {
270 0 $xmin = $self->{'x3bp'}; $xmax = $self->{'x4bp'};
271 }
272 0 ▶ if($self->{'t'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'t'}) { } 0 0 0
273 0 $back = $vmin * exp(
274 (log($vmax/$vmin) * ($coord - $xmin)) / ($xmax - $xmin)
275 );
276 } else {
277 0 $back = $vmin + ((($vmax - $vmin) * ($coord - $xmin)) / ($xmax - $xmin));
278 }
279 }
280 0 return $back;
281 }
282  
283  
284  
285 sub set_unit
286 0 ▶{
Subroutine set_unit: not called CC=2 SCAR=17.9
Pod undocumented
287 0 my $self = undef;
288 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
289 0 croak "Usage: \$axis->set_unit(text)";
290 } else {
291 0 $self = shift; $self->{'u'} = shift;
292 }
293 0 return $self;
294 }
295  
296  
297  
298 sub set_label
299 0 ▶{
Subroutine set_label: not called CC=2 SCAR=17.9
Pod undocumented
300 0 my $self = undef;
301 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
302 0 croak "Usage: \$axis->set_label(text)";
303 } else {
304 0 $self = shift; $self->{'l'} = shift;
305 }
306 0 return $self;
307 }
308  
309  
310  
311 sub set_tic_offset
312 0 ▶{
Subroutine set_tic_offset: not called CC=2 SCAR=17.9
Pod undocumented
313 0 my $self = undef;
314 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
315 0 croak "Usage: \$axis->set_tic_offset(offset)";
316 } else {
317 0 $self = shift; $self->{'to'} = shift;
318 }
319 0 return $self;
320 }
321  
322  
323  
324 sub set_label_offset
325 0 ▶{
Subroutine set_label_offset: not called CC=2 SCAR=17.9
Pod undocumented
326 0 my $self = undef;
327 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
328 0 croak "Usage: \$axis->set_tic_offset(offset)";
329 } else {
330 0 $self = shift; $self->{'lo'} = shift;
331 }
332 0 return $self;
333 }
334  
335  
336  
337 sub set_border
338 0 ▶{
Subroutine set_border: not called CC=2 SCAR=17.9
Pod undocumented
339 0 my $self = undef;
340 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
341 0 croak "Usage: \$axis->set_tic_offset(offset)";
342 } else {
343 0 $self = shift; $self->{'bo'} = shift;
344 }
345 0 return $self;
346 }
347  
348  
349  
350 sub set_color
351 0 ▶{
Subroutine set_color: not called CC=2 SCAR=17.9
Pod undocumented
352 0 my $self = undef;
353 0 ▶ if($#_ < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ < 1) { } 0 0 0
354 0 croak "Usage: \$plot->set_color(color)";
355 } else {
356 0 $self = shift; $self->{'color'} = shift;
357 }
358 0 return $self;
359 }
360  
361  
362  
363 1 1;
364 __END__
« Diagram2D/Plot.pm ↑ Summary Diagram2D/NumberPrinter.pm »