File Coverage

blib/lib/PDF/Reuse/OverlayChart.pm
Criterion Covered Total %
statement 15 1097 1.3
branch 0 466 0.0
condition 0 216 0.0
subroutine 5 29 17.2
pod 6 24 25.0
total 26 1832 1.4


line stmt bran cond sub pod time code
1             package PDF::Reuse::OverlayChart;
2 1     1   9326 use PDF::Reuse;
  1         130504  
  1         257  
3            
4 1     1   35 use 5.006;
  1         56  
  1         41  
5 1     1   6 use strict;
  1         7  
  1         33  
6 1     1   5 use warnings;
  1         2  
  1         257  
7            
8             our $VERSION = '0.03';
9            
10             our %possible = (x => 1,
11             y => 1,
12             width => 1,
13             height => 1,
14             size => 1,
15             xsize => 1,
16             ysize => 1,
17             initialmaxy => 1,
18             initialminy => 1,
19             type => 1,
20             background => 1,
21             yunit => 1,
22             nounits => 1,
23             title => 1,
24             groupstitle => 1,
25             groupstext => 1,
26             iparam => 1,
27             nogroups => 1,
28             merge => 1,
29             xdensity => 1,
30             ydensity => 1,
31             rightscale => 1,
32             topscale => 1,
33             nomarker => 1);
34            
35             my @gray = ( '0.97 0.97 0.97', '0.8 0.8 0.8', '0.6 0.6 0.6', '0.72 0.72 0.72', '0.9 0.9 0.9',
36             '0.93 0.93 0.93', '0.7 0.7 0.7', '0.5 0.5 0.5', '0.1 0.1 0.1', '0.98 0.98 0.98');
37            
38             my @light = ('1 0.9 0.9', '0.9 0.9 1', '0.9 1 1', '1 1 0.9', '1 0.9 1', '0.9 1 0.9',
39             '0.6 0.8 0.95', '0.95 0.8 0.6', '0.6 0.95 0.9', '0.9 0.95 0.6' );
40            
41             my @dark = ('0.1 0.5 0.8', '0.8 0.5 0.1', '0.1 0.8 0.8', '0.8 0.8 0.1', '0.8 0.1 0.8', '0.5 0.8 0.5',
42             '0.1 0.1 0.5', '0.5 0.1 0.1', '0.1 0.5 0.5', '0.5 0.5 0.1' );
43            
44             my @bright = ('1 0 1', '1 0 0', '0 1 1', '1 1 0', '0 0 1', '0 1 0',
45             '0.3 0.3 0.97', '0.57 0.97 0.97', '0.97 0.5 0.5', '0.5 0.5 0.97' );
46            
47             sub new
48 0     0 1   { my $name = shift;
49 0           my ($class, $self);
50 0 0         if (ref($name))
51 0           { $class = ref($name);
52 0           $self = $name;
53             }
54             else
55 0           { $class = $name;
56 0           $self = {};
57             }
58 0           bless $self, $class;
59 0           return $self;
60             }
61            
62             sub outlines
63 1     1   5 { no warnings;
  1         1  
  1         15281  
64 0     0 0   my $self = shift;
65 0           my %param = @_;
66 0           for (keys %param)
67 0           { my $key = lc($_);
68 0 0         if ($possible{$key})
69 0           { $self->{$key} = $param{$_};
70             }
71             else
72 0           { warn "Unrecognized parameter: $_, ignored\n";
73             }
74             }
75 0 0         $self->{xsize} = 1 unless ($self->{xsize} != 0);
76 0 0         $self->{ysize} = 1 unless ($self->{ysize} != 0);
77 0 0         $self->{size} = 1 unless ($self->{size} != 0);
78 0 0         $self->{width} = 450 unless ($self->{width} != 0);
79 0 0         $self->{height} = 450 unless ($self->{height} != 0);
80            
81 0 0 0       if (($self->{type} ne 'bars')
      0        
      0        
      0        
82             && ($self->{type} ne 'totalbars')
83             && ($self->{type} ne 'percentbars')
84             && ($self->{type} ne 'lines')
85             && ($self->{type} ne 'area'))
86 0 0         { if (substr($self->{type}, 0, 1) eq 't')
    0          
    0          
    0          
87 0           { $self->{type} = 'totalbars';
88             }
89             elsif (substr($self->{type}, 0, 1) eq 'p')
90 0           { $self->{type} = 'percentbars';
91             }
92             elsif (substr($self->{type}, 0, 1) eq 'l')
93 0           { $self->{type} = 'lines';
94             }
95             elsif (substr($self->{type}, 0, 1) eq 'a')
96 0           { $self->{type} = 'area';
97             }
98             else
99 0           { $self->{type} = 'bars';
100             }
101             }
102            
103 0 0         if (! defined $self->{color})
104 0           { $self->{color} = ['0 0 0.8', '0.8 0 0.3', '0.9 0.9 0', '0 1 0', '0.6 0.6 0.6',
105             '1 0.8 0.9', '0 1 1', '0.9 0 0.55', '0.2 0.2 0.2','0.55 0.9 0.9'];
106             }
107 0           return $self;
108             }
109            
110             sub overlay
111 0     0 1   { my $self = shift;
112 0           my %param = @_;
113 0           for (keys %param)
114 0           { my $key = lc($_);
115 0 0         if ($possible{$key})
116 0           { $self->{$key} = $param{$_};
117             }
118             else
119 0           { warn "Unrecognized parameter: $_, ignored\n";
120             }
121             }
122 0 0 0       if (($self->{type} ne 'bars')
      0        
      0        
123             && ($self->{type} ne 'totalbars')
124             && ($self->{type} ne 'lines')
125             && ($self->{type} ne 'area'))
126 0 0         { if (substr($self->{type}, 0, 1) eq 't')
    0          
    0          
127 0           { $self->{type} = 'totalbars';
128             }
129             elsif (substr($self->{type}, 0, 1) eq 'l')
130 0           { $self->{type} = 'lines';
131             }
132             elsif (substr($self->{type}, 0, 1) eq 'a')
133 0           { $self->{type} = 'area';
134             }
135             else
136 0           { $self->{type} = 'bars';
137             }
138             }
139            
140 0 0         $self->{xdensity} = 1 if (! exists $self->{xdensity});
141 0 0         $self->{ydensity} = 1 if (! exists $self->{ydensity});
142 0           $self->{level} = 'overlay';
143 0           return $self;
144             }
145            
146             sub add
147 0     0 1   { my $self = shift;
148 0           my @values = @_;
149 0   0       my $name = shift @values || ' ';
150 0           my $num = 0;
151 0           my $ready;
152 0 0         if (! defined $self->{col})
153 0           { for (@values)
154 0 0         { if (ref($_) eq 'ARRAY')
155 0           { last;
156             }
157 0 0 0       if ((defined $_)
      0        
158             && ($_ =~ m'[A-Za-z]+'o)
159             && ($_ !~ m'undef'oi))
160 0           { $ready = 1;
161 0           $self->{col} = \@values;
162 0           $self->{xunit} = $name;
163 0           last;
164             }
165             }
166             }
167 0 0         if (! defined $ready)
168 0 0         { if (! exists $self->{series}->{$name})
169 0           { push @{$self->{sequence}}, $name;
  0            
170 0           $self->{series}->{$name} = [];
171             }
172 0           my @array = @{$self->{series}->{$name}};
  0            
173            
174 0           for (@values)
175 0 0 0       { if (ref($_) eq 'ARRAY')
    0          
176 0           { my @newArray;
177 0           for my $element (@{$_})
  0            
178 0 0 0       { if ((defined $element) && (length($element)))
179 0           { push @newArray, $element;
180             }
181             else
182 0           { push @newArray, undef;
183             }
184             }
185 0           $array[$num] = [ @newArray ];
186             }
187             elsif ((defined $_) && ($_ =~ m'([\d\.\-]*)'o))
188 0 0         { if (length($1))
189 0           { $array[$num] += $1;
190             }
191             }
192 0           $num++;
193             }
194 0           $self->{series}->{$name} = \@array;
195             }
196 0           return $self;
197             }
198            
199             sub columns
200 0     0 1   { my $self = shift;
201 0           my $xunit = shift;
202 0           $self->{col} = \@_;
203 0           $self->{xunit} = $xunit;
204 0           return $self;
205             }
206            
207             sub color
208 0     0 1   { my $self = shift;
209 0           my @vector = @_;
210 0 0         if ($vector[0] =~ m'gray'oi)
    0          
    0          
    0          
211 0           { $self->{color} = [ (@gray) ];
212             }
213             elsif ($vector[0] =~ m'light'oi)
214 0           { $self->{color} = [ (@light) ];
215             }
216             elsif ($vector[0] =~ m'dark'oi)
217 0           { $self->{color} = [ (@dark) ];
218             }
219             elsif ($vector[0] =~ m'bright'oi)
220 0           { $self->{color} = [ (@bright) ];
221             }
222             else
223 0           { $self->{color} = [ (@_) ];
224             }
225 0           return $self;
226             }
227            
228             sub analysera
229 0     0 0   { my $self = shift;
230 0           my ($min, $max, $maxSum, $minSum, $i);
231            
232 0           my @tot = ();
233 0           my @pos = ();
234 0           my @neg = ();
235 0           my $num = 0;
236 0           for my $namn (@{$self->{sequence}})
  0            
237 0           { $i = -1;
238 0           for my $unit (@{$self->{series}->{$namn}})
  0            
239 0           { $i++;
240 0 0         next if (! defined $unit);
241 0 0         if (ref($unit) eq 'ARRAY')
242 0           { my $k = 0;
243 0           for (@{$unit})
  0            
244 0 0 0       { if ((! defined $_) || ($_ eq ''))
245 0           { $k++;
246 0           next;
247             }
248 0 0 0       $max = $_ if ((! defined $max) || ($_ > $max));
249 0 0 0       $min = $_ if ((! defined $min) || ($_ < $min));
250 0           $tot[$i][$k] += abs($_);
251 0 0         $pos[$i][$k] += $_ if $_ > 0;
252 0 0         $neg[$i][$k] += abs($_) if $_ < 0;
253 0           $k++;
254             }
255             }
256             else
257 0 0 0       { $max = $unit if ((! defined $max) || ($unit > $max));
258 0 0 0       $min = $unit if ((! defined $min) || ($unit < $min));
259 0           $tot[$i] += abs($unit);
260 0 0         $pos[$i] += $unit if $unit > 0;
261 0 0         $neg[$i] += abs($unit) if $unit < 0;
262             }
263             }
264 0 0 0       $num = $i if ((! defined $num) || ($i > $num));
265             }
266            
267 0 0         $num = (defined $num) ? ($num + 1) : 0;
268            
269 0           my $posPercent = 0;
270 0           my $negPercent = 0;
271            
272 0           for ($i = 0; $i < $num; $i++)
273 0 0         { if (! defined $tot[$i])
274 0           { next;
275             }
276 0 0         if (ref($tot[$i]) eq 'ARRAY')
277 0           { my $k = 0;
278 0           for my $element (@{$tot[$i]})
  0            
279 0 0         { if (! defined $element)
280 0           { $k++;
281 0           next;
282             }
283 0 0 0       $maxSum = $element if ((! defined $maxSum) || ($element > $maxSum));
284 0 0 0       $minSum = $element if ((! defined $minSum) || ($element < $minSum));
285 0 0 0       if ((defined $neg[$i][$k]) && (($neg[$i][$k] * -1) < $minSum))
286 0           { $minSum = $neg[$i][$k] * -1;
287             }
288 0 0 0       if (($posPercent < 100) && (defined $pos[$i][$k]))
289 0           { my $percent = sprintf("%.3f", (($pos[$i][$k] / $element) * 100));
290 0 0         $posPercent = $percent if ($percent > $posPercent);
291             }
292 0 0 0       if (($negPercent < 100) && (defined $neg[$i][$k]))
293 0           { my $percent = sprintf("%.3f", (($neg[$i][$k] / $element) * 100));
294 0 0         $negPercent = $percent if ($percent > $posPercent);
295             }
296 0           $k++;
297             }
298             }
299             else
300 0 0 0       { $maxSum = $tot[$i] if ((! defined $maxSum) || ($tot[$i] > $maxSum));
301 0 0 0       $minSum = $tot[$i] if ((! defined $minSum) || ($tot[$i] < $minSum));
302 0 0 0       if ((defined $neg[$i]) && (($neg[$i] * -1) < $minSum))
303 0           { $minSum = $neg[$i] * -1;
304             }
305 0 0 0       if (($posPercent < 100) && (defined $pos[$i]))
306 0           { my $percent = sprintf("%.3f", (($pos[$i] / $tot[$i]) * 100));
307 0 0         $posPercent = $percent if ($percent > $posPercent);
308             }
309 0 0 0       if (($negPercent < 100) && (defined $neg[$i]))
310 0           { my $percent = sprintf("%.3f", (($neg[$i] / $tot[$i]) * 100));
311 0 0         $negPercent = $percent if ($percent > $negPercent);
312             }
313             }
314             }
315            
316 0 0         $self->{max} = (defined $max) ? $max : 0;
317 0 0         $self->{min} = (defined $min) ? $min : 0;
318 0 0         $self->{maxSum} = (defined $maxSum) ? $maxSum : 0;
319 0 0         $self->{minSum} = (defined $minSum) ? $minSum : 0;
320 0           $self->{tot} = \@tot;
321 0           $self->{pos} = \@pos;
322 0           $self->{neg} = \@neg;
323 0           $self->{posPercent} = $posPercent;
324 0           $self->{negPercent} = $negPercent;
325 0           $self->{num} = $num;
326            
327 0           return ($self->{max}, $self->{min}, $self->{maxSum}, $self->{minSum},
328             $self->{num}, $self->{posPercent}, $self->{negPercent});
329             }
330            
331             sub marginAction
332 0     0 0   { my $self = shift;
333 0           my $code = shift;
334 0           $self->{marginAction} = $self->prepare($code);
335 0           return $self;
336             }
337            
338             sub marginToolTip
339 0     0 0   { my $self = shift;
340 0           my $text = shift;
341 0           $self->{marginToolTip} = $self->prepare($text);
342 0           return $self;
343             }
344            
345            
346             sub barsActions
347 0     0 0   { my $self = shift;
348 0           my $namn = shift;
349 0           my (@codeArray, $str);
350 0           for (@_)
351 0 0         { if (ref($_) eq 'ARRAY')
352 0           { my @vector;
353 0           my @array = @{$_};
  0            
354 0           for my $element (@array)
355 0           { push @vector, $self->prepare($element);
356             }
357 0           push @codeArray, [@vector];
358             }
359             else
360 0           { push @codeArray, $self->prepare($_);
361             }
362             }
363            
364 0 0         if ($namn)
365 0           { $self->{barAction}->{$namn} = \@codeArray;
366             }
367 0           return $self;
368             }
369            
370             sub prepare
371 0     0 0   { my $self = shift;
372 0           my $str = shift;
373 0 0         if ($str !~ m'\"'os)
    0          
374 0           { $str = '"' . $str . '"';
375             }
376             elsif ($str !~ m/\'/os)
377 0           { $str = '\'' . $str . '\'';
378             }
379             else
380 0           { $str =~ s/\'/\\\'/og;
381 0           $str =~ s/\\\\\'/\\\'/og;
382 0           $str = "'" . $str . "'";
383             }
384 0           return $str;
385             }
386            
387            
388             sub barsToolTips
389 0     0 0   { my $self = shift;
390 0           my $namn = shift;
391 0           my (@toolTips, $str);
392 0           for (@_)
393 0 0         { if (ref($_) eq 'ARRAY')
394 0           { my @vector;
395 0           my @array = @{$_};
  0            
396 0           for my $element (@array)
397 0           { push @vector, $self->prepare($element);
398             }
399 0           push @toolTips, [@vector];
400             }
401             else
402 0           { push @toolTips, $self->prepare($_);
403             }
404             }
405 0 0         if ($namn)
406 0           { $self->{barToolTip}->{$namn} = \@toolTips;
407             }
408 0           return $self;
409             }
410            
411             sub columnsActions
412 0     0 0   { my $self = shift;
413 0           my (@codeArray, $str);
414            
415 0           for (@_)
416 0 0         { if (ref($_) eq 'ARRAY')
417 0           { my @vector;
418 0           my @array = @{$_};
  0            
419 0           for my $element (@array)
420 0           { push @vector, $self->prepare($element);
421             }
422 0           push @codeArray, [@vector];
423             }
424             else
425 0           { push @codeArray, $self->prepare($_);
426             }
427             }
428 0           $self->{columnsActions} = \@codeArray;
429            
430 0           return $self;
431             }
432            
433             sub columnsToolTips
434 0     0 0   { my $self = shift;
435 0           my (@toolTips, $str);
436 0           for (@_)
437 0 0         { if (ref($_) eq 'ARRAY')
438 0           { my @vector;
439 0           my @array = @{$_};
  0            
440 0           for my $element (@array)
441 0           { push @vector, $self->prepare($element);
442             }
443 0           push @toolTips, [@vector];
444             }
445             else
446 0           { push @toolTips, $self->prepare($_);
447             }
448             }
449 0           $self->{columnsToolTips} = \@toolTips;
450 0           return $self;
451             }
452            
453            
454             sub boxAction
455 0     0 0   { my $self = shift;
456 0           my $namn = shift;
457 0           my $code = shift;
458 0           $self->{boxAction}->{$namn} = $self->prepare($code);
459 0           return $self;
460             }
461            
462             sub boxToolTip
463 0     0 0   { my $self = shift;
464 0           my $namn = shift;
465 0           my $text = shift;
466 0           $self->{boxToolTip}->{$namn} = $self->prepare($text);
467 0           return $self;
468             }
469            
470            
471             sub defineIArea
472 0     0 0   { my $self = shift;
473 0           my $code =<<"EOF";
474             function iArea()
475             { var vec = iArea.arguments;
476             var page = vec[0];
477             var x = vec[1];
478             var y2 = vec[2];
479             var x2 = vec[3] + x;
480             var y = y2 + vec[4];
481             var name = 'p' + page + 'x' + x + 'y' + y + 'x2' + x2 + 'y2' + y2;
482             var b = this.addField(name, "button", page, [x, y, x2, y2]);
483             b.setAction("MouseUp", vec[5]);
484             if (vec[6])
485             b.userName = vec[6];
486             }
487             EOF
488            
489 0           prJs($code);
490 0           return $self;
491             }
492            
493            
494             sub draw
495 0     0 1   { my $self = shift;
496 0           my %param = @_;
497 0           for (keys %param)
498 0           { my $key = lc($_);
499 0 0         if ($possible{$key})
500 0           { $self->{$key} = $param{$_};
501             }
502             else
503 0           { warn "Unrecognized parameter: $_, ignored\n";
504             }
505             }
506 0           $self->outlines();
507 0           $self->{level} = 'top';
508 0           my ($str, $xsize, $ysize, $font, $x, $y, $y0, $ySteps, $xT, @array, $chartMax,
509             $chartMin, $rightScale, $topScale);
510            
511 0           my ($max, $min, $maxSum, $minSum, $num,
512             $posPercent, $negPercent ) = $self->analysera();
513 0 0 0       if (($self->{type} eq 'totalbars') || ($self->{type} eq 'area'))
514 0           { $chartMax = $maxSum;
515 0           $chartMin = $minSum;
516             }
517             else
518 0           { $chartMax = $max;
519 0           $chartMin = $min;
520             }
521            
522 0 0 0       if ((defined $self->{initialmaxy})
523             && ($self->{initialmaxy} > $chartMax))
524 0           { $chartMax = $self->{initialmaxy}
525             }
526            
527 0 0 0       if ((defined $self->{initialminy})
528             && ($self->{initialminy} < $chartMin))
529 0           { $chartMin = $self->{initialminy}
530             }
531            
532            
533 0 0 0       if ((exists $param{'merge'}) && ($self->{type} ne 'percentbars'))
534 0           { for (@{$param{'merge'}})
  0            
535 0 0         { if ($_->{type} ne 'percentbars')
536 0           { push @array, $_;
537             }
538             }
539 0           for my $overlay (@array)
540 0           { my ($tmax, $tmin, $tmaxSum, $tminSum, $tnum) = $overlay->analysera();
541 0 0 0       if (($overlay->{type} eq 'totalbars') || ($overlay->{type} eq 'area'))
542 0           { $tmaxSum = sprintf ("%.0f", ($tmaxSum / $overlay->{ydensity}));
543 0           $tminSum = sprintf ("%.0f", ($tminSum / $overlay->{ydensity}));
544            
545 0 0         $chartMax = $tmaxSum if ($tmaxSum > $chartMax);
546 0 0         $chartMin = $tminSum if ($tminSum < $chartMin);
547             }
548             else
549 0           { $tmax = sprintf ("%.0f", ($tmax / $overlay->{ydensity}));
550 0           $tmin = sprintf ("%.0f", ($tmin / $overlay->{ydensity}));
551            
552 0 0         $chartMax = $tmax if ($tmax > $chartMax);
553 0 0         $chartMin = $tmin if ($tmin < $chartMin);
554             }
555 0           $tnum = sprintf ("%.0f", ($tnum / $overlay->{xdensity}));
556 0 0         $num = $tnum if ($tnum > $num);
557 0           $tnum = sprintf ("%.0f", ($self->{num} / $overlay->{xdensity}));
558 0 0         $num = $tnum if ($tnum > $num);
559 0 0 0       if ((defined $overlay->{rightscale})
560             && (! defined $rightScale))
561 0           { $rightScale = $overlay;
562             }
563 0 0 0       if ((defined $overlay->{topscale})
564             && (! defined $topScale))
565 0           { $topScale = $overlay;
566             }
567 0           $overlay->{x} = $self->{x};
568 0           $overlay->{xsize} = $self->{xsize};
569 0           $overlay->{size} = $self->{size};
570 0           $overlay->{y} = $self->{y};
571 0           $overlay->{ysize} = $self->{ysize};
572             }
573             }
574 0           my $xSteps = $#{$self->{col}} + 1;
  0            
575 0 0         $xSteps = $num if ($num > $xSteps);
576 0           my $groups = $#{$self->{sequence}} + 1;
  0            
577            
578 0 0         if ($self->{type} ne 'percentbars')
579 0 0         { if ($chartMin > 0)
    0          
580 0   0       { $ySteps = $chartMax || 1;
581             }
582             elsif ($chartMax < 0)
583 0   0       { $ySteps = ($chartMin * -1) || 1;
584             }
585             else
586 0   0       { $ySteps = ($chartMax - $chartMin) || 1;
587             }
588             }
589             else
590 0           { $max = $posPercent;
591 0           $min = $negPercent * -1;
592 0           $ySteps = sprintf("%.0f", ($max - $min));
593 0           $chartMax = $max;
594 0           $chartMin = $min;
595             }
596            
597             ####################
598             # Några kontroller
599             ####################
600            
601 0 0         if ($num < 1)
602 0           { prText ($self->{x}, $self->{y},
603             'Values are missing - no graph can be shown');
604 0           return;
605             }
606            
607 0 0 0       if ((! defined $max) || (! defined $min))
608 0           { prText ($self->{x}, $self->{y},
609             'Values are missing - no graph can be shown');
610 0           return;
611             }
612 0           my $tal1 = sprintf("%.0f", $chartMax);
613 0           my $tal2 = sprintf("%.0f", $chartMin);
614 0 0         my $tal = (length($tal1) > length($tal2)) ? $tal1 : $tal2;
615 0           my $langd = length($tal);
616            
617 0   0       my $xCor = ($langd * 7.5) || 25; # margin to the left
618 0           my $yCor = 20; # margin from the bottom
619 0           my $xEnd = $self->{width};
620 0           my $yEnd = $self->{height};
621 0           my $xArrow = $xEnd * 0.9;
622 0           my $yArrow = $yEnd * 0.97;
623 0           my $xAreaEnd = $xEnd * 0.85;
624 0           my $yAreaEnd = $yEnd * 0.92;
625 0           my $xAxis = $xAreaEnd - $xCor;
626 0           my $yAxis = $yAreaEnd - $yCor;
627            
628 0           $xsize = $self->{xsize} * $self->{size};
629 0           $ysize = $self->{ysize} * $self->{size};
630 0           $str = "q\n"; # save graphic state
631 0           $str .= "3 M\n"; # miter limit
632 0           $str .= "1 w\n"; # line width
633 0           $str .= "0.5 0.5 0.5 RG\n"; # Gray as stroke color
634 0           $str .= "$xsize 0 0 $ysize $self->{x} $self->{y} cm\n";
635 0           $font = prFont('H');
636            
637 0           my $labelStep = sprintf("%.5f", ($xAxis / $xSteps));
638 0           my $prop = sprintf("%.5f", ($yAxis / $ySteps));
639 0           my $xStart = $xArrow + 10;
640 0           my $yStart = $yAreaEnd;
641            
642 0           my $iStep = sprintf("%.3f", ($yAxis / $groups));
643 0 0         if ($chartMax < 0)
    0          
644 0           { $y0 = $yAreaEnd;
645             }
646             elsif ($chartMin < 0)
647 0           { $y0 = $yCor - ($chartMin * $prop);
648             }
649             else
650 0           { $y0 = $yCor;
651             }
652            
653             ################
654             # Rita y-axeln
655             ################
656            
657 0 0         if (defined $self->{background})
658 0           { $str .= "$self->{background} rg\n";
659 0           $str .= "$xCor $yCor $xAxis $yAxis re\n";
660 0           $str .= "b*\n";
661 0           $str .= "0 0 0 rg\n";
662             }
663 0           $str .= "$xCor $yCor m\n";
664 0           $str .= "$xCor $yArrow l\n";
665             # $str .= "b*\n";
666            
667             ###############
668             # Rita X-axeln
669             ###############
670            
671 0           $str .= "$xCor $y0 m\n";
672 0           $str .= "$xArrow $y0 l\n";
673 0           $str .= "b*\n";
674            
675             #####################
676             # Draw the arrowhead
677             #####################
678            
679 0           $str .= "$xCor $yArrow m\n";
680 0           $x = $xCor + 2;
681 0           $y = $yArrow - 5;
682 0           $str .= "$x $y l\n";
683 0           $x = $xCor;
684 0           $y = $yArrow - 2;
685 0           $str .= "$x $y l\n";
686 0           $x = $xCor - 2;
687 0           $y = $yArrow - 5;
688 0           $str .= "$x $y l\n";
689 0           $str .= "s\n";
690            
691 0           my $xT2 = 0;
692            
693 0 0 0       if ((! defined $self->{nounits}) && (defined $self->{yunit}))
694 0           { $xT = $xCor - (length($self->{yunit}) * 3);
695 0 0         $xT = 1 if $xT < 1;
696 0           $xT2 = $xT + (length($self->{yunit}) * 6);
697 0           $y = $yArrow + 7;
698 0           $x = $xCor - 15;
699 0           $str .= "BT\n";
700 0           $str .= "/$font 12 Tf\n";
701 0           $str .= "$xT $y Td\n";
702 0           $str .= '(' . $self->{yunit} . ') Tj' . "\n";
703 0           $str .= "ET\n";
704             }
705            
706 0 0         if ($self->{title})
707 0           { $xT = ($self->{width} - (length($self->{title}) * 7)) / 2;
708 0 0         if ($xT < ($xT2 + 10))
709 0           { $xT = $xT2 + 10;
710             }
711 0           $y = $yArrow + 12;
712 0           $str .= "BT\n";
713 0           $str .= "/$font 14 Tf\n";
714 0           $str .= "$xT $y Td\n";
715 0           $str .= '(' . $self->{title} . ') Tj' . "\n";
716 0           $str .= "ET\n";
717             }
718            
719             #####################
720             # draw the arrowhead
721             #####################
722            
723 0           $str .= "$xArrow $y0 m\n";
724 0           $x = $xArrow - 5;
725 0           $y = $y0 - 2;
726 0           $str .= "$x $y l\n";
727 0           $x = $xArrow - 2;
728 0           $y = $y0;
729 0           $str .= "$x $y l\n";
730 0           $x = $xArrow - 5;
731 0           $y = $y0 + 2;
732 0           $str .= "$x $y l\n";
733 0           $str .= "s\n";
734            
735 0 0 0       if ((! defined $self->{nounits}) && (defined $self->{xunit}))
736 0           { $y = $y0 - 5;
737 0           $x = $xArrow + 10;
738 0           $str .= "BT\n";
739 0           $str .= "/$font 12 Tf\n";
740 0           $str .= "$x $y Td\n";
741 0           $str .= '(' . $self->{xunit} . ') Tj' . "\n";
742 0           $str .= "ET\n";
743             }
744            
745             ##################################
746             # draw the lines cross the x-axis
747             ##################################
748 0           my $yCor2 = $yCor - 5;
749 0           my $yFrom = $yAreaEnd;
750 0 0 0       if (($self->{type} eq 'area') || ($self->{type} eq 'lines'))
751 0           { $xT = sprintf("%.4f", ($labelStep / 2));
752 0           $xT += $xCor;
753             }
754            
755 0           $str .= "0.9 w\n";
756            
757 0           $x = $xCor;
758 0           for (my $i = 0; $i < $xSteps; $i++)
759 0 0 0       { if (($self->{type} eq 'area') || ($self->{type} eq 'lines'))
760 0           { $str .= "0.9 0.9 0.9 RG\n";
761 0           $str .= "$xT $yAreaEnd m\n";
762 0           $str .= "$xT $yCor l\n";
763 0           $str .= "S\n";
764 0           $str .= "0 0 0 RG\n";
765 0           $xT += $labelStep;
766             }
767            
768 0 0 0       if ((defined $self->{iparam})
769             && (defined $self->{columnsActions}->[$i]))
770 0           { $self->insert($x,
771             0,
772             $labelStep,
773             $yCor,
774             $self->{iparam},
775             $self->{columnsActions}->[$i],
776             $self->{columnsToolTips}->[$i]);
777             }
778 0           $x += $labelStep;
779 0           $str .= "$x $yCor m\n";
780 0           $str .= "$x $yCor2 l\n";
781 0           $str .= "s\n";
782             }
783            
784             ####################################
785             # Write the labels under the x-axis
786             ####################################
787            
788 0           $str .= "1 w\n";
789 0           $str .= "0 0 0 RG\n";
790 0           $x = $xCor + sprintf("%.3f", ($labelStep / 2.5));
791 0 0 0       if ((scalar @{$self->{col}}) && ($labelStep > 5) && (! $self->{nounits}))
  0   0        
792 0           { my $radian = 5.3;
793 0           my $Cos = sprintf("%.4f", (cos($radian)));
794 0           my $Sin = sprintf("%.4f", (sin($radian)));
795 0           my $negSin = $Sin * -1;
796 0           my $negCos = $Cos * -1;
797 0           for (my $i = 0; $i <= $xSteps; $i++)
798 0 0         { if (exists $self->{col}->[$i])
799 0           { $str .= "BT\n";
800 0           $str .= "/$font 8 Tf\n";
801 0           $str .= "$Cos $Sin $negSin $Cos $x $yCor2 Tm\n";
802 0           $str .= '(' . $self->{col}->[$i] . ') Tj' . "\n";
803 0           $str .= "ET\n";
804             }
805 0           $x += $labelStep;
806             }
807            
808             }
809 0 0         if (defined $topScale)
810             {
811 0           my $numSteps = $topScale->{num};
812 0           my $factor = 1 / $topScale->{xdensity};
813 0           my $tLabelStep = sprintf("%.5f", ($labelStep * $factor));
814             ##################################
815             # draw the lines cross the x-axis
816             ##################################
817 0           my $ty1 = $yAreaEnd - 2;
818 0           my $ty2 = $yAreaEnd;
819 0           my $ty3 = $ty2 + 3;
820 0           my $ty4 = $ty2 + 1;
821            
822 0           $str .= "0.9 w\n";
823            
824 0           $x = $xCor;
825 0           for (my $i = 0; $i < $numSteps; $i++)
826 0 0 0       { if ((defined $self->{iparam})
827             && (defined $topScale->{columnsActions}->[$i]))
828 0           { $topScale->insert($x,
829             $ty2,
830             $tLabelStep,
831             10,
832             $self->{iparam},
833             $topScale->{columnsActions}->[$i],
834             $topScale->{columnsToolTips}->[$i]);
835             }
836 0           $x += $tLabelStep;
837 0           $str .= "$x $ty1 m\n";
838 0           $str .= "$x $ty3 l\n";
839 0           $str .= "s\n";
840             }
841            
842             ######################################
843             # Write the labels over the top scale
844             ######################################
845            
846 0           $str .= "1 w\n";
847 0           $str .= "0 0 0 RG\n";
848 0           $x = $xCor + sprintf("%.3f", ($tLabelStep / 2.5));
849 0 0 0       if ((exists $topScale->{col})
  0   0        
      0        
850             && (scalar @{$topScale->{col}})
851             && ($tLabelStep > 5)
852             && (! $self->{nounits}))
853 0           { my $radian = 0.45;
854 0           my $Cos = sprintf("%.4f", (cos($radian)));
855 0           my $Sin = sprintf("%.4f", (sin($radian)));
856 0           my $negSin = $Sin * -1;
857 0           my $negCos = $Cos * -1;
858 0           for (my $i = 0; $i <= $numSteps; $i++)
859 0 0         { if (exists $topScale->{col}->[$i])
860 0           { $str .= "BT\n";
861 0           $str .= "/$font 8 Tf\n";
862 0           $str .= "$Cos $Sin $negSin $Cos $x $ty4 Tm\n";
863 0           $str .= '(' . $topScale->{col}->[$i] . ') Tj' . "\n";
864 0           $str .= "ET\n";
865             }
866 0           $x += $tLabelStep;
867             }
868            
869             }
870             }
871            
872 0 0         if ($iStep > 20)
873 0           { $iStep = 20;
874             }
875            
876 0 0         if ($tal < 0)
877 0           { $tal *= -1;
878 0           $langd = length($tal);
879             }
880            
881 0 0         if ($langd > 1)
882 0           { $langd--;
883 0 0 0       if (($langd > 1)
      0        
884             || (($langd == 1) && (substr($tal, 0, 1) le '5')))
885 0           { $langd--;
886             }
887 0           $langd = '0' x $langd;
888 0           $langd = '1' . $langd;
889             }
890 0   0       my $skala = $langd || 1;
891 0           my $xCor2 = $xCor - 5;
892            
893 0           $str .= "0.3 w\n";
894 0           $str .= "0.5 0.5 0.5 RG\n";
895 0           $x = $xAreaEnd + 5;
896 0           my $last = 0;
897            
898 0           while ($skala <= $chartMax)
899 0           { my $yPos = $prop * $skala + $y0;
900 0 0         if (($yPos - $last) > 13)
901 0 0         { if (! $self->{nounits})
902 0           { $xT = $xCor - (length($skala) * 7.5) - 7;
903 0           $str .= "BT\n";
904 0           $str .= "/$font 12 Tf\n";
905 0           $str .= "$xT $yPos Td\n";
906 0           $str .= "($skala)Tj\n";
907 0           $str .= "ET\n";
908             }
909 0           $last = $yPos;
910 0           $str .= "$xCor2 $yPos m\n";
911 0           $str .= "$x $yPos l\n";
912 0           $str .= "b*\n";
913             }
914 0           $skala += $langd;
915             }
916 0           $last = $prop * $langd + $y0;
917 0           $skala = 0;
918 0           while ($skala >= $chartMin)
919 0           { my $yPos = $prop * $skala + $y0;
920 0 0         if (($last - $yPos) > 13)
921 0 0         { if (! $self->{nounits})
922 0           { $xT = $xCor - (length($skala) * 6) - 10;
923 0 0         $xT = 1 if ($xT < 1);
924 0           $str .= "BT\n";
925 0           $str .= "/$font 12 Tf\n";
926 0           $str .= "$xT $yPos Td\n";
927 0           $str .= "($skala)Tj\n";
928 0           $str .= "ET\n";
929             }
930 0           $last = $yPos;
931 0           $str .= "$xCor2 $yPos m\n";
932 0           $str .= "$x $yPos l\n";
933 0           $str .= "b*\n";
934             }
935 0           $skala -= $langd;
936             }
937            
938 0 0 0       if ((defined $self->{marginAction})
939             && (defined $self->{iparam}))
940 0           { $self->insert( 0,
941             0,
942             $xCor,
943             $yArrow,
944             $self->{iparam},
945             $self->{marginAction},
946             $self->{marginToolTip});
947             }
948            
949            
950 0 0         if (defined $rightScale)
951 0           { my $rightFactor = $rightScale->{ydensity};
952 0           my $rightMax = sprintf("%.0f", ($chartMax * $rightFactor));
953 0           my $rightMin = sprintf("%.0f", ($chartMin * $rightFactor));
954 0           $tal1 = $rightMax;
955 0           $tal2 = $rightMin;
956 0           $rightFactor = sprintf("%.5f", ($prop / $rightFactor));
957 0 0         $tal = (length($tal1) > length($tal2)) ? $tal1 : $tal2;
958 0           $langd = length($tal);
959 0           my $rx1 = $xAreaEnd + 2;
960 0           my $rx2 = $rx1 + 4;
961 0           my $rx3 = $rx2 + 3;
962 0           my $rx4 = $rx3 + 7;
963 0           $str .= "0.3 w\n";
964 0           $str .= "0.5 0.5 0.5 RG\n";
965 0           $str .= "$rx2 $yAreaEnd m\n";
966 0           $str .= "$rx2 $yCor l\n";
967 0           $str .= "b*\n";
968            
969 0   0       $xStart += ($langd * 7.5) || 25;
970 0 0         if ($tal < 0)
971 0           { $tal *= -1;
972 0           $langd = length($tal);
973             }
974            
975 0 0         if ($langd > 1)
976 0           { $langd--;
977 0 0 0       if (($langd > 1)
      0        
978             || (($langd == 1) && (substr($tal, 0, 1) le '5')))
979 0           { $langd--;
980             }
981 0           $langd = '0' x $langd;
982 0           $langd = '1' . $langd;
983             }
984 0   0       $skala = $langd || 1;
985            
986 0           $last = 0;
987            
988 0           while ($skala <= $rightMax)
989 0           { my $yPos = $rightFactor * $skala + $y0;
990 0 0         if (($yPos - $last) > 13)
991 0 0         { if (! $self->{nounits})
992 0           { $str .= "BT\n";
993 0           $str .= "/$font 12 Tf\n";
994 0           $str .= "$rx4 $yPos Td\n";
995 0           $str .= "($skala)Tj\n";
996 0           $str .= "ET\n";
997             }
998 0           $last = $yPos;
999 0           $str .= "$rx1 $yPos m\n";
1000 0           $str .= "$rx3 $yPos l\n";
1001 0           $str .= "b*\n";
1002             }
1003 0           $skala += $langd;
1004             }
1005 0           $last = $rightFactor * $langd + $y0;
1006 0           $skala = 0;
1007 0           while ($skala >= $rightMin)
1008 0           { my $yPos = $rightFactor * $skala + $y0;
1009 0 0         if (($last - $yPos) > 13)
1010 0 0         { if (! $self->{nounits})
1011 0           { $str .= "BT\n";
1012 0           $str .= "/$font 12 Tf\n";
1013 0           $str .= "$rx4 $yPos Td\n";
1014 0           $str .= "($skala)Tj\n";
1015 0           $str .= "ET\n";
1016             }
1017 0           $last = $yPos;
1018 0           $str .= "$rx1 $yPos m\n";
1019 0           $str .= "$rx3 $yPos l\n";
1020 0           $str .= "b*\n";
1021             }
1022 0           $skala -= $langd;
1023             }
1024 0 0 0       if ((defined $rightScale->{marginAction})
1025             && (defined $self->{iparam}))
1026 0           { $rightScale->insert( $xAreaEnd,
1027             0,
1028             35,
1029             $yArrow,
1030             $self->{iparam},
1031             $rightScale->{marginAction},
1032             $rightScale->{marginToolTip});
1033             }
1034            
1035             }
1036 0           $str .= "0 0 0 RG\n";
1037            
1038 0           my $col1 = 0.9;
1039 0           my $col2 = 0.4;
1040 0           my $col3 = 0.9;
1041 0           srand(9);
1042            
1043 0           my $tStart = $xStart + 20;
1044            
1045 0           unshift @array, $self;
1046            
1047 0           for my $overlay (@array)
1048 0 0         { if (defined $overlay->{groupstitle})
1049 0           { my $yTemp = $yStart;
1050 0 0         if ($yTemp < ($y0 + 20))
1051 0           { $yTemp = $y0 - 20;
1052 0           $yStart = $yTemp - 20;
1053             }
1054 0           $str .= "0 0 0 rg\n";
1055 0           $str .= "BT\n";
1056 0           $str .= "/$font 12 Tf\n";
1057 0           $str .= "$xStart $yTemp Td\n";
1058 0           $str .= '(' . $overlay->{groupstitle} . ') Tj' . "\n";
1059 0           $str .= "ET\n";
1060 0           $yStart -= $iStep;
1061             }
1062            
1063 0 0         if (defined $overlay->{groupstext})
1064 0           { my $yTemp = $yStart;
1065 0 0         if ($yTemp < ($y0 + 20))
1066 0           { $yTemp = $y0 - 20;
1067 0           $yStart = $yTemp - 20;
1068             }
1069 0           $str .= "0 0 0 rg\n";
1070 0           $str .= "BT\n";
1071 0           $str .= "/$font 12 Tf\n";
1072 0           $str .= "$xStart $yTemp Td\n";
1073 0           $str .= '(' . $overlay->{groupstext} . ') Tj' . "\n";
1074 0           $str .= "ET\n";
1075 0           $yStart -= $iStep;
1076             }
1077            
1078 0 0         my @color = (defined $overlay->{color}) ? @{$overlay->{color}} : ();
  0            
1079 0           my $groups = $#{$overlay->{sequence}} + 1;
  0            
1080 0           for (my $i = 0; $i < $groups; $i++)
1081 0 0         { if (! defined $color[$i])
1082 0           { $col1 = $col3;
1083 0           my $alt1 = sprintf("%.2f", (rand(1)));
1084 0           my $alt2 = sprintf("%.2f", (rand(1)));
1085 0 0         $col2 = abs($col2 - $col3) > abs(1 - $col3) ? $col3 : (1 - $col3);
1086 0 0         $col3 = abs($col3 - $alt1) > abs($col3 - $alt2) ? $alt1 : $alt2;
1087 0           $color[$i] = "$col1 $col2 $col3";
1088             }
1089 0 0 0       if ((defined $overlay->{nogroups}) && ($overlay->{nogroups}))
1090 0           { next;
1091             }
1092 0           my $name = $overlay->{sequence}->[$i];
1093 0           $str .= "$color[$i] rg\n";
1094 0 0 0       if (($yStart < ($y0 + 13)) && ($yStart > ($y0 - 18)))
1095 0           { $yStart = $y0 - 20;
1096             }
1097 0           $str .= "$xStart $yStart 10 7 re\n";
1098 0           $str .= "b*\n";
1099 0           $str .= "0 0 0 rg\n";
1100 0           $str .= "BT\n";
1101 0           $str .= "/$font 12 Tf\n";
1102 0           $str .= "$tStart $yStart Td\n";
1103 0 0         if ($name)
1104 0           { $str .= '(' . $name . ') Tj' . "\n";
1105             }
1106             else
1107 0           { $str .= '(' . $i . ') Tj' . "\n";
1108             }
1109 0           $str .= "ET\n";
1110            
1111 0 0 0       if ((defined $self->{iparam})
1112             && (defined $overlay->{boxAction}->{$name}))
1113 0           { $overlay->insert($xStart,
1114             $yStart,
1115             10,
1116             7,
1117             $self->{iparam},
1118             $overlay->{boxAction}->{$name},
1119             $overlay->{boxToolTip}->{$name});
1120             }
1121            
1122 0           $yStart -= $iStep;
1123             }
1124 0           @{$overlay->{color}} = @color;
  0            
1125             }
1126            
1127 0           for my $overlay ( reverse @array)
1128 0           { $str .= "0 0 0 RG\n0 j\n0 J\n";
1129 0 0         if ($overlay->{type} eq 'bars')
    0          
    0          
    0          
    0          
1130 0           { $str .= $overlay->draw_bars($xSteps, $xCor, $y0, $labelStep, $prop);
1131             }
1132             elsif ($overlay->{type} eq 'totalbars')
1133 0           { $str .= $overlay->draw_totalbars($xSteps, $xCor, $y0, $labelStep, $prop);
1134             }
1135             elsif ($overlay->{type} eq 'lines')
1136 0           { $str .= $overlay->draw_lines($xSteps, $xCor, $yCor, $labelStep, $prop, $min);
1137             }
1138             elsif ($overlay->{type} eq 'percentbars')
1139 0           { $str .= $overlay->draw_percentbars($xSteps, $xCor, $y0, $labelStep, $prop);
1140             }
1141             elsif ($overlay->{type} eq 'area')
1142 0           { $str .= $overlay->draw_area($xSteps, $xCor, $y0, $labelStep, $prop);
1143             }
1144             }
1145 0           $str .= "Q\n";
1146 0           PDF::Reuse::prAdd($str);
1147            
1148 0           return $self;
1149             }
1150            
1151             sub draw_bars
1152 0     0 0   { my $self = shift;
1153 0           my ($xSteps, $xCor, $y0, $labelStep, $prop) = @_;
1154 0 0         if ($self->{level} ne 'top')
1155 0 0         { if ($self->{ydensity} != 1)
1156 0           { $prop = sprintf("%.5f", ($prop / $self->{ydensity}));
1157             }
1158 0 0         if ($self->{xdensity} != 1)
1159 0           { $labelStep = sprintf("%.5f", ($labelStep / $self->{xdensity}));
1160             }
1161             }
1162            
1163 0           my $string = '';
1164 0           my @color = @{$self->{color}};
  0            
1165 0           my $groups = $#{$self->{sequence}} + 1;
  0            
1166            
1167 0           my $width = sprintf("%.5f", ($labelStep / $groups ));
1168 0           for (my $j = 0; $j <= $xSteps; $j++)
1169 0           { my $height;
1170 0           my $i = -1;
1171 0           for my $namn (@{$self->{sequence}})
  0            
1172 0           { $i++;
1173 0 0         if (defined $self->{series}->{$namn}->[$j])
1174 0 0         { if (ref($self->{series}->{$namn}->[$j]) eq 'ARRAY')
1175 0           { my $number = $#{$self->{series}->{$namn}->[$j]} + 1;
  0            
1176 0           my $fraction = sprintf("%.4f", ($width / $number));
1177 0           my @actions = (ref($self->{barAction}->{$namn}->[$j]) eq 'ARRAY') ?
1178 0 0         @{$self->{barAction}->{$namn}->[$j]} : ();
1179 0           my @toolTips = (ref($self->{barToolTip}->{$namn}->[$j]) eq 'ARRAY')
1180 0 0         ? @{$self->{barToolTip}->{$namn}->[$j]} : ();
1181 0           my $k = 0;
1182 0           for (@{$self->{series}->{$namn}->[$j]})
  0            
1183 0 0         { if (! defined $_)
1184 0           { $xCor += $fraction;
1185 0           $k++;
1186 0           next;
1187             }
1188 0           $height = sprintf("%.5f", ($_ * $prop));
1189 0           $string .= "$color[$i] rg\n";
1190 0           $string .= "$xCor $y0 $fraction $height re\n";
1191 0           $string .= "b*\n";
1192 0 0 0       if ((defined $self->{iparam})
1193             && (defined $actions[$i]))
1194 0           { $self->insert( $xCor,
1195             $y0,
1196             $fraction,
1197             $height,
1198             $self->{iparam},
1199             $actions[$i],
1200             $toolTips[$i]);
1201             }
1202 0           $xCor += $fraction;
1203 0           $k++;
1204             }
1205             }
1206             else
1207 0           { $height = sprintf("%.5f", ($self->{series}->{$namn}->[$j] * $prop));
1208 0           $string .= "$color[$i] rg\n";
1209 0           $string .= "$xCor $y0 $width $height re\n";
1210 0           $string .= "b*\n";
1211 0 0 0       if ((defined $self->{iparam})
1212             && (defined $self->{barAction}->{$namn}->[$j]))
1213 0           { $self->insert( $xCor,
1214             $y0,
1215             $width,
1216             $height,
1217             $self->{iparam},
1218             $self->{barAction}->{$namn}->[$j],
1219             $self->{barToolTip}->{$namn}->[$j]);
1220             }
1221 0           $xCor += $width;
1222             }
1223             }
1224             else
1225 0           { $xCor += $width;
1226             }
1227             }
1228             }
1229 0           return $string;
1230             }
1231            
1232             sub draw_totalbars
1233 0     0 0   { my $self = shift;
1234 0           my ($xSteps, $xCor, $y0, $labelStep, $prop) = @_;
1235 0           my $string = '';
1236 0 0         if ($self->{level} ne 'top')
1237 0 0         { if ($self->{ydensity} != 1)
1238 0           { $prop = sprintf("%.5f", ($prop / $self->{ydensity}));
1239             }
1240 0 0         if ($self->{xdensity} != 1)
1241 0           { $labelStep = sprintf("%.5f", ($labelStep / $self->{xdensity}));
1242             }
1243             }
1244 0           my ($x, $y, $yNeg, $height, $number, $fraction, $namn, $k, $value,
1245             @actions, @toolTips);
1246 0           my @color = @{$self->{color}};
  0            
1247            
1248 0           for (my $j = 0; $j <= $xSteps; $j++)
1249 0           { $x = ($j * $labelStep) + $xCor;
1250 0           my $i = -1;
1251 0 0         if (! defined $self->{tot}[$j])
1252 0           { next;
1253             }
1254 0 0         if (ref($self->{tot}[$j]) eq 'ARRAY')
1255 0           { $number = $#{$self->{tot}[$j]} + 1;
  0            
1256 0           $fraction = sprintf("%.4f", ($labelStep / $number));
1257 0           for ($i = 0; $i < $number; $i++)
1258 0           { $k = 0;
1259 0           $y = $y0;
1260 0           $yNeg = $y0;
1261 0           for $namn (@{$self->{sequence}})
  0            
1262 0           { @actions = (ref($self->{barAction}->{$namn}->[$j]) eq 'ARRAY') ?
1263 0 0         @{$self->{barAction}->{$namn}->[$j]} : ();
1264 0           @toolTips = (ref($self->{barToolTip}->{$namn}->[$j]) eq 'ARRAY')
1265 0 0         ? @{$self->{barToolTip}->{$namn}->[$j]} : ();
1266 0           $value = $self->{series}->{$namn}->[$j][$i];
1267 0 0         if (! defined $value)
1268 0           { $k++;
1269 0           next;
1270             }
1271 0 0         if ($value > 0)
    0          
1272 0           { $height = sprintf("%.5f", ($value * $prop));
1273 0           $string .= "$color[$k] rg\n";
1274 0           $string .= "$x $y $fraction $height re\n";
1275 0           $string .= "b*\n";
1276 0 0 0       if ((defined $self->{iparam})
1277             && (defined $actions[$i]))
1278 0           { $self->insert( $x,
1279             $y,
1280             $fraction,
1281             $height,
1282             $self->{iparam},
1283             $actions[$i],
1284             $toolTips[$i]);
1285             }
1286 0           $y += $height;
1287 0           $k++;
1288             }
1289             elsif ($value < 0)
1290 0           { $height = sprintf("%.5f", ($value * $prop));
1291 0           $string .= "$color[$k] rg\n";
1292 0           $string .= "$x $yNeg $fraction $height re\n";
1293 0           $string .= "b*\n";
1294 0 0 0       if ((defined $self->{iparam})
1295             && (defined $actions[$i]))
1296 0           { $self->insert( $x,
1297             $yNeg,
1298             $fraction,
1299             $height,
1300             $self->{iparam},
1301             $actions[$i],
1302             $toolTips[$i]);
1303             }
1304            
1305 0           $yNeg += $height;
1306 0           $k++;
1307             }
1308             }
1309 0           $x += $fraction;
1310             }
1311             }
1312             else
1313 0           { $number = 1;
1314 0           $fraction = sprintf("%.4f", ($labelStep / $number));
1315 0           $y = $y0;
1316 0           $yNeg = $y0;
1317 0           $height = 0;
1318 0           $k = 0;
1319 0           for $namn (@{$self->{sequence}})
  0            
1320 0           { $value = $self->{series}->{$namn}->[$j];
1321 0 0         if (! defined $value)
1322 0           { $k++;
1323 0           next;
1324             }
1325 0 0         if ($value > 0)
    0          
1326 0           { $height = sprintf("%.5f", ($value * $prop));
1327 0           $string .= "$color[$k] rg\n";
1328 0           $string .= "$x $y $fraction $height re\n";
1329 0           $string .= "b*\n";
1330 0 0 0       if ((defined $self->{iparam})
1331             && (defined $self->{barAction}->{$namn}->[$j]))
1332 0           { $self->insert( $x,
1333             $y,
1334             $fraction,
1335             $height,
1336             $self->{iparam},
1337             $self->{barAction}->{$namn}->[$j],
1338             $self->{barToolTip}->{$namn}->[$j]);
1339             }
1340            
1341 0           $y += $height;
1342 0           $k++;
1343             }
1344             elsif ($value < 0)
1345 0           { $height = sprintf("%.5f", ($value * $prop));
1346 0           $string .= "$color[$k] rg\n";
1347 0           $string .= "$x $yNeg $fraction $height re\n";
1348 0           $string .= "b*\n";
1349 0 0 0       if ((defined $self->{iparam})
1350             && (defined $self->{barAction}->{$namn}->[$j]))
1351 0           { $self->insert( $x,
1352             $yNeg,
1353             $fraction,
1354             $height,
1355             $self->{iparam},
1356             $self->{barAction}->{$namn}->[$j],
1357             $self->{barToolTip}->{$namn}->[$j]);
1358             }
1359 0           $yNeg += $height;
1360 0           $k++;
1361             }
1362             }
1363             }
1364             }
1365 0           return $string;
1366             }
1367            
1368            
1369             sub draw_lines
1370 0     0 0   { my $self = shift;
1371 0           my ($xSteps, $xCor, $yCor, $labelStep, $prop, $min) = @_;
1372 0 0         if ($self->{level} ne 'top')
1373 0 0         { if ($self->{ydensity} != 1)
1374 0           { $prop = sprintf("%.5f", ($prop / $self->{ydensity}));
1375             }
1376 0 0         if ($self->{xdensity} != 1)
1377 0           { $labelStep = sprintf("%.5f", ($labelStep / $self->{xdensity}));
1378             }
1379             }
1380            
1381 0           my $string = "1 w\n1 j\n1 J\n";
1382 0           my @color = @{$self->{color}};
  0            
1383 0 0         my $offSet = ($min < 0) ? $min : 0;
1384 0           my $i = -1;
1385            
1386 0           for my $namn (@{$self->{sequence}})
  0            
1387 0           { $i++;
1388 0           my ($move, $step);
1389 0           my $height;
1390 0           my $x = $xCor;
1391 0           my $x2;
1392             my $y2;
1393 0           $string .= "$color[$i] RG\n";
1394 0           $string .= "$color[$i] rg\n";
1395 0           for (my $j = 0; $j <= $xSteps; $j++)
1396 0 0         { if (defined $self->{series}->{$namn}->[$j])
1397 0 0         { if (ref($self->{series}->{$namn}->[$j]) eq 'ARRAY')
1398 0           { my $number = $#{$self->{series}->{$namn}->[$j]} + 2;
  0            
1399 0           $step = sprintf("%.4f", ($labelStep / $number));
1400 0           my @actions = (ref($self->{barAction}->{$namn}->[$j]) eq 'ARRAY') ?
1401 0 0         @{$self->{barAction}->{$namn}->[$j]} : ();
1402 0           my @toolTips = (ref($self->{barToolTip}->{$namn}->[$j]) eq 'ARRAY')
1403 0 0         ? @{$self->{barToolTip}->{$namn}->[$j]} : ();
1404            
1405 0           my $k = 0;
1406 0           $x += $step;
1407 0           for (@{$self->{series}->{$namn}->[$j]})
  0            
1408 0 0         { if (! defined $_)
1409 0 0         { if ($move)
1410 0           { $string .= "b*\n";
1411 0           $move = undef;
1412             }
1413 0           $k++;
1414 0           $x += $step;
1415 0           next;
1416             }
1417 0           $height = sprintf("%.5f", (($_ - $offSet) * $prop));
1418 0           $height += $yCor;
1419 0           $x2 = $x - 1.5;
1420 0           $y2 = $height - 1.5;
1421 0 0         if ($move)
1422 0 0         { $string .= "$move m\n" if ($move);
1423 0           $string .= "$x $height l\n";
1424             }
1425 0 0         if (! defined $self->{nomarker})
1426 0           { $string .= "$x2 $y2 3 3 re\n";
1427 0 0 0       if ((defined $self->{iparam})
1428             && (defined $actions[$i]))
1429 0           { $self->insert( $x2,
1430             $y2,
1431             3,
1432             3,
1433             $self->{iparam},
1434             $actions[$i],
1435             $toolTips[$i]);
1436             }
1437             }
1438 0           $move = "$x $height";
1439 0           $k++;
1440 0           $x += $step;
1441             }
1442             }
1443             else
1444 0           { $x += $labelStep / 2;
1445 0           $height = sprintf("%.5f", (($self->{series}->{$namn}->[$j] - $offSet) * $prop));
1446 0           $height += $yCor;
1447 0           $x2 = $x - 1.5;
1448 0           $y2 = $height - 1.5;
1449 0 0         if ($move)
1450 0 0         { $string .= "$move m\n" if ($move);
1451 0           $string .= "$x $height l\n";
1452             }
1453 0 0         if (! defined $self->{nomarker})
1454 0           { $string .= "$x2 $y2 3 3 re\n";
1455 0 0 0       if ((defined $self->{iparam})
1456             && (defined $self->{barAction}->{$namn}->[$j]))
1457 0           { $self->insert( $x2,
1458             $y2,
1459             3,
1460             3,
1461             $self->{iparam},
1462             $self->{barAction}->{$namn}->[$j],
1463             $self->{barToolTip}->{$namn}->[$j]);
1464             }
1465             }
1466 0           $move = "$x $height";
1467 0           $x += $labelStep / 2;
1468             }
1469             }
1470             else
1471 0           { $string .= "b*\n";
1472 0           $move = undef;
1473 0           $x += $labelStep;
1474             }
1475            
1476             }
1477 0           $string .= "b*\n";
1478             }
1479 0           return $string;
1480             }
1481            
1482             sub draw_percentbars
1483 0     0 0   { my $self = shift;
1484 0           my ($xSteps, $xCor, $y0, $labelStep, $prop) = @_;
1485 0 0         if ($self->{level} ne 'top')
1486 0 0         { if ($self->{ydensity} != 1)
1487 0           { $prop = sprintf("%.5f", ($prop / $self->{ydensity}));
1488             }
1489 0 0         if ($self->{xdensity} != 1)
1490 0           { $labelStep = sprintf("%.5f", ($labelStep / $self->{xdensity}));
1491             }
1492             }
1493 0           my $string = '';
1494 0           my ($x, $y, $yNeg, $height, $number, $fraction, $namn, $k, $value,
1495             @actions, @toolTips);
1496 0           my @color = @{$self->{color}};
  0            
1497            
1498 0           for (my $j = 0; $j <= $xSteps; $j++)
1499 0           { $x = ($j * $labelStep) + $xCor;
1500 0           my $i = -1;
1501 0 0         if (! defined $self->{tot}[$j])
1502 0           { next;
1503             }
1504 0 0         if (ref($self->{tot}[$j]) eq 'ARRAY')
1505 0           { $number = $#{$self->{tot}[$j]} + 1;
  0            
1506 0           $fraction = sprintf("%.4f", ($labelStep / $number));
1507 0           for ($i = 0; $i < $number; $i++)
1508 0           { $k = 0;
1509 0           $y = $y0;
1510 0           $yNeg = $y0;
1511 0           for $namn (@{$self->{sequence}})
  0            
1512 0           { @actions = (ref($self->{barAction}->{$namn}->[$j]) eq 'ARRAY') ?
1513 0 0         @{$self->{barAction}->{$namn}->[$j]} : ();
1514 0           @toolTips = (ref($self->{barToolTip}->{$namn}->[$j]) eq 'ARRAY')
1515 0 0         ? @{$self->{barToolTip}->{$namn}->[$j]} : ();
1516 0           $value = $self->{series}->{$namn}->[$j][$i];
1517 0 0         if (! defined $value)
1518 0           { $k++;
1519 0           next;
1520             }
1521 0 0         if ($value > 0)
    0          
1522 0           { $height = sprintf("%.4f", (($value / $self->{tot}[$j][$i])
1523             * 100) * $prop);
1524 0           $string .= "$color[$k] rg\n";
1525 0           $string .= "$x $y $fraction $height re\n";
1526 0           $string .= "b*\n";
1527 0 0 0       if ((defined $self->{iparam})
1528             && (defined $actions[$i]))
1529 0           { $self->insert( $x,
1530             $y,
1531             $fraction,
1532             $height,
1533             $self->{iparam},
1534             $actions[$i],
1535             $toolTips[$i]);
1536             }
1537 0           $y += $height;
1538 0           $k++;
1539             }
1540             elsif ($value < 0)
1541 0           { $height = sprintf("%.4f", (($value / $self->{tot}[$j][$i])
1542             * 100) * $prop);
1543 0           $string .= "$color[$k] rg\n";
1544 0           $string .= "$x $yNeg $fraction $height re\n";
1545 0           $string .= "b*\n";
1546 0 0 0       if ((defined $self->{iparam})
1547             && (defined $actions[$i]))
1548 0           { $self->insert( $x,
1549             $yNeg,
1550             $fraction,
1551             $height,
1552             $self->{iparam},
1553             $actions[$i],
1554             $toolTips[$i]);
1555             }
1556            
1557 0           $yNeg += $height;
1558 0           $k++;
1559             }
1560             }
1561 0           $x += $fraction;
1562             }
1563             }
1564             else
1565 0           { $number = 1;
1566 0           $fraction = sprintf("%.4f", ($labelStep / $number));
1567 0           $y = $y0;
1568 0           $yNeg = $y0;
1569 0           $height = 0;
1570 0           $k = 0;
1571 0           for $namn (@{$self->{sequence}})
  0            
1572 0           { $value = $self->{series}->{$namn}->[$j];
1573 0 0         if (! defined $value)
1574 0           { $k++;
1575 0           next;
1576             }
1577 0 0         if ($value > 0)
    0          
1578 0           { $height = sprintf("%.4f", (($value / $self->{tot}[$j])
1579             * 100) * $prop);
1580 0           $string .= "$color[$k] rg\n";
1581 0           $string .= "$x $y $fraction $height re\n";
1582 0           $string .= "b*\n";
1583 0 0 0       if ((defined $self->{iparam})
1584             && (defined $self->{barAction}->{$namn}->[$j]))
1585 0           { $self->insert( $x,
1586             $y,
1587             $fraction,
1588             $height,
1589             $self->{iparam},
1590             $self->{barAction}->{$namn}->[$j],
1591             $self->{barToolTip}->{$namn}->[$j]);
1592             }
1593            
1594 0           $y += $height;
1595 0           $k++;
1596             }
1597             elsif ($value < 0)
1598 0           { $height = sprintf("%.4f", (($value / $self->{tot}[$j])
1599             * 100) * $prop);
1600 0           $string .= "$color[$k] rg\n";
1601 0           $string .= "$x $yNeg $fraction $height re\n";
1602 0           $string .= "b*\n";
1603 0 0 0       if ((defined $self->{iparam})
1604             && (defined $self->{barAction}->{$namn}->[$j]))
1605 0           { $self->insert( $x,
1606             $yNeg,
1607             $fraction,
1608             $height,
1609             $self->{iparam},
1610             $self->{barAction}->{$namn}->[$j],
1611             $self->{barToolTip}->{$namn}->[$j]);
1612             }
1613 0           $yNeg += $height;
1614 0           $k++;
1615             }
1616             }
1617             }
1618             }
1619 0           return $string;
1620             }
1621            
1622            
1623             sub draw_area
1624 0     0 0   { my $self = shift;
1625 0           my ($xSteps, $xCor, $y0, $labelStep, $prop) = @_;
1626 0 0         if ($self->{level} ne 'top')
1627 0 0         { if ($self->{ydensity} != 1)
1628 0           { $prop = sprintf("%.5f", ($prop / $self->{ydensity}));
1629             }
1630 0 0         if ($self->{xdensity} != 1)
1631 0           { $labelStep = sprintf("%.5f", ($labelStep / $self->{xdensity}));
1632             }
1633             }
1634 0           my $string = '';
1635 0           my @color = @{$self->{color}};
  0            
1636 0           my $width = $labelStep / 2;
1637 0           my @pos = @{$self->{pos}};
  0            
1638 0           my @neg = @{$self->{neg}};
  0            
1639 0           my $i = -1;
1640 0           my ($y, $fraction);
1641 0           for my $namn (@{$self->{sequence}})
  0            
1642 0           { $i++;
1643 0           my $move;
1644 0           my $x = $xCor;
1645 0           $string .= "$color[$i] RG\n";
1646 0           $string .= "$color[$i] rg\n";
1647 0           for (my $j = 0; $j <= $xSteps; $j++)
1648 0 0         { if (defined $self->{series}->{$namn}->[$j])
1649 0           { my $value = $self->{series}->{$namn}->[$j];
1650 0 0         if (ref($value) eq 'ARRAY')
1651 0           { my $number = $#{$value} + 1;
  0            
1652 0           my $fraction = sprintf("%.3f", ($labelStep / ($number * 2)));
1653 0           my $k = 0;
1654 0           for (@{$value})
  0            
1655 0 0         { if (! defined $_)
    0          
    0          
1656 0 0         { if ($move)
1657 0           { $string .= "$x $y l\n";
1658 0           $string .= "$x $y0 l\n";
1659 0           $string .= "B*\n";
1660 0           undef $move;
1661             }
1662 0           $x += $fraction;
1663             }
1664             elsif ($_ > 0)
1665 0           { $y = sprintf("%.5f", (($pos[$j][$k] * $prop) + $y0));
1666 0 0         if (! defined $move)
1667 0           { $string .= "$x $y0 m\n";
1668 0           $string .= "$x $y l\n";
1669 0           $move = 1;
1670             }
1671 0           $x += $fraction;
1672 0           $string .= "$x $y l\n";
1673 0           $pos[$j][$k] -= $_;
1674             }
1675             elsif ($_ < 0)
1676 0 0         { $neg[$j][$k] = 0 if (! defined $neg[$j][$k]);
1677 0           $y = sprintf("%.5f", ($y0 - ($neg[$j][$k] * $prop)));
1678 0 0         if (! defined $move)
1679 0           { $string .= "$x $y0 m\n";
1680 0           $string .= "$x $y l\n";
1681 0           $move = 1;
1682             }
1683 0           $x += $fraction;
1684 0           $string .= "$x $y l\n";
1685 0           $neg[$j][$k] += $_;
1686             }
1687             else
1688 0           { $x += $fraction;
1689             }
1690 0           $x += $fraction;
1691 0           $k++;
1692             }
1693             }
1694             else
1695 0           { $fraction = $labelStep / 2;
1696 0 0         if ($value > 0)
    0          
1697 0           { $y = sprintf("%.5f", (($pos[$j] * $prop) + $y0));
1698 0 0         if (! defined $move)
1699 0           { $string .= "$x $y0 m\n";
1700 0           $string .= "$x $y l\n";
1701 0           $move = 1;
1702             }
1703 0           $x += $fraction;
1704 0           $string .= "$x $y l\n";
1705 0           $pos[$j] -= $value;
1706             }
1707             elsif ($value < 0)
1708 0 0         { $neg[$j] = 0 if (! defined $neg[$j]);
1709 0           $y = sprintf("%.5f", ($y0 - ($neg[$j] * $prop)));
1710 0 0         if (! defined $move)
1711 0           { $string .= "$x $y0 m\n";
1712 0           $string .= "$x $y l\n";
1713 0           $move = 1;
1714             }
1715 0           $x += $fraction;
1716 0           $string .= "$x $y l\n";
1717 0           $neg[$j] += $value;
1718             }
1719             else
1720 0           { $x += $fraction;
1721             }
1722 0           $x += $fraction;
1723             }
1724             }
1725             else
1726 0 0         { if ($move)
1727 0           { $string .= "$x $y l\n";
1728 0           $string .= "$x $y0 l\n";
1729 0           $string .= "B*\n";
1730 0           undef $move;
1731             }
1732 0           $x += $labelStep;
1733             }
1734            
1735             }
1736 0 0         if ($move)
1737 0           { $string .= "$x $y l\n";
1738 0           $string .= "$x $y0 l\n";
1739 0           $string .= "B*\n";
1740             }
1741             }
1742 0           return $string;
1743             }
1744            
1745            
1746            
1747             sub insert
1748 0     0 0   { my $self = shift;
1749 0           my ($xPos, $yPos, $wid, $hei, $page, $action, $mess) = @_;
1750            
1751 0           my $x = $self->{x} + $xPos * ($self->{xsize} * $self->{size});
1752 0           my $y = $self->{y} + $yPos * ($self->{ysize} * $self->{size});
1753 0           my $width = $wid * ($self->{xsize} * $self->{size});
1754 0           my $height = $hei * ($self->{ysize} * $self->{size});
1755            
1756 0 0         if ($mess)
1757 0           { prInit("iArea($page, $x, $y, $width, $height, $action, $mess);");
1758             }
1759             else
1760 0           { prInit("iArea($page, $x, $y, $width, $height, $action);");
1761             }
1762 0           1;
1763             }
1764            
1765             1;
1766            
1767             __END__