5 Bweb - A Bacula web interface
6 Bacula® - The Network Backup Solution
8 Copyright (C) 2000-2010 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.
13 This program is Free Software; you can redistribute it and/or
14 modify it under the terms of version three of the GNU Affero General Public
15 License as published by the Free Software Foundation and included
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU Affero General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 Bacula® is a registered trademark of Kern Sibbald.
29 The licensor of Bacula is the Free Software Foundation Europe
30 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
31 Switzerland, email:ftf@fsfeurope.org.
60 my ($class, %arg) = @_ ;
64 degrees_complete => 0,
65 parent_percent => 100,
82 map { $self->{$_} = $arg{$_} } keys %arg ;
85 $height = $self->{height} ;
86 $width = $self->{width} ;
88 $gd = new GD::Image($width,$height);
89 $white = $gd->colorAllocate(255,255,255);
91 push @color_tab, ($gd->colorAllocate(135,236,88),
92 $gd->colorAllocate(255,95,95),
93 $gd->colorAllocate(245,207,91),
94 $gd->colorAllocate( 255, 236, 139),
95 $gd->colorAllocate( 255, 174, 185),
96 $gd->colorAllocate( 179, 255, 58),
97 $gd->colorAllocate( 205, 133, 0),
98 $gd->colorAllocate(205, 133, 0 ),
99 $gd->colorAllocate(238, 238, 209),
104 $black = $gd->colorAllocate(0,0,0);
105 #$gd->>transparent($white);
106 $gd->interlaced('true');
108 $gd->arc($self->{center_x},$self->{center_y},
109 $self->{diameter},$self->{diameter},
110 $self->{start_degrees},360, $black) ;
114 $self->{rayon} = $self->{diameter} / 2 ;
118 # pour afficher les labels tout propre
119 if ($self->{level} > $last_level) {
120 $last_level = $self->{level} ;
128 my ($self, $level, $deg) = @_ ;
130 my $x1 = $self->{center_x}+$self->{rayon} * $level * cos($deg*$pi/180) ;
131 my $y1 = $self->{center_y}+$self->{rayon} * $level * sin($deg*$pi/180) ;
139 my ($self, $percent, $label, $tips) = @_ ;
141 $tips = $tips || $label ;
143 if (($percent + $self->{percent_total}) > 100.05) {
144 print STDERR "Attention $label ($percent\% + $self->{percent_total}\%) > 100\%\n" ;
149 print STDERR "Attention $label <= 0\%\n" ;
153 # angle de depart de l'arc
154 my $start_degrees = (($self->{degrees_complete})?
155 $self->{degrees_complete}:$self->{start_degrees}) ;
157 # angle de fin de l'arc
158 my $end_degrees = $start_degrees +
159 ($percent * ( ( $self->{parent_percent} * 360 )/100 ) ) /100 ;
161 # print STDERR "-------- $debug --------
164 #level = $self->{level}
165 #start = $start_degrees
167 #parent= $self->{parent_percent}
169 if (($end_degrees - $start_degrees) < $self->{min_degrees}) {
170 $self->{min_total} += $percent ;
174 if ($percent <= $self->{min_percent}) {
175 $self->{min_total} += $percent ;
179 # on totalise les % en cours
180 $self->{percent_total} += $percent ;
182 #print STDERR "percent_total = $self->{percent_total}\n" ;
184 # position dans le cercle
185 my $n = $self->{level} ; # on ajoute/retire 0.005 pour depasser un peu
188 # si c'est la premiere tranche de la nouvelle serie, il faut dessiner
191 if ($self->{degrees_complete} == 0) {
192 my ($x1, $y1) = $self->calc_xy($n-0.005, $self->{start_degrees}) ;
193 my ($x2, $y2) = $self->calc_xy($m+0.005, $self->{start_degrees}) ;
195 $gd->line($x1, $y1, $x2, $y2, $black) ;
199 my ($x3, $y3) = $self->calc_xy($n-0.005, $end_degrees) ;
201 my ($x4, $y4) = $self->calc_xy($m+0.005, $end_degrees) ;
203 # ligne de bord exterieur
204 $gd->line($x3, $y3, $x4, $y4, $black);
207 $gd->arc($self->{center_x},$self->{center_y},
208 $self->{diameter}*($self->{level}+1),
209 $self->{diameter}*($self->{level}+1),
212 $end_degrees+0.5, $black) ;
214 # on calcule le point qui est au milieu de la tranche
215 # angle = (angle nouvelle tranche)/2
217 # rayon = n*rayon - 0.5*rayon
222 my $mid_rad = ($end_degrees - $start_degrees) /2 + $start_degrees;
224 my $moy_x = ($self->{center_x}+
225 ($self->{rayon}*$m - 0.5*$self->{rayon})
226 *cos($mid_rad*$pi/180)) ;
228 my $moy_y = ($self->{center_y}+
229 ($self->{rayon}*$m - 0.5*$self->{rayon})
230 *sin($mid_rad*$pi/180)) ;
232 $gd->fillToBorder($moy_x,
237 # on prend une couleur au hasard
238 $cur_color = ($cur_color % $#color_tab) + 1 ;
240 # si le % est assez grand, on affiche le label
241 if ($percent > $self->{min_label}) {
242 push @draw_label, [$label,
246 $self->push_image_map($label, $tips, $start_degrees, $end_degrees) ;
249 # pour pourvoir ajouter des sous donnees
250 my $ret = new CCircle(start_degrees => $start_degrees,
251 parent_percent => $percent*$self->{parent_percent}/100,
253 center_x => $self->{center_x},
254 center_y => $self->{center_y},
255 min_percent => $self->{min_percent},
256 min_degrees => $self->{min_degrees},
257 base_url => $self->{base_url} . $label,
260 $self->{degrees_complete} = $end_degrees ;
262 #print STDERR "$debug : [$self->{level}] $label ($percent)\n" ;
263 #open(FP, sprintf(">/tmp/img.%.3i.png", $debug)) ;
272 # on dessine le restant < min_percent
277 $self->add_part($self->{min_total},
278 "other < $self->{min_percent}%",
285 my ($self, $title) = @_ ;
287 $gd->string(GD::gdSmallFont, $self->{center_x} - $self->{rayon}*0.7,
288 $self->{center_y}, $title, $black) ;
295 my ($self, $title, $img) = @_ ;
301 <img src='$img' border=0 usemap='#testmap' alt=''>
308 my ($self, $label, $tips, $start_degrees, $end_degrees) = @_ ;
310 if ($label =~ /^other .*</) {
311 if (!$self->{display_other}) {
317 # on prend des points tous les $delta sur l'arc interieur et exterieur
321 if (($end_degrees - $start_degrees) < $delta) {
327 for (my $i = $start_degrees ;
331 my ($x1, $y1) = $self->calc_xy($self->{level}, $i) ;
332 my ($x2, $y2) = $self->calc_xy($self->{level} + 1, $i) ;
334 push @pts, sprintf("%.2f,%.2f",$x1,$y1) ;
335 unshift @pts, sprintf("%.2f,%.2f",$x2, $y2) ;
338 my ($x1, $y1) = $self->calc_xy($self->{level}, $end_degrees) ;
339 my ($x2, $y2) = $self->calc_xy($self->{level} + 1, $end_degrees) ;
341 push @pts, sprintf("%.2f,%.2f",$x1,$y1) ;
342 unshift @pts, sprintf("%.2f,%.2f",$x2, $y2) ;
344 my $ret = join(",", @pts) ;
346 # on refait le traitement avec $i = $end_degrees
347 $_image_map .= "<area shape='polygon' coords='$ret' ".
348 "title='$tips' href='$self->{base_url}$label'>\n" ;
352 sub get_labels_imagemap
357 for my $l (@draw_label)
360 my ($label, $x, $y, $level) = @{ $l } ;
362 next if ($level > $self->{max_label_level}) ;
364 next if (!$self->{display_other} and $label =~ /^other .*</) ;
366 my $dy = ($y - $self->{center_y})*($last_level - $level) + $y ;
371 if ($x < $self->{center_x}) {
372 $x2 = $self->{center_x}
373 - $self->{rayon} * ($last_level + 3.7) ;
374 $xp = $x2 - (length($label) *6 + 2) ; # moins la taille de la police
376 $x2 = $self->{center_x} + $self->{rayon} * ($last_level + 3.7) ;
380 push @ret, $xp - 1 . ";" . $dy - 6 . ";" . $xp + length($label) * $font_size . ";" . $dy + 10 . "\n" ;
382 $gd->rectangle($xp - 1, $dy - 6,
383 $xp + length($label) * $font_size,
391 my $_label_init = 0 ;
393 # on va stocker les positions dans un bitmap $_label_pos
395 # si on match pas la position exacte, on essaye la case
396 # au dessus ou en dessous
398 # on a un bitmap pour les labels de gauche et un pour la droite
399 # $_label_pos->[0] et $_label_pos->[1]
402 my ($self, $x, $y) = @_ ;
404 unless ($_label_init) {
405 $_label_hauteur = $self->{rayon} * 2 * $last_level ;
406 # nombre max de label = hauteur max / taille de la font
407 $_label_max = $_label_hauteur / 12 ;
408 $_label_pos = [ [], [] ] ;
412 # on calcule la position du label dans le bitmap
414 my $num = $y * $_label_max / $_label_hauteur ;
417 my $n = 0 ; # nombre d'iteration
420 # on prend le bon bitmap
421 if ($x < $self->{center_x}) {
422 $l = $_label_pos->[0] ;
424 $l = $_label_pos->[1] ;
427 # on parcours le bitmap pour trouver la bonne position
428 while (($num - $n) > 0) {
429 if (not $l->[$num]) {
431 } elsif (not $l->[$num + $n]) {
434 } elsif (not $l->[$num - $n]) {
441 $l->[$num] = 1 ; # on prend la position
447 # calcul de la position
448 $y = $num * $_label_hauteur / $_label_max ;
462 for my $l (@draw_label)
465 my ($label, $x, $y, $level) = @{ $l } ;
467 next if ($level > $self->{max_label_level}) ;
469 next if (!$self->{display_other} and $label =~ /^other .*</) ;
471 my $dx = ($x - $self->{center_x})*($last_level - $level) + $x ;
472 my $dy = ($y - $self->{center_y})*($last_level - $level) + $y ;
474 $dy = $self->get_label_pos($dx, $dy) ;
476 next unless ($dy) ; # pas d'affichage si pas de place
485 if ($x < $self->{center_x}) {
486 $x2 = $self->{center_x}
487 - $self->{rayon} * ($last_level + 3.7) ;
488 $xp = $x2 - (length($label) * $font_size + 2) ; # moins la taille de la police
490 $x2 = $self->{center_x} + $self->{rayon} * ($last_level + 3.7) ;
498 $gd->string(GD::gdSmallFont, $xp, $dy - 5, $label, $black) ;
507 my $top = new CCircle() ;
509 my $chld1 = $top->add_part(50, 'test') ;
510 my $chld2 = $top->add_part(20, 'test') ;
511 my $chld3 = $top->add_part(10, 'test') ;
512 my $chld4 = $top->add_part(20, 'test') ;
515 $chld1->add_part(20, 'test1') ;
516 $chld1->add_part(20, 'test1') ;
518 $chld2->add_part(20, 'test1') ;
519 $chld2->add_part(20, 'test1') ;
521 $chld3->add_part(20, 'test1') ;
522 my $chld5 = $chld3->add_part(20, 'test1') ;
524 $chld5->add_part(50, 'test3') ;
533 $top->draw_labels() ;
534 # make sure we are writing to a binary stream
537 # Convert the image to PNG and print it on standard output
538 print $CCircle::gd->png;