[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (c) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (c) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: graph.class.php,v 1.15 2005/09/02 21:39:10 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/graph.class.php,v $ 21 */ 22 23 /** 24 \file htdocs/graph.class.php 25 \brief Fichier de la classe mère de gestion des graph phplot 26 \version $Revision: 1.15 $ 27 */ 28 29 include_once (DOL_DOCUMENT_ROOT."/includes/phplot/phplot.php"); 30 31 32 /** 33 \class Graph 34 \brief Classe mère permettant la gestion des graph phplot 35 */ 36 37 class Graph 38 { 39 var $db; 40 var $errorstr; 41 42 var $graph; // Objet PHPlot 43 44 45 /** 46 * \brief Génère le fichier graphique sur le disque 47 * \param file Nom du fichier image 48 */ 49 function draw($file) 50 { 51 // Prepare parametres 52 $this->prepare($file); 53 54 // Génère le fichier $file 55 $this->graph->DrawGraph(); 56 } 57 58 /** 59 * \brief Prépare l'objet PHPlot 60 * \param file Nom du fichier image à générer 61 */ 62 function prepare($file) 63 { 64 // Define the object 65 $this->graph = new PHPlot($this->width, $this->height); 66 $this->graph->SetIsInline(1); 67 68 $this->graph->SetPlotType( $this->PlotType ); 69 70 //Set some data 71 $this->graph->SetDataValues($this->data); 72 73 if (isset($this->MaxValue)) 74 { 75 $nts = array(); 76 $this->MaxValue = $this->MaxValue + 1; 77 $max = $this->MaxValue; 78 if (($max % 2) <> 0) 79 { 80 $this->MaxValue = $this->MaxValue + 1; 81 $max++; 82 } 83 84 $this->graph->SetPlotAreaWorld(0,0,12,$this->MaxValue); 85 86 $j = 0; 87 for ($i = 1 ; $i < 11 ; $i++) 88 { 89 $res = $max % $i; 90 $cal = $max / $i; 91 92 if ($res == 0 && $cal <= 11) 93 { 94 $nts[$j] = $cal; 95 $j++; 96 } 97 98 } 99 rsort($nts); 100 101 $this->graph->SetNumVertTicks($nts[0]); 102 } 103 else 104 { 105 $this->graph->SetPlotAreaPixels(60, 10, $this->width-10, $this->height - 30) ; 106 } 107 108 $this->graph->SetBackgroundColor($this->bgcolor); 109 $this->graph->SetDataColors($this->datacolor, $this->bordercolor); 110 111 // Define title 112 if (strlen($this->title)) $this->graph->SetTitle($this->title); 113 114 // TODO 115 //$this->graph->SetPrecisionY($this->precision_Y); 116 // $this->graph->SetVertTickIncrement(0); 117 // $this->graph->SetSkipBottomTick(1); 118 119 $this->graph->SetVertTickPosition('plotleft'); 120 121 $this->graph->SetYGridLabelType("data"); 122 123 $this->graph->SetDrawYGrid(1); 124 125 // Affiche les valeurs 126 //$this->graph->SetDrawDataLabels('1'); 127 //$this->graph->SetLabelScalePosition('1'); 128 129 $this->graph->SetOutputFile($file); 130 131 // Défini position du graphe (et legende) au sein de l'image 132 if (isset($this->Legend)) 133 { 134 $this->graph->SetMarginsPixels(100,100,10,30); 135 136 $this->graph->SetLegend($this->Legend); 137 $this->graph->SetLegendWorld(13,$this->MaxValue); 138 } 139 else 140 { 141 $this->graph->SetMarginsPixels(100,10,10,30); 142 } 143 144 if (substr($this->MaxValue,0,1) == 1) 145 { 146 $this->graph->SetNumVertTicks(10); 147 } 148 elseif (substr($this->MaxValue,0,1) == 2) 149 { 150 $this->graph->SetNumVertTicks(4); 151 } 152 elseif (substr($this->MaxValue,0,1) == 3) 153 { 154 $this->graph->SetNumVertTicks(6); 155 } 156 elseif (substr($this->MaxValue,0,1) == 4) 157 { 158 $this->graph->SetNumVertTicks(8); 159 } 160 else 161 { 162 $this->graph->SetNumVertTicks(substr($this->MaxValue,0,1)); 163 } 164 165 } 166 167 function SetPrecisionY($which_prec) 168 { 169 $this->precision_y = $which_prec; 170 return true; 171 } 172 173 function SetYLabel($label) 174 { 175 $this->YLabel = $label; 176 } 177 178 function SetWidth($w) 179 { 180 $this->width = $w; 181 } 182 183 function SetTitle($title) 184 { 185 $this->title = $title; 186 } 187 188 function SetData($data) 189 { 190 $this->data = $data; 191 } 192 193 function SetLegend($legend) 194 { 195 $this->Legend = $legend; 196 } 197 198 function SetMaxValue($max) 199 { 200 $this->MaxValue = $max; 201 } 202 203 function SetHeight($h) 204 { 205 $this->height = $h; 206 } 207 208 function ResetBgColor() 209 { 210 unset($this->bgcolor); 211 } 212 213 function SetBgColor($bg_color = array(255,255,255)) 214 { 215 $this->bgcolor = $bg_color; 216 } 217 218 function ResetDataColor() 219 { 220 unset($this->datacolor); 221 } 222 223 function GetMaxValue() 224 { 225 $k = 0; 226 $vals = array(); 227 228 $nblines = sizeof($this->data); 229 $nbvalues = sizeof($this->data[0]) - 1; 230 231 for ($j = 0 ; $j < $nblines ; $j++) 232 { 233 for ($i = 0 ; $i < $nbvalues ; $i++) 234 { 235 $vals[$k] = $this->data[$j][$i+1]; 236 $k++; 237 } 238 } 239 rsort($vals); 240 return $vals[0]; 241 } 242 243 function GetAmountMaxValue() 244 { 245 246 $max = ceil($this->GetMaxValue()); 247 $size = strlen("$max"); 248 if (substr($max,0,1) == 9) 249 { 250 $res = 1; 251 } 252 else 253 { 254 $size = $size - 1; 255 $res = substr($max,0,1) + 1; 256 } 257 258 for ($i = 0 ; $i < $size ; $i++) 259 { 260 $res .= "0"; 261 } 262 263 return ($res - 2); 264 } 265 266 } 267 268 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |