]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/classes/graph/bgraph.inc.php
bacula-web: Removed useless functions in bweb php classe
[bacula/bacula] / gui / bacula-web / classes / graph / bgraph.inc.php
1 <?php
2
3 class BGraph{
4         private $title;
5         
6         private $data;
7         private $data_type;
8         private $type;
9         
10         private $colors;
11         private $shading;
12         
13         private $width;
14         private $height;
15         private $output_file;
16         private $plot;
17         
18         function __construct( $filename = "graph.png" )
19         {
20                 $this->output_file = 'templates_c/' . $filename;
21         }
22         
23         public function SetData( $data_in, $type, $data_type, $shading = 5 )
24         {
25                 $this->data             = $data_in;
26                 $this->type             = $type;
27                 $this->data_type        = $data_type;
28                 $this->shadding         = $shading;
29         }
30         
31         public function SetGraphSize( $width, $height )
32         {
33                 $this->width  = $width;
34                 $this->height = $height;
35         }
36         
37         public function SetTitle( $title )
38         {
39                 if( !empty($title) )
40                         $this->title = $title;
41                 else
42                         die( "Please provide a non empty title for the graph" );
43         }
44         
45         public function SetColors( $colors )
46         {
47                 if( is_array( $colors ) )
48                         $this->colors = $colors;
49                 else
50                         die( "Please provide a array in BGraph->SetColors()" );
51         }
52         
53         public function Get_Image_file()
54         {
55                 return $this->output_file;
56         }
57         
58         public function Render()
59         {
60                 // Setting the size
61                 $this->plot = new PHPlot( $this->width, $this->height );
62                 
63                 // Render to file instead of screen
64                 $this->plot->SetOutputFile( $this->output_file );
65                 $this->plot->SetFileFormat("png");
66                 $this->plot->SetIsInline( true );
67                 
68                 
69                 $this->plot->SetImageBorderType('plain');
70
71                 // Data, type and data type
72                 $this->plot->SetPlotType( $this->type );
73                 $this->plot->SetDataType( $this->data_type );
74                 $this->plot->SetDataValues( $this->data );
75                 
76                 // Plot colors
77                 $this->plot->SetDataColors( $this->colors );
78                 
79                 // Plot shading
80                 $this->plot->SetShading( $this->shading );
81                 
82                 // Image border
83                 $this->plot->SetImageBorderType( 'none' );
84
85                 // Plot area (calculated regarding the width and height of the graph)
86                 if( $this->type == 'pie' )
87                         $this->plot->SetPlotAreaPixels( 10, 10, ($this->width / 2), $this->height-10 );
88                 
89                 // Legend position (calculated regarding the width and height of the graph)
90                 $this->plot->SetLegendPixels( ($this->width / 2) + 10, 25 );
91
92                 // Labels scale position
93                 if( $this->type == 'pie' )
94                         $this->plot->SetLabelScalePosition( 0.2 );
95                 
96                 // Graph title
97                 $this->plot->SetTitle( $this->title );
98
99                 // Setting up legends
100                 if( $this->type != 'bars' ) {
101                         $legends = array();
102                         foreach( $this->data as $key => $legend ) {
103                                 $this->plot->SetLegend( implode(': ',$legend) );
104                         }
105                 }
106
107                 # Turn off X tick labels and ticks because they don't apply here:
108                 $this->plot->SetXTickLabelPos('none');
109                 $this->plot->SetXTickPos('none');
110                 $this->plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
111
112
113                 $this->plot->DrawGraph();
114         } // end function Render()
115 } // end BGraph classe
116
117 ?>