PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 1ms

/graph/jpgraph.php

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