PageRenderTime 536ms CodeModel.GetById 121ms app.highlight 256ms RepoModel.GetById 76ms app.codeStats 1ms

/oscommerce-2.2rc2/admin/includes/classes/phplot.php

http://myopensources.googlecode.com/
PHP | 2639 lines | 1963 code | 377 blank | 299 comment | 459 complexity | ded2829ff3d112f41a705a7c6d06d2c8 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/*
   3  $Id: phplot.php 1739 2007-12-20 00:52:16Z hpdl $
   4
   5  osCommerce, Open Source E-Commerce Solutions
   6  http://www.oscommerce.com
   7
   8  Copyright (c) 2003 osCommerce
   9
  10  Released under the GNU General Public License
  11
  12  PHPLOT 4.4.6 Copyright (c) 1998-2001 Afan Ottenheimer
  13*/
  14
  15class PHPlot{
  16
  17	var $is_inline = 0;			//0 = Sends headers, 1 = sends just raw image data
  18	var $browser_cache = '1';	// 0 = Sends headers for browser to not cache the image, (i.e. 0 = don't let browser cache image)
  19									// (only if is_inline = 0 also)
  20	var $session_set = '';		//Do not change
  21	var $scale_is_set = '';		//Do not change
  22	var $draw_plot_area_background = '';
  23
  24	var $image_width;	//Total Width in Pixels 
  25	var $image_height; 	//Total Height in Pixels
  26	var $image_border_type = ''; //raised, plain, ''
  27	var $x_left_margin;
  28	var $y_top_margin;
  29	var $x_right_margin;
  30	var $y_bot_margin;
  31	var $plot_area = array(5,5,600,400);
  32	var $x_axis_position = 0;	//Where to draw the X_axis (world coordinates)
  33	var $y_axis_position = '';  //Leave blank for Y axis at left of plot. (world coord.)
  34	var $xscale_type = 'linear';  //linear or log
  35	var $yscale_type = 'linear';
  36
  37//Use for multiple plots per image
  38	var $print_image = 1;  //Used for multiple charts per image. 
  39
  40//Fonts
  41	var $use_ttf  = 0;		  //Use TTF fonts (1) or not (0)
  42	var $font_path = './';  //To be added 
  43	var $font = './benjamingothic.ttf';
  44
  45	///////////Fonts: Small/Generic
  46	var $small_ttffont_size = 12; //
  47	//non-ttf
  48	var $small_font = 2; // fonts = 1,2,3,4 or 5
  49	var $small_font_width = 6.0; // width in pixels (2=6,3=8,4=8)
  50	var $small_font_height = 8.0; // height in pixels (2=8,3=10,4=12)
  51
  52	//////////   Fonts:Title
  53	var $title_ttffont = './benjamingothic.ttf';
  54	var $title_ttffont_size = 14;
  55	var $title_angle= 0;
  56	//non-ttf
  57	var $title_font = '4'; // fonts = 1,2,3,4,5
  58
  59	//////////////  Fonts:Axis
  60	var $axis_ttffont = './benjamingothic.ttf';
  61	var $axis_ttffont_size = 8;
  62	var $x_datalabel_angle = 0;
  63	//non-ttf
  64	var $axis_font = 2;
  65
  66	////////////////Fonts:Labels of Data
  67	var $datalabel_font = '2';
  68
  69	//////////////// Fonts:Labels (Axis Titles)
  70	var $x_label_ttffont = './benjamingothic.ttf';
  71	var $x_label_ttffont_size = '12';
  72	var $x_label_angle = '0';
  73
  74	var $y_label_ttffont = './benjamingothic.ttf';
  75	var $y_label_ttffont_size = '12';
  76	var $y_label_angle = 90;
  77	var $y_label_width = '';
  78
  79//Formats
  80	var $file_format = 'png';
  81	var $file_name = '';  //For output to a file instead of stdout
  82
  83//Plot Colors
  84	var $shading = 0;
  85	var $color_array = 1;	//1 = include small list
  86							//2 = include large list
  87							//array =  define your own color translation. See rgb.inc.php and SetRGBArray
  88	var $bg_color;
  89	var $plot_bg_color;
  90	var $grid_color;
  91	var $light_grid_color;
  92	var $tick_color;
  93	var $title_color;
  94	var $label_color;
  95	var $text_color;
  96	var $i_light = '';
  97
  98//Data
  99	var $data_type = 'text-data'; //text-data, data-data-error, data-data 
 100	var $plot_type= 'linepoints'; //bars, lines, linepoints, area, points, pie, thinbarline
 101	var $line_width = 2;
 102	var $line_style = array('solid','solid','solid','dashed','dashed','solid'); //Solid or dashed lines
 103
 104	var $data_color = ''; //array('blue','green','yellow',array(0,0,0));
 105	var $data_border_color = '';
 106
 107	var $label_scale_position = '.5';  //1 = top, 0 = bottom
 108	var $group_frac_width = '.7'; //value from 0 to 1 = width of bar
 109	var $bar_width_adjust = '1'; //1 = bars of normal width, must be > 0
 110
 111	var $point_size = 10;
 112	var $point_shape = 'diamond'; //rect,circle,diamond,triangle,dot,line,halfline
 113	var $error_bar_shape = 'tee'; //tee, line
 114	var $error_bar_size = 5; //right left size of tee
 115	var $error_bar_line_width = ''; //If set then use it, else use $line_width for thickness
 116	var $error_bar_color = ''; 
 117	var $data_values;
 118
 119	var $plot_border_type = 'full'; //left, none, full
 120	var $plot_area_width = '';
 121	var $number_x_points;
 122	var $plot_min_x; // Max and min of the plot area
 123	var $plot_max_x= ''; // Max and min of the plot area
 124	var $plot_min_y= ''; // Max and min of the plot area
 125	var $plot_max_y = ''; // Max and min of the plot area
 126	var $min_y = '';
 127	var $max_y = '';
 128	var $max_x = 10;  //Must not be = 0;
 129	var $y_precision = '1';
 130	var $x_precision = '1';
 131	var $si_units = '';
 132
 133//Labels
 134	var $draw_data_labels = '0';  
 135	var $legend = '';  //an array
 136	var $legend_x_pos = '';
 137	var $legend_y_pos = '';
 138	var $title_txt = "";
 139	var $y_label_txt = '';
 140	var $x_label_txt = "";
 141
 142//DataAxis Labels (on each axis)
 143	var $y_grid_label_type = 'data';    //data, none, time, other
 144	var $y_grid_label_pos = 'plotleft'; //plotleft, plotright, yaxis, both
 145	var $x_grid_label_type = 'data';    //data, title, none, time, other
 146	var $draw_x_data_labels = '';       // 0=false, 1=true, ""=let program decide 
 147	var $x_time_format = "%H:%m:%s";    //See http://www.php.net/manual/html/function.strftime.html
 148	var $x_datalabel_maxlength = 10;	
 149
 150//Tick Formatting
 151	var $tick_length = '10';   //pixels: tick length from axis left/downward
 152	//tick_length2 to be implemented
 153	//var $tick_length2 = '';  //pixels: tick length from axis line rightward/upward
 154	var $draw_vert_ticks = 1;  //1 = draw ticks, 0 = don't draw ticks
 155	var $num_vert_ticks = '';
 156	var $vert_tick_increment=''; //Set num_vert_ticks or vert_tick_increment, not both.
 157	var $vert_tick_position = 'both'; //plotright=(right of plot only), plotleft=(left of plot only), 
 158								//both = (both left and right of plot), yaxis=(crosses y axis)
 159	var $horiz_tick_increment=''; //Set num_horiz_ticks or horiz_tick_increment, not both.
 160	var $num_horiz_ticks='';
 161	var $skip_top_tick = '0';
 162	var $skip_bottom_tick = '0';
 163
 164//Grid Formatting
 165	var $draw_x_grid = 0;
 166	var $draw_y_grid = 1;
 167
 168
 169//BEGIN CODE
 170//////////////////////////////////////////////////////
 171	//Constructor: Setup Img pointer, Colors and Size of Image
 172	function PHPlot($which_width=600,$which_height=400,$which_output_file="",$which_input_file="") {
 173
 174		$this->SetRGBArray('2'); 
 175		$this->background_done = 0; //Set to 1 after background image first drawn
 176
 177		if ($which_output_file != "") { $this->SetOutputFile($which_output_file);  };
 178
 179		if ($which_input_file != "") { 
 180			$this->SetInputFile($which_input_file) ; 
 181		} else { 
 182			$this->SetImageArea($which_width, $which_height);
 183			$this->InitImage();
 184		}
 185
 186		if ( ($this->session_set == 1) && ($this->img == "") ) {  //For sessions
 187			//Do nothing
 188		} else { 
 189			$this->SetDefaultColors();
 190		}
 191
 192		$this->SetIndexColors();
 193
 194	}
 195	    
 196	//Set up the image and colors
 197	function InitImage() {
 198		//if ($this->img) { 
 199		//	ImageDestroy($this->img);
 200		//}
 201		$this->img = ImageCreate($this->image_width, $this->image_height);
 202		return true;
 203	}
 204
 205	function SetBrowserCache($which_browser_cache) {  //Submitted by Thiemo Nagel
 206		$this->browser_cache = $which_browser_cache;
 207		return true;
 208	}
 209
 210	function SetPrintImage($which_pi) {
 211		$this->print_image = $which_pi;
 212		return true;
 213	}
 214
 215	function SetIsInline($which_ii) {
 216		$this->is_inline = $which_ii;
 217		return true;
 218	}
 219
 220	function SetUseTTF($which_ttf) {
 221		$this->use_ttf = $which_ttf;
 222		return true;
 223	}
 224
 225	function SetTitleFontSize($which_tfs) {
 226		//TTF
 227		$this->title_ttffont_size = $which_tfs; //pt size
 228
 229		//Non-TTF settings
 230		if (($which_tfs > 5) && (!$this->use_ttf)) {
 231			$this->DrawError('Non-TTF font size must be 1,2,3,4 or 5');
 232			return false;
 233		} else {
 234			$this->title_font = $which_tfs;
 235			//$this->title_font_height = ImageFontHeight($which_tfs) // height in pixels 
 236			//$this->title_font_width = ImageFontWidth($which_tfs); // width in pixels 
 237		}
 238		return true;
 239	}
 240
 241	function SetLineStyles($which_sls){
 242		$this->line_style = $which_sls;
 243		return true;
 244	}
 245
 246	function SetLegend($which_leg){
 247		if (is_array($which_leg)) { 
 248			$this->legend = $which_leg;
 249			return true;
 250		} else { 
 251			$this->DrawError('Error: SetLegend argument must be an array');
 252			return false;
 253		}
 254	}
 255
 256	function SetLegendPixels($which_x,$which_y,$which_type) { 
 257		//which_type not yet used
 258		$this->legend_x_pos = $which_x;
 259		$this->legend_y_pos = $which_y;
 260		return true;
 261	}
 262
 263	function SetLegendWorld($which_x,$which_y,$which_type='') { 
 264		//which_type not yet used
 265		//Must be called after scales are set up. 
 266		if ($this->scale_is_set != 1) { $this->SetTranslation(); };
 267		$this->legend_x_pos = $this->xtr($which_x);
 268		$this->legend_y_pos = $this->ytr($which_y);
 269		return true;
 270	}
 271/* ***************************************
 272	function SetFileFormat($which_file_format) { //Only works with PHP4
 273		$asked = strtolower($which_file_format);
 274		if( $asked =="jpg" || $asked =="png" || $asked =="gif" || $asked =="wbmp" ) {
 275			if( $asked=="jpg" && !(imagetypes() & IMG_JPG) )
 276				return false;
 277			elseif( $asked=="png" && !(imagetypes() & IMG_PNG) ) 
 278				return false;
 279			elseif( $asked=="gif" && !(imagetypes() & IMG_GIF) ) 	
 280				return false;
 281			elseif( $asked=="wbmp" && !(imagetypes() & IMG_WBMP) ) 	
 282				return false;
 283			else {
 284				$this->img_format=$asked;
 285				return true;
 286			}
 287		}
 288		else
 289			return false;
 290	}	
 291
 292*************************************** */
 293	function SetFileFormat($which_file_format) {
 294	//eventually test to see if that is supported - if not then return false
 295		$asked = strtolower(trim($which_file_format));
 296		if( ($asked=='jpg') || ($asked=='png') || ($asked=='gif') || ($asked=='wbmp') ) {
 297			$this->file_format = $asked;
 298			return true;
 299		} else {
 300			return false;
 301		}
 302	}
 303
 304	function SetInputFile($which_input_file) { 
 305		//$this->SetFileFormat($which_frmt);
 306		$size = GetImageSize($which_input_file);
 307		$input_type = $size[2]; 
 308
 309		switch($input_type) {  //After SetFileFormat is in lower case
 310			case "1":
 311				$im = @ImageCreateFromGIF ($which_input_file);
 312				if (!$im) { // See if it failed 
 313					$this->PrintError("Unable to open $which_input_file as a GIF");
 314					return false;
 315				}
 316			break;
 317			case "3":
 318				$im = @ImageCreateFromPNG ($which_input_file); 
 319				if (!$im) { // See if it failed 
 320					$this->PrintError("Unable to open $which_input_file as a PNG");
 321					return false;
 322				}
 323			break;
 324			case "2":
 325				$im = @ImageCreateFromJPEG ($which_input_file); 
 326				if (!$im) { // See if it failed 
 327					$this->PrintError("Unable to open $which_input_file as a JPG");
 328					return false;
 329				}
 330			break;
 331			default:
 332				$this->PrintError('Please select wbmp,gif,jpg, or png for image type!');
 333				return false;
 334			break;
 335		}
 336
 337		//Get Width and Height of Image
 338		$this->SetImageArea($size[0],$size[1]);
 339
 340		$this->img = $im;
 341
 342		return true;
 343
 344	}
 345
 346	function SetOutputFile($which_output_file) { 
 347		$this->output_file = $which_output_file;
 348		return true;
 349	}
 350
 351	function SetImageArea($which_iw,$which_ih) {
 352		//Note this is now an Internal function - please set w/h via PHPlot()
 353		$this->image_width = $which_iw;
 354		$this->image_height = $which_ih;
 355
 356		return true;
 357	}
 358
 359
 360	function SetYAxisPosition($which_pos) {
 361		$this->y_axis_position = $which_pos;
 362		return true;
 363	}
 364	function SetXAxisPosition($which_pos) {
 365		$this->x_axis_position = $which_pos;
 366		return true;
 367	}
 368	function SetXTimeFormat($which_xtf) {
 369		$this->x_time_format = $which_xtf;
 370		return true;
 371	}
 372	function SetXDataLabelMaxlength($which_xdlm) { 
 373		if ($which_xdlm >0 ) { 
 374			$this->x_datalabel_maxlength = $which_xdlm;
 375			return true;
 376		} else { 
 377			return false;
 378		}
 379	}
 380	function SetXDataLabelAngle($which_xdla) { 
 381		$this->x_datalabel_angle = $which_xdla;
 382		return true;
 383	}
 384	function SetXScaleType($which_xst) { 
 385		$this->xscale_type = $which_xst;
 386		return true;
 387	}
 388	function SetYScaleType($which_yst) { 
 389		$this->yscale_type = $which_yst;
 390		if ($this->x_axis_position <= 0) { 
 391			$this->x_axis_position = 1;
 392		}
 393		return true;
 394	}
 395
 396	function SetPrecisionX($which_prec) {
 397		$this->x_precision = $which_prec;
 398		return true;
 399	}
 400	function SetPrecisionY($which_prec) {
 401		$this->y_precision = $which_prec;
 402		return true;
 403	}
 404
 405
 406	function SetIndexColors() { //Internal Method called to set colors and preserve state
 407		//These are the colors of the image that are used. They are initialized
 408		//to work with sessions and PHP. 
 409
 410		$this->ndx_i_light = $this->SetIndexColor($this->i_light);
 411		$this->ndx_i_dark  = $this->SetIndexColor($this->i_dark);
 412		$this->ndx_bg_color= $this->SetIndexColor($this->bg_color);
 413		$this->ndx_plot_bg_color= $this->SetIndexColor($this->plot_bg_color);
 414
 415		$this->ndx_title_color= $this->SetIndexColor($this->title_color);
 416		$this->ndx_tick_color= $this->SetIndexColor($this->tick_color);
 417		$this->ndx_label_color= $this->SetIndexColor($this->label_color);
 418		$this->ndx_text_color= $this->SetIndexColor($this->text_color);
 419		$this->ndx_light_grid_color= $this->SetIndexColor($this->light_grid_color);
 420		$this->ndx_grid_color= $this->SetIndexColor($this->grid_color);
 421
 422		reset($this->error_bar_color);  
 423		unset($ndx_error_bar_color);
 424		$i = 0; 
 425		while (list(, $col) = each($this->error_bar_color)) {
 426		  $this->ndx_error_bar_color[$i] = $this->SetIndexColor($col);
 427			$i++;
 428		}
 429		//reset($this->data_border_color);
 430		unset($ndx_data_border_color);
 431		$i = 0;
 432		while (list(, $col) = each($this->data_border_color)) {
 433			$this->ndx_data_border_color[$i] = $this->SetIndexColor($col);
 434			$i++;
 435		}
 436		//reset($this->data_color); 
 437		unset($ndx_data_color);
 438		$i = 0;
 439		while (list(, $col) = each($this->data_color)) {
 440			$this->ndx_data_color[$i] = $this->SetIndexColor($col);
 441			$i++;
 442		}
 443
 444		return true;
 445	}
 446
 447
 448	function SetDefaultColors() {
 449
 450		$this->i_light = array(194,194,194);
 451		$this->i_dark =  array(100,100,100);
 452		$this->SetPlotBgColor(array(222,222,222));
 453		$this->SetBackgroundColor(array(200,222,222)); //can use rgb values or "name" values
 454		$this->SetLabelColor('black');
 455		$this->SetTextColor('black');
 456		$this->SetGridColor('black');
 457		$this->SetLightGridColor(array(175,175,175));
 458		$this->SetTickColor('black');
 459		$this->SetTitleColor(array(0,0,0)); // Can be array or name
 460		$this->data_color = array('blue','green','yellow','red','orange');
 461		$this->error_bar_color = array('blue','green','yellow','red','orange');
 462		$this->data_border_color = array('black');
 463
 464		$this->session_set = 1; //Mark it down for PHP session() usage.
 465	}
 466
 467	function PrintImage() {
 468
 469		if ( ($this->browser_cache == 0) && ($this->is_inline == 0)) { //Submitted by Thiemo Nagel
 470			header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
 471			header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT');
 472			header('Cache-Control: no-cache, must-revalidate');
 473			header('Pragma: no-cache');
 474		}
 475
 476		switch($this->file_format) {
 477			case "png":
 478				if ($this->is_inline == 0) {
 479					Header('Content-type: image/png');
 480				}
 481				if ($this->is_inline == 1 && $this->output_file != "") {
 482					ImagePng($this->img,$this->output_file);
 483				} else {
 484					ImagePng($this->img);
 485				}
 486				break;
 487			case "jpg":
 488				if ($this->is_inline == 0) {
 489					Header('Content-type: image/jpeg');
 490				}
 491				if ($this->is_inline == 1 && $this->output_file != "") {
 492					ImageJPEG($this->img,$this->output_file);
 493				} else {
 494					ImageJPEG($this->img);
 495				}
 496				break;
 497			case "gif":
 498				if ($this->is_inline == 0) {
 499					Header('Content-type: image/gif');
 500				}
 501				if ($this->is_inline == 1 && $this->output_file != "") {
 502					ImageGIF($this->img,$this->output_file);
 503				} else {
 504					ImageGIF($this->img);
 505				}
 506
 507				break;
 508			case "wbmp":
 509				if ($this->is_inline == 0) {
 510					Header('Content-type: image/wbmp');
 511				}
 512				if ($this->is_inline == 1 && $this->output_file != "") {
 513					ImageWBMP($this->img,$this->output_file);
 514				} else {
 515					ImageWBMP($this->img);
 516				}
 517
 518				break;
 519			default:
 520				$this->PrintError('Please select an image type!<br>');
 521				break;
 522		}
 523		ImageDestroy($this->img);
 524		return true;
 525	}
 526
 527
 528	function DrawBackground() {
 529		//if ($this->img == "") { $this->InitImage(); };
 530		if ($this->background_done == 0) { //Don't draw it twice if drawing two plots on one image
 531			ImageFilledRectangle($this->img, 0, 0,
 532				$this->image_width, $this->image_height, $this->ndx_bg_color);
 533			$this->background_done = 1;
 534		}
 535		return true;
 536	}
 537
 538	function DrawImageBorder() {
 539		switch ($this->image_border_type) {
 540			case "raised":
 541				ImageLine($this->img,0,0,$this->image_width-1,0,$this->ndx_i_light);
 542				ImageLine($this->img,1,1,$this->image_width-2,1,$this->ndx_i_light);
 543				ImageLine($this->img,0,0,0,$this->image_height-1,$this->ndx_i_light);
 544				ImageLine($this->img,1,1,1,$this->image_height-2,$this->ndx_i_light);
 545				ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
 546				ImageLine($this->img,0,$this->image_height-1,$this->image_width-1,$this->image_height-1,$this->ndx_i_dark);
 547				ImageLine($this->img,$this->image_width-2,1,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
 548				ImageLine($this->img,1,$this->image_height-2,$this->image_width-2,$this->image_height-2,$this->ndx_i_dark);
 549			break;
 550			case "plain":
 551				ImageLine($this->img,0,0,$this->image_width,0,$this->ndx_i_dark);
 552				ImageLine($this->img,$this->image_width-1,0,$this->image_width-1,$this->image_height,$this->ndx_i_dark);
 553				ImageLine($this->img,$this->image_width-1,$this->image_height-1,0,$this->image_height-1,$this->ndx_i_dark);
 554				ImageLine($this->img,0,0,0,$this->image_height,$this->ndx_i_dark);
 555			break;
 556			default:
 557			break;
 558		}
 559		return true;
 560	}
 561
 562	function SetPlotBorderType($which_pbt) {
 563		$this->plot_border_type = $which_pbt; //left, none, anything else=full
 564	}
 565
 566	function SetImageBorderType($which_sibt) {
 567		$this->image_border_type = $which_sibt; //raised, plain
 568	}
 569
 570	function SetDrawPlotAreaBackground($which_dpab) {
 571		$this->draw_plot_area_background = $which_dpab;  // 1=true or anything else=false
 572	}
 573
 574	function SetDrawDataLabels($which_ddl) {  //Draw next to datapoints
 575		$this->draw_data_labels = $which_ddl;  // 1=true or anything else=false
 576	}
 577
 578	function SetDrawXDataLabels($which_dxdl) {  //Draw on X Axis
 579		$this->draw_x_data_labels = $which_dxdl;  // 1=true or anything else=false
 580	}
 581
 582	function SetDrawYGrid($which_dyg) {
 583		$this->draw_y_grid = $which_dyg;  // 1=true or anything else=false
 584	}
 585
 586	function SetDrawXGrid($which_dxg) {
 587		$this->draw_x_grid = $which_dxg;  // 1=true or anything else=false
 588	}
 589
 590	function SetYGridLabelType($which_yglt) {
 591		$this->y_grid_label_type = $which_yglt;
 592		return true;
 593	}
 594
 595	function SetXGridLabelType($which_xglt) {
 596		$this->x_grid_label_type = $which_xglt;
 597		return true;
 598	}
 599
 600	function SetXLabel($xlbl) {
 601		$this->x_label_txt = $xlbl;
 602		return true;
 603	}
 604	function SetYLabel($ylbl) {
 605		$this->y_label_txt = $ylbl;
 606		return true;
 607	}
 608	function SetTitle($title) {
 609		$this->title_txt = $title;
 610		return true;
 611	}
 612
 613	//function SetLabels($xlbl,$ylbl,$title) {
 614	//	$this->title_txt = $title;
 615	//	$this->x_label_txt = $xlbl;
 616	//	$this->y_label_txt = $ylbl;
 617	//}
 618
 619	function DrawLabels() {
 620		$this->DrawTitle();
 621		$this->DrawXLabel();
 622		$this->DrawYLabel();
 623		return true;
 624	}
 625
 626	function DrawXLabel() {
 627		if ($this->use_ttf == 1) { 
 628			$xpos = $this->xtr(($this->plot_max_x + $this->plot_min_x)/2.0) ;
 629			$ypos = $this->ytr($this->plot_min_y) + $this->x_label_height/2.0;
 630			$this->DrawText($this->x_label_ttffont, $this->x_label_angle,
 631				$xpos, $ypos, $this->ndx_label_color, $this->x_label_ttffont_size, $this->x_label_txt,'center');
 632		} else { 
 633			//$xpos = 0.0 - (ImageFontWidth($this->small_font)*strlen($this->x_label_txt)/2.0) + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ;
 634			$xpos = 0.0 + $this->xtr(($this->plot_max_x+$this->plot_min_x)/2.0) ;
 635			$ypos = ($this->ytr($this->plot_min_y) + $this->x_label_height/2);
 636
 637			$this->DrawText($this->small_font, $this->x_label_angle, 
 638				$xpos, $ypos, $this->ndx_label_color, "", $this->x_label_txt, 'center');
 639
 640		}
 641		return true;
 642	}
 643
 644	function DrawYLabel() {
 645		if ($this->use_ttf == 1) { 
 646			$size = $this->TTFBBoxSize($this->y_label_ttffont_size, 90, $this->y_label_ttffont, $this->y_label_txt);
 647			$xpos = 8 + $size[0];
 648			$ypos = ($size[1])/2 + $this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) ;
 649			$this->DrawText($this->y_label_ttffont, 90,
 650				$xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
 651		} else { 
 652			$xpos = 8;
 653			$ypos = (($this->small_font_width*strlen($this->y_label_txt)/2.0) +
 654					$this->ytr(($this->plot_max_y + $this->plot_min_y)/2.0) );
 655			$this->DrawText($this->small_font, 90,
 656				$xpos, $ypos, $this->ndx_label_color, $this->y_label_ttffont_size, $this->y_label_txt);
 657		}
 658		return true;
 659	}
 660
 661	function DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left',$which_valign='') {
 662
 663		if ($this->use_ttf == 1 ) { 
 664			$size = $this->TTFBBoxSize($which_size, $which_angle, $which_font, $which_text); 
 665			if ($which_valign == 'bottom') { 
 666				$which_ypos = $which_ypos + ImageFontHeight($which_font);
 667			}
 668			if ($which_halign == 'center') { 
 669				$which_xpos = $which_xpos - $size[0]/2;
 670			}
 671			ImageTTFText($this->img, $which_size, $which_angle, 
 672				$which_xpos, $which_ypos, $which_color, $which_font, $which_text); 
 673		} else { 
 674			if ($which_valign == 'top') { 
 675				$which_ypos = $which_ypos - ImageFontHeight($which_font);
 676			}
 677			$which_text = ereg_replace("\r","",$which_text);
 678			$str = split("\n",$which_text); //multiple lines submitted by Remi Ricard
 679			$height = ImageFontHeight($which_font);
 680			$width = ImageFontWidth($which_font);
 681			if ($which_angle == 90) {  //Vertical Code Submitted by Marlin Viss
 682				for($i=0;$i<count($str);$i++) { 
 683					ImageStringUp($this->img, $which_font, ($i*$height + $which_xpos), $which_ypos, $str[$i], $which_color);
 684				} 
 685			} else {
 686				for($i=0;$i<count($str);$i++) { 
 687					if ($which_halign == 'center') { 
 688                    	$xpos = $which_xpos - strlen($str[$i]) * $width/2;
 689 						ImageString($this->img, $which_font, $xpos, ($i*$height + $which_ypos), $str[$i], $which_color);
 690					} else { 
 691						ImageString($this->img, $which_font, $which_xpos, ($i*$height + $which_ypos), $str[$i], $which_color); 
 692					}
 693				} 
 694			}
 695
 696		} 
 697		return true; 
 698
 699	}
 700	function DrawTitle() {
 701		if ($this->use_ttf == 1 ) { 
 702			$xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
 703			$ypos = $this->y_top_margin/2;
 704			$this->DrawText($this->title_ttffont, $this->title_angle, 
 705				$xpos, $ypos, $this->ndx_title_color, $this->title_ttffont_size, $this->title_txt,'center'); 
 706		} else { 
 707			$xpos = ($this->plot_area[0] + $this->plot_area_width / 2);
 708			$ypos = ImageFontHeight($this->title_font); 
 709			$this->DrawText($this->title_font, $this->title_angle, 
 710				$xpos, $ypos, $this->ndx_title_color, '', $this->title_txt,'center'); 
 711		} 
 712		return true; 
 713
 714	}
 715
 716	function DrawPlotAreaBackground() {
 717		ImageFilledRectangle($this->img,$this->plot_area[0],
 718			$this->plot_area[1],$this->plot_area[2],$this->plot_area[3],
 719			$this->ndx_plot_bg_color);
 720	}
 721
 722	function SetBackgroundColor($which_color) {
 723		$this->bg_color= $which_color;
 724		$this->ndx_bg_color= $this->SetIndexColor($which_color);
 725		return true;
 726	}
 727	function SetPlotBgColor($which_color) {
 728		$this->plot_bg_color= $which_color;
 729		$this->ndx_plot_bg_color= $this->SetIndexColor($which_color);
 730		return true;
 731	}
 732
 733	function SetShading($which_s) { 
 734		$this->shading = $which_s;
 735		return true;
 736	}
 737
 738	function SetTitleColor($which_color) {
 739		$this->title_color= $which_color;
 740		$this->ndx_title_color= $this->SetIndexColor($which_color);
 741		return true;
 742	}
 743
 744	function SetTickColor ($which_color) {
 745		$this->tick_color= $which_color;
 746		$this->ndx_tick_color= $this->SetIndexColor($which_color);
 747		return true;
 748	}
 749
 750	function SetLabelColor ($which_color) {
 751		$this->label_color= $which_color;
 752		$this->ndx_label_color= $this->SetIndexColor($which_color);
 753		return true;
 754	}
 755
 756	function SetTextColor ($which_color) {
 757		$this->text_color= $which_color;
 758		$this->ndx_text_color= $this->SetIndexColor($which_color);
 759		return true;
 760	}
 761
 762	function SetLightGridColor ($which_color) {
 763		$this->light_grid_color= $which_color;
 764		$this->ndx_light_grid_color= $this->SetIndexColor($which_color);
 765		return true;
 766	}
 767
 768	function SetGridColor ($which_color) {
 769		$this->grid_color = $which_color;
 770		$this->ndx_grid_color= $this->SetIndexColor($which_color);
 771		return true;
 772	}
 773
 774	function SetCharacterHeight() {
 775		//to be set
 776		return true;
 777	}
 778
 779	function SetPlotType($which_pt) {
 780		$accepted = "bars,lines,linepoints,area,points,pie,thinbarline";
 781		$asked = trim($which_pt);
 782		if (eregi($asked, $accepted)) {
 783			$this->plot_type = $which_pt;
 784			return true;
 785		} else {
 786			$this->DrawError('$which_pt not an acceptable plot type');
 787			return false;
 788		}
 789	}
 790
 791	function FindDataLimits() {
 792		//Text-Data is different than data-data graphs. For them what
 793		// we have, instead of X values, is # of records equally spaced on data.
 794		//text-data is passed in as $data[] = (title,y1,y2,y3,y4,...)
 795		//data-data is passed in as $data[] = (title,x,y1,y2,y3,y4,...) 
 796
 797		$this->number_x_points = count($this->data_values);
 798
 799		switch ($this->data_type) {
 800			case "text-data":
 801				$minx = 0; //valid for BAR TYPE GRAPHS ONLY
 802				$maxx = $this->number_x_points - 1 ;  //valid for BAR TYPE GRAPHS ONLY
 803				$miny = (double) $this->data_values[0][1];
 804				$maxy = $miny;
 805				if ($this->draw_x_data_labels == "") { 
 806					$this->draw_x_data_labels = 1;  //labels_note1: prevent both data labels and x-axis labels being both drawn and overlapping
 807				}
 808			break;
 809			default:  //Everything else: data-data, etc.
 810				$maxx = $this->data_values[0][1];
 811				$minx = $maxx;
 812				$miny = $this->data_values[0][2];
 813				$maxy = $miny;
 814				$maxy = $miny;
 815			break;
 816		}
 817
 818		$max_records_per_group = 0;
 819		$total_records = 0;
 820		$mine = 0; //Maximum value for the -error bar (assume error bars always > 0) 
 821		$maxe = 0; //Maximum value for the +error bar (assume error bars always > 0) 
 822
 823		reset($this->data_values);
 824		while (list($dat_key, $dat) = each($this->data_values)) {  //for each X barchart setting
 825		//foreach($this->data_values as $dat)  //can use foreach only in php4
 826
 827			$tmp = 0;
 828			$total_records += count($dat) - 1; // -1 for label
 829
 830			switch ($this->data_type) {
 831				case "text-data":
 832					//Find the relative Max and Min
 833
 834					while (list($key, $val) = each($dat)) {
 835						if ($key != 0) {  //$dat[0] = label
 836							SetType($val,"double");
 837							if ($val > $maxy) {
 838								$maxy = $val ;
 839							}
 840							if ($val < $miny) {
 841								$miny = (double) $val ;
 842							}
 843						}
 844						$tmp++;
 845					}
 846				break;
 847				case "data-data":  //X-Y data is passed in as $data[] = (title,x,y,y2,y3,...) which you can use for multi-dimentional plots.
 848
 849					while (list($key, $val) = each($dat)) {
 850						if ($key == 1) {  //$dat[0] = label
 851							SetType($val,"double");
 852							if ($val > $maxx) {
 853								$maxx = $val;
 854							} elseif ($val < $minx) {
 855								$minx = $val;
 856							}
 857						} elseif ($key > 1) {
 858							SetType($val,"double");
 859							if ($val > $maxy) {
 860								$maxy = $val ;
 861							} elseif ($val < $miny) {
 862								$miny = $val ;
 863							}
 864						}
 865						$tmp++;
 866					}
 867					$tmp = $tmp - 1; //# records per group
 868				break;
 869				case "data-data-error":  //Assume 2-D for now, can go higher
 870				//Regular X-Y data is passed in as $data[] = (title,x,y,error+,error-,y2,error2+,error2-)
 871
 872					while (list($key, $val) = each($dat)) {
 873						if ($key == 1) {  //$dat[0] = label
 874							SetType($val,'double');
 875							if ($val > $maxx) {
 876								$maxx = $val;
 877							} elseif ($val < $minx) {
 878								$minx = $val;
 879							}
 880						} elseif ($key%3 == 2) {
 881							SetType($val,'double');
 882							if ($val > $maxy) {
 883								$maxy = $val ;
 884							} elseif ($val < $miny) {
 885								$miny = $val ;
 886							}
 887						} elseif ($key%3 == 0) {
 888							SetType($val,'double');
 889							if ($val > $maxe) {
 890								$maxe = $val ;
 891							}
 892						} elseif ($key%3 == 1) {
 893							SetType($val,'double');
 894							if ($val > $mine) {
 895								$mine = $val ;
 896							}
 897						}
 898						$tmp++;
 899					}
 900					$maxy = $maxy + $maxe;
 901					$miny = $miny - $mine; //assume error bars are always > 0
 902
 903				break;
 904				default:
 905					$this->PrintError('ERROR: unknown chart type');
 906				break;
 907			}
 908			if ($tmp > $max_records_per_group) {
 909				$max_records_per_group = $tmp;
 910			}
 911		}
 912
 913
 914		$this->min_x = $minx;
 915		$this->max_x = $maxx;
 916		$this->min_y = $miny;
 917		$this->max_y = $maxy;
 918
 919
 920		if ($max_records_per_group > 1) {
 921			$this->records_per_group = $max_records_per_group - 1;
 922		} else {
 923			$this->records_per_group = 1;
 924		}
 925
 926
 927		//$this->data_count = $total_records ;
 928	} // function FindDataLimits
 929
 930	function SetMargins() {
 931		/////////////////////////////////////////////////////////////////
 932		// When the image is first created - set the margins
 933		// to be the standard viewport.
 934		// The standard viewport is the full area of the view surface (or panel),
 935		// less a margin of 4 character heights all round for labelling.
 936		// It thus depends on the current character size, set by SetCharacterHeight().
 937		/////////////////////////////////////////////////////////////////
 938
 939		$str = split("\n",$this->title_txt); 
 940		$nbLines = count($str); 
 941
 942		if ($this->use_ttf == 1) {
 943			$title_size = $this->TTFBBoxSize($this->title_ttffont_size, $this->title_angle, $this->title_ttffont, 'X'); //An array
 944			if ($nbLines == 1) { 
 945				$this->y_top_margin = $title_size[1] * 4;
 946			} else { 
 947				$this->y_top_margin = $title_size[1] * ($nbLines+3);
 948			}
 949
 950			//ajo working here
 951			//$x_label_size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt);
 952
 953			$this->y_bot_margin = $this->x_label_height ;
 954			$this->x_left_margin = $this->y_label_width * 2 + $this->tick_length;
 955			$this->x_right_margin = 33.0; // distance between right and end of x axis in pixels 
 956		} else {
 957			$title_size = array(ImageFontWidth($this->title_font) * strlen($this->title_txt),ImageFontHeight($this->title_font));
 958			//$this->y_top_margin = ($title_size[1] * 4);
 959			if ($nbLines == 1) { 
 960				$this->y_top_margin = $title_size[1] * 4;
 961			} else { 
 962				$this->y_top_margin = $title_size[1] * ($nbLines+3);
 963			}
 964			if ($this->x_datalabel_angle == 90) {
 965				$this->y_bot_margin = 76.0; // Must be integer
 966			} else {
 967				$this->y_bot_margin = 66.0; // Must be integer
 968			}
 969			$this->x_left_margin = 77.0; // distance between left and start of x axis in pixels
 970			$this->x_right_margin = 33.0; // distance between right and end of x axis in pixels
 971		}
 972
 973//exit;
 974		$this->x_tot_margin = $this->x_left_margin + $this->x_right_margin;
 975		$this->y_tot_margin = $this->y_top_margin + $this->y_bot_margin;
 976
 977		if ($this->plot_max_x && $this->plot_max_y && $this->plot_area_width ) { //If data has already been analysed then set translation
 978			$this->SetTranslation();
 979		}
 980	}
 981
 982	function SetMarginsPixels($which_lm,$which_rm,$which_tm,$which_bm) { 
 983		//Set the plot area using margins in pixels (left, right, top, bottom)
 984		$this->SetNewPlotAreaPixels($which_lm,$which_tm,($this->image_width - $which_rm),($this->image_height - $which_bm));
 985		return true;
 986	}
 987
 988	function SetNewPlotAreaPixels($x1,$y1,$x2,$y2) {
 989		//Like in GD 0,0 is upper left set via pixel Coordinates
 990		$this->plot_area = array($x1,$y1,$x2,$y2);
 991		$this->plot_area_width = $this->plot_area[2] - $this->plot_area[0];
 992		$this->plot_area_height = $this->plot_area[3] - $this->plot_area[1];
 993		$this->y_top_margin = $this->plot_area[1];
 994		if ($this->plot_max_x) {
 995			$this->SetTranslation();
 996		}
 997		return true;
 998	}
 999
1000	function SetPlotAreaPixels($x1,$y1,$x2,$y2) {
1001		//Like in GD 0,0 is upper left
1002		if (!$this->x_tot_margin) {
1003			$this->SetMargins();
1004		}
1005		if ($x2 && $y2) {
1006			$this->plot_area = array($x1,$y1,$x2,$y2);
1007		} else {
1008			$this->plot_area = array($this->x_left_margin, $this->y_top_margin,
1009								$this->image_width - $this->x_right_margin,
1010								$this->image_height - $this->y_bot_margin
1011							);
1012		}
1013		$this->plot_area_width = $this->plot_area[2] - $this->plot_area[0];
1014		$this->plot_area_height = $this->plot_area[3] - $this->plot_area[1];
1015
1016		return true;
1017
1018	}
1019
1020	function SetPlotAreaWorld($xmin,$ymin,$xmax,$ymax) {
1021		if (($xmin == "")  && ($xmax == "")) {
1022			//For automatic setting of data we need $this->max_x
1023				if (!$this->max_y) {
1024					$this->FindDataLimits() ;
1025				}
1026				if ($this->data_type == 'text-data') { //labels for text-data is done at data drawing time for speed.
1027					$xmax = $this->max_x + 1 ;  //valid for BAR CHART TYPE GRAPHS ONLY
1028					$xmin = 0 ; 				//valid for BAR CHART TYPE GRAPHS ONLY
1029				} else {
1030					$xmax = $this->max_x * 1.02;
1031					$xmin = $this->min_x;
1032				}
1033
1034				$ymax = ceil($this->max_y * 1.2);
1035				if ($this->min_y < 0) {
1036					$ymin = floor($this->min_y * 1.2);
1037				} else {
1038					$ymin = 0;
1039				}
1040		}
1041
1042		$this->plot_min_x = $xmin;
1043		$this->plot_max_x = $xmax;
1044
1045		if ($ymin == $ymax) {
1046			$ymax += 1;
1047		}
1048		if ($this->yscale_type == "log") { 
1049			//extra error checking
1050			if ($ymin <= 0) { 
1051				$ymin = 1;
1052			} 
1053			if ($ymax <= 0) { 
1054				$this->PrintError('Log plots need data greater than 0');
1055			}
1056		}
1057		$this->plot_min_y = $ymin;
1058		$this->plot_max_y = $ymax;
1059
1060		if ($ymax <= $ymin) {
1061			$this->DrawError('Error in Data - max not gt min');
1062		}
1063
1064//Set the boundaries of the box for plotting in world coord
1065//		if (!$this->x_tot_margin) { //We need to know the margins before we can calculate scale
1066//			$this->SetMargins();
1067//		}
1068		//For this we have to reset the scale
1069		if ($this->plot_area_width) {
1070			$this->SetTranslation();
1071		}
1072
1073		return true;
1074
1075	} //function SetPlotAreaWorld
1076
1077
1078	function PrintError($error_message) {
1079	// prints the error message to stdout and die
1080		echo "<p><b>Fatal error</b>: $error_message<p>";
1081		die;
1082	}
1083
1084	function DrawError($error_message) {
1085	// prints the error message inline into
1086	// the generated image
1087
1088		if (($this->img) == "") { $this->InitImage(); } ;
1089
1090		$ypos = $this->image_height/2;
1091
1092		if ($this->use_ttf == 1) {
1093			ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255));
1094			ImageTTFText($this->img, $this->small_ttffont_size, 0, $xpos, $ypos, ImageColorAllocate($this->img,0,0,0), $this->axis_ttffont, $error_message);
1095		} else {
1096			ImageRectangle($this->img, 0,0,$this->image_width,$this->image_height,ImageColorAllocate($this->img,255,255,255));
1097			ImageString($this->img, $this->small_font,1,$ypos,$error_message, ImageColorAllocate($this->img,0,0,0));
1098		}
1099
1100		$this->PrintImage();
1101		return true;
1102	}
1103
1104	function TTFBBoxSize($size, $angle, $font, $string) {
1105
1106		//Assume angle < 90
1107		$arr = ImageTTFBBox($size, 0, $font, $string);
1108		$flat_width  = $arr[0] - $arr[2];
1109		$flat_height = abs($arr[3] - $arr[5]);
1110
1111			// for 90deg:
1112			//	$height = $arr[5] - $arr[7];
1113			//	$width = $arr[2] - $arr[4];
1114
1115		$angle = deg2rad($angle);
1116		$width  = ceil(abs($flat_width*cos($angle) + $flat_height*sin($angle))); //Must be integer
1117		$height = ceil(abs($flat_width*sin($angle) + $flat_height*cos($angle))); //Must be integer
1118
1119		return array($width, $height);
1120	}
1121
1122	function SetXLabelHeight() {
1123
1124		if ($this->use_ttf == 1) {
1125			//Space for the X Label
1126			$size = $this->TTFBBoxSize($this->x_label_ttffont_size, 0, $this->axis_ttffont, $this->x_label_txt);
1127			$tmp = $size[1];
1128
1129			//$string = Str_Repeat('w', $this->x_datalabel_maxlength);
1130			$i = 0;
1131			$string = '';
1132			while ($i < $this->x_datalabel_maxlength) {
1133			  $string .= 'w';
1134			  $i++;
1135			}
1136
1137			//Space for the axis data labels
1138			$size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $string);
1139
1140			$this->x_label_height = 2*$tmp + $size[1] + 4;
1141
1142		} else {
1143			//For Non-TTF fonts we can have only angles 0 or 90
1144			if ($this->x_datalabel_angle == 90) {
1145				$this->x_label_height = $this->x_datalabel_maxlength * ImageFontWidth($this->small_font) / 1.5;
1146			} else {
1147				$this->x_label_height = 5 * ImageFontHeight($this->small_font);
1148			}
1149		}
1150
1151		$this->SetMargins();
1152
1153		return true;
1154	} //function SetXLabelHeight
1155
1156	function SetYLabelWidth() {
1157		//$ylab = sprintf("%6.1f %s",$i,$si_units[0]);  //use for PHP2 compatibility
1158		//the "." is for space. It isn't actually printed
1159		$ylab = number_format($this->max_y, $this->y_precision, ".", ",") . $this->si_units . ".";
1160
1161		if ($this->use_ttf == 1) {
1162			$size = $this->TTFBBoxSize($this->axis_ttffont_size, 0, $this->axis_ttffont, $ylab);
1163		} else {
1164			$size[0] = StrLen($ylab) * $this->small_font_width * .6;
1165		}
1166
1167		$this->y_label_width = $size[0] * 2;
1168//echo "SYLW: $this->y_label_width<br>";
1169//exit;
1170
1171		$this->SetMargins();
1172		return true;
1173	}
1174
1175	function SetEqualXCoord() {
1176		//for plots that have equally spaced x variables and multiple bars per x-point.
1177
1178		$space = ($this->plot_area[2] - $this->plot_area[0]) / ($this->number_x_points * 2) * $this->group_frac_width;
1179		$group_width = $space * 2;
1180		$bar_width = $group_width / $this->records_per_group;
1181  //I think that eventually this space variable will be replaced by just graphing x.
1182		$this->data_group_space = $space;
1183		$this->record_bar_width = $bar_width;
1184		return true;
1185	}
1186
1187	function SetLabelScalePosition($which_blp) {
1188		//0 to 1
1189		$this->label_scale_position = $which_blp;
1190		return true;
1191	}
1192
1193	function SetErrorBarSize($which_ebs) {
1194		//in pixels
1195		$this->error_bar_size = $which_ebs;
1196		return true;
1197	}
1198
1199	function SetErrorBarShape($which_ebs) {
1200		//in pixels
1201		$this->error_bar_shape = $which_ebs;
1202		return true;
1203	}
1204
1205	function SetPointShape($which_pt) {
1206		//in pixels
1207		$this->point_shape = $which_pt;
1208		return true;
1209	}
1210
1211	function SetPointSize($which_ps) {
1212		//in pixels
1213		SetType($which_ps,'integer');
1214		$this->point_size = $which_ps;
1215
1216		if ($this->point_shape == "diamond" or $this->point_shape == "triangle") {
1217			if ($this->point_size % 2 != 0) {
1218				$this->point_size++;
1219			}
1220		}
1221		return true;
1222	}
1223
1224	function SetDataType($which_dt) {
1225		//The next three lines are for past compatibility.
1226		if ($which_dt == "text-linear") { $which_dt = "text-data"; };
1227		if ($which_dt == "linear-linear") { $which_dt = "data-data"; };
1228		if ($which_dt == "linear-linear-error") { $which_dt = "data-data-error"; };
1229
1230		$this->data_type = $which_dt; //text-data, data-data, data-data-error
1231		return true;
1232	}
1233
1234	function SetDataValues($which_dv) {
1235		$this->data_values = $which_dv;
1236//echo $this->data_values
1237		return true;
1238	}
1239
1240//////////////COLORS
1241	function SetRGBArray ($which_color_array) { 
1242		if ( is_array($which_color_array) ) { 
1243			//User Defined Array
1244			$this->rgb_array = $which_color_array;
1245			return true;
1246		} elseif ($which_color_array == 2) { //Use the small predefined color array
1247		$this->rgb_array = array(
1248			"white"			=> array(255, 255, 255),
1249			"snow"			=> array(255, 250, 250),
1250			"PeachPuff"		=> array(255, 218, 185),
1251			"ivory"			=> array(255, 255, 240),
1252			"lavender"		=> array(230, 230, 250),
1253			"black"			=> array(  0,   0,   0),
1254			"DimGrey"			=> array(105, 105, 105),
1255			"gray"			=> array(190, 190, 190),
1256			"grey"			=> array(190, 190, 190),
1257			"navy"			=> array(  0,   0, 128),
1258			"SlateBlue"			=> array(106,  90, 205),
1259			"blue"			=> array(  0,   0, 255),
1260			"SkyBlue"			=> array(135, 206, 235),
1261			"cyan"			=> array(  0, 255, 255),
1262			"DarkGreen"			=> array(  0, 100,   0),
1263			"green"			=> array(  0, 255,   0),
1264			"YellowGreen"			=> array(154, 205,  50),
1265			"yellow"			=> array(255, 255,   0),
1266			"orange"			=> array(255, 165,   0),
1267			"gold"			=> array(255, 215,   0),
1268			"peru"			=> array(205, 133,  63),
1269			"beige"			=> array(245, 245, 220),
1270			"wheat"			=> array(245, 222, 179),
1271			"tan"			=> array(210, 180, 140),
1272			"brown"			=> array(165,  42,  42),
1273			"salmon"			=> array(250, 128, 114),
1274			"red"			=> array(255,   0,   0),
1275			"pink"			=> array(255, 192, 203),
1276			"maroon"			=> array(176,  48,  96),
1277			"magenta"			=> array(255,   0, 255),
1278			"violet"			=> array(238, 130, 238),
1279			"plum"			=> array(221, 160, 221),
1280			"orchid"			=> array(218, 112, 214),
1281			"purple"			=> array(160,  32, 240),
1282			"azure1"			=> array(240, 255, 255),
1283			"aquamarine1"		=> array(127, 255, 212)
1284			);
1285			return true;
1286		} elseif ($which_color_array == 1)  { 
1287			include("./rgb.inc.php"); //Get large $ColorArray
1288			$this->rgb_array = $RGBArray;
1289		} else { 
1290			$this->rgb_array = array("white" =>array(255,255,255), "black" => array(0,0,0));
1291			exit;
1292		}
1293
1294		return true;
1295	}
1296
1297	function SetColor($which_color) { 
1298		//obsoleted by SetRGBColor
1299		SetRgbColor($which_color);
1300		return true;
1301	}
1302
1303	function SetIndexColor($which_color) { //Color is passed in as anything
1304  		list ($r, $g, $b) = $this->SetRgbColor($which_color);  //Translate to RGB
1305		$index = ImageColorExact($this->img, $r, $g, $b);
1306		if ($index == -1) {
1307	  			//return ImageColorAllocate($this->img, $r, $g, $b);
1308	  			//return ImageColorClosest($this->img, $r, $g, $b);
1309	  			return ImageColorResolve($this->img, $r, $g, $b); //requires PHP 3.0.2 and later
1310 		} else {
1311	  			return $index;
1312  		}
1313	}
1314	
1315	function SetTransparentColor($which_color) { 
1316		ImageColorTransparent($this->img,$this->SetIndexColor($which_color));
1317		return true;
1318	}
1319
1320	function SetRgbColor($color_asked) {
1321		//Returns an array in R,G,B format 0-255
1322		if ($color_asked == "") { $color_asked = array(0,0,0); };
1323
1324		if ( count($color_asked) == 3 ) { //already array of 3 rgb
1325	   		$ret_val =  $color_asked;
1326		} else { // is asking for a color by string
1327			if(substr($color_asked,0,1) == "#") {  //asking in #FFFFFF format. 
1328				$ret_val =  array(hexdec(substr($color_asked,1,2)), hexdec(substr($color_asked,3,2)), hexdec(substr($color,5,2)));
1329			} else { 
1330				$ret_val =  $this->rgb_array[$color_asked];
1331			}
1332		}
1333		return $ret_val;
1334	}
1335
1336	function SetDataColors($which_data,$which_border) {
1337		//Set the data to be displayed in a particular color
1338		if (!$which_data) {
1339			$which_data = array(array(0,255,0),array(0,0,248),'yellow',array(255,0,0),'orange');
1340			$which_border = array('black');
1341		}
1342
1343		$this->data_color = $which_data;  //an array
1344		$this->data_border_color = $which_border;  //an array
1345
1346		unset($this->ndx_data_color);
1347		reset($this->data_color);  //data_color can be an array of colors, one for each thing plotted
1348		//while (list(, $col) = each($this->data_color)) 
1349		$i = 0;
1350		while (list(, $col) = each($which_data)) {
1351			$this->ndx_data_color[$i] = $this->SetIndexColor($col);
1352			$i++;
1353		}
1354
1355		// border_color
1356		//If we are also going to put a border on the data (bars, dots, area, ...)
1357		//	then lets also set a border color as well.
1358		//foreach($this->data_border_color as $col) 
1359		unset($this->ndx_data_border_color);
1360		reset($this->data_border_color);
1361		$i = 0;
1362		while (list(, $col) = each($this->data_border_color)) {
1363			$this->ndx_data_border_color[$i] = $this->SetIndexColor($col);
1364			$i++;
1365		}
1366
1367		//Set color of the error bars to be that of data if not already set. 
1368		if (!$this->error_bar_color) { 
1369				reset($which_data);
1370				$this->SetErrorBarColors($which_data);
1371		}
1372
1373		return true;
1374
1375	} //function SetDataColors
1376
1377	function SetErrorBarColors($which_data) {
1378
1379	 //Set the data to be displayed in a particular color
1380
1381	 if ($which_data) {
1382		$this->error_bar_color = $which_data;  //an array
1383		unset($this->ndx_error_bar_color);
1384		reset($this->error_bar_color);  //data_color can be an array of colors, one for each thing plotted
1385		$i = 0;
1386		while (list(, $col) = each($this->error_bar_color)) {
1387			$this->ndx_error_bar_color[$i] = $this->SetIndexColor($col);
1388			$i++;
1389		}
1390		return true;
1391	  }
1392	  return false;
1393	} //function SetErrorBarColors
1394
1395
1396	function DrawPlotBorder() {
1397		switch ($this->plot_border_type) {
1398			case "left" :
1399				ImageLine($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y),
1400					$this->plot_area[0],$this->ytr($this->plot_max_y),$this->ndx_grid_color);
1401			break;
1402			case "none":
1403				//Draw No Border
1404			break;
1405			default:
1406				ImageRectangle($this->img, $this->plot_area[0],$this->ytr($this->plot_min_y),
1407					$this->plot_area[2],$this->ytr($this->plot_max_y),$this->ndx_grid_color);
1408			break;
1409		}
1410		$this->DrawYAxis();
1411		$this->DrawXAxis();
1412		return true;
1413	}
1414
1415
1416	function SetHorizTickIncrement($which_ti) {
1417		//Use either this or NumHorizTicks to set where to place x tick marks
1418		if ($which_ti) {
1419			$this->horiz_tick_increment = $which_ti;  //world coordinates
1420		} else {
1421			if (!$this->max_x) {
1422				$this->FindDataLimits();  //Get maxima and minima for scaling
1423			}
1424			//$this->horiz_tick_increment = ( ceil($this->max_x * 1.2) - floor($this->min_x * 1.2) )/10;
1425			$this->horiz_tick_increment =  ($this->plot_max_x  - $this->plot_min_x  )/10;
1426		}
1427		$this->num_horiz_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both
1428		return true;
1429	}
1430
1431	function SetDrawVertTicks($which_dvt) {
1432		$this->draw_vert_ticks = $which_dvt;
1433		return true;
1434	} 
1435
1436	function SetVertTickIncrement($which_ti) {
1437		//Use either this or NumVertTicks to set where to place y tick marks
1438		if ($which_ti) {
1439			$this->vert_tick_increment = $which_ti;  //world coordinates
1440		} else {
1441			if (!$this->max_y) {
1442				$this->FindDataLimits();  //Get maxima and minima for scaling
1443			}
1444			//$this->vert_tick_increment = ( ceil($this->max_y * 1.2) - floor($this->min_y * 1.2) )/10;
1445			$this->vert_tick_increment =  ($this->plot_max_y  - $this->plot_min_y  )/10;
1446		}
1447		$this->num_vert_ticks = ''; //either use num_vert_ticks or vert_tick_increment, not both
1448		return true;
1449	}
1450
1451	function SetNumHorizTicks($which_nt) {
1452		$this->num_horiz_ticks = $which_nt;
1453		$this->horiz_tick_increment = '';  //either use num_horiz_ticks or horiz_tick_increment, not both
1454		return true;
1455	}
1456
1457	function SetNumVertTicks($which_nt) {
1458		$this->num_vert_ticks = $which_nt;
1459		$this->vert_tick_increment = '';  //either use num_vert_ticks or vert_tick_increment, not both
1460		return true;
1461	}
1462	function SetVertTickPosition($which_tp) {
1463		$this->vert_tick_position = $which_tp; //plotleft, plotright, both, yaxis
1464		return true;
1465	}
1466	function SetSkipBottomTick($which_sbt) {
1467		$this->skip_bottom_tick = $which_sbt;
1468		return true;
1469	}
1470
1471	function SetTickLength($which_tl) {
1472		$this->tick_length = $which_tl;
1473		return true;
1474	}
1475
1476	function DrawYAxis() { 
1477		//Draw Line at left side or at this->y_axis_position
1478		if ($this->y_axis_position != "") { 
1479			$yaxis_x = $this->xtr($this->y_axis_position);
1480		} else { 
1481			$yaxis_x = $this->plot_area[0];
1482		}
1483
1484		ImageLine($this->img, $yaxis_x, $this->plot_area[1], 
1485			$yaxis_x, $this->plot_area[3], $this->ndx_grid_color);
1486			//$yaxis_x, $this->plot_area[3], 9);
1487
1488		if ($this->draw_vert_ticks == 1) { 
1489			$this->DrawVerticalTicks();
1490		}
1491
1492	} //function DrawYAxis
1493
1494	function DrawXAxis() {
1495		//Draw Tick and Label for Y axis
1496		$ylab =$this->FormatYTickLabel($this->x_axis_position);
1497		if ($this->skip_bottom_tick != 1) { 
1498			$this->DrawVerticalTick($ylab,$this->x_axis_position);
1499		}
1500
1501		//Draw X Axis at Y=$x_axis_postion
1502		ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->x_axis_position),
1503				$this->xtr($this->plot_max_x)-1,$this->ytr($this->x_axis_position),$this->ndx_tick_color);
1504
1505		//X Ticks and Labels
1506		if ($this->data_type != 'text-data') { //labels for text-data done at data drawing time for speed.
1507			$this->DrawHorizontalTicks();
1508		}
1509		return true;
1510	}
1511
1512	function DrawHorizontalTicks() {
1513		//Ticks and lables are drawn on the left border of PlotArea.
1514		//Left Bottom
1515		ImageLine($this->img,$this->plot_area[0],
1516				$this->plot_area[3]+$this->tick_length,
1517				$this->plot_area[0],$this->plot_area[3],$this->ndx_tick_color);
1518
1519		switch ($this->x_grid_label_type) {
1520			case "title":
1521				$xlab = $this->data_values[0][0];
1522			break;
1523			case "data":
1524				$xlab = number_format($this->plot_min_x,$this->x_precision,".",",") . "$this->si_units";
1525			break;
1526			case "none":
1527				$xlab = '';
1528			break;
1529			case "time":  //Time formatting suggested by Marlin Viss
1530				$xlab = strftime($this->x_time_format,$this->plot_min_x);
1531			break;
1532			default:
1533				//Unchanged from whatever format is passed in
1534				$xlab = $this->plot_min_x;
1535			break;
1536		}
1537
1538		if ($this->x_datalabel_angle == 90) { 
1539			$xpos =  $this->plot_area[0] - $this->small_font_height/2;
1540			$ypos = ( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height);
1541			ImageStringUp($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color);
1542		} else {
1543			$xpos = $this->plot_area[0] - $this->small_font_width*strlen($xlab)/2 ;
1544			$ypos = $this->plot_area[3] + $this->small_font_height;
1545			ImageString($this->img, $this->small_font,$xpos, $ypos, $xlab, $this->ndx_text_color);
1546		}
1547
1548		//Will be changed to allow for TTF fonts in data as well.
1549		//$this->DrawText($this->small_font, $this->x_datalabel_angle, $xpos, $ypos, $this->ndx_title_color, '', $xlab); 
1550
1551		//Top
1552
1553		if ($this->horiz_tick_increment) {
1554			$delta_x = $this->horiz_tick_increment;
1555		} elseif ($this->num_horiz_ticks) {
1556			$delta_x = ($this->plot_max_x - $this->plot_min_x) / $this->num_horiz_ticks;
1557		} else {
1558			$delta_x =($this->plot_max_x - $this->plot_min_x) / 10 ;
1559		}
1560
1561		$i = 0;
1562		$x_tmp = $this->plot_min_x;
1563		SetType($x_tmp,'double');
1564
1565		while ($x_tmp <= $this->plot_max_x){
1566			//$xlab = sprintf("%6.1f %s",$min_x,$si_units[0]);  //PHP2 past compatibility
1567			switch ($this->x_grid_label_type) {
1568				case "title":
1569					$xlab = $this->data_values[$x_tmp][0];
1570				break;
1571				case "data":
1572					$xlab = number_format($x_tmp,$this->x_precision,".",",") . "$this->si_units";
1573				break;
1574				case "none":
1575					$xlab = '';
1576				break;
1577				case "time":  //Time formatting suggested by Marlin Viss
1578					$xlab = strftime($this->x_time_format,$x_tmp);
1579				break;
1580				default:
1581					//Unchanged from whatever format is passed in
1582					$xlab = $x_tmp;
1583				break;
1584			}
1585
1586			$x_pixels = $this->xtr($x_tmp);
1587
1588			//Bottom Tick
1589			ImageLine($this->img,$x_pixels,$this->plot_area[3] + $this->tick_length,
1590				$x_pixels,$this->plot_area[3], $this->ndx_tick_color);
1591			//Top Tick
1592			//ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
1593			//	$y_pixels,$this->xtr($this->plot_max_x)-1,$y_pixels,$this->ndx_tick_color);
1594
1595			if ($this->draw_x_grid == 1) {
1596				ImageLine($this->img,$x_pixels,$this->plot_area[1],
1597					$x_pixels,$this->plot_area[3], $this->ndx_light_grid_color);
1598			}
1599
1600			if ($this->x_datalabel_angle == 90) {  //Vertical Code Submitted by Marlin Viss
1601 			   ImageStringUp($this->img, $this->small_font,
1602				( $x_pixels - $this->small_font_height/2),
1603				( $this->small_font_width*strlen($xlab) + $this->plot_area[3] + $this->small_font_height),$xlab, $this->ndx_text_color);
1604			} else {
1605				ImageString($this->img, $this->small_font,
1606					( $x_pixels - $this->small_font_width*strlen($xlab)/2) ,
1607					( $this->small_font_height + $this->plot_area[3]),$xlab, $this->ndx_text_color);
1608			

Large files files are truncated, but you can click here to view the full file