[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* 3 Copyright (C) 1998, 1999, 2000, 2001 Afan Ottenheimer. Released under 4 the GPL and PHP licenses as stated in the the README file which 5 should have been included with this document. 6 7 World Coordinates are the XY coordinates relative to the 8 axis origin that can be drawn. Not the device (pixel) coordinates 9 which in GD is relative to the origin at the upper left 10 side of the image. 11 */ 12 13 //PHPLOT Version 4.4.6 14 //Requires PHP 3.0.2 or later 15 16 17 class PHPlot{ 18 19 var $is_inline = 0; //0 = Sends headers, 1 = sends just raw image data 20 var $browser_cache = '1'; // 0 = Sends headers for browser to not cache the image, (i.e. 0 = don't let browser cache image) 21 // (only if is_inline = 0 also) 22 var $session_set = ''; //Do not change 23 var $scale_is_set = ''; //Do not change 24 var $draw_plot_area_background = ''; 25 26 var $image_width; //Total Width in Pixels 27 var $image_height; //Total Height in Pixels 28 var $image_border_type = ''; //raised, plain, '' 29 var $x_left_margin; 30 var $y_top_margin; 31 var $x_right_margin; 32 var $y_bot_margin; 33 var $plot_area = array(5,5,600,400); 34 var $x_axis_position = 0; //Where to draw the X_axis (world coordinates) 35 var $y_axis_position = ''; //Leave blank for Y axis at left of plot. (world coord.) 36 var $xscale_type = 'linear'; //linear or log 37 var $yscale_type = 'linear'; 38 39 //Use for multiple plots per image 40 var $print_image = 1; //Used for multiple charts per image. 41 42 //Fonts 43 var $use_ttf = 0; //Use TTF fonts (1) or not (0) 44 var $font_path = './'; //To be added 45 var $font = './benjamingothic.ttf'; 46 47 ///////////Fonts: Small/Generic 48 var $small_ttffont_size = 12; // 49 //non-ttf 50 var $small_font = 2; // fonts = 1,2,3,4 or 5 51 var $small_font_width = 6.0; // width in pixels (2=6,3=8,4=8) 52 var $small_font_height = 8.0; // height in pixels (2=8,3=10,4=12) 53 54 ////////// Fonts:Title 55 var $title_ttffont = './benjamingothic.ttf'; 56 var $title_ttffont_size = 14; 57 var $title_angle= 0; 58 //non-ttf 59 var $title_font = '4'; // fonts = 1,2,3,4,5 60 61 ////////////// Fonts:Axis 62 var $axis_ttffont = './benjamingothic.ttf'; 63 var $axis_ttffont_size = 8; 64 var $x_datalabel_angle = 0; 65 //non-ttf 66 var $axis_font = 2; 67 68 ////////////////Fonts:Labels of Data 69 var $datalabel_font = '2'; 70 71 //////////////// Fonts:Labels (Axis Titles) 72 var $x_label_ttffont = './benjamingothic.ttf'; 73 var $x_label_ttffont_size = '12'; 74 var $x_label_angle = '0'; 75 76 var $y_label_ttffont = './benjamingothic.ttf'; 77 var $y_label_ttffont_size = '12'; 78 var $y_label_angle = 90; 79 var $y_label_width = ''; 80 81 //Formats 82 var $file_format = 'png'; 83 var $file_name = ''; //For output to a file instead of stdout 84 85 //Plot Colors 86 var $shading = 0; 87 var $color_array = 1; //1 = include small list 88 //2 = include large list 89 //array = define your own color translation. See rgb.inc.php and SetRGBArray 90 var $bg_color; 91 var $plot_bg_color; 92 var $grid_color; 93 var $light_grid_color; 94 var $tick_color; 95 var $title_color; 96 var $label_color; 97 var $text_color; 98 var $i_light = ''; 99 100 //Data 101 var $data_type = 'text-data'; //text-data, data-data-error, data-data 102 var $plot_type= 'linepoints'; //bars, lines, linepoints, area, points, pie, thinbarline 103 var $line_width = 2; 104 var $line_style = array('solid','solid','solid','dashed','dashed','solid'); //Solid or dashed lines 105 106 var $data_color = ''; //array('blue','green','yellow',array(0,0,0)); 107 var $data_border_color = ''; 108 109 var $label_scale_position = '.5'; //1 = top, 0 = bottom 110 var $group_frac_width = '.7'; //value from 0 to 1 = width of bar 111 var $bar_width_adjust = '1'; //1 = bars of normal width, must be > 0 112 113 var $point_size = 10; 114 var $point_shape = 'diamond'; //rect,circle,diamond,triangle,dot,line,halfline 115 var $error_bar_shape = 'tee'; //tee, line 116 var $error_bar_size = 5; //right left size of tee 117 var $error_bar_line_width = ''; //If set then use it, else use $line_width for thickness 118 var $error_bar_color = ''; 119 var $data_values; 120 121 var $plot_border_type = 'full'; //left, none, full 122 var $plot_area_width = ''; 123 var $number_x_points; 124 var $plot_min_x; // Max and min of the plot area 125 var $plot_max_x= ''; // Max and min of the plot area 126 var $plot_min_y= ''; // Max and min of the plot area 127 var $plot_max_y = ''; // Max and min of the plot area 128 var $min_y = ''; 129 var $max_y = ''; 130 var $max_x = 10; //Must not be = 0; 131 var $y_precision = '1'; 132 var $x_precision = '1'; 133 var $si_units = ''; 134 135 //Labels 136 var $draw_data_labels = '0'; 137 var $legend = ''; //an array 138 var $legend_x_pos = ''; 139 var $legend_y_pos = ''; 140 var $title_txt = ""; 141 var $y_label_txt = ''; 142 var $x_label_txt = ""; 143 144 //DataAxis Labels (on each axis) 145 var $y_grid_label_type = 'data'; //data, none, time, other 146 var $y_grid_label_pos = 'plotleft'; //plotleft, plotright, yaxis, both 147 var $x_grid_label_type = 'data'; //data, title, none, time, other 148 var $draw_x_data_labels = ''; // 0=false, 1=true, ""=let program decide 149 var $x_time_format = "%H:%m:%s"; //See http://www.php.net/manual/html/function.strftime.html 150 var $x_datalabel_maxlength = 10; 151 152 //Tick Formatting 153 var $tick_length = '10'; //pixels: tick length from axis left/downward 154 //tick_length2 to be implemented 155 //var $tick_length2 = ''; //pixels: tick length from axis line rightward/upward 156 var $draw_vert_ticks = 1; //1 = draw ticks, 0 = don't draw ticks 157 var $num_vert_ticks = ''; 158 var $vert_tick_increment=''; //Set num_vert_ticks or vert_tick_increment, not both. 159 var $vert_tick_position = 'both'; //plotright=(right of plot only), plotleft=(left of plot only), 160 //both = (both left and right of plot), yaxis=(crosses y axis) 161 var $horiz_tick_increment=''; //Set num_horiz_ticks or horiz_tick_increment, not both. 162 var $num_horiz_ticks=''; 163 var $skip_top_tick = '0'; 164 var $skip_bottom_tick = '0'; 165 166 //Grid Formatting 167 var $draw_x_grid = 0; 168 var $draw_y_grid = 1; 169 170 171 //BEGIN CODE 172 ////////////////////////////////////////////////////// 173 //Constructor: Setup Img pointer, Colors and Size of Image 174 function PHPlot($which_width=600,$which_height=400,$which_output_file="",$which_input_file="") { 175 176 $this->SetRGBArray('2'); 177 $this->background_done = 0; //Set to 1 after background image first drawn 178 179 if ($which_output_file != "") { $this->SetOutputFile($which_output_file); }; 180 181 if ($which_input_file != "") { 182 $this->SetInputFile($which_input_file) ; 183 } else { 184 $this->SetImageArea($which_width, $which_height); 185 $this->InitImage(); 186 } 187 188 if ( ($this->session_set == 1) && ($this->img == "") ) { //For sessions 189 //Do nothing 190 } else { 191 $this->SetDefaultColors(); 192 } 193 194 $this->SetIndexColors(); 195 196 } 197 198 //Set up the image and colors 199 function InitImage() { 200 //if ($this->img) { 201 // ImageDestroy($this->img); 202 //} 203 $this->img = ImageCreate($this->image_width, $this->image_height); 204 return true; 205 } 206 207 function SetBrowserCache($which_browser_cache) { //Submitted by Thiemo Nagel 208 $this->browser_cache = $which_browser_cache; 209 return true; 210 } 211 212 function SetPrintImage($which_pi) { 213 $this->print_image = $which_pi; 214 return true; 215 } 216 217 function SetIsInline($which_ii) { 218 $this->is_inline = $which_ii; 219 return true; 220 } 221 222 function SetUseTTF($which_ttf) { 223 $this->use_ttf = $which_ttf; 224 return true; 225 } 226 227 function SetTitleFontSize($which_tfs) { 228 //TTF 229 $this->title_ttffont_size = $which_tfs; //pt size 230 231 //Non-TTF settings 232 if (($which_tfs > 5) && (!$this->use_ttf)) { 233 $this->DrawError('Non-TTF font size must be 1,2,3,4 or 5'); 234 return false; 235 } else { 236 $this->title_font = $which_tfs; 237 //$this->title_font_height = ImageFontHeight($which_tfs) // height in pixels 238 //$this->title_font_width = ImageFontWidth($which_tfs); // width in pixels 239 } 240 return true; 241 } 242 243 function SetLineStyles($which_sls){ 244 $this->line_style = $which_sls; 245 return true; 246 } 247 248 function SetLegend($which_leg){ 249 if (is_array($which_leg)) { 250 $this->legend = $which_leg; 251 return true; 252 } else { 253 $this->DrawError('Error: SetLegend argument must be an array'); 254 return false; 255 } 256 } 257 258 function SetLegendPixels($which_x,$which_y,$which_type) { 259 //which_type not yet used 260 $this->legend_x_pos = $which_x; 261 $this->legend_y_pos = $which_y; 262 return true; 263 } 264 265 function SetLegendWorld($which_x,$which_y,$which_type='') { 266 //which_type not yet used 267 //Must be called after scales are set up. 268 if ($this->scale_is_set != 1) { $this->SetTranslation(); }; 269 $this->legend_x_pos = $this->xtr($which_x); 270 $this->legend_y_pos = $this->ytr($which_y); 271 return true; 272 } 273 274 function SetFileFormat($which_file_format) { 275 //eventually test to see if that is supported - if not then return false 276 $asked = strtolower(trim($which_file_format)); 277 if( ($asked=='jpg') || ($asked=='png') || ($asked=='gif') || ($asked=='wbmp') ) { 278 $this->file_format = $asked; 279 return true; 280 } else { 281 return false; 282 } 283 } 284 285 function SetInputFile($which_input_file) { 286 //$this->SetFileFormat($which_frmt); 287 $size = GetImageSize($which_input_file); 288 $input_type = $size[2]; 289 290 switch($input_type) { //After SetFileFormat is in lower case 291 case "1": 292 $im = @ImageCreateFromGIF ($which_input_file); 293 if (!$im) { // See if it failed 294 $this->PrintError("Unable to open $which_input_file as a GIF"); 295 return false; 296 } 297 break; 298 case "3": 299 $im = @ImageCreateFromPNG ($which_input_file); 300 if (!$im) { // See if it failed 301 $this->PrintError("Unable to open $which_input_file as a PNG"); 302 return false; 303 } 304 break; 305 case "2": 306 $im = @ImageCreateFromJPEG ($which_input_file); 307 if (!$im) { // See if it failed 308 $this->PrintError("Unable to open $which_input_file as a JPG"); 309 return false; 310 } 311 break; 312 default: 313 $this->PrintError('Please select wbmp,gif,jpg, or png for image type!'); 314 return false; 315 break; 316 } 317 318 //Get Width and Height of Image 319 $this->SetImageArea($size[0],$size[1]); 320 321 $this->img = $im; 322 323 return true; 324 325 } 326 327 function SetOutputFile($which_output_file) { 328 $this->output_file = $which_output_file; 329 return true; 330 } 331 332 function SetImageArea($which_iw,$which_ih) { 333 //Note this is now an Internal function - please set w/h via PHPlot() 334 $this->image_width = $which_iw; 335 $this->image_height = $which_ih; 336 337 return true; 338 } 339 340 341 function SetYAxisPosition($which_pos) { 342 $this->y_axis_position = $which_pos; 343 return true; 344 } 345 function SetXAxisPosition($which_pos) { 346 $this->x_axis_position = $which_pos; 347 return true; 348 } 349 function SetXTimeFormat($which_xtf) { 350 $this->x_time_format = $which_xtf; 351 return true; 352 } 353 function SetXDataLabelMaxlength($which_xdlm) { 354 if ($which_xdlm >0 ) { 355 $this->x_datalabel_maxlength = $which_xdlm; 356 return true; 357 } else { 358 return false; 359 } 360 } 361 function SetXDataLabelAngle($which_xdla) { 362 $this->x_datalabel_angle = $which_xdla; 363 return true; 364 } 365 function SetXScaleType($which_xst) { 366 $this->xscale_type = $which_xst; 367 return true; 368 } 369 function SetYScaleType($which_yst) { 370 $this->yscale_type = $which_yst; 371 if ($this->x_axis_position <= 0) { 372 $this->x_axis_position = 1; 373 } 374 return true; 375 } 376 377 function SetPrecisionX($which_prec) { 378 $this->x_precision = $which_prec; 379 return true; 380 } 381 function SetPrecisionY($which_prec) { 382 $this->y_precision = $which_prec; 383 return true; 384 } 385 386 387 function SetIndexColors() { //Internal Method called to set colors and preserve state 388 //These are the colors of the image that are used. They are initialized 389 //to work with sessions and PHP. 390 391 $this->ndx_i_light = $this->SetIndexColor($this->i_light); 392 $this->ndx_i_dark = $this->SetIndexColor($this->i_dark); 393 $this->ndx_bg_color= $this->SetIndexColor($this->bg_color); 394 $this->ndx_plot_bg_color= $this->SetIndexColor($this->plot_bg_color); 395 396 $this->ndx_title_color= $this->SetIndexColor($this->title_color); 397 $this->ndx_tick_color= $this->SetIndexColor($this->tick_color); 398 $this->ndx_label_color= $this->SetIndexColor($this->label_color); 399 $this->ndx_text_color= $this->SetIndexColor($this->text_color); 400 $this->ndx_light_grid_color= $this->SetIndexColor($this->light_grid_color); 401 $this->ndx_grid_color= $this->SetIndexColor($this->grid_color); 402 403 reset($this->error_bar_color); 404 unset($ndx_error_bar_color); 405 $i = 0; 406 while (list(, $col) = each($this->error_bar_color)) { 407 $this->ndx_error_bar_color[$i] = $this->SetIndexColor($col); 408 $i++; 409 } 410 //reset($this->data_border_color); 411 unset($ndx_data_border_color); 412 $i = 0; 413 while (list(, $col) = each($this->data_border_color)) { 414 $this->ndx_data_border_color[$i] = $this->SetIndexColor($col); 415 $i++; 416 } 417 //reset($this->data_color); 418 unset($ndx_data_color); 419 $i = 0; 420 while (list(, $col) = each($this->data_color)) { 421 $this->ndx_data_color[$i] = $this->SetIndexColor($col); 422 $i++; 423 } 424 425 return true; 426 } 427 428 429 function SetDefaultColors() { 430 431 $this->i_light = array(194,194,194); 432 $this->i_dark = array(100,100,100); 433 $this->SetPlotBgColor(array(222,222,222)); 434 $this->SetBackgroundColor(array(200,222,222)); //can use rgb values or "name" values 435 $this->SetLabelColor('black'); 436 $this->SetTextColor('black'); 437 $this->SetGridColor('black'); 438 $this->SetLightGridColor(array(175,175,175)); 439 $this->SetTickColor('black'); 440 $this->SetTitleColor(array(0,0,0)); // Can be array or name 441 $this->data_color = array('blue','green','yellow','red','orange'); 442 $this->error_bar_color = array('blue','green','yellow','red','orange'); 443 $this->data_border_color = array('black'); 444 445 $this->session_set = 1; //Mark it down for PHP session() usage. 446 } 447 448 function PrintImage() { 449 450 if ( ($this->browser_cache == 0) && ($this->is_inline == 0)) { //Submitted by Thiemo Nagel 451 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 452 header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT'); 453 header('Cache-Control: no-cache, must-revalidate'); 454 header('Pragma: no-cache'); 455 } 456 457 switch($this->file_format) { 458 case "png": 459 if ($this->is_inline == 0) { 460 Header('Content-type: image/png'); 461 } 462 if ($this->is_inline == 1 && $this->output_file != "") { 463 ImagePng($this->img,$this->output_file); 464 } else { 465 ImagePng($this->img); 466 } 467 break; 468 case "jpg": 469 if ($this->is_inline == 0) { 470 Header('Content-type: image/jpeg'); 471 } 472 if ($this->is_inline == 1 && $this->output_file != "") { 473 ImageJPEG($this->img,$this->output_file); 474 } else { 475 ImageJPEG($this->img); 476 } 477 break; 478 case "gif": 479 if ($this->is_inline == 0) { 480 Header('Content-type: image/gif'); 481 } 482 if ($this->is_inline == 1 && $this->output_file != "") { 483 ImageGIF($this->img,$this->output_file); 484 } else { 485 ImageGIF($this->img); 486 } 487 488 break; 489 case "wbmp": 490 if ($this->is_inline == 0) { 491 Header('Content-type: image/wbmp'); 492 } 493 if ($this->is_inline == 1 && $this->output_file != "") { 494 ImageWBMP($this->img,$this->output_file); 495 } else { 496 ImageWBMP($this->img); 497 } 498 499 break; 500 default: 501 $this->PrintError('Please select an image type!<br>'); 502 break; 503 } 504 ImageDestroy($this->img); 505 return true; 506 } 507 508 509 function DrawBackground() { 510 //if ($this->img == "") { $this->InitImage(); }; 511 if ($this->background_done == 0) { //Don't draw it twice if drawing two plots on one image 512 ImageFilledRectangle($this->img, 0, 0, 513 $this->image_width, $this->image_height, $this->ndx_bg_color); 514 $this->background_done = 1; 515 } 516 return true; 517 } 518 519 function DrawImageBorder() { 520 switch ($this->image_border_type) { 521 case "raised": 522 ImageLine($this->img,0,0,$this->image_width-1,0,$this->ndx_i_light); 523 ImageLine($this->img,1,1,$this->image_width-2,1,$this->ndx_i_light); 524 ImageLine($this->img,0,0,0,$this->image_height-1,$this->ndx_i_light); 525 ImageLine($this->img,1,1,1,$this->image_height-2,$this->ndx_i_light); 526 ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark); 527 ImageLine($this->img,0,$this->image_height-1,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark); 528 ImageLine($this->img,$this->image_width-2,1,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark); 529 ImageLine($this->img,1,$this->image_height-2,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark); 530 break; 531 case "plain": 532 ImageLine($this->img,0,0,$this->image_width,0,$this->ndx_i_dark); 533 ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height,$this->ndx_i_dark); 534 ImageLine($this->img,$this->image_width-1,$this->image_height-1,0,$this->image_height-1,$this->ndx_i_dark); 535 ImageLine($this->img,0,0,0,$this->image_height,$this->ndx_i_dark); 536 break; 537 default: 538 break; 539 } 540 return true; 541 } 542 543 function SetPlotBorderType($which_pbt) { 544 $this->plot_border_type = $which_pbt; //left, none, anything else=full 545 } 546 547 function SetImageBorderType($which_sibt) { 548 $this->image_border_type = $which_sibt; //raised, plain 549 } 550 551 function SetDrawPlotAreaBackground($which_dpab) { 552 $this->draw_plot_area_background = $which_dpab; // 1=true or anything else=false 553 } 554 555 function SetDrawDataLabels($which_ddl) { //Draw next to datapoints 556 $this->draw_data_labels = $which_ddl; // 1=true or anything else=false 557 } 558 559 function SetDrawXDataLabels($which_dxdl) { //Draw on X Axis 560 $this->draw_x_data_labels = $which_dxdl; // 1=true or anything else=false 561 } 562 563 function SetDrawYGrid($which_dyg) { 564 $this->draw_y_grid = $which_dyg; // 1=true or anything else=false 565 } 566 567 function SetDrawXGrid($which_dxg) { 568 $this->draw_x_grid = $which_dxg; // 1=true or anything else=false 569 } 570 571 function SetYGridLabelType($which_yglt) { 572 $this->y_grid_label_type = $which_yglt; 573 return true; 574 } 575 576 function SetXGridLabelType($which_xglt) { 577 $this->x_grid_label_type = $which_xglt; 578 return true; 579 } 580 581 function SetXLabel($xlbl) { 582 $this->x_label_txt = $xlbl; 583 return true; 584 } 585 function SetYLabel($ylbl) { 586 $this->y_label_txt = $ylbl; 587 return true; 588 } 589 function SetTitle($title) { 590 $this->title_txt = $title; 591 return true; 592 } 593 function DrawLabels() { 594 $this->DrawTitle(); 595 $this->DrawXLabel(); 596 $this->DrawYLabel(); 597 return true; 598 } 599 600 function DrawXLabel() { 601 if ($this->use_ttf == 1) { 602 $xpos = $this->xtr(($this->plot_max_x + $this->plot_min_x)/2.0) ; 603 $ypos = $this->ytr($this->plot_min_y) + $this->x_label_height/2.0; 604 $this->DrawText($this->x_label_ttffont, $this->x_label_angle, 605 $xpos, $ypos, $this->ndx_label_color, $this->x_label_ttffont_size, $this->x_label_txt,'center'); 606 } else { 607 608 $xpos = 0.0 + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ; 609 $ypos = ($this->ytr($this->plot_min_y) + $this->x_label_height/2); 610 611 $this->DrawText($this->small_font, $this->x_label_angle, 612 $xpos, $ypos, $this->ndx_label_color, "", $this->x_label_txt, 'center'); 613 614 } 615 return true; 616 } 617 618 function DrawYLabel() { 619 if ($this->use_ttf == 1) { 620 $size = $this->TTFBBoxSize($this->y_label_ttffont_size, 90, $this->y_label_ttffont, $this->y_label_txt); 621 $xpos = 8 + $size[0]; 622 $ypos = ($size[1])/2 + $this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) ; 623 $this->DrawText($this->y_label_ttffont, 90, 624 $xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt); 625 } else { 626 $xpos = 8; 627 $ypos = (($this->small_font_width*strlen($this->y_label_txt)/2.0) + 628 $this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) ); 629 $this->DrawText($this->small_font, 90, 630 $xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt); 631 } 632 return true; 633 } 634 635 function DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left',$which_valign='') { 636 637 if ($this->use_ttf == 1 ) { 638 $size = $this->TTFBBoxSize($which_size, $which_angle, $which_font, $which_text); 639 if ($which_valign == 'bottom') { 640 $which_ypos = $which_ypos + ImageFontHeight($which_font); 641 } 642 if ($which_halign == 'center') { 643 $which_xpos = $which_xpos - $size[0]/2; 644 } 645 ImageTTFText($this->img, $which_size, $which_angle, 646 $which_xpos, $which_ypos, $which_color, $which_font, $which_text); 647 } else { 648 if ($which_valign == 'top') { 649 $which_ypos = $which_ypos - ImageFontHeight($which_font); 650 } 651 $which_text = ereg_replace("\r","",$which_text); 652 $str = split("\n",$which_text); //multiple lines submitted by Remi Ricard 653 $height = ImageFontHeight($which_font); 654 $width = ImageFontWidth($which_font); 655 if ($which_angle == 90) { //Vertical Code Submitted by Marlin Viss 656 for($i=0;$i<count($str);$i++) { 657 ImageStringUp($this->img, $which_font, ($i*$height + $which_xpos), $which_ypos, $str[$i], $which_color); 658 } 659 } else { 660 for($i=0;$i<count($str);$i++) { 661 if ($which_halign == 'center') { 662 $xpos = $which_xpos - strlen($str[$i]) * $width/2; 663 ImageString($this->img, $which_font, $xpos, ($i*$height + $which_ypos), $str[$i], $which_color); 664 } else { 665 ImageString($this->img, $which_font, $which_xpos, ($i*$height + $which_ypos), $str[$i], $which_color); 666 } 667 } 668 } 669 670 } 671 return true; 672 673 } 674 function DrawTitle() { 675 if ($this->use_ttf == 1 ) { 676 $xpos = ($this->plot_area[0] + $this->plot_area_width / 2); 677 $ypos = $this->y_top_margin/2; 678 $this->DrawText($this->title_ttffont, $this->title_angle, 679 $xpos, $ypos, $this->ndx_title_color, $this->title_ttffont_size, $this->title_txt,'center'); 680 } else { 681 $xpos = ($this->plot_area[0] + $this->plot_area_width / 2); 682 $ypos = ImageFontHeight($this->title_font); 683 $this->DrawText($this->title_font, $this->title_angle, 684 $xpos, $ypos, $this->ndx_title_color, '', $this->title_txt,'center'); 685 } 686 return true; 687 688 } 689 690 function DrawPlotAreaBackground() { 691 ImageFilledRectangle($this->img,$this->plot_area[0], 692 $this->plot_area[1],$this->plot_area[2],$this->plot_area[3], 693 $this->ndx_plot_bg_color); 694 } 695 696 function SetBackgroundColor($which_color) { 697 $this->bg_color= $which_color; 698 $this->ndx_bg_color= $this->SetIndexColor($which_color); 699 return true; 700 } 701 function SetPlotBgColor($which_color) { 702 $this->plot_bg_color= $which_color; 703 $this->ndx_plot_bg_color= $this->SetIndexColor($which_color); 704 return true; 705 } 706 707 function SetShading($which_s) { 708 $this->shading = $which_s; 709 return true; 710 } 711 712 function SetTitleColor($which_color) { 713 $this->title_color= $which_color; 714 $this->ndx_title_color= $this->SetIndexColor($which_color); 715 return true; 716 } 717 718 function SetTickColor ($which_color) { 719 $this->tick_color= $which_color; 720 $this->ndx_tick_color= $this->SetIndexColor($which_color); 721 return true; 722 } 723 724 function SetLabelColor ($which_color) { 725 $this->label_color= $which_color; 726 $this->ndx_label_color= $this->SetIndexColor($which_color); 727 return true; 728 } 729 730 function SetTextColor ($which_color) { 731 $this->text_color= $which_color; 732 $this->ndx_text_color= $this->SetIndexColor($which_color); 733 return true; 734 } 735 736 function SetLightGridColor ($which_color) { 737 $this->light_grid_color= $which_color; 738 $this->ndx_light_grid_color= $this->SetIndexColor($which_color); 739 return true; 740 } 741 742 function SetGridColor ($which_color) { 743 $this->grid_color = $which_color; 744 $this->ndx_grid_color= $this->SetIndexColor($which_color); 745 return true; 746 } 747 748 function SetCharacterHeight() { 749 //to be set 750 return true; 751 } 752 753 function SetPlotType($which_pt) { 754 $accepted = "bars,lines,linepoints,area,points,pie,thinbarline"; 755 $asked = trim($which_pt); 756 if (eregi($asked, $accepted)) { 757 $this->plot_type = $which_pt; 758 return true; 759 } else { 760 $this->DrawError('$which_pt not an acceptable plot type'); 761 return false; 762 } 763 } 764 765 function FindDataLimits() { 766 //Text-Data is different than data-data graphs. For them what 767 // we have, instead of X values, is # of records equally spaced on data. 768 //text-data is passed in as $data[] = (title,y1,y2,y3,y4,...) 769 //data-data is passed in as $data[] = (title,x,y1,y2,y3,y4,...) 770 771 $this->number_x_points = count($this->data_values); 772 773 switch ($this->data_type) { 774 case "text-data": 775 $minx = 0; //valid for BAR TYPE GRAPHS ONLY 776 $maxx = $this->number_x_points - 1 ; //valid for BAR TYPE GRAPHS ONLY 777 $miny = (double) $this->data_values[0][1]; 778 $maxy = $miny; 779 if ($this->draw_x_data_labels == "") { 780 $this->draw_x_data_labels = 1; //labels_note1: prevent both data labels and x-axis labels being both drawn and overlapping 781 } 782 break; 783 default: //Everything else: data-data, etc. 784 $maxx = $this->data_values[0][1]; 785 $minx = $maxx; 786 $miny = $this->data_values[0][2]; 787 $maxy = $miny; 788 $maxy = $miny; 789 break; 790 } 791 792 $max_records_per_group = 0; 793 $total_records = 0; 794 $mine = 0; //Maximum value for the -error bar (assume error bars always > 0) 795 $maxe = 0; //Maximum value for the +error bar (assume error bars always > 0) 796 797 reset($this->data_values); 798 while (list($dat_key, $dat) = each($this->data_values)) { //for each X barchart setting 799 //foreach($this->data_values as $dat) //can use foreach only in php4 800 801 $tmp = 0; 802 $total_records += count($dat) - 1; // -1 for label 803 804 switch ($this->data_type) { 805 case "text-data": 806 //Find the relative Max and Min 807 808 while (list($key, $val) = each($dat)) { 809 if ($key != 0) { //$dat[0] = label 810 SetType($val,"double"); 811 if ($val > $maxy) { 812 $maxy = $val ; 813 } 814 if ($val < $miny) { 815 $miny = (double) $val ; 816 } 817 } 818 $tmp++; 819 } 820 break; 821 case "data-data": //X-Y data is passed in as $data[] = (title,x,y,y2,y3,...) which you can use for multi-dimentional plots. 822 823 while (list($key, $val) = each($dat)) { 824 if ($key == 1) { //$dat[0] = label 825 SetType($val,"double"); 826 if ($val > $maxx) { 827 $maxx = $val; 828 } elseif ($val < $minx) { 829 $minx = $val; 830 } 831 } elseif ($key > 1) { 832 SetType($val,"double"); 833 if ($val > $maxy) { 834 $maxy = $val ; 835 } elseif ($val < $miny) { 836 $miny = $val ; 837 } 838 } 839 $tmp++; 840 } 841 $tmp = $tmp - 1; //# records per group 842 break; 843 case "data-data-error": //Assume 2-D for now, can go higher 844 //Regular X-Y data is passed in as $data[] = (title,x,y,error+,error-,y2,error2+,error2-) 845 846 while (list($key, $val) = each($dat)) { 847 if ($key == 1) { //$dat[0] = label 848 SetType($val,'double'); 849 if ($val > $maxx) { 850 $maxx = $val; 851 } elseif ($val < $minx) { 852 $minx = $val; 853 } 854 } elseif ($key%3 == 2) { 855 SetType($val,'double'); 856 if ($val > $maxy) { 857 $maxy = $val ; 858 } elseif ($val < $miny) { 859 $miny = $val ; 860 } 861 } elseif ($key%3 == 0) { 862 SetType($val,'double'); 863 if ($val > $maxe) { 864 $maxe = $val ; 865 } 866 } elseif ($key%3 == 1) { 867 SetType($val,'double'); 868 if ($val > $mine) { 869 $mine = $val ; 870 } 871 } 872 $tmp++; 873 } 874 $maxy = $maxy + $maxe; 875 $miny = $miny - $mine; //assume error bars are always > 0 876 877 break; 878 default: 879 $this->PrintError('ERROR: unknown chart type'); 880 break; 881 } 882 if ($tmp > $max_records_per_group) { 883 $max_records_per_group = $tmp; 884 } 885 } 886 887 888 $this->min_x = $minx; 889 $this->max_x = $maxx; 890 $this->min_y = $miny; 891 $this->max_y = $maxy; 892 893 894 if ($max_records_per_group > 1) { 895 $this->records_per_group = $max_records_per_group - 1; 896 } else { 897 $this->records_per_group = 1; 898 } 899 900 901 //$this->data_count = $total_records ; 902 } // function FindDataLimits 903 904 function SetMargins() { 905 ///////////////////////////////////////////////////////////////// 906 // When the image is first created - set the margins 907 // to be the standard viewport. 908 // The standard viewport is the full area of the view surface (or panel), 909 // less a margin of 4 character heights all round for labelling. 910 // It thus depends on the current character size, set by SetCharacterHeight(). 911 ///////////////////////////////////////////////////////////////// 912 913 $str = split("\n",$this->title_txt); 914 $nbLines = count($str); 915 916 if ($this->use_ttf == 1) { 917 $title_size = $this->TTFBBoxSize($this->title_ttffont_size, $this->title_angle, $this->title_ttffont, 'X'); //An array 918 if ($nbLines == 1) { 919 $this->y_top_margin = $title_size[1] * 4; 920 } else { 921 $this->y_top_margin = $title_size[1] * ($nbLines+3); 922 } 923 924 //ajo working here 925 //$x_label_size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt); 926 927 $this->y_bot_margin = $this->x_label_height ; 928 $this->x_left_margin = $this->y_label_width * 2 + $this->tick_length; 929 $this->x_right_margin = 33.0; // distance between right and end of x axis in pixels 930 } else { 931 $title_size = array(ImageFontWidth($this->title_font) * strlen($this->title_txt),ImageFontHeight($this->title_font)); 932 //$this->y_top_margin = ($title_size[1] * 4); 933 if ($nbLines == 1) { 934 $this->y_top_margin = $title_size[1] * 4; 935 } else { 936 $this->y_top_margin = $title_size[1] * ($nbLines+3); 937 } 938 if ($this->x_datalabel_angle == 90) { 939 $this->y_bot_margin = 76.0; // Must be integer 940 } else { 941 $this->y_bot_margin = 66.0; // Must be integer 942 } 943 $this->x_left_margin = 77.0; // distance between left and start of x axis in pixels 944 $this->x_right_margin = 33.0; // distance between right and end of x axis in pixels 945 } 946 947 //exit; 948 $this->x_tot_margin = $this->x_left_margin + $this->x_right_margin; 949 $this->y_tot_margin = $this->y_top_margin + $this->y_bot_margin; 950 951 if ($this->plot_max_x && $this->plot_max_y && $this->plot_area_width ) { //If data has already been analysed then set translation 952 $this->SetTranslation(); 953 } 954 } 955 956 function SetMarginsPixels($which_lm,$which_rm,$which_tm,$which_bm) { 957 //Set the plot area using margins in pixels (left, right, top, bottom) 958 $this->SetNewPlotAreaPixels($which_lm,$which_tm,($this->image_width - $which_rm),($this->image_height - $which_bm)); 959 return true; 960 } 961 962 function SetNewPlotAreaPixels($x1,$y1,$x2,$y2) { 963 //Like in GD 0,0 is upper left set via pixel Coordinates 964 $this->plot_area = array($x1,$y1,$x2,$y2); 965 $this->plot_area_width = $this->plot_area[2] - $this->plot_area[0]; 966 $this->plot_area_height = $this->plot_area[3] - $this->plot_area[1]; 967 $this->y_top_margin = $this->plot_area[1]; 968 if ($this->plot_max_x) { 969 $this->SetTranslation(); 970 } 971 return true; 972 } 973 974 function SetPlotAreaPixels($x1,$y1,$x2,$y2) { 975 //Like in GD 0,0 is upper left 976 if (!$this->x_tot_margin) { 977 $this->SetMargins(); 978 } 979 if ($x2 && $y2) { 980 $this->plot_area = array($x1,$y1,$x2,$y2); 981 } else { 982 $this->plot_area = array($this->x_left_margin, $this->y_top_margin, 983 $this->image_width - $this->x_right_margin, 984 $this->image_height - $this->y_bot_margin 985 ); 986 } 987 $this->plot_area_width = $this->plot_area[2] - $this->plot_area[0]; 988 $this->plot_area_height = $this->plot_area[3] - $this->plot_area[1]; 989 990 return true; 991 992 } 993 994 function SetPlotAreaWorld($xmin,$ymin,$xmax,$ymax) 995 { 996 if (($xmin == "") && ($xmax == "")) 997 { 998 //For automatic setting of data we need $this->max_x 999 if (!$this->max_y) 1000 { 1001 $this->FindDataLimits() ; 1002 } 1003 if ($this->data_type == 'text-data') { //labels for text-data is done at data drawing time for speed. 1004 $xmax = $this->max_x + 1 ; //valid for BAR CHART TYPE GRAPHS ONLY 1005 $xmin = 0 ; //valid for BAR CHART TYPE GRAPHS ONLY 1006 } else { 1007 $xmax = $this->max_x * 1.02; 1008 $xmin = $this->min_x; 1009 } 1010 1011 $ymax = ceil($this->max_y * 1.2); 1012 if ($this->min_y < 0) { 1013 $ymin = floor($this->min_y * 1.2); 1014 } else { 1015 $ymin = 0; 1016 } 1017 } 1018 1019 $this->plot_min_x = $xmin; 1020 $this->plot_max_x = $xmax; 1021 1022 if ($ymin == $ymax) { 1023 $ymax += 1; 1024 } 1025 if ($this->yscale_type == "log") { 1026 //extra error checking 1027 if ($ymin <= 0) { 1028 $ymin = 1; 1029 } 1030 if ($ymax <= 0) { 1031 $this->PrintError('Log plots need data greater than 0'); 1032 } 1033 } 1034 $this->plot_min_y = $ymin; 1035 $this->plot_max_y = $ymax; 1036 1037 if ($ymax <= $ymin) { 1038 $this->DrawError('Error in Data - max not gt min'); 1039 } 1040 1041 //Set the boundaries of the box for plotting in world coord 1042 // if (!$this->x_tot_margin) { //We need to know the margins before we can calculate scale 1043 // $this->SetMargins(); 1044 // } 1045 //For this we have to reset the scale 1046 if ($this->plot_area_width) { 1047 $this->SetTranslation(); 1048 } 1049 1050 return true; 1051 1052 } //function SetPlotAreaWorld 1053 1054 1055 function PrintError($error_message) { 1056 // prints the error message to stdout and die 1057 echo "<p><b>Fatal error</b>: $error_message<p>"; 1058 die; 1059 } 1060 1061 function DrawError($error_message) { 1062 // prints the error message inline into 1063 // the generated image 1064 1065 if (($this->img) == "") { $this->InitImage(); } ; 1066 1067 $ypos = $this->image_height/2; 1068 1069 if ($this->use_ttf == 1) { 1070 ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255)); 1071 ImageTTFText($this->img, $this->small_ttffont_size, 0, $xpos, $ypos, ImageColorAllocate($this->img,0,0,0), $this->axis_ttffont, $error_message); 1072 } else { 1073 ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255)); 1074 ImageString($this->img, $this->small_font,1,$ypos,$error_message, ImageColorAllocate($this->img,0,0,0)); 1075 } 1076 1077 $this->PrintImage(); 1078 return true; 1079 } 1080 1081 function TTFBBoxSize($size, $angle, $font, $string) { 1082 1083 //Assume angle < 90 1084 $arr = ImageTTFBBox($size, 0, $font, $string); 1085 $flat_width = $arr[0] - $arr[2]; 1086 $flat_height = abs($arr[3] - $arr[5]); 1087 1088 // for 90deg: 1089 // $height = $arr[5] - $arr[7]; 1090 // $width = $arr[2] - $arr[4]; 1091 1092 $angle = deg2rad($angle); 1093 $width = ceil(abs($flat_width*cos($angle) + $flat_height*sin($angle))); //Must be integer 1094 $height = ceil(abs($flat_width*sin($angle) + $flat_height*cos($angle))); //Must be integer 1095 1096 return array($width, $height); 1097 } 1098 1099 function SetXLabelHeight() { 1100 1101 if ($this->use_ttf == 1) { 1102 //Space for the X Label 1103 $size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt); 1104 $tmp = $size[1]; 1105 1106 //$string = Str_Repeat('w', $this->x_datalabel_maxlength); 1107 $i = 0; 1108 $string = ''; 1109 while ($i < $this->x_datalabel_maxlength) { 1110 $string .= 'w'; 1111 $i++; 1112 } 1113 1114 //Space for the axis data labels 1115 $size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $string); 1116 1117 $this->x_label_height = 2*$tmp + $size[1] + 4; 1118 1119 } else { 1120 //For Non-TTF fonts we can have only angles 0 or 90 1121 if ($this->x_datalabel_angle == 90) { 1122 $this->x_label_height = $this->x_datalabel_maxlength * ImageFontWidth($this->small_font) / 1.5; 1123 } else { 1124 $this->x_label_height = 5 * ImageFontHeight($this->small_font); 1125 } 1126 } 1127 1128 $this->SetMargins(); 1129 1130 return true; 1131 } //function SetXLabelHeight 1132 1133 function SetYLabelWidth() { 1134 //$ylab = sprintf("%6.1f %s",$i,$si_units[0]); //use for PHP2 compatibility 1135 //the "." is for space. It isn't actually printed 1136 $ylab = number_format($this->max_y, $this->y_precision, ".", ",") . $this->si_units . "."; 1137 1138 if ($this->use_ttf == 1) { 1139 $size = $this->TTFBBoxSize($this->axis_ttffont_size, 0, $this->axis_ttffont, $ylab); 1140 } else { 1141 $size[0] = StrLen($ylab) * $this->small_font_width * .6; 1142 } 1143 1144 $this->y_label_width = $size[0] * 2; 1145 //echo "SYLW: $this->y_label_width<br>"; 1146 //exit; 1147 1148 $this->SetMargins(); 1149 return true; 1150 } 1151 1152 function SetEqualXCoord() { 1153 //for plots that have equally spaced x variables and multiple bars per x-point. 1154 1155 $space = ($this->plot_area[2] - $this->plot_area[0]) / ($this->number_x_points * 2) * $this->group_frac_width; 1156 $group_width = $space * 2; 1157 $bar_width = $group_width / $this->records_per_group; 1158 //I think that eventually this space variable will be replaced by just graphing x. 1159 $this->data_group_space = $space; 1160 $this->record_bar_width = $bar_width; 1161 return true; 1162 } 1163 1164 function SetLabelScalePosition($which_blp) { 1165 //0 to 1 1166 $this->label_scale_position = $which_blp; 1167 return true; 1168 } 1169 1170 function SetErrorBarSize($which_ebs) { 1171 //in pixels 1172 $this->error_bar_size = $which_ebs; 1173 return true; 1174 } 1175 1176 function SetErrorBarShape($which_ebs) { 1177 //in pixels 1178 $this->error_bar_shape = $which_ebs; 1179 return true; 1180 } 1181 1182 function SetPointShape($which_pt) { 1183 //in pixels 1184 $this->point_shape = $which_pt; 1185 return true; 1186 } 1187 1188 function SetPointSize($which_ps) { 1189 //in pixels 1190 SetType($which_ps,'integer'); 1191 $this->point_size = $which_ps; 1192 1193 if ($this->point_shape == "diamond" or $this->point_shape == "triangle") { 1194 if ($this->point_size % 2 != 0) { 1195 $this->point_size++; 1196 } 1197 } 1198 return true; 1199 } 1200 1201 function SetDataType($which_dt) { 1202 //The next three lines are for past compatibility. 1203 if ($which_dt == "text-linear") { $which_dt = "text-data"; }; 1204 if ($which_dt == "linear-linear") { $which_dt = "data-data"; }; 1205 if ($which_dt == "linear-linear-error") { $which_dt = "data-data-error"; }; 1206 1207 $this->data_type = $which_dt; //text-data, data-data, data-data-error 1208 return true; 1209 } 1210 1211 function SetDataValues($which_dv) { 1212 $this->data_values = $which_dv; 1213 //echo $this->data_values 1214 return true; 1215 } 1216 1217 //////////////COLORS 1218 function SetRGBArray ($which_color_array) { 1219 if ( is_array($which_color_array) ) { 1220 //User Defined Array 1221 $this->rgb_array = $which_color_array; 1222 return true; 1223 } elseif ($which_color_array == 2) { //Use the small predefined color array 1224 $this->rgb_array = array( 1225 "white" => array(255, 255, 255), 1226 "snow" => array(255, 250, 250), 1227 "PeachPuff" => array(255, 218, 185), 1228 "ivory" => array(255, 255, 240), 1229 "lavender" => array(230, 230, 250), 1230 "black" => array( 0, 0, 0), 1231 "DimGrey" => array(105, 105, 105), 1232 "gray" => array(190, 190, 190), 1233 "grey" => array(190, 190, 190), 1234 "navy" => array( 0, 0, 128), 1235 "SlateBlue" => array(106, 90, 205), 1236 "blue" => array( 0, 0, 255), 1237 "SkyBlue" => array(135, 206, 235), 1238 "cyan" => array( 0, 255, 255), 1239 "DarkGreen" => array( 0, 100, 0), 1240 "green" => array( 0, 255, 0), 1241 "YellowGreen" => array(154, 205, 50), 1242 "yellow" => array(255, 255, 0), 1243 "orange" => array(255, 165, 0), 1244 "gold" => array(255, 215, 0), 1245 "peru" => array(205, 133, 63), 1246 "beige" => array(245, 245, 220), 1247 "wheat" => array(245, 222, 179), 1248 "tan" => array(210, 180, 140), 1249 "brown" => array(165, 42, 42), 1250 "salmon" => array(250, 128, 114), 1251 "red" => array(255, 0, 0), 1252 "pink" => array(255, 192, 203), 1253 "maroon" => array(176, 48, 96), 1254 "magenta" => array(255, 0, 255), 1255 "violet" => array(238, 130, 238), 1256 "plum" => array(221, 160, 221), 1257 "orchid" => array(218, 112, 214), 1258 "purple" => array(160, 32, 240), 1259 "azure1" => array(240, 255, 255), 1260 "aquamarine1" => array(127, 255, 212) 1261 ); 1262 return true; 1263 } elseif ($which_color_array == 1) { 1264 include ("./rgb.inc.php"); //Get large $ColorArray 1265 $this->rgb_array = $RGBArray; 1266 } else { 1267 $this->rgb_array = array("white" =>array(255,255,255), "black" => array(0,0,0)); 1268 exit; 1269 } 1270 1271 return true; 1272 } 1273 1274 function SetColor($which_color) { 1275 //obsoleted by SetRGBColor 1276 SetRgbColor($which_color); 1277 return true; 1278 } 1279 1280 function SetIndexColor($which_color) { //Color is passed in as anything 1281 list ($r, $g, $b) = $this->SetRgbColor($which_color); //Translate to RGB 1282 $index = ImageColorExact($this->img, $r, $g, $b); 1283 if ($index == -1) { 1284 //return ImageColorAllocate($this->img, $r, $g, $b); 1285 //return ImageColorClosest($this->img, $r, $g, $b); 1286 return ImageColorResolve($this->img, $r, $g, $b); //requires PHP 3.0.2 and later 1287 } else { 1288 return $index; 1289 } 1290 } 1291 1292 function SetTransparentColor($which_color) { 1293 ImageColorTransparent($this->img,$this->SetIndexColor($which_color)); 1294 return true; 1295 } 1296 1297 function SetRgbColor($color_asked) { 1298 //Returns an array in R,G,B format 0-255 1299 if ($color_asked == "") { $color_asked = array(0,0,0); }; 1300 1301 if ( count($color_asked) == 3 ) { //already array of 3 rgb 1302 $ret_val = $color_asked; 1303 } else { // is asking for a color by string 1304 if(substr($color_asked,0,1) == "#") { //asking in #FFFFFF format. 1305 $ret_val = array(hexdec(substr($color_asked,1,2)), hexdec(substr($color_asked,3,2)), hexdec(substr($color,5,2))); 1306 } else { 1307 $ret_val = $this->rgb_array[$color_asked]; 1308 } 1309 } 1310 return $ret_val; 1311 } 1312 1313 function SetDataColors($which_data,$which_border) { 1314 //Set the data to be displayed in a particular color 1315 if (!$which_data) { 1316 $which_data = array(array(0,255,0),array(0,0,248),'yellow',array(255,0,0),'orange'); 1317 $which_border = array('black'); 1318 } 1319 1320 $this->data_color = $which_data; //an array 1321 $this->data_border_color = $which_border; //an array 1322 1323 unset($this->ndx_data_color); 1324 reset($this->data_color); //data_color can be an array of colors, one for each thing plotted 1325 //while (list(, $col) = each($this->data_color)) 1326 $i = 0; 1327 while (list(, $col) = each($which_data)) { 1328 $this->ndx_data_color[$i] = $this->SetIndexColor($col); 1329 $i++; 1330 } 1331 1332 // border_color 1333 //If we are also going to put a border on the data (bars, dots, area, ...) 1334 // then lets also set a border color as well. 1335 //foreach($this->data_border_color as $col) 1336 unset($this->ndx_data_border_color); 1337 reset($this->data_border_color); 1338 $i = 0; 1339 while (list(, $col) = each($this->data_border_color)) { 1340 $this->ndx_data_border_color[$i] = $this->SetIndexColor($col); 1341 $i++; 1342 } 1343 1344 //Set color of the error bars to be that of data if not already set. 1345 if (!$this->error_bar_color) { 1346 reset($which_data); 1347 $this->SetErrorBarColors($which_data); 1348 } 1349 1350 return true; 1351 1352 } //function SetDataColors 1353 1354 function SetErrorBarColors($which_data) { 1355 1356 //Set the data to be displayed in a particular color 1357 1358 if ($which_data) { 1359 $this->error_bar_color = $which_data; //an array 1360 unset($this->ndx_error_bar_color); 1361 reset($this->error_bar_color); //data_color can be an array of colors, one for each thing plotted 1362 $i = 0; 1363 while (list(, $col) = each($this->error_bar_color)) { 1364 $this->ndx_error_bar_color[$i] = $this->SetIndexColor($col); 1365 $i++; 1366 } 1367 return true; 1368 } 1369 return false; 1370 } //function SetErrorBarColors 1371 1372 1373 function DrawPlotBorder() { 1374 switch ($this->plot_border_type) { 1375 case "left" : 1376 ImageLine($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y), 1377 $this->plot_area[0],$this->ytr($this->plot_max_y),$this->ndx_grid_color); 1378 break; 1379 case "none": 1380 //Draw No Border 1381 break; 1382 default: 1383 ImageRectangle($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y), 1384 $this->plot_area[2],$this->ytr($this->plot_max_y),$this->ndx_grid_color); 1385 break; 1386 } 1387 $this->DrawYAxis(); 1388 $this->DrawXAxis(); 1389 return true; 1390 } 1391 1392 1393 function SetHorizTickIncrement($which_ti) { 1394 //Use either this or NumHorizTicks to set where to place x tick marks 1395 if ($which_ti) { 1396 $this->horiz_tick_increment = $which_ti; //world coordinates 1397 } else { 1398 if (!$this->max_x) { 1399 $this->FindDataLimits(); //Get maxima and minima for scaling 1400 } 1401 //$this->horiz_tick_increment = ( ceil($this->max_x * 1.2) - floor($this->min_x * 1.2) )/10; 1402 $this->horiz_tick_increment = ($this->plot_max_x - $this->plot_min_x )/10; 1403 } 1404 $this->num_horiz_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both 1405 return true; 1406 } 1407 1408 function SetDrawVertTicks($which_dvt) { 1409 $this->draw_vert_ticks = $which_dvt; 1410 return true; 1411 } 1412 1413 function SetVertTickIncrement($which_ti) { 1414 //Use either this or NumVertTicks to set where to place y tick marks 1415 if ($which_ti) { 1416 $this->vert_tick_increment = $which_ti; //world coordinates 1417 } else { 1418 if (!$this->max_y) { 1419 $this->FindDataLimits(); //Get maxima and minima for scaling 1420 } 1421 //$this->vert_tick_increment = ( ceil($this->max_y * 1.2) - floor($this->min_y * 1.2) )/10; 1422 $this->vert_tick_increment = ($this->plot_max_y - $this->plot_min_y )/10; 1423 } 1424 $this->num_vert_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both 1425 return true; 1426 } 1427 1428 function SetNumHorizTicks($which_nt) { 1429 $this->num_horiz_ticks = $which_nt; 1430 $this->horiz_tick_increment = ''; //either use num_horiz_ticks or horiz_tick_increment, not both 1431 return true; 1432 } 1433 1434 function SetNumVertTicks($which_nt) { 1435 $this->num_vert_ticks = $which_nt; 1436 $this->vert_tick_increment = ''; //either use num_vert_ticks or vert_tick_increment, not both 1437 return true; 1438 } 1439 function SetVertTickPosition($which_tp) { 1440 $this->vert_tick_position = $which_tp; //plotleft, plotright, both, yaxis 1441 return true; 1442 } 1443 function SetSkipBottomTick($which_sbt) { 1444 $this->skip_bottom_tick = $which_sbt; 1445 return true; 1446 } 1447 1448 function SetTickLength($which_tl) { 1449 $this->tick_length = $which_tl; 1450 return true; 1451 } 1452 1453 function DrawYAxis() { 1454 //Draw Line at left side or at this->y_axis_position 1455 if ($this->y_axis_position != "") { 1456 $yaxis_x = $this->xtr($this->y_axis_position); 1457 } else { 1458 $yaxis_x = $this->plot_area[0]; 1459 } 1460 1461 ImageLine($this->img, $yaxis_x, $this->plot_area[1], 1462 $yaxis_x, $this->plot_area[3], $this->ndx_grid_color); 1463 //$yaxis_x, $this->plot_area[3], 9); 1464 1465 if ($this->draw_vert_ticks == 1) { 1466 $this->DrawVerticalTicks(); 1467 } 1468 1469 } //function DrawYAxis 1470 1471 function DrawXAxis() { 1472 //Draw Tick and Label for Y axis 1473 $ylab =$this->FormatYTickLabel($this->x_axis_position); 1474 if ($this->skip_bottom_tick != 1) { 1475 $this->DrawVerticalTick($ylab,$this->x_axis_position); 1476 } 1477 1478 //Draw X Axis at Y=$x_axis_postion 1479 ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->x_axis_position), 1480 $this->xtr($this->plot_max_x)-1,$this->ytr($this->x_axis_position),$this->ndx_tick_color); 1481 1482 //X Ticks and Labels 1483 if ($this->data_type != 'text-data') { //labels for text-data done at data drawing time for speed. 1484 $this->DrawHorizontalTicks(); 1485 } 1486 return true; 1487 } 1488 1489 function DrawHorizontalTicks() { 1490 //Ticks and lables are drawn on the left border of PlotArea. 1491 //Left Bottom 1492 ImageLine($this->img,$this->plot_area[0], 1493 $this->plot_area[3]+$this->tick_length, 1494 $this->plot_area[0],$this->plot_area[3],$this->ndx_tick_color); 1495 1496 switch ($this->x_grid_label_type) { 1497 case "title": 1498 $xlab = $this->data_values[0][0]; 1499 break; 1500 case "data": 1501 $xlab = number_format($this->plot_min_x,$this->x_precision,".",",") . "$this->si_units"; 1502 break; 1503 case "none": 1504 $xlab = ''; 1505 break; 1506 case "time": //Time formatting suggested by Marlin Viss 1507 $xlab = strftime($this->x_time_format,$this->plot_min_x); 1508 break; 1509 default: 1510 //Unchanged from whatever format is passed in 1511 $xlab = $this->plot_min_x; 1512 break; 1513 } 1514 1515 if ($this->x_datalabel_angle == 90) { 1516 $xpos = $this->plot_area[0] - $this->small_font_height/2; 1517 $ypos = ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height); 1518 ImageStringUp($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color); 1519 } else { 1520 $xpos = $this->plot_area[0] - $this->small_font_width*strlen($xlab)/2 ; 1521 $ypos = $this->plot_area[3] + $this->small_font_height; 1522 ImageString($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color); 1523 } 1524 1525 //Will be changed to allow for TTF fonts in data as well. 1526 //$this->DrawText($this->small_font, $this->x_datalabel_angle, $xpos, $ypos, $this->ndx_title_color, '', $xlab); 1527 1528 //Top 1529 1530 if ($this->horiz_tick_increment) { 1531 $delta_x = $this->horiz_tick_increment; 1532 } elseif ($this->num_horiz_ticks) { 1533 $delta_x = ($this->plot_max_x - $this->plot_min_x) / $this->num_horiz_ticks; 1534 } else { 1535 $delta_x =($this->plot_max_x - $this->plot_min_x) / 10 ; 1536 } 1537 1538 $i = 0; 1539 $x_tmp = $this->plot_min_x; 1540 SetType($x_tmp,'double'); 1541 1542 while ($x_tmp <= $this->plot_max_x){ 1543 //$xlab = sprintf("%6.1f %s",$min_x,$si_units[0]); //PHP2 past compatibility 1544 switch ($this->x_grid_label_type) { 1545 case "title": 1546 $xlab = $this->data_values[$x_tmp][0]; 1547 break; 1548 case "data": 1549 $xlab = number_format($x_tmp,$this->x_precision,".",",") . "$this->si_units"; 1550 break; 1551 case "none": 1552 $xlab = ''; 1553 break; 1554 case "time": //Time formatting suggested by Marlin Viss 1555 $xlab = strftime($this->x_time_format,$x_tmp); 1556 break; 1557 default: 1558 //Unchanged from whatever format is passed in 1559 $xlab = $x_tmp; 1560 break; 1561 } 1562 1563 $x_pixels = $this->xtr($x_tmp); 1564 1565 //Bottom Tick 1566 ImageLine($this->img,$x_pixels,$this->plot_area[3] + $this->tick_length, 1567 $x_pixels,$this->plot_area[3], $this->ndx_tick_color); 1568 //Top Tick 1569 //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length), 1570 // $y_pixels,$this->xtr($this->plot_max_x)-1,$y_pixels,$this->ndx_tick_color); 1571 1572 if ($this->draw_x_grid == 1) { 1573 ImageLine($this->img,$x_pixels,$this->plot_area[1], 1574 $x_pixels,$this->plot_area[3], $this->ndx_light_grid_color); 1575 } 1576 1577 if ($this->x_datalabel_angle == 90) { //Vertical Code Submitted by Marlin Viss 1578 ImageStringUp($this->img, $this->small_font, 1579 ( $x_pixels - $this->small_font_height/2), 1580 ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height),$xlab, $this->ndx_text_color); 1581 } else { 1582 ImageString($this->img, $this->small_font, 1583 ( $x_pixels - $this->small_font_width*strlen($xlab)/2) , 1584 ( $this->small_font_height + $this->plot_area[3]),$xlab, $this->ndx_text_color); 1585 } 1586 1587 $i++; 1588 $x_tmp += $delta_x; 1589 } 1590 1591 } // function DrawHorizontalTicks 1592 1593 function FormatYTickLabel($which_ylab) { 1594 switch ($this->y_grid_label_type) { 1595 case "data": 1596 $ylab = number_format($which_ylab,$this->y_precision,".",",") . "$this->si_units"; 1597 break; 1598 case "none": 1599 $ylab = ''; 1600 break; 1601 case "time": 1602 $ylab = strftime($this->y_time_format,$which_ylab); 1603 break; 1604 case "right": 1605 //Make it right aligned 1606 //$ylab = str_pad($which_ylab,$this->y_label_width," ",STR_PAD_LEFT); //PHP4 only 1607 $sstr = "%".strlen($this->plot_max_y)."s"; 1608 $ylab = sprintf($sstr,$which_ylab); 1609 break; 1610 default: 1611 //Unchanged from whatever format is passed in 1612 $ylab = $which_ylab; 1613 break; 1614 } 1615 1616 return($ylab); 1617 1618 } //function FormatYTickLabel 1619 1620 function DrawVerticalTick($which_ylab,$which_ypos) { //ylab in world coord. 1621 //Draw Just one Tick, called from DrawVerticalTicks 1622 //Ticks and datalables can be left of plot only, right of plot only, 1623 // both on the left and right of plot, or crossing a user defined Y-axis 1624 // 1625 //Its faster to draw both left and right ticks at same time 1626 // than first left and then right. 1627 1628 if ($this->y_axis_position != "") { 1629 //Ticks and lables are drawn on the left border of yaxis 1630 $yaxis_x = $this->xtr($this->y_axis_position); 1631 } else { 1632 //Ticks and lables are drawn on the left border of PlotArea. 1633 $yaxis_x = $this->plot_area[0]; 1634 } 1635 1636 $y_pixels = $this->ytr($which_ypos); 1637 1638 //Lines Across the Plot Area 1639 if ($this->draw_y_grid == 1) { 1640 ImageLine($this->img,$this->plot_area[0]+1,$y_pixels, 1641 $this->plot_area[2]-1,$y_pixels,$this->ndx_light_grid_color); 1642 } 1643 1644 //Ticks to the Left of the Plot Area 1645 if (($this->vert_tick_position == "plotleft") || ($this->vert_tick_position == "both") ) { 1646 ImageLine($this->img,(-$this->tick_length+$yaxis_x), 1647 $y_pixels,$yaxis_x, 1648 $y_pixels, $this->ndx_tick_color); 1649 } 1650 1651 //Ticks to the Right of the Plot Area 1652 if (($this->vert_tick_position == "plotright") || ($this->vert_tick_position == "both") ) { 1653 ImageLine($this->img,($this->plot_area[2]+$this->tick_length), 1654 $y_pixels,$this->plot_area[2], 1655 $y_pixels,$this->ndx_tick_color); 1656 } 1657 1658 //Ticks on the Y Axis 1659 if (($this->vert_tick_position == "yaxis") ) { 1660 ImageLine($this->img,($yaxis_x - $this->tick_length), 1661 $y_pixels,$yaxis_x,$y_pixels,$this->ndx_tick_color); 1662 } 1663 1664 //DataLabel 1665 //ajo working 1666 //$this->DrawText($this->y_label_ttffont, 0,($yaxis_x - $this->y_label_width - $this->tick_length/2), 1667 // $y_pixels, $this->ndx_text_color, $this->axis_ttffont_size, $which_ylab); 1668 ImageString($this->img, $this->small_font, ($yaxis_x - $this->y_label_width - $this->tick_length/2), 1669 ( -($this->small_font_height/2.0) + $y_pixels),$which_ylab, $this->ndx_text_color); 1670 } 1671 1672 function DrawVerticalTicks() { 1673 1674 if ($this->skip_top_tick != 1) { //If tick increment doesn't hit the top 1675 //Left Top 1676 //ImageLine($this->img,(-$this->tick_length+$this->xtr($this->plot_min_x)), 1677 // $this->ytr($this->plot_max_y),$this->xtr($this->plot_min_x),$this->ytr($this->plot_max_y),$this->ndx_tick_color); 1678 //$ylab = $this->FormatYTickLabel($plot_max_y); 1679 1680 //Right Top 1681 //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length), 1682 // $this->ytr($this->plot_max_y),$this->xtr($this->plot_max_x-1),$this->ytr($this->plot_max_y),$this->ndx_tick_color); 1683 1684 //Draw Grid Line at Top 1685 ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->plot_max_y), 1686 $this->plot_area[2]-1,$this->ytr($this->plot_max_y),$this->ndx_light_grid_color); 1687 1688 } 1689 1690 if ($this->skip_bottom_tick != 1) { 1691 //Right Bottom 1692 //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length), 1693 // $this->ytr($this->plot_min_y),$this->xtr($this->plot_max_x), 1694 // $this->ytr($this->plot_min_y),$this->ndx_tick_color); 1695 1696 //Draw Grid Line at Bottom of Plot 1697 ImageLine($this->img,$this->xtr($this->plot_min_x)+1,$this->ytr($this->plot_min_y), 1698 $this->xtr($this->plot_max_x),$this->ytr($this->plot_min_y),$this->ndx_light_grid_color); 1699 } 1700 1701 // maxy is always > miny so delta_y is always positive 1702 if ($this->vert_tick_increment) { 1703 $delta_y = $this->vert_tick_increment; 1704 } elseif ($this->num_vert_ticks) { 1705 $delta_y = ($this->plot_max_y - $this->plot_min_y) / $this->num_vert_ticks; 1706 } else { 1707 $delta_y =($this->plot_max_y - $this->plot_min_y) / 10 ; 1708 } 1709 1710 $y_tmp = $this->plot_min_y; 1711 SetType($y_tmp,'double'); 1712 if ($this->skip_bottom_tick == 1) { 1713 $y_tmp += $delta_y; 1714 } 1715 1716 while ($y_tmp <= $this->plot_max_y){ 1717 //For log plots: 1718 if (($this->yscale_type == "log") && ($this->plot_min_y == 1) && 1719 ($delta_y%10 == 0) && ($y_tmp == $this->plot_min_y)) { 1720 $y_tmp = $y_tmp - 1; //Set first increment to 9 to get: 1,10,20,30,... 1721 } 1722 1723 $ylab = $this->FormatYTickLabel($y_tmp); 1724 1725 $this->DrawVerticalTick($ylab,$y_tmp); 1726 1727 $y_tmp += $delta_y; 1728 } 1729 1730 return true; 1731 1732 } // function DrawVerticalTicks 1733 1734 function SetTranslation() { 1735 if ($this->xscale_type == "log") { 1736 $this->xscale = ($this->plot_area_width)/(log10($this->plot_max_x) - log10($this->plot_min_x)); 1737 } else { 1738 $this->xscale = ($this->plot_area_width)/($this->plot_max_x - $this->plot_min_x); 1739 } 1740 if ($this->yscale_type == "log") { 1741 $this->yscale = ($this->plot_area_height)/(log10($this->plot_max_y) - log10($this->plot_min_y)); 1742 } else { 1743 $this->yscale = ($this->plot_area_height)/($this->plot_max_y - $this->plot_min_y); 1744 } 1745 1746 // GD defines x=0 at left and y=0 at TOP so -/+ respectively 1747 if ($this->xscale_type == "log") { 1748 $this->plot_origin_x = $this->plot_area[0] - ($this->xscale * log10($this->plot_min_x) ); 1749 } else { 1750 $this->plot_origin_x = $this->plot_area[0] - ($this->xscale * $this->plot_min_x); 1751 } 1752 if ($this->yscale_type == "log") { 1753 $this->plot_origin_y = $this->plot_area[3] + ($this->yscale * log10($this->plot_min_y)); 1754 } else { 1755 $this->plot_origin_y = $this->plot_area[3] + ($this->yscale * $this->plot_min_y); 1756 } 1757 1758 $this->scale_is_set = 1; 1759 } // function SetTranslation 1760 1761 function xtr($x_world) { 1762 //Translate world coordinates into pixel coordinates 1763 //The pixel coordinates are those of the ENTIRE image, not just the plot_area 1764 //$x_pixels = $this->x_left_margin + ($this->image_width - $this->x_tot_margin)*(($x_world - $this->plot_min_x) / ($this->plot_max_x - $this->plot_min_x)) ; 1765 //which with a little bit of math reduces to ... 1766 if ($this->xscale_type == "log") { 1767 $x_pixels = $this->plot_origin_x + log10($x_world) * $this->xscale ; 1768 } else { 1769 $x_pixels = $this->plot_origin_x + $x_world * $this->xscale ; 1770 } 1771 return($x_pixels); 1772 } 1773 1774 function ytr($y_world) { 1775 // translate y world coord into pixel coord 1776 if ($this->yscale_type == "log") { 1777 $y_pixels = $this->plot_origin_y - log10($y_world) * $this->yscale ; //minus because GD defines y=0 at top. doh! 1778 } else { 1779 $y_pixels = $this->plot_origin_y - $y_world * $this->yscale ; 1780 } 1781 return ($y_pixels); 1782 } 1783 1784 1785 function DrawDataLabel($lab,$x_world,$y_world) { 1786 //Depreciated. Use DrawText Instead. 1787 //Data comes in in WORLD coordinates 1788 //Draw data label near actual data point 1789 //$y = $this->ytr($y_world) ; //in pixels 1790 //$x = $this->xtr($x_world) ; 1791 //$this->DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left'); 1792 if ($this->use_ttf) { 1793 //ajjjo 1794 $lab_size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $lab); //An array 1795 $y = $this->ytr($y_world) - $lab_size[1] ; //in pixels 1796 $x = $this->xtr($x_world) - $lab_size[0]/2; 1797 ImageTTFText($this->img, $this->axis_ttffont_size, $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $lab); 1798 } else { 1799 $lab_size = array($this->small_font_width*StrLen($lab), $this->small_font_height*3); 1800 if ($this->x_datalabel_angle == 90) { 1801 $y = $this->ytr($y_world) - $this->small_font_width*StrLen($lab); //in pixels 1802 $x = $this->xtr($x_world) - $this->small_font_height; 1803 ImageStringUp($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color); 1804 } else { 1805 $y = $this->ytr($y_world) - $this->small_font_height; //in pixels 1806 $x = $this->xtr($x_world) - ($this->small_font_width*StrLen($lab))/2; 1807 ImageString($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color); 1808 } 1809 } 1810 1811 } 1812 1813 function DrawXDataLabel($xlab,$xpos) { 1814 //xpos comes in in PIXELS not in world coordinates. 1815 //Draw an x data label centered at xlab 1816 if ($this->use_ttf) { 1817 $xlab_size = $this->TTFBBoxSize($this->axis_ttffont_size, 1818 $this->x_datalabel_angle, $this->axis_ttffont, $xlab); //An array 1819 $y = $this->plot_area[3] + $xlab_size[1] + 4; //in pixels 1820 $x = $xpos - $xlab_size[0]/2; 1821 ImageTTFText($this->img, $this->axis_ttffont_size, 1822 $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $xlab); 1823 } else { 1824 $xlab_size = array(ImageFontWidth($this->axis_font)*StrLen($xlab), $this->small_font_height*3); 1825 if ($this->x_datalabel_angle == 90) { 1826 $y = $this->plot_area[3] + ImageFontWidth($this->axis_font)*StrLen($xlab); //in pixels 1827 $x = $xpos - ($this->small_font_height); 1828 ImageStringUp($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color); 1829 } else { 1830 $y = $this->plot_area[3] + ImageFontHeight($this->axis_font); //in pixels 1831 $x = $xpos - (ImageFontWidth($this->axis_font)*StrLen($xlab))/2; 1832 ImageString($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color); 1833 } 1834 } 1835 1836 } 1837 1838 function DrawPieChart() { 1839 //$pi = '3.14159265358979323846'; 1840 $xpos = $this->plot_area[0] + $this->plot_area_width/2; 1841 $ypos = $this->plot_area[1] + $this->plot_area_height/2; 1842 $diameter = (min($this->plot_area_width, $this->plot_area_height)) ; 1843 $radius = $diameter/2; 1844 1845 ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color); 1846 1847 $total = 0; 1848 reset($this->data_values); 1849 $tmp = $this->number_x_points - 1; 1850 while (list($j, $row) = each($this->data_values)) { 1851 //Get sum of each type 1852 $color_index = 0; 1853 $i = 0; 1854 //foreach ($row as $v) 1855 while (list($k, $v) = each($row)) { 1856 if ($k != 0) { 1857 if ($j == 0) { 1858 $sumarr[$i] = $v; 1859 } elseif ($j < $tmp) { 1860 $sumarr[$i] += $v; 1861 } else { 1862 $sumarr[$i] += $v; 1863 // NOTE! sum > 0 to make pie charts 1864 $sumarr[$i] = abs($sumarr[$i]); 1865 $total += $sumarr[$i]; 1866 } 1867 } 1868 $i++; 1869 } 1870 } 1871 1872 $color_index = 0; 1873 $start_angle = 0; 1874 1875 reset($sumarr); 1876 $end_angle = 0; 1877 while (list(, $val) = each($sumarr)) { 1878 if ($color_index >= count($this->ndx_data_color)) $color_index=0; //data_color = array 1879 $label_txt = number_format(($val / $total * 100), $this->y_precision, ".", ",") . "%"; 1880 $val = 360 * ($val / $total); 1881 1882 $end_angle += $val; 1883 $mid_angle = $end_angle - ($val / 2); 1884 1885 $slicecol = $this->ndx_data_color[$color_index]; 1886 1887 //Need this again for FillToBorder 1888 ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color); 1889 1890 $out_x = $radius * cos(deg2rad($end_angle)); 1891 $out_y = - $radius * sin(deg2rad($end_angle)); 1892 1893 $mid_x = $xpos + ($radius/2 * cos(deg2rad($mid_angle))) ; 1894 $mid_y = $ypos + (- $radius/2 * sin(deg2rad($mid_angle))); 1895 1896 $label_x = $xpos + ($radius * cos(deg2rad($mid_angle))) * $this->label_scale_position; 1897 $label_y = $ypos + (- $radius * sin(deg2rad($mid_angle))) * $this->label_scale_position; 1898 1899 $out_x = $xpos + $out_x; 1900 $out_y = $ypos + $out_y; 1901 1902 ImageLine($this->img, $xpos, $ypos, $out_x, $out_y, $this->ndx_grid_color); 1903 //ImageLine($this->img, $xpos, $ypos, $label_x, $label_y, $this->ndx_grid_color); 1904 ImageFillToBorder($this->img, $mid_x, $mid_y, $this->ndx_grid_color, $slicecol); 1905 1906 if ($this->use_ttf) { 1907 ImageTTFText($this->img, $this->axis_ttffont_size, 0, $label_x, $label_y, $this->ndx_grid_color, $this->axis_ttffont, $label_txt); 1908 } else { 1909 ImageString($this->img, $this->small_font, $label_x, $label_y, $label_txt, $this->ndx_grid_color); 1910 } 1911 1912 $start_angle = $val; 1913 1914 $color_index++; 1915 } 1916 1917 } 1918 1919 function DrawLinesError() { 1920 //Draw Lines with Error Bars - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...); 1921 $start_lines = 0; 1922 1923 reset($this->data_values); 1924 while (list(, $row) = each($this->data_values)) { 1925 $color_index = 0; 1926 $i = 0; 1927 1928 while (list($key, $val) = each($row)) { 1929 //echo "$key, $i, $val<br>"; 1930 if ($key == 0) { 1931 $lab = $val; 1932 } elseif ($key == 1) { 1933 $x_now = $val; 1934 $x_now_pixels = $this->xtr($x_now); //Use a bit more memory to save 2N operations. 1935 } elseif ($key%3 == 2) { 1936 $y_now = $val; 1937 $y_now_pixels = $this->ytr($y_now); 1938 1939 //Draw Data Label 1940 if ( $this->draw_data_labels == 1) { 1941 $this->DrawDataLabel($lab,$x_now,$y_now); 1942 } 1943 1944 if ($color_index >= count($this->ndx_data_color)) { $color_index=0;}; 1945 $barcol = $this->ndx_data_color[$color_index]; 1946 $error_barcol = $this->ndx_error_bar_color[$color_index]; 1947 1948 //echo "start = $start_lines<br>"; 1949 if ($start_lines == 1) { 1950 for ($width = 0; $width < $this->line_width; $width++) { 1951 ImageLine($this->img, $x_now_pixels, $y_now_pixels + $width, 1952 $lastx[$i], $lasty[$i] + $width, $barcol); 1953 } 1954 } 1955 1956 $lastx[$i] = $x_now_pixels; 1957 $lasty[$i] = $y_now_pixels; 1958 $color_index++; 1959 $i++; 1960 $start_lines = 1; 1961 } elseif ($key%3 == 0) { 1962 $this->DrawYErrorBar($x_now,$y_now,$val,$this->error_bar_shape,$error_barcol); 1963 } elseif ($key%3 == 1) { 1964 $this->DrawYErrorBar($x_now,$y_now,-$val,$this->error_bar_shape,$error_barcol); 1965 } 1966 } 1967 } 1968 } 1969 1970 function DrawDotsError() { 1971 //Draw Dots - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...); 1972 reset($this->data_values); 1973 while (list(, $row) = each($this->data_values)) { 1974 $color_index = 0; 1975 //foreach ($row as $v) 1976 while (list($key, $val) = each($row)) { 1977 if ($key == 0) { 1978 } elseif ($key == 1) { 1979 $xpos = $val; 1980 } elseif ($key%3 == 2) { 1981 if ($color_index >= count($this->ndx_data_color)) $color_index=0; 1982 $barcol = $this->ndx_data_color[$color_index]; 1983 $error_barcol = $this->ndx_error_bar_color[$color_index]; 1984 $ypos = $val; 1985 1986 $color_index++; 1987 $this->DrawDot($xpos,$ypos,$this->point_shape,$barcol); 1988 } elseif ($key%3 == 0) { 1989 $this->DrawYErrorBar($xpos,$ypos,$val,$this->error_bar_shape,$error_barcol); 1990 } elseif ($key%3 == 1) { 1991 $mine = $val ; 1992 $this->DrawYErrorBar($xpos,$ypos,-$val,$this->error_bar_shape,$error_barcol); 1993 } 1994 } 1995 } 1996 1997 } 1998 1999 function DrawDots() { 2000 //Draw Dots - data comes in as array("title",x,y1,y2,y3,...); 2001 reset($this->data_values); 2002 while (list($j, $row) = each($this->data_values)) { 2003 $color_index = 0; 2004 //foreach ($row as $v) 2005 while (list($k, $v) = each($row)) { 2006 if ($k == 0) { 2007 } elseif (($k == 1) && ($this->data_type == "data-data")) { 2008 $xpos = $v; 2009 } else { 2010 if ($this->data_type == "text-data") { 2011 $xpos = ($j+.5); 2012 } 2013 if ($color_index >= count($this->ndx_data_color)) $color_index=0; 2014 $barcol = $this->ndx_data_color[$color_index]; 2015 2016 //if (is_numeric($v)) //PHP4 only 2017 if ((strval($v) != "") ) { //Allow for missing Y data 2018 $this->DrawDot($xpos,$v,$this->point_shape,$barcol); 2019 } 2020 $color_index++; 2021 } 2022 } 2023 } 2024 2025 } //function DrawDots 2026 2027 function DrawDotSeries() { 2028 //Depreciated: Use DrawDots 2029 $this->DrawDots(); 2030 } 2031 2032 function DrawThinBarLines() { 2033 //A clean,fast routine for when you just want charts like stock volume charts 2034 //Data must be text-data since I didn't see a graphing need for equally spaced thin lines. 2035 //If you want it - then write to afan@jeo.net and I might add it. 2036 2037 if ($this->data_type != "data-data") { $this->DrawError('Data Type for ThinBarLines must be data-data'); }; 2038 $y1 = $this->ytr($this->x_axis_position); 2039 2040 reset($this->data_values); 2041 while (list(, $row) = each($this->data_values)) { 2042 $color_index = 0; 2043 while (list($k, $v) = each($row)) { 2044 if ($k == 0) { 2045 $xlab = $v; 2046 } elseif ($k == 1) { 2047 $xpos = $this->xtr($v); 2048 if ( ($this->draw_x_data_labels == 1) ) { //See "labels_note1 above. 2049 $this->DrawXDataLabel($xlab,$xpos); 2050 } 2051 } else { 2052 if ($color_index >= count($this->ndx_data_color)) $color_index=0; 2053 $barcol = $this->ndx_data_color[$color_index]; 2054 2055 ImageLine($this->img,$xpos,$y1,$xpos,$this->ytr($v),$barcol); 2056 $color_index++; 2057 } 2058 } 2059 } 2060 2061 } //function DrawThinBarLines 2062 2063 function DrawYErrorBar($x_world,$y_world,$error_height,$error_bar_type,$color) { 2064 $x1 = $this->xtr($x_world); 2065 $y1 = $this->ytr($y_world); 2066 $y2 = $this->ytr($y_world+$error_height) ; 2067 2068 for ($width = 0; $width < $this->error_bar_line_width; $width++) { 2069 ImageLine($this->img, $x1+$width, $y1 , $x1+$width, $y2, $color); 2070 ImageLine($this->img, $x1-$width, $y1 , $x1-$width, $y2, $color); 2071 } 2072 switch ($error_bar_type) { 2073 case "line": 2074 break; 2075 case "tee": 2076 ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color); 2077 break; 2078 default: 2079 ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color); 2080 break; 2081 } 2082 return true; 2083 } 2084 2085 function DrawDot($x_world,$y_world,$dot_type,$color) { 2086 $half_point = $this->point_size / 2; 2087 $x1 = $this->xtr($x_world) - $half_point; 2088 $x2 = $this->xtr($x_world) + $half_point; 2089 $y1 = $this->ytr($y_world) - $half_point; 2090 $y2 = $this->ytr($y_world) + $half_point; 2091 2092 switch ($dot_type) { 2093 case "halfline": 2094 ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $this->xtr($x_world), $this->ytr($y_world), $color); 2095 break; 2096 case "line": 2097 ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $x2, $this->ytr($y_world), $color); 2098 break; 2099 case "rect": 2100 ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color); 2101 break; 2102 case "circle": 2103 ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color); 2104 break; 2105 case "dot": 2106 ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color); 2107 ImageFillToBorder($this->img, $x1 + $half_point, $y1 + $half_point, $color, $color); 2108 break; 2109 case "diamond": 2110 2111 $arrpoints = array( 2112 $x1,$y1 + $half_point, 2113 $x1 + $half_point, $y1, 2114 $x2,$y1 + $half_point, 2115 $x1 + $half_point, $y2 2116 ); 2117 2118 ImageFilledPolygon($this->img, $arrpoints, 4, $color); 2119 break; 2120 case "triangle": 2121 $arrpoints = array( $x1, $y1 + $half_point, 2122 $x2, $y1 + $half_point, 2123 $x1 + $half_point, $y2 2124 ); 2125 ImageFilledPolygon($this->img, $arrpoints, 3, $color); 2126 break; 2127 default: 2128 ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color); 2129 break; 2130 } 2131 return true; 2132 } 2133 2134 function SetErrorBarLineWidth($which_seblw) { 2135 $this->error_bar_line_width = $which_seblw; 2136 return true; 2137 } 2138 2139 2140 function SetLineWidth($which_lw) { 2141 $this->line_width = $which_lw; 2142 if (!$this->error_bar_line_width) { 2143 $this->error_bar_line_width = $which_lw; 2144 } 2145 return true; 2146 } 2147 2148 function DrawArea() { 2149 //Data comes in as $data[]=("title",x,y,...); 2150 //Set first and last datapoints of area 2151 $i = 0; 2152 while ($i < $this->records_per_group) { 2153 $posarr[$i][] = $this->xtr($this->min_x); //x initial 2154 $posarr[$i][] = $this->ytr($this->x_axis_position); //y initial 2155 $i++; 2156 } 2157 2158 reset($this->data_values); 2159 while (list($j, $row) = each($this->data_values)) { 2160 $color_index = 0; 2161 //foreach ($row as $v) 2162 while (list($k, $v) = each($row)) { 2163 if ($k == 0) { 2164 //Draw Data Labels 2165 $xlab = SubStr($v,0,$this->x_datalabel_maxlength); 2166 } elseif ($k == 1) { 2167 $x = $this->xtr($v); 2168 // DrawXDataLabel interferes with Numbers on x-axis 2169 //$this->DrawXDataLabel($xlab,$x); 2170 } else { 2171 // Create Array of points for later 2172 2173 $y = $this->ytr($v); 2174 $posarr[$color_index][] = $x; 2175 $posarr[$color_index][] = $y; 2176 $color_index++; 2177 } 2178 } 2179 } 2180 2181 //Final_points 2182 for ($i = 0; $i < $this->records_per_group; $i++) { 2183 $posarr[$i][] = $this->xtr($this->max_x); //x final 2184 $posarr[$i][] = $this->ytr($this->x_axis_position); //y final 2185 } 2186 2187 $color_index=0; 2188 2189 //foreach($posarr as $row) 2190 reset($posarr); 2191 while (list(, $row) = each($posarr)) { 2192 if ($color_index >= count($this->ndx_data_color)) $color_index=0; 2193 $barcol = $this->ndx_data_color[$color_index]; 2194 //echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br>"; 2195 ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol); 2196 $color_index++; 2197 } 2198 //exit; 2199 2200 } 2201 2202 function DrawAreaSeries() { 2203 2204 //Set first and last datapoints of area 2205 $i = 0; 2206 while ($i < $this->records_per_group) { 2207 $posarr[$i][] = $this->xtr(.5); //x initial 2208 $posarr[$i][] = $this->ytr($this->x_axis_position); //y initial 2209 $i++; 2210 } 2211 2212 reset($this->data_values); 2213 while (list($j, $row) = each($this->data_values)) { 2214 $color_index = 0; 2215 //foreach ($row as $v) 2216 while (list($k, $v) = each($row)) { 2217 if ($k == 0) { 2218 //Draw Data Labels 2219 $xlab = SubStr($v,0,$this->x_datalabel_maxlength); 2220 $this->DrawXDataLabel($xlab,$this->xtr($j + .5)); 2221 } else { 2222 // Create Array of points for later 2223 2224 $x = round($this->xtr($j + .5 )); 2225 $y = round($this->ytr($v)); 2226 $posarr[$color_index][] = $x; 2227 $posarr[$color_index][] = $y; 2228 $color_index++; 2229 } 2230 } 2231 } 2232 2233 //Final_points 2234 for ($i = 0; $i < $this->records_per_group; $i++) { 2235 $posarr[$i][] = round($this->xtr($this->max_x + .5)); //x final 2236 $posarr[$i][] = $this->ytr($this->x_axis_position); //y final 2237 } 2238 2239 $color_index=0; 2240 2241 //foreach($posarr as $row) 2242 reset($posarr); 2243 while (list(, $row) = each($posarr)) { 2244 if ($color_index >= count($this->ndx_data_color)) $color_index=0; 2245 $barcol = $this->ndx_data_color[$color_index]; 2246 //echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br>"; 2247 ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol); 2248 $color_index++; 2249 } 2250 2251 } 2252 2253 function DrawLines() { 2254 //Data comes in as $data[]=("title",x,y,...); 2255 $start_lines = 0; 2256 if ($this->data_type == "text-data") { 2257 $lastx[0] = $this->xtr(0); 2258 $lasty[0] = $this->xtr(0); 2259 } 2260 2261 //foreach ($this->data_values as $row) 2262 reset($this->data_values); 2263 while (list($j, $row) = each($this->data_values)) { 2264 2265 $color_index = 0; 2266 $i = 0; 2267 //foreach ($row as $v) 2268 while (list($k, $v) = each($row)) { 2269 if ($k == 0) { 2270 $xlab = SubStr($v,0,$this->x_datalabel_maxlength); 2271 } elseif (($k == 1) && ($this->data_type == "data-data")) { 2272 $x_now = $this->xtr($v); 2273 } else { 2274 //(double) $v; 2275 // Draw Lines 2276 if ($this->data_type == "text-data") { 2277 $x_now = $this->xtr($j+.5); 2278 } 2279 2280 //if (is_numeric($v)) //PHP4 only 2281 if ((strval($v) != "") ) { //Allow for missing Y data 2282 $y_now = $this->ytr($v); 2283 if ($color_index >= count($this->ndx_data_color)) { $color_index=0;} ; 2284 $barcol = $this->ndx_data_color[$color_index]; 2285 2286 if ($start_lines == 1) { 2287 for ($width = 0; $width < $this->line_width; $width++) { 2288 if ($this->line_style[$i] == "dashed") { 2289 $this->DrawDashedLine($x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, 4,4, $barcol); 2290 } else { 2291 ImageLine($this->img, $x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, $barcol); 2292 } 2293 } 2294 } 2295 $lastx[$i] = $x_now; 2296 } else { 2297 $y_now = $lasty[$i]; 2298 //Don't increment lastx[$i] 2299 } 2300 //$bordercol = $this->ndx_data_border_color[$colbarcount]; 2301 2302 $lasty[$i] = $y_now; 2303 $color_index++; 2304 $i++; 2305 } 2306 //Now we are assured an x_value 2307 if ( ($this->draw_x_data_labels == 1) && ($k == 1) ) { //See "labels_note1 above. 2308 $this->DrawXDataLabel($xlab,$x_now); 2309 } 2310 } //while rows of data 2311 $start_lines = 1; 2312 } 2313 } 2314 2315 //Data comes in as $data[]=("title",x,y,e+,e-,y2,e2+,e2-,...); 2316 2317 function DrawLineSeries() { 2318 //This function is replaced by DrawLines 2319 //Tests have shown not much improvement in speed by having separate routines for DrawLineSeries and DrawLines 2320 //For ease of programming I have combined them 2321 return false; 2322 } //function DrawLineSeries 2323 2324 function DrawDashedLine($x1pix,$y1pix,$x2pix,$y2pix,$dash_length,$dash_space,$color) { 2325 //Code based on work by Ariel Garza and James Pine 2326 //I've decided to have this be in pixels only as a replacement for ImageLine 2327 //$x1pix = $this->xtr($x1); 2328 //$y1pix = $this->ytr($y1); 2329 //$x2pix = $this->xtr($x2); 2330 //$y2pix = $this->ytr($y2); 2331 2332 // Get the length of the line in pixels 2333 $line_length = ceil (sqrt(pow(($x2pix - $x1pix),2) + pow(($y2pix - $y1pix),2)) ); 2334 2335 $dx = ($x2pix - $x1pix) / $line_length; 2336 $dy = ($y2pix - $y1pix) / $line_length; 2337 $lastx = $x1pix; 2338 $lasty = $y1pix; 2339 2340 // Draw the dashed line 2341 for ($i = 0; $i < $line_length; $i += ($dash_length + $dash_space)) { 2342 $xpix = ($dash_length * $dx) + $lastx; 2343 $ypix = ($dash_length * $dy) + $lasty; 2344 2345 ImageLine($this->img,$lastx,$lasty,$xpix,$ypix,$color); 2346 $lastx = $xpix + ($dash_space * $dx); 2347 $lasty = $ypix + ($dash_space * $dy); 2348 } 2349 } // function DrawDashedLine 2350 2351 function DrawBars() { 2352 2353 if ($this->data_type != "text-data") { 2354 $this->DrawError('Bar plots must be text-data: use function SetDataType("text-data")'); 2355 } 2356 2357 $xadjust = ($this->records_per_group * $this->record_bar_width )/4; 2358 2359 reset($this->data_values); 2360 while (list($j, $row) = each($this->data_values)) { 2361 2362 $color_index = 0; 2363 $colbarcount = 0; 2364 $x_now = $this->xtr($j+.5); 2365 2366 while (list($k, $v) = each($row)) { 2367 if ($k == 0) { 2368 //Draw Data Labels 2369 $xlab = SubStr($v,0,$this->x_datalabel_maxlength); 2370 $this->DrawXDataLabel($xlab,$x_now); 2371 } else { 2372 // Draw Bars ($v) 2373 $x1 = $x_now - $this->data_group_space + ($k-1)*$this->record_bar_width; 2374 $x2 = $x1 + $this->record_bar_width*$this->bar_width_adjust; 2375 2376 if ($v < $this->x_axis_position) { 2377 $y1 = $this->ytr($this->x_axis_position); 2378 $y2 = $this->ytr($v); 2379 } else { 2380 $y1 = $this->ytr($v); 2381 $y2 = $this->ytr($this->x_axis_position); 2382 } 2383 2384 if ($color_index >= count($this->ndx_data_color)) $color_index=0; 2385 if ($colbarcount >= count($this->ndx_data_border_color)) $colbarcount=0; 2386 $barcol = $this->ndx_data_color[$color_index]; 2387 $bordercol = $this->ndx_data_border_color[$colbarcount]; 2388 2389 if ((strval($v) != "") ) { //Allow for missing Y data 2390 if ($this->shading > 0) { 2391 for($i=0;$i<($this->shading);$i++) { 2392 //Shading set in SetDefaultColors 2393 ImageFilledRectangle($this->img, $x1+$i, $y1-$i, $x2+$i, $y2-$i, $this->ndx_i_light); 2394 } 2395 } 2396 2397 ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $barcol); 2398 ImageRectangle($this->img, $x1, $y1, $x2, $y2, $bordercol); 2399 if ($this->draw_data_labels == '1') { //ajo 2400 $y1 = $this->ytr($this->label_scale_position * $v); 2401 //$this->DrawDataLabel($v,$j + .5,$v*$this->label_scale_position); 2402 $this->DrawText($this->x_label_ttffont, $this->x_label_angle, 2403 $x1+$this->record_bar_width/2, $y1, $this->ndx_label_color, $this->x_label_ttffont_size, $v,'center','top'); 2404 } 2405 } 2406 2407 $color_index++; 2408 $colbarcount++; 2409 } 2410 } 2411 } 2412 } //function DrawBars 2413 2414 function DrawLegend($which_x1,$which_y1,$which_boxtype) { 2415 //Base code submitted by Marlin Viss 2416 $max_legend_length=0; 2417 reset($this->legend); 2418 while (list(,$leg) = each($this->legend)) { 2419 $len = strlen($leg); 2420 if ($max_legend_length < $len) { 2421 $max_legend_length = $len; 2422 } 2423 } 2424 2425 $line_spacing = 1.25; 2426 $vert_margin = $this->small_font_height/2 ; 2427 $dot_height = $this->small_font_height*$line_spacing - 1; 2428 2429 //Upper Left 2430 if ((!$which_x1) || (!$which_y1) ) { 2431 $box_start_x = $this->plot_area[2] - $this->small_font_width*($max_legend_length+4); 2432 $box_start_y = $this->plot_area[1] + 4; 2433 } else { 2434 $box_start_x = $which_x1; 2435 $box_start_y = $which_y1; 2436 } 2437 2438 //Lower Right 2439 $box_end_y = $box_start_y + $this->small_font_height*(count($this->legend)+1) + 2*$vert_margin; 2440 //$box_end_x = $this->plot_area[2] - 5; 2441 $box_end_x = $box_start_x + $this->small_font_width*($max_legend_length+4) - 5; 2442 2443 2444 // Draw box for legend 2445 ImageFilledRectangle($this->img, 2446 $box_start_x, $box_start_y,$box_end_x, 2447 $box_end_y, $this->ndx_bg_color); 2448 ImageRectangle($this->img, 2449 $box_start_x, $box_start_y,$box_end_x, 2450 $box_end_y, $this->ndx_grid_color); 2451 2452 $color_index=0; 2453 $i = 0; 2454 2455 2456 reset($this->legend); 2457 2458 2459 while (list(,$leg) = each($this->legend)) { 2460 $y_pos = $box_start_y + $this->small_font_height*($i)*($line_spacing) + $vert_margin; 2461 2462 ImageString($this->img, $this->small_font, 2463 $box_start_x + $this->small_font_width*( $max_legend_length - strlen($leg) + 1 ) , 2464 $y_pos, 2465 $leg, $this->ndx_text_color); 2466 2467 if ($color_index >= count($this->ndx_data_color)) $color_index=0; 2468 // Draw a box in the data color 2469 ImageFilledRectangle($this->img, 2470 $box_end_x - $this->small_font_width*2, 2471 $y_pos + 1, $box_end_x - $this->small_font_width, 2472 $y_pos + $dot_height, 2473 $this->ndx_data_color[$color_index]); 2474 2475 ImageRectangle($this->img, 2476 $box_end_x - $this->small_font_width*2, 2477 $y_pos + 1, $box_end_x - $this->small_font_width, 2478 $y_pos + $dot_height, 2479 $this->ndx_text_color); 2480 $i++; 2481 $color_index++; 2482 } 2483 } //function DrawLegend 2484 2485 2486 function DrawGraph() { 2487 2488 if (($this->img) == "") { 2489 $this->DrawError('No Image Defined: DrawGraph'); 2490 //$this->PHPlot(); 2491 } 2492 2493 if (! is_array($this->data_values)) { 2494 $this->DrawBackground(); 2495 $this->DrawError("No array of data in \$data_values"); 2496 } else { 2497 if (!$this->data_color) { 2498 $this->SetDataColors(array('blue','green','yellow','red','orange','blue'),array('black')); 2499 } 2500 2501 $this->FindDataLimits(); //Get maxima and minima for scaling 2502 2503 $this->SetXLabelHeight(); //Get data for bottom margin 2504 2505 $this->SetYLabelWidth(); //Get data for left margin 2506 2507 if (!$this->plot_area_width) { 2508 $this->SetPlotAreaPixels('','','',''); //Set Margins 2509 } 2510 2511 if (!$this->plot_max_y) { //If not set by user call SetPlotAreaWorld, 2512 $this->SetPlotAreaWorld('','','',''); 2513 } 2514 2515 if ($this->data_type == "text-data") { 2516 $this->SetEqualXCoord(); 2517 } 2518 2519 $this->SetPointSize($this->point_size); 2520 2521 $this->DrawBackground(); 2522 $this->DrawImageBorder(); 2523 2524 $this->SetTranslation(); 2525 2526 if ($this->draw_plot_area_background == 1) { 2527 $this->DrawPlotAreaBackground(); 2528 } 2529 //$foo = "$this->max_y, $this->min_y, $new_miny, $new_maxy, $this->x_label_height"; 2530 //ImageString($this->img, 4, 20, 20, $foo, $this->ndx_text_color); 2531 2532 switch ($this->plot_type) { 2533 case "bars": 2534 $this->DrawPlotBorder(); 2535 $this->DrawLabels(); 2536 $this->DrawBars(); 2537 $this->DrawXAxis(); 2538 break; 2539 case "thinbarline": 2540 $this->DrawPlotBorder(); 2541 $this->DrawLabels(); 2542 $this->DrawThinBarLines(); 2543 break; 2544 case "lines": 2545 $this->DrawPlotBorder(); 2546 $this->DrawLabels(); 2547 if ( $this->data_type == "text-data") { 2548 $this->DrawLines(); 2549 } elseif ( $this->data_type == "data-data-error") { 2550 $this->DrawLinesError(); 2551 } else { 2552 $this->DrawLines(); 2553 } 2554 break; 2555 case "area": 2556 $this->DrawPlotBorder(); 2557 $this->DrawLabels(); 2558 if ( $this->data_type == "text-data") { 2559 $this->DrawAreaSeries(); 2560 } else { 2561 $this->DrawArea(); 2562 } 2563 break; 2564 case "linepoints": 2565 $this->DrawPlotBorder(); 2566 $this->DrawLabels(); 2567 if ( $this->data_type == "text-data") { 2568 $this->DrawLines(); 2569 $this->DrawDots(); 2570 } elseif ( $this->data_type == "data-data-error") { 2571 $this->DrawLinesError(); 2572 $this->DrawDotsError(); 2573 } else { 2574 $this->DrawLines(); 2575 $this->DrawDots(); 2576 } 2577 break; 2578 case "points"; 2579 $this->DrawPlotBorder(); 2580 $this->DrawLabels(); 2581 if ( $this->data_type == "text-data") { 2582 $this->DrawDots(); 2583 } elseif ( $this->data_type == "data-data-error") { 2584 $this->DrawDotsError(); 2585 } else { 2586 $this->DrawDots(); 2587 } 2588 break; 2589 case "pie": 2590 $this->DrawPieChart(); 2591 $this->DrawLabels(); 2592 break; 2593 default: 2594 $this->DrawPlotBorder(); 2595 $this->DrawLabels(); 2596 $this->DrawBars(); 2597 break; 2598 } 2599 2600 if ($this->legend) { 2601 $this->DrawLegend($this->legend_x_pos,$this->legend_y_pos,''); 2602 } 2603 2604 } 2605 if ($this->print_image == 1) { 2606 $this->PrintImage(); 2607 } 2608 } //function DrawGraph 2609 2610 } 2611 2612 // $graph = new PHPlot; 2613 2614 // $graph->DrawGraph(); 2615 2616 ?>
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 |
![]() |