[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/includes/classes/ -> phplot.php (source)

   1  <?php
   2  /*

   3  $Id: phplot.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  

  12    PHPLOT 4.4.6 Copyright 2006 osCMax1998-2001 Afan Ottenheimer

  13  */
  14  
  15  class PHPlot{
  16  
  17      var $is_inline = 0;            //0 = Sends headers, 1 = sends just raw image data

  18      var $browser_cache = '1';    // 0 = Sends headers for browser to not cache the image, (i.e. 0 = don't let browser cache image)

  19                                      // (only if is_inline = 0 also)

  20      var $session_set = '';        //Do not change

  21      var $scale_is_set = '';        //Do not change

  22      var $draw_plot_area_background = '';
  23  
  24      var $image_width;    //Total Width in Pixels 

  25      var $image_height;     //Total Height in Pixels

  26      var $image_border_type = ''; //raised, plain, ''

  27      var $x_left_margin;
  28      var $y_top_margin;
  29      var $x_right_margin;
  30      var $y_bot_margin;
  31      var $plot_area = array(5,5,600,400);
  32      var $x_axis_position = 0;    //Where to draw the X_axis (world coordinates)

  33      var $y_axis_position = '';  //Leave blank for Y axis at left of plot. (world coord.)

  34      var $xscale_type = 'linear';  //linear or log

  35      var $yscale_type = 'linear';
  36  
  37  //Use for multiple plots per image

  38      var $print_image = 1;  //Used for multiple charts per image. 

  39  
  40  //Fonts

  41      var $use_ttf  = 0;          //Use TTF fonts (1) or not (0)

  42      var $font_path = './';  //To be added 

  43      var $font = './benjamingothic.ttf';
  44  
  45      ///////////Fonts: Small/Generic

  46      var $small_ttffont_size = 12; //

  47      //non-ttf

  48      var $small_font = 2; // fonts = 1,2,3,4 or 5

  49      var $small_font_width = 6.0; // width in pixels (2=6,3=8,4=8)

  50      var $small_font_height = 8.0; // height in pixels (2=8,3=10,4=12)

  51  
  52      //////////   Fonts:Title

  53      var $title_ttffont = './benjamingothic.ttf';
  54      var $title_ttffont_size = 14;
  55      var $title_angle= 0;
  56      //non-ttf

  57      var $title_font = '4'; // fonts = 1,2,3,4,5

  58  
  59      //////////////  Fonts:Axis

  60      var $axis_ttffont = './benjamingothic.ttf';
  61      var $axis_ttffont_size = 8;
  62      var $x_datalabel_angle = 0;
  63      //non-ttf

  64      var $axis_font = 2;
  65  
  66      ////////////////Fonts:Labels of Data

  67      var $datalabel_font = '2';
  68  
  69      //////////////// Fonts:Labels (Axis Titles)

  70      var $x_label_ttffont = './benjamingothic.ttf';
  71      var $x_label_ttffont_size = '12';
  72      var $x_label_angle = '0';
  73  
  74      var $y_label_ttffont = './benjamingothic.ttf';
  75      var $y_label_ttffont_size = '12';
  76      var $y_label_angle = 90;
  77      var $y_label_width = '';
  78  
  79  //Formats

  80      var $file_format = 'png';
  81      var $file_name = '';  //For output to a file instead of stdout

  82  
  83  //Plot Colors

  84      var $shading = 0;
  85      var $color_array = 1;    //1 = include small list

  86                              //2 = include large list

  87                              //array =  define your own color translation. See rgb.inc.php and SetRGBArray

  88      var $bg_color;
  89      var $plot_bg_color;
  90      var $grid_color;
  91      var $light_grid_color;
  92      var $tick_color;
  93      var $title_color;
  94      var $label_color;
  95      var $text_color;
  96      var $i_light = '';
  97  
  98  //Data

  99      var $data_type = 'text-data'; //text-data, data-data-error, data-data 

 100      var $plot_type= 'linepoints'; //bars, lines, linepoints, area, points, pie, thinbarline

 101      var $line_width = 2;
 102      var $line_style = array('solid','solid','solid','dashed','dashed','solid'); //Solid or dashed lines

 103  
 104      var $data_color = ''; //array('blue','green','yellow',array(0,0,0));

 105      var $data_border_color = '';
 106  
 107      var $label_scale_position = '.5';  //1 = top, 0 = bottom

 108      var $group_frac_width = '.7'; //value from 0 to 1 = width of bar

 109      var $bar_width_adjust = '1'; //1 = bars of normal width, must be > 0

 110  
 111      var $point_size = 10;
 112      var $point_shape = 'diamond'; //rect,circle,diamond,triangle,dot,line,halfline

 113      var $error_bar_shape = 'tee'; //tee, line

 114      var $error_bar_size = 5; //right left size of tee

 115      var $error_bar_line_width = ''; //If set then use it, else use $line_width for thickness

 116      var $error_bar_color = ''; 
 117      var $data_values;
 118  
 119      var $plot_border_type = 'full'; //left, none, full

 120      var $plot_area_width = '';
 121      var $number_x_points;
 122      var $plot_min_x; // Max and min of the plot area

 123      var $plot_max_x= ''; // Max and min of the plot area

 124      var $plot_min_y= ''; // Max and min of the plot area

 125      var $plot_max_y = ''; // Max and min of the plot area

 126      var $min_y = '';
 127      var $max_y = '';
 128      var $max_x = 10;  //Must not be = 0;

 129      var $y_precision = '1';
 130      var $x_precision = '1';
 131      var $si_units = '';
 132  
 133  //Labels

 134      var $draw_data_labels = '0';  
 135      var $legend = '';  //an array

 136      var $legend_x_pos = '';
 137      var $legend_y_pos = '';
 138      var $title_txt = "";
 139      var $y_label_txt = '';
 140      var $x_label_txt = "";
 141  
 142  //DataAxis Labels (on each axis)

 143      var $y_grid_label_type = 'data';    //data, none, time, other

 144      var $y_grid_label_pos = 'plotleft'; //plotleft, plotright, yaxis, both

 145      var $x_grid_label_type = 'data';    //data, title, none, time, other

 146      var $draw_x_data_labels = '';       // 0=false, 1=true, ""=let program decide 

 147      var $x_time_format = "%H:%m:%s";    //See http://www.php.net/manual/html/function.strftime.html

 148      var $x_datalabel_maxlength = 10;    
 149  
 150  //Tick Formatting

 151      var $tick_length = '10';   //pixels: tick length from axis left/downward

 152      //tick_length2 to be implemented

 153      //var $tick_length2 = '';  //pixels: tick length from axis line rightward/upward

 154      var $draw_vert_ticks = 1;  //1 = draw ticks, 0 = don't draw ticks

 155      var $num_vert_ticks = '';
 156      var $vert_tick_increment=''; //Set num_vert_ticks or vert_tick_increment, not both.

 157      var $vert_tick_position = 'both'; //plotright=(right of plot only), plotleft=(left of plot only), 

 158                                  //both = (both left and right of plot), yaxis=(crosses y axis)

 159      var $horiz_tick_increment=''; //Set num_horiz_ticks or horiz_tick_increment, not both.

 160      var $num_horiz_ticks='';
 161      var $skip_top_tick = '0';
 162      var $skip_bottom_tick = '0';
 163  
 164  //Grid Formatting

 165      var $draw_x_grid = 0;
 166      var $draw_y_grid = 1;
 167  
 168  
 169  //BEGIN CODE

 170  //////////////////////////////////////////////////////

 171      //Constructor: Setup Img pointer, Colors and Size of Image

 172  	function PHPlot($which_width=600,$which_height=400,$which_output_file="",$which_input_file="") {
 173  
 174          $this->SetRGBArray('2'); 
 175          $this->background_done = 0; //Set to 1 after background image first drawn

 176  
 177          if ($which_output_file != "") { $this->SetOutputFile($which_output_file);  };
 178  
 179          if ($which_input_file != "") { 
 180              $this->SetInputFile($which_input_file) ; 
 181          } else { 
 182              $this->SetImageArea($which_width, $which_height);
 183              $this->InitImage();
 184          }
 185  
 186          if ( ($this->session_set == 1) && ($this->img == "") ) {  //For sessions
 187              //Do nothing

 188          } else { 
 189              $this->SetDefaultColors();
 190          }
 191  
 192          $this->SetIndexColors();
 193  
 194      }
 195          
 196      //Set up the image and colors

 197  	function InitImage() {
 198          //if ($this->img) { 

 199          //    ImageDestroy($this->img);

 200          //}

 201          $this->img = ImageCreate($this->image_width, $this->image_height);
 202          return true;
 203      }
 204  
 205  	function SetBrowserCache($which_browser_cache) {  //Submitted by Thiemo Nagel
 206          $this->browser_cache = $which_browser_cache;
 207          return true;
 208      }
 209  
 210  	function SetPrintImage($which_pi) {
 211          $this->print_image = $which_pi;
 212          return true;
 213      }
 214  
 215  	function SetIsInline($which_ii) {
 216          $this->is_inline = $which_ii;
 217          return true;
 218      }
 219  
 220  	function SetUseTTF($which_ttf) {
 221          $this->use_ttf = $which_ttf;
 222          return true;
 223      }
 224  
 225  	function SetTitleFontSize($which_tfs) {
 226          //TTF

 227          $this->title_ttffont_size = $which_tfs; //pt size

 228  
 229          //Non-TTF settings

 230          if (($which_tfs > 5) && (!$this->use_ttf)) {
 231              $this->DrawError('Non-TTF font size must be 1,2,3,4 or 5');
 232              return false;
 233          } else {
 234              $this->title_font = $which_tfs;
 235              //$this->title_font_height = ImageFontHeight($which_tfs) // height in pixels 

 236              //$this->title_font_width = ImageFontWidth($which_tfs); // width in pixels 

 237          }
 238          return true;
 239      }
 240  
 241  	function SetLineStyles($which_sls){
 242          $this->line_style = $which_sls;
 243          return true;
 244      }
 245  
 246  	function SetLegend($which_leg){
 247          if (is_array($which_leg)) { 
 248              $this->legend = $which_leg;
 249              return true;
 250          } else { 
 251              $this->DrawError('Error: SetLegend argument must be an array');
 252              return false;
 253          }
 254      }
 255  
 256  	function SetLegendPixels($which_x,$which_y,$which_type) { 
 257          //which_type not yet used

 258          $this->legend_x_pos = $which_x;
 259          $this->legend_y_pos = $which_y;
 260          return true;
 261      }
 262  
 263  	function SetLegendWorld($which_x,$which_y,$which_type='') { 
 264          //which_type not yet used

 265          //Must be called after scales are set up. 

 266          if ($this->scale_is_set != 1) { $this->SetTranslation(); };
 267          $this->legend_x_pos = $this->xtr($which_x);
 268          $this->legend_y_pos = $this->ytr($which_y);
 269          return true;
 270      }
 271  /* ***************************************

 272      function SetFileFormat($which_file_format) { //Only works with PHP4

 273          $asked = strtolower($which_file_format);

 274          if( $asked =="jpg" || $asked =="png" || $asked =="gif" || $asked =="wbmp" ) {

 275              if( $asked=="jpg" && !(imagetypes() & IMG_JPG) )

 276                  return false;

 277              elseif( $asked=="png" && !(imagetypes() & IMG_PNG) ) 

 278                  return false;

 279              elseif( $asked=="gif" && !(imagetypes() & IMG_GIF) )     

 280                  return false;

 281              elseif( $asked=="wbmp" && !(imagetypes() & IMG_WBMP) )     

 282                  return false;

 283              else {

 284                  $this->img_format=$asked;

 285                  return true;

 286              }

 287          }

 288          else

 289              return false;

 290      }    

 291  

 292  *************************************** */
 293  	function SetFileFormat($which_file_format) {
 294      //eventually test to see if that is supported - if not then return false

 295          $asked = strtolower(trim($which_file_format));
 296          if( ($asked=='jpg') || ($asked=='png') || ($asked=='gif') || ($asked=='wbmp') ) {
 297              $this->file_format = $asked;
 298              return true;
 299          } else {
 300              return false;
 301          }
 302      }
 303  
 304  	function SetInputFile($which_input_file) { 
 305          //$this->SetFileFormat($which_frmt);

 306          $size = GetImageSize($which_input_file);
 307          $input_type = $size[2]; 
 308  
 309          switch($input_type) {  //After SetFileFormat is in lower case
 310              case "1":
 311                  $im = @ImageCreateFromGIF ($which_input_file);
 312                  if (!$im) { // See if it failed 
 313                      $this->PrintError("Unable to open $which_input_file as a GIF");
 314                      return false;
 315                  }
 316              break;
 317              case "3":
 318                  $im = @ImageCreateFromPNG ($which_input_file); 
 319                  if (!$im) { // See if it failed 
 320                      $this->PrintError("Unable to open $which_input_file as a PNG");
 321                      return false;
 322                  }
 323              break;
 324              case "2":
 325                  $im = @ImageCreateFromJPEG ($which_input_file); 
 326                  if (!$im) { // See if it failed 
 327                      $this->PrintError("Unable to open $which_input_file as a JPG");
 328                      return false;
 329                  }
 330              break;
 331              default:
 332                  $this->PrintError('Please select wbmp,gif,jpg, or png for image type!');
 333                  return false;
 334              break;
 335          }
 336  
 337          //Get Width and Height of Image

 338          $this->SetImageArea($size[0],$size[1]);
 339  
 340          $this->img = $im;
 341  
 342          return true;
 343  
 344      }
 345  
 346  	function SetOutputFile($which_output_file) { 
 347          $this->output_file = $which_output_file;
 348          return true;
 349      }
 350  
 351  	function SetImageArea($which_iw,$which_ih) {
 352          //Note this is now an Internal function - please set w/h via PHPlot()

 353          $this->image_width = $which_iw;
 354          $this->image_height = $which_ih;
 355  
 356          return true;
 357      }
 358  
 359  
 360  	function SetYAxisPosition($which_pos) {
 361          $this->y_axis_position = $which_pos;
 362          return true;
 363      }
 364  	function SetXAxisPosition($which_pos) {
 365          $this->x_axis_position = $which_pos;
 366          return true;
 367      }
 368  	function SetXTimeFormat($which_xtf) {
 369          $this->x_time_format = $which_xtf;
 370          return true;
 371      }
 372  	function SetXDataLabelMaxlength($which_xdlm) { 
 373          if ($which_xdlm >0 ) { 
 374              $this->x_datalabel_maxlength = $which_xdlm;
 375              return true;
 376          } else { 
 377              return false;
 378          }
 379      }
 380  	function SetXDataLabelAngle($which_xdla) { 
 381          $this->x_datalabel_angle = $which_xdla;
 382          return true;
 383      }
 384  	function SetXScaleType($which_xst) { 
 385          $this->xscale_type = $which_xst;
 386          return true;
 387      }
 388  	function SetYScaleType($which_yst) { 
 389          $this->yscale_type = $which_yst;
 390          if ($this->x_axis_position <= 0) { 
 391              $this->x_axis_position = 1;
 392          }
 393          return true;
 394      }
 395  
 396  	function SetPrecisionX($which_prec) {
 397          $this->x_precision = $which_prec;
 398          return true;
 399      }
 400  	function SetPrecisionY($which_prec) {
 401          $this->y_precision = $which_prec;
 402          return true;
 403      }
 404  
 405  
 406  	function SetIndexColors() { //Internal Method called to set colors and preserve state
 407          //These are the colors of the image that are used. They are initialized

 408          //to work with sessions and PHP. 

 409  
 410          $this->ndx_i_light = $this->SetIndexColor($this->i_light);
 411          $this->ndx_i_dark  = $this->SetIndexColor($this->i_dark);
 412          $this->ndx_bg_color= $this->SetIndexColor($this->bg_color);
 413          $this->ndx_plot_bg_color= $this->SetIndexColor($this->plot_bg_color);
 414  
 415          $this->ndx_title_color= $this->SetIndexColor($this->title_color);
 416          $this->ndx_tick_color= $this->SetIndexColor($this->tick_color);
 417          $this->ndx_label_color= $this->SetIndexColor($this->label_color);
 418          $this->ndx_text_color= $this->SetIndexColor($this->text_color);
 419          $this->ndx_light_grid_color= $this->SetIndexColor($this->light_grid_color);
 420          $this->ndx_grid_color= $this->SetIndexColor($this->grid_color);
 421  
 422          reset($this->error_bar_color);  
 423          unset($ndx_error_bar_color);
 424          $i = 0; 
 425          while (list(, $col) = each($this->error_bar_color)) {
 426            $this->ndx_error_bar_color[$i] = $this->SetIndexColor($col);
 427              $i++;
 428          }
 429          //reset($this->data_border_color);

 430          unset($ndx_data_border_color);
 431          $i = 0;
 432          while (list(, $col) = each($this->data_border_color)) {
 433              $this->ndx_data_border_color[$i] = $this->SetIndexColor($col);
 434              $i++;
 435          }
 436          //reset($this->data_color); 

 437          unset($ndx_data_color);
 438          $i = 0;
 439          while (list(, $col) = each($this->data_color)) {
 440              $this->ndx_data_color[$i] = $this->SetIndexColor($col);
 441              $i++;
 442          }
 443  
 444          return true;
 445      }
 446  
 447  
 448  	function SetDefaultColors() {
 449  
 450          $this->i_light = array(194,194,194);
 451          $this->i_dark =  array(100,100,100);
 452          $this->SetPlotBgColor(array(222,222,222));
 453          $this->SetBackgroundColor(array(200,222,222)); //can use rgb values or "name" values

 454          $this->SetLabelColor('black');
 455          $this->SetTextColor('black');
 456          $this->SetGridColor('black');
 457          $this->SetLightGridColor(array(175,175,175));
 458          $this->SetTickColor('black');
 459          $this->SetTitleColor(array(0,0,0)); // Can be array or name

 460          $this->data_color = array('blue','green','yellow','red','orange');
 461          $this->error_bar_color = array('blue','green','yellow','red','orange');
 462          $this->data_border_color = array('black');
 463  
 464          $this->session_set = 1; //Mark it down for PHP session() usage.

 465      }
 466  
 467  	function PrintImage() {
 468  
 469          if ( ($this->browser_cache == 0) && ($this->is_inline == 0)) { //Submitted by Thiemo Nagel
 470              header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
 471              header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT');
 472              header('Cache-Control: no-cache, must-revalidate');
 473              header('Pragma: no-cache');
 474          }
 475  
 476          switch($this->file_format) {
 477              case "png":
 478                  if ($this->is_inline == 0) {
 479                      Header('Content-type: image/png');
 480                  }
 481                  if ($this->is_inline == 1 && $this->output_file != "") {
 482                      ImagePng($this->img,$this->output_file);
 483                  } else {
 484                      ImagePng($this->img);
 485                  }
 486                  break;
 487              case "jpg":
 488                  if ($this->is_inline == 0) {
 489                      Header('Content-type: image/jpeg');
 490                  }
 491                  if ($this->is_inline == 1 && $this->output_file != "") {
 492                      ImageJPEG($this->img,$this->output_file);
 493                  } else {
 494                      ImageJPEG($this->img);
 495                  }
 496                  break;
 497              case "gif":
 498                  if ($this->is_inline == 0) {
 499                      Header('Content-type: image/gif');
 500                  }
 501                  if ($this->is_inline == 1 && $this->output_file != "") {
 502                      ImageGIF($this->img,$this->output_file);
 503                  } else {
 504                      ImageGIF($this->img);
 505                  }
 506  
 507                  break;
 508              case "wbmp":
 509                  if ($this->is_inline == 0) {
 510                      Header('Content-type: image/wbmp');
 511                  }
 512                  if ($this->is_inline == 1 && $this->output_file != "") {
 513                      ImageWBMP($this->img,$this->output_file);
 514                  } else {
 515                      ImageWBMP($this->img);
 516                  }
 517  
 518                  break;
 519              default:
 520                  $this->PrintError('Please select an image type!<br>');
 521                  break;
 522          }
 523          ImageDestroy($this->img);
 524          return true;
 525      }
 526  
 527  
 528  	function DrawBackground() {
 529          //if ($this->img == "") { $this->InitImage(); };

 530          if ($this->background_done == 0) { //Don't draw it twice if drawing two plots on one image
 531              ImageFilledRectangle($this->img, 0, 0,
 532                  $this->image_width, $this->image_height, $this->ndx_bg_color);
 533              $this->background_done = 1;
 534          }
 535          return true;
 536      }
 537  
 538  	function DrawImageBorder() {
 539          switch ($this->image_border_type) {
 540              case "raised":
 541                  ImageLine($this->img,0,0,$this->image_width-1,0,$this->ndx_i_light);
 542                  ImageLine($this->img,1,1,$this->image_width-2,1,$this->ndx_i_light);
 543                  ImageLine($this->img,0,0,0,$this->image_height-1,$this->ndx_i_light);
 544                  ImageLine($this->img,1,1,1,$this->image_height-2,$this->ndx_i_light);
 545                  ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
 546                  ImageLine($this->img,0,$this->image_height-1,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
 547                  ImageLine($this->img,$this->image_width-2,1,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
 548                  ImageLine($this->img,1,$this->image_height-2,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
 549              break;
 550              case "plain":
 551                  ImageLine($this->img,0,0,$this->image_width,0,$this->ndx_i_dark);
 552                  ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height,$this->ndx_i_dark);
 553                  ImageLine($this->img,$this->image_width-1,$this->image_height-1,0,$this->image_height-1,$this->ndx_i_dark);
 554                  ImageLine($this->img,0,0,0,$this->image_height,$this->ndx_i_dark);
 555              break;
 556              default:
 557              break;
 558          }
 559          return true;
 560      }
 561  
 562  	function SetPlotBorderType($which_pbt) {
 563          $this->plot_border_type = $which_pbt; //left, none, anything else=full

 564      }
 565  
 566  	function SetImageBorderType($which_sibt) {
 567          $this->image_border_type = $which_sibt; //raised, plain

 568      }
 569  
 570  	function SetDrawPlotAreaBackground($which_dpab) {
 571          $this->draw_plot_area_background = $which_dpab;  // 1=true or anything else=false

 572      }
 573  
 574  	function SetDrawDataLabels($which_ddl) {  //Draw next to datapoints
 575          $this->draw_data_labels = $which_ddl;  // 1=true or anything else=false

 576      }
 577  
 578  	function SetDrawXDataLabels($which_dxdl) {  //Draw on X Axis
 579          $this->draw_x_data_labels = $which_dxdl;  // 1=true or anything else=false

 580      }
 581  
 582  	function SetDrawYGrid($which_dyg) {
 583          $this->draw_y_grid = $which_dyg;  // 1=true or anything else=false

 584      }
 585  
 586  	function SetDrawXGrid($which_dxg) {
 587          $this->draw_x_grid = $which_dxg;  // 1=true or anything else=false

 588      }
 589  
 590  	function SetYGridLabelType($which_yglt) {
 591          $this->y_grid_label_type = $which_yglt;
 592          return true;
 593      }
 594  
 595  	function SetXGridLabelType($which_xglt) {
 596          $this->x_grid_label_type = $which_xglt;
 597          return true;
 598      }
 599  
 600  	function SetXLabel($xlbl) {
 601          $this->x_label_txt = $xlbl;
 602          return true;
 603      }
 604  	function SetYLabel($ylbl) {
 605          $this->y_label_txt = $ylbl;
 606          return true;
 607      }
 608  	function SetTitle($title) {
 609          $this->title_txt = $title;
 610          return true;
 611      }
 612  
 613      //function SetLabels($xlbl,$ylbl,$title) {

 614      //    $this->title_txt = $title;

 615      //    $this->x_label_txt = $xlbl;

 616      //    $this->y_label_txt = $ylbl;

 617      //}

 618  
 619  	function DrawLabels() {
 620          $this->DrawTitle();
 621          $this->DrawXLabel();
 622          $this->DrawYLabel();
 623          return true;
 624      }
 625  
 626  	function DrawXLabel() {
 627          if ($this->use_ttf == 1) { 
 628              $xpos = $this->xtr(($this->plot_max_x + $this->plot_min_x)/2.0) ;
 629              $ypos = $this->ytr($this->plot_min_y) + $this->x_label_height/2.0;
 630              $this->DrawText($this->x_label_ttffont, $this->x_label_angle,
 631                  $xpos, $ypos, $this->ndx_label_color, $this->x_label_ttffont_size, $this->x_label_txt,'center');
 632          } else { 
 633              //$xpos = 0.0 - (ImageFontWidth($this->small_font)*strlen($this->x_label_txt)/2.0) + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ;

 634              $xpos = 0.0 + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ;
 635              $ypos = ($this->ytr($this->plot_min_y) + $this->x_label_height/2);
 636  
 637              $this->DrawText($this->small_font, $this->x_label_angle, 
 638                  $xpos, $ypos, $this->ndx_label_color, "", $this->x_label_txt, 'center');
 639  
 640          }
 641          return true;
 642      }
 643  
 644  	function DrawYLabel() {
 645          if ($this->use_ttf == 1) { 
 646              $size = $this->TTFBBoxSize($this->y_label_ttffont_size, 90, $this->y_label_ttffont, $this->y_label_txt);
 647              $xpos = 8 + $size[0];
 648              $ypos = ($size[1])/2 + $this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) ;
 649              $this->DrawText($this->y_label_ttffont, 90,
 650                  $xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
 651          } else { 
 652              $xpos = 8;
 653              $ypos = (($this->small_font_width*strlen($this->y_label_txt)/2.0) +
 654                      $this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) );
 655              $this->DrawText($this->small_font, 90,
 656                  $xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
 657          }
 658          return true;
 659      }
 660  
 661  	function DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left',$which_valign='') {
 662  
 663          if ($this->use_ttf == 1 ) { 
 664              $size = $this->TTFBBoxSize($which_size, $which_angle, $which_font, $which_text); 
 665              if ($which_valign == 'bottom') { 
 666                  $which_ypos = $which_ypos + ImageFontHeight($which_font);
 667              }
 668              if ($which_halign == 'center') { 
 669                  $which_xpos = $which_xpos - $size[0]/2;
 670              }
 671              ImageTTFText($this->img, $which_size, $which_angle, 
 672                  $which_xpos, $which_ypos, $which_color, $which_font, $which_text); 
 673          } else { 
 674              if ($which_valign == 'top') { 
 675                  $which_ypos = $which_ypos - ImageFontHeight($which_font);
 676              }
 677              $which_text = ereg_replace("\r","",$which_text);
 678              $str = split("\n",$which_text); //multiple lines submitted by Remi Ricard

 679              $height = ImageFontHeight($which_font);
 680              $width = ImageFontWidth($which_font);
 681              if ($which_angle == 90) {  //Vertical Code Submitted by Marlin Viss
 682                  for($i=0;$i<count($str);$i++) { 
 683                      ImageStringUp($this->img, $which_font, ($i*$height + $which_xpos), $which_ypos, $str[$i], $which_color);
 684                  } 
 685              } else {
 686                  for($i=0;$i<count($str);$i++) { 
 687                      if ($which_halign == 'center') { 
 688                          $xpos = $which_xpos - strlen($str[$i]) * $width/2;
 689                           ImageString($this->img, $which_font, $xpos, ($i*$height + $which_ypos), $str[$i], $which_color);
 690                      } else { 
 691                          ImageString($this->img, $which_font, $which_xpos, ($i*$height + $which_ypos), $str[$i], $which_color); 
 692                      }
 693                  } 
 694              }
 695  
 696          } 
 697          return true; 
 698  
 699      }
 700  	function DrawTitle() {
 701          if ($this->use_ttf == 1 ) { 
 702              $xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
 703              $ypos = $this->y_top_margin/2;
 704              $this->DrawText($this->title_ttffont, $this->title_angle, 
 705                  $xpos, $ypos, $this->ndx_title_color, $this->title_ttffont_size, $this->title_txt,'center'); 
 706          } else { 
 707              $xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
 708              $ypos = ImageFontHeight($this->title_font); 
 709              $this->DrawText($this->title_font, $this->title_angle, 
 710                  $xpos, $ypos, $this->ndx_title_color, '', $this->title_txt,'center'); 
 711          } 
 712          return true; 
 713  
 714      }
 715  
 716  	function DrawPlotAreaBackground() {
 717          ImageFilledRectangle($this->img,$this->plot_area[0],
 718              $this->plot_area[1],$this->plot_area[2],$this->plot_area[3],
 719              $this->ndx_plot_bg_color);
 720      }
 721  
 722  	function SetBackgroundColor($which_color) {
 723          $this->bg_color= $which_color;
 724          $this->ndx_bg_color= $this->SetIndexColor($which_color);
 725          return true;
 726      }
 727  	function SetPlotBgColor($which_color) {
 728          $this->plot_bg_color= $which_color;
 729          $this->ndx_plot_bg_color= $this->SetIndexColor($which_color);
 730          return true;
 731      }
 732  
 733  	function SetShading($which_s) { 
 734          $this->shading = $which_s;
 735          return true;
 736      }
 737  
 738  	function SetTitleColor($which_color) {
 739          $this->title_color= $which_color;
 740          $this->ndx_title_color= $this->SetIndexColor($which_color);
 741          return true;
 742      }
 743  
 744  	function SetTickColor ($which_color) {
 745          $this->tick_color= $which_color;
 746          $this->ndx_tick_color= $this->SetIndexColor($which_color);
 747          return true;
 748      }
 749  
 750  	function SetLabelColor ($which_color) {
 751          $this->label_color= $which_color;
 752          $this->ndx_label_color= $this->SetIndexColor($which_color);
 753          return true;
 754      }
 755  
 756  	function SetTextColor ($which_color) {
 757          $this->text_color= $which_color;
 758          $this->ndx_text_color= $this->SetIndexColor($which_color);
 759          return true;
 760      }
 761  
 762  	function SetLightGridColor ($which_color) {
 763          $this->light_grid_color= $which_color;
 764          $this->ndx_light_grid_color= $this->SetIndexColor($which_color);
 765          return true;
 766      }
 767  
 768  	function SetGridColor ($which_color) {
 769          $this->grid_color = $which_color;
 770          $this->ndx_grid_color= $this->SetIndexColor($which_color);
 771          return true;
 772      }
 773  
 774  	function SetCharacterHeight() {
 775          //to be set

 776          return true;
 777      }
 778  
 779  	function SetPlotType($which_pt) {
 780          $accepted = "bars,lines,linepoints,area,points,pie,thinbarline";
 781          $asked = trim($which_pt);
 782          if (eregi($asked, $accepted)) {
 783              $this->plot_type = $which_pt;
 784              return true;
 785          } else {
 786              $this->DrawError('$which_pt not an acceptable plot type');
 787              return false;
 788          }
 789      }
 790  
 791  	function FindDataLimits() {
 792          //Text-Data is different than data-data graphs. For them what

 793          // we have, instead of X values, is # of records equally spaced on data.

 794          //text-data is passed in as $data[] = (title,y1,y2,y3,y4,...)

 795          //data-data is passed in as $data[] = (title,x,y1,y2,y3,y4,...) 

 796  
 797          $this->number_x_points = count($this->data_values);
 798  
 799          switch ($this->data_type) {
 800              case "text-data":
 801                  $minx = 0; //valid for BAR TYPE GRAPHS ONLY

 802                  $maxx = $this->number_x_points - 1 ;  //valid for BAR TYPE GRAPHS ONLY

 803                  $miny = (double) $this->data_values[0][1];
 804                  $maxy = $miny;
 805                  if ($this->draw_x_data_labels == "") { 
 806                      $this->draw_x_data_labels = 1;  //labels_note1: prevent both data labels and x-axis labels being both drawn and overlapping

 807                  }
 808              break;
 809              default:  //Everything else: data-data, etc.
 810                  $maxx = $this->data_values[0][1];
 811                  $minx = $maxx;
 812                  $miny = $this->data_values[0][2];
 813                  $maxy = $miny;
 814                  $maxy = $miny;
 815              break;
 816          }
 817  
 818          $max_records_per_group = 0;
 819          $total_records = 0;
 820          $mine = 0; //Maximum value for the -error bar (assume error bars always > 0) 

 821          $maxe = 0; //Maximum value for the +error bar (assume error bars always > 0) 

 822  
 823          reset($this->data_values);
 824          while (list($dat_key, $dat) = each($this->data_values)) {  //for each X barchart setting
 825          //foreach($this->data_values as $dat)  //can use foreach only in php4

 826  
 827              $tmp = 0;
 828              $total_records += count($dat) - 1; // -1 for label

 829  
 830              switch ($this->data_type) {
 831                  case "text-data":
 832                      //Find the relative Max and Min

 833  
 834                      while (list($key, $val) = each($dat)) {
 835                          if ($key != 0) {  //$dat[0] = label
 836                              SetType($val,"double");
 837                              if ($val > $maxy) {
 838                                  $maxy = $val ;
 839                              }
 840                              if ($val < $miny) {
 841                                  $miny = (double) $val ;
 842                              }
 843                          }
 844                          $tmp++;
 845                      }
 846                  break;
 847                  case "data-data":  //X-Y data is passed in as $data[] = (title,x,y,y2,y3,...) which you can use for multi-dimentional plots.
 848  
 849                      while (list($key, $val) = each($dat)) {
 850                          if ($key == 1) {  //$dat[0] = label
 851                              SetType($val,"double");
 852                              if ($val > $maxx) {
 853                                  $maxx = $val;
 854                              } elseif ($val < $minx) {
 855                                  $minx = $val;
 856                              }
 857                          } elseif ($key > 1) {
 858                              SetType($val,"double");
 859                              if ($val > $maxy) {
 860                                  $maxy = $val ;
 861                              } elseif ($val < $miny) {
 862                                  $miny = $val ;
 863                              }
 864                          }
 865                          $tmp++;
 866                      }
 867                      $tmp = $tmp - 1; //# records per group

 868                  break;
 869                  case "data-data-error":  //Assume 2-D for now, can go higher
 870                  //Regular X-Y data is passed in as $data[] = (title,x,y,error+,error-,y2,error2+,error2-)

 871  
 872                      while (list($key, $val) = each($dat)) {
 873                          if ($key == 1) {  //$dat[0] = label
 874                              SetType($val,'double');
 875                              if ($val > $maxx) {
 876                                  $maxx = $val;
 877                              } elseif ($val < $minx) {
 878                                  $minx = $val;
 879                              }
 880                          } elseif ($key%3 == 2) {
 881                              SetType($val,'double');
 882                              if ($val > $maxy) {
 883                                  $maxy = $val ;
 884                              } elseif ($val < $miny) {
 885                                  $miny = $val ;
 886                              }
 887                          } elseif ($key%3 == 0) {
 888                              SetType($val,'double');
 889                              if ($val > $maxe) {
 890                                  $maxe = $val ;
 891                              }
 892                          } elseif ($key%3 == 1) {
 893                              SetType($val,'double');
 894                              if ($val > $mine) {
 895                                  $mine = $val ;
 896                              }
 897                          }
 898                          $tmp++;
 899                      }
 900                      $maxy = $maxy + $maxe;
 901                      $miny = $miny - $mine; //assume error bars are always > 0

 902  
 903                  break;
 904                  default:
 905                      $this->PrintError('ERROR: unknown chart type');
 906                  break;
 907              }
 908              if ($tmp > $max_records_per_group) {
 909                  $max_records_per_group = $tmp;
 910              }
 911          }
 912  
 913  
 914          $this->min_x = $minx;
 915          $this->max_x = $maxx;
 916          $this->min_y = $miny;
 917          $this->max_y = $maxy;
 918  
 919  
 920          if ($max_records_per_group > 1) {
 921              $this->records_per_group = $max_records_per_group - 1;
 922          } else {
 923              $this->records_per_group = 1;
 924          }
 925  
 926  
 927          //$this->data_count = $total_records ;

 928      } // function FindDataLimits

 929  
 930  	function SetMargins() {
 931          /////////////////////////////////////////////////////////////////

 932          // When the image is first created - set the margins

 933          // to be the standard viewport.

 934          // The standard viewport is the full area of the view surface (or panel),

 935          // less a margin of 4 character heights all round for labelling.

 936          // It thus depends on the current character size, set by SetCharacterHeight().

 937          /////////////////////////////////////////////////////////////////

 938  
 939          $str = split("\n",$this->title_txt); 
 940          $nbLines = count($str); 
 941  
 942          if ($this->use_ttf == 1) {
 943              $title_size = $this->TTFBBoxSize($this->title_ttffont_size, $this->title_angle, $this->title_ttffont, 'X'); //An array

 944              if ($nbLines == 1) { 
 945                  $this->y_top_margin = $title_size[1] * 4;
 946              } else { 
 947                  $this->y_top_margin = $title_size[1] * ($nbLines+3);
 948              }
 949  
 950              //ajo working here

 951              //$x_label_size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt);

 952  
 953              $this->y_bot_margin = $this->x_label_height ;
 954              $this->x_left_margin = $this->y_label_width * 2 + $this->tick_length;
 955              $this->x_right_margin = 33.0; // distance between right and end of x axis in pixels 

 956          } else {
 957              $title_size = array(ImageFontWidth($this->title_font) * strlen($this->title_txt),ImageFontHeight($this->title_font));
 958              //$this->y_top_margin = ($title_size[1] * 4);

 959              if ($nbLines == 1) { 
 960                  $this->y_top_margin = $title_size[1] * 4;
 961              } else { 
 962                  $this->y_top_margin = $title_size[1] * ($nbLines+3);
 963              }
 964              if ($this->x_datalabel_angle == 90) {
 965                  $this->y_bot_margin = 76.0; // Must be integer

 966              } else {
 967                  $this->y_bot_margin = 66.0; // Must be integer

 968              }
 969              $this->x_left_margin = 77.0; // distance between left and start of x axis in pixels

 970              $this->x_right_margin = 33.0; // distance between right and end of x axis in pixels

 971          }
 972  
 973  //exit;

 974          $this->x_tot_margin = $this->x_left_margin + $this->x_right_margin;
 975          $this->y_tot_margin = $this->y_top_margin + $this->y_bot_margin;
 976  
 977          if ($this->plot_max_x && $this->plot_max_y && $this->plot_area_width ) { //If data has already been analysed then set translation
 978              $this->SetTranslation();
 979          }
 980      }
 981  
 982  	function SetMarginsPixels($which_lm,$which_rm,$which_tm,$which_bm) { 
 983          //Set the plot area using margins in pixels (left, right, top, bottom)

 984          $this->SetNewPlotAreaPixels($which_lm,$which_tm,($this->image_width - $which_rm),($this->image_height - $which_bm));
 985          return true;
 986      }
 987  
 988  	function SetNewPlotAreaPixels($x1,$y1,$x2,$y2) {
 989          //Like in GD 0,0 is upper left set via pixel Coordinates

 990          $this->plot_area = array($x1,$y1,$x2,$y2);
 991          $this->plot_area_width = $this->plot_area[2] - $this->plot_area[0];
 992          $this->plot_area_height = $this->plot_area[3] - $this->plot_area[1];
 993          $this->y_top_margin = $this->plot_area[1];
 994          if ($this->plot_max_x) {
 995              $this->SetTranslation();
 996          }
 997          return true;
 998      }
 999  
1000  	function SetPlotAreaPixels($x1,$y1,$x2,$y2) {
1001          //Like in GD 0,0 is upper left

1002          if (!$this->x_tot_margin) {
1003              $this->SetMargins();
1004          }
1005          if ($x2 && $y2) {
1006              $this->plot_area = array($x1,$y1,$x2,$y2);
1007          } else {
1008              $this->plot_area = array($this->x_left_margin, $this->y_top_margin,
1009                                  $this->image_width - $this->x_right_margin,
1010                                  $this->image_height - $this->y_bot_margin
1011                              );
1012          }
1013          $this->plot_area_width = $this->plot_area[2] - $this->plot_area[0];
1014          $this->plot_area_height = $this->plot_area[3] - $this->plot_area[1];
1015  
1016          return true;
1017  
1018      }
1019  
1020  	function SetPlotAreaWorld($xmin,$ymin,$xmax,$ymax) {
1021          if (($xmin == "")  && ($xmax == "")) {
1022              //For automatic setting of data we need $this->max_x

1023                  if (!$this->max_y) {
1024                      $this->FindDataLimits() ;
1025                  }
1026                  if ($this->data_type == 'text-data') { //labels for text-data is done at data drawing time for speed.
1027                      $xmax = $this->max_x + 1 ;  //valid for BAR CHART TYPE GRAPHS ONLY

1028                      $xmin = 0 ;                 //valid for BAR CHART TYPE GRAPHS ONLY

1029                  } else {
1030                      $xmax = $this->max_x * 1.02;
1031                      $xmin = $this->min_x;
1032                  }
1033  
1034                  $ymax = ceil($this->max_y * 1.2);
1035                  if ($this->min_y < 0) {
1036                      $ymin = floor($this->min_y * 1.2);
1037                  } else {
1038                      $ymin = 0;
1039                  }
1040          }
1041  
1042          $this->plot_min_x = $xmin;
1043          $this->plot_max_x = $xmax;
1044  
1045          if ($ymin == $ymax) {
1046              $ymax += 1;
1047          }
1048          if ($this->yscale_type == "log") { 
1049              //extra error checking

1050              if ($ymin <= 0) { 
1051                  $ymin = 1;
1052              } 
1053              if ($ymax <= 0) { 
1054                  $this->PrintError('Log plots need data greater than 0');
1055              }
1056          }
1057          $this->plot_min_y = $ymin;
1058          $this->plot_max_y = $ymax;
1059  
1060          if ($ymax <= $ymin) {
1061              $this->DrawError('Error in Data - max not gt min');
1062          }
1063  
1064  //Set the boundaries of the box for plotting in world coord

1065  //        if (!$this->x_tot_margin) { //We need to know the margins before we can calculate scale

1066  //            $this->SetMargins();

1067  //        }

1068          //For this we have to reset the scale

1069          if ($this->plot_area_width) {
1070              $this->SetTranslation();
1071          }
1072  
1073          return true;
1074  
1075      } //function SetPlotAreaWorld

1076  
1077  
1078  	function PrintError($error_message) {
1079      // prints the error message to stdout and die

1080          echo "<p><b>Fatal error</b>: $error_message<p>";
1081          die;
1082      }
1083  
1084  	function DrawError($error_message) {
1085      // prints the error message inline into

1086      // the generated image

1087  
1088          if (($this->img) == "") { $this->InitImage(); } ;
1089  
1090          $ypos = $this->image_height/2;
1091  
1092          if ($this->use_ttf == 1) {
1093              ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255));
1094              ImageTTFText($this->img, $this->small_ttffont_size, 0, $xpos, $ypos, ImageColorAllocate($this->img,0,0,0), $this->axis_ttffont, $error_message);
1095          } else {
1096              ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255));
1097              ImageString($this->img, $this->small_font,1,$ypos,$error_message, ImageColorAllocate($this->img,0,0,0));
1098          }
1099  
1100          $this->PrintImage();
1101          return true;
1102      }
1103  
1104  	function TTFBBoxSize($size, $angle, $font, $string) {
1105  
1106          //Assume angle < 90

1107          $arr = ImageTTFBBox($size, 0, $font, $string);
1108          $flat_width  = $arr[0] - $arr[2];
1109          $flat_height = abs($arr[3] - $arr[5]);
1110  
1111              // for 90deg:

1112              //    $height = $arr[5] - $arr[7];

1113              //    $width = $arr[2] - $arr[4];

1114  
1115          $angle = deg2rad($angle);
1116          $width  = ceil(abs($flat_width*cos($angle) + $flat_height*sin($angle))); //Must be integer

1117          $height = ceil(abs($flat_width*sin($angle) + $flat_height*cos($angle))); //Must be integer

1118  
1119          return array($width, $height);
1120      }
1121  
1122  	function SetXLabelHeight() {
1123  
1124          if ($this->use_ttf == 1) {
1125              //Space for the X Label

1126              $size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt);
1127              $tmp = $size[1];
1128  
1129              //$string = Str_Repeat('w', $this->x_datalabel_maxlength);

1130              $i = 0;
1131              $string = '';
1132              while ($i < $this->x_datalabel_maxlength) {
1133                $string .= 'w';
1134                $i++;
1135              }
1136  
1137              //Space for the axis data labels

1138              $size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $string);
1139  
1140              $this->x_label_height = 2*$tmp + $size[1] + 4;
1141  
1142          } else {
1143              //For Non-TTF fonts we can have only angles 0 or 90

1144              if ($this->x_datalabel_angle == 90) {
1145                  $this->x_label_height = $this->x_datalabel_maxlength * ImageFontWidth($this->small_font) / 1.5;
1146              } else {
1147                  $this->x_label_height = 5 * ImageFontHeight($this->small_font);
1148              }
1149          }
1150  
1151          $this->SetMargins();
1152  
1153          return true;
1154      } //function SetXLabelHeight

1155  
1156  	function SetYLabelWidth() {
1157          //$ylab = sprintf("%6.1f %s",$i,$si_units[0]);  //use for PHP2 compatibility

1158          //the "." is for space. It isn't actually printed

1159          $ylab = number_format($this->max_y, $this->y_precision, ".", ",") . $this->si_units . ".";
1160  
1161          if ($this->use_ttf == 1) {
1162              $size = $this->TTFBBoxSize($this->axis_ttffont_size, 0, $this->axis_ttffont, $ylab);
1163          } else {
1164              $size[0] = StrLen($ylab) * $this->small_font_width * .6;
1165          }
1166  
1167          $this->y_label_width = $size[0] * 2;
1168  //echo "SYLW: $this->y_label_width<br>";

1169  //exit;

1170  
1171          $this->SetMargins();
1172          return true;
1173      }
1174  
1175  	function SetEqualXCoord() {
1176          //for plots that have equally spaced x variables and multiple bars per x-point.

1177  
1178          $space = ($this->plot_area[2] - $this->plot_area[0]) / ($this->number_x_points * 2) * $this->group_frac_width;
1179          $group_width = $space * 2;
1180          $bar_width = $group_width / $this->records_per_group;
1181    //I think that eventually this space variable will be replaced by just graphing x.

1182          $this->data_group_space = $space;
1183          $this->record_bar_width = $bar_width;
1184          return true;
1185      }
1186  
1187  	function SetLabelScalePosition($which_blp) {
1188          //0 to 1

1189          $this->label_scale_position = $which_blp;
1190          return true;
1191      }
1192  
1193  	function SetErrorBarSize($which_ebs) {
1194          //in pixels

1195          $this->error_bar_size = $which_ebs;
1196          return true;
1197      }
1198  
1199  	function SetErrorBarShape($which_ebs) {
1200          //in pixels

1201          $this->error_bar_shape = $which_ebs;
1202          return true;
1203      }
1204  
1205  	function SetPointShape($which_pt) {
1206          //in pixels

1207          $this->point_shape = $which_pt;
1208          return true;
1209      }
1210  
1211  	function SetPointSize($which_ps) {
1212          //in pixels

1213          SetType($which_ps,'integer');
1214          $this->point_size = $which_ps;
1215  
1216          if ($this->point_shape == "diamond" or $this->point_shape == "triangle") {
1217              if ($this->point_size % 2 != 0) {
1218                  $this->point_size++;
1219              }
1220          }
1221          return true;
1222      }
1223  
1224  	function SetDataType($which_dt) {
1225          //The next three lines are for past compatibility.

1226          if ($which_dt == "text-linear") { $which_dt = "text-data"; };
1227          if ($which_dt == "linear-linear") { $which_dt = "data-data"; };
1228          if ($which_dt == "linear-linear-error") { $which_dt = "data-data-error"; };
1229  
1230          $this->data_type = $which_dt; //text-data, data-data, data-data-error

1231          return true;
1232      }
1233  
1234  	function SetDataValues($which_dv) {
1235          $this->data_values = $which_dv;
1236  //echo $this->data_values

1237          return true;
1238      }
1239  
1240  //////////////COLORS

1241  	function SetRGBArray ($which_color_array) { 
1242          if ( is_array($which_color_array) ) { 
1243              //User Defined Array

1244              $this->rgb_array = $which_color_array;
1245              return true;
1246          } elseif ($which_color_array == 2) { //Use the small predefined color array
1247          $this->rgb_array = array(
1248              "white"            => array(255, 255, 255),
1249              "snow"            => array(255, 250, 250),
1250              "PeachPuff"        => array(255, 218, 185),
1251              "ivory"            => array(255, 255, 240),
1252              "lavender"        => array(230, 230, 250),
1253              "black"            => array(  0,   0,   0),
1254              "DimGrey"            => array(105, 105, 105),
1255              "gray"            => array(190, 190, 190),
1256              "grey"            => array(190, 190, 190),
1257              "navy"            => array(  0,   0, 128),
1258              "SlateBlue"            => array(106,  90, 205),
1259              "blue"            => array(  0,   0, 255),
1260              "SkyBlue"            => array(135, 206, 235),
1261              "cyan"            => array(  0, 255, 255),
1262              "DarkGreen"            => array(  0, 100,   0),
1263              "green"            => array(  0, 255,   0),
1264              "YellowGreen"            => array(154, 205,  50),
1265              "yellow"            => array(255, 255,   0),
1266              "orange"            => array(255, 165,   0),
1267              "gold"            => array(255, 215,   0),
1268              "peru"            => array(205, 133,  63),
1269              "beige"            => array(245, 245, 220),
1270              "wheat"            => array(245, 222, 179),
1271              "tan"            => array(210, 180, 140),
1272              "brown"            => array(165,  42,  42),
1273              "salmon"            => array(250, 128, 114),
1274              "red"            => array(255,   0,   0),
1275              "pink"            => array(255, 192, 203),
1276              "maroon"            => array(176,  48,  96),
1277              "magenta"            => array(255,   0, 255),
1278              "violet"            => array(238, 130, 238),
1279              "plum"            => array(221, 160, 221),
1280              "orchid"            => array(218, 112, 214),
1281              "purple"            => array(160,  32, 240),
1282              "azure1"            => array(240, 255, 255),
1283              "aquamarine1"        => array(127, 255, 212)
1284              );
1285              return true;
1286          } elseif ($which_color_array == 1)  { 
1287              include("./rgb.inc.php"); //Get large $ColorArray

1288              $this->rgb_array = $RGBArray;
1289          } else { 
1290              $this->rgb_array = array("white" =>array(255,255,255), "black" => array(0,0,0));
1291              exit;
1292          }
1293  
1294          return true;
1295      }
1296  
1297  	function SetColor($which_color) { 
1298          //obsoleted by SetRGBColor

1299          SetRgbColor($which_color);
1300          return true;
1301      }
1302  
1303  	function SetIndexColor($which_color) { //Color is passed in as anything
1304            list ($r, $g, $b) = $this->SetRgbColor($which_color);  //Translate to RGB

1305          $index = ImageColorExact($this->img, $r, $g, $b);
1306          if ($index == -1) {
1307                    //return ImageColorAllocate($this->img, $r, $g, $b);

1308                    //return ImageColorClosest($this->img, $r, $g, $b);

1309                    return ImageColorResolve($this->img, $r, $g, $b); //requires PHP 3.0.2 and later

1310           } else {
1311                    return $index;
1312            }
1313      }
1314      
1315  	function SetTransparentColor($which_color) { 
1316          ImageColorTransparent($this->img,$this->SetIndexColor($which_color));
1317          return true;
1318      }
1319  
1320  	function SetRgbColor($color_asked) {
1321          //Returns an array in R,G,B format 0-255

1322          if ($color_asked == "") { $color_asked = array(0,0,0); };
1323  
1324          if ( count($color_asked) == 3 ) { //already array of 3 rgb
1325                 $ret_val =  $color_asked;
1326          } else { // is asking for a color by string
1327              if(substr($color_asked,0,1) == "#") {  //asking in #FFFFFF format. 
1328                  $ret_val =  array(hexdec(substr($color_asked,1,2)), hexdec(substr($color_asked,3,2)), hexdec(substr($color,5,2)));
1329              } else { 
1330                  $ret_val =  $this->rgb_array[$color_asked];
1331              }
1332          }
1333          return $ret_val;
1334      }
1335  
1336  	function SetDataColors($which_data,$which_border) {
1337          //Set the data to be displayed in a particular color

1338          if (!$which_data) {
1339              $which_data = array(array(0,255,0),array(0,0,248),'yellow',array(255,0,0),'orange');
1340              $which_border = array('black');
1341          }
1342  
1343          $this->data_color = $which_data;  //an array

1344          $this->data_border_color = $which_border;  //an array

1345  
1346          unset($this->ndx_data_color);
1347          reset($this->data_color);  //data_color can be an array of colors, one for each thing plotted

1348          //while (list(, $col) = each($this->data_color)) 

1349          $i = 0;
1350          while (list(, $col) = each($which_data)) {
1351              $this->ndx_data_color[$i] = $this->SetIndexColor($col);
1352              $i++;
1353          }
1354  
1355          // border_color

1356          //If we are also going to put a border on the data (bars, dots, area, ...)

1357          //    then lets also set a border color as well.

1358          //foreach($this->data_border_color as $col) 

1359          unset($this->ndx_data_border_color);
1360          reset($this->data_border_color);
1361          $i = 0;
1362          while (list(, $col) = each($this->data_border_color)) {
1363              $this->ndx_data_border_color[$i] = $this->SetIndexColor($col);
1364              $i++;
1365          }
1366  
1367          //Set color of the error bars to be that of data if not already set. 

1368          if (!$this->error_bar_color) { 
1369                  reset($which_data);
1370                  $this->SetErrorBarColors($which_data);
1371          }
1372  
1373          return true;
1374  
1375      } //function SetDataColors

1376  
1377  	function SetErrorBarColors($which_data) {
1378  
1379       //Set the data to be displayed in a particular color

1380  
1381       if ($which_data) {
1382          $this->error_bar_color = $which_data;  //an array

1383          unset($this->ndx_error_bar_color);
1384          reset($this->error_bar_color);  //data_color can be an array of colors, one for each thing plotted

1385          $i = 0;
1386          while (list(, $col) = each($this->error_bar_color)) {
1387              $this->ndx_error_bar_color[$i] = $this->SetIndexColor($col);
1388              $i++;
1389          }
1390          return true;
1391        }
1392        return false;
1393      } //function SetErrorBarColors

1394  
1395  
1396  	function DrawPlotBorder() {
1397          switch ($this->plot_border_type) {
1398              case "left" :
1399                  ImageLine($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y),
1400                      $this->plot_area[0],$this->ytr($this->plot_max_y),$this->ndx_grid_color);
1401              break;
1402              case "none":
1403                  //Draw No Border

1404              break;
1405              default:
1406                  ImageRectangle($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y),
1407                      $this->plot_area[2],$this->ytr($this->plot_max_y),$this->ndx_grid_color);
1408              break;
1409          }
1410          $this->DrawYAxis();
1411          $this->DrawXAxis();
1412          return true;
1413      }
1414  
1415  
1416  	function SetHorizTickIncrement($which_ti) {
1417          //Use either this or NumHorizTicks to set where to place x tick marks

1418          if ($which_ti) {
1419              $this->horiz_tick_increment = $which_ti;  //world coordinates

1420          } else {
1421              if (!$this->max_x) {
1422                  $this->FindDataLimits();  //Get maxima and minima for scaling

1423              }
1424              //$this->horiz_tick_increment = ( ceil($this->max_x * 1.2) - floor($this->min_x * 1.2) )/10;

1425              $this->horiz_tick_increment =  ($this->plot_max_x  - $this->plot_min_x  )/10;
1426          }
1427          $this->num_horiz_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both

1428          return true;
1429      }
1430  
1431  	function SetDrawVertTicks($which_dvt) {
1432          $this->draw_vert_ticks = $which_dvt;
1433          return true;
1434      } 
1435  
1436  	function SetVertTickIncrement($which_ti) {
1437          //Use either this or NumVertTicks to set where to place y tick marks

1438          if ($which_ti) {
1439              $this->vert_tick_increment = $which_ti;  //world coordinates

1440          } else {
1441              if (!$this->max_y) {
1442                  $this->FindDataLimits();  //Get maxima and minima for scaling

1443              }
1444              //$this->vert_tick_increment = ( ceil($this->max_y * 1.2) - floor($this->min_y * 1.2) )/10;

1445              $this->vert_tick_increment =  ($this->plot_max_y  - $this->plot_min_y  )/10;
1446          }
1447          $this->num_vert_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both

1448          return true;
1449      }
1450  
1451  	function SetNumHorizTicks($which_nt) {
1452          $this->num_horiz_ticks = $which_nt;
1453          $this->horiz_tick_increment = '';  //either use num_horiz_ticks or horiz_tick_increment, not both

1454          return true;
1455      }
1456  
1457  	function SetNumVertTicks($which_nt) {
1458          $this->num_vert_ticks = $which_nt;
1459          $this->vert_tick_increment = '';  //either use num_vert_ticks or vert_tick_increment, not both

1460          return true;
1461      }
1462  	function SetVertTickPosition($which_tp) {
1463          $this->vert_tick_position = $which_tp; //plotleft, plotright, both, yaxis

1464          return true;
1465      }
1466  	function SetSkipBottomTick($which_sbt) {
1467          $this->skip_bottom_tick = $which_sbt;
1468          return true;
1469      }
1470  
1471  	function SetTickLength($which_tl) {
1472          $this->tick_length = $which_tl;
1473          return true;
1474      }
1475  
1476  	function DrawYAxis() { 
1477          //Draw Line at left side or at this->y_axis_position

1478          if ($this->y_axis_position != "") { 
1479              $yaxis_x = $this->xtr($this->y_axis_position);
1480          } else { 
1481              $yaxis_x = $this->plot_area[0];
1482          }
1483  
1484          ImageLine($this->img, $yaxis_x, $this->plot_area[1], 
1485              $yaxis_x, $this->plot_area[3], $this->ndx_grid_color);
1486              //$yaxis_x, $this->plot_area[3], 9);

1487  
1488          if ($this->draw_vert_ticks == 1) { 
1489              $this->DrawVerticalTicks();
1490          }
1491  
1492      } //function DrawYAxis

1493  
1494  	function DrawXAxis() {
1495          //Draw Tick and Label for Y axis

1496          $ylab =$this->FormatYTickLabel($this->x_axis_position);
1497          if ($this->skip_bottom_tick != 1) { 
1498              $this->DrawVerticalTick($ylab,$this->x_axis_position);
1499          }
1500  
1501          //Draw X Axis at Y=$x_axis_postion

1502          ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->x_axis_position),
1503                  $this->xtr($this->plot_max_x)-1,$this->ytr($this->x_axis_position),$this->ndx_tick_color);
1504  
1505          //X Ticks and Labels

1506          if ($this->data_type != 'text-data') { //labels for text-data done at data drawing time for speed.
1507              $this->DrawHorizontalTicks();
1508          }
1509          return true;
1510      }
1511  
1512  	function DrawHorizontalTicks() {
1513          //Ticks and lables are drawn on the left border of PlotArea.

1514          //Left Bottom

1515          ImageLine($this->img,$this->plot_area[0],
1516                  $this->plot_area[3]+$this->tick_length,
1517                  $this->plot_area[0],$this->plot_area[3],$this->ndx_tick_color);
1518  
1519          switch ($this->x_grid_label_type) {
1520              case "title":
1521                  $xlab = $this->data_values[0][0];
1522              break;
1523              case "data":
1524                  $xlab = number_format($this->plot_min_x,$this->x_precision,".",",") . "$this->si_units";
1525              break;
1526              case "none":
1527                  $xlab = '';
1528              break;
1529              case "time":  //Time formatting suggested by Marlin Viss
1530                  $xlab = strftime($this->x_time_format,$this->plot_min_x);
1531              break;
1532              default:
1533                  //Unchanged from whatever format is passed in

1534                  $xlab = $this->plot_min_x;
1535              break;
1536          }
1537  
1538          if ($this->x_datalabel_angle == 90) { 
1539              $xpos =  $this->plot_area[0] - $this->small_font_height/2;
1540              $ypos = ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height);
1541              ImageStringUp($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color);
1542          } else {
1543              $xpos = $this->plot_area[0] - $this->small_font_width*strlen($xlab)/2 ;
1544              $ypos = $this->plot_area[3] + $this->small_font_height;
1545              ImageString($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color);
1546          }
1547  
1548          //Will be changed to allow for TTF fonts in data as well.

1549          //$this->DrawText($this->small_font, $this->x_datalabel_angle, $xpos, $ypos, $this->ndx_title_color, '', $xlab); 

1550  
1551          //Top

1552  
1553          if ($this->horiz_tick_increment) {
1554              $delta_x = $this->horiz_tick_increment;
1555          } elseif ($this->num_horiz_ticks) {
1556              $delta_x = ($this->plot_max_x - $this->plot_min_x) / $this->num_horiz_ticks;
1557          } else {
1558              $delta_x =($this->plot_max_x - $this->plot_min_x) / 10 ;
1559          }
1560  
1561          $i = 0;
1562          $x_tmp = $this->plot_min_x;
1563          SetType($x_tmp,'double');
1564  
1565          while ($x_tmp <= $this->plot_max_x){
1566              //$xlab = sprintf("%6.1f %s",$min_x,$si_units[0]);  //PHP2 past compatibility

1567              switch ($this->x_grid_label_type) {
1568                  case "title":
1569                      $xlab = $this->data_values[$x_tmp][0];
1570                  break;
1571                  case "data":
1572                      $xlab = number_format($x_tmp,$this->x_precision,".",",") . "$this->si_units";
1573                  break;
1574                  case "none":
1575                      $xlab = '';
1576                  break;
1577                  case "time":  //Time formatting suggested by Marlin Viss
1578                      $xlab = strftime($this->x_time_format,$x_tmp);
1579                  break;
1580                  default:
1581                      //Unchanged from whatever format is passed in

1582                      $xlab = $x_tmp;
1583                  break;
1584              }
1585  
1586              $x_pixels = $this->xtr($x_tmp);
1587  
1588              //Bottom Tick

1589              ImageLine($this->img,$x_pixels,$this->plot_area[3] + $this->tick_length,
1590                  $x_pixels,$this->plot_area[3], $this->ndx_tick_color);
1591              //Top Tick

1592              //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),

1593              //    $y_pixels,$this->xtr($this->plot_max_x)-1,$y_pixels,$this->ndx_tick_color);

1594  
1595              if ($this->draw_x_grid == 1) {
1596                  ImageLine($this->img,$x_pixels,$this->plot_area[1],
1597                      $x_pixels,$this->plot_area[3], $this->ndx_light_grid_color);
1598              }
1599  
1600              if ($this->x_datalabel_angle == 90) {  //Vertical Code Submitted by Marlin Viss
1601                  ImageStringUp($this->img, $this->small_font,
1602                  ( $x_pixels - $this->small_font_height/2),
1603                  ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height),$xlab, $this->ndx_text_color);
1604              } else {
1605                  ImageString($this->img, $this->small_font,
1606                      ( $x_pixels - $this->small_font_width*strlen($xlab)/2) ,
1607                      ( $this->small_font_height + $this->plot_area[3]),$xlab, $this->ndx_text_color);
1608              }
1609  
1610              $i++;
1611              $x_tmp += $delta_x;
1612          }
1613  
1614      } // function DrawHorizontalTicks

1615  
1616  	function FormatYTickLabel($which_ylab) { 
1617          switch ($this->y_grid_label_type) {
1618              case "data":
1619                  $ylab = number_format($which_ylab,$this->y_precision,".",",") . "$this->si_units";
1620              break;
1621              case "none":
1622                  $ylab = '';
1623              break;
1624              case "time":
1625                  $ylab = strftime($this->y_time_format,$which_ylab);
1626              break;
1627              case "right":
1628                  //Make it right aligned

1629                  //$ylab = str_pad($which_ylab,$this->y_label_width," ",STR_PAD_LEFT); //PHP4 only

1630                  $sstr = "%".strlen($this->plot_max_y)."s";
1631                  $ylab = sprintf($sstr,$which_ylab);
1632              break;
1633              default:
1634                  //Unchanged from whatever format is passed in

1635                  $ylab = $which_ylab;
1636              break;
1637          }
1638  
1639          return($ylab);
1640  
1641      } //function FormatYTickLabel

1642  
1643  	function DrawVerticalTick($which_ylab,$which_ypos) {  //ylab in world coord.
1644          //Draw Just one Tick, called from DrawVerticalTicks

1645          //Ticks and datalables can be left of plot only, right of plot only, 

1646          //  both on the left and right of plot, or crossing a user defined Y-axis

1647          // 

1648          //Its faster to draw both left and right ticks at same time

1649          //  than first left and then right. 

1650  
1651          if ($this->y_axis_position != "") { 
1652              //Ticks and lables are drawn on the left border of yaxis

1653              $yaxis_x = $this->xtr($this->y_axis_position);
1654          } else { 
1655              //Ticks and lables are drawn on the left border of PlotArea.

1656              $yaxis_x = $this->plot_area[0];
1657          }
1658  
1659          $y_pixels = $this->ytr($which_ypos);
1660  
1661          //Lines Across the Plot Area

1662          if ($this->draw_y_grid == 1) {
1663              ImageLine($this->img,$this->plot_area[0]+1,$y_pixels,
1664                  $this->plot_area[2]-1,$y_pixels,$this->ndx_light_grid_color);
1665          }
1666  
1667          //Ticks to the Left of the Plot Area

1668          if (($this->vert_tick_position == "plotleft") || ($this->vert_tick_position == "both") ) { 
1669              ImageLine($this->img,(-$this->tick_length+$yaxis_x),
1670              $y_pixels,$yaxis_x,
1671              $y_pixels, $this->ndx_tick_color);
1672          }
1673  
1674          //Ticks to the Right of the Plot Area

1675          if (($this->vert_tick_position == "plotright") || ($this->vert_tick_position == "both") ) { 
1676              ImageLine($this->img,($this->plot_area[2]+$this->tick_length),
1677              $y_pixels,$this->plot_area[2],
1678              $y_pixels,$this->ndx_tick_color);
1679          }
1680  
1681          //Ticks on the Y Axis 

1682          if (($this->vert_tick_position == "yaxis") ) { 
1683              ImageLine($this->img,($yaxis_x - $this->tick_length),
1684              $y_pixels,$yaxis_x,$y_pixels,$this->ndx_tick_color);
1685          }
1686  
1687          //DataLabel

1688  //ajo working

1689          //$this->DrawText($this->y_label_ttffont, 0,($yaxis_x - $this->y_label_width - $this->tick_length/2),

1690          //        $y_pixels, $this->ndx_text_color, $this->axis_ttffont_size, $which_ylab);

1691          ImageString($this->img, $this->small_font, ($yaxis_x - $this->y_label_width - $this->tick_length/2),
1692              ( -($this->small_font_height/2.0) + $y_pixels),$which_ylab, $this->ndx_text_color);
1693      }
1694  
1695  	function DrawVerticalTicks() {
1696  
1697          if ($this->skip_top_tick != 1) { //If tick increment doesn't hit the top 
1698              //Left Top

1699              //ImageLine($this->img,(-$this->tick_length+$this->xtr($this->plot_min_x)),

1700              //        $this->ytr($this->plot_max_y),$this->xtr($this->plot_min_x),$this->ytr($this->plot_max_y),$this->ndx_tick_color);

1701              //$ylab = $this->FormatYTickLabel($plot_max_y);

1702  
1703              //Right Top

1704              //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),

1705              //        $this->ytr($this->plot_max_y),$this->xtr($this->plot_max_x-1),$this->ytr($this->plot_max_y),$this->ndx_tick_color);

1706  
1707              //Draw Grid Line at Top

1708              ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->plot_max_y),
1709                      $this->plot_area[2]-1,$this->ytr($this->plot_max_y),$this->ndx_light_grid_color);
1710  
1711          }
1712  
1713          if ($this->skip_bottom_tick != 1) { 
1714              //Right Bottom

1715              //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),

1716              //        $this->ytr($this->plot_min_y),$this->xtr($this->plot_max_x),

1717              //        $this->ytr($this->plot_min_y),$this->ndx_tick_color);

1718  
1719              //Draw Grid Line at Bottom of Plot

1720              ImageLine($this->img,$this->xtr($this->plot_min_x)+1,$this->ytr($this->plot_min_y),
1721                      $this->xtr($this->plot_max_x),$this->ytr($this->plot_min_y),$this->ndx_light_grid_color);
1722          }
1723          
1724          // maxy is always > miny so delta_y is always positive

1725          if ($this->vert_tick_increment) {
1726              $delta_y = $this->vert_tick_increment;
1727          } elseif ($this->num_vert_ticks) {
1728              $delta_y = ($this->plot_max_y - $this->plot_min_y) / $this->num_vert_ticks;
1729          } else {
1730              $delta_y =($this->plot_max_y - $this->plot_min_y) / 10 ;
1731          }
1732  
1733          $y_tmp = $this->plot_min_y;
1734          SetType($y_tmp,'double');
1735          if ($this->skip_bottom_tick == 1) { 
1736              $y_tmp += $delta_y;
1737          }
1738  
1739          while ($y_tmp <= $this->plot_max_y){
1740              //For log plots: 

1741              if (($this->yscale_type == "log") && ($this->plot_min_y == 1) && 
1742                  ($delta_y%10 == 0) && ($y_tmp == $this->plot_min_y)) { 
1743                  $y_tmp = $y_tmp - 1; //Set first increment to 9 to get: 1,10,20,30,...

1744              }
1745  
1746              $ylab = $this->FormatYTickLabel($y_tmp);
1747  
1748              $this->DrawVerticalTick($ylab,$y_tmp);
1749  
1750              $y_tmp += $delta_y;
1751          }
1752  
1753          return true;
1754  
1755      } // function DrawVerticalTicks

1756  
1757  	function SetTranslation() {
1758          if ($this->xscale_type == "log") { 
1759              $this->xscale = ($this->plot_area_width)/(log10($this->plot_max_x) - log10($this->plot_min_x));
1760          } else { 
1761              $this->xscale = ($this->plot_area_width)/($this->plot_max_x - $this->plot_min_x);
1762          }
1763          if ($this->yscale_type == "log") { 
1764              $this->yscale = ($this->plot_area_height)/(log10($this->plot_max_y) - log10($this->plot_min_y));
1765          } else { 
1766              $this->yscale = ($this->plot_area_height)/($this->plot_max_y - $this->plot_min_y);
1767          }
1768  
1769          // GD defines x=0 at left and y=0 at TOP so -/+ respectively

1770          if ($this->xscale_type == "log") { 
1771              $this->plot_origin_x = $this->plot_area[0] - ($this->xscale * log10($this->plot_min_x) );
1772          } else { 
1773              $this->plot_origin_x = $this->plot_area[0] - ($this->xscale * $this->plot_min_x);
1774          }
1775          if ($this->yscale_type == "log") { 
1776              $this->plot_origin_y = $this->plot_area[3] + ($this->yscale * log10($this->plot_min_y));
1777          } else { 
1778              $this->plot_origin_y = $this->plot_area[3] + ($this->yscale * $this->plot_min_y);
1779          }
1780  
1781          $this->scale_is_set = 1;
1782      } // function SetTranslation

1783  
1784  	function xtr($x_world) {
1785      //Translate world coordinates into pixel coordinates

1786      //The pixel coordinates are those of the ENTIRE image, not just the plot_area

1787          //$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)) ;

1788          //which with a little bit of math reduces to ...

1789          if ($this->xscale_type == "log") { 
1790              $x_pixels =  $this->plot_origin_x + log10($x_world) * $this->xscale ;
1791          } else { 
1792              $x_pixels =  $this->plot_origin_x + $x_world * $this->xscale ;
1793          }
1794          return($x_pixels);
1795      }
1796  
1797  	function ytr($y_world) {
1798          // translate y world coord into pixel coord

1799          if ($this->yscale_type == "log") { 
1800              $y_pixels =  $this->plot_origin_y - log10($y_world) * $this->yscale ;  //minus because GD defines y=0 at top. doh!

1801          } else { 
1802              $y_pixels =  $this->plot_origin_y - $y_world * $this->yscale ;  
1803          }
1804          return ($y_pixels);
1805      }
1806  
1807  
1808  	function DrawDataLabel($lab,$x_world,$y_world) {
1809          //Depreciated. Use DrawText Instead.

1810          //Data comes in in WORLD coordinates

1811          //Draw data label near actual data point

1812              //$y = $this->ytr($y_world) ;  //in pixels

1813              //$x = $this->xtr($x_world) ;

1814              //$this->DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left');

1815              if ($this->use_ttf) {
1816  //ajjjo

1817                  $lab_size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $lab); //An array

1818                  $y = $this->ytr($y_world) - $lab_size[1] ;  //in pixels

1819                  $x = $this->xtr($x_world) - $lab_size[0]/2;
1820                  ImageTTFText($this->img, $this->axis_ttffont_size, $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $lab);
1821              } else {
1822                  $lab_size = array($this->small_font_width*StrLen($lab), $this->small_font_height*3);
1823                  if ($this->x_datalabel_angle == 90) {
1824                      $y = $this->ytr($y_world) - $this->small_font_width*StrLen($lab); //in pixels

1825                      $x = $this->xtr($x_world) - $this->small_font_height;
1826                      ImageStringUp($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
1827                  } else {
1828                      $y = $this->ytr($y_world) - $this->small_font_height; //in pixels

1829                      $x = $this->xtr($x_world) - ($this->small_font_width*StrLen($lab))/2;
1830                      ImageString($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
1831                  }
1832              }
1833  
1834      }
1835  
1836  	function DrawXDataLabel($xlab,$xpos) {
1837          //xpos comes in in PIXELS not in world coordinates.

1838          //Draw an x data label centered at xlab

1839              if ($this->use_ttf) {
1840                  $xlab_size = $this->TTFBBoxSize($this->axis_ttffont_size,
1841                      $this->x_datalabel_angle, $this->axis_ttffont, $xlab); //An array

1842                  $y = $this->plot_area[3] + $xlab_size[1] + 4;  //in pixels

1843                  $x = $xpos - $xlab_size[0]/2;
1844                  ImageTTFText($this->img, $this->axis_ttffont_size,
1845                      $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $xlab);
1846              } else {
1847                  $xlab_size = array(ImageFontWidth($this->axis_font)*StrLen($xlab), $this->small_font_height*3);
1848                  if ($this->x_datalabel_angle == 90) {
1849                      $y = $this->plot_area[3] + ImageFontWidth($this->axis_font)*StrLen($xlab); //in pixels

1850                      $x = $xpos - ($this->small_font_height);
1851                      ImageStringUp($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
1852                  } else {
1853                      $y = $this->plot_area[3] + ImageFontHeight($this->axis_font); //in pixels

1854                      $x = $xpos - (ImageFontWidth($this->axis_font)*StrLen($xlab))/2;
1855                      ImageString($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
1856                  }
1857              }
1858  
1859      }
1860  
1861  	function DrawPieChart() {
1862          //$pi = '3.14159265358979323846';

1863          $xpos = $this->plot_area[0] + $this->plot_area_width/2;
1864          $ypos = $this->plot_area[1] + $this->plot_area_height/2;
1865          $diameter = (min($this->plot_area_width, $this->plot_area_height)) ;
1866          $radius = $diameter/2;
1867  
1868          ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
1869  
1870          $total = 0;
1871          reset($this->data_values);
1872          $tmp = $this->number_x_points - 1;
1873          while (list($j, $row) = each($this->data_values)) {
1874              //Get sum of each type

1875              $color_index = 0;
1876              $i = 0;
1877              //foreach ($row as $v) 

1878              while (list($k, $v) = each($row)) {
1879                  if ($k != 0) {
1880                      if ($j == 0) { 
1881                          $sumarr[$i] = $v;
1882                      } elseif ($j < $tmp) { 
1883                          $sumarr[$i] += $v;
1884                      } else { 
1885                          $sumarr[$i] += $v;
1886                      // NOTE!  sum > 0 to make pie charts

1887                          $sumarr[$i] = abs($sumarr[$i]); 
1888                          $total += $sumarr[$i];
1889                      }
1890                  }
1891              $i++;
1892              }
1893          }
1894  
1895          $color_index = 0;
1896          $start_angle = 0;
1897  
1898          reset($sumarr);
1899          $end_angle = 0;
1900          while (list(, $val) = each($sumarr)) {
1901              if ($color_index >= count($this->ndx_data_color)) $color_index=0;  //data_color = array

1902              $label_txt = number_format(($val / $total * 100), $this->y_precision, ".", ",") . "%";
1903              $val = 360 * ($val / $total);
1904  
1905              $end_angle += $val;
1906              $mid_angle = $end_angle - ($val / 2);
1907  
1908              $slicecol = $this->ndx_data_color[$color_index];
1909  
1910  //Need this again for FillToBorder

1911              ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
1912  
1913              $out_x = $radius * cos(deg2rad($end_angle));
1914              $out_y = - $radius * sin(deg2rad($end_angle));
1915  
1916              $mid_x = $xpos + ($radius/2 * cos(deg2rad($mid_angle))) ;
1917              $mid_y = $ypos + (- $radius/2 * sin(deg2rad($mid_angle)));
1918  
1919              $label_x = $xpos + ($radius * cos(deg2rad($mid_angle))) * $this->label_scale_position;
1920              $label_y = $ypos + (- $radius * sin(deg2rad($mid_angle))) * $this->label_scale_position;
1921  
1922              $out_x = $xpos + $out_x;
1923              $out_y = $ypos + $out_y;
1924  
1925              ImageLine($this->img, $xpos, $ypos, $out_x, $out_y, $this->ndx_grid_color);
1926              //ImageLine($this->img, $xpos, $ypos, $label_x, $label_y, $this->ndx_grid_color);

1927              ImageFillToBorder($this->img, $mid_x, $mid_y, $this->ndx_grid_color, $slicecol);
1928  
1929              if ($this->use_ttf) {
1930                  ImageTTFText($this->img, $this->axis_ttffont_size, 0, $label_x, $label_y, $this->ndx_grid_color, $this->axis_ttffont, $label_txt);
1931              } else {
1932                  ImageString($this->img, $this->small_font, $label_x, $label_y, $label_txt, $this->ndx_grid_color);
1933              }
1934  
1935              $start_angle = $val;
1936  
1937              $color_index++;
1938          }
1939  
1940      }
1941  
1942  	function DrawLinesError() {
1943          //Draw Lines with Error Bars - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...);

1944          $start_lines = 0;
1945  
1946          reset($this->data_values);
1947          while (list(, $row) = each($this->data_values)) {
1948              $color_index = 0;
1949              $i = 0;
1950  
1951              while (list($key, $val) = each($row)) {
1952  //echo "$key, $i, $val<br>";

1953                  if ($key == 0) {
1954                      $lab = $val;
1955                  } elseif ($key == 1) {
1956                      $x_now = $val;
1957                      $x_now_pixels = $this->xtr($x_now); //Use a bit more memory to save 2N operations.

1958                  } elseif ($key%3 == 2) {
1959                      $y_now = $val;
1960                      $y_now_pixels = $this->ytr($y_now);
1961  
1962                      //Draw Data Label

1963                      if ( $this->draw_data_labels == 1) {
1964                          $this->DrawDataLabel($lab,$x_now,$y_now);
1965                      }
1966  
1967                      if ($color_index >= count($this->ndx_data_color)) { $color_index=0;};
1968                      $barcol = $this->ndx_data_color[$color_index];
1969                      $error_barcol = $this->ndx_error_bar_color[$color_index];
1970  
1971  //echo "start = $start_lines<br>";

1972                      if ($start_lines == 1) {
1973                          for ($width = 0; $width < $this->line_width; $width++) {
1974                              ImageLine($this->img, $x_now_pixels, $y_now_pixels + $width,
1975                                  $lastx[$i], $lasty[$i] + $width, $barcol);
1976                          }
1977                      }
1978  
1979                      $lastx[$i] = $x_now_pixels;
1980                      $lasty[$i] = $y_now_pixels;
1981                      $color_index++;
1982                      $i++;
1983                      $start_lines = 1;
1984                  } elseif ($key%3 == 0) {
1985                      $this->DrawYErrorBar($x_now,$y_now,$val,$this->error_bar_shape,$error_barcol);
1986                  } elseif ($key%3 == 1) {
1987                      $this->DrawYErrorBar($x_now,$y_now,-$val,$this->error_bar_shape,$error_barcol);
1988                  }
1989              }
1990          }
1991      }
1992  
1993  	function DrawDotsError() {
1994          //Draw Dots - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...);

1995          reset($this->data_values);
1996          while (list(, $row) = each($this->data_values)) {
1997              $color_index = 0;
1998              //foreach ($row as $v) 

1999              while (list($key, $val) = each($row)) {
2000                  if ($key == 0) {
2001                  } elseif ($key == 1) {
2002                      $xpos = $val;
2003                  } elseif ($key%3 == 2) {
2004                      if ($color_index >= count($this->ndx_data_color)) $color_index=0;
2005                      $barcol = $this->ndx_data_color[$color_index];
2006                      $error_barcol = $this->ndx_error_bar_color[$color_index];
2007                      $ypos = $val;
2008  
2009                      $color_index++;
2010                      $this->DrawDot($xpos,$ypos,$this->point_shape,$barcol);
2011                  } elseif ($key%3 == 0) {
2012                      $this->DrawYErrorBar($xpos,$ypos,$val,$this->error_bar_shape,$error_barcol);
2013                  } elseif ($key%3 == 1) {
2014                      $mine = $val ;
2015                      $this->DrawYErrorBar($xpos,$ypos,-$val,$this->error_bar_shape,$error_barcol);
2016                  }
2017              }
2018          }
2019  
2020      }
2021  
2022  	function DrawDots() {
2023          //Draw Dots - data comes in as array("title",x,y1,y2,y3,...);

2024          reset($this->data_values);
2025          while (list($j, $row) = each($this->data_values)) {
2026              $color_index = 0;
2027              //foreach ($row as $v) 

2028              while (list($k, $v) = each($row)) {
2029                  if ($k == 0) {
2030                  } elseif (($k == 1) && ($this->data_type == "data-data"))  { 
2031                      $xpos = $v;
2032                  } else {
2033                      if ($this->data_type == "text-data") { 
2034                          $xpos = ($j+.5); 
2035                      } 
2036                      if ($color_index >= count($this->ndx_data_color)) $color_index=0;
2037                      $barcol = $this->ndx_data_color[$color_index];
2038  
2039                      //if (is_numeric($v))  //PHP4 only

2040                      if ((strval($v) != "") ) {   //Allow for missing Y data 
2041                          $this->DrawDot($xpos,$v,$this->point_shape,$barcol);
2042                      }
2043                      $color_index++;
2044                  }
2045              }
2046          }
2047  
2048      } //function DrawDots

2049  
2050  	function DrawDotSeries() {
2051          //Depreciated: Use DrawDots

2052          $this->DrawDots();
2053      }
2054  
2055  	function DrawThinBarLines() {
2056          //A clean,fast routine for when you just want charts like stock volume charts

2057          //Data must be text-data since I didn't see a graphing need for equally spaced thin lines. 

2058          //If you want it - then write to [email protected] and I might add it. 

2059  
2060          if ($this->data_type != "data-data") { $this->DrawError('Data Type for ThinBarLines must be data-data'); };
2061          $y1 = $this->ytr($this->x_axis_position);
2062  
2063          reset($this->data_values);
2064          while (list(, $row) = each($this->data_values)) {
2065              $color_index = 0;
2066              while (list($k, $v) = each($row)) {
2067                  if ($k == 0) {
2068                          $xlab = $v;
2069                  } elseif ($k == 1) {
2070                      $xpos = $this->xtr($v);
2071                      if ( ($this->draw_x_data_labels == 1) )  { //See "labels_note1 above.
2072                          $this->DrawXDataLabel($xlab,$xpos);
2073                      }
2074                  } else {
2075                      if ($color_index >= count($this->ndx_data_color)) $color_index=0;
2076                      $barcol = $this->ndx_data_color[$color_index];
2077  
2078                      ImageLine($this->img,$xpos,$y1,$xpos,$this->ytr($v),$barcol);
2079                      $color_index++;
2080                  }
2081              }
2082          }
2083  
2084      }  //function DrawThinBarLines

2085  
2086  	function DrawYErrorBar($x_world,$y_world,$error_height,$error_bar_type,$color) {
2087          $x1 = $this->xtr($x_world);
2088          $y1 = $this->ytr($y_world);
2089          $y2 = $this->ytr($y_world+$error_height) ;
2090  
2091          for ($width = 0; $width < $this->error_bar_line_width; $width++) {
2092              ImageLine($this->img, $x1+$width, $y1 , $x1+$width, $y2, $color);
2093              ImageLine($this->img, $x1-$width, $y1 , $x1-$width, $y2, $color);
2094          }
2095          switch ($error_bar_type) {
2096              case "line":
2097                  break;
2098              case "tee":
2099                  ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color);
2100                  break;
2101              default:
2102                  ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color);
2103                  break;
2104          }
2105          return true;
2106      }
2107  
2108  	function DrawDot($x_world,$y_world,$dot_type,$color) {
2109          $half_point = $this->point_size / 2;
2110          $x1 = $this->xtr($x_world) - $half_point;
2111          $x2 = $this->xtr($x_world) + $half_point;
2112          $y1 = $this->ytr($y_world) - $half_point;
2113          $y2 = $this->ytr($y_world) + $half_point;
2114  
2115          switch ($dot_type) {
2116              case "halfline":
2117                  ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $this->xtr($x_world), $this->ytr($y_world), $color);
2118                  break;
2119              case "line":
2120                  ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $x2, $this->ytr($y_world), $color);
2121                  break;
2122              case "rect":
2123                  ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
2124                  break;
2125              case "circle":
2126                  ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
2127                  break;
2128              case "dot":
2129                  ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
2130                  ImageFillToBorder($this->img, $x1 + $half_point, $y1 + $half_point, $color, $color);
2131                  break;
2132              case "diamond":
2133  
2134                  $arrpoints = array(
2135                      $x1,$y1 + $half_point,
2136                      $x1 + $half_point, $y1,
2137                      $x2,$y1 + $half_point,
2138                      $x1 + $half_point, $y2
2139                  );
2140  
2141                  ImageFilledPolygon($this->img, $arrpoints, 4, $color);
2142                  break;
2143              case "triangle":
2144                  $arrpoints = array( $x1, $y1 + $half_point,
2145                      $x2, $y1 + $half_point,
2146                      $x1 + $half_point, $y2
2147                  );
2148                  ImageFilledPolygon($this->img, $arrpoints, 3, $color);
2149                  break;
2150              default:
2151                  ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
2152                  break;
2153          }
2154          return true;
2155      }
2156  
2157  	function SetErrorBarLineWidth($which_seblw) {
2158          $this->error_bar_line_width = $which_seblw;
2159          return true;
2160      }
2161  
2162  
2163  	function SetLineWidth($which_lw) {
2164          $this->line_width = $which_lw;
2165          if (!$this->error_bar_line_width) { 
2166              $this->error_bar_line_width = $which_lw;
2167          }
2168          return true;
2169      }
2170  
2171  	function DrawArea() {
2172          //Data comes in as $data[]=("title",x,y,...);

2173          //Set first and last datapoints of area

2174          $i = 0;
2175          while ($i < $this->records_per_group) {
2176              $posarr[$i][] =  $this->xtr($this->min_x);    //x initial

2177              $posarr[$i][] =  $this->ytr($this->x_axis_position);     //y initial

2178              $i++;
2179          }
2180  
2181          reset($this->data_values);
2182          while (list($j, $row) = each($this->data_values)) {
2183              $color_index = 0;
2184              //foreach ($row as $v)

2185              while (list($k, $v) = each($row)) {
2186                  if ($k == 0) {
2187                      //Draw Data Labels

2188                      $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
2189                  } elseif ($k == 1) {
2190                      $x = $this->xtr($v);
2191                      // DrawXDataLabel interferes with Numbers on x-axis

2192                      //$this->DrawXDataLabel($xlab,$x);

2193                  } else {
2194                      // Create Array of points for later

2195  
2196                      $y = $this->ytr($v);
2197                      $posarr[$color_index][] = $x;
2198                      $posarr[$color_index][] = $y;
2199                      $color_index++;
2200                  }
2201              }
2202          }
2203  
2204          //Final_points

2205          for ($i = 0; $i < $this->records_per_group; $i++) {
2206              $posarr[$i][] =  $this->xtr($this->max_x);            //x final

2207              $posarr[$i][] =  $this->ytr($this->x_axis_position);     //y final

2208             }
2209  
2210          $color_index=0;
2211  
2212          //foreach($posarr as $row)

2213          reset($posarr);
2214          while (list(, $row) = each($posarr)) {
2215              if ($color_index >= count($this->ndx_data_color)) $color_index=0;
2216              $barcol = $this->ndx_data_color[$color_index];
2217  //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>";

2218              ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
2219              $color_index++;
2220          }
2221  //exit;

2222  
2223      }
2224  
2225  	function DrawAreaSeries() {
2226  
2227          //Set first and last datapoints of area

2228          $i = 0;
2229          while ($i < $this->records_per_group) {
2230              $posarr[$i][] =  $this->xtr(.5);            //x initial

2231              $posarr[$i][] =  $this->ytr($this->x_axis_position);     //y initial

2232              $i++;
2233          }
2234  
2235          reset($this->data_values);
2236          while (list($j, $row) = each($this->data_values)) {
2237              $color_index = 0;
2238              //foreach ($row as $v)

2239              while (list($k, $v) = each($row)) {
2240                  if ($k == 0) {
2241                      //Draw Data Labels

2242                      $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
2243                      $this->DrawXDataLabel($xlab,$this->xtr($j + .5));
2244                  } else {
2245                      // Create Array of points for later

2246  
2247                      $x = round($this->xtr($j + .5 ));
2248                      $y = round($this->ytr($v));
2249                      $posarr[$color_index][] = $x;
2250                      $posarr[$color_index][] = $y;
2251                      $color_index++;
2252                  }
2253              }
2254          }
2255  
2256          //Final_points

2257          for ($i = 0; $i < $this->records_per_group; $i++) {
2258              $posarr[$i][] =  round($this->xtr($this->max_x + .5));    //x final

2259              $posarr[$i][] =  $this->ytr($this->x_axis_position);         //y final

2260             }
2261  
2262          $color_index=0;
2263  
2264          //foreach($posarr as $row)

2265          reset($posarr);
2266          while (list(, $row) = each($posarr)) {
2267              if ($color_index >= count($this->ndx_data_color)) $color_index=0;
2268              $barcol = $this->ndx_data_color[$color_index];
2269  //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>";

2270              ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
2271              $color_index++;
2272          }
2273  
2274      }
2275  
2276  	function DrawLines() {
2277          //Data comes in as $data[]=("title",x,y,...);

2278          $start_lines = 0;
2279          if ($this->data_type == "text-data") { 
2280              $lastx[0] = $this->xtr(0);
2281              $lasty[0] = $this->xtr(0);
2282          }
2283  
2284          //foreach ($this->data_values as $row)

2285          reset($this->data_values);
2286          while (list($j, $row) = each($this->data_values)) {
2287  
2288              $color_index = 0;
2289              $i = 0; 
2290              //foreach ($row as $v)

2291              while (list($k, $v) = each($row)) {
2292                  if ($k == 0) { 
2293                      $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
2294                  } elseif (($k == 1) && ($this->data_type == "data-data"))  { 
2295                          $x_now = $this->xtr($v);
2296                  } else {
2297                      //(double) $v;

2298                      // Draw Lines

2299                      if ($this->data_type == "text-data") { 
2300                          $x_now = $this->xtr($j+.5); 
2301                      } 
2302  
2303                      //if (is_numeric($v))  //PHP4 only

2304                      if ((strval($v) != "") ) {   //Allow for missing Y data 
2305                          $y_now = $this->ytr($v);
2306                          if ($color_index >= count($this->ndx_data_color)) { $color_index=0;} ;
2307                          $barcol = $this->ndx_data_color[$color_index];
2308  
2309                          if ($start_lines == 1) {
2310                              for ($width = 0; $width < $this->line_width; $width++) {
2311                                  if ($this->line_style[$i] == "dashed") {
2312                                      $this->DrawDashedLine($x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, 4,4, $barcol);
2313                                  } else {
2314                                      ImageLine($this->img, $x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, $barcol);
2315                                  }
2316                              }
2317                          }
2318                          $lastx[$i] = $x_now;
2319                      } else { 
2320                          $y_now = $lasty[$i];
2321                          //Don't increment lastx[$i]

2322                      }
2323                      //$bordercol = $this->ndx_data_border_color[$colbarcount];

2324  
2325                      $lasty[$i] = $y_now;
2326                      $color_index++;
2327                      $i++;
2328                  }
2329                  //Now we are assured an x_value

2330                  if ( ($this->draw_x_data_labels == 1) && ($k == 1) )  { //See "labels_note1 above.
2331                      $this->DrawXDataLabel($xlab,$x_now);
2332                  }
2333              } //while rows of data

2334              $start_lines = 1;
2335          }
2336      }
2337  
2338          //Data comes in as $data[]=("title",x,y,e+,e-,y2,e2+,e2-,...);

2339  
2340  	function DrawLineSeries() {
2341          //This function is replaced by DrawLines

2342          //Tests have shown not much improvement in speed by having separate routines for DrawLineSeries and DrawLines

2343          //For ease of programming I have combined them

2344          return false;
2345      } //function DrawLineSeries

2346  
2347  	function DrawDashedLine($x1pix,$y1pix,$x2pix,$y2pix,$dash_length,$dash_space,$color) {
2348          //Code based on work by Ariel Garza and James Pine

2349          //I've decided to have this be in pixels only as a replacement for ImageLine

2350          //$x1pix = $this->xtr($x1);

2351          //$y1pix = $this->ytr($y1);

2352          //$x2pix = $this->xtr($x2);

2353          //$y2pix = $this->ytr($y2);

2354  
2355          // Get the length of the line in pixels

2356          $line_length = ceil (sqrt(pow(($x2pix - $x1pix),2) + pow(($y2pix - $y1pix),2)) );
2357  
2358          $dx = ($x2pix - $x1pix) / $line_length;
2359          $dy = ($y2pix - $y1pix) / $line_length;
2360          $lastx    = $x1pix;
2361          $lasty    = $y1pix;
2362  
2363          // Draw the dashed line

2364          for ($i = 0; $i < $line_length; $i += ($dash_length + $dash_space)) {
2365              $xpix = ($dash_length * $dx) + $lastx;
2366              $ypix = ($dash_length * $dy) + $lasty;
2367  
2368              ImageLine($this->img,$lastx,$lasty,$xpix,$ypix,$color);
2369              $lastx = $xpix + ($dash_space * $dx);
2370              $lasty = $ypix + ($dash_space * $dy);
2371          }
2372      } // function DrawDashedLine

2373  
2374  	function DrawBars() {
2375  
2376          if ($this->data_type != "text-data") { 
2377              $this->DrawError('Bar plots must be text-data: use function SetDataType("text-data")');
2378          }
2379  
2380          $xadjust = ($this->records_per_group * $this->record_bar_width )/4;
2381  
2382          reset($this->data_values);
2383          while (list($j, $row) = each($this->data_values)) {
2384  
2385              $color_index = 0;
2386              $colbarcount = 0;
2387              $x_now = $this->xtr($j+.5);
2388  
2389              while (list($k, $v) = each($row)) {
2390                  if ($k == 0) {
2391                      //Draw Data Labels

2392                      $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
2393                      $this->DrawXDataLabel($xlab,$x_now);
2394                  } else {
2395                      // Draw Bars ($v)

2396                      $x1 = $x_now - $this->data_group_space + ($k-1)*$this->record_bar_width;
2397                      $x2 = $x1 + $this->record_bar_width*$this->bar_width_adjust; 
2398  
2399                      if ($v < $this->x_axis_position) {
2400                          $y1 = $this->ytr($this->x_axis_position);
2401                          $y2 = $this->ytr($v);
2402                      } else {
2403                          $y1 = $this->ytr($v);
2404                          $y2 = $this->ytr($this->x_axis_position);
2405                      }
2406  
2407                      if ($color_index >= count($this->ndx_data_color)) $color_index=0;
2408                      if ($colbarcount >= count($this->ndx_data_border_color)) $colbarcount=0;
2409                      $barcol = $this->ndx_data_color[$color_index];
2410                      $bordercol = $this->ndx_data_border_color[$colbarcount];
2411  
2412                      if ((strval($v) != "") ) {   //Allow for missing Y data 
2413                          if ($this->shading > 0) {
2414                              for($i=0;$i<($this->shading);$i++) { 
2415                              //Shading set in SetDefaultColors

2416                              ImageFilledRectangle($this->img, $x1+$i, $y1-$i, $x2+$i, $y2-$i, $this->ndx_i_light);
2417                              }
2418                          }
2419  
2420                          ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $barcol);
2421                          ImageRectangle($this->img, $x1, $y1, $x2, $y2, $bordercol);
2422                          if ($this->draw_data_labels == '1') {  //ajo
2423                              $y1 = $this->ytr($this->label_scale_position * $v);
2424                              //$this->DrawDataLabel($v,$j + .5,$v*$this->label_scale_position);

2425                              $this->DrawText($this->x_label_ttffont, $this->x_label_angle,
2426                                  $x1+$this->record_bar_width/2, $y1, $this->ndx_label_color, $this->x_label_ttffont_size, $v,'center','top');
2427                          }
2428                      } 
2429  
2430                      $color_index++;
2431                      $colbarcount++;
2432                  }
2433              }
2434          }
2435      } //function DrawBars

2436  
2437  	function DrawLegend($which_x1,$which_y1,$which_boxtype) {
2438          //Base code submitted by Marlin Viss

2439          $max_legend_length=0;
2440          reset($this->legend);
2441          while (list(,$leg) = each($this->legend)) {
2442              $len = strlen($leg);
2443              if ($max_legend_length < $len) {
2444                  $max_legend_length = $len;
2445              }
2446          }
2447  
2448          $line_spacing = 1.25;
2449          $vert_margin = $this->small_font_height/2 ;
2450          $dot_height = $this->small_font_height*$line_spacing - 1;
2451  
2452      //Upper Left

2453          if ((!$which_x1) || (!$which_y1) ) {
2454              $box_start_x = $this->plot_area[2] - $this->small_font_width*($max_legend_length+4);
2455              $box_start_y = $this->plot_area[1] + 4;
2456          } else { 
2457              $box_start_x = $which_x1;
2458              $box_start_y = $which_y1;
2459          }
2460  
2461      //Lower Right

2462          $box_end_y = $box_start_y + $this->small_font_height*(count($this->legend)+1) + 2*$vert_margin; 
2463          //$box_end_x = $this->plot_area[2] - 5;

2464          $box_end_x = $box_start_x + $this->small_font_width*($max_legend_length+4) - 5;
2465  
2466  
2467      // Draw box for legend

2468          ImageFilledRectangle($this->img,
2469              $box_start_x, $box_start_y,$box_end_x,
2470              $box_end_y, $this->ndx_bg_color);
2471          ImageRectangle($this->img,
2472              $box_start_x, $box_start_y,$box_end_x,
2473              $box_end_y, $this->ndx_grid_color);
2474  
2475          $color_index=0;
2476          $i = 0;
2477  
2478  
2479          reset($this->legend);
2480  
2481  
2482          while (list(,$leg) = each($this->legend)) {
2483              $y_pos = $box_start_y + $this->small_font_height*($i)*($line_spacing) + $vert_margin;
2484  
2485              ImageString($this->img, $this->small_font,
2486              $box_start_x + $this->small_font_width*( $max_legend_length - strlen($leg) + 1 ) ,
2487              $y_pos,
2488              $leg, $this->ndx_text_color);
2489  
2490              if ($color_index >= count($this->ndx_data_color)) $color_index=0;
2491      // Draw a box in the data color

2492              ImageFilledRectangle($this->img,
2493                  $box_end_x - $this->small_font_width*2,
2494                  $y_pos + 1, $box_end_x - $this->small_font_width,
2495                  $y_pos + $dot_height,
2496                  $this->ndx_data_color[$color_index]);
2497  
2498              ImageRectangle($this->img,
2499                  $box_end_x - $this->small_font_width*2,
2500                  $y_pos + 1, $box_end_x - $this->small_font_width,
2501                  $y_pos + $dot_height,
2502                  $this->ndx_text_color);
2503              $i++;
2504              $color_index++;
2505          }
2506      } //function DrawLegend

2507  
2508  
2509  	function DrawGraph() {
2510  
2511          if (($this->img) == "") {
2512              $this->DrawError('No Image Defined: DrawGraph');
2513              //$this->PHPlot();

2514          }
2515  
2516          if (! is_array($this->data_values)) {
2517              $this->DrawBackground();
2518              $this->DrawError("No array of data in \$data_values");
2519          } else {
2520              if (!$this->data_color) {
2521                  $this->SetDataColors(array('blue','green','yellow','red','orange','blue'),array('black'));
2522              }
2523  
2524              $this->FindDataLimits();  //Get maxima and minima for scaling

2525  
2526              $this->SetXLabelHeight();        //Get data for bottom margin

2527  
2528              $this->SetYLabelWidth();        //Get data for left margin

2529  
2530              if (!$this->plot_area_width) {
2531                  $this->SetPlotAreaPixels('','','','');        //Set Margins

2532              }
2533  
2534              if (!$this->plot_max_y) {  //If not set by user call SetPlotAreaWorld,
2535                  $this->SetPlotAreaWorld('','','','');
2536              }
2537  
2538              if ($this->data_type == "text-data") {
2539                  $this->SetEqualXCoord();
2540              }
2541  
2542              $this->SetPointSize($this->point_size);
2543  
2544              $this->DrawBackground();
2545              $this->DrawImageBorder();
2546  
2547              $this->SetTranslation();
2548  
2549              if ($this->draw_plot_area_background == 1) {
2550                  $this->DrawPlotAreaBackground();
2551              }
2552  //$foo = "$this->max_y, $this->min_y, $new_miny, $new_maxy, $this->x_label_height";

2553  //ImageString($this->img, 4, 20, 20, $foo, $this->ndx_text_color);

2554  
2555              switch ($this->plot_type) {
2556                  case "bars":
2557                      $this->DrawPlotBorder();
2558                      $this->DrawLabels();
2559                      $this->DrawBars();
2560                      $this->DrawXAxis();
2561                      break;
2562                  case "thinbarline":
2563                      $this->DrawPlotBorder();
2564                      $this->DrawLabels();
2565                      $this->DrawThinBarLines();
2566                      break;
2567                  case "lines":
2568                      $this->DrawPlotBorder();
2569                      $this->DrawLabels();
2570                      if ( $this->data_type == "text-data") {
2571                          $this->DrawLines();
2572                      } elseif ( $this->data_type == "data-data-error") {
2573                          $this->DrawLinesError();
2574                      } else {
2575                          $this->DrawLines();
2576                      }
2577                      break;
2578                  case "area":
2579                      $this->DrawPlotBorder();
2580                      $this->DrawLabels();
2581                      if ( $this->data_type == "text-data") {
2582                          $this->DrawAreaSeries();
2583                      } else {
2584                          $this->DrawArea();
2585                      }
2586                      break;
2587                  case "linepoints":
2588                      $this->DrawPlotBorder();
2589                      $this->DrawLabels();
2590                      if ( $this->data_type == "text-data") {
2591                          $this->DrawLines();
2592                          $this->DrawDots();
2593                      } elseif ( $this->data_type == "data-data-error") {
2594                          $this->DrawLinesError();
2595                          $this->DrawDotsError();
2596                      } else {
2597                          $this->DrawLines();
2598                          $this->DrawDots();
2599                      }
2600                      break;
2601                  case "points";
2602                      $this->DrawPlotBorder();
2603                      $this->DrawLabels();
2604                      if ( $this->data_type == "text-data") {
2605                          $this->DrawDots();
2606                      } elseif ( $this->data_type == "data-data-error") {
2607                          $this->DrawDotsError();
2608                      } else {
2609                          $this->DrawDots();
2610                      }
2611                      break;
2612                  case "pie":
2613                      $this->DrawPieChart();
2614                      $this->DrawLabels();
2615                      break;
2616                  default:
2617                      $this->DrawPlotBorder();
2618                      $this->DrawLabels();
2619                      $this->DrawBars();
2620                      break;
2621              }
2622  
2623              if ($this->legend) {
2624                  $this->DrawLegend($this->legend_x_pos,$this->legend_y_pos,'');
2625              }
2626  
2627          }
2628          if ($this->print_image == 1) { 
2629              $this->PrintImage();
2630          }
2631      } //function DrawGraph

2632  
2633   }
2634  
2635  // $graph = new PHPlot;

2636  
2637  // $graph->DrawGraph();

2638  
2639  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7