PageRenderTime 65ms CodeModel.GetById 19ms 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
  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);
  1383. }
  1384. $i++;
  1385. $x_tmp += $delta_x;
  1386. }
  1387. } // function DrawHorizontalTicks
  1388. function FormatYTickLabel($which_ylab) {
  1389. switch ($this->y_grid_label_type) {
  1390. case "data":
  1391. $ylab = number_format($which_ylab,$this->y_precision,".",",") . "$this->si_units";
  1392. break;
  1393. case "none":
  1394. $ylab = '';
  1395. break;
  1396. case "time":
  1397. $ylab = strftime($this->y_time_format,$which_ylab);
  1398. break;
  1399. case "right":
  1400. //Make it right aligned
  1401. //$ylab = str_pad($which_ylab,$this->y_label_width," ",STR_PAD_LEFT); //PHP4 only
  1402. $sstr = "%".strlen($this->plot_max_y)."s";
  1403. $ylab = sprintf($sstr,$which_ylab);
  1404. break;
  1405. default:
  1406. //Unchanged from whatever format is passed in
  1407. $ylab = $which_ylab;
  1408. break;
  1409. }
  1410. return($ylab);
  1411. } //function FormatYTickLabel
  1412. function DrawVerticalTick($which_ylab,$which_ypos) { //ylab in world coord.
  1413. //Draw Just one Tick, called from DrawVerticalTicks
  1414. //Ticks and datalables can be left of plot only, right of plot only,
  1415. // both on the left and right of plot, or crossing a user defined Y-axis
  1416. //
  1417. //Its faster to draw both left and right ticks at same time
  1418. // than first left and then right.
  1419. if ($this->y_axis_position != "") {
  1420. //Ticks and lables are drawn on the left border of yaxis
  1421. $yaxis_x = $this->xtr($this->y_axis_position);
  1422. } else {
  1423. //Ticks and lables are drawn on the left border of PlotArea.
  1424. $yaxis_x = $this->plot_area[0];
  1425. }
  1426. $y_pixels = $this->ytr($which_ypos);
  1427. //Lines Across the Plot Area
  1428. if ($this->draw_y_grid == 1) {
  1429. ImageLine($this->img,$this->plot_area[0]+1,$y_pixels,
  1430. $this->plot_area[2]-1,$y_pixels,$this->ndx_light_grid_color);
  1431. }
  1432. //Ticks to the Left of the Plot Area
  1433. if (($this->vert_tick_position == "plotleft") || ($this->vert_tick_position == "both") ) {
  1434. ImageLine($this->img,(-$this->tick_length+$yaxis_x),
  1435. $y_pixels,$yaxis_x,
  1436. $y_pixels, $this->ndx_tick_color);
  1437. }
  1438. //Ticks to the Right of the Plot Area
  1439. if (($this->vert_tick_position == "plotright") || ($this->vert_tick_position == "both") ) {
  1440. ImageLine($this->img,($this->plot_area[2]+$this->tick_length),
  1441. $y_pixels,$this->plot_area[2],
  1442. $y_pixels,$this->ndx_tick_color);
  1443. }
  1444. //Ticks on the Y Axis
  1445. if (($this->vert_tick_position == "yaxis") ) {
  1446. ImageLine($this->img,($yaxis_x - $this->tick_length),
  1447. $y_pixels,$yaxis_x,$y_pixels,$this->ndx_tick_color);
  1448. }
  1449. //DataLabel
  1450. //ajo working
  1451. //$this->DrawText($this->y_label_ttffont, 0,($yaxis_x - $this->y_label_width - $this->tick_length/2),
  1452. // $y_pixels, $this->ndx_text_color, $this->axis_ttffont_size, $which_ylab);
  1453. ImageString($this->img, $this->small_font, ($yaxis_x - $this->y_label_width - $this->tick_length/2),
  1454. ( -($this->small_font_height/2.0) + $y_pixels),$which_ylab, $this->ndx_text_color);
  1455. }
  1456. function DrawVerticalTicks() {
  1457. if ($this->skip_top_tick != 1) { //If tick increment doesn't hit the top
  1458. //Left Top
  1459. //ImageLine($this->img,(-$this->tick_length+$this->xtr($this->plot_min_x)),
  1460. // $this->ytr($this->plot_max_y),$this->xtr($this->plot_min_x),$this->ytr($this->plot_max_y),$this->ndx_tick_color);
  1461. //$ylab = $this->FormatYTickLabel($plot_max_y);
  1462. //Right Top
  1463. //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
  1464. // $this->ytr($this->plot_max_y),$this->xtr($this->plot_max_x-1),$this->ytr($this->plot_max_y),$this->ndx_tick_color);
  1465. //Draw Grid Line at Top
  1466. ImageLine($this->img,$this->plot_area[0]+1,$this->ytr($this->plot_max_y),
  1467. $this->plot_area[2]-1,$this->ytr($this->plot_max_y),$this->ndx_light_grid_color);
  1468. }
  1469. if ($this->skip_bottom_tick != 1) {
  1470. //Right Bottom
  1471. //ImageLine($this->img,($this->xtr($this->plot_max_x)+$this->tick_length),
  1472. // $this->ytr($this->plot_min_y),$this->xtr($this->plot_max_x),
  1473. // $this->ytr($this->plot_min_y),$this->ndx_tick_color);
  1474. //Draw Grid Line at Bottom of Plot
  1475. ImageLine($this->img,$this->xtr($this->plot_min_x)+1,$this->ytr($this->plot_min_y),
  1476. $this->xtr($this->plot_max_x),$this->ytr($this->plot_min_y),$this->ndx_light_grid_color);
  1477. }
  1478. // maxy is always > miny so delta_y is always positive
  1479. if ($this->vert_tick_increment) {
  1480. $delta_y = $this->vert_tick_increment;
  1481. } elseif ($this->num_vert_ticks) {
  1482. $delta_y = ($this->plot_max_y - $this->plot_min_y) / $this->num_vert_ticks;
  1483. } else {
  1484. $delta_y =($this->plot_max_y - $this->plot_min_y) / 10 ;
  1485. }
  1486. $y_tmp = $this->plot_min_y;
  1487. SetType($y_tmp,'double');
  1488. if ($this->skip_bottom_tick == 1) {
  1489. $y_tmp += $delta_y;
  1490. }
  1491. while ($y_tmp <= $this->plot_max_y){
  1492. //For log plots:
  1493. if (($this->yscale_type == "log") && ($this->plot_min_y == 1) &&
  1494. ($delta_y%10 == 0) && ($y_tmp == $this->plot_min_y)) {
  1495. $y_tmp = $y_tmp - 1; //Set first increment to 9 to get: 1,10,20,30,...
  1496. }
  1497. $ylab = $this->FormatYTickLabel($y_tmp);
  1498. $this->DrawVerticalTick($ylab,$y_tmp);
  1499. $y_tmp += $delta_y;
  1500. }
  1501. return true;
  1502. } // function DrawVerticalTicks
  1503. function SetTranslation() {
  1504. if ($this->xscale_type == "log") {
  1505. $this->xscale = ($this->plot_area_width)/(log10($this->plot_max_x) - log10($this->plot_min_x));
  1506. } else {
  1507. $this->xscale = ($this->plot_area_width)/($this->plot_max_x - $this->plot_min_x);
  1508. }
  1509. if ($this->yscale_type == "log") {
  1510. $this->yscale = ($this->plot_area_height)/(log10($this->plot_max_y) - log10($this->plot_min_y));
  1511. } else {
  1512. $this->yscale = ($this->plot_area_height)/($this->plot_max_y - $this->plot_min_y);
  1513. }
  1514. // GD defines x=0 at left and y=0 at TOP so -/+ respectively
  1515. if ($this->xscale_type == "log") {
  1516. $this->plot_origin_x = $this->plot_area[0] - ($this->xscale * log10($this->plot_min_x) );
  1517. } else {
  1518. $this->plot_origin_x = $this->plot_area[0] - ($this->xscale * $this->plot_min_x);
  1519. }
  1520. if ($this->yscale_type == "log") {
  1521. $this->plot_origin_y = $this->plot_area[3] + ($this->yscale * log10($this->plot_min_y));
  1522. } else {
  1523. $this->plot_origin_y = $this->plot_area[3] + ($this->yscale * $this->plot_min_y);
  1524. }
  1525. $this->scale_is_set = 1;
  1526. } // function SetTranslation
  1527. function xtr($x_world) {
  1528. //Translate world coordinates into pixel coordinates
  1529. //The pixel coordinates are those of the ENTIRE image, not just the plot_area
  1530. //$x_pixels = $this->x_left_margin + ($this->image_width - $this->x_tot_margin)*(($x_world - $this->plot_min_x) / ($this->plot_max_x - $this->plot_min_x)) ;
  1531. //which with a little bit of math reduces to ...
  1532. if ($this->xscale_type == "log") {
  1533. $x_pixels = $this->plot_origin_x + log10($x_world) * $this->xscale ;
  1534. } else {
  1535. $x_pixels = $this->plot_origin_x + $x_world * $this->xscale ;
  1536. }
  1537. return($x_pixels);
  1538. }
  1539. function ytr($y_world) {
  1540. // translate y world coord into pixel coord
  1541. if ($this->yscale_type == "log") {
  1542. $y_pixels = $this->plot_origin_y - log10($y_world) * $this->yscale ; //minus because GD defines y=0 at top. doh!
  1543. } else {
  1544. $y_pixels = $this->plot_origin_y - $y_world * $this->yscale ;
  1545. }
  1546. return ($y_pixels);
  1547. }
  1548. function DrawDataLabel($lab,$x_world,$y_world) {
  1549. //Depreciated. Use DrawText Instead.
  1550. //Data comes in in WORLD coordinates
  1551. //Draw data label near actual data point
  1552. //$y = $this->ytr($y_world) ; //in pixels
  1553. //$x = $this->xtr($x_world) ;
  1554. //$this->DrawText($which_font,$which_angle,$which_xpos,$which_ypos,$which_color,$which_size,$which_text,$which_halign='left');
  1555. if ($this->use_ttf) {
  1556. //ajjjo
  1557. $lab_size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $lab); //An array
  1558. $y = $this->ytr($y_world) - $lab_size[1] ; //in pixels
  1559. $x = $this->xtr($x_world) - $lab_size[0]/2;
  1560. ImageTTFText($this->img, $this->axis_ttffont_size, $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $lab);
  1561. } else {
  1562. $lab_size = array($this->small_font_width*StrLen($lab), $this->small_font_height*3);
  1563. if ($this->x_datalabel_angle == 90) {
  1564. $y = $this->ytr($y_world) - $this->small_font_width*StrLen($lab); //in pixels
  1565. $x = $this->xtr($x_world) - $this->small_font_height;
  1566. ImageStringUp($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
  1567. } else {
  1568. $y = $this->ytr($y_world) - $this->small_font_height; //in pixels
  1569. $x = $this->xtr($x_world) - ($this->small_font_width*StrLen($lab))/2;
  1570. ImageString($this->img, $this->small_font,$x, $y ,$lab, $this->ndx_text_color);
  1571. }
  1572. }
  1573. }
  1574. function DrawXDataLabel($xlab,$xpos) {
  1575. //xpos comes in in PIXELS not in world coordinates.
  1576. //Draw an x data label centered at xlab
  1577. if ($this->use_ttf) {
  1578. $xlab_size = $this->TTFBBoxSize($this->axis_ttffont_size,
  1579. $this->x_datalabel_angle, $this->axis_ttffont, $xlab); //An array
  1580. $y = $this->plot_area[3] + $xlab_size[1] + 4; //in pixels
  1581. $x = $xpos - $xlab_size[0]/2;
  1582. ImageTTFText($this->img, $this->axis_ttffont_size,
  1583. $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $xlab);
  1584. } else {
  1585. $xlab_size = array(ImageFontWidth($this->axis_font)*StrLen($xlab), $this->small_font_height*3);
  1586. if ($this->x_datalabel_angle == 90) {
  1587. $y = $this->plot_area[3] + ImageFontWidth($this->axis_font)*StrLen($xlab); //in pixels
  1588. $x = $xpos - ($this->small_font_height);
  1589. ImageStringUp($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
  1590. } else {
  1591. $y = $this->plot_area[3] + ImageFontHeight($this->axis_font); //in pixels
  1592. $x = $xpos - (ImageFontWidth($this->axis_font)*StrLen($xlab))/2;
  1593. ImageString($this->img, $this->axis_font,$x, $y ,$xlab, $this->ndx_text_color);
  1594. }
  1595. }
  1596. }
  1597. function DrawPieChart() {
  1598. //$pi = '3.14159265358979323846';
  1599. $xpos = $this->plot_area[0] + $this->plot_area_width/2;
  1600. $ypos = $this->plot_area[1] + $this->plot_area_height/2;
  1601. $diameter = (min($this->plot_area_width, $this->plot_area_height)) ;
  1602. $radius = $diameter/2;
  1603. ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
  1604. $total = 0;
  1605. reset($this->data_values);
  1606. $tmp = $this->number_x_points - 1;
  1607. while (list($j, $row) = each($this->data_values)) {
  1608. //Get sum of each type
  1609. $color_index = 0;
  1610. $i = 0;
  1611. //foreach ($row as $v)
  1612. while (list($k, $v) = each($row)) {
  1613. if ($k != 0) {
  1614. if ($j == 0) {
  1615. $sumarr[$i] = $v;
  1616. } elseif ($j < $tmp) {
  1617. $sumarr[$i] += $v;
  1618. } else {
  1619. $sumarr[$i] += $v;
  1620. // NOTE! sum > 0 to make pie charts
  1621. $sumarr[$i] = abs($sumarr[$i]);
  1622. $total += $sumarr[$i];
  1623. }
  1624. }
  1625. $i++;
  1626. }
  1627. }
  1628. $color_index = 0;
  1629. $start_angle = 0;
  1630. reset($sumarr);
  1631. $end_angle = 0;
  1632. while (list(, $val) = each($sumarr)) {
  1633. if ($color_index >= count($this->ndx_data_color)) $color_index=0; //data_color = array
  1634. $label_txt = number_format(($val / $total * 100), $this->y_precision, ".", ",") . "%";
  1635. $val = 360 * ($val / $total);
  1636. $end_angle += $val;
  1637. $mid_angle = $end_angle - ($val / 2);
  1638. $slicecol = $this->ndx_data_color[$color_index];
  1639. //Need this again for FillToBorder
  1640. ImageArc($this->img, $xpos, $ypos, $diameter, $diameter, 0, 360, $this->ndx_grid_color);
  1641. $out_x = $radius * cos(deg2rad($end_angle));
  1642. $out_y = - $radius * sin(deg2rad($end_angle));
  1643. $mid_x = $xpos + ($radius/2 * cos(deg2rad($mid_angle))) ;
  1644. $mid_y = $ypos + (- $radius/2 * sin(deg2rad($mid_angle)));
  1645. $label_x = $xpos + ($radius * cos(deg2rad($mid_angle))) * $this->label_scale_position;
  1646. $label_y = $ypos + (- $radius * sin(deg2rad($mid_angle))) * $this->label_scale_position;
  1647. $out_x = $xpos + $out_x;
  1648. $out_y = $ypos + $out_y;
  1649. ImageLine($this->img, $xpos, $ypos, $out_x, $out_y, $this->ndx_grid_color);
  1650. //ImageLine($this->img, $xpos, $ypos, $label_x, $label_y, $this->ndx_grid_color);
  1651. ImageFillToBorder($this->img, $mid_x, $mid_y, $this->ndx_grid_color, $slicecol);
  1652. if ($this->use_ttf) {
  1653. ImageTTFText($this->img, $this->axis_ttffont_size, 0, $label_x, $label_y, $this->ndx_grid_color, $this->axis_ttffont, $label_txt);
  1654. } else {
  1655. ImageString($this->img, $this->small_font, $label_x, $label_y, $label_txt, $this->ndx_grid_color);
  1656. }
  1657. $start_angle = $val;
  1658. $color_index++;
  1659. }
  1660. }
  1661. function DrawLinesError() {
  1662. //Draw Lines with Error Bars - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...);
  1663. $start_lines = 0;
  1664. reset($this->data_values);
  1665. while (list(, $row) = each($this->data_values)) {
  1666. $color_index = 0;
  1667. $i = 0;
  1668. while (list($key, $val) = each($row)) {
  1669. //echo "$key, $i, $val<br>";
  1670. if ($key == 0) {
  1671. $lab = $val;
  1672. } elseif ($key == 1) {
  1673. $x_now = $val;
  1674. $x_now_pixels = $this->xtr($x_now); //Use a bit more memory to save 2N operations.
  1675. } elseif ($key%3 == 2) {
  1676. $y_now = $val;
  1677. $y_now_pixels = $this->ytr($y_now);
  1678. //Draw Data Label
  1679. if ( $this->draw_data_labels == 1) {
  1680. $this->DrawDataLabel($lab,$x_now,$y_now);
  1681. }
  1682. if ($color_index >= count($this->ndx_data_color)) { $color_index=0;};
  1683. $barcol = $this->ndx_data_color[$color_index];
  1684. $error_barcol = $this->ndx_error_bar_color[$color_index];
  1685. //echo "start = $start_lines<br>";
  1686. if ($start_lines == 1) {
  1687. for ($width = 0; $width < $this->line_width; $width++) {
  1688. ImageLine($this->img, $x_now_pixels, $y_now_pixels + $width,
  1689. $lastx[$i], $lasty[$i] + $width, $barcol);
  1690. }
  1691. }
  1692. $lastx[$i] = $x_now_pixels;
  1693. $lasty[$i] = $y_now_pixels;
  1694. $color_index++;
  1695. $i++;
  1696. $start_lines = 1;
  1697. } elseif ($key%3 == 0) {
  1698. $this->DrawYErrorBar($x_now,$y_now,$val,$this->error_bar_shape,$error_barcol);
  1699. } elseif ($key%3 == 1) {
  1700. $this->DrawYErrorBar($x_now,$y_now,-$val,$this->error_bar_shape,$error_barcol);
  1701. }
  1702. }
  1703. }
  1704. }
  1705. function DrawDotsError() {
  1706. //Draw Dots - data comes in as array("title",x,y,error+,error-,y2,error2+,error2-,...);
  1707. reset($this->data_values);
  1708. while (list(, $row) = each($this->data_values)) {
  1709. $color_index = 0;
  1710. //foreach ($row as $v)
  1711. while (list($key, $val) = each($row)) {
  1712. if ($key == 0) {
  1713. } elseif ($key == 1) {
  1714. $xpos = $val;
  1715. } elseif ($key%3 == 2) {
  1716. if ($color_index >= count($this->ndx_data_color)) $color_index=0;
  1717. $barcol = $this->ndx_data_color[$color_index];
  1718. $error_barcol = $this->ndx_error_bar_color[$color_index];
  1719. $ypos = $val;
  1720. $color_index++;
  1721. $this->DrawDot($xpos,$ypos,$this->point_shape,$barcol);
  1722. } elseif ($key%3 == 0) {
  1723. $this->DrawYErrorBar($xpos,$ypos,$val,$this->error_bar_shape,$error_barcol);
  1724. } elseif ($key%3 == 1) {
  1725. $mine = $val ;
  1726. $this->DrawYErrorBar($xpos,$ypos,-$val,$this->error_bar_shape,$error_barcol);
  1727. }
  1728. }
  1729. }
  1730. }
  1731. function DrawDots() {
  1732. //Draw Dots - data comes in as array("title",x,y1,y2,y3,...);
  1733. reset($this->data_values);
  1734. while (list($j, $row) = each($this->data_values)) {
  1735. $color_index = 0;
  1736. //foreach ($row as $v)
  1737. while (list($k, $v) = each($row)) {
  1738. if ($k == 0) {
  1739. } elseif (($k == 1) && ($this->data_type == "data-data")) {
  1740. $xpos = $v;
  1741. } else {
  1742. if ($this->data_type == "text-data") {
  1743. $xpos = ($j+.5);
  1744. }
  1745. if ($color_index >= count($this->ndx_data_color)) $color_index=0;
  1746. $barcol = $this->ndx_data_color[$color_index];
  1747. //if (is_numeric($v)) //PHP4 only
  1748. if ((strval($v) != "") ) { //Allow for missing Y data
  1749. $this->DrawDot($xpos,$v,$this->point_shape,$barcol);
  1750. }
  1751. $color_index++;
  1752. }
  1753. }
  1754. }
  1755. } //function DrawDots
  1756. function DrawDotSeries() {
  1757. //Depreciated: Use DrawDots
  1758. $this->DrawDots();
  1759. }
  1760. function DrawThinBarLines() {
  1761. //A clean,fast routine for when you just want charts like stock volume charts
  1762. //Data must be text-data since I didn't see a graphing need for equally spaced thin lines.
  1763. //If you want it - then write to afan@jeo.net and I might add it.
  1764. if ($this->data_type != "data-data") { $this->DrawError('Data Type for ThinBarLines must be data-data'); };
  1765. $y1 = $this->ytr($this->x_axis_position);
  1766. reset($this->data_values);
  1767. while (list(, $row) = each($this->data_values)) {
  1768. $color_index = 0;
  1769. while (list($k, $v) = each($row)) {
  1770. if ($k == 0) {
  1771. $xlab = $v;
  1772. } elseif ($k == 1) {
  1773. $xpos = $this->xtr($v);
  1774. if ( ($this->draw_x_data_labels == 1) ) { //See "labels_note1 above.
  1775. $this->DrawXDataLabel($xlab,$xpos);
  1776. }
  1777. } else {
  1778. if ($color_index >= count($this->ndx_data_color)) $color_index=0;
  1779. $barcol = $this->ndx_data_color[$color_index];
  1780. ImageLine($this->img,$xpos,$y1,$xpos,$this->ytr($v),$barcol);
  1781. $color_index++;
  1782. }
  1783. }
  1784. }
  1785. } //function DrawThinBarLines
  1786. function DrawYErrorBar($x_world,$y_world,$error_height,$error_bar_type,$color) {
  1787. $x1 = $this->xtr($x_world);
  1788. $y1 = $this->ytr($y_world);
  1789. $y2 = $this->ytr($y_world+$error_height) ;
  1790. for ($width = 0; $width < $this->error_bar_line_width; $width++) {
  1791. ImageLine($this->img, $x1+$width, $y1 , $x1+$width, $y2, $color);
  1792. ImageLine($this->img, $x1-$width, $y1 , $x1-$width, $y2, $color);
  1793. }
  1794. switch ($error_bar_type) {
  1795. case "line":
  1796. break;
  1797. case "tee":
  1798. ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color);
  1799. break;
  1800. default:
  1801. ImageLine($this->img, $x1-$this->error_bar_size, $y2, $x1+$this->error_bar_size, $y2, $color);
  1802. break;
  1803. }
  1804. return true;
  1805. }
  1806. function DrawDot($x_world,$y_world,$dot_type,$color) {
  1807. $half_point = $this->point_size / 2;
  1808. $x1 = $this->xtr($x_world) - $half_point;
  1809. $x2 = $this->xtr($x_world) + $half_point;
  1810. $y1 = $this->ytr($y_world) - $half_point;
  1811. $y2 = $this->ytr($y_world) + $half_point;
  1812. switch ($dot_type) {
  1813. case "halfline":
  1814. ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $this->xtr($x_world), $this->ytr($y_world), $color);
  1815. break;
  1816. case "line":
  1817. ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $x2, $this->ytr($y_world), $color);
  1818. break;
  1819. case "rect":
  1820. ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
  1821. break;
  1822. case "circle":
  1823. ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
  1824. break;
  1825. case "dot":
  1826. ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
  1827. ImageFillToBorder($this->img, $x1 + $half_point, $y1 + $half_point, $color, $color);
  1828. break;
  1829. case "diamond":
  1830. $arrpoints = array(
  1831. $x1,$y1 + $half_point,
  1832. $x1 + $half_point, $y1,
  1833. $x2,$y1 + $half_point,
  1834. $x1 + $half_point, $y2
  1835. );
  1836. ImageFilledPolygon($this->img, $arrpoints, 4, $color);
  1837. break;
  1838. case "triangle":
  1839. $arrpoints = array( $x1, $y1 + $half_point,
  1840. $x2, $y1 + $half_point,
  1841. $x1 + $half_point, $y2
  1842. );
  1843. ImageFilledPolygon($this->img, $arrpoints, 3, $color);
  1844. break;
  1845. default:
  1846. ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
  1847. break;
  1848. }
  1849. return true;
  1850. }
  1851. function SetErrorBarLineWidth($which_seblw) {
  1852. $this->error_bar_line_width = $which_seblw;
  1853. return true;
  1854. }
  1855. function SetLineWidth($which_lw) {
  1856. $this->line_width = $which_lw;
  1857. if (!$this->error_bar_line_width) {
  1858. $this->error_bar_line_width = $which_lw;
  1859. }
  1860. return true;
  1861. }
  1862. function DrawArea() {
  1863. //Data comes in as $data[]=("title",x,y,...);
  1864. //Set first and last datapoints of area
  1865. $i = 0;
  1866. while ($i < $this->records_per_group) {
  1867. $posarr[$i][] = $this->xtr($this->min_x); //x initial
  1868. $posarr[$i][] = $this->ytr($this->x_axis_position); //y initial
  1869. $i++;
  1870. }
  1871. reset($this->data_values);
  1872. while (list($j, $row) = each($this->data_values)) {
  1873. $color_index = 0;
  1874. //foreach ($row as $v)
  1875. while (list($k, $v) = each($row)) {
  1876. if ($k == 0) {
  1877. //Draw Data Labels
  1878. $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
  1879. } elseif ($k == 1) {
  1880. $x = $this->xtr($v);
  1881. // DrawXDataLabel interferes with Numbers on x-axis
  1882. //$this->DrawXDataLabel($xlab,$x);
  1883. } else {
  1884. // Create Array of points for later
  1885. $y = $this->ytr($v);
  1886. $posarr[$color_index][] = $x;
  1887. $posarr[$color_index][] = $y;
  1888. $color_index++;
  1889. }
  1890. }
  1891. }
  1892. //Final_points
  1893. for ($i = 0; $i < $this->records_per_group; $i++) {
  1894. $posarr[$i][] = $this->xtr($this->max_x); //x final
  1895. $posarr[$i][] = $this->ytr($this->x_axis_position); //y final
  1896. }
  1897. $color_index=0;
  1898. //foreach($posarr as $row)
  1899. reset($posarr);
  1900. while (list(, $row) = each($posarr)) {
  1901. if ($color_index >= count($this->ndx_data_color)) $color_index=0;
  1902. $barcol = $this->ndx_data_color[$color_index];
  1903. //echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br>";
  1904. ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
  1905. $color_index++;
  1906. }
  1907. //exit;
  1908. }
  1909. function DrawAreaSeries() {
  1910. //Set first and last datapoints of area
  1911. $i = 0;
  1912. while ($i < $this->records_per_group) {
  1913. $posarr[$i][] = $this->xtr(.5); //x initial
  1914. $posarr[$i][] = $this->ytr($this->x_axis_position); //y initial
  1915. $i++;
  1916. }
  1917. reset($this->data_values);
  1918. while (list($j, $row) = each($this->data_values)) {
  1919. $color_index = 0;
  1920. //foreach ($row as $v)
  1921. while (list($k, $v) = each($row)) {
  1922. if ($k == 0) {
  1923. //Draw Data Labels
  1924. $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
  1925. $this->DrawXDataLabel($xlab,$this->xtr($j + .5));
  1926. } else {
  1927. // Create Array of points for later
  1928. $x = round($this->xtr($j + .5 ));
  1929. $y = round($this->ytr($v));
  1930. $posarr[$color_index][] = $x;
  1931. $posarr[$color_index][] = $y;
  1932. $color_index++;
  1933. }
  1934. }
  1935. }
  1936. //Final_points
  1937. for ($i = 0; $i < $this->records_per_group; $i++) {
  1938. $posarr[$i][] = round($this->xtr($this->max_x + .5)); //x final
  1939. $posarr[$i][] = $this->ytr($this->x_axis_position); //y final
  1940. }
  1941. $color_index=0;
  1942. //foreach($posarr as $row)
  1943. reset($posarr);
  1944. while (list(, $row) = each($posarr)) {
  1945. if ($color_index >= count($this->ndx_data_color)) $color_index=0;
  1946. $barcol = $this->ndx_data_color[$color_index];
  1947. //echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11],$row[12], $barcol<br>";
  1948. ImageFilledPolygon($this->img, $row, (count($row)) / 2, $barcol);
  1949. $color_index++;
  1950. }
  1951. }
  1952. function DrawLines() {
  1953. //Data comes in as $data[]=("title",x,y,...);
  1954. $start_lines = 0;
  1955. if ($this->data_type == "text-data") {
  1956. $lastx[0] = $this->xtr(0);
  1957. $lasty[0] = $this->xtr(0);
  1958. }
  1959. //foreach ($this->data_values as $row)
  1960. reset($this->data_values);
  1961. while (list($j, $row) = each($this->data_values)) {
  1962. $color_index = 0;
  1963. $i = 0;
  1964. //foreach ($row as $v)
  1965. while (list($k, $v) = each($row)) {
  1966. if ($k == 0) {
  1967. $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
  1968. } elseif (($k == 1) && ($this->data_type == "data-data")) {
  1969. $x_now = $this->xtr($v);
  1970. } else {
  1971. //(double) $v;
  1972. // Draw Lines
  1973. if ($this->data_type == "text-data") {
  1974. $x_now = $this->xtr($j+.5);
  1975. }
  1976. //if (is_numeric($v)) //PHP4 only
  1977. if ((strval($v) != "") ) { //Allow for missing Y data
  1978. $y_now = $this->ytr($v);
  1979. if ($color_index >= count($this->ndx_data_color)) { $color_index=0;} ;
  1980. $barcol = $this->ndx_data_color[$color_index];
  1981. if ($start_lines == 1) {
  1982. for ($width = 0; $width < $this->line_width; $width++) {
  1983. if ($this->line_style[$i] == "dashed") {
  1984. $this->DrawDashedLine($x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, 4,4, $barcol);
  1985. } else {
  1986. ImageLine($this->img, $x_now, $y_now + $width, $lastx[$i], $lasty[$i] + $width, $barcol);
  1987. }
  1988. }
  1989. }
  1990. $lastx[$i] = $x_now;
  1991. } else {
  1992. $y_now = $lasty[$i];
  1993. //Don't increment lastx[$i]
  1994. }
  1995. //$bordercol = $this->ndx_data_border_color[$colbarcount];
  1996. $lasty[$i] = $y_now;
  1997. $color_index++;
  1998. $i++;
  1999. }
  2000. //Now we are assured an x_value
  2001. if ( ($this->draw_x_data_labels == 1) && ($k == 1) ) { //See "labels_note1 above.
  2002. $this->DrawXDataLabel($xlab,$x_now);
  2003. }
  2004. } //while rows of data
  2005. $start_lines = 1;
  2006. }
  2007. }
  2008. //Data comes in as $data[]=("title",x,y,e+,e-,y2,e2+,e2-,...);
  2009. function DrawLineSeries() {
  2010. //This function is replaced by DrawLines
  2011. //Tests have shown not much improvement in speed by having separate routines for DrawLineSeries and DrawLines
  2012. //For ease of programming I have combined them
  2013. return false;
  2014. } //function DrawLineSeries
  2015. function DrawDashedLine($x1pix,$y1pix,$x2pix,$y2pix,$dash_length,$dash_space,$color) {
  2016. //Code based on work by Ariel Garza and James Pine
  2017. //I've decided to have this be in pixels only as a replacement for ImageLine
  2018. //$x1pix = $this->xtr($x1);
  2019. //$y1pix = $this->ytr($y1);
  2020. //$x2pix = $this->xtr($x2);
  2021. //$y2pix = $this->ytr($y2);
  2022. // Get the length of the line in pixels
  2023. $line_length = ceil (sqrt(pow(($x2pix - $x1pix),2) + pow(($y2pix - $y1pix),2)) );
  2024. $dx = ($x2pix - $x1pix) / $line_length;
  2025. $dy = ($y2pix - $y1pix) / $line_length;
  2026. $lastx = $x1pix;
  2027. $lasty = $y1pix;
  2028. // Draw the dashed line
  2029. for ($i = 0; $i < $line_length; $i += ($dash_length + $dash_space)) {
  2030. $xpix = ($dash_length * $dx) + $lastx;
  2031. $ypix = ($dash_length * $dy) + $lasty;
  2032. ImageLine($this->img,$lastx,$lasty,$xpix,$ypix,$color);
  2033. $lastx = $xpix + ($dash_space * $dx);
  2034. $lasty = $ypix + ($dash_space * $dy);
  2035. }
  2036. } // function DrawDashedLine
  2037. function DrawBars() {
  2038. if ($this->data_type != "text-data") {
  2039. $this->DrawError('Bar plots must be text-data: use function SetDataType("text-data")');
  2040. }
  2041. $xadjust = ($this->records_per_group * $this->record_bar_width )/4;
  2042. reset($this->data_values);
  2043. while (list($j, $row) = each($this->data_values)) {
  2044. $color_index = 0;
  2045. $colbarcount = 0;
  2046. $x_now = $this->xtr($j+.5);
  2047. while (list($k, $v) = each($row)) {
  2048. if ($k == 0) {
  2049. //Draw Data Labels
  2050. $xlab = SubStr($v,0,$this->x_datalabel_maxlength);
  2051. $this->DrawXDataLabel($xlab,$x_now);
  2052. } else {
  2053. // Draw Bars ($v)
  2054. $x1 = $x_now - $this->data_group_space + ($k-1)*$this->record_bar_width;
  2055. $x2 = $x1 + $this->record_bar_width*$this->bar_width_adjust;
  2056. if ($v < $this->x_axis_position) {
  2057. $y1 = $this->ytr($this->x_axis_position);
  2058. $y2 = $this->ytr($v);
  2059. } else {
  2060. $y1 = $this->ytr($v);
  2061. $y2 = $this->ytr($this->x_axis_position);
  2062. }
  2063. if ($color_index >= count($this->ndx_data_color)) $color_index=0;
  2064. if ($colbarcount >= count($this->ndx_data_border_color)) $colbarcount=0;
  2065. $barcol = $this->ndx_data_color[$color_index];
  2066. $bordercol = $this->ndx_data_border_color[$colbarcount];
  2067. if ((strval($v) != "") ) { //Allow for missing Y data
  2068. if ($this->shading > 0) {
  2069. for($i=0;$i<($this->shading);$i++) {
  2070. //Shading set in SetDefaultColors
  2071. ImageFilledRectangle($this->img, $x1+$i, $y1-$i, $x2+$i, $y2-$i, $this->ndx_i_light);
  2072. }
  2073. }
  2074. ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $barcol);
  2075. ImageRectangle($this->img, $x1, $y1, $x2, $y2, $bordercol);
  2076. if ($this->draw_data_labels == '1') { //ajo
  2077. $y1 = $this->ytr($this->label_scale_position * $v);
  2078. //$this->DrawDataLabel($v,$j + .5,$v*$this->label_scale_position);
  2079. $this->DrawText($this->x_label_ttffont, $this->x_label_angle,
  2080. $x1+$this->record_bar_width/2, $y1, $this->ndx_label_color, $this->x_label_ttffont_size, $v,'center','top');
  2081. }
  2082. }
  2083. $color_index++;
  2084. $colbarcount++;
  2085. }
  2086. }
  2087. }
  2088. } //function DrawBars
  2089. function DrawLegend($which_x1,$which_y1,$which_boxtype) {
  2090. //Base code submitted by Marlin Viss
  2091. $max_legend_length=0;
  2092. reset($this->legend);
  2093. while (list(,$leg) = each($this->legend)) {
  2094. $len = strlen($leg);
  2095. if ($max_legend_length < $len) {
  2096. $max_legend_length = $len;
  2097. }
  2098. }
  2099. $line_spacing = 1.25;
  2100. $vert_margin = $this->small_font_height/2 ;
  2101. $dot_height = $this->small_font_height*$line_spacing - 1;
  2102. //Upper Left
  2103. if ((!$which_x1) || (!$which_y1) ) {
  2104. $box_start_x = $this->plot_area[2] - $this->small_font_width*($max_legend_length+4);
  2105. $box_start_y = $this->plot_area[1] + 4;
  2106. } else {
  2107. $box_start_x = $which_x1;
  2108. $box_start_y = $which_y1;
  2109. }
  2110. //Lower Right
  2111. $box_end_y = $box_start_y + $this->small_font_height*(count($this->legend)+1) + 2*$vert_margin;
  2112. //$box_end_x = $this->plot_area[2] - 5;
  2113. $box_end_x = $box_start_x + $this->small_font_width*($max_legend_length+4) - 5;
  2114. // Draw box for legend
  2115. ImageFilledRectangle($this->img,
  2116. $box_start_x, $box_start_y,$box_end_x,
  2117. $box_end_y, $this->ndx_bg_color);
  2118. ImageRectangle($this->img,
  2119. $box_start_x, $box_start_y,$box_end_x,
  2120. $box_end_y, $this->ndx_grid_color);
  2121. $color_index=0;
  2122. $i = 0;
  2123. reset($this->legend);
  2124. while (list(,$leg) = each($this->legend)) {
  2125. $y_pos = $box_start_y + $this->small_font_height*($i)*($line_spacing) + $vert_margin;
  2126. ImageString($this->img, $this->small_font,
  2127. $box_start_x + $this->small_font_width*( $max_legend_length - strlen($leg) + 1 ) ,
  2128. $y_pos,
  2129. $leg, $this->ndx_text_color);
  2130. if ($color_index >= count($this->ndx_data_color)) $color_index=0;
  2131. // Draw a box in the data color
  2132. ImageFilledRectangle($this->img,
  2133. $box_end_x - $this->small_font_width*2,
  2134. $y_pos + 1, $box_end_x - $this->small_font_width,
  2135. $y_pos + $dot_height,
  2136. $this->ndx_data_color[$color_index]);
  2137. ImageRectangle($this->img,
  2138. $box_end_x - $this->small_font_width*2,
  2139. $y_pos + 1, $box_end_x - $this->small_font_width,
  2140. $y_pos + $dot_height,
  2141. $this->ndx_text_color);
  2142. $i++;
  2143. $color_index++;
  2144. }
  2145. } //function DrawLegend
  2146. function DrawGraph() {
  2147. if (($this->img) == "") {
  2148. $this->DrawError('No Image Defined: DrawGraph');
  2149. //$this->PHPlot();
  2150. }
  2151. if (! is_array($this->data_values)) {
  2152. $this->DrawBackground();
  2153. $this->DrawError("No array of data in \$data_values");
  2154. } else {
  2155. if (!$this->data_color) {
  2156. $this->SetDataColors(array('blue','green','yellow','red','orange','blue'),array('black'));
  2157. }
  2158. $this->FindDataLimits(); //Get maxima and minima for scaling
  2159. $this->SetXLabelHeight(); //Get data for bottom margin
  2160. $this->SetYLabelWidth(); //Get data for left margin
  2161. if (!$this->plot_area_width) {
  2162. $this->SetPlotAreaPixels('','','',''); //Set Margins
  2163. }
  2164. if (!$this->plot_max_y) { //If not set by user call SetPlotAreaWorld,
  2165. $this->SetPlotAreaWorld('','','','');
  2166. }
  2167. if ($this->data_type == "text-data") {
  2168. $this->SetEqualXCoord();
  2169. }
  2170. $this->SetPointSize($this->point_size);
  2171. $this->DrawBackground();
  2172. $this->DrawImageBorder();
  2173. $this->SetTranslation();
  2174. if ($this->draw_plot_area_background == 1) {
  2175. $this->DrawPlotAreaBackground();
  2176. }
  2177. //$foo = "$this->max_y, $this->min_y, $new_miny, $new_maxy, $this->x_label_height";
  2178. //ImageString($this->img, 4, 20, 20, $foo, $this->ndx_text_color);
  2179. switch ($this->plot_type) {
  2180. case "bars":
  2181. $this->DrawPlotBorder();
  2182. $this->DrawLabels();
  2183. $this->DrawBars();
  2184. $this->DrawXAxis();
  2185. break;
  2186. case "thinbarline":
  2187. $this->DrawPlotBorder();
  2188. $this->DrawLabels();
  2189. $this->DrawThinBarLines();
  2190. break;
  2191. case "lines":
  2192. $this->DrawPlotBorder();
  2193. $this->DrawLabels();
  2194. if ( $this->data_type == "text-data") {
  2195. $this->DrawLines();
  2196. } elseif ( $this->data_type == "data-data-error") {
  2197. $this->DrawLinesError();
  2198. } else {
  2199. $this->DrawLines();
  2200. }
  2201. break;
  2202. case "area":
  2203. $this->DrawPlotBorder();
  2204. $this->DrawLabels();
  2205. if ( $this->data_type == "text-data") {
  2206. $this->DrawAreaSeries();
  2207. } else {
  2208. $this->DrawArea();
  2209. }
  2210. break;
  2211. case "linepoints":
  2212. $this->DrawPlotBorder();
  2213. $this->DrawLabels();
  2214. if ( $this->data_type == "text-data") {
  2215. $this->DrawLines();
  2216. $this->DrawDots();
  2217. } elseif ( $this->data_type == "data-data-error") {
  2218. $this->DrawLinesError();
  2219. $this->DrawDotsError();
  2220. } else {
  2221. $this->DrawLines();
  2222. $this->DrawDots();
  2223. }
  2224. break;
  2225. case "points";
  2226. $this->DrawPlotBorder();
  2227. $this->DrawLabels();
  2228. if ( $this->data_type == "text-data") {
  2229. $this->DrawDots();
  2230. } elseif ( $this->data_type == "data-data-error") {
  2231. $this->DrawDotsError();
  2232. } else {
  2233. $this->DrawDots();
  2234. }
  2235. break;
  2236. case "pie":
  2237. $this->DrawPieChart();
  2238. $this->DrawLabels();
  2239. break;
  2240. default:
  2241. $this->DrawPlotBorder();
  2242. $this->DrawLabels();
  2243. $this->DrawBars();
  2244. break;
  2245. }
  2246. if ($this->legend) {
  2247. $this->DrawLegend($this->legend_x_pos,$this->legend_y_pos,'');
  2248. }
  2249. }
  2250. if ($this->print_image == 1) {
  2251. $this->PrintImage();
  2252. }
  2253. } //function DrawGraph
  2254. }
  2255. // $graph = new PHPlot;
  2256. // $graph->DrawGraph();
  2257. ?>