PageRenderTime 66ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/code/web/public_php/admin/jpgraph/jpgraph_pie.php

https://bitbucket.org/0xcc/ryzomcore
PHP | 1341 lines | 941 code | 196 blank | 204 comment | 245 complexity | d50e3e4870c07a44acb73a922d948998 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. /*=======================================================================
  3. // File: JPGRAPH_PIE.PHP
  4. // Description: Pie plot extension for JpGraph
  5. // Created: 2001-02-14
  6. // Author: Johan Persson (johanp@aditus.nu)
  7. // Ver: $Id: jpgraph_pie.php,v 1.1 2006/07/07 13:37:14 powles Exp $
  8. //
  9. // Copyright (c) Aditus Consulting. All rights reserved.
  10. //========================================================================
  11. */
  12. // Defines for PiePlot::SetLabelType()
  13. DEFINE("PIE_VALUE_ABS",1);
  14. DEFINE("PIE_VALUE_PER",0);
  15. DEFINE("PIE_VALUE_PERCENTAGE",0);
  16. DEFINE("PIE_VALUE_ADJPERCENTAGE",2);
  17. DEFINE("PIE_VALUE_ADJPER",2);
  18. //===================================================
  19. // CLASS PiePlot
  20. // Description: Draws a pie plot
  21. //===================================================
  22. class PiePlot {
  23. var $posx=0.5,$posy=0.5;
  24. var $radius=0.3;
  25. var $explode_radius=array(),$explode_all=false,$explode_r=20;
  26. var $labels=null, $legends=null;
  27. var $csimtargets=null; // Array of targets for CSIM
  28. var $csimareas=''; // Generated CSIM text
  29. var $csimalts=null; // ALT tags for corresponding target
  30. var $data=null;
  31. var $title;
  32. var $startangle=0;
  33. var $weight=1, $color="black";
  34. var $legend_margin=6,$show_labels=true;
  35. var $themearr = array(
  36. "earth" => array(136,34,40,45,46,62,63,134,74,10,120,136,141,168,180,77,209,218,346,395,89,430),
  37. "pastel" => array(27,415,128,59,66,79,105,110,42,147,152,230,236,240,331,337,405,38),
  38. "water" => array(8,370,24,40,335,56,213,237,268,14,326,387,10,388),
  39. "sand" => array(27,168,34,170,19,50,65,72,131,209,46,393));
  40. var $theme="earth";
  41. var $setslicecolors=array();
  42. var $labeltype=0; // Default to percentage
  43. var $pie_border=true,$pie_interior_border=true;
  44. var $value;
  45. var $ishadowcolor='',$ishadowdrop=4;
  46. var $ilabelposadj=1;
  47. var $legendcsimtargets = array();
  48. var $legendcsimalts = array();
  49. var $adjusted_data = array();
  50. var $guideline = null,$guidelinemargin=10;
  51. var $iShowGuideLineForSingle = false;
  52. var $iGuideLineCurve = false,$iGuideVFactor=1.4,$iGuideLineRFactor=0.8;
  53. //---------------
  54. // CONSTRUCTOR
  55. function PiePlot($data) {
  56. $this->data = array_reverse($data);
  57. $this->title = new Text("");
  58. $this->title->SetFont(FF_FONT1,FS_BOLD);
  59. $this->value = new DisplayValue();
  60. $this->value->Show();
  61. $this->value->SetFormat('%.1f%%');
  62. $this->guideline = new LineProperty();
  63. }
  64. //---------------
  65. // PUBLIC METHODS
  66. function SetCenter($x,$y=0.5) {
  67. $this->posx = $x;
  68. $this->posy = $y;
  69. }
  70. // Enable guideline and set drwaing policy
  71. function SetGuideLines($aFlg=true,$aCurved=true,$aAlways=false) {
  72. $this->guideline->Show($aFlg);
  73. $this->iShowGuideLineForSingle = $aAlways;
  74. $this->iGuideLineCurve = $aCurved;
  75. }
  76. // Adjuste the distance between labels and labels and pie
  77. function SetGuideLinesAdjust($aVFactor,$aRFactor=0.8) {
  78. $this->iGuideVFactor=$aVFactor;
  79. $this->iGuideLineRFactor=$aRFactor;
  80. }
  81. function SetColor($aColor) {
  82. $this->color = $aColor;
  83. }
  84. function SetSliceColors($aColors) {
  85. $this->setslicecolors = $aColors;
  86. }
  87. function SetShadow($aColor='darkgray',$aDropWidth=4) {
  88. $this->ishadowcolor = $aColor;
  89. $this->ishadowdrop = $aDropWidth;
  90. }
  91. function SetCSIMTargets($targets,$alts=null) {
  92. $this->csimtargets=array_reverse($targets);
  93. if( is_array($alts) )
  94. $this->csimalts=array_reverse($alts);
  95. }
  96. function GetCSIMareas() {
  97. return $this->csimareas;
  98. }
  99. function AddSliceToCSIM($i,$xc,$yc,$radius,$sa,$ea) {
  100. //Slice number, ellipse centre (x,y), height, width, start angle, end angle
  101. while( $sa > 2*M_PI ) $sa = $sa - 2*M_PI;
  102. while( $ea > 2*M_PI ) $ea = $ea - 2*M_PI;
  103. $sa = 2*M_PI - $sa;
  104. $ea = 2*M_PI - $ea;
  105. // Special case when we have only one slice since then both start and end
  106. // angle will be == 0
  107. if( abs($sa - $ea) < 0.0001 ) {
  108. $sa=2*M_PI; $ea=0;
  109. }
  110. //add coordinates of the centre to the map
  111. $xc = floor($xc);$yc=floor($yc);
  112. $coords = "$xc, $yc";
  113. //add coordinates of the first point on the arc to the map
  114. $xp = floor(($radius*cos($ea))+$xc);
  115. $yp = floor($yc-$radius*sin($ea));
  116. $coords.= ", $xp, $yp";
  117. //add coordinates every 0.2 radians
  118. $a=$ea+0.2;
  119. // If we cross the 260-limit with a slice we need to handle
  120. // the fact that end angle is smaller than start
  121. if( $sa < $ea ) {
  122. while ($a <= 2*M_PI) {
  123. $xp = floor($radius*cos($a)+$xc);
  124. $yp = floor($yc-$radius*sin($a));
  125. $coords.= ", $xp, $yp";
  126. $a += 0.2;
  127. }
  128. $a -= 2*M_PI;
  129. }
  130. while ($a < $sa) {
  131. $xp = floor($radius*cos($a)+$xc);
  132. $yp = floor($yc-$radius*sin($a));
  133. $coords.= ", $xp, $yp";
  134. $a += 0.2;
  135. }
  136. //Add the last point on the arc
  137. $xp = floor($radius*cos($sa)+$xc);
  138. $yp = floor($yc-$radius*sin($sa));
  139. $coords.= ", $xp, $yp";
  140. if( !empty($this->csimtargets[$i]) ) {
  141. $this->csimareas .= "<area shape=\"poly\" coords=\"$coords\" href=\"".$this->csimtargets[$i]."\"";
  142. $tmp="";
  143. if( !empty($this->csimalts[$i]) ) {
  144. $tmp=sprintf($this->csimalts[$i],$this->data[$i]);
  145. $this->csimareas .= " title=\"$tmp\"";
  146. }
  147. $this->csimareas .= " alt=\"$tmp\" />\n";
  148. }
  149. }
  150. function SetTheme($aTheme) {
  151. if( in_array($aTheme,array_keys($this->themearr)) )
  152. $this->theme = $aTheme;
  153. else
  154. JpGraphError::RaiseL(15001,$aTheme);//("PiePLot::SetTheme() Unknown theme: $aTheme");
  155. }
  156. function ExplodeSlice($e,$radius=20) {
  157. if( ! is_integer($e) )
  158. JpGraphError::RaiseL(15002);//('Argument to PiePlot::ExplodeSlice() must be an integer');
  159. $this->explode_radius[$e]=$radius;
  160. }
  161. function ExplodeAll($radius=20) {
  162. $this->explode_all=true;
  163. $this->explode_r = $radius;
  164. }
  165. function Explode($aExplodeArr) {
  166. if( !is_array($aExplodeArr) ) {
  167. JpGraphError::RaiseL(15003);
  168. //("Argument to PiePlot::Explode() must be an array with integer distances.");
  169. }
  170. $this->explode_radius = $aExplodeArr;
  171. }
  172. function SetStartAngle($aStart) {
  173. if( $aStart < 0 || $aStart > 360 ) {
  174. JpGraphError::RaiseL(15004);//('Slice start angle must be between 0 and 360 degrees.');
  175. }
  176. $this->startangle = 360-$aStart;
  177. $this->startangle *= M_PI/180;
  178. }
  179. function SetFont($family,$style=FS_NORMAL,$size=10) {
  180. JpGraphError::RaiseL(15005);//('PiePlot::SetFont() is deprecated. Use PiePlot->value->SetFont() instead.');
  181. }
  182. // Size in percentage
  183. function SetSize($aSize) {
  184. if( ($aSize>0 && $aSize<=0.5) || ($aSize>10 && $aSize<1000) )
  185. $this->radius = $aSize;
  186. else
  187. JpGraphError::RaiseL(15006);
  188. //("PiePlot::SetSize() Radius for pie must either be specified as a fraction [0, 0.5] of the size of the image or as an absolute size in pixels in the range [10, 1000]");
  189. }
  190. function SetFontColor($aColor) {
  191. JpGraphError::RaiseL(15007);
  192. //('PiePlot::SetFontColor() is deprecated. Use PiePlot->value->SetColor() instead.');
  193. }
  194. // Set label arrays
  195. function SetLegends($aLegend) {
  196. $this->legends = $aLegend;
  197. }
  198. // Set text labels for slices
  199. function SetLabels($aLabels,$aLblPosAdj="auto") {
  200. $this->labels = array_reverse($aLabels);
  201. $this->ilabelposadj=$aLblPosAdj;
  202. }
  203. function SetLabelPos($aLblPosAdj) {
  204. $this->ilabelposadj=$aLblPosAdj;
  205. }
  206. // Should we display actual value or percentage?
  207. function SetLabelType($t) {
  208. if( $t < 0 || $t > 2 )
  209. JpGraphError::RaiseL(15008,$t);
  210. //("PiePlot::SetLabelType() Type for pie plots must be 0 or 1 (not $t).");
  211. $this->labeltype=$t;
  212. }
  213. // Deprecated.
  214. function SetValueType($aType) {
  215. $this->SetLabelType($aType);
  216. }
  217. // Should the circle around a pie plot be displayed
  218. function ShowBorder($exterior=true,$interior=true) {
  219. $this->pie_border = $exterior;
  220. $this->pie_interior_border = $interior;
  221. }
  222. // Setup the legends (Framework method)
  223. function Legend(&$graph) {
  224. $colors = array_keys($graph->img->rgb->rgb_table);
  225. sort($colors);
  226. $ta=$this->themearr[$this->theme];
  227. $n = count($this->data);
  228. if( $this->setslicecolors==null ) {
  229. $numcolors=count($ta);
  230. if( is_a($this,'PiePlot3D') ) {
  231. $ta = array_reverse(array_slice($ta,0,$n));
  232. }
  233. }
  234. else {
  235. $this->setslicecolors = array_slice($this->setslicecolors,0,$n);
  236. $numcolors=count($this->setslicecolors);
  237. if( $graph->pieaa && is_a($this,'PiePlot') ) {
  238. $this->setslicecolors = array_reverse($this->setslicecolors);
  239. }
  240. }
  241. $sum=0;
  242. for($i=0; $i < $n; ++$i)
  243. $sum += $this->data[$i];
  244. // Bail out with error if the sum is 0
  245. if( $sum==0 )
  246. JpGraphError::RaiseL(15009);//("Illegal pie plot. Sum of all data is zero for Pie!");
  247. // Make sure we don't plot more values than data points
  248. // (in case the user added more legends than data points)
  249. $n = min(count($this->legends),count($this->data));
  250. if( $this->legends != "" ) {
  251. $this->legends = array_reverse(array_slice($this->legends,0,$n));
  252. }
  253. for( $i=$n-1; $i >= 0; --$i ) {
  254. $l = $this->legends[$i];
  255. // Replace possible format with actual values
  256. if( count($this->csimalts) > $i ) {
  257. $fmt = $this->csimalts[$i];
  258. }
  259. else {
  260. $fmt = "%d"; // Deafult Alt if no other has been specified
  261. }
  262. if( $this->labeltype==0 ) {
  263. $l = sprintf($l,100*$this->data[$i]/$sum);
  264. $alt = sprintf($fmt,$this->data[$i]);
  265. }
  266. elseif( $this->labeltype == 1) {
  267. $l = sprintf($l,$this->data[$i]);
  268. $alt = sprintf($fmt,$this->data[$i]);
  269. }
  270. else {
  271. $l = sprintf($l,$this->adjusted_data[$i]);
  272. $alt = sprintf($fmt,$this->adjusted_data[$i]);
  273. }
  274. if( $this->setslicecolors==null ) {
  275. $graph->legend->Add($l,$colors[$ta[$i%$numcolors]],"",0,$this->csimtargets[$i],$alt);
  276. }
  277. else {
  278. $graph->legend->Add($l,$this->setslicecolors[$i%$numcolors],"",0,$this->csimtargets[$i],$alt);
  279. }
  280. }
  281. }
  282. // Adjust the rounded percetage value so that the sum of
  283. // of the pie slices are always 100%
  284. // Using the Hare/Niemeyer method
  285. function AdjPercentage($aData,$aPrec=0) {
  286. $mul=100;
  287. if( $aPrec > 0 && $aPrec < 3 ) {
  288. if( $aPrec == 1 )
  289. $mul=1000;
  290. else
  291. $mul=10000;
  292. }
  293. $tmp = array();
  294. $result = array();
  295. $quote_sum=0;
  296. $n = count($aData) ;
  297. for( $i=0, $sum=0; $i < $n; ++$i )
  298. $sum+=$aData[$i];
  299. foreach($aData as $index => $value) {
  300. $tmp_percentage=$value/$sum*$mul;
  301. $result[$index]=floor($tmp_percentage);
  302. $tmp[$index]=$tmp_percentage-$result[$index];
  303. $quote_sum+=$result[$index];
  304. }
  305. if( $quote_sum == $mul) {
  306. if( $mul > 100 ) {
  307. $tmp = $mul / 100;
  308. for( $i=0; $i < $n; ++$i ) {
  309. $result[$i] /= $tmp ;
  310. }
  311. }
  312. return $result;
  313. }
  314. arsort($tmp,SORT_NUMERIC);
  315. reset($tmp);
  316. for($i=0; $i < $mul-$quote_sum; $i++)
  317. {
  318. $result[key($tmp)]++;
  319. next($tmp);
  320. }
  321. if( $mul > 100 ) {
  322. $tmp = $mul / 100;
  323. for( $i=0; $i < $n; ++$i ) {
  324. $result[$i] /= $tmp ;
  325. }
  326. }
  327. return $result;
  328. }
  329. function Stroke(&$img,$aaoption=0) {
  330. // aaoption is used to handle antialias
  331. // aaoption == 0 a normal pie
  332. // aaoption == 1 just the body
  333. // aaoption == 2 just the values
  334. // Explode scaling. If anti anti alias we scale the image
  335. // twice and we also need to scale the exploding distance
  336. $expscale = $aaoption === 1 ? 2 : 1;
  337. if( $this->labeltype == 2 ) {
  338. // Adjust the data so that it will add up to 100%
  339. $this->adjusted_data = $this->AdjPercentage($this->data);
  340. }
  341. $colors = array_keys($img->rgb->rgb_table);
  342. sort($colors);
  343. $ta=$this->themearr[$this->theme];
  344. $n = count($this->data);
  345. if( $this->setslicecolors==null ) {
  346. $numcolors=count($ta);
  347. }
  348. else {
  349. $this->setslicecolors = array_reverse(array_slice($this->setslicecolors,0,$n));
  350. $numcolors=count($this->setslicecolors);
  351. $tt = array_slice($this->setslicecolors,$n % $numcolors);
  352. $tt2 = array_slice($this->setslicecolors,0,$n % $numcolors);
  353. $tt2 = array_merge($tt, $tt2);
  354. $this->setslicecolors = $tt + $tt2;
  355. }
  356. // Draw the slices
  357. $sum=0;
  358. for($i=0; $i < $n; ++$i)
  359. $sum += $this->data[$i];
  360. // Bail out with error if the sum is 0
  361. if( $sum==0 )
  362. JpGraphError::RaiseL(15009);//("Sum of all data is 0 for Pie.");
  363. // Set up the pie-circle
  364. if( $this->radius <= 1 )
  365. $radius = floor($this->radius*min($img->width,$img->height));
  366. else {
  367. $radius = $aaoption === 1 ? $this->radius*2 : $this->radius;
  368. }
  369. if( $this->posx <= 1 && $this->posx > 0 )
  370. $xc = round($this->posx*$img->width);
  371. else
  372. $xc = $this->posx ;
  373. if( $this->posy <= 1 && $this->posy > 0 )
  374. $yc = round($this->posy*$img->height);
  375. else
  376. $yc = $this->posy ;
  377. $n = count($this->data);
  378. if( $this->explode_all )
  379. for($i=0; $i < $n; ++$i)
  380. $this->explode_radius[$i]=$this->explode_r;
  381. if( $this->ishadowcolor != "" && $aaoption !== 2) {
  382. $accsum=0;
  383. $angle2 = $this->startangle;
  384. $img->SetColor($this->ishadowcolor);
  385. for($i=0; $sum > 0 && $i < $n; ++$i) {
  386. $j = $n-$i-1;
  387. $d = $this->data[$i];
  388. $angle1 = $angle2;
  389. $accsum += $d;
  390. $angle2 = $this->startangle+2*M_PI*$accsum/$sum;
  391. if( empty($this->explode_radius[$j]) )
  392. $this->explode_radius[$j]=0;
  393. $la = 2*M_PI - (abs($angle2-$angle1)/2.0+$angle1);
  394. $xcm = $xc + $this->explode_radius[$j]*cos($la)*$expscale;
  395. $ycm = $yc - $this->explode_radius[$j]*sin($la)*$expscale;
  396. $xcm += $this->ishadowdrop*$expscale;
  397. $ycm += $this->ishadowdrop*$expscale;
  398. $img->CakeSlice($xcm,$ycm,$radius,$radius,
  399. $angle1*180/M_PI,$angle2*180/M_PI,$this->ishadowcolor);
  400. }
  401. }
  402. $accsum=0;
  403. $angle2 = $this->startangle;
  404. $img->SetColor($this->color);
  405. for($i=0; $sum>0 && $i < $n; ++$i) {
  406. $j = $n-$i-1;
  407. if( empty($this->explode_radius[$j]) )
  408. $this->explode_radius[$j]=0;
  409. $d = $this->data[$i];
  410. $angle1 = $angle2;
  411. $accsum += $d;
  412. $angle2 = $this->startangle+2*M_PI*$accsum/$sum;
  413. $this->la[$i] = 2*M_PI - (abs($angle2-$angle1)/2.0+$angle1);
  414. if( $d == 0 ) continue;
  415. if( $this->setslicecolors==null )
  416. $slicecolor=$colors[$ta[$i%$numcolors]];
  417. else
  418. $slicecolor=$this->setslicecolors[$i%$numcolors];
  419. if( $this->pie_interior_border && $aaoption===0 )
  420. $img->SetColor($this->color);
  421. else
  422. $img->SetColor($slicecolor);
  423. $arccolor = $this->pie_border && $aaoption===0 ? $this->color : "";
  424. $xcm = $xc + $this->explode_radius[$j]*cos($this->la[$i])*$expscale;
  425. $ycm = $yc - $this->explode_radius[$j]*sin($this->la[$i])*$expscale;
  426. if( $aaoption !== 2 ) {
  427. $img->CakeSlice($xcm,$ycm,$radius-1,$radius-1,
  428. $angle1*180/M_PI,$angle2*180/M_PI,$slicecolor,$arccolor);
  429. }
  430. if( $this->csimtargets && $aaoption !== 1 ) {
  431. $this->AddSliceToCSIM($i,$xcm,$ycm,$radius,$angle1,$angle2);
  432. }
  433. }
  434. // Format the titles for each slice
  435. if( $aaoption!==2) {
  436. for( $i=0; $i < $n; ++$i) {
  437. if( $this->labeltype==0 ) {
  438. if( $sum != 0 )
  439. $l = 100.0*$this->data[$i]/$sum;
  440. else
  441. $l = 0.0;
  442. }
  443. elseif( $this->labeltype==1 ) {
  444. $l = $this->data[$i]*1.0;
  445. }
  446. else {
  447. $l = $this->adjusted_data[$i];
  448. }
  449. if( isset($this->labels[$i]) && is_string($this->labels[$i]) )
  450. $this->labels[$i]=sprintf($this->labels[$i],$l);
  451. else
  452. $this->labels[$i]=$l;
  453. }
  454. }
  455. If( $this->value->show && $aaoption !== 1 ) {
  456. $this->StrokeAllLabels($img,$xc,$yc,$radius);
  457. }
  458. // Adjust title position
  459. if( $aaoption !== 1 ) {
  460. $this->title->Pos($xc,
  461. $yc-$this->title->GetFontHeight($img)-$radius-$this->title->margin,
  462. "center","bottom");
  463. $this->title->Stroke($img);
  464. }
  465. }
  466. //---------------
  467. // PRIVATE METHODS
  468. function NormAngle($a) {
  469. while( $a < 0 ) $a += 2*M_PI;
  470. while( $a > 2*M_PI ) $a -= 2*M_PI;
  471. return $a;
  472. }
  473. function Quadrant($a) {
  474. $a=$this->NormAngle($a);
  475. if( $a > 0 && $a <= M_PI/2 )
  476. return 0;
  477. if( $a > M_PI/2 && $a <= M_PI )
  478. return 1;
  479. if( $a > M_PI && $a <= 1.5*M_PI )
  480. return 2;
  481. if( $a > 1.5*M_PI )
  482. return 3;
  483. }
  484. function StrokeGuideLabels($img,$xc,$yc,$radius) {
  485. $n = count($this->labels);
  486. //-----------------------------------------------------------------------
  487. // Step 1 of the algorithm is to construct a number of clusters
  488. // a cluster is defined as all slices within the same quadrant (almost)
  489. // that has an angular distance less than the threshold
  490. //-----------------------------------------------------------------------
  491. $tresh_hold=25 * M_PI/180; // 25 degrees difference to be in a cluster
  492. $incluster=false; // flag if we are currently in a cluster or not
  493. $clusters = array(); // array of clusters
  494. $cidx=-1; // running cluster index
  495. // Go through all the labels and construct a number of clusters
  496. for($i=0; $i < $n-1; ++$i) {
  497. // Calc the angle distance between two consecutive slices
  498. $a1=$this->la[$i];
  499. $a2=$this->la[$i+1];
  500. $q1 = $this->Quadrant($a1);
  501. $q2 = $this->Quadrant($a2);
  502. $diff = abs($a1-$a2);
  503. if( $diff < $tresh_hold ) {
  504. if( $incluster ) {
  505. $clusters[$cidx][1]++;
  506. // Each cluster can only cover one quadrant
  507. // Do we cross a quadrant ( and must break the cluster)
  508. if( $q1 != $q2 ) {
  509. // If we cross a quadrant boundary we normally start a
  510. // new cluster. However we need to take the 12'a clock
  511. // and 6'a clock positions into a special consideration.
  512. // Case 1: WE go from q=1 to q=2 if the last slice on
  513. // the cluster for q=1 is close to 12'a clock and the
  514. // first slice in q=0 is small we extend the previous
  515. // cluster
  516. if( $q1 == 1 && $q2 == 0 && $a2 > (90-15)*M_PI/180 ) {
  517. if( $i < $n-2 ) {
  518. $a3 = $this->la[$i+2];
  519. // If there isn't a cluster coming up with the next-next slice
  520. // we extend the previous cluster to cover this slice as well
  521. if( abs($a3-$a2) >= $tresh_hold ) {
  522. $clusters[$cidx][1]++;
  523. $i++;
  524. }
  525. }
  526. }
  527. elseif( $q1 == 3 && $q2 == 2 && $a2 > (270-15)*M_PI/180 ) {
  528. if( $i < $n-2 ) {
  529. $a3 = $this->la[$i+2];
  530. // If there isn't a cluster coming up with the next-next slice
  531. // we extend the previous cluster to cover this slice as well
  532. if( abs($a3-$a2) >= $tresh_hold ) {
  533. $clusters[$cidx][1]++;
  534. $i++;
  535. }
  536. }
  537. }
  538. if( $q1==2 && $q2==1 && $a2 > (180-15)*M_PI/180 ) {
  539. $clusters[$cidx][1]++;
  540. $i++;
  541. }
  542. $incluster = false;
  543. }
  544. }
  545. elseif( $q1 == $q2) {
  546. $incluster = true;
  547. // Now we have a special case for quadrant 0. If we previously
  548. // have a cluster of one in quadrant 0 we just extend that
  549. // cluster. If we don't do this then we risk that the label
  550. // for the cluster of one will cross the guide-line
  551. if( $q1 == 0 && $cidx > -1 &&
  552. $clusters[$cidx][1] == 1 &&
  553. $this->Quadrant($this->la[$clusters[$cidx][0]]) == 0 ) {
  554. $clusters[$cidx][1]++;
  555. }
  556. else {
  557. $cidx++;
  558. $clusters[$cidx][0] = $i;
  559. $clusters[$cidx][1] = 1;
  560. }
  561. }
  562. else {
  563. // Create a "cluster" of one since we are just crossing
  564. // a quadrant
  565. $cidx++;
  566. $clusters[$cidx][0] = $i;
  567. $clusters[$cidx][1] = 1;
  568. }
  569. }
  570. else {
  571. if( $incluster ) {
  572. // Add the last slice
  573. $clusters[$cidx][1]++;
  574. $incluster = false;
  575. }
  576. else { // Create a "cluster" of one
  577. $cidx++;
  578. $clusters[$cidx][0] = $i;
  579. $clusters[$cidx][1] = 1;
  580. }
  581. }
  582. }
  583. // Handle the very last slice
  584. if( $incluster ) {
  585. $clusters[$cidx][1]++;
  586. }
  587. else { // Create a "cluster" of one
  588. $cidx++;
  589. $clusters[$cidx][0] = $i;
  590. $clusters[$cidx][1] = 1;
  591. }
  592. /*
  593. if( true ) {
  594. // Debug printout in labels
  595. for( $i=0; $i <= $cidx; ++$i ) {
  596. for( $j=0; $j < $clusters[$i][1]; ++$j ) {
  597. $a = $this->la[$clusters[$i][0]+$j];
  598. $aa = round($a*180/M_PI);
  599. $q = $this->Quadrant($a);
  600. $this->labels[$clusters[$i][0]+$j]="[$q:$aa] $i:$j";
  601. }
  602. }
  603. }
  604. */
  605. //-----------------------------------------------------------------------
  606. // Step 2 of the algorithm is use the clusters and draw the labels
  607. // and guidelines
  608. //-----------------------------------------------------------------------
  609. // We use the font height as the base factor for how far we need to
  610. // spread the labels in the Y-direction.
  611. $img->SetFont($this->value->ff,$this->value->fs,$this->value->fsize);
  612. $fh = $img->GetFontHeight();
  613. $origvstep=$fh*$this->iGuideVFactor;
  614. $this->value->SetMargin(0);
  615. // Number of clusters found
  616. $nc = count($clusters);
  617. // Walk through all the clusters
  618. for($i=0; $i < $nc; ++$i) {
  619. // Start angle and number of slices in this cluster
  620. $csize = $clusters[$i][1];
  621. $a = $this->la[$clusters[$i][0]];
  622. $q = $this->Quadrant($a);
  623. // Now set up the start and end conditions to make sure that
  624. // in each cluster we walk through the all the slices starting with the slice
  625. // closest to the equator. Since all slices are numbered clockwise from "3'a clock"
  626. // we have different conditions depending on in which quadrant the slice lies within.
  627. if( $q == 0 ) {
  628. $start = $csize-1; $idx = $start; $step = -1; $vstep = -$origvstep;
  629. }
  630. elseif( $q == 1 ) {
  631. $start = 0; $idx = $start; $step = 1; $vstep = -$origvstep;
  632. }
  633. elseif( $q == 2 ) {
  634. $start = $csize-1; $idx = $start; $step = -1; $vstep = $origvstep;
  635. }
  636. elseif( $q == 3 ) {
  637. $start = 0; $idx = $start; $step = 1; $vstep = $origvstep;
  638. }
  639. // Walk through all slices within this cluster
  640. for($j=0; $j < $csize; ++$j) {
  641. // Now adjust the position of the labels in each cluster starting
  642. // with the slice that is closest to the equator of the pie
  643. $a = $this->la[$clusters[$i][0]+$idx];
  644. // Guide line start in the center of the arc of the slice
  645. $r = $radius+$this->explode_radius[$n-1-($clusters[$i][0]+$idx)];
  646. $x = round($r*cos($a)+$xc);
  647. $y = round($yc-$r*sin($a));
  648. // The distance from the arc depends on chosen font and the "R-Factor"
  649. $r += $fh*$this->iGuideLineRFactor;
  650. // Should the labels be placed curved along the pie or in straight columns
  651. // outside the pie?
  652. if( $this->iGuideLineCurve )
  653. $xt=round($r*cos($a)+$xc);
  654. // If this is the first slice in the cluster we need some first time
  655. // proessing
  656. if( $idx == $start ) {
  657. if( ! $this->iGuideLineCurve )
  658. $xt=round($r*cos($a)+$xc);
  659. $yt=round($yc-$r*sin($a));
  660. // Some special consideration in case this cluster starts
  661. // in quadrant 1 or 3 very close to the "equator" (< 20 degrees)
  662. // and the previous clusters last slice is within the tolerance.
  663. // In that case we add a font height to this labels Y-position
  664. // so it doesn't collide with
  665. // the slice in the previous cluster
  666. $prevcluster = ($i + ($nc-1) ) % $nc;
  667. $previdx=$clusters[$prevcluster][0]+$clusters[$prevcluster][1]-1;
  668. if( $q == 1 && $a > 160*M_PI/180 ) {
  669. // Get the angle for the previous clusters last slice
  670. $diff = abs($a-$this->la[$previdx]);
  671. if( $diff < $tresh_hold ) {
  672. $yt -= $fh;
  673. }
  674. }
  675. elseif( $q == 3 && $a > 340*M_PI/180 ) {
  676. // We need to subtract 360 to compare angle distance between
  677. // q=0 and q=3
  678. $diff = abs($a-$this->la[$previdx]-360*M_PI/180);
  679. if( $diff < $tresh_hold ) {
  680. $yt += $fh;
  681. }
  682. }
  683. }
  684. else {
  685. // The step is at minimum $vstep but if the slices are relatively large
  686. // we make sure that we add at least a step that corresponds to the vertical
  687. // distance between the centers at the arc on the slice
  688. $prev_a = $this->la[$clusters[$i][0]+($idx-$step)];
  689. $dy = abs($radius*(sin($a)-sin($prev_a))*1.2);
  690. if( $vstep > 0 )
  691. $yt += max($vstep,$dy);
  692. else
  693. $yt += min($vstep,-$dy);
  694. }
  695. $label = $this->labels[$clusters[$i][0]+$idx];
  696. if( $csize == 1 ) {
  697. // A "meta" cluster with only one slice
  698. $r = $radius+$this->explode_radius[$n-1-($clusters[$i][0]+$idx)];
  699. $rr = $r+$img->GetFontHeight()/2;
  700. $xt=round($rr*cos($a)+$xc);
  701. $yt=round($yc-$rr*sin($a));
  702. $this->StrokeLabel($label,$img,$xc,$yc,$a,$r);
  703. if( $this->iShowGuideLineForSingle )
  704. $this->guideline->Stroke($img,$x,$y,$xt,$yt);
  705. }
  706. else {
  707. $this->guideline->Stroke($img,$x,$y,$xt,$yt);
  708. if( $q==1 || $q==2 ) {
  709. // Left side of Pie
  710. $this->guideline->Stroke($img,$xt,$yt,$xt-$this->guidelinemargin,$yt);
  711. $lbladj = -$this->guidelinemargin-5;
  712. $this->value->halign = "right";
  713. $this->value->valign = "center";
  714. }
  715. else {
  716. // Right side of pie
  717. $this->guideline->Stroke($img,$xt,$yt,$xt+$this->guidelinemargin,$yt);
  718. $lbladj = $this->guidelinemargin+5;
  719. $this->value->halign = "left";
  720. $this->value->valign = "center";
  721. }
  722. $this->value->Stroke($img,$label,$xt+$lbladj,$yt);
  723. }
  724. // Udate idx to point to next slice in the cluster to process
  725. $idx += $step;
  726. }
  727. }
  728. }
  729. function StrokeAllLabels($img,$xc,$yc,$radius) {
  730. // First normalize all angles for labels
  731. $n = count($this->la);
  732. for($i=0; $i < $n; ++$i) {
  733. $this->la[$i] = $this->NormAngle($this->la[$i]);
  734. }
  735. if( $this->guideline->iShow ) {
  736. $this->StrokeGuideLabels($img,$xc,$yc,$radius);
  737. }
  738. else {
  739. $n = count($this->labels);
  740. for($i=0; $i < $n; ++$i) {
  741. $this->StrokeLabel($this->labels[$i],$img,$xc,$yc,
  742. $this->la[$i],
  743. $radius + $this->explode_radius[$n-1-$i]);
  744. }
  745. }
  746. }
  747. // Position the labels of each slice
  748. function StrokeLabel($label,$img,$xc,$yc,$a,$radius) {
  749. // Default value
  750. if( $this->ilabelposadj === 'auto' )
  751. $this->ilabelposadj = 0.65;
  752. $r = $radius;
  753. // We position the values diferently depending on if they are inside
  754. // or outside the pie
  755. if( $this->ilabelposadj < 1.0 ) {
  756. $this->value->SetAlign('center','center');
  757. $this->value->margin = 0;
  758. $xt=round($this->ilabelposadj*$r*cos($a)+$xc);
  759. $yt=round($yc-$this->ilabelposadj*$r*sin($a));
  760. $this->value->Stroke($img,$label,$xt,$yt);
  761. }
  762. else {
  763. $this->value->halign = "left";
  764. $this->value->valign = "top";
  765. $this->value->margin = 0;
  766. // Position the axis title.
  767. // dx, dy is the offset from the top left corner of the bounding box that sorrounds the text
  768. // that intersects with the extension of the corresponding axis. The code looks a little
  769. // bit messy but this is really the only way of having a reasonable position of the
  770. // axis titles.
  771. $img->SetFont($this->value->ff,$this->value->fs,$this->value->fsize);
  772. $h=$img->GetTextHeight($label);
  773. // For numeric values the format of the display value
  774. // must be taken into account
  775. if( is_numeric($label) ) {
  776. if( $label > 0 )
  777. $w=$img->GetTextWidth(sprintf($this->value->format,$label));
  778. else
  779. $w=$img->GetTextWidth(sprintf($this->value->negformat,$label));
  780. }
  781. else
  782. $w=$img->GetTextWidth($label);
  783. if( $this->ilabelposadj > 1.0 && $this->ilabelposadj < 5.0) {
  784. $r *= $this->ilabelposadj;
  785. }
  786. $r += $img->GetFontHeight()/1.5;
  787. $xt=round($r*cos($a)+$xc);
  788. $yt=round($yc-$r*sin($a));
  789. // Normalize angle
  790. while( $a < 0 ) $a += 2*M_PI;
  791. while( $a > 2*M_PI ) $a -= 2*M_PI;
  792. if( $a>=7*M_PI/4 || $a <= M_PI/4 ) $dx=0;
  793. if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dx=($a-M_PI/4)*2/M_PI;
  794. if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dx=1;
  795. if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dx=(1-($a-M_PI*5/4)*2/M_PI);
  796. if( $a>=7*M_PI/4 ) $dy=(($a-M_PI)-3*M_PI/4)*2/M_PI;
  797. if( $a<=M_PI/4 ) $dy=(1-$a*2/M_PI);
  798. if( $a>=M_PI/4 && $a <= 3*M_PI/4 ) $dy=1;
  799. if( $a>=3*M_PI/4 && $a <= 5*M_PI/4 ) $dy=(1-($a-3*M_PI/4)*2/M_PI);
  800. if( $a>=5*M_PI/4 && $a <= 7*M_PI/4 ) $dy=0;
  801. $this->value->Stroke($img,$label,$xt-$dx*$w,$yt-$dy*$h);
  802. }
  803. }
  804. } // Class
  805. //===================================================
  806. // CLASS PiePlotC
  807. // Description: Same as a normal pie plot but with a
  808. // filled circle in the center
  809. //===================================================
  810. class PiePlotC extends PiePlot {
  811. var $imidsize=0.5; // Fraction of total width
  812. var $imidcolor='white';
  813. var $midtitle='';
  814. var $middlecsimtarget="",$middlecsimalt="";
  815. function PiePlotC($data,$aCenterTitle='') {
  816. parent::PiePlot($data);
  817. $this->midtitle = new Text();
  818. $this->midtitle->ParagraphAlign('center');
  819. }
  820. function SetMid($aTitle,$aColor='white',$aSize=0.5) {
  821. $this->midtitle->Set($aTitle);
  822. $this->imidsize = $aSize ;
  823. $this->imidcolor = $aColor ;
  824. }
  825. function SetMidTitle($aTitle) {
  826. $this->midtitle->Set($aTitle);
  827. }
  828. function SetMidSize($aSize) {
  829. $this->imidsize = $aSize ;
  830. }
  831. function SetMidColor($aColor) {
  832. $this->imidcolor = $aColor ;
  833. }
  834. function SetMidCSIM($aTarget,$aAlt) {
  835. $this->middlecsimtarget = $aTarget;
  836. $this->middlecsimalt = $aAlt;
  837. }
  838. function AddSliceToCSIM($i,$xc,$yc,$radius,$sa,$ea) {
  839. //Slice number, ellipse centre (x,y), radius, start angle, end angle
  840. while( $sa > 2*M_PI ) $sa = $sa - 2*M_PI;
  841. while( $ea > 2*M_PI ) $ea = $ea - 2*M_PI;
  842. $sa = 2*M_PI - $sa;
  843. $ea = 2*M_PI - $ea;
  844. // Special case when we have only one slice since then both start and end
  845. // angle will be == 0
  846. if( abs($sa - $ea) < 0.0001 ) {
  847. $sa=2*M_PI; $ea=0;
  848. }
  849. // Add inner circle first point
  850. $xp = floor(($this->imidsize*$radius*cos($ea))+$xc);
  851. $yp = floor($yc-($this->imidsize*$radius*sin($ea)));
  852. $coords = "$xp, $yp";
  853. //add coordinates every 0.25 radians
  854. $a=$ea+0.25;
  855. // If we cross the 260-limit with a slice we need to handle
  856. // the fact that end angle is smaller than start
  857. if( $sa < $ea ) {
  858. while ($a <= 2*M_PI) {
  859. $xp = floor($radius*cos($a)+$xc);
  860. $yp = floor($yc-$radius*sin($a));
  861. $coords.= ", $xp, $yp";
  862. $a += 0.25;
  863. }
  864. $a -= 2*M_PI;
  865. }
  866. while ($a < $sa) {
  867. $xp = floor(($this->imidsize*$radius*cos($a)+$xc));
  868. $yp = floor($yc-($this->imidsize*$radius*sin($a)));
  869. $coords.= ", $xp, $yp";
  870. $a += 0.25;
  871. }
  872. // Make sure we end at the last point
  873. $xp = floor(($this->imidsize*$radius*cos($sa)+$xc));
  874. $yp = floor($yc-($this->imidsize*$radius*sin($sa)));
  875. $coords.= ", $xp, $yp";
  876. // Straight line to outer circle
  877. $xp = floor($radius*cos($sa)+$xc);
  878. $yp = floor($yc-$radius*sin($sa));
  879. $coords.= ", $xp, $yp";
  880. //add coordinates every 0.25 radians
  881. $a=$sa - 0.25;
  882. while ($a > $ea) {
  883. $xp = floor($radius*cos($a)+$xc);
  884. $yp = floor($yc-$radius*sin($a));
  885. $coords.= ", $xp, $yp";
  886. $a -= 0.25;
  887. }
  888. //Add the last point on the arc
  889. $xp = floor($radius*cos($ea)+$xc);
  890. $yp = floor($yc-$radius*sin($ea));
  891. $coords.= ", $xp, $yp";
  892. // Close the arc
  893. $xp = floor(($this->imidsize*$radius*cos($ea))+$xc);
  894. $yp = floor($yc-($this->imidsize*$radius*sin($ea)));
  895. $coords .= ", $xp, $yp";
  896. if( !empty($this->csimtargets[$i]) ) {
  897. $this->csimareas .= "<area shape=\"poly\" coords=\"$coords\" href=\"".
  898. $this->csimtargets[$i]."\"";
  899. if( !empty($this->csimalts[$i]) ) {
  900. $tmp=sprintf($this->csimalts[$i],$this->data[$i]);
  901. $this->csimareas .= " title=\"$tmp\"";
  902. }
  903. $this->csimareas .= " alt=\"$tmp\" />\n";
  904. }
  905. }
  906. function Stroke($img,$aaoption=0) {
  907. // Stroke the pie but don't stroke values
  908. $tmp = $this->value->show;
  909. $this->value->show = false;
  910. parent::Stroke($img,$aaoption);
  911. $this->value->show = $tmp;
  912. $xc = round($this->posx*$img->width);
  913. $yc = round($this->posy*$img->height);
  914. $radius = floor($this->radius * min($img->width,$img->height)) ;
  915. if( $this->imidsize > 0 && $aaoption !== 2 ) {
  916. if( $this->ishadowcolor != "" ) {
  917. $img->SetColor($this->ishadowcolor);
  918. $img->FilledCircle($xc+$this->ishadowdrop,$yc+$this->ishadowdrop,
  919. round($radius*$this->imidsize));
  920. }
  921. $img->SetColor($this->imidcolor);
  922. $img->FilledCircle($xc,$yc,round($radius*$this->imidsize));
  923. if( $this->pie_border && $aaoption === 0 ) {
  924. $img->SetColor($this->color);
  925. $img->Circle($xc,$yc,round($radius*$this->imidsize));
  926. }
  927. if( !empty($this->middlecsimtarget) )
  928. $this->AddMiddleCSIM($xc,$yc,round($radius*$this->imidsize));
  929. }
  930. if( $this->value->show && $aaoption !== 1) {
  931. $this->StrokeAllLabels($img,$xc,$yc,$radius);
  932. $this->midtitle->Pos($xc,$yc,'center','center');
  933. $this->midtitle->Stroke($img);
  934. }
  935. }
  936. function AddMiddleCSIM($xc,$yc,$r) {
  937. $xc=round($xc);$yc=round($yc);$r=round($r);
  938. $this->csimareas .= "<area shape=\"circle\" coords=\"$xc,$yc,$r\" href=\"".
  939. $this->middlecsimtarget."\"";
  940. if( !empty($this->middlecsimalt) ) {
  941. $tmp = $this->middlecsimalt;
  942. $this->csimareas .= " title=\"$tmp\"";
  943. }
  944. $this->csimareas .= " alt=\"$tmp\" />\n";
  945. }
  946. function StrokeLabel($label,$img,$xc,$yc,$a,$r) {
  947. if( $this->ilabelposadj === 'auto' )
  948. $this->ilabelposadj = (1-$this->imidsize)/2+$this->imidsize;
  949. parent::StrokeLabel($label,$img,$xc,$yc,$a,$r);
  950. }
  951. }
  952. //===================================================
  953. // CLASS PieGraph
  954. // Description:
  955. //===================================================
  956. class PieGraph extends Graph {
  957. var $posx, $posy, $radius;
  958. var $legends=array();
  959. var $plots=array();
  960. var $pieaa = false ;
  961. //---------------
  962. // CONSTRUCTOR
  963. function PieGraph($width=300,$height=200,$cachedName="",$timeout=0,$inline=1) {
  964. $this->Graph($width,$height,$cachedName,$timeout,$inline);
  965. $this->posx=$width/2;
  966. $this->posy=$height/2;
  967. $this->SetColor(array(255,255,255));
  968. }
  969. //---------------
  970. // PUBLIC METHODS
  971. function Add($aObj) {
  972. if( is_array($aObj) && count($aObj) > 0 )
  973. $cl = $aObj[0];
  974. else
  975. $cl = $aObj;
  976. if( is_a($cl,'Text') )
  977. $this->AddText($aObj);
  978. elseif( is_a($cl,'IconPlot') )
  979. $this->AddIcon($aObj);
  980. else {
  981. if( is_array($aObj) ) {
  982. $n = count($aObj);
  983. for($i=0; $i < $n; ++$i ) {
  984. $this->plots[] = $aObj[$i];
  985. }
  986. }
  987. else {
  988. $this->plots[] = $aObj;
  989. }
  990. }
  991. }
  992. function SetAntiAliasing($aFlg=true) {
  993. $this->pieaa = $aFlg;
  994. }
  995. function SetColor($c) {
  996. $this->SetMarginColor($c);
  997. }
  998. function DisplayCSIMAreas() {
  999. $csim="";
  1000. foreach($this->plots as $p ) {
  1001. $csim .= $p->GetCSIMareas();
  1002. }
  1003. //$csim.= $this->legend->GetCSIMareas();
  1004. if (preg_match_all("/area shape=\"(\w+)\" coords=\"([0-9\, ]+)\"/", $csim, $coords)) {
  1005. $this->img->SetColor($this->csimcolor);
  1006. $n = count($coords[0]);
  1007. for ($i=0; $i < $n; $i++) {
  1008. if ($coords[1][$i]=="poly") {
  1009. preg_match_all('/\s*([0-9]+)\s*,\s*([0-9]+)\s*,*/',$coords[2][$i],$pts);
  1010. $this->img->SetStartPoint($pts[1][count($pts[0])-1],$pts[2][count($pts[0])-1]);
  1011. $m = count($pts[0]);
  1012. for ($j=0; $j < $m; $j++) {
  1013. $this->img->LineTo($pts[1][$j],$pts[2][$j]);
  1014. }
  1015. } else if ($coords[1][$i]=="rect") {
  1016. $pts = preg_split('/,/', $coords[2][$i]);
  1017. $this->img->SetStartPoint($pts[0],$pts[1]);
  1018. $this->img->LineTo($pts[2],$pts[1]);
  1019. $this->img->LineTo($pts[2],$pts[3]);
  1020. $this->img->LineTo($pts[0],$pts[3]);
  1021. $this->img->LineTo($pts[0],$pts[1]);
  1022. }
  1023. }
  1024. }
  1025. }
  1026. // Method description
  1027. function Stroke($aStrokeFileName="") {
  1028. // If the filename is the predefined value = '_csim_special_'
  1029. // we assume that the call to stroke only needs to do enough
  1030. // to correctly generate the CSIM maps.
  1031. // We use this variable to skip things we don't strictly need
  1032. // to do to generate the image map to improve performance
  1033. // a best we can. Therefor you will see a lot of tests !$_csim in the
  1034. // code below.
  1035. $_csim = ($aStrokeFileName===_CSIM_SPECIALFILE);
  1036. // We need to know if we have stroked the plot in the
  1037. // GetCSIMareas. Otherwise the CSIM hasn't been generated
  1038. // and in the case of GetCSIM called before stroke to generate
  1039. // CSIM without storing an image to disk GetCSIM must call Stroke.
  1040. $this->iHasStroked = true;
  1041. $n = count($this->plots);
  1042. if( $this->pieaa ) {
  1043. if( !$_csim ) {
  1044. if( $this->background_image != "" ) {
  1045. $this->StrokeFrameBackground();
  1046. }
  1047. else {
  1048. $this->StrokeFrame();
  1049. }
  1050. }
  1051. $w = $this->img->width;
  1052. $h = $this->img->height;
  1053. $oldimg = $this->img->img;
  1054. $this->img->CreateImgCanvas(2*$w,2*$h);
  1055. $this->img->SetColor( $this->margin_color );
  1056. $this->img->FilledRectangle(0,0,2*$w-1,2*$h-1);
  1057. // Make all icons *2 i size since we will be scaling down the
  1058. // image to do the anti aliasing
  1059. $ni = count($this->iIcons);
  1060. for($i=0; $i < $ni; ++$i) {
  1061. $this->iIcons[$i]->iScale *= 2 ;
  1062. }
  1063. $this->StrokeIcons();
  1064. for($i=0; $i < $n; ++$i) {
  1065. if( $this->plots[$i]->posx > 1 )
  1066. $this->plots[$i]->posx *= 2 ;
  1067. if( $this->plots[$i]->posy > 1 )
  1068. $this->plots[$i]->posy *= 2 ;
  1069. $this->plots[$i]->Stroke($this->img,1);
  1070. if( $this->plots[$i]->posx > 1 )
  1071. $this->plots[$i]->posx /= 2 ;
  1072. if( $this->plots[$i]->posy > 1 )
  1073. $this->plots[$i]->posy /= 2 ;
  1074. }
  1075. $indent = $this->doframe ? ($this->frame_weight + ($this->doshadow ? $this->shadow_width : 0 )) : 0 ;
  1076. $indent += $this->framebevel ? $this->framebeveldepth + 1 : 0 ;
  1077. $this->img->CopyCanvasH($oldimg,$this->img->img,$indent,$indent,$indent,$indent,
  1078. $w-2*$indent,$h-2*$indent,2*($w-$indent),2*($h-$indent));
  1079. $this->img->img = $oldimg ;
  1080. $this->img->width = $w ;
  1081. $this->img->height = $h ;
  1082. for($i=0; $i < $n; ++$i) {
  1083. $this->plots[$i]->Stroke($this->img,2); // Stroke labels
  1084. $this->plots[$i]->Legend($this);
  1085. }
  1086. }
  1087. else {
  1088. // No antialias
  1089. if( !$_csim ) {
  1090. if( $this->background_image != "" ) {
  1091. $this->StrokeFrameBackground();
  1092. }
  1093. else {
  1094. $this->StrokeFrame();
  1095. $this->StrokeBackgroundGrad();
  1096. }
  1097. }
  1098. $this->StrokeIcons();
  1099. for($i=0; $i < $n; ++$i) {
  1100. $this->plots[$i]->Stroke($this->img);
  1101. $this->plots[$i]->Legend($this);
  1102. }
  1103. }
  1104. $this->legend->Stroke($this->img);
  1105. $this->footer->Stroke($this->img);
  1106. $this->StrokeTitles();
  1107. if( !$_csim ) {
  1108. // Stroke texts
  1109. if( $this->texts != null ) {
  1110. $n = count($this->texts);
  1111. for($i=0; $i < $n; ++$i ) {
  1112. $this->texts[$i]->Stroke($this->img);
  1113. }
  1114. }
  1115. if( _JPG_DEBUG ) {
  1116. $this->DisplayCSIMAreas();
  1117. }
  1118. // Should we do any final image transformation
  1119. if( $this->iImgTrans ) {
  1120. if( !class_exists('ImgTrans') ) {
  1121. require_once('jpgraph_imgtrans.php');
  1122. //JpGraphError::Raise('In order to use image transformation you must include the file jpgraph_imgtrans.php in your script.');
  1123. }
  1124. $tform = new ImgTrans($this->img->img);
  1125. $this->img->img = $tform->Skew3D($this->iImgTransHorizon,$this->iImgTransSkewDist,
  1126. $this->iImgTransDirection,$this->iImgTransHighQ,
  1127. $this->iImgTransMinSize,$this->iImgTransFillColor,
  1128. $this->iImgTransBorder);
  1129. }
  1130. // If the filename is given as the special "__handle"
  1131. // then the image handler is returned and the image is NOT
  1132. // streamed back
  1133. if( $aStrokeFileName == _IMG_HANDLER ) {
  1134. return $this->img->img;
  1135. }
  1136. else {
  1137. // Finally stream the generated picture
  1138. $this->cache->PutAndStream($this->img,$this->cache_name,$this->inline,
  1139. $aStrokeFileName);
  1140. }
  1141. }
  1142. }
  1143. } // Class
  1144. /* EOF */
  1145. ?>