PageRenderTime 30ms CodeModel.GetById 34ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, LGPL-2.1

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

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