PageRenderTime 30ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/includes/classes/phplot.php

https://bitbucket.org/flth/xtcm
PHP | 2536 lines | 2078 code | 156 blank | 302 comment | 459 complexity | 8ab2193bcb27bb7b9ce6d35b842df629 MD5 | raw file
Possible License(s): AGPL-1.0

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

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

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