5 Bweb - A Bacula web interface
6 Bacula® - The Network Backup Solution
8 Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
10 The main author of Bweb is Eric Bollengier.
11 The main author of Bacula is Kern Sibbald, with contributions from
12 many others, a complete list can be found in the file AUTHORS.
14 This program is Free Software; you can redistribute it and/or
15 modify it under the terms of version two of the GNU General Public
16 License as published by the Free Software Foundation plus additions
17 that are listed in the file LICENSE.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 Bacula® is a registered trademark of John Walker.
30 The licensor of Bacula is the Free Software Foundation Europe
31 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
32 Switzerland, email:ftf@fsfeurope.org.
65 my ($class, %arg) = @_ ;
69 degrees_complete => 0,
70 parent_percent => 100,
87 map { $self->{$_} = $arg{$_} } keys %arg ;
90 $height = $self->{height} ;
91 $width = $self->{width} ;
93 $gd = new GD::Image($width,$height);
94 $white = $gd->colorAllocate(255,255,255);
96 push @color_tab, ($gd->colorAllocate(135,236,88),
97 $gd->colorAllocate(255,95,95),
98 $gd->colorAllocate(245,207,91),
99 $gd->colorAllocate( 255, 236, 139),
100 $gd->colorAllocate( 255, 174, 185),
101 $gd->colorAllocate( 179, 255, 58),
102 $gd->colorAllocate( 205, 133, 0),
103 $gd->colorAllocate(205, 133, 0 ),
104 $gd->colorAllocate(238, 238, 209),
109 $black = $gd->colorAllocate(0,0,0);
110 #$gd->>transparent($white);
111 $gd->interlaced('true');
113 $gd->arc($self->{center_x},$self->{center_y},
114 $self->{diameter},$self->{diameter},
115 $self->{start_degrees},360, $black) ;
119 $self->{rayon} = $self->{diameter} / 2 ;
123 # pour afficher les labels tout propre
124 if ($self->{level} > $last_level) {
125 $last_level = $self->{level} ;
133 my ($self, $level, $deg) = @_ ;
135 my $x1 = $self->{center_x}+$self->{rayon} * $level * cos($deg*$pi/180) ;
136 my $y1 = $self->{center_y}+$self->{rayon} * $level * sin($deg*$pi/180) ;
144 my ($self, $percent, $label, $tips) = @_ ;
146 $tips = $tips || $label ;
148 if (($percent + $self->{percent_total}) > 100.05) {
149 print STDERR "Attention $label ($percent\% + $self->{percent_total}\%) > 100\%\n" ;
154 print STDERR "Attention $label <= 0\%\n" ;
158 # angle de depart de l'arc
159 my $start_degrees = (($self->{degrees_complete})?
160 $self->{degrees_complete}:$self->{start_degrees}) ;
162 # angle de fin de l'arc
163 my $end_degrees = $start_degrees +
164 ($percent * ( ( $self->{parent_percent} * 360 )/100 ) ) /100 ;
166 # print STDERR "-------- $debug --------
169 #level = $self->{level}
170 #start = $start_degrees
172 #parent= $self->{parent_percent}
174 if (($end_degrees - $start_degrees) < $self->{min_degrees}) {
175 $self->{min_total} += $percent ;
179 if ($percent <= $self->{min_percent}) {
180 $self->{min_total} += $percent ;
184 # on totalise les % en cours
185 $self->{percent_total} += $percent ;
187 #print STDERR "percent_total = $self->{percent_total}\n" ;
189 # position dans le cercle
190 my $n = $self->{level} ; # on ajoute/retire 0.005 pour depasser un peu
193 # si c'est la premiere tranche de la nouvelle serie, il faut dessiner
196 if ($self->{degrees_complete} == 0) {
197 my ($x1, $y1) = $self->calc_xy($n-0.005, $self->{start_degrees}) ;
198 my ($x2, $y2) = $self->calc_xy($m+0.005, $self->{start_degrees}) ;
200 $gd->line($x1, $y1, $x2, $y2, $black) ;
204 my ($x3, $y3) = $self->calc_xy($n-0.005, $end_degrees) ;
206 my ($x4, $y4) = $self->calc_xy($m+0.005, $end_degrees) ;
208 # ligne de bord exterieur
209 $gd->line($x3, $y3, $x4, $y4, $black);
212 $gd->arc($self->{center_x},$self->{center_y},
213 $self->{diameter}*($self->{level}+1),
214 $self->{diameter}*($self->{level}+1),
217 $end_degrees+0.5, $black) ;
219 # on calcule le point qui est au milieu de la tranche
220 # angle = (angle nouvelle tranche)/2
222 # rayon = n*rayon - 0.5*rayon
227 my $mid_rad = ($end_degrees - $start_degrees) /2 + $start_degrees;
229 my $moy_x = ($self->{center_x}+
230 ($self->{rayon}*$m - 0.5*$self->{rayon})
231 *cos($mid_rad*$pi/180)) ;
233 my $moy_y = ($self->{center_y}+
234 ($self->{rayon}*$m - 0.5*$self->{rayon})
235 *sin($mid_rad*$pi/180)) ;
237 $gd->fillToBorder($moy_x,
242 # on prend une couleur au hasard
243 $cur_color = ($cur_color % $#color_tab) + 1 ;
245 # si le % est assez grand, on affiche le label
246 if ($percent > $self->{min_label}) {
247 push @draw_label, [$label,
251 $self->push_image_map($label, $tips, $start_degrees, $end_degrees) ;
254 # pour pourvoir ajouter des sous donnees
255 my $ret = new CCircle(start_degrees => $start_degrees,
256 parent_percent => $percent*$self->{parent_percent}/100,
258 center_x => $self->{center_x},
259 center_y => $self->{center_y},
260 min_percent => $self->{min_percent},
261 min_degrees => $self->{min_degrees},
262 base_url => $self->{base_url} . $label,
265 $self->{degrees_complete} = $end_degrees ;
267 #print STDERR "$debug : [$self->{level}] $label ($percent)\n" ;
268 #open(FP, sprintf(">/tmp/img.%.3i.png", $debug)) ;
277 # on dessine le restant < min_percent
282 $self->add_part($self->{min_total},
283 "other < $self->{min_percent}%",
290 my ($self, $title) = @_ ;
292 $gd->string(GD::gdSmallFont, $self->{center_x} - $self->{rayon}*0.7,
293 $self->{center_y}, $title, $black) ;
300 my ($self, $title, $img) = @_ ;
306 <img src='$img' border=0 usemap='#testmap' alt=''>
313 my ($self, $label, $tips, $start_degrees, $end_degrees) = @_ ;
315 if ($label =~ /^other .*</) {
316 if (!$self->{display_other}) {
322 # on prend des points tous les $delta sur l'arc interieur et exterieur
326 if (($end_degrees - $start_degrees) < $delta) {
332 for (my $i = $start_degrees ;
336 my ($x1, $y1) = $self->calc_xy($self->{level}, $i) ;
337 my ($x2, $y2) = $self->calc_xy($self->{level} + 1, $i) ;
339 push @pts, sprintf("%.2f,%.2f",$x1,$y1) ;
340 unshift @pts, sprintf("%.2f,%.2f",$x2, $y2) ;
343 my ($x1, $y1) = $self->calc_xy($self->{level}, $end_degrees) ;
344 my ($x2, $y2) = $self->calc_xy($self->{level} + 1, $end_degrees) ;
346 push @pts, sprintf("%.2f,%.2f",$x1,$y1) ;
347 unshift @pts, sprintf("%.2f,%.2f",$x2, $y2) ;
349 my $ret = join(",", @pts) ;
351 # on refait le traitement avec $i = $end_degrees
352 $_image_map .= "<area shape='polygon' coords='$ret' ".
353 "title='$tips' href='$self->{base_url}$label'>\n" ;
357 sub get_labels_imagemap
362 for my $l (@draw_label)
365 my ($label, $x, $y, $level) = @{ $l } ;
367 next if ($level > $self->{max_label_level}) ;
369 next if (!$self->{display_other} and $label =~ /^other .*</) ;
371 my $dy = ($y - $self->{center_y})*($last_level - $level) + $y ;
376 if ($x < $self->{center_x}) {
377 $x2 = $self->{center_x}
378 - $self->{rayon} * ($last_level + 3.7) ;
379 $xp = $x2 - (length($label) *6 + 2) ; # moins la taille de la police
381 $x2 = $self->{center_x} + $self->{rayon} * ($last_level + 3.7) ;
385 push @ret, $xp - 1 . ";" . $dy - 6 . ";" . $xp + length($label) * $font_size . ";" . $dy + 10 . "\n" ;
387 $gd->rectangle($xp - 1, $dy - 6,
388 $xp + length($label) * $font_size,
396 my $_label_init = 0 ;
398 # on va stocker les positions dans un bitmap $_label_pos
400 # si on match pas la position exacte, on essaye la case
401 # au dessus ou en dessous
403 # on a un bitmap pour les labels de gauche et un pour la droite
404 # $_label_pos->[0] et $_label_pos->[1]
407 my ($self, $x, $y) = @_ ;
409 unless ($_label_init) {
410 $_label_hauteur = $self->{rayon} * 2 * $last_level ;
411 # nombre max de label = hauteur max / taille de la font
412 $_label_max = $_label_hauteur / 12 ;
413 $_label_pos = [ [], [] ] ;
417 # on calcule la position du label dans le bitmap
419 my $num = $y * $_label_max / $_label_hauteur ;
422 my $n = 0 ; # nombre d'iteration
425 # on prend le bon bitmap
426 if ($x < $self->{center_x}) {
427 $l = $_label_pos->[0] ;
429 $l = $_label_pos->[1] ;
432 # on parcours le bitmap pour trouver la bonne position
433 while (($num - $n) > 0) {
434 if (not $l->[$num]) {
436 } elsif (not $l->[$num + $n]) {
439 } elsif (not $l->[$num - $n]) {
446 $l->[$num] = 1 ; # on prend la position
452 # calcul de la position
453 $y = $num * $_label_hauteur / $_label_max ;
467 for my $l (@draw_label)
470 my ($label, $x, $y, $level) = @{ $l } ;
472 next if ($level > $self->{max_label_level}) ;
474 next if (!$self->{display_other} and $label =~ /^other .*</) ;
476 my $dx = ($x - $self->{center_x})*($last_level - $level) + $x ;
477 my $dy = ($y - $self->{center_y})*($last_level - $level) + $y ;
479 $dy = $self->get_label_pos($dx, $dy) ;
481 next unless ($dy) ; # pas d'affichage si pas de place
490 if ($x < $self->{center_x}) {
491 $x2 = $self->{center_x}
492 - $self->{rayon} * ($last_level + 3.7) ;
493 $xp = $x2 - (length($label) * $font_size + 2) ; # moins la taille de la police
495 $x2 = $self->{center_x} + $self->{rayon} * ($last_level + 3.7) ;
503 $gd->string(GD::gdSmallFont, $xp, $dy - 5, $label, $black) ;
512 my $top = new CCircle() ;
514 my $chld1 = $top->add_part(50, 'test') ;
515 my $chld2 = $top->add_part(20, 'test') ;
516 my $chld3 = $top->add_part(10, 'test') ;
517 my $chld4 = $top->add_part(20, 'test') ;
520 $chld1->add_part(20, 'test1') ;
521 $chld1->add_part(20, 'test1') ;
523 $chld2->add_part(20, 'test1') ;
524 $chld2->add_part(20, 'test1') ;
526 $chld3->add_part(20, 'test1') ;
527 my $chld5 = $chld3->add_part(20, 'test1') ;
529 $chld5->add_part(50, 'test3') ;
538 $top->draw_labels() ;
539 # make sure we are writing to a binary stream
542 # Convert the image to PNG and print it on standard output
543 print $CCircle::gd->png;