PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_sm2emailmarketing/includes/phplot/phplot.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 4450 lines | 2834 code | 647 blank | 969 comment | 605 complexity | f4e2a07677533cfe435dcdd5f5a533ce MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

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

  1. <?php
  2. /* $Id: phplot.php,v 1.3 2007/07/20 21:47:24 sm2tony Exp $ */
  3. /*
  4. * PHPLOT Version 5.0.rc1
  5. * Copyright (C) 1998, 1999, 2000, 2001 Afan Ottenheimer. Released under
  6. * the GPL and PHP licenses as stated in the the README file which should
  7. * have been included with this document.
  8. *
  9. * Recent (2003-2004) work by Miguel de Benito Delgado <nonick AT vodafone DOT es>
  10. *
  11. * Requires PHP 4.2.0 or later (CHECK THIS)
  12. */
  13. defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
  14. if (! defined(__FUNCTION__))
  15. define(__FUNCTION__, '__FUNCTION__ Requires at least PHP 4.3.0.');
  16. define ('MINY', -1); // Indexes in $data (for DrawXDataLine())
  17. define ('MAXY', -2);
  18. define ('TOTY', -3);
  19. error_reporting(E_ALL);
  20. class PHPlot {
  21. /* I have removed internal variable declarations, some isset() checking was required,
  22. * but now the variables left are those which can be tweaked by the user. This is intended to
  23. * be the first step towards moving most of the Set...() methods into a subclass which will be
  24. * used only when strictly necessary. Many users will be able to put default values here in the
  25. * class and thus avoid memory overhead and reduce parsing times.
  26. */
  27. //////////////// CONFIG PARAMETERS //////////////////////
  28. var $is_inline = FALSE; // FALSE = Sends headers, TRUE = sends just raw image data
  29. var $browser_cache = FALSE; // FALSE = Sends headers for browser to not cache the image,
  30. // (only if is_inline = FALSE also)
  31. var $safe_margin = 5; // Extra margin used in several places. In pixels
  32. var $x_axis_position = ''; // Where to draw both axis (world coordinates),
  33. var $y_axis_position = ''; // leave blank for X axis at 0 and Y axis at left of plot.
  34. var $xscale_type = 'linear'; // linear, log
  35. var $yscale_type = 'linear';
  36. //Fonts
  37. var $use_ttf = FALSE; // Use True Type Fonts?
  38. var $ttf_path = '.'; // Default path to look in for TT Fonts.
  39. var $default_ttfont = 'benjamingothic.ttf';
  40. var $line_spacing = 4; // Pixels between lines.
  41. // Font angles: 0 or 90 degrees for fixed fonts, any for TTF
  42. var $x_label_angle = 0; // For labels on X axis (tick and data)
  43. var $y_label_angle = 0; // For labels on Y axis (tick and data)
  44. var $x_title_angle = 0; // Don't change this if you don't want to screw things up!
  45. var $y_title_angle = 90; // Nor this.
  46. var $title_angle = 0; // Or this.
  47. //Formats
  48. var $file_format = 'png';
  49. var $output_file = ''; // For output to a file instead of stdout
  50. //Data
  51. var $data_type = 'text-data'; // text-data, data-data-error, data-data, text-data-single
  52. var $plot_type= 'linepoints'; // bars, lines, linepoints, area, points, pie, thinbarline, squared
  53. var $label_scale_position = 0.5; // Shifts data labes in pie charts. 1 = top, 0 = bottom
  54. var $group_frac_width = 0.7; // value from 0 to 1 = width of bar groups
  55. var $bar_width_adjust = 1; // 1 = bars of normal width, must be > 0
  56. var $y_precision = 1;
  57. var $x_precision = 1;
  58. var $data_units_text = ''; // Units text for 'data' labels (i.e: '�', '$', etc.)
  59. // Titles
  60. var $title_txt = '';
  61. var $x_title_txt = '';
  62. var $x_title_pos = 'plotdown'; // plotdown, plotup, both, none
  63. var $y_title_txt = '';
  64. var $y_title_pos = 'plotleft'; // plotleft, plotright, both, none
  65. //Labels
  66. // There are two types of labels in PHPlot:
  67. // Tick labels: they follow the grid, next to ticks in axis. (DONE)
  68. // they are drawn at grid drawing time, by DrawXTicks() and DrawYTicks()
  69. // Data labels: they follow the data points, and can be placed on the axis or the plot (x/y) (TODO)
  70. // they are drawn at graph plotting time, by Draw*DataLabel(), called by DrawLines(), etc.
  71. // Draw*DataLabel() also draws H/V lines to datapoints depending on draw_*_data_label_lines
  72. // Tick Labels
  73. var $x_tick_label_pos = 'plotdown'; // plotdown, plotup, both, xaxis, none
  74. var $y_tick_label_pos = 'plotleft'; // plotleft, plotright, both, yaxis, none
  75. // Data Labels:
  76. var $x_data_label_pos = 'plotdown'; // plotdown, plotup, both, plot, all, none
  77. var $y_data_label_pos = 'plotleft'; // plotleft, plotright, both, plot, all, none
  78. var $draw_x_data_label_lines = FALSE; // Draw a line from the data point to the axis?
  79. var $draw_y_data_label_lines = FALSE; // TODO
  80. // Label types: (for tick, data and plot labels)
  81. var $x_label_type = ''; // data, time. Leave blank for no formatting.
  82. var $y_label_type = ''; // data, time. Leave blank for no formatting.
  83. var $x_time_format = '%H:%m:%s'; // See http://www.php.net/manual/html/function.strftime.html
  84. var $y_time_format = '%H:%m:%s'; // SetYTimeFormat() too...
  85. // Skipping labels
  86. var $x_label_inc = 1; // Draw a label every this many (1 = all) (TODO)
  87. var $y_label_inc = 1;
  88. var $_x_label_cnt = 0; // internal count FIXME: work in progress
  89. // Legend
  90. var $legend = ''; // An array with legend titles
  91. var $legend_x_pos = '';
  92. var $legend_y_pos = '';
  93. //Ticks
  94. var $x_tick_length = 5; // tick length in pixels for upper/lower axis
  95. var $y_tick_length = 5; // tick length in pixels for left/right axis
  96. var $x_tick_cross = 3; // ticks cross x axis this many pixels
  97. var $y_tick_cross = 3; // ticks cross y axis this many pixels
  98. var $x_tick_pos = 'plotdown'; // plotdown, plotup, both, xaxis, none
  99. var $y_tick_pos = 'plotleft'; // plotright, plotleft, both, yaxis, none
  100. var $num_x_ticks = '';
  101. var $num_y_ticks = '';
  102. var $x_tick_inc = ''; // Set num_x_ticks or x_tick_inc, not both.
  103. var $y_tick_inc = ''; // Set num_y_ticks or y_tick_inc, not both.
  104. var $skip_top_tick = FALSE;
  105. var $skip_bottom_tick = FALSE;
  106. var $skip_left_tick = FALSE;
  107. var $skip_right_tick = FALSE;
  108. //Grid Formatting
  109. var $draw_x_grid = FALSE;
  110. var $draw_y_grid = TRUE;
  111. var $dashed_grid = TRUE;
  112. var $grid_at_foreground = FALSE; // Chooses whether to draw the grid below or above the graph
  113. //Colors and styles (all colors can be array (R,G,B) or named color)
  114. var $color_array = 'small'; // 'small', 'large' or array (define your own colors)
  115. // See rgb.inc.php and SetRGBArray()
  116. var $i_border = array(194, 194, 194);
  117. var $plot_bg_color = 'white';
  118. var $bg_color = 'white';
  119. var $label_color = 'black';
  120. var $text_color = 'black';
  121. var $grid_color = 'black';
  122. var $light_grid_color = 'gray';
  123. var $tick_color = 'black';
  124. var $title_color = 'black';
  125. var $data_colors = array('SkyBlue', 'green', 'orange', 'blue', 'orange', 'red', 'violet', 'azure1');
  126. var $error_bar_colors = array('SkyBlue', 'green', 'orange', 'blue', 'orange', 'red', 'violet', 'azure1');
  127. var $data_border_colors = array('black');
  128. var $line_widths = 1; // single value or array
  129. var $line_styles = array('solid', 'solid', 'dashed'); // single value or array
  130. var $dashed_style = '2-4'; // colored dots-transparent dots
  131. var $point_sizes = array(5,5,3); // single value or array
  132. var $point_shapes = array('diamond'); // rect, circle, diamond, triangle, dot, line, halfline, cross
  133. var $error_bar_size = 5; // right and left size of tee
  134. var $error_bar_shape = 'tee'; // 'tee' or 'line'
  135. var $error_bar_line_width = 1; // single value (or array TODO)
  136. var $plot_border_type = 'sides'; // left, sides, none, full
  137. var $image_border_type = 'none'; // 'raised', 'plain', 'none'
  138. var $shading = 5; // 0 for no shading, > 0 is size of shadows in pixels
  139. var $draw_plot_area_background = FALSE;
  140. var $draw_broken_lines = FALSE; // Tells not to draw lines for missing Y data.
  141. //////////////////////////////////////////////////////
  142. //BEGIN CODE
  143. //////////////////////////////////////////////////////
  144. /*!
  145. * Constructor: Setup img resource, colors and size of the image, and font sizes.
  146. *
  147. * \param which_width int Image width in pixels.
  148. * \param which_height int Image height in pixels.
  149. * \param which_output_file string Filename for output.
  150. * \param which_input_fule string Path to a file to be used as background.
  151. */
  152. function PHPlot($which_width=600, $which_height=400, $which_output_file=NULL, $which_input_file=NULL)
  153. {
  154. /*
  155. * Please see http://www.php.net/register_shutdown_function
  156. * PLEASE NOTE: register_shutdown_function() will take a copy of the object rather than a reference
  157. * so we put an ampersand. However, the function registered will work on the object as it
  158. * was upon registration. To solve this, one of two methods can be used:
  159. * $obj = new object();
  160. * register_shutdown_function(array(&$obj,'shutdown'));
  161. * OR
  162. * $obj = &new object();
  163. * HOWEVER, as the second statement assigns $obj a reference to the current object, it might be that
  164. * several instances mess things up... (CHECK THIS)
  165. *
  166. * AND
  167. * as $this->img is set upon construction of the object, problems will not arise for us (for the
  168. * moment maybe, so I put all this here just in case)
  169. */
  170. register_shutdown_function(array(&$this, '_PHPlot'));
  171. $this->SetRGBArray($this->color_array);
  172. $this->background_done = FALSE; // Set to TRUE after background image is drawn once
  173. if ($which_output_file)
  174. $this->SetOutputFile($which_output_file);
  175. if ($which_input_file)
  176. $this->SetInputFile($which_input_file);
  177. else {
  178. $this->image_width = $which_width;
  179. $this->image_height = $which_height;
  180. $this->img = ImageCreate($this->image_width, $this->image_height);
  181. if (! $this->img)
  182. $this->PrintError('PHPlot(): Could not create image resource.');
  183. }
  184. $this->SetDefaultStyles();
  185. $this->SetDefaultFonts();
  186. $this->SetTitle('');
  187. $this->SetXTitle('');
  188. $this->SetYTitle('');
  189. $this->print_image = TRUE; // Use for multiple plots per image (TODO: automatic)
  190. }
  191. /*!
  192. * Destructor. Image resources not deallocated can be memory hogs, I think
  193. * it is safer to automatically call imagedestroy upon script termination than
  194. * do it ourselves.
  195. * See notes in the constructor code.
  196. */
  197. function _PHPlot ()
  198. {
  199. imagedestroy($this->img);
  200. return;
  201. }
  202. /////////////////////////////////////////////
  203. ////////////// COLORS
  204. /////////////////////////////////////////////
  205. /*!
  206. * Returns an index to a color passed in as anything (string, hex, rgb)
  207. *
  208. * \param which_color * Color (can be '#AABBCC', 'Colorname', or array(r,g,b))
  209. */
  210. function SetIndexColor($which_color)
  211. {
  212. list ($r, $g, $b) = $this->SetRGBColor($which_color); //Translate to RGB
  213. $index = ImageColorExact($this->img, $r, $g, $b);
  214. if ($index == -1) {
  215. return ImageColorResolve($this->img, $r, $g, $b);
  216. } else {
  217. return $index;
  218. }
  219. }
  220. /*!
  221. * Returns an index to a slightly darker color than the one requested.
  222. */
  223. function SetIndexDarkColor($which_color)
  224. {
  225. list ($r, $g, $b) = $this->SetRGBColor($which_color);
  226. $r -= 0x30; $r = ($r < 0) ? 0 : $r;
  227. $g -= 0x30; $g = ($g < 0) ? 0 : $g;
  228. $b -= 0x30; $b = ($b < 0) ? 0 : $b;
  229. $index = ImageColorExact($this->img, $r, $g, $b);
  230. if ($index == -1) {
  231. return ImageColorResolve($this->img, $r, $g, $b);
  232. } else {
  233. return $index;
  234. }
  235. }
  236. /*!
  237. * Sets/reverts all colors and styles to their defaults. If session is set, then only updates indices,
  238. * as they are lost with every script execution, else, sets the default colors by name or value and
  239. * then updates indices too.
  240. *
  241. * FIXME Isn't this too slow?
  242. *
  243. */
  244. function SetDefaultStyles()
  245. {
  246. /* Some of the Set*() functions use default values when they get no parameters. */
  247. if (! isset($this->session_set)) {
  248. // If sessions are enabled, this variable will be preserved, so upon future executions, we
  249. // will have it set, as well as color names (though not color indices, that's why we
  250. // need to rebuild them)
  251. $this->session_set = TRUE;
  252. // These only need to be set once
  253. $this->SetLineWidths();
  254. $this->SetLineStyles();
  255. $this->SetDefaultDashedStyle($this->dashed_style);
  256. $this->SetPointSizes($this->point_sizes);
  257. }
  258. $this->SetImageBorderColor($this->i_border);
  259. $this->SetPlotBgColor($this->plot_bg_color);
  260. $this->SetBackgroundColor($this->bg_color);
  261. $this->SetLabelColor($this->label_color);
  262. $this->SetTextColor($this->text_color);
  263. $this->SetGridColor($this->grid_color);
  264. $this->SetLightGridColor($this->light_grid_color);
  265. $this->SetTickColor($this->tick_color);
  266. $this->SetTitleColor($this->title_color);
  267. $this->SetDataColors();
  268. $this->SetErrorBarColors();
  269. $this->SetDataBorderColors();
  270. }
  271. /*
  272. *
  273. */
  274. function SetBackgroundColor($which_color)
  275. {
  276. $this->bg_color= $which_color;
  277. $this->ndx_bg_color= $this->SetIndexColor($this->bg_color);
  278. return TRUE;
  279. }
  280. /*
  281. *
  282. */
  283. function SetPlotBgColor($which_color)
  284. {
  285. $this->plot_bg_color= $which_color;
  286. $this->ndx_plot_bg_color= $this->SetIndexColor($this->plot_bg_color);
  287. return TRUE;
  288. }
  289. /*
  290. *
  291. */
  292. function SetTitleColor($which_color)
  293. {
  294. $this->title_color= $which_color;
  295. $this->ndx_title_color= $this->SetIndexColor($this->title_color);
  296. return TRUE;
  297. }
  298. /*
  299. *
  300. */
  301. function SetTickColor ($which_color)
  302. {
  303. $this->tick_color= $which_color;
  304. $this->ndx_tick_color= $this->SetIndexColor($this->tick_color);
  305. return TRUE;
  306. }
  307. /*
  308. *
  309. */
  310. function SetLabelColor ($which_color)
  311. {
  312. $this->label_color = $which_color;
  313. $this->ndx_title_color= $this->SetIndexColor($this->label_color);
  314. return TRUE;
  315. }
  316. /*
  317. *
  318. */
  319. function SetTextColor ($which_color)
  320. {
  321. $this->text_color= $which_color;
  322. $this->ndx_text_color= $this->SetIndexColor($this->text_color);
  323. return TRUE;
  324. }
  325. /*
  326. *
  327. */
  328. function SetLightGridColor ($which_color)
  329. {
  330. $this->light_grid_color= $which_color;
  331. $this->ndx_light_grid_color= $this->SetIndexColor($this->light_grid_color);
  332. return TRUE;
  333. }
  334. /*
  335. *
  336. */
  337. function SetGridColor ($which_color)
  338. {
  339. $this->grid_color = $which_color;
  340. $this->ndx_grid_color= $this->SetIndexColor($this->grid_color);
  341. return TRUE;
  342. }
  343. /*
  344. *
  345. */
  346. function SetImageBorderColor($which_color)
  347. {
  348. $this->i_border = $which_color;
  349. $this->ndx_i_border = $this->SetIndexColor($this->i_border);
  350. $this->ndx_i_border_dark = $this->SetIndexDarkColor($this->i_border);
  351. return TRUE;
  352. }
  353. /*
  354. *
  355. */
  356. function SetTransparentColor($which_color)
  357. {
  358. ImageColorTransparent($this->img, $this->SetIndexColor($which_color));
  359. return TRUE;
  360. }
  361. /*!
  362. * Sets the array of colors to be used. It can be user defined, a small predefined one
  363. * or a large one included from 'rgb.inc.php'.
  364. *
  365. * \param which_color_array If an array, the used as color array. If a string can
  366. * be one of 'small' or 'large'.
  367. */
  368. function SetRGBArray ($which_color_array)
  369. {
  370. if ( is_array($which_color_array) ) { // User defined array
  371. $this->rgb_array = $which_color_array;
  372. return TRUE;
  373. } elseif ($which_color_array == 'small') { // Small predefined color array
  374. $this->rgb_array = array(
  375. 'white' => array(255, 255, 255),
  376. 'snow' => array(255, 250, 250),
  377. 'PeachPuff' => array(255, 218, 185),
  378. 'ivory' => array(255, 255, 240),
  379. 'lavender' => array(230, 230, 250),
  380. 'black' => array( 0, 0, 0),
  381. 'DimGrey' => array(105, 105, 105),
  382. 'gray' => array(190, 190, 190),
  383. 'grey' => array(190, 190, 190),
  384. 'navy' => array( 0, 0, 128),
  385. 'SlateBlue' => array(106, 90, 205),
  386. 'blue' => array( 0, 0, 255),
  387. 'SkyBlue' => array(135, 206, 235),
  388. 'cyan' => array( 0, 255, 255),
  389. 'DarkGreen' => array( 0, 100, 0),
  390. 'green' => array( 0, 255, 0),
  391. 'YellowGreen' => array(154, 205, 50),
  392. 'yellow' => array(255, 255, 0),
  393. 'orange' => array(255, 165, 0),
  394. 'gold' => array(255, 215, 0),
  395. 'peru' => array(205, 133, 63),
  396. 'beige' => array(245, 245, 220),
  397. 'wheat' => array(245, 222, 179),
  398. 'tan' => array(210, 180, 140),
  399. 'brown' => array(165, 42, 42),
  400. 'salmon' => array(250, 128, 114),
  401. 'red' => array(255, 0, 0),
  402. 'pink' => array(255, 192, 203),
  403. 'maroon' => array(176, 48, 96),
  404. 'magenta' => array(255, 0, 255),
  405. 'violet' => array(238, 130, 238),
  406. 'plum' => array(221, 160, 221),
  407. 'orchid' => array(218, 112, 214),
  408. 'purple' => array(160, 32, 240),
  409. 'azure1' => array(240, 255, 255),
  410. 'aquamarine1' => array(127, 255, 212)
  411. );
  412. return TRUE;
  413. } elseif ($which_color_array === 'large') { // Large color array
  414. global $sm2emPHPLotPath;
  415. include($sm2emPHPLotPath."/rgb.inc.php");
  416. $this->rgb_array = $RGBArray;
  417. } else { // Default to black and white only.
  418. $this->rgb_array = array('white' => array(255, 255, 255), 'black' => array(0, 0, 0));
  419. }
  420. return TRUE;
  421. }
  422. /*!
  423. * Returns an array in R, G, B format 0-255
  424. *
  425. * \param color_asked array(R,G,B) or string (named color or '#AABBCC')
  426. */
  427. function SetRGBColor($color_asked)
  428. {
  429. if ($color_asked == '') { $color_asked = array(0, 0, 0); };
  430. if ( count($color_asked) == 3 ) { // already array of 3 rgb
  431. $ret_val = $color_asked;
  432. } else { // asking for a color by string
  433. if(substr($color_asked, 0, 1) == '#') { // asking in #FFFFFF format.
  434. $ret_val = array(hexdec(substr($color_asked, 1, 2)), hexdec(substr($color_asked, 3, 2)),
  435. hexdec(substr($color_asked, 5, 2)));
  436. } else { // asking by color name
  437. $ret_val = $this->rgb_array[$color_asked];
  438. }
  439. }
  440. return $ret_val;
  441. }
  442. /*!
  443. * Sets the colors for the data.
  444. */
  445. function SetDataColors($which_data = NULL, $which_border = NULL)
  446. {
  447. if (is_null($which_data) && is_array($this->data_colors)) {
  448. // use already set data_colors
  449. } else if (! is_array($which_data)) {
  450. $this->data_colors = ($which_data) ? array($which_data) : array('blue', 'red', 'green', 'orange');
  451. } else {
  452. $this->data_colors = $which_data;
  453. }
  454. $i = 0;
  455. foreach ($this->data_colors as $col) {
  456. $this->ndx_data_colors[$i] = $this->SetIndexColor($col);
  457. $this->ndx_data_dark_colors[$i] = $this->SetIndexDarkColor($col);
  458. $i++;
  459. }
  460. // For past compatibility:
  461. $this->SetDataBorderColors($which_border);
  462. } // function SetDataColors()
  463. /*!
  464. *
  465. */
  466. function SetDataBorderColors($which_br = NULL)
  467. {
  468. if (is_null($which_br) && is_array($this->data_border_colors)) {
  469. // use already set data_border_colors
  470. } else if (! is_array($which_br)) {
  471. // Create new array with specified color
  472. $this->data_border_colors = ($which_br) ? array($which_br) : array('black');
  473. } else {
  474. $this->data_border_colors = $which_br;
  475. }
  476. $i = 0;
  477. foreach($this->data_border_colors as $col) {
  478. $this->ndx_data_border_colors[$i] = $this->SetIndexColor($col);
  479. $i++;
  480. }
  481. } // function SetDataBorderColors()
  482. /*!
  483. * Sets the colors for the data error bars.
  484. */
  485. function SetErrorBarColors($which_err = NULL)
  486. {
  487. if (is_null($which_err) && is_array($this->error_bar_colors)) {
  488. // use already set error_bar_colors
  489. } else if (! is_array($which_err)) {
  490. $this->error_bar_colors = ($which_err) ? array($which_err) : array('black');
  491. } else {
  492. $this->error_bar_colors = $which_err;
  493. }
  494. $i = 0;
  495. foreach($this->error_bar_colors as $col) {
  496. $this->ndx_error_bar_colors[$i] = $this->SetIndexColor($col);
  497. $i++;
  498. }
  499. return TRUE;
  500. } // function SetErrorBarColors()
  501. /*!
  502. * Sets the default dashed style.
  503. * \param which_style A string specifying order of colored and transparent dots,
  504. * i.e: '4-3' means 4 colored, 3 transparent;
  505. * '2-3-1-2' means 2 colored, 3 transparent, 1 colored, 2 transparent.
  506. */
  507. function SetDefaultDashedStyle($which_style)
  508. {
  509. // String: "numcol-numtrans-numcol-numtrans..."
  510. $asked = explode('-', $which_style);
  511. if (count($asked) < 2) {
  512. $this->DrawError("SetDefaultDashedStyle(): Wrong parameter '$which_style'.");
  513. return FALSE;
  514. }
  515. // Build the string to be eval()uated later by SetDashedStyle()
  516. $this->default_dashed_style = 'array( ';
  517. $t = 0;
  518. foreach($asked as $s) {
  519. if ($t % 2 == 0) {
  520. $this->default_dashed_style .= str_repeat('$which_ndxcol,', $s);
  521. } else {
  522. $this->default_dashed_style .= str_repeat('IMG_COLOR_TRANSPARENT,', $s);
  523. }
  524. $t++;
  525. }
  526. // Remove trailing comma and add closing parenthesis
  527. $this->default_dashed_style = substr($this->default_dashed_style, 0, -1);
  528. $this->default_dashed_style .= ')';
  529. return TRUE;
  530. }
  531. /*!
  532. * Sets the style before drawing a dashed line. Defaults to $this->default_dashed_style
  533. * \param which_ndxcol Color index to be used.
  534. */
  535. function SetDashedStyle($which_ndxcol)
  536. {
  537. // See SetDefaultDashedStyle() to understand this.
  538. eval ("\$style = $this->default_dashed_style;");
  539. return imagesetstyle($this->img, $style);
  540. }
  541. /*!
  542. * Sets line widths on a per-line basis.
  543. */
  544. function SetLineWidths($which_lw=NULL)
  545. {
  546. if (is_null($which_lw)) {
  547. // Do nothing, use default value.
  548. } else if (is_array($which_lw)) {
  549. // Did we get an array with line widths?
  550. $this->line_widths = $which_lw;
  551. } else {
  552. $this->line_widths = array($which_lw);
  553. }
  554. return TRUE;
  555. }
  556. /*!
  557. *
  558. */
  559. function SetLineStyles($which_ls=NULL)
  560. {
  561. if (is_null($which_ls)) {
  562. // Do nothing, use default value.
  563. } else if (! is_array($which_ls)) {
  564. // Did we get an array with line styles?
  565. $this->line_styles = $which_ls;
  566. } else {
  567. $this->line_styles = ($which_ls) ? array($which_ls) : array('solid');
  568. }
  569. return TRUE;
  570. }
  571. /////////////////////////////////////////////
  572. ////////////// FONTS
  573. /////////////////////////////////////////////
  574. /*!
  575. * Sets number of pixels between lines of the same text.
  576. */
  577. function SetLineSpacing($which_spc)
  578. {
  579. $this->line_spacing = $which_spc;
  580. }
  581. /*!
  582. * Enables use of TrueType fonts in the graph. Font initialisation methods
  583. * depend on this setting, so when called, SetUseTTF() resets the font
  584. * settings
  585. */
  586. function SetUseTTF($which_ttf)
  587. {
  588. $this->use_ttf = $which_ttf;
  589. if ($which_ttf)
  590. $this->SetDefaultFonts();
  591. return TRUE;
  592. }
  593. /*!
  594. * Sets the directory name to look into for TrueType fonts.
  595. */
  596. function SetTTFPath($which_path)
  597. {
  598. // Maybe someone needs really dynamic config. He'll need this:
  599. // clearstatcache();
  600. if (is_dir($which_path) && is_readable($which_path)) {
  601. $this->ttf_path = $which_path;
  602. return TRUE;
  603. } else {
  604. $this->PrintError("SetTTFPath(): $which_path is not a valid path.");
  605. return FALSE;
  606. }
  607. }
  608. /*!
  609. * Sets the default TrueType font and updates all fonts to that.
  610. */
  611. function SetDefaultTTFont($which_font)
  612. {
  613. if (is_file($which_font) && is_readable($which_font)) {
  614. $this->default_ttfont = $which_font;
  615. return $this->SetDefaultFonts();
  616. } else {
  617. $this->PrintError("SetDefaultTTFont(): $which_font is not a valid font file.");
  618. return FALSE;
  619. }
  620. }
  621. /*!
  622. * Sets fonts to their defaults
  623. */
  624. function SetDefaultFonts()
  625. {
  626. // TTF:
  627. if ($this->use_ttf) {
  628. //$this->SetTTFPath(dirname($_SERVER['PHP_SELF']));
  629. $this->SetTTFPath(getcwd());
  630. $this->SetFont('generic', $this->default_ttfont, 8);
  631. $this->SetFont('title', $this->default_ttfont, 14);
  632. $this->SetFont('legend', $this->default_ttfont, 8);
  633. $this->SetFont('x_label', $this->default_ttfont, 6);
  634. $this->SetFont('y_label', $this->default_ttfont, 6);
  635. $this->SetFont('x_title', $this->default_ttfont, 10);
  636. $this->SetFont('y_title', $this->default_ttfont, 10);
  637. }
  638. // Fixed:
  639. else {
  640. $this->SetFont('generic', 2);
  641. $this->SetFont('title', 5);
  642. $this->SetFont('legend', 2);
  643. $this->SetFont('x_label', 1);
  644. $this->SetFont('y_label', 1);
  645. $this->SetFont('x_title', 3);
  646. $this->SetFont('y_title', 3);
  647. }
  648. return TRUE;
  649. }
  650. /*!
  651. * Sets Fixed/Truetype font parameters.
  652. * \param $which_elem Is the element whose font is to be changed.
  653. * It can be one of 'title', 'legend', 'generic',
  654. * 'x_label', 'y_label', x_title' or 'y_title'
  655. * \param $which_font Can be a number (for fixed font sizes) or
  656. * a string with the filename when using TTFonts.
  657. * \param $which_size Point size (TTF only)
  658. * Calculates and updates internal height and width variables.
  659. */
  660. function SetFont($which_elem, $which_font, $which_size = 12)
  661. {
  662. // TTF:
  663. if ($this->use_ttf) {
  664. $path = $this->ttf_path.'/'.$which_font;
  665. if (! is_file($path) || ! is_readable($path) ) {
  666. $this->DrawError("SetFont(): True Type font $path doesn't exist");
  667. return FALSE;
  668. }
  669. switch ($which_elem) {
  670. case 'generic':
  671. $this->generic_font['font'] = $path;
  672. $this->generic_font['size'] = $which_size;
  673. break;
  674. case 'title':
  675. $this->title_font['font'] = $path;
  676. $this->title_font['size'] = $which_size;
  677. break;
  678. case 'legend':
  679. $this->legend_font['font'] = $path;
  680. $this->legend_font['size'] = $which_size;
  681. break;
  682. case 'x_label':
  683. $this->x_label_font['font'] = $path;
  684. $this->x_label_font['size'] = $which_size;
  685. break;
  686. case 'y_label':
  687. $this->y_label_font['font'] = $path;
  688. $this->y_label_font['size'] = $which_size;
  689. break;
  690. case 'x_title':
  691. $this->x_title_font['font'] = $path;
  692. $this->x_title_font['size'] = $which_size;
  693. break;
  694. case 'y_title':
  695. $this->y_title_font['font'] = $path;
  696. $this->y_title_font['size'] = $which_size;
  697. break;
  698. default:
  699. $this->DrawError("SetFont(): Unknown element '$which_elem' specified.");
  700. return FALSE;
  701. }
  702. return TRUE;
  703. }
  704. // Fixed fonts:
  705. if ($which_font > 5 || $which_font < 0) {
  706. $this->DrawError('SetFont(): Non-TTF font size must be 1, 2, 3, 4 or 5');
  707. return FALSE;
  708. }
  709. switch ($which_elem) {
  710. case 'generic':
  711. $this->generic_font['font'] = $which_font;
  712. $this->generic_font['height'] = ImageFontHeight($which_font);
  713. $this->generic_font['width'] = ImageFontWidth($which_font);
  714. break;
  715. case 'title':
  716. $this->title_font['font'] = $which_font;
  717. $this->title_font['height'] = ImageFontHeight($which_font);
  718. $this->title_font['width'] = ImageFontWidth($which_font);
  719. break;
  720. case 'legend':
  721. $this->legend_font['font'] = $which_font;
  722. $this->legend_font['height'] = ImageFontHeight($which_font);
  723. $this->legend_font['width'] = ImageFontWidth($which_font);
  724. break;
  725. case 'x_label':
  726. $this->x_label_font['font'] = $which_font;
  727. $this->x_label_font['height'] = ImageFontHeight($which_font);
  728. $this->x_label_font['width'] = ImageFontWidth($which_font);
  729. break;
  730. case 'y_label':
  731. $this->y_label_font['font'] = $which_font;
  732. $this->y_label_font['height'] = ImageFontHeight($which_font);
  733. $this->y_label_font['width'] = ImageFontWidth($which_font);
  734. break;
  735. case 'x_title':
  736. $this->x_title_font['font'] = $which_font;
  737. $this->x_title_font['height'] = ImageFontHeight($which_font);
  738. $this->x_title_font['width'] = ImageFontWidth($which_font);
  739. break;
  740. case 'y_title':
  741. $this->y_title_font['font'] = $which_font;
  742. $this->y_title_font['height'] = ImageFontHeight($which_font);
  743. $this->y_title_font['width'] = ImageFontWidth($which_font);
  744. break;
  745. default:
  746. $this->DrawError("SetFont(): Unknown element '$which_elem' specified.");
  747. return FALSE;
  748. }
  749. return TRUE;
  750. }
  751. /*!
  752. * Returns an array with the size of the bounding box of an
  753. * arbitrarily placed (rotated) TrueType text string.
  754. */
  755. function TTFBBoxSize($size, $angle, $font, $string)
  756. {
  757. // First, assume angle < 90
  758. $arr = ImageTTFBBox($size, 0, $font, $string);
  759. $flat_width = $arr[2] - $arr[0];
  760. $flat_height = abs($arr[3] - $arr[5]);
  761. // Now the bounding box
  762. $angle = deg2rad($angle);
  763. $width = ceil(abs($flat_width*cos($angle) + $flat_height*sin($angle))); //Must be integer
  764. $height = ceil(abs($flat_width*sin($angle) + $flat_height*cos($angle))); //Must be integer
  765. return array($width, $height);
  766. }
  767. /*!
  768. * Draws a string of text. Horizontal and vertical alignment are relative to
  769. * to the drawing. That is: vertical text (90 deg) gets centered along y-axis
  770. * with v_align = 'center', and adjusted to the left of x-axis with h_align = 'right',
  771. *
  772. * \note Original multiple lines code submitted by Remi Ricard.
  773. * \note Original vertical code submitted by Marlin Viss.
  774. */
  775. function DrawText($which_font, $which_angle, $which_xpos, $which_ypos, $which_color, $which_text,
  776. $which_halign = 'left', $which_valign = 'bottom')
  777. {
  778. // TTF:
  779. if ($this->use_ttf) {
  780. $size = $this->TTFBBoxSize($which_font['size'], $which_angle, $which_font['font'], $which_text);
  781. $rads = deg2rad($which_angle);
  782. if ($which_valign == 'center')
  783. $which_ypos += $size[1]/2;
  784. if ($which_valign == 'bottom')
  785. $which_ypos += $size[1];
  786. if ($which_halign == 'center')
  787. $which_xpos -= ($size[0]/2) * cos($rads);
  788. if ($which_halign == 'left')
  789. $which_xpos += $size[0] * sin($rads);
  790. if ($which_halign == 'right')
  791. $which_xpos -= $size[0] * cos($rads);
  792. ImageTTFText($this->img, $which_font['size'], $which_angle,
  793. $which_xpos, $which_ypos, $which_color, $which_font['font'], $which_text);
  794. }
  795. // Fixed fonts:
  796. else {
  797. // Split the text by its lines, and count them
  798. $which_text = ereg_replace("\r", "", $which_text);
  799. $str = split("\n", $which_text);
  800. $nlines = count($str);
  801. $spacing = $this->line_spacing * ($nlines - 1);
  802. // Vertical text:
  803. // (Remember the alignment convention with vertical text)
  804. if ($which_angle == 90) {
  805. // The text goes around $which_xpos.
  806. if ($which_halign == 'center')
  807. $which_xpos -= ($nlines * ($which_font['height'] + $spacing))/2;
  808. // Left alignment requires no modification to $xpos...
  809. // Right-align it. $which_xpos designated the rightmost x coordinate.
  810. else if ($which_halign == 'right')
  811. $which_xpos += ($nlines * ($which_font['height'] + $spacing));
  812. $ypos = $which_ypos;
  813. for($i = 0; $i < $nlines; $i++) {
  814. // Center the text vertically around $which_ypos (each line)
  815. if ($which_valign == 'center')
  816. $ypos = $which_ypos + (strlen($str[$i]) * $which_font['width']) / 2;
  817. // Make the text finish (vertically) at $which_ypos
  818. if ($which_valign == 'bottom')
  819. $ypos = $which_ypos + strlen($str[$i]) * $which_font['width'];
  820. ImageStringUp($this->img, $which_font['font'],
  821. $i * ($which_font['height'] + $spacing) + $which_xpos,
  822. $ypos, $str[$i], $which_color);
  823. }
  824. }
  825. // Horizontal text:
  826. else {
  827. // The text goes above $which_ypos
  828. if ($which_valign == 'top')
  829. $which_ypos -= $nlines * ($which_font['height'] + $spacing);
  830. // The text is centered around $which_ypos
  831. if ($which_valign == 'center')
  832. $which_ypos -= ($nlines * ($which_font['height'] + $spacing))/2;
  833. // valign = 'bottom' requires no modification
  834. $xpos = $which_xpos;
  835. for($i = 0; $i < $nlines; $i++) {
  836. // center the text around $which_xpos
  837. if ($which_halign == 'center')
  838. $xpos = $which_xpos - (strlen($str[$i]) * $which_font['width'])/2;
  839. // make the text finish at $which_xpos
  840. if ($which_halign == 'right')
  841. $xpos = $which_xpos - strlen($str[$i]) * $which_font['width'];
  842. ImageString($this->img, $which_font['font'], $xpos,
  843. $i * ($which_font['height'] + $spacing) + $which_ypos,
  844. $str[$i], $which_color);
  845. }
  846. }
  847. }
  848. return TRUE;
  849. } // function DrawText()
  850. /////////////////////////////////////////////
  851. /////////// INPUT / OUTPUT CONTROL
  852. /////////////////////////////////////////////
  853. /*!
  854. * Sets output file format.
  855. */
  856. function SetFileFormat($format)
  857. {
  858. $asked = $this->CheckOption($format, 'jpg, png, gif, wbmp', __FUNCTION__);
  859. switch ($asked) {
  860. case 'jpg':
  861. if (imagetypes() & IMG_JPG)
  862. $this->file_format = 'jpg';
  863. return TRUE;
  864. break;
  865. case 'png':
  866. if (imagetypes() & IMG_PNG)
  867. $this->file_format = 'png';
  868. return TRUE;
  869. break;
  870. case 'gif':
  871. if (imagetypes() & IMG_GIF)
  872. $this->file_format = 'gif';
  873. return TRUE;
  874. break;
  875. case 'wbmp':
  876. if (imagetypes() & IMG_WBMP)
  877. $this->file_format = 'wbmp';
  878. return TRUE;
  879. break;
  880. default:
  881. $this->PrintError("SetFileFormat():File format '$format' not supported");
  882. return FALSE;
  883. }
  884. }
  885. /*!
  886. * Selects an input file to be used as graph background and scales or tiles this image
  887. * to fit the sizes.
  888. * \param input_file string Path to the file to be used (jpeg, png and gif accepted)
  889. * \param mode string 'centeredtile', 'tile', 'scale' (the image to the graph's size)
  890. */
  891. function SetBgImage($input_file, $mode='centeredtile')
  892. {
  893. $this->bgmode = $this->CheckOption($mode, 'tile, centeredtile, scale', __FUNCTION__);
  894. $this->bgimg = $input_file;
  895. }
  896. /*!
  897. * Selects an input file to be used as plot area background and scales or tiles this image
  898. * to fit the sizes.
  899. * \param input_file string Path to the file to be used (jpeg, png and gif accepted)
  900. * \param mode string 'centeredtile', 'tile', 'scale' (the image to the graph's size)
  901. */
  902. function SetPlotAreaBgImage($input_file, $mode='tile')
  903. {
  904. $this->plotbgmode = $this->CheckOption($mode, 'tile, centeredtile, scale', __FUNCTION__);
  905. $this->plotbgimg = $input_file;
  906. }
  907. /*!
  908. * Sets the name of the file to be used as output file.
  909. */
  910. function SetOutputFile($which_output_file)
  911. {
  912. $this->output_file = $which_output_file;
  913. return TRUE;
  914. }
  915. /*!
  916. * Sets the output image as 'inline', that is: no Content-Type headers are sent
  917. * to the browser. Needed if you want to embed the images.
  918. */
  919. function SetIsInline($which_ii)
  920. {
  921. $this->is_inline = (bool)$which_ii;
  922. return TRUE;
  923. }
  924. /*!
  925. * Performs the actual outputting of the generated graph, and
  926. * destroys the image resource.
  927. */
  928. function PrintImage()
  929. {
  930. // Browser cache stuff submitted by Thiemo Nagel
  931. if ( (! $this->browser_cache) && (! $this->is_inline)) {
  932. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  933. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
  934. header('Cache-Control: no-cache, must-revalidate');
  935. header('Pragma: no-cache');
  936. }
  937. switch($this->file_format) {
  938. case 'png':
  939. if (! $this->is_inline) {
  940. Header('Content-type: image/png');
  941. }
  942. if ($this->is_inline && $this->output_file != '') {
  943. ImagePng($this->img, $this->output_file);
  944. } else {
  945. ImagePng($this->img);
  946. }
  947. break;
  948. case 'jpg':
  949. if (! $this->is_inline) {
  950. Header('Content-type: image/jpeg');
  951. }
  952. if ($this->is_inline && $this->output_file != '') {
  953. ImageJPEG($this->img, $this->output_file);
  954. } else {
  955. ImageJPEG($this->img);
  956. }
  957. break;
  958. case 'gif':
  959. if (! $this->is_inline) {
  960. Header('Content-type: image/gif');
  961. }
  962. if ($this->is_inline && $this->output_file != '') {
  963. ImageGIF($this->img, $this->output_file);
  964. } else {
  965. ImageGIF($this->img);
  966. }
  967. break;
  968. case 'wbmp': // wireless bitmap, 2 bit.
  969. if (! $this->is_inline) {
  970. Header('Content-type: image/wbmp');
  971. }
  972. if ($this->is_inline && $this->output_file != '') {
  973. ImageWBMP($this->img, $this->output_file);
  974. } else {
  975. ImageWBMP($this->img);
  976. }
  977. break;
  978. default:
  979. $this->PrintError('PrintImage(): Please select an image type!');
  980. break;
  981. }
  982. return TRUE;
  983. }
  984. /*!
  985. * Prints an error message to stdout and dies
  986. */
  987. function PrintError($error_message)
  988. {
  989. echo "<p><b>Fatal error</b>: $error_message<p>";
  990. die;
  991. }
  992. /*!
  993. * Prints an error message inline into the generated image and draws it centered
  994. * around the given coordinates (defaults to center of the image)
  995. * \param error_message Message to be drawn
  996. * \param where_x X coordinate
  997. * \param where_y Y coordinate
  998. */
  999. function DrawError($error_message, $where_x = NULL, $where_y = NULL)
  1000. {
  1001. if (! $this->img)
  1002. $this->PrintError('_DrawError(): Warning, no image resource allocated. '.
  1003. 'The message to be written was: '.$error_message);
  1004. $ypos = (! $where_y) ? $this->image_height/2 : $where_y;
  1005. $xpos = (! $where_x) ? $this->image_width/2 : $where_x;
  1006. ImageRectangle($this->img, 0, 0, $this->image_width, $this->image_height,
  1007. ImageColorAllocate($this->img, 255, 255, 255));
  1008. $this->DrawText($this->generic_font, 0, $xpos, $ypos, ImageColorAllocate($this->img, 0, 0, 0),
  1009. $error_message, 'center', 'center');
  1010. $this->PrintImage();
  1011. exit;
  1012. // return TRUE;
  1013. }
  1014. /////////////////////////////////////////////
  1015. /////////// LABELS
  1016. /////////////////////////////////////////////
  1017. /*!
  1018. * Sets position for X labels following data points.
  1019. */
  1020. function SetXDataLabelPos($which_xdlp)
  1021. {
  1022. $this->x_data_label_pos = $this->CheckOption($which_xdlp, 'plotdown, plotup, both, xaxis, all, none',
  1023. __FUNCTION__);
  1024. if ($which_xdlp != 'none')
  1025. $this->x_tick_label_pos = 'none';
  1026. return TRUE;
  1027. }
  1028. /*!
  1029. * Sets position for Y labels following data points.
  1030. */
  1031. function SetYDataLabelPos($which_ydlp)
  1032. {
  1033. $this->y_data_label_pos = $this->CheckOption($which_ydlp, 'plotleft, plotright, both, yaxis, all, none',
  1034. __FUNCTION__);
  1035. if ($which_ydlp != 'none')
  1036. $this->y_tick_label_pos = 'none';
  1037. return TRUE;
  1038. }
  1039. /*!
  1040. * Sets position for X labels following ticks (hence grid lines)
  1041. */
  1042. function SetXTickLabelPos($which_xtlp)
  1043. {
  1044. $this->x_tick_label_pos = $this->CheckOption($which_xtlp, 'plotdown, plotup, both, xaxis, all, none',
  1045. __FUNCTION__);
  1046. if ($which_xtlp != 'none')
  1047. $this->x_data_label_pos = 'none';
  1048. return TRUE;
  1049. }
  1050. /*!
  1051. * Sets position for Y labels following ticks (hence grid lines)
  1052. */
  1053. function SetYTickLabelPos($which_ytlp)
  1054. {
  1055. $this->y_tick_label_pos = $this->CheckOption($which_ytlp, 'plotleft, plotright, both, yaxis, all, none',
  1056. __FUNCTION__);
  1057. if ($which_ytlp != 'none')
  1058. $this->y_data_label_pos = 'none';
  1059. return TRUE;
  1060. }
  1061. /*!
  1062. * Sets type for tick and data labels on X axis.
  1063. * \note 'title' type left for backwards compatibility.
  1064. */
  1065. function SetXLabelType($which_xlt)
  1066. {
  1067. $this->x_label_type = $this->CheckOption($which_xlt, 'data, time, title', __FUNCTION__);
  1068. return TRUE;
  1069. }
  1070. /*!
  1071. * Sets type for tick and data labels on Y axis.
  1072. */
  1073. function SetYLabelType($which_ylt)
  1074. {
  1075. $this->y_label_type = $this->CheckOption($which_ylt, 'data, time', __FUNCTION__);
  1076. return TRUE;
  1077. }
  1078. function SetXTimeFormat($which_xtf)
  1079. {
  1080. $this->x_time_format = $which_xtf;
  1081. return TRUE;
  1082. }
  1083. function SetYTimeFormat($which_ytf)
  1084. {
  1085. $this->y_time_format = $which_ytf;
  1086. return TRUE;
  1087. }
  1088. function SetXLabelAngle($which_xla)
  1089. {
  1090. $this->x_label_angle = $which_xla;
  1091. return TRUE;
  1092. }
  1093. function SetYLabelAngle($which_yla)
  1094. {
  1095. $this->y_label_angle = $which_yla;
  1096. return TRUE;
  1097. }
  1098. /////////////////////////////////////////////
  1099. /////////// MISC
  1100. /////////////////////////////////////////////
  1101. /*!
  1102. * Checks the valididy of an option.
  1103. * \param which_opt String to check.
  1104. * \param which_acc String of accepted choices.
  1105. * \param which_func Name of the calling function, for error messages.
  1106. * \note If checking everywhere for correctness slows things down, we could provide a
  1107. * child class overriding every Set...() method which uses CheckOption(). Those new
  1108. * methods could proceed in the unsafe but faster way.
  1109. */
  1110. function CheckOption($which_opt, $which_acc, $which_func)
  1111. {
  1112. $asked = trim($which_opt);
  1113. // FIXME: this for backward compatibility, as eregi() fails with empty strings.
  1114. if ($asked == '')
  1115. return '';
  1116. $asked = strtolower($asked);
  1117. if (@ eregi($asked, $which_acc)) {
  1118. return $asked;
  1119. } else {
  1120. $this->DrawError("$which_func(): '$which_opt' not in available choices: '$which_acc'.");
  1121. return NULL;
  1122. }
  1123. }
  1124. /*!
  1125. * \note Submitted by Thiemo Nagel
  1126. */
  1127. function SetBrowserCache($which_browser_cache)
  1128. {
  1129. $this->browser_cache = $which_browser_cache;
  1130. return TRUE;
  1131. }
  1132. /*!
  1133. * Whether to show the final image or not
  1134. */
  1135. function SetPrintImage($which_pi)
  1136. {
  1137. $this->print_image = $which_pi;
  1138. return TRUE;
  1139. }
  1140. /*!
  1141. * Sets the graph's legend. If argument is not an array, appends it to the legend.
  1142. */
  1143. function SetLegend($which_leg)
  1144. {
  1145. if (is_array($which_leg)) { // use array
  1146. $this->legend = $which_leg;
  1147. return TRUE;
  1148. } else if (! is_null($which_leg)) { // append string
  1149. $this->legend[] = $which_leg;
  1150. return TRUE;
  1151. } else {
  1152. $this->DrawError("SetLegend(): argument must not be null.");
  1153. return FALSE;
  1154. }
  1155. }
  1156. /*!
  1157. * Specifies the absolute (relative to image's up/left corner) position
  1158. * of the legend's upper/leftmost corner.
  1159. * $which_type not yet used (TODO)
  1160. */
  1161. function SetLegendPixels($which_x, $which_y, $which_type=NULL)
  1162. {
  1163. $this->legend_x_pos = $which_x;
  1164. $this->legend_y_pos = $which_y;
  1165. return TRUE;
  1166. }
  1167. /*!
  1168. * Specifies the relative (to graph's origin) position of the legend's
  1169. * upper/leftmost corner. MUST be called after scales are set up.
  1170. * $which_type not yet used (TODO)
  1171. */
  1172. function SetLegendWorld($which_x, $which_y, $which_type=NULL)
  1173. {
  1174. if (! isset($this->scale_is_set))
  1175. $this->CalcTranslation();
  1176. $this->legend_x_pos = $this->xtr($which_x);
  1177. $this->legend_y_pos = $this->ytr($which_y);
  1178. return TRUE;
  1179. }
  1180. /*!
  1181. * Accepted values are: left, sides, none, full
  1182. */
  1183. function SetPlotBorderType($pbt)
  1184. {
  1185. $this->plot_border_type = $this->CheckOption($pbt, 'left, sides, none, full', __FUNCTION__);
  1186. }
  1187. /*!
  1188. * Accepted values are: raised, plain
  1189. */
  1190. function SetImageBorderType($sibt)
  1191. {
  1192. $this->image_border_type = $this->CheckOption($sibt, 'raised, plain', __FUNCTION__);
  1193. }
  1194. /*!
  1195. * \param dpab bool
  1196. */
  1197. function SetDrawPlotAreaBackground($dpab)
  1198. {
  1199. $this->draw_plot_area_background = (bool)$dpab;
  1200. }
  1201. /*!
  1202. * \param dyg bool
  1203. */
  1204. function SetDrawYGrid($dyg)
  1205. {
  1206. $this->draw_y_grid = (bool)$dyg;
  1207. return TRUE;
  1208. }
  1209. /*!
  1210. * \param dxg bool
  1211. */
  1212. function SetDrawXGrid($dxg)
  1213. {
  1214. $this->draw_x_grid = (bool)$dxg;
  1215. return TRUE;
  1216. }
  1217. /*!
  1218. * \param ddg bool
  1219. */
  1220. function SetDrawDashedGrid($ddg)
  1221. {
  1222. $this->dashed_grid = (bool)$ddg;
  1223. return TRUE;
  1224. }
  1225. /*!
  1226. * \param dxdl bool
  1227. */
  1228. function SetDrawXDataLabelLine

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