PageRenderTime 89ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/www/wptmonitor/jpgraph/jpgraph.php

http://webpagetest.googlecode.com/
PHP | 6391 lines | 4808 code | 752 blank | 831 comment | 1046 complexity | 8ce79e4ee26b013a10715e97d37c2398 MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, GPL-3.0, LGPL-3.0, MIT, BSD-3-Clause, ISC, LGPL-2.1
  1. <?php
  2. //=======================================================================
  3. // File: JPGRAPH.PHP
  4. // Description: PHP Graph Plotting library. Base module.
  5. // Created: 2001-01-08
  6. // Ver: $Id: jpgraph.php,v 1.1 2009/04/22 16:39:35 pc_geek Exp $
  7. //
  8. // Copyright (c) Aditus Consulting. All rights reserved.
  9. //========================================================================
  10. require_once('jpg-config.inc.php');
  11. require_once('jpgraph_gradient.php');
  12. require_once('jpgraph_errhandler.inc.php');
  13. require_once('jpgraph_ttf.inc.php');
  14. // Version info
  15. DEFINE('JPG_VERSION','2.3.3');
  16. // Minimum required PHP version
  17. DEFINE('MIN_PHPVERSION','5.1.0');
  18. // Should the image be a truecolor image?
  19. DEFINE('USE_TRUECOLOR',true);
  20. //------------------------------------------------------------------------
  21. // Automatic settings of path for cache and font directory
  22. // if they have not been previously specified
  23. //------------------------------------------------------------------------
  24. if(USE_CACHE) {
  25. if (!defined('CACHE_DIR')) {
  26. if ( strstr( PHP_OS, 'WIN') ) {
  27. if( empty($_SERVER['TEMP']) ) {
  28. $t = new ErrMsgText();
  29. $msg = $t->Get(11,$file,$lineno);
  30. die($msg);
  31. }
  32. else {
  33. DEFINE('CACHE_DIR', $_SERVER['TEMP'] . '/');
  34. }
  35. } else {
  36. DEFINE('CACHE_DIR','/tmp/jpgraph_cache/');
  37. }
  38. }
  39. }
  40. elseif( !defined('CACHE_DIR') ) {
  41. DEFINE('CACHE_DIR', '');
  42. }
  43. if (!defined('TTF_DIR')) {
  44. if (strstr( PHP_OS, 'WIN') ) {
  45. $sroot = getenv('SystemRoot');
  46. if( empty($sroot) ) {
  47. $t = new ErrMsgText();
  48. $msg = $t->Get(12,$file,$lineno);
  49. die($msg);
  50. }
  51. else {
  52. DEFINE('TTF_DIR', $sroot.'/fonts/');
  53. }
  54. } else {
  55. DEFINE('TTF_DIR','/usr/X11R6/lib/X11/fonts/truetype/');
  56. }
  57. }
  58. if (!defined('MBTTF_DIR')) {
  59. DEFINE('MBTTF_DIR','/usr/share/fonts/ja/TrueType/');
  60. }
  61. //------------------------------------------------------------------
  62. // Constants which are used as parameters for the method calls
  63. //------------------------------------------------------------------
  64. // Tick density
  65. DEFINE("TICKD_DENSE",1);
  66. DEFINE("TICKD_NORMAL",2);
  67. DEFINE("TICKD_SPARSE",3);
  68. DEFINE("TICKD_VERYSPARSE",4);
  69. // Side for ticks and labels.
  70. DEFINE("SIDE_LEFT",-1);
  71. DEFINE("SIDE_RIGHT",1);
  72. DEFINE("SIDE_DOWN",-1);
  73. DEFINE("SIDE_BOTTOM",-1);
  74. DEFINE("SIDE_UP",1);
  75. DEFINE("SIDE_TOP",1);
  76. // Legend type stacked vertical or horizontal
  77. DEFINE("LEGEND_VERT",0);
  78. DEFINE("LEGEND_HOR",1);
  79. // Mark types for plot marks
  80. DEFINE("MARK_SQUARE",1);
  81. DEFINE("MARK_UTRIANGLE",2);
  82. DEFINE("MARK_DTRIANGLE",3);
  83. DEFINE("MARK_DIAMOND",4);
  84. DEFINE("MARK_CIRCLE",5);
  85. DEFINE("MARK_FILLEDCIRCLE",6);
  86. DEFINE("MARK_CROSS",7);
  87. DEFINE("MARK_STAR",8);
  88. DEFINE("MARK_X",9);
  89. DEFINE("MARK_LEFTTRIANGLE",10);
  90. DEFINE("MARK_RIGHTTRIANGLE",11);
  91. DEFINE("MARK_FLASH",12);
  92. DEFINE("MARK_IMG",13);
  93. DEFINE("MARK_FLAG1",14);
  94. DEFINE("MARK_FLAG2",15);
  95. DEFINE("MARK_FLAG3",16);
  96. DEFINE("MARK_FLAG4",17);
  97. // Builtin images
  98. DEFINE("MARK_IMG_PUSHPIN",50);
  99. DEFINE("MARK_IMG_SPUSHPIN",50);
  100. DEFINE("MARK_IMG_LPUSHPIN",51);
  101. DEFINE("MARK_IMG_DIAMOND",52);
  102. DEFINE("MARK_IMG_SQUARE",53);
  103. DEFINE("MARK_IMG_STAR",54);
  104. DEFINE("MARK_IMG_BALL",55);
  105. DEFINE("MARK_IMG_SBALL",55);
  106. DEFINE("MARK_IMG_MBALL",56);
  107. DEFINE("MARK_IMG_LBALL",57);
  108. DEFINE("MARK_IMG_BEVEL",58);
  109. // Inline defines
  110. DEFINE("INLINE_YES",1);
  111. DEFINE("INLINE_NO",0);
  112. // Format for background images
  113. DEFINE("BGIMG_FILLPLOT",1);
  114. DEFINE("BGIMG_FILLFRAME",2);
  115. DEFINE("BGIMG_COPY",3);
  116. DEFINE("BGIMG_CENTER",4);
  117. // Depth of objects
  118. DEFINE("DEPTH_BACK",0);
  119. DEFINE("DEPTH_FRONT",1);
  120. // Direction
  121. DEFINE("VERTICAL",1);
  122. DEFINE("HORIZONTAL",0);
  123. // Axis styles for scientific style axis
  124. DEFINE('AXSTYLE_SIMPLE',1);
  125. DEFINE('AXSTYLE_BOXIN',2);
  126. DEFINE('AXSTYLE_BOXOUT',3);
  127. DEFINE('AXSTYLE_YBOXIN',4);
  128. DEFINE('AXSTYLE_YBOXOUT',5);
  129. // Style for title backgrounds
  130. DEFINE('TITLEBKG_STYLE1',1);
  131. DEFINE('TITLEBKG_STYLE2',2);
  132. DEFINE('TITLEBKG_STYLE3',3);
  133. DEFINE('TITLEBKG_FRAME_NONE',0);
  134. DEFINE('TITLEBKG_FRAME_FULL',1);
  135. DEFINE('TITLEBKG_FRAME_BOTTOM',2);
  136. DEFINE('TITLEBKG_FRAME_BEVEL',3);
  137. DEFINE('TITLEBKG_FILLSTYLE_HSTRIPED',1);
  138. DEFINE('TITLEBKG_FILLSTYLE_VSTRIPED',2);
  139. DEFINE('TITLEBKG_FILLSTYLE_SOLID',3);
  140. // Style for background gradient fills
  141. DEFINE('BGRAD_FRAME',1);
  142. DEFINE('BGRAD_MARGIN',2);
  143. DEFINE('BGRAD_PLOT',3);
  144. // Width of tab titles
  145. DEFINE('TABTITLE_WIDTHFIT',0);
  146. DEFINE('TABTITLE_WIDTHFULL',-1);
  147. // Defines for 3D skew directions
  148. DEFINE('SKEW3D_UP',0);
  149. DEFINE('SKEW3D_DOWN',1);
  150. DEFINE('SKEW3D_LEFT',2);
  151. DEFINE('SKEW3D_RIGHT',3);
  152. // Line styles
  153. DEFINE('LINESTYLE_SOLID',1);
  154. DEFINE('LINESTYLE_DOTTED',2);
  155. DEFINE('LINESTYLE_DASHED',3);
  156. DEFINE('LINESTYLE_LONGDASH',4);
  157. // For internal use only
  158. DEFINE("_JPG_DEBUG",false);
  159. DEFINE("_FORCE_IMGTOFILE",false);
  160. DEFINE("_FORCE_IMGDIR",'/tmp/jpgimg/');
  161. require_once('gd_image.inc.php');
  162. function CheckPHPVersion($aMinVersion)
  163. {
  164. list($majorC, $minorC, $editC) = split('[/.-]', PHP_VERSION);
  165. list($majorR, $minorR, $editR) = split('[/.-]', $aMinVersion);
  166. if ($majorC != $majorR) return false;
  167. if ($majorC < $majorR) return false;
  168. // same major - check ninor
  169. if ($minorC > $minorR) return true;
  170. if ($minorC < $minorR) return false;
  171. // and same minor
  172. if ($editC >= $editR) return true;
  173. return true;
  174. }
  175. //
  176. // Make sure PHP version is high enough
  177. //
  178. if( !CheckPHPVersion(MIN_PHPVERSION) ) {
  179. JpGraphError::RaiseL(13,PHP_VERSION,MIN_PHPVERSION);
  180. die();
  181. }
  182. //
  183. // Make GD sanity check
  184. //
  185. if( !function_exists("imagetypes") || !function_exists('imagecreatefromstring') ) {
  186. JpGraphError::RaiseL(25001);
  187. //("This PHP installation is not configured with the GD library. Please recompile PHP with GD support to run JpGraph. (Neither function imagetypes() nor imagecreatefromstring() does exist)");
  188. }
  189. //
  190. // Setup PHP error handler
  191. //
  192. function _phpErrorHandler($errno,$errmsg,$filename, $linenum, $vars) {
  193. // Respect current error level
  194. if( $errno & error_reporting() ) {
  195. JpGraphError::RaiseL(25003,basename($filename),$linenum,$errmsg);
  196. }
  197. }
  198. if( INSTALL_PHP_ERR_HANDLER ) {
  199. set_error_handler("_phpErrorHandler");
  200. }
  201. //
  202. //Check if there were any warnings, perhaps some wrong includes by the
  203. //user
  204. //
  205. if( isset($GLOBALS['php_errormsg']) && CATCH_PHPERRMSG &&
  206. !preg_match('/|Deprecated|/i', $GLOBALS['php_errormsg']) ) {
  207. JpGraphError::RaiseL(25004,$GLOBALS['php_errormsg']);
  208. }
  209. // Useful mathematical function
  210. function sign($a) {return $a >= 0 ? 1 : -1;}
  211. // Utility function to generate an image name based on the filename we
  212. // are running from and assuming we use auto detection of graphic format
  213. // (top level), i.e it is safe to call this function
  214. // from a script that uses JpGraph
  215. function GenImgName() {
  216. // Determine what format we should use when we save the images
  217. $supported = imagetypes();
  218. if( $supported & IMG_PNG ) $img_format="png";
  219. elseif( $supported & IMG_GIF ) $img_format="gif";
  220. elseif( $supported & IMG_JPG ) $img_format="jpeg";
  221. elseif( $supported & IMG_WBMP ) $img_format="wbmp";
  222. elseif( $supported & IMG_XPM ) $img_format="xpm";
  223. if( !isset($_SERVER['PHP_SELF']) )
  224. JpGraphError::RaiseL(25005);
  225. //(" Can't access PHP_SELF, PHP global variable. You can't run PHP from command line if you want to use the 'auto' naming of cache or image files.");
  226. $fname = basename($_SERVER['PHP_SELF']);
  227. if( !empty($_SERVER['QUERY_STRING']) ) {
  228. $q = @$_SERVER['QUERY_STRING'];
  229. $fname .= '_'.preg_replace("/\W/", "_", $q).'.'.$img_format;
  230. }
  231. else {
  232. $fname = substr($fname,0,strlen($fname)-4).'.'.$img_format;
  233. }
  234. return $fname;
  235. }
  236. //===================================================
  237. // CLASS JpgTimer
  238. // Description: General timing utility class to handle
  239. // time measurement of generating graphs. Multiple
  240. // timers can be started.
  241. //===================================================
  242. class JpgTimer {
  243. private $start, $idx;
  244. //---------------
  245. // CONSTRUCTOR
  246. function JpgTimer() {
  247. $this->idx=0;
  248. }
  249. //---------------
  250. // PUBLIC METHODS
  251. // Push a new timer start on stack
  252. function Push() {
  253. list($ms,$s)=explode(" ",microtime());
  254. $this->start[$this->idx++]=floor($ms*1000) + 1000*$s;
  255. }
  256. // Pop the latest timer start and return the diff with the
  257. // current time
  258. function Pop() {
  259. assert($this->idx>0);
  260. list($ms,$s)=explode(" ",microtime());
  261. $etime=floor($ms*1000) + (1000*$s);
  262. $this->idx--;
  263. return $etime-$this->start[$this->idx];
  264. }
  265. } // Class
  266. $gJpgBrandTiming = BRAND_TIMING;
  267. //===================================================
  268. // CLASS DateLocale
  269. // Description: Hold localized text used in dates
  270. //===================================================
  271. class DateLocale {
  272. public $iLocale = 'C'; // environmental locale be used by default
  273. private $iDayAbb = null, $iShortDay = null, $iShortMonth = null, $iMonthName = null;
  274. //---------------
  275. // CONSTRUCTOR
  276. function DateLocale() {
  277. settype($this->iDayAbb, 'array');
  278. settype($this->iShortDay, 'array');
  279. settype($this->iShortMonth, 'array');
  280. settype($this->iMonthName, 'array');
  281. $this->Set('C');
  282. }
  283. //---------------
  284. // PUBLIC METHODS
  285. function Set($aLocale) {
  286. if ( in_array($aLocale, array_keys($this->iDayAbb)) ){
  287. $this->iLocale = $aLocale;
  288. return TRUE; // already cached nothing else to do!
  289. }
  290. $pLocale = setlocale(LC_TIME, 0); // get current locale for LC_TIME
  291. if (is_array($aLocale)) {
  292. foreach ($aLocale as $loc) {
  293. $res = @setlocale(LC_TIME, $loc);
  294. if ( $res ) {
  295. $aLocale = $loc;
  296. break;
  297. }
  298. }
  299. }
  300. else {
  301. $res = @setlocale(LC_TIME, $aLocale);
  302. }
  303. if ( ! $res ){
  304. JpGraphError::RaiseL(25007,$aLocale);
  305. //("You are trying to use the locale ($aLocale) which your PHP installation does not support. Hint: Use '' to indicate the default locale for this geographic region.");
  306. return FALSE;
  307. }
  308. $this->iLocale = $aLocale;
  309. for ( $i = 0, $ofs = 0 - strftime('%w'); $i < 7; $i++, $ofs++ ){
  310. $day = strftime('%a', strtotime("$ofs day"));
  311. $day[0] = strtoupper($day[0]);
  312. $this->iDayAbb[$aLocale][]= $day[0];
  313. $this->iShortDay[$aLocale][]= $day;
  314. }
  315. for($i=1; $i<=12; ++$i) {
  316. list($short ,$full) = explode('|', strftime("%b|%B",strtotime("2001-$i-01")));
  317. $this->iShortMonth[$aLocale][] = ucfirst($short);
  318. $this->iMonthName [$aLocale][] = ucfirst($full);
  319. }
  320. setlocale(LC_TIME, $pLocale);
  321. return TRUE;
  322. }
  323. function GetDayAbb() {
  324. return $this->iDayAbb[$this->iLocale];
  325. }
  326. function GetShortDay() {
  327. return $this->iShortDay[$this->iLocale];
  328. }
  329. function GetShortMonth() {
  330. return $this->iShortMonth[$this->iLocale];
  331. }
  332. function GetShortMonthName($aNbr) {
  333. return $this->iShortMonth[$this->iLocale][$aNbr];
  334. }
  335. function GetLongMonthName($aNbr) {
  336. return $this->iMonthName[$this->iLocale][$aNbr];
  337. }
  338. function GetMonth() {
  339. return $this->iMonthName[$this->iLocale];
  340. }
  341. }
  342. $gDateLocale = new DateLocale();
  343. $gJpgDateLocale = new DateLocale();
  344. //=======================================================
  345. // CLASS Footer
  346. // Description: Encapsulates the footer line in the Graph
  347. //=======================================================
  348. class Footer {
  349. public $iLeftMargin = 3, $iRightMargin = 3, $iBottomMargin = 3 ;
  350. public $left,$center,$right;
  351. function Footer() {
  352. $this->left = new Text();
  353. $this->left->ParagraphAlign('left');
  354. $this->center = new Text();
  355. $this->center->ParagraphAlign('center');
  356. $this->right = new Text();
  357. $this->right->ParagraphAlign('right');
  358. }
  359. function SetMargin($aLeft=3,$aRight=3,$aBottom=3) {
  360. $this->iLeftMargin = $aLeft;
  361. $this->iRightMargin = $aRight;
  362. $this->iBottomMargin = $aBottom;
  363. }
  364. function Stroke($aImg) {
  365. $y = $aImg->height - $this->iBottomMargin;
  366. $x = $this->iLeftMargin;
  367. $this->left->Align('left','bottom');
  368. $this->left->Stroke($aImg,$x,$y);
  369. $x = ($aImg->width - $this->iLeftMargin - $this->iRightMargin)/2;
  370. $this->center->Align('center','bottom');
  371. $this->center->Stroke($aImg,$x,$y);
  372. $x = $aImg->width - $this->iRightMargin;
  373. $this->right->Align('right','bottom');
  374. $this->right->Stroke($aImg,$x,$y);
  375. }
  376. }
  377. //===================================================
  378. // CLASS Graph
  379. // Description: Main class to handle graphs
  380. //===================================================
  381. class Graph {
  382. public $cache=null; // Cache object (singleton)
  383. public $img=null; // Img object (singleton)
  384. public $plots=array(); // Array of all plot object in the graph (for Y 1 axis)
  385. public $y2plots=array();// Array of all plot object in the graph (for Y 2 axis)
  386. public $ynplots=array();
  387. public $xscale=null; // X Scale object (could be instance of LinearScale or LogScale
  388. public $yscale=null,$y2scale=null, $ynscale=array();
  389. public $iIcons = array(); // Array of Icons to add to
  390. public $cache_name; // File name to be used for the current graph in the cache directory
  391. public $xgrid=null; // X Grid object (linear or logarithmic)
  392. public $ygrid=null,$y2grid=null; //dito for Y
  393. public $doframe=true,$frame_color=array(0,0,0), $frame_weight=1; // Frame around graph
  394. public $boxed=false, $box_color=array(0,0,0), $box_weight=1; // Box around plot area
  395. public $doshadow=false,$shadow_width=4,$shadow_color=array(102,102,102); // Shadow for graph
  396. public $xaxis=null; // X-axis (instane of Axis class)
  397. public $yaxis=null, $y2axis=null, $ynaxis=array(); // Y axis (instance of Axis class)
  398. public $margin_color=array(200,200,200); // Margin color of graph
  399. public $plotarea_color=array(255,255,255); // Plot area color
  400. public $title,$subtitle,$subsubtitle; // Title and subtitle(s) text object
  401. public $axtype="linlin"; // Type of axis
  402. public $xtick_factor,$ytick_factor; // Factor to determine the maximum number of ticks depending on the plot width
  403. public $texts=null, $y2texts=null; // Text object to ge shown in the graph
  404. public $lines=null, $y2lines=null;
  405. public $bands=null, $y2bands=null;
  406. public $text_scale_off=0, $text_scale_abscenteroff=-1; // Text scale in fractions and for centering bars
  407. public $background_image="",$background_image_type=-1,$background_image_format="png";
  408. public $background_image_bright=0,$background_image_contr=0,$background_image_sat=0;
  409. public $image_bright=0, $image_contr=0, $image_sat=0;
  410. public $inline;
  411. public $showcsim=0,$csimcolor="red"; //debug stuff, draw the csim boundaris on the image if <>0
  412. public $grid_depth=DEPTH_BACK; // Draw grid under all plots as default
  413. public $iAxisStyle = AXSTYLE_SIMPLE;
  414. public $iCSIMdisplay=false,$iHasStroked = false;
  415. public $footer;
  416. public $csimcachename = '', $csimcachetimeout = 0, $iCSIMImgAlt='';
  417. public $iDoClipping = false;
  418. public $y2orderback=true;
  419. public $tabtitle;
  420. public $bkg_gradtype=-1,$bkg_gradstyle=BGRAD_MARGIN;
  421. public $bkg_gradfrom='navy', $bkg_gradto='silver';
  422. public $titlebackground = false;
  423. public $titlebackground_color = 'lightblue',
  424. $titlebackground_style = 1,
  425. $titlebackground_framecolor = 'blue',
  426. $titlebackground_framestyle = 2,
  427. $titlebackground_frameweight = 1,
  428. $titlebackground_bevelheight = 3 ;
  429. public $titlebkg_fillstyle=TITLEBKG_FILLSTYLE_SOLID;
  430. public $titlebkg_scolor1='black',$titlebkg_scolor2='white';
  431. public $framebevel = false, $framebeveldepth = 2 ;
  432. public $framebevelborder = false, $framebevelbordercolor='black';
  433. public $framebevelcolor1='white@0.4', $framebevelcolor2='black@0.4';
  434. public $background_image_mix=100;
  435. public $background_cflag = '';
  436. public $background_cflag_type = BGIMG_FILLPLOT;
  437. public $background_cflag_mix = 100;
  438. public $iImgTrans=false,
  439. $iImgTransHorizon = 100,$iImgTransSkewDist=150,
  440. $iImgTransDirection = 1, $iImgTransMinSize = true,
  441. $iImgTransFillColor='white',$iImgTransHighQ=false,
  442. $iImgTransBorder=false,$iImgTransHorizonPos=0.5;
  443. public $legend;
  444. protected $iYAxisDeltaPos=50;
  445. protected $iIconDepth=DEPTH_BACK;
  446. protected $iAxisLblBgType = 0,
  447. $iXAxisLblBgFillColor = 'lightgray', $iXAxisLblBgColor = 'black',
  448. $iYAxisLblBgFillColor = 'lightgray', $iYAxisLblBgColor = 'black';
  449. protected $iTables=NULL;
  450. //---------------
  451. // CONSTRUCTOR
  452. // aWIdth Width in pixels of image
  453. // aHeight Height in pixels of image
  454. // aCachedName Name for image file in cache directory
  455. // aTimeOut Timeout in minutes for image in cache
  456. // aInline If true the image is streamed back in the call to Stroke()
  457. // If false the image is just created in the cache
  458. function Graph($aWidth=300,$aHeight=200,$aCachedName="",$aTimeOut=0,$aInline=true) {
  459. GLOBAL $gJpgBrandTiming;
  460. // If timing is used create a new timing object
  461. if( $gJpgBrandTiming ) {
  462. global $tim;
  463. $tim = new JpgTimer();
  464. $tim->Push();
  465. }
  466. if( !is_numeric($aWidth) || !is_numeric($aHeight) ) {
  467. JpGraphError::RaiseL(25008);//('Image width/height argument in Graph::Graph() must be numeric');
  468. }
  469. // Automatically generate the image file name based on the name of the script that
  470. // generates the graph
  471. if( $aCachedName=="auto" )
  472. $aCachedName=GenImgName();
  473. // Should the image be streamed back to the browser or only to the cache?
  474. $this->inline=$aInline;
  475. $this->img = new RotImage($aWidth,$aHeight);
  476. $this->cache = new ImgStreamCache($this->img);
  477. $this->cache->SetTimeOut($aTimeOut);
  478. $this->title = new Text();
  479. $this->title->ParagraphAlign('center');
  480. $this->title->SetFont(FF_FONT2,FS_BOLD);
  481. $this->title->SetMargin(3);
  482. $this->title->SetAlign('center');
  483. $this->subtitle = new Text();
  484. $this->subtitle->ParagraphAlign('center');
  485. $this->subtitle->SetMargin(2);
  486. $this->subtitle->SetAlign('center');
  487. $this->subsubtitle = new Text();
  488. $this->subsubtitle->ParagraphAlign('center');
  489. $this->subsubtitle->SetMargin(2);
  490. $this->subsubtitle->SetAlign('center');
  491. $this->legend = new Legend();
  492. $this->footer = new Footer();
  493. // Window doesn't like '?' in the file name so replace it with an '_'
  494. $aCachedName = str_replace("?","_",$aCachedName);
  495. // If the cached version exist just read it directly from the
  496. // cache, stream it back to browser and exit
  497. if( $aCachedName!="" && READ_CACHE && $aInline )
  498. if( $this->cache->GetAndStream($aCachedName) ) {
  499. exit();
  500. }
  501. $this->cache_name = $aCachedName;
  502. $this->SetTickDensity(); // Normal density
  503. $this->tabtitle = new GraphTabTitle();
  504. }
  505. //---------------
  506. // PUBLIC METHODS
  507. // Enable final image perspective transformation
  508. function Set3DPerspective($aDir=1,$aHorizon=100,$aSkewDist=120,$aQuality=false,$aFillColor='#FFFFFF',$aBorder=false,$aMinSize=true,$aHorizonPos=0.5) {
  509. $this->iImgTrans = true;
  510. $this->iImgTransHorizon = $aHorizon;
  511. $this->iImgTransSkewDist= $aSkewDist;
  512. $this->iImgTransDirection = $aDir;
  513. $this->iImgTransMinSize = $aMinSize;
  514. $this->iImgTransFillColor=$aFillColor;
  515. $this->iImgTransHighQ=$aQuality;
  516. $this->iImgTransBorder=$aBorder;
  517. $this->iImgTransHorizonPos=$aHorizonPos;
  518. }
  519. // Set Image format and optional quality
  520. function SetImgFormat($aFormat,$aQuality=75) {
  521. $this->img->SetImgFormat($aFormat,$aQuality);
  522. }
  523. // Should the grid be in front or back of the plot?
  524. function SetGridDepth($aDepth) {
  525. $this->grid_depth=$aDepth;
  526. }
  527. function SetIconDepth($aDepth) {
  528. $this->iIconDepth=$aDepth;
  529. }
  530. // Specify graph angle 0-360 degrees.
  531. function SetAngle($aAngle) {
  532. $this->img->SetAngle($aAngle);
  533. }
  534. function SetAlphaBlending($aFlg=true) {
  535. $this->img->SetAlphaBlending($aFlg);
  536. }
  537. // Shortcut to image margin
  538. function SetMargin($lm,$rm,$tm,$bm) {
  539. $this->img->SetMargin($lm,$rm,$tm,$bm);
  540. }
  541. function SetY2OrderBack($aBack=true) {
  542. $this->y2orderback = $aBack;
  543. }
  544. // Rotate the graph 90 degrees and set the margin
  545. // when we have done a 90 degree rotation
  546. function Set90AndMargin($lm=0,$rm=0,$tm=0,$bm=0) {
  547. $lm = $lm ==0 ? floor(0.2 * $this->img->width) : $lm ;
  548. $rm = $rm ==0 ? floor(0.1 * $this->img->width) : $rm ;
  549. $tm = $tm ==0 ? floor(0.2 * $this->img->height) : $tm ;
  550. $bm = $bm ==0 ? floor(0.1 * $this->img->height) : $bm ;
  551. $adj = ($this->img->height - $this->img->width)/2;
  552. $this->img->SetMargin($tm-$adj,$bm-$adj,$rm+$adj,$lm+$adj);
  553. $this->img->SetCenter(floor($this->img->width/2),floor($this->img->height/2));
  554. $this->SetAngle(90);
  555. if( empty($this->yaxis) || empty($this->xaxis) ) {
  556. JpgraphError::RaiseL(25009);//('You must specify what scale to use with a call to Graph::SetScale()');
  557. }
  558. $this->xaxis->SetLabelAlign('right','center');
  559. $this->yaxis->SetLabelAlign('center','bottom');
  560. }
  561. function SetClipping($aFlg=true) {
  562. $this->iDoClipping = $aFlg ;
  563. }
  564. // Add a plot object to the graph
  565. function Add($aPlot) {
  566. if( $aPlot == null )
  567. JpGraphError::RaiseL(25010);//("Graph::Add() You tried to add a null plot to the graph.");
  568. if( is_array($aPlot) && count($aPlot) > 0 )
  569. $cl = $aPlot[0];
  570. else
  571. $cl = $aPlot;
  572. if( $cl instanceof Text )
  573. $this->AddText($aPlot);
  574. elseif( $cl instanceof PlotLine )
  575. $this->AddLine($aPlot);
  576. elseif( class_exists('PlotBand',false) && ($cl instanceof PlotBand) )
  577. $this->AddBand($aPlot);
  578. elseif( class_exists('IconPlot',false) && ($cl instanceof IconPlot) )
  579. $this->AddIcon($aPlot);
  580. elseif( class_exists('GTextTable',false) && ($cl instanceof GTextTable) )
  581. $this->AddTable($aPlot);
  582. else
  583. $this->plots[] = $aPlot;
  584. }
  585. function AddTable($aTable) {
  586. if( is_array($aTable) ) {
  587. for($i=0; $i < count($aTable); ++$i )
  588. $this->iTables[]=$aTable[$i];
  589. }
  590. else {
  591. $this->iTables[] = $aTable ;
  592. }
  593. }
  594. function AddIcon($aIcon) {
  595. if( is_array($aIcon) ) {
  596. for($i=0; $i < count($aIcon); ++$i )
  597. $this->iIcons[]=$aIcon[$i];
  598. }
  599. else {
  600. $this->iIcons[] = $aIcon ;
  601. }
  602. }
  603. // Add plot to second Y-scale
  604. function AddY2($aPlot) {
  605. if( $aPlot == null )
  606. JpGraphError::RaiseL(25011);//("Graph::AddY2() You tried to add a null plot to the graph.");
  607. if( is_array($aPlot) && count($aPlot) > 0 )
  608. $cl = $aPlot[0];
  609. else
  610. $cl = $aPlot;
  611. if( $cl instanceof Text )
  612. $this->AddText($aPlot,true);
  613. elseif( $cl instanceof PlotLine )
  614. $this->AddLine($aPlot,true);
  615. elseif( class_exists('PlotBand',false) && ($cl instanceof PlotBand) )
  616. $this->AddBand($aPlot,true);
  617. else
  618. $this->y2plots[] = $aPlot;
  619. }
  620. // Add plot to the extra Y-axises
  621. function AddY($aN,$aPlot) {
  622. if( $aPlot == null )
  623. JpGraphError::RaiseL(25012);//("Graph::AddYN() You tried to add a null plot to the graph.");
  624. if( is_array($aPlot) && count($aPlot) > 0 )
  625. $cl = $aPlot[0];
  626. else
  627. $cl = $aPlot;
  628. if( ($cl instanceof Text) || ($cl instanceof PlotLine) ||
  629. (class_exists('PlotBand',false) && ($cl instanceof PlotBand)) )
  630. JpGraph::RaiseL(25013);//('You can only add standard plots to multiple Y-axis');
  631. else
  632. $this->ynplots[$aN][] = $aPlot;
  633. }
  634. // Add text object to the graph
  635. function AddText($aTxt,$aToY2=false) {
  636. if( $aTxt == null )
  637. JpGraphError::RaiseL(25014);//("Graph::AddText() You tried to add a null text to the graph.");
  638. if( $aToY2 ) {
  639. if( is_array($aTxt) ) {
  640. for($i=0; $i < count($aTxt); ++$i )
  641. $this->y2texts[]=$aTxt[$i];
  642. }
  643. else
  644. $this->y2texts[] = $aTxt;
  645. }
  646. else {
  647. if( is_array($aTxt) ) {
  648. for($i=0; $i < count($aTxt); ++$i )
  649. $this->texts[]=$aTxt[$i];
  650. }
  651. else
  652. $this->texts[] = $aTxt;
  653. }
  654. }
  655. // Add a line object (class PlotLine) to the graph
  656. function AddLine($aLine,$aToY2=false) {
  657. if( $aLine == null )
  658. JpGraphError::RaiseL(25015);//("Graph::AddLine() You tried to add a null line to the graph.");
  659. if( $aToY2 ) {
  660. if( is_array($aLine) ) {
  661. for($i=0; $i < count($aLine); ++$i )
  662. $this->y2lines[]=$aLine[$i];
  663. }
  664. else
  665. $this->y2lines[] = $aLine;
  666. }
  667. else {
  668. if( is_array($aLine) ) {
  669. for($i=0; $i<count($aLine); ++$i )
  670. $this->lines[]=$aLine[$i];
  671. }
  672. else
  673. $this->lines[] = $aLine;
  674. }
  675. }
  676. // Add vertical or horizontal band
  677. function AddBand($aBand,$aToY2=false) {
  678. if( $aBand == null )
  679. JpGraphError::RaiseL(25016);//(" Graph::AddBand() You tried to add a null band to the graph.");
  680. if( $aToY2 ) {
  681. if( is_array($aBand) ) {
  682. for($i=0; $i < count($aBand); ++$i )
  683. $this->y2bands[] = $aBand[$i];
  684. }
  685. else
  686. $this->y2bands[] = $aBand;
  687. }
  688. else {
  689. if( is_array($aBand) ) {
  690. for($i=0; $i < count($aBand); ++$i )
  691. $this->bands[] = $aBand[$i];
  692. }
  693. else
  694. $this->bands[] = $aBand;
  695. }
  696. }
  697. function SetBackgroundGradient($aFrom='navy',$aTo='silver',$aGradType=2,$aStyle=BGRAD_FRAME) {
  698. $this->bkg_gradtype=$aGradType;
  699. $this->bkg_gradstyle=$aStyle;
  700. $this->bkg_gradfrom = $aFrom;
  701. $this->bkg_gradto = $aTo;
  702. }
  703. // Set a country flag in the background
  704. function SetBackgroundCFlag($aName,$aBgType=BGIMG_FILLPLOT,$aMix=100) {
  705. $this->background_cflag = $aName;
  706. $this->background_cflag_type = $aBgType;
  707. $this->background_cflag_mix = $aMix;
  708. }
  709. // Alias for the above method
  710. function SetBackgroundCountryFlag($aName,$aBgType=BGIMG_FILLPLOT,$aMix=100) {
  711. $this->background_cflag = $aName;
  712. $this->background_cflag_type = $aBgType;
  713. $this->background_cflag_mix = $aMix;
  714. }
  715. // Specify a background image
  716. function SetBackgroundImage($aFileName,$aBgType=BGIMG_FILLPLOT,$aImgFormat="auto") {
  717. if( !USE_TRUECOLOR ) {
  718. JpGraphError::RaiseL(25017);//("You are using GD 2.x and are trying to use a background images on a non truecolor image. To use background images with GD 2.x you <b>must</b> enable truecolor by setting the USE_TRUECOLOR constant to TRUE. Due to a bug in GD 2.0.1 using any truetype fonts with truecolor images will result in very poor quality fonts.");
  719. }
  720. // Get extension to determine image type
  721. if( $aImgFormat == "auto" ) {
  722. $e = explode('.',$aFileName);
  723. if( !$e ) {
  724. JpGraphError::RaiseL(25018,$aFileName);//('Incorrect file name for Graph::SetBackgroundImage() : '.$aFileName.' Must have a valid image extension (jpg,gif,png) when using autodetection of image type');
  725. }
  726. $valid_formats = array('png', 'jpg', 'gif');
  727. $aImgFormat = strtolower($e[count($e)-1]);
  728. if ($aImgFormat == 'jpeg') {
  729. $aImgFormat = 'jpg';
  730. }
  731. elseif (!in_array($aImgFormat, $valid_formats) ) {
  732. JpGraphError::RaiseL(25019,$aImgFormat);//('Unknown file extension ($aImgFormat) in Graph::SetBackgroundImage() for filename: '.$aFileName);
  733. }
  734. }
  735. $this->background_image = $aFileName;
  736. $this->background_image_type=$aBgType;
  737. $this->background_image_format=$aImgFormat;
  738. }
  739. function SetBackgroundImageMix($aMix) {
  740. $this->background_image_mix = $aMix ;
  741. }
  742. // Specify axis style (boxed or single)
  743. function SetAxisStyle($aStyle) {
  744. $this->iAxisStyle = $aStyle ;
  745. }
  746. // Set a frame around the plot area
  747. function SetBox($aDrawPlotFrame=true,$aPlotFrameColor=array(0,0,0),$aPlotFrameWeight=1) {
  748. $this->boxed = $aDrawPlotFrame;
  749. $this->box_weight = $aPlotFrameWeight;
  750. $this->box_color = $aPlotFrameColor;
  751. }
  752. // Specify color for the plotarea (not the margins)
  753. function SetColor($aColor) {
  754. $this->plotarea_color=$aColor;
  755. }
  756. // Specify color for the margins (all areas outside the plotarea)
  757. function SetMarginColor($aColor) {
  758. $this->margin_color=$aColor;
  759. }
  760. // Set a frame around the entire image
  761. function SetFrame($aDrawImgFrame=true,$aImgFrameColor=array(0,0,0),$aImgFrameWeight=1) {
  762. $this->doframe = $aDrawImgFrame;
  763. $this->frame_color = $aImgFrameColor;
  764. $this->frame_weight = $aImgFrameWeight;
  765. }
  766. function SetFrameBevel($aDepth=3,$aBorder=false,$aBorderColor='black',$aColor1='white@0.4',$aColor2='darkgray@0.4',$aFlg=true) {
  767. $this->framebevel = $aFlg ;
  768. $this->framebeveldepth = $aDepth ;
  769. $this->framebevelborder = $aBorder ;
  770. $this->framebevelbordercolor = $aBorderColor ;
  771. $this->framebevelcolor1 = $aColor1 ;
  772. $this->framebevelcolor2 = $aColor2 ;
  773. $this->doshadow = false ;
  774. }
  775. // Set the shadow around the whole image
  776. function SetShadow($aShowShadow=true,$aShadowWidth=5,$aShadowColor=array(102,102,102)) {
  777. $this->doshadow = $aShowShadow;
  778. $this->shadow_color = $aShadowColor;
  779. $this->shadow_width = $aShadowWidth;
  780. $this->footer->iBottomMargin += $aShadowWidth;
  781. $this->footer->iRightMargin += $aShadowWidth;
  782. }
  783. // Specify x,y scale. Note that if you manually specify the scale
  784. // you must also specify the tick distance with a call to Ticks::Set()
  785. function SetScale($aAxisType,$aYMin=1,$aYMax=1,$aXMin=1,$aXMax=1) {
  786. $this->axtype = $aAxisType;
  787. if( $aYMax < $aYMin || $aXMax < $aXMin )
  788. JpGraphError::RaiseL(25020);//('Graph::SetScale(): Specified Max value must be larger than the specified Min value.');
  789. $yt=substr($aAxisType,-3,3);
  790. if( $yt=="lin" )
  791. $this->yscale = new LinearScale($aYMin,$aYMax);
  792. elseif( $yt == "int" ) {
  793. $this->yscale = new LinearScale($aYMin,$aYMax);
  794. $this->yscale->SetIntScale();
  795. }
  796. elseif( $yt=="log" )
  797. $this->yscale = new LogScale($aYMin,$aYMax);
  798. else
  799. JpGraphError::RaiseL(25021,$aAxisType);//("Unknown scale specification for Y-scale. ($aAxisType)");
  800. $xt=substr($aAxisType,0,3);
  801. if( $xt == "lin" || $xt == "tex" ) {
  802. $this->xscale = new LinearScale($aXMin,$aXMax,"x");
  803. $this->xscale->textscale = ($xt == "tex");
  804. }
  805. elseif( $xt == "int" ) {
  806. $this->xscale = new LinearScale($aXMin,$aXMax,"x");
  807. $this->xscale->SetIntScale();
  808. }
  809. elseif( $xt == "dat" ) {
  810. $this->xscale = new DateScale($aXMin,$aXMax,"x");
  811. }
  812. elseif( $xt == "log" )
  813. $this->xscale = new LogScale($aXMin,$aXMax,"x");
  814. else
  815. JpGraphError::RaiseL(25022,$aAxisType);//(" Unknown scale specification for X-scale. ($aAxisType)");
  816. $this->xaxis = new Axis($this->img,$this->xscale);
  817. $this->yaxis = new Axis($this->img,$this->yscale);
  818. $this->xgrid = new Grid($this->xaxis);
  819. $this->ygrid = new Grid($this->yaxis);
  820. $this->ygrid->Show();
  821. }
  822. // Specify secondary Y scale
  823. function SetY2Scale($aAxisType="lin",$aY2Min=1,$aY2Max=1) {
  824. if( $aAxisType=="lin" )
  825. $this->y2scale = new LinearScale($aY2Min,$aY2Max);
  826. elseif( $aAxisType == "int" ) {
  827. $this->y2scale = new LinearScale($aY2Min,$aY2Max);
  828. $this->y2scale->SetIntScale();
  829. }
  830. elseif( $aAxisType=="log" ) {
  831. $this->y2scale = new LogScale($aY2Min,$aY2Max);
  832. }
  833. else JpGraphError::RaiseL(25023,$aAxisType);//("JpGraph: Unsupported Y2 axis type: $aAxisType\nMust be one of (lin,log,int)");
  834. $this->y2axis = new Axis($this->img,$this->y2scale);
  835. $this->y2axis->scale->ticks->SetDirection(SIDE_LEFT);
  836. $this->y2axis->SetLabelSide(SIDE_RIGHT);
  837. $this->y2axis->SetPos('max');
  838. $this->y2axis->SetTitleSide(SIDE_RIGHT);
  839. // Deafult position is the max x-value
  840. $this->y2grid = new Grid($this->y2axis);
  841. }
  842. // Set the delta position (in pixels) between the multiple Y-axis
  843. function SetYDeltaDist($aDist) {
  844. $this->iYAxisDeltaPos = $aDist;
  845. }
  846. // Specify secondary Y scale
  847. function SetYScale($aN,$aAxisType="lin",$aYMin=1,$aYMax=1) {
  848. if( $aAxisType=="lin" )
  849. $this->ynscale[$aN] = new LinearScale($aYMin,$aYMax);
  850. elseif( $aAxisType == "int" ) {
  851. $this->ynscale[$aN] = new LinearScale($aYMin,$aYMax);
  852. $this->ynscale[$aN]->SetIntScale();
  853. }
  854. elseif( $aAxisType=="log" ) {
  855. $this->ynscale[$aN] = new LogScale($aYMin,$aYMax);
  856. }
  857. else JpGraphError::RaiseL(25024,$aAxisType);//("JpGraph: Unsupported Y axis type: $aAxisType\nMust be one of (lin,log,int)");
  858. $this->ynaxis[$aN] = new Axis($this->img,$this->ynscale[$aN]);
  859. $this->ynaxis[$aN]->scale->ticks->SetDirection(SIDE_LEFT);
  860. $this->ynaxis[$aN]->SetLabelSide(SIDE_RIGHT);
  861. }
  862. // Specify density of ticks when autoscaling 'normal', 'dense', 'sparse', 'verysparse'
  863. // The dividing factor have been determined heuristically according to my aesthetic
  864. // sense (or lack off) y.m.m.v !
  865. function SetTickDensity($aYDensity=TICKD_NORMAL,$aXDensity=TICKD_NORMAL) {
  866. $this->xtick_factor=30;
  867. $this->ytick_factor=25;
  868. switch( $aYDensity ) {
  869. case TICKD_DENSE:
  870. $this->ytick_factor=12;
  871. break;
  872. case TICKD_NORMAL:
  873. $this->ytick_factor=25;
  874. break;
  875. case TICKD_SPARSE:
  876. $this->ytick_factor=40;
  877. break;
  878. case TICKD_VERYSPARSE:
  879. $this->ytick_factor=100;
  880. break;
  881. default:
  882. JpGraphError::RaiseL(25025,$densy);//("JpGraph: Unsupported Tick density: $densy");
  883. }
  884. switch( $aXDensity ) {
  885. case TICKD_DENSE:
  886. $this->xtick_factor=15;
  887. break;
  888. case TICKD_NORMAL:
  889. $this->xtick_factor=30;
  890. break;
  891. case TICKD_SPARSE:
  892. $this->xtick_factor=45;
  893. break;
  894. case TICKD_VERYSPARSE:
  895. $this->xtick_factor=60;
  896. break;
  897. default:
  898. JpGraphError::RaiseL(25025,$densx);//("JpGraph: Unsupported Tick density: $densx");
  899. }
  900. }
  901. // Get a string of all image map areas
  902. function GetCSIMareas() {
  903. if( !$this->iHasStroked )
  904. $this->Stroke(_CSIM_SPECIALFILE);
  905. $csim = $this->title->GetCSIMAreas();
  906. $csim .= $this->subtitle->GetCSIMAreas();
  907. $csim .= $this->subsubtitle->GetCSIMAreas();
  908. $csim .= $this->legend->GetCSIMAreas();
  909. if( $this->y2axis != NULL ) {
  910. $csim .= $this->y2axis->title->GetCSIMAreas();
  911. }
  912. if( $this->texts != null ) {
  913. $n = count($this->texts);
  914. for($i=0; $i < $n; ++$i ) {
  915. $csim .= $this->texts[$i]->GetCSIMAreas();
  916. }
  917. }
  918. if( $this->y2texts != null && $this->y2scale != null ) {
  919. $n = count($this->y2texts);
  920. for($i=0; $i < $n; ++$i ) {
  921. $csim .= $this->y2texts[$i]->GetCSIMAreas();
  922. }
  923. }
  924. if( $this->yaxis != null && $this->xaxis != null ) {
  925. $csim .= $this->yaxis->title->GetCSIMAreas();
  926. $csim .= $this->xaxis->title->GetCSIMAreas();
  927. }
  928. $n = count($this->plots);
  929. for( $i=0; $i < $n; ++$i )
  930. $csim .= $this->plots[$i]->GetCSIMareas();
  931. $n = count($this->y2plots);
  932. for( $i=0; $i < $n; ++$i )
  933. $csim .= $this->y2plots[$i]->GetCSIMareas();
  934. $n = count($this->ynaxis);
  935. for( $i=0; $i < $n; ++$i ) {
  936. $m = count($this->ynplots[$i]);
  937. for($j=0; $j < $m; ++$j ) {
  938. $csim .= $this->ynplots[$i][$j]->GetCSIMareas();
  939. }
  940. }
  941. $n = count($this->iTables);
  942. for( $i=0; $i < $n; ++$i ) {
  943. $csim .= $this->iTables[$i]->GetCSIMareas();
  944. }
  945. return $csim;
  946. }
  947. // Get a complete <MAP>..</MAP> tag for the final image map
  948. function GetHTMLImageMap($aMapName) {
  949. $im = "<map name=\"$aMapName\" id=\"$aMapName\" >\n";
  950. $im .= $this->GetCSIMareas();
  951. $im .= "</map>";
  952. return $im;
  953. }
  954. function CheckCSIMCache($aCacheName,$aTimeOut=60) {
  955. global $_SERVER;
  956. if( $aCacheName=='auto' )
  957. $aCacheName=basename($_SERVER['PHP_SELF']);
  958. $urlarg = $this->GetURLArguments();
  959. $this->csimcachename = CSIMCACHE_DIR.$aCacheName.$urlarg;
  960. $this->csimcachetimeout = $aTimeOut;
  961. // First determine if we need to check for a cached version
  962. // This differs from the standard cache in the sense that the
  963. // image and CSIM map HTML file is written relative to the directory
  964. // the script executes in and not the specified cache directory.
  965. // The reason for this is that the cache directory is not necessarily
  966. // accessible from the HTTP server.
  967. if( $this->csimcachename != '' ) {
  968. $dir = dirname($this->csimcachename);
  969. $base = basename($this->csimcachename);
  970. $base = strtok($base,'.');
  971. $suffix = strtok('.');
  972. $basecsim = $dir.'/'.$base.'?'.$urlarg.'_csim_.html';
  973. $baseimg = $dir.'/'.$base.'?'.$urlarg.'.'.$this->img->img_format;
  974. $timedout=false;
  975. // Does it exist at all ?
  976. if( file_exists($basecsim) && file_exists($baseimg) ) {
  977. // Check that it hasn't timed out
  978. $diff=time()-filemtime($basecsim);
  979. if( $this->csimcachetimeout>0 && ($diff > $this->csimcachetimeout*60) ) {
  980. $timedout=true;
  981. @unlink($basecsim);
  982. @unlink($baseimg);
  983. }
  984. else {
  985. if ($fh = @fopen($basecsim, "r")) {
  986. fpassthru($fh);
  987. return true;
  988. }
  989. else
  990. JpGraphError::RaiseL(25027,$basecsim);//(" Can't open cached CSIM \"$basecsim\" for reading.");
  991. }
  992. }
  993. }
  994. return false;
  995. }
  996. // Build the argument string to be used with the csim images
  997. function GetURLArguments() {
  998. // This is a JPGRAPH internal defined that prevents
  999. // us from recursively coming here again
  1000. $urlarg = _CSIM_DISPLAY.'=1';
  1001. // Now reconstruct any user URL argument
  1002. reset($_REQUEST);
  1003. while( list($key,$value) = each($_REQUEST) ) {
  1004. if( is_array($value) ) {
  1005. foreach ( $value as $k => $v ) {
  1006. $urlarg .= '&amp;'.$key.'%5B'.$k.'%5D='.urlencode($v);
  1007. }
  1008. }
  1009. else {
  1010. $urlarg .= '&amp;'.$key.'='.urlencode($value);
  1011. }
  1012. }
  1013. // It's not ideal to convert POST argument to GET arguments
  1014. // but there is little else we can do. One idea for the
  1015. // future might be recreate the POST header in case.
  1016. reset($_REQUEST);
  1017. while( list($key,$value) = each($_REQUEST) ) {
  1018. if( is_array($value) ) {
  1019. foreach ( $value as $k => $v ) {
  1020. $urlarg .= '&amp;'.$key.'%5B'.$k.'%5D='.urlencode($v);
  1021. }
  1022. }
  1023. else {
  1024. $urlarg .= '&amp;'.$key.'='.urlencode($value);
  1025. }
  1026. }
  1027. return $urlarg;
  1028. }
  1029. function SetCSIMImgAlt($aAlt) {
  1030. $this->iCSIMImgAlt = $aAlt;
  1031. }
  1032. function StrokeCSIM($aScriptName='auto',$aCSIMName='',$aBorder=0) {
  1033. if( $aCSIMName=='' ) {
  1034. // create a random map name
  1035. srand ((double) microtime() * 1000000);
  1036. $r = rand(0,100000);
  1037. $aCSIMName='__mapname'.$r.'__';
  1038. }
  1039. if( $aScriptName=='auto' )
  1040. $aScriptName=basename($_SERVER['PHP_SELF']);
  1041. $urlarg = $this->GetURLArguments();
  1042. if( empty($_REQUEST[_CSIM_DISPLAY]) ) {
  1043. // First determine if we need to check for a cached version
  1044. // This differs from the standard cache in the sense that the
  1045. // image and CSIM map HTML file is written relative to the directory
  1046. // the script executes in and not the specified cache directory.
  1047. // The reason for this is that the cache directory is not necessarily
  1048. // accessible from the HTTP server.
  1049. if( $this->csimcachename != '' ) {
  1050. $dir = dirname($this->csimcachename);
  1051. $base = basename($this->csimcachename);
  1052. $base = strtok($base,'.');
  1053. $suffix = strtok('.');
  1054. $basecsim = $dir.'/'.$base.'?'.$urlarg.'_csim_.html';
  1055. $baseimg = $base.'?'.$urlarg.'.'.$this->img->img_format;
  1056. // Check that apache can write to directory specified
  1057. if( file_exists($dir) && !is_writeable($dir) ) {
  1058. JpgraphError::RaiseL(25028,$dir);//('Apache/PHP does not have permission to write to the CSIM cache directory ('.$dir.'). Check permissions.');
  1059. }
  1060. // Make sure directory exists
  1061. $this->cache->MakeDirs($dir);
  1062. // Write the image file
  1063. $this->Stroke(CSIMCACHE_DIR.$baseimg);
  1064. // Construct wrapper HTML and write to file and send it back to browser
  1065. // In the src URL we must replace the '?' with its encoding to prevent the arguments
  1066. // to be converted to real arguments.
  1067. $tmp = str_replace('?','%3f',$baseimg);
  1068. $htmlwrap = $this->GetHTMLImageMap($aCSIMName)."\n".
  1069. '<img src="'.CSIMCACHE_HTTP_DIR.$tmp.'" ismap="ismap" usemap="#'.$aCSIMName.'" border="'.$aBorder.'" width="'.$this->img->width.'" height="'.$this->img->height."\" alt=\"".$this->iCSIMImgAlt."\" />\n";
  1070. if($fh = @fopen($basecsim,'w') ) {
  1071. fwrite($fh,$htmlwrap);
  1072. fclose($fh);
  1073. echo $htmlwrap;
  1074. }
  1075. else
  1076. JpGraphError::RaiseL(25029,$basecsim);//(" Can't write CSIM \"$basecsim\" for writing. Check free space and permissions.");
  1077. }
  1078. else {
  1079. if( $aScriptName=='' ) {
  1080. JpGraphError::RaiseL(25030);//('Missing script name in call to StrokeCSIM(). You must specify the name of the actual image script as the first parameter to StrokeCSIM().');
  1081. }
  1082. echo $this->GetHTMLImageMap($aCSIMName);
  1083. echo "<img src=\"".$aScriptName.'?'.$urlarg."\" ismap=\"ismap\" usemap=\"#".$aCSIMName.'" border="'.$aBorder.'" width="'.$this->img->width.'" height="'.$this->img->height."\" alt=\"".$this->iCSIMImgAlt."\" />\n";
  1084. }
  1085. }
  1086. else {
  1087. $this->Stroke();
  1088. }
  1089. }
  1090. function GetTextsYMinMax($aY2=false) {
  1091. if( $aY2 )
  1092. $txts = $this->y2texts;
  1093. else
  1094. $txts = $this->texts;
  1095. $n = count($txts);
  1096. $min=null;
  1097. $max=null;
  1098. for( $i=0; $i < $n; ++$i ) {
  1099. if( $txts[$i]->iScalePosY !== null &&
  1100. $txts[$i]->iScalePosX !== null ) {
  1101. if( $min === null ) {
  1102. $min = $max = $txts[$i]->iScalePosY ;
  1103. }
  1104. else {
  1105. $min = min($min,$txts[$i]->iScalePosY);
  1106. $max = max($max,$txts[$i]->iScalePosY);
  1107. }
  1108. }
  1109. }
  1110. if( $min !== null ) {
  1111. return array($min,$max);
  1112. }
  1113. else
  1114. return null;
  1115. }
  1116. function GetTextsXMinMax($aY2=false) {
  1117. if( $aY2 )
  1118. $txts = $this->y2texts;
  1119. else
  1120. $txts = $this->texts;
  1121. $n = count($txts);
  1122. $min=null;
  1123. $max=null;
  1124. for( $i=0; $i < $n; ++$i ) {
  1125. if( $txts[$i]->iScalePosY !== null &&
  1126. $txts[$i]->iScalePosX !== null ) {
  1127. if( $min === null ) {
  1128. $min = $max = $txts[$i]->iScalePosX ;
  1129. }
  1130. else {
  1131. $min = min($min,$txts[$i]->iScalePosX);
  1132. $max = max($max,$txts[$i]->iScalePosX);
  1133. }
  1134. }
  1135. }
  1136. if( $min !== null ) {
  1137. return array($min,$max);
  1138. }
  1139. else
  1140. return null;
  1141. }
  1142. function GetXMinMax() {
  1143. list($min,$ymin) = $this->plots[0]->Min();
  1144. list($max,$ymax) = $this->plots[0]->Max();
  1145. foreach( $this->plots as $p ) {
  1146. list($xmin,$ymin) = $p->Min();
  1147. list($xmax,$ymax) = $p->Max();
  1148. $min = Min($xmin,$min);
  1149. $max = Max($xmax,$max);
  1150. }
  1151. if( $this->y2axis != null ) {
  1152. foreach( $this->y2plots as $p ) {
  1153. list($xmin,$ymin) = $p->Min();
  1154. list($xmax,$ymax) = $p->Max();
  1155. $min = Min($xmin,$min);
  1156. $max = Max($xmax,$max);
  1157. }
  1158. }
  1159. $n = count($this->ynaxis);
  1160. for( $i=0; $i < $n; ++$i ) {
  1161. if( $this->ynaxis[$i] != null) {
  1162. foreach( $this->ynplots[$i] as $p ) {
  1163. list($xmin,$ymin) = $p->Min();
  1164. list($xmax,$ymax) = $p->Max();
  1165. $min = Min($xmin,$min);
  1166. $max = Max($xmax,$max);
  1167. }
  1168. }
  1169. }
  1170. return array($min,$max);
  1171. }
  1172. function AdjustMarginsForTitles() {
  1173. $totrequired =
  1174. ($this->title->t != '' ?
  1175. $this->title->GetTextHeight($this->img) + $this->title->margin + 5 : 0 ) +
  1176. ($this->subtitle->t != '' ?
  1177. $this->subtitle->GetTextHeight($this->img) + $this->subtitle->margin + 5 : 0 ) +
  1178. ($this->subsubtitle->t != '' ?
  1179. $this->subsubtitle->GetTextHeight($this->img) + $this->subsubtitle->margin + 5 : 0 ) ;
  1180. $btotrequired = 0;
  1181. if($this->xaxis != null && !$this->xaxis->hide && !$this->xaxis->hide_labels ) {
  1182. // Minimum bottom margin
  1183. if( $this->xaxis->title->t != '' ) {
  1184. if( $this->img->a == 90 )
  1185. $btotrequired = $this->yaxis->title->GetTextHeight($this->img) + 5 ;
  1186. else
  1187. $btotrequired = $this->xaxis->title->GetTextHeight($this->img) + 5 ;
  1188. }
  1189. else
  1190. $btotrequired = 0;
  1191. if( $this->img->a == 90 ) {
  1192. $this->img->SetFont($this->yaxis->font_family,$this->yaxis->font_style,
  1193. $this->yaxis->font_size);
  1194. $lh = $this->img->GetTextHeight('Mg',$this->yaxis->label_angle);
  1195. }
  1196. else {
  1197. $this->img->SetFont($this->xaxis->font_family,$this->xaxis->font_style,
  1198. $this->xaxis->font_size);
  1199. $lh = $this->img->GetTextHeight('Mg',$this->xaxis->label_angle);
  1200. }
  1201. $btotrequired += $lh + 5;
  1202. }
  1203. if( $this->img->a == 90 ) {
  1204. // DO Nothing. It gets too messy to do this properly for 90 deg...
  1205. }
  1206. else{
  1207. if( $this->img->top_margin < $totrequired ) {
  1208. $this->SetMargin($this->img->left_margin,$this->img->right_margin,
  1209. $totrequired,$this->img->bottom_margin);
  1210. }
  1211. if( $this->img->bottom_margin < $btotrequired ) {
  1212. $this->SetMargin($this->img->left_margin,$this->img->right_margin,
  1213. $this->img->top_margin,$btotrequired);
  1214. }
  1215. }
  1216. }
  1217. // Stroke the graph
  1218. // $aStrokeFileName If != "" the image will be written to this file and NOT
  1219. // streamed back to the browser
  1220. function Stroke($aStrokeFileName="") {
  1221. // Fist make a sanity check that user has specified a scale
  1222. if( empty($this->yscale) ) {
  1223. JpGraphError::RaiseL(25031);//('You must specify what scale to use with a call to Graph::SetScale().');
  1224. }
  1225. // Start by adjusting the margin so that potential titles will fit.
  1226. $this->AdjustMarginsForTitles();
  1227. // Setup scale constants
  1228. if( $this->yscale ) $this->yscale->InitConstants($this->img);
  1229. if( $this->xscale ) $this->xscale->InitConstants($this->img);
  1230. if( $this->y2scale ) $this->y2scale->InitConstants($this->img);
  1231. $n=count($this->ynscale);
  1232. for($i=0; $i < $n; ++$i) {
  1233. if( $this->ynscale[$i] ) $this->ynscale[$i]->InitConstants($this->img);
  1234. }
  1235. // If the filename is the predefined value = '_csim_special_'
  1236. // we assume that the call to stroke only needs to do enough
  1237. // to correctly generate the CSIM maps.
  1238. // We use this variable to skip things we don't strictly need
  1239. // to do to generate the image map to improve performance
  1240. // a best we can. Therefor you will see a lot of tests !$_csim in the
  1241. // code below.
  1242. $_csim = ($aStrokeFileName===_CSIM_SPECIALFILE);
  1243. // We need to know if we have stroked the plot in the
  1244. // GetCSIMareas. Otherwise the CSIM hasn't been generated
  1245. // and in the case of GetCSIM called before stroke to generate
  1246. // CSIM without storing an image to disk GetCSIM must call Stroke.
  1247. $this->iHasStroked = true;
  1248. // Do any pre-stroke adjustment that is needed by the different plot types
  1249. // (i.e bar plots want's to add an offset to the x-labels etc)
  1250. for($i=0; $i < count($this->plots) ; ++$i ) {
  1251. $this->plots[$i]->PreStrokeAdjust($this);
  1252. $this->plots[$i]->DoLegend($this);
  1253. }
  1254. // Any plots on the second Y scale?
  1255. if( $this->y2scale != null ) {
  1256. for($i=0; $i<count($this->y2plots) ; ++$i ) {
  1257. $this->y2plots[$i]->PreStrokeAdjust($this);
  1258. $this->y2plots[$i]->DoLegend($this);
  1259. }
  1260. }
  1261. // Any plots on the extra Y axises?
  1262. $n = count($this->ynaxis);
  1263. for($i=0; $i<$n ; ++$i ) {
  1264. if( $this->ynplots == null || $this->ynplots[$i] == null) {
  1265. JpGraphError::RaiseL(25032,$i);//("No plots for Y-axis nbr:$i");
  1266. }
  1267. $m = count($this->ynplots[$i]);
  1268. for($j=0; $j < $m; ++$j ) {
  1269. $this->ynplots[$i][$j]->PreStrokeAdjust($this);
  1270. $this->ynplots[$i][$j]->DoLegend($this);
  1271. }
  1272. }
  1273. // Bail out if any of the Y-axis not been specified and
  1274. // has no plots. (This means it is impossible to do autoscaling and
  1275. // no other scale was given so we can't possible draw anything). If you use manual
  1276. // scaling you also have to supply the tick steps as well.
  1277. if( (!$this->yscale->IsSpecified() && count($this->plots)==0) ||
  1278. ($this->y2scale!=null && !$this->y2scale->IsSpecified() && count($this->y2plots)==0) ) {
  1279. //$e = "n=".count($this->y2plots)."\n";
  1280. // $e = "Can't draw unspecified Y-scale.<br>\nYou have either:<br>\n";
  1281. // $e .= "1. Specified an Y axis for autoscaling but have not supplied any plots<br>\n";
  1282. // $e .= "2. Specified a scale manually but have forgot to specify the tick steps";
  1283. JpGraphError::RaiseL(25026);
  1284. }
  1285. // Bail out if no plots and no specified X-scale
  1286. if( (!$this->xscale->IsSpecified() && count($this->plots)==0 && count($this->y2plots)==0) )
  1287. JpGraphError::RaiseL(25034);//("<strong>JpGraph: Can't draw unspecified X-scale.</strong><br>No plots.<br>");
  1288. //Check if we should autoscale y-axis
  1289. if( !$this->yscale->IsSpecified() && count($this->plots)>0 ) {
  1290. list($min,$max) = $this->GetPlotsYMinMax($this->plots);
  1291. $lres = $this->GetLinesYMinMax($this->lines);
  1292. if( is_array($lres) ) {
  1293. list($linmin,$linmax) = $lres ;
  1294. $min = min($min,$linmin);
  1295. $max = max($max,$linmax);
  1296. }
  1297. $tres = $this->GetTextsYMinMax();
  1298. if( is_array($tres) ) {
  1299. list($tmin,$tmax) = $tres ;
  1300. $min = min($min,$tmin);
  1301. $max = max($max,$tmax);
  1302. }
  1303. $this->yscale->AutoScale($this->img,$min,$max,
  1304. $this->img->plotheight/$this->ytick_factor);
  1305. }
  1306. elseif( $this->yscale->IsSpecified() &&
  1307. ( $this->yscale->auto_ticks || !$this->yscale->ticks->IsSpecified()) ) {
  1308. // The tick calculation will use the user suplied min/max values to determine
  1309. // the ticks. If auto_ticks is false the exact user specifed min and max
  1310. // values will be used for the scale.
  1311. // If auto_ticks is true then the scale might be slightly adjusted
  1312. // so that the min and max values falls on an even major step.
  1313. $min = $this->yscale->scale[0];
  1314. $max = $this->yscale->scale[1];
  1315. $this->yscale->AutoScale($this->img,$min,$max,
  1316. $this->img->plotheight/$this->ytick_factor,
  1317. $this->yscale->auto_ticks);
  1318. // Now make sure we show enough precision to accurate display the
  1319. // labels. If this is not done then the user might end up with
  1320. // a scale that might actually start with, say 13.5, butdue to rounding
  1321. // the scale label will ony show 14.
  1322. if( abs(floor($min)-$min) > 0 ) {
  1323. // If the user has set a format then we bail out
  1324. if( $this->yscale->ticks->label_formatstr == '' && $this->yscale->ticks->label_dateformatstr == '' ) {
  1325. $this->yscale->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1;
  1326. }
  1327. }
  1328. }
  1329. if( $this->y2scale != null) {
  1330. if( !$this->y2scale->IsSpecified() && count($this->y2plots)>0 ) {
  1331. list($min,$max) = $this->GetPlotsYMinMax($this->y2plots);
  1332. $lres = $this->GetLinesYMinMax($this->y2lines);
  1333. if( is_array($lres) ) {
  1334. list($linmin,$linmax) = $lres ;
  1335. $min = min($min,$linmin);
  1336. $max = max($max,$linmax);
  1337. }
  1338. $tres = $this->GetTextsYMinMax(true);
  1339. if( is_array($tres) ) {
  1340. list($tmin,$tmax) = $tres ;
  1341. $min = min($min,$tmin);
  1342. $max = max($max,$tmax);
  1343. }
  1344. $this->y2scale->AutoScale($this->img,$min,$max,$this->img->plotheight/$this->ytick_factor);
  1345. }
  1346. elseif( $this->y2scale->IsSpecified() &&
  1347. ( $this->y2scale->auto_ticks || !$this->y2scale->ticks->IsSpecified()) ) {
  1348. // The tick calculation will use the user suplied min/max values to determine
  1349. // the ticks. If auto_ticks is false the exact user specifed min and max
  1350. // values will be used for the scale.
  1351. // If auto_ticks is true then the scale might be slightly adjusted
  1352. // so that the min and max values falls on an even major step.
  1353. $min = $this->y2scale->scale[0];
  1354. $max = $this->y2scale->scale[1];
  1355. $this->y2scale->AutoScale($this->img,$min,$max,
  1356. $this->img->plotheight/$this->ytick_factor,
  1357. $this->y2scale->auto_ticks);
  1358. // Now make sure we show enough precision to accurate display the
  1359. // labels. If this is not done then the user might end up with
  1360. // a scale that might actually start with, say 13.5, butdue to rounding
  1361. // the scale label will ony show 14.
  1362. if( abs(floor($min)-$min) > 0 ) {
  1363. // If the user has set a format then we bail out
  1364. if( $this->y2scale->ticks->label_formatstr == '' && $this->y2scale->ticks->label_dateformatstr == '' ) {
  1365. $this->y2scale->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1;
  1366. }
  1367. }
  1368. }
  1369. }
  1370. //
  1371. // Autoscale the extra Y-axises
  1372. //
  1373. $n = count($this->ynaxis);
  1374. for( $i=0; $i < $n; ++$i ) {
  1375. if( $this->ynscale[$i] != null) {
  1376. if( !$this->ynscale[$i]->IsSpecified() && count($this->ynplots[$i])>0 ) {
  1377. list($min,$max) = $this->GetPlotsYMinMax($this->ynplots[$i]);
  1378. $this->ynscale[$i]->AutoScale($this->img,$min,$max,$this->img->plotheight/$this->ytick_factor);
  1379. }
  1380. elseif( $this->ynscale[$i]->IsSpecified() &&
  1381. ( $this->ynscale[$i]->auto_ticks || !$this->ynscale[$i]->ticks->IsSpecified()) ) {
  1382. // The tick calculation will use the user suplied min/max values to determine
  1383. // the ticks. If auto_ticks is false the exact user specifed min and max
  1384. // values will be used for the scale.
  1385. // If auto_ticks is true then the scale might be slightly adjusted
  1386. // so that the min and max values falls on an even major step.
  1387. $min = $this->ynscale[$i]->scale[0];
  1388. $max = $this->ynscale[$i]->scale[1];
  1389. $this->ynscale[$i]->AutoScale($this->img,$min,$max,
  1390. $this->img->plotheight/$this->ytick_factor,
  1391. $this->ynscale[$i]->auto_ticks);
  1392. // Now make sure we show enough precision to accurate display the
  1393. // labels. If this is not done then the user might end up with
  1394. // a scale that might actually start with, say 13.5, butdue to rounding
  1395. // the scale label will ony show 14.
  1396. if( abs(floor($min)-$min) > 0 ) {
  1397. // If the user has set a format then we bail out
  1398. if( $this->ynscale[$i]->ticks->label_formatstr == '' && $this->ynscale[$i]->ticks->label_dateformatstr == '' ) {
  1399. $this->ynscale[$i]->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1;
  1400. }
  1401. }
  1402. }
  1403. }
  1404. }
  1405. //Check if we should autoscale x-axis
  1406. if( !$this->xscale->IsSpecified() ) {
  1407. if( substr($this->axtype,0,4) == "text" ) {
  1408. $max=0;
  1409. $n = count($this->plots);
  1410. for($i=0; $i < $n; ++$i ) {
  1411. $p = $this->plots[$i];
  1412. // We need some unfortunate sub class knowledge here in order
  1413. // to increase number of data points in case it is a line plot
  1414. // which has the barcenter set. If not it could mean that the
  1415. // last point of the data is outside the scale since the barcenter
  1416. // settings means that we will shift the entire plot half a tick step
  1417. // to the right in oder to align with the center of the bars.
  1418. if( class_exists('BarPlot',false) ) {
  1419. $cl = strtolower(get_class($p));
  1420. if( (class_exists('BarPlot',false) && ($p instanceof BarPlot)) ||
  1421. empty($p->barcenter) )
  1422. $max=max($max,$p->numpoints-1);
  1423. else {
  1424. $max=max($max,$p->numpoints);
  1425. }
  1426. }
  1427. else {
  1428. if( empty($p->barcenter) ) {
  1429. $max=max($max,$p->numpoints-1);
  1430. }
  1431. else {
  1432. $max=max($max,$p->numpoints);
  1433. }
  1434. }
  1435. }
  1436. $min=0;
  1437. if( $this->y2axis != null ) {
  1438. foreach( $this->y2plots as $p ) {
  1439. $max=max($max,$p->numpoints-1);
  1440. }
  1441. }
  1442. $n = count($this->ynaxis);
  1443. for( $i=0; $i < $n; ++$i ) {
  1444. if( $this->ynaxis[$i] != null) {
  1445. foreach( $this->ynplots[$i] as $p ) {
  1446. $max=max($max,$p->numpoints-1);
  1447. }
  1448. }
  1449. }
  1450. $this->xscale->Update($this->img,$min,$max);
  1451. $this->xscale->ticks->Set($this->xaxis->tick_step,1);
  1452. $this->xscale->ticks->SupressMinorTickMarks();
  1453. }
  1454. else {
  1455. list($min,$max) = $this->GetXMinMax();
  1456. $lres = $this->GetLinesXMinMax($this->lines);
  1457. if( $lres ) {
  1458. list($linmin,$linmax) = $lres ;
  1459. $min = min($min,$linmin);
  1460. $max = max($max,$linmax);
  1461. }
  1462. $lres = $this->GetLinesXMinMax($this->y2lines);
  1463. if( $lres ) {
  1464. list($linmin,$linmax) = $lres ;
  1465. $min = min($min,$linmin);
  1466. $max = max($max,$linmax);
  1467. }
  1468. $tres = $this->GetTextsXMinMax();
  1469. if( $tres ) {
  1470. list($tmin,$tmax) = $tres ;
  1471. $min = min($min,$tmin);
  1472. $max = max($max,$tmax);
  1473. }
  1474. $tres = $this->GetTextsXMinMax(true);
  1475. if( $tres ) {
  1476. list($tmin,$tmax) = $tres ;
  1477. $min = min($min,$tmin);
  1478. $max = max($max,$tmax);
  1479. }
  1480. $this->xscale->AutoScale($this->img,$min,$max,round($this->img->plotwidth/$this->xtick_factor));
  1481. }
  1482. //Adjust position of y-axis and y2-axis to minimum/maximum of x-scale
  1483. if( !is_numeric($this->yaxis->pos) && !is_string($this->yaxis->pos) )
  1484. $this->yaxis->SetPos($this->xscale->GetMinVal());
  1485. if( $this->y2axis != null ) {
  1486. if( !is_numeric($this->y2axis->pos) && !is_string($this->y2axis->pos) )
  1487. $this->y2axis->SetPos($this->xscale->GetMaxVal());
  1488. $this->y2axis->SetTitleSide(SIDE_RIGHT);
  1489. }
  1490. $n = count($this->ynaxis);
  1491. $nY2adj = $this->y2axis != null ? $this->iYAxisDeltaPos : 0;
  1492. for( $i=0; $i < $n; ++$i ) {
  1493. if( $this->ynaxis[$i] != null ) {
  1494. if( !is_numeric($this->ynaxis[$i]->pos) && !is_string($this->ynaxis[$i]->pos) ) {
  1495. $this->ynaxis[$i]->SetPos($this->xscale->GetMaxVal());
  1496. $this->ynaxis[$i]->SetPosAbsDelta($i*$this->iYAxisDeltaPos + $nY2adj);
  1497. }
  1498. $this->ynaxis[$i]->SetTitleSide(SIDE_RIGHT);
  1499. }
  1500. }
  1501. }
  1502. elseif( $this->xscale->IsSpecified() &&
  1503. ( $this->xscale->auto_ticks || !$this->xscale->ticks->IsSpecified()) ) {
  1504. // The tick calculation will use the user suplied min/max values to determine
  1505. // the ticks. If auto_ticks is false the exact user specifed min and max
  1506. // values will be used for the scale.
  1507. // If auto_ticks is true then the scale might be slightly adjusted
  1508. // so that the min and max values falls on an even major step.
  1509. $min = $this->xscale->scale[0];
  1510. $max = $this->xscale->scale[1];
  1511. $this->xscale->AutoScale($this->img,$min,$max,
  1512. round($this->img->plotwidth/$this->xtick_factor),
  1513. false);
  1514. // Now make sure we show enough precision to accurate display the
  1515. // labels. If this is not done then the user might end up with
  1516. // a scale that might actually start with, say 13.5, butdue to rounding
  1517. // the scale label will ony show 14.
  1518. if( abs(floor($min)-$min) > 0 ) {
  1519. // If the user has set a format then we bail out
  1520. if( $this->xscale->ticks->label_formatstr == '' && $this->xscale->ticks->label_dateformatstr == '' ) {
  1521. $this->xscale->ticks->precision = abs( floor(log10( abs(floor($min)-$min))) )+1;
  1522. }
  1523. }
  1524. if( $this->y2axis != null ) {
  1525. if( !is_numeric($this->y2axis->pos) && !is_string($this->y2axis->pos) )
  1526. $this->y2axis->SetPos($this->xscale->GetMaxVal());
  1527. $this->y2axis->SetTitleSide(SIDE_RIGHT);
  1528. }
  1529. }
  1530. // If we have a negative values and x-axis position is at 0
  1531. // we need to supress the first and possible the last tick since
  1532. // they will be drawn on top of the y-axis (and possible y2 axis)
  1533. // The test below might seem strange the reasone being that if
  1534. // the user hasn't specified a value for position this will not
  1535. // be set until we do the stroke for the axis so as of now it
  1536. // is undefined.
  1537. // For X-text scale we ignore all this since the tick are usually
  1538. // much further in and not close to the Y-axis. Hence the test
  1539. // for 'text'
  1540. if( ($this->yaxis->pos==$this->xscale->GetMinVal() ||
  1541. (is_string($this->yaxis->pos) && $this->yaxis->pos=='min')) &&
  1542. !is_numeric($this->xaxis->pos) && $this->yscale->GetMinVal() < 0 &&
  1543. substr($this->axtype,0,4) != 'text' && $this->xaxis->pos!="min" ) {
  1544. //$this->yscale->ticks->SupressZeroLabel(false);
  1545. $this->xscale->ticks->SupressFirst();
  1546. if( $this->y2axis != null ) {
  1547. $this->xscale->ticks->SupressLast();
  1548. }
  1549. }
  1550. elseif( !is_numeric($this->yaxis->pos) && $this->yaxis->pos=='max' ) {
  1551. $this->xscale->ticks->SupressLast();
  1552. }
  1553. if( !$_csim ) {
  1554. $this->StrokePlotArea();
  1555. if( $this->iIconDepth == DEPTH_BACK ) {
  1556. $this->StrokeIcons();
  1557. }
  1558. }
  1559. $this->StrokeAxis(false);
  1560. // Stroke bands
  1561. if( $this->bands != null && !$_csim)
  1562. for($i=0; $i < count($this->bands); ++$i) {
  1563. // Stroke all bands that asks to be in the background
  1564. if( $this->bands[$i]->depth == DEPTH_BACK )
  1565. $this->bands[$i]->Stroke($this->img,$this->xscale,$this->yscale);
  1566. }
  1567. if( $this->y2bands != null && $this->y2scale != null && !$_csim )
  1568. for($i=0; $i < count($this->y2bands); ++$i) {
  1569. // Stroke all bands that asks to be in the foreground
  1570. if( $this->y2bands[$i]->depth == DEPTH_BACK )
  1571. $this->y2bands[$i]->Stroke($this->img,$this->xscale,$this->y2scale);
  1572. }
  1573. if( $this->grid_depth == DEPTH_BACK && !$_csim) {
  1574. $this->ygrid->Stroke();
  1575. $this->xgrid->Stroke();
  1576. }
  1577. // Stroke Y2-axis
  1578. if( $this->y2axis != null && !$_csim) {
  1579. $this->y2axis->Stroke($this->xscale);
  1580. $this->y2grid->Stroke();
  1581. }
  1582. // Stroke yn-axis
  1583. $n = count($this->ynaxis);
  1584. for( $i=0; $i < $n; ++$i ) {
  1585. $this->ynaxis[$i]->Stroke($this->xscale);
  1586. }
  1587. $oldoff=$this->xscale->off;
  1588. if(substr($this->axtype,0,4)=="text") {
  1589. if( $this->text_scale_abscenteroff > -1 ) {
  1590. // For a text scale the scale factor is the number of pixel per step.
  1591. // Hence we can use the scale factor as a substitute for number of pixels
  1592. // per major scale step and use that in order to adjust the offset so that
  1593. // an object of width "abscenteroff" becomes centered.
  1594. $this->xscale->off += round($this->xscale->scale_factor/2)-round($this->text_scale_abscenteroff/2);
  1595. }
  1596. else {
  1597. $this->xscale->off +=
  1598. ceil($this->xscale->scale_factor*$this->text_scale_off*$this->xscale->ticks->minor_step);
  1599. }
  1600. }
  1601. if( $this->iDoClipping ) {
  1602. $oldimage = $this->img->CloneCanvasH();
  1603. }
  1604. if( ! $this->y2orderback ) {
  1605. // Stroke all plots for Y1 axis
  1606. for($i=0; $i < count($this->plots); ++$i) {
  1607. $this->plots[$i]->Stroke($this->img,$this->xscale,$this->yscale);
  1608. $this->plots[$i]->StrokeMargin($this->img);
  1609. }
  1610. }
  1611. // Stroke all plots for Y2 axis
  1612. if( $this->y2scale != null )
  1613. for($i=0; $i< count($this->y2plots); ++$i ) {
  1614. $this->y2plots[$i]->Stroke($this->img,$this->xscale,$this->y2scale);
  1615. }
  1616. if( $this->y2orderback ) {
  1617. // Stroke all plots for Y1 axis
  1618. for($i=0; $i < count($this->plots); ++$i) {
  1619. $this->plots[$i]->Stroke($this->img,$this->xscale,$this->yscale);
  1620. $this->plots[$i]->StrokeMargin($this->img);
  1621. }
  1622. }
  1623. $n = count($this->ynaxis);
  1624. for( $i=0; $i < $n; ++$i ) {
  1625. $m = count($this->ynplots[$i]);
  1626. for( $j=0; $j < $m; ++$j ) {
  1627. $this->ynplots[$i][$j]->Stroke($this->img,$this->xscale,$this->ynscale[$i]);
  1628. $this->ynplots[$i][$j]->StrokeMargin($this->img);
  1629. }
  1630. }
  1631. if( $this->iIconDepth == DEPTH_FRONT) {
  1632. $this->StrokeIcons();
  1633. }
  1634. if( $this->iDoClipping ) {
  1635. // Clipping only supports graphs at 0 and 90 degrees
  1636. if( $this->img->a == 0 ) {
  1637. $this->img->CopyCanvasH($oldimage,$this->img->img,
  1638. $this->img->left_margin,$this->img->top_margin,
  1639. $this->img->left_margin,$this->img->top_margin,
  1640. $this->img->plotwidth+1,$this->img->plotheight);
  1641. }
  1642. elseif( $this->img->a == 90 ) {
  1643. $adj = ($this->img->height - $this->img->width)/2;
  1644. $this->img->CopyCanvasH($oldimage,$this->img->img,
  1645. $this->img->bottom_margin-$adj,$this->img->left_margin+$adj,
  1646. $this->img->bottom_margin-$adj,$this->img->left_margin+$adj,
  1647. $this->img->plotheight+1,$this->img->plotwidth);
  1648. }
  1649. else {
  1650. JpGraphError::RaiseL(25035,$this->img->a);//('You have enabled clipping. Cliping is only supported for graphs at 0 or 90 degrees rotation. Please adjust you current angle (='.$this->img->a.' degrees) or disable clipping.');
  1651. }
  1652. $this->img->Destroy();
  1653. $this->img->SetCanvasH($oldimage);
  1654. }
  1655. $this->xscale->off=$oldoff;
  1656. if( $this->grid_depth == DEPTH_FRONT && !$_csim ) {
  1657. $this->ygrid->Stroke();
  1658. $this->xgrid->Stroke();
  1659. }
  1660. // Stroke bands
  1661. if( $this->bands!= null )
  1662. for($i=0; $i < count($this->bands); ++$i) {
  1663. // Stroke all bands that asks to be in the foreground
  1664. if( $this->bands[$i]->depth == DEPTH_FRONT )
  1665. $this->bands[$i]->Stroke($this->img,$this->xscale,$this->yscale);
  1666. }
  1667. if( $this->y2bands!= null && $this->y2scale != null )
  1668. for($i=0; $i < count($this->y2bands); ++$i) {
  1669. // Stroke all bands that asks to be in the foreground
  1670. if( $this->y2bands[$i]->depth == DEPTH_FRONT )
  1671. $this->y2bands[$i]->Stroke($this->img,$this->xscale,$this->y2scale);
  1672. }
  1673. // Stroke any lines added
  1674. if( $this->lines != null ) {
  1675. for($i=0; $i < count($this->lines); ++$i) {
  1676. $this->lines[$i]->Stroke($this->img,$this->xscale,$this->yscale);
  1677. $this->lines[$i]->DoLegend($this);
  1678. }
  1679. }
  1680. if( $this->y2lines != null && $this->y2scale != null ) {
  1681. for($i=0; $i < count($this->y2lines); ++$i) {
  1682. $this->y2lines[$i]->Stroke($this->img,$this->xscale,$this->y2scale);
  1683. $this->y2lines[$i]->DoLegend($this);
  1684. }
  1685. }
  1686. // Finally draw the axis again since some plots may have nagged
  1687. // the axis in the edges.
  1688. if( !$_csim ) {
  1689. $this->StrokeAxis();
  1690. }
  1691. if( $this->y2scale != null && !$_csim )
  1692. $this->y2axis->Stroke($this->xscale,false);
  1693. if( !$_csim ) {
  1694. $this->StrokePlotBox();
  1695. }
  1696. // The titles and legends never gets rotated so make sure
  1697. // that the angle is 0 before stroking them
  1698. $aa = $this->img->SetAngle(0);
  1699. $this->StrokeTitles();
  1700. $this->footer->Stroke($this->img);
  1701. $this->legend->Stroke($this->img);
  1702. $this->img->SetAngle($aa);
  1703. $this->StrokeTexts();
  1704. $this->StrokeTables();
  1705. if( !$_csim ) {
  1706. $this->img->SetAngle($aa);
  1707. // Draw an outline around the image map
  1708. if(_JPG_DEBUG) {
  1709. $this->DisplayClientSideaImageMapAreas();
  1710. }
  1711. // Should we do any final image transformation
  1712. if( $this->iImgTrans ) {
  1713. if( !class_exists('ImgTrans',false) ) {
  1714. require_once('jpgraph_imgtrans.php');
  1715. //JpGraphError::Raise('In order to use image transformation you must include the file jpgraph_imgtrans.php in your script.');
  1716. }
  1717. $tform = new ImgTrans($this->img->img);
  1718. $this->img->img = $tform->Skew3D($this->iImgTransHorizon,$this->iImgTransSkewDist,
  1719. $this->iImgTransDirection,$this->iImgTransHighQ,
  1720. $this->iImgTransMinSize,$this->iImgTransFillColor,
  1721. $this->iImgTransBorder);
  1722. }
  1723. // If the filename is given as the special "__handle"
  1724. // then the image handler is returned and the image is NOT
  1725. // streamed back
  1726. if( $aStrokeFileName == _IMG_HANDLER ) {
  1727. return $this->img->img;
  1728. }
  1729. else {
  1730. // Finally stream the generated picture
  1731. $this->cache->PutAndStream($this->img,$this->cache_name,$this->inline,$aStrokeFileName);
  1732. }
  1733. }
  1734. }
  1735. function SetAxisLabelBackground($aType,$aXFColor='lightgray',$aXColor='black',$aYFColor='lightgray',$aYColor='black') {
  1736. $this->iAxisLblBgType = $aType;
  1737. $this->iXAxisLblBgFillColor = $aXFColor;
  1738. $this->iXAxisLblBgColor = $aXColor;
  1739. $this->iYAxisLblBgFillColor = $aYFColor;
  1740. $this->iYAxisLblBgColor = $aYColor;
  1741. }
  1742. //---------------
  1743. // PRIVATE METHODS
  1744. function StrokeAxisLabelBackground() {
  1745. // Types
  1746. // 0 = No background
  1747. // 1 = Only X-labels, length of axis
  1748. // 2 = Only Y-labels, length of axis
  1749. // 3 = As 1 but extends to width of graph
  1750. // 4 = As 2 but extends to height of graph
  1751. // 5 = Combination of 3 & 4
  1752. // 6 = Combination of 1 & 2
  1753. $t = $this->iAxisLblBgType ;
  1754. if( $t < 1 ) return;
  1755. // Stroke optional X-axis label background color
  1756. if( $t == 1 || $t == 3 || $t == 5 || $t == 6 ) {
  1757. $this->img->PushColor($this->iXAxisLblBgFillColor);
  1758. if( $t == 1 || $t == 6 ) {
  1759. $xl = $this->img->left_margin;
  1760. $yu = $this->img->height - $this->img->bottom_margin + 1;
  1761. $xr = $this->img->width - $this->img->right_margin ;
  1762. $yl = $this->img->height-1-$this->frame_weight;
  1763. }
  1764. else { // t==3 || t==5
  1765. $xl = $this->frame_weight;
  1766. $yu = $this->img->height - $this->img->bottom_margin + 1;
  1767. $xr = $this->img->width - 1 - $this->frame_weight;
  1768. $yl = $this->img->height-1-$this->frame_weight;
  1769. }
  1770. $this->img->FilledRectangle($xl,$yu,$xr,$yl);
  1771. $this->img->PopColor();
  1772. // Check if we should add the vertical lines at left and right edge
  1773. if( $this->iXAxisLblBgColor !== '' ) {
  1774. $this->img->PushColor($this->iXAxisLblBgColor);
  1775. if( $t == 1 || $t == 6 ) {
  1776. $this->img->Line($xl,$yu,$xl,$yl);
  1777. $this->img->Line($xr,$yu,$xr,$yl);
  1778. }
  1779. else {
  1780. $xl = $this->img->width - $this->img->right_margin ;
  1781. $this->img->Line($xl,$yu-1,$xr,$yu-1);
  1782. }
  1783. $this->img->PopColor();
  1784. }
  1785. }
  1786. if( $t == 2 || $t == 4 || $t == 5 || $t == 6 ) {
  1787. $this->img->PushColor($this->iYAxisLblBgFillColor);
  1788. if( $t == 2 || $t == 6 ) {
  1789. $xl = $this->frame_weight;
  1790. $yu = $this->frame_weight+$this->img->top_margin;
  1791. $xr = $this->img->left_margin - 1;
  1792. $yl = $this->img->height - $this->img->bottom_margin + 1;
  1793. }
  1794. else {
  1795. $xl = $this->frame_weight;
  1796. $yu = $this->frame_weight;
  1797. $xr = $this->img->left_margin - 1;
  1798. $yl = $this->img->height-1-$this->frame_weight;
  1799. }
  1800. $this->img->FilledRectangle($xl,$yu,$xr,$yl);
  1801. $this->img->PopColor();
  1802. // Check if we should add the vertical lines at left and right edge
  1803. if( $this->iXAxisLblBgColor !== '' ) {
  1804. $this->img->PushColor($this->iXAxisLblBgColor);
  1805. if( $t == 2 || $t == 6 ) {
  1806. $this->img->Line($xl,$yu-1,$xr,$yu-1);
  1807. $this->img->Line($xl,$yl-1,$xr,$yl-1);
  1808. }
  1809. else {
  1810. $this->img->Line($xr+1,$yu,$xr+1,$this->img->top_margin);
  1811. }
  1812. $this->img->PopColor();
  1813. }
  1814. }
  1815. }
  1816. function StrokeAxis($aStrokeLabels=true) {
  1817. if( $aStrokeLabels ) {
  1818. $this->StrokeAxisLabelBackground();
  1819. }
  1820. // Stroke axis
  1821. if( $this->iAxisStyle != AXSTYLE_SIMPLE ) {
  1822. switch( $this->iAxisStyle ) {
  1823. case AXSTYLE_BOXIN :
  1824. $toppos = SIDE_DOWN;
  1825. $bottompos = SIDE_UP;
  1826. $leftpos = SIDE_RIGHT;
  1827. $rightpos = SIDE_LEFT;
  1828. break;
  1829. case AXSTYLE_BOXOUT :
  1830. $toppos = SIDE_UP;
  1831. $bottompos = SIDE_DOWN;
  1832. $leftpos = SIDE_LEFT;
  1833. $rightpos = SIDE_RIGHT;
  1834. break;
  1835. case AXSTYLE_YBOXIN:
  1836. $toppos = FALSE;
  1837. $bottompos = SIDE_UP;
  1838. $leftpos = SIDE_RIGHT;
  1839. $rightpos = SIDE_LEFT;
  1840. break;
  1841. case AXSTYLE_YBOXOUT:
  1842. $toppos = FALSE;
  1843. $bottompos = SIDE_DOWN;
  1844. $leftpos = SIDE_LEFT;
  1845. $rightpos = SIDE_RIGHT;
  1846. break;
  1847. default:
  1848. JpGRaphError::RaiseL(25036,$this->iAxisStyle); //('Unknown AxisStyle() : '.$this->iAxisStyle);
  1849. break;
  1850. }
  1851. // By default we hide the first label so it doesn't cross the
  1852. // Y-axis in case the positon hasn't been set by the user.
  1853. // However, if we use a box we always want the first value
  1854. // displayed so we make sure it will be displayed.
  1855. $this->xscale->ticks->SupressFirst(false);
  1856. // Now draw the bottom X-axis
  1857. $this->xaxis->SetPos('min');
  1858. $this->xaxis->SetLabelSide(SIDE_DOWN);
  1859. $this->xaxis->scale->ticks->SetSide($bottompos);
  1860. $this->xaxis->Stroke($this->yscale,$aStrokeLabels);
  1861. if( $toppos !== FALSE ) {
  1862. // We also want a top X-axis
  1863. $this->xaxis = $this->xaxis;
  1864. $this->xaxis->SetPos('max');
  1865. $this->xaxis->SetLabelSide(SIDE_UP);
  1866. // No title for the top X-axis
  1867. if( $aStrokeLabels ) {
  1868. $this->xaxis->title->Set('');
  1869. }
  1870. $this->xaxis->scale->ticks->SetSide($toppos);
  1871. $this->xaxis->Stroke($this->yscale,$aStrokeLabels);
  1872. }
  1873. // Stroke the left Y-axis
  1874. $this->yaxis->SetPos('min');
  1875. $this->yaxis->SetLabelSide(SIDE_LEFT);
  1876. $this->yaxis->scale->ticks->SetSide($leftpos);
  1877. $this->yaxis->Stroke($this->xscale,$aStrokeLabels);
  1878. // Stroke the right Y-axis
  1879. $this->yaxis->SetPos('max');
  1880. // No title for the right side
  1881. if( $aStrokeLabels ) {
  1882. $this->yaxis->title->Set('');
  1883. }
  1884. $this->yaxis->SetLabelSide(SIDE_RIGHT);
  1885. $this->yaxis->scale->ticks->SetSide($rightpos);
  1886. $this->yaxis->Stroke($this->xscale,$aStrokeLabels);
  1887. }
  1888. else {
  1889. $this->xaxis->Stroke($this->yscale,$aStrokeLabels);
  1890. $this->yaxis->Stroke($this->xscale,$aStrokeLabels);
  1891. }
  1892. }
  1893. // Private helper function for backgound image
  1894. static function LoadBkgImage($aImgFormat='',$aFile='',$aImgStr='') {
  1895. if( $aImgStr != '' ) {
  1896. return Image::CreateFromString($aImgStr);
  1897. }
  1898. // Remove case sensitivity and setup appropriate function to create image
  1899. // Get file extension. This should be the LAST '.' separated part of the filename
  1900. $e = explode('.',$aFile);
  1901. $ext = strtolower($e[count($e)-1]);
  1902. if ($ext == "jpeg") {
  1903. $ext = "jpg";
  1904. }
  1905. if( trim($ext) == '' )
  1906. $ext = 'png'; // Assume PNG if no extension specified
  1907. if( $aImgFormat == '' )
  1908. $imgtag = $ext;
  1909. else
  1910. $imgtag = $aImgFormat;
  1911. $supported = imagetypes();
  1912. if( ( $ext == 'jpg' && !($supported & IMG_JPG) ) ||
  1913. ( $ext == 'gif' && !($supported & IMG_GIF) ) ||
  1914. ( $ext == 'png' && !($supported & IMG_PNG) ) ||
  1915. ( $ext == 'bmp' && !($supported & IMG_WBMP) ) ||
  1916. ( $ext == 'xpm' && !($supported & IMG_XPM) ) ) {
  1917. JpGraphError::RaiseL(25037,$aFile);//('The image format of your background image ('.$aFile.') is not supported in your system configuration. ');
  1918. }
  1919. if( $imgtag == "jpg" || $imgtag == "jpeg")
  1920. {
  1921. $f = "imagecreatefromjpeg";
  1922. $imgtag = "jpg";
  1923. }
  1924. else
  1925. {
  1926. $f = "imagecreatefrom".$imgtag;
  1927. }
  1928. // Compare specified image type and file extension
  1929. if( $imgtag != $ext ) {
  1930. //$t = "Background image seems to be of different type (has different file extension) than specified imagetype. Specified: '".$aImgFormat."'File: '".$aFile."'";
  1931. JpGraphError::RaiseL(25038, $aImgFormat, $aFile);
  1932. }
  1933. $img = @$f($aFile);
  1934. if( !$img ) {
  1935. JpGraphError::RaiseL(25039,$aFile);//(" Can't read background image: '".$aFile."'");
  1936. }
  1937. return $img;
  1938. }
  1939. function StrokeBackgroundGrad() {
  1940. if( $this->bkg_gradtype < 0 )
  1941. return;
  1942. $grad = new Gradient($this->img);
  1943. if( $this->bkg_gradstyle == BGRAD_PLOT ) {
  1944. $xl = $this->img->left_margin;
  1945. $yt = $this->img->top_margin;
  1946. $xr = $xl + $this->img->plotwidth+1 ;
  1947. $yb = $yt + $this->img->plotheight ;
  1948. $grad->FilledRectangle($xl,$yt,$xr,$yb,$this->bkg_gradfrom,$this->bkg_gradto,$this->bkg_gradtype);
  1949. }
  1950. else {
  1951. $xl = 0;
  1952. $yt = 0;
  1953. $xr = $xl + $this->img->width - 1;
  1954. $yb = $yt + $this->img->height ;
  1955. if( $this->doshadow ) {
  1956. $xr -= $this->shadow_width;
  1957. $yb -= $this->shadow_width;
  1958. }
  1959. if( $this->doframe ) {
  1960. $yt += $this->frame_weight;
  1961. $yb -= $this->frame_weight;
  1962. $xl += $this->frame_weight;
  1963. $xr -= $this->frame_weight;
  1964. }
  1965. $aa = $this->img->SetAngle(0);
  1966. $grad->FilledRectangle($xl,$yt,$xr,$yb,$this->bkg_gradfrom,$this->bkg_gradto,$this->bkg_gradtype);
  1967. $aa = $this->img->SetAngle($aa);
  1968. }
  1969. }
  1970. function StrokeFrameBackground() {
  1971. if( $this->background_image != "" && $this->background_cflag != "" ) {
  1972. JpGraphError::RaiseL(25040);//('It is not possible to specify both a background image and a background country flag.');
  1973. }
  1974. if( $this->background_image != "" ) {
  1975. $bkgimg = $this->LoadBkgImage($this->background_image_format,$this->background_image);
  1976. }
  1977. elseif( $this->background_cflag != "" ) {
  1978. if( ! class_exists('FlagImages',false) ) {
  1979. JpGraphError::RaiseL(25041);//('In order to use Country flags as backgrounds you must include the "jpgraph_flags.php" file.');
  1980. }
  1981. $fobj = new FlagImages(FLAGSIZE4);
  1982. $dummy='';
  1983. $bkgimg = $fobj->GetImgByName($this->background_cflag,$dummy);
  1984. $this->background_image_mix = $this->background_cflag_mix;
  1985. $this->background_image_type = $this->background_cflag_type;
  1986. }
  1987. else {
  1988. return ;
  1989. }
  1990. $bw = ImageSX($bkgimg);
  1991. $bh = ImageSY($bkgimg);
  1992. // No matter what the angle is we always stroke the image and frame
  1993. // assuming it is 0 degree
  1994. $aa = $this->img->SetAngle(0);
  1995. switch( $this->background_image_type ) {
  1996. case BGIMG_FILLPLOT: // Resize to just fill the plotarea
  1997. $this->FillMarginArea();
  1998. $this->StrokeFrame();
  1999. // Special case to hande 90 degree rotated graph corectly
  2000. if( $aa == 90 ) {
  2001. $this->img->SetAngle(90);
  2002. $this->FillPlotArea();
  2003. $aa = $this->img->SetAngle(0);
  2004. $adj = ($this->img->height - $this->img->width)/2;
  2005. $this->img->CopyMerge($bkgimg,
  2006. $this->img->bottom_margin-$adj,$this->img->left_margin+$adj,
  2007. 0,0,
  2008. $this->img->plotheight+1,$this->img->plotwidth,
  2009. $bw,$bh,$this->background_image_mix);
  2010. }
  2011. else {
  2012. $this->FillPlotArea();
  2013. $this->img->CopyMerge($bkgimg,
  2014. $this->img->left_margin,$this->img->top_margin,
  2015. 0,0,$this->img->plotwidth+1,$this->img->plotheight,
  2016. $bw,$bh,$this->background_image_mix);
  2017. }
  2018. break;
  2019. case BGIMG_FILLFRAME: // Fill the whole area from upper left corner, resize to just fit
  2020. $hadj=0; $vadj=0;
  2021. if( $this->doshadow ) {
  2022. $hadj = $this->shadow_width;
  2023. $vadj = $this->shadow_width;
  2024. }
  2025. $this->FillMarginArea();
  2026. $this->FillPlotArea();
  2027. $this->img->CopyMerge($bkgimg,0,0,0,0,$this->img->width-$hadj,$this->img->height-$vadj,
  2028. $bw,$bh,$this->background_image_mix);
  2029. $this->StrokeFrame();
  2030. break;
  2031. case BGIMG_COPY: // Just copy the image from left corner, no resizing
  2032. $this->FillMarginArea();
  2033. $this->FillPlotArea();
  2034. $this->img->CopyMerge($bkgimg,0,0,0,0,$bw,$bh,
  2035. $bw,$bh,$this->background_image_mix);
  2036. $this->StrokeFrame();
  2037. break;
  2038. case BGIMG_CENTER: // Center original image in the plot area
  2039. $this->FillMarginArea();
  2040. $this->FillPlotArea();
  2041. $centerx = round($this->img->plotwidth/2+$this->img->left_margin-$bw/2);
  2042. $centery = round($this->img->plotheight/2+$this->img->top_margin-$bh/2);
  2043. $this->img->CopyMerge($bkgimg,$centerx,$centery,0,0,$bw,$bh,
  2044. $bw,$bh,$this->background_image_mix);
  2045. $this->StrokeFrame();
  2046. break;
  2047. default:
  2048. JpGraphError::RaiseL(25042);//(" Unknown background image layout");
  2049. }
  2050. $this->img->SetAngle($aa);
  2051. }
  2052. // Private
  2053. // Draw a frame around the image
  2054. function StrokeFrame() {
  2055. if( !$this->doframe ) return;
  2056. if( $this->background_image_type <= 1 &&
  2057. ($this->bkg_gradtype < 0 || ($this->bkg_gradtype > 0 && $this->bkg_gradstyle==BGRAD_PLOT)) ) {
  2058. $c = $this->margin_color;
  2059. }
  2060. else {
  2061. $c = false;
  2062. }
  2063. if( $this->doshadow ) {
  2064. $this->img->SetColor($this->frame_color);
  2065. $this->img->ShadowRectangle(0,0,$this->img->width,$this->img->height,
  2066. $c,$this->shadow_width,$this->shadow_color);
  2067. }
  2068. elseif( $this->framebevel ) {
  2069. if( $c ) {
  2070. $this->img->SetColor($this->margin_color);
  2071. $this->img->FilledRectangle(0,0,$this->img->width-1,$this->img->height-1);
  2072. }
  2073. $this->img->Bevel(1,1,$this->img->width-2,$this->img->height-2,
  2074. $this->framebeveldepth,
  2075. $this->framebevelcolor1,$this->framebevelcolor2);
  2076. if( $this->framebevelborder ) {
  2077. $this->img->SetColor($this->framebevelbordercolor);
  2078. $this->img->Rectangle(0,0,$this->img->width-1,$this->img->height-1);
  2079. }
  2080. }
  2081. else {
  2082. $this->img->SetLineWeight($this->frame_weight);
  2083. if( $c ) {
  2084. $this->img->SetColor($this->margin_color);
  2085. $this->img->FilledRectangle(0,0,$this->img->width-1,$this->img->height-1);
  2086. }
  2087. $this->img->SetColor($this->frame_color);
  2088. $this->img->Rectangle(0,0,$this->img->width-1,$this->img->height-1);
  2089. }
  2090. }
  2091. function FillMarginArea() {
  2092. $hadj=0; $vadj=0;
  2093. if( $this->doshadow ) {
  2094. $hadj = $this->shadow_width;
  2095. $vadj = $this->shadow_width;
  2096. }
  2097. $this->img->SetColor($this->margin_color);
  2098. // $this->img->FilledRectangle(0,0,$this->img->width-1-$hadj,$this->img->height-1-$vadj);
  2099. $this->img->FilledRectangle(0,0,$this->img->width-1-$hadj,$this->img->top_margin);
  2100. $this->img->FilledRectangle(0,$this->img->top_margin,$this->img->left_margin,$this->img->height-1-$hadj);
  2101. $this->img->FilledRectangle($this->img->left_margin+1,
  2102. $this->img->height-$this->img->bottom_margin,
  2103. $this->img->width-1-$hadj,
  2104. $this->img->height-1-$hadj);
  2105. $this->img->FilledRectangle($this->img->width-$this->img->right_margin,
  2106. $this->img->top_margin+1,
  2107. $this->img->width-1-$hadj,
  2108. $this->img->height-$this->img->bottom_margin-1);
  2109. }
  2110. function FillPlotArea() {
  2111. $this->img->PushColor($this->plotarea_color);
  2112. $this->img->FilledRectangle($this->img->left_margin,
  2113. $this->img->top_margin,
  2114. $this->img->width-$this->img->right_margin,
  2115. $this->img->height-$this->img->bottom_margin);
  2116. $this->img->PopColor();
  2117. }
  2118. // Stroke the plot area with either a solid color or a background image
  2119. function StrokePlotArea() {
  2120. // Note: To be consistent we really should take a possible shadow
  2121. // into account. However, that causes some problem for the LinearScale class
  2122. // since in the current design it does not have any links to class Graph which
  2123. // means it has no way of compensating for the adjusted plotarea in case of a
  2124. // shadow. So, until I redesign LinearScale we can't compensate for this.
  2125. // So just set the two adjustment parameters to zero for now.
  2126. $boxadj = 0; //$this->doframe ? $this->frame_weight : 0 ;
  2127. $adj = 0; //$this->doshadow ? $this->shadow_width : 0 ;
  2128. if( $this->background_image != "" || $this->background_cflag != "" ) {
  2129. $this->StrokeFrameBackground();
  2130. }
  2131. else {
  2132. $aa = $this->img->SetAngle(0);
  2133. $this->StrokeFrame();
  2134. $aa = $this->img->SetAngle($aa);
  2135. $this->StrokeBackgroundGrad();
  2136. if( $this->bkg_gradtype < 0 ||
  2137. ($this->bkg_gradtype > 0 && $this->bkg_gradstyle==BGRAD_MARGIN) ) {
  2138. $this->FillPlotArea();
  2139. }
  2140. }
  2141. }
  2142. function StrokeIcons() {
  2143. $n = count($this->iIcons);
  2144. for( $i=0; $i < $n; ++$i ) {
  2145. $this->iIcons[$i]->StrokeWithScale($this->img,$this->xscale,$this->yscale);
  2146. }
  2147. }
  2148. function StrokePlotBox() {
  2149. // Should we draw a box around the plot area?
  2150. if( $this->boxed ) {
  2151. $this->img->SetLineWeight(1);
  2152. $this->img->SetLineStyle('solid');
  2153. $this->img->SetColor($this->box_color);
  2154. for($i=0; $i < $this->box_weight; ++$i ) {
  2155. $this->img->Rectangle(
  2156. $this->img->left_margin-$i,$this->img->top_margin-$i,
  2157. $this->img->width-$this->img->right_margin+$i,
  2158. $this->img->height-$this->img->bottom_margin+$i);
  2159. }
  2160. }
  2161. }
  2162. function SetTitleBackgroundFillStyle($aStyle,$aColor1='black',$aColor2='white') {
  2163. $this->titlebkg_fillstyle = $aStyle;
  2164. $this->titlebkg_scolor1 = $aColor1;
  2165. $this->titlebkg_scolor2 = $aColor2;
  2166. }
  2167. function SetTitleBackground($aBackColor='gray', $aStyle=TITLEBKG_STYLE1, $aFrameStyle=TITLEBKG_FRAME_NONE, $aFrameColor='black', $aFrameWeight=1, $aBevelHeight=3, $aEnable=true) {
  2168. $this->titlebackground = $aEnable;
  2169. $this->titlebackground_color = $aBackColor;
  2170. $this->titlebackground_style = $aStyle;
  2171. $this->titlebackground_framecolor = $aFrameColor;
  2172. $this->titlebackground_framestyle = $aFrameStyle;
  2173. $this->titlebackground_frameweight = $aFrameWeight;
  2174. $this->titlebackground_bevelheight = $aBevelHeight ;
  2175. }
  2176. function StrokeTitles() {
  2177. $margin=3;
  2178. if( $this->titlebackground ) {
  2179. // Find out height
  2180. $this->title->margin += 2 ;
  2181. $h = $this->title->GetTextHeight($this->img)+$this->title->margin+$margin;
  2182. if( $this->subtitle->t != "" && !$this->subtitle->hide ) {
  2183. $h += $this->subtitle->GetTextHeight($this->img)+$margin+
  2184. $this->subtitle->margin;
  2185. $h += 2;
  2186. }
  2187. if( $this->subsubtitle->t != "" && !$this->subsubtitle->hide ) {
  2188. $h += $this->subsubtitle->GetTextHeight($this->img)+$margin+
  2189. $this->subsubtitle->margin;
  2190. $h += 2;
  2191. }
  2192. $this->img->PushColor($this->titlebackground_color);
  2193. if( $this->titlebackground_style === TITLEBKG_STYLE1 ) {
  2194. // Inside the frame
  2195. if( $this->framebevel ) {
  2196. $x1 = $y1 = $this->framebeveldepth + 1 ;
  2197. $x2 = $this->img->width - $this->framebeveldepth - 2 ;
  2198. $this->title->margin += $this->framebeveldepth + 1 ;
  2199. $h += $y1 ;
  2200. $h += 2;
  2201. }
  2202. else {
  2203. $x1 = $y1 = $this->frame_weight;
  2204. $x2 = $this->img->width - 2*$x1;
  2205. }
  2206. }
  2207. elseif( $this->titlebackground_style === TITLEBKG_STYLE2 ) {
  2208. // Cover the frame as well
  2209. $x1 = $y1 = 0;
  2210. $x2 = $this->img->width - 1 ;
  2211. }
  2212. elseif( $this->titlebackground_style === TITLEBKG_STYLE3 ) {
  2213. // Cover the frame as well (the difference is that
  2214. // for style==3 a bevel frame border is on top
  2215. // of the title background)
  2216. $x1 = $y1 = 0;
  2217. $x2 = $this->img->width - 1 ;
  2218. $h += $this->framebeveldepth ;
  2219. $this->title->margin += $this->framebeveldepth ;
  2220. }
  2221. else {
  2222. JpGraphError::RaiseL(25043);//('Unknown title background style.');
  2223. }
  2224. if( $this->titlebackground_framestyle === 3 ) {
  2225. $h += $this->titlebackground_bevelheight*2 + 1 ;
  2226. $this->title->margin += $this->titlebackground_bevelheight ;
  2227. }
  2228. if( $this->doshadow ) {
  2229. $x2 -= $this->shadow_width ;
  2230. }
  2231. $indent=0;
  2232. if( $this->titlebackground_framestyle == TITLEBKG_FRAME_BEVEL ) {
  2233. $ind = $this->titlebackground_bevelheight;
  2234. }
  2235. if( $this->titlebkg_fillstyle==TITLEBKG_FILLSTYLE_HSTRIPED ) {
  2236. $this->img->FilledRectangle2($x1+$ind,$y1+$ind,$x2-$ind,$h-$ind,
  2237. $this->titlebkg_scolor1,
  2238. $this->titlebkg_scolor2);
  2239. }
  2240. elseif( $this->titlebkg_fillstyle==TITLEBKG_FILLSTYLE_VSTRIPED ) {
  2241. $this->img->FilledRectangle2($x1+$ind,$y1+$ind,$x2-$ind,$h-$ind,
  2242. $this->titlebkg_scolor1,
  2243. $this->titlebkg_scolor2,2);
  2244. }
  2245. else {
  2246. // Solid fill
  2247. $this->img->FilledRectangle($x1,$y1,$x2,$h);
  2248. }
  2249. $this->img->PopColor();
  2250. $this->img->PushColor($this->titlebackground_framecolor);
  2251. $this->img->SetLineWeight($this->titlebackground_frameweight);
  2252. if( $this->titlebackground_framestyle == TITLEBKG_FRAME_FULL ) {
  2253. // Frame background
  2254. $this->img->Rectangle($x1,$y1,$x2,$h);
  2255. }
  2256. elseif( $this->titlebackground_framestyle == TITLEBKG_FRAME_BOTTOM ) {
  2257. // Bottom line only
  2258. $this->img->Line($x1,$h,$x2,$h);
  2259. }
  2260. elseif( $this->titlebackground_framestyle == TITLEBKG_FRAME_BEVEL ) {
  2261. $this->img->Bevel($x1,$y1,$x2,$h,$this->titlebackground_bevelheight);
  2262. }
  2263. $this->img->PopColor();
  2264. // This is clumsy. But we neeed to stroke the whole graph frame if it is
  2265. // set to bevel to get the bevel shading on top of the text background
  2266. if( $this->framebevel && $this->doframe &&
  2267. $this->titlebackground_style === 3 ) {
  2268. $this->img->Bevel(1,1,$this->img->width-2,$this->img->height-2,
  2269. $this->framebeveldepth,
  2270. $this->framebevelcolor1,$this->framebevelcolor2);
  2271. if( $this->framebevelborder ) {
  2272. $this->img->SetColor($this->framebevelbordercolor);
  2273. $this->img->Rectangle(0,0,$this->img->width-1,$this->img->height-1);
  2274. }
  2275. }
  2276. }
  2277. // Stroke title
  2278. $y = $this->title->margin;
  2279. if( $this->title->halign == 'center' )
  2280. $this->title->Center(0,$this->img->width,$y);
  2281. elseif( $this->title->halign == 'left' ) {
  2282. $this->title->SetPos($this->title->margin+2,$y);
  2283. }
  2284. elseif( $this->title->halign == 'right' ) {
  2285. $indent = 0;
  2286. if( $this->doshadow )
  2287. $indent = $this->shadow_width+2;
  2288. $this->title->SetPos($this->img->width-$this->title->margin-$indent,$y,'right');
  2289. }
  2290. $this->title->Stroke($this->img);
  2291. // ... and subtitle
  2292. $y += $this->title->GetTextHeight($this->img) + $margin + $this->subtitle->margin;
  2293. if( $this->subtitle->halign == 'center' )
  2294. $this->subtitle->Center(0,$this->img->width,$y);
  2295. elseif( $this->subtitle->halign == 'left' ) {
  2296. $this->subtitle->SetPos($this->subtitle->margin+2,$y);
  2297. }
  2298. elseif( $this->subtitle->halign == 'right' ) {
  2299. $indent = 0;
  2300. if( $this->doshadow )
  2301. $indent = $this->shadow_width+2;
  2302. $this->subtitle->SetPos($this->img->width-$this->subtitle->margin-$indent,$y,'right');
  2303. }
  2304. $this->subtitle->Stroke($this->img);
  2305. // ... and subsubtitle
  2306. $y += $this->subtitle->GetTextHeight($this->img) + $margin + $this->subsubtitle->margin;
  2307. if( $this->subsubtitle->halign == 'center' )
  2308. $this->subsubtitle->Center(0,$this->img->width,$y);
  2309. elseif( $this->subsubtitle->halign == 'left' ) {
  2310. $this->subsubtitle->SetPos($this->subsubtitle->margin+2,$y);
  2311. }
  2312. elseif( $this->subsubtitle->halign == 'right' ) {
  2313. $indent = 0;
  2314. if( $this->doshadow )
  2315. $indent = $this->shadow_width+2;
  2316. $this->subsubtitle->SetPos($this->img->width-$this->subsubtitle->margin-$indent,$y,'right');
  2317. }
  2318. $this->subsubtitle->Stroke($this->img);
  2319. // ... and fancy title
  2320. $this->tabtitle->Stroke($this->img);
  2321. }
  2322. function StrokeTexts() {
  2323. // Stroke any user added text objects
  2324. if( $this->texts != null ) {
  2325. for($i=0; $i < count($this->texts); ++$i) {
  2326. $this->texts[$i]->StrokeWithScale($this->img,$this->xscale,$this->yscale);
  2327. }
  2328. }
  2329. if( $this->y2texts != null && $this->y2scale != null ) {
  2330. for($i=0; $i < count($this->y2texts); ++$i) {
  2331. $this->y2texts[$i]->StrokeWithScale($this->img,$this->xscale,$this->y2scale);
  2332. }
  2333. }
  2334. }
  2335. function StrokeTables() {
  2336. if( $this->iTables != null ) {
  2337. $n = count($this->iTables);
  2338. for( $i=0; $i < $n; ++$i ) {
  2339. $this->iTables[$i]->StrokeWithScale($this->img,$this->xscale,$this->yscale);
  2340. }
  2341. }
  2342. }
  2343. function DisplayClientSideaImageMapAreas() {
  2344. // Debug stuff - display the outline of the image map areas
  2345. $csim='';
  2346. foreach ($this->plots as $p) {
  2347. $csim.= $p->GetCSIMareas();
  2348. }
  2349. $csim .= $this->legend->GetCSIMareas();
  2350. if (preg_match_all("/area shape=\"(\w+)\" coords=\"([0-9\, ]+)\"/", $csim, $coords)) {
  2351. $this->img->SetColor($this->csimcolor);
  2352. $n = count($coords[0]);
  2353. for ($i=0; $i < $n; $i++) {
  2354. if ($coords[1][$i]=="poly") {
  2355. preg_match_all('/\s*([0-9]+)\s*,\s*([0-9]+)\s*,*/',$coords[2][$i],$pts);
  2356. $this->img->SetStartPoint($pts[1][count($pts[0])-1],$pts[2][count($pts[0])-1]);
  2357. $m = count($pts[0]);
  2358. for ($j=0; $j < $m; $j++) {
  2359. $this->img->LineTo($pts[1][$j],$pts[2][$j]);
  2360. }
  2361. } else if ($coords[1][$i]=="rect") {
  2362. $pts = preg_split('/,/', $coords[2][$i]);
  2363. $this->img->SetStartPoint($pts[0],$pts[1]);
  2364. $this->img->LineTo($pts[2],$pts[1]);
  2365. $this->img->LineTo($pts[2],$pts[3]);
  2366. $this->img->LineTo($pts[0],$pts[3]);
  2367. $this->img->LineTo($pts[0],$pts[1]);
  2368. }
  2369. }
  2370. }
  2371. }
  2372. // Text scale offset in world coordinates
  2373. function SetTextScaleOff($aOff) {
  2374. $this->text_scale_off = $aOff;
  2375. $this->xscale->text_scale_off = $aOff;
  2376. }
  2377. // Text width of bar to be centered in absolute pixels
  2378. function SetTextScaleAbsCenterOff($aOff) {
  2379. $this->text_scale_abscenteroff = $aOff;
  2380. }
  2381. // Get Y min and max values for added lines
  2382. function GetLinesYMinMax( $aLines ) {
  2383. $n = count($aLines);
  2384. if( $n == 0 ) return false;
  2385. $min = $aLines[0]->scaleposition ;
  2386. $max = $min ;
  2387. $flg = false;
  2388. for( $i=0; $i < $n; ++$i ) {
  2389. if( $aLines[$i]->direction == HORIZONTAL ) {
  2390. $flg = true ;
  2391. $v = $aLines[$i]->scaleposition ;
  2392. if( $min > $v ) $min = $v ;
  2393. if( $max < $v ) $max = $v ;
  2394. }
  2395. }
  2396. return $flg ? array($min,$max) : false ;
  2397. }
  2398. // Get X min and max values for added lines
  2399. function GetLinesXMinMax( $aLines ) {
  2400. $n = count($aLines);
  2401. if( $n == 0 ) return false ;
  2402. $min = $aLines[0]->scaleposition ;
  2403. $max = $min ;
  2404. $flg = false;
  2405. for( $i=0; $i < $n; ++$i ) {
  2406. if( $aLines[$i]->direction == VERTICAL ) {
  2407. $flg = true ;
  2408. $v = $aLines[$i]->scaleposition ;
  2409. if( $min > $v ) $min = $v ;
  2410. if( $max < $v ) $max = $v ;
  2411. }
  2412. }
  2413. return $flg ? array($min,$max) : false ;
  2414. }
  2415. // Get min and max values for all included plots
  2416. function GetPlotsYMinMax($aPlots) {
  2417. $n = count($aPlots);
  2418. $i=0;
  2419. do {
  2420. list($xmax,$max) = $aPlots[$i]->Max();
  2421. } while( ++$i < $n && !is_numeric($max) );
  2422. $i=0;
  2423. do {
  2424. list($xmin,$min) = $aPlots[$i]->Min();
  2425. } while( ++$i < $n && !is_numeric($min) );
  2426. if( !is_numeric($min) || !is_numeric($max) ) {
  2427. JpGraphError::RaiseL(25044);//('Cannot use autoscaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).');
  2428. }
  2429. for($i=0; $i < $n; ++$i ) {
  2430. list($xmax,$ymax)=$aPlots[$i]->Max();
  2431. list($xmin,$ymin)=$aPlots[$i]->Min();
  2432. if (is_numeric($ymax)) $max=max($max,$ymax);
  2433. if (is_numeric($ymin)) $min=min($min,$ymin);
  2434. }
  2435. if( $min == '' ) $min = 0;
  2436. if( $max == '' ) $max = 0;
  2437. if( $min == 0 && $max == 0 ) {
  2438. // Special case if all values are 0
  2439. $min=0;$max=1;
  2440. }
  2441. return array($min,$max);
  2442. }
  2443. } // Class
  2444. //===================================================
  2445. // CLASS LineProperty
  2446. // Description: Holds properties for a line
  2447. //===================================================
  2448. class LineProperty {
  2449. public $iWeight=1, $iColor="black",$iStyle="solid",$iShow=true;
  2450. //---------------
  2451. // PUBLIC METHODS
  2452. function SetColor($aColor) {
  2453. $this->iColor = $aColor;
  2454. }
  2455. function SetWeight($aWeight) {
  2456. $this->iWeight = $aWeight;
  2457. }
  2458. function SetStyle($aStyle) {
  2459. $this->iStyle = $aStyle;
  2460. }
  2461. function Show($aShow=true) {
  2462. $this->iShow=$aShow;
  2463. }
  2464. function Stroke($aImg,$aX1,$aY1,$aX2,$aY2) {
  2465. if( $this->iShow ) {
  2466. $aImg->PushColor($this->iColor);
  2467. $oldls = $aImg->line_style;
  2468. $oldlw = $aImg->line_weight;
  2469. $aImg->SetLineWeight($this->iWeight);
  2470. $aImg->SetLineStyle($this->iStyle);
  2471. $aImg->StyleLine($aX1,$aY1,$aX2,$aY2);
  2472. $aImg->PopColor($this->iColor);
  2473. $aImg->line_style = $oldls;
  2474. $aImg->line_weight = $oldlw;
  2475. }
  2476. }
  2477. }
  2478. //===================================================
  2479. // CLASS Text
  2480. // Description: Arbitrary text object that can be added to the graph
  2481. //===================================================
  2482. class Text {
  2483. public $t,$margin=0;
  2484. public $x=0,$y=0,$halign="left",$valign="top",$color=array(0,0,0);
  2485. public $hide=false, $dir=0;
  2486. public $iScalePosY=null,$iScalePosX=null;
  2487. public $iWordwrap=0;
  2488. public $font_family=FF_FONT1,$font_style=FS_NORMAL,$font_size=12;
  2489. protected $boxed=false; // Should the text be boxed
  2490. protected $paragraph_align="left";
  2491. protected $icornerradius=0,$ishadowwidth=3;
  2492. protected $fcolor='white',$bcolor='black',$shadow=false;
  2493. protected $iCSIMarea='',$iCSIMalt='',$iCSIMtarget='',$iCSIMWinTarget='';
  2494. //---------------
  2495. // CONSTRUCTOR
  2496. // Create new text at absolute pixel coordinates
  2497. function Text($aTxt="",$aXAbsPos=0,$aYAbsPos=0) {
  2498. if( ! is_string($aTxt) ) {
  2499. JpGraphError::RaiseL(25050);//('First argument to Text::Text() must be s atring.');
  2500. }
  2501. $this->t = $aTxt;
  2502. $this->x = round($aXAbsPos);
  2503. $this->y = round($aYAbsPos);
  2504. $this->margin = 0;
  2505. }
  2506. //---------------
  2507. // PUBLIC METHODS
  2508. // Set the string in the text object
  2509. function Set($aTxt) {
  2510. $this->t = $aTxt;
  2511. }
  2512. // Alias for Pos()
  2513. function SetPos($aXAbsPos=0,$aYAbsPos=0,$aHAlign="left",$aVAlign="top") {
  2514. //$this->Pos($aXAbsPos,$aYAbsPos,$aHAlign,$aVAlign);
  2515. $this->x = $aXAbsPos;
  2516. $this->y = $aYAbsPos;
  2517. $this->halign = $aHAlign;
  2518. $this->valign = $aVAlign;
  2519. }
  2520. function SetScalePos($aX,$aY) {
  2521. $this->iScalePosX = $aX;
  2522. $this->iScalePosY = $aY;
  2523. }
  2524. // Specify alignment for the text
  2525. function Align($aHAlign,$aVAlign="top",$aParagraphAlign="") {
  2526. $this->halign = $aHAlign;
  2527. $this->valign = $aVAlign;
  2528. if( $aParagraphAlign != "" )
  2529. $this->paragraph_align = $aParagraphAlign;
  2530. }
  2531. // Alias
  2532. function SetAlign($aHAlign,$aVAlign="top",$aParagraphAlign="") {
  2533. $this->Align($aHAlign,$aVAlign,$aParagraphAlign);
  2534. }
  2535. // Specifies the alignment for a multi line text
  2536. function ParagraphAlign($aAlign) {
  2537. $this->paragraph_align = $aAlign;
  2538. }
  2539. // Specifies the alignment for a multi line text
  2540. function SetParagraphAlign($aAlign) {
  2541. $this->paragraph_align = $aAlign;
  2542. }
  2543. function SetShadow($aShadowColor='gray',$aShadowWidth=3) {
  2544. $this->ishadowwidth=$aShadowWidth;
  2545. $this->shadow=$aShadowColor;
  2546. $this->boxed=true;
  2547. }
  2548. function SetWordWrap($aCol) {
  2549. $this->iWordwrap = $aCol ;
  2550. }
  2551. // Specify that the text should be boxed. fcolor=frame color, bcolor=border color,
  2552. // $shadow=drop shadow should be added around the text.
  2553. function SetBox($aFrameColor=array(255,255,255),$aBorderColor=array(0,0,0),$aShadowColor=false,$aCornerRadius=4,$aShadowWidth=3) {
  2554. if( $aFrameColor==false )
  2555. $this->boxed=false;
  2556. else
  2557. $this->boxed=true;
  2558. $this->fcolor=$aFrameColor;
  2559. $this->bcolor=$aBorderColor;
  2560. // For backwards compatibility when shadow was just true or false
  2561. if( $aShadowColor === true )
  2562. $aShadowColor = 'gray';
  2563. $this->shadow=$aShadowColor;
  2564. $this->icornerradius=$aCornerRadius;
  2565. $this->ishadowwidth=$aShadowWidth;
  2566. }
  2567. // Hide the text
  2568. function Hide($aHide=true) {
  2569. $this->hide=$aHide;
  2570. }
  2571. // This looks ugly since it's not a very orthogonal design
  2572. // but I added this "inverse" of Hide() to harmonize
  2573. // with some classes which I designed more recently (especially)
  2574. // jpgraph_gantt
  2575. function Show($aShow=true) {
  2576. $this->hide=!$aShow;
  2577. }
  2578. // Specify font
  2579. function SetFont($aFamily,$aStyle=FS_NORMAL,$aSize=10) {
  2580. $this->font_family=$aFamily;
  2581. $this->font_style=$aStyle;
  2582. $this->font_size=$aSize;
  2583. }
  2584. // Center the text between $left and $right coordinates
  2585. function Center($aLeft,$aRight,$aYAbsPos=false) {
  2586. $this->x = $aLeft + ($aRight-$aLeft )/2;
  2587. $this->halign = "center";
  2588. if( is_numeric($aYAbsPos) )
  2589. $this->y = $aYAbsPos;
  2590. }
  2591. // Set text color
  2592. function SetColor($aColor) {
  2593. $this->color = $aColor;
  2594. }
  2595. function SetAngle($aAngle) {
  2596. $this->SetOrientation($aAngle);
  2597. }
  2598. // Orientation of text. Note only TTF fonts can have an arbitrary angle
  2599. function SetOrientation($aDirection=0) {
  2600. if( is_numeric($aDirection) )
  2601. $this->dir=$aDirection;
  2602. elseif( $aDirection=="h" )
  2603. $this->dir = 0;
  2604. elseif( $aDirection=="v" )
  2605. $this->dir = 90;
  2606. else JpGraphError::RaiseL(25051);//(" Invalid direction specified for text.");
  2607. }
  2608. // Total width of text
  2609. function GetWidth($aImg) {
  2610. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  2611. $w = $aImg->GetTextWidth($this->t,$this->dir);
  2612. return $w;
  2613. }
  2614. // Hight of font
  2615. function GetFontHeight($aImg) {
  2616. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  2617. $h = $aImg->GetFontHeight();
  2618. return $h;
  2619. }
  2620. function GetTextHeight($aImg) {
  2621. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  2622. $h = $aImg->GetTextHeight($this->t,$this->dir);
  2623. return $h;
  2624. }
  2625. function GetHeight($aImg) {
  2626. // Synonym for GetTextHeight()
  2627. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  2628. $h = $aImg->GetTextHeight($this->t,$this->dir);
  2629. return $h;
  2630. }
  2631. // Set the margin which will be interpretated differently depending
  2632. // on the context.
  2633. function SetMargin($aMarg) {
  2634. $this->margin = $aMarg;
  2635. }
  2636. function StrokeWithScale($aImg,$axscale,$ayscale) {
  2637. if( $this->iScalePosX === null ||
  2638. $this->iScalePosY === null ) {
  2639. $this->Stroke($aImg);
  2640. }
  2641. else {
  2642. $this->Stroke($aImg,
  2643. round($axscale->Translate($this->iScalePosX)),
  2644. round($ayscale->Translate($this->iScalePosY)));
  2645. }
  2646. }
  2647. function SetCSIMTarget($aURITarget,$aAlt='',$aWinTarget='') {
  2648. $this->iCSIMtarget = $aURITarget;
  2649. $this->iCSIMalt = $aAlt;
  2650. $this->iCSIMWinTarget = $aWinTarget;
  2651. }
  2652. function GetCSIMareas() {
  2653. if( $this->iCSIMtarget !== '' )
  2654. return $this->iCSIMarea;
  2655. else
  2656. return '';
  2657. }
  2658. // Display text in image
  2659. function Stroke($aImg,$x=null,$y=null) {
  2660. if( !empty($x) ) $this->x = round($x);
  2661. if( !empty($y) ) $this->y = round($y);
  2662. // Insert newlines
  2663. if( $this->iWordwrap > 0 ) {
  2664. $this->t = wordwrap($this->t,$this->iWordwrap,"\n");
  2665. }
  2666. // If position been given as a fraction of the image size
  2667. // calculate the absolute position
  2668. if( $this->x < 1 && $this->x > 0 ) $this->x *= $aImg->width;
  2669. if( $this->y < 1 && $this->y > 0 ) $this->y *= $aImg->height;
  2670. $aImg->PushColor($this->color);
  2671. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  2672. $aImg->SetTextAlign($this->halign,$this->valign);
  2673. if( $this->boxed ) {
  2674. if( $this->fcolor=="nofill" )
  2675. $this->fcolor=false;
  2676. $aImg->SetLineWeight(1);
  2677. $bbox = $aImg->StrokeBoxedText($this->x,$this->y,$this->t,
  2678. $this->dir,$this->fcolor,$this->bcolor,$this->shadow,
  2679. $this->paragraph_align,5,5,$this->icornerradius,
  2680. $this->ishadowwidth);
  2681. }
  2682. else {
  2683. $bbox = $aImg->StrokeText($this->x,$this->y,$this->t,$this->dir,$this->paragraph_align);
  2684. }
  2685. // Create CSIM targets
  2686. $coords = $bbox[0].','.$bbox[1].','.$bbox[2].','.$bbox[3].','.$bbox[4].','.$bbox[5].','.$bbox[6].','.$bbox[7];
  2687. $this->iCSIMarea = "<area shape=\"poly\" coords=\"$coords\" href=\"".htmlentities($this->iCSIMtarget)."\" ";
  2688. if( trim($this->iCSIMalt) != '' ) {
  2689. $this->iCSIMarea .= " alt=\"".$this->iCSIMalt."\" ";
  2690. $this->iCSIMarea .= " title=\"".$this->iCSIMalt."\" ";
  2691. }
  2692. if( trim($this->iCSIMWinTarget) != '' ) {
  2693. $this->iCSIMarea .= " target=\"".$this->iCSIMWinTarget."\" ";
  2694. }
  2695. $this->iCSIMarea .= " />\n";
  2696. $aImg->PopColor($this->color);
  2697. }
  2698. } // Class
  2699. class GraphTabTitle extends Text{
  2700. private $corner = 6 , $posx = 7, $posy = 4;
  2701. private $fillcolor='lightyellow',$bordercolor='black';
  2702. private $align = 'left', $width=TABTITLE_WIDTHFIT;
  2703. function GraphTabTitle() {
  2704. $this->t = '';
  2705. $this->font_style = FS_BOLD;
  2706. $this->hide = true;
  2707. $this->color = 'darkred';
  2708. }
  2709. function SetColor($aTxtColor,$aFillColor='lightyellow',$aBorderColor='black') {
  2710. $this->color = $aTxtColor;
  2711. $this->fillcolor = $aFillColor;
  2712. $this->bordercolor = $aBorderColor;
  2713. }
  2714. function SetFillColor($aFillColor) {
  2715. $this->fillcolor = $aFillColor;
  2716. }
  2717. function SetTabAlign($aAlign) {
  2718. $this->align = $aAlign;
  2719. }
  2720. function SetWidth($aWidth) {
  2721. $this->width = $aWidth ;
  2722. }
  2723. function Set($t) {
  2724. $this->t = $t;
  2725. $this->hide = false;
  2726. }
  2727. function SetCorner($aD) {
  2728. $this->corner = $aD ;
  2729. }
  2730. function Stroke($aImg,$aDummy1=null,$aDummy2=null) {
  2731. if( $this->hide )
  2732. return;
  2733. $this->boxed = false;
  2734. $w = $this->GetWidth($aImg) + 2*$this->posx;
  2735. $h = $this->GetTextHeight($aImg) + 2*$this->posy;
  2736. $x = $aImg->left_margin;
  2737. $y = $aImg->top_margin;
  2738. if( $this->width === TABTITLE_WIDTHFIT ) {
  2739. if( $this->align == 'left' ) {
  2740. $p = array($x, $y,
  2741. $x, $y-$h+$this->corner,
  2742. $x + $this->corner,$y-$h,
  2743. $x + $w - $this->corner, $y-$h,
  2744. $x + $w, $y-$h+$this->corner,
  2745. $x + $w, $y);
  2746. }
  2747. elseif( $this->align == 'center' ) {
  2748. $x += round($aImg->plotwidth/2) - round($w/2);
  2749. $p = array($x, $y,
  2750. $x, $y-$h+$this->corner,
  2751. $x + $this->corner, $y-$h,
  2752. $x + $w - $this->corner, $y-$h,
  2753. $x + $w, $y-$h+$this->corner,
  2754. $x + $w, $y);
  2755. }
  2756. else {
  2757. $x += $aImg->plotwidth -$w;
  2758. $p = array($x, $y,
  2759. $x, $y-$h+$this->corner,
  2760. $x + $this->corner,$y-$h,
  2761. $x + $w - $this->corner, $y-$h,
  2762. $x + $w, $y-$h+$this->corner,
  2763. $x + $w, $y);
  2764. }
  2765. }
  2766. else {
  2767. if( $this->width === TABTITLE_WIDTHFULL )
  2768. $w = $aImg->plotwidth ;
  2769. else
  2770. $w = $this->width ;
  2771. // Make the tab fit the width of the plot area
  2772. $p = array($x, $y,
  2773. $x, $y-$h+$this->corner,
  2774. $x + $this->corner,$y-$h,
  2775. $x + $w - $this->corner, $y-$h,
  2776. $x + $w, $y-$h+$this->corner,
  2777. $x + $w, $y);
  2778. }
  2779. if( $this->halign == 'left' ) {
  2780. $aImg->SetTextAlign('left','bottom');
  2781. $x += $this->posx;
  2782. $y -= $this->posy;
  2783. }
  2784. elseif( $this->halign == 'center' ) {
  2785. $aImg->SetTextAlign('center','bottom');
  2786. $x += $w/2;
  2787. $y -= $this->posy;
  2788. }
  2789. else {
  2790. $aImg->SetTextAlign('right','bottom');
  2791. $x += $w - $this->posx;
  2792. $y -= $this->posy;
  2793. }
  2794. $aImg->SetColor($this->fillcolor);
  2795. $aImg->FilledPolygon($p);
  2796. $aImg->SetColor($this->bordercolor);
  2797. $aImg->Polygon($p,true);
  2798. $aImg->SetColor($this->color);
  2799. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  2800. $aImg->StrokeText($x,$y,$this->t,0,'center');
  2801. }
  2802. }
  2803. //===================================================
  2804. // CLASS SuperScriptText
  2805. // Description: Format a superscript text
  2806. //===================================================
  2807. class SuperScriptText extends Text {
  2808. private $iSuper="";
  2809. private $sfont_family="",$sfont_style="",$sfont_size=8;
  2810. private $iSuperMargin=2,$iVertOverlap=4,$iSuperScale=0.65;
  2811. private $iSDir=0;
  2812. private $iSimple=false;
  2813. function SuperScriptText($aTxt="",$aSuper="",$aXAbsPos=0,$aYAbsPos=0) {
  2814. parent::Text($aTxt,$aXAbsPos,$aYAbsPos);
  2815. $this->iSuper = $aSuper;
  2816. }
  2817. function FromReal($aVal,$aPrecision=2) {
  2818. // Convert a floating point number to scientific notation
  2819. $neg=1.0;
  2820. if( $aVal < 0 ) {
  2821. $neg = -1.0;
  2822. $aVal = -$aVal;
  2823. }
  2824. $l = floor(log10($aVal));
  2825. $a = sprintf("%0.".$aPrecision."f",round($aVal / pow(10,$l),$aPrecision));
  2826. $a *= $neg;
  2827. if( $this->iSimple && ($a == 1 || $a==-1) ) $a = '';
  2828. if( $a != '' )
  2829. $this->t = $a.' * 10';
  2830. else {
  2831. if( $neg == 1 )
  2832. $this->t = '10';
  2833. else
  2834. $this->t = '-10';
  2835. }
  2836. $this->iSuper = $l;
  2837. }
  2838. function Set($aTxt,$aSuper="") {
  2839. $this->t = $aTxt;
  2840. $this->iSuper = $aSuper;
  2841. }
  2842. function SetSuperFont($aFontFam,$aFontStyle=FS_NORMAL,$aFontSize=8) {
  2843. $this->sfont_family = $aFontFam;
  2844. $this->sfont_style = $aFontStyle;
  2845. $this->sfont_size = $aFontSize;
  2846. }
  2847. // Total width of text
  2848. function GetWidth($aImg) {
  2849. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  2850. $w = $aImg->GetTextWidth($this->t);
  2851. $aImg->SetFont($this->sfont_family,$this->sfont_style,$this->sfont_size);
  2852. $w += $aImg->GetTextWidth($this->iSuper);
  2853. $w += $this->iSuperMargin;
  2854. return $w;
  2855. }
  2856. // Hight of font (approximate the height of the text)
  2857. function GetFontHeight($aImg) {
  2858. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  2859. $h = $aImg->GetFontHeight();
  2860. $aImg->SetFont($this->sfont_family,$this->sfont_style,$this->sfont_size);
  2861. $h += $aImg->GetFontHeight();
  2862. return $h;
  2863. }
  2864. // Hight of text
  2865. function GetTextHeight($aImg) {
  2866. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  2867. $h = $aImg->GetTextHeight($this->t);
  2868. $aImg->SetFont($this->sfont_family,$this->sfont_style,$this->sfont_size);
  2869. $h += $aImg->GetTextHeight($this->iSuper);
  2870. return $h;
  2871. }
  2872. function Stroke($aImg,$ax=-1,$ay=-1) {
  2873. // To position the super script correctly we need different
  2874. // cases to handle the alignmewnt specified since that will
  2875. // determine how we can interpret the x,y coordinates
  2876. $w = parent::GetWidth($aImg);
  2877. $h = parent::GetTextHeight($aImg);
  2878. switch( $this->valign ) {
  2879. case 'top':
  2880. $sy = $this->y;
  2881. break;
  2882. case 'center':
  2883. $sy = $this->y - $h/2;
  2884. break;
  2885. case 'bottom':
  2886. $sy = $this->y - $h;
  2887. break;
  2888. default:
  2889. JpGraphError::RaiseL(25052);//('PANIC: Internal error in SuperScript::Stroke(). Unknown vertical alignment for text');
  2890. break;
  2891. }
  2892. switch( $this->halign ) {
  2893. case 'left':
  2894. $sx = $this->x + $w;
  2895. break;
  2896. case 'center':
  2897. $sx = $this->x + $w/2;
  2898. break;
  2899. case 'right':
  2900. $sx = $this->x;
  2901. break;
  2902. default:
  2903. JpGraphError::RaiseL(25053);//('PANIC: Internal error in SuperScript::Stroke(). Unknown horizontal alignment for text');
  2904. break;
  2905. }
  2906. $sx += $this->iSuperMargin;
  2907. $sy += $this->iVertOverlap;
  2908. // Should we automatically determine the font or
  2909. // has the user specified it explicetly?
  2910. if( $this->sfont_family == "" ) {
  2911. if( $this->font_family <= FF_FONT2 ) {
  2912. if( $this->font_family == FF_FONT0 ) {
  2913. $sff = FF_FONT0;
  2914. }
  2915. elseif( $this->font_family == FF_FONT1 ) {
  2916. if( $this->font_style == FS_NORMAL )
  2917. $sff = FF_FONT0;
  2918. else
  2919. $sff = FF_FONT1;
  2920. }
  2921. else {
  2922. $sff = FF_FONT1;
  2923. }
  2924. $sfs = $this->font_style;
  2925. $sfz = $this->font_size;
  2926. }
  2927. else {
  2928. // TTF fonts
  2929. $sff = $this->font_family;
  2930. $sfs = $this->font_style;
  2931. $sfz = floor($this->font_size*$this->iSuperScale);
  2932. if( $sfz < 8 ) $sfz = 8;
  2933. }
  2934. $this->sfont_family = $sff;
  2935. $this->sfont_style = $sfs;
  2936. $this->sfont_size = $sfz;
  2937. }
  2938. else {
  2939. $sff = $this->sfont_family;
  2940. $sfs = $this->sfont_style;
  2941. $sfz = $this->sfont_size;
  2942. }
  2943. parent::Stroke($aImg,$ax,$ay);
  2944. // For the builtin fonts we need to reduce the margins
  2945. // since the bounding bx reported for the builtin fonts
  2946. // are much larger than for the TTF fonts.
  2947. if( $sff <= FF_FONT2 ) {
  2948. $sx -= 2;
  2949. $sy += 3;
  2950. }
  2951. $aImg->SetTextAlign('left','bottom');
  2952. $aImg->SetFont($sff,$sfs,$sfz);
  2953. $aImg->PushColor($this->color);
  2954. $aImg->StrokeText($sx,$sy,$this->iSuper,$this->iSDir,'left');
  2955. $aImg->PopColor();
  2956. }
  2957. }
  2958. //===================================================
  2959. // CLASS Grid
  2960. // Description: responsible for drawing grid lines in graph
  2961. //===================================================
  2962. class Grid {
  2963. protected $img;
  2964. protected $scale;
  2965. protected $grid_color='#DDDDDD',$grid_mincolor='#DDDDDD';
  2966. protected $type="solid";
  2967. protected $show=false, $showMinor=false,$weight=1;
  2968. protected $fill=false,$fillcolor=array('#EFEFEF','#BBCCFF');
  2969. //---------------
  2970. // CONSTRUCTOR
  2971. function Grid($aAxis) {
  2972. $this->scale = $aAxis->scale;
  2973. $this->img = $aAxis->img;
  2974. }
  2975. //---------------
  2976. // PUBLIC METHODS
  2977. function SetColor($aMajColor,$aMinColor=false) {
  2978. $this->grid_color=$aMajColor;
  2979. if( $aMinColor === false )
  2980. $aMinColor = $aMajColor ;
  2981. $this->grid_mincolor = $aMinColor;
  2982. }
  2983. function SetWeight($aWeight) {
  2984. $this->weight=$aWeight;
  2985. }
  2986. // Specify if grid should be dashed, dotted or solid
  2987. function SetLineStyle($aType) {
  2988. $this->type = $aType;
  2989. }
  2990. // Decide if both major and minor grid should be displayed
  2991. function Show($aShowMajor=true,$aShowMinor=false) {
  2992. $this->show=$aShowMajor;
  2993. $this->showMinor=$aShowMinor;
  2994. }
  2995. function SetFill($aFlg=true,$aColor1='lightgray',$aColor2='lightblue') {
  2996. $this->fill = $aFlg;
  2997. $this->fillcolor = array( $aColor1, $aColor2 );
  2998. }
  2999. // Display the grid
  3000. function Stroke() {
  3001. if( $this->showMinor && !$this->scale->textscale ) {
  3002. $tmp = $this->grid_color;
  3003. $this->grid_color = $this->grid_mincolor;
  3004. $this->DoStroke($this->scale->ticks->ticks_pos);
  3005. $this->grid_color = $tmp;
  3006. $this->DoStroke($this->scale->ticks->maj_ticks_pos);
  3007. }
  3008. else {
  3009. $this->DoStroke($this->scale->ticks->maj_ticks_pos);
  3010. }
  3011. }
  3012. //--------------
  3013. // Private methods
  3014. // Draw the grid
  3015. function DoStroke($aTicksPos) {
  3016. if( !$this->show )
  3017. return;
  3018. $nbrgrids = count($aTicksPos);
  3019. if( $this->scale->type=="y" ) {
  3020. $xl=$this->img->left_margin;
  3021. $xr=$this->img->width-$this->img->right_margin;
  3022. if( $this->fill ) {
  3023. // Draw filled areas
  3024. $y2 = $aTicksPos[0];
  3025. $i=1;
  3026. while( $i < $nbrgrids ) {
  3027. $y1 = $y2;
  3028. $y2 = $aTicksPos[$i++];
  3029. $this->img->SetColor($this->fillcolor[$i & 1]);
  3030. $this->img->FilledRectangle($xl,$y1,$xr,$y2);
  3031. }
  3032. }
  3033. $this->img->SetColor($this->grid_color);
  3034. $this->img->SetLineWeight($this->weight);
  3035. // Draw grid lines
  3036. switch( $this->type ) {
  3037. case "solid": $style = LINESTYLE_SOLID; break;
  3038. case "dotted": $style = LINESTYLE_DOTTED; break;
  3039. case "dashed": $style = LINESTYLE_DASHED; break;
  3040. case "longdashed": $style = LINESTYLE_LONGDASH; break;
  3041. default:
  3042. $style = LINESTYLE_SOLID; break;
  3043. }
  3044. for($i=0; $i < $nbrgrids; ++$i) {
  3045. $y=$aTicksPos[$i];
  3046. $this->img->StyleLine($xl,$y,$xr,$y,$style);
  3047. }
  3048. }
  3049. elseif( $this->scale->type=="x" ) {
  3050. $yu=$this->img->top_margin;
  3051. $yl=$this->img->height-$this->img->bottom_margin;
  3052. $limit=$this->img->width-$this->img->right_margin;
  3053. if( $this->fill ) {
  3054. // Draw filled areas
  3055. $x2 = $aTicksPos[0];
  3056. $i=1;
  3057. while( $i < $nbrgrids ) {
  3058. $x1 = $x2;
  3059. $x2 = min($aTicksPos[$i++],$limit) ;
  3060. $this->img->SetColor($this->fillcolor[$i & 1]);
  3061. $this->img->FilledRectangle($x1,$yu,$x2,$yl);
  3062. }
  3063. }
  3064. $this->img->SetColor($this->grid_color);
  3065. $this->img->SetLineWeight($this->weight);
  3066. // We must also test for limit since we might have
  3067. // an offset and the number of ticks is calculated with
  3068. // assumption offset==0 so we might end up drawing one
  3069. // to many gridlines
  3070. $i=0;
  3071. $x=$aTicksPos[$i];
  3072. while( $i<count($aTicksPos) && ($x=$aTicksPos[$i]) <= $limit ) {
  3073. if( $this->type == "solid" )
  3074. $this->img->Line($x,$yl,$x,$yu);
  3075. elseif( $this->type == "dotted" )
  3076. $this->img->DashedLine($x,$yl,$x,$yu,1,6);
  3077. elseif( $this->type == "dashed" )
  3078. $this->img->DashedLine($x,$yl,$x,$yu,2,4);
  3079. elseif( $this->type == "longdashed" )
  3080. $this->img->DashedLine($x,$yl,$x,$yu,8,6);
  3081. ++$i;
  3082. }
  3083. }
  3084. else {
  3085. JpGraphError::RaiseL(25054,$this->scale->type);//('Internal error: Unknown grid axis ['.$this->scale->type.']');
  3086. }
  3087. return true;
  3088. }
  3089. } // Class
  3090. //===================================================
  3091. // CLASS Axis
  3092. // Description: Defines X and Y axis. Notes that at the
  3093. // moment the code is not really good since the axis on
  3094. // several occasion must know wheter it's an X or Y axis.
  3095. // This was a design decision to make the code easier to
  3096. // follow.
  3097. //===================================================
  3098. class AxisPrototype {
  3099. public $scale=null;
  3100. public $img=null;
  3101. public $hide=false,$hide_labels=false;
  3102. public $title=null;
  3103. public $font_family=FF_FONT1,$font_style=FS_NORMAL,$font_size=12,$label_angle=0;
  3104. public $tick_step=1;
  3105. public $pos = false;
  3106. public $ticks_label = array();
  3107. protected $weight=1;
  3108. protected $color=array(0,0,0),$label_color=array(0,0,0);
  3109. protected $ticks_label_colors=null;
  3110. protected $show_first_label=true,$show_last_label=true;
  3111. protected $label_step=1; // Used by a text axis to specify what multiple of major steps
  3112. // should be labeled.
  3113. protected $labelPos=0; // Which side of the axis should the labels be?
  3114. protected $title_adjust,$title_margin,$title_side=SIDE_LEFT;
  3115. protected $tick_label_margin=7;
  3116. protected $label_halign = '',$label_valign = '', $label_para_align='left';
  3117. protected $hide_line=false;
  3118. protected $iDeltaAbsPos=0;
  3119. //---------------
  3120. // CONSTRUCTOR
  3121. function Axis($img,$aScale,$color=array(0,0,0)) {
  3122. $this->img = $img;
  3123. $this->scale = $aScale;
  3124. $this->color = $color;
  3125. $this->title=new Text("");
  3126. if( $aScale->type=="y" ) {
  3127. $this->title_margin = 25;
  3128. $this->title_adjust="middle";
  3129. $this->title->SetOrientation(90);
  3130. $this->tick_label_margin=7;
  3131. $this->labelPos=SIDE_LEFT;
  3132. }
  3133. else {
  3134. $this->title_margin = 5;
  3135. $this->title_adjust="high";
  3136. $this->title->SetOrientation(0);
  3137. $this->tick_label_margin=7;
  3138. $this->labelPos=SIDE_DOWN;
  3139. $this->title_side=SIDE_DOWN;
  3140. }
  3141. }
  3142. //---------------
  3143. // PUBLIC METHODS
  3144. function SetLabelFormat($aFormStr) {
  3145. $this->scale->ticks->SetLabelFormat($aFormStr);
  3146. }
  3147. function SetLabelFormatString($aFormStr,$aDate=false) {
  3148. $this->scale->ticks->SetLabelFormat($aFormStr,$aDate);
  3149. }
  3150. function SetLabelFormatCallback($aFuncName) {
  3151. $this->scale->ticks->SetFormatCallback($aFuncName);
  3152. }
  3153. function SetLabelAlign($aHAlign,$aVAlign="top",$aParagraphAlign='left') {
  3154. $this->label_halign = $aHAlign;
  3155. $this->label_valign = $aVAlign;
  3156. $this->label_para_align = $aParagraphAlign;
  3157. }
  3158. // Don't display the first label
  3159. function HideFirstTickLabel($aShow=false) {
  3160. $this->show_first_label=$aShow;
  3161. }
  3162. function HideLastTickLabel($aShow=false) {
  3163. $this->show_last_label=$aShow;
  3164. }
  3165. // Manually specify the major and (optional) minor tick position and labels
  3166. function SetTickPositions($aMajPos,$aMinPos=NULL,$aLabels=NULL) {
  3167. $this->scale->ticks->SetTickPositions($aMajPos,$aMinPos,$aLabels);
  3168. }
  3169. // Manually specify major tick positions and optional labels
  3170. function SetMajTickPositions($aMajPos,$aLabels=NULL) {
  3171. $this->scale->ticks->SetTickPositions($aMajPos,NULL,$aLabels);
  3172. }
  3173. // Hide minor or major tick marks
  3174. function HideTicks($aHideMinor=true,$aHideMajor=true) {
  3175. $this->scale->ticks->SupressMinorTickMarks($aHideMinor);
  3176. $this->scale->ticks->SupressTickMarks($aHideMajor);
  3177. }
  3178. // Hide zero label
  3179. function HideZeroLabel($aFlag=true) {
  3180. $this->scale->ticks->SupressZeroLabel();
  3181. }
  3182. function HideFirstLastLabel() {
  3183. // The two first calls to ticks method will supress
  3184. // automatically generated scale values. However, that
  3185. // will not affect manually specified value, e.g text-scales.
  3186. // therefor we also make a kludge here to supress manually
  3187. // specified scale labels.
  3188. $this->scale->ticks->SupressLast();
  3189. $this->scale->ticks->SupressFirst();
  3190. $this->show_first_label = false;
  3191. $this->show_last_label = false;
  3192. }
  3193. // Hide the axis
  3194. function Hide($aHide=true) {
  3195. $this->hide=$aHide;
  3196. }
  3197. // Hide the actual axis-line, but still print the labels
  3198. function HideLine($aHide=true) {
  3199. $this->hide_line = $aHide;
  3200. }
  3201. function HideLabels($aHide=true) {
  3202. $this->hide_labels = $aHide;
  3203. }
  3204. // Weight of axis
  3205. function SetWeight($aWeight) {
  3206. $this->weight = $aWeight;
  3207. }
  3208. // Axis color
  3209. function SetColor($aColor,$aLabelColor=false) {
  3210. $this->color = $aColor;
  3211. if( !$aLabelColor ) $this->label_color = $aColor;
  3212. else $this->label_color = $aLabelColor;
  3213. }
  3214. // Title on axis
  3215. function SetTitle($aTitle,$aAdjustAlign="high") {
  3216. $this->title->Set($aTitle);
  3217. $this->title_adjust=$aAdjustAlign;
  3218. }
  3219. // Specify distance from the axis
  3220. function SetTitleMargin($aMargin) {
  3221. $this->title_margin=$aMargin;
  3222. }
  3223. // Which side of the axis should the axis title be?
  3224. function SetTitleSide($aSideOfAxis) {
  3225. $this->title_side = $aSideOfAxis;
  3226. }
  3227. // Utility function to set the direction for tick marks
  3228. function SetTickDirection($aDir) {
  3229. // Will be deprecated from 1.7
  3230. if( ERR_DEPRECATED )
  3231. JpGraphError::RaiseL(25055);//('Axis::SetTickDirection() is deprecated. Use Axis::SetTickSide() instead');
  3232. $this->scale->ticks->SetSide($aDir);
  3233. }
  3234. function SetTickSide($aDir) {
  3235. $this->scale->ticks->SetSide($aDir);
  3236. }
  3237. // Specify text labels for the ticks. One label for each data point
  3238. function SetTickLabels($aLabelArray,$aLabelColorArray=null) {
  3239. $this->ticks_label = $aLabelArray;
  3240. $this->ticks_label_colors = $aLabelColorArray;
  3241. }
  3242. // How far from the axis should the labels be drawn
  3243. function SetTickLabelMargin($aMargin) {
  3244. if( ERR_DEPRECATED )
  3245. JpGraphError::RaiseL(25056);//('SetTickLabelMargin() is deprecated. Use Axis::SetLabelMargin() instead.');
  3246. $this->tick_label_margin=$aMargin;
  3247. }
  3248. function SetLabelMargin($aMargin) {
  3249. $this->tick_label_margin=$aMargin;
  3250. }
  3251. // Specify that every $step of the ticks should be displayed starting
  3252. // at $start
  3253. // DEPRECATED FUNCTION: USE SetTextTickInterval() INSTEAD
  3254. function SetTextTicks($step,$start=0) {
  3255. JpGraphError::RaiseL(25057);//(" SetTextTicks() is deprecated. Use SetTextTickInterval() instead.");
  3256. }
  3257. // Specify that every $step of the ticks should be displayed starting
  3258. // at $start
  3259. function SetTextTickInterval($aStep,$aStart=0) {
  3260. $this->scale->ticks->SetTextLabelStart($aStart);
  3261. $this->tick_step=$aStep;
  3262. }
  3263. // Specify that every $step tick mark should have a label
  3264. // should be displayed starting
  3265. function SetTextLabelInterval($aStep) {
  3266. if( $aStep < 1 )
  3267. JpGraphError::RaiseL(25058);//(" Text label interval must be specified >= 1.");
  3268. $this->label_step=$aStep;
  3269. }
  3270. // Which side of the axis should the labels be on?
  3271. function SetLabelPos($aSidePos) {
  3272. // This will be deprecated from 1.7
  3273. if( ERR_DEPRECATED )
  3274. JpGraphError::RaiseL(25059);//('SetLabelPos() is deprecated. Use Axis::SetLabelSide() instead.');
  3275. $this->labelPos=$aSidePos;
  3276. }
  3277. function SetLabelSide($aSidePos) {
  3278. $this->labelPos=$aSidePos;
  3279. }
  3280. // Set the font
  3281. function SetFont($aFamily,$aStyle=FS_NORMAL,$aSize=10) {
  3282. $this->font_family = $aFamily;
  3283. $this->font_style = $aStyle;
  3284. $this->font_size = $aSize;
  3285. }
  3286. // Position for axis line on the "other" scale
  3287. function SetPos($aPosOnOtherScale) {
  3288. $this->pos=$aPosOnOtherScale;
  3289. }
  3290. // Set the position of the axis to be X-pixels delta to the right
  3291. // of the max X-position (used to position the multiple Y-axis)
  3292. function SetPosAbsDelta($aDelta) {
  3293. $this->iDeltaAbsPos=$aDelta;
  3294. }
  3295. // Specify the angle for the tick labels
  3296. function SetLabelAngle($aAngle) {
  3297. $this->label_angle = $aAngle;
  3298. }
  3299. } // Class
  3300. //===================================================
  3301. // CLASS Axis
  3302. // Description: Defines X and Y axis. Notes that at the
  3303. // moment the code is not really good since the axis on
  3304. // several occasion must know wheter it's an X or Y axis.
  3305. // This was a design decision to make the code easier to
  3306. // follow.
  3307. //===================================================
  3308. class Axis extends AxisPrototype {
  3309. function Axis($img,$aScale,$color=array(0,0,0)) {
  3310. parent::Axis($img,$aScale,$color);
  3311. }
  3312. // Stroke the axis.
  3313. function Stroke($aOtherAxisScale,$aStrokeLabels=true) {
  3314. if( $this->hide ) return;
  3315. if( is_numeric($this->pos) ) {
  3316. $pos=$aOtherAxisScale->Translate($this->pos);
  3317. }
  3318. else { // Default to minimum of other scale if pos not set
  3319. if( ($aOtherAxisScale->GetMinVal() >= 0 && $this->pos==false) || $this->pos=="min" ) {
  3320. $pos = $aOtherAxisScale->scale_abs[0];
  3321. }
  3322. elseif($this->pos == "max") {
  3323. $pos = $aOtherAxisScale->scale_abs[1];
  3324. }
  3325. else { // If negative set x-axis at 0
  3326. $this->pos=0;
  3327. $pos=$aOtherAxisScale->Translate(0);
  3328. }
  3329. }
  3330. $pos += $this->iDeltaAbsPos;
  3331. $this->img->SetLineWeight($this->weight);
  3332. $this->img->SetColor($this->color);
  3333. $this->img->SetFont($this->font_family,$this->font_style,$this->font_size);
  3334. if( $this->scale->type == "x" ) {
  3335. if( !$this->hide_line )
  3336. $this->img->FilledRectangle($this->img->left_margin,$pos,
  3337. $this->img->width-$this->img->right_margin,$pos+$this->weight-1);
  3338. if( $this->title_side == SIDE_DOWN ) {
  3339. $y = $pos + $this->img->GetFontHeight() + $this->title_margin + $this->title->margin;
  3340. $yalign = 'top';
  3341. }
  3342. else {
  3343. $y = $pos - $this->img->GetFontHeight() - $this->title_margin - $this->title->margin;
  3344. $yalign = 'bottom';
  3345. }
  3346. if( $this->title_adjust=='high' )
  3347. $this->title->SetPos($this->img->width-$this->img->right_margin,$y,'right',$yalign);
  3348. elseif( $this->title_adjust=='middle' || $this->title_adjust=='center' )
  3349. $this->title->SetPos(($this->img->width-$this->img->left_margin-$this->img->right_margin)/2+$this->img->left_margin,$y,'center',$yalign);
  3350. elseif($this->title_adjust=='low')
  3351. $this->title->SetPos($this->img->left_margin,$y,'left',$yalign);
  3352. else {
  3353. JpGraphError::RaiseL(25060,$this->title_adjust);//('Unknown alignment specified for X-axis title. ('.$this->title_adjust.')');
  3354. }
  3355. }
  3356. elseif( $this->scale->type == "y" ) {
  3357. // Add line weight to the height of the axis since
  3358. // the x-axis could have a width>1 and we want the axis to fit nicely together.
  3359. if( !$this->hide_line )
  3360. $this->img->FilledRectangle($pos-$this->weight+1,$this->img->top_margin,
  3361. $pos,$this->img->height-$this->img->bottom_margin+$this->weight-1);
  3362. $x=$pos ;
  3363. if( $this->title_side == SIDE_LEFT ) {
  3364. $x -= $this->title_margin;
  3365. $x -= $this->title->margin;
  3366. $halign="right";
  3367. }
  3368. else {
  3369. $x += $this->title_margin;
  3370. $x += $this->title->margin;
  3371. $halign="left";
  3372. }
  3373. // If the user has manually specified an hor. align
  3374. // then we override the automatic settings with this
  3375. // specifed setting. Since default is 'left' we compare
  3376. // with that. (This means a manually set 'left' align
  3377. // will have no effect.)
  3378. if( $this->title->halign != 'left' )
  3379. $halign = $this->title->halign;
  3380. if( $this->title_adjust=="high" )
  3381. $this->title->SetPos($x,$this->img->top_margin,$halign,"top");
  3382. elseif($this->title_adjust=="middle" || $this->title_adjust=="center")
  3383. $this->title->SetPos($x,($this->img->height-$this->img->top_margin-$this->img->bottom_margin)/2+$this->img->top_margin,$halign,"center");
  3384. elseif($this->title_adjust=="low")
  3385. $this->title->SetPos($x,$this->img->height-$this->img->bottom_margin,$halign,"bottom");
  3386. else
  3387. JpGraphError::RaiseL(25061,$this->title_adjust);//('Unknown alignment specified for Y-axis title. ('.$this->title_adjust.')');
  3388. }
  3389. $this->scale->ticks->Stroke($this->img,$this->scale,$pos);
  3390. if( $aStrokeLabels ) {
  3391. if( !$this->hide_labels )
  3392. $this->StrokeLabels($pos);
  3393. $this->title->Stroke($this->img);
  3394. }
  3395. }
  3396. //---------------
  3397. // PRIVATE METHODS
  3398. // Draw all the tick labels on major tick marks
  3399. function StrokeLabels($aPos,$aMinor=false,$aAbsLabel=false) {
  3400. $this->img->SetColor($this->label_color);
  3401. $this->img->SetFont($this->font_family,$this->font_style,$this->font_size);
  3402. $yoff=$this->img->GetFontHeight()/2;
  3403. // Only draw labels at major tick marks
  3404. $nbr = count($this->scale->ticks->maj_ticks_label);
  3405. // We have the option to not-display the very first mark
  3406. // (Usefull when the first label might interfere with another
  3407. // axis.)
  3408. $i = $this->show_first_label ? 0 : 1 ;
  3409. if( !$this->show_last_label ) --$nbr;
  3410. // Now run through all labels making sure we don't overshoot the end
  3411. // of the scale.
  3412. $ncolor=0;
  3413. if( isset($this->ticks_label_colors) )
  3414. $ncolor=count($this->ticks_label_colors);
  3415. while( $i<$nbr ) {
  3416. // $tpos holds the absolute text position for the label
  3417. $tpos=$this->scale->ticks->maj_ticklabels_pos[$i];
  3418. // Note. the $limit is only used for the x axis since we
  3419. // might otherwise overshoot if the scale has been centered
  3420. // This is due to us "loosing" the last tick mark if we center.
  3421. if( $this->scale->type=="x" && $tpos > $this->img->width-$this->img->right_margin+1 ) {
  3422. return;
  3423. }
  3424. // we only draw every $label_step label
  3425. if( ($i % $this->label_step)==0 ) {
  3426. // Set specific label color if specified
  3427. if( $ncolor > 0 )
  3428. $this->img->SetColor($this->ticks_label_colors[$i % $ncolor]);
  3429. // If the label has been specified use that and in other case
  3430. // just label the mark with the actual scale value
  3431. $m=$this->scale->ticks->GetMajor();
  3432. // ticks_label has an entry for each data point and is the array
  3433. // that holds the labels set by the user. If the user hasn't
  3434. // specified any values we use whats in the automatically asigned
  3435. // labels in the maj_ticks_label
  3436. if( isset($this->ticks_label[$i*$m]) )
  3437. $label=$this->ticks_label[$i*$m];
  3438. else {
  3439. if( $aAbsLabel )
  3440. $label=abs($this->scale->ticks->maj_ticks_label[$i]);
  3441. else
  3442. $label=$this->scale->ticks->maj_ticks_label[$i];
  3443. if( $this->scale->textscale && $this->scale->ticks->label_formfunc == '' ) {
  3444. ++$label;
  3445. }
  3446. }
  3447. if( $this->scale->type == "x" ) {
  3448. if( $this->labelPos == SIDE_DOWN ) {
  3449. if( $this->label_angle==0 || $this->label_angle==90 ) {
  3450. if( $this->label_halign=='' && $this->label_valign=='')
  3451. $this->img->SetTextAlign('center','top');
  3452. else
  3453. $this->img->SetTextAlign($this->label_halign,$this->label_valign);
  3454. }
  3455. else {
  3456. if( $this->label_halign=='' && $this->label_valign=='')
  3457. $this->img->SetTextAlign("right","top");
  3458. else
  3459. $this->img->SetTextAlign($this->label_halign,$this->label_valign);
  3460. }
  3461. $this->img->StrokeText($tpos,$aPos+$this->tick_label_margin+1,$label,
  3462. $this->label_angle,$this->label_para_align);
  3463. }
  3464. else {
  3465. if( $this->label_angle==0 || $this->label_angle==90 ) {
  3466. if( $this->label_halign=='' && $this->label_valign=='')
  3467. $this->img->SetTextAlign("center","bottom");
  3468. else
  3469. $this->img->SetTextAlign($this->label_halign,$this->label_valign);
  3470. }
  3471. else {
  3472. if( $this->label_halign=='' && $this->label_valign=='')
  3473. $this->img->SetTextAlign("right","bottom");
  3474. else
  3475. $this->img->SetTextAlign($this->label_halign,$this->label_valign);
  3476. }
  3477. $this->img->StrokeText($tpos,$aPos-$this->tick_label_margin-1,$label,
  3478. $this->label_angle,$this->label_para_align);
  3479. }
  3480. }
  3481. else {
  3482. // scale->type == "y"
  3483. //if( $this->label_angle!=0 )
  3484. //JpGraphError::Raise(" Labels at an angle are not supported on Y-axis");
  3485. if( $this->labelPos == SIDE_LEFT ) { // To the left of y-axis
  3486. if( $this->label_halign=='' && $this->label_valign=='')
  3487. $this->img->SetTextAlign("right","center");
  3488. else
  3489. $this->img->SetTextAlign($this->label_halign,$this->label_valign);
  3490. $this->img->StrokeText($aPos-$this->tick_label_margin,$tpos,$label,$this->label_angle,$this->label_para_align);
  3491. }
  3492. else { // To the right of the y-axis
  3493. if( $this->label_halign=='' && $this->label_valign=='')
  3494. $this->img->SetTextAlign("left","center");
  3495. else
  3496. $this->img->SetTextAlign($this->label_halign,$this->label_valign);
  3497. $this->img->StrokeText($aPos+$this->tick_label_margin,$tpos,$label,$this->label_angle,$this->label_para_align);
  3498. }
  3499. }
  3500. }
  3501. ++$i;
  3502. }
  3503. }
  3504. }
  3505. //===================================================
  3506. // CLASS Ticks
  3507. // Description: Abstract base class for drawing linear and logarithmic
  3508. // tick marks on axis
  3509. //===================================================
  3510. class Ticks {
  3511. public $label_formatstr=''; // C-style format string to use for labels
  3512. public $label_formfunc='';
  3513. public $label_dateformatstr='';
  3514. public $direction=1; // Should ticks be in(=1) the plot area or outside (=-1)
  3515. public $supress_last=false,$supress_tickmarks=false,$supress_minor_tickmarks=false;
  3516. public $maj_ticks_pos = array(), $maj_ticklabels_pos = array(),
  3517. $ticks_pos = array(), $maj_ticks_label = array();
  3518. public $precision;
  3519. protected $minor_abs_size=3, $major_abs_size=5;
  3520. protected $scale;
  3521. protected $is_set=false;
  3522. protected $supress_zerolabel=false,$supress_first=false;
  3523. protected $mincolor="",$majcolor="";
  3524. protected $weight=1;
  3525. protected $label_usedateformat=FALSE;
  3526. //---------------
  3527. // CONSTRUCTOR
  3528. function Ticks($aScale) {
  3529. $this->scale=$aScale;
  3530. $this->precision = -1;
  3531. }
  3532. //---------------
  3533. // PUBLIC METHODS
  3534. // Set format string for automatic labels
  3535. function SetLabelFormat($aFormatString,$aDate=FALSE) {
  3536. $this->label_formatstr=$aFormatString;
  3537. $this->label_usedateformat=$aDate;
  3538. }
  3539. function SetLabelDateFormat($aFormatString) {
  3540. $this->label_dateformatstr=$aFormatString;
  3541. }
  3542. function SetFormatCallback($aCallbackFuncName) {
  3543. $this->label_formfunc = $aCallbackFuncName;
  3544. }
  3545. // Don't display the first zero label
  3546. function SupressZeroLabel($aFlag=true) {
  3547. $this->supress_zerolabel=$aFlag;
  3548. }
  3549. // Don't display minor tick marks
  3550. function SupressMinorTickMarks($aHide=true) {
  3551. $this->supress_minor_tickmarks=$aHide;
  3552. }
  3553. // Don't display major tick marks
  3554. function SupressTickMarks($aHide=true) {
  3555. $this->supress_tickmarks=$aHide;
  3556. }
  3557. // Hide the first tick mark
  3558. function SupressFirst($aHide=true) {
  3559. $this->supress_first=$aHide;
  3560. }
  3561. // Hide the last tick mark
  3562. function SupressLast($aHide=true) {
  3563. $this->supress_last=$aHide;
  3564. }
  3565. // Size (in pixels) of minor tick marks
  3566. function GetMinTickAbsSize() {
  3567. return $this->minor_abs_size;
  3568. }
  3569. // Size (in pixels) of major tick marks
  3570. function GetMajTickAbsSize() {
  3571. return $this->major_abs_size;
  3572. }
  3573. function SetSize($aMajSize,$aMinSize=3) {
  3574. $this->major_abs_size = $aMajSize;
  3575. $this->minor_abs_size = $aMinSize;
  3576. }
  3577. // Have the ticks been specified
  3578. function IsSpecified() {
  3579. return $this->is_set;
  3580. }
  3581. // Specify number of decimals in automatic labels
  3582. // Deprecated from 1.4. Use SetFormatString() instead
  3583. function SetPrecision($aPrecision) {
  3584. if( ERR_DEPRECATED )
  3585. JpGraphError::RaiseL(25063);//('Ticks::SetPrecision() is deprecated. Use Ticks::SetLabelFormat() (or Ticks::SetFormatCallback()) instead');
  3586. $this->precision=$aPrecision;
  3587. }
  3588. function SetSide($aSide) {
  3589. $this->direction=$aSide;
  3590. }
  3591. // Which side of the axis should the ticks be on
  3592. function SetDirection($aSide=SIDE_RIGHT) {
  3593. $this->direction=$aSide;
  3594. }
  3595. // Set colors for major and minor tick marks
  3596. function SetMarkColor($aMajorColor,$aMinorColor="") {
  3597. $this->SetColor($aMajorColor,$aMinorColor);
  3598. }
  3599. function SetColor($aMajorColor,$aMinorColor="") {
  3600. $this->majcolor=$aMajorColor;
  3601. // If not specified use same as major
  3602. if( $aMinorColor=="" )
  3603. $this->mincolor=$aMajorColor;
  3604. else
  3605. $this->mincolor=$aMinorColor;
  3606. }
  3607. function SetWeight($aWeight) {
  3608. $this->weight=$aWeight;
  3609. }
  3610. } // Class
  3611. //===================================================
  3612. // CLASS LinearTicks
  3613. // Description: Draw linear ticks on axis
  3614. //===================================================
  3615. class LinearTicks extends Ticks {
  3616. public $minor_step=1, $major_step=2;
  3617. public $xlabel_offset=0,$xtick_offset=0;
  3618. private $label_offset=0; // What offset should the displayed label have
  3619. // i.e should we display 0,1,2 or 1,2,3,4 or 2,3,4 etc
  3620. private $text_label_start=0;
  3621. private $iManualTickPos = NULL, $iManualMinTickPos = NULL, $iManualTickLabels = NULL;
  3622. private $iAdjustForDST = false; // If a date falls within the DST period add one hour to the diaplyed time
  3623. //---------------
  3624. // CONSTRUCTOR
  3625. function LinearTicks() {
  3626. $this->precision = -1;
  3627. }
  3628. //---------------
  3629. // PUBLIC METHODS
  3630. // Return major step size in world coordinates
  3631. function GetMajor() {
  3632. return $this->major_step;
  3633. }
  3634. // Return minor step size in world coordinates
  3635. function GetMinor() {
  3636. return $this->minor_step;
  3637. }
  3638. // Set Minor and Major ticks (in world coordinates)
  3639. function Set($aMajStep,$aMinStep=false) {
  3640. if( $aMinStep==false )
  3641. $aMinStep=$aMajStep;
  3642. if( $aMajStep <= 0 || $aMinStep <= 0 ) {
  3643. JpGraphError::RaiseL(25064);
  3644. //(" Minor or major step size is 0. Check that you haven't got an accidental SetTextTicks(0) in your code. If this is not the case you might have stumbled upon a bug in JpGraph. Please report this and if possible include the data that caused the problem.");
  3645. }
  3646. $this->major_step=$aMajStep;
  3647. $this->minor_step=$aMinStep;
  3648. $this->is_set = true;
  3649. }
  3650. function SetMajTickPositions($aMajPos,$aLabels=NULL) {
  3651. $this->SetTickPositions($aMajPos,NULL,$aLabels);
  3652. }
  3653. function SetTickPositions($aMajPos,$aMinPos=NULL,$aLabels=NULL) {
  3654. if( !is_array($aMajPos) || ($aMinPos!==NULL && !is_array($aMinPos)) ) {
  3655. JpGraphError::RaiseL(25065);//('Tick positions must be specifued as an array()');
  3656. return;
  3657. }
  3658. $n=count($aMajPos);
  3659. if( is_array($aLabels) && (count($aLabels) != $n) ) {
  3660. JpGraphError::RaiseL(25066);//('When manually specifying tick positions and labels the number of labels must be the same as the number of specified ticks.');
  3661. return;
  3662. }
  3663. $this->iManualTickPos = $aMajPos;
  3664. $this->iManualMinTickPos = $aMinPos;
  3665. $this->iManualTickLabels = $aLabels;
  3666. }
  3667. // Specify all the tick positions manually and possible also the exact labels
  3668. function _doManualTickPos($aScale) {
  3669. $n=count($this->iManualTickPos);
  3670. $m=count($this->iManualMinTickPos);
  3671. $doLbl=count($this->iManualTickLabels) > 0;
  3672. $this->maj_ticks_pos = array();
  3673. $this->maj_ticklabels_pos = array();
  3674. $this->ticks_pos = array();
  3675. // Now loop through the supplied positions and translate them to screen coordinates
  3676. // and store them in the maj_label_positions
  3677. $minScale = $aScale->scale[0];
  3678. $maxScale = $aScale->scale[1];
  3679. $j=0;
  3680. for($i=0; $i < $n ; ++$i ) {
  3681. // First make sure that the first tick is not lower than the lower scale value
  3682. if( !isset($this->iManualTickPos[$i]) ||
  3683. $this->iManualTickPos[$i] < $minScale || $this->iManualTickPos[$i] > $maxScale) {
  3684. continue;
  3685. }
  3686. $this->maj_ticks_pos[$j] = $aScale->Translate($this->iManualTickPos[$i]);
  3687. $this->maj_ticklabels_pos[$j] = $this->maj_ticks_pos[$j];
  3688. // Set the minor tick marks the same as major if not specified
  3689. if( $m <= 0 ) {
  3690. $this->ticks_pos[$j] = $this->maj_ticks_pos[$j];
  3691. }
  3692. if( $doLbl ) {
  3693. $this->maj_ticks_label[$j] = $this->iManualTickLabels[$i];
  3694. }
  3695. else {
  3696. $this->maj_ticks_label[$j]=$this->_doLabelFormat($this->iManualTickPos[$i],$i,$n);
  3697. }
  3698. ++$j;
  3699. }
  3700. // Some sanity check
  3701. if( count($this->maj_ticks_pos) < 2 ) {
  3702. JpGraphError::RaiseL(25067);//('Your manually specified scale and ticks is not correct. The scale seems to be too small to hold any of the specified tickl marks.');
  3703. }
  3704. // Setup the minor tick marks
  3705. $j=0;
  3706. for($i=0; $i < $m; ++$i ) {
  3707. if( empty($this->iManualMinTickPos[$i]) ||
  3708. $this->iManualMinTickPos[$i] < $minScale || $this->iManualMinTickPos[$i] > $maxScale)
  3709. continue;
  3710. $this->ticks_pos[$j] = $aScale->Translate($this->iManualMinTickPos[$i]);
  3711. ++$j;
  3712. }
  3713. }
  3714. function _doAutoTickPos($aScale) {
  3715. $maj_step_abs = $aScale->scale_factor*$this->major_step;
  3716. $min_step_abs = $aScale->scale_factor*$this->minor_step;
  3717. if( $min_step_abs==0 || $maj_step_abs==0 ) {
  3718. JpGraphError::RaiseL(25068);//("A plot has an illegal scale. This could for example be that you are trying to use text autoscaling to draw a line plot with only one point or that the plot area is too small. It could also be that no input data value is numeric (perhaps only '-' or 'x')");
  3719. }
  3720. // We need to make this an int since comparing it below
  3721. // with the result from round() can give wrong result, such that
  3722. // (40 < 40) == TRUE !!!
  3723. $limit = (int)$aScale->scale_abs[1];
  3724. if( $aScale->textscale ) {
  3725. // This can only be true for a X-scale (horizontal)
  3726. // Define ticks for a text scale. This is slightly different from a
  3727. // normal linear type of scale since the position might be adjusted
  3728. // and the labels start at on
  3729. $label = (float)$aScale->GetMinVal()+$this->text_label_start+$this->label_offset;
  3730. $start_abs=$aScale->scale_factor*$this->text_label_start;
  3731. $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal()-$this->text_label_start )/$this->major_step)+1;
  3732. $x = $aScale->scale_abs[0]+$start_abs+$this->xlabel_offset*$min_step_abs;
  3733. for( $i=0; $label <= $aScale->GetMaxVal()+$this->label_offset; ++$i ) {
  3734. // Apply format to label
  3735. $this->maj_ticks_label[$i]=$this->_doLabelFormat($label,$i,$nbrmajticks);
  3736. $label+=$this->major_step;
  3737. // The x-position of the tick marks can be different from the labels.
  3738. // Note that we record the tick position (not the label) so that the grid
  3739. // happen upon tick marks and not labels.
  3740. $xtick=$aScale->scale_abs[0]+$start_abs+$this->xtick_offset*$min_step_abs+$i*$maj_step_abs;
  3741. $this->maj_ticks_pos[$i]=$xtick;
  3742. $this->maj_ticklabels_pos[$i] = round($x);
  3743. $x += $maj_step_abs;
  3744. }
  3745. }
  3746. else {
  3747. $label = $aScale->GetMinVal();
  3748. $abs_pos = $aScale->scale_abs[0];
  3749. $j=0; $i=0;
  3750. $step = round($maj_step_abs/$min_step_abs);
  3751. if( $aScale->type == "x" ) {
  3752. // For a normal linear type of scale the major ticks will always be multiples
  3753. // of the minor ticks. In order to avoid any rounding issues the major ticks are
  3754. // defined as every "step" minor ticks and not calculated separately
  3755. $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal()-$this->text_label_start )/$this->major_step)+1;
  3756. while( round($abs_pos) <= $limit ) {
  3757. $this->ticks_pos[] = round($abs_pos);
  3758. $this->ticks_label[] = $label;
  3759. if( $step== 0 || $i % $step == 0 && $j < $nbrmajticks ) {
  3760. $this->maj_ticks_pos[$j] = round($abs_pos);
  3761. $this->maj_ticklabels_pos[$j] = round($abs_pos);
  3762. $this->maj_ticks_label[$j]=$this->_doLabelFormat($label,$j,$nbrmajticks);
  3763. ++$j;
  3764. }
  3765. ++$i;
  3766. $abs_pos += $min_step_abs;
  3767. $label+=$this->minor_step;
  3768. }
  3769. }
  3770. elseif( $aScale->type == "y" ) {
  3771. $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal())/$this->major_step)+1;
  3772. while( round($abs_pos) >= $limit ) {
  3773. $this->ticks_pos[$i] = round($abs_pos);
  3774. $this->ticks_label[$i]=$label;
  3775. if( $step== 0 || $i % $step == 0 && $j < $nbrmajticks) {
  3776. $this->maj_ticks_pos[$j] = round($abs_pos);
  3777. $this->maj_ticklabels_pos[$j] = round($abs_pos);
  3778. $this->maj_ticks_label[$j]=$this->_doLabelFormat($label,$j,$nbrmajticks);
  3779. ++$j;
  3780. }
  3781. ++$i;
  3782. $abs_pos += $min_step_abs;
  3783. $label += $this->minor_step;
  3784. }
  3785. }
  3786. }
  3787. }
  3788. function AdjustForDST($aFlg=true) {
  3789. $this->iAdjustForDST = $aFlg;
  3790. }
  3791. function _doLabelFormat($aVal,$aIdx,$aNbrTicks) {
  3792. // If precision hasn't been specified set it to a sensible value
  3793. if( $this->precision==-1 ) {
  3794. $t = log10($this->minor_step);
  3795. if( $t > 0 )
  3796. $precision = 0;
  3797. else
  3798. $precision = -floor($t);
  3799. }
  3800. else
  3801. $precision = $this->precision;
  3802. if( $this->label_formfunc != '' ) {
  3803. $f=$this->label_formfunc;
  3804. $l = call_user_func($f,$aVal);
  3805. }
  3806. elseif( $this->label_formatstr != '' || $this->label_dateformatstr != '' ) {
  3807. if( $this->label_usedateformat ) {
  3808. // Adjust the value to take daylight savings into account
  3809. if (date("I",$aVal)==1 && $this->iAdjustForDST ) // DST
  3810. $aVal+=3600;
  3811. $l = date($this->label_formatstr,$aVal);
  3812. if( $this->label_formatstr == 'W' ) {
  3813. // If we use week formatting then add a single 'w' in front of the
  3814. // week number to differentiate it from dates
  3815. $l = 'w'.$l;
  3816. }
  3817. }
  3818. else {
  3819. if( $this->label_dateformatstr !== '' ) {
  3820. // Adjust the value to take daylight savings into account
  3821. if (date("I",$aVal)==1 && $this->iAdjustForDST ) // DST
  3822. $aVal+=3600;
  3823. $l = date($this->label_dateformatstr,$aVal);
  3824. if( $this->label_formatstr == 'W' ) {
  3825. // If we use week formatting then add a single 'w' in front of the
  3826. // week number to differentiate it from dates
  3827. $l = 'w'.$l;
  3828. }
  3829. }
  3830. else
  3831. $l = sprintf($this->label_formatstr,$aVal);
  3832. }
  3833. }
  3834. else {
  3835. $l = sprintf('%01.'.$precision.'f',round($aVal,$precision));
  3836. }
  3837. if( ($this->supress_zerolabel && $l==0) || ($this->supress_first && $aIdx==0) ||
  3838. ($this->supress_last && $aIdx==$aNbrTicks-1) ) {
  3839. $l='';
  3840. }
  3841. return $l;
  3842. }
  3843. // Stroke ticks on either X or Y axis
  3844. function _StrokeTicks($aImg,$aScale,$aPos) {
  3845. $hor = $aScale->type == 'x';
  3846. $aImg->SetLineWeight($this->weight);
  3847. // We need to make this an int since comparing it below
  3848. // with the result from round() can give wrong result, such that
  3849. // (40 < 40) == TRUE !!!
  3850. $limit = (int)$aScale->scale_abs[1];
  3851. // A text scale doesn't have any minor ticks
  3852. if( !$aScale->textscale ) {
  3853. // Stroke minor ticks
  3854. $yu = $aPos - $this->direction*$this->GetMinTickAbsSize();
  3855. $xr = $aPos + $this->direction*$this->GetMinTickAbsSize();
  3856. $n = count($this->ticks_pos);
  3857. for($i=0; $i < $n; ++$i ) {
  3858. if( !$this->supress_tickmarks && !$this->supress_minor_tickmarks) {
  3859. if( $this->mincolor!="" ) $aImg->PushColor($this->mincolor);
  3860. if( $hor ) {
  3861. //if( $this->ticks_pos[$i] <= $limit )
  3862. $aImg->Line($this->ticks_pos[$i],$aPos,$this->ticks_pos[$i],$yu);
  3863. }
  3864. else {
  3865. //if( $this->ticks_pos[$i] >= $limit )
  3866. $aImg->Line($aPos,$this->ticks_pos[$i],$xr,$this->ticks_pos[$i]);
  3867. }
  3868. if( $this->mincolor!="" ) $aImg->PopColor();
  3869. }
  3870. }
  3871. }
  3872. // Stroke major ticks
  3873. $yu = $aPos - $this->direction*$this->GetMajTickAbsSize();
  3874. $xr = $aPos + $this->direction*$this->GetMajTickAbsSize();
  3875. $nbrmajticks=round(($aScale->GetMaxVal()-$aScale->GetMinVal()-$this->text_label_start )/$this->major_step)+1;
  3876. $n = count($this->maj_ticks_pos);
  3877. for($i=0; $i < $n ; ++$i ) {
  3878. if(!($this->xtick_offset > 0 && $i==$nbrmajticks-1) && !$this->supress_tickmarks) {
  3879. if( $this->majcolor!="" ) $aImg->PushColor($this->majcolor);
  3880. if( $hor ) {
  3881. //if( $this->maj_ticks_pos[$i] <= $limit )
  3882. $aImg->Line($this->maj_ticks_pos[$i],$aPos,$this->maj_ticks_pos[$i],$yu);
  3883. }
  3884. else {
  3885. //if( $this->maj_ticks_pos[$i] >= $limit )
  3886. $aImg->Line($aPos,$this->maj_ticks_pos[$i],$xr,$this->maj_ticks_pos[$i]);
  3887. }
  3888. if( $this->majcolor!="" ) $aImg->PopColor();
  3889. }
  3890. }
  3891. }
  3892. // Draw linear ticks
  3893. function Stroke($aImg,$aScale,$aPos) {
  3894. if( $this->iManualTickPos != NULL )
  3895. $this->_doManualTickPos($aScale);
  3896. else
  3897. $this->_doAutoTickPos($aScale);
  3898. $this->_StrokeTicks($aImg,$aScale,$aPos, $aScale->type == 'x' );
  3899. }
  3900. //---------------
  3901. // PRIVATE METHODS
  3902. // Spoecify the offset of the displayed tick mark with the tick "space"
  3903. // Legal values for $o is [0,1] used to adjust where the tick marks and label
  3904. // should be positioned within the major tick-size
  3905. // $lo specifies the label offset and $to specifies the tick offset
  3906. // this comes in handy for example in bar graphs where we wont no offset for the
  3907. // tick but have the labels displayed halfway under the bars.
  3908. function SetXLabelOffset($aLabelOff,$aTickOff=-1) {
  3909. $this->xlabel_offset=$aLabelOff;
  3910. if( $aTickOff==-1 ) // Same as label offset
  3911. $this->xtick_offset=$aLabelOff;
  3912. else
  3913. $this->xtick_offset=$aTickOff;
  3914. if( $aLabelOff>0 )
  3915. $this->SupressLast(); // The last tick wont fit
  3916. }
  3917. // Which tick label should we start with?
  3918. function SetTextLabelStart($aTextLabelOff) {
  3919. $this->text_label_start=$aTextLabelOff;
  3920. }
  3921. } // Class
  3922. //===================================================
  3923. // CLASS LinearScale
  3924. // Description: Handle linear scaling between screen and world
  3925. //===================================================
  3926. class LinearScale {
  3927. public $textscale=false; // Just a flag to let the Plot class find out if
  3928. // we are a textscale or not. This is a cludge since
  3929. // this information is available in Graph::axtype but
  3930. // we don't have access to the graph object in the Plots
  3931. // stroke method. So we let graph store the status here
  3932. // when the linear scale is created. A real cludge...
  3933. public $type; // is this x or y scale ?
  3934. public $ticks=null; // Store ticks
  3935. public $text_scale_off = 0;
  3936. public $scale_abs=array(0,0);
  3937. public $scale_factor; // Scale factor between world and screen
  3938. public $off; // Offset between image edge and plot area
  3939. public $scale=array(0,0);
  3940. public $name = 'lin';
  3941. public $auto_ticks=false; // When using manual scale should the ticks be automatically set?
  3942. public $world_abs_size; // Plot area size in pixels (Needed public in jpgraph_radar.php)
  3943. public $world_size; // Plot area size in world coordinates
  3944. public $intscale=false; // Restrict autoscale to integers
  3945. protected $autoscale_min=false; // Forced minimum value, auto determine max
  3946. protected $autoscale_max=false; // Forced maximum value, auto determine min
  3947. private $gracetop=0,$gracebottom=0;
  3948. //---------------
  3949. // CONSTRUCTOR
  3950. function LinearScale($aMin=0,$aMax=0,$aType="y") {
  3951. assert($aType=="x" || $aType=="y" );
  3952. assert($aMin<=$aMax);
  3953. $this->type=$aType;
  3954. $this->scale=array($aMin,$aMax);
  3955. $this->world_size=$aMax-$aMin;
  3956. $this->ticks = new LinearTicks();
  3957. }
  3958. //---------------
  3959. // PUBLIC METHODS
  3960. // Check if scale is set or if we should autoscale
  3961. // We should do this is either scale or ticks has not been set
  3962. function IsSpecified() {
  3963. if( $this->GetMinVal()==$this->GetMaxVal() ) { // Scale not set
  3964. return false;
  3965. }
  3966. return true;
  3967. }
  3968. // Set the minimum data value when the autoscaling is used.
  3969. // Usefull if you want a fix minimum (like 0) but have an
  3970. // automatic maximum
  3971. function SetAutoMin($aMin) {
  3972. $this->autoscale_min=$aMin;
  3973. }
  3974. // Set the minimum data value when the autoscaling is used.
  3975. // Usefull if you want a fix minimum (like 0) but have an
  3976. // automatic maximum
  3977. function SetAutoMax($aMax) {
  3978. $this->autoscale_max=$aMax;
  3979. }
  3980. // If the user manually specifies a scale should the ticks
  3981. // still be set automatically?
  3982. function SetAutoTicks($aFlag=true) {
  3983. $this->auto_ticks = $aFlag;
  3984. }
  3985. // Specify scale "grace" value (top and bottom)
  3986. function SetGrace($aGraceTop,$aGraceBottom=0) {
  3987. if( $aGraceTop<0 || $aGraceBottom < 0 )
  3988. JpGraphError::RaiseL(25069);//(" Grace must be larger then 0");
  3989. $this->gracetop=$aGraceTop;
  3990. $this->gracebottom=$aGraceBottom;
  3991. }
  3992. // Get the minimum value in the scale
  3993. function GetMinVal() {
  3994. return $this->scale[0];
  3995. }
  3996. // get maximum value for scale
  3997. function GetMaxVal() {
  3998. return $this->scale[1];
  3999. }
  4000. // Specify a new min/max value for sclae
  4001. function Update($aImg,$aMin,$aMax) {
  4002. $this->scale=array($aMin,$aMax);
  4003. $this->world_size=$aMax-$aMin;
  4004. $this->InitConstants($aImg);
  4005. }
  4006. // Translate between world and screen
  4007. function Translate($aCoord) {
  4008. if( !is_numeric($aCoord) ) {
  4009. if( $aCoord != '' && $aCoord != '-' && $aCoord != 'x' )
  4010. JpGraphError::RaiseL(25070);//('Your data contains non-numeric values.');
  4011. return 0;
  4012. }
  4013. else {
  4014. return $this->off+($aCoord - $this->scale[0]) * $this->scale_factor;
  4015. }
  4016. }
  4017. // Relative translate (don't include offset) usefull when we just want
  4018. // to know the relative position (in pixels) on the axis
  4019. function RelTranslate($aCoord) {
  4020. if( !is_numeric($aCoord) ) {
  4021. if( $aCoord != '' && $aCoord != '-' && $aCoord != 'x' )
  4022. JpGraphError::RaiseL(25070);//('Your data contains non-numeric values.');
  4023. return 0;
  4024. }
  4025. else {
  4026. return ($aCoord - $this->scale[0]) * $this->scale_factor;
  4027. }
  4028. }
  4029. // Restrict autoscaling to only use integers
  4030. function SetIntScale($aIntScale=true) {
  4031. $this->intscale=$aIntScale;
  4032. }
  4033. // Calculate an integer autoscale
  4034. function IntAutoScale($img,$min,$max,$maxsteps,$majend=true) {
  4035. // Make sure limits are integers
  4036. $min=floor($min);
  4037. $max=ceil($max);
  4038. if( abs($min-$max)==0 ) {
  4039. --$min; ++$max;
  4040. }
  4041. $maxsteps = floor($maxsteps);
  4042. $gracetop=round(($this->gracetop/100.0)*abs($max-$min));
  4043. $gracebottom=round(($this->gracebottom/100.0)*abs($max-$min));
  4044. if( is_numeric($this->autoscale_min) ) {
  4045. $min = ceil($this->autoscale_min);
  4046. if( $min >= $max ) {
  4047. JpGraphError::RaiseL(25071);//('You have specified a min value with SetAutoMin() which is larger than the maximum value used for the scale. This is not possible.');
  4048. }
  4049. }
  4050. if( is_numeric($this->autoscale_max) ) {
  4051. $max = ceil($this->autoscale_max);
  4052. if( $min >= $max ) {
  4053. JpGraphError::RaiseL(25072);//('You have specified a max value with SetAutoMax() which is smaller than the miminum value used for the scale. This is not possible.');
  4054. }
  4055. }
  4056. if( abs($min-$max ) == 0 ) {
  4057. ++$max;
  4058. --$min;
  4059. }
  4060. $min -= $gracebottom;
  4061. $max += $gracetop;
  4062. // First get tickmarks as multiples of 1, 10, ...
  4063. if( $majend ) {
  4064. list($num1steps,$adj1min,$adj1max,$maj1step) =
  4065. $this->IntCalcTicks($maxsteps,$min,$max,1);
  4066. }
  4067. else {
  4068. $adj1min = $min;
  4069. $adj1max = $max;
  4070. list($num1steps,$maj1step) =
  4071. $this->IntCalcTicksFreeze($maxsteps,$min,$max,1);
  4072. }
  4073. if( abs($min-$max) > 2 ) {
  4074. // Then get tick marks as 2:s 2, 20, ...
  4075. if( $majend ) {
  4076. list($num2steps,$adj2min,$adj2max,$maj2step) =
  4077. $this->IntCalcTicks($maxsteps,$min,$max,5);
  4078. }
  4079. else {
  4080. $adj2min = $min;
  4081. $adj2max = $max;
  4082. list($num2steps,$maj2step) =
  4083. $this->IntCalcTicksFreeze($maxsteps,$min,$max,5);
  4084. }
  4085. }
  4086. else {
  4087. $num2steps = 10000; // Dummy high value so we don't choose this
  4088. }
  4089. if( abs($min-$max) > 5 ) {
  4090. // Then get tickmarks as 5:s 5, 50, 500, ...
  4091. if( $majend ) {
  4092. list($num5steps,$adj5min,$adj5max,$maj5step) =
  4093. $this->IntCalcTicks($maxsteps,$min,$max,2);
  4094. }
  4095. else {
  4096. $adj5min = $min;
  4097. $adj5max = $max;
  4098. list($num5steps,$maj5step) =
  4099. $this->IntCalcTicksFreeze($maxsteps,$min,$max,2);
  4100. }
  4101. }
  4102. else {
  4103. $num5steps = 10000; // Dummy high value so we don't choose this
  4104. }
  4105. // Check to see whichof 1:s, 2:s or 5:s fit better with
  4106. // the requested number of major ticks
  4107. $match1=abs($num1steps-$maxsteps);
  4108. $match2=abs($num2steps-$maxsteps);
  4109. if( !empty($maj5step) && $maj5step > 1 )
  4110. $match5=abs($num5steps-$maxsteps);
  4111. else
  4112. $match5=10000; // Dummy high value
  4113. // Compare these three values and see which is the closest match
  4114. // We use a 0.6 weight to gravitate towards multiple of 5:s
  4115. if( $match1 < $match2 ) {
  4116. if( $match1 < $match5 )
  4117. $r=1;
  4118. else
  4119. $r=3;
  4120. }
  4121. else {
  4122. if( $match2 < $match5 )
  4123. $r=2;
  4124. else
  4125. $r=3;
  4126. }
  4127. // Minsteps are always the same as maxsteps for integer scale
  4128. switch( $r ) {
  4129. case 1:
  4130. $this->ticks->Set($maj1step,$maj1step);
  4131. $this->Update($img,$adj1min,$adj1max);
  4132. break;
  4133. case 2:
  4134. $this->ticks->Set($maj2step,$maj2step);
  4135. $this->Update($img,$adj2min,$adj2max);
  4136. break;
  4137. case 3:
  4138. $this->ticks->Set($maj5step,$maj5step);
  4139. $this->Update($img,$adj5min,$adj5max);
  4140. break;
  4141. default:
  4142. JpGraphError::RaiseL(25073,$r);//('Internal error. Integer scale algorithm comparison out of bound (r=$r)');
  4143. }
  4144. }
  4145. // Calculate autoscale. Used if user hasn't given a scale and ticks
  4146. // $maxsteps is the maximum number of major tickmarks allowed.
  4147. function AutoScale($img,$min,$max,$maxsteps,$majend=true) {
  4148. if( $this->intscale ) {
  4149. $this->IntAutoScale($img,$min,$max,$maxsteps,$majend);
  4150. return;
  4151. }
  4152. if( abs($min-$max) < 0.00001 ) {
  4153. // We need some difference to be able to autoscale
  4154. // make it 5% above and 5% below value
  4155. if( $min==0 && $max==0 ) { // Special case
  4156. $min=-1; $max=1;
  4157. }
  4158. else {
  4159. $delta = (abs($max)+abs($min))*0.005;
  4160. $min -= $delta;
  4161. $max += $delta;
  4162. }
  4163. }
  4164. $gracetop=($this->gracetop/100.0)*abs($max-$min);
  4165. $gracebottom=($this->gracebottom/100.0)*abs($max-$min);
  4166. if( is_numeric($this->autoscale_min) ) {
  4167. $min = $this->autoscale_min;
  4168. if( $min >= $max ) {
  4169. JpGraphError::RaiseL(25071);//('You have specified a min value with SetAutoMin() which is larger than the maximum value used for the scale. This is not possible.');
  4170. }
  4171. if( abs($min-$max ) < 0.00001 )
  4172. $max *= 1.2;
  4173. }
  4174. if( is_numeric($this->autoscale_max) ) {
  4175. $max = $this->autoscale_max;
  4176. if( $min >= $max ) {
  4177. JpGraphError::RaiseL(25072);//('You have specified a max value with SetAutoMax() which is smaller than the miminum value used for the scale. This is not possible.');
  4178. }
  4179. if( abs($min-$max ) < 0.00001 )
  4180. $min *= 0.8;
  4181. }
  4182. $min -= $gracebottom;
  4183. $max += $gracetop;
  4184. // First get tickmarks as multiples of 0.1, 1, 10, ...
  4185. if( $majend ) {
  4186. list($num1steps,$adj1min,$adj1max,$min1step,$maj1step) =
  4187. $this->CalcTicks($maxsteps,$min,$max,1,2);
  4188. }
  4189. else {
  4190. $adj1min=$min;
  4191. $adj1max=$max;
  4192. list($num1steps,$min1step,$maj1step) =
  4193. $this->CalcTicksFreeze($maxsteps,$min,$max,1,2,false);
  4194. }
  4195. // Then get tick marks as 2:s 0.2, 2, 20, ...
  4196. if( $majend ) {
  4197. list($num2steps,$adj2min,$adj2max,$min2step,$maj2step) =
  4198. $this->CalcTicks($maxsteps,$min,$max,5,2);
  4199. }
  4200. else {
  4201. $adj2min=$min;
  4202. $adj2max=$max;
  4203. list($num2steps,$min2step,$maj2step) =
  4204. $this->CalcTicksFreeze($maxsteps,$min,$max,5,2,false);
  4205. }
  4206. // Then get tickmarks as 5:s 0.05, 0.5, 5, 50, ...
  4207. if( $majend ) {
  4208. list($num5steps,$adj5min,$adj5max,$min5step,$maj5step) =
  4209. $this->CalcTicks($maxsteps,$min,$max,2,5);
  4210. }
  4211. else {
  4212. $adj5min=$min;
  4213. $adj5max=$max;
  4214. list($num5steps,$min5step,$maj5step) =
  4215. $this->CalcTicksFreeze($maxsteps,$min,$max,2,5,false);
  4216. }
  4217. // Check to see whichof 1:s, 2:s or 5:s fit better with
  4218. // the requested number of major ticks
  4219. $match1=abs($num1steps-$maxsteps);
  4220. $match2=abs($num2steps-$maxsteps);
  4221. $match5=abs($num5steps-$maxsteps);
  4222. // Compare these three values and see which is the closest match
  4223. // We use a 0.8 weight to gravitate towards multiple of 5:s
  4224. $r=$this->MatchMin3($match1,$match2,$match5,0.8);
  4225. switch( $r ) {
  4226. case 1:
  4227. $this->Update($img,$adj1min,$adj1max);
  4228. $this->ticks->Set($maj1step,$min1step);
  4229. break;
  4230. case 2:
  4231. $this->Update($img,$adj2min,$adj2max);
  4232. $this->ticks->Set($maj2step,$min2step);
  4233. break;
  4234. case 3:
  4235. $this->Update($img,$adj5min,$adj5max);
  4236. $this->ticks->Set($maj5step,$min5step);
  4237. break;
  4238. }
  4239. }
  4240. //---------------
  4241. // PRIVATE METHODS
  4242. // This method recalculates all constants that are depending on the
  4243. // margins in the image. If the margins in the image are changed
  4244. // this method should be called for every scale that is registred with
  4245. // that image. Should really be installed as an observer of that image.
  4246. function InitConstants($img) {
  4247. if( $this->type=="x" ) {
  4248. $this->world_abs_size=$img->width - $img->left_margin - $img->right_margin;
  4249. $this->off=$img->left_margin;
  4250. $this->scale_factor = 0;
  4251. if( $this->world_size > 0 )
  4252. $this->scale_factor=$this->world_abs_size/($this->world_size*1.0);
  4253. }
  4254. else { // y scale
  4255. $this->world_abs_size=$img->height - $img->top_margin - $img->bottom_margin;
  4256. $this->off=$img->top_margin+$this->world_abs_size;
  4257. $this->scale_factor = 0;
  4258. if( $this->world_size > 0 )
  4259. $this->scale_factor=-$this->world_abs_size/($this->world_size*1.0);
  4260. }
  4261. $size = $this->world_size * $this->scale_factor;
  4262. $this->scale_abs=array($this->off,$this->off + $size);
  4263. }
  4264. // Initialize the conversion constants for this scale
  4265. // This tries to pre-calculate as much as possible to speed up the
  4266. // actual conversion (with Translate()) later on
  4267. // $start =scale start in absolute pixels (for x-scale this is an y-position
  4268. // and for an y-scale this is an x-position
  4269. // $len =absolute length in pixels of scale
  4270. function SetConstants($aStart,$aLen) {
  4271. $this->world_abs_size=$aLen;
  4272. $this->off=$aStart;
  4273. if( $this->world_size<=0 ) {
  4274. // This should never ever happen !!
  4275. JpGraphError::RaiseL(25074);
  4276. //("You have unfortunately stumbled upon a bug in JpGraph. It seems like the scale range is ".$this->world_size." [for ".$this->type." scale] <br> Please report Bug #01 to jpgraph@aditus.nu and include the script that gave this error. This problem could potentially be caused by trying to use \"illegal\" values in the input data arrays (like trying to send in strings or only NULL values) which causes the autoscaling to fail.");
  4277. }
  4278. // scale_factor = number of pixels per world unit
  4279. $this->scale_factor=$this->world_abs_size/($this->world_size*1.0);
  4280. // scale_abs = start and end points of scale in absolute pixels
  4281. $this->scale_abs=array($this->off,$this->off+$this->world_size*$this->scale_factor);
  4282. }
  4283. // Calculate number of ticks steps with a specific division
  4284. // $a is the divisor of 10**x to generate the first maj tick intervall
  4285. // $a=1, $b=2 give major ticks with multiple of 10, ...,0.1,1,10,...
  4286. // $a=5, $b=2 give major ticks with multiple of 2:s ...,0.2,2,20,...
  4287. // $a=2, $b=5 give major ticks with multiple of 5:s ...,0.5,5,50,...
  4288. // We return a vector of
  4289. // [$numsteps,$adjmin,$adjmax,$minstep,$majstep]
  4290. // If $majend==true then the first and last marks on the axis will be major
  4291. // labeled tick marks otherwise it will be adjusted to the closest min tick mark
  4292. function CalcTicks($maxsteps,$min,$max,$a,$b,$majend=true) {
  4293. $diff=$max-$min;
  4294. if( $diff==0 )
  4295. $ld=0;
  4296. else
  4297. $ld=floor(log10($diff));
  4298. // Gravitate min towards zero if we are close
  4299. if( $min>0 && $min < pow(10,$ld) ) $min=0;
  4300. //$majstep=pow(10,$ld-1)/$a;
  4301. $majstep=pow(10,$ld)/$a;
  4302. $minstep=$majstep/$b;
  4303. $adjmax=ceil($max/$minstep)*$minstep;
  4304. $adjmin=floor($min/$minstep)*$minstep;
  4305. $adjdiff = $adjmax-$adjmin;
  4306. $numsteps=$adjdiff/$majstep;
  4307. while( $numsteps>$maxsteps ) {
  4308. $majstep=pow(10,$ld)/$a;
  4309. $numsteps=$adjdiff/$majstep;
  4310. ++$ld;
  4311. }
  4312. $minstep=$majstep/$b;
  4313. $adjmin=floor($min/$minstep)*$minstep;
  4314. $adjdiff = $adjmax-$adjmin;
  4315. if( $majend ) {
  4316. $adjmin = floor($min/$majstep)*$majstep;
  4317. $adjdiff = $adjmax-$adjmin;
  4318. $adjmax = ceil($adjdiff/$majstep)*$majstep+$adjmin;
  4319. }
  4320. else
  4321. $adjmax=ceil($max/$minstep)*$minstep;
  4322. return array($numsteps,$adjmin,$adjmax,$minstep,$majstep);
  4323. }
  4324. function CalcTicksFreeze($maxsteps,$min,$max,$a,$b) {
  4325. // Same as CalcTicks but don't adjust min/max values
  4326. $diff=$max-$min;
  4327. if( $diff==0 )
  4328. $ld=0;
  4329. else
  4330. $ld=floor(log10($diff));
  4331. //$majstep=pow(10,$ld-1)/$a;
  4332. $majstep=pow(10,$ld)/$a;
  4333. $minstep=$majstep/$b;
  4334. $numsteps=floor($diff/$majstep);
  4335. while( $numsteps > $maxsteps ) {
  4336. $majstep=pow(10,$ld)/$a;
  4337. $numsteps=floor($diff/$majstep);
  4338. ++$ld;
  4339. }
  4340. $minstep=$majstep/$b;
  4341. return array($numsteps,$minstep,$majstep);
  4342. }
  4343. function IntCalcTicks($maxsteps,$min,$max,$a,$majend=true) {
  4344. $diff=$max-$min;
  4345. if( $diff==0 )
  4346. JpGraphError::RaiseL(25075);//('Can\'t automatically determine ticks since min==max.');
  4347. else
  4348. $ld=floor(log10($diff));
  4349. // Gravitate min towards zero if we are close
  4350. if( $min>0 && $min < pow(10,$ld) ) $min=0;
  4351. if( $ld == 0 ) $ld=1;
  4352. if( $a == 1 )
  4353. $majstep = 1;
  4354. else
  4355. $majstep=pow(10,$ld)/$a;
  4356. $adjmax=ceil($max/$majstep)*$majstep;
  4357. $adjmin=floor($min/$majstep)*$majstep;
  4358. $adjdiff = $adjmax-$adjmin;
  4359. $numsteps=$adjdiff/$majstep;
  4360. while( $numsteps>$maxsteps ) {
  4361. $majstep=pow(10,$ld)/$a;
  4362. $numsteps=$adjdiff/$majstep;
  4363. ++$ld;
  4364. }
  4365. $adjmin=floor($min/$majstep)*$majstep;
  4366. $adjdiff = $adjmax-$adjmin;
  4367. if( $majend ) {
  4368. $adjmin = floor($min/$majstep)*$majstep;
  4369. $adjdiff = $adjmax-$adjmin;
  4370. $adjmax = ceil($adjdiff/$majstep)*$majstep+$adjmin;
  4371. }
  4372. else
  4373. $adjmax=ceil($max/$majstep)*$majstep;
  4374. return array($numsteps,$adjmin,$adjmax,$majstep);
  4375. }
  4376. function IntCalcTicksFreeze($maxsteps,$min,$max,$a) {
  4377. // Same as IntCalcTick but don't change min/max values
  4378. $diff=$max-$min;
  4379. if( $diff==0 )
  4380. JpGraphError::RaiseL(25075);//('Can\'t automatically determine ticks since min==max.');
  4381. else
  4382. $ld=floor(log10($diff));
  4383. if( $ld == 0 ) $ld=1;
  4384. if( $a == 1 )
  4385. $majstep = 1;
  4386. else
  4387. $majstep=pow(10,$ld)/$a;
  4388. $numsteps=floor($diff/$majstep);
  4389. while( $numsteps > $maxsteps ) {
  4390. $majstep=pow(10,$ld)/$a;
  4391. $numsteps=floor($diff/$majstep);
  4392. ++$ld;
  4393. }
  4394. return array($numsteps,$majstep);
  4395. }
  4396. // Determine the minimum of three values witha weight for last value
  4397. function MatchMin3($a,$b,$c,$weight) {
  4398. if( $a < $b ) {
  4399. if( $a < ($c*$weight) )
  4400. return 1; // $a smallest
  4401. else
  4402. return 3; // $c smallest
  4403. }
  4404. elseif( $b < ($c*$weight) )
  4405. return 2; // $b smallest
  4406. return 3; // $c smallest
  4407. }
  4408. } // Class
  4409. //===================================================
  4410. // CLASS RGB
  4411. // Description: Color definitions as RGB triples
  4412. //===================================================
  4413. class RGB {
  4414. public $rgb_table;
  4415. public $img;
  4416. function RGB($aImg=null) {
  4417. $this->img = $aImg;
  4418. // Conversion array between color names and RGB
  4419. $this->rgb_table = array(
  4420. "aqua"=> array(0,255,255),
  4421. "lime"=> array(0,255,0),
  4422. "teal"=> array(0,128,128),
  4423. "whitesmoke"=>array(245,245,245),
  4424. "gainsboro"=>array(220,220,220),
  4425. "oldlace"=>array(253,245,230),
  4426. "linen"=>array(250,240,230),
  4427. "antiquewhite"=>array(250,235,215),
  4428. "papayawhip"=>array(255,239,213),
  4429. "blanchedalmond"=>array(255,235,205),
  4430. "bisque"=>array(255,228,196),
  4431. "peachpuff"=>array(255,218,185),
  4432. "navajowhite"=>array(255,222,173),
  4433. "moccasin"=>array(255,228,181),
  4434. "cornsilk"=>array(255,248,220),
  4435. "ivory"=>array(255,255,240),
  4436. "lemonchiffon"=>array(255,250,205),
  4437. "seashell"=>array(255,245,238),
  4438. "mintcream"=>array(245,255,250),
  4439. "azure"=>array(240,255,255),
  4440. "aliceblue"=>array(240,248,255),
  4441. "lavender"=>array(230,230,250),
  4442. "lavenderblush"=>array(255,240,245),
  4443. "mistyrose"=>array(255,228,225),
  4444. "white"=>array(255,255,255),
  4445. "black"=>array(0,0,0),
  4446. "darkslategray"=>array(47,79,79),
  4447. "dimgray"=>array(105,105,105),
  4448. "slategray"=>array(112,128,144),
  4449. "lightslategray"=>array(119,136,153),
  4450. "gray"=>array(190,190,190),
  4451. "lightgray"=>array(211,211,211),
  4452. "midnightblue"=>array(25,25,112),
  4453. "navy"=>array(0,0,128),
  4454. "cornflowerblue"=>array(100,149,237),
  4455. "darkslateblue"=>array(72,61,139),
  4456. "slateblue"=>array(106,90,205),
  4457. "mediumslateblue"=>array(123,104,238),
  4458. "lightslateblue"=>array(132,112,255),
  4459. "mediumblue"=>array(0,0,205),
  4460. "royalblue"=>array(65,105,225),
  4461. "blue"=>array(0,0,255),
  4462. "dodgerblue"=>array(30,144,255),
  4463. "deepskyblue"=>array(0,191,255),
  4464. "skyblue"=>array(135,206,235),
  4465. "lightskyblue"=>array(135,206,250),
  4466. "steelblue"=>array(70,130,180),
  4467. "lightred"=>array(211,167,168),
  4468. "lightsteelblue"=>array(176,196,222),
  4469. "lightblue"=>array(173,216,230),
  4470. "powderblue"=>array(176,224,230),
  4471. "paleturquoise"=>array(175,238,238),
  4472. "darkturquoise"=>array(0,206,209),
  4473. "mediumturquoise"=>array(72,209,204),
  4474. "turquoise"=>array(64,224,208),
  4475. "cyan"=>array(0,255,255),
  4476. "lightcyan"=>array(224,255,255),
  4477. "cadetblue"=>array(95,158,160),
  4478. "mediumaquamarine"=>array(102,205,170),
  4479. "aquamarine"=>array(127,255,212),
  4480. "darkgreen"=>array(0,100,0),
  4481. "darkolivegreen"=>array(85,107,47),
  4482. "darkseagreen"=>array(143,188,143),
  4483. "seagreen"=>array(46,139,87),
  4484. "mediumseagreen"=>array(60,179,113),
  4485. "lightseagreen"=>array(32,178,170),
  4486. "palegreen"=>array(152,251,152),
  4487. "springgreen"=>array(0,255,127),
  4488. "lawngreen"=>array(124,252,0),
  4489. "green"=>array(0,255,0),
  4490. "chartreuse"=>array(127,255,0),
  4491. "mediumspringgreen"=>array(0,250,154),
  4492. "greenyellow"=>array(173,255,47),
  4493. "limegreen"=>array(50,205,50),
  4494. "yellowgreen"=>array(154,205,50),
  4495. "forestgreen"=>array(34,139,34),
  4496. "olivedrab"=>array(107,142,35),
  4497. "darkkhaki"=>array(189,183,107),
  4498. "khaki"=>array(240,230,140),
  4499. "palegoldenrod"=>array(238,232,170),
  4500. "lightgoldenrodyellow"=>array(250,250,210),
  4501. "lightyellow"=>array(255,255,200),
  4502. "yellow"=>array(255,255,0),
  4503. "gold"=>array(255,215,0),
  4504. "lightgoldenrod"=>array(238,221,130),
  4505. "goldenrod"=>array(218,165,32),
  4506. "darkgoldenrod"=>array(184,134,11),
  4507. "rosybrown"=>array(188,143,143),
  4508. "indianred"=>array(205,92,92),
  4509. "saddlebrown"=>array(139,69,19),
  4510. "sienna"=>array(160,82,45),
  4511. "peru"=>array(205,133,63),
  4512. "burlywood"=>array(222,184,135),
  4513. "beige"=>array(245,245,220),
  4514. "wheat"=>array(245,222,179),
  4515. "sandybrown"=>array(244,164,96),
  4516. "tan"=>array(210,180,140),
  4517. "chocolate"=>array(210,105,30),
  4518. "firebrick"=>array(178,34,34),
  4519. "brown"=>array(165,42,42),
  4520. "darksalmon"=>array(233,150,122),
  4521. "salmon"=>array(250,128,114),
  4522. "lightsalmon"=>array(255,160,122),
  4523. "orange"=>array(255,165,0),
  4524. "darkorange"=>array(255,140,0),
  4525. "coral"=>array(255,127,80),
  4526. "lightcoral"=>array(240,128,128),
  4527. "tomato"=>array(255,99,71),
  4528. "orangered"=>array(255,69,0),
  4529. "red"=>array(255,0,0),
  4530. "hotpink"=>array(255,105,180),
  4531. "deeppink"=>array(255,20,147),
  4532. "pink"=>array(255,192,203),
  4533. "lightpink"=>array(255,182,193),
  4534. "palevioletred"=>array(219,112,147),
  4535. "maroon"=>array(176,48,96),
  4536. "mediumvioletred"=>array(199,21,133),
  4537. "violetred"=>array(208,32,144),
  4538. "magenta"=>array(255,0,255),
  4539. "violet"=>array(238,130,238),
  4540. "plum"=>array(221,160,221),
  4541. "orchid"=>array(218,112,214),
  4542. "mediumorchid"=>array(186,85,211),
  4543. "darkorchid"=>array(153,50,204),
  4544. "darkviolet"=>array(148,0,211),
  4545. "blueviolet"=>array(138,43,226),
  4546. "purple"=>array(160,32,240),
  4547. "mediumpurple"=>array(147,112,219),
  4548. "thistle"=>array(216,191,216),
  4549. "snow1"=>array(255,250,250),
  4550. "snow2"=>array(238,233,233),
  4551. "snow3"=>array(205,201,201),
  4552. "snow4"=>array(139,137,137),
  4553. "seashell1"=>array(255,245,238),
  4554. "seashell2"=>array(238,229,222),
  4555. "seashell3"=>array(205,197,191),
  4556. "seashell4"=>array(139,134,130),
  4557. "AntiqueWhite1"=>array(255,239,219),
  4558. "AntiqueWhite2"=>array(238,223,204),
  4559. "AntiqueWhite3"=>array(205,192,176),
  4560. "AntiqueWhite4"=>array(139,131,120),
  4561. "bisque1"=>array(255,228,196),
  4562. "bisque2"=>array(238,213,183),
  4563. "bisque3"=>array(205,183,158),
  4564. "bisque4"=>array(139,125,107),
  4565. "peachPuff1"=>array(255,218,185),
  4566. "peachpuff2"=>array(238,203,173),
  4567. "peachpuff3"=>array(205,175,149),
  4568. "peachpuff4"=>array(139,119,101),
  4569. "navajowhite1"=>array(255,222,173),
  4570. "navajowhite2"=>array(238,207,161),
  4571. "navajowhite3"=>array(205,179,139),
  4572. "navajowhite4"=>array(139,121,94),
  4573. "lemonchiffon1"=>array(255,250,205),
  4574. "lemonchiffon2"=>array(238,233,191),
  4575. "lemonchiffon3"=>array(205,201,165),
  4576. "lemonchiffon4"=>array(139,137,112),
  4577. "ivory1"=>array(255,255,240),
  4578. "ivory2"=>array(238,238,224),
  4579. "ivory3"=>array(205,205,193),
  4580. "ivory4"=>array(139,139,131),
  4581. "honeydew"=>array(193,205,193),
  4582. "lavenderblush1"=>array(255,240,245),
  4583. "lavenderblush2"=>array(238,224,229),
  4584. "lavenderblush3"=>array(205,193,197),
  4585. "lavenderblush4"=>array(139,131,134),
  4586. "mistyrose1"=>array(255,228,225),
  4587. "mistyrose2"=>array(238,213,210),
  4588. "mistyrose3"=>array(205,183,181),
  4589. "mistyrose4"=>array(139,125,123),
  4590. "azure1"=>array(240,255,255),
  4591. "azure2"=>array(224,238,238),
  4592. "azure3"=>array(193,205,205),
  4593. "azure4"=>array(131,139,139),
  4594. "slateblue1"=>array(131,111,255),
  4595. "slateblue2"=>array(122,103,238),
  4596. "slateblue3"=>array(105,89,205),
  4597. "slateblue4"=>array(71,60,139),
  4598. "royalblue1"=>array(72,118,255),
  4599. "royalblue2"=>array(67,110,238),
  4600. "royalblue3"=>array(58,95,205),
  4601. "royalblue4"=>array(39,64,139),
  4602. "dodgerblue1"=>array(30,144,255),
  4603. "dodgerblue2"=>array(28,134,238),
  4604. "dodgerblue3"=>array(24,116,205),
  4605. "dodgerblue4"=>array(16,78,139),
  4606. "steelblue1"=>array(99,184,255),
  4607. "steelblue2"=>array(92,172,238),
  4608. "steelblue3"=>array(79,148,205),
  4609. "steelblue4"=>array(54,100,139),
  4610. "deepskyblue1"=>array(0,191,255),
  4611. "deepskyblue2"=>array(0,178,238),
  4612. "deepskyblue3"=>array(0,154,205),
  4613. "deepskyblue4"=>array(0,104,139),
  4614. "skyblue1"=>array(135,206,255),
  4615. "skyblue2"=>array(126,192,238),
  4616. "skyblue3"=>array(108,166,205),
  4617. "skyblue4"=>array(74,112,139),
  4618. "lightskyblue1"=>array(176,226,255),
  4619. "lightskyblue2"=>array(164,211,238),
  4620. "lightskyblue3"=>array(141,182,205),
  4621. "lightskyblue4"=>array(96,123,139),
  4622. "slategray1"=>array(198,226,255),
  4623. "slategray2"=>array(185,211,238),
  4624. "slategray3"=>array(159,182,205),
  4625. "slategray4"=>array(108,123,139),
  4626. "lightsteelblue1"=>array(202,225,255),
  4627. "lightsteelblue2"=>array(188,210,238),
  4628. "lightsteelblue3"=>array(162,181,205),
  4629. "lightsteelblue4"=>array(110,123,139),
  4630. "lightblue1"=>array(191,239,255),
  4631. "lightblue2"=>array(178,223,238),
  4632. "lightblue3"=>array(154,192,205),
  4633. "lightblue4"=>array(104,131,139),
  4634. "lightcyan1"=>array(224,255,255),
  4635. "lightcyan2"=>array(209,238,238),
  4636. "lightcyan3"=>array(180,205,205),
  4637. "lightcyan4"=>array(122,139,139),
  4638. "paleturquoise1"=>array(187,255,255),
  4639. "paleturquoise2"=>array(174,238,238),
  4640. "paleturquoise3"=>array(150,205,205),
  4641. "paleturquoise4"=>array(102,139,139),
  4642. "cadetblue1"=>array(152,245,255),
  4643. "cadetblue2"=>array(142,229,238),
  4644. "cadetblue3"=>array(122,197,205),
  4645. "cadetblue4"=>array(83,134,139),
  4646. "turquoise1"=>array(0,245,255),
  4647. "turquoise2"=>array(0,229,238),
  4648. "turquoise3"=>array(0,197,205),
  4649. "turquoise4"=>array(0,134,139),
  4650. "cyan1"=>array(0,255,255),
  4651. "cyan2"=>array(0,238,238),
  4652. "cyan3"=>array(0,205,205),
  4653. "cyan4"=>array(0,139,139),
  4654. "darkslategray1"=>array(151,255,255),
  4655. "darkslategray2"=>array(141,238,238),
  4656. "darkslategray3"=>array(121,205,205),
  4657. "darkslategray4"=>array(82,139,139),
  4658. "aquamarine1"=>array(127,255,212),
  4659. "aquamarine2"=>array(118,238,198),
  4660. "aquamarine3"=>array(102,205,170),
  4661. "aquamarine4"=>array(69,139,116),
  4662. "darkseagreen1"=>array(193,255,193),
  4663. "darkseagreen2"=>array(180,238,180),
  4664. "darkseagreen3"=>array(155,205,155),
  4665. "darkseagreen4"=>array(105,139,105),
  4666. "seagreen1"=>array(84,255,159),
  4667. "seagreen2"=>array(78,238,148),
  4668. "seagreen3"=>array(67,205,128),
  4669. "seagreen4"=>array(46,139,87),
  4670. "palegreen1"=>array(154,255,154),
  4671. "palegreen2"=>array(144,238,144),
  4672. "palegreen3"=>array(124,205,124),
  4673. "palegreen4"=>array(84,139,84),
  4674. "springgreen1"=>array(0,255,127),
  4675. "springgreen2"=>array(0,238,118),
  4676. "springgreen3"=>array(0,205,102),
  4677. "springgreen4"=>array(0,139,69),
  4678. "chartreuse1"=>array(127,255,0),
  4679. "chartreuse2"=>array(118,238,0),
  4680. "chartreuse3"=>array(102,205,0),
  4681. "chartreuse4"=>array(69,139,0),
  4682. "olivedrab1"=>array(192,255,62),
  4683. "olivedrab2"=>array(179,238,58),
  4684. "olivedrab3"=>array(154,205,50),
  4685. "olivedrab4"=>array(105,139,34),
  4686. "darkolivegreen1"=>array(202,255,112),
  4687. "darkolivegreen2"=>array(188,238,104),
  4688. "darkolivegreen3"=>array(162,205,90),
  4689. "darkolivegreen4"=>array(110,139,61),
  4690. "khaki1"=>array(255,246,143),
  4691. "khaki2"=>array(238,230,133),
  4692. "khaki3"=>array(205,198,115),
  4693. "khaki4"=>array(139,134,78),
  4694. "lightgoldenrod1"=>array(255,236,139),
  4695. "lightgoldenrod2"=>array(238,220,130),
  4696. "lightgoldenrod3"=>array(205,190,112),
  4697. "lightgoldenrod4"=>array(139,129,76),
  4698. "yellow1"=>array(255,255,0),
  4699. "yellow2"=>array(238,238,0),
  4700. "yellow3"=>array(205,205,0),
  4701. "yellow4"=>array(139,139,0),
  4702. "gold1"=>array(255,215,0),
  4703. "gold2"=>array(238,201,0),
  4704. "gold3"=>array(205,173,0),
  4705. "gold4"=>array(139,117,0),
  4706. "goldenrod1"=>array(255,193,37),
  4707. "goldenrod2"=>array(238,180,34),
  4708. "goldenrod3"=>array(205,155,29),
  4709. "goldenrod4"=>array(139,105,20),
  4710. "darkgoldenrod1"=>array(255,185,15),
  4711. "darkgoldenrod2"=>array(238,173,14),
  4712. "darkgoldenrod3"=>array(205,149,12),
  4713. "darkgoldenrod4"=>array(139,101,8),
  4714. "rosybrown1"=>array(255,193,193),
  4715. "rosybrown2"=>array(238,180,180),
  4716. "rosybrown3"=>array(205,155,155),
  4717. "rosybrown4"=>array(139,105,105),
  4718. "indianred1"=>array(255,106,106),
  4719. "indianred2"=>array(238,99,99),
  4720. "indianred3"=>array(205,85,85),
  4721. "indianred4"=>array(139,58,58),
  4722. "sienna1"=>array(255,130,71),
  4723. "sienna2"=>array(238,121,66),
  4724. "sienna3"=>array(205,104,57),
  4725. "sienna4"=>array(139,71,38),
  4726. "burlywood1"=>array(255,211,155),
  4727. "burlywood2"=>array(238,197,145),
  4728. "burlywood3"=>array(205,170,125),
  4729. "burlywood4"=>array(139,115,85),
  4730. "wheat1"=>array(255,231,186),
  4731. "wheat2"=>array(238,216,174),
  4732. "wheat3"=>array(205,186,150),
  4733. "wheat4"=>array(139,126,102),
  4734. "tan1"=>array(255,165,79),
  4735. "tan2"=>array(238,154,73),
  4736. "tan3"=>array(205,133,63),
  4737. "tan4"=>array(139,90,43),
  4738. "chocolate1"=>array(255,127,36),
  4739. "chocolate2"=>array(238,118,33),
  4740. "chocolate3"=>array(205,102,29),
  4741. "chocolate4"=>array(139,69,19),
  4742. "firebrick1"=>array(255,48,48),
  4743. "firebrick2"=>array(238,44,44),
  4744. "firebrick3"=>array(205,38,38),
  4745. "firebrick4"=>array(139,26,26),
  4746. "brown1"=>array(255,64,64),
  4747. "brown2"=>array(238,59,59),
  4748. "brown3"=>array(205,51,51),
  4749. "brown4"=>array(139,35,35),
  4750. "salmon1"=>array(255,140,105),
  4751. "salmon2"=>array(238,130,98),
  4752. "salmon3"=>array(205,112,84),
  4753. "salmon4"=>array(139,76,57),
  4754. "lightsalmon1"=>array(255,160,122),
  4755. "lightsalmon2"=>array(238,149,114),
  4756. "lightsalmon3"=>array(205,129,98),
  4757. "lightsalmon4"=>array(139,87,66),
  4758. "orange1"=>array(255,165,0),
  4759. "orange2"=>array(238,154,0),
  4760. "orange3"=>array(205,133,0),
  4761. "orange4"=>array(139,90,0),
  4762. "darkorange1"=>array(255,127,0),
  4763. "darkorange2"=>array(238,118,0),
  4764. "darkorange3"=>array(205,102,0),
  4765. "darkorange4"=>array(139,69,0),
  4766. "coral1"=>array(255,114,86),
  4767. "coral2"=>array(238,106,80),
  4768. "coral3"=>array(205,91,69),
  4769. "coral4"=>array(139,62,47),
  4770. "tomato1"=>array(255,99,71),
  4771. "tomato2"=>array(238,92,66),
  4772. "tomato3"=>array(205,79,57),
  4773. "tomato4"=>array(139,54,38),
  4774. "orangered1"=>array(255,69,0),
  4775. "orangered2"=>array(238,64,0),
  4776. "orangered3"=>array(205,55,0),
  4777. "orangered4"=>array(139,37,0),
  4778. "deeppink1"=>array(255,20,147),
  4779. "deeppink2"=>array(238,18,137),
  4780. "deeppink3"=>array(205,16,118),
  4781. "deeppink4"=>array(139,10,80),
  4782. "hotpink1"=>array(255,110,180),
  4783. "hotpink2"=>array(238,106,167),
  4784. "hotpink3"=>array(205,96,144),
  4785. "hotpink4"=>array(139,58,98),
  4786. "pink1"=>array(255,181,197),
  4787. "pink2"=>array(238,169,184),
  4788. "pink3"=>array(205,145,158),
  4789. "pink4"=>array(139,99,108),
  4790. "lightpink1"=>array(255,174,185),
  4791. "lightpink2"=>array(238,162,173),
  4792. "lightpink3"=>array(205,140,149),
  4793. "lightpink4"=>array(139,95,101),
  4794. "palevioletred1"=>array(255,130,171),
  4795. "palevioletred2"=>array(238,121,159),
  4796. "palevioletred3"=>array(205,104,137),
  4797. "palevioletred4"=>array(139,71,93),
  4798. "maroon1"=>array(255,52,179),
  4799. "maroon2"=>array(238,48,167),
  4800. "maroon3"=>array(205,41,144),
  4801. "maroon4"=>array(139,28,98),
  4802. "violetred1"=>array(255,62,150),
  4803. "violetred2"=>array(238,58,140),
  4804. "violetred3"=>array(205,50,120),
  4805. "violetred4"=>array(139,34,82),
  4806. "magenta1"=>array(255,0,255),
  4807. "magenta2"=>array(238,0,238),
  4808. "magenta3"=>array(205,0,205),
  4809. "magenta4"=>array(139,0,139),
  4810. "mediumred"=>array(140,34,34),
  4811. "orchid1"=>array(255,131,250),
  4812. "orchid2"=>array(238,122,233),
  4813. "orchid3"=>array(205,105,201),
  4814. "orchid4"=>array(139,71,137),
  4815. "plum1"=>array(255,187,255),
  4816. "plum2"=>array(238,174,238),
  4817. "plum3"=>array(205,150,205),
  4818. "plum4"=>array(139,102,139),
  4819. "mediumorchid1"=>array(224,102,255),
  4820. "mediumorchid2"=>array(209,95,238),
  4821. "mediumorchid3"=>array(180,82,205),
  4822. "mediumorchid4"=>array(122,55,139),
  4823. "darkorchid1"=>array(191,62,255),
  4824. "darkorchid2"=>array(178,58,238),
  4825. "darkorchid3"=>array(154,50,205),
  4826. "darkorchid4"=>array(104,34,139),
  4827. "purple1"=>array(155,48,255),
  4828. "purple2"=>array(145,44,238),
  4829. "purple3"=>array(125,38,205),
  4830. "purple4"=>array(85,26,139),
  4831. "mediumpurple1"=>array(171,130,255),
  4832. "mediumpurple2"=>array(159,121,238),
  4833. "mediumpurple3"=>array(137,104,205),
  4834. "mediumpurple4"=>array(93,71,139),
  4835. "thistle1"=>array(255,225,255),
  4836. "thistle2"=>array(238,210,238),
  4837. "thistle3"=>array(205,181,205),
  4838. "thistle4"=>array(139,123,139),
  4839. "gray1"=>array(10,10,10),
  4840. "gray2"=>array(40,40,30),
  4841. "gray3"=>array(70,70,70),
  4842. "gray4"=>array(100,100,100),
  4843. "gray5"=>array(130,130,130),
  4844. "gray6"=>array(160,160,160),
  4845. "gray7"=>array(190,190,190),
  4846. "gray8"=>array(210,210,210),
  4847. "gray9"=>array(240,240,240),
  4848. "darkgray"=>array(100,100,100),
  4849. "darkblue"=>array(0,0,139),
  4850. "darkcyan"=>array(0,139,139),
  4851. "darkmagenta"=>array(139,0,139),
  4852. "darkred"=>array(139,0,0),
  4853. "silver"=>array(192, 192, 192),
  4854. "eggplant"=>array(144,176,168),
  4855. "lightgreen"=>array(144,238,144));
  4856. }
  4857. //----------------
  4858. // PUBLIC METHODS
  4859. // Colors can be specified as either
  4860. // 1. #xxxxxx HTML style
  4861. // 2. "colorname" as a named color
  4862. // 3. array(r,g,b) RGB triple
  4863. // This function translates this to a native RGB format and returns an
  4864. // RGB triple.
  4865. function Color($aColor) {
  4866. if (is_string($aColor)) {
  4867. // Strip of any alpha factor
  4868. $pos = strpos($aColor,'@');
  4869. if( $pos === false ) {
  4870. $alpha = 0;
  4871. }
  4872. else {
  4873. $pos2 = strpos($aColor,':');
  4874. if( $pos2===false )
  4875. $pos2 = $pos-1; // Sentinel
  4876. if( $pos > $pos2 ) {
  4877. $alpha = str_replace(',','.',substr($aColor,$pos+1));
  4878. $aColor = substr($aColor,0,$pos);
  4879. }
  4880. else {
  4881. $alpha = substr($aColor,$pos+1,$pos2-$pos-1);
  4882. $aColor = substr($aColor,0,$pos).substr($aColor,$pos2);
  4883. }
  4884. }
  4885. // Extract potential adjustment figure at end of color
  4886. // specification
  4887. $pos = strpos($aColor,":");
  4888. if( $pos === false ) {
  4889. $adj = 1.0;
  4890. }
  4891. else {
  4892. $adj = 0.0 + str_replace(',','.',substr($aColor,$pos+1));
  4893. $aColor = substr($aColor,0,$pos);
  4894. }
  4895. if( $adj < 0 )
  4896. JpGraphError::RaiseL(25077);//('Adjustment factor for color must be > 0');
  4897. if (substr($aColor, 0, 1) == "#") {
  4898. $r = hexdec(substr($aColor, 1, 2));
  4899. $g = hexdec(substr($aColor, 3, 2));
  4900. $b = hexdec(substr($aColor, 5, 2));
  4901. } else {
  4902. if(!isset($this->rgb_table[$aColor]) )
  4903. JpGraphError::RaiseL(25078,$aColor);//(" Unknown color: $aColor");
  4904. $tmp=$this->rgb_table[$aColor];
  4905. $r = $tmp[0];
  4906. $g = $tmp[1];
  4907. $b = $tmp[2];
  4908. }
  4909. // Scale adj so that an adj=2 always
  4910. // makes the color 100% white (i.e. 255,255,255.
  4911. // and adj=1 neutral and adj=0 black.
  4912. if( $adj > 1 ) {
  4913. $m = ($adj-1.0)*(255-min(255,min($r,min($g,$b))));
  4914. return array(min(255,$r+$m), min(255,$g+$m), min(255,$b+$m),$alpha);
  4915. }
  4916. elseif( $adj < 1 ) {
  4917. $m = ($adj-1.0)*max(255,max($r,max($g,$b)));
  4918. return array(max(0,$r+$m), max(0,$g+$m), max(0,$b+$m),$alpha);
  4919. }
  4920. else {
  4921. return array($r,$g,$b,$alpha);
  4922. }
  4923. } elseif( is_array($aColor) ) {
  4924. if( count($aColor)==3 ) {
  4925. $aColor[3]=0;
  4926. return $aColor;
  4927. }
  4928. else
  4929. return $aColor;
  4930. }
  4931. else
  4932. JpGraphError::RaiseL(25079,$aColor,count($aColor));//(" Unknown color specification: $aColor , size=".count($aColor));
  4933. }
  4934. // Compare two colors
  4935. // return true if equal
  4936. function Equal($aCol1,$aCol2) {
  4937. $c1 = $this->Color($aCol1);
  4938. $c2 = $this->Color($aCol2);
  4939. if( $c1[0]==$c2[0] && $c1[1]==$c2[1] && $c1[2]==$c2[2] )
  4940. return true;
  4941. else
  4942. return false;
  4943. }
  4944. // Allocate a new color in the current image
  4945. // Return new color index, -1 if no more colors could be allocated
  4946. function Allocate($aColor,$aAlpha=0.0) {
  4947. list ($r, $g, $b, $a) = $this->color($aColor);
  4948. // If alpha is specified in the color string then this
  4949. // takes precedence over the second argument
  4950. if( $a > 0 )
  4951. $aAlpha = $a;
  4952. if( $aAlpha < 0 || $aAlpha > 1 ) {
  4953. JpGraphError::RaiseL(25080);//('Alpha parameter for color must be between 0.0 and 1.0');
  4954. }
  4955. return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127));
  4956. }
  4957. } // Class
  4958. //===================================================
  4959. // CLASS Legend
  4960. // Description: Responsible for drawing the box containing
  4961. // all the legend text for the graph
  4962. //===================================================
  4963. DEFINE('_DEFAULT_LPM_SIZE',8);
  4964. class Legend {
  4965. public $txtcol=array();
  4966. private $color=array(0,0,0); // Default fram color
  4967. private $fill_color=array(235,235,235); // Default fill color
  4968. private $shadow=true; // Shadow around legend "box"
  4969. private $shadow_color='darkgray@0.5';
  4970. private $mark_abs_hsize=_DEFAULT_LPM_SIZE,$mark_abs_vsize=_DEFAULT_LPM_SIZE;
  4971. private $xmargin=10,$ymargin=3,$shadow_width=2;
  4972. private $xlmargin=2, $ylmargin='';
  4973. private $xpos=0.05, $ypos=0.15, $xabspos=-1, $yabspos=-1;
  4974. private $halign="right", $valign="top";
  4975. private $font_family=FF_FONT1,$font_style=FS_NORMAL,$font_size=12;
  4976. private $font_color='black';
  4977. private $hide=false,$layout_n=1;
  4978. private $weight=1,$frameweight=1;
  4979. private $csimareas='';
  4980. private $reverse = false ;
  4981. //---------------
  4982. // CONSTRUCTOR
  4983. function Legend() {
  4984. // Empty
  4985. }
  4986. //---------------
  4987. // PUBLIC METHODS
  4988. function Hide($aHide=true) {
  4989. $this->hide=$aHide;
  4990. }
  4991. function SetHColMargin($aXMarg) {
  4992. $this->xmargin = $aXMarg;
  4993. }
  4994. function SetVColMargin($aSpacing) {
  4995. $this->ymargin = $aSpacing ;
  4996. }
  4997. function SetLeftMargin($aXMarg) {
  4998. $this->xlmargin = $aXMarg;
  4999. }
  5000. // Synonym
  5001. function SetLineSpacing($aSpacing) {
  5002. $this->ymargin = $aSpacing ;
  5003. }
  5004. function SetShadow($aShow='gray',$aWidth=2) {
  5005. if( is_string($aShow) ) {
  5006. $this->shadow_color = $aShow;
  5007. $this->shadow=true;
  5008. }
  5009. else
  5010. $this->shadow=$aShow;
  5011. $this->shadow_width=$aWidth;
  5012. }
  5013. function SetMarkAbsSize($aSize) {
  5014. $this->mark_abs_vsize = $aSize ;
  5015. $this->mark_abs_hsize = $aSize ;
  5016. }
  5017. function SetMarkAbsVSize($aSize) {
  5018. $this->mark_abs_vsize = $aSize ;
  5019. }
  5020. function SetMarkAbsHSize($aSize) {
  5021. $this->mark_abs_hsize = $aSize ;
  5022. }
  5023. function SetLineWeight($aWeight) {
  5024. $this->weight = $aWeight;
  5025. }
  5026. function SetFrameWeight($aWeight) {
  5027. $this->frameweight = $aWeight;
  5028. }
  5029. function SetLayout($aDirection=LEGEND_VERT) {
  5030. $this->layout_n = $aDirection==LEGEND_VERT ? 1 : 99 ;
  5031. }
  5032. function SetColumns($aCols) {
  5033. $this->layout_n = $aCols ;
  5034. }
  5035. function SetReverse($f=true) {
  5036. $this->reverse = $f ;
  5037. }
  5038. // Set color on frame around box
  5039. function SetColor($aFontColor,$aColor='black') {
  5040. $this->font_color=$aFontColor;
  5041. $this->color=$aColor;
  5042. }
  5043. function SetFont($aFamily,$aStyle=FS_NORMAL,$aSize=10) {
  5044. $this->font_family = $aFamily;
  5045. $this->font_style = $aStyle;
  5046. $this->font_size = $aSize;
  5047. }
  5048. function SetPos($aX,$aY,$aHAlign="right",$aVAlign="top") {
  5049. $this->Pos($aX,$aY,$aHAlign,$aVAlign);
  5050. }
  5051. function SetAbsPos($aX,$aY,$aHAlign="right",$aVAlign="top") {
  5052. $this->xabspos=$aX;
  5053. $this->yabspos=$aY;
  5054. $this->halign=$aHAlign;
  5055. $this->valign=$aVAlign;
  5056. }
  5057. function Pos($aX,$aY,$aHAlign="right",$aVAlign="top") {
  5058. if( !($aX<1 && $aY<1) )
  5059. JpGraphError::RaiseL(25120);//(" Position for legend must be given as percentage in range 0-1");
  5060. $this->xpos=$aX;
  5061. $this->ypos=$aY;
  5062. $this->halign=$aHAlign;
  5063. $this->valign=$aVAlign;
  5064. }
  5065. function SetFillColor($aColor) {
  5066. $this->fill_color=$aColor;
  5067. }
  5068. function Add($aTxt,$aColor,$aPlotmark='',$aLinestyle=0,$csimtarget='',$csimalt='',$csimwintarget='') {
  5069. $this->txtcol[]=array($aTxt,$aColor,$aPlotmark,$aLinestyle,$csimtarget,$csimalt,$csimwintarget);
  5070. }
  5071. function GetCSIMAreas() {
  5072. return $this->csimareas;
  5073. }
  5074. function Stroke(&$aImg) {
  5075. // Constant
  5076. $fillBoxFrameWeight=1;
  5077. if( $this->hide ) return;
  5078. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  5079. if( $this->reverse ) {
  5080. $this->txtcol = array_reverse($this->txtcol);
  5081. }
  5082. $n=count($this->txtcol);
  5083. if( $n == 0 ) return;
  5084. // Find out the max width and height of each column to be able
  5085. // to size the legend box.
  5086. $numcolumns = ($n > $this->layout_n ? $this->layout_n : $n);
  5087. for( $i=0; $i < $numcolumns; ++$i ) {
  5088. $colwidth[$i] = $aImg->GetTextWidth($this->txtcol[$i][0]) +
  5089. 2*$this->xmargin + 2*$this->mark_abs_hsize;
  5090. $colheight[$i] = 0;
  5091. }
  5092. // Find our maximum height in each row
  5093. $rows = 0 ; $rowheight[0] = 0;
  5094. for( $i=0; $i < $n; ++$i ) {
  5095. $h = max($this->mark_abs_vsize,$aImg->GetTextHeight($this->txtcol[$i][0]))+$this->ymargin;
  5096. if( $i % $numcolumns == 0 ) {
  5097. $rows++;
  5098. $rowheight[$rows-1] = 0;
  5099. }
  5100. $rowheight[$rows-1] = max($rowheight[$rows-1],$h);
  5101. }
  5102. $abs_height = 0;
  5103. for( $i=0; $i < $rows; ++$i ) {
  5104. $abs_height += $rowheight[$i] ;
  5105. }
  5106. // Make sure that the height is at least as high as mark size + ymargin
  5107. $abs_height = max($abs_height,$this->mark_abs_vsize);
  5108. // We add 3 extra pixels height to compensate for the difficult in
  5109. // calculating font height
  5110. $abs_height += $this->ymargin+3;
  5111. // Find out the maximum width in each column
  5112. for( $i=$numcolumns; $i < $n; ++$i ) {
  5113. $colwidth[$i % $numcolumns] = max(
  5114. $aImg->GetTextWidth($this->txtcol[$i][0])+2*$this->xmargin+2*$this->mark_abs_hsize,$colwidth[$i % $numcolumns]);
  5115. }
  5116. // Get the total width
  5117. $mtw = 0;
  5118. for( $i=0; $i < $numcolumns; ++$i ) {
  5119. $mtw += $colwidth[$i] ;
  5120. }
  5121. // Find out maximum width we need for legend box
  5122. $abs_width = $mtw+$this->xlmargin;
  5123. if( $this->xabspos === -1 && $this->yabspos === -1 ) {
  5124. $this->xabspos = $this->xpos*$aImg->width ;
  5125. $this->yabspos = $this->ypos*$aImg->height ;
  5126. }
  5127. // Positioning of the legend box
  5128. if( $this->halign == 'left' )
  5129. $xp = $this->xabspos;
  5130. elseif( $this->halign == 'center' )
  5131. $xp = $this->xabspos - $abs_width/2;
  5132. else
  5133. $xp = $aImg->width - $this->xabspos - $abs_width;
  5134. $yp=$this->yabspos;
  5135. if( $this->valign == 'center' )
  5136. $yp-=$abs_height/2;
  5137. elseif( $this->valign == 'bottom' )
  5138. $yp-=$abs_height;
  5139. // Stroke legend box
  5140. $aImg->SetColor($this->color);
  5141. $aImg->SetLineWeight($this->frameweight);
  5142. $aImg->SetLineStyle('solid');
  5143. if( $this->shadow )
  5144. $aImg->ShadowRectangle($xp,$yp,$xp+$abs_width+$this->shadow_width,
  5145. $yp+$abs_height+$this->shadow_width,
  5146. $this->fill_color,$this->shadow_width,$this->shadow_color);
  5147. else {
  5148. $aImg->SetColor($this->fill_color);
  5149. $aImg->FilledRectangle($xp,$yp,$xp+$abs_width,$yp+$abs_height);
  5150. $aImg->SetColor($this->color);
  5151. $aImg->Rectangle($xp,$yp,$xp+$abs_width,$yp+$abs_height);
  5152. }
  5153. // x1,y1 is the position for the legend mark
  5154. $x1=$xp+$this->mark_abs_hsize+$this->xlmargin;
  5155. $y1=$yp + $this->ymargin;
  5156. $f2 = round($aImg->GetTextHeight('X')/2);
  5157. $grad = new Gradient($aImg);
  5158. $patternFactory = null;
  5159. // Now stroke each legend in turn
  5160. // Each plot has added the following information to the legend
  5161. // p[0] = Legend text
  5162. // p[1] = Color,
  5163. // p[2] = For markers a reference to the PlotMark object
  5164. // p[3] = For lines the line style, for gradient the negative gradient style
  5165. // p[4] = CSIM target
  5166. // p[5] = CSIM Alt text
  5167. $i = 1 ; $row = 0;
  5168. foreach($this->txtcol as $p) {
  5169. // STROKE DEBUG BOX
  5170. if( _JPG_DEBUG ) {
  5171. $aImg->SetLineWeight(1);
  5172. $aImg->SetColor('red');
  5173. $aImg->SetLineStyle('solid');
  5174. $aImg->Rectangle($xp,$y1,$xp+$abs_width,$y1+$rowheight[$row]);
  5175. }
  5176. $aImg->SetLineWeight($this->weight);
  5177. $x1 = round($x1); $y1=round($y1);
  5178. if ( !empty($p[2]) && $p[2]->GetType() > -1 ) {
  5179. // Make a plot mark legend
  5180. $aImg->SetColor($p[1]);
  5181. if( is_string($p[3]) || $p[3]>0 ) {
  5182. $aImg->SetLineStyle($p[3]);
  5183. $aImg->StyleLine($x1-$this->mark_abs_hsize,$y1+$f2,$x1+$this->mark_abs_hsize,$y1+$f2);
  5184. }
  5185. // Stroke a mark with the standard size
  5186. // (As long as it is not an image mark )
  5187. if( $p[2]->GetType() != MARK_IMG ) {
  5188. // Clear any user callbacks since we ont want them called for
  5189. // the legend marks
  5190. $p[2]->iFormatCallback = '';
  5191. $p[2]->iFormatCallback2 = '';
  5192. // Since size for circles is specified as the radius
  5193. // this means that we must half the size to make the total
  5194. // width behave as the other marks
  5195. if( $p[2]->GetType() == MARK_FILLEDCIRCLE || $p[2]->GetType() == MARK_CIRCLE ) {
  5196. $p[2]->SetSize(min($this->mark_abs_vsize,$this->mark_abs_hsize)/2);
  5197. $p[2]->Stroke($aImg,$x1,$y1+$f2);
  5198. }
  5199. else {
  5200. $p[2]->SetSize(min($this->mark_abs_vsize,$this->mark_abs_hsize));
  5201. $p[2]->Stroke($aImg,$x1,$y1+$f2);
  5202. }
  5203. }
  5204. }
  5205. elseif ( !empty($p[2]) && (is_string($p[3]) || $p[3]>0 ) ) {
  5206. // Draw a styled line
  5207. $aImg->SetColor($p[1]);
  5208. $aImg->SetLineStyle($p[3]);
  5209. $aImg->StyleLine($x1-1,$y1+$f2,$x1+$this->mark_abs_hsize,$y1+$f2);
  5210. $aImg->StyleLine($x1-1,$y1+$f2+1,$x1+$this->mark_abs_hsize,$y1+$f2+1);
  5211. }
  5212. else {
  5213. // Draw a colored box
  5214. $color = $p[1] ;
  5215. // We make boxes slightly larger to better show
  5216. $boxsize = min($this->mark_abs_vsize,$this->mark_abs_hsize) + 2 ;
  5217. $ym = round($y1 + $f2 - $boxsize/2);
  5218. // We either need to plot a gradient or a
  5219. // pattern. To differentiate we use a kludge.
  5220. // Patterns have a p[3] value of < -100
  5221. if( $p[3] < -100 ) {
  5222. // p[1][0] == iPattern, p[1][1] == iPatternColor, p[1][2] == iPatternDensity
  5223. if( $patternFactory == null ) {
  5224. $patternFactory = new RectPatternFactory();
  5225. }
  5226. $prect = $patternFactory->Create($p[1][0],$p[1][1],1);
  5227. $prect->SetBackground($p[1][3]);
  5228. $prect->SetDensity($p[1][2]+1);
  5229. $prect->SetPos(new Rectangle($x1,$ym,$boxsize,$boxsize));
  5230. $prect->Stroke($aImg);
  5231. $prect=null;
  5232. }
  5233. else {
  5234. if( is_array($color) && count($color)==2 ) {
  5235. // The client want a gradient color
  5236. $grad->FilledRectangle($x1,$ym,
  5237. $x1+$boxsize,$ym+$boxsize,
  5238. $color[0],$color[1],-$p[3]);
  5239. }
  5240. else {
  5241. $aImg->SetColor($p[1]);
  5242. $aImg->FilledRectangle($x1,$ym,$x1+$boxsize,$ym+$boxsize);
  5243. }
  5244. $aImg->SetColor($this->color);
  5245. $aImg->SetLineWeight($fillBoxFrameWeight);
  5246. $aImg->Rectangle($x1,$ym,$x1+$boxsize,$ym+$boxsize);
  5247. }
  5248. }
  5249. $aImg->SetColor($this->font_color);
  5250. $aImg->SetFont($this->font_family,$this->font_style,$this->font_size);
  5251. $aImg->SetTextAlign("left","top");
  5252. $aImg->StrokeText(round($x1+$this->mark_abs_hsize+$this->xmargin),$y1,$p[0]);
  5253. // Add CSIM for Legend if defined
  5254. if( !empty($p[4]) ) {
  5255. $xe = $x1 + $this->xmargin+$this->mark_abs_hsize+$aImg->GetTextWidth($p[0]);
  5256. $ye = $y1 + max($this->mark_abs_vsize,$aImg->GetTextHeight($p[0]));
  5257. $coords = "$x1,$y1,$xe,$y1,$xe,$ye,$x1,$ye";
  5258. if( ! empty($p[4]) ) {
  5259. $this->csimareas .= "<area shape=\"poly\" coords=\"$coords\" href=\"".htmlentities($p[4])."\"";
  5260. if( !empty($p[6]) ) {
  5261. $this->csimareas .= " target=\"".$p[6]."\"";
  5262. }
  5263. if( !empty($p[5]) ) {
  5264. $tmp=sprintf($p[5],$p[0]);
  5265. $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" ";
  5266. }
  5267. $this->csimareas .= " />\n";
  5268. }
  5269. }
  5270. if( $i >= $this->layout_n ) {
  5271. $x1 = $xp+$this->mark_abs_hsize+$this->xlmargin;
  5272. $y1 += $rowheight[$row++];
  5273. $i = 1;
  5274. }
  5275. else {
  5276. $x1 += $colwidth[($i-1) % $numcolumns] ;
  5277. ++$i;
  5278. }
  5279. }
  5280. }
  5281. } // Class
  5282. //===================================================
  5283. // CLASS DisplayValue
  5284. // Description: Used to print data values at data points
  5285. //===================================================
  5286. class DisplayValue {
  5287. public $margin=5;
  5288. public $show=false;
  5289. public $valign="",$halign="center";
  5290. public $format="%.1f",$negformat="";
  5291. private $ff=FF_FONT1,$fs=FS_NORMAL,$fsize=10;
  5292. private $iFormCallback='';
  5293. private $angle=0;
  5294. private $color="navy",$negcolor="";
  5295. private $iHideZero=false;
  5296. function Show($aFlag=true) {
  5297. $this->show=$aFlag;
  5298. }
  5299. function SetColor($aColor,$aNegcolor="") {
  5300. $this->color = $aColor;
  5301. $this->negcolor = $aNegcolor;
  5302. }
  5303. function SetFont($aFontFamily,$aFontStyle=FS_NORMAL,$aFontSize=10) {
  5304. $this->ff=$aFontFamily;
  5305. $this->fs=$aFontStyle;
  5306. $this->fsize=$aFontSize;
  5307. }
  5308. function ApplyFont($aImg) {
  5309. $aImg->SetFont($this->ff,$this->fs,$this->fsize);
  5310. }
  5311. function SetMargin($aMargin) {
  5312. $this->margin = $aMargin;
  5313. }
  5314. function SetAngle($aAngle) {
  5315. $this->angle = $aAngle;
  5316. }
  5317. function SetAlign($aHAlign,$aVAlign='') {
  5318. $this->halign = $aHAlign;
  5319. $this->valign = $aVAlign;
  5320. }
  5321. function SetFormat($aFormat,$aNegFormat="") {
  5322. $this->format= $aFormat;
  5323. $this->negformat= $aNegFormat;
  5324. }
  5325. function SetFormatCallback($aFunc) {
  5326. $this->iFormCallback = $aFunc;
  5327. }
  5328. function HideZero($aFlag=true) {
  5329. $this->iHideZero=$aFlag;
  5330. }
  5331. function Stroke($img,$aVal,$x,$y) {
  5332. if( $this->show )
  5333. {
  5334. if( $this->negformat=="" ) $this->negformat=$this->format;
  5335. if( $this->negcolor=="" ) $this->negcolor=$this->color;
  5336. if( $aVal===NULL || (is_string($aVal) && ($aVal=="" || $aVal=="-" || $aVal=="x" ) ) )
  5337. return;
  5338. if( is_numeric($aVal) && $aVal==0 && $this->iHideZero ) {
  5339. return;
  5340. }
  5341. // Since the value is used in different cirumstances we need to check what
  5342. // kind of formatting we shall use. For example, to display values in a line
  5343. // graph we simply display the formatted value, but in the case where the user
  5344. // has already specified a text string we don't fo anything.
  5345. if( $this->iFormCallback != '' ) {
  5346. $f = $this->iFormCallback;
  5347. $sval = call_user_func($f,$aVal);
  5348. }
  5349. elseif( is_numeric($aVal) ) {
  5350. if( $aVal >= 0 )
  5351. $sval=sprintf($this->format,$aVal);
  5352. else
  5353. $sval=sprintf($this->negformat,$aVal);
  5354. }
  5355. else
  5356. $sval=$aVal;
  5357. $y = $y-sign($aVal)*$this->margin;
  5358. $txt = new Text($sval,$x,$y);
  5359. $txt->SetFont($this->ff,$this->fs,$this->fsize);
  5360. if( $this->valign == "" ) {
  5361. if( $aVal >= 0 )
  5362. $valign = "bottom";
  5363. else
  5364. $valign = "top";
  5365. }
  5366. else
  5367. $valign = $this->valign;
  5368. $txt->Align($this->halign,$valign);
  5369. $txt->SetOrientation($this->angle);
  5370. if( $aVal > 0 )
  5371. $txt->SetColor($this->color);
  5372. else
  5373. $txt->SetColor($this->negcolor);
  5374. $txt->Stroke($img);
  5375. }
  5376. }
  5377. }
  5378. //===================================================
  5379. // CLASS Plot
  5380. // Description: Abstract base class for all concrete plot classes
  5381. //===================================================
  5382. class Plot {
  5383. public $numpoints=0;
  5384. public $value;
  5385. public $legend='';
  5386. public $coords=array();
  5387. public $color="black";
  5388. public $hidelegend=false;
  5389. public $line_weight=1;
  5390. public $csimtargets=array(),$csimwintargets=array(); // Array of targets for CSIM
  5391. public $csimareas=""; // Resultant CSIM area tags
  5392. public $csimalts=null; // ALT:s for corresponding target
  5393. public $legendcsimtarget='',$legendcsimwintarget='';
  5394. public $legendcsimalt='';
  5395. protected $weight=1;
  5396. protected $center=false;
  5397. //---------------
  5398. // CONSTRUCTOR
  5399. function Plot($aDatay,$aDatax=false) {
  5400. $this->numpoints = count($aDatay);
  5401. if( $this->numpoints==0 )
  5402. JpGraphError::RaiseL(25121);//("Empty input data array specified for plot. Must have at least one data point.");
  5403. $this->coords[0]=$aDatay;
  5404. if( is_array($aDatax) ) {
  5405. $this->coords[1]=$aDatax;
  5406. $n = count($aDatax);
  5407. for($i=0; $i < $n; ++$i ) {
  5408. if( !is_numeric($aDatax[$i]) ) {
  5409. JpGraphError::RaiseL(25070);
  5410. }
  5411. }
  5412. }
  5413. $this->value = new DisplayValue();
  5414. }
  5415. //---------------
  5416. // PUBLIC METHODS
  5417. // Stroke the plot
  5418. // "virtual" function which must be implemented by
  5419. // the subclasses
  5420. function Stroke($aImg,$aXScale,$aYScale) {
  5421. JpGraphError::RaiseL(25122);//("JpGraph: Stroke() must be implemented by concrete subclass to class Plot");
  5422. }
  5423. function HideLegend($f=true) {
  5424. $this->hidelegend = $f;
  5425. }
  5426. function DoLegend($graph) {
  5427. if( !$this->hidelegend )
  5428. $this->Legend($graph);
  5429. }
  5430. function StrokeDataValue($img,$aVal,$x,$y) {
  5431. $this->value->Stroke($img,$aVal,$x,$y);
  5432. }
  5433. // Set href targets for CSIM
  5434. function SetCSIMTargets($aTargets,$aAlts='',$aWinTargets='') {
  5435. $this->csimtargets=$aTargets;
  5436. $this->csimwintargets=$aWinTargets;
  5437. $this->csimalts=$aAlts;
  5438. }
  5439. // Get all created areas
  5440. function GetCSIMareas() {
  5441. return $this->csimareas;
  5442. }
  5443. // "Virtual" function which gets called before any scale
  5444. // or axis are stroked used to do any plot specific adjustment
  5445. function PreStrokeAdjust($aGraph) {
  5446. if( substr($aGraph->axtype,0,4) == "text" && (isset($this->coords[1])) )
  5447. JpGraphError::RaiseL(25123);//("JpGraph: You can't use a text X-scale with specified X-coords. Use a \"int\" or \"lin\" scale instead.");
  5448. return true;
  5449. }
  5450. // Get minimum values in plot
  5451. function Min() {
  5452. if( isset($this->coords[1]) )
  5453. $x=$this->coords[1];
  5454. else
  5455. $x="";
  5456. if( $x != "" && count($x) > 0 ) {
  5457. $xm=min($x);
  5458. }
  5459. else
  5460. $xm=0;
  5461. $y=$this->coords[0];
  5462. $cnt = count($y);
  5463. if( $cnt > 0 ) {
  5464. /*
  5465. if( ! isset($y[0]) ) {
  5466. JpGraphError('The input data array must have consecutive values from position 0 and forward. The given y-array starts with empty values (NULL)');
  5467. }
  5468. $ym = $y[0];
  5469. */
  5470. $i=0;
  5471. while( $i<$cnt && !is_numeric($ym=$y[$i]) )
  5472. $i++;
  5473. while( $i < $cnt) {
  5474. if( is_numeric($y[$i]) )
  5475. $ym=min($ym,$y[$i]);
  5476. ++$i;
  5477. }
  5478. }
  5479. else
  5480. $ym="";
  5481. return array($xm,$ym);
  5482. }
  5483. // Get maximum value in plot
  5484. function Max() {
  5485. if( isset($this->coords[1]) )
  5486. $x=$this->coords[1];
  5487. else
  5488. $x="";
  5489. if( $x!="" && count($x) > 0 )
  5490. $xm=max($x);
  5491. else {
  5492. $xm = $this->numpoints-1;
  5493. }
  5494. $y=$this->coords[0];
  5495. if( count($y) > 0 ) {
  5496. /*
  5497. if( !isset($y[0]) ) {
  5498. JpGraphError::Raise('The input data array must have consecutive values from position 0 and forward. The given y-array starts with empty values (NULL)');
  5499. // $y[0] = 0;
  5500. // Change in 1.5.1 Don't treat this as an error any more. Just silently convert to 0
  5501. // Change in 1.17 Treat his as an error again !! This is the right way to do !!
  5502. }
  5503. */
  5504. $cnt = count($y);
  5505. $i=0;
  5506. while( $i<$cnt && !is_numeric($ym=$y[$i]) )
  5507. $i++;
  5508. while( $i < $cnt ) {
  5509. if( is_numeric($y[$i]) )
  5510. $ym=max($ym,$y[$i]);
  5511. ++$i;
  5512. }
  5513. }
  5514. else
  5515. $ym="";
  5516. return array($xm,$ym);
  5517. }
  5518. function SetColor($aColor) {
  5519. $this->color=$aColor;
  5520. }
  5521. function SetLegend($aLegend,$aCSIM='',$aCSIMAlt='',$aCSIMWinTarget='') {
  5522. $this->legend = $aLegend;
  5523. $this->legendcsimtarget = $aCSIM;
  5524. $this->legendcsimwintarget = $aCSIMWinTarget;
  5525. $this->legendcsimalt = $aCSIMAlt;
  5526. }
  5527. function SetWeight($aWeight) {
  5528. $this->weight=$aWeight;
  5529. }
  5530. function SetLineWeight($aWeight=1) {
  5531. $this->line_weight=$aWeight;
  5532. }
  5533. function SetCenter($aCenter=true) {
  5534. $this->center = $aCenter;
  5535. }
  5536. // This method gets called by Graph class to plot anything that should go
  5537. // into the margin after the margin color has been set.
  5538. function StrokeMargin($aImg) {
  5539. return true;
  5540. }
  5541. // Framework function the chance for each plot class to set a legend
  5542. function Legend($aGraph) {
  5543. if( $this->legend != "" )
  5544. $aGraph->legend->Add($this->legend,$this->color,"",0,$this->legendcsimtarget,
  5545. $this->legendcsimalt,$this->legendcsimwintarget);
  5546. }
  5547. } // Class
  5548. //===================================================
  5549. // CLASS PlotLine
  5550. // Description:
  5551. // Data container class to hold properties for a static
  5552. // line that is drawn directly in the plot area.
  5553. // Usefull to add static borders inside a plot to show
  5554. // for example set-values
  5555. //===================================================
  5556. class PlotLine {
  5557. public $scaleposition, $direction=-1;
  5558. protected $weight=1;
  5559. protected $color="black";
  5560. private $legend='',$hidelegend=false, $legendcsimtarget='', $legendcsimalt='',$legendcsimwintarget='';
  5561. private $iLineStyle='solid';
  5562. //---------------
  5563. // CONSTRUCTOR
  5564. function PlotLine($aDir=HORIZONTAL,$aPos=0,$aColor="black",$aWeight=1) {
  5565. $this->direction = $aDir;
  5566. $this->color=$aColor;
  5567. $this->weight=$aWeight;
  5568. $this->scaleposition=$aPos;
  5569. }
  5570. //---------------
  5571. // PUBLIC METHODS
  5572. function SetLegend($aLegend,$aCSIM='',$aCSIMAlt='',$aCSIMWinTarget='') {
  5573. $this->legend = $aLegend;
  5574. $this->legendcsimtarget = $aCSIM;
  5575. $this->legendcsimwintarget = $aCSIMWinTarget;
  5576. $this->legendcsimalt = $aCSIMAlt;
  5577. }
  5578. function HideLegend($f=true) {
  5579. $this->hidelegend = $f;
  5580. }
  5581. function SetPosition($aScalePosition) {
  5582. $this->scaleposition=$aScalePosition;
  5583. }
  5584. function SetDirection($aDir) {
  5585. $this->direction = $aDir;
  5586. }
  5587. function SetColor($aColor) {
  5588. $this->color=$aColor;
  5589. }
  5590. function SetWeight($aWeight) {
  5591. $this->weight=$aWeight;
  5592. }
  5593. function SetLineStyle($aStyle) {
  5594. $this->iLineStyle = $aStyle;
  5595. }
  5596. //---------------
  5597. // PRIVATE METHODS
  5598. function DoLegend(&$graph) {
  5599. if( !$this->hidelegend )
  5600. $this->Legend($graph);
  5601. }
  5602. // Framework function the chance for each plot class to set a legend
  5603. function Legend(&$aGraph) {
  5604. if( $this->legend != "" ) {
  5605. $dummyPlotMark = new PlotMark();
  5606. $lineStyle = 1;
  5607. $aGraph->legend->Add($this->legend,$this->color,$dummyPlotMark,$lineStyle,
  5608. $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget);
  5609. }
  5610. }
  5611. function PreStrokeAdjust($aGraph) {
  5612. // Nothing to do
  5613. }
  5614. function Stroke($aImg,$aXScale,$aYScale) {
  5615. $aImg->SetColor($this->color);
  5616. $aImg->SetLineWeight($this->weight);
  5617. $oldStyle = $aImg->SetLineStyle($this->iLineStyle);
  5618. if( $this->direction == VERTICAL ) {
  5619. $ymin_abs=$aYScale->Translate($aYScale->GetMinVal());
  5620. $ymax_abs=$aYScale->Translate($aYScale->GetMaxVal());
  5621. $xpos_abs=$aXScale->Translate($this->scaleposition);
  5622. $aImg->StyleLine($xpos_abs, $ymin_abs, $xpos_abs, $ymax_abs);
  5623. }
  5624. elseif( $this->direction == HORIZONTAL ) {
  5625. $xmin_abs=$aXScale->Translate($aXScale->GetMinVal());
  5626. $xmax_abs=$aXScale->Translate($aXScale->GetMaxVal());
  5627. $ypos_abs=$aYScale->Translate($this->scaleposition);
  5628. $aImg->StyleLine($xmin_abs, $ypos_abs, $xmax_abs, $ypos_abs);
  5629. }
  5630. else {
  5631. JpGraphError::RaiseL(25125);//(" Illegal direction for static line");
  5632. }
  5633. $aImg->SetLineStyle($oldStyle);
  5634. }
  5635. }
  5636. // <EOF>
  5637. ?>