]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/includes/graph/bgraph.class.php
bacula-web: Replaced Get_human_file_size() function by Utils::Get_Human_Size
[bacula/bacula] / gui / bacula-web / includes / graph / bgraph.class.php
1 <?php
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright 2010-2011, Davide Franco                                              |
5 |                                                                         |
6 | This program is free software; you can redistribute it and/or           |
7 | modify it under the terms of the GNU General Public License             |
8 | as published by the Free Software Foundation; either version 2          |
9 | of the License, or (at your option) any later version.                  |
10 |                                                                         |
11 | This program is distributed in the hope that it will be useful,         |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
14 | GNU General Public License for more details.                            |
15 +-------------------------------------------------------------------------+ 
16 */
17
18 class BGraph{
19         private $title;
20         
21         private $data;
22         private $data_type;
23         private $type;
24         
25         private $colors;
26         private $shading;
27         
28         private $width;
29         private $height;
30         private $output_file;
31         private $plot;
32         
33         function __construct( $filename = "graph.png" )
34         {
35                 $this->output_file = 'templates_c/' . $filename;
36         }
37         
38         public function SetData( $data_in, $type, $data_type, $shading = 5 )
39         {
40                 $this->data             = $data_in;
41                 $this->type             = $type;
42                 $this->data_type        = $data_type;
43                 $this->shadding         = $shading;
44         }
45         
46         public function SetGraphSize( $width, $height )
47         {
48                 $this->width  = $width;
49                 $this->height = $height;
50         }
51         
52         public function SetTitle( $title )
53         {
54                 if( !empty($title) )
55                         $this->title = $title;
56                 else
57                         die( "Please provide a non empty title for the graph" );
58         }
59         
60         public function SetColors( $colors )
61         {
62                 if( is_array( $colors ) )
63                         $this->colors = $colors;
64                 else
65                         die( "Please provide a array in BGraph->SetColors()" );
66         }
67         
68         public function Get_Image_file()
69         {
70                 return $this->output_file;
71         }
72         
73         public function Render()
74         {
75                 // Setting the size
76                 $this->plot = new PHPlot( $this->width, $this->height );
77                 
78                 // Render to file instead of screen
79                 $this->plot->SetOutputFile( $this->output_file );
80                 $this->plot->SetFileFormat("png");
81                 $this->plot->SetIsInline( true );
82                 
83                 
84                 $this->plot->SetImageBorderType('plain');
85
86                 // Data, type and data type
87                 $this->plot->SetPlotType( $this->type );
88                 $this->plot->SetDataType( $this->data_type );
89                 $this->plot->SetDataValues( $this->data );
90                 
91                 // Plot colors
92                 $this->plot->SetDataColors( $this->colors );
93                 
94                 // Plot shading
95                 $this->plot->SetShading( $this->shading );
96                 
97                 // Image border
98                 $this->plot->SetImageBorderType( 'none' );
99
100                 // Plot area (calculated regarding the width and height of the graph)
101                 if( $this->type == 'pie' )
102                         $this->plot->SetPlotAreaPixels( 10, 10, ($this->width / 2), $this->height-10 );
103                 
104                 // Legend position (calculated regarding the width and height of the graph)
105                 $this->plot->SetLegendPixels( ($this->width / 2) + 10, 25 );
106
107                 // Labels scale position
108                 if( $this->type == 'pie' )
109                         $this->plot->SetLabelScalePosition( 0.2 );
110                 
111                 // Graph title
112                 $this->plot->SetTitle( $this->title );
113
114                 // Setting up legends
115                 if( $this->type != 'bars' ) {
116                         $legends = array();
117                         foreach( $this->data as $key => $legend ) {
118                                 $this->plot->SetLegend( implode(': ',$legend) );
119                         }
120                 }
121
122                 # Turn off X tick labels and ticks because they don't apply here:
123                 $this->plot->SetXTickLabelPos('none');
124                 $this->plot->SetXTickPos('none');
125                 $this->plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
126
127
128                 $this->plot->DrawGraph();
129         } // end function Render()
130 } // end BGraph classe
131
132 ?>