PageRenderTime 168ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 2ms

/TEMPLATE/Reports/class/pchart2/class/pDraw.class.php

https://bitbucket.org/Lahiru_LCB/sep_wd_07
PHP | 5363 lines | 4329 code | 922 blank | 112 comment | 2009 complexity | 13ffc408e253cc133be311d5c20035d7 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. pDraw - class extension with drawing methods
  4. Version : 2.1.1
  5. Made by : Jean-Damien POGOLOTTI
  6. Last Update : 28/03/11
  7. This file can be distributed under the license you can find at :
  8. http://www.pchart.net/license
  9. You can find the whole class documentation on the pChart web site.
  10. */
  11. define("DIRECTION_VERTICAL" , 690001);
  12. define("DIRECTION_HORIZONTAL" , 690002);
  13. define("SCALE_POS_LEFTRIGHT" , 690101);
  14. define("SCALE_POS_TOPBOTTOM" , 690102);
  15. define("SCALE_MODE_FLOATING" , 690201);
  16. define("SCALE_MODE_START0" , 690202);
  17. define("SCALE_MODE_ADDALL" , 690203);
  18. define("SCALE_MODE_ADDALL_START0" , 690204);
  19. define("SCALE_MODE_MANUAL" , 690205);
  20. define("SCALE_SKIP_NONE" , 690301);
  21. define("SCALE_SKIP_SAME" , 690302);
  22. define("SCALE_SKIP_NUMBERS" , 690303);
  23. define("TEXT_ALIGN_TOPLEFT" , 690401);
  24. define("TEXT_ALIGN_TOPMIDDLE" , 690402);
  25. define("TEXT_ALIGN_TOPRIGHT" , 690403);
  26. define("TEXT_ALIGN_MIDDLELEFT" , 690404);
  27. define("TEXT_ALIGN_MIDDLEMIDDLE" , 690405);
  28. define("TEXT_ALIGN_MIDDLERIGHT" , 690406);
  29. define("TEXT_ALIGN_BOTTOMLEFT" , 690407);
  30. define("TEXT_ALIGN_BOTTOMMIDDLE" , 690408);
  31. define("TEXT_ALIGN_BOTTOMRIGHT" , 690409);
  32. define("POSITION_TOP" , 690501);
  33. define("POSITION_BOTTOM" , 690502);
  34. define("LABEL_POS_LEFT" , 690601);
  35. define("LABEL_POS_CENTER" , 690602);
  36. define("LABEL_POS_RIGHT" , 690603);
  37. define("LABEL_POS_TOP" , 690604);
  38. define("LABEL_POS_BOTTOM" , 690605);
  39. define("LABEL_POS_INSIDE" , 690606);
  40. define("LABEL_POS_OUTSIDE" , 690607);
  41. define("ORIENTATION_HORIZONTAL" , 690701);
  42. define("ORIENTATION_VERTICAL" , 690702);
  43. define("LEGEND_NOBORDER" , 690800);
  44. define("LEGEND_BOX" , 690801);
  45. define("LEGEND_ROUND" , 690802);
  46. define("LEGEND_VERTICAL" , 690901);
  47. define("LEGEND_HORIZONTAL" , 690902);
  48. define("LEGEND_FAMILY_BOX" , 691051);
  49. define("LEGEND_FAMILY_CIRCLE" , 691052);
  50. define("LEGEND_FAMILY_LINE" , 691053);
  51. define("DISPLAY_AUTO" , 691001);
  52. define("DISPLAY_MANUAL" , 691002);
  53. define("LABELING_ALL" , 691011);
  54. define("LABELING_DIFFERENT" , 691012);
  55. define("BOUND_MIN" , 691021);
  56. define("BOUND_MAX" , 691022);
  57. define("BOUND_BOTH" , 691023);
  58. define("BOUND_LABEL_POS_TOP" , 691031);
  59. define("BOUND_LABEL_POS_BOTTOM" , 691032);
  60. define("BOUND_LABEL_POS_AUTO" , 691033);
  61. define("CAPTION_LEFT_TOP" , 691041);
  62. define("CAPTION_RIGHT_BOTTOM" , 691042);
  63. define("GRADIENT_SIMPLE" , 691051);
  64. define("GRADIENT_EFFECT_CAN" , 691052);
  65. define("LABEL_TITLE_NOBACKGROUND" , 691061);
  66. define("LABEL_TITLE_BACKGROUND" , 691062);
  67. define("LABEL_POINT_NONE" , 691071);
  68. define("LABEL_POINT_CIRCLE" , 691072);
  69. define("LABEL_POINT_BOX" , 691073);
  70. define("PI" , 3.14159265);
  71. define("ALL" , 69);
  72. define("NONE" , 31);
  73. define("AUTO" , 690000);
  74. define("OUT_OF_SIGHT" , -10000000000000);
  75. class pDraw
  76. {
  77. /* Returns the number of drawable series */
  78. function countDrawableSeries()
  79. {
  80. $Results = 0;
  81. $Data = $this->DataSet->getData();
  82. foreach($Data["Series"] as $SerieName => $Serie)
  83. { if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] ) { $Results++; } }
  84. return($Results);
  85. }
  86. /* Fix box coordinates */
  87. function fixBoxCoordinates($Xa,$Ya,$Xb,$Yb)
  88. {
  89. $X1 = min($Xa,$Xb); $Y1 = min($Ya,$Yb);
  90. $X2 = max($Xa,$Xb); $Y2 = max($Ya,$Yb);
  91. return(array($X1,$Y1,$X2,$Y2));
  92. }
  93. /* Draw a polygon */
  94. function drawPolygon($Points,$Format="")
  95. {
  96. $R = isset($Format["R"]) ? $Format["R"] : 0;
  97. $G = isset($Format["G"]) ? $Format["G"] : 0;
  98. $B = isset($Format["B"]) ? $Format["B"] : 0;
  99. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  100. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  101. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  102. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  103. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  104. $BorderAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $Alpha / 2;
  105. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  106. $SkipX = isset($Format["SkipX"]) ? $Format["SkipX"] : OUT_OF_SIGHT;
  107. $SkipY = isset($Format["SkipY"]) ? $Format["SkipY"] : OUT_OF_SIGHT;
  108. /* Calling the ImageFilledPolygon() function over the $Points array will round it */
  109. $Backup = $Points;
  110. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  111. if ( $SkipX != OUT_OF_SIGHT ) { $SkipX = floor($SkipX); }
  112. if ( $SkipY != OUT_OF_SIGHT ) { $SkipY = floor($SkipY); }
  113. $RestoreShadow = $this->Shadow;
  114. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  115. {
  116. $this->Shadow = FALSE;
  117. for($i=0;$i<=count($Points)-1;$i=$i+2)
  118. { $Shadow[] = $Points[$i] + $this->ShadowX; $Shadow[] = $Points[$i+1] + $this->ShadowY; }
  119. $this->drawPolygon($Shadow,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"NoBorder"=>TRUE));
  120. }
  121. $FillColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  122. if ( count($Points) >= 6 )
  123. { ImageFilledPolygon($this->Picture,$Points,count($Points)/2,$FillColor); }
  124. if ( !$NoBorder )
  125. {
  126. $Points = $Backup;
  127. $BorderSettings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha);
  128. for($i=0;$i<=count($Points)-1;$i=$i+2)
  129. {
  130. if ( isset($Points[$i+2]) )
  131. {
  132. if ( !($Points[$i] == $Points[$i+2] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[$i+3] && $Points[$i+1] == $SkipY ) )
  133. $this->drawLine($Points[$i],$Points[$i+1],$Points[$i+2],$Points[$i+3],$BorderSettings);
  134. }
  135. else
  136. {
  137. if ( !($Points[$i] == $Points[0] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[1] && $Points[$i+1] == $SkipY ) )
  138. $this->drawLine($Points[$i],$Points[$i+1],$Points[0],$Points[1],$BorderSettings);
  139. }
  140. }
  141. }
  142. $this->Shadow = $RestoreShadow;
  143. }
  144. /* Apply AALias correction to the rounded box boundaries */
  145. function offsetCorrection($Value,$Mode)
  146. {
  147. $Value = round($Value,1);
  148. if ( $Value == 0 && $Mode == 1 ) { return(.9); }
  149. if ( $Value == 0 ) { return(0); }
  150. if ( $Mode == 1)
  151. { if ( $Value == 1 ) { return(.9); }; if ( $Value == .1 ) { return(.9); }; if ( $Value == .2 ) { return(.8); }; if ( $Value == .3 ) { return(.8); }; if ( $Value == .4 ) { return(.7); }; if ( $Value == .5 ) { return(.5); }; if ( $Value == .6 ) { return(.8); }; if ( $Value == .7 ) { return(.7); }; if ( $Value == .8 ) { return(.6); }; if ( $Value == .9 ) { return(.9); }; }
  152. if ( $Mode == 2)
  153. { if ( $Value == 1 ) { return(.9); }; if ( $Value == .1 ) { return(.1); }; if ( $Value == .2 ) { return(.2); }; if ( $Value == .3 ) { return(.3); }; if ( $Value == .4 ) { return(.4); }; if ( $Value == .5 ) { return(.5); }; if ( $Value == .6 ) { return(.8); }; if ( $Value == .7 ) { return(.7); }; if ( $Value == .8 ) { return(.8); }; if ( $Value == .9 ) { return(.9); }; }
  154. if ( $Mode == 3)
  155. { if ( $Value == 1 ) { return(.1); }; if ( $Value == .1 ) { return(.1); }; if ( $Value == .2 ) { return(.2); }; if ( $Value == .3 ) { return(.3); }; if ( $Value == .4 ) { return(.4); }; if ( $Value == .5 ) { return(.9); }; if ( $Value == .6 ) { return(.6); }; if ( $Value == .7 ) { return(.7); }; if ( $Value == .8 ) { return(.4); }; if ( $Value == .9 ) { return(.5); }; }
  156. if ( $Mode == 4)
  157. { if ( $Value == 1 ) { return(-1); }; if ( $Value == .1 ) { return(.1); }; if ( $Value == .2 ) { return(.2); }; if ( $Value == .3 ) { return(.3); }; if ( $Value == .4 ) { return(.1); }; if ( $Value == .5 ) { return(-.1); }; if ( $Value == .6 ) { return(.8); }; if ( $Value == .7 ) { return(.1); }; if ( $Value == .8 ) { return(.1); }; if ( $Value == .9 ) { return(.1); }; }
  158. }
  159. /* Draw a rectangle with rounded corners */
  160. function drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  161. {
  162. $R = isset($Format["R"]) ? $Format["R"] : 0;
  163. $G = isset($Format["G"]) ? $Format["G"] : 0;
  164. $B = isset($Format["B"]) ? $Format["B"] : 0;
  165. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  166. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  167. if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1))/2); }
  168. if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1))/2); }
  169. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);
  170. if ( $Radius <= 0 ) { $this->drawRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }
  171. if ( $this->Antialias )
  172. {
  173. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
  174. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
  175. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
  176. $this->drawLine($X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
  177. }
  178. else
  179. {
  180. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  181. imageline($this->Picture,$X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
  182. imageline($this->Picture,$X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
  183. imageline($this->Picture,$X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
  184. imageline($this->Picture,$X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
  185. }
  186. $Step = 360 / (2 * PI * $Radius);
  187. for($i=0;$i<=90;$i=$i+$Step)
  188. {
  189. $X = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  190. $Y = sin(($i+180)*PI/180) * $Radius + $Y1 + $Radius;
  191. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  192. $X = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  193. $Y = sin(($i+90)*PI/180) * $Radius + $Y2 - $Radius;
  194. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  195. $X = cos($i*PI/180) * $Radius + $X2 - $Radius;
  196. $Y = sin($i*PI/180) * $Radius + $Y2 - $Radius;
  197. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  198. $X = cos(($i+270)*PI/180) * $Radius + $X2 - $Radius;
  199. $Y = sin(($i+270)*PI/180) * $Radius + $Y1 + $Radius;
  200. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  201. }
  202. }
  203. /* Draw a rectangle with rounded corners */
  204. function drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  205. {
  206. $R = isset($Format["R"]) ? $Format["R"] : 0;
  207. $G = isset($Format["G"]) ? $Format["G"] : 0;
  208. $B = isset($Format["B"]) ? $Format["B"] : 0;
  209. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  210. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  211. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  212. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  213. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  214. /* Temporary fix for AA issue */
  215. $Y1 = floor($Y1); $Y2 = floor($Y2); $X1 = floor($X1); $X2 = floor($X2);
  216. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  217. if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }
  218. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  219. if ( $X2 - $X1 < $Radius*2 ) { $Radius = floor((($X2-$X1))/4); }
  220. if ( $Y2 - $Y1 < $Radius*2 ) { $Radius = floor((($Y2-$Y1))/4); }
  221. $RestoreShadow = $this->Shadow;
  222. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  223. {
  224. $this->Shadow = FALSE;
  225. $this->drawRoundedFilledRectangle($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  226. }
  227. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);
  228. if ( $Radius <= 0 ) { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }
  229. $YTop = $Y1+$Radius;
  230. $YBottom = $Y2-$Radius;
  231. $Step = 360 / (2 * PI * $Radius);
  232. $Positions = ""; $Radius--; $MinY = ""; $MaxY = "";
  233. for($i=0;$i<=90;$i=$i+$Step)
  234. {
  235. $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  236. $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
  237. $Yp = floor(sin(($i+180)*PI/180) * $Radius + $YTop);
  238. if ( $MinY == "" || $Yp > $MinY ) { $MinY = $Yp; }
  239. if ( $Xp2 >= floor($X2) ) { $Xp2--; }
  240. $Xp1++;
  241. if ( !isset($Positions[$Yp]) )
  242. { $Positions[$Yp]["X1"] = $Xp1; $Positions[$Yp]["X2"] = $Xp2; }
  243. else
  244. { $Positions[$Yp]["X1"] = ($Positions[$Yp]["X1"]+$Xp1)/2; $Positions[$Yp]["X2"] = ($Positions[$Yp]["X2"]+$Xp2)/2; }
  245. $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  246. $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
  247. $Yp = floor(sin(($i+90)*PI/180) * $Radius + $YBottom);
  248. if ( $MaxY == "" || $Yp < $MaxY ) { $MaxY = $Yp; }
  249. if ( $Xp2 >= floor($X2) ) { $Xp2--; }
  250. $Xp1++;
  251. if ( !isset($Positions[$Yp]) )
  252. { $Positions[$Yp]["X1"] = $Xp1; $Positions[$Yp]["X2"] = $Xp2; }
  253. else
  254. { $Positions[$Yp]["X1"] = ($Positions[$Yp]["X1"]+$Xp1)/2; $Positions[$Yp]["X2"] = ($Positions[$Yp]["X2"]+$Xp2)/2; }
  255. }
  256. $ManualColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  257. foreach($Positions as $Yp => $Bounds)
  258. {
  259. $X1 = $Bounds["X1"]; $X1Dec = $this->getFirstDecimal($X1); if ( $X1Dec != 0 ) { $X1 = floor($X1)+1; }
  260. $X2 = $Bounds["X2"]; $X2Dec = $this->getFirstDecimal($X2); if ( $X2Dec != 0 ) { $X2 = floor($X2)-1; }
  261. imageline($this->Picture,$X1,$Yp,$X2,$Yp,$ManualColor);
  262. }
  263. $this->drawFilledRectangle($X1,$MinY+1,floor($X2),$MaxY-1,$Color);
  264. $Radius++;
  265. $this->drawRoundedRectangle($X1,$Y1,$X2+1,$Y2-1,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  266. $this->Shadow = $RestoreShadow;
  267. }
  268. /* Draw a rectangle with rounded corners */
  269. function drawRoundedFilledRectangle_deprecated($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  270. {
  271. $R = isset($Format["R"]) ? $Format["R"] : 0;
  272. $G = isset($Format["G"]) ? $Format["G"] : 0;
  273. $B = isset($Format["B"]) ? $Format["B"] : 0;
  274. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  275. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  276. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  277. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  278. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  279. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  280. if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }
  281. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  282. if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1)+2)/2); }
  283. if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1)+2)/2); }
  284. $RestoreShadow = $this->Shadow;
  285. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  286. {
  287. $this->Shadow = FALSE;
  288. $this->drawRoundedFilledRectangle($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  289. }
  290. if ( $this->getFirstDecimal($X2) >= 5 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  291. if ( $this->getFirstDecimal($X1) <= 5 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  292. if ( !$this->Antialias ) { $XOffset1 = 1; $XOffset2 = 1; }
  293. $YTop = floor($Y1+$Radius);
  294. $YBottom = floor($Y2-$Radius);
  295. $this->drawFilledRectangle($X1-$XOffset1,$YTop,$X2+$XOffset2,$YBottom,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE));
  296. $Step = 360 / (2 * PI * $Radius);
  297. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  298. $Color2 = $this->allocateColor($this->Picture,255,0,0,$Alpha);
  299. $Drawn = "";
  300. if ( $Alpha < 100 ) { $Drawn[$YTop] = FALSE; }
  301. if ( $Alpha < 100 ) { $Drawn[$YBottom] = TRUE; }
  302. for($i=0;$i<=90;$i=$i+$Step)
  303. {
  304. $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  305. $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
  306. $Yp = sin(($i+180)*PI/180) * $Radius + $YTop;
  307. if ( $this->getFirstDecimal($Xp1) > 5 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  308. if ( $this->getFirstDecimal($Xp2) > 5 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  309. if ( $this->getFirstDecimal($Yp) > 5 ) { $YOffset = 1; } else { $YOffset = 0; }
  310. if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
  311. imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);
  312. $Drawn[$Yp+$YOffset] = $Xp2;
  313. $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  314. $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
  315. $Yp = sin(($i+90)*PI/180) * $Radius + $YBottom;
  316. if ( $this->getFirstDecimal($Xp1) > 7 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  317. if ( $this->getFirstDecimal($Xp2) > 7 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  318. if ( $this->getFirstDecimal($Yp) > 5 ) { $YOffset = 1; } else { $YOffset = 0; }
  319. if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
  320. imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);
  321. $Drawn[$Yp+$YOffset] = $Xp2;
  322. }
  323. $this->drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  324. $this->Shadow = $RestoreShadow;
  325. }
  326. /* Draw a rectangle */
  327. function drawRectangle($X1,$Y1,$X2,$Y2,$Format="")
  328. {
  329. $R = isset($Format["R"]) ? $Format["R"] : 0;
  330. $G = isset($Format["G"]) ? $Format["G"] : 0;
  331. $B = isset($Format["B"]) ? $Format["B"] : 0;
  332. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  333. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  334. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;
  335. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  336. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  337. if ( $this->Antialias )
  338. {
  339. if ( $NoAngle )
  340. {
  341. $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  342. $this->drawLine($X2,$Y1+1,$X2,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  343. $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  344. $this->drawLine($X1,$Y1+1,$X1,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  345. }
  346. else
  347. {
  348. $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  349. $this->drawLine($X2,$Y1,$X2,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  350. $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  351. $this->drawLine($X1,$Y1,$X1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  352. }
  353. }
  354. else
  355. {
  356. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  357. imagerectangle($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
  358. }
  359. }
  360. /* Draw a filled rectangle */
  361. function drawFilledRectangle($X1,$Y1,$X2,$Y2,$Format="")
  362. {
  363. $R = isset($Format["R"]) ? $Format["R"] : 0;
  364. $G = isset($Format["G"]) ? $Format["G"] : 0;
  365. $B = isset($Format["B"]) ? $Format["B"] : 0;
  366. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  367. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  368. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  369. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  370. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
  371. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  372. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  373. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : NULL;
  374. $Dash = isset($Format["Dash"]) ? $Format["Dash"] : FALSE;
  375. $DashStep = isset($Format["DashStep"]) ? $Format["DashStep"] : 4;
  376. $DashR = isset($Format["DashR"]) ? $Format["DashR"] : 0;
  377. $DashG = isset($Format["DashG"]) ? $Format["DashG"] : 0;
  378. $DashB = isset($Format["DashB"]) ? $Format["DashB"] : 0;
  379. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  380. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  381. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  382. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  383. $RestoreShadow = $this->Shadow;
  384. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  385. {
  386. $this->Shadow = FALSE;
  387. $this->drawFilledRectangle($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks,"NoAngle"=>$NoAngle));
  388. }
  389. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  390. if ( $NoAngle )
  391. {
  392. imagefilledrectangle($this->Picture,ceil($X1)+1,ceil($Y1),floor($X2)-1,floor($Y2),$Color);
  393. imageline($this->Picture,ceil($X1),ceil($Y1)+1,ceil($X1),floor($Y2)-1,$Color);
  394. imageline($this->Picture,floor($X2),ceil($Y1)+1,floor($X2),floor($Y2)-1,$Color);
  395. }
  396. else
  397. imagefilledrectangle($this->Picture,ceil($X1),ceil($Y1),floor($X2),floor($Y2),$Color);
  398. if ( $Dash )
  399. {
  400. if ( $BorderR != -1 ) { $iX1=$X1+1; $iY1=$Y1+1; $iX2=$X2-1; $iY2=$Y2-1; } else { $iX1=$X1; $iY1=$Y1; $iX2=$X2; $iY2=$Y2; }
  401. $Color = $this->allocateColor($this->Picture,$DashR,$DashG,$DashB,$Alpha);
  402. $Y=$iY1-$DashStep;
  403. for($X=$iX1; $X<=$iX2+($iY2-$iY1); $X=$X+$DashStep)
  404. {
  405. $Y=$Y+$DashStep;
  406. if ( $X > $iX2 ) { $Xa = $X-($X-$iX2); $Ya = $iY1+($X-$iX2); } else { $Xa = $X; $Ya = $iY1; }
  407. if ( $Y > $iY2 ) { $Xb = $iX1+($Y-$iY2); $Yb = $Y-($Y-$iY2); } else { $Xb = $iX1; $Yb = $Y; }
  408. imageline($this->Picture,$Xa,$Ya,$Xb,$Yb,$Color);
  409. }
  410. }
  411. if ( $this->Antialias && !$NoBorder )
  412. {
  413. if ( $X1 < ceil($X1) )
  414. {
  415. $AlphaA = $Alpha * (ceil($X1) - $X1);
  416. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  417. imageline($this->Picture,ceil($X1)-1,ceil($Y1),ceil($X1)-1,floor($Y2),$Color);
  418. }
  419. if ( $Y1 < ceil($Y1) )
  420. {
  421. $AlphaA = $Alpha * (ceil($Y1) - $Y1);
  422. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  423. imageline($this->Picture,ceil($X1),ceil($Y1)-1,floor($X2),ceil($Y1)-1,$Color);
  424. }
  425. if ( $X2 > floor($X2) )
  426. {
  427. $AlphaA = $Alpha * (.5-($X2 - floor($X2)));
  428. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  429. imageline($this->Picture,floor($X2)+1,ceil($Y1),floor($X2)+1,floor($Y2),$Color);
  430. }
  431. if ( $Y2 > floor($Y2) )
  432. {
  433. $AlphaA = $Alpha * (.5-($Y2 - floor($Y2)));
  434. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  435. imageline($this->Picture,ceil($X1),floor($Y2)+1,floor($X2),floor($Y2)+1,$Color);
  436. }
  437. }
  438. if ( $BorderR != -1 )
  439. $this->drawRectangle($X1,$Y1,$X2,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks,"NoAngle"=>$NoAngle));
  440. $this->Shadow = $RestoreShadow;
  441. }
  442. /* Draw a rectangular marker of the specified size */
  443. function drawRectangleMarker($X,$Y,$Format="")
  444. {
  445. $Size = isset($Format["Size"]) ? $Format["Size"] : 4;
  446. $HalfSize = floor($Size/2);
  447. $this->drawFilledRectangle($X-$HalfSize,$Y-$HalfSize,$X+$HalfSize,$Y+$HalfSize,$Format);
  448. }
  449. /* Drawn a spline based on the bezier function */
  450. function drawSpline($Coordinates,$Format="")
  451. {
  452. $R = isset($Format["R"]) ? $Format["R"] : 0;
  453. $G = isset($Format["G"]) ? $Format["G"] : 0;
  454. $B = isset($Format["B"]) ? $Format["B"] : 0;
  455. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  456. $Force = isset($Format["Force"]) ? $Format["Force"] : 30;
  457. $Forces = isset($Format["Forces"]) ? $Format["Forces"] : NULL;
  458. $ShowC = isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
  459. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  460. $PathOnly = isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
  461. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  462. $Cpt = NULL; $Mode = NULL; $Result = "";
  463. for($i=1;$i<=count($Coordinates)-1;$i++)
  464. {
  465. $X1 = $Coordinates[$i-1][0]; $Y1 = $Coordinates[$i-1][1];
  466. $X2 = $Coordinates[$i][0]; $Y2 = $Coordinates[$i][1];
  467. if ( $Forces != NULL ) { $Force = $Forces[$i]; }
  468. /* First segment */
  469. if ( $i == 1 )
  470. { $Xv1 = $X1; $Yv1 = $Y1; }
  471. else
  472. {
  473. $Angle1 = $this->getAngle($XLast,$YLast,$X1,$Y1);
  474. $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
  475. $XOff = cos($Angle2 * PI / 180) * $Force + $X1;
  476. $YOff = sin($Angle2 * PI / 180) * $Force + $Y1;
  477. $Xv1 = cos($Angle1 * PI / 180) * $Force + $XOff;
  478. $Yv1 = sin($Angle1 * PI / 180) * $Force + $YOff;
  479. }
  480. /* Last segment */
  481. if ( $i == count($Coordinates)-1 )
  482. { $Xv2 = $X2; $Yv2 = $Y2; }
  483. else
  484. {
  485. $Angle1 = $this->getAngle($X2,$Y2,$Coordinates[$i+1][0],$Coordinates[$i+1][1]);
  486. $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
  487. $XOff = cos(($Angle2+180) * PI / 180) * $Force + $X2;
  488. $YOff = sin(($Angle2+180) * PI / 180) * $Force + $Y2;
  489. $Xv2 = cos(($Angle1+180) * PI / 180) * $Force + $XOff;
  490. $Yv2 = sin(($Angle1+180) * PI / 180) * $Force + $YOff;
  491. }
  492. $Path = $this->drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format);
  493. if ($PathOnly) { $Result[] = $Path; }
  494. $XLast = $X1; $YLast = $Y1;
  495. }
  496. return($Result);
  497. }
  498. /* Draw a bezier curve with two controls points */
  499. function drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format="")
  500. {
  501. $R = isset($Format["R"]) ? $Format["R"] : 0;
  502. $G = isset($Format["G"]) ? $Format["G"] : 0;
  503. $B = isset($Format["B"]) ? $Format["B"] : 0;
  504. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  505. $ShowC = isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
  506. $Segments = isset($Format["Segments"]) ? $Format["Segments"] : NULL;
  507. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  508. $NoDraw = isset($Format["NoDraw"]) ? $Format["NoDraw"] : FALSE;
  509. $PathOnly = isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
  510. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  511. $DrawArrow = isset($Format["DrawArrow"]) ? $Format["DrawArrow"] : FALSE;
  512. $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 10;
  513. $ArrowRatio = isset($Format["ArrowRatio"]) ? $Format["ArrowRatio"] : .5;
  514. $ArrowTwoHeads = isset($Format["ArrowTwoHeads"]) ? $Format["ArrowTwoHeads"] : FALSE;
  515. if ( $Segments == NULL )
  516. {
  517. $Length = $this->getLength($X1,$Y1,$X2,$Y2);
  518. $Precision = ($Length*125)/1000;
  519. }
  520. else
  521. $Precision = $Segments;
  522. $P[0]["X"] = $X1; $P[0]["Y"] = $Y1;
  523. $P[1]["X"] = $Xv1; $P[1]["Y"] = $Yv1;
  524. $P[2]["X"] = $Xv2; $P[2]["Y"] = $Yv2;
  525. $P[3]["X"] = $X2; $P[3]["Y"] = $Y2;
  526. /* Compute the bezier points */
  527. $Q = ""; $ID = 0; $Path = "";
  528. for($i=0;$i<=$Precision;$i=$i+1)
  529. {
  530. $u = $i / $Precision;
  531. $C = "";
  532. $C[0] = (1 - $u) * (1 - $u) * (1 - $u);
  533. $C[1] = ($u * 3) * (1 - $u) * (1 - $u);
  534. $C[2] = 3 * $u * $u * (1 - $u);
  535. $C[3] = $u * $u * $u;
  536. for($j=0;$j<=3;$j++)
  537. {
  538. if ( !isset($Q[$ID]) ) { $Q[$ID] = ""; }
  539. if ( !isset($Q[$ID]["X"]) ) { $Q[$ID]["X"] = 0; }
  540. if ( !isset($Q[$ID]["Y"]) ) { $Q[$ID]["Y"] = 0; }
  541. $Q[$ID]["X"] = $Q[$ID]["X"] + $P[$j]["X"] * $C[$j];
  542. $Q[$ID]["Y"] = $Q[$ID]["Y"] + $P[$j]["Y"] * $C[$j];
  543. }
  544. $ID++;
  545. }
  546. $Q[$ID]["X"] = $X2; $Q[$ID]["Y"] = $Y2;
  547. if ( !$NoDraw )
  548. {
  549. /* Display the control points */
  550. if ( $ShowC && !$PathOnly )
  551. {
  552. $Xv1 = floor($Xv1); $Yv1 = floor($Yv1); $Xv2 = floor($Xv2); $Yv2 = floor($Yv2);
  553. $this->drawLine($X1,$Y1,$X2,$Y2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));
  554. $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  555. $this->drawRectangleMarker($Xv1,$Yv1,$MyMarkerSettings);
  556. $this->drawText($Xv1+4,$Yv1,"v1");
  557. $MyMarkerSettings = array("R"=>0,"G"=>0,"B"=>255,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  558. $this->drawRectangleMarker($Xv2,$Yv2,$MyMarkerSettings);
  559. $this->drawText($Xv2+4,$Yv2,"v2");
  560. }
  561. /* Draw the bezier */
  562. $LastX = NULL; $LastY = NULL; $Cpt = NULL; $Mode = NULL; $ArrowS = NULL;
  563. foreach ($Q as $Key => $Point)
  564. {
  565. $X = $Point["X"]; $Y = $Point["Y"];
  566. /* Get the first segment */
  567. if ( $ArrowS == NULL && $LastX != NULL && $LastY != NULL )
  568. { $ArrowS["X2"] = $LastX; $ArrowS["Y2"] = $LastY; $ArrowS["X1"] = $X; $ArrowS["Y1"] = $Y; }
  569. if ( $LastX != NULL && $LastY != NULL && !$PathOnly)
  570. list($Cpt,$Mode) = $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Cpt"=>$Cpt,"Mode"=>$Mode,"Weight"=>$Weight));
  571. /* Get the last segment */
  572. $ArrowE["X1"] = $LastX; $ArrowE["Y1"] = $LastY; $ArrowE["X2"] = $X; $ArrowE["Y2"] = $Y;
  573. $LastX = $X; $LastY = $Y;
  574. }
  575. if ( $DrawArrow && !$PathOnly )
  576. {
  577. $ArrowSettings = array("FillR"=>$R,"FillG"=>$G,"FillB"=>$B,"Alpha"=>$Alpha,"Size"=>$ArrowSize,"Ratio"=>$ArrowRatio);
  578. if ( $ArrowTwoHeads )
  579. $this->drawArrow($ArrowS["X1"],$ArrowS["Y1"],$ArrowS["X2"],$ArrowS["Y2"],$ArrowSettings);
  580. $this->drawArrow($ArrowE["X1"],$ArrowE["Y1"],$ArrowE["X2"],$ArrowE["Y2"],$ArrowSettings);
  581. }
  582. }
  583. return($Q);
  584. }
  585. /* Draw a line between two points */
  586. function drawLine($X1,$Y1,$X2,$Y2,$Format="")
  587. {
  588. $R = isset($Format["R"]) ? $Format["R"] : 0;
  589. $G = isset($Format["G"]) ? $Format["G"] : 0;
  590. $B = isset($Format["B"]) ? $Format["B"] : 0;
  591. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  592. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  593. $Cpt = isset($Format["Cpt"]) ? $Format["Cpt"] : 1;
  594. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : 1;
  595. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  596. if ( $this->Antialias == FALSE && $Ticks == NULL )
  597. {
  598. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  599. {
  600. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  601. imageline($this->Picture,$X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$ShadowColor);
  602. }
  603. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  604. imageline($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
  605. return(0);
  606. }
  607. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  608. if ( $Distance == 0 ) { return(-1); }
  609. /* Derivative algorithm for overweighted lines, re-route to polygons primitives */
  610. if ( $Weight != NULL )
  611. {
  612. $Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
  613. $PolySettings = array ("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderAlpha"=>$Alpha);
  614. if ( $Ticks == NULL )
  615. {
  616. $Points = "";
  617. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y1;
  618. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y1;
  619. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y2;
  620. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y2;
  621. $this->drawPolygon($Points,$PolySettings);
  622. }
  623. else
  624. {
  625. for($i=0;$i<=$Distance;$i=$i+$Ticks*2)
  626. {
  627. $Xa = (($X2-$X1)/$Distance) * $i + $X1; $Ya = (($Y2-$Y1)/$Distance) * $i + $Y1;
  628. $Xb = (($X2-$X1)/$Distance) * ($i+$Ticks) + $X1; $Yb = (($Y2-$Y1)/$Distance) * ($i+$Ticks) + $Y1;
  629. $Points = "";
  630. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Ya;
  631. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Ya;
  632. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Yb;
  633. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Yb;
  634. $this->drawPolygon($Points,$PolySettings);
  635. }
  636. }
  637. return(1);
  638. }
  639. $XStep = ($X2-$X1) / $Distance;
  640. $YStep = ($Y2-$Y1) / $Distance;
  641. for($i=0;$i<=$Distance;$i++)
  642. {
  643. $X = $i * $XStep + $X1;
  644. $Y = $i * $YStep + $Y1;
  645. if ( $Ticks != NULL )
  646. {
  647. if ( $Cpt % $Ticks == 0 )
  648. { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }
  649. if ( $Mode == 1 )
  650. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  651. $Cpt++;
  652. }
  653. else
  654. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  655. }
  656. return(array($Cpt,$Mode));
  657. }
  658. /* Draw a circle */
  659. function drawCircle($Xc,$Yc,$Height,$Width,$Format="")
  660. {
  661. $R = isset($Format["R"]) ? $Format["R"] : 0;
  662. $G = isset($Format["G"]) ? $Format["G"] : 0;
  663. $B = isset($Format["B"]) ? $Format["B"] : 0;
  664. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  665. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  666. $Height = abs($Height);
  667. $Width = abs($Width);
  668. if ( $Height == 0 ) { $Height = 1; }
  669. if ( $Width == 0 ) { $Width = 1; }
  670. $Xc = floor($Xc); $Yc = floor($Yc);
  671. $RestoreShadow = $this->Shadow;
  672. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  673. {
  674. $this->Shadow = FALSE;
  675. $this->drawCircle($Xc+$this->ShadowX,$Yc+$this->ShadowY,$Height,$Width,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks));
  676. }
  677. if ( $Width == 0 ) { $Width = $Height; }
  678. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  679. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  680. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  681. $Step = 360 / (2 * PI * max($Width,$Height));
  682. $Mode = 1; $Cpt = 1;
  683. for($i=0;$i<=360;$i=$i+$Step)
  684. {
  685. $X = cos($i*PI/180) * $Height + $Xc;
  686. $Y = sin($i*PI/180) * $Width + $Yc;
  687. if ( $Ticks != NULL )
  688. {
  689. if ( $Cpt % $Ticks == 0 )
  690. { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }
  691. if ( $Mode == 1 )
  692. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  693. $Cpt++;
  694. }
  695. else
  696. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  697. }
  698. $this->Shadow = $RestoreShadow;
  699. }
  700. /* Draw a filled circle */
  701. function drawFilledCircle($X,$Y,$Radius,$Format="")
  702. {
  703. $R = isset($Format["R"]) ? $Format["R"] : 0;
  704. $G = isset($Format["G"]) ? $Format["G"] : 0;
  705. $B = isset($Format["B"]) ? $Format["B"] : 0;
  706. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  707. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  708. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  709. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  710. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
  711. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  712. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  713. if ( $Radius == 0 ) { $Radius = 1; }
  714. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  715. $X = floor($X); $Y = floor($Y);
  716. $Radius = abs($Radius);
  717. $RestoreShadow = $this->Shadow;
  718. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  719. {
  720. $this->Shadow = FALSE;
  721. $this->drawFilledCircle($X+$this->ShadowX,$Y+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks));
  722. }
  723. $this->Mask = "";
  724. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  725. for ($i=0; $i<=$Radius*2; $i++)
  726. {
  727. $Slice = sqrt($Radius * $Radius - ($Radius - $i) * ($Radius - $i));
  728. $XPos = floor($Slice);
  729. $YPos = $Y + $i - $Radius;
  730. $AAlias = $Slice - floor($Slice);
  731. $this->Mask[$X-$XPos][$YPos] = TRUE;
  732. $this->Mask[$X+$XPos][$YPos] = TRUE;
  733. imageline($this->Picture,$X-$XPos,$YPos,$X+$XPos,$YPos,$Color);
  734. }
  735. if ( $this->Antialias )
  736. $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  737. $this->Mask = "";
  738. if ( $BorderR != -1 )
  739. $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks));
  740. $this->Shadow = $RestoreShadow;
  741. }
  742. /* Write text */
  743. function drawText($X,$Y,$Text,$Format="")
  744. {
  745. $R = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
  746. $G = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
  747. $B = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
  748. $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
  749. $Align = isset($Format["Align"]) ? $Format["Align"] : TEXT_ALIGN_BOTTOMLEFT;
  750. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
  751. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  752. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  753. $ShowOrigine = isset($Format["ShowOrigine"]) ? $Format["ShowOrigine"] : FALSE;
  754. $TOffset = isset($Format["TOffset"]) ? $Format["TOffset"] : 2;
  755. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : FALSE;
  756. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : TRUE;
  757. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 6;
  758. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : FALSE;
  759. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 6;
  760. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 255;
  761. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 255;
  762. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 255;
  763. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
  764. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  765. $BoxBorderR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  766. $BoxBorderG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  767. $BoxBorderB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  768. $BoxBorderAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
  769. $NoShadow = isset($Format["NoShadow"]) ? $Format["NoShadow"] : FALSE;
  770. $Shadow = $this->Shadow;
  771. if ( $NoShadow ) { $this->Shadow = FALSE; }
  772. if ( $BoxSurrounding != "" ) { $BoxBorderR = $BoxR - $BoxSurrounding; $BoxBorderG = $BoxG - $BoxSurrounding; $BoxBorderB = $BoxB - $BoxSurrounding; $BoxBorderAlpha = $Boxalpha; }
  773. if ( $ShowOrigine )
  774. {
  775. $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  776. $this->drawRectangleMarker($X,$Y,$MyMarkerSettings);
  777. }
  778. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,$Angle,$Text);
  779. if ( $DrawBox && ($Angle == 0 || $Angle == 90 || $Angle == 180 || $Angle == 270))
  780. {
  781. $T[0]["X"]=0;$T[0]["Y"]=0;$T[1]["X"]=0;$T[1]["Y"]=0;$T[2]["X"]=0;$T[2]["Y"]=0;$T[3]["X"]=0;$T[3]["Y"]=0;
  782. if ( $Angle == 0 ) { $T[0]["X"]=-$TOffset;$T[0]["Y"]=$TOffset;$T[1]["X"]=$TOffset;$T[1]["Y"]=$TOffset;$T[2]["X"]=$TOffset;$T[2]["Y"]=-$TOffset;$T[3]["X"]=-$TOffset;$T[3]["Y"]=-$TOffset; }
  783. $X1 = min($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) - $BorderOffset + 3;
  784. $Y1 = min($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) - $BorderOffset;
  785. $X2 = max($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) + $BorderOffset + 3;
  786. $Y2 = max($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) + $BorderOffset - 3;
  787. $X1 = $X1 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
  788. $Y1 = $Y1 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
  789. $X2 = $X2 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
  790. $Y2 = $Y2 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
  791. $Settings = array("R"=>$BoxR,"G"=>$BoxG,"B"=>$BoxB,"Alpha"=>$BoxAlpha,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"BorderAlpha"=>$BoxBorderAlpha);
  792. if ( $BoxRounded )
  793. { $this->drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$RoundedRadius,$Settings); }
  794. else
  795. { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Settings); }
  796. }
  797. $X = $X - $TxtPos[$Align]["X"] + $X;
  798. $Y = $Y - $TxtPos[$Align]["Y"] + $Y;
  799. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  800. {
  801. $C_ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  802. imagettftext($this->Picture,$FontSize,$Angle,$X+$this->ShadowX,$Y+$this->ShadowY,$C_ShadowColor,$FontName,$Text);
  803. }
  804. $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B,$Alpha);
  805. imagettftext($this->Picture,$FontSize,$Angle,$X,$Y,$C_TextColor,$FontName,$Text);
  806. $this->Shadow = $Shadow;
  807. return($TxtPos);
  808. }
  809. /* Draw a gradient within a defined area */
  810. function drawGradientArea($X1,$Y1,$X2,$Y2,$Direction,$Format="")
  811. {
  812. $StartR = isset($Format["StartR"]) ? $Format["StartR"] : 90;
  813. $StartG = isset($Format["StartG"]) ? $Format["StartG"] : 90;
  814. $StartB = isset($Format["StartB"]) ? $Format["StartB"] : 90;
  815. $EndR = isset($Format["EndR"]) ? $Format["EndR"] : 0;
  816. $EndG = isset($Format["EndG"]) ? $Format["EndG"] : 0;
  817. $EndB = isset($Format["EndB"]) ? $Format["EndB"] : 0;
  818. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  819. $Levels = isset($Format["Levels"]) ? $Format["Levels"] : NULL;
  820. $Shadow = $this->Shadow;
  821. $this->Shadow = FALSE;
  822. if ( $StartR == $EndR && $StartG == $EndG && $StartB == $EndB )
  823. {
  824. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,array("R"=>$StartR,"G"=>$StartG,"B"=>$StartB,"Alpha"=>$Alpha));
  825. return(0);
  826. }
  827. if ( $Levels != NULL )
  828. { $EndR=$StartR+$Levels; $EndG=$StartG+$Levels; $EndB=$StartB+$Levels; }
  829. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  830. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  831. if ( $Direction == DIRECTION_VERTICAL ) { $Width = abs($Y2-$Y1); }
  832. if ( $Direction == DIRECTION_HORIZONTAL ) { $Width = abs($X2-$X1); }
  833. $Step = max(abs($EndR-$StartR),abs($EndG-$StartG),abs($EndB-$StartB));
  834. $StepSize = $Width/$Step;
  835. $RStep = ($EndR-$StartR)/$Step;
  836. $GStep = ($EndG-$StartG)/$Step;
  837. $BStep = ($EndB-$StartB)/$Step;
  838. $R=$StartR;$G=$StartG;$B=$StartB;
  839. switch($Direction)
  840. {
  841. case DIRECTION_VERTICAL:
  842. $StartY = $Y1; $EndY = floor($Y2)+1; $LastY2 = $StartY;
  843. for($i=0;$i<=$Step;$i++)
  844. {
  845. $Y2 = floor($StartY + ($i * $StepSize));
  846. if ($Y2 > $EndY) { $Y2 = $EndY; }
  847. if (($Y1 != $Y2 && $Y1 < $Y2) || $Y2 == $EndY)
  848. {
  849. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  850. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
  851. $LastY2 = max($LastY2,$Y2);
  852. $Y1 = $Y2+1;
  853. }
  854. $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep;
  855. }
  856. if ( $LastY2 < $EndY && isset($Color)) { for ($i=$LastY2+1;$i<=$EndY;$i++) { $this->drawLine($X1,$i,$X2,$i,$Color); } }
  857. break;
  858. case DIRECTION_HORIZONTAL:
  859. $StartX = $X1; $EndX = $X2;
  860. for($i=0;$i<=$Step;$i++)
  861. {
  862. $X2 = floor($StartX + ($i * $StepSize));
  863. if ($X2 > $EndX) { $X2 = $EndX; }
  864. if (($X1 != $X2 && $X1 < $X2) || $X2 == $EndX)
  865. {
  866. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  867. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
  868. $X1 = $X2+1;
  869. }
  870. $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep;
  871. }
  872. if ( $X2 < $EndX && isset($Color)) { $this->drawFilledRectangle($X2,$Y1,$EndX,$Y2,$Color); }
  873. break;
  874. }
  875. $this->Shadow = $Shadow;
  876. }
  877. /* Draw an aliased pixel */
  878. function drawAntialiasPixel($X,$Y,$Format="")
  879. {
  880. $R = isset($Format["R"]) ? $Format["R"] : 0;
  881. $G = isset($Format["G"]) ? $Format["G"] : 0;
  882. $B = isset($Format["B"]) ? $Format["B"] : 0;
  883. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  884. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  885. return(-1);
  886. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  887. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  888. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  889. if ( !$this->Antialias )
  890. {
  891. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  892. {
  893. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  894. imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
  895. }
  896. $PlotColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  897. imagesetpixel($this->Picture,$X,$Y,$PlotColor);
  898. return(0);
  899. }
  900. $Plot = "";
  901. $Xi = floor($X);
  902. $Yi = floor($Y);
  903. if ( $Xi == $X && $Yi == $Y)
  904. {
  905. if ( $Alpha == 100 )
  906. $this->drawAlphaPixel($X,$Y,100,$R,$G,$B);
  907. else
  908. $this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B);
  909. }
  910. else
  911. {
  912. $Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  913. if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); }
  914. $Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  915. if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); }
  916. $Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  917. if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); }
  918. $Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  919. if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); }
  920. }
  921. }
  922. /* Draw a semi-transparent pixel */
  923. function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
  924. {
  925. if ( isset($this->Mask[$X])) { if ( isset($this->Mask[$X][$Y]) ) { return(0); } }
  926. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  927. return(-1);
  928. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  929. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  930. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  931. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  932. {
  933. $AlphaFactor = floor(($Alpha / 100) * $this->Shadowa);
  934. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$AlphaFactor);
  935. imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
  936. }
  937. $C_Aliased = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  938. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  939. }
  940. /* Convert apha to base 10 */
  941. function convertAlpha($AlphaValue)
  942. { return((127/100)*(100-$AlphaValue)); }
  943. /* Allocate a color with transparency */
  944. function allocateColor($Picture,$R,$G,$B,$Alpha=100)
  945. {
  946. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  947. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  948. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  949. if ( $Alpha < 0 ) { $Alpha = 0; }
  950. if ( $Alpha > 100) { $Alpha = 100; }
  951. $Alpha = $this->convertAlpha($Alpha);
  952. return(imagecolorallocatealpha($Picture,$R,$G,$B,$Alpha));
  953. }
  954. /* Load a PNG file and draw it over the chart */
  955. function drawFromPNG($X,$Y,$FileName)
  956. { $this->drawFromPicture(1,$FileName,$X,$Y); }
  957. /* Load a GIF file and draw it over the chart */
  958. function drawFromGIF($X,$Y,$FileName)
  959. { $this->drawFromPicture(2,$FileName,$X,$Y); }
  960. /* Load a JPEG file and draw it over the chart */
  961. function drawFromJPG($X,$Y,$FileName)
  962. { $this->drawFromPicture(3,$FileName,$X,$Y); }
  963. function getPicInfo($FileName)
  964. {
  965. $Infos = getimagesize($FileName);
  966. $Width = $Infos[0];
  967. $Height = $Infos[1];
  968. $Type = $Infos["mime"];
  969. if ( $Type == "image/png") { $Type = 1; }
  970. if ( $Type == "image/gif") { $Type = 2; }
  971. if ( $Type == "image/jpeg ") { $Type = 3; }
  972. return(array($Width,$Height,$Type));
  973. }
  974. /* Generic loader function for external pictures */
  975. function drawFromPicture($PicType,$FileName,$X,$Y)
  976. {
  977. if ( file_exists($FileName))
  978. {
  979. list($Width,$Height) = $this->getPicInfo($FileName);
  980. if ( $PicType == 1 )
  981. { $Raster = imagecreatefrompng($FileName); }
  982. elseif ( $PicType == 2 )
  983. { $Raster = imagecreatefromgif($FileName); }
  984. elseif ( $PicType == 3 )
  985. { $Raster = imagecreatefromjpeg($FileName); }
  986. else
  987. { return(0); }
  988. $RestoreShadow = $this->Shadow;
  989. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  990. {
  991. $this->Shadow = FALSE;
  992. if ( $PicType == 3 )
  993. $this->drawFilledRectangle($X+$this->ShadowX,$Y+$this->ShadowY,$X+$Width+$this->ShadowX,$Y+$Height+$this->ShadowY,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  994. else
  995. {
  996. $TranparentID = imagecolortransparent($Raster);
  997. for ($Xc=0;$Xc<=$Width-1;$Xc++)
  998. {
  999. for ($Yc=0;$Yc<=$Height-1;$Yc++)
  1000. {
  1001. $RGBa = imagecolorat($Raster,$Xc,$Yc);
  1002. $Values = imagecolorsforindex($Raster,$RGBa);
  1003. if ( $Values["alpha"] < 120 )
  1004. {
  1005. $AlphaFactor = floor(($this->Shadowa / 100) * ((100 / 127) * (127-$Values["alpha"])));
  1006. $this->drawAlphaPixel($X+$Xc+$this->ShadowX,$Y+$Yc+$this->ShadowY,$AlphaFactor,$this->ShadowR,$this->ShadowG,$this->ShadowB);
  1007. }
  1008. }
  1009. }
  1010. }
  1011. }
  1012. $this->Shadow = $RestoreShadow;
  1013. imagecopy($this->Picture,$Raster,$X,$Y,0,0,$Width,$Height);
  1014. imagedestroy($Raster);
  1015. }
  1016. }
  1017. /* Draw an arrow */
  1018. function drawArrow($X1,$Y1,$X2,$Y2,$Format="")
  1019. {
  1020. $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
  1021. $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
  1022. $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
  1023. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
  1024. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
  1025. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
  1026. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1027. $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
  1028. $Ratio = isset($Format["Ratio"]) ? $Format["Ratio"] : .5;
  1029. $TwoHeads = isset($Format["TwoHeads"]) ? $Format["TwoHeads"] : FALSE;
  1030. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : FALSE;
  1031. /* Calculate the line angle */
  1032. $Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
  1033. /* Override Shadow support, this will be managed internally */
  1034. $RestoreShadow = $this->Shadow;
  1035. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  1036. {
  1037. $this->Shadow = FALSE;
  1038. $this->drawArrow($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,array("FillR"=>$this->ShadowR,"FillG"=>$this->ShadowG,"FillB"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Size"=>$Size,"Ratio"=>$Ratio,"TwoHeads"=>$TwoHeads,"Ticks"=>$Ticks));
  1039. }
  1040. /* Draw the 1st Head */
  1041. $TailX = cos(($Angle-180)*PI/180)*$Size+$X2;
  1042. $TailY = sin(($Angle-180)*PI/180)*$Size+$Y2;
  1043. $Points = "";
  1044. $Points[] = $X2; $Points[] = $Y2;
  1045. $Points[] = cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY;
  1046. $Points[] = cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY;
  1047. $Points[] = $X2; $Points[] = $Y2;
  1048. /* Visual correction */
  1049. if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
  1050. if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }
  1051. $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
  1052. ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);
  1053. $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1054. $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1055. $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1056. /* Draw the second head */
  1057. if ( $TwoHeads )
  1058. {
  1059. $Angle = $this->getAngle($X2,$Y2,$X1,$Y1);
  1060. $TailX2 = cos(($Angle-180)*PI/180)*$Size+$X1;
  1061. $TailY2 = sin(($Angle-180)*PI/180)*$Size+$Y1;
  1062. $Points = "";
  1063. $Points[] = $X1; $Points[] = $Y1;
  1064. $Points[] = cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY2;
  1065. $Points[] = cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY2;
  1066. $Points[] = $X1; $Points[] = $Y1;
  1067. /* Visual correction */
  1068. if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
  1069. if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }
  1070. $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
  1071. ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);
  1072. $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1073. $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1074. $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1075. $this->drawLine($TailX,$TailY,$TailX2,$TailY2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1076. }
  1077. else
  1078. $this->drawLine($X1,$Y1,$TailX,$TailY,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1079. /* Re-enable shadows */
  1080. $this->Shadow = $RestoreShadow;
  1081. }
  1082. /* Draw a label with associated arrow */
  1083. function drawArrowLabel($X1,$Y1,$Text,$Format="")
  1084. {
  1085. $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
  1086. $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
  1087. $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
  1088. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
  1089. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
  1090. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
  1091. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1092. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1093. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1094. $Length = isset($Format["Length"]) ? $Format["Length"] : 50;
  1095. $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 315;
  1096. $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
  1097. $Position = isset($Format["Position"]) ? $Format["Position"] : POSITION_TOP;
  1098. $RoundPos = isset($Format["RoundPos"]) ? $Format["RoundPos"] : FALSE;
  1099. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  1100. $Angle = $Angle % 360;
  1101. $X2 = sin(($Angle+180)*PI/180)*$Length+$X1;
  1102. $Y2 = cos(($Angle+180)*PI/180)*$Length+$Y1;
  1103. if ( $RoundPos && $Angle > 0 && $Angle < 180 ) { $Y2 = ceil($Y2); }
  1104. if ( $RoundPos && $Angle > 180 ) { $Y2 = floor($Y2); }
  1105. $this->drawArrow($X2,$Y2,$X1,$Y1,$Format);
  1106. $Size = imagettfbbox($FontSize,0,$FontName,$Text);
  1107. $TxtWidth = max(abs($Size[2]-$Size[0]),abs($Size[0]-$Size[6]));
  1108. $TxtHeight = max(abs($Size[1]-$Size[7]),abs($Size[3]-$Size[1]));
  1109. if ( $Angle > 0 && $Angle < 180 )
  1110. {
  1111. $this->drawLine($X2,$Y2,$X2-$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1112. if ( $Position == POSITION_TOP )
  1113. $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_BOTTOMRIGHT));
  1114. else
  1115. $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPRIGHT));
  1116. }
  1117. else
  1118. {
  1119. $this->drawLine($X2,$Y2,$X2+$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1120. if ( $Position == POSITION_TOP )
  1121. $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1122. else
  1123. $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPLEFT));
  1124. }
  1125. }
  1126. /* Draw a progress bar filled with specified % */
  1127. function drawProgress($X,$Y,$Percent,$Format="")
  1128. {
  1129. if ( $Percent > 100 ) { $Percent = 100; }
  1130. if ( $Percent < 0 ) { $Percent = 0; }
  1131. $Width = isset($Format["Width"]) ? $Format["Width"] : 200;
  1132. $Height = isset($Format["Height"]) ? $Format["Height"] : 20;
  1133. $Orientation = isset($Format["Orientation"]) ? $Format["Orientation"] : ORIENTATION_HORIZONTAL;
  1134. $ShowLabel = isset($Format["ShowLabel"]) ? $Format["ShowLabel"] : FALSE;
  1135. $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : LABEL_POS_INSIDE;
  1136. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 10;
  1137. $R = isset($Format["R"]) ? $Format["R"] : 130;
  1138. $G = isset($Format["G"]) ? $Format["G"] : 130;
  1139. $B = isset($Format["B"]) ? $Format["B"] : 130;
  1140. $RFade = isset($Format["RFade"]) ? $Format["RFade"] : -1;
  1141. $GFade = isset($Format["GFade"]) ? $Format["GFade"] : -1;
  1142. $BFade = isset($Format["BFade"]) ? $Format["BFade"] : -1;
  1143. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  1144. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  1145. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  1146. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 0;
  1147. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 0;
  1148. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 0;
  1149. $BoxBackR = isset($Format["BoxBackR"]) ? $Format["BoxBackR"] : 255;
  1150. $BoxBackG = isset($Format["BoxBackG"]) ? $Format["BoxBackG"] : 255;
  1151. $BoxBackB = isset($Format["BoxBackB"]) ? $Format["BoxBackB"] : 255;
  1152. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1153. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  1154. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : NULL;
  1155. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;
  1156. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1157. {
  1158. $RFade = (($RFade-$R)/100)*$Percent+$R;
  1159. $GFade = (($GFade-$G)/100)*$Percent+$G;
  1160. $BFade = (($BFade-$B)/100)*$Percent+$B;
  1161. }
  1162. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  1163. if ( $BoxSurrounding != NULL ) { $BoxBorderR = $BoxBackR + $Surrounding; $BoxBorderG = $BoxBackG + $Surrounding; $BoxBorderB = $BoxBackB + $Surrounding; }
  1164. if ( $Orientation == ORIENTATION_VERTICAL )
  1165. {
  1166. $InnerHeight = (($Height-2)/100)*$Percent;
  1167. $this->drawFilledRectangle($X,$Y,$X+$Width,$Y-$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));
  1168. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1169. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1170. {
  1171. $GradientOptions = array("StartR"=>$RFade,"StartG"=>$GFade,"StartB"=>$BFade,"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  1172. $this->drawGradientArea($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,DIRECTION_VERTICAL,$GradientOptions);
  1173. if ( $Surrounding )
  1174. $this->drawRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
  1175. }
  1176. else
  1177. $this->drawFilledRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1178. $this->Shadow = $RestoreShadow;
  1179. if ( $ShowLabel && $LabelPos == LABEL_POS_BOTTOM ) { $this->drawText($X+($Width/2),$Y+$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_TOPMIDDLE)); }
  1180. if ( $ShowLabel && $LabelPos == LABEL_POS_TOP ) { $this->drawText($X+($Width/2),$Y-$Height-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
  1181. if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE ) { $this->drawText($X+($Width/2),$Y-$InnerHeight-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT,"Angle"=>90)); }
  1182. if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER ) { $this->drawText($X+($Width/2),$Y-($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"Angle"=>90)); }
  1183. }
  1184. else
  1185. {
  1186. if ( $Percent == 100 )
  1187. $InnerWidth = $Width-1;
  1188. else
  1189. $InnerWidth = (($Width-2)/100)*$Percent;
  1190. $this->drawFilledRectangle($X,$Y,$X+$Width,$Y+$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));
  1191. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1192. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1193. {
  1194. $GradientOptions = array("StartR"=>$R,"StartG"=>$G,"StartB"=>$B,"EndR"=>$RFade,"EndG"=>$GFade,"EndB"=>$BFade);
  1195. $this->drawGradientArea($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,DIRECTION_HORIZONTAL,$GradientOptions);
  1196. if ( $Surrounding )
  1197. $this->drawRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
  1198. }
  1199. else
  1200. $this->drawFilledRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1201. $this->Shadow = $RestoreShadow;
  1202. if ( $ShowLabel && $LabelPos == LABEL_POS_LEFT ) { $this->drawText($X-$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); }
  1203. if ( $ShowLabel && $LabelPos == LABEL_POS_RIGHT ) { $this->drawText($X+$Width+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
  1204. if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER ) { $this->drawText($X+($Width/2),$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE)); }
  1205. if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE ) { $this->drawText($X+$InnerWidth+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
  1206. }
  1207. }
  1208. /* Get the legend box size */
  1209. function getLegendSize($Format="")
  1210. {
  1211. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1212. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1213. $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
  1214. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  1215. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  1216. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  1217. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
  1218. $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
  1219. $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
  1220. $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
  1221. $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
  1222. $Data = $this->DataSet->getData();
  1223. foreach($Data["Series"] as $SerieName => $Serie)
  1224. {
  1225. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
  1226. {
  1227. list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
  1228. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  1229. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  1230. }
  1231. }
  1232. $YStep = max($this->FontSize,$IconAreaHeight) + 5;
  1233. $XStep = $IconAreaWidth + 5;
  1234. $XStep = $XSpacing;
  1235. $X=100; $Y=100;
  1236. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  1237. foreach($Data["Series"] as $SerieName => $Serie)
  1238. {
  1239. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1240. {
  1241. if ( $Mode == LEGEND_VERTICAL )
  1242. {
  1243. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);
  1244. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1245. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1246. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1247. $Lines = preg_split("/\n/",$Serie["Description"]);
  1248. $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1249. }
  1250. elseif ( $Mode == LEGEND_HORIZONTAL )
  1251. {
  1252. $Lines = preg_split("/\n/",$Serie["Description"]);
  1253. $Width = "";
  1254. foreach($Lines as $Key => $Value)
  1255. {
  1256. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  1257. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1258. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1259. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1260. $Width[] = $BoxArray[1]["X"];
  1261. }
  1262. $vX=max($Width)+$XStep;
  1263. }
  1264. }
  1265. }
  1266. $vY=$vY-$YStep; $vX=$vX-$XStep;
  1267. $TopOffset = $Y - $Boundaries["T"];
  1268. if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
  1269. $Width = ($Boundaries["R"]+$Margin) - ($Boundaries["L"]-$Margin);
  1270. $Height = ($Boundaries["B"]+$Margin) - ($Boundaries["T"]-$Margin);
  1271. return(array("Width"=>$Width,"Height"=>$Height));
  1272. }
  1273. /* Draw the legend of the active series */
  1274. function drawLegend($X,$Y,$Format="")
  1275. {
  1276. $Family = isset($Format["Family"]) ? $Format["Family"] : LEGEND_FAMILY_BOX;
  1277. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1278. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1279. $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->FontColorR;
  1280. $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->FontColorG;
  1281. $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->FontColorB;
  1282. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
  1283. $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
  1284. $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
  1285. $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
  1286. $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
  1287. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  1288. $R = isset($Format["R"]) ? $Format["R"] : 200;
  1289. $G = isset($Format["G"]) ? $Format["G"] : 200;
  1290. $B = isset($Format["B"]) ? $Format["B"] : 200;
  1291. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1292. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
  1293. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
  1294. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
  1295. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  1296. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  1297. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  1298. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  1299. $Data = $this->DataSet->getData();
  1300. foreach($Data["Series"] as $SerieName => $Serie)
  1301. {
  1302. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
  1303. {
  1304. list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
  1305. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  1306. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  1307. }
  1308. }
  1309. $YStep = max($this->FontSize,$IconAreaHeight) + 5;
  1310. $XStep = $IconAreaWidth + 5;
  1311. $XStep = $XSpacing;
  1312. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  1313. foreach($Data["Series"] as $SerieName => $Serie)
  1314. {
  1315. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1316. {
  1317. if ( $Mode == LEGEND_VERTICAL )
  1318. {
  1319. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);
  1320. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1321. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1322. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1323. $Lines = preg_split("/\n/",$Serie["Description"]);
  1324. $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1325. }
  1326. elseif ( $Mode == LEGEND_HORIZONTAL )
  1327. {
  1328. $Lines = preg_split("/\n/",$Serie["Description"]);
  1329. $Width = "";
  1330. foreach($Lines as $Key => $Value)
  1331. {
  1332. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  1333. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1334. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1335. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1336. $Width[] = $BoxArray[1]["X"];
  1337. }
  1338. $vX=max($Width)+$XStep;
  1339. }
  1340. }
  1341. }
  1342. $vY=$vY-$YStep; $vX=$vX-$XStep;
  1343. $TopOffset = $Y - $Boundaries["T"];
  1344. if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
  1345. if ( $Style == LEGEND_ROUND )
  1346. $this->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1347. elseif ( $Style == LEGEND_BOX )
  1348. $this->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1349. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1350. foreach($Data["Series"] as $SerieName => $Serie)
  1351. {
  1352. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1353. {
  1354. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"];
  1355. $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  1356. if ( isset($Serie["Picture"]) )
  1357. {
  1358. $Picture = $Serie["Picture"];
  1359. list($PicWidth,$PicHeight) = $this->getPicInfo($Picture);
  1360. $PicX = $X+$IconAreaWidth/2; $PicY = $Y+$IconAreaHeight/2;
  1361. $this->drawFromPNG($PicX-$PicWidth/2,$PicY-$PicHeight/2,$Picture);
  1362. }
  1363. else
  1364. {
  1365. if ( $Family == LEGEND_FAMILY_BOX )
  1366. {
  1367. if ( $BoxWidth != $IconAreaWidth ) { $XOffset = floor(($IconAreaWidth-$BoxWidth)/2); } else { $XOffset = 0; }
  1368. if ( $BoxHeight != $IconAreaHeight ) { $YOffset = floor(($IconAreaHeight-$BoxHeight)/2); } else { $YOffset = 0; }
  1369. $this->drawFilledRectangle($X+1+$XOffset,$Y+1+$YOffset,$X+$BoxWidth+$XOffset+1,$Y+$BoxHeight+1+$YOffset,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
  1370. $this->drawFilledRectangle($X+$XOffset,$Y+$YOffset,$X+$BoxWidth+$XOffset,$Y+$BoxHeight+$YOffset,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
  1371. }
  1372. elseif ( $Family == LEGEND_FAMILY_CIRCLE )
  1373. {
  1374. $this->drawFilledCircle($X+1+$IconAreaWidth/2,$Y+1+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
  1375. $this->drawFilledCircle($X+$IconAreaWidth/2,$Y+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
  1376. }
  1377. elseif ( $Family == LEGEND_FAMILY_LINE )
  1378. {
  1379. $this->drawLine($X+1,$Y+1+$IconAreaHeight/2,$X+1+$IconAreaWidth,$Y+1+$IconAreaHeight/2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20,"Ticks"=>$Ticks,"Weight"=>$Weight));
  1380. $this->drawLine($X,$Y+$IconAreaHeight/2,$X+$IconAreaWidth,$Y+$IconAreaHeight/2,array("R"=>$R,"G"=>$G,"B"=>$B,"Ticks"=>$Ticks,"Weight"=>$Weight));
  1381. }
  1382. }
  1383. if ( $Mode == LEGEND_VERTICAL )
  1384. {
  1385. $Lines = preg_split("/\n/",$Serie["Description"]);
  1386. foreach($Lines as $Key => $Value)
  1387. $this->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
  1388. $Y=$Y+max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1389. }
  1390. elseif ( $Mode == LEGEND_HORIZONTAL )
  1391. {
  1392. $Lines = preg_split("/\n/",$Serie["Description"]);
  1393. $Width = "";
  1394. foreach($Lines as $Key => $Value)
  1395. {
  1396. $BoxArray = $this->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
  1397. $Width[] = $BoxArray[1]["X"];
  1398. }
  1399. $X=max($Width)+2+$XStep;
  1400. }
  1401. }
  1402. }
  1403. $this->Shadow = $RestoreShadow;
  1404. }
  1405. function drawScale($Format="")
  1406. {
  1407. $Pos = isset($Format["Pos"]) ? $Format["Pos"] : SCALE_POS_LEFTRIGHT;
  1408. $Floating = isset($Format["Floating"]) ? $Format["Floating"] : FALSE;
  1409. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : SCALE_MODE_FLOATING;
  1410. $MinDivHeight = isset($Format["MinDivHeight"]) ? $Format["MinDivHeight"] : 20;
  1411. $Factors = isset($Format["Factors"]) ? $Format["Factors"] : array(1,2,5);
  1412. $ManualScale = isset($Format["ManualScale"]) ? $Format["ManualScale"] : array("0"=>array("Min"=>-100,"Max"=>100));
  1413. $XMargin = isset($Format["XMargin"]) ? $Format["XMargin"] : AUTO;
  1414. $YMargin = isset($Format["YMargin"]) ? $Format["YMargin"] : 0;
  1415. $ScaleSpacing = isset($Format["ScaleSpacing"]) ? $Format["ScaleSpacing"] : 15;
  1416. $InnerTickWidth = isset($Format["InnerTickWidth"]) ? $Format["InnerTickWidth"] : 2;
  1417. $OuterTickWidth = isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2;
  1418. $DrawXLines = isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : TRUE;
  1419. $DrawYLines = isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL;
  1420. $GridTicks = isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4;
  1421. $GridR = isset($Format["GridR"]) ? $Format["GridR"] : 255;
  1422. $GridG = isset($Format["GridG"]) ? $Format["GridG"] : 255;
  1423. $GridB = isset($Format["GridB"]) ? $Format["GridB"] : 255;
  1424. $GridAlpha = isset($Format["GridAlpha"]) ? $Format["GridAlpha"] : 40;
  1425. $AxisRo = isset($Format["AxisR"]) ? $Format["AxisR"] : 0;
  1426. $AxisGo = isset($Format["AxisG"]) ? $Format["AxisG"] : 0;
  1427. $AxisBo = isset($Format["AxisB"]) ? $Format["AxisB"] : 0;
  1428. $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100;
  1429. $TickRo = isset($Format["TickR"]) ? $Format["TickR"] : 0;
  1430. $TickGo = isset($Format["TickG"]) ? $Format["TickG"] : 0;
  1431. $TickBo = isset($Format["TickB"]) ? $Format["TickB"] : 0;
  1432. $TickAlpha = isset($Format["TickAlpha"]) ? $Format["TickAlpha"] : 100;
  1433. $DrawSubTicks = isset($Format["DrawSubTicks"]) ? $Format["DrawSubTicks"] : FALSE;
  1434. $InnerSubTickWidth = isset($Format["InnerSubTickWidth"]) ? $Format["InnerSubTickWidth"] : 0;
  1435. $OuterSubTickWidth = isset($Format["OuterSubTickWidth"]) ? $Format["OuterSubTickWidth"] : 2;
  1436. $SubTickR = isset($Format["SubTickR"]) ? $Format["SubTickR"] : 255;
  1437. $SubTickG = isset($Format["SubTickG"]) ? $Format["SubTickG"] : 0;
  1438. $SubTickB = isset($Format["SubTickB"]) ? $Format["SubTickB"] : 0;
  1439. $SubTickAlpha = isset($Format["SubTickAlpha"]) ? $Format["SubTickAlpha"] : 100;
  1440. $AutoAxisLabels = isset($Format["AutoAxisLabels"]) ? $Format["AutoAxisLabels"] : TRUE;
  1441. $XReleasePercent = isset($Format["XReleasePercent"]) ? $Format["XReleasePercent"] : 1;
  1442. $DrawArrows = isset($Format["DrawArrows"]) ? $Format["DrawArrows"] : FALSE;
  1443. $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 8;
  1444. $CycleBackground = isset($Format["CycleBackground"]) ? $Format["CycleBackground"] : FALSE;
  1445. $BackgroundR1 = isset($Format["BackgroundR1"]) ? $Format["BackgroundR1"] : 255;
  1446. $BackgroundG1 = isset($Format["BackgroundG1"]) ? $Format["BackgroundG1"] : 255;
  1447. $BackgroundB1 = isset($Format["BackgroundB1"]) ? $Format["BackgroundB1"] : 255;
  1448. $BackgroundAlpha1 = isset($Format["BackgroundAlpha1"]) ? $Format["BackgroundAlpha1"] : 20;
  1449. $BackgroundR2 = isset($Format["BackgroundR2"]) ? $Format["BackgroundR2"] : 230;
  1450. $BackgroundG2 = isset($Format["BackgroundG2"]) ? $Format["BackgroundG2"] : 230;
  1451. $BackgroundB2 = isset($Format["BackgroundB2"]) ? $Format["BackgroundB2"] : 230;
  1452. $BackgroundAlpha2 = isset($Format["BackgroundAlpha2"]) ? $Format["BackgroundAlpha2"] : 20;
  1453. $LabelingMethod = isset($Format["LabelingMethod"]) ? $Format["LabelingMethod"] : LABELING_ALL;
  1454. $LabelSkip = isset($Format["LabelSkip"]) ? $Format["LabelSkip"] : 0;
  1455. $LabelRotation = isset($Format["LabelRotation"]) ? $Format["LabelRotation"] : 0;
  1456. $SkippedAxisTicks = isset($Format["SkippedAxisTicks"]) ? $Format["SkippedAxisTicks"] : $GridTicks+2;
  1457. $SkippedAxisR = isset($Format["SkippedAxisR"]) ? $Format["SkippedAxisR"] : $GridR;
  1458. $SkippedAxisG = isset($Format["SkippedAxisG"]) ? $Format["SkippedAxisG"] : $GridG;
  1459. $SkippedAxisB = isset($Format["SkippedAxisB"]) ? $Format["SkippedAxisB"] : $GridB;
  1460. $SkippedAxisAlpha = isset($Format["SkippedAxisAlpha"]) ? $Format["SkippedAxisAlpha"] : $GridAlpha-30;
  1461. $SkippedTickR = isset($Format["SkippedTickR"]) ? $Format["SkippedTickR"] : $TickRo;
  1462. $SkippedTickG = isset($Format["SkippedTickG"]) ? $Format["SkippedTickG"] : $TickGo;
  1463. $SkippedTickB = isset($Format["SkippedTicksB"]) ? $Format["SkippedTickB"] : $TickBo;
  1464. $SkippedTickAlpha = isset($Format["SkippedTickAlpha"]) ? $Format["SkippedTickAlpha"] : $TickAlpha-80;
  1465. $SkippedInnerTickWidth = isset($Format["SkippedInnerTickWidth"]) ? $Format["SkippedInnerTickWidth"] : 0;
  1466. $SkippedOuterTickWidth = isset($Format["SkippedOuterTickWidth"]) ? $Format["SkippedOuterTickWidth"] : 2;
  1467. /* Floating scale require X & Y margins to be set manually */
  1468. if ( $Floating && ( $XMargin == AUTO || $YMargin == 0 ) ) { $Floating = FALSE; }
  1469. /* Skip a NOTICE event in case of an empty array */
  1470. if ( $DrawYLines == NONE || $DrawYLines == FALSE ) { $DrawYLines = array("zarma"=>"31"); }
  1471. /* Define the color for the skipped elements */
  1472. $SkippedAxisColor = array("R"=>$SkippedAxisR,"G"=>$SkippedAxisG,"B"=>$SkippedAxisB,"Alpha"=>$SkippedAxisAlpha,"Ticks"=>$SkippedAxisTicks);
  1473. $SkippedTickColor = array("R"=>$SkippedTickR,"G"=>$SkippedTickG,"B"=>$SkippedTickB,"Alpha"=>$SkippedTickAlpha);
  1474. $Data = $this->DataSet->getData();
  1475. if ( isset($Data["Abscissa"]) ) { $Abscissa = $Data["Abscissa"]; } else { $Abscissa = NULL; }
  1476. /* Unset the abscissa axis, needed if we display multiple charts on the same picture */
  1477. if ( $Abscissa != NULL )
  1478. {
  1479. foreach($Data["Axis"] as $AxisID => $Parameters)
  1480. { if ($Parameters["Identity"] == AXIS_X) { unset($Data["Axis"][$AxisID]); } }
  1481. }
  1482. /* Build the scale settings */
  1483. $GotXAxis = FALSE;
  1484. foreach($Data["Axis"] as $AxisID => $AxisParameter)
  1485. {
  1486. if ( $AxisParameter["Identity"] == AXIS_X ) { $GotXAxis = TRUE; }
  1487. if ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_Y)
  1488. { $Height = $this->GraphAreaY2-$this->GraphAreaY1 - $YMargin*2; }
  1489. elseif ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_X)
  1490. { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
  1491. elseif ( $Pos == SCALE_POS_TOPBOTTOM && $AxisParameter["Identity"] == AXIS_Y)
  1492. { $Height = $this->GraphAreaX2-$this->GraphAreaX1 - $YMargin*2;; }
  1493. else
  1494. { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }
  1495. $AxisMin = ABSOLUTE_MAX; $AxisMax = OUT_OF_SIGHT;
  1496. if ( $Mode == SCALE_MODE_FLOATING || $Mode == SCALE_MODE_START0 )
  1497. {
  1498. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1499. {
  1500. if ( $SerieParameter["Axis"] == $AxisID && $Data["Series"][$SerieID]["isDrawable"] && $Data["Abscissa"] != $SerieID)
  1501. {
  1502. $AxisMax = max($AxisMax,$Data["Series"][$SerieID]["Max"]);
  1503. $AxisMin = min($AxisMin,$Data["Series"][$SerieID]["Min"]);
  1504. }
  1505. }
  1506. $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
  1507. $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
  1508. if ( $Mode == SCALE_MODE_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; }
  1509. }
  1510. elseif ( $Mode == SCALE_MODE_MANUAL )
  1511. {
  1512. if ( isset($ManualScale[$AxisID]["Min"]) && isset($ManualScale[$AxisID]["Max"]) )
  1513. {
  1514. $Data["Axis"][$AxisID]["Min"] = $ManualScale[$AxisID]["Min"];
  1515. $Data["Axis"][$AxisID]["Max"] = $ManualScale[$AxisID]["Max"];
  1516. }
  1517. else
  1518. { echo "Manual scale boundaries not set."; exit(); }
  1519. }
  1520. elseif ( $Mode == SCALE_MODE_ADDALL || $Mode == SCALE_MODE_ADDALL_START0 )
  1521. {
  1522. $Series = "";
  1523. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1524. { if ( $SerieParameter["Axis"] == $AxisID && $SerieParameter["isDrawable"] && $Data["Abscissa"] != $SerieID ) { $Series[$SerieID] = count($Data["Series"][$SerieID]["Data"]); } }
  1525. for ($ID=0;$ID<=max($Series)-1;$ID++)
  1526. {
  1527. $PointMin = 0; $PointMax = 0;
  1528. foreach($Series as $SerieID => $ValuesCount )
  1529. {
  1530. if (isset($Data["Series"][$SerieID]["Data"][$ID]) && $Data["Series"][$SerieID]["Data"][$ID] != NULL )
  1531. {
  1532. $Value = $Data["Series"][$SerieID]["Data"][$ID];
  1533. if ( $Value > 0 ) { $PointMax = $PointMax + $Value; } else { $PointMin = $PointMin + $Value; }
  1534. }
  1535. }
  1536. $AxisMax = max($AxisMax,$PointMax);
  1537. $AxisMin = min($AxisMin,$PointMin);
  1538. }
  1539. $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
  1540. $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
  1541. }
  1542. $MaxDivs = floor($Height/$MinDivHeight);
  1543. if ( $Mode == SCALE_MODE_ADDALL_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; $Data["Axis"][$AxisID]["Max"] =$ManualScale[$AxisID]["Max"];}
  1544. $Scale = $this->computeScale($Data["Axis"][$AxisID]["Min"],$Data["Axis"][$AxisID]["Max"],$MaxDivs,$Factors,$AxisID);
  1545. $Data["Axis"][$AxisID]["Margin"] = $AxisParameter["Identity"] == AXIS_X ? $XMargin : $YMargin;
  1546. $Data["Axis"][$AxisID]["ScaleMin"] = $Scale["XMin"];
  1547. $Data["Axis"][$AxisID]["ScaleMax"] = $Scale["XMax"];
  1548. $Data["Axis"][$AxisID]["Rows"] = $Scale["Rows"];
  1549. $Data["Axis"][$AxisID]["RowHeight"] = $Scale["RowHeight"];
  1550. if ( isset($Scale["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = $Scale["Format"]; }
  1551. if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
  1552. if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
  1553. if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
  1554. }
  1555. /* Still no X axis */
  1556. if ( $GotXAxis == FALSE )
  1557. {
  1558. if ( $Abscissa != NULL )
  1559. {
  1560. $Points = count($Data["Series"][$Abscissa]["Data"]);
  1561. if ( $AutoAxisLabels )
  1562. $AxisName = isset($Data["Series"][$Abscissa]["Description"]) ? $Data["Series"][$Abscissa]["Description"] : NULL;
  1563. else
  1564. $AxisName = NULL;
  1565. }
  1566. else
  1567. {
  1568. $Points = 0;
  1569. $AxisName = isset($Data["XAxisName"]) ? $Data["XAxisName"] : NULL;
  1570. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1571. { if ( $SerieParameter["isDrawable"] ) { $Points = max($Points,count($SerieParameter["Data"])); } }
  1572. }
  1573. $AxisID = count($Data["Axis"]);
  1574. $Data["Axis"][$AxisID]["Identity"] = AXIS_X;
  1575. if ( $Pos == SCALE_POS_LEFTRIGHT ) { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_BOTTOM; } else { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_LEFT; }
  1576. if ( isset($Data["AbscissaName"]) ) { $Data["Axis"][$AxisID]["Name"] = $Data["AbscissaName"]; }
  1577. if ( $XMargin == AUTO )
  1578. {
  1579. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1580. { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
  1581. else
  1582. { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }
  1583. if ( $Points == 1 )
  1584. $Data["Axis"][$AxisID]["Margin"] = $Height / 2;
  1585. else
  1586. $Data["Axis"][$AxisID]["Margin"] = ($Height/$Points) / 2;
  1587. }
  1588. else
  1589. { $Data["Axis"][$AxisID]["Margin"] = $XMargin; }
  1590. $Data["Axis"][$AxisID]["Rows"] = $Points-1;
  1591. if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
  1592. if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
  1593. if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
  1594. }
  1595. $this->DataSet->saveOrientation($Pos);
  1596. $this->DataSet->saveAxisConfig($Data["Axis"]);
  1597. $this->DataSet->saveYMargin($YMargin);
  1598. $FontColorRo = $this->FontColorR; $FontColorGo = $this->FontColorG; $FontColorBo = $this->FontColorB;
  1599. $AxisPos["L"] = $this->GraphAreaX1; $AxisPos["R"] = $this->GraphAreaX2; $AxisPos["T"] = $this->GraphAreaY1; $AxisPos["B"] = $this->GraphAreaY2;
  1600. foreach($Data["Axis"] as $AxisID => $Parameters)
  1601. {
  1602. if ( isset($Parameters["Color"]) )
  1603. {
  1604. $AxisR = $Parameters["Color"]["R"]; $AxisG = $Parameters["Color"]["G"]; $AxisB = $Parameters["Color"]["B"];
  1605. $TickR = $Parameters["Color"]["R"]; $TickG = $Parameters["Color"]["G"]; $TickB = $Parameters["Color"]["B"];
  1606. $this->setFontProperties(array("R"=>$Parameters["Color"]["R"],"G"=>$Parameters["Color"]["G"],"B"=>$Parameters["Color"]["B"]));
  1607. }
  1608. else
  1609. {
  1610. $AxisR = $AxisRo; $AxisG = $AxisGo; $AxisB = $AxisBo;
  1611. $TickR = $TickRo; $TickG = $TickGo; $TickB = $TickBo;
  1612. $this->setFontProperties(array("R"=>$FontColorRo,"G"=>$FontColorGo,"B"=>$FontColorBo));
  1613. }
  1614. $LastValue = "w00t"; $ID = 1;
  1615. if ( $Parameters["Identity"] == AXIS_X )
  1616. {
  1617. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1618. {
  1619. if ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
  1620. {
  1621. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 2; }
  1622. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }
  1623. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 5; }
  1624. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }
  1625. if ( $Floating )
  1626. { $FloatingOffset = $YMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1627. else
  1628. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1629. if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["B"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1630. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1631. if ($Parameters["Rows"] == 0 ) { $Step = $Width; } else { $Step = $Width / ($Parameters["Rows"]); }
  1632. $MaxBottom = $AxisPos["B"];
  1633. for($i=0;$i<=$Parameters["Rows"];$i++)
  1634. {
  1635. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1636. $YPos = $AxisPos["B"];
  1637. if ( $Abscissa != NULL )
  1638. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1639. else
  1640. {
  1641. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1642. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1643. else
  1644. $Value = $i;
  1645. }
  1646. $ID++; $Skipped = TRUE;
  1647. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) )
  1648. {
  1649. $Bounds = $this->drawText($XPos,$YPos+$OuterTickWidth+$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1650. $TxtBottom = $YPos+$OuterTickWidth+2+($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  1651. $MaxBottom = max($MaxBottom,$TxtBottom);
  1652. $LastValue = $Value;
  1653. $Skipped = FALSE;
  1654. }
  1655. if ( $Skipped )
  1656. {
  1657. if ( $DrawXLines ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
  1658. if ( $SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0 ) { $this->drawLine($XPos,$YPos-$SkippedInnerTickWidth,$XPos,$YPos+$SkippedOuterTickWidth,$SkippedTickColor); }
  1659. }
  1660. else
  1661. {
  1662. if ( $DrawXLines && ($XPos != $this->GraphAreaX1 && $XPos != $this->GraphAreaX2) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1663. if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { $this->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1664. }
  1665. }
  1666. if ( isset($Parameters["Name"]) )
  1667. {
  1668. $YPos = $MaxBottom+2;
  1669. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1670. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  1671. $MaxBottom = $Bounds[0]["Y"];
  1672. $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
  1673. }
  1674. $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
  1675. }
  1676. elseif ( $Parameters["Position"] == AXIS_POSITION_TOP )
  1677. {
  1678. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 2; }
  1679. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }
  1680. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 5; }
  1681. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }
  1682. if ( $Floating )
  1683. { $FloatingOffset = $YMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1684. else
  1685. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1686. if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["T"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1687. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1688. if ($Parameters["Rows"] == 0 ) { $Step = $Width; } else { $Step = $Width / $Parameters["Rows"]; }
  1689. $MinTop = $AxisPos["T"];
  1690. for($i=0;$i<=$Parameters["Rows"];$i++)
  1691. {
  1692. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1693. $YPos = $AxisPos["T"];
  1694. if ( $Abscissa != NULL )
  1695. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1696. else
  1697. {
  1698. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1699. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1700. else
  1701. $Value = $i;
  1702. }
  1703. $ID++; $Skipped = TRUE;
  1704. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) )
  1705. {
  1706. $Bounds = $this->drawText($XPos,$YPos-$OuterTickWidth-$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1707. $TxtBox = $YPos-$OuterTickWidth-2-($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  1708. $MinTop = min($MinTop,$TxtBox);
  1709. $LastValue = $Value;
  1710. $Skipped = FALSE;
  1711. }
  1712. if ( $Skipped )
  1713. {
  1714. if ( $DrawXLines ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
  1715. if ( $SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0 ) { $this->drawLine($XPos,$YPos+$SkippedInnerTickWidth,$XPos,$YPos-$SkippedOuterTickWidth,$SkippedTickColor); }
  1716. }
  1717. else
  1718. {
  1719. if ( $DrawXLines ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1720. if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { $this->drawLine($XPos,$YPos+$InnerTickWidth,$XPos,$YPos-$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1721. }
  1722. }
  1723. if ( isset($Parameters["Name"]) )
  1724. {
  1725. $YPos = $MinTop-2;
  1726. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1727. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  1728. $MinTop = $Bounds[2]["Y"];
  1729. $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
  1730. }
  1731. $AxisPos["T"] = $MinTop - $ScaleSpacing;
  1732. }
  1733. }
  1734. elseif ( $Pos == SCALE_POS_TOPBOTTOM )
  1735. {
  1736. if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
  1737. {
  1738. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -2; }
  1739. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -6; }
  1740. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -2; }
  1741. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -5; }
  1742. if ( $Floating )
  1743. { $FloatingOffset = $YMargin; $this->drawLine($AxisPos["L"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1744. else
  1745. { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1746. if ( $DrawArrows ) { $this->drawArrow($AxisPos["L"],$this->GraphAreaY2-$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY2+($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1747. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1748. if ($Parameters["Rows"] == 0 ) { $Step = $Height; } else { $Step = $Height / $Parameters["Rows"]; }
  1749. $MinLeft = $AxisPos["L"];
  1750. for($i=0;$i<=$Parameters["Rows"];$i++)
  1751. {
  1752. $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
  1753. $XPos = $AxisPos["L"];
  1754. if ( $Abscissa != NULL )
  1755. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1756. else
  1757. {
  1758. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1759. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1760. else
  1761. $Value = $i;
  1762. }
  1763. $ID++; $Skipped = TRUE;
  1764. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) )
  1765. {
  1766. $Bounds = $this->drawText($XPos-$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1767. $TxtBox = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
  1768. $MinLeft = min($MinLeft,$TxtBox);
  1769. $LastValue = $Value;
  1770. $Skipped = FALSE;
  1771. }
  1772. if ( $Skipped )
  1773. {
  1774. if ( $DrawXLines ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
  1775. if ( $SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0 ) { $this->drawLine($XPos-$SkippedOuterTickWidth,$YPos,$XPos+$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
  1776. }
  1777. else
  1778. {
  1779. if ( $DrawXLines && ($YPos != $this->GraphAreaY1 && $YPos != $this->GraphAreaY2) ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1780. if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1781. }
  1782. }
  1783. if ( isset($Parameters["Name"]) )
  1784. {
  1785. $XPos = $MinLeft-2;
  1786. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1787. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
  1788. $MinLeft = $Bounds[0]["X"];
  1789. $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
  1790. }
  1791. $AxisPos["L"] = $MinLeft - $ScaleSpacing;
  1792. }
  1793. elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
  1794. {
  1795. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 2; }
  1796. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 6; }
  1797. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 5; }
  1798. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 7; }
  1799. if ( $Floating )
  1800. { $FloatingOffset = $YMargin; $this->drawLine($AxisPos["R"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1801. else
  1802. { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1803. if ( $DrawArrows ) { $this->drawArrow($AxisPos["R"],$this->GraphAreaY2-$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY2+($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1804. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1805. if ($Parameters["Rows"] == 0 ) { $Step = $Height; } else { $Step = $Height / $Parameters["Rows"]; }
  1806. $MaxRight = $AxisPos["R"];
  1807. for($i=0;$i<=$Parameters["Rows"];$i++)
  1808. {
  1809. $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
  1810. $XPos = $AxisPos["R"];
  1811. if ( $Abscissa != NULL )
  1812. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1813. else
  1814. {
  1815. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1816. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1817. else
  1818. $Value = $i;
  1819. }
  1820. $ID++; $Skipped = TRUE;
  1821. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) )
  1822. {
  1823. $Bounds = $this->drawText($XPos+$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1824. $TxtBox = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
  1825. $MaxRight = max($MaxRight,$TxtBox);
  1826. $LastValue = $Value;
  1827. $Skipped = FALSE;
  1828. }
  1829. if ( $Skipped )
  1830. {
  1831. if ( $DrawXLines ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
  1832. if ( $SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0 ) { $this->drawLine($XPos+$SkippedOuterTickWidth,$YPos,$XPos-$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
  1833. }
  1834. else
  1835. {
  1836. if ( $DrawXLines ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1837. if ( $InnerTickWidth !=0 || $OuterTickWidth != 0 ) { $this->drawLine($XPos+$OuterTickWidth,$YPos,$XPos-$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1838. }
  1839. }
  1840. if ( isset($Parameters["Name"]) )
  1841. {
  1842. $XPos = $MaxRight+4;
  1843. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1844. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
  1845. $MaxRight = $Bounds[1]["X"];
  1846. $this->DataSet->Data["GraphArea"]["X2"] = $MaxRight + $this->FontSize;
  1847. }
  1848. $AxisPos["R"] = $MaxRight + $ScaleSpacing;
  1849. }
  1850. }
  1851. }
  1852. if ( $Parameters["Identity"] == AXIS_Y )
  1853. {
  1854. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1855. {
  1856. if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
  1857. {
  1858. if ( $Floating )
  1859. { $FloatingOffset = $XMargin; $this->drawLine($AxisPos["L"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1860. else
  1861. { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1862. if ( $DrawArrows ) { $this->drawArrow($AxisPos["L"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1863. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1864. $Step = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinLeft = $AxisPos["L"];
  1865. $LastY = NULL;
  1866. for($i=0;$i<=$Parameters["Rows"];$i++)
  1867. {
  1868. $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
  1869. $XPos = $AxisPos["L"];
  1870. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1871. if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
  1872. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  1873. if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1874. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1875. $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1876. $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1877. $Bounds = $this->drawText($XPos-$OuterTickWidth-2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLERIGHT));
  1878. $TxtLeft = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
  1879. $MinLeft = min($MinLeft,$TxtLeft);
  1880. $LastY = $YPos;
  1881. }
  1882. if ( isset($Parameters["Name"]) )
  1883. {
  1884. $XPos = $MinLeft-2;
  1885. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1886. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
  1887. $MinLeft = $Bounds[2]["X"];
  1888. $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
  1889. }
  1890. $AxisPos["L"] = $MinLeft - $ScaleSpacing;
  1891. }
  1892. elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
  1893. {
  1894. if ( $Floating )
  1895. { $FloatingOffset = $XMargin; $this->drawLine($AxisPos["R"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1896. else
  1897. { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1898. if ( $DrawArrows ) { $this->drawArrow($AxisPos["R"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1899. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1900. $Step = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxLeft = $AxisPos["R"];
  1901. $LastY = NULL;
  1902. for($i=0;$i<=$Parameters["Rows"];$i++)
  1903. {
  1904. $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
  1905. $XPos = $AxisPos["R"];
  1906. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1907. if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
  1908. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  1909. if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1910. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1911. $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1912. $this->drawLine($XPos-$InnerTickWidth,$YPos,$XPos+$OuterTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1913. $Bounds = $this->drawText($XPos+$OuterTickWidth+2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
  1914. $TxtLeft = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
  1915. $MaxLeft = max($MaxLeft,$TxtLeft);
  1916. $LastY = $YPos;
  1917. }
  1918. if ( isset($Parameters["Name"]) )
  1919. {
  1920. $XPos = $MaxLeft+6;
  1921. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1922. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
  1923. $MaxLeft = $Bounds[2]["X"];
  1924. $this->DataSet->Data["GraphArea"]["X2"] = $MaxLeft + $this->FontSize;
  1925. }
  1926. $AxisPos["R"] = $MaxLeft + $ScaleSpacing;
  1927. }
  1928. }
  1929. elseif ( $Pos == SCALE_POS_TOPBOTTOM )
  1930. {
  1931. if ( $Parameters["Position"] == AXIS_POSITION_TOP )
  1932. {
  1933. if ( $Floating )
  1934. { $FloatingOffset = $XMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1935. else
  1936. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1937. if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["T"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1938. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1939. $Step = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinTop = $AxisPos["T"];
  1940. $LastX = NULL;
  1941. for($i=0;$i<=$Parameters["Rows"];$i++)
  1942. {
  1943. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1944. $YPos = $AxisPos["T"];
  1945. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1946. if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
  1947. if ( $LastX != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }
  1948. if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1949. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1950. $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1951. $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1952. $Bounds = $this->drawText($XPos,$YPos-$OuterTickWidth-2,$Value,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  1953. $TxtHeight = $YPos-$OuterTickWidth-2-($Bounds[1]["Y"]-$Bounds[2]["Y"]);
  1954. $MinTop = min($MinTop,$TxtHeight);
  1955. $LastX = $XPos;
  1956. }
  1957. if ( isset($Parameters["Name"]) )
  1958. {
  1959. $YPos = $MinTop-2;
  1960. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1961. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  1962. $MinTop = $Bounds[2]["Y"];
  1963. $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
  1964. }
  1965. $AxisPos["T"] = $MinTop - $ScaleSpacing;
  1966. }
  1967. elseif ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
  1968. {
  1969. if ( $Floating )
  1970. { $FloatingOffset = $XMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1971. else
  1972. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1973. if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["B"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1974. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1975. $Step = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxBottom = $AxisPos["B"];
  1976. $LastX = NULL;
  1977. for($i=0;$i<=$Parameters["Rows"];$i++)
  1978. {
  1979. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1980. $YPos = $AxisPos["B"];
  1981. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1982. if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
  1983. if ( $LastX != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }
  1984. if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1985. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1986. $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1987. $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1988. $Bounds = $this->drawText($XPos,$YPos+$OuterTickWidth+2,$Value,array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  1989. $TxtHeight = $YPos+$OuterTickWidth+2+($Bounds[1]["Y"]-$Bounds[2]["Y"]);
  1990. $MaxBottom = max($MaxBottom,$TxtHeight);
  1991. $LastX = $XPos;
  1992. }
  1993. if ( isset($Parameters["Name"]) )
  1994. {
  1995. $YPos = $MaxBottom+2;
  1996. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1997. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  1998. $MaxBottom = $Bounds[0]["Y"];
  1999. $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
  2000. }
  2001. $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
  2002. }
  2003. }
  2004. }
  2005. }
  2006. }
  2007. function isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip)
  2008. {
  2009. if ( $LabelingMethod == LABELING_DIFFERENT && $Value != $LastValue ) { return(TRUE); }
  2010. if ( $LabelingMethod == LABELING_DIFFERENT && $Value == $LastValue ) { return(FALSE); }
  2011. if ( $LabelingMethod == LABELING_ALL && $LabelSkip == 0 ) { return(TRUE); }
  2012. if ( $LabelingMethod == LABELING_ALL && ($ID+$LabelSkip) % ($LabelSkip+1) != 1 ) { return(FALSE); }
  2013. return(TRUE);
  2014. }
  2015. /* Compute the scale, check for the best visual factors */
  2016. function computeScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID=0)
  2017. {
  2018. /* Compute each factors */
  2019. $Results = "";
  2020. foreach ($Factors as $Key => $Factor)
  2021. $Results[$Factor] = $this->processScale($XMin,$XMax,$MaxDivs,array($Factor),$AxisID);
  2022. /* Remove scales that are creating to much decimals */
  2023. $GoodScaleFactors = "";
  2024. foreach ($Results as $Key => $Result)
  2025. {
  2026. $Decimals = preg_split("/\./",$Result["RowHeight"]);
  2027. if ( (!isset($Decimals[1])) || (strlen($Decimals[1]) < 6) ) { $GoodScaleFactors[] = $Key; }
  2028. }
  2029. /* Found no correct scale, shame,... returns the 1st one as default */
  2030. if ( $GoodScaleFactors == "" ) { return($Results[$Factors[0]]); }
  2031. /* Find the factor that cause the maximum number of Rows */
  2032. $MaxRows = 0; $BestFactor = 0;
  2033. foreach($GoodScaleFactors as $Key => $Factor)
  2034. { if ( $Results[$Factor]["Rows"] > $MaxRows ) { $MaxRows = $Results[$Factor]["Rows"]; $BestFactor = $Factor; } }
  2035. /* Return the best visual scale */
  2036. return($Results[$BestFactor]);
  2037. }
  2038. /* Compute the best matching scale based on size & factors */
  2039. function processScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID)
  2040. {
  2041. $ScaleHeight = abs(ceil($XMax)-floor($XMin));
  2042. if ( isset($this->DataSet->Data["Axis"][$AxisID]["Format"]) )
  2043. $Format = $this->DataSet->Data["Axis"][$AxisID]["Format"];
  2044. else
  2045. $Format = NULL;
  2046. if ( isset($this->DataSet->Data["Axis"][$AxisID]["Display"]) )
  2047. $Mode = $this->DataSet->Data["Axis"][$AxisID]["Display"];
  2048. else
  2049. $Mode = AXIS_FORMAT_DEFAULT;
  2050. $Scale = "";
  2051. if ( $XMin != $XMax )
  2052. {
  2053. $Found = FALSE; $Rescaled = FALSE; $Scaled10Factor = .0001; $Result = 0;
  2054. while(!$Found)
  2055. {
  2056. foreach($Factors as $Key => $Factor)
  2057. {
  2058. if ( !$Found )
  2059. {
  2060. if ( !($this->modulo($XMin,$Factor*$Scaled10Factor) == 0) || ($XMin != floor($XMin))) { $XMinRescaled = floor($XMin/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor; } else { $XMinRescaled = $XMin; }
  2061. if ( !($this->modulo($XMax,$Factor*$Scaled10Factor) == 0) || ($XMax != floor($XMax))) { $XMaxRescaled = floor($XMax/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor+($Factor*$Scaled10Factor); } else { $XMaxRescaled = $XMax; }
  2062. $ScaleHeightRescaled = abs($XMaxRescaled-$XMinRescaled);
  2063. if ( !$Found && floor($ScaleHeightRescaled/($Factor*$Scaled10Factor)) <= $MaxDivs ) { $Found = TRUE; $Rescaled = TRUE; $Result = $Factor * $Scaled10Factor; }
  2064. }
  2065. }
  2066. $Scaled10Factor = $Scaled10Factor * 10;
  2067. }
  2068. /* ReCall Min / Max / Height */
  2069. if ( $Rescaled ) { $XMin = $XMinRescaled; $XMax = $XMaxRescaled; $ScaleHeight = $ScaleHeightRescaled; }
  2070. /* Compute rows size */
  2071. $Rows = floor($ScaleHeight / $Result); if ( $Rows == 0 ) { $Rows = 1; }
  2072. $RowHeight = $ScaleHeight / $Rows;
  2073. /* Return the results */
  2074. $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin; $Scale["XMax"] = $XMax;
  2075. /* Compute the needed decimals for the metric view to avoid repetition of the same X Axis labels */
  2076. if ( $Mode == AXIS_FORMAT_METRIC && $Format == NULL )
  2077. {
  2078. $Done = FALSE; $GoodDecimals = 0;
  2079. for($Decimals=0;$Decimals<=10;$Decimals++)
  2080. {
  2081. if ( !$Done )
  2082. {
  2083. $LastLabel = "zob"; $ScaleOK = TRUE;
  2084. for($i=0;$i<=$Rows;$i++)
  2085. {
  2086. $Value = $XMin + $i*$RowHeight;
  2087. $Label = $this->scaleFormat($Value,AXIS_FORMAT_METRIC,$Decimals);
  2088. if ( $LastLabel == $Label ) { $ScaleOK = FALSE; }
  2089. $LastLabel = $Label;
  2090. }
  2091. if ( $ScaleOK ) { $Done = TRUE; $GoodDecimals = $Decimals; }
  2092. }
  2093. }
  2094. $Scale["Format"] = $GoodDecimals;
  2095. }
  2096. }
  2097. else
  2098. {
  2099. /* If all values are the same we keep a +1/-1 scale */
  2100. $Rows = 2; $XMin = $XMax-1; $XMax = $XMax+1; $RowHeight = 1;
  2101. /* Return the results */
  2102. $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin; $Scale["XMax"] = $XMax;
  2103. }
  2104. return($Scale);
  2105. }
  2106. function modulo($Value1,$Value2)
  2107. {
  2108. if (floor($Value2) == 0) { return(0); }
  2109. if (floor($Value2) != 0) { return($Value1 % $Value2); }
  2110. $MinValue = min($Value1,$Value2); $Factor = 10;
  2111. while ( floor($MinValue*$Factor) == 0 )
  2112. { $Factor = $Factor * 10; }
  2113. return(($Value1*$Factor) % ($Value2*$Factor));
  2114. }
  2115. /* Draw a threshold with the computed scale */
  2116. function drawThreshold($Value,$Format="")
  2117. {
  2118. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  2119. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2120. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2121. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2122. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
  2123. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  2124. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
  2125. $Wide = isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
  2126. $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
  2127. $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
  2128. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : NULL;
  2129. $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
  2130. $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
  2131. $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
  2132. $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
  2133. $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
  2134. $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
  2135. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2136. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2137. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 3;
  2138. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2139. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2140. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2141. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2142. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2143. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 30;
  2144. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2145. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2146. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2147. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2148. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2149. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2150. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2151. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
  2152. "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);
  2153. if ( $Caption == NULL ) { $Caption = $Value; }
  2154. $Data = $this->DataSet->getData();
  2155. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2156. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2157. {
  2158. $YPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
  2159. if ( $YPos >= $this->GraphAreaY1 && $YPos <= $this->GraphAreaY2 )
  2160. {
  2161. $this->drawLine($this->GraphAreaX1,$YPos,$this->GraphAreaX2,$YPos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2162. if ( $Wide )
  2163. {
  2164. $this->drawLine($this->GraphAreaX1,$YPos-1,$this->GraphAreaX2,$YPos-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2165. $this->drawLine($this->GraphAreaX1,$YPos+1,$this->GraphAreaX2,$YPos+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2166. }
  2167. if ( $WriteCaption )
  2168. {
  2169. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2170. { $X = $this->GraphAreaX1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
  2171. else
  2172. { $X = $this->GraphAreaX2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
  2173. $this->drawText($X,$YPos,$Caption,$CaptionSettings);
  2174. }
  2175. }
  2176. return(array("Y"=>$YPos));
  2177. }
  2178. if ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2179. {
  2180. $XPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
  2181. if ( $XPos >= $this->GraphAreaX1 && $XPos <= $this->GraphAreaX2 )
  2182. {
  2183. $this->drawLine($XPos,$this->GraphAreaY1,$XPos,$this->GraphAreaY2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2184. if ( $Wide )
  2185. {
  2186. $this->drawLine($XPos-1,$this->GraphAreaY1,$XPos-1,$this->GraphAreaY2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2187. $this->drawLine($XPos+1,$this->GraphAreaY1,$XPos+1,$this->GraphAreaY2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2188. }
  2189. if ( $WriteCaption )
  2190. {
  2191. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2192. { $Y = $this->GraphAreaY1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
  2193. else
  2194. { $Y = $this->GraphAreaY2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
  2195. $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
  2196. $this->drawText($XPos,$Y,$Caption,$CaptionSettings);
  2197. }
  2198. }
  2199. return(array("Y"=>$XPos));
  2200. }
  2201. }
  2202. /* Draw a threshold with the computed scale */
  2203. function drawThresholdArea($Value1,$Value2,$Format="")
  2204. {
  2205. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  2206. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2207. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2208. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2209. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
  2210. $Border = isset($Format["Border"]) ? $Format["Border"] : TRUE;
  2211. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  2212. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  2213. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  2214. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
  2215. $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
  2216. if ($BorderAlpha >100) { $BorderAlpha = 100;}
  2217. $Data = $this->DataSet->getData();
  2218. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2219. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2220. {
  2221. $YPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
  2222. $YPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));
  2223. if ( $YPos1 > $this->GraphAreaY2 ) { $YPos1 = $this->GraphAreaY2; } if ( $YPos1 < $this->GraphAreaY1 ) { $YPos1 = $this->GraphAreaY1; }
  2224. if ( $YPos2 > $this->GraphAreaY2 ) { $YPos2 = $this->GraphAreaY2; } if ( $YPos2 < $this->GraphAreaY1 ) { $YPos2 = $this->GraphAreaY1; }
  2225. $this->drawFilledRectangle($this->GraphAreaX1+1,$YPos1,$this->GraphAreaX2-1,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2226. if ( $Border )
  2227. {
  2228. $this->drawLine($this->GraphAreaX1+1,$YPos1,$this->GraphAreaX2-1,$YPos1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2229. $this->drawLine($this->GraphAreaX1+1,$YPos2,$this->GraphAreaX2-1,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2230. }
  2231. return(array("Y1"=>$YPos1,"Y2"=>$YPos2));
  2232. }
  2233. if ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2234. {
  2235. $XPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
  2236. $XPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));
  2237. if ( $XPos1 > $this->GraphAreaX2 ) { $XPos1 = $this->GraphAreaX2; } if ( $XPos1 < $this->GraphAreaX1 ) { $XPos1 = $this->GraphAreaX1; }
  2238. if ( $XPos2 > $this->GraphAreaX2 ) { $XPos2 = $this->GraphAreaX2; } if ( $XPos2 < $this->GraphAreaX1 ) { $XPos2 = $this->GraphAreaX1; }
  2239. $this->drawFilledRectangle($XPos1,$this->GraphAreaY1+1,$XPos2,$this->GraphAreaY2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2240. if ( $Border )
  2241. {
  2242. $this->drawLine($XPos1,$this->GraphAreaY1+1,$XPos1,$this->GraphAreaY2-1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2243. $this->drawLine($XPos2,$this->GraphAreaY1+1,$XPos2,$this->GraphAreaY2-1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2244. }
  2245. return(array("Y1"=>$XPos1,"Y2"=>$XPos2));
  2246. }
  2247. }
  2248. function scaleGetXSettings()
  2249. {
  2250. $Data = $this->DataSet->getData();
  2251. foreach($Data["Axis"] as $AxisID => $Settings)
  2252. {
  2253. if ( $Settings["Identity"] == AXIS_X )
  2254. {
  2255. $Rows = $Settings["Rows"];
  2256. return(array($Settings["Margin"],$Rows));
  2257. }
  2258. }
  2259. }
  2260. function scaleComputeY($Values,$Option="",$ReturnOnly0Height=FALSE)
  2261. {
  2262. $AxisID = isset($Option["AxisID"]) ? $Option["AxisID"] : 0;
  2263. $SerieName = isset($Option["SerieName"]) ? $Option["SerieName"] : NULL;
  2264. $Data = $this->DataSet->getData();
  2265. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2266. if ( $SerieName != NULL ) { $AxisID = $Data["Series"][$SerieName]["Axis"]; }
  2267. if ( !is_array($Values) ) { $tmp = $Values; $Values = ""; $Values[0] = $tmp; }
  2268. $Result = "";
  2269. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2270. {
  2271. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Data["Axis"][$AxisID]["Margin"]*2;
  2272. $ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  2273. $Step = $Height / $ScaleHeight;
  2274. if ( $ReturnOnly0Height )
  2275. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
  2276. else
  2277. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
  2278. }
  2279. else
  2280. {
  2281. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Data["Axis"][$AxisID]["Margin"]*2;
  2282. $ScaleWidth = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  2283. $Step = $Width / $ScaleWidth;
  2284. if ( $ReturnOnly0Height )
  2285. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
  2286. else
  2287. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
  2288. }
  2289. if ( count($Result) == 1 )
  2290. return($Result[0]);
  2291. else
  2292. return($Result);
  2293. }
  2294. /* Format the axis values */
  2295. function scaleFormat($Value,$Mode=NULL,$Format=NULL,$Unit=NULL)
  2296. {
  2297. if ( $Value == VOID ) { return(""); }
  2298. if ( $Mode == AXIS_FORMAT_DATE )
  2299. { if ( $Format == NULL ) { $Pattern = "d/m/Y"; } else { $Pattern = $Format; } return(date($Pattern,$Value)); }
  2300. if ( $Mode == AXIS_FORMAT_TIME )
  2301. { if ( $Format == NULL ) { $Pattern = "H:i:s"; } else { $Pattern = $Format; } return(date($Pattern,$Value)); }
  2302. if ( $Mode == AXIS_FORMAT_CURRENCY )
  2303. { return($Format.number_format($Value,2)); }
  2304. if ( $Mode == AXIS_FORMAT_METRIC )
  2305. {
  2306. if (abs($Value) > 1000000000)
  2307. return(round($Value/1000000000,$Format)."g".$Unit);
  2308. if (abs($Value) > 1000000)
  2309. return(round($Value/1000000,$Format)."m".$Unit);
  2310. elseif (abs($Value) >= 1000)
  2311. return(round($Value/1000,$Format)."k".$Unit);
  2312. }
  2313. return($Value.$Unit);
  2314. }
  2315. /* Write Max value on a chart */
  2316. function writeBounds($Type=BOUND_BOTH,$Format=NULL)
  2317. {
  2318. $MaxLabelTxt = isset($Format["MaxLabelTxt"]) ? $Format["MaxLabelTxt"] : "max=";
  2319. $MinLabelTxt = isset($Format["MinLabelTxt"]) ? $Format["MinLabelTxt"] : "min=";
  2320. $Decimals = isset($Format["Decimals"]) ? $Format["Decimals"] : 1;
  2321. $ExcludedSeries = isset($Format["ExcludedSeries"]) ? $Format["ExcludedSeries"] : "";
  2322. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
  2323. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2324. $MaxDisplayR = isset($Format["MaxDisplayR"]) ? $Format["MaxDisplayR"] : 0;
  2325. $MaxDisplayG = isset($Format["MaxDisplayG"]) ? $Format["MaxDisplayG"] : 0;
  2326. $MaxDisplayB = isset($Format["MaxDisplayB"]) ? $Format["MaxDisplayB"] : 0;
  2327. $MinDisplayR = isset($Format["MinDisplayR"]) ? $Format["MinDisplayR"] : 255;
  2328. $MinDisplayG = isset($Format["MinDisplayG"]) ? $Format["MinDisplayG"] : 255;
  2329. $MinDisplayB = isset($Format["MinDisplayB"]) ? $Format["MinDisplayB"] : 255;
  2330. $MinLabelPos = isset($Format["MinLabelPos"]) ? $Format["MinLabelPos"] : BOUND_LABEL_POS_AUTO;
  2331. $MaxLabelPos = isset($Format["MaxLabelPos"]) ? $Format["MaxLabelPos"] : BOUND_LABEL_POS_AUTO;
  2332. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2333. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2334. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 3;
  2335. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2336. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2337. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2338. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2339. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2340. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
  2341. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2342. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2343. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2344. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2345. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2346. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2347. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2348. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha);
  2349. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2350. $Data = $this->DataSet->getData();
  2351. foreach($Data["Series"] as $SerieName => $Serie)
  2352. {
  2353. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && !isset($ExcludedSeries[$SerieName]))
  2354. {
  2355. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2356. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2357. $MinValue = $this->DataSet->getMin($SerieName);
  2358. $MaxValue = $this->DataSet->getMax($SerieName);
  2359. $MinPos = VOID; $MaxPos = VOID;
  2360. foreach($Serie["Data"] as $Key => $Value)
  2361. {
  2362. if ( $Value == $MinValue && $MinPos == VOID ) { $MinPos = $Key; }
  2363. if ( $Value == $MaxValue ) { $MaxPos = $Key; }
  2364. }
  2365. $AxisID = $Serie["Axis"];
  2366. $Mode = $Data["Axis"][$AxisID]["Display"];
  2367. $Format = $Data["Axis"][$AxisID]["Format"];
  2368. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2369. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2370. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2371. {
  2372. $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs;
  2373. $X = $this->GraphAreaX1 + $XMargin;
  2374. $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
  2375. if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
  2376. {
  2377. if ( $MaxLabelPos == BOUND_LABEL_POS_TOP || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
  2378. if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }
  2379. $XPos = $X + $MaxPos*$XStep + $SerieOffset;
  2380. $Label = $MaxLabelTxt.$this->scaleFormat(round($MaxValue,$Decimals),$Mode,$Format,$Unit);
  2381. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
  2382. $XOffset = 0; $YOffset = 0;
  2383. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
  2384. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
  2385. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
  2386. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }
  2387. $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
  2388. $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;
  2389. $this->drawText($XPos+$XOffset,$YPos+$YOffset,$Label,$CaptionSettings);
  2390. }
  2391. if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
  2392. {
  2393. if ( $MinLabelPos == BOUND_LABEL_POS_TOP || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
  2394. if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }
  2395. $XPos = $X + $MinPos*$XStep + $SerieOffset;
  2396. $Label = $MinLabelTxt.$this->scaleFormat(round($MinValue,$Decimals),$Mode,$Format,$Unit);
  2397. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
  2398. $XOffset = 0; $YOffset = 0;
  2399. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
  2400. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
  2401. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
  2402. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }
  2403. $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
  2404. $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;
  2405. $this->drawText($XPos+$XOffset,$YPos-$DisplayOffset+$YOffset,$Label,$CaptionSettings);
  2406. }
  2407. }
  2408. else
  2409. {
  2410. $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs;
  2411. $X = $this->GraphAreaY1 + $XMargin;
  2412. $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
  2413. if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
  2414. {
  2415. if ( $MaxLabelPos == BOUND_LABEL_POS_TOP || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
  2416. if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }
  2417. $XPos = $X + $MaxPos*$XStep + $SerieOffset;
  2418. $Label = $MaxLabelTxt.$this->scaleFormat($MaxValue,$Mode,$Format,$Unit);
  2419. $TxtPos = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
  2420. $XOffset = 0; $YOffset = 0;
  2421. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
  2422. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
  2423. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
  2424. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}
  2425. $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
  2426. $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;
  2427. $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
  2428. }
  2429. if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
  2430. {
  2431. if ( $MinLabelPos == BOUND_LABEL_POS_TOP || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
  2432. if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }
  2433. $XPos = $X + $MinPos*$XStep + $SerieOffset;
  2434. $Label = $MinLabelTxt.$this->scaleFormat($MinValue,$Mode,$Format,$Unit);
  2435. $TxtPos = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
  2436. $XOffset = 0; $YOffset = 0;
  2437. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
  2438. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
  2439. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
  2440. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}
  2441. $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
  2442. $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;
  2443. $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
  2444. }
  2445. }
  2446. }
  2447. }
  2448. }
  2449. /* Draw a plot chart */
  2450. function drawPlotChart($Format=NULL)
  2451. {
  2452. $PlotSize = isset($Format["PlotSize"]) ? $Format["PlotSize"] : 3;
  2453. $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : FALSE;
  2454. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 50;
  2455. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 50;
  2456. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 50;
  2457. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
  2458. $BorderSize = isset($Format["BorderSize"]) ? $Format["BorderSize"] : 2;
  2459. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  2460. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2461. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
  2462. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2463. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2464. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2465. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2466. $Data = $this->DataSet->getData();
  2467. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2468. foreach($Data["Series"] as $SerieName => $Serie)
  2469. {
  2470. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2471. {
  2472. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2473. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  2474. if ( isset($Serie["Picture"]) )
  2475. { $Picture = $Serie["Picture"]; list($PicWidth,$PicHeight,$PicType) = $this->getPicInfo($Picture); }
  2476. else { $Picture = NULL; $PicOffset = 0; }
  2477. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2478. $AxisID = $Serie["Axis"];
  2479. $Shape = $Serie["Shape"];
  2480. $Mode = $Data["Axis"][$AxisID]["Display"];
  2481. $Format = $Data["Axis"][$AxisID]["Format"];
  2482. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2483. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2484. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2485. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2486. {
  2487. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2488. if ( $Picture != NULL ) { $PicOffset = $PicHeight / 2; $PlotSize = 0; }
  2489. $X = $this->GraphAreaX1 + $XMargin;
  2490. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2491. foreach($PosArray as $Key => $Y)
  2492. {
  2493. if ( $DisplayValues )
  2494. $this->drawText($X,$Y-$DisplayOffset-$PlotSize-$BorderSize-$PicOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2495. if ( $Y != VOID )
  2496. {
  2497. if ( $Picture != NULL )
  2498. { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
  2499. else
  2500. { $this->drawShape($X,$Y,$Shape,$PlotSize,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha); }
  2501. }
  2502. $X = $X + $XStep;
  2503. }
  2504. }
  2505. else
  2506. {
  2507. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2508. if ( $Picture != NULL ) { $PicOffset = $PicWidth / 2; $PlotSize = 0; }
  2509. $Y = $this->GraphAreaY1 + $XMargin;
  2510. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2511. foreach($PosArray as $Key => $X)
  2512. {
  2513. if ( $DisplayValues )
  2514. $this->drawText($X+$DisplayOffset+$PlotSize+$BorderSize+$PicOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2515. if ( $X != VOID )
  2516. {
  2517. if ( $Picture != NULL )
  2518. { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
  2519. else
  2520. { $this->drawShape($X,$Y,$Shape,$PlotSize,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha); }
  2521. }
  2522. $Y = $Y + $YStep;
  2523. }
  2524. }
  2525. }
  2526. }
  2527. }
  2528. /* Draw a spline chart */
  2529. function drawSplineChart($Format=NULL)
  2530. {
  2531. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
  2532. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  2533. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL; // 234
  2534. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL; // 55
  2535. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL; // 26
  2536. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2537. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2538. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2539. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2540. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2541. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2542. $Data = $this->DataSet->getData();
  2543. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2544. foreach($Data["Series"] as $SerieName => $Serie)
  2545. {
  2546. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2547. {
  2548. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  2549. if ( $BreakR == NULL )
  2550. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks);
  2551. else
  2552. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  2553. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2554. $AxisID = $Serie["Axis"];
  2555. $Mode = $Data["Axis"][$AxisID]["Display"];
  2556. $Format = $Data["Axis"][$AxisID]["Format"];
  2557. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2558. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2559. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2560. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2561. {
  2562. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2563. $X = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
  2564. $Force = $XStep / 5;
  2565. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2566. $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
  2567. foreach($PosArray as $Key => $Y)
  2568. {
  2569. if ( $DisplayValues )
  2570. $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2571. if ( $Y == VOID && $LastY != NULL )
  2572. { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }
  2573. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  2574. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }
  2575. if ( $Y != VOID )
  2576. $WayPoints[] = array($X,$Y);
  2577. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  2578. if ( $Y == VOID ) { $Y = NULL; }
  2579. $LastX = $X; $LastY = $Y;
  2580. $X = $X + $XStep;
  2581. }
  2582. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2583. }
  2584. else
  2585. {
  2586. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2587. $Y = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
  2588. $Force = $YStep / 5;
  2589. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2590. $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
  2591. foreach($PosArray as $Key => $X)
  2592. {
  2593. if ( $DisplayValues )
  2594. $this->drawText($X+$DisplayOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2595. if ( $X == VOID && $LastX != NULL )
  2596. { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }
  2597. if ( $X != VOID && $LastX == NULL && $LastGoodX != NULL && !$BreakVoid )
  2598. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }
  2599. if ( $X != VOID )
  2600. $WayPoints[] = array($X,$Y);
  2601. if ( $X != VOID ) { $LastGoodX = $X; $LastGoodY = $Y; }
  2602. if ( $X == VOID ) { $X = NULL; }
  2603. $LastX = $X; $LastY = $Y;
  2604. $Y = $Y + $YStep;
  2605. }
  2606. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2607. }
  2608. }
  2609. }
  2610. }
  2611. /* Draw a filled spline chart */
  2612. function drawFilledSplineChart($Format=NULL)
  2613. {
  2614. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2615. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2616. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2617. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2618. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2619. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2620. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  2621. $Data = $this->DataSet->getData();
  2622. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2623. foreach($Data["Series"] as $SerieName => $Serie)
  2624. {
  2625. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2626. {
  2627. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2628. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2629. $AxisID = $Serie["Axis"];
  2630. $Mode = $Data["Axis"][$AxisID]["Display"];
  2631. $Format = $Data["Axis"][$AxisID]["Format"];
  2632. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2633. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2634. if ( $AroundZero ) { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }
  2635. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2636. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2637. {
  2638. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2639. $X = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
  2640. $Force = $XStep / 5;
  2641. if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }
  2642. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  2643. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  2644. $LastX = ""; $LastY = "";
  2645. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2646. foreach($PosArray as $Key => $Y)
  2647. {
  2648. if ( $DisplayValues )
  2649. $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2650. if ( $Y == VOID )
  2651. {
  2652. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  2653. if ( $Area != "" )
  2654. {
  2655. foreach ($Area as $key => $Points)
  2656. {
  2657. $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
  2658. foreach($Points as $subKey => $Point)
  2659. {
  2660. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  2661. $Corners[] = $Point["Y"]+1;
  2662. }
  2663. $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;
  2664. $this->drawPolygon($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE));
  2665. }
  2666. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  2667. }
  2668. $WayPoints = "";
  2669. }
  2670. else
  2671. $WayPoints[] = array($X,$Y-.5); /* -.5 for AA visual fix */
  2672. $X = $X + $XStep;
  2673. }
  2674. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  2675. if ( $Area != "" )
  2676. {
  2677. foreach ($Area as $key => $Points)
  2678. {
  2679. $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
  2680. foreach($Points as $subKey => $Point)
  2681. {
  2682. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  2683. $Corners[] = $Point["Y"]+1;
  2684. }
  2685. $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;
  2686. $this->drawPolygon($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE));
  2687. }
  2688. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  2689. }
  2690. }
  2691. else
  2692. {
  2693. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2694. $Y = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
  2695. $Force = $YStep / 5;
  2696. if ( !$AroundZero ) { $YZero = $this->GraphAreaX1+1; }
  2697. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  2698. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  2699. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2700. foreach($PosArray as $Key => $X)
  2701. {
  2702. if ( $DisplayValues )
  2703. $this->drawText($X+$DisplayOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2704. if ( $X == VOID )
  2705. {
  2706. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  2707. if ( $Area != "" )
  2708. {
  2709. foreach ($Area as $key => $Points)
  2710. {
  2711. $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
  2712. foreach($Points as $subKey => $Point)
  2713. {
  2714. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  2715. $Corners[] = $Point["Y"];
  2716. }
  2717. $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;
  2718. $this->drawPolygon($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE));
  2719. }
  2720. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  2721. }
  2722. $WayPoints = "";
  2723. }
  2724. else
  2725. $WayPoints[] = array($X,$Y);
  2726. $Y = $Y + $YStep;
  2727. }
  2728. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  2729. if ( $Area != "" )
  2730. {
  2731. foreach ($Area as $key => $Points)
  2732. {
  2733. $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
  2734. foreach($Points as $subKey => $Point)
  2735. {
  2736. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  2737. $Corners[] = $Point["Y"];
  2738. }
  2739. $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;
  2740. $this->drawPolygon($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE));
  2741. }
  2742. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  2743. }
  2744. }
  2745. }
  2746. }
  2747. }
  2748. /* Draw a line chart */
  2749. function drawLineChart($Format=NULL)
  2750. {
  2751. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
  2752. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  2753. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
  2754. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
  2755. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
  2756. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2757. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2758. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2759. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2760. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2761. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2762. $Data = $this->DataSet->getData();
  2763. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2764. foreach($Data["Series"] as $SerieName => $Serie)
  2765. {
  2766. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2767. {
  2768. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  2769. if ( $BreakR == NULL )
  2770. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  2771. else
  2772. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  2773. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2774. $AxisID = $Serie["Axis"];
  2775. $Mode = $Data["Axis"][$AxisID]["Display"];
  2776. $Format = $Data["Axis"][$AxisID]["Format"];
  2777. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2778. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2779. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2780. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2781. {
  2782. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2783. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  2784. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2785. $LastGoodY = NULL; $LastGoodX = NULL;
  2786. foreach($PosArray as $Key => $Y)
  2787. {
  2788. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  2789. {
  2790. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  2791. $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  2792. }
  2793. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  2794. $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2795. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  2796. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }
  2797. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  2798. if ( $Y == VOID ) { $Y = NULL; }
  2799. $LastX = $X; $LastY = $Y;
  2800. $X = $X + $XStep;
  2801. }
  2802. }
  2803. else
  2804. {
  2805. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2806. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  2807. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2808. $LastGoodY = NULL; $LastGoodX = NULL;
  2809. foreach($PosArray as $Key => $X)
  2810. {
  2811. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  2812. { $this->drawText($X+$DisplayOffset+$Weight,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
  2813. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  2814. $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2815. if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
  2816. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }
  2817. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  2818. if ( $X == VOID ) { $X = NULL; }
  2819. $LastX = $X; $LastY = $Y;
  2820. $Y = $Y + $YStep;
  2821. }
  2822. }
  2823. }
  2824. }
  2825. }
  2826. /* Draw a step chart */
  2827. function drawStepChart($Format=NULL)
  2828. {
  2829. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : FALSE;
  2830. $ReCenter = isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
  2831. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  2832. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
  2833. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
  2834. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
  2835. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
  2836. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2837. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2838. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2839. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2840. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2841. $Data = $this->DataSet->getData();
  2842. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2843. foreach($Data["Series"] as $SerieName => $Serie)
  2844. {
  2845. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2846. {
  2847. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  2848. if ( $BreakR == NULL )
  2849. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  2850. else
  2851. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  2852. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2853. $AxisID = $Serie["Axis"];
  2854. $Mode = $Data["Axis"][$AxisID]["Display"];
  2855. $Format = $Data["Axis"][$AxisID]["Format"];
  2856. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2857. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  2858. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2859. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2860. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2861. {
  2862. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2863. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  2864. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2865. $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
  2866. foreach($PosArray as $Key => $Y)
  2867. {
  2868. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  2869. {
  2870. if ( $Y <= $LastY ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  2871. $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  2872. }
  2873. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  2874. {
  2875. $this->drawLine($LastX,$LastY,$X,$LastY,$Color);
  2876. $this->drawLine($X,$LastY,$X,$Y,$Color);
  2877. if ( $ReCenter && $X+$XStep < $this->GraphAreaX2 - $XMargin ) { $this->drawLine($X,$Y,$X+$XStep,$Y,$Color); }
  2878. }
  2879. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  2880. {
  2881. if ( $ReCenter )
  2882. $this->drawLine($LastGoodX+$XStep,$LastGoodY,$X,$LastGoodY,$BreakSettings);
  2883. else
  2884. $this->drawLine($LastGoodX,$LastGoodY,$X,$LastGoodY,$BreakSettings);
  2885. $this->drawLine($X,$LastGoodY,$X,$Y,$BreakSettings);
  2886. $LastGoodY = NULL;
  2887. }
  2888. elseif( !$BreakVoid && $LastGoodY == NULL && $Y != VOID )
  2889. $this->drawLine($this->GraphAreaX1 + $XMargin,$Y,$X,$Y,$BreakSettings);
  2890. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  2891. if ( $Y == VOID ) { $Y = NULL; }
  2892. if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
  2893. $LastX = $X; $LastY = $Y;
  2894. if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
  2895. $X = $X + $XStep;
  2896. }
  2897. if ( $ReCenter ) { $this->drawLine($LastX,$LastY,$this->GraphAreaX2 - $XMargin,$LastY,$Color); }
  2898. }
  2899. else
  2900. {
  2901. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2902. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  2903. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2904. $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
  2905. foreach($PosArray as $Key => $X)
  2906. {
  2907. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  2908. {
  2909. if ( $X >= $LastX ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
  2910. $this->drawText($X+$Offset+$Weight,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  2911. }
  2912. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  2913. {
  2914. $this->drawLine($LastX,$LastY,$LastX,$Y,$Color);
  2915. $this->drawLine($LastX,$Y,$X,$Y,$Color);
  2916. }
  2917. if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
  2918. {
  2919. $this->drawLine($LastGoodX,$LastGoodY,$LastGoodX,$LastGoodY+$YStep,$Color);
  2920. $this->drawLine($LastGoodX,$LastGoodY+$YStep,$LastGoodX,$Y,$BreakSettings);
  2921. $this->drawLine($LastGoodX,$Y,$X,$Y,$BreakSettings);
  2922. $LastGoodY = NULL;
  2923. }
  2924. elseif ( $X != VOID && $LastGoodY == NULL && !$BreakVoid )
  2925. $this->drawLine($X,$this->GraphAreaY1 + $XMargin,$X,$Y,$BreakSettings);
  2926. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  2927. if ( $X == VOID ) { $X = NULL; }
  2928. if ( !$Init && $ReCenter ) { $Y = $Y - $YStep/2; $Init = TRUE; }
  2929. $LastX = $X; $LastY = $Y;
  2930. if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
  2931. $Y = $Y + $YStep;
  2932. }
  2933. if ( $ReCenter ) { $this->drawLine($LastX,$LastY,$LastX,$this->GraphAreaY2 - $XMargin,$Color); }
  2934. }
  2935. }
  2936. }
  2937. }
  2938. /* Draw a step chart */
  2939. function drawFilledStepChart($Format=NULL)
  2940. {
  2941. $ReCenter = isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
  2942. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
  2943. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2944. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2945. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
  2946. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2947. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2948. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2949. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  2950. $Data = $this->DataSet->getData();
  2951. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2952. foreach($Data["Series"] as $SerieName => $Serie)
  2953. {
  2954. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2955. {
  2956. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  2957. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2958. $AxisID = $Serie["Axis"];
  2959. $Mode = $Data["Axis"][$AxisID]["Display"];
  2960. $Format = $Data["Axis"][$AxisID]["Format"];
  2961. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2962. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  2963. if ( $ForceTransparency != NULL ) { $Color["Alpha"] = $ForceTransparency; } else { $Color["Alpha"] = $Alpha; }
  2964. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2965. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  2966. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2967. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2968. {
  2969. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  2970. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  2971. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2972. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  2973. if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }
  2974. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2975. $LastGoodY = NULL; $LastGoodX = NULL; $Points = ""; $Init = FALSE;
  2976. foreach($PosArray as $Key => $Y)
  2977. {
  2978. if ( $Y == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
  2979. {
  2980. $Points[] = $LastX; $Points[] = $LastY;
  2981. $Points[] = $X; $Points[] = $LastY;
  2982. $Points[] = $X; $Points[] = $YZero;
  2983. $this->drawPolygon($Points,$Color);
  2984. $Points = "";
  2985. }
  2986. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  2987. {
  2988. if ( $Points == "") { $Points[] = $LastX; $Points[] = $YZero; }
  2989. $Points[] = $LastX; $Points[] = $LastY;
  2990. $Points[] = $X; $Points[] = $LastY;
  2991. $Points[] = $X; $Points[] = $Y;
  2992. }
  2993. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  2994. if ( $Y == VOID ) { $Y = NULL; }
  2995. if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
  2996. $LastX = $X; $LastY = $Y;
  2997. if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
  2998. $X = $X + $XStep;
  2999. }
  3000. if ( $ReCenter )
  3001. {
  3002. $Points[] = $LastX+$XStep/2; $Points[] = $LastY;
  3003. $Points[] = $LastX+$XStep/2; $Points[] = $YZero;
  3004. }
  3005. else
  3006. { $Points[] = $LastX; $Points[] = $YZero; }
  3007. $this->drawPolygon($Points,$Color);
  3008. }
  3009. else
  3010. {
  3011. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3012. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3013. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3014. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3015. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3016. $LastGoodY = NULL; $LastGoodX = NULL; $Points = "";
  3017. foreach($PosArray as $Key => $X)
  3018. {
  3019. if ( $X == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
  3020. {
  3021. $Points[] = $LastX; $Points[] = $LastY;
  3022. $Points[] = $LastX; $Points[] = $Y;
  3023. $Points[] = $YZero; $Points[] = $Y;
  3024. $this->drawPolygon($Points,$Color);
  3025. $Points = "";
  3026. }
  3027. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3028. {
  3029. if ( $Points == "") { $Points[] = $YZero; $Points[] = $LastY; }
  3030. $Points[] = $LastX; $Points[] = $LastY;
  3031. $Points[] = $LastX; $Points[] = $Y;
  3032. $Points[] = $X; $Points[] = $Y;
  3033. }
  3034. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3035. if ( $X == VOID ) { $X = NULL; }
  3036. if ( $LastX == NULL && $ReCenter ) { $Y = $Y - $YStep/2; }
  3037. $LastX = $X; $LastY = $Y;
  3038. if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
  3039. $Y = $Y + $YStep;
  3040. }
  3041. if ( $ReCenter )
  3042. {
  3043. $Points[] = $LastX; $Points[] = $LastY+$YStep/2;
  3044. $Points[] = $YZero; $Points[] = $LastY+$YStep/2;
  3045. }
  3046. else
  3047. { $Points[] = $YZero; $Points[] = $LastY; }
  3048. $this->drawPolygon($Points,$Color);
  3049. }
  3050. }
  3051. }
  3052. }
  3053. /* Draw an area chart */
  3054. function drawAreaChart($Format=NULL)
  3055. {
  3056. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3057. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3058. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3059. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3060. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3061. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3062. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : 50;
  3063. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3064. $Data = $this->DataSet->getData();
  3065. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3066. foreach($Data["Series"] as $SerieName => $Serie)
  3067. {
  3068. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3069. {
  3070. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3071. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3072. $AxisID = $Serie["Axis"];
  3073. $Mode = $Data["Axis"][$AxisID]["Display"];
  3074. $Format = $Data["Axis"][$AxisID]["Format"];
  3075. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3076. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3077. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  3078. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3079. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3080. {
  3081. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3082. $Areas = ""; $AreaID = 0;
  3083. $Areas[$AreaID][] = $this->GraphAreaX1 + $XMargin;
  3084. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3085. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3086. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3087. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3088. foreach($PosArray as $Key => $Y)
  3089. {
  3090. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3091. {
  3092. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3093. $this->drawText($X,$Y-$Offset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3094. }
  3095. if ( $Y == VOID && isset($Areas[$AreaID]) )
  3096. {
  3097. $Areas[$AreaID][] = $LastX;
  3098. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3099. $AreaID++;
  3100. }
  3101. elseif ($Y != VOID)
  3102. {
  3103. if ( !isset($Areas[$AreaID]) )
  3104. {
  3105. $Areas[$AreaID][] = $X;
  3106. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3107. }
  3108. $Areas[$AreaID][] = $X;
  3109. $Areas[$AreaID][] = $Y;
  3110. }
  3111. $LastX = $X;
  3112. $X = $X + $XStep;
  3113. }
  3114. $Areas[$AreaID][] = $LastX;
  3115. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3116. $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
  3117. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  3118. foreach($Areas as $Key => $Points)
  3119. $this->drawPolygon($Points,$Color);
  3120. }
  3121. else
  3122. {
  3123. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3124. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3125. $Areas = ""; $AreaID = 0;
  3126. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3127. $Areas[$AreaID][] = $this->GraphAreaY1 + $XMargin;
  3128. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3129. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3130. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3131. foreach($PosArray as $Key => $X)
  3132. {
  3133. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3134. {
  3135. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3136. $this->drawText($X+$Offset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3137. }
  3138. if ( $X == VOID && isset($Areas[$AreaID]) )
  3139. {
  3140. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3141. $Areas[$AreaID][] = $LastY;
  3142. $AreaID++;
  3143. }
  3144. elseif ($X != VOID)
  3145. {
  3146. if ( !isset($Areas[$AreaID]) )
  3147. {
  3148. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3149. $Areas[$AreaID][] = $Y;
  3150. }
  3151. $Areas[$AreaID][] = $X;
  3152. $Areas[$AreaID][] = $Y;
  3153. }
  3154. $LastX = $X; $LastY = $Y;
  3155. $Y = $Y + $YStep;
  3156. }
  3157. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3158. $Areas[$AreaID][] = $LastY;
  3159. $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
  3160. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  3161. foreach($Areas as $Key => $Points)
  3162. $this->drawPolygon($Points,$Color);
  3163. }
  3164. }
  3165. }
  3166. }
  3167. /* Draw a bar chart */
  3168. function drawBarChart($Format=NULL)
  3169. {
  3170. $Floating0Serie = isset($Format["Floating0Serie"]) ? $Format["Floating0Serie"] : NULL;
  3171. $Floating0Value = isset($Format["Floating0Value"]) ? $Format["Floating0Value"] : NULL;
  3172. $Draw0Line = isset($Format["Draw0Line"]) ? $Format["Draw0Line"] : FALSE;
  3173. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3174. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3175. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3176. $DisplayFont = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontName;
  3177. $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
  3178. $DisplayPos = isset($Format["DisplayPos"]) ? $Format["DisplayPos"] : LABEL_POS_OUTSIDE;
  3179. $DisplayShadow = isset($Format["DisplayShadow"]) ? $Format["DisplayShadow"] : TRUE;
  3180. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3181. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3182. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3183. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3184. $Interleave = isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
  3185. $Rounded = isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
  3186. $RoundRadius = isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
  3187. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  3188. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  3189. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  3190. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  3191. $Gradient = isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
  3192. $GradientMode = isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
  3193. $GradientAlpha = isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
  3194. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  3195. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  3196. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  3197. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
  3198. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
  3199. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
  3200. $TxtMargin = isset($Format["TxtMargin"]) ? $Format["TxtMargin"] : 6;
  3201. $OverrideColors = isset($Format["OverrideColors"]) ? $Format["OverrideColors"] : NULL;
  3202. $OverrideSurrounding = isset($Format["OverrideSurrounding"]) ? $Format["OverrideSurrounding"] : 30;
  3203. $Data = $this->DataSet->getData();
  3204. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3205. if ( $OverrideColors != NULL )
  3206. {
  3207. $OverrideColors = $this->validatePalette($OverrideColors,$OverrideSurrounding);
  3208. $this->DataSet->saveExtendedData("Palette",$OverrideColors);
  3209. }
  3210. $RestoreShadow = $this->Shadow;
  3211. $SeriesCount = $this->countDrawableSeries();
  3212. $CurrentSerie = 0;
  3213. foreach($Data["Series"] as $SerieName => $Serie)
  3214. {
  3215. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3216. {
  3217. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3218. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3219. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  3220. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);
  3221. $AxisID = $Serie["Axis"];
  3222. $Mode = $Data["Axis"][$AxisID]["Display"];
  3223. $Format = $Data["Axis"][$AxisID]["Format"];
  3224. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3225. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3226. if ( $Floating0Value != NULL )
  3227. { $YZero = $this->scaleComputeY($Floating0Value,array("AxisID"=>$Serie["Axis"])); }
  3228. else
  3229. { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }
  3230. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3231. {
  3232. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3233. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3234. if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3235. $X = $this->GraphAreaX1 + $XMargin;
  3236. if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
  3237. if ( $XDivs == 0 ) { $XSize = ($this->GraphAreaX2-$this->GraphAreaX1)/($SeriesCount+$Interleave); } else { $XSize = ($XStep / ($SeriesCount+$Interleave) ); }
  3238. $XOffset = -($XSize*$SeriesCount)/2 + $CurrentSerie * $XSize;
  3239. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $XOffset + $XSize / 2;
  3240. if ( $Rounded || $BorderR != -1) { $XSpace = 1; } else { $XSpace = 0; }
  3241. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3242. $ID = 0;
  3243. foreach($PosArray as $Key => $Y2)
  3244. {
  3245. if ( $Floating0Serie != NULL )
  3246. {
  3247. if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
  3248. $Value = $Data["Series"][$Floating0Serie]["Data"][$Key];
  3249. else { $Value = 0; }
  3250. $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
  3251. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3252. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3253. if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
  3254. }
  3255. if ( $OverrideColors != NULL )
  3256. { if ( isset($OverrideColors[$ID]) ) { $Color = array("R"=>$OverrideColors[$ID]["R"],"G"=>$OverrideColors[$ID]["G"],"B"=>$OverrideColors[$ID]["B"],"Alpha"=>$OverrideColors[$ID]["Alpha"],"BorderR"=>$OverrideColors[$ID]["BorderR"],"BorderG"=>$OverrideColors[$ID]["BorderG"],"BorderB"=>$OverrideColors[$ID]["BorderB"]); } else { $Color = $this->getRandomColor(); } }
  3257. if ( $Y2 != VOID )
  3258. {
  3259. $BarHeight = $Y1 - $Y2;
  3260. if ( $Serie["Data"][$Key] == 0 )
  3261. $this->drawLine($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y1,$Color);
  3262. else
  3263. {
  3264. if ( $Rounded )
  3265. $this->drawRoundedFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$RoundRadius,$Color);
  3266. else
  3267. {
  3268. $this->drawFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$Color);
  3269. if ( $Gradient )
  3270. {
  3271. $this->Shadow = FALSE;
  3272. if ( $GradientMode == GRADIENT_SIMPLE )
  3273. {
  3274. if ( $Serie["Data"][$Key] >= 0 )
  3275. $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3276. else
  3277. $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3278. $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_VERTICAL,$GradienColor);
  3279. }
  3280. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3281. {
  3282. $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3283. $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3284. $XSpan = floor($XSize / 3);
  3285. $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSpan-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor1);
  3286. $this->drawGradientArea($X+$XOffset+$XSpan+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor2);
  3287. }
  3288. $this->Shadow = $RestoreShadow;
  3289. }
  3290. }
  3291. if ( $Draw0Line )
  3292. {
  3293. $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);
  3294. if ( abs($Y1 - $Y2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
  3295. if ( $Y1 - $Y2 < 0 ) { $Line0Width = -$Line0Width; }
  3296. $this->drawFilledRectangle($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1)-$Line0Width,$Line0Color);
  3297. $this->drawLine($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1),$Line0Color);
  3298. }
  3299. }
  3300. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3301. {
  3302. if ( $DisplayShadow ) { $this->Shadow = TRUE; }
  3303. $Caption = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
  3304. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,90,$Caption);
  3305. $TxtHeight = $TxtPos[0]["Y"] - $TxtPos[1]["Y"] + $TxtMargin;
  3306. if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtHeight) < abs($BarHeight) )
  3307. {
  3308. $CenterX = (($X+$XOffset+$XSize-$XSpace)-($X+$XOffset+$XSpace))/2 + $X+$XOffset+$XSpace;
  3309. $CenterY = ($Y2-$Y1)/2 + $Y1;
  3310. $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"Angle"=>90));
  3311. }
  3312. else
  3313. {
  3314. if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3315. $this->drawText($X+$XOffset+$XSize/2,$Y2-$Offset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align,"FontSize"=>$DisplaySize));
  3316. }
  3317. $this->Shadow = $RestoreShadow;
  3318. }
  3319. }
  3320. $X = $X + $XStep;
  3321. $ID++;
  3322. }
  3323. }
  3324. else
  3325. {
  3326. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3327. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3328. if ( $XDivs == 0 ) { $YStep = 0; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3329. $Y = $this->GraphAreaY1 + $XMargin;
  3330. if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
  3331. if ( $XDivs == 0 ) { $YSize = ($this->GraphAreaY2-$this->GraphAreaY1)/($SeriesCount+$Interleave); } else { $YSize = ($YStep / ($SeriesCount+$Interleave) ); }
  3332. $YOffset = -($YSize*$SeriesCount)/2 + $CurrentSerie * $YSize;
  3333. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $YOffset + $YSize / 2;
  3334. if ( $Rounded || $BorderR != -1 ) { $YSpace = 1; } else { $YSpace = 0; }
  3335. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3336. $ID = 0 ;
  3337. foreach($PosArray as $Key => $X2)
  3338. {
  3339. if ( $Floating0Serie != NULL )
  3340. {
  3341. if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
  3342. $Value = $Data["Series"][$Floating0Serie]["Data"][$Key];
  3343. else { $Value = 0; }
  3344. $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
  3345. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3346. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3347. if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
  3348. }
  3349. if ( $OverrideColors != NULL )
  3350. { if ( isset($OverrideColors[$ID]) ) { $Color = array("R"=>$OverrideColors[$ID]["R"],"G"=>$OverrideColors[$ID]["G"],"B"=>$OverrideColors[$ID]["B"],"Alpha"=>$OverrideColors[$ID]["Alpha"],"BorderR"=>$OverrideColors[$ID]["BorderR"],"BorderG"=>$OverrideColors[$ID]["BorderG"],"BorderB"=>$OverrideColors[$ID]["BorderB"]); } else { $Color = $this->getRandomColor(); } }
  3351. if ( $X2 != VOID )
  3352. {
  3353. $BarWidth = $X2 - $X1;
  3354. if ( $Serie["Data"][$Key] == 0 )
  3355. $this->drawLine($X1,$Y+$YOffset+$YSpace,$X1,$Y+$YOffset+$YSize-$YSpace,$Color);
  3356. else
  3357. {
  3358. if ( $Rounded )
  3359. $this->drawRoundedFilledRectangle($X1+1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$RoundRadius,$Color);
  3360. else
  3361. {
  3362. $this->drawFilledRectangle($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$Color);
  3363. if ( $Gradient )
  3364. {
  3365. $this->Shadow = FALSE;
  3366. if ( $GradientMode == GRADIENT_SIMPLE )
  3367. {
  3368. if ( $Serie["Data"][$Key] >= 0 )
  3369. $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3370. else
  3371. $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3372. $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_HORIZONTAL,$GradienColor);
  3373. }
  3374. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3375. {
  3376. $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3377. $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3378. $YSpan = floor($YSize / 3);
  3379. $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSpan-$YSpace,DIRECTION_VERTICAL,$GradienColor1);
  3380. $this->drawGradientArea($X1,$Y+$YOffset+$YSpan,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_VERTICAL,$GradienColor2);
  3381. }
  3382. $this->Shadow = $RestoreShadow;
  3383. }
  3384. }
  3385. if ( $Draw0Line )
  3386. {
  3387. $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);
  3388. if ( abs($X1 - $X2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
  3389. if ( $X2 - $X1 < 0 ) { $Line0Width = -$Line0Width; }
  3390. $this->drawFilledRectangle(floor($X1),$Y+$YOffset+$YSpace,floor($X1)+$Line0Width,$Y+$YOffset+$YSize-$YSpace,$Line0Color);
  3391. $this->drawLine(floor($X1),$Y+$YOffset+$YSpace,floor($X1),$Y+$YOffset+$YSize-$YSpace,$Line0Color);
  3392. }
  3393. }
  3394. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3395. {
  3396. if ( $DisplayShadow ) { $this->Shadow = TRUE; }
  3397. $Caption = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
  3398. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3399. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"] + $TxtMargin;
  3400. if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtWidth) < abs($BarWidth) )
  3401. {
  3402. $CenterX = ($X2-$X1)/2 + $X1;
  3403. $CenterY = (($Y+$YOffset+$YSize-$YSpace)-($Y+$YOffset+$YSpace))/2 + ($Y+$YOffset+$YSpace);
  3404. $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize));
  3405. }
  3406. else
  3407. {
  3408. if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
  3409. $this->drawText($X2+$Offset,$Y+$YOffset+$YSize/2,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align,"FontSize"=>$DisplaySize));
  3410. }
  3411. $this->Shadow = $RestoreShadow;
  3412. }
  3413. }
  3414. $Y = $Y + $YStep;
  3415. $ID++;
  3416. }
  3417. }
  3418. $CurrentSerie++;
  3419. }
  3420. }
  3421. }
  3422. /* Draw a bar chart */
  3423. function drawStackedBarChart($Format=NULL)
  3424. {
  3425. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3426. $DisplayRound = isset($Format["DisplayRound"]) ? $Format["DisplayRound"] : 0;
  3427. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3428. $DisplayFont = isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;
  3429. $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
  3430. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3431. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3432. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3433. $Interleave = isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
  3434. $Rounded = isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
  3435. $RoundRadius = isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
  3436. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  3437. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  3438. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  3439. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  3440. $Gradient = isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
  3441. $GradientMode = isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
  3442. $GradientAlpha = isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
  3443. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  3444. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  3445. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  3446. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
  3447. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
  3448. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
  3449. $Data = $this->DataSet->getData();
  3450. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3451. $RestoreShadow = $this->Shadow;
  3452. $LastX = ""; $LastY = "";
  3453. foreach($Data["Series"] as $SerieName => $Serie)
  3454. {
  3455. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3456. {
  3457. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3458. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = 255; $DisplayG = 255; $DisplayB = 255; }
  3459. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  3460. $AxisID = $Serie["Axis"];
  3461. $Mode = $Data["Axis"][$AxisID]["Display"];
  3462. $Format = $Data["Axis"][$AxisID]["Format"];
  3463. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3464. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
  3465. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  3466. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3467. $Color = array("TransCorner"=>TRUE,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);
  3468. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3469. {
  3470. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3471. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3472. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3473. $X = $this->GraphAreaX1 + $XMargin;
  3474. $XSize = ($XStep / (1+$Interleave) );
  3475. $XOffset = -($XSize/2);
  3476. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3477. foreach($PosArray as $Key => $Height)
  3478. {
  3479. if ( $Height != VOID && $Serie["Data"][$Key] != 0 )
  3480. {
  3481. if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }
  3482. if ( !isset($LastY[$Key] ) ) { $LastY[$Key] = ""; }
  3483. if ( !isset($LastY[$Key][$Pos] ) ) { $LastY[$Key][$Pos] = $YZero; }
  3484. $Y1 = $LastY[$Key][$Pos];
  3485. $Y2 = $Y1 - $Height;
  3486. if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $Y1 != $YZero) ) { $YSpaceUp = 1; } else { $YSpaceUp = 0; }
  3487. if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $Y1 != $YZero) ) { $YSpaceDown = 1; } else { $YSpaceDown = 0; }
  3488. if ( $Rounded )
  3489. $this->drawRoundedFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$RoundRadius,$Color);
  3490. else
  3491. {
  3492. $this->drawFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$Color);
  3493. if ( $Gradient )
  3494. {
  3495. $this->Shadow = FALSE;
  3496. if ( $GradientMode == GRADIENT_SIMPLE )
  3497. {
  3498. $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3499. $this->drawGradientArea($X+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+.5,DIRECTION_VERTICAL,$GradientColor);
  3500. }
  3501. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3502. {
  3503. $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3504. $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3505. $XSpan = floor($XSize / 3);
  3506. $this->drawGradientArea($X+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSpan,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor1);
  3507. $this->drawGradientArea($X+$XSpan+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor2);
  3508. }
  3509. $this->Shadow = $RestoreShadow;
  3510. }
  3511. }
  3512. if ( $DisplayValues )
  3513. {
  3514. $BarHeight = abs($Y2-$Y1);
  3515. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  3516. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3517. $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
  3518. if ( $BarHeight > $TxtHeight )
  3519. {
  3520. $XCenter = ( ($X+$XOffset+$XSize) - ($X+$XOffset) ) / 2 + $X+$XOffset;
  3521. $YCenter = ( ($Y2) - ($Y1-$YSpaceUp+$YSpaceDown) ) / 2 + $Y1-$YSpaceUp+$YSpaceDown;
  3522. $this->drawText($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  3523. }
  3524. }
  3525. $LastY[$Key][$Pos] = $Y2;
  3526. }
  3527. $X = $X + $XStep;
  3528. }
  3529. }
  3530. else
  3531. {
  3532. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3533. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3534. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3535. $Y = $this->GraphAreaY1 + $XMargin;
  3536. $YSize = $YStep / (1+$Interleave);
  3537. $YOffset = -($YSize/2);
  3538. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3539. foreach($PosArray as $Key => $Width)
  3540. {
  3541. if ( $Width != VOID && $Serie["Data"][$Key] != 0 )
  3542. {
  3543. if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }
  3544. if ( !isset($LastX[$Key] ) ) { $LastX[$Key] = ""; }
  3545. if ( !isset($LastX[$Key][$Pos] ) ) { $LastX[$Key][$Pos] = $YZero; }
  3546. $X1 = $LastX[$Key][$Pos];
  3547. $X2 = $X1 + $Width;
  3548. if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $X1 != $YZero) ) { $XSpaceLeft = 2; } else { $XSpaceLeft = 0; }
  3549. if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $X1 != $YZero) ) { $XSpaceRight = 2; } else { $XSpaceRight = 0; }
  3550. if ( $Rounded )
  3551. $this->drawRoundedFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$RoundRadius,$Color);
  3552. else
  3553. {
  3554. $this->drawFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$Color);
  3555. if ( $Gradient )
  3556. {
  3557. $this->Shadow = FALSE;
  3558. if ( $GradientMode == GRADIENT_SIMPLE )
  3559. {
  3560. $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3561. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_HORIZONTAL,$GradientColor);
  3562. }
  3563. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3564. {
  3565. $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3566. $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3567. $YSpan = floor($YSize / 3);
  3568. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSpan,DIRECTION_VERTICAL,$GradientColor1);
  3569. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset+$YSpan,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_VERTICAL,$GradientColor2);
  3570. }
  3571. $this->Shadow = $RestoreShadow;
  3572. }
  3573. }
  3574. if ( $DisplayValues )
  3575. {
  3576. $BarWidth = abs($X2-$X1);
  3577. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  3578. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3579. $TxtWidth = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);
  3580. if ( $BarWidth > $TxtWidth )
  3581. {
  3582. $XCenter = ( $X2 - $X1 ) / 2 + $X1;
  3583. $YCenter = ( ($Y+$YOffset+$YSize) - ($Y+$YOffset) ) / 2 + $Y+$YOffset;
  3584. $this->drawText($XCenter,$YCenter,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  3585. }
  3586. }
  3587. $LastX[$Key][$Pos] = $X2;
  3588. }
  3589. $Y = $Y + $YStep;
  3590. }
  3591. }
  3592. }
  3593. }
  3594. }
  3595. /* Draw a bar chart */
  3596. function drawStackedAreaChart($Format=NULL)
  3597. {
  3598. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3599. $DisplayRound = isset($Format["DisplayRound"]) ? $Format["DisplayRound"] : 0;
  3600. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3601. $DisplayFont = isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;
  3602. $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
  3603. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3604. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3605. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3606. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  3607. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  3608. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  3609. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  3610. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
  3611. $Data = $this->DataSet->getData();
  3612. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3613. $RestoreShadow = $this->Shadow;
  3614. /* Determine if we only have positive or negatives values */
  3615. $Sign["+"] = 0; $Sign["-"] = 0;
  3616. foreach($Data["Series"] as $SerieName => $Serie)
  3617. {
  3618. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3619. { foreach($Serie["Data"] as $Key => $Value) { if ($Value > 0) { $Sign["+"]++; } elseif ($Value < 0) { $Sign["-"]++; } } }
  3620. }
  3621. if ( $Sign["+"] == 0 || $Sign["-"] == 0 ) { $SingleWay = TRUE; } else { $SingleWay = FALSE; }
  3622. $LastX = ""; $LastY = "";
  3623. foreach($Data["Series"] as $SerieName => $Serie)
  3624. {
  3625. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3626. {
  3627. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3628. if ( $ForceTransparency != NULL ) { $Alpha = $ForceTransparency; }
  3629. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = 255; $DisplayG = 255; $DisplayB = 255; }
  3630. if ( $Surrounding != NULL )
  3631. { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  3632. else
  3633. { $BorderR = $R; $BorderG = $G; $BorderB = $B; }
  3634. $AxisID = $Serie["Axis"];
  3635. $Mode = $Data["Axis"][$AxisID]["Display"];
  3636. $Format = $Data["Axis"][$AxisID]["Format"];
  3637. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3638. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
  3639. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  3640. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3641. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3642. {
  3643. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3644. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3645. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB,"SkipY"=>$YZero);
  3646. if ( $SingleWay ) { unset($Color["SkipY"]); }
  3647. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3648. $X = $this->GraphAreaX1 + $XMargin;
  3649. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3650. $PointsTop = ""; $PointsBottom = ""; $Labels = ""; $Pos = "+";
  3651. foreach($PosArray as $Key => $Height)
  3652. {
  3653. if ( !isset($LastY[$Key] ) ) { $LastY[$Key] = ""; }
  3654. if ( !isset($LastY[$Key][$Pos] ) ) { $LastY[$Key][$Pos] = $YZero; }
  3655. if ( $Height != VOID && $Serie["Data"][$Key] >= 0)
  3656. {
  3657. $Y1 = $LastY[$Key][$Pos];
  3658. $Y2 = $Y1 - $Height;
  3659. $PointsTop[] = $X; $PointsTop[] = $Y2;
  3660. $PointsBottom[] = $X; $PointsBottom[] = $Y1;
  3661. if ( $DisplayValues )
  3662. {
  3663. $BarHeight = abs($Y2-$Y1);
  3664. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  3665. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3666. $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
  3667. if ( $BarHeight > $TxtHeight )
  3668. {
  3669. $XCenter = $X;
  3670. $YCenter = $Y1- $BarHeight / 2;
  3671. $Labels[] = array($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  3672. }
  3673. }
  3674. $LastY[$Key][$Pos] = $Y2;
  3675. }
  3676. else
  3677. { $PointsTop[] = $X; $PointsTop[] = $LastY[$Key][$Pos]; $PointsBottom[] = $X; $PointsBottom[] = $LastY[$Key][$Pos]; }
  3678. $X = $X + $XStep;
  3679. }
  3680. $Points = $PointsTop;
  3681. for($i=count($PointsBottom)-2;$i>=0;$i-=2) { $Points[] = $PointsBottom[$i]; $Points[] = $PointsBottom[$i+1]; }
  3682. $this->drawPolygon($Points,$Color);
  3683. /* Reset the X axis parser for the negative values pass */
  3684. $X = $this->GraphAreaX1 + $XMargin;
  3685. $PointsTop = ""; $PointsBottom = ""; $Pos = "-";
  3686. foreach($PosArray as $Key => $Height)
  3687. {
  3688. if ( !isset($LastY[$Key] ) ) { $LastY[$Key] = ""; }
  3689. if ( !isset($LastY[$Key][$Pos] ) ) { $LastY[$Key][$Pos] = $YZero; }
  3690. if ( $Height != VOID && $Serie["Data"][$Key] < 0)
  3691. {
  3692. $Y1 = $LastY[$Key][$Pos];
  3693. $Y2 = $Y1 - $Height;
  3694. $PointsTop[] = $X; $PointsTop[] = $Y2;
  3695. $PointsBottom[] = $X; $PointsBottom[] = $Y1;
  3696. if ( $DisplayValues )
  3697. {
  3698. $BarHeight = abs($Y2-$Y1);
  3699. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  3700. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3701. $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
  3702. if ( $BarHeight > $TxtHeight )
  3703. {
  3704. $XCenter = $X;
  3705. $YCenter = $BarHeight / 2 + $Y1;
  3706. $Labels[] = array($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  3707. }
  3708. }
  3709. $LastY[$Key][$Pos] = $Y2;
  3710. }
  3711. else
  3712. { $PointsTop[] = $X; $PointsTop[] = $LastY[$Key][$Pos]; $PointsBottom[] = $X; $PointsBottom[] = $LastY[$Key][$Pos]; }
  3713. $X = $X + $XStep;
  3714. }
  3715. $Points = $PointsTop;
  3716. for($i=count($PointsBottom)-2;$i>=0;$i-=2) { $Points[] = $PointsBottom[$i]; $Points[] = $PointsBottom[$i+1]; }
  3717. $this->drawPolygon($Points,$Color);
  3718. if ( $DisplayValues ) { foreach($Labels as $Key => $Value) { $this->drawText($Value[0],$Value[1],$Value[2],$Value[3]);} }
  3719. }
  3720. else
  3721. {
  3722. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3723. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3724. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB,"SkipX"=>$YZero);
  3725. if ( $SingleWay ) { unset($Color["SkipX"]); }
  3726. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3727. $Y = $this->GraphAreaY1 + $XMargin;
  3728. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3729. $PointsTop = ""; $PointsBottom = ""; $Labels = ""; $Pos = "+";
  3730. foreach($PosArray as $Key => $Width)
  3731. {
  3732. if ( !isset($LastX[$Key] ) ) { $LastX[$Key] = ""; }
  3733. if ( !isset($LastX[$Key][$Pos] ) ) { $LastX[$Key][$Pos] = $YZero; }
  3734. if ( $Width != VOID && $Serie["Data"][$Key] >= 0)
  3735. {
  3736. $X1 = $LastX[$Key][$Pos];
  3737. $X2 = $X1 + $Width;
  3738. $PointsTop[] = $X1; $PointsTop[] = $Y;
  3739. $PointsBottom[] = $X2; $PointsBottom[] = $Y;
  3740. if ( $DisplayValues )
  3741. {
  3742. $BarWidth = abs($X2-$X1);
  3743. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  3744. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3745. $TxtWidth = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);
  3746. if ( $BarWidth > $TxtWidth )
  3747. {
  3748. $XCenter = $X1 + $BarWidth / 2;
  3749. $YCenter = $Y;
  3750. $Labels[] = array($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  3751. }
  3752. }
  3753. $LastX[$Key][$Pos] = $X2;
  3754. }
  3755. else
  3756. { $PointsTop[] = $LastX[$Key][$Pos]; $PointsTop[] = $Y; $PointsBottom[] = $LastX[$Key][$Pos]; $PointsBottom[] = $Y; }
  3757. $Y = $Y + $YStep;
  3758. }
  3759. $Points = $PointsTop;
  3760. for($i=count($PointsBottom)-2;$i>=0;$i-=2) { $Points[] = $PointsBottom[$i]; $Points[] = $PointsBottom[$i+1]; }
  3761. $this->drawPolygon($Points,$Color);
  3762. /* Reset the X axis parser for the negative values pass */
  3763. $Y = $this->GraphAreaY1 + $XMargin;
  3764. $PointsTop = ""; $PointsBottom = ""; $Pos = "-";
  3765. foreach($PosArray as $Key => $Width)
  3766. {
  3767. if ( !isset($LastX[$Key] ) ) { $LastX[$Key] = ""; }
  3768. if ( !isset($LastX[$Key][$Pos] ) ) { $LastX[$Key][$Pos] = $YZero; }
  3769. if ( $Width != VOID && $Serie["Data"][$Key] < 0)
  3770. {
  3771. $X1 = $LastX[$Key][$Pos];
  3772. $X2 = $X1 + $Width;
  3773. $PointsTop[] = $X1; $PointsTop[] = $Y;
  3774. $PointsBottom[] = $X2; $PointsBottom[] = $Y;
  3775. if ( $DisplayValues )
  3776. {
  3777. $BarWidth = abs($X2-$X1);
  3778. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  3779. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3780. $TxtWidth = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);
  3781. if ( $BarWidth > $TxtWidth )
  3782. {
  3783. $XCenter = $X1 - $BarWidth / 2;
  3784. $YCenter = $Y;
  3785. $Labels[] = array($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  3786. }
  3787. }
  3788. $LastX[$Key][$Pos] = $X2;
  3789. }
  3790. else
  3791. { $PointsTop[] = $LastX[$Key][$Pos]; $PointsTop[] = $Y; $PointsBottom[] = $LastX[$Key][$Pos]; $PointsBottom[] = $Y; }
  3792. $Y = $Y + $YStep;
  3793. }
  3794. $Points = $PointsTop;
  3795. for($i=count($PointsBottom)-2;$i>=0;$i-=2) { $Points[] = $PointsBottom[$i]; $Points[] = $PointsBottom[$i+1]; }
  3796. $this->drawPolygon($Points,$Color);
  3797. if ( $DisplayValues ) { foreach($Labels as $Key => $Value) { $this->drawText($Value[0],$Value[1],$Value[2],$Value[3]);} }
  3798. }
  3799. }
  3800. }
  3801. }
  3802. /* Returns a random color */
  3803. function getRandomColor($Alpha=100)
  3804. { return(array("R"=>rand(0,255),"G"=>rand(0,255),"B"=>rand(0,255),"Alpha"=>$Alpha)); }
  3805. /* Validate a palette */
  3806. function validatePalette($Colors,$Surrounding=NULL)
  3807. {
  3808. $Result = "";
  3809. if ( !is_array($Colors) ) { return($this->getRandomColor()); }
  3810. foreach($Colors as $Key => $Values)
  3811. {
  3812. if ( isset($Values["R"]) ) { $Result[$Key]["R"] = $Values["R"]; } else { $Result[$Key]["R"] = rand(0,255); }
  3813. if ( isset($Values["G"]) ) { $Result[$Key]["G"] = $Values["G"]; } else { $Result[$Key]["G"] = rand(0,255); }
  3814. if ( isset($Values["B"]) ) { $Result[$Key]["B"] = $Values["B"]; } else { $Result[$Key]["B"] = rand(0,255); }
  3815. if ( isset($Values["Alpha"]) ) { $Result[$Key]["Alpha"] = $Values["Alpha"]; } else { $Result[$Key]["Alpha"] = 100; }
  3816. if ( $Surrounding != NULL )
  3817. {
  3818. $Result[$Key]["BorderR"] = $Result[$Key]["R"] + $Surrounding;
  3819. $Result[$Key]["BorderG"] = $Result[$Key]["G"] + $Surrounding;
  3820. $Result[$Key]["BorderB"] = $Result[$Key]["B"] + $Surrounding;
  3821. }
  3822. else
  3823. {
  3824. if ( isset($Values["BorderR"]) ) { $Result[$Key]["BorderR"] = $Values["BorderR"]; } else { $Result[$Key]["BorderR"] = $Result[$Key]["R"]; }
  3825. if ( isset($Values["BorderG"]) ) { $Result[$Key]["BorderG"] = $Values["BorderG"]; } else { $Result[$Key]["BorderG"] = $Result[$Key]["G"]; }
  3826. if ( isset($Values["BorderB"]) ) { $Result[$Key]["BorderB"] = $Values["BorderB"]; } else { $Result[$Key]["BorderB"] = $Result[$Key]["B"]; }
  3827. if ( isset($Values["BorderAlpha"]) ) { $Result[$Key]["BorderAlpha"] = $Values["BorderAlpha"]; } else { $Result[$Key]["BorderAlpha"] = $Result[$Key]["Alpha"]; }
  3828. }
  3829. }
  3830. return($Result);
  3831. }
  3832. /* Draw the derivative chart associated to the data series */
  3833. function drawDerivative($Format=NULL)
  3834. {
  3835. $Offset = isset($Format["Offset"]) ? $Format["Offset"] : 10;
  3836. $SerieSpacing = isset($Format["SerieSpacing"]) ? $Format["SerieSpacing"] : 3;
  3837. $DerivativeHeight = isset($Format["DerivativeHeight"]) ? $Format["DerivativeHeight"] : 4;
  3838. $ShadedSlopeBox = isset($Format["ShadedSlopeBox"]) ? $Format["ShadedSlopeBox"] : FALSE;
  3839. $DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE;
  3840. $BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255;
  3841. $BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255;
  3842. $BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255;
  3843. $BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 20;
  3844. $DrawBorder = isset($Format["DrawBorder"]) ? $Format["DrawBorder"] : TRUE;
  3845. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 0;
  3846. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 0;
  3847. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 0;
  3848. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 100;
  3849. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : TRUE;
  3850. $CaptionHeight = isset($Format["CaptionHeight"]) ? $Format["CaptionHeight"] : 10;
  3851. $CaptionWidth = isset($Format["CaptionWidth"]) ? $Format["CaptionWidth"] : 20;
  3852. $CaptionMargin = isset($Format["CaptionMargin"]) ? $Format["CaptionMargin"] : 4;
  3853. $CaptionLine = isset($Format["CaptionLine"]) ? $Format["CaptionLine"] : FALSE;
  3854. $CaptionBox = isset($Format["CaptionBox"]) ? $Format["CaptionBox"] : FALSE;
  3855. $CaptionBorderR = isset($Format["CaptionBorderR"]) ? $Format["CaptionBorderR"] : 0;
  3856. $CaptionBorderG = isset($Format["CaptionBorderG"]) ? $Format["CaptionBorderG"] : 0;
  3857. $CaptionBorderB = isset($Format["CaptionBorderB"]) ? $Format["CaptionBorderB"] : 0;
  3858. $CaptionFillR = isset($Format["CaptionFillR"]) ? $Format["CaptionFillR"] : 255;
  3859. $CaptionFillG = isset($Format["CaptionFillG"]) ? $Format["CaptionFillG"] : 255;
  3860. $CaptionFillB = isset($Format["CaptionFillB"]) ? $Format["CaptionFillB"] : 255;
  3861. $CaptionFillAlpha = isset($Format["CaptionFillAlpha"]) ? $Format["CaptionFillAlpha"] : 80;
  3862. $PositiveSlopeStartR = isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 184;
  3863. $PositiveSlopeStartG = isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 234;
  3864. $PositiveSlopeStartB = isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 88;
  3865. $PositiveSlopeEndR = isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 239;
  3866. $PositiveSlopeEndG = isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 31;
  3867. $PositiveSlopeEndB = isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 36;
  3868. $NegativeSlopeStartR = isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 184;
  3869. $NegativeSlopeStartG = isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 234;
  3870. $NegativeSlopeStartB = isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 88;
  3871. $NegativeSlopeEndR = isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 67;
  3872. $NegativeSlopeEndG = isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 124;
  3873. $NegativeSlopeEndB = isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 227;
  3874. $Data = $this->DataSet->getData();
  3875. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3876. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3877. $YPos = $this->DataSet->Data["GraphArea"]["Y2"] + $Offset;
  3878. else
  3879. $XPos = $this->DataSet->Data["GraphArea"]["X2"] + $Offset;
  3880. foreach($Data["Series"] as $SerieName => $Serie)
  3881. {
  3882. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3883. {
  3884. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3885. $AxisID = $Serie["Axis"];
  3886. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3887. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3888. {
  3889. if ( $Caption )
  3890. {
  3891. if ( $CaptionLine )
  3892. {
  3893. $StartX = floor($this->GraphAreaX1-$CaptionWidth+$XMargin-$CaptionMargin);
  3894. $EndX = floor($this->GraphAreaX1-$CaptionMargin+$XMargin);
  3895. $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  3896. if ( $CaptionBox ) { $this->drawFilledRectangle($StartX,$YPos,$EndX,$YPos+$CaptionHeight,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
  3897. $this->drawLine($StartX+2,$YPos+($CaptionHeight/2),$EndX-2,$YPos+($CaptionHeight/2),$CaptionSettings);
  3898. }
  3899. else
  3900. $this->drawFilledRectangle($this->GraphAreaX1-$CaptionWidth+$XMargin-$CaptionMargin,$YPos,$this->GraphAreaX1-$CaptionMargin+$XMargin,$YPos+$CaptionHeight,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB));
  3901. }
  3902. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3903. $X = $this->GraphAreaX1 + $XMargin;
  3904. $TopY = $YPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
  3905. $BottomY = $YPos + ($CaptionHeight/2) + ($DerivativeHeight/2);
  3906. $StartX = floor($this->GraphAreaX1+$XMargin);
  3907. $EndX = floor($this->GraphAreaX2-$XMargin);
  3908. if ( $DrawBackground ) { $this->drawFilledRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
  3909. if ( $DrawBorder ) { $this->drawRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  3910. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3911. $RestoreShadow = $this->Shadow;
  3912. $this->Shadow = FALSE;
  3913. /* Determine the Max slope index */
  3914. $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
  3915. foreach($PosArray as $Key => $Y)
  3916. {
  3917. if ( $Y != VOID && $LastX != NULL )
  3918. { $Slope = ($LastY - $Y); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }
  3919. if ( $Y == VOID )
  3920. { $LastX = NULL; $LastY = NULL; }
  3921. else
  3922. { $LastX = $X; $LastY = $Y; }
  3923. }
  3924. $LastX = NULL; $LastY = NULL; $LastColor = NULL;
  3925. foreach($PosArray as $Key => $Y)
  3926. {
  3927. if ( $Y != VOID && $LastY != NULL )
  3928. {
  3929. $Slope = ($LastY - $Y);
  3930. if ( $Slope >= 0 )
  3931. {
  3932. $SlopeIndex = (100 / $MaxSlope) * $Slope;
  3933. $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
  3934. $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
  3935. $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
  3936. }
  3937. elseif ( $Slope < 0 )
  3938. {
  3939. $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
  3940. $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
  3941. $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
  3942. $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
  3943. }
  3944. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  3945. if ( $ShadedSlopeBox && $LastColor != NULL ) // && $Slope != 0
  3946. {
  3947. $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  3948. $this->drawGradientArea($LastX,$TopY,$X,$BottomY,DIRECTION_HORIZONTAL,$GradientSettings);
  3949. }
  3950. elseif ( !$ShadedSlopeBox || $LastColor == NULL ) // || $Slope == 0
  3951. $this->drawFilledRectangle(floor($LastX),$TopY,floor($X),$BottomY,$Color);
  3952. $LastColor = $Color;
  3953. }
  3954. if ( $Y == VOID )
  3955. { $LastY = NULL; }
  3956. else
  3957. { $LastX = $X; $LastY = $Y; }
  3958. $X = $X + $XStep;
  3959. }
  3960. $YPos = $YPos + $CaptionHeight + $SerieSpacing;
  3961. }
  3962. else
  3963. {
  3964. if ( $Caption )
  3965. {
  3966. $StartY = floor($this->GraphAreaY1-$CaptionWidth+$XMargin-$CaptionMargin);
  3967. $EndY = floor($this->GraphAreaY1-$CaptionMargin+$XMargin);
  3968. if ( $CaptionLine )
  3969. {
  3970. $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  3971. if ( $CaptionBox ) { $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
  3972. $this->drawLine($XPos+($CaptionHeight/2),$StartY+2,$XPos+($CaptionHeight/2),$EndY-2,$CaptionSettings);
  3973. }
  3974. else
  3975. $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB));
  3976. }
  3977. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3978. $Y = $this->GraphAreaY1 + $XMargin;
  3979. $TopX = $XPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
  3980. $BottomX = $XPos + ($CaptionHeight/2) + ($DerivativeHeight/2);
  3981. $StartY = floor($this->GraphAreaY1+$XMargin);
  3982. $EndY = floor($this->GraphAreaY2-$XMargin);
  3983. if ( $DrawBackground ) { $this->drawFilledRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
  3984. if ( $DrawBorder ) { $this->drawRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  3985. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3986. $RestoreShadow = $this->Shadow;
  3987. $this->Shadow = FALSE;
  3988. /* Determine the Max slope index */
  3989. $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
  3990. foreach($PosArray as $Key => $X)
  3991. {
  3992. if ( $X != VOID && $LastX != NULL )
  3993. { $Slope = ($X - $LastX); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }
  3994. if ( $X == VOID )
  3995. { $LastX = NULL; }
  3996. else
  3997. { $LastX = $X; }
  3998. }
  3999. $LastX = NULL; $LastY = NULL; $LastColor = NULL;
  4000. foreach($PosArray as $Key => $X)
  4001. {
  4002. if ( $X != VOID && $LastX != NULL )
  4003. {
  4004. $Slope = ($X - $LastX);
  4005. if ( $Slope >= 0 )
  4006. {
  4007. $SlopeIndex = (100 / $MaxSlope) * $Slope;
  4008. $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
  4009. $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
  4010. $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
  4011. }
  4012. elseif ( $Slope < 0 )
  4013. {
  4014. $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
  4015. $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
  4016. $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
  4017. $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
  4018. }
  4019. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  4020. if ( $ShadedSlopeBox && $LastColor != NULL )
  4021. {
  4022. $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  4023. $this->drawGradientArea($TopX,$LastY,$BottomX,$Y,DIRECTION_VERTICAL,$GradientSettings);
  4024. }
  4025. elseif ( !$ShadedSlopeBox || $LastColor == NULL )
  4026. $this->drawFilledRectangle($TopX,floor($LastY),$BottomX,floor($Y),$Color);
  4027. $LastColor = $Color;
  4028. }
  4029. if ( $X == VOID )
  4030. { $LastX = NULL; }
  4031. else
  4032. { $LastX = $X; $LastY = $Y; }
  4033. $Y = $Y + $XStep;
  4034. }
  4035. $XPos = $XPos + $CaptionHeight + $SerieSpacing;
  4036. }
  4037. $this->Shadow = $RestoreShadow;
  4038. }
  4039. }
  4040. }
  4041. /* Draw the line of best fit */
  4042. function drawBestFit($Format="")
  4043. {
  4044. $OverrideTicks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  4045. $OverrideR = isset($Format["R"]) ? $Format["R"] : VOID;
  4046. $OverrideG = isset($Format["G"]) ? $Format["G"] : VOID;
  4047. $OverrideB = isset($Format["B"]) ? $Format["B"] : VOID;
  4048. $OverrideAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : VOID;
  4049. $Data = $this->DataSet->getData();
  4050. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4051. foreach($Data["Series"] as $SerieName => $Serie)
  4052. {
  4053. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4054. {
  4055. if ( $OverrideR != VOID && $OverrideG != VOID && $OverrideB != VOID ) { $R = $OverrideR; $G = $OverrideG; $B = $OverrideB; } else { $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; }
  4056. if ( $OverrideTicks == NULL ) { $Ticks = $Serie["Ticks"]; } else { $Ticks = $OverrideTicks; }
  4057. if ( $OverrideAlpha == VOID ) { $Alpha = $Serie["Color"]["Alpha"]; } else { $Alpha = $OverrideAlpha; }
  4058. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks);
  4059. $AxisID = $Serie["Axis"];
  4060. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  4061. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4062. {
  4063. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4064. $X = $this->GraphAreaX1 + $XMargin;
  4065. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4066. $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
  4067. foreach($PosArray as $Key => $Y)
  4068. {
  4069. $Sxy = $Sxy + $X*$Y;
  4070. $Sx = $Sx + $X;
  4071. $Sy = $Sy + $Y;
  4072. $Sxx = $Sxx + $X*$X;
  4073. $X = $X + $XStep;
  4074. }
  4075. $n = count($PosArray);
  4076. $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
  4077. $B = (($Sy)-($M*$Sx))/($n);
  4078. $X1 = $this->GraphAreaX1 + $XMargin;
  4079. $Y1 = $M * $X1 + $B;
  4080. $X2 = $this->GraphAreaX2 - $XMargin;
  4081. $Y2 = $M * $X2 + $B;
  4082. if ( $Y1 < $this->GraphAreaY1 ) { $X1 = $X1 + ($this->GraphAreaY1-$Y1); $Y1 = $this->GraphAreaY1; }
  4083. if ( $Y1 > $this->GraphAreaY2 ) { $X1 = $X1 + ($Y1-$this->GraphAreaY2); $Y1 = $this->GraphAreaY2; }
  4084. if ( $Y2 < $this->GraphAreaY1 ) { $X2 = $X2 - ($this->GraphAreaY1-$Y2); $Y2 = $this->GraphAreaY1; }
  4085. if ( $Y2 > $this->GraphAreaY2 ) { $X2 = $X2 - ($Y2-$this->GraphAreaY2); $Y2 = $this->GraphAreaY2; }
  4086. $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
  4087. }
  4088. else
  4089. {
  4090. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4091. $Y = $this->GraphAreaY1 + $XMargin;
  4092. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4093. $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
  4094. foreach($PosArray as $Key => $X)
  4095. {
  4096. $Sxy = $Sxy + $X*$Y;
  4097. $Sx = $Sx + $Y;
  4098. $Sy = $Sy + $X;
  4099. $Sxx = $Sxx + $Y*$Y;
  4100. $Y = $Y + $YStep;
  4101. }
  4102. $n = count($PosArray);
  4103. $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
  4104. $B = (($Sy)-($M*$Sx))/($n);
  4105. $Y1 = $this->GraphAreaY1 + $XMargin;
  4106. $X1 = $M * $Y1 + $B;
  4107. $Y2 = $this->GraphAreaY2 - $XMargin;
  4108. $X2 = $M * $Y2 + $B;
  4109. if ( $X1 < $this->GraphAreaX1 ) { $Y1 = $Y1 + ($this->GraphAreaX1-$X1); $X1 = $this->GraphAreaX1; }
  4110. if ( $X1 > $this->GraphAreaX2 ) { $Y1 = $Y1 + ($X1-$this->GraphAreaX2); $X1 = $this->GraphAreaX2; }
  4111. if ( $X2 < $this->GraphAreaX1 ) { $Y2 = $Y2 - ($this->GraphAreaY1-$X2); $X2 = $this->GraphAreaX1; }
  4112. if ( $X2 > $this->GraphAreaX2 ) { $Y2 = $Y2 - ($X2-$this->GraphAreaX2); $X2 = $this->GraphAreaX2; }
  4113. $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
  4114. }
  4115. }
  4116. }
  4117. }
  4118. /* Write labels */
  4119. function writeLabel($SeriesName,$Indexes,$Format="")
  4120. {
  4121. $OverrideTitle = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
  4122. $ForceLabels = isset($Format["ForceLabels"]) ? $Format["ForceLabels"] : NULL;
  4123. $DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
  4124. $DrawVerticalLine = isset($Format["DrawVerticalLine"]) ? $Format["DrawVerticalLine"] : FALSE;
  4125. $VerticalLineR = isset($Format["VerticalLineR"]) ? $Format["VerticalLineR"] : 0;
  4126. $VerticalLineG = isset($Format["VerticalLineG"]) ? $Format["VerticalLineG"] : 0;
  4127. $VerticalLineB = isset($Format["VerticalLineB"]) ? $Format["VerticalLineB"] : 0;
  4128. $VerticalLineAlpha = isset($Format["VerticalLineAlpha"]) ? $Format["VerticalLineAlpha"] : 40;
  4129. $VerticalLineTicks = isset($Format["VerticalLineTicks"]) ? $Format["VerticalLineTicks"] : 2;
  4130. $Data = $this->DataSet->getData();
  4131. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4132. if ( !is_array($Indexes) ) { $Index = $Indexes; $Indexes = ""; $Indexes[] = $Index; }
  4133. if ( !is_array($SeriesName) ) { $SerieName = $SeriesName; $SeriesName = ""; $SeriesName[] = $SerieName; }
  4134. if ( $ForceLabels != NULL && !is_array($ForceLabels) ) { $ForceLabel = $ForceLabels; $ForceLabels = ""; $ForceLabels[] = $ForceLabel; }
  4135. foreach ($Indexes as $Key => $Index)
  4136. {
  4137. $Series = "";
  4138. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4139. {
  4140. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4141. $X = $this->GraphAreaX1 + $XMargin + $Index * $XStep;
  4142. if ( $DrawVerticalLine ) { $this->drawLine($X,$this->GraphAreaY1+$Data["YMargin"],$X,$this->GraphAreaY2-$Data["YMargin"],array("R"=>$VerticalLineR,"G"=>$VerticalLineG,"B"=>$VerticalLineB,"Alpha"=>$VerticalLineAlpha,"Ticks"=>$VerticalLineTicks)); }
  4143. $MinY = $this->GraphAreaY2;
  4144. foreach ($SeriesName as $iKey => $SerieName)
  4145. {
  4146. if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
  4147. {
  4148. $AxisID = $Data["Series"][$SerieName]["Axis"];
  4149. if ( $OverrideTitle != NULL)
  4150. $Description = $OverrideTitle;
  4151. elseif ( count($SeriesName) == 1 )
  4152. {
  4153. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4154. $Description = $Data["Series"][$SerieName]["Description"]." - ".$Data["Series"][$Data["Abscissa"]]["Data"][$Index];
  4155. else
  4156. $Description = $Data["Series"][$SerieName]["Description"];
  4157. }
  4158. elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4159. $Description = $Data["Series"][$Data["Abscissa"]]["Data"][$Index];
  4160. $AxisMode = $Data["Axis"][$AxisID]["Display"];
  4161. $AxisFormat = $Data["Axis"][$AxisID]["Format"];
  4162. $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
  4163. $Serie = "";
  4164. $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
  4165. $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
  4166. $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
  4167. $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
  4168. if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
  4169. $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
  4170. else
  4171. $SerieOffset = 0;
  4172. $Value = $Data["Series"][$SerieName]["Data"][$Index];
  4173. if ( $ForceLabels != NULL )
  4174. $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
  4175. else
  4176. $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
  4177. $X = floor($this->GraphAreaX1 + $XMargin + $Index * $XStep + $SerieOffset);
  4178. $Y = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
  4179. if ($Y < $MinY) { $MinY = $Y; }
  4180. if ( $DrawPoint == LABEL_POINT_CIRCLE )
  4181. $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4182. elseif ( $DrawPoint == LABEL_POINT_BOX )
  4183. $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4184. $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
  4185. }
  4186. }
  4187. $this->drawLabelBox($X,$MinY-3,$Description,$Series,$Format);
  4188. }
  4189. else
  4190. {
  4191. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4192. $Y = $this->GraphAreaY1 + $XMargin + $Index * $XStep;
  4193. if ( $DrawVerticalLine ) { $this->drawLine($this->GraphAreaX1+$Data["YMargin"],$Y,$this->GraphAreaX2-$Data["YMargin"],$Y,array("R"=>$VerticalLineR,"G"=>$VerticalLineG,"B"=>$VerticalLineB,"Alpha"=>$VerticalLineAlpha,"Ticks"=>$VerticalLineTicks)); }
  4194. $MinX = $this->GraphAreaX2;
  4195. foreach ($SeriesName as $Key => $SerieName)
  4196. {
  4197. if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
  4198. {
  4199. $AxisID = $Data["Series"][$SerieName]["Axis"];
  4200. if ( $OverrideTitle != NULL)
  4201. $Description = $OverrideTitle;
  4202. elseif ( count($SeriesName) == 1 )
  4203. {
  4204. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4205. $Description = $Data["Series"][$SerieName]["Description"]." - ".$Data["Series"][$Data["Abscissa"]]["Data"][$Index];
  4206. else
  4207. $Description = $Data["Series"][$SerieName]["Description"];
  4208. }
  4209. elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4210. $Description = $Data["Series"][$Data["Abscissa"]]["Data"][$Index];
  4211. $AxisMode = $Data["Axis"][$AxisID]["Display"];
  4212. $AxisFormat = $Data["Axis"][$AxisID]["Format"];
  4213. $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
  4214. $Serie = "";
  4215. if ( isset($Data["Extended"]["Palette"][$Index] ) )
  4216. {
  4217. $Serie["R"] = $Data["Extended"]["Palette"][$Index]["R"];
  4218. $Serie["G"] = $Data["Extended"]["Palette"][$Index]["G"];
  4219. $Serie["B"] = $Data["Extended"]["Palette"][$Index]["B"];
  4220. $Serie["Alpha"] = $Data["Extended"]["Palette"][$Index]["Alpha"];
  4221. }
  4222. else
  4223. {
  4224. $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
  4225. $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
  4226. $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
  4227. $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
  4228. }
  4229. if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
  4230. $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
  4231. else
  4232. $SerieOffset = 0;
  4233. $Value = $Data["Series"][$SerieName]["Data"][$Index];
  4234. if ( $ForceLabels != NULL )
  4235. $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
  4236. else
  4237. $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
  4238. $X = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
  4239. $Y = floor($this->GraphAreaY1 + $XMargin + $Index * $XStep + $SerieOffset);
  4240. if ($X < $MinX) { $MinX = $X; }
  4241. if ( $DrawPoint == LABEL_POINT_CIRCLE )
  4242. $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4243. elseif ( $DrawPoint == LABEL_POINT_BOX )
  4244. $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4245. $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
  4246. }
  4247. }
  4248. $this->drawLabelBox($MinX,$Y-3,$Description,$Series,$Format);
  4249. }
  4250. }
  4251. }
  4252. /* Draw a label box */
  4253. function drawLabelBox($X,$Y,$Title,$Captions,$Format="")
  4254. {
  4255. $NoTitle = isset($Format["NoTitle"]) ? $Format["NoTitle"] : NULL;
  4256. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 50;
  4257. $DrawSerieColor = isset($Format["DrawSerieColor"]) ? $Format["DrawSerieColor"] : TRUE;
  4258. $SerieR = isset($Format["SerieR"]) ? $Format["SerieR"] : NULL;
  4259. $SerieG = isset($Format["SerieG"]) ? $Format["SerieG"] : NULL;
  4260. $SerieB = isset($Format["SerieB"]) ? $Format["SerieB"] : NULL;
  4261. $SerieAlpha = isset($Format["SerieAlpha"]) ? $Format["SerieAlpha"] : NULL;
  4262. $SerieBoxSize = isset($Format["SerieBoxSize"]) ? $Format["SerieBoxSize"] : 6;
  4263. $SerieBoxSpacing = isset($Format["SerieBoxSpacing"]) ? $Format["SerieBoxSpacing"] : 4;
  4264. $VerticalMargin = isset($Format["VerticalMargin"]) ? $Format["VerticalMargin"] : 10;
  4265. $HorizontalMargin = isset($Format["HorizontalMargin"]) ? $Format["HorizontalMargin"] : 8;
  4266. $R = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
  4267. $G = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
  4268. $B = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
  4269. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
  4270. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  4271. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  4272. $TitleMode = isset($Format["TitleMode"]) ? $Format["TitleMode"] : LABEL_TITLE_NOBACKGROUND;
  4273. $TitleR = isset($Format["TitleR"]) ? $Format["TitleR"] : $R;
  4274. $TitleG = isset($Format["TitleG"]) ? $Format["TitleG"] : $G;
  4275. $TitleB = isset($Format["TitleB"]) ? $Format["TitleB"] : $B;
  4276. $TitleBackgroundR = isset($Format["TitleBackgroundR"]) ? $Format["TitleBackgroundR"] : 0;
  4277. $TitleBackgroundG = isset($Format["TitleBackgroundG"]) ? $Format["TitleBackgroundG"] : 0;
  4278. $TitleBackgroundB = isset($Format["TitleBackgroundB"]) ? $Format["TitleBackgroundB"] : 0;
  4279. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  4280. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  4281. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  4282. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 220;
  4283. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 220;
  4284. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 220;
  4285. if ( !$DrawSerieColor ) { $SerieBoxSize = 0; $SerieBoxSpacing = 0; }
  4286. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Title);
  4287. $TitleWidth = ($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2;
  4288. $TitleHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);
  4289. if ( $NoTitle ) { $TitleWidth = 0; $TitleHeight = 0; }
  4290. $CaptionWidth = 0; $CaptionHeight = -$HorizontalMargin;
  4291. foreach($Captions as $Key =>$Caption)
  4292. {
  4293. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Caption["Caption"]);
  4294. $CaptionWidth = max($CaptionWidth,($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2);
  4295. $CaptionHeight = $CaptionHeight + max(($TxtPos[0]["Y"] - $TxtPos[2]["Y"]),($SerieBoxSize+2)) + $HorizontalMargin;
  4296. }
  4297. if ( $CaptionHeight <= 5 ) { $CaptionHeight = $CaptionHeight + $HorizontalMargin/2; }
  4298. if ( $DrawSerieColor ) { $CaptionWidth = $CaptionWidth + $SerieBoxSize + $SerieBoxSpacing; }
  4299. $BoxWidth = max($BoxWidth,$TitleWidth,$CaptionWidth);
  4300. $XMin = $X - 5 - floor(($BoxWidth-10) / 2);
  4301. $XMax = $X + 5 + floor(($BoxWidth-10) / 2);
  4302. $RestoreShadow = $this->Shadow;
  4303. if ( $this->Shadow == TRUE )
  4304. {
  4305. $this->Shadow = FALSE;
  4306. $Poly = "";
  4307. $Poly[] = $X+$this->ShadowX; $Poly[] = $Y+$this->ShadowX;
  4308. $Poly[] = $X+5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4309. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4310. if ( $NoTitle )
  4311. {
  4312. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
  4313. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
  4314. }
  4315. else
  4316. {
  4317. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
  4318. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
  4319. }
  4320. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4321. $Poly[] = $X-5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4322. $this->drawPolygon($Poly,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  4323. }
  4324. /* Draw the background */
  4325. $GradientSettings = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB);
  4326. if ( $NoTitle )
  4327. $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
  4328. else
  4329. $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
  4330. $Poly = ""; $Poly[] = $X; $Poly[] = $Y; $Poly[] = $X-5; $Poly[] = $Y-5; $Poly[] = $X+5; $Poly[] = $Y-5;
  4331. $this->drawPolygon($Poly,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB,"NoBorder"=>TRUE));
  4332. /* Outer border */
  4333. $OuterBorderColor = $this->allocateColor($this->Picture,100,100,100,100);
  4334. imageline($this->Picture,$XMin,$Y-5,$X-5,$Y-5,$OuterBorderColor);
  4335. imageline($this->Picture,$X,$Y,$X-5,$Y-5,$OuterBorderColor);
  4336. imageline($this->Picture,$X,$Y,$X+5,$Y-5,$OuterBorderColor);
  4337. imageline($this->Picture,$X+5,$Y-5,$XMax,$Y-5,$OuterBorderColor);
  4338. if ( $NoTitle )
  4339. {
  4340. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin,$Y-5,$OuterBorderColor);
  4341. imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5,$OuterBorderColor);
  4342. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$OuterBorderColor);
  4343. }
  4344. else
  4345. {
  4346. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin,$Y-5,$OuterBorderColor);
  4347. imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5,$OuterBorderColor);
  4348. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$OuterBorderColor);
  4349. }
  4350. /* Inner border */
  4351. $InnerBorderColor = $this->allocateColor($this->Picture,255,255,255,100);
  4352. imageline($this->Picture,$XMin+1,$Y-6,$X-5,$Y-6,$InnerBorderColor);
  4353. imageline($this->Picture,$X,$Y-1,$X-5,$Y-6,$InnerBorderColor);
  4354. imageline($this->Picture,$X,$Y-1,$X+5,$Y-6,$InnerBorderColor);
  4355. imageline($this->Picture,$X+5,$Y-6,$XMax-1,$Y-6,$InnerBorderColor);
  4356. if ( $NoTitle )
  4357. {
  4358. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin+1,$Y-6,$InnerBorderColor);
  4359. imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-6,$InnerBorderColor);
  4360. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$InnerBorderColor);
  4361. }
  4362. else
  4363. {
  4364. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin+1,$Y-6,$InnerBorderColor);
  4365. imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-6,$InnerBorderColor);
  4366. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$InnerBorderColor);
  4367. }
  4368. /* Draw the separator line */
  4369. if ( $TitleMode == LABEL_TITLE_NOBACKGROUND && !$NoTitle )
  4370. {
  4371. $YPos = $Y-7-$CaptionHeight-$HorizontalMargin-$HorizontalMargin/2;
  4372. $XMargin = $VerticalMargin / 2;
  4373. $this->drawLine($XMin+$XMargin,$YPos+1,$XMax-$XMargin,$YPos+1,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB));
  4374. $this->drawLine($XMin+$XMargin,$YPos,$XMax-$XMargin,$YPos,array("R"=>$GradientStartR,"G"=>$GradientStartG,"B"=>$GradientStartB));
  4375. }
  4376. elseif ( $TitleMode == LABEL_TITLE_BACKGROUND )
  4377. {
  4378. $this->drawFilledRectangle($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2,array("R"=>$TitleBackgroundR,"G"=>$TitleBackgroundG,"B"=>$TitleBackgroundB));
  4379. imageline($this->Picture,$XMin+1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$XMax-1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$InnerBorderColor);
  4380. }
  4381. /* Write the description */
  4382. if ( !$NoTitle )
  4383. $this->drawText($XMin+$VerticalMargin,$Y-7-$CaptionHeight-$HorizontalMargin*2,$Title,array("Align"=>TEXT_ALIGN_BOTTOMLEFT,"R"=>$TitleR,"G"=>$TitleG,"B"=>$TitleB));
  4384. /* Write the value */
  4385. $YPos = $Y-5-$HorizontalMargin; $XPos = $XMin+$VerticalMargin+$SerieBoxSize+$SerieBoxSpacing;
  4386. foreach($Captions as $Key => $Caption)
  4387. {
  4388. $CaptionTxt = $Caption["Caption"];
  4389. $TxtPos = $this->getTextBox($XPos,$YPos,$FontName,$FontSize,0,$CaptionTxt);
  4390. $CaptionHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);
  4391. /* Write the serie color if needed */
  4392. if ( $DrawSerieColor )
  4393. {
  4394. $BoxSettings = array("R"=>$Caption["Format"]["R"],"G"=>$Caption["Format"]["G"],"B"=>$Caption["Format"]["B"],"Alpha"=>$Caption["Format"]["Alpha"],"BorderR"=>0,"BorderG"=>0,"BorderB"=>0);
  4395. $this->drawFilledRectangle($XMin+$VerticalMargin,$YPos-$SerieBoxSize,$XMin+$VerticalMargin+$SerieBoxSize,$YPos,$BoxSettings);
  4396. }
  4397. $this->drawText($XPos,$YPos,$CaptionTxt,array("Align"=>TEXT_ALIGN_BOTTOMLEFT));
  4398. $YPos = $YPos - $CaptionHeight - $HorizontalMargin;
  4399. }
  4400. $this->Shadow = $RestoreShadow;
  4401. }
  4402. /* Draw a basic shape */
  4403. function drawShape($X,$Y,$Shape,$PlotSize,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha)
  4404. {
  4405. if ( $Shape == SERIE_SHAPE_FILLEDCIRCLE )
  4406. {
  4407. if ( $PlotBorder ) { $this->drawFilledCircle($X,$Y,$PlotSize+$BorderSize,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4408. $this->drawFilledCircle($X,$Y,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4409. }
  4410. elseif ( $Shape == SERIE_SHAPE_FILLEDSQUARE )
  4411. {
  4412. if ( $PlotBorder ) { $this->drawFilledRectangle($X-$PlotSize-$BorderSize,$Y-$PlotSize-$BorderSize,$X+$PlotSize+$BorderSize,$Y+$PlotSize+$BorderSize,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4413. $this->drawFilledRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4414. }
  4415. elseif ( $Shape == SERIE_SHAPE_FILLEDTRIANGLE )
  4416. {
  4417. if ( $PlotBorder )
  4418. {
  4419. $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize-$BorderSize; $Pos[]=$X-$PlotSize-$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize; $Pos[]=$X+$PlotSize+$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize;
  4420. $this->drawPolygon($Pos,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha));
  4421. }
  4422. $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X-$PlotSize; $Pos[]=$Y+$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y+$PlotSize;
  4423. $this->drawPolygon($Pos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4424. }
  4425. elseif ( $Shape == SERIE_SHAPE_TRIANGLE )
  4426. {
  4427. $this->drawLine($X,$Y-$PlotSize,$X-$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4428. $this->drawLine($X-$PlotSize,$Y+$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4429. $this->drawLine($X+$PlotSize,$Y+$PlotSize,$X,$Y-$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4430. }
  4431. elseif ( $Shape == SERIE_SHAPE_SQUARE )
  4432. $this->drawRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4433. elseif ( $Shape == SERIE_SHAPE_CIRCLE )
  4434. $this->drawCircle($X,$Y,$PlotSize,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4435. }
  4436. }
  4437. ?>