ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/classes/phplot.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // +----------------------------------------------------------------------+
00004 // |zen-cart Open Source E-commerce                                       |
00005 // +----------------------------------------------------------------------+
00006 // | Copyright (c) 2003-2009 The zen-cart developers                           |
00007 // |                                                                      |
00008 // | http://www.zen-cart.com/index.php                                    |
00009 // |                                                                      |
00010 // | Portions Copyright (c) 2003 osCommerce                               |
00011 // +----------------------------------------------------------------------+
00012 // | This source file is subject to version 2.0 of the GPL license,       |
00013 // | that is bundled with this package in the file LICENSE, and is        |
00014 // | available through the world-wide-web at the following url:           |
00015 // | http://www.zen-cart.com/license/2_0.txt.                             |
00016 // | If you did not receive a copy of the zen-cart license and are unable |
00017 // | to obtain it through the world-wide-web, please send a note to       |
00018 // | [email protected] so we can mail you a copy immediately.          |
00019 // +----------------------------------------------------------------------+
00020 //  $Id: phplot.php 15673 2010-03-14 21:40:00Z kuroi $
00021 
00022 /*
00023   PHPLOT 4.4.6 Copyright (c) 1998-2001 Afan Ottenheimer
00024 */
00025 
00026 class PHPlot{
00027 
00028   var $is_inline = 0;                   //0 = Sends headers, 1 = sends just raw image data
00029   var $browser_cache = '1';     // 0 = Sends headers for browser to not cache the image, (i.e. 0 = don't let browser cache image)
00030                   // (only if is_inline = 0 also)
00031   var $session_set = '';                //Do not change
00032   var $scale_is_set = '';               //Do not change
00033   var $draw_plot_area_background = '';
00034 
00035   var $image_width;     //Total Width in Pixels
00036   var $image_height;    //Total Height in Pixels
00037   var $image_border_type = ''; //raised, plain, ''
00038   var $x_left_margin;
00039   var $y_top_margin;
00040   var $x_right_margin;
00041   var $y_bot_margin;
00042   var $plot_area = array(5,5,600,400);
00043   var $x_axis_position = 0;     //Where to draw the X_axis (world coordinates)
00044   var $y_axis_position = '';  //Leave blank for Y axis at left of plot. (world coord.)
00045   var $xscale_type = 'linear';  //linear or log
00046   var $yscale_type = 'linear';
00047 
00048 //Use for multiple plots per image
00049   var $print_image = 1;  //Used for multiple charts per image.
00050 
00051 //Fonts
00052   var $use_ttf  = 0;              //Use TTF fonts (1) or not (0)
00053   var $font_path = './';  //To be added
00054   var $font = './benjamingothic.ttf';
00055 
00057   var $small_ttffont_size = 12; //
00058   //non-ttf
00059   var $small_font = 2; // fonts = 1,2,3,4 or 5
00060   var $small_font_width = 6.0; // width in pixels (2=6,3=8,4=8)
00061   var $small_font_height = 8.0; // height in pixels (2=8,3=10,4=12)
00062 
00064   var $title_ttffont = './benjamingothic.ttf';
00065   var $title_ttffont_size = 14;
00066   var $title_angle= 0;
00067   //non-ttf
00068   var $title_font = '4'; // fonts = 1,2,3,4,5
00069 
00071   var $axis_ttffont = './benjamingothic.ttf';
00072   var $axis_ttffont_size = 8;
00073   var $x_datalabel_angle = 0;
00074   //non-ttf
00075   var $axis_font = 2;
00076 
00078   var $datalabel_font = '2';
00079 
00081   var $x_label_ttffont = './benjamingothic.ttf';
00082   var $x_label_ttffont_size = '12';
00083   var $x_label_angle = '0';
00084 
00085   var $y_label_ttffont = './benjamingothic.ttf';
00086   var $y_label_ttffont_size = '12';
00087   var $y_label_angle = 90;
00088   var $y_label_width = '';
00089 
00090 //Formats
00091   var $file_format = 'png';
00092   var $file_name = '';  //For output to a file instead of stdout
00093 
00094 //Plot Colors
00095   var $shading = 0;
00096   var $color_array = 1; //1 = include small list
00097               //2 = include large list
00098               //array =  define your own color translation. See rgb.inc.php and SetRGBArray
00099   var $bg_color;
00100   var $plot_bg_color;
00101   var $grid_color;
00102   var $light_grid_color;
00103   var $tick_color;
00104   var $title_color;
00105   var $label_color;
00106   var $text_color;
00107   var $i_light = '';
00108 
00109 //Data
00110   var $data_type = 'text-data'; //text-data, data-data-error, data-data
00111   var $plot_type= 'linepoints'; //bars, lines, linepoints, area, points, pie, thinbarline
00112   var $line_width = 2;
00113   var $line_style = array('solid','solid','solid','dashed','dashed','solid'); //Solid or dashed lines
00114 
00115   var $data_color = ''; //array('blue','green','yellow',array(0,0,0));
00116   var $data_border_color = '';
00117 
00118   var $label_scale_position = '.5';  //1 = top, 0 = bottom
00119   var $group_frac_width = '.7'; //value from 0 to 1 = width of bar
00120   var $bar_width_adjust = '1'; //1 = bars of normal width, must be > 0
00121 
00122   var $point_size = 10;
00123   var $point_shape = 'diamond'; //rect,circle,diamond,triangle,dot,line,halfline
00124   var $error_bar_shape = 'tee'; //tee, line
00125   var $error_bar_size = 5; //right left size of tee
00126   var $error_bar_line_width = ''; //If set then use it, else use $line_width for thickness
00127   var $error_bar_color = '';
00128   var $data_values;
00129 
00130   var $plot_border_type = 'full'; //left, none, full
00131   var $plot_area_width = '';
00132   var $number_x_points;
00133   var $plot_min_x; // Max and min of the plot area
00134   var $plot_max_x= ''; // Max and min of the plot area
00135   var $plot_min_y= ''; // Max and min of the plot area
00136   var $plot_max_y = ''; // Max and min of the plot area
00137   var $min_y = '';
00138   var $max_y = '';
00139   var $max_x = 10;  //Must not be = 0;
00140   var $y_precision = '1';
00141   var $x_precision = '1';
00142   var $si_units = '';
00143 
00144 //Labels
00145   var $draw_data_labels = '0';
00146   var $legend = '';  //an array
00147   var $legend_x_pos = '';
00148   var $legend_y_pos = '';
00149   var $title_txt = "";
00150   var $y_label_txt = '';
00151   var $x_label_txt = "";
00152 
00153 //DataAxis Labels (on each axis)
00154   var $y_grid_label_type = 'data';    //data, none, time, other
00155   var $y_grid_label_pos = 'plotleft'; //plotleft, plotright, yaxis, both
00156   var $x_grid_label_type = 'data';    //data, title, none, time, other
00157   var $draw_x_data_labels = '';       // 0=false, 1=true, ""=let program decide
00158   var $x_time_format = "%H:%m:%s";    //See http://www.php.net/manual/html/function.strftime.html
00159   var $x_datalabel_maxlength = 10;
00160 
00161 //Tick Formatting
00162   var $tick_length = '10';   //pixels: tick length from axis left/downward
00163   //tick_length2 to be implemented
00164   //var $tick_length2 = '';  //pixels: tick length from axis line rightward/upward
00165   var $draw_vert_ticks = 1;  //1 = draw ticks, 0 = don't draw ticks
00166   var $num_vert_ticks = '';
00167   var $vert_tick_increment=''; //Set num_vert_ticks or vert_tick_increment, not both.
00168   var $vert_tick_position = 'both'; //plotright=(right of plot only), plotleft=(left of plot only),
00169                 //both = (both left and right of plot), yaxis=(crosses y axis)
00170   var $horiz_tick_increment=''; //Set num_horiz_ticks or horiz_tick_increment, not both.
00171   var $num_horiz_ticks='';
00172   var $skip_top_tick = '0';
00173   var $skip_bottom_tick = '0';
00174 
00175 //Grid Formatting
00176   var $draw_x_grid = 0;
00177   var $draw_y_grid = 1;
00178 
00179 
00180 //BEGIN CODE
00182   //Constructor: Setup Img pointer, Colors and Size of Image
00183   function PHPlot($which_width=600,$which_height=400,$which_output_file="",$which_input_file="") {
00184 
00185     $this->SetRGBArray('2');
00186     $this->background_done = 0; //Set to 1 after background image first drawn
00187 
00188     if ($which_output_file != "") { $this->SetOutputFile($which_output_file);  }
00189 
00190     if ($which_input_file != "") {
00191       $this->SetInputFile($which_input_file) ;
00192     } else {
00193       $this->SetImageArea($which_width, $which_height);
00194       $this->InitImage();
00195     }
00196 
00197     if ( ($this->session_set == 1) && ($this->img == "") ) {  //For sessions
00198       //Do nothing
00199     } else {
00200       $this->SetDefaultColors();
00201     }
00202 
00203     $this->SetIndexColors();
00204 
00205   }
00206 
00207   //Set up the image and colors
00208   function InitImage() {
00209     //if ($this->img) {
00210     //  ImageDestroy($this->img);
00211     //}
00212     $this->img = ImageCreate($this->image_width, $this->image_height);
00213     return true;
00214   }
00215 
00216   function SetBrowserCache($which_browser_cache) {  //Submitted by Thiemo Nagel
00217     $this->browser_cache = $which_browser_cache;
00218     return true;
00219   }
00220 
00221   function SetPrintImage($which_pi) {
00222     $this->print_image = $which_pi;
00223     return true;
00224   }
00225 
00226   function SetIsInline($which_ii) {
00227     $this->is_inline = $which_ii;
00228     return true;
00229   }
00230 
00231   function SetUseTTF($which_ttf) {
00232     $this->use_ttf = $which_ttf;
00233     return true;
00234   }
00235 
00236   function SetTitleFontSize($which_tfs) {
00237     //TTF
00238     $this->title_ttffont_size = $which_tfs; //pt size
00239 
00240     //Non-TTF settings
00241     if (($which_tfs > 5) && (!$this->use_ttf)) {
00242       $this->DrawError('Non-TTF font size must be 1,2,3,4 or 5');
00243       return false;
00244     } else {
00245       $this->title_font = $which_tfs;
00246       //$this->title_font_height = ImageFontHeight($which_tfs) // height in pixels
00247       //$this->title_font_width = ImageFontWidth($which_tfs); // width in pixels
00248     }
00249     return true;
00250   }
00251 
00252   function SetLineStyles($which_sls){
00253     $this->line_style = $which_sls;
00254     return true;
00255   }
00256 
00257   function SetLegend($which_leg){
00258     if (is_array($which_leg)) {
00259       $this->legend = $which_leg;
00260       return true;
00261     } else {
00262       $this->DrawError('Error: SetLegend argument must be an array');
00263       return false;
00264     }
00265   }
00266 
00267   function SetLegendPixels($which_x,$which_y,$which_type) {
00268     //which_type not yet used
00269     $this->legend_x_pos = $which_x;
00270     $this->legend_y_pos = $which_y;
00271     return true;
00272   }
00273 
00274   function SetLegendWorld($which_x,$which_y,$which_type='') {
00275     //which_type not yet used
00276     //Must be called after scales are set up.
00277     if ($this->scale_is_set != 1) { $this->SetTranslation(); }
00278     $this->legend_x_pos = $this->xtr($which_x);
00279     $this->legend_y_pos = $this->ytr($which_y);
00280     return true;
00281   }
00282 /* ***************************************
00283   function SetFileFormat($which_file_format) { //Only works with PHP4
00284     $asked = strtolower($which_file_format);
00285     if( $asked =="jpg" || $asked =="png" || $asked =="gif" || $asked =="wbmp" ) {
00286       if( $asked=="jpg" && !(imagetypes() & IMG_JPG) )
00287         return false;
00288       elseif( $asked=="png" && !(imagetypes() & IMG_PNG) )
00289         return false;
00290       elseif( $asked=="gif" && !(imagetypes() & IMG_GIF) )
00291         return false;
00292       elseif( $asked=="wbmp" && !(imagetypes() & IMG_WBMP) )
00293         return false;
00294       else {
00295         $this->img_format=$asked;
00296         return true;
00297       }
00298     }
00299     else
00300       return false;
00301   }
00302 
00303 *************************************** */
00304   function SetFileFormat($which_file_format) {
00305   //eventually test to see if that is supported - if not then return false
00306     $asked = strtolower(trim($which_file_format));
00307     if( ($asked=='jpg') || ($asked=='png') || ($asked=='gif') || ($asked=='wbmp') ) {
00308       $this->file_format = $asked;
00309       return true;
00310     } else {
00311       return false;
00312     }
00313   }
00314 
00315   function SetInputFile($which_input_file) {
00316     //$this->SetFileFormat($which_frmt);
00317     $size = GetImageSize($which_input_file);
00318     $input_type = $size[2];
00319 
00320     switch($input_type) {  //After SetFileFormat is in lower case
00321       case "1":
00322         $im = @ImageCreateFromGIF ($which_input_file);
00323         if (!$im) { // See if it failed
00324           $this->PrintError("Unable to open $which_input_file as a GIF");
00325           return false;
00326         }
00327       break;
00328       case "3":
00329         $im = @ImageCreateFromPNG ($which_input_file);
00330         if (!$im) { // See if it failed
00331           $this->PrintError("Unable to open $which_input_file as a PNG");
00332           return false;
00333         }
00334       break;
00335       case "2":
00336         $im = @ImageCreateFromJPEG ($which_input_file);
00337         if (!$im) { // See if it failed
00338           $this->PrintError("Unable to open $which_input_file as a JPG");
00339           return false;
00340         }
00341       break;
00342       default:
00343         $this->PrintError('Please select wbmp,gif,jpg, or png for image type!');
00344         return false;
00345       break;
00346     }
00347 
00348     //Get Width and Height of Image
00349     $this->SetImageArea($size[0],$size[1]);
00350 
00351     $this->img = $im;
00352 
00353     return true;
00354 
00355   }
00356 
00357   function SetOutputFile($which_output_file) {
00358     $this->output_file = $which_output_file;
00359     return true;
00360   }
00361 
00362   function SetImageArea($which_iw,$which_ih) {
00363     //Note this is now an Internal function - please set w/h via PHPlot()
00364     $this->image_width = $which_iw;
00365     $this->image_height = $which_ih;
00366 
00367     return true;
00368   }
00369 
00370 
00371   function SetYAxisPosition($which_pos) {
00372     $this->y_axis_position = $which_pos;
00373     return true;
00374   }
00375   function SetXAxisPosition($which_pos) {
00376     $this->x_axis_position = $which_pos;
00377     return true;
00378   }
00379   function SetXTimeFormat($which_xtf) {
00380     $this->x_time_format = $which_xtf;
00381     return true;
00382   }
00383   function SetXDataLabelMaxlength($which_xdlm) {
00384     if ($which_xdlm >0 ) {
00385       $this->x_datalabel_maxlength = $which_xdlm;
00386       return true;
00387     } else {
00388       return false;
00389     }
00390   }
00391   function SetXDataLabelAngle($which_xdla) {
00392     $this->x_datalabel_angle = $which_xdla;
00393     return true;
00394   }
00395   function SetXScaleType($which_xst) {
00396     $this->xscale_type = $which_xst;
00397     return true;
00398   }
00399   function SetYScaleType($which_yst) {
00400     $this->yscale_type = $which_yst;
00401     if ($this->x_axis_position <= 0) {
00402       $this->x_axis_position = 1;
00403     }
00404     return true;
00405   }
00406 
00407   function SetPrecisionX($which_prec) {
00408     $this->x_precision = $which_prec;
00409     return true;
00410   }
00411   function SetPrecisionY($which_prec) {
00412     $this->y_precision = $which_prec;
00413     return true;
00414   }
00415 
00416 
00417   function SetIndexColors() { //Internal Method called to set colors and preserve state
00418     //These are the colors of the image that are used. They are initialized
00419     //to work with sessions and PHP.
00420 
00421     $this->ndx_i_light = $this->SetIndexColor($this->i_light);
00422     $this->ndx_i_dark  = $this->SetIndexColor($this->i_dark);
00423     $this->ndx_bg_color= $this->SetIndexColor($this->bg_color);
00424     $this->ndx_plot_bg_color= $this->SetIndexColor($this->plot_bg_color);
00425 
00426     $this->ndx_title_color= $this->SetIndexColor($this->title_color);
00427     $this->ndx_tick_color= $this->SetIndexColor($this->tick_color);
00428     $this->ndx_label_color= $this->SetIndexColor($this->label_color);
00429     $this->ndx_text_color= $this->SetIndexColor($this->text_color);
00430     $this->ndx_light_grid_color= $this->SetIndexColor($this->light_grid_color);
00431     $this->ndx_grid_color= $this->SetIndexColor($this->grid_color);
00432 
00433     reset($this->error_bar_color);
00434     unset($ndx_error_bar_color);
00435     $i = 0;
00436     while (list(, $col) = each($this->error_bar_color)) {
00437       $this->ndx_error_bar_color[$i] = $this->SetIndexColor($col);
00438       $i++;
00439     }
00440     //reset($this->data_border_color);
00441     unset($ndx_data_border_color);
00442     $i = 0;
00443     while (list(, $col) = each($this->data_border_color)) {
00444       $this->ndx_data_border_color[$i] = $this->SetIndexColor($col);
00445       $i++;
00446     }
00447     //reset($this->data_color);
00448     unset($ndx_data_color);
00449     $i = 0;
00450     while (list(, $col) = each($this->data_color)) {
00451       $this->ndx_data_color[$i] = $this->SetIndexColor($col);
00452       $i++;
00453     }
00454 
00455     return true;
00456   }
00457 
00458 
00459   function SetDefaultColors() {
00460 
00461     $this->i_light = array(194,194,194);
00462     $this->i_dark =  array(100,100,100);
00463     $this->SetPlotBgColor(array(222,222,222));
00464     $this->SetBackgroundColor(array(200,222,222)); //can use rgb values or "name" values
00465     $this->SetLabelColor('black');
00466     $this->SetTextColor('black');
00467     $this->SetGridColor('black');
00468     $this->SetLightGridColor(array(175,175,175));
00469     $this->SetTickColor('black');
00470     $this->SetTitleColor(array(0,0,0)); // Can be array or name
00471     $this->data_color = array('blue','green','yellow','red','orange');
00472     $this->error_bar_color = array('blue','green','yellow','red','orange');
00473     $this->data_border_color = array('black');
00474 
00475     $this->session_set = 1; //Mark it down for PHP session() usage.
00476   }
00477 
00478   function PrintImage() {
00479 
00480     if ( ($this->browser_cache == 0) && ($this->is_inline == 0)) { //Submitted by Thiemo Nagel
00481       header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
00482       header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT');
00483       header('Cache-Control: no-cache, must-revalidate');
00484       header('Pragma: no-cache');
00485     }
00486 
00487     switch($this->file_format) {
00488       case "png":
00489         if ($this->is_inline == 0) {
00490           Header('Content-type: image/png');
00491         }
00492         if ($this->is_inline == 1 && $this->output_file != "") {
00493           ImagePng($this->img,$this->output_file);
00494         } else {
00495           ImagePng($this->img);
00496         }
00497         break;
00498       case "jpg":
00499         if ($this->is_inline == 0) {
00500           Header('Content-type: image/jpeg');
00501         }
00502         if ($this->is_inline == 1 && $this->output_file != "") {
00503           ImageJPEG($this->img,$this->output_file);
00504         } else {
00505           ImageJPEG($this->img);
00506         }
00507         break;
00508       case "gif":
00509         if ($this->is_inline == 0) {
00510           Header('Content-type: image/gif');
00511         }
00512         if ($this->is_inline == 1 && $this->output_file != "") {
00513           ImageGIF($this->img,$this->output_file);
00514         } else {
00515           ImageGIF($this->img);
00516         }
00517 
00518         break;
00519       case "wbmp":
00520         if ($this->is_inline == 0) {
00521           Header('Content-type: image/wbmp');
00522         }
00523         if ($this->is_inline == 1 && $this->output_file != "") {
00524           ImageWBMP($this->img,$this->output_file);
00525         } else {
00526           ImageWBMP($this->img);
00527         }
00528 
00529         break;
00530       default:
00531         $this->PrintError('Please select an image type!<br>');
00532         break;
00533     }
00534     ImageDestroy($this->img);
00535     return true;
00536   }
00537 
00538 
00539   function DrawBackground() {
00540     //if ($this->img == "") { $this->InitImage(); }
00541     if ($this->background_done == 0) { //Don't draw it twice if drawing two plots on one image
00542       ImageFilledRectangle($this->img, 0, 0,
00543         $this->image_width, $this->image_height, $this->ndx_bg_color);
00544       $this->background_done = 1;
00545     }
00546     return true;
00547   }
00548 
00549   function DrawImageBorder() {
00550     switch ($this->image_border_type) {
00551       case "raised":
00552         ImageLine($this->img,0,0,$this->image_width-1,0,$this->ndx_i_light);
00553         ImageLine($this->img,1,1,$this->image_width-2,1,$this->ndx_i_light);
00554         ImageLine($this->img,0,0,0,$this->image_height-1,$this->ndx_i_light);
00555         ImageLine($this->img,1,1,1,$this->image_height-2,$this->ndx_i_light);
00556         ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
00557         ImageLine($this->img,0,$this->image_height-1,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
00558         ImageLine($this->img,$this->image_width-2,1,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
00559         ImageLine($this->img,1,$this->image_height-2,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
00560       break;
00561       case "plain":
00562         ImageLine($this->img,0,0,$this->image_width,0,$this->ndx_i_dark);
00563         ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height,$this->ndx_i_dark);
00564         ImageLine($this->img,$this->image_width-1,$this->image_height-1,0,$this->image_height-1,$this->ndx_i_dark);
00565         ImageLine($this->img,0,0,0,$this->image_height,$this->ndx_i_dark);
00566       break;
00567       default:
00568       break;
00569     }
00570     return true;
00571   }
00572 
00573   function SetPlotBorderType($which_pbt) {
00574     $this->plot_border_type = $which_pbt; //left, none, anything else=full
00575   }
00576 
00577   function SetImageBorderType($which_sibt) {
00578     $this->image_border_type = $which_sibt; //raised, plain
00579   }
00580 
00581   function SetDrawPlotAreaBackground($which_dpab) {
00582     $this->draw_plot_area_background = $which_dpab;  // 1=true or anything else=false
00583   }
00584 
00585   function SetDrawDataLabels($which_ddl) {  //Draw next to datapoints
00586     $this->draw_data_labels = $which_ddl;  // 1=true or anything else=false
00587   }
00588 
00589   function SetDrawXDataLabels($which_dxdl) {  //Draw on X Axis
00590     $this->draw_x_data_labels = $which_dxdl;  // 1=true or anything else=false
00591   }
00592 
00593   function SetDrawYGrid($which_dyg) {
00594     $this->draw_y_grid = $which_dyg;  // 1=true or anything else=false
00595   }
00596 
00597   function SetDrawXGrid($which_dxg) {
00598     $this->draw_x_grid = $which_dxg;  // 1=true or anything else=false
00599   }
00600 
00601   function SetYGridLabelType($which_yglt) {
00602     $this->y_grid_label_type = $which_yglt;
00603     return true;
00604   }
00605 
00606   function SetXGridLabelType($which_xglt) {
00607     $this->x_grid_label_type = $which_xglt;
00608     return true;
00609   }
00610 
00611   function SetXLabel($xlbl) {
00612     $this->x_label_txt = $xlbl;
00613     return true;
00614   }
00615   function SetYLabel($ylbl) {
00616     $this->y_label_txt = $ylbl;
00617     return true;
00618   }
00619   function SetTitle($title) {
00620     $this->title_txt = $title;
00621     return true;
00622   }
00623 
00624   //function SetLabels($xlbl,$ylbl,$title) {
00625   //    $this->title_txt = $title;
00626   //    $this->x_label_txt = $xlbl;
00627   //    $this->y_label_txt = $ylbl;
00628   //}
00629 
00630   function DrawLabels() {
00631     $this->DrawTitle();
00632     $this->DrawXLabel();
00633     $this->DrawYLabel();
00634     return true;
00635   }
00636 
00637   function DrawXLabel() {
00638     if ($this->use_ttf == 1) {
00639       $xpos = $this->xtr(($this->plot_max_x + $this->plot_min_x)/2.0) ;
00640       $ypos = $this->ytr($this->plot_min_y) + $this->x_label_height/2.0;
00641       $this->DrawText($this->x_label_ttffont, $this->x_label_angle,
00642         $xpos, $ypos, $this->ndx_label_color, $this->x_label_ttffont_size, $this->x_label_txt,'center');
00643     } else {
00644       //$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) ;
00645       $xpos = 0.0 + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ;
00646       $ypos = ($this->ytr($this->plot_min_y) + $this->x_label_height/2);
00647 
00648       $this->DrawText($this->small_font, $this->x_label_angle,
00649         $xpos, $ypos, $this->ndx_label_color, "", $this->x_label_txt, 'center');
00650 
00651     }
00652     return true;
00653   }
00654 
00655   function DrawYLabel() {
00656     if ($this->use_ttf == 1) {
00657       $size = $this->TTFBBoxSize($this->y_label_ttffont_size, 90, $this->y_label_ttffont, $this->y_label_txt);
00658       $xpos = 8 + $size[0];
00659       $ypos = ($size[1])/2 + $this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) ;
00660       $this->DrawText($this->y_label_ttffont, 90,
00661         $xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
00662     } else {
00663       $xpos = 8;
00664       $ypos = (($this->small_font_width*strlen($this->y_label_txt)/2.0) +
00665           $this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) );
00666       $this->DrawText($this->small_font, 90,
00667         $xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
00668     }
00669     return true;
00670   }
00671 
00672   function DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left',$which_valign='') {
00673     if ($this->use_ttf == 1 ) {
00674       $size = $this->TTFBBoxSize($which_size, $which_angle, $which_font, $which_text);
00675       if ($which_valign == 'bottom') {
00676         $which_ypos = $which_ypos + ImageFontHeight($which_font);
00677       }
00678       if ($which_halign == 'center') {
00679         $which_xpos = $which_xpos - $size[0]/2;
00680       }
00681       ImageTTFText($this->img, $which_size, $which_angle,
00682         $which_xpos, $which_ypos, $which_color, $which_font, $which_text);
00683     } else {
00684       if ($which_valign == 'top') {
00685         $which_ypos = $which_ypos - ImageFontHeight($which_font);
00686       }
00687       $which_text = preg_replace("/\r/","",$which_text);
00688       $str = preg_split("/\n/",$which_text); //multiple lines submitted by Remi Ricard
00689       $height = ImageFontHeight($which_font);
00690       $width = ImageFontWidth($which_font);
00691       if ($which_angle == 90) {  //Vertical Code Submitted by Marlin Viss
00692         for($i=0;$i<count($str);$i++) {
00693           ImageStringUp($this->img, $which_font, ($i*$height + $which_xpos), $which_ypos, $str[$i], $which_color);
00694         }
00695       } else {
00696         for($i=0;$i<count($str);$i++) {
00697           if ($which_halign == 'center') {
00698                       $xpos = $which_xpos - strlen($str[$i]) * $width/2;
00699              ImageString($this->img, $which_font, $xpos, ($i*$height + $which_ypos), $str[$i], $which_color);
00700           } else {
00701             ImageString($this->img, $which_font, $which_xpos, ($i*$height + $which_ypos), $str[$i], $which_color);
00702           }
00703         }
00704       }
00705 
00706     }
00707     return true;
00708 
00709   }
00710   function DrawTitle() {
00711     if ($this->use_ttf == 1 ) {
00712       $xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
00713       $ypos = $this->y_top_margin/2;
00714       $this->DrawText($this->title_ttffont, $this->title_angle,
00715         $xpos, $ypos, $this->ndx_title_color, $this->title_ttffont_size, $this->title_txt,'center');
00716     } else {
00717       $xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
00718       $ypos = ImageFontHeight($this->title_font);
00719       $this->DrawText($this->title_font, $this->title_angle,
00720         $xpos, $ypos, $this->ndx_title_color, '', $this->title_txt,'center');
00721     }
00722     return true;
00723 
00724   }
00725 
00726   function DrawPlotAreaBackground() {
00727     ImageFilledRectangle($this->img,$this->plot_area[0],
00728       $this->plot_area[1],$this->plot_area[2],$this->plot_area[3],
00729       $this->ndx_plot_bg_color);
00730   }
00731 
00732   function SetBackgroundColor($which_color) {
00733     $this->bg_color= $which_color;
00734     $this->ndx_bg_color= $this->SetIndexColor($which_color);
00735     return true;
00736   }
00737   function SetPlotBgColor($which_color) {
00738     $this->plot_bg_color= $which_color;
00739     $this->ndx_plot_bg_color= $this->SetIndexColor($which_color);
00740     return true;
00741   }
00742 
00743   function SetShading($which_s) {
00744     $this->shading = $which_s;
00745     return true;
00746   }
00747 
00748   function SetTitleColor($which_color) {
00749     $this->title_color= $which_color;
00750     $this->ndx_title_color= $this->SetIndexColor($which_color);
00751     return true;
00752   }
00753 
00754   function SetTickColor ($which_color) {
00755     $this->tick_color= $which_color;
00756     $this->ndx_tick_color= $this->SetIndexColor($which_color);
00757     return true;
00758   }
00759 
00760   function SetLabelColor ($which_color) {
00761     $this->label_color= $which_color;
00762     $this->ndx_label_color= $this->SetIndexColor($which_color);
00763     return true;
00764   }
00765 
00766   function SetTextColor ($which_color) {
00767     $this->text_color= $which_color;
00768     $this->ndx_text_color= $this->SetIndexColor($which_color);
00769     return true;
00770   }
00771 
00772   function SetLightGridColor ($which_color) {
00773     $this->light_grid_color= $which_color;
00774     $this->ndx_light_grid_color= $this->SetIndexColor($which_color);
00775     return true;
00776   }
00777 
00778   function SetGridColor ($which_color) {
00779     $this->grid_color = $which_color;
00780     $this->ndx_grid_color= $this->SetIndexColor($which_color);
00781     return true;
00782   }
00783 
00784   function SetCharacterHeight() {
00785     //to be set
00786     return true;
00787   }
00788 
00789   function SetPlotType($which_pt) {
00790     $accepted = "bars,lines,linepoints,area,points,pie,thinbarline";
00791     $asked = trim($which_pt);
00792     if (preg_match('/' . $asked . '/i', $accepted)) {
00793       $this->plot_type = $which_pt;
00794       return true;
00795     } else {
00796       $this->DrawError('$which_pt not an acceptable plot type');
00797       return false;
00798     }
00799   }
00800 
00801   function FindDataLimits() {
00802     //Text-Data is different than data-data graphs. For them what
00803     // we have, instead of X values, is # of records equally spaced on data.
00804     //text-data is passed in as $data[] = (title,y1,y2,y3,y4,...)
00805     //data-data is passed in as $data[] = (title,x,y1,y2,y3,y4,...)
00806 
00807     $this->number_x_points = count($this->data_values);
00808 
00809     switch ($this->data_type) {
00810       case "text-data":
00811         $minx = 0; //valid for BAR TYPE GRAPHS ONLY
00812         $maxx = $this->number_x_points - 1 ;  //valid for BAR TYPE GRAPHS ONLY
00813         $miny = (double) $this->data_values[0][1];
00814         $maxy = $miny;
00815         if ($this->draw_x_data_labels == "") {
00816           $this->draw_x_data_labels = 1;  //labels_note1: prevent both data labels and x-axis labels being both drawn and overlapping
00817         }
00818       break;
00819       default:  //Everything else: data-data, etc.
00820         $maxx = $this->data_values[0][1];
00821         $minx = $maxx;
00822         $miny = $this->data_values[0][2];
00823         $maxy = $miny;
00824         $maxy = $miny;
00825       break;
00826     }
00827 
00828     $max_records_per_group = 0;
00829     $total_records = 0;
00830     $mine = 0; //Maximum value for the -error bar (assume error bars always > 0)
00831     $maxe = 0; //Maximum value for the +error bar (assume error bars always > 0)
00832 
00833     reset($this->data_values);
00834     while (list($dat_key, $dat) = each($this->data_values)) {  //for each X barchart setting
00835     //foreach($this->data_values as $dat)  //can use foreach only in php4
00836 
00837       $tmp = 0;
00838       $total_records += count($dat) - 1; // -1 for label
00839 
00840       switch ($this->data_type) {
00841         case "text-data":
00842           //Find the relative Max and Min
00843 
00844           while (list($key, $val) = each($dat)) {
00845             if ($key != 0) {  //$dat[0] = label
00846               SetType($val,"double");
00847               if ($val > $maxy) {
00848                 $maxy = $val ;
00849               }
00850               if ($val < $miny) {
00851                 $miny = (double) $val ;
00852               }
00853             }
00854             $tmp++;
00855           }
00856         break;
00857         case "data-data":  //X-Y data is passed in as $data[] = (title,x,y,y2,y3,...) which you can use for multi-dimentional plots.
00858 
00859           while (list($key, $val) = each($dat)) {
00860             if ($key == 1) {  //$dat[0] = label
00861               SetType($val,"double");
00862               if ($val > $maxx) {
00863                 $maxx = $val;
00864               } elseif ($val < $minx) {
00865                 $minx = $val;
00866               }
00867             } elseif ($key > 1) {
00868               SetType($val,"double");
00869               if ($val > $maxy) {
00870                 $maxy = $val ;
00871               } elseif ($val < $miny) {
00872                 $miny = $val ;
00873               }
00874             }
00875             $tmp++;
00876           }
00877           $tmp = $tmp - 1; //# records per group
00878         break;
00879         case "data-data-error":  //Assume 2-D for now, can go higher
00880         //Regular X-Y data is passed in as $data[] = (title,x,y,error+,error-,y2,error2+,error2-)
00881 
00882           while (list($key, $val) = each($dat)) {
00883             if ($key == 1) {  //$dat[0] = label
00884               SetType($val,'double');
00885               if ($val > $maxx) {
00886                 $maxx = $val;
00887               } elseif ($val < $minx) {
00888                 $minx = $val;
00889               }
00890             } elseif ($key%3 == 2) {
00891               SetType($val,'double');
00892               if ($val > $maxy) {
00893                 $maxy = $val ;
00894               } elseif ($val < $miny) {
00895                 $miny = $val ;
00896               }
00897             } elseif ($key%3 == 0) {
00898               SetType($val,'double');
00899               if ($val > $maxe) {
00900                 $maxe = $val ;
00901               }
00902             } elseif ($key%3 == 1) {
00903               SetType($val,'double');
00904               if ($val > $mine) {
00905                 $mine = $val ;
00906               }
00907             }
00908             $tmp++;
00909           }
00910           $maxy = $maxy + $maxe;
00911           $miny = $miny - $mine; //assume error bars are always > 0
00912 
00913         break;
00914         default:
00915           $this->PrintError('ERROR: unknown chart type');
00916         break;
00917       }
00918       if ($tmp > $max_records_per_group) {
00919         $max_records_per_group = $tmp;
00920       }
00921     }
00922 
00923 
00924     $this->min_x = $minx;
00925     $this->max_x = $maxx;
00926     $this->min_y = $miny;
00927     $this->max_y = $maxy;
00928 
00929 
00930     if ($max_records_per_group > 1) {
00931       $this->records_per_group = $max_records_per_group - 1;
00932     } else {
00933       $this->records_per_group = 1;
00934     }
00935 
00936 
00937     //$this->data_count = $total_records ;
00938   } // function FindDataLimits
00939 
00940   function SetMargins() {
00942     // When the image is first created - set the margins
00943     // to be the standard viewport.
00944     // The standard viewport is the full area of the view surface (or panel),
00945     // less a margin of 4 character heights all round for labelling.
00946     // It thus depends on the current character size, set by SetCharacterHeight().
00948 
00949     $str = preg_split("/\n/",$this->title_txt);
00950     $nbLines = count($str);
00951 
00952     if ($this->use_ttf == 1) {
00953       $title_size = $this->TTFBBoxSize($this->title_ttffont_size, $this->title_angle, $this->title_ttffont, 'X'); //An array
00954       if ($nbLines == 1) {
00955         $this->y_top_margin = $title_size[1] * 4;
00956       } else {
00957         $this->y_top_margin = $title_size[1] * ($nbLines+3);
00958       }
00959 
00960       //ajo working here
00961       //$x_label_size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt);
00962 
00963       $this->y_bot_margin = $this->x_label_height ;
00964       $this->x_left_margin = $this->y_label_width * 2 + $this->tick_length;
00965       $this->x_right_margin = 33.0; // distance between right and end of x axis in pixels
00966     } else {
00967       $title_size = array(ImageFontWidth($this->title_font) * strlen($this->title_txt),ImageFontHeight($this->title_font));
00968       //$this->y_top_margin = ($title_size[1] * 4);
00969       if ($nbLines == 1) {
00970         $this->y_top_margin = $title_size[1] * 4;
00971       } else {
00972         $this->y_top_margin = $title_size[1] * ($nbLines+3);
00973       }
00974       if ($this->x_datalabel_angle == 90) {
00975         $this->y_bot_margin = 76.0; // Must be integer
00976       } else {
00977         $this->y_bot_margin = 66.0; // Must be integer
00978       }
00979       $this->x_left_margin = 77.0; // distance between left and start of x axis in pixels
00980       $this->x_right_margin = 33.0; // distance between right and end of x axis in pixels
00981     }
00982 
00983 //exit;
00984     $this->x_tot_margin = $this->x_left_margin + $this->x_right_margin;
00985     $this->y_tot_margin = $this->y_top_margin + $this->y_bot_margin;
00986 
00987     if ($this->plot_max_x && $this->plot_max_y && $this->plot_area_width ) { //If data has already been analysed then set translation
00988       $this->SetTranslation();
00989     }
00990   }
00991 
00992   function SetMarginsPixels($which_lm,$which_rm,$which_tm,$which_bm) {
00993     //Set the plot area using margins in pixels (left, right, top, bottom)
00994     $this->SetNewPlotAreaPixels($which_lm,$which_tm,($this->image_width - $which_rm),($this->image_height - $which_bm));
00995     return true;
00996   }
00997 
00998   function SetNewPlotAreaPixels($x1,$y1,$x2,$y2) {
00999     //Like in GD 0,0 is upper left set via pixel Coordinates
01000     $this->plot_area = array($x1,$y1,$x2,$y2);
01001     $this->plot_area_width = $this->plot_area[2] - $this->plot_area[0];
01002     $this->plot_area_height = $this->plot_area[3] - $this->plot_area[1];
01003     $this->y_top_margin = $this->plot_area[1];
01004     if ($this->plot_max_x) {
01005       $this->SetTranslation();
01006     }
01007     return true;
01008   }
01009 
01010   function SetPlotAreaPixels($x1,$y1,$x2,$y2) {
01011     //Like in GD 0,0 is upper left
01012     if (!$this->x_tot_margin) {
01013       $this->SetMargins();
01014     }
01015     if ($x2 && $y2) {
01016       $this->plot_area = array($x1,$y1,$x2,$y2);
01017     } else {
01018       $this->plot_area = array($this->x_left_margin, $this->y_top_margin,
01019                 $this->image_width - $this->x_right_margin,
01020                 $this->image_height - $this->y_bot_margin
01021               );
01022     }
01023     $this->plot_area_width = $this->plot_area[2] - $this->plot_area[0];
01024     $this->plot_area_height = $this->plot_area[3] - $this->plot_area[1];
01025 
01026     return true;
01027 
01028   }
01029 
01030   function SetPlotAreaWorld($xmin,$ymin,$xmax,$ymax) {
01031     if (($xmin == "")  && ($xmax == "")) {
01032       //For automatic setting of data we need $this->max_x
01033         if (!$this->max_y) {
01034           $this->FindDataLimits() ;
01035         }
01036         if ($this->data_type == 'text-data') { //labels for text-data is done at data drawing time for speed.
01037           $xmax = $this->max_x + 1 ;  //valid for BAR CHART TYPE GRAPHS ONLY
01038           $xmin = 0 ;                           //valid for BAR CHART TYPE GRAPHS ONLY
01039         } else {
01040           $xmax = $this->max_x * 1.02;
01041           $xmin = $this->min_x;
01042         }
01043 
01044         $ymax = ceil($this->max_y * 1.2);
01045         if ($this->min_y < 0) {
01046           $ymin = floor($this->min_y * 1.2);
01047         } else {
01048           $ymin = 0;
01049         }
01050     }
01051 
01052     $this->plot_min_x = $xmin;
01053     $this->plot_max_x = $xmax;
01054 
01055     if ($ymin == $ymax) {
01056       $ymax += 1;
01057     }
01058     if ($this->yscale_type == "log") {
01059       //extra error checking
01060       if ($ymin <= 0) {
01061         $ymin = 1;
01062       }
01063       if ($ymax <= 0) {
01064         $this->PrintError('Log plots need data greater than 0');
01065       }
01066     }
01067     $this->plot_min_y = $ymin;
01068     $this->plot_max_y = $ymax;
01069 
01070     if ($ymax <= $ymin) {
01071       $this->DrawError('Error in Data - max not gt min');
01072     }
01073 
01074 //Set the boundaries of the box for plotting in world coord
01075 //              if (!$this->x_tot_margin) { //We need to know the margins before we can calculate scale
01076 //                      $this->SetMargins();
01077 //              }
01078     //For this we have to reset the scale
01079     if ($this->plot_area_width) {
01080       $this->SetTranslation();
01081     }
01082 
01083     return true;
01084 
01085   } //function SetPlotAreaWorld
01086 
01087 
01088   function PrintError($error_message) {
01089   // prints the error message to stdout and die
01090     echo "<p><b>Fatal error</b>: $error_message<p>";
01091     die;
01092   }
01093 
01094   function DrawError($error_message) {
01095   // prints the error message inline into
01096   // the generated image
01097 
01098     if (($this->img) == "") { $this->InitImage(); } ;
01099 
01100     $ypos = $this->image_height/2;
01101 
01102     if ($this->use_ttf == 1) {
01103       ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255));
01104       ImageTTFText($this->img, $this->small_ttffont_size, 0, $xpos, $ypos, ImageColorAllocate($this->img,0,0,0), $this->axis_ttffont, $error_message);
01105     } else {
01106       ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255));
01107       ImageString($this->img, $this->small_font,1,$ypos,$error_message, ImageColorAllocate($this->img,0,0,0));
01108     }
01109 
01110     $this->PrintImage();
01111     return true;
01112   }
01113 
01114   function TTFBBoxSize($size, $angle, $font, $string) {
01115 
01116     //Assume angle < 90
01117     $arr = ImageTTFBBox($size, 0, $font, $string);
01118     $flat_width  = $arr[0] - $arr[2];
01119     $flat_height = abs($arr[3] - $arr[5]);
01120 
01121       // for 90deg:
01122       //        $height = $arr[5] - $arr[7];
01123       //        $width = $arr[2] - $arr[4];
01124 
01125     $angle = deg2rad($angle);
01126     $width  = ceil(abs($flat_width*cos($angle) + $flat_height*sin($angle))); //Must be integer
01127     $height = ceil(abs($flat_width*sin($angle) + $flat_height*cos($angle))); //Must be integer
01128 
01129     return array($width, $height);
01130   }
01131 
01132   function SetXLabelHeight() {
01133 
01134     if ($this->use_ttf == 1) {
01135       //Space for the X Label
01136       $size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt);
01137       $tmp = $size[1];
01138 
01139       //$string = Str_Repeat('w', $this->x_datalabel_maxlength);
01140       $i = 0;
01141       $string = '';
01142       while ($i < $this->x_datalabel_maxlength) {
01143         $string .= 'w';
01144         $i++;
01145       }
01146 
01147       //Space for the axis data labels
01148       $size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $string);
01149 
01150       $this->x_label_height = 2*$tmp + $size[1] + 4;
01151 
01152     } else {
01153       //For Non-TTF fonts we can have only angles 0 or 90
01154       if ($this->x_datalabel_angle == 90) {
01155         $this->x_label_height = $this->x_datalabel_maxlength * ImageFontWidth($this->small_font) / 1.5;
01156       } else {
01157         $this->x_label_height = 5 * ImageFontHeight($this->small_font);
01158       }
01159     }
01160 
01161     $this->SetMargins();
01162 
01163     return true;
01164   } //function SetXLabelHeight
01165 
01166   function SetYLabelWidth() {
01167     //$ylab = sprintf("%6.1f %s",$i,$si_units[0]);  //use for PHP2 compatibility
01168     //the "." is for space. It isn't actually printed
01169     $ylab = number_format($this->max_y, $this->y_precision, ".", ",") . $this->si_units . ".";
01170 
01171     if ($this->use_ttf == 1) {
01172       $size = $this->TTFBBoxSize($this->axis_ttffont_size, 0, $this->axis_ttffont, $ylab);
01173     } else {
01174       $size[0] = StrLen($ylab) * $this->small_font_width * .6;
01175     }
01176 
01177     $this->y_label_width = $size[0] * 2;
01178 //echo "SYLW: $this->y_label_width<br>";
01179 //exit;
01180 
01181     $this->SetMargins();
01182     return true;
01183   }
01184 
01185   function SetEqualXCoord() {
01186     //for plots that have equally spaced x variables and multiple bars per x-point.
01187 
01188     $space = ($this->plot_area[2] - $this->plot_area[0]) / ($this->number_x_points * 2) * $this->group_frac_width;
01189     $group_width = $space * 2;
01190     $bar_width = $group_width / $this->records_per_group;
01191   //I think that eventually this space variable will be replaced by just graphing x.
01192     $this->data_group_space = $space;
01193     $this->record_bar_width = $bar_width;
01194     return true;
01195   }
01196 
01197   function SetLabelScalePosition($which_blp) {
01198     //0 to 1
01199     $this->label_scale_position = $which_blp;
01200     return true;
01201   }
01202 
01203   function SetErrorBarSize($which_ebs) {
01204     //in pixels
01205     $this->error_bar_size = $which_ebs;
01206     return true;
01207   }
01208 
01209   function SetErrorBarShape($which_ebs) {
01210     //in pixels
01211     $this->error_bar_shape = $which_ebs;
01212     return true;
01213   }
01214 
01215   function SetPointShape($which_pt) {
01216     //in pixels
01217     $this->point_shape = $which_pt;
01218     return true;
01219   }
01220 
01221   function SetPointSize($which_ps) {
01222     //in pixels
01223     SetType($which_ps,'integer');
01224     $this->point_size = $which_ps;
01225 
01226     if ($this->point_shape == "diamond" or $this->point_shape == "triangle") {
01227       if ($this->point_size % 2 != 0) {
01228         $this->point_size++;
01229       }
01230     }
01231     return true;
01232   }
01233 
01234   function SetDataType($which_dt) {
01235     //The next three lines are for past compatibility.
01236     if ($which_dt == "text-linear") { $which_dt = "text-data"; }
01237     if ($which_dt == "linear-linear") { $which_dt = "data-data"; }
01238     if ($which_dt == "linear-linear-error") { $which_dt = "data-data-error"; }
01239 
01240     $this->data_type = $which_dt; //text-data, data-data, data-data-error
01241     return true;
01242   }
01243 
01244   function SetDataValues($which_dv) {
01245     $this->data_values = $which_dv;
01246 //echo $this->data_values
01247     return true;
01248   }
01249 
01251   function SetRGBArray ($which_color_array) {
01252     if ( is_array($which_color_array) ) {
01253       //User Defined Array
01254       $this->rgb_array = $which_color_array;
01255       return true;
01256     } elseif ($which_color_array == 2) { //Use the small predefined color array
01257     $this->rgb_array = array(
01258       "white"                   => array(255, 255, 255),
01259       "snow"                    => array(255, 250, 250),
01260       "PeachPuff"               => array(255, 218, 185),
01261       "ivory"                   => array(255, 255, 240),
01262       "lavender"                => array(230, 230, 250),
01263       "black"                   => array(  0,   0,   0),
01264       "DimGrey"                 => array(105, 105, 105),
01265       "gray"                    => array(190, 190, 190),
01266       "grey"                    => array(190, 190, 190),
01267       "navy"                    => array(  0,   0, 128),
01268       "SlateBlue"                       => array(106,  90, 205),
01269       "blue"                    => array(  0,   0, 255),
01270       "SkyBlue"                 => array(135, 206, 235),
01271       "cyan"                    => array(  0, 255, 255),
01272       "DarkGreen"                       => array(  0, 100,   0),
01273       "green"                   => array(  0, 255,   0),
01274       "YellowGreen"                     => array(154, 205,  50),
01275       "yellow"                  => array(255, 255,   0),
01276       "orange"                  => array(255, 165,   0),
01277       "gold"                    => array(255, 215,   0),
01278       "peru"                    => array(205, 133,  63),
01279       "beige"                   => array(245, 245, 220),
01280       "wheat"                   => array(245, 222, 179),
01281       "tan"                     => array(210, 180, 140),
01282       "brown"                   => array(165,  42,  42),
01283       "salmon"                  => array(250, 128, 114),
01284       "red"                     => array(255,   0,   0),
01285       "pink"                    => array(255, 192, 203),
01286       "maroon"                  => array(176,  48,  96),
01287       "magenta"                 => array(255,   0, 255),
01288       "violet"                  => array(238, 130, 238),
01289       "plum"                    => array(221, 160, 221),
01290       "orchid"                  => array(218, 112, 214),
01291       "purple"                  => array(160,  32, 240),
01292       "azure1"                  => array(240, 255, 255),
01293       "aquamarine1"             => array(127, 255, 212)
01294       );
01295       return true;
01296     } elseif ($which_color_array == 1)  {
01297       include("./rgb.inc.php"); //Get large $ColorArray
01298       $this->rgb_array = $RGBArray;
01299     } else {
01300       $this->rgb_array = array("white" =>array(255,255,255), "black" => array(0,0,0));
01301       exit;
01302     }
01303 
01304     return true;
01305   }
01306 
01307   function SetColor($which_color) {
01308     //obsoleted by SetRGBColor
01309     SetRgbColor($which_color);
01310     return true;
01311   }
01312 
01313   function SetIndexColor($which_color) { //Color is passed in as anything
01314       list ($r, $g, $b) = $this->SetRgbColor($which_color);  //Translate to RGB
01315     $index = ImageColorExact($this->img, $r, $g, $b);
01316     if ($index == -1) {
01317           //return ImageColorAllocate($this->img, $r, $g, $b);
01318           //return ImageColorClosest($this->img, $r, $g, $b);
01319           return ImageColorResolve($this->img, $r, $g, $b); //requires PHP 3.0.2 and later
01320      } else {
01321           return $index;
01322       }
01323   }
01324 
01325   function SetTransparentColor($which_color) {
01326     ImageColorTransparent($this->img,$this->SetIndexColor($which_color));
01327     return true;
01328   }
01329 
01330   function SetRgbColor($color_asked) {
01331     //Returns an array in R,G,B format 0-255
01332     if ($color_asked == "") { $color_asked = array(0,0,0); }
01333 
01334     if ( count($color_asked) == 3 ) { //already array of 3 rgb
01335          $ret_val =  $color_asked;
01336     } else { // is asking for a color by string
01337       if(substr($color_asked,0,1) == "#") {  //asking in #FFFFFF format.
01338         $ret_val =  array(hexdec(substr($color_asked,1,2)), hexdec(substr($color_asked,3,2)), hexdec(substr($color,5,2)));
01339       } else {
01340         $ret_val =  $this->rgb_array[$color_asked];
01341       }
01342     }
01343     return $ret_val;
01344   }
01345 
01346   function SetDataColors($which_data,$which_border) {
01347     //Set the data to be displayed in a particular color
01348     if (!$which_data) {
01349       $which_data = array(array(0,255,0),array(0,0,248),'yellow',array(255,0,0),'orange');
01350       $which_border = array('black');
01351     }
01352 
01353     $this->data_color = $which_data;  //an array
01354     $this->data_border_color = $which_border;  //an array
01355 
01356     unset($this->ndx_data_color);
01357     reset($this->data_color);  //data_color can be an array of colors, one for each thing plotted
01358     //while (list(, $col) = each($this->data_color))
01359     $i = 0;
01360     while (list(, $col) = each($which_data)) {
01361       $this->ndx_data_color[$i] = $this->SetIndexColor($col);
01362       $i++;
01363     }
01364 
01365     // border_color
01366     //If we are also going to put a border on the data (bars, dots, area, ...)
01367     //  then lets also set a border color as well.
01368     //foreach($this->data_border_color as $col)
01369     unset($this->ndx_data_border_color);
01370     reset($this->data_border_color);
01371     $i = 0;
01372     while (list(, $col) = each($this->data_border_color)) {
01373       $this->ndx_data_border_color[$i] = $this->SetIndexColor($col);
01374       $i++;
01375     }
01376 
01377     //Set color of the error bars to be that of data if not already set.
01378     if (!$this->error_bar_color) {
01379         reset($which_data);
01380         $this->SetErrorBarColors($which_data);
01381     }
01382 
01383     return true;
01384 
01385   } //function SetDataColors
01386 
01387   function SetErrorBarColors($which_data) {
01388 
01389    //Set the data to be displayed in a particular color
01390 
01391    if ($which_data) {
01392     $this->error_bar_color = $which_data;  //an array
01393     unset($this->ndx_error_bar_color);
01394     reset($this->error_bar_color);  //data_color can be an array of colors, one for each thing plotted
01395     $i = 0;
01396     while (list(, $col) = each($this->error_bar_color)) {
01397       $this->ndx_error_bar_color[$i] = $this->SetIndexColor($col);
01398       $i++;
01399     }
01400     return true;
01401     }
01402     return false;
01403   } //function SetErrorBarColors
01404 
01405 
01406   function DrawPlotBorder() {
01407     switch ($this->plot_border_type) {
01408       case "left" :
01409         ImageLine($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y),
01410           $this->plot_area[0],$this->ytr($this->plot_max_y),$this->ndx_grid_color);
01411       break;
01412       case "none":
01413         //Draw No Border
01414       break;
01415       default:
01416         ImageRectangle($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y),
01417           $this->plot_area[2],$this->ytr($this->plot_max_y),$this->ndx_grid_color);
01418       break;
01419     }
01420     $this->DrawYAxis();
01421     $this->DrawXAxis();
01422     return true;
01423   }
01424 
01425 
01426   function SetHorizTickIncrement($which_ti) {
01427     //Use either this or NumHorizTicks to set where to place x tick marks
01428     if ($which_ti) {
01429       $this->horiz_tick_increment = $which_ti;  //world coordinates
01430     } else {
01431       if (!$this->max_x) {
01432         $this->FindDataLimits();  //Get maxima and minima for scaling
01433       }
01434       //$this->horiz_tick_increment = ( ceil($this->max_x * 1.2) - floor($this->min_x * 1.2) )/10;
01435       $this->horiz_tick_increment =  ($this->plot_max_x  - $this->plot_min_x  )/10;
01436     }
01437     $this->num_horiz_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both
01438     return true;
01439   }
01440 
01441   function SetDrawVertTicks($which_dvt) {
01442     $this->draw_vert_ticks = $which_dvt;
01443     return true;
01444   }
01445 
01446   function SetVertTickIncrement($which_ti) {
01447     //Use either this or NumVertTicks to set where to place y tick marks
01448     if ($which_ti) {
01449       $this->vert_tick_increment = $which_ti;  //world coordinates
01450     } else {
01451       if (!$this->max_y) {
01452         $this->FindDataLimits();  //Get maxima and minima for scaling
01453       }
01454       //$this->vert_tick_increment = ( ceil($this->max_y * 1.2) - floor($this->min_y * 1.2) )/10;
01455       $this->vert_tick_increment =  ($this->plot_max_y  - $this->plot_min_y  )/10;
01456     }
01457     $this->num_vert_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both
01458     return true;
01459   }
01460 
01461   function SetNumHorizTicks($which_nt) {
01462     $this->num_horiz_ticks = $which_nt;
01463     $this->horiz_tick_increment = '';  //either use num_horiz_ticks or horiz_tick_increment, not both
01464     return true;
01465   }
01466 
01467   function SetNumVertTicks($which_nt) {
01468     $this->num_vert_ticks = $which_nt;
01469     $this->vert_tick_increment = '';  //either use num_vert_ticks or vert_tick_increment, not both
01470     return true;
01471   }
01472   function SetVertTickPosition($which_tp) {
01473     $this->vert_tick_position = $which_tp; //plotleft, plotright, both, yaxis
01474     return true;
01475   }
01476   function SetSkipBottomTick($which_sbt) {
01477     $this->skip_bottom_tick = $which_sbt;
01478     return true;
01479   }
01480 
01481   function SetTickLength($which_tl) {
01482     $this->tick_length = $which_tl;
01483     return true;
01484   }
01485 
01486   function DrawYAxis() {
01487     //Draw Line at left side or at this->y_axis_position
01488     if ($this->y_axis_position != "") {
01489       $yaxis_x = $this->xtr($this->y_axis_position);
01490     } else {
01491       $yaxis_x = $this->plot_area[0];
01492     }
01493 
01494     ImageLine($this->img, $yaxis_x, $this->plot_area[1],
01495       $yaxis_x, $this->plot_area[3], $this->ndx_grid_color);
01496       //$yaxis_x, $this->plot_area[3], 9);
01497 
01498     if ($this->draw_vert_ticks == 1) {
01499       $this->DrawVerticalTicks();
01500     }
01501 
01502   } //function DrawYAxis
01503 
01504   function DrawXAxis() {
01505     //Draw Tick and Label for Y axis
01506     $ylab =$this->FormatYTickLabel($this->x_axis_position);
01507     if ($this->skip_bottom_tick != 1) {
01508       $this->DrawVerticalTick($ylab,$this->x_axis_position);
01509     }
01510 
01511     //Draw X Axis at Y=$x_axis_postion
01512     ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->x_axis_position),
01513         $this->xtr($this->plot_max_x)-1,$this->ytr($this->x_axis_position),$this->ndx_tick_color);
01514 
01515     //X Ticks and Labels
01516     if ($this->data_type != 'text-data') { //labels for text-data done at data drawing time for speed.
01517       $this->DrawHorizontalTicks();
01518     }
01519     return true;
01520   }
01521 
01522   function DrawHorizontalTicks() {
01523     //Ticks and lables are drawn on the left border of PlotArea.
01524     //Left Bottom
01525     ImageLine($this->img,$this->plot_area[0],
01526         $this->plot_area[3]+$this->tick_length,
01527         $this->plot_area[0],$this->plot_area[3],$this->ndx_tick_color);
01528 
01529     switch ($this->x_grid_label_type) {
01530       case "title":
01531         $xlab = $this->data_values[0][0];
01532       break;
01533       case "data":
01534         $xlab = number_format($this->plot_min_x,$this->x_precision,".",",") . "$this->si_units";
01535       break;
01536       case "none":
01537         $xlab = '';
01538       break;
01539       case "time":  //Time formatting suggested by Marlin Viss
01540         $xlab = strftime($this->x_time_format,$this->plot_min_x);
01541       break;
01542       default:
01543         //Unchanged from whatever format is passed in
01544         $xlab = $this->plot_min_x;
01545       break;
01546     }
01547 
01548     if ($this->x_datalabel_angle == 90) {
01549       $xpos =  $this->plot_area[0] - $this->small_font_height/2;
01550       $ypos = ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height);
01551       ImageStringUp($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color);
01552     } else {
01553       $xpos = $this->plot_area[0] - $this->small_font_width*strlen($xlab)/2 ;
01554       $ypos = $this->plot_area[3] + $this->small_font_height;
01555       ImageString($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color);
01556     }
01557 
01558     //Will be changed to allow for TTF fonts in data as well.
01559     //$this->DrawText($this->small_font, $this->x_datalabel_angle, $xpos, $ypos, $this->ndx_title_color, '', $xlab);
01560 
01561     //Top
01562 
01563     if ($this->horiz_tick_increment) {
01564       $delta_x = $this->horiz_tick_increment;
01565     } elseif ($this->num_horiz_ticks) {
01566       $delta_x = ($this->plot_max_x - $this->plot_min_x) / $this->num_horiz_ticks;
01567     } else {
01568       $delta_x =($this->plot_max_x - $this->plot_min_x) / 10 ;
01569     }
01570 
01571     $i = 0;
01572     $x_tmp = $this->plot_min_x;
01573     SetType($x_tmp,'double');
01574 
01575     while ($x_tmp <= $this->plot_max_x){
01576       //$xlab = sprintf("%6.1f %s",$min_x,$si_units[0]);  //PHP2 past compatibility
01577       switch ($this->x_grid_label_type) {
01578         case "title":
01579           $xlab = $this->data_values[$x_tmp][0];
01580         break;
01581         case "data":
01582           $xlab = number_format($x_tmp,$this->x_precision,".",",") . "$this->si_units";
01583         break;
01584         case "none":
01585           $xlab = '';
01586         break;
01587         case "time":  //Time formatting suggested by Marlin Viss
01588           $xlab = strftime($this->x_time_format,$x_tmp);
01589         break;
01590         default:
01591           //Unchanged from whatever format is passed in
01592           $xlab = $x_tmp;
01593         break;
01594       }
01595 
01596       $x_pixels = $this->xtr($x_tmp);
01597 
01598       //Bottom Tick
01599       ImageLine($this->img,$x_pixels,$this->plot_area[3] + $this->tick_length,
01600         $x_pixels,$this->plot_area[3], $this->ndx_tick_color);
01601       //Top Tick
01602       //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
01603       //        $y_pixels,$this->xtr($this->plot_max_x)-1,$y_pixels,$this->ndx_tick_color);
01604 
01605       if ($this->draw_x_grid == 1) {
01606         ImageLine($this->img,$x_pixels,$this->plot_area[1],
01607           $x_pixels,$this->plot_area[3], $this->ndx_light_grid_color);
01608       }
01609 
01610       if ($this->x_datalabel_angle == 90) {  //Vertical Code Submitted by Marlin Viss
01611           ImageStringUp($this->img, $this->small_font,
01612         ( $x_pixels - $this->small_font_height/2),
01613         ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height),$xlab, $this->ndx_text_color);
01614       } else {
01615         ImageString($this->img, $this->small_font,
01616           ( $x_pixels - $this->small_font_width*strlen($xlab)/2) ,
01617           ( $this->small_font_height + $this->plot_area[3]),$xlab, $this->ndx_text_color);
01618       }
01619 
01620       $i++;
01621       $x_tmp += $delta_x;
01622     }
01623 
01624   } // function DrawHorizontalTicks
01625 
01626   function FormatYTickLabel($which_ylab) {
01627     switch ($this->y_grid_label_type) {
01628       case "data":
01629         $ylab = number_format($which_ylab,$this->y_precision,".",",") . "$this->si_units";
01630       break;
01631       case "none":
01632         $ylab = '';
01633       break;
01634       case "time":
01635         $ylab = strftime($this->y_time_format,$which_ylab);
01636       break;
01637       case "right":
01638         //Make it right aligned
01639         //$ylab = str_pad($which_ylab,$this->y_label_width," ",STR_PAD_LEFT); //PHP4 only
01640         $sstr = "%".strlen($this->plot_max_y)."s";
01641         $ylab = sprintf($sstr,$which_ylab);
01642       break;
01643       default:
01644         //Unchanged from whatever format is passed in
01645         $ylab = $which_ylab;
01646       break;
01647     }
01648 
01649     return($ylab);
01650 
01651   } //function FormatYTickLabel
01652 
01653   function DrawVerticalTick($which_ylab,$which_ypos) {  //ylab in world coord.
01654     //Draw Just one Tick, called from DrawVerticalTicks
01655     //Ticks and datalables can be left of plot only, right of plot only,
01656     //  both on the left and right of plot, or crossing a user defined Y-axis
01657     //
01658     //Its faster to draw both left and right ticks at same time
01659     //  than first left and then right.
01660 
01661     if ($this->y_axis_position != "") {
01662       //Ticks and lables are drawn on the left border of yaxis
01663       $yaxis_x = $this->xtr($this->y_axis_position);
01664     } else {
01665       //Ticks and lables are drawn on the left border of PlotArea.
01666       $yaxis_x = $this->plot_area[0];
01667     }
01668 
01669     $y_pixels = $this->ytr($which_ypos);
01670 
01671     //Lines Across the Plot Area
01672     if ($this->draw_y_grid == 1) {
01673       ImageLine($this->img,$this->plot_area[0]+1,$y_pixels,
01674         $this->plot_area[2]-1,$y_pixels,$this->ndx_light_grid_color);
01675     }
01676 
01677     //Ticks to the Left of the Plot Area
01678     if (($this->vert_tick_position == "plotleft") || ($this->vert_tick_position == "both") ) {
01679       ImageLine($this->img,(-$this->tick_length+$yaxis_x),
01680       $y_pixels,$yaxis_x,
01681       $y_pixels, $this->ndx_tick_color);
01682     }
01683 
01684     //Ticks to the Right of the Plot Area
01685     if (($this->vert_tick_position == "plotright") || ($this->vert_tick_position == "both") ) {
01686       ImageLine($this->img,($this->plot_area[2]+$this->tick_length),
01687       $y_pixels,$this->plot_area[2],
01688       $y_pixels,$this->ndx_tick_color);
01689     }
01690 
01691     //Ticks on the Y Axis
01692     if (($this->vert_tick_position == "yaxis") ) {
01693       ImageLine($this->img,($yaxis_x - $this->tick_length),
01694       $y_pixels,$yaxis_x,$y_pixels,$this->ndx_tick_color);
01695     }
01696 
01697     //DataLabel
01698 //ajo working
01699     //$this->DrawText($this->y_label_ttffont, 0,($yaxis_x - $this->y_label_width - $this->tick_length/2),
01700     //          $y_pixels, $this->ndx_text_color, $this->axis_ttffont_size, $which_ylab);
01701     ImageString($this->img, $this->small_font, ($yaxis_x - $this->y_label_width - $this->tick_length/2),
01702       ( -($this->small_font_height/2.0) + $y_pixels),$which_ylab, $this->ndx_text_color);
01703   }
01704 
01705   function DrawVerticalTicks() {
01706 
01707     if ($this->skip_top_tick != 1) { //If tick increment doesn't hit the top
01708       //Left Top
01709       //ImageLine($this->img,(-$this->tick_length+$this->xtr($this->plot_min_x)),
01710       //                $this->ytr($this->plot_max_y),$this->xtr($this->plot_min_x),$this->ytr($this->plot_max_y),$this->ndx_tick_color);
01711       //$ylab = $this->FormatYTickLabel($plot_max_y);
01712 
01713       //Right Top
01714       //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
01715       //                $this->ytr($this->plot_max_y),$this->xtr($this->plot_max_x-1),$this->ytr($this->plot_max_y),$this->ndx_tick_color);
01716 
01717       //Draw Grid Line at Top
01718       ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->plot_max_y),
01719           $this->plot_area[2]-1,$this->ytr($this->plot_max_y),$this->ndx_light_grid_color);
01720 
01721     }
01722 
01723     if ($this->skip_bottom_tick != 1) {
01724       //Right Bottom
01725       //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
01726       //                $this->ytr($this->plot_min_y),$this->xtr($this->plot_max_x),
01727       //                $this->ytr($this->plot_min_y),$this->ndx_tick_color);
01728 
01729       //Draw Grid Line at Bottom of Plot
01730       ImageLine($this->img,$this->xtr($this->plot_min_x)+1,$this->ytr($this->plot_min_y),
01731           $this->xtr($this->plot_max_x),$this->ytr($this->plot_min_y),$this->ndx_light_grid_color);
01732     }
01733 
01734     // maxy is always > miny so delta_y is always positive
01735     if ($this->vert_tick_increment) {
01736       $delta_y = $this->vert_tick_increment;
01737     } elseif ($this->num_vert_ticks) {
01738       $delta_y = ($this->plot_max_y - $this->plot_min_y) / $this->num_vert_ticks;
01739     } else {
01740       $delta_y =($this->plot_max_y - $this->plot_min_y) / 10 ;
01741     }
01742 
01743     $y_tmp = $this->plot_min_y;
01744     SetType($y_tmp,'double');
01745     if ($this->skip_bottom_tick == 1) {
01746       $y_tmp += $delta_y;
01747     }
01748 
01749     while ($y_tmp <= $this->plot_max_y){
01750       //For log plots:
01751       if (($this->yscale_type == "log") && ($this->plot_min_y == 1) &&
01752         ($delta_y%10 == 0) && ($y_tmp == $this->plot_min_y)) {
01753         $y_tmp = $y_tmp - 1; //Set first increment to 9 to get: 1,10,20,30,...
01754       }
01755 
01756       $ylab = $this->FormatYTickLabel($y_tmp);
01757 
01758       $this->DrawVerticalTick($ylab,$y_tmp);
01759 
01760       $y_tmp += $delta_y;
01761     }
01762 
01763     return true;
01764 
01765   } // function DrawVerticalTicks
01766 
01767   function SetTranslation() {
01768     if ($this->xscale_type == "log") {
01769       $this->xscale = ($this->plot_area_width)/(log10($this->plot_max_x) - log10($this->plot_min_x));
01770     } else {
01771       $this->xscale = ($this->plot_area_width)/($this->plot_max_x - $this->plot_min_x);
01772     }
01773     if ($this->yscale_type == "log") {
01774       $this->yscale = ($this->plot_area_height)/(log10($this->plot_max_y) - log10($this->plot_min_y));
01775     } else {
01776       $this->yscale = ($this->plot_area_height)/($this->plot_max_y - $this->plot_min_y);
01777     }
01778 
01779     // GD defines x=0 at left and y=0 at TOP so -/+ respectively
01780     if ($this->xscale_type == "log") {
01781       $this->plot_origin_x = $this->plot_area[0] - ($this->xscale * log10($this->plot_min_x) );
01782     } else {
01783       $this->plot_origin_x = $this->plot_area[0] - ($this->xscale * $this->plot_min_x);
01784     }
01785     if ($this->yscale_type == "log") {
01786       $this->plot_origin_y = $this->plot_area[3] + ($this->yscale * log10($this->plot_min_y));
01787     } else {
01788       $this->plot_origin_y = $this->plot_area[3] + ($this->yscale * $this->plot_min_y);
01789     }
01790 
01791     $this->scale_is_set = 1;
01792   } // function SetTranslation
01793 
01794   function xtr($x_world) {
01795   //Translate world coordinates into pixel coordinates
01796   //The pixel coordinates are those of the ENTIRE image, not just the plot_area
01797     //$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)) ;
01798     //which with a little bit of math reduces to ...
01799     if ($this->xscale_type == "log") {
01800       $x_pixels =  $this->plot_origin_x + log10($x_world) * $this->xscale ;
01801     } else {
01802       $x_pixels =  $this->plot_origin_x + $x_world * $this->xscale ;
01803     }
01804     return($x_pixels);
01805   }
01806 
01807   function ytr($y_world) {
01808     // translate y world coord into pixel coord
01809     if ($this->yscale_type == "log") {
01810       $y_pixels =  $this->plot_origin_y - log10($y_world) * $this->yscale ;  //minus because GD defines y=0 at top. doh!
01811     } else {
01812       $y_pixels =  $this->plot_origin_y - $y_world * $this->yscale ;
01813     }
01814     return ($y_pixels);
01815   }
01816 
01817 
01818   function DrawDataLabel($lab,$x_world,$y_world) {
01819     //Depreciated. Use DrawText Instead.
01820     //Data comes in in WORLD coordinates
01821     //Draw data label near actual data point
01822       //$y = $this->ytr($y_world) ;  //in pixels
01823       //$x = $this->xtr($x_world) ;
01824       //$this->DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left');
01825       if ($this->use_ttf) {
01826 //ajjjo
01827         $lab_size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $lab); //An array
01828         $y = $this->ytr($y_world) - $lab_size[1] ;  //in pixels
01829         $x = $this->xtr($x_world) - $lab_size[0]/2;
01830         ImageTTFText($this->img, $this->axis_ttffont_size, $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $lab);
01831       } else {
01832         $lab_size = array($this->small_font_width*StrLen($lab), $this->small_font_height*3);
01833         if ($this->x_datalabel_angle == 90) {
01834           $y = $this->ytr($y_world) - $this->small_font_width*StrLen($lab); //in pixels
01835           $x = $this->xtr($x_world) - $this->small_font_height;
01836           ImageStringUp($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
01837         } else {
01838           $y = $this->ytr($y_world) - $this->small_font_height; //in pixels
01839           $x = $this->xtr($x_world) - ($this->small_font_width*StrLen($lab))/2;
01840           ImageString($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
01841         }
01842       }
01843 
01844   }
01845 
01846   function DrawXDataLabel($xlab,$xpos) {
01847     //xpos comes in in PIXELS not in world coordinates.
01848     //Draw an x data label centered at xlab
01849       if ($this->use_ttf) {
01850         $xlab_size = $this->TTFBBoxSize($this->axis_ttffont_size,
01851           $this->x_datalabel_angle, $this->axis_ttffont, $xlab); //An array
01852         $y = $this->plot_area[3] + $xlab_size[1] + 4;  //in pixels
01853         $x = $xpos - $xlab_size[0]/2;
01854         ImageTTFText($this->img, $this->axis_ttffont_size,
01855           $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $xlab);
01856       } else {
01857         $xlab_size = array(ImageFontWidth($this->axis_font)*StrLen($xlab), $this->small_font_height*3);
01858         if ($this->x_datalabel_angle == 90) {
01859           $y = $this->plot_area[3] + ImageFontWidth($this->axis_font)*StrLen($xlab); //in pixels
01860           $x = $xpos - ($this->small_font_height);
01861           ImageStringUp($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
01862         } else {
01863           $y = $this->plot_area[3] + ImageFontHeight($this->axis_font); //in pixels
01864           $x = $xpos - (ImageFontWidth($this->axis_font)*StrLen($xlab))/2;
01865           ImageString($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
01866         }
01867       }
01868 
01869   }
01870 
01871   function DrawPieChart() {
01872     //$pi = '3.14159265358979323846';
01873     $xpos = $this->plot_area[0] + $this->plot_area_width/2;
01874     $ypos = $this->plot_area[1] + $this->plot_area_height/2;
01875     $diameter = (min($this->plot_area_width, $this->plot_area_height)) ;
01876     $radius = $diameter/2;
01877 
01878     ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
01879 
01880     $total = 0;
01881     reset($this->data_values);
01882     $tmp = $this->number_x_points - 1;
01883     while (list($j, $row) = each($this->data_values)) {
01884       //Get sum of each type
01885       $color_index = 0;
01886       $i = 0;
01887       //foreach ($row as $v)
01888       while (list($k, $v) = each($row)) {
01889         if ($k != 0) {
01890           if ($j == 0) {
01891             $sumarr[$i] = $v;
01892           } elseif ($j < $tmp) {
01893             $sumarr[$i] += $v;
01894           } else {
01895             $sumarr[$i] += $v;
01896           // NOTE!  sum > 0 to make pie charts
01897             $sumarr[$i] = abs($sumarr[$i]);
01898             $total += $sumarr[$i];
01899           }
01900         }
01901       $i++;
01902       }
01903     }
01904 
01905     $color_index = 0;
01906     $start_angle = 0;
01907 
01908     reset($sumarr);
01909     $end_angle = 0;
01910     while (list(, $val) = each($sumarr)) {
01911       if ($color_index >= count($this->ndx_data_color)) $color_index=0;  //data_color = array
01912       $label_txt = number_format(($val / $total * 100), $this->y_precision, ".", ",") . "%";
01913       $val = 360 * ($val / $total);
01914 
01915       $end_angle += $val;
01916       $mid_angle = $end_angle - ($val / 2);
01917 
01918       $slicecol = $this->ndx_data_color[$color_index];
01919 
01920 //Need this again for FillToBorder
01921       ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
01922 
01923       $out_x = $radius * cos(deg2rad($end_angle));
01924       $out_y = - $radius * sin(deg2rad($end_angle));
01925 
01926       $mid_x = $xpos + ($radius/2 * cos(deg2rad($mid_angle))) ;
01927       $mid_y = $ypos + (- $radius/2 * sin(deg2rad($mid_angle)));
01928 
01929       $label_x = $xpos + ($radius * cos(deg2rad($mid_angle))) * $this->label_scale_position;
01930       $label_y = $ypos + (- $radius * sin(deg2rad($mid_angle))) * $this->label_scale_position;
01931 
01932       $out_x = $xpos + $out_x;
01933       $out_y = $ypos + $out_y;
01934 
01935       ImageLine($this->img, $xpos, $ypos, $out_x, $out_y, $this->ndx_grid_color);
01936       //ImageLine($this->img, $xpos, $ypos, $label_x, $label_y, $this->ndx_grid_color);
01937       ImageFillToBorder($this->img, $mid_x, $mid_y, $this->ndx_grid_color, $slicecol);
01938 
01939       if ($this->use_ttf) {
01940         ImageTTFText($this->img, $this->axis_ttffont_size, 0, $label_x, $label_y, $this->ndx_grid_color, $this->axis_ttffont, $label_txt);
01941       } else {
01942         ImageString($this->img, $this->small_font, $label_x, $label_y, $label_txt, $this->ndx_grid_color);
01943       }
01944 
01945       $start_angle = $val;
01946 
01947       $color_index++;
01948     }
01949 
01950   }
01951 
01952   function DrawLinesError() {
01953     //Draw Lines with Error Bars - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...);
01954     $start_lines = 0;
01955 
01956     reset($this->data_values);
01957     while (list(, $row) = each($this->data_values)) {
01958       $color_index = 0;
01959       $i = 0;
01960 
01961       while (list($key, $val) = each($row)) {
01962 //echo "$key, $i, $val<br>";
01963         if ($key == 0) {
01964           $lab = $val;
01965         } elseif ($key == 1) {
01966           $x_now = $val;
01967           $x_now_pixels = $this->xtr($x_now); //Use a bit more memory to save 2N operations.
01968         } elseif ($key%3 == 2) {
01969           $y_now = $val;
01970           $y_now_pixels = $this->ytr($y_now);
01971 
01972           //Draw Data Label
01973           if ( $this->draw_data_labels == 1) {
01974             $this->DrawDataLabel($lab,$x_now,$y_now);
01975           }
01976 
01977           if ($color_index >= count($this->ndx_data_color)) { $color_index=0;}
01978           $barcol = $this->ndx_data_color[$color_index];
01979           $error_barcol = $this->ndx_error_bar_color[$color_index];
01980 
01981 //echo "start = $start_lines<br>";
01982           if ($start_lines == 1) {
01983             for ($width = 0; $width < $this->line_width; $width++) {
01984               ImageLine($this->img, $x_now_pixels, $y_now_pixels + $width,
01985                 $lastx[$i], $lasty[$i] + $width, $barcol);
01986             }
01987           }
01988 
01989           $lastx[$i] = $x_now_pixels;
01990           $lasty[$i] = $y_now_pixels;
01991           $color_index++;
01992           $i++;
01993           $start_lines = 1;
01994         } elseif ($key%3 == 0) {
01995           $this->DrawYErrorBar($x_now,$y_now,$val,$this->error_bar_shape,$error_barcol);
01996         } elseif ($key%3 == 1) {
01997           $this->DrawYErrorBar($x_now,$y_now,-$val,$this->error_bar_shape,$error_barcol);
01998         }
01999       }
02000     }
02001   }
02002 
02003   function DrawDotsError() {
02004     //Draw Dots - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...);
02005     reset($this->data_values);
02006     while (list(, $row) = each($this->data_values)) {
02007       $color_index = 0;
02008       //foreach ($row as $v)
02009       while (list($key, $val) = each($row)) {
02010         if ($key == 0) {
02011         } elseif ($key == 1) {
02012           $xpos = $val;
02013         } elseif ($key%3 == 2) {
02014           if ($color_index >= count($this->ndx_data_color)) $color_index=0;
02015           $barcol = $this->ndx_data_color[$color_index];
02016           $error_barcol = $this->ndx_error_bar_color[$color_index];
02017           $ypos = $val;
02018 
02019           $color_index++;
02020           $this->DrawDot($xpos,$ypos,$this->point_shape,$barcol);
02021         } elseif ($key%3 == 0) {
02022           $this->DrawYErrorBar($xpos,$ypos,$val,$this->error_bar_shape,$error_barcol);
02023         } elseif ($key%3 == 1) {
02024           $mine = $val ;
02025           $this->DrawYErrorBar($xpos,$ypos,-$val,$this->error_bar_shape,$error_barcol);
02026         }
02027       }
02028     }
02029 
02030   }
02031 
02032   function DrawDots() {
02033     //Draw Dots - data comes in as array("title",x,y1,y2,y3,...);
02034     reset($this->data_values);
02035     while (list($j, $row) = each($this->data_values)) {
02036       $color_index = 0;
02037       //foreach ($row as $v)
02038       while (list($k, $v) = each($row)) {
02039         if ($k == 0) {
02040         } elseif (($k == 1) && ($this->data_type == "data-data"))  {
02041           $xpos = $v;
02042         } else {
02043           if ($this->data_type == "text-data") {
02044             $xpos = ($j+.5);
02045           }
02046           if ($color_index >= count($this->ndx_data_color)) $color_index=0;
02047           $barcol = $this->ndx_data_color[$color_index];
02048 
02049           //if (is_numeric($v))  //PHP4 only
02050           if ((strval($v) != "") ) {   //Allow for missing Y data
02051             $this->DrawDot($xpos,$v,$this->point_shape,$barcol);
02052           }
02053           $color_index++;
02054         }
02055       }
02056     }
02057 
02058   } //function DrawDots
02059 
02060   function DrawDotSeries() {
02061     //Depreciated: Use DrawDots
02062     $this->DrawDots();
02063   }
02064 
02065   function DrawThinBarLines() {
02066     //A clean,fast routine for when you just want charts like stock volume charts
02067     //Data must be text-data since I didn't see a graphing need for equally spaced thin lines.
02068     //If you want it - then write to [email protected] and I might add it.
02069 
02070     if ($this->data_type != "data-data") { $this->DrawError('Data Type for ThinBarLines must be data-data'); }
02071     $y1 = $this->ytr($this->x_axis_position);
02072 
02073     reset($this->data_values);
02074     while (list(, $row) = each($this->data_values)) {
02075       $color_index = 0;
02076       while (list($k, $v) = each($row)) {
02077         if ($k == 0) {
02078             $xlab = $v;
02079         } elseif ($k == 1) {
02080           $xpos = $this->xtr($v);
02081           if ( ($this->draw_x_data_labels == 1) )  { //See "labels_note1 above.
02082             $this->DrawXDataLabel($xlab,$xpos);
02083           }
02084         } else {
02085           if ($color_index >= count($this->ndx_data_color)) $color_index=0;
02086           $barcol = $this->ndx_data_color[$color_index];
02087 
02088           ImageLine($this->img,$xpos,$y1,$xpos,$this->ytr($v),$barcol);
02089           $color_index++;
02090         }
02091       }
02092     }
02093 
02094   }  //function DrawThinBarLines
02095 
02096   function DrawYErrorBar($x_world,$y_world,$error_height,$error_bar_type,$color) {
02097     $x1 = $this->xtr($x_world);
02098     $y1 = $this->ytr($y_world);
02099     $y2 = $this->ytr($y_world+$error_height) ;
02100 
02101     for ($width = 0; $width < $this->error_bar_line_width; $width++) {
02102       ImageLine($this->img, $x1+$width, $y1 , $x1+$width, $y2, $color);
02103       ImageLine($this->img, $x1-$width, $y1 , $x1-$width, $y2, $color);
02104     }
02105     switch ($error_bar_type) {
02106       case "line":
02107         break;
02108       case "tee":
02109         ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color);
02110         break;
02111       default:
02112         ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color);
02113         break;
02114     }
02115     return true;
02116   }
02117 
02118   function DrawDot($x_world,$y_world,$dot_type,$color) {
02119     $half_point = $this->point_size / 2;
02120     $x1 = $this->xtr($x_world) - $half_point;
02121     $x2 = $this->xtr($x_world) + $half_point;
02122     $y1 = $this->ytr($y_world) - $half_point;
02123     $y2 = $this->ytr($y_world) + $half_point;
02124 
02125     switch ($dot_type) {
02126       case "halfline":
02127         ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $this->xtr($x_world), $this->ytr($y_world), $color);
02128         break;
02129       case "line":
02130         ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $x2, $this->ytr($y_world), $color);
02131         break;
02132       case "rect":
02133         ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
02134         break;
02135       case "circle":
02136         ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
02137         break;
02138       case "dot":
02139         ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
02140         ImageFillToBorder($this->img, $x1 + $half_point, $y1 + $half_point, $color, $color);
02141         break;
02142       case "diamond":
02143 
02144         $arrpoints = array(
02145           $x1,$y1 + $half_point,
02146           $x1 + $half_point, $y1,
02147           $x2,$y1 + $half_point,
02148           $x1 + $half_point, $y2
02149         );
02150 
02151         ImageFilledPolygon($this->img, $arrpoints, 4, $color);
02152         break;
02153       case "triangle":
02154         $arrpoints = array( $x1, $y1 + $half_point,
02155           $x2, $y1 + $half_point,
02156           $x1 + $half_point, $y2
02157         );
02158         ImageFilledPolygon($this->img, $arrpoints, 3, $color);
02159         break;
02160       default:
02161         ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
02162         break;
02163     }
02164     return true;
02165   }
02166 
02167   function SetErrorBarLineWidth($which_seblw) {
02168     $this->error_bar_line_width = $which_seblw;
02169     return true;
02170   }
02171 
02172 
02173   function SetLineWidth($which_lw) {
02174     $this->line_width = $which_lw;
02175     if (!$this->error_bar_line_width) {
02176       $this->error_bar_line_width = $which_lw;
02177     }
02178     return true;
02179   }
02180 
02181   function DrawArea() {
02182     //Data comes in as $data[]=("title",x,y,...);
02183     //Set first and last datapoints of area
02184     $i = 0;
02185     while ($i < $this->records_per_group) {
02186       $posarr[$i][] =  $this->xtr($this->min_x);        //x initial
02187       $posarr[$i][] =  $this->ytr($this->x_axis_position);      //y initial
02188       $i++;
02189     }
02190 
02191     reset($this->data_values);
02192     while (list($j, $row) = each($this->data_values)) {
02193       $color_index = 0;
02194       //foreach ($row as $v)
02195       while (list($k, $v) = each($row)) {
02196         if ($k == 0) {
02197           //Draw Data Labels
02198           $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
02199         } elseif ($k == 1) {
02200           $x = $this->xtr($v);
02201           // DrawXDataLabel interferes with Numbers on x-axis
02202           //$this->DrawXDataLabel($xlab,$x);
02203         } else {
02204           // Create Array of points for later
02205 
02206           $y = $this->ytr($v);
02207           $posarr[$color_index][] = $x;
02208           $posarr[$color_index][] = $y;
02209           $color_index++;
02210         }
02211       }
02212     }
02213 
02214     //Final_points
02215     for ($i = 0; $i < $this->records_per_group; $i++) {
02216       $posarr[$i][] =  $this->xtr($this->max_x);                        //x final
02217       $posarr[$i][] =  $this->ytr($this->x_axis_position);      //y final
02218        }
02219 
02220     $color_index=0;
02221 
02222     //foreach($posarr as $row)
02223     reset($posarr);
02224     while (list(, $row) = each($posarr)) {
02225       if ($color_index >= count($this->ndx_data_color)) $color_index=0;
02226       $barcol = $this->ndx_data_color[$color_index];
02227 //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>";
02228       ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
02229       $color_index++;
02230     }
02231 //exit;
02232 
02233   }
02234 
02235   function DrawAreaSeries() {
02236 
02237     //Set first and last datapoints of area
02238     $i = 0;
02239     while ($i < $this->records_per_group) {
02240       $posarr[$i][] =  $this->xtr(.5);                  //x initial
02241       $posarr[$i][] =  $this->ytr($this->x_axis_position);      //y initial
02242       $i++;
02243     }
02244 
02245     reset($this->data_values);
02246     while (list($j, $row) = each($this->data_values)) {
02247       $color_index = 0;
02248       //foreach ($row as $v)
02249       while (list($k, $v) = each($row)) {
02250         if ($k == 0) {
02251           //Draw Data Labels
02252           $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
02253           $this->DrawXDataLabel($xlab,$this->xtr($j + .5));
02254         } else {
02255           // Create Array of points for later
02256 
02257           $x = round($this->xtr($j + .5 ));
02258           $y = round($this->ytr($v));
02259           $posarr[$color_index][] = $x;
02260           $posarr[$color_index][] = $y;
02261           $color_index++;
02262         }
02263       }
02264     }
02265 
02266     //Final_points
02267     for ($i = 0; $i < $this->records_per_group; $i++) {
02268       $posarr[$i][] =  round($this->xtr($this->max_x + .5));    //x final
02269       $posarr[$i][] =  $this->ytr($this->x_axis_position);              //y final
02270        }
02271 
02272     $color_index=0;
02273 
02274     //foreach($posarr as $row)
02275     reset($posarr);
02276     while (list(, $row) = each($posarr)) {
02277       if ($color_index >= count($this->ndx_data_color)) $color_index=0;
02278       $barcol = $this->ndx_data_color[$color_index];
02279 //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>";
02280       ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
02281       $color_index++;
02282     }
02283 
02284   }
02285 
02286   function DrawLines() {
02287     //Data comes in as $data[]=("title",x,y,...);
02288     $start_lines = 0;
02289     if ($this->data_type == "text-data") {
02290       $lastx[0] = $this->xtr(0);
02291       $lasty[0] = $this->xtr(0);
02292     }
02293 
02294     //foreach ($this->data_values as $row)
02295     reset($this->data_values);
02296     while (list($j, $row) = each($this->data_values)) {
02297 
02298       $color_index = 0;
02299       $i = 0;
02300       //foreach ($row as $v)
02301       while (list($k, $v) = each($row)) {
02302         if ($k == 0) {
02303           $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
02304         } elseif (($k == 1) && ($this->data_type == "data-data"))  {
02305             $x_now = $this->xtr($v);
02306         } else {
02307           //(double) $v;
02308           // Draw Lines
02309           if ($this->data_type == "text-data") {
02310             $x_now = $this->xtr($j+.5);
02311           }
02312 
02313           //if (is_numeric($v))  //PHP4 only
02314           if ((strval($v) != "") ) {   //Allow for missing Y data
02315             $y_now = $this->ytr($v);
02316             if ($color_index >= count($this->ndx_data_color)) { $color_index=0;} ;
02317             $barcol = $this->ndx_data_color[$color_index];
02318 
02319             if ($start_lines == 1) {
02320               for ($width = 0; $width < $this->line_width; $width++) {
02321                 if ($this->line_style[$i] == "dashed") {
02322                   $this->DrawDashedLine($x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, 4,4, $barcol);
02323                 } else {
02324                   ImageLine($this->img, $x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, $barcol);
02325                 }
02326               }
02327             }
02328             $lastx[$i] = $x_now;
02329           } else {
02330             $y_now = $lasty[$i];
02331             //Don't increment lastx[$i]
02332           }
02333           //$bordercol = $this->ndx_data_border_color[$colbarcount];
02334 
02335           $lasty[$i] = $y_now;
02336           $color_index++;
02337           $i++;
02338         }
02339         //Now we are assured an x_value
02340         if ( ($this->draw_x_data_labels == 1) && ($k == 1) )  { //See "labels_note1 above.
02341           $this->DrawXDataLabel($xlab,$x_now);
02342         }
02343       } //while rows of data
02344       $start_lines = 1;
02345     }
02346   }
02347 
02348     //Data comes in as $data[]=("title",x,y,e+,e-,y2,e2+,e2-,...);
02349 
02350   function DrawLineSeries() {
02351     //This function is replaced by DrawLines
02352     //Tests have shown not much improvement in speed by having separate routines for DrawLineSeries and DrawLines
02353     //For ease of programming I have combined them
02354     return false;
02355   } //function DrawLineSeries
02356 
02357   function DrawDashedLine($x1pix,$y1pix,$x2pix,$y2pix,$dash_length,$dash_space,$color) {
02358     //Code based on work by Ariel Garza and James Pine
02359     //I've decided to have this be in pixels only as a replacement for ImageLine
02360     //$x1pix = $this->xtr($x1);
02361     //$y1pix = $this->ytr($y1);
02362     //$x2pix = $this->xtr($x2);
02363     //$y2pix = $this->ytr($y2);
02364 
02365     // Get the length of the line in pixels
02366     $line_length = ceil (sqrt(pow(($x2pix - $x1pix),2) + pow(($y2pix - $y1pix),2)) );
02367 
02368     $dx = ($x2pix - $x1pix) / $line_length;
02369     $dy = ($y2pix - $y1pix) / $line_length;
02370     $lastx      = $x1pix;
02371     $lasty      = $y1pix;
02372 
02373     // Draw the dashed line
02374     for ($i = 0; $i < $line_length; $i += ($dash_length + $dash_space)) {
02375       $xpix = ($dash_length * $dx) + $lastx;
02376       $ypix = ($dash_length * $dy) + $lasty;
02377 
02378       ImageLine($this->img,$lastx,$lasty,$xpix,$ypix,$color);
02379       $lastx = $xpix + ($dash_space * $dx);
02380       $lasty = $ypix + ($dash_space * $dy);
02381     }
02382   } // function DrawDashedLine
02383 
02384   function DrawBars() {
02385 
02386     if ($this->data_type != "text-data") {
02387       $this->DrawError('Bar plots must be text-data: use function SetDataType("text-data")');
02388     }
02389 
02390     $xadjust = ($this->records_per_group * $this->record_bar_width )/4;
02391 
02392     reset($this->data_values);
02393     while (list($j, $row) = each($this->data_values)) {
02394 
02395       $color_index = 0;
02396       $colbarcount = 0;
02397       $x_now = $this->xtr($j+.5);
02398 
02399       while (list($k, $v) = each($row)) {
02400         if ($k == 0) {
02401           //Draw Data Labels
02402           $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
02403           $this->DrawXDataLabel($xlab,$x_now);
02404         } else {
02405           // Draw Bars ($v)
02406           $x1 = $x_now - $this->data_group_space + ($k-1)*$this->record_bar_width;
02407           $x2 = $x1 + $this->record_bar_width*$this->bar_width_adjust;
02408 
02409           if ($v < $this->x_axis_position) {
02410             $y1 = $this->ytr($this->x_axis_position);
02411             $y2 = $this->ytr($v);
02412           } else {
02413             $y1 = $this->ytr($v);
02414             $y2 = $this->ytr($this->x_axis_position);
02415           }
02416 
02417           if ($color_index >= count($this->ndx_data_color)) $color_index=0;
02418           if ($colbarcount >= count($this->ndx_data_border_color)) $colbarcount=0;
02419           $barcol = $this->ndx_data_color[$color_index];
02420           $bordercol = $this->ndx_data_border_color[$colbarcount];
02421 
02422           if ((strval($v) != "") ) {   //Allow for missing Y data
02423             if ($this->shading > 0) {
02424               for($i=0;$i<($this->shading);$i++) {
02425               //Shading set in SetDefaultColors
02426               ImageFilledRectangle($this->img, $x1+$i, $y1-$i, $x2+$i, $y2-$i, $this->ndx_i_light);
02427               }
02428             }
02429 
02430             ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $barcol);
02431             ImageRectangle($this->img, $x1, $y1, $x2, $y2, $bordercol);
02432             if ($this->draw_data_labels == '1') {  //ajo
02433               $y1 = $this->ytr($this->label_scale_position * $v);
02434               //$this->DrawDataLabel($v,$j + .5,$v*$this->label_scale_position);
02435               $this->DrawText($this->small_font, $this->x_label_angle,
02436                 $x1+$this->record_bar_width/2, $y1, $this->ndx_label_color, $this->x_label_ttffont_size, $v,'center','top');
02437             }
02438           }
02439 
02440           $color_index++;
02441           $colbarcount++;
02442         }
02443       }
02444     }
02445   } //function DrawBars
02446 
02447   function DrawLegend($which_x1,$which_y1,$which_boxtype) {
02448     //Base code submitted by Marlin Viss
02449     $max_legend_length=0;
02450     reset($this->legend);
02451     while (list(,$leg) = each($this->legend)) {
02452       $len = strlen($leg);
02453       if ($max_legend_length < $len) {
02454         $max_legend_length = $len;
02455       }
02456     }
02457 
02458     $line_spacing = 1.25;
02459     $vert_margin = $this->small_font_height/2 ;
02460     $dot_height = $this->small_font_height*$line_spacing - 1;
02461 
02462   //Upper Left
02463     if ((!$which_x1) || (!$which_y1) ) {
02464       $box_start_x = $this->plot_area[2] - $this->small_font_width*($max_legend_length+4);
02465       $box_start_y = $this->plot_area[1] + 4;
02466     } else {
02467       $box_start_x = $which_x1;
02468       $box_start_y = $which_y1;
02469     }
02470 
02471   //Lower Right
02472     $box_end_y = $box_start_y + $this->small_font_height*(count($this->legend)+1) + 2*$vert_margin;
02473     //$box_end_x = $this->plot_area[2] - 5;
02474     $box_end_x = $box_start_x + $this->small_font_width*($max_legend_length+4) - 5;
02475 
02476 
02477   // Draw box for legend
02478     ImageFilledRectangle($this->img,
02479       $box_start_x, $box_start_y,$box_end_x,
02480       $box_end_y, $this->ndx_bg_color);
02481     ImageRectangle($this->img,
02482       $box_start_x, $box_start_y,$box_end_x,
02483       $box_end_y, $this->ndx_grid_color);
02484 
02485     $color_index=0;
02486     $i = 0;
02487 
02488 
02489     reset($this->legend);
02490 
02491 
02492     while (list(,$leg) = each($this->legend)) {
02493       $y_pos = $box_start_y + $this->small_font_height*($i)*($line_spacing) + $vert_margin;
02494 
02495       ImageString($this->img, $this->small_font,
02496       $box_start_x + $this->small_font_width*( $max_legend_length - strlen($leg) + 1 ) ,
02497       $y_pos,
02498       $leg, $this->ndx_text_color);
02499 
02500       if ($color_index >= count($this->ndx_data_color)) $color_index=0;
02501   // Draw a box in the data color
02502       ImageFilledRectangle($this->img,
02503         $box_end_x - $this->small_font_width*2,
02504         $y_pos + 1, $box_end_x - $this->small_font_width,
02505         $y_pos + $dot_height,
02506         $this->ndx_data_color[$color_index]);
02507 
02508       ImageRectangle($this->img,
02509         $box_end_x - $this->small_font_width*2,
02510         $y_pos + 1, $box_end_x - $this->small_font_width,
02511         $y_pos + $dot_height,
02512         $this->ndx_text_color);
02513       $i++;
02514       $color_index++;
02515     }
02516   } //function DrawLegend
02517 
02518 
02519   function DrawGraph() {
02520 
02521     if (($this->img) == "") {
02522       $this->DrawError('No Image Defined: DrawGraph');
02523             //$this->PHPlot();
02524         }
02525 
02526     if (! is_array($this->data_values)) {
02527       $this->DrawBackground();
02528       $this->DrawError("No array of data in \$data_values");
02529     } else {
02530       if (!$this->data_color) {
02531         $this->SetDataColors(array('blue','green','yellow','red','orange','blue'),array('black'));
02532       }
02533 
02534       $this->FindDataLimits();  //Get maxima and minima for scaling
02535 
02536       $this->SetXLabelHeight();         //Get data for bottom margin
02537 
02538       $this->SetYLabelWidth();          //Get data for left margin
02539 
02540       if (!$this->plot_area_width) {
02541         $this->SetPlotAreaPixels('','','','');          //Set Margins
02542       }
02543 
02544       if (!$this->plot_max_y) {  //If not set by user call SetPlotAreaWorld,
02545         $this->SetPlotAreaWorld('','','','');
02546       }
02547 
02548       if ($this->data_type == "text-data") {
02549         $this->SetEqualXCoord();
02550       }
02551 
02552       $this->SetPointSize($this->point_size);
02553 
02554       $this->DrawBackground();
02555       $this->DrawImageBorder();
02556 
02557       $this->SetTranslation();
02558 
02559       if ($this->draw_plot_area_background == 1) {
02560         $this->DrawPlotAreaBackground();
02561       }
02562 //$foo = "$this->max_y, $this->min_y, $new_miny, $new_maxy, $this->x_label_height";
02563 //ImageString($this->img, 4, 20, 20, $foo, $this->ndx_text_color);
02564 
02565       switch ($this->plot_type) {
02566         case "bars":
02567           $this->DrawPlotBorder();
02568           $this->DrawLabels();
02569           $this->DrawBars();
02570           $this->DrawXAxis();
02571           break;
02572         case "thinbarline":
02573           $this->DrawPlotBorder();
02574           $this->DrawLabels();
02575           $this->DrawThinBarLines();
02576           break;
02577         case "lines":
02578           $this->DrawPlotBorder();
02579           $this->DrawLabels();
02580           if ( $this->data_type == "text-data") {
02581             $this->DrawLines();
02582           } elseif ( $this->data_type == "data-data-error") {
02583             $this->DrawLinesError();
02584           } else {
02585             $this->DrawLines();
02586           }
02587           break;
02588         case "area":
02589           $this->DrawPlotBorder();
02590           $this->DrawLabels();
02591           if ( $this->data_type == "text-data") {
02592             $this->DrawAreaSeries();
02593           } else {
02594             $this->DrawArea();
02595           }
02596           break;
02597         case "linepoints":
02598           $this->DrawPlotBorder();
02599           $this->DrawLabels();
02600           if ( $this->data_type == "text-data") {
02601             $this->DrawLines();
02602             $this->DrawDots();
02603           } elseif ( $this->data_type == "data-data-error") {
02604             $this->DrawLinesError();
02605             $this->DrawDotsError();
02606           } else {
02607             $this->DrawLines();
02608             $this->DrawDots();
02609           }
02610           break;
02611         case "points";
02612           $this->DrawPlotBorder();
02613           $this->DrawLabels();
02614           if ( $this->data_type == "text-data") {
02615             $this->DrawDots();
02616           } elseif ( $this->data_type == "data-data-error") {
02617             $this->DrawDotsError();
02618           } else {
02619             $this->DrawDots();
02620           }
02621           break;
02622         case "pie":
02623           $this->DrawPieChart();
02624           $this->DrawLabels();
02625           break;
02626         default:
02627           $this->DrawPlotBorder();
02628           $this->DrawLabels();
02629           $this->DrawBars();
02630           break;
02631       }
02632 
02633       if ($this->legend) {
02634         $this->DrawLegend($this->legend_x_pos,$this->legend_y_pos,'');
02635       }
02636 
02637     }
02638     if ($this->print_image == 1) {
02639       $this->PrintImage();
02640     }
02641   } //function DrawGraph
02642 
02643  }
02644 
02645 // $graph = new PHPlot;
02646 
02647 // $graph->DrawGraph();
02648 
 All Data Structures Namespaces Files Functions Variables Enumerations