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 +-------------------------------------------------------------------------+
33 function __construct( $filename = "graph.png" )
35 $this->output_file = 'templates_c/' . $filename;
38 public function SetData( $data_in, $type, $data_type, $shading = 5 )
40 $this->data = $data_in;
42 $this->data_type = $data_type;
43 $this->shadding = $shading;
46 public function SetGraphSize( $width, $height )
48 $this->width = $width;
49 $this->height = $height;
52 public function SetTitle( $title )
55 $this->title = $title;
57 die( "Please provide a non empty title for the graph" );
60 public function SetColors( $colors )
62 if( is_array( $colors ) )
63 $this->colors = $colors;
65 die( "Please provide a array in BGraph->SetColors()" );
68 public function Get_Image_file()
70 return $this->output_file;
73 public function Render()
76 $this->plot = new PHPlot( $this->width, $this->height );
78 // Render to file instead of screen
79 $this->plot->SetOutputFile( $this->output_file );
80 $this->plot->SetFileFormat("png");
81 $this->plot->SetIsInline( true );
84 $this->plot->SetImageBorderType('plain');
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 );
92 $this->plot->SetDataColors( $this->colors );
95 $this->plot->SetShading( $this->shading );
98 $this->plot->SetImageBorderType( 'none' );
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 );
104 // Legend position (calculated regarding the width and height of the graph)
105 $this->plot->SetLegendPixels( ($this->width / 2) + 10, 25 );
107 // Labels scale position
108 if( $this->type == 'pie' )
109 $this->plot->SetLabelScalePosition( 0.2 );
112 $this->plot->SetTitle( $this->title );
114 // Setting up legends
115 if( $this->type != 'bars' ) {
117 foreach( $this->data as $key => $legend ) {
118 $this->plot->SetLegend( implode(': ',$legend) );
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);
128 $this->plot->DrawGraph();
129 } // end function Render()
130 } // end BGraph classe