3 +-------------------------------------------------------------------------+
4 | Copyright 2010-2011, Davide Franco |
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. |
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 +-------------------------------------------------------------------------+
34 function __construct( $filename = "graph.png" )
36 $this->output_file = 'templates_c/' . $filename;
39 public function SetData( $data_in, $type, $data_type, $shading = 5 )
41 $this->data = $data_in;
43 $this->data_type = $data_type;
44 $this->shadding = $shading;
47 public function SetGraphSize( $width, $height )
49 $this->width = $width;
50 $this->height = $height;
53 public function SetTitle( $title )
56 $this->title = $title;
58 die( "Please provide a non empty title for the graph" );
61 public function SetYTitle( $ytitle )
64 $this->ytitle = $ytitle;
66 die( "Please provide a non empty title for the Y axis" );
69 public function SetColors( $colors )
71 if( is_array( $colors ) )
72 $this->colors = $colors;
74 die( "Please provide a array in BGraph->SetColors()" );
77 public function Get_Image_file()
79 return $this->output_file;
82 public function Render()
85 $this->plot = new PHPlot( $this->width, $this->height );
87 // Render to file instead of screen
88 $this->plot->SetOutputFile( $this->output_file );
89 $this->plot->SetFileFormat("png");
90 $this->plot->SetIsInline( true );
93 $this->plot->SetImageBorderType('plain');
95 // Data, type and data type
96 $this->plot->SetPlotType( $this->type );
97 $this->plot->SetDataType( $this->data_type );
98 $this->plot->SetDataValues( $this->data );
101 $this->plot->SetDataColors( $this->colors );
104 $this->plot->SetShading( $this->shading );
107 $this->plot->SetImageBorderType( 'none' );
109 // Plot area (calculated regarding the width and height of the graph)
110 if( $this->type == 'pie' )
111 $this->plot->SetPlotAreaPixels( 10, 10, ($this->width / 2), $this->height-10 );
113 // Legend position (calculated regarding the width and height of the graph)
114 $this->plot->SetLegendPixels( ($this->width / 2) + 10, 25 );
116 // Labels scale position
117 if( $this->type == 'pie' )
118 $this->plot->SetLabelScalePosition( 0.2 );
121 $this->plot->SetTitle( $this->title );
122 $this->plot->SetYTitle( $this->ytitle );
124 // Setting up legends
125 if( $this->type != 'bars' ) {
127 foreach( $this->data as $key => $legend ) {
128 $this->plot->SetLegend( implode(': ',$legend) );
132 # Turn off X tick labels and ticks because they don't apply here:
133 $this->plot->SetXTickLabelPos('none');
134 $this->plot->SetXTickPos('none');
135 $this->plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
138 $this->plot->DrawGraph();
139 } // end function Render()
140 } // end BGraph classe