PageRenderTime 142ms CodeModel.GetById 38ms RepoModel.GetById 1ms app.codeStats 1ms

/lib/pChart2.1.4/class/pDraw.class.php

https://bitbucket.org/aditsaxena/php_grossing_film_chart
PHP | 6216 lines | 5040 code | 1048 blank | 128 comment | 2380 complexity | 0b9bbffe4c457652343862347e1357ef MD5 | raw file
  1. <?php
  2. /*
  3. pDraw - class extension with drawing methods
  4. Version : 2.1.4
  5. Made by : Jean-Damien POGOLOTTI
  6. Last Update : 19/01/2014
  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("ORIENTATION_AUTO" , 690703);
  44. define("LEGEND_NOBORDER" , 690800);
  45. define("LEGEND_BOX" , 690801);
  46. define("LEGEND_ROUND" , 690802);
  47. define("LEGEND_VERTICAL" , 690901);
  48. define("LEGEND_HORIZONTAL" , 690902);
  49. define("LEGEND_FAMILY_BOX" , 691051);
  50. define("LEGEND_FAMILY_CIRCLE" , 691052);
  51. define("LEGEND_FAMILY_LINE" , 691053);
  52. define("DISPLAY_AUTO" , 691001);
  53. define("DISPLAY_MANUAL" , 691002);
  54. define("LABELING_ALL" , 691011);
  55. define("LABELING_DIFFERENT" , 691012);
  56. define("BOUND_MIN" , 691021);
  57. define("BOUND_MAX" , 691022);
  58. define("BOUND_BOTH" , 691023);
  59. define("BOUND_LABEL_POS_TOP" , 691031);
  60. define("BOUND_LABEL_POS_BOTTOM" , 691032);
  61. define("BOUND_LABEL_POS_AUTO" , 691033);
  62. define("CAPTION_LEFT_TOP" , 691041);
  63. define("CAPTION_RIGHT_BOTTOM" , 691042);
  64. define("GRADIENT_SIMPLE" , 691051);
  65. define("GRADIENT_EFFECT_CAN" , 691052);
  66. define("LABEL_TITLE_NOBACKGROUND" , 691061);
  67. define("LABEL_TITLE_BACKGROUND" , 691062);
  68. define("LABEL_POINT_NONE" , 691071);
  69. define("LABEL_POINT_CIRCLE" , 691072);
  70. define("LABEL_POINT_BOX" , 691073);
  71. define("ZONE_NAME_ANGLE_AUTO" , 691081);
  72. define("PI" , 3.14159265);
  73. define("ALL" , 69);
  74. define("NONE" , 31);
  75. define("AUTO" , 690000);
  76. define("OUT_OF_SIGHT" , -10000000000000);
  77. class pDraw
  78. {
  79. /* Returns the number of drawable series */
  80. function countDrawableSeries()
  81. {
  82. $Results = 0;
  83. $Data = $this->DataSet->getData();
  84. foreach($Data["Series"] as $SerieName => $Serie)
  85. { if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] ) { $Results++; } }
  86. return($Results);
  87. }
  88. /* Fix box coordinates */
  89. function fixBoxCoordinates($Xa,$Ya,$Xb,$Yb)
  90. {
  91. $X1 = min($Xa,$Xb); $Y1 = min($Ya,$Yb);
  92. $X2 = max($Xa,$Xb); $Y2 = max($Ya,$Yb);
  93. return(array($X1,$Y1,$X2,$Y2));
  94. }
  95. /* Draw a polygon */
  96. function drawPolygon($Points,$Format="")
  97. {
  98. $R = isset($Format["R"]) ? $Format["R"] : 0;
  99. $G = isset($Format["G"]) ? $Format["G"] : 0;
  100. $B = isset($Format["B"]) ? $Format["B"] : 0;
  101. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  102. $NoFill = isset($Format["NoFill"]) ? $Format["NoFill"] : FALSE;
  103. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  104. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  105. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  106. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  107. $BorderAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $Alpha / 2;
  108. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  109. $SkipX = isset($Format["SkipX"]) ? $Format["SkipX"] : OUT_OF_SIGHT;
  110. $SkipY = isset($Format["SkipY"]) ? $Format["SkipY"] : OUT_OF_SIGHT;
  111. /* Calling the ImageFilledPolygon() function over the $Points array will round it */
  112. $Backup = $Points;
  113. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  114. if ( $SkipX != OUT_OF_SIGHT ) { $SkipX = floor($SkipX); }
  115. if ( $SkipY != OUT_OF_SIGHT ) { $SkipY = floor($SkipY); }
  116. $RestoreShadow = $this->Shadow;
  117. if ( !$NoFill )
  118. {
  119. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  120. {
  121. $this->Shadow = FALSE;
  122. for($i=0;$i<=count($Points)-1;$i=$i+2)
  123. { $Shadow[] = $Points[$i] + $this->ShadowX; $Shadow[] = $Points[$i+1] + $this->ShadowY; }
  124. $this->drawPolygon($Shadow,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"NoBorder"=>TRUE));
  125. }
  126. $FillColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  127. if ( count($Points) >= 6 )
  128. { ImageFilledPolygon($this->Picture,$Points,count($Points)/2,$FillColor); }
  129. }
  130. if ( !$NoBorder )
  131. {
  132. $Points = $Backup;
  133. if ( $NoFill )
  134. $BorderSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  135. else
  136. $BorderSettings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha);
  137. for($i=0;$i<=count($Points)-1;$i=$i+2)
  138. {
  139. if ( isset($Points[$i+2]) )
  140. {
  141. if ( !($Points[$i] == $Points[$i+2] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[$i+3] && $Points[$i+1] == $SkipY ) )
  142. $this->drawLine($Points[$i],$Points[$i+1],$Points[$i+2],$Points[$i+3],$BorderSettings);
  143. }
  144. else
  145. {
  146. if ( !($Points[$i] == $Points[0] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[1] && $Points[$i+1] == $SkipY ) )
  147. $this->drawLine($Points[$i],$Points[$i+1],$Points[0],$Points[1],$BorderSettings);
  148. }
  149. }
  150. }
  151. $this->Shadow = $RestoreShadow;
  152. }
  153. /* Apply AALias correction to the rounded box boundaries */
  154. function offsetCorrection($Value,$Mode)
  155. {
  156. $Value = round($Value,1);
  157. if ( $Value == 0 && $Mode == 1 ) { return(.9); }
  158. if ( $Value == 0 ) { return(0); }
  159. if ( $Mode == 1)
  160. { 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); }; }
  161. if ( $Mode == 2)
  162. { 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); }; }
  163. if ( $Mode == 3)
  164. { 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); }; }
  165. if ( $Mode == 4)
  166. { 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); }; }
  167. }
  168. /* Draw a rectangle with rounded corners */
  169. function drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  170. {
  171. $R = isset($Format["R"]) ? $Format["R"] : 0;
  172. $G = isset($Format["G"]) ? $Format["G"] : 0;
  173. $B = isset($Format["B"]) ? $Format["B"] : 0;
  174. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  175. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  176. if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1))/2); }
  177. if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1))/2); }
  178. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);
  179. if ( $Radius <= 0 ) { $this->drawRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }
  180. if ( $this->Antialias )
  181. {
  182. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
  183. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
  184. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
  185. $this->drawLine($X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
  186. }
  187. else
  188. {
  189. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  190. imageline($this->Picture,$X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
  191. imageline($this->Picture,$X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
  192. imageline($this->Picture,$X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
  193. imageline($this->Picture,$X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
  194. }
  195. $Step = 360 / (2 * PI * $Radius);
  196. for($i=0;$i<=90;$i=$i+$Step)
  197. {
  198. $X = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  199. $Y = sin(($i+180)*PI/180) * $Radius + $Y1 + $Radius;
  200. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  201. $X = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  202. $Y = sin(($i+90)*PI/180) * $Radius + $Y2 - $Radius;
  203. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  204. $X = cos($i*PI/180) * $Radius + $X2 - $Radius;
  205. $Y = sin($i*PI/180) * $Radius + $Y2 - $Radius;
  206. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  207. $X = cos(($i+270)*PI/180) * $Radius + $X2 - $Radius;
  208. $Y = sin(($i+270)*PI/180) * $Radius + $Y1 + $Radius;
  209. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  210. }
  211. }
  212. /* Draw a rectangle with rounded corners */
  213. function drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  214. {
  215. $R = isset($Format["R"]) ? $Format["R"] : 0;
  216. $G = isset($Format["G"]) ? $Format["G"] : 0;
  217. $B = isset($Format["B"]) ? $Format["B"] : 0;
  218. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  219. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  220. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  221. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  222. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  223. /* Temporary fix for AA issue */
  224. $Y1 = floor($Y1); $Y2 = floor($Y2); $X1 = floor($X1); $X2 = floor($X2);
  225. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  226. if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }
  227. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  228. if ( $X2 - $X1 < $Radius*2 ) { $Radius = floor((($X2-$X1))/4); }
  229. if ( $Y2 - $Y1 < $Radius*2 ) { $Radius = floor((($Y2-$Y1))/4); }
  230. $RestoreShadow = $this->Shadow;
  231. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  232. {
  233. $this->Shadow = FALSE;
  234. $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));
  235. }
  236. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);
  237. if ( $Radius <= 0 ) { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }
  238. $YTop = $Y1+$Radius;
  239. $YBottom = $Y2-$Radius;
  240. $Step = 360 / (2 * PI * $Radius);
  241. $Positions = ""; $Radius--; $MinY = ""; $MaxY = "";
  242. for($i=0;$i<=90;$i=$i+$Step)
  243. {
  244. $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  245. $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
  246. $Yp = floor(sin(($i+180)*PI/180) * $Radius + $YTop);
  247. if ( $MinY == "" || $Yp > $MinY ) { $MinY = $Yp; }
  248. if ( $Xp1 <= floor($X1) ) { $Xp1++; }
  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. $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  256. $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
  257. $Yp = floor(sin(($i+90)*PI/180) * $Radius + $YBottom);
  258. if ( $MaxY == "" || $Yp < $MaxY ) { $MaxY = $Yp; }
  259. if ( $Xp1 <= floor($X1) ) { $Xp1++; }
  260. if ( $Xp2 >= floor($X2) ) { $Xp2--; }
  261. $Xp1++;
  262. if ( !isset($Positions[$Yp]) )
  263. { $Positions[$Yp]["X1"] = $Xp1; $Positions[$Yp]["X2"] = $Xp2; }
  264. else
  265. { $Positions[$Yp]["X1"] = ($Positions[$Yp]["X1"]+$Xp1)/2; $Positions[$Yp]["X2"] = ($Positions[$Yp]["X2"]+$Xp2)/2; }
  266. }
  267. $ManualColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  268. foreach($Positions as $Yp => $Bounds)
  269. {
  270. $X1 = $Bounds["X1"]; $X1Dec = $this->getFirstDecimal($X1); if ( $X1Dec != 0 ) { $X1 = floor($X1)+1; }
  271. $X2 = $Bounds["X2"]; $X2Dec = $this->getFirstDecimal($X2); if ( $X2Dec != 0 ) { $X2 = floor($X2)-1; }
  272. imageline($this->Picture,$X1,$Yp,$X2,$Yp,$ManualColor);
  273. }
  274. $this->drawFilledRectangle($X1,$MinY+1,floor($X2),$MaxY-1,$Color);
  275. $Radius++;
  276. $this->drawRoundedRectangle($X1,$Y1,$X2+1,$Y2-1,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  277. $this->Shadow = $RestoreShadow;
  278. }
  279. /* Draw a rectangle with rounded corners */
  280. function drawRoundedFilledRectangle_deprecated($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  281. {
  282. $R = isset($Format["R"]) ? $Format["R"] : 0;
  283. $G = isset($Format["G"]) ? $Format["G"] : 0;
  284. $B = isset($Format["B"]) ? $Format["B"] : 0;
  285. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  286. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  287. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  288. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  289. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  290. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  291. if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }
  292. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  293. if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1)+2)/2); }
  294. if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1)+2)/2); }
  295. $RestoreShadow = $this->Shadow;
  296. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  297. {
  298. $this->Shadow = FALSE;
  299. $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));
  300. }
  301. if ( $this->getFirstDecimal($X2) >= 5 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  302. if ( $this->getFirstDecimal($X1) <= 5 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  303. if ( !$this->Antialias ) { $XOffset1 = 1; $XOffset2 = 1; }
  304. $YTop = floor($Y1+$Radius);
  305. $YBottom = floor($Y2-$Radius);
  306. $this->drawFilledRectangle($X1-$XOffset1,$YTop,$X2+$XOffset2,$YBottom,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE));
  307. $Step = 360 / (2 * PI * $Radius);
  308. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  309. $Color2 = $this->allocateColor($this->Picture,255,0,0,$Alpha);
  310. $Drawn = "";
  311. if ( $Alpha < 100 ) { $Drawn[$YTop] = FALSE; }
  312. if ( $Alpha < 100 ) { $Drawn[$YBottom] = TRUE; }
  313. for($i=0;$i<=90;$i=$i+$Step)
  314. {
  315. $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  316. $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
  317. $Yp = sin(($i+180)*PI/180) * $Radius + $YTop;
  318. if ( $this->getFirstDecimal($Xp1) > 5 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  319. if ( $this->getFirstDecimal($Xp2) > 5 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  320. if ( $this->getFirstDecimal($Yp) > 5 ) { $YOffset = 1; } else { $YOffset = 0; }
  321. if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
  322. imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);
  323. $Drawn[$Yp+$YOffset] = $Xp2;
  324. $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  325. $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
  326. $Yp = sin(($i+90)*PI/180) * $Radius + $YBottom;
  327. if ( $this->getFirstDecimal($Xp1) > 7 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  328. if ( $this->getFirstDecimal($Xp2) > 7 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  329. if ( $this->getFirstDecimal($Yp) > 5 ) { $YOffset = 1; } else { $YOffset = 0; }
  330. if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
  331. imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);
  332. $Drawn[$Yp+$YOffset] = $Xp2;
  333. }
  334. $this->drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  335. $this->Shadow = $RestoreShadow;
  336. }
  337. /* Draw a rectangle */
  338. function drawRectangle($X1,$Y1,$X2,$Y2,$Format="")
  339. {
  340. $R = isset($Format["R"]) ? $Format["R"] : 0;
  341. $G = isset($Format["G"]) ? $Format["G"] : 0;
  342. $B = isset($Format["B"]) ? $Format["B"] : 0;
  343. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  344. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  345. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;
  346. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  347. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  348. if ( $this->Antialias )
  349. {
  350. if ( $NoAngle )
  351. {
  352. $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  353. $this->drawLine($X2,$Y1+1,$X2,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  354. $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  355. $this->drawLine($X1,$Y1+1,$X1,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  356. }
  357. else
  358. {
  359. $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  360. $this->drawLine($X2,$Y1,$X2,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  361. $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  362. $this->drawLine($X1,$Y1,$X1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  363. }
  364. }
  365. else
  366. {
  367. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  368. imagerectangle($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
  369. }
  370. }
  371. /* Draw a filled rectangle */
  372. function drawFilledRectangle($X1,$Y1,$X2,$Y2,$Format="")
  373. {
  374. $R = isset($Format["R"]) ? $Format["R"] : 0;
  375. $G = isset($Format["G"]) ? $Format["G"] : 0;
  376. $B = isset($Format["B"]) ? $Format["B"] : 0;
  377. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  378. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  379. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  380. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  381. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
  382. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  383. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  384. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : NULL;
  385. $Dash = isset($Format["Dash"]) ? $Format["Dash"] : FALSE;
  386. $DashStep = isset($Format["DashStep"]) ? $Format["DashStep"] : 4;
  387. $DashR = isset($Format["DashR"]) ? $Format["DashR"] : 0;
  388. $DashG = isset($Format["DashG"]) ? $Format["DashG"] : 0;
  389. $DashB = isset($Format["DashB"]) ? $Format["DashB"] : 0;
  390. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  391. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  392. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  393. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  394. $RestoreShadow = $this->Shadow;
  395. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  396. {
  397. $this->Shadow = FALSE;
  398. $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));
  399. }
  400. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  401. if ( $NoAngle )
  402. {
  403. imagefilledrectangle($this->Picture,ceil($X1)+1,ceil($Y1),floor($X2)-1,floor($Y2),$Color);
  404. imageline($this->Picture,ceil($X1),ceil($Y1)+1,ceil($X1),floor($Y2)-1,$Color);
  405. imageline($this->Picture,floor($X2),ceil($Y1)+1,floor($X2),floor($Y2)-1,$Color);
  406. }
  407. else
  408. imagefilledrectangle($this->Picture,ceil($X1),ceil($Y1),floor($X2),floor($Y2),$Color);
  409. if ( $Dash )
  410. {
  411. if ( $BorderR != -1 ) { $iX1=$X1+1; $iY1=$Y1+1; $iX2=$X2-1; $iY2=$Y2-1; } else { $iX1=$X1; $iY1=$Y1; $iX2=$X2; $iY2=$Y2; }
  412. $Color = $this->allocateColor($this->Picture,$DashR,$DashG,$DashB,$Alpha);
  413. $Y=$iY1-$DashStep;
  414. for($X=$iX1; $X<=$iX2+($iY2-$iY1); $X=$X+$DashStep)
  415. {
  416. $Y=$Y+$DashStep;
  417. if ( $X > $iX2 ) { $Xa = $X-($X-$iX2); $Ya = $iY1+($X-$iX2); } else { $Xa = $X; $Ya = $iY1; }
  418. if ( $Y > $iY2 ) { $Xb = $iX1+($Y-$iY2); $Yb = $Y-($Y-$iY2); } else { $Xb = $iX1; $Yb = $Y; }
  419. imageline($this->Picture,$Xa,$Ya,$Xb,$Yb,$Color);
  420. }
  421. }
  422. if ( $this->Antialias && !$NoBorder )
  423. {
  424. if ( $X1 < ceil($X1) )
  425. {
  426. $AlphaA = $Alpha * (ceil($X1) - $X1);
  427. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  428. imageline($this->Picture,ceil($X1)-1,ceil($Y1),ceil($X1)-1,floor($Y2),$Color);
  429. }
  430. if ( $Y1 < ceil($Y1) )
  431. {
  432. $AlphaA = $Alpha * (ceil($Y1) - $Y1);
  433. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  434. imageline($this->Picture,ceil($X1),ceil($Y1)-1,floor($X2),ceil($Y1)-1,$Color);
  435. }
  436. if ( $X2 > floor($X2) )
  437. {
  438. $AlphaA = $Alpha * (.5-($X2 - floor($X2)));
  439. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  440. imageline($this->Picture,floor($X2)+1,ceil($Y1),floor($X2)+1,floor($Y2),$Color);
  441. }
  442. if ( $Y2 > floor($Y2) )
  443. {
  444. $AlphaA = $Alpha * (.5-($Y2 - floor($Y2)));
  445. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  446. imageline($this->Picture,ceil($X1),floor($Y2)+1,floor($X2),floor($Y2)+1,$Color);
  447. }
  448. }
  449. if ( $BorderR != -1 )
  450. $this->drawRectangle($X1,$Y1,$X2,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks,"NoAngle"=>$NoAngle));
  451. $this->Shadow = $RestoreShadow;
  452. }
  453. /* Draw a rectangular marker of the specified size */
  454. function drawRectangleMarker($X,$Y,$Format="")
  455. {
  456. $Size = isset($Format["Size"]) ? $Format["Size"] : 4;
  457. $HalfSize = floor($Size/2);
  458. $this->drawFilledRectangle($X-$HalfSize,$Y-$HalfSize,$X+$HalfSize,$Y+$HalfSize,$Format);
  459. }
  460. /* Drawn a spline based on the bezier function */
  461. function drawSpline($Coordinates,$Format="")
  462. {
  463. $R = isset($Format["R"]) ? $Format["R"] : 0;
  464. $G = isset($Format["G"]) ? $Format["G"] : 0;
  465. $B = isset($Format["B"]) ? $Format["B"] : 0;
  466. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  467. $Force = isset($Format["Force"]) ? $Format["Force"] : 30;
  468. $Forces = isset($Format["Forces"]) ? $Format["Forces"] : NULL;
  469. $ShowC = isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
  470. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  471. $PathOnly = isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
  472. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  473. $Cpt = NULL; $Mode = NULL; $Result = "";
  474. for($i=1;$i<=count($Coordinates)-1;$i++)
  475. {
  476. $X1 = $Coordinates[$i-1][0]; $Y1 = $Coordinates[$i-1][1];
  477. $X2 = $Coordinates[$i][0]; $Y2 = $Coordinates[$i][1];
  478. if ( $Forces != NULL ) { $Force = $Forces[$i]; }
  479. /* First segment */
  480. if ( $i == 1 )
  481. { $Xv1 = $X1; $Yv1 = $Y1; }
  482. else
  483. {
  484. $Angle1 = $this->getAngle($XLast,$YLast,$X1,$Y1);
  485. $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
  486. $XOff = cos($Angle2 * PI / 180) * $Force + $X1;
  487. $YOff = sin($Angle2 * PI / 180) * $Force + $Y1;
  488. $Xv1 = cos($Angle1 * PI / 180) * $Force + $XOff;
  489. $Yv1 = sin($Angle1 * PI / 180) * $Force + $YOff;
  490. }
  491. /* Last segment */
  492. if ( $i == count($Coordinates)-1 )
  493. { $Xv2 = $X2; $Yv2 = $Y2; }
  494. else
  495. {
  496. $Angle1 = $this->getAngle($X2,$Y2,$Coordinates[$i+1][0],$Coordinates[$i+1][1]);
  497. $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
  498. $XOff = cos(($Angle2+180) * PI / 180) * $Force + $X2;
  499. $YOff = sin(($Angle2+180) * PI / 180) * $Force + $Y2;
  500. $Xv2 = cos(($Angle1+180) * PI / 180) * $Force + $XOff;
  501. $Yv2 = sin(($Angle1+180) * PI / 180) * $Force + $YOff;
  502. }
  503. $Path = $this->drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format);
  504. if ($PathOnly) { $Result[] = $Path; }
  505. $XLast = $X1; $YLast = $Y1;
  506. }
  507. return($Result);
  508. }
  509. /* Draw a bezier curve with two controls points */
  510. function drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format="")
  511. {
  512. $R = isset($Format["R"]) ? $Format["R"] : 0;
  513. $G = isset($Format["G"]) ? $Format["G"] : 0;
  514. $B = isset($Format["B"]) ? $Format["B"] : 0;
  515. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  516. $ShowC = isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
  517. $Segments = isset($Format["Segments"]) ? $Format["Segments"] : NULL;
  518. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  519. $NoDraw = isset($Format["NoDraw"]) ? $Format["NoDraw"] : FALSE;
  520. $PathOnly = isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
  521. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  522. $DrawArrow = isset($Format["DrawArrow"]) ? $Format["DrawArrow"] : FALSE;
  523. $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 10;
  524. $ArrowRatio = isset($Format["ArrowRatio"]) ? $Format["ArrowRatio"] : .5;
  525. $ArrowTwoHeads = isset($Format["ArrowTwoHeads"]) ? $Format["ArrowTwoHeads"] : FALSE;
  526. if ( $Segments == NULL )
  527. {
  528. $Length = $this->getLength($X1,$Y1,$X2,$Y2);
  529. $Precision = ($Length*125)/1000;
  530. }
  531. else
  532. $Precision = $Segments;
  533. $P[0]["X"] = $X1; $P[0]["Y"] = $Y1;
  534. $P[1]["X"] = $Xv1; $P[1]["Y"] = $Yv1;
  535. $P[2]["X"] = $Xv2; $P[2]["Y"] = $Yv2;
  536. $P[3]["X"] = $X2; $P[3]["Y"] = $Y2;
  537. /* Compute the bezier points */
  538. $Q = ""; $ID = 0; $Path = "";
  539. for($i=0;$i<=$Precision;$i=$i+1)
  540. {
  541. $u = $i / $Precision;
  542. $C = "";
  543. $C[0] = (1 - $u) * (1 - $u) * (1 - $u);
  544. $C[1] = ($u * 3) * (1 - $u) * (1 - $u);
  545. $C[2] = 3 * $u * $u * (1 - $u);
  546. $C[3] = $u * $u * $u;
  547. for($j=0;$j<=3;$j++)
  548. {
  549. if ( !isset($Q[$ID]) ) { $Q[$ID] = ""; }
  550. if ( !isset($Q[$ID]["X"]) ) { $Q[$ID]["X"] = 0; }
  551. if ( !isset($Q[$ID]["Y"]) ) { $Q[$ID]["Y"] = 0; }
  552. $Q[$ID]["X"] = $Q[$ID]["X"] + $P[$j]["X"] * $C[$j];
  553. $Q[$ID]["Y"] = $Q[$ID]["Y"] + $P[$j]["Y"] * $C[$j];
  554. }
  555. $ID++;
  556. }
  557. $Q[$ID]["X"] = $X2; $Q[$ID]["Y"] = $Y2;
  558. if ( !$NoDraw )
  559. {
  560. /* Display the control points */
  561. if ( $ShowC && !$PathOnly )
  562. {
  563. $Xv1 = floor($Xv1); $Yv1 = floor($Yv1); $Xv2 = floor($Xv2); $Yv2 = floor($Yv2);
  564. $this->drawLine($X1,$Y1,$X2,$Y2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));
  565. $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  566. $this->drawRectangleMarker($Xv1,$Yv1,$MyMarkerSettings);
  567. $this->drawText($Xv1+4,$Yv1,"v1");
  568. $MyMarkerSettings = array("R"=>0,"G"=>0,"B"=>255,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  569. $this->drawRectangleMarker($Xv2,$Yv2,$MyMarkerSettings);
  570. $this->drawText($Xv2+4,$Yv2,"v2");
  571. }
  572. /* Draw the bezier */
  573. $LastX = NULL; $LastY = NULL; $Cpt = NULL; $Mode = NULL; $ArrowS = NULL;
  574. foreach ($Q as $Key => $Point)
  575. {
  576. $X = $Point["X"]; $Y = $Point["Y"];
  577. /* Get the first segment */
  578. if ( $ArrowS == NULL && $LastX != NULL && $LastY != NULL )
  579. { $ArrowS["X2"] = $LastX; $ArrowS["Y2"] = $LastY; $ArrowS["X1"] = $X; $ArrowS["Y1"] = $Y; }
  580. if ( $LastX != NULL && $LastY != NULL && !$PathOnly)
  581. 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));
  582. /* Get the last segment */
  583. $ArrowE["X1"] = $LastX; $ArrowE["Y1"] = $LastY; $ArrowE["X2"] = $X; $ArrowE["Y2"] = $Y;
  584. $LastX = $X; $LastY = $Y;
  585. }
  586. if ( $DrawArrow && !$PathOnly )
  587. {
  588. $ArrowSettings = array("FillR"=>$R,"FillG"=>$G,"FillB"=>$B,"Alpha"=>$Alpha,"Size"=>$ArrowSize,"Ratio"=>$ArrowRatio);
  589. if ( $ArrowTwoHeads )
  590. $this->drawArrow($ArrowS["X1"],$ArrowS["Y1"],$ArrowS["X2"],$ArrowS["Y2"],$ArrowSettings);
  591. $this->drawArrow($ArrowE["X1"],$ArrowE["Y1"],$ArrowE["X2"],$ArrowE["Y2"],$ArrowSettings);
  592. }
  593. }
  594. return($Q);
  595. }
  596. /* Draw a line between two points */
  597. function drawLine($X1,$Y1,$X2,$Y2,$Format="")
  598. {
  599. $R = isset($Format["R"]) ? $Format["R"] : 0;
  600. $G = isset($Format["G"]) ? $Format["G"] : 0;
  601. $B = isset($Format["B"]) ? $Format["B"] : 0;
  602. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  603. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  604. $Cpt = isset($Format["Cpt"]) ? $Format["Cpt"] : 1;
  605. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : 1;
  606. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  607. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  608. if ( $this->Antialias == FALSE && $Ticks == NULL )
  609. {
  610. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  611. {
  612. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  613. imageline($this->Picture,$X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$ShadowColor);
  614. }
  615. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  616. imageline($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
  617. return(0);
  618. }
  619. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  620. if ( $Distance == 0 ) { return(-1); }
  621. /* Derivative algorithm for overweighted lines, re-route to polygons primitives */
  622. if ( $Weight != NULL )
  623. {
  624. $Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
  625. $PolySettings = array ("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderAlpha"=>$Alpha);
  626. if ( $Ticks == NULL )
  627. {
  628. $Points = "";
  629. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y1;
  630. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y1;
  631. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y2;
  632. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y2;
  633. $this->drawPolygon($Points,$PolySettings);
  634. }
  635. else
  636. {
  637. for($i=0;$i<=$Distance;$i=$i+$Ticks*2)
  638. {
  639. $Xa = (($X2-$X1)/$Distance) * $i + $X1; $Ya = (($Y2-$Y1)/$Distance) * $i + $Y1;
  640. $Xb = (($X2-$X1)/$Distance) * ($i+$Ticks) + $X1; $Yb = (($Y2-$Y1)/$Distance) * ($i+$Ticks) + $Y1;
  641. $Points = "";
  642. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Ya;
  643. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Ya;
  644. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Yb;
  645. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Yb;
  646. $this->drawPolygon($Points,$PolySettings);
  647. }
  648. }
  649. return(1);
  650. }
  651. $XStep = ($X2-$X1) / $Distance;
  652. $YStep = ($Y2-$Y1) / $Distance;
  653. for($i=0;$i<=$Distance;$i++)
  654. {
  655. $X = $i * $XStep + $X1;
  656. $Y = $i * $YStep + $Y1;
  657. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  658. if ( $Threshold != NULL )
  659. {
  660. foreach($Threshold as $Key => $Parameters)
  661. {
  662. if ( $Y <= $Parameters["MinX"] && $Y >= $Parameters["MaxX"])
  663. {
  664. if ( isset($Parameters["R"]) ) { $RT = $Parameters["R"]; } else { $RT = 0; }
  665. if ( isset($Parameters["G"]) ) { $GT = $Parameters["G"]; } else { $GT = 0; }
  666. if ( isset($Parameters["B"]) ) { $BT = $Parameters["B"]; } else { $BT = 0; }
  667. if ( isset($Parameters["Alpha"]) ) { $AlphaT = $Parameters["Alpha"]; } else { $AlphaT = 0; }
  668. $Color = array("R"=>$RT,"G"=>$GT,"B"=>$BT,"Alpha"=>$AlphaT);
  669. }
  670. }
  671. }
  672. if ( $Ticks != NULL )
  673. {
  674. if ( $Cpt % $Ticks == 0 )
  675. { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }
  676. if ( $Mode == 1 )
  677. $this->drawAntialiasPixel($X,$Y,$Color);
  678. $Cpt++;
  679. }
  680. else
  681. $this->drawAntialiasPixel($X,$Y,$Color);
  682. }
  683. return(array($Cpt,$Mode));
  684. }
  685. /* Draw a circle */
  686. function drawCircle($Xc,$Yc,$Height,$Width,$Format="")
  687. {
  688. $R = isset($Format["R"]) ? $Format["R"] : 0;
  689. $G = isset($Format["G"]) ? $Format["G"] : 0;
  690. $B = isset($Format["B"]) ? $Format["B"] : 0;
  691. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  692. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  693. $Height = abs($Height);
  694. $Width = abs($Width);
  695. if ( $Height == 0 ) { $Height = 1; }
  696. if ( $Width == 0 ) { $Width = 1; }
  697. $Xc = floor($Xc); $Yc = floor($Yc);
  698. $RestoreShadow = $this->Shadow;
  699. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  700. {
  701. $this->Shadow = FALSE;
  702. $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));
  703. }
  704. if ( $Width == 0 ) { $Width = $Height; }
  705. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  706. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  707. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  708. $Step = 360 / (2 * PI * max($Width,$Height));
  709. $Mode = 1; $Cpt = 1;
  710. for($i=0;$i<=360;$i=$i+$Step)
  711. {
  712. $X = cos($i*PI/180) * $Height + $Xc;
  713. $Y = sin($i*PI/180) * $Width + $Yc;
  714. if ( $Ticks != NULL )
  715. {
  716. if ( $Cpt % $Ticks == 0 )
  717. { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }
  718. if ( $Mode == 1 )
  719. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  720. $Cpt++;
  721. }
  722. else
  723. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  724. }
  725. $this->Shadow = $RestoreShadow;
  726. }
  727. /* Draw a filled circle */
  728. function drawFilledCircle($X,$Y,$Radius,$Format="")
  729. {
  730. $R = isset($Format["R"]) ? $Format["R"] : 0;
  731. $G = isset($Format["G"]) ? $Format["G"] : 0;
  732. $B = isset($Format["B"]) ? $Format["B"] : 0;
  733. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  734. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  735. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  736. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  737. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
  738. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  739. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  740. if ( $Radius == 0 ) { $Radius = 1; }
  741. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  742. $X = floor($X); $Y = floor($Y);
  743. $Radius = abs($Radius);
  744. $RestoreShadow = $this->Shadow;
  745. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  746. {
  747. $this->Shadow = FALSE;
  748. $this->drawFilledCircle($X+$this->ShadowX,$Y+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks));
  749. }
  750. $this->Mask = "";
  751. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  752. for ($i=0; $i<=$Radius*2; $i++)
  753. {
  754. $Slice = sqrt($Radius * $Radius - ($Radius - $i) * ($Radius - $i));
  755. $XPos = floor($Slice);
  756. $YPos = $Y + $i - $Radius;
  757. $AAlias = $Slice - floor($Slice);
  758. $this->Mask[$X-$XPos][$YPos] = TRUE;
  759. $this->Mask[$X+$XPos][$YPos] = TRUE;
  760. imageline($this->Picture,$X-$XPos,$YPos,$X+$XPos,$YPos,$Color);
  761. }
  762. if ( $this->Antialias )
  763. $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  764. $this->Mask = "";
  765. if ( $BorderR != -1 )
  766. $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks));
  767. $this->Shadow = $RestoreShadow;
  768. }
  769. /* Write text */
  770. function drawText($X,$Y,$Text,$Format="")
  771. {
  772. $R = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
  773. $G = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
  774. $B = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
  775. $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
  776. $Align = isset($Format["Align"]) ? $Format["Align"] : TEXT_ALIGN_BOTTOMLEFT;
  777. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
  778. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  779. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  780. $ShowOrigine = isset($Format["ShowOrigine"]) ? $Format["ShowOrigine"] : FALSE;
  781. $TOffset = isset($Format["TOffset"]) ? $Format["TOffset"] : 2;
  782. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : FALSE;
  783. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : TRUE;
  784. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 6;
  785. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : FALSE;
  786. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 6;
  787. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 255;
  788. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 255;
  789. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 255;
  790. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
  791. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  792. $BoxBorderR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  793. $BoxBorderG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  794. $BoxBorderB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  795. $BoxBorderAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
  796. $NoShadow = isset($Format["NoShadow"]) ? $Format["NoShadow"] : FALSE;
  797. $Shadow = $this->Shadow;
  798. if ( $NoShadow ) { $this->Shadow = FALSE; }
  799. if ( $BoxSurrounding != "" ) { $BoxBorderR = $BoxR - $BoxSurrounding; $BoxBorderG = $BoxG - $BoxSurrounding; $BoxBorderB = $BoxB - $BoxSurrounding; $BoxBorderAlpha = $BoxAlpha; }
  800. if ( $ShowOrigine )
  801. {
  802. $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  803. $this->drawRectangleMarker($X,$Y,$MyMarkerSettings);
  804. }
  805. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,$Angle,$Text);
  806. if ( $DrawBox && ($Angle == 0 || $Angle == 90 || $Angle == 180 || $Angle == 270))
  807. {
  808. $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;
  809. 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; }
  810. $X1 = min($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) - $BorderOffset + 3;
  811. $Y1 = min($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) - $BorderOffset;
  812. $X2 = max($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) + $BorderOffset + 3;
  813. $Y2 = max($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) + $BorderOffset - 3;
  814. $X1 = $X1 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
  815. $Y1 = $Y1 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
  816. $X2 = $X2 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
  817. $Y2 = $Y2 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
  818. $Settings = array("R"=>$BoxR,"G"=>$BoxG,"B"=>$BoxB,"Alpha"=>$BoxAlpha,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"BorderAlpha"=>$BoxBorderAlpha);
  819. if ( $BoxRounded )
  820. { $this->drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$RoundedRadius,$Settings); }
  821. else
  822. { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Settings); }
  823. }
  824. $X = $X - $TxtPos[$Align]["X"] + $X;
  825. $Y = $Y - $TxtPos[$Align]["Y"] + $Y;
  826. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  827. {
  828. $C_ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  829. imagettftext($this->Picture,$FontSize,$Angle,$X+$this->ShadowX,$Y+$this->ShadowY,$C_ShadowColor,$FontName,$Text);
  830. }
  831. $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B,$Alpha);
  832. imagettftext($this->Picture,$FontSize,$Angle,$X,$Y,$C_TextColor,$FontName,$Text);
  833. $this->Shadow = $Shadow;
  834. return($TxtPos);
  835. }
  836. /* Draw a gradient within a defined area */
  837. function drawGradientArea($X1,$Y1,$X2,$Y2,$Direction,$Format="")
  838. {
  839. $StartR = isset($Format["StartR"]) ? $Format["StartR"] : 90;
  840. $StartG = isset($Format["StartG"]) ? $Format["StartG"] : 90;
  841. $StartB = isset($Format["StartB"]) ? $Format["StartB"] : 90;
  842. $EndR = isset($Format["EndR"]) ? $Format["EndR"] : 0;
  843. $EndG = isset($Format["EndG"]) ? $Format["EndG"] : 0;
  844. $EndB = isset($Format["EndB"]) ? $Format["EndB"] : 0;
  845. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  846. $Levels = isset($Format["Levels"]) ? $Format["Levels"] : NULL;
  847. $Shadow = $this->Shadow;
  848. $this->Shadow = FALSE;
  849. if ( $StartR == $EndR && $StartG == $EndG && $StartB == $EndB )
  850. {
  851. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,array("R"=>$StartR,"G"=>$StartG,"B"=>$StartB,"Alpha"=>$Alpha));
  852. return(0);
  853. }
  854. if ( $Levels != NULL )
  855. { $EndR=$StartR+$Levels; $EndG=$StartG+$Levels; $EndB=$StartB+$Levels; }
  856. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  857. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  858. if ( $Direction == DIRECTION_VERTICAL ) { $Width = abs($Y2-$Y1); }
  859. if ( $Direction == DIRECTION_HORIZONTAL ) { $Width = abs($X2-$X1); }
  860. $Step = max(abs($EndR-$StartR),abs($EndG-$StartG),abs($EndB-$StartB));
  861. $StepSize = $Width/$Step;
  862. $RStep = ($EndR-$StartR)/$Step;
  863. $GStep = ($EndG-$StartG)/$Step;
  864. $BStep = ($EndB-$StartB)/$Step;
  865. $R=$StartR;$G=$StartG;$B=$StartB;
  866. switch($Direction)
  867. {
  868. case DIRECTION_VERTICAL:
  869. $StartY = $Y1; $EndY = floor($Y2)+1; $LastY2 = $StartY;
  870. for($i=0;$i<=$Step;$i++)
  871. {
  872. $Y2 = floor($StartY + ($i * $StepSize));
  873. if ($Y2 > $EndY) { $Y2 = $EndY; }
  874. if (($Y1 != $Y2 && $Y1 < $Y2) || $Y2 == $EndY)
  875. {
  876. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  877. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
  878. $LastY2 = max($LastY2,$Y2);
  879. $Y1 = $Y2+1;
  880. }
  881. $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep;
  882. }
  883. if ( $LastY2 < $EndY && isset($Color)) { for ($i=$LastY2+1;$i<=$EndY;$i++) { $this->drawLine($X1,$i,$X2,$i,$Color); } }
  884. break;
  885. case DIRECTION_HORIZONTAL:
  886. $StartX = $X1; $EndX = $X2;
  887. for($i=0;$i<=$Step;$i++)
  888. {
  889. $X2 = floor($StartX + ($i * $StepSize));
  890. if ($X2 > $EndX) { $X2 = $EndX; }
  891. if (($X1 != $X2 && $X1 < $X2) || $X2 == $EndX)
  892. {
  893. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  894. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
  895. $X1 = $X2+1;
  896. }
  897. $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep;
  898. }
  899. if ( $X2 < $EndX && isset($Color)) { $this->drawFilledRectangle($X2,$Y1,$EndX,$Y2,$Color); }
  900. break;
  901. }
  902. $this->Shadow = $Shadow;
  903. }
  904. /* Draw an aliased pixel */
  905. function drawAntialiasPixel($X,$Y,$Format="")
  906. {
  907. $R = isset($Format["R"]) ? $Format["R"] : 0;
  908. $G = isset($Format["G"]) ? $Format["G"] : 0;
  909. $B = isset($Format["B"]) ? $Format["B"] : 0;
  910. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  911. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  912. return(-1);
  913. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  914. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  915. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  916. if ( !$this->Antialias )
  917. {
  918. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  919. {
  920. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  921. imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
  922. }
  923. $PlotColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  924. imagesetpixel($this->Picture,$X,$Y,$PlotColor);
  925. return(0);
  926. }
  927. $Plot = "";
  928. $Xi = floor($X);
  929. $Yi = floor($Y);
  930. if ( $Xi == $X && $Yi == $Y)
  931. {
  932. if ( $Alpha == 100 )
  933. $this->drawAlphaPixel($X,$Y,100,$R,$G,$B);
  934. else
  935. $this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B);
  936. }
  937. else
  938. {
  939. $Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  940. if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); }
  941. $Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  942. if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); }
  943. $Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  944. if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); }
  945. $Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  946. if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); }
  947. }
  948. }
  949. /* Draw a semi-transparent pixel */
  950. function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
  951. {
  952. if ( isset($this->Mask[$X])) { if ( isset($this->Mask[$X][$Y]) ) { return(0); } }
  953. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  954. return(-1);
  955. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  956. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  957. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  958. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  959. {
  960. $AlphaFactor = floor(($Alpha / 100) * $this->Shadowa);
  961. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$AlphaFactor);
  962. imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
  963. }
  964. $C_Aliased = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  965. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  966. }
  967. /* Convert apha to base 10 */
  968. function convertAlpha($AlphaValue)
  969. { return((127/100)*(100-$AlphaValue)); }
  970. /* Allocate a color with transparency */
  971. function allocateColor($Picture,$R,$G,$B,$Alpha=100)
  972. {
  973. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  974. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  975. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  976. if ( $Alpha < 0 ) { $Alpha = 0; }
  977. if ( $Alpha > 100) { $Alpha = 100; }
  978. $Alpha = $this->convertAlpha($Alpha);
  979. return(imagecolorallocatealpha($Picture,$R,$G,$B,$Alpha));
  980. }
  981. /* Load a PNG file and draw it over the chart */
  982. function drawFromPNG($X,$Y,$FileName)
  983. { $this->drawFromPicture(1,$FileName,$X,$Y); }
  984. /* Load a GIF file and draw it over the chart */
  985. function drawFromGIF($X,$Y,$FileName)
  986. { $this->drawFromPicture(2,$FileName,$X,$Y); }
  987. /* Load a JPEG file and draw it over the chart */
  988. function drawFromJPG($X,$Y,$FileName)
  989. { $this->drawFromPicture(3,$FileName,$X,$Y); }
  990. function getPicInfo($FileName)
  991. {
  992. $Infos = getimagesize($FileName);
  993. $Width = $Infos[0];
  994. $Height = $Infos[1];
  995. $Type = $Infos["mime"];
  996. if ( $Type == "image/png") { $Type = 1; }
  997. if ( $Type == "image/gif") { $Type = 2; }
  998. if ( $Type == "image/jpeg ") { $Type = 3; }
  999. return(array($Width,$Height,$Type));
  1000. }
  1001. /* Generic loader function for external pictures */
  1002. function drawFromPicture($PicType,$FileName,$X,$Y)
  1003. {
  1004. if ( file_exists($FileName))
  1005. {
  1006. list($Width,$Height) = $this->getPicInfo($FileName);
  1007. if ( $PicType == 1 )
  1008. { $Raster = imagecreatefrompng($FileName); }
  1009. elseif ( $PicType == 2 )
  1010. { $Raster = imagecreatefromgif($FileName); }
  1011. elseif ( $PicType == 3 )
  1012. { $Raster = imagecreatefromjpeg($FileName); }
  1013. else
  1014. { return(0); }
  1015. $RestoreShadow = $this->Shadow;
  1016. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  1017. {
  1018. $this->Shadow = FALSE;
  1019. if ( $PicType == 3 )
  1020. $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));
  1021. else
  1022. {
  1023. $TranparentID = imagecolortransparent($Raster);
  1024. for ($Xc=0;$Xc<=$Width-1;$Xc++)
  1025. {
  1026. for ($Yc=0;$Yc<=$Height-1;$Yc++)
  1027. {
  1028. $RGBa = imagecolorat($Raster,$Xc,$Yc);
  1029. $Values = imagecolorsforindex($Raster,$RGBa);
  1030. if ( $Values["alpha"] < 120 )
  1031. {
  1032. $AlphaFactor = floor(($this->Shadowa / 100) * ((100 / 127) * (127-$Values["alpha"])));
  1033. $this->drawAlphaPixel($X+$Xc+$this->ShadowX,$Y+$Yc+$this->ShadowY,$AlphaFactor,$this->ShadowR,$this->ShadowG,$this->ShadowB);
  1034. }
  1035. }
  1036. }
  1037. }
  1038. }
  1039. $this->Shadow = $RestoreShadow;
  1040. imagecopy($this->Picture,$Raster,$X,$Y,0,0,$Width,$Height);
  1041. imagedestroy($Raster);
  1042. }
  1043. }
  1044. /* Draw an arrow */
  1045. function drawArrow($X1,$Y1,$X2,$Y2,$Format="")
  1046. {
  1047. $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
  1048. $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
  1049. $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
  1050. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
  1051. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
  1052. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
  1053. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1054. $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
  1055. $Ratio = isset($Format["Ratio"]) ? $Format["Ratio"] : .5;
  1056. $TwoHeads = isset($Format["TwoHeads"]) ? $Format["TwoHeads"] : FALSE;
  1057. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : FALSE;
  1058. /* Calculate the line angle */
  1059. $Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
  1060. /* Override Shadow support, this will be managed internally */
  1061. $RestoreShadow = $this->Shadow;
  1062. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  1063. {
  1064. $this->Shadow = FALSE;
  1065. $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));
  1066. }
  1067. /* Draw the 1st Head */
  1068. $TailX = cos(($Angle-180)*PI/180)*$Size+$X2;
  1069. $TailY = sin(($Angle-180)*PI/180)*$Size+$Y2;
  1070. $Points = "";
  1071. $Points[] = $X2; $Points[] = $Y2;
  1072. $Points[] = cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY;
  1073. $Points[] = cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY;
  1074. $Points[] = $X2; $Points[] = $Y2;
  1075. /* Visual correction */
  1076. if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
  1077. if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }
  1078. $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
  1079. ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);
  1080. $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1081. $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1082. $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1083. /* Draw the second head */
  1084. if ( $TwoHeads )
  1085. {
  1086. $Angle = $this->getAngle($X2,$Y2,$X1,$Y1);
  1087. $TailX2 = cos(($Angle-180)*PI/180)*$Size+$X1;
  1088. $TailY2 = sin(($Angle-180)*PI/180)*$Size+$Y1;
  1089. $Points = "";
  1090. $Points[] = $X1; $Points[] = $Y1;
  1091. $Points[] = cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY2;
  1092. $Points[] = cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY2;
  1093. $Points[] = $X1; $Points[] = $Y1;
  1094. /* Visual correction */
  1095. if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
  1096. if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }
  1097. $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
  1098. ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);
  1099. $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1100. $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1101. $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1102. $this->drawLine($TailX,$TailY,$TailX2,$TailY2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1103. }
  1104. else
  1105. $this->drawLine($X1,$Y1,$TailX,$TailY,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1106. /* Re-enable shadows */
  1107. $this->Shadow = $RestoreShadow;
  1108. }
  1109. /* Draw a label with associated arrow */
  1110. function drawArrowLabel($X1,$Y1,$Text,$Format="")
  1111. {
  1112. $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
  1113. $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
  1114. $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
  1115. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
  1116. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
  1117. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
  1118. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1119. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1120. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1121. $Length = isset($Format["Length"]) ? $Format["Length"] : 50;
  1122. $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 315;
  1123. $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
  1124. $Position = isset($Format["Position"]) ? $Format["Position"] : POSITION_TOP;
  1125. $RoundPos = isset($Format["RoundPos"]) ? $Format["RoundPos"] : FALSE;
  1126. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  1127. $Angle = $Angle % 360;
  1128. $X2 = sin(($Angle+180)*PI/180)*$Length+$X1;
  1129. $Y2 = cos(($Angle+180)*PI/180)*$Length+$Y1;
  1130. if ( $RoundPos && $Angle > 0 && $Angle < 180 ) { $Y2 = ceil($Y2); }
  1131. if ( $RoundPos && $Angle > 180 ) { $Y2 = floor($Y2); }
  1132. $this->drawArrow($X2,$Y2,$X1,$Y1,$Format);
  1133. $Size = imagettfbbox($FontSize,0,$FontName,$Text);
  1134. $TxtWidth = max(abs($Size[2]-$Size[0]),abs($Size[0]-$Size[6]));
  1135. $TxtHeight = max(abs($Size[1]-$Size[7]),abs($Size[3]-$Size[1]));
  1136. if ( $Angle > 0 && $Angle < 180 )
  1137. {
  1138. $this->drawLine($X2,$Y2,$X2-$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1139. if ( $Position == POSITION_TOP )
  1140. $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_BOTTOMRIGHT));
  1141. else
  1142. $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPRIGHT));
  1143. }
  1144. else
  1145. {
  1146. $this->drawLine($X2,$Y2,$X2+$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1147. if ( $Position == POSITION_TOP )
  1148. $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1149. else
  1150. $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPLEFT));
  1151. }
  1152. }
  1153. /* Draw a progress bar filled with specified % */
  1154. function drawProgress($X,$Y,$Percent,$Format="")
  1155. {
  1156. if ( $Percent > 100 ) { $Percent = 100; }
  1157. if ( $Percent < 0 ) { $Percent = 0; }
  1158. $Width = isset($Format["Width"]) ? $Format["Width"] : 200;
  1159. $Height = isset($Format["Height"]) ? $Format["Height"] : 20;
  1160. $Orientation = isset($Format["Orientation"]) ? $Format["Orientation"] : ORIENTATION_HORIZONTAL;
  1161. $ShowLabel = isset($Format["ShowLabel"]) ? $Format["ShowLabel"] : FALSE;
  1162. $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : LABEL_POS_INSIDE;
  1163. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 10;
  1164. $R = isset($Format["R"]) ? $Format["R"] : 130;
  1165. $G = isset($Format["G"]) ? $Format["G"] : 130;
  1166. $B = isset($Format["B"]) ? $Format["B"] : 130;
  1167. $RFade = isset($Format["RFade"]) ? $Format["RFade"] : -1;
  1168. $GFade = isset($Format["GFade"]) ? $Format["GFade"] : -1;
  1169. $BFade = isset($Format["BFade"]) ? $Format["BFade"] : -1;
  1170. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  1171. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  1172. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  1173. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 0;
  1174. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 0;
  1175. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 0;
  1176. $BoxBackR = isset($Format["BoxBackR"]) ? $Format["BoxBackR"] : 255;
  1177. $BoxBackG = isset($Format["BoxBackG"]) ? $Format["BoxBackG"] : 255;
  1178. $BoxBackB = isset($Format["BoxBackB"]) ? $Format["BoxBackB"] : 255;
  1179. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1180. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  1181. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : NULL;
  1182. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;
  1183. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1184. {
  1185. $RFade = (($RFade-$R)/100)*$Percent+$R;
  1186. $GFade = (($GFade-$G)/100)*$Percent+$G;
  1187. $BFade = (($BFade-$B)/100)*$Percent+$B;
  1188. }
  1189. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  1190. if ( $BoxSurrounding != NULL ) { $BoxBorderR = $BoxBackR + $Surrounding; $BoxBorderG = $BoxBackG + $Surrounding; $BoxBorderB = $BoxBackB + $Surrounding; }
  1191. if ( $Orientation == ORIENTATION_VERTICAL )
  1192. {
  1193. $InnerHeight = (($Height-2)/100)*$Percent;
  1194. $this->drawFilledRectangle($X,$Y,$X+$Width,$Y-$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));
  1195. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1196. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1197. {
  1198. $GradientOptions = array("StartR"=>$RFade,"StartG"=>$GFade,"StartB"=>$BFade,"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  1199. $this->drawGradientArea($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,DIRECTION_VERTICAL,$GradientOptions);
  1200. if ( $Surrounding )
  1201. $this->drawRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
  1202. }
  1203. else
  1204. $this->drawFilledRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1205. $this->Shadow = $RestoreShadow;
  1206. if ( $ShowLabel && $LabelPos == LABEL_POS_BOTTOM ) { $this->drawText($X+($Width/2),$Y+$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_TOPMIDDLE)); }
  1207. if ( $ShowLabel && $LabelPos == LABEL_POS_TOP ) { $this->drawText($X+($Width/2),$Y-$Height-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
  1208. if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE ) { $this->drawText($X+($Width/2),$Y-$InnerHeight-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT,"Angle"=>90)); }
  1209. if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER ) { $this->drawText($X+($Width/2),$Y-($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"Angle"=>90)); }
  1210. }
  1211. else
  1212. {
  1213. if ( $Percent == 100 )
  1214. $InnerWidth = $Width-1;
  1215. else
  1216. $InnerWidth = (($Width-2)/100)*$Percent;
  1217. $this->drawFilledRectangle($X,$Y,$X+$Width,$Y+$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));
  1218. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1219. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1220. {
  1221. $GradientOptions = array("StartR"=>$R,"StartG"=>$G,"StartB"=>$B,"EndR"=>$RFade,"EndG"=>$GFade,"EndB"=>$BFade);
  1222. $this->drawGradientArea($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,DIRECTION_HORIZONTAL,$GradientOptions);
  1223. if ( $Surrounding )
  1224. $this->drawRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
  1225. }
  1226. else
  1227. $this->drawFilledRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1228. $this->Shadow = $RestoreShadow;
  1229. if ( $ShowLabel && $LabelPos == LABEL_POS_LEFT ) { $this->drawText($X-$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); }
  1230. if ( $ShowLabel && $LabelPos == LABEL_POS_RIGHT ) { $this->drawText($X+$Width+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
  1231. if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER ) { $this->drawText($X+($Width/2),$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE)); }
  1232. if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE ) { $this->drawText($X+$InnerWidth+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
  1233. }
  1234. }
  1235. /* Get the legend box size */
  1236. function getLegendSize($Format="")
  1237. {
  1238. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1239. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1240. $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
  1241. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  1242. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  1243. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  1244. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
  1245. $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
  1246. $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
  1247. $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
  1248. $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
  1249. $Data = $this->DataSet->getData();
  1250. foreach($Data["Series"] as $SerieName => $Serie)
  1251. {
  1252. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
  1253. {
  1254. list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
  1255. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  1256. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  1257. }
  1258. }
  1259. $YStep = max($this->FontSize,$IconAreaHeight) + 5;
  1260. $XStep = $IconAreaWidth + 5;
  1261. $XStep = $XSpacing;
  1262. $X=100; $Y=100;
  1263. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  1264. foreach($Data["Series"] as $SerieName => $Serie)
  1265. {
  1266. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1267. {
  1268. if ( $Mode == LEGEND_VERTICAL )
  1269. {
  1270. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);
  1271. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1272. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1273. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1274. $Lines = preg_split("/\n/",$Serie["Description"]);
  1275. $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1276. }
  1277. elseif ( $Mode == LEGEND_HORIZONTAL )
  1278. {
  1279. $Lines = preg_split("/\n/",$Serie["Description"]);
  1280. $Width = "";
  1281. foreach($Lines as $Key => $Value)
  1282. {
  1283. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  1284. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1285. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1286. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1287. $Width[] = $BoxArray[1]["X"];
  1288. }
  1289. $vX=max($Width)+$XStep;
  1290. }
  1291. }
  1292. }
  1293. $vY=$vY-$YStep; $vX=$vX-$XStep;
  1294. $TopOffset = $Y - $Boundaries["T"];
  1295. if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
  1296. $Width = ($Boundaries["R"]+$Margin) - ($Boundaries["L"]-$Margin);
  1297. $Height = ($Boundaries["B"]+$Margin) - ($Boundaries["T"]-$Margin);
  1298. return(array("Width"=>$Width,"Height"=>$Height));
  1299. }
  1300. /* Draw the legend of the active series */
  1301. function drawLegend($X,$Y,$Format="")
  1302. {
  1303. $Family = isset($Format["Family"]) ? $Format["Family"] : LEGEND_FAMILY_BOX;
  1304. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1305. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1306. $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->FontColorR;
  1307. $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->FontColorG;
  1308. $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->FontColorB;
  1309. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
  1310. $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
  1311. $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
  1312. $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
  1313. $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
  1314. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  1315. $R = isset($Format["R"]) ? $Format["R"] : 200;
  1316. $G = isset($Format["G"]) ? $Format["G"] : 200;
  1317. $B = isset($Format["B"]) ? $Format["B"] : 200;
  1318. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1319. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
  1320. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
  1321. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
  1322. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  1323. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  1324. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  1325. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  1326. $Data = $this->DataSet->getData();
  1327. foreach($Data["Series"] as $SerieName => $Serie)
  1328. {
  1329. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
  1330. {
  1331. list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
  1332. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  1333. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  1334. }
  1335. }
  1336. $YStep = max($this->FontSize,$IconAreaHeight) + 5;
  1337. $XStep = $IconAreaWidth + 5;
  1338. $XStep = $XSpacing;
  1339. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  1340. foreach($Data["Series"] as $SerieName => $Serie)
  1341. {
  1342. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1343. {
  1344. if ( $Mode == LEGEND_VERTICAL )
  1345. {
  1346. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);
  1347. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1348. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1349. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1350. $Lines = preg_split("/\n/",$Serie["Description"]);
  1351. $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1352. }
  1353. elseif ( $Mode == LEGEND_HORIZONTAL )
  1354. {
  1355. $Lines = preg_split("/\n/",$Serie["Description"]);
  1356. $Width = "";
  1357. foreach($Lines as $Key => $Value)
  1358. {
  1359. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  1360. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1361. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1362. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1363. $Width[] = $BoxArray[1]["X"];
  1364. }
  1365. $vX=max($Width)+$XStep;
  1366. }
  1367. }
  1368. }
  1369. $vY=$vY-$YStep; $vX=$vX-$XStep;
  1370. $TopOffset = $Y - $Boundaries["T"];
  1371. if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
  1372. if ( $Style == LEGEND_ROUND )
  1373. $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));
  1374. elseif ( $Style == LEGEND_BOX )
  1375. $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));
  1376. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1377. foreach($Data["Series"] as $SerieName => $Serie)
  1378. {
  1379. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1380. {
  1381. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"];
  1382. $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  1383. if ( isset($Serie["Picture"]) )
  1384. {
  1385. $Picture = $Serie["Picture"];
  1386. list($PicWidth,$PicHeight) = $this->getPicInfo($Picture);
  1387. $PicX = $X+$IconAreaWidth/2; $PicY = $Y+$IconAreaHeight/2;
  1388. $this->drawFromPNG($PicX-$PicWidth/2,$PicY-$PicHeight/2,$Picture);
  1389. }
  1390. else
  1391. {
  1392. if ( $Family == LEGEND_FAMILY_BOX )
  1393. {
  1394. if ( $BoxWidth != $IconAreaWidth ) { $XOffset = floor(($IconAreaWidth-$BoxWidth)/2); } else { $XOffset = 0; }
  1395. if ( $BoxHeight != $IconAreaHeight ) { $YOffset = floor(($IconAreaHeight-$BoxHeight)/2); } else { $YOffset = 0; }
  1396. $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));
  1397. $this->drawFilledRectangle($X+$XOffset,$Y+$YOffset,$X+$BoxWidth+$XOffset,$Y+$BoxHeight+$YOffset,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
  1398. }
  1399. elseif ( $Family == LEGEND_FAMILY_CIRCLE )
  1400. {
  1401. $this->drawFilledCircle($X+1+$IconAreaWidth/2,$Y+1+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
  1402. $this->drawFilledCircle($X+$IconAreaWidth/2,$Y+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
  1403. }
  1404. elseif ( $Family == LEGEND_FAMILY_LINE )
  1405. {
  1406. $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));
  1407. $this->drawLine($X,$Y+$IconAreaHeight/2,$X+$IconAreaWidth,$Y+$IconAreaHeight/2,array("R"=>$R,"G"=>$G,"B"=>$B,"Ticks"=>$Ticks,"Weight"=>$Weight));
  1408. }
  1409. }
  1410. if ( $Mode == LEGEND_VERTICAL )
  1411. {
  1412. $Lines = preg_split("/\n/",$Serie["Description"]);
  1413. foreach($Lines as $Key => $Value)
  1414. $this->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontSize"=>$FontSize,"FontName"=>$FontName));
  1415. $Y=$Y+max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1416. }
  1417. elseif ( $Mode == LEGEND_HORIZONTAL )
  1418. {
  1419. $Lines = preg_split("/\n/",$Serie["Description"]);
  1420. $Width = "";
  1421. foreach($Lines as $Key => $Value)
  1422. {
  1423. $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,"FontSize"=>$FontSize,"FontName"=>$FontName));
  1424. $Width[] = $BoxArray[1]["X"];
  1425. }
  1426. $X=max($Width)+2+$XStep;
  1427. }
  1428. }
  1429. }
  1430. $this->Shadow = $RestoreShadow;
  1431. }
  1432. function drawScale($Format="")
  1433. {
  1434. $Pos = isset($Format["Pos"]) ? $Format["Pos"] : SCALE_POS_LEFTRIGHT;
  1435. $Floating = isset($Format["Floating"]) ? $Format["Floating"] : FALSE;
  1436. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : SCALE_MODE_FLOATING;
  1437. $RemoveXAxis = isset($Format["RemoveXAxis"]) ? $Format["RemoveXAxis"] : FALSE;
  1438. $MinDivHeight = isset($Format["MinDivHeight"]) ? $Format["MinDivHeight"] : 20;
  1439. $Factors = isset($Format["Factors"]) ? $Format["Factors"] : array(1,2,5);
  1440. $ManualScale = isset($Format["ManualScale"]) ? $Format["ManualScale"] : array("0"=>array("Min"=>-100,"Max"=>100));
  1441. $XMargin = isset($Format["XMargin"]) ? $Format["XMargin"] : AUTO;
  1442. $YMargin = isset($Format["YMargin"]) ? $Format["YMargin"] : 0;
  1443. $ScaleSpacing = isset($Format["ScaleSpacing"]) ? $Format["ScaleSpacing"] : 15;
  1444. $InnerTickWidth = isset($Format["InnerTickWidth"]) ? $Format["InnerTickWidth"] : 2;
  1445. $OuterTickWidth = isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2;
  1446. $DrawXLines = isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : TRUE;
  1447. $DrawYLines = isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL;
  1448. $GridTicks = isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4;
  1449. $GridR = isset($Format["GridR"]) ? $Format["GridR"] : 255;
  1450. $GridG = isset($Format["GridG"]) ? $Format["GridG"] : 255;
  1451. $GridB = isset($Format["GridB"]) ? $Format["GridB"] : 255;
  1452. $GridAlpha = isset($Format["GridAlpha"]) ? $Format["GridAlpha"] : 40;
  1453. $AxisRo = isset($Format["AxisR"]) ? $Format["AxisR"] : 0;
  1454. $AxisGo = isset($Format["AxisG"]) ? $Format["AxisG"] : 0;
  1455. $AxisBo = isset($Format["AxisB"]) ? $Format["AxisB"] : 0;
  1456. $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100;
  1457. $TickRo = isset($Format["TickR"]) ? $Format["TickR"] : 0;
  1458. $TickGo = isset($Format["TickG"]) ? $Format["TickG"] : 0;
  1459. $TickBo = isset($Format["TickB"]) ? $Format["TickB"] : 0;
  1460. $TickAlpha = isset($Format["TickAlpha"]) ? $Format["TickAlpha"] : 100;
  1461. $DrawSubTicks = isset($Format["DrawSubTicks"]) ? $Format["DrawSubTicks"] : FALSE;
  1462. $InnerSubTickWidth = isset($Format["InnerSubTickWidth"]) ? $Format["InnerSubTickWidth"] : 0;
  1463. $OuterSubTickWidth = isset($Format["OuterSubTickWidth"]) ? $Format["OuterSubTickWidth"] : 2;
  1464. $SubTickR = isset($Format["SubTickR"]) ? $Format["SubTickR"] : 255;
  1465. $SubTickG = isset($Format["SubTickG"]) ? $Format["SubTickG"] : 0;
  1466. $SubTickB = isset($Format["SubTickB"]) ? $Format["SubTickB"] : 0;
  1467. $SubTickAlpha = isset($Format["SubTickAlpha"]) ? $Format["SubTickAlpha"] : 100;
  1468. $AutoAxisLabels = isset($Format["AutoAxisLabels"]) ? $Format["AutoAxisLabels"] : TRUE;
  1469. $XReleasePercent = isset($Format["XReleasePercent"]) ? $Format["XReleasePercent"] : 1;
  1470. $DrawArrows = isset($Format["DrawArrows"]) ? $Format["DrawArrows"] : FALSE;
  1471. $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 8;
  1472. $CycleBackground = isset($Format["CycleBackground"]) ? $Format["CycleBackground"] : FALSE;
  1473. $BackgroundR1 = isset($Format["BackgroundR1"]) ? $Format["BackgroundR1"] : 255;
  1474. $BackgroundG1 = isset($Format["BackgroundG1"]) ? $Format["BackgroundG1"] : 255;
  1475. $BackgroundB1 = isset($Format["BackgroundB1"]) ? $Format["BackgroundB1"] : 255;
  1476. $BackgroundAlpha1 = isset($Format["BackgroundAlpha1"]) ? $Format["BackgroundAlpha1"] : 20;
  1477. $BackgroundR2 = isset($Format["BackgroundR2"]) ? $Format["BackgroundR2"] : 230;
  1478. $BackgroundG2 = isset($Format["BackgroundG2"]) ? $Format["BackgroundG2"] : 230;
  1479. $BackgroundB2 = isset($Format["BackgroundB2"]) ? $Format["BackgroundB2"] : 230;
  1480. $BackgroundAlpha2 = isset($Format["BackgroundAlpha2"]) ? $Format["BackgroundAlpha2"] : 20;
  1481. $LabelingMethod = isset($Format["LabelingMethod"]) ? $Format["LabelingMethod"] : LABELING_ALL;
  1482. $LabelSkip = isset($Format["LabelSkip"]) ? $Format["LabelSkip"] : 0;
  1483. $LabelRotation = isset($Format["LabelRotation"]) ? $Format["LabelRotation"] : 0;
  1484. $RemoveSkippedAxis = isset($Format["RemoveSkippedAxis"]) ? $Format["RemoveSkippedAxis"] : FALSE;
  1485. $SkippedAxisTicks = isset($Format["SkippedAxisTicks"]) ? $Format["SkippedAxisTicks"] : $GridTicks+2;
  1486. $SkippedAxisR = isset($Format["SkippedAxisR"]) ? $Format["SkippedAxisR"] : $GridR;
  1487. $SkippedAxisG = isset($Format["SkippedAxisG"]) ? $Format["SkippedAxisG"] : $GridG;
  1488. $SkippedAxisB = isset($Format["SkippedAxisB"]) ? $Format["SkippedAxisB"] : $GridB;
  1489. $SkippedAxisAlpha = isset($Format["SkippedAxisAlpha"]) ? $Format["SkippedAxisAlpha"] : $GridAlpha-30;
  1490. $SkippedTickR = isset($Format["SkippedTickR"]) ? $Format["SkippedTickR"] : $TickRo;
  1491. $SkippedTickG = isset($Format["SkippedTickG"]) ? $Format["SkippedTickG"] : $TickGo;
  1492. $SkippedTickB = isset($Format["SkippedTicksB"]) ? $Format["SkippedTickB"] : $TickBo;
  1493. $SkippedTickAlpha = isset($Format["SkippedTickAlpha"]) ? $Format["SkippedTickAlpha"] : $TickAlpha-80;
  1494. $SkippedInnerTickWidth = isset($Format["SkippedInnerTickWidth"]) ? $Format["SkippedInnerTickWidth"] : 0;
  1495. $SkippedOuterTickWidth = isset($Format["SkippedOuterTickWidth"]) ? $Format["SkippedOuterTickWidth"] : 2;
  1496. /* Floating scale require X & Y margins to be set manually */
  1497. if ( $Floating && ( $XMargin == AUTO || $YMargin == 0 ) ) { $Floating = FALSE; }
  1498. /* Skip a NOTICE event in case of an empty array */
  1499. if ( $DrawYLines == NONE || $DrawYLines == FALSE ) { $DrawYLines = array("zarma"=>"31"); }
  1500. /* Define the color for the skipped elements */
  1501. $SkippedAxisColor = array("R"=>$SkippedAxisR,"G"=>$SkippedAxisG,"B"=>$SkippedAxisB,"Alpha"=>$SkippedAxisAlpha,"Ticks"=>$SkippedAxisTicks);
  1502. $SkippedTickColor = array("R"=>$SkippedTickR,"G"=>$SkippedTickG,"B"=>$SkippedTickB,"Alpha"=>$SkippedTickAlpha);
  1503. $Data = $this->DataSet->getData();
  1504. if ( isset($Data["Abscissa"]) ) { $Abscissa = $Data["Abscissa"]; } else { $Abscissa = NULL; }
  1505. /* Unset the abscissa axis, needed if we display multiple charts on the same picture */
  1506. if ( $Abscissa != NULL )
  1507. {
  1508. foreach($Data["Axis"] as $AxisID => $Parameters)
  1509. { if ($Parameters["Identity"] == AXIS_X) { unset($Data["Axis"][$AxisID]); } }
  1510. }
  1511. /* Build the scale settings */
  1512. $GotXAxis = FALSE;
  1513. foreach($Data["Axis"] as $AxisID => $AxisParameter)
  1514. {
  1515. if ( $AxisParameter["Identity"] == AXIS_X ) { $GotXAxis = TRUE; }
  1516. if ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_Y)
  1517. { $Height = $this->GraphAreaY2-$this->GraphAreaY1 - $YMargin*2; }
  1518. elseif ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_X)
  1519. { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
  1520. elseif ( $Pos == SCALE_POS_TOPBOTTOM && $AxisParameter["Identity"] == AXIS_Y)
  1521. { $Height = $this->GraphAreaX2-$this->GraphAreaX1 - $YMargin*2;; }
  1522. else
  1523. { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }
  1524. $AxisMin = ABSOLUTE_MAX; $AxisMax = OUT_OF_SIGHT;
  1525. if ( $Mode == SCALE_MODE_FLOATING || $Mode == SCALE_MODE_START0 )
  1526. {
  1527. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1528. {
  1529. if ( $SerieParameter["Axis"] == $AxisID && $Data["Series"][$SerieID]["isDrawable"] && $Data["Abscissa"] != $SerieID)
  1530. {
  1531. $AxisMax = max($AxisMax,$Data["Series"][$SerieID]["Max"]);
  1532. $AxisMin = min($AxisMin,$Data["Series"][$SerieID]["Min"]);
  1533. }
  1534. }
  1535. $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
  1536. $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
  1537. if ( $Mode == SCALE_MODE_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; }
  1538. }
  1539. elseif ( $Mode == SCALE_MODE_MANUAL )
  1540. {
  1541. if ( isset($ManualScale[$AxisID]["Min"]) && isset($ManualScale[$AxisID]["Max"]) )
  1542. {
  1543. $Data["Axis"][$AxisID]["Min"] = $ManualScale[$AxisID]["Min"];
  1544. $Data["Axis"][$AxisID]["Max"] = $ManualScale[$AxisID]["Max"];
  1545. }
  1546. else
  1547. { echo "Manual scale boundaries not set."; exit(); }
  1548. }
  1549. elseif ( $Mode == SCALE_MODE_ADDALL || $Mode == SCALE_MODE_ADDALL_START0 )
  1550. {
  1551. $Series = "";
  1552. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1553. { if ( $SerieParameter["Axis"] == $AxisID && $SerieParameter["isDrawable"] && $Data["Abscissa"] != $SerieID ) { $Series[$SerieID] = count($Data["Series"][$SerieID]["Data"]); } }
  1554. for ($ID=0;$ID<=max($Series)-1;$ID++)
  1555. {
  1556. $PointMin = 0; $PointMax = 0;
  1557. foreach($Series as $SerieID => $ValuesCount )
  1558. {
  1559. if (isset($Data["Series"][$SerieID]["Data"][$ID]) && $Data["Series"][$SerieID]["Data"][$ID] != NULL )
  1560. {
  1561. $Value = $Data["Series"][$SerieID]["Data"][$ID];
  1562. if ( $Value > 0 ) { $PointMax = $PointMax + $Value; } else { $PointMin = $PointMin + $Value; }
  1563. }
  1564. }
  1565. $AxisMax = max($AxisMax,$PointMax);
  1566. $AxisMin = min($AxisMin,$PointMin);
  1567. }
  1568. $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
  1569. $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
  1570. }
  1571. $MaxDivs = floor($Height/$MinDivHeight);
  1572. if ( $Mode == SCALE_MODE_ADDALL_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; }
  1573. $Scale = $this->computeScale($Data["Axis"][$AxisID]["Min"],$Data["Axis"][$AxisID]["Max"],$MaxDivs,$Factors,$AxisID);
  1574. $Data["Axis"][$AxisID]["Margin"] = $AxisParameter["Identity"] == AXIS_X ? $XMargin : $YMargin;
  1575. $Data["Axis"][$AxisID]["ScaleMin"] = $Scale["XMin"];
  1576. $Data["Axis"][$AxisID]["ScaleMax"] = $Scale["XMax"];
  1577. $Data["Axis"][$AxisID]["Rows"] = $Scale["Rows"];
  1578. $Data["Axis"][$AxisID]["RowHeight"] = $Scale["RowHeight"];
  1579. if ( isset($Scale["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = $Scale["Format"]; }
  1580. if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
  1581. if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
  1582. if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
  1583. }
  1584. /* Still no X axis */
  1585. if ( $GotXAxis == FALSE )
  1586. {
  1587. if ( $Abscissa != NULL )
  1588. {
  1589. $Points = count($Data["Series"][$Abscissa]["Data"]);
  1590. if ( $AutoAxisLabels )
  1591. $AxisName = isset($Data["Series"][$Abscissa]["Description"]) ? $Data["Series"][$Abscissa]["Description"] : NULL;
  1592. else
  1593. $AxisName = NULL;
  1594. }
  1595. else
  1596. {
  1597. $Points = 0;
  1598. $AxisName = isset($Data["XAxisName"]) ? $Data["XAxisName"] : NULL;
  1599. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1600. { if ( $SerieParameter["isDrawable"] ) { $Points = max($Points,count($SerieParameter["Data"])); } }
  1601. }
  1602. $AxisID = count($Data["Axis"]);
  1603. $Data["Axis"][$AxisID]["Identity"] = AXIS_X;
  1604. if ( $Pos == SCALE_POS_LEFTRIGHT ) { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_BOTTOM; } else { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_LEFT; }
  1605. if ( isset($Data["AbscissaName"]) ) { $Data["Axis"][$AxisID]["Name"] = $Data["AbscissaName"]; }
  1606. if ( $XMargin == AUTO )
  1607. {
  1608. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1609. { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
  1610. else
  1611. { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }
  1612. if ( $Points == 1 )
  1613. $Data["Axis"][$AxisID]["Margin"] = $Height / 2;
  1614. else
  1615. $Data["Axis"][$AxisID]["Margin"] = ($Height/$Points) / 2;
  1616. }
  1617. else
  1618. { $Data["Axis"][$AxisID]["Margin"] = $XMargin; }
  1619. $Data["Axis"][$AxisID]["Rows"] = $Points-1;
  1620. if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
  1621. if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
  1622. if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
  1623. }
  1624. /* Do we need to reverse the abscissa position? */
  1625. if ( $Pos != SCALE_POS_LEFTRIGHT )
  1626. {
  1627. if ( $Data["AbsicssaPosition"] == AXIS_POSITION_BOTTOM )
  1628. { $Data["AbsicssaPosition"] = AXIS_POSITION_LEFT; }
  1629. else
  1630. { $Data["AbsicssaPosition"] = AXIS_POSITION_RIGHT; }
  1631. }
  1632. $Data["Axis"][$AxisID]["Position"] = $Data["AbsicssaPosition"];
  1633. $this->DataSet->saveOrientation($Pos);
  1634. $this->DataSet->saveAxisConfig($Data["Axis"]);
  1635. $this->DataSet->saveYMargin($YMargin);
  1636. $FontColorRo = $this->FontColorR; $FontColorGo = $this->FontColorG; $FontColorBo = $this->FontColorB;
  1637. $AxisPos["L"] = $this->GraphAreaX1; $AxisPos["R"] = $this->GraphAreaX2; $AxisPos["T"] = $this->GraphAreaY1; $AxisPos["B"] = $this->GraphAreaY2;
  1638. foreach($Data["Axis"] as $AxisID => $Parameters)
  1639. {
  1640. if ( isset($Parameters["Color"]) )
  1641. {
  1642. $AxisR = $Parameters["Color"]["R"]; $AxisG = $Parameters["Color"]["G"]; $AxisB = $Parameters["Color"]["B"];
  1643. $TickR = $Parameters["Color"]["R"]; $TickG = $Parameters["Color"]["G"]; $TickB = $Parameters["Color"]["B"];
  1644. $this->setFontProperties(array("R"=>$Parameters["Color"]["R"],"G"=>$Parameters["Color"]["G"],"B"=>$Parameters["Color"]["B"]));
  1645. }
  1646. else
  1647. {
  1648. $AxisR = $AxisRo; $AxisG = $AxisGo; $AxisB = $AxisBo;
  1649. $TickR = $TickRo; $TickG = $TickGo; $TickB = $TickBo;
  1650. $this->setFontProperties(array("R"=>$FontColorRo,"G"=>$FontColorGo,"B"=>$FontColorBo));
  1651. }
  1652. $LastValue = "w00t"; $ID = 1;
  1653. if ( $Parameters["Identity"] == AXIS_X )
  1654. {
  1655. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1656. {
  1657. if ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
  1658. {
  1659. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 2; }
  1660. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }
  1661. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 5; }
  1662. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }
  1663. if ( !$RemoveXAxis )
  1664. {
  1665. if ( $Floating )
  1666. { $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)); }
  1667. else
  1668. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1669. 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)); }
  1670. }
  1671. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1672. if ($Parameters["Rows"] == 0 ) { $Step = $Width; } else { $Step = $Width / ($Parameters["Rows"]); }
  1673. $MaxBottom = $AxisPos["B"];
  1674. for($i=0;$i<=$Parameters["Rows"];$i++)
  1675. {
  1676. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1677. $YPos = $AxisPos["B"];
  1678. if ( $Abscissa != NULL )
  1679. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1680. else
  1681. {
  1682. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1683. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1684. else
  1685. $Value = $i;
  1686. }
  1687. $ID++; $Skipped = TRUE;
  1688. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1689. {
  1690. $Bounds = $this->drawText($XPos,$YPos+$OuterTickWidth+$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1691. $TxtBottom = $YPos+$OuterTickWidth+2+($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  1692. $MaxBottom = max($MaxBottom,$TxtBottom);
  1693. $LastValue = $Value;
  1694. $Skipped = FALSE;
  1695. }
  1696. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1697. if ( $Skipped )
  1698. {
  1699. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
  1700. if ( ($SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis) { $this->drawLine($XPos,$YPos-$SkippedInnerTickWidth,$XPos,$YPos+$SkippedOuterTickWidth,$SkippedTickColor); }
  1701. }
  1702. else
  1703. {
  1704. 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)); }
  1705. if ( ($InnerTickWidth !=0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1706. }
  1707. }
  1708. if ( isset($Parameters["Name"]) && !$RemoveXAxis)
  1709. {
  1710. $YPos = $MaxBottom+2;
  1711. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1712. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  1713. $MaxBottom = $Bounds[0]["Y"];
  1714. $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
  1715. }
  1716. $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
  1717. }
  1718. elseif ( $Parameters["Position"] == AXIS_POSITION_TOP )
  1719. {
  1720. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 2; }
  1721. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }
  1722. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 5; }
  1723. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }
  1724. if ( !$RemoveXAxis )
  1725. {
  1726. if ( $Floating )
  1727. { $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)); }
  1728. else
  1729. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1730. 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)); }
  1731. }
  1732. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1733. if ($Parameters["Rows"] == 0 ) { $Step = $Width; } else { $Step = $Width / $Parameters["Rows"]; }
  1734. $MinTop = $AxisPos["T"];
  1735. for($i=0;$i<=$Parameters["Rows"];$i++)
  1736. {
  1737. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1738. $YPos = $AxisPos["T"];
  1739. if ( $Abscissa != NULL )
  1740. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1741. else
  1742. {
  1743. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1744. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1745. else
  1746. $Value = $i;
  1747. }
  1748. $ID++; $Skipped = TRUE;
  1749. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1750. {
  1751. $Bounds = $this->drawText($XPos,$YPos-$OuterTickWidth-$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1752. $TxtBox = $YPos-$OuterTickWidth-2-($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  1753. $MinTop = min($MinTop,$TxtBox);
  1754. $LastValue = $Value;
  1755. $Skipped = FALSE;
  1756. }
  1757. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1758. if ( $Skipped )
  1759. {
  1760. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
  1761. if ( ($SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis ) { $this->drawLine($XPos,$YPos+$SkippedInnerTickWidth,$XPos,$YPos-$SkippedOuterTickWidth,$SkippedTickColor); }
  1762. }
  1763. else
  1764. {
  1765. if ( $DrawXLines ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1766. if ( ($InnerTickWidth !=0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos,$YPos+$InnerTickWidth,$XPos,$YPos-$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1767. }
  1768. }
  1769. if ( isset($Parameters["Name"]) && !$RemoveXAxis )
  1770. {
  1771. $YPos = $MinTop-2;
  1772. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1773. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  1774. $MinTop = $Bounds[2]["Y"];
  1775. $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
  1776. }
  1777. $AxisPos["T"] = $MinTop - $ScaleSpacing;
  1778. }
  1779. }
  1780. elseif ( $Pos == SCALE_POS_TOPBOTTOM )
  1781. {
  1782. if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
  1783. {
  1784. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -2; }
  1785. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -6; }
  1786. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -2; }
  1787. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -5; }
  1788. if ( !$RemoveXAxis )
  1789. {
  1790. if ( $Floating )
  1791. { $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)); }
  1792. else
  1793. { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1794. 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)); }
  1795. }
  1796. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1797. if ($Parameters["Rows"] == 0 ) { $Step = $Height; } else { $Step = $Height / $Parameters["Rows"]; }
  1798. $MinLeft = $AxisPos["L"];
  1799. for($i=0;$i<=$Parameters["Rows"];$i++)
  1800. {
  1801. $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
  1802. $XPos = $AxisPos["L"];
  1803. if ( $Abscissa != NULL )
  1804. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1805. else
  1806. {
  1807. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1808. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1809. else
  1810. $Value = $i;
  1811. }
  1812. $ID++; $Skipped = TRUE;
  1813. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1814. {
  1815. $Bounds = $this->drawText($XPos-$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1816. $TxtBox = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
  1817. $MinLeft = min($MinLeft,$TxtBox);
  1818. $LastValue = $Value;
  1819. $Skipped = FALSE;
  1820. }
  1821. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1822. if ( $Skipped )
  1823. {
  1824. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
  1825. if ( ($SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis ) { $this->drawLine($XPos-$SkippedOuterTickWidth,$YPos,$XPos+$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
  1826. }
  1827. else
  1828. {
  1829. 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)); }
  1830. if ( ($InnerTickWidth !=0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1831. }
  1832. }
  1833. if ( isset($Parameters["Name"]) && !$RemoveXAxis )
  1834. {
  1835. $XPos = $MinLeft-2;
  1836. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1837. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
  1838. $MinLeft = $Bounds[0]["X"];
  1839. $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
  1840. }
  1841. $AxisPos["L"] = $MinLeft - $ScaleSpacing;
  1842. }
  1843. elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
  1844. {
  1845. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 2; }
  1846. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 6; }
  1847. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 5; }
  1848. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 7; }
  1849. if ( !$RemoveXAxis )
  1850. {
  1851. if ( $Floating )
  1852. { $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)); }
  1853. else
  1854. { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1855. 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)); }
  1856. }
  1857. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1858. if ($Parameters["Rows"] == 0 ) { $Step = $Height; } else { $Step = $Height / $Parameters["Rows"]; }
  1859. $MaxRight = $AxisPos["R"];
  1860. for($i=0;$i<=$Parameters["Rows"];$i++)
  1861. {
  1862. $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
  1863. $XPos = $AxisPos["R"];
  1864. if ( $Abscissa != NULL )
  1865. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1866. else
  1867. {
  1868. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1869. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1870. else
  1871. $Value = $i;
  1872. }
  1873. $ID++; $Skipped = TRUE;
  1874. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1875. {
  1876. $Bounds = $this->drawText($XPos+$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1877. $TxtBox = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
  1878. $MaxRight = max($MaxRight,$TxtBox);
  1879. $LastValue = $Value;
  1880. $Skipped = FALSE;
  1881. }
  1882. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1883. if ( $Skipped )
  1884. {
  1885. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
  1886. if ( ($SkippedInnerTickWidth != 0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis ) { $this->drawLine($XPos+$SkippedOuterTickWidth,$YPos,$XPos-$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
  1887. }
  1888. else
  1889. {
  1890. if ( $DrawXLines ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1891. if ( ($InnerTickWidth != 0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos+$OuterTickWidth,$YPos,$XPos-$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1892. }
  1893. }
  1894. if ( isset($Parameters["Name"]) && !$RemoveXAxis)
  1895. {
  1896. $XPos = $MaxRight+4;
  1897. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1898. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
  1899. $MaxRight = $Bounds[1]["X"];
  1900. $this->DataSet->Data["GraphArea"]["X2"] = $MaxRight + $this->FontSize;
  1901. }
  1902. $AxisPos["R"] = $MaxRight + $ScaleSpacing;
  1903. }
  1904. }
  1905. }
  1906. if ( $Parameters["Identity"] == AXIS_Y )
  1907. {
  1908. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1909. {
  1910. if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
  1911. {
  1912. if ( $Floating )
  1913. { $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)); }
  1914. else
  1915. { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1916. 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)); }
  1917. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1918. $Step = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinLeft = $AxisPos["L"];
  1919. $LastY = NULL;
  1920. for($i=0;$i<=$Parameters["Rows"];$i++)
  1921. {
  1922. $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
  1923. $XPos = $AxisPos["L"];
  1924. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1925. 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); }
  1926. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  1927. 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)); }
  1928. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1929. $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1930. $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1931. $Bounds = $this->drawText($XPos-$OuterTickWidth-2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLERIGHT));
  1932. $TxtLeft = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
  1933. $MinLeft = min($MinLeft,$TxtLeft);
  1934. $LastY = $YPos;
  1935. }
  1936. if ( isset($Parameters["Name"]) )
  1937. {
  1938. $XPos = $MinLeft-2;
  1939. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1940. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
  1941. $MinLeft = $Bounds[2]["X"];
  1942. $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
  1943. }
  1944. $AxisPos["L"] = $MinLeft - $ScaleSpacing;
  1945. }
  1946. elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
  1947. {
  1948. if ( $Floating )
  1949. { $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)); }
  1950. else
  1951. { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1952. 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)); }
  1953. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1954. $Step = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxLeft = $AxisPos["R"];
  1955. $LastY = NULL;
  1956. for($i=0;$i<=$Parameters["Rows"];$i++)
  1957. {
  1958. $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
  1959. $XPos = $AxisPos["R"];
  1960. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1961. 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); }
  1962. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  1963. 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)); }
  1964. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1965. $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1966. $this->drawLine($XPos-$InnerTickWidth,$YPos,$XPos+$OuterTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1967. $Bounds = $this->drawText($XPos+$OuterTickWidth+2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
  1968. $TxtLeft = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
  1969. $MaxLeft = max($MaxLeft,$TxtLeft);
  1970. $LastY = $YPos;
  1971. }
  1972. if ( isset($Parameters["Name"]) )
  1973. {
  1974. $XPos = $MaxLeft+6;
  1975. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1976. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
  1977. $MaxLeft = $Bounds[2]["X"];
  1978. $this->DataSet->Data["GraphArea"]["X2"] = $MaxLeft + $this->FontSize;
  1979. }
  1980. $AxisPos["R"] = $MaxLeft + $ScaleSpacing;
  1981. }
  1982. }
  1983. elseif ( $Pos == SCALE_POS_TOPBOTTOM )
  1984. {
  1985. if ( $Parameters["Position"] == AXIS_POSITION_TOP )
  1986. {
  1987. if ( $Floating )
  1988. { $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)); }
  1989. else
  1990. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1991. 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)); }
  1992. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1993. $Step = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinTop = $AxisPos["T"];
  1994. $LastX = NULL;
  1995. for($i=0;$i<=$Parameters["Rows"];$i++)
  1996. {
  1997. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1998. $YPos = $AxisPos["T"];
  1999. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  2000. 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); }
  2001. if ( $LastX != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }
  2002. 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)); }
  2003. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  2004. $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  2005. $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  2006. $Bounds = $this->drawText($XPos,$YPos-$OuterTickWidth-2,$Value,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2007. $TxtHeight = $YPos-$OuterTickWidth-2-($Bounds[1]["Y"]-$Bounds[2]["Y"]);
  2008. $MinTop = min($MinTop,$TxtHeight);
  2009. $LastX = $XPos;
  2010. }
  2011. if ( isset($Parameters["Name"]) )
  2012. {
  2013. $YPos = $MinTop-2;
  2014. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  2015. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2016. $MinTop = $Bounds[2]["Y"];
  2017. $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
  2018. }
  2019. $AxisPos["T"] = $MinTop - $ScaleSpacing;
  2020. }
  2021. elseif ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
  2022. {
  2023. if ( $Floating )
  2024. { $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)); }
  2025. else
  2026. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  2027. 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)); }
  2028. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  2029. $Step = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxBottom = $AxisPos["B"];
  2030. $LastX = NULL;
  2031. for($i=0;$i<=$Parameters["Rows"];$i++)
  2032. {
  2033. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  2034. $YPos = $AxisPos["B"];
  2035. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  2036. 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); }
  2037. if ( $LastX != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }
  2038. 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)); }
  2039. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  2040. $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  2041. $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  2042. $Bounds = $this->drawText($XPos,$YPos+$OuterTickWidth+2,$Value,array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  2043. $TxtHeight = $YPos+$OuterTickWidth+2+($Bounds[1]["Y"]-$Bounds[2]["Y"]);
  2044. $MaxBottom = max($MaxBottom,$TxtHeight);
  2045. $LastX = $XPos;
  2046. }
  2047. if ( isset($Parameters["Name"]) )
  2048. {
  2049. $YPos = $MaxBottom+2;
  2050. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  2051. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  2052. $MaxBottom = $Bounds[0]["Y"];
  2053. $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
  2054. }
  2055. $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. function isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip)
  2062. {
  2063. if ( $LabelingMethod == LABELING_DIFFERENT && $Value != $LastValue ) { return(TRUE); }
  2064. if ( $LabelingMethod == LABELING_DIFFERENT && $Value == $LastValue ) { return(FALSE); }
  2065. if ( $LabelingMethod == LABELING_ALL && $LabelSkip == 0 ) { return(TRUE); }
  2066. if ( $LabelingMethod == LABELING_ALL && ($ID+$LabelSkip) % ($LabelSkip+1) != 1 ) { return(FALSE); }
  2067. return(TRUE);
  2068. }
  2069. /* Compute the scale, check for the best visual factors */
  2070. function computeScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID=0)
  2071. {
  2072. /* Compute each factors */
  2073. $Results = "";
  2074. foreach ($Factors as $Key => $Factor)
  2075. $Results[$Factor] = $this->processScale($XMin,$XMax,$MaxDivs,array($Factor),$AxisID);
  2076. /* Remove scales that are creating to much decimals */
  2077. $GoodScaleFactors = "";
  2078. foreach ($Results as $Key => $Result)
  2079. {
  2080. $Decimals = preg_split("/\./",$Result["RowHeight"]);
  2081. if ( (!isset($Decimals[1])) || (strlen($Decimals[1]) < 6) ) { $GoodScaleFactors[] = $Key; }
  2082. }
  2083. /* Found no correct scale, shame,... returns the 1st one as default */
  2084. if ( $GoodScaleFactors == "" ) { return($Results[$Factors[0]]); }
  2085. /* Find the factor that cause the maximum number of Rows */
  2086. $MaxRows = 0; $BestFactor = 0;
  2087. foreach($GoodScaleFactors as $Key => $Factor)
  2088. { if ( $Results[$Factor]["Rows"] > $MaxRows ) { $MaxRows = $Results[$Factor]["Rows"]; $BestFactor = $Factor; } }
  2089. /* Return the best visual scale */
  2090. return($Results[$BestFactor]);
  2091. }
  2092. /* Compute the best matching scale based on size & factors */
  2093. function processScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID)
  2094. {
  2095. $ScaleHeight = abs(ceil($XMax)-floor($XMin));
  2096. if ( isset($this->DataSet->Data["Axis"][$AxisID]["Format"]) )
  2097. $Format = $this->DataSet->Data["Axis"][$AxisID]["Format"];
  2098. else
  2099. $Format = NULL;
  2100. if ( isset($this->DataSet->Data["Axis"][$AxisID]["Display"]) )
  2101. $Mode = $this->DataSet->Data["Axis"][$AxisID]["Display"];
  2102. else
  2103. $Mode = AXIS_FORMAT_DEFAULT;
  2104. $Scale = "";
  2105. if ( $XMin != $XMax )
  2106. {
  2107. $Found = FALSE; $Rescaled = FALSE; $Scaled10Factor = .0001; $Result = 0;
  2108. while(!$Found)
  2109. {
  2110. foreach($Factors as $Key => $Factor)
  2111. {
  2112. if ( !$Found )
  2113. {
  2114. if ( !($this->modulo($XMin,$Factor*$Scaled10Factor) == 0) || ($XMin != floor($XMin))) { $XMinRescaled = floor($XMin/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor; } else { $XMinRescaled = $XMin; }
  2115. if ( !($this->modulo($XMax,$Factor*$Scaled10Factor) == 0) || ($XMax != floor($XMax))) { $XMaxRescaled = floor($XMax/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor+($Factor*$Scaled10Factor); } else { $XMaxRescaled = $XMax; }
  2116. $ScaleHeightRescaled = abs($XMaxRescaled-$XMinRescaled);
  2117. if ( !$Found && floor($ScaleHeightRescaled/($Factor*$Scaled10Factor)) <= $MaxDivs ) { $Found = TRUE; $Rescaled = TRUE; $Result = $Factor * $Scaled10Factor; }
  2118. }
  2119. }
  2120. $Scaled10Factor = $Scaled10Factor * 10;
  2121. }
  2122. /* ReCall Min / Max / Height */
  2123. if ( $Rescaled ) { $XMin = $XMinRescaled; $XMax = $XMaxRescaled; $ScaleHeight = $ScaleHeightRescaled; }
  2124. /* Compute rows size */
  2125. $Rows = floor($ScaleHeight / $Result); if ( $Rows == 0 ) { $Rows = 1; }
  2126. $RowHeight = $ScaleHeight / $Rows;
  2127. /* Return the results */
  2128. $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin; $Scale["XMax"] = $XMax;
  2129. /* Compute the needed decimals for the metric view to avoid repetition of the same X Axis labels */
  2130. if ( $Mode == AXIS_FORMAT_METRIC && $Format == NULL )
  2131. {
  2132. $Done = FALSE; $GoodDecimals = 0;
  2133. for($Decimals=0;$Decimals<=10;$Decimals++)
  2134. {
  2135. if ( !$Done )
  2136. {
  2137. $LastLabel = "zob"; $ScaleOK = TRUE;
  2138. for($i=0;$i<=$Rows;$i++)
  2139. {
  2140. $Value = $XMin + $i*$RowHeight;
  2141. $Label = $this->scaleFormat($Value,AXIS_FORMAT_METRIC,$Decimals);
  2142. if ( $LastLabel == $Label ) { $ScaleOK = FALSE; }
  2143. $LastLabel = $Label;
  2144. }
  2145. if ( $ScaleOK ) { $Done = TRUE; $GoodDecimals = $Decimals; }
  2146. }
  2147. }
  2148. $Scale["Format"] = $GoodDecimals;
  2149. }
  2150. }
  2151. else
  2152. {
  2153. /* If all values are the same we keep a +1/-1 scale */
  2154. $Rows = 2; $XMin = $XMax-1; $XMax = $XMax+1; $RowHeight = 1;
  2155. /* Return the results */
  2156. $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin; $Scale["XMax"] = $XMax;
  2157. }
  2158. return($Scale);
  2159. }
  2160. function modulo($Value1,$Value2)
  2161. {
  2162. if (floor($Value2) == 0) { return(0); }
  2163. if (floor($Value2) != 0) { return($Value1 % $Value2); }
  2164. $MinValue = min($Value1,$Value2); $Factor = 10;
  2165. while ( floor($MinValue*$Factor) == 0 )
  2166. { $Factor = $Factor * 10; }
  2167. return(($Value1*$Factor) % ($Value2*$Factor));
  2168. }
  2169. /* Draw an X threshold */
  2170. function drawXThreshold($Value,$Format="")
  2171. {
  2172. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2173. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2174. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2175. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
  2176. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  2177. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
  2178. $Wide = isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
  2179. $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
  2180. $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
  2181. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : NULL;
  2182. $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
  2183. $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 5;
  2184. $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
  2185. $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
  2186. $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
  2187. $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
  2188. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2189. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2190. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 3;
  2191. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2192. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2193. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2194. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2195. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2196. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 30;
  2197. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2198. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2199. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2200. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2201. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2202. $ValueIsLabel = isset($Format["ValueIsLabel"]) ? $Format["ValueIsLabel"] : FALSE;
  2203. $Data = $this->DataSet->getData();
  2204. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2205. $XScale = $this->scaleGetXSettings();
  2206. if ( is_array($Value) ) { foreach ($Value as $Key => $ID) { $this->drawXThreshold($ID,$Format); } return(0); }
  2207. if ( $ValueIsLabel )
  2208. {
  2209. $Format["ValueIsLabel"] = FALSE;
  2210. foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $SerieValue)
  2211. { if ( $SerieValue == $Value ) { $this->drawXThreshold($Key,$Format); } }
  2212. return(0);
  2213. }
  2214. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2215. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2216. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
  2217. "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);
  2218. if ( $Caption == NULL )
  2219. {
  2220. if ( isset($Data["Abscissa"]) )
  2221. {
  2222. if ( isset($Data["Series"][$Data["Abscissa"]]["Data"][$Value]) )
  2223. $Caption = $Data["Series"][$Data["Abscissa"]]["Data"][$Value];
  2224. else
  2225. $Caption = $Value;
  2226. }
  2227. else
  2228. $Caption = $Value;
  2229. }
  2230. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2231. {
  2232. $XStep = (($this->GraphAreaX2 - $this->GraphAreaX1) - $XScale[0] *2 ) / $XScale[1];
  2233. $XPos = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value;
  2234. $YPos1 = $this->GraphAreaY1 + $Data["YMargin"];
  2235. $YPos2 = $this->GraphAreaY2 - $Data["YMargin"];
  2236. if ( $XPos >= $this->GraphAreaX1 + $AbscissaMargin && $XPos <= $this->GraphAreaX2 - $AbscissaMargin )
  2237. {
  2238. $this->drawLine($XPos,$YPos1,$XPos,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2239. if ( $Wide )
  2240. {
  2241. $this->drawLine($XPos-1,$YPos1,$XPos-1,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2242. $this->drawLine($XPos+1,$YPos1,$XPos+1,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2243. }
  2244. if ( $WriteCaption )
  2245. {
  2246. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2247. { $Y = $YPos1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
  2248. else
  2249. { $Y = $YPos2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
  2250. $this->drawText($XPos,$Y,$Caption,$CaptionSettings);
  2251. }
  2252. return(array("X"=>$XPos));
  2253. }
  2254. }
  2255. elseif( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2256. {
  2257. $XStep = (($this->GraphAreaY2 - $this->GraphAreaY1) - $XScale[0] *2 ) / $XScale[1];
  2258. $XPos = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value;
  2259. $YPos1 = $this->GraphAreaX1 + $Data["YMargin"];
  2260. $YPos2 = $this->GraphAreaX2 - $Data["YMargin"];
  2261. if ( $XPos >= $this->GraphAreaY1 + $AbscissaMargin && $XPos <= $this->GraphAreaY2 - $AbscissaMargin )
  2262. {
  2263. $this->drawLine($YPos1,$XPos,$YPos2,$XPos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2264. if ( $Wide )
  2265. {
  2266. $this->drawLine($YPos1,$XPos-1,$YPos2,$XPos-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2267. $this->drawLine($YPos1,$XPos+1,$YPos2,$XPos+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2268. }
  2269. if ( $WriteCaption )
  2270. {
  2271. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2272. { $Y = $YPos1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
  2273. else
  2274. { $Y = $YPos2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
  2275. $this->drawText($Y,$XPos,$Caption,$CaptionSettings);
  2276. }
  2277. return(array("X"=>$XPos));
  2278. }
  2279. }
  2280. }
  2281. /* Draw an X threshold area */
  2282. function drawXThresholdArea($Value1,$Value2,$Format="")
  2283. {
  2284. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2285. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2286. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2287. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
  2288. $Border = isset($Format["Border"]) ? $Format["Border"] : TRUE;
  2289. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  2290. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  2291. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  2292. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
  2293. $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
  2294. $AreaName = isset($Format["AreaName"]) ? $Format["AreaName"] : NULL;
  2295. $NameAngle = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
  2296. $NameR = isset($Format["NameR"]) ? $Format["NameR"] : 255;
  2297. $NameG = isset($Format["NameG"]) ? $Format["NameG"] : 255;
  2298. $NameB = isset($Format["NameB"]) ? $Format["NameB"] : 255;
  2299. $NameAlpha = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
  2300. $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : TRUE;
  2301. $RestoreShadow = $this->Shadow;
  2302. if ( $DisableShadowOnArea && $this->Shadow ) { $this->Shadow = FALSE; }
  2303. if ($BorderAlpha >100) { $BorderAlpha = 100;}
  2304. $Data = $this->DataSet->getData();
  2305. $XScale = $this->scaleGetXSettings();
  2306. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2307. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2308. {
  2309. $XStep = (($this->GraphAreaX2 - $this->GraphAreaX1) - $XScale[0] *2 ) / $XScale[1];
  2310. $XPos1 = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value1;
  2311. $XPos2 = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value2;
  2312. $YPos1 = $this->GraphAreaY1 + $Data["YMargin"];
  2313. $YPos2 = $this->GraphAreaY2 - $Data["YMargin"];
  2314. if ( $XPos1 < $this->GraphAreaX1 + $XScale[0] ) { $XPos1 = $this->GraphAreaX1 + $XScale[0]; }
  2315. if ( $XPos1 > $this->GraphAreaX2 - $XScale[0] ) { $XPos1 = $this->GraphAreaX2 - $XScale[0]; }
  2316. if ( $XPos2 < $this->GraphAreaX1 + $XScale[0] ) { $XPos2 = $this->GraphAreaX1 + $XScale[0]; }
  2317. if ( $XPos2 > $this->GraphAreaX2 - $XScale[0] ) { $XPos2 = $this->GraphAreaX2 - $XScale[0]; }
  2318. $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2319. if ( $Border )
  2320. {
  2321. $this->drawLine($XPos1,$YPos1,$XPos1,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2322. $this->drawLine($XPos2,$YPos1,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2323. }
  2324. if ( $AreaName != NULL )
  2325. {
  2326. $XPos = ($XPos2-$XPos1)/2 + $XPos1;
  2327. $YPos = ($YPos2-$YPos1)/2 + $YPos1;
  2328. if ( $NameAngle == ZONE_NAME_ANGLE_AUTO )
  2329. {
  2330. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$AreaName);
  2331. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
  2332. if ( abs($XPos2 - $XPos1) > $TxtWidth ) { $NameAngle = 0; } else { $NameAngle = 90; }
  2333. }
  2334. $this->Shadow = $RestoreShadow;
  2335. $this->drawText($XPos,$YPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>$NameAngle,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2336. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2337. }
  2338. $this->Shadow = $RestoreShadow;
  2339. return(array("X1"=>$XPos1,"X2"=>$XPos2));
  2340. }
  2341. elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2342. {
  2343. $XStep = (($this->GraphAreaY2 - $this->GraphAreaY1) - $XScale[0] *2 ) / $XScale[1];
  2344. $XPos1 = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value1;
  2345. $XPos2 = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value2;
  2346. $YPos1 = $this->GraphAreaX1 + $Data["YMargin"];
  2347. $YPos2 = $this->GraphAreaX2 - $Data["YMargin"];
  2348. if ( $XPos1 < $this->GraphAreaY1 + $XScale[0] ) { $XPos1 = $this->GraphAreaY1 + $XScale[0]; }
  2349. if ( $XPos1 > $this->GraphAreaY2 - $XScale[0] ) { $XPos1 = $this->GraphAreaY2 - $XScale[0]; }
  2350. if ( $XPos2 < $this->GraphAreaY1 + $XScale[0] ) { $XPos2 = $this->GraphAreaY1 + $XScale[0]; }
  2351. if ( $XPos2 > $this->GraphAreaY2 - $XScale[0] ) { $XPos2 = $this->GraphAreaY2 - $XScale[0]; }
  2352. $this->drawFilledRectangle($YPos1,$XPos1,$YPos2,$XPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2353. if ( $Border )
  2354. {
  2355. $this->drawLine($YPos1,$XPos1,$YPos2,$XPos1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2356. $this->drawLine($YPos1,$XPos2,$YPos2,$XPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2357. }
  2358. if ( $AreaName != NULL )
  2359. {
  2360. $XPos = ($XPos2-$XPos1)/2 + $XPos1;
  2361. $YPos = ($YPos2-$YPos1)/2 + $YPos1;
  2362. $this->Shadow = $RestoreShadow;
  2363. $this->drawText($YPos,$XPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2364. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2365. }
  2366. $this->Shadow = $RestoreShadow;
  2367. return(array("X1"=>$XPos1,"X2"=>$XPos2));
  2368. }
  2369. }
  2370. /* Draw an Y threshold with the computed scale */
  2371. function drawThreshold($Value,$Format="")
  2372. {
  2373. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  2374. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2375. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2376. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2377. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
  2378. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  2379. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
  2380. $Wide = isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
  2381. $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
  2382. $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
  2383. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : NULL;
  2384. $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
  2385. $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
  2386. $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
  2387. $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
  2388. $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
  2389. $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
  2390. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2391. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2392. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
  2393. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2394. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2395. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2396. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2397. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2398. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
  2399. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2400. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2401. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2402. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2403. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2404. $NoMargin = isset($Format["NoMargin"]) ? $Format["NoMargin"] : FALSE;
  2405. if ( is_array($Value) ) { foreach ($Value as $Key => $ID) { $this->drawThreshold($ID,$Format); } return(0); }
  2406. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2407. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2408. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
  2409. "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);
  2410. $Data = $this->DataSet->getData();
  2411. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2412. if ( $NoMargin ) { $AbscissaMargin = 0; }
  2413. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2414. if ( $Caption == NULL ) { $Caption = $Value; }
  2415. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2416. {
  2417. $YPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
  2418. if ( $YPos >= $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"] && $YPos <= $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"] )
  2419. {
  2420. $X1 = $this->GraphAreaX1 + $AbscissaMargin;
  2421. $X2 = $this->GraphAreaX2 - $AbscissaMargin;
  2422. $this->drawLine($X1,$YPos,$X2,$YPos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2423. if ( $Wide )
  2424. {
  2425. $this->drawLine($X1,$YPos-1,$X2,$YPos-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2426. $this->drawLine($X1,$YPos+1,$X2,$YPos+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2427. }
  2428. if ( $WriteCaption )
  2429. {
  2430. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2431. { $X = $X1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
  2432. else
  2433. { $X = $X2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
  2434. $this->drawText($X,$YPos,$Caption,$CaptionSettings);
  2435. }
  2436. }
  2437. return(array("Y"=>$YPos));
  2438. }
  2439. if ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2440. {
  2441. $XPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
  2442. if ( $XPos >= $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"] && $XPos <= $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"] )
  2443. {
  2444. $Y1 = $this->GraphAreaY1 + $AbscissaMargin;
  2445. $Y2 = $this->GraphAreaY2 - $AbscissaMargin;
  2446. $this->drawLine($XPos,$Y1,$XPos,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2447. if ( $Wide )
  2448. {
  2449. $this->drawLine($XPos-1,$Y1,$XPos-1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2450. $this->drawLine($XPos+1,$Y1,$XPos+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2451. }
  2452. if ( $WriteCaption )
  2453. {
  2454. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2455. { $Y = $Y1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
  2456. else
  2457. { $Y = $Y2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
  2458. $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
  2459. $this->drawText($XPos,$Y,$Caption,$CaptionSettings);
  2460. }
  2461. }
  2462. return(array("Y"=>$XPos));
  2463. }
  2464. }
  2465. /* Draw a threshold with the computed scale */
  2466. function drawThresholdArea($Value1,$Value2,$Format="")
  2467. {
  2468. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  2469. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2470. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2471. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2472. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
  2473. $Border = isset($Format["Border"]) ? $Format["Border"] : TRUE;
  2474. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  2475. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  2476. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  2477. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
  2478. $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
  2479. $AreaName = isset($Format["AreaName"]) ? $Format["AreaName"] : NULL;
  2480. $NameAngle = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
  2481. $NameR = isset($Format["NameR"]) ? $Format["NameR"] : 255;
  2482. $NameG = isset($Format["NameG"]) ? $Format["NameG"] : 255;
  2483. $NameB = isset($Format["NameB"]) ? $Format["NameB"] : 255;
  2484. $NameAlpha = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
  2485. $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : TRUE;
  2486. $NoMargin = isset($Format["NoMargin"]) ? $Format["NoMargin"] : FALSE;
  2487. if ($Value1 > $Value2) { list($Value1, $Value2) = array($Value2, $Value1); }
  2488. $RestoreShadow = $this->Shadow;
  2489. if ( $DisableShadowOnArea && $this->Shadow ) { $this->Shadow = FALSE; }
  2490. if ($BorderAlpha >100) { $BorderAlpha = 100;}
  2491. $Data = $this->DataSet->getData();
  2492. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2493. if ( $NoMargin ) { $AbscissaMargin = 0; }
  2494. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2495. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2496. {
  2497. $XPos1 = $this->GraphAreaX1 + $AbscissaMargin;
  2498. $XPos2 = $this->GraphAreaX2 - $AbscissaMargin;
  2499. $YPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
  2500. $YPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));
  2501. if ( $YPos1 < $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"] ) { $YPos1 = $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"]; }
  2502. if ( $YPos1 > $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"] ) { $YPos1 = $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"]; }
  2503. if ( $YPos2 < $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"] ) { $YPos2 = $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"]; }
  2504. if ( $YPos2 > $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"] ) { $YPos2 = $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"]; }
  2505. $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2506. if ( $Border )
  2507. {
  2508. $this->drawLine($XPos1,$YPos1,$XPos2,$YPos1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2509. $this->drawLine($XPos1,$YPos2,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2510. }
  2511. if ( $AreaName != NULL )
  2512. {
  2513. $XPos = ($XPos2-$XPos1)/2 + $XPos1;
  2514. $YPos = ($YPos2-$YPos1)/2 + $YPos1;
  2515. $this->Shadow = $RestoreShadow;
  2516. $this->drawText($XPos,$YPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2517. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2518. }
  2519. $this->Shadow = $RestoreShadow;
  2520. return(array("Y1"=>$YPos1,"Y2"=>$YPos2));
  2521. }
  2522. elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2523. {
  2524. $YPos1 = $this->GraphAreaY1 + $AbscissaMargin;
  2525. $YPos2 = $this->GraphAreaY2 - $AbscissaMargin;
  2526. $XPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
  2527. $XPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));
  2528. if ( $XPos1 < $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"] ) { $XPos1 = $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"]; }
  2529. if ( $XPos1 > $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"] ) { $XPos1 = $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"]; }
  2530. if ( $XPos2 < $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"] ) { $XPos2 = $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"]; }
  2531. if ( $XPos2 > $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"] ) { $XPos2 = $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"]; }
  2532. $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2533. if ( $Border )
  2534. {
  2535. $this->drawLine($XPos1,$YPos1,$XPos1,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2536. $this->drawLine($XPos2,$YPos1,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2537. }
  2538. if ( $AreaName != NULL )
  2539. {
  2540. $XPos = ($YPos2-$YPos1)/2 + $YPos1;
  2541. $YPos = ($XPos2-$XPos1)/2 + $XPos1;
  2542. if ( $NameAngle == ZONE_NAME_ANGLE_AUTO )
  2543. {
  2544. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$AreaName);
  2545. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
  2546. if ( abs($XPos2 - $XPos1) > $TxtWidth ) { $NameAngle = 0; } else { $NameAngle = 90; }
  2547. }
  2548. $this->Shadow = $RestoreShadow;
  2549. $this->drawText($YPos,$XPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>$NameAngle,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2550. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2551. }
  2552. $this->Shadow = $RestoreShadow;
  2553. return(array("Y1"=>$XPos1,"Y2"=>$XPos2));
  2554. }
  2555. }
  2556. function scaleGetXSettings()
  2557. {
  2558. $Data = $this->DataSet->getData();
  2559. foreach($Data["Axis"] as $AxisID => $Settings)
  2560. {
  2561. if ( $Settings["Identity"] == AXIS_X )
  2562. {
  2563. $Rows = $Settings["Rows"];
  2564. return(array($Settings["Margin"],$Rows));
  2565. }
  2566. }
  2567. }
  2568. function scaleComputeY($Values,$Option="",$ReturnOnly0Height=FALSE)
  2569. {
  2570. $AxisID = isset($Option["AxisID"]) ? $Option["AxisID"] : 0;
  2571. $SerieName = isset($Option["SerieName"]) ? $Option["SerieName"] : NULL;
  2572. $Data = $this->DataSet->getData();
  2573. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2574. if ( $SerieName != NULL ) { $AxisID = $Data["Series"][$SerieName]["Axis"]; }
  2575. if ( !is_array($Values) ) { $tmp = $Values; $Values = ""; $Values[0] = $tmp; }
  2576. $Result = "";
  2577. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2578. {
  2579. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Data["Axis"][$AxisID]["Margin"]*2;
  2580. $ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  2581. $Step = $Height / $ScaleHeight;
  2582. if ( $ReturnOnly0Height )
  2583. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
  2584. else
  2585. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
  2586. }
  2587. else
  2588. {
  2589. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Data["Axis"][$AxisID]["Margin"]*2;
  2590. $ScaleWidth = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  2591. $Step = $Width / $ScaleWidth;
  2592. if ( $ReturnOnly0Height )
  2593. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
  2594. else
  2595. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
  2596. }
  2597. if ( count($Result) == 1 )
  2598. return($Result[0]);
  2599. else
  2600. return($Result);
  2601. }
  2602. /* Format the axis values */
  2603. function scaleFormat($Value,$Mode=NULL,$Format=NULL,$Unit=NULL)
  2604. {
  2605. if ( $Value == VOID ) { return(""); }
  2606. if ( $Mode == AXIS_FORMAT_TRAFFIC )
  2607. {
  2608. if ( $Value == 0 ) { return("0B"); }
  2609. $Units = array("B","KB","MB","GB","TB","PB");
  2610. $Sign = ""; if ( $Value < 0 ) { $Value = abs($Value); $Sign = "-"; }
  2611. $Value = number_format($Value/pow(1024,($Scale=floor(log($Value,1024)))),2,",",".");
  2612. return($Sign.$Value." ".$Units[$Scale]);
  2613. }
  2614. if ( $Mode == AXIS_FORMAT_CUSTOM )
  2615. { if ( function_exists($Format) ) { return(call_user_func($Format,$Value)); } }
  2616. if ( $Mode == AXIS_FORMAT_DATE )
  2617. { if ( $Format == NULL ) { $Pattern = "d/m/Y"; } else { $Pattern = $Format; } return(gmdate($Pattern,$Value)); }
  2618. if ( $Mode == AXIS_FORMAT_TIME )
  2619. { if ( $Format == NULL ) { $Pattern = "H:i:s"; } else { $Pattern = $Format; } return(gmdate($Pattern,$Value)); }
  2620. if ( $Mode == AXIS_FORMAT_CURRENCY )
  2621. { return($Format.number_format($Value,2)); }
  2622. if ( $Mode == AXIS_FORMAT_METRIC )
  2623. {
  2624. if (abs($Value) > 1000000000)
  2625. return(round($Value/1000000000,$Format)."g".$Unit);
  2626. if (abs($Value) > 1000000)
  2627. return(round($Value/1000000,$Format)."m".$Unit);
  2628. elseif (abs($Value) >= 1000)
  2629. return(round($Value/1000,$Format)."k".$Unit);
  2630. }
  2631. return($Value.$Unit);
  2632. }
  2633. /* Write Max value on a chart */
  2634. function writeBounds($Type=BOUND_BOTH,$Format=NULL)
  2635. {
  2636. $MaxLabelTxt = isset($Format["MaxLabelTxt"]) ? $Format["MaxLabelTxt"] : "max=";
  2637. $MinLabelTxt = isset($Format["MinLabelTxt"]) ? $Format["MinLabelTxt"] : "min=";
  2638. $Decimals = isset($Format["Decimals"]) ? $Format["Decimals"] : 1;
  2639. $ExcludedSeries = isset($Format["ExcludedSeries"]) ? $Format["ExcludedSeries"] : "";
  2640. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
  2641. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2642. $MaxDisplayR = isset($Format["MaxDisplayR"]) ? $Format["MaxDisplayR"] : 0;
  2643. $MaxDisplayG = isset($Format["MaxDisplayG"]) ? $Format["MaxDisplayG"] : 0;
  2644. $MaxDisplayB = isset($Format["MaxDisplayB"]) ? $Format["MaxDisplayB"] : 0;
  2645. $MinDisplayR = isset($Format["MinDisplayR"]) ? $Format["MinDisplayR"] : 255;
  2646. $MinDisplayG = isset($Format["MinDisplayG"]) ? $Format["MinDisplayG"] : 255;
  2647. $MinDisplayB = isset($Format["MinDisplayB"]) ? $Format["MinDisplayB"] : 255;
  2648. $MinLabelPos = isset($Format["MinLabelPos"]) ? $Format["MinLabelPos"] : BOUND_LABEL_POS_AUTO;
  2649. $MaxLabelPos = isset($Format["MaxLabelPos"]) ? $Format["MaxLabelPos"] : BOUND_LABEL_POS_AUTO;
  2650. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2651. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2652. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
  2653. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2654. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2655. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2656. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2657. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2658. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
  2659. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2660. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2661. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2662. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2663. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2664. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2665. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2666. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha);
  2667. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2668. $Data = $this->DataSet->getData();
  2669. foreach($Data["Series"] as $SerieName => $Serie)
  2670. {
  2671. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && !isset($ExcludedSeries[$SerieName]))
  2672. {
  2673. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2674. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2675. $MinValue = $this->DataSet->getMin($SerieName);
  2676. $MaxValue = $this->DataSet->getMax($SerieName);
  2677. $MinPos = VOID; $MaxPos = VOID;
  2678. foreach($Serie["Data"] as $Key => $Value)
  2679. {
  2680. if ( $Value == $MinValue && $MinPos == VOID ) { $MinPos = $Key; }
  2681. if ( $Value == $MaxValue ) { $MaxPos = $Key; }
  2682. }
  2683. $AxisID = $Serie["Axis"];
  2684. $Mode = $Data["Axis"][$AxisID]["Display"];
  2685. $Format = $Data["Axis"][$AxisID]["Format"];
  2686. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2687. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2688. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2689. {
  2690. $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs;
  2691. $X = $this->GraphAreaX1 + $XMargin;
  2692. $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
  2693. if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
  2694. {
  2695. if ( $MaxLabelPos == BOUND_LABEL_POS_TOP || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
  2696. if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }
  2697. $XPos = $X + $MaxPos*$XStep + $SerieOffset;
  2698. $Label = $MaxLabelTxt.$this->scaleFormat(round($MaxValue,$Decimals),$Mode,$Format,$Unit);
  2699. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
  2700. $XOffset = 0; $YOffset = 0;
  2701. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
  2702. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
  2703. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
  2704. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }
  2705. $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
  2706. $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;
  2707. $this->drawText($XPos+$XOffset,$YPos+$YOffset,$Label,$CaptionSettings);
  2708. }
  2709. if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
  2710. {
  2711. if ( $MinLabelPos == BOUND_LABEL_POS_TOP || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
  2712. if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }
  2713. $XPos = $X + $MinPos*$XStep + $SerieOffset;
  2714. $Label = $MinLabelTxt.$this->scaleFormat(round($MinValue,$Decimals),$Mode,$Format,$Unit);
  2715. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
  2716. $XOffset = 0; $YOffset = 0;
  2717. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
  2718. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
  2719. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
  2720. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }
  2721. $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
  2722. $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;
  2723. $this->drawText($XPos+$XOffset,$YPos-$DisplayOffset+$YOffset,$Label,$CaptionSettings);
  2724. }
  2725. }
  2726. else
  2727. {
  2728. $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs;
  2729. $X = $this->GraphAreaY1 + $XMargin;
  2730. $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
  2731. if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
  2732. {
  2733. if ( $MaxLabelPos == BOUND_LABEL_POS_TOP || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
  2734. if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }
  2735. $XPos = $X + $MaxPos*$XStep + $SerieOffset;
  2736. $Label = $MaxLabelTxt.$this->scaleFormat($MaxValue,$Mode,$Format,$Unit);
  2737. $TxtPos = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
  2738. $XOffset = 0; $YOffset = 0;
  2739. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
  2740. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
  2741. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
  2742. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}
  2743. $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
  2744. $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;
  2745. $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
  2746. }
  2747. if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
  2748. {
  2749. if ( $MinLabelPos == BOUND_LABEL_POS_TOP || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
  2750. if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }
  2751. $XPos = $X + $MinPos*$XStep + $SerieOffset;
  2752. $Label = $MinLabelTxt.$this->scaleFormat($MinValue,$Mode,$Format,$Unit);
  2753. $TxtPos = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
  2754. $XOffset = 0; $YOffset = 0;
  2755. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
  2756. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
  2757. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
  2758. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}
  2759. $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
  2760. $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;
  2761. $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
  2762. }
  2763. }
  2764. }
  2765. }
  2766. }
  2767. /* Draw a plot chart */
  2768. function drawPlotChart($Format=NULL)
  2769. {
  2770. $PlotSize = isset($Format["PlotSize"]) ? $Format["PlotSize"] : NULL;
  2771. $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : FALSE;
  2772. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 50;
  2773. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 50;
  2774. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 50;
  2775. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
  2776. $BorderSize = isset($Format["BorderSize"]) ? $Format["BorderSize"] : 2;
  2777. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  2778. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2779. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
  2780. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2781. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2782. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2783. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2784. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  2785. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  2786. $Data = $this->DataSet->getData();
  2787. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2788. foreach($Data["Series"] as $SerieName => $Serie)
  2789. {
  2790. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2791. {
  2792. if ( isset($Serie["Weight"]) ) { $SerieWeight = $Serie["Weight"] + 2; } else { $SerieWeight = 2; }
  2793. if ( $PlotSize != NULL ) { $SerieWeight = $PlotSize; }
  2794. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2795. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  2796. if ( isset($Serie["Picture"]) )
  2797. { $Picture = $Serie["Picture"]; list($PicWidth,$PicHeight,$PicType) = $this->getPicInfo($Picture); }
  2798. else { $Picture = NULL; $PicOffset = 0; }
  2799. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2800. $AxisID = $Serie["Axis"];
  2801. $Shape = $Serie["Shape"];
  2802. $Mode = $Data["Axis"][$AxisID]["Display"];
  2803. $Format = $Data["Axis"][$AxisID]["Format"];
  2804. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2805. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  2806. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2807. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2808. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2809. {
  2810. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2811. if ( $Picture != NULL ) { $PicOffset = $PicHeight / 2; $SerieWeight = 0; }
  2812. $X = $this->GraphAreaX1 + $XMargin;
  2813. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2814. foreach($PosArray as $Key => $Y)
  2815. {
  2816. if ( $DisplayValues )
  2817. $this->drawText($X,$Y-$DisplayOffset-$SerieWeight-$BorderSize-$PicOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2818. if ( $Y != VOID )
  2819. {
  2820. if ( $RecordImageMap ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$SerieWeight,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2821. if ( $Picture != NULL )
  2822. { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
  2823. else
  2824. { $this->drawShape($X,$Y,$Shape,$SerieWeight,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha); }
  2825. }
  2826. $X = $X + $XStep;
  2827. }
  2828. }
  2829. else
  2830. {
  2831. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2832. if ( $Picture != NULL ) { $PicOffset = $PicWidth / 2; $SerieWeight = 0; }
  2833. $Y = $this->GraphAreaY1 + $XMargin;
  2834. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2835. foreach($PosArray as $Key => $X)
  2836. {
  2837. if ( $DisplayValues )
  2838. $this->drawText($X+$DisplayOffset+$SerieWeight+$BorderSize+$PicOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2839. if ( $X != VOID )
  2840. {
  2841. if ( $RecordImageMap ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$SerieWeight,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2842. if ( $Picture != NULL )
  2843. { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
  2844. else
  2845. { $this->drawShape($X,$Y,$Shape,$SerieWeight,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha); }
  2846. }
  2847. $Y = $Y + $YStep;
  2848. }
  2849. }
  2850. }
  2851. }
  2852. }
  2853. /* Draw a spline chart */
  2854. function drawSplineChart($Format=NULL)
  2855. {
  2856. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
  2857. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  2858. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL; // 234
  2859. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL; // 55
  2860. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL; // 26
  2861. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2862. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2863. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2864. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2865. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2866. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2867. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  2868. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  2869. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  2870. $Data = $this->DataSet->getData();
  2871. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2872. foreach($Data["Series"] as $SerieName => $Serie)
  2873. {
  2874. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2875. {
  2876. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  2877. if ( $BreakR == NULL )
  2878. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks);
  2879. else
  2880. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  2881. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2882. $AxisID = $Serie["Axis"];
  2883. $Mode = $Data["Axis"][$AxisID]["Display"];
  2884. $Format = $Data["Axis"][$AxisID]["Format"];
  2885. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2886. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  2887. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2888. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2889. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2890. {
  2891. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2892. $X = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
  2893. $Force = $XStep / 5;
  2894. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2895. $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
  2896. foreach($PosArray as $Key => $Y)
  2897. {
  2898. if ( $DisplayValues )
  2899. $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2900. if ( $RecordImageMap && $Y != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2901. if ( $Y == VOID && $LastY != NULL )
  2902. { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }
  2903. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  2904. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }
  2905. if ( $Y != VOID )
  2906. $WayPoints[] = array($X,$Y);
  2907. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  2908. if ( $Y == VOID ) { $Y = NULL; }
  2909. $LastX = $X; $LastY = $Y;
  2910. $X = $X + $XStep;
  2911. }
  2912. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2913. }
  2914. else
  2915. {
  2916. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2917. $Y = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
  2918. $Force = $YStep / 5;
  2919. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2920. $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
  2921. foreach($PosArray as $Key => $X)
  2922. {
  2923. if ( $DisplayValues )
  2924. $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));
  2925. if ( $RecordImageMap && $X != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2926. if ( $X == VOID && $LastX != NULL )
  2927. { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }
  2928. if ( $X != VOID && $LastX == NULL && $LastGoodX != NULL && !$BreakVoid )
  2929. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }
  2930. if ( $X != VOID )
  2931. $WayPoints[] = array($X,$Y);
  2932. if ( $X != VOID ) { $LastGoodX = $X; $LastGoodY = $Y; }
  2933. if ( $X == VOID ) { $X = NULL; }
  2934. $LastX = $X; $LastY = $Y;
  2935. $Y = $Y + $YStep;
  2936. }
  2937. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2938. }
  2939. }
  2940. }
  2941. }
  2942. /* Draw a filled spline chart */
  2943. function drawFilledSplineChart($Format=NULL)
  2944. {
  2945. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2946. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2947. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2948. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2949. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2950. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2951. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  2952. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  2953. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  2954. $Data = $this->DataSet->getData();
  2955. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2956. foreach($Data["Series"] as $SerieName => $Serie)
  2957. {
  2958. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2959. {
  2960. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2961. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2962. $AxisID = $Serie["Axis"];
  2963. $Mode = $Data["Axis"][$AxisID]["Display"];
  2964. $Format = $Data["Axis"][$AxisID]["Format"];
  2965. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2966. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2967. if ( $AroundZero ) { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }
  2968. if ( $Threshold != NULL )
  2969. {
  2970. foreach($Threshold as $Key => $Params)
  2971. {
  2972. $Threshold[$Key]["MinX"] = $this->scaleComputeY($Params["Min"],array("AxisID"=>$Serie["Axis"]));
  2973. $Threshold[$Key]["MaxX"] = $this->scaleComputeY($Params["Max"],array("AxisID"=>$Serie["Axis"]));
  2974. }
  2975. }
  2976. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2977. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2978. {
  2979. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2980. $X = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
  2981. $Force = $XStep / 5;
  2982. if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }
  2983. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  2984. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  2985. $LastX = ""; $LastY = "";
  2986. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2987. foreach($PosArray as $Key => $Y)
  2988. {
  2989. if ( $DisplayValues )
  2990. $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2991. if ( $Y == VOID )
  2992. {
  2993. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  2994. if ( $Area != "" )
  2995. {
  2996. foreach ($Area as $key => $Points)
  2997. {
  2998. $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
  2999. foreach($Points as $subKey => $Point)
  3000. {
  3001. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3002. $Corners[] = $Point["Y"]+1;
  3003. }
  3004. $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;
  3005. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3006. }
  3007. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3008. }
  3009. $WayPoints = "";
  3010. }
  3011. else
  3012. $WayPoints[] = array($X,$Y-.5); /* -.5 for AA visual fix */
  3013. $X = $X + $XStep;
  3014. }
  3015. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3016. if ( $Area != "" )
  3017. {
  3018. foreach ($Area as $key => $Points)
  3019. {
  3020. $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
  3021. foreach($Points as $subKey => $Point)
  3022. {
  3023. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3024. $Corners[] = $Point["Y"]+1;
  3025. }
  3026. $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;
  3027. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3028. }
  3029. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3030. }
  3031. }
  3032. else
  3033. {
  3034. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3035. $Y = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
  3036. $Force = $YStep / 5;
  3037. if ( !$AroundZero ) { $YZero = $this->GraphAreaX1+1; }
  3038. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3039. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3040. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3041. foreach($PosArray as $Key => $X)
  3042. {
  3043. if ( $DisplayValues )
  3044. $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));
  3045. if ( $X == VOID )
  3046. {
  3047. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3048. if ( $Area != "" )
  3049. {
  3050. foreach ($Area as $key => $Points)
  3051. {
  3052. $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
  3053. foreach($Points as $subKey => $Point)
  3054. {
  3055. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3056. $Corners[] = $Point["Y"];
  3057. }
  3058. $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;
  3059. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3060. }
  3061. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3062. }
  3063. $WayPoints = "";
  3064. }
  3065. else
  3066. $WayPoints[] = array($X,$Y);
  3067. $Y = $Y + $YStep;
  3068. }
  3069. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3070. if ( $Area != "" )
  3071. {
  3072. foreach ($Area as $key => $Points)
  3073. {
  3074. $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
  3075. foreach($Points as $subKey => $Point)
  3076. {
  3077. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3078. $Corners[] = $Point["Y"];
  3079. }
  3080. $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;
  3081. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3082. }
  3083. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3084. }
  3085. }
  3086. }
  3087. }
  3088. }
  3089. /* Draw a line chart */
  3090. function drawLineChart($Format=NULL)
  3091. {
  3092. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
  3093. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  3094. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
  3095. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
  3096. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
  3097. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3098. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3099. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3100. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3101. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3102. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3103. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3104. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  3105. $ForceColor = isset($Format["ForceColor"]) ? $Format["ForceColor"] : FALSE;
  3106. $ForceR = isset($Format["ForceR"]) ? $Format["ForceR"] : 0;
  3107. $ForceG = isset($Format["ForceG"]) ? $Format["ForceG"] : 0;
  3108. $ForceB = isset($Format["ForceB"]) ? $Format["ForceB"] : 0;
  3109. $ForceAlpha = isset($Format["ForceAlpha"]) ? $Format["ForceAlpha"] : 100;
  3110. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3111. $Data = $this->DataSet->getData();
  3112. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3113. foreach($Data["Series"] as $SerieName => $Serie)
  3114. {
  3115. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3116. {
  3117. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3118. if ( $ForceColor )
  3119. { $R = $ForceR; $G = $ForceG; $B = $ForceB; $Alpha = $ForceAlpha; }
  3120. if ( $BreakR == NULL )
  3121. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3122. else
  3123. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3124. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3125. $AxisID = $Serie["Axis"];
  3126. $Mode = $Data["Axis"][$AxisID]["Display"];
  3127. $Format = $Data["Axis"][$AxisID]["Format"];
  3128. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3129. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  3130. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3131. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3132. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3133. {
  3134. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3135. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3136. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3137. $LastGoodY = NULL; $LastGoodX = NULL;
  3138. foreach($PosArray as $Key => $Y)
  3139. {
  3140. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3141. {
  3142. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3143. $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3144. }
  3145. if ( $RecordImageMap && $Y != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3146. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  3147. $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  3148. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  3149. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }
  3150. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3151. if ( $Y == VOID ) { $Y = NULL; }
  3152. $LastX = $X; $LastY = $Y;
  3153. $X = $X + $XStep;
  3154. }
  3155. }
  3156. else
  3157. {
  3158. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3159. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3160. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3161. $LastGoodY = NULL; $LastGoodX = NULL;
  3162. foreach($PosArray as $Key => $X)
  3163. {
  3164. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3165. { $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)); }
  3166. if ( $RecordImageMap && $X != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3167. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3168. $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  3169. if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
  3170. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }
  3171. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3172. if ( $X == VOID ) { $X = NULL; }
  3173. $LastX = $X; $LastY = $Y;
  3174. $Y = $Y + $YStep;
  3175. }
  3176. }
  3177. }
  3178. }
  3179. }
  3180. /* Draw a line chart */
  3181. function drawZoneChart($SerieA,$SerieB,$Format=NULL)
  3182. {
  3183. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  3184. $LineR = isset($Format["LineR"]) ? $Format["LineR"] : 150;
  3185. $LineG = isset($Format["LineG"]) ? $Format["LineG"] : 150;
  3186. $LineB = isset($Format["LineB"]) ? $Format["LineB"] : 150;
  3187. $LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 50;
  3188. $LineTicks = isset($Format["LineTicks"]) ? $Format["LineTicks"] : 1;
  3189. $AreaR = isset($Format["AreaR"]) ? $Format["AreaR"] : 150;
  3190. $AreaG = isset($Format["AreaG"]) ? $Format["AreaG"] : 150;
  3191. $AreaB = isset($Format["AreaB"]) ? $Format["AreaB"] : 150;
  3192. $AreaAlpha = isset($Format["AreaAlpha"]) ? $Format["AreaAlpha"] : 5;
  3193. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3194. $Data = $this->DataSet->getData();
  3195. if ( !isset($Data["Series"][$SerieA]["Data"]) || !isset($Data["Series"][$SerieB]["Data"]) ) { return(0); }
  3196. $SerieAData = $Data["Series"][$SerieA]["Data"];
  3197. $SerieBData = $Data["Series"][$SerieB]["Data"];
  3198. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3199. $Mode = $Data["Axis"][$AxisID]["Display"];
  3200. $Format = $Data["Axis"][$AxisID]["Format"];
  3201. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3202. $PosArrayA = $this->scaleComputeY($SerieAData,array("AxisID"=>$AxisID));
  3203. $PosArrayB = $this->scaleComputeY($SerieBData,array("AxisID"=>$AxisID));
  3204. if ( count($PosArrayA) != count($PosArrayB) ) { return(0); }
  3205. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3206. {
  3207. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3208. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3209. $LastX = NULL; $LastY1 = NULL; $LastY2 = NULL;
  3210. $BoundsA = ""; $BoundsB = "";
  3211. foreach($PosArrayA as $Key => $Y1)
  3212. {
  3213. $Y2 = $PosArrayB[$Key];
  3214. $BoundsA[] = $X; $BoundsA[] = $Y1;
  3215. $BoundsB[] = $X; $BoundsB[] = $Y2;
  3216. $LastX = $X;
  3217. $LastY1 = $Y1; $LastY2 = $Y2;
  3218. $X = $X + $XStep;
  3219. }
  3220. $Bounds = array_merge($BoundsA,$this->reversePlots($BoundsB));
  3221. $this->drawPolygonChart($Bounds,array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"Alpha"=>$AreaAlpha));
  3222. for($i=0;$i<=count($BoundsA)-4;$i=$i+2)
  3223. {
  3224. $this->drawLine($BoundsA[$i],$BoundsA[$i+1],$BoundsA[$i+2],$BoundsA[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3225. $this->drawLine($BoundsB[$i],$BoundsB[$i+1],$BoundsB[$i+2],$BoundsB[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3226. }
  3227. }
  3228. else
  3229. {
  3230. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3231. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3232. $LastY = NULL; $LastX1 = NULL; $LastX2 = NULL;
  3233. $BoundsA = ""; $BoundsB = "";
  3234. foreach($PosArrayA as $Key => $X1)
  3235. {
  3236. $X2 = $PosArrayB[$Key];
  3237. $BoundsA[] = $X1; $BoundsA[] = $Y;
  3238. $BoundsB[] = $X2; $BoundsB[] = $Y;
  3239. $LastY = $Y;
  3240. $LastX1 = $X1; $LastX2 = $X2;
  3241. $Y = $Y + $YStep;
  3242. }
  3243. $Bounds = array_merge($BoundsA,$this->reversePlots($BoundsB));
  3244. $this->drawPolygonChart($Bounds,array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"Alpha"=>$AreaAlpha));
  3245. for($i=0;$i<=count($BoundsA)-4;$i=$i+2)
  3246. {
  3247. $this->drawLine($BoundsA[$i],$BoundsA[$i+1],$BoundsA[$i+2],$BoundsA[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3248. $this->drawLine($BoundsB[$i],$BoundsB[$i+1],$BoundsB[$i+2],$BoundsB[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3249. }
  3250. }
  3251. }
  3252. /* Draw a step chart */
  3253. function drawStepChart($Format=NULL)
  3254. {
  3255. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : FALSE;
  3256. $ReCenter = isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
  3257. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  3258. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
  3259. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
  3260. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
  3261. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
  3262. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3263. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3264. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3265. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3266. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3267. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3268. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  3269. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3270. $Data = $this->DataSet->getData();
  3271. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3272. foreach($Data["Series"] as $SerieName => $Serie)
  3273. {
  3274. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3275. {
  3276. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3277. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  3278. if ( $BreakR == NULL )
  3279. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3280. else
  3281. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3282. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3283. $AxisID = $Serie["Axis"];
  3284. $Mode = $Data["Axis"][$AxisID]["Display"];
  3285. $Format = $Data["Axis"][$AxisID]["Format"];
  3286. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3287. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  3288. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3289. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3290. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3291. {
  3292. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3293. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3294. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3295. $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
  3296. foreach($PosArray as $Key => $Y)
  3297. {
  3298. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3299. {
  3300. if ( $Y <= $LastY ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3301. $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3302. }
  3303. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  3304. {
  3305. $this->drawLine($LastX,$LastY,$X,$LastY,$Color);
  3306. $this->drawLine($X,$LastY,$X,$Y,$Color);
  3307. if ( $ReCenter && $X+$XStep < $this->GraphAreaX2 - $XMargin )
  3308. {
  3309. $this->drawLine($X,$Y,$X+$XStep,$Y,$Color);
  3310. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X-$ImageMapPlotSize).",".floor($Y-$ImageMapPlotSize).",".floor($X+$XStep+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3311. }
  3312. else
  3313. { if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($LastY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); } }
  3314. }
  3315. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  3316. {
  3317. if ( $ReCenter )
  3318. {
  3319. $this->drawLine($LastGoodX+$XStep,$LastGoodY,$X,$LastGoodY,$BreakSettings);
  3320. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX+$XStep-$ImageMapPlotSize).",".floor($LastGoodY-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($LastGoodY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3321. }
  3322. else
  3323. {
  3324. $this->drawLine($LastGoodX,$LastGoodY,$X,$LastGoodY,$BreakSettings);
  3325. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX-$ImageMapPlotSize).",".floor($LastGoodY-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($LastGoodY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3326. }
  3327. $this->drawLine($X,$LastGoodY,$X,$Y,$BreakSettings);
  3328. $LastGoodY = NULL;
  3329. }
  3330. elseif( !$BreakVoid && $LastGoodY == NULL && $Y != VOID )
  3331. {
  3332. $this->drawLine($this->GraphAreaX1 + $XMargin,$Y,$X,$Y,$BreakSettings);
  3333. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($this->GraphAreaX1+$XMargin-$ImageMapPlotSize).",".floor($Y-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3334. }
  3335. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3336. if ( $Y == VOID ) { $Y = NULL; }
  3337. if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
  3338. $LastX = $X; $LastY = $Y;
  3339. if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
  3340. $X = $X + $XStep;
  3341. }
  3342. if ( $ReCenter )
  3343. {
  3344. $this->drawLine($LastX,$LastY,$this->GraphAreaX2 - $XMargin,$LastY,$Color);
  3345. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($this->GraphAreaX2-$XMargin+$ImageMapPlotSize).",".floor($LastY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3346. }
  3347. }
  3348. else
  3349. {
  3350. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3351. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3352. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3353. $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
  3354. foreach($PosArray as $Key => $X)
  3355. {
  3356. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3357. {
  3358. if ( $X >= $LastX ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
  3359. $this->drawText($X+$Offset+$Weight,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3360. }
  3361. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3362. {
  3363. $this->drawLine($LastX,$LastY,$LastX,$Y,$Color);
  3364. $this->drawLine($LastX,$Y,$X,$Y,$Color);
  3365. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($LastX+$XStep+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3366. }
  3367. if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
  3368. {
  3369. $this->drawLine($LastGoodX,$LastGoodY,$LastGoodX,$LastGoodY+$YStep,$Color);
  3370. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX-$ImageMapPlotSize).",".floor($LastGoodY-$ImageMapPlotSize).",".floor($LastGoodX+$ImageMapPlotSize).",".floor($LastGoodY+$YStep+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3371. $this->drawLine($LastGoodX,$LastGoodY+$YStep,$LastGoodX,$Y,$BreakSettings);
  3372. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX-$ImageMapPlotSize).",".floor($LastGoodY+$YStep-$ImageMapPlotSize).",".floor($LastGoodX+$ImageMapPlotSize).",".floor($YStep+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3373. $this->drawLine($LastGoodX,$Y,$X,$Y,$BreakSettings);
  3374. $LastGoodY = NULL;
  3375. }
  3376. elseif ( $X != VOID && $LastGoodY == NULL && !$BreakVoid )
  3377. {
  3378. $this->drawLine($X,$this->GraphAreaY1 + $XMargin,$X,$Y,$BreakSettings);
  3379. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X-$ImageMapPlotSize).",".floor($this->GraphAreaY1+$XMargin-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3380. }
  3381. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3382. if ( $X == VOID ) { $X = NULL; }
  3383. if ( !$Init && $ReCenter ) { $Y = $Y - $YStep/2; $Init = TRUE; }
  3384. $LastX = $X; $LastY = $Y;
  3385. if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
  3386. $Y = $Y + $YStep;
  3387. }
  3388. if ( $ReCenter )
  3389. {
  3390. $this->drawLine($LastX,$LastY,$LastX,$this->GraphAreaY2 - $XMargin,$Color);
  3391. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($LastX+$ImageMapPlotSize).",".floor($this->GraphAreaY2-$XMargin+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. }
  3397. /* Draw a step chart */
  3398. function drawFilledStepChart($Format=NULL)
  3399. {
  3400. $ReCenter = isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
  3401. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
  3402. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3403. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3404. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
  3405. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3406. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3407. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3408. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3409. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3410. $Data = $this->DataSet->getData();
  3411. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3412. foreach($Data["Series"] as $SerieName => $Serie)
  3413. {
  3414. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3415. {
  3416. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3417. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3418. $AxisID = $Serie["Axis"];
  3419. $Mode = $Data["Axis"][$AxisID]["Display"];
  3420. $Format = $Data["Axis"][$AxisID]["Format"];
  3421. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3422. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  3423. if ( $ForceTransparency != NULL ) { $Color["Alpha"] = $ForceTransparency; } else { $Color["Alpha"] = $Alpha; }
  3424. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3425. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  3426. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3427. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3428. {
  3429. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3430. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3431. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3432. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3433. if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }
  3434. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3435. $LastGoodY = NULL; $LastGoodX = NULL; $Points = ""; $Init = FALSE;
  3436. foreach($PosArray as $Key => $Y)
  3437. {
  3438. if ( $Y == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
  3439. {
  3440. $Points[] = $LastX; $Points[] = $LastY;
  3441. $Points[] = $X; $Points[] = $LastY;
  3442. $Points[] = $X; $Points[] = $YZero;
  3443. $this->drawPolygon($Points,$Color);
  3444. $Points = "";
  3445. }
  3446. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  3447. {
  3448. if ( $Points == "") { $Points[] = $LastX; $Points[] = $YZero; }
  3449. $Points[] = $LastX; $Points[] = $LastY;
  3450. $Points[] = $X; $Points[] = $LastY;
  3451. $Points[] = $X; $Points[] = $Y;
  3452. }
  3453. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3454. if ( $Y == VOID ) { $Y = NULL; }
  3455. if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
  3456. $LastX = $X; $LastY = $Y;
  3457. if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
  3458. $X = $X + $XStep;
  3459. }
  3460. if ( $ReCenter )
  3461. {
  3462. $Points[] = $LastX+$XStep/2; $Points[] = $LastY;
  3463. $Points[] = $LastX+$XStep/2; $Points[] = $YZero;
  3464. }
  3465. else
  3466. { $Points[] = $LastX; $Points[] = $YZero; }
  3467. $this->drawPolygon($Points,$Color);
  3468. }
  3469. else
  3470. {
  3471. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3472. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3473. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3474. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3475. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3476. $LastGoodY = NULL; $LastGoodX = NULL; $Points = "";
  3477. foreach($PosArray as $Key => $X)
  3478. {
  3479. if ( $X == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
  3480. {
  3481. $Points[] = $LastX; $Points[] = $LastY;
  3482. $Points[] = $LastX; $Points[] = $Y;
  3483. $Points[] = $YZero; $Points[] = $Y;
  3484. $this->drawPolygon($Points,$Color);
  3485. $Points = "";
  3486. }
  3487. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3488. {
  3489. if ( $Points == "") { $Points[] = $YZero; $Points[] = $LastY; }
  3490. $Points[] = $LastX; $Points[] = $LastY;
  3491. $Points[] = $LastX; $Points[] = $Y;
  3492. $Points[] = $X; $Points[] = $Y;
  3493. }
  3494. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3495. if ( $X == VOID ) { $X = NULL; }
  3496. if ( $LastX == NULL && $ReCenter ) { $Y = $Y - $YStep/2; }
  3497. $LastX = $X; $LastY = $Y;
  3498. if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
  3499. $Y = $Y + $YStep;
  3500. }
  3501. if ( $ReCenter )
  3502. {
  3503. $Points[] = $LastX; $Points[] = $LastY+$YStep/2;
  3504. $Points[] = $YZero; $Points[] = $LastY+$YStep/2;
  3505. }
  3506. else
  3507. { $Points[] = $YZero; $Points[] = $LastY; }
  3508. $this->drawPolygon($Points,$Color);
  3509. }
  3510. }
  3511. }
  3512. }
  3513. /* Draw an area chart */
  3514. function drawAreaChart($Format=NULL)
  3515. {
  3516. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3517. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3518. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3519. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3520. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3521. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3522. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : 25;
  3523. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3524. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  3525. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3526. $Data = $this->DataSet->getData();
  3527. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3528. foreach($Data["Series"] as $SerieName => $Serie)
  3529. {
  3530. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3531. {
  3532. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3533. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3534. $AxisID = $Serie["Axis"];
  3535. $Mode = $Data["Axis"][$AxisID]["Display"];
  3536. $Format = $Data["Axis"][$AxisID]["Format"];
  3537. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3538. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3539. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  3540. if ( $Threshold != NULL )
  3541. {
  3542. foreach($Threshold as $Key => $Params)
  3543. {
  3544. $Threshold[$Key]["MinX"] = $this->scaleComputeY($Params["Min"],array("AxisID"=>$Serie["Axis"]));
  3545. $Threshold[$Key]["MaxX"] = $this->scaleComputeY($Params["Max"],array("AxisID"=>$Serie["Axis"]));
  3546. }
  3547. }
  3548. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3549. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3550. {
  3551. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3552. $Areas = ""; $AreaID = 0;
  3553. $Areas[$AreaID][] = $this->GraphAreaX1 + $XMargin;
  3554. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3555. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3556. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3557. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3558. foreach($PosArray as $Key => $Y)
  3559. {
  3560. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3561. {
  3562. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3563. $this->drawText($X,$Y-$Offset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3564. }
  3565. if ( $Y == VOID && isset($Areas[$AreaID]) )
  3566. {
  3567. if($LastX == NULL)
  3568. { $Areas[$AreaID][] = $X; }
  3569. else
  3570. { $Areas[$AreaID][] = $LastX; }
  3571. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3572. $AreaID++;
  3573. }
  3574. elseif ($Y != VOID)
  3575. {
  3576. if ( !isset($Areas[$AreaID]) )
  3577. {
  3578. $Areas[$AreaID][] = $X;
  3579. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3580. }
  3581. $Areas[$AreaID][] = $X;
  3582. $Areas[$AreaID][] = $Y;
  3583. }
  3584. $LastX = $X;
  3585. $X = $X + $XStep;
  3586. }
  3587. $Areas[$AreaID][] = $LastX;
  3588. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3589. /* Handle shadows in the areas */
  3590. if ( $this->Shadow )
  3591. {
  3592. $ShadowArea = "";
  3593. foreach($Areas as $Key => $Points)
  3594. {
  3595. $ShadowArea[$Key] = "";
  3596. foreach($Points as $Key2 => $Value)
  3597. {
  3598. if ( $Key2 % 2 == 0 )
  3599. { $ShadowArea[$Key][] = $Value + $this->ShadowX; }
  3600. else
  3601. { $ShadowArea[$Key][] = $Value + $this->ShadowY; }
  3602. }
  3603. }
  3604. foreach($ShadowArea as $Key => $Points)
  3605. $this->drawPolygonChart($Points,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  3606. }
  3607. $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
  3608. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Threshold"=>$Threshold);
  3609. foreach($Areas as $Key => $Points)
  3610. $this->drawPolygonChart($Points,$Color);
  3611. }
  3612. else
  3613. {
  3614. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3615. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3616. $Areas = ""; $AreaID = 0;
  3617. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3618. $Areas[$AreaID][] = $this->GraphAreaY1 + $XMargin;
  3619. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3620. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3621. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3622. foreach($PosArray as $Key => $X)
  3623. {
  3624. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3625. {
  3626. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3627. $this->drawText($X+$Offset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3628. }
  3629. if ( $X == VOID && isset($Areas[$AreaID]) )
  3630. {
  3631. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3632. if($LastY == NULL)
  3633. { $Areas[$AreaID][] = $Y; }
  3634. else
  3635. { $Areas[$AreaID][] = $LastY; }
  3636. $AreaID++;
  3637. }
  3638. elseif ($X != VOID)
  3639. {
  3640. if ( !isset($Areas[$AreaID]) )
  3641. {
  3642. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3643. $Areas[$AreaID][] = $Y;
  3644. }
  3645. $Areas[$AreaID][] = $X;
  3646. $Areas[$AreaID][] = $Y;
  3647. }
  3648. $LastX = $X; $LastY = $Y;
  3649. $Y = $Y + $YStep;
  3650. }
  3651. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3652. $Areas[$AreaID][] = $LastY;
  3653. /* Handle shadows in the areas */
  3654. if ( $this->Shadow )
  3655. {
  3656. $ShadowArea = "";
  3657. foreach($Areas as $Key => $Points)
  3658. {
  3659. $ShadowArea[$Key] = "";
  3660. foreach($Points as $Key2 => $Value)
  3661. {
  3662. if ( $Key2 % 2 == 0 )
  3663. { $ShadowArea[$Key][] = $Value + $this->ShadowX; }
  3664. else
  3665. { $ShadowArea[$Key][] = $Value + $this->ShadowY; }
  3666. }
  3667. }
  3668. foreach($ShadowArea as $Key => $Points)
  3669. $this->drawPolygonChart($Points,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  3670. }
  3671. $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
  3672. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Threshold"=>$Threshold);
  3673. foreach($Areas as $Key => $Points)
  3674. $this->drawPolygonChart($Points,$Color);
  3675. }
  3676. }
  3677. }
  3678. }
  3679. /* Draw a bar chart */
  3680. function drawBarChart($Format=NULL)
  3681. {
  3682. $Floating0Serie = isset($Format["Floating0Serie"]) ? $Format["Floating0Serie"] : NULL;
  3683. $Floating0Value = isset($Format["Floating0Value"]) ? $Format["Floating0Value"] : NULL;
  3684. $Draw0Line = isset($Format["Draw0Line"]) ? $Format["Draw0Line"] : FALSE;
  3685. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3686. $DisplayOrientation = isset($Format["DisplayOrientation"]) ? $Format["DisplayOrientation"] : ORIENTATION_HORIZONTAL;
  3687. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3688. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3689. $DisplayFont = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontName;
  3690. $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
  3691. $DisplayPos = isset($Format["DisplayPos"]) ? $Format["DisplayPos"] : LABEL_POS_OUTSIDE;
  3692. $DisplayShadow = isset($Format["DisplayShadow"]) ? $Format["DisplayShadow"] : TRUE;
  3693. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3694. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3695. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3696. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3697. $Interleave = isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
  3698. $Rounded = isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
  3699. $RoundRadius = isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
  3700. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  3701. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  3702. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  3703. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  3704. $Gradient = isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
  3705. $GradientMode = isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
  3706. $GradientAlpha = isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
  3707. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  3708. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  3709. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  3710. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
  3711. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
  3712. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
  3713. $TxtMargin = isset($Format["TxtMargin"]) ? $Format["TxtMargin"] : 6;
  3714. $OverrideColors = isset($Format["OverrideColors"]) ? $Format["OverrideColors"] : NULL;
  3715. $OverrideSurrounding = isset($Format["OverrideSurrounding"]) ? $Format["OverrideSurrounding"] : 30;
  3716. $InnerSurrounding = isset($Format["InnerSurrounding"]) ? $Format["InnerSurrounding"] : NULL;
  3717. $InnerBorderR = isset($Format["InnerBorderR"]) ? $Format["InnerBorderR"] : -1;
  3718. $InnerBorderG = isset($Format["InnerBorderG"]) ? $Format["InnerBorderG"] : -1;
  3719. $InnerBorderB = isset($Format["InnerBorderB"]) ? $Format["InnerBorderB"] : -1;
  3720. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3721. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3722. $Data = $this->DataSet->getData();
  3723. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3724. if ( $OverrideColors != NULL )
  3725. {
  3726. $OverrideColors = $this->validatePalette($OverrideColors,$OverrideSurrounding);
  3727. $this->DataSet->saveExtendedData("Palette",$OverrideColors);
  3728. }
  3729. $RestoreShadow = $this->Shadow;
  3730. $SeriesCount = $this->countDrawableSeries();
  3731. $CurrentSerie = 0;
  3732. foreach($Data["Series"] as $SerieName => $Serie)
  3733. {
  3734. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3735. {
  3736. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3737. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3738. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  3739. if ( $InnerSurrounding != NULL ) { $InnerBorderR = $R+$InnerSurrounding; $InnerBorderG = $G+$InnerSurrounding; $InnerBorderB = $B+$InnerSurrounding; }
  3740. if ( $InnerBorderR == -1 ) { $InnerColor = NULL; } else { $InnerColor = array("R"=>$InnerBorderR,"G"=>$InnerBorderG,"B"=>$InnerBorderB); }
  3741. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);
  3742. $AxisID = $Serie["Axis"];
  3743. $Mode = $Data["Axis"][$AxisID]["Display"];
  3744. $Format = $Data["Axis"][$AxisID]["Format"];
  3745. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3746. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  3747. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3748. if ( $Floating0Value != NULL )
  3749. { $YZero = $this->scaleComputeY($Floating0Value,array("AxisID"=>$Serie["Axis"])); }
  3750. else
  3751. { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }
  3752. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3753. {
  3754. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3755. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3756. if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3757. $X = $this->GraphAreaX1 + $XMargin;
  3758. if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
  3759. if ( $XDivs == 0 ) { $XSize = ($this->GraphAreaX2-$this->GraphAreaX1)/($SeriesCount+$Interleave); } else { $XSize = ($XStep / ($SeriesCount+$Interleave) ); }
  3760. $XOffset = -($XSize*$SeriesCount)/2 + $CurrentSerie * $XSize;
  3761. if ( $X + $XOffset <= $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $X + 1 ; }
  3762. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $XOffset + $XSize / 2;
  3763. if ( $Rounded || $BorderR != -1) { $XSpace = 1; } else { $XSpace = 0; }
  3764. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3765. $ID = 0;
  3766. foreach($PosArray as $Key => $Y2)
  3767. {
  3768. if ( $Floating0Serie != NULL )
  3769. {
  3770. if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
  3771. { $Value = $Data["Series"][$Floating0Serie]["Data"][$Key]; }
  3772. else
  3773. { $Value = 0; }
  3774. $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
  3775. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3776. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3777. if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
  3778. }
  3779. if ( $OverrideColors != NULL )
  3780. { 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(); } }
  3781. if ( $Y2 != VOID )
  3782. {
  3783. $BarHeight = $Y1 - $Y2;
  3784. if ( $Serie["Data"][$Key] == 0 )
  3785. {
  3786. $this->drawLine($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y1,$Color);
  3787. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X+$XOffset+$XSpace).",".floor($Y1-1).",".floor($X+$XOffset+$XSize-$XSpace).",".floor($Y1+1),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3788. }
  3789. else
  3790. {
  3791. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X+$XOffset+$XSpace).",".floor($Y1).",".floor($X+$XOffset+$XSize-$XSpace).",".floor($Y2),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3792. if ( $Rounded )
  3793. $this->drawRoundedFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$RoundRadius,$Color);
  3794. else
  3795. {
  3796. $this->drawFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$Color);
  3797. if ( $InnerColor != NULL ) { $this->drawRectangle($X+$XOffset+$XSpace+1,min($Y1,$Y2)+1,$X+$XOffset+$XSize-$XSpace-1,max($Y1,$Y2)-1,$InnerColor); }
  3798. if ( $Gradient )
  3799. {
  3800. $this->Shadow = FALSE;
  3801. if ( $GradientMode == GRADIENT_SIMPLE )
  3802. {
  3803. if ( $Serie["Data"][$Key] >= 0 )
  3804. $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3805. else
  3806. $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3807. $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_VERTICAL,$GradienColor);
  3808. }
  3809. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3810. {
  3811. $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3812. $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3813. $XSpan = floor($XSize / 3);
  3814. $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSpan-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor1);
  3815. $this->drawGradientArea($X+$XOffset+$XSpan+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor2);
  3816. }
  3817. $this->Shadow = $RestoreShadow;
  3818. }
  3819. }
  3820. if ( $Draw0Line )
  3821. {
  3822. $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);
  3823. if ( abs($Y1 - $Y2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
  3824. if ( $Y1 - $Y2 < 0 ) { $Line0Width = -$Line0Width; }
  3825. $this->drawFilledRectangle($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1)-$Line0Width,$Line0Color);
  3826. $this->drawLine($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1),$Line0Color);
  3827. }
  3828. }
  3829. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3830. {
  3831. if ( $DisplayShadow ) { $this->Shadow = TRUE; }
  3832. $Caption = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
  3833. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,90,$Caption);
  3834. $TxtHeight = $TxtPos[0]["Y"] - $TxtPos[1]["Y"] + $TxtMargin;
  3835. if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtHeight) < abs($BarHeight) )
  3836. {
  3837. $CenterX = (($X+$XOffset+$XSize-$XSpace)-($X+$XOffset+$XSpace))/2 + $X+$XOffset+$XSpace;
  3838. $CenterY = ($Y2-$Y1)/2 + $Y1;
  3839. $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"Angle"=>90));
  3840. }
  3841. else
  3842. {
  3843. if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3844. $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));
  3845. }
  3846. $this->Shadow = $RestoreShadow;
  3847. }
  3848. }
  3849. $X = $X + $XStep;
  3850. $ID++;
  3851. }
  3852. }
  3853. else
  3854. {
  3855. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3856. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3857. if ( $XDivs == 0 ) { $YStep = 0; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3858. $Y = $this->GraphAreaY1 + $XMargin;
  3859. if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
  3860. if ( $XDivs == 0 ) { $YSize = ($this->GraphAreaY2-$this->GraphAreaY1)/($SeriesCount+$Interleave); } else { $YSize = ($YStep / ($SeriesCount+$Interleave) ); }
  3861. $YOffset = -($YSize*$SeriesCount)/2 + $CurrentSerie * $YSize;
  3862. if ( $Y + $YOffset <= $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $Y + 1 ; }
  3863. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $YOffset + $YSize / 2;
  3864. if ( $Rounded || $BorderR != -1 ) { $YSpace = 1; } else { $YSpace = 0; }
  3865. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3866. $ID = 0 ;
  3867. foreach($PosArray as $Key => $X2)
  3868. {
  3869. if ( $Floating0Serie != NULL )
  3870. {
  3871. if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
  3872. $Value = $Data["Series"][$Floating0Serie]["Data"][$Key];
  3873. else { $Value = 0; }
  3874. $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
  3875. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3876. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3877. if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
  3878. }
  3879. if ( $OverrideColors != NULL )
  3880. { 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(); } }
  3881. if ( $X2 != VOID )
  3882. {
  3883. $BarWidth = $X2 - $X1;
  3884. if ( $Serie["Data"][$Key] == 0 )
  3885. {
  3886. $this->drawLine($X1,$Y+$YOffset+$YSpace,$X1,$Y+$YOffset+$YSize-$YSpace,$Color);
  3887. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X1-1).",".floor($Y+$YOffset+$YSpace).",".floor($X1+1).",".floor($Y+$YOffset+$YSize-$YSpace),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3888. }
  3889. else
  3890. {
  3891. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X1).",".floor($Y+$YOffset+$YSpace).",".floor($X2).",".floor($Y+$YOffset+$YSize-$YSpace),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3892. if ( $Rounded )
  3893. $this->drawRoundedFilledRectangle($X1+1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$RoundRadius,$Color);
  3894. else
  3895. {
  3896. $this->drawFilledRectangle($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$Color);
  3897. if ( $InnerColor != NULL ) { $this->drawRectangle(min($X1,$X2)+1,$Y+$YOffset+$YSpace+1,max($X1,$X2)-1,$Y+$YOffset+$YSize-$YSpace-1,$InnerColor); }
  3898. if ( $Gradient )
  3899. {
  3900. $this->Shadow = FALSE;
  3901. if ( $GradientMode == GRADIENT_SIMPLE )
  3902. {
  3903. if ( $Serie["Data"][$Key] >= 0 )
  3904. $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3905. else
  3906. $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3907. $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_HORIZONTAL,$GradienColor);
  3908. }
  3909. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3910. {
  3911. $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3912. $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3913. $YSpan = floor($YSize / 3);
  3914. $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSpan-$YSpace,DIRECTION_VERTICAL,$GradienColor1);
  3915. $this->drawGradientArea($X1,$Y+$YOffset+$YSpan,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_VERTICAL,$GradienColor2);
  3916. }
  3917. $this->Shadow = $RestoreShadow;
  3918. }
  3919. }
  3920. if ( $Draw0Line )
  3921. {
  3922. $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);
  3923. if ( abs($X1 - $X2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
  3924. if ( $X2 - $X1 < 0 ) { $Line0Width = -$Line0Width; }
  3925. $this->drawFilledRectangle(floor($X1),$Y+$YOffset+$YSpace,floor($X1)+$Line0Width,$Y+$YOffset+$YSize-$YSpace,$Line0Color);
  3926. $this->drawLine(floor($X1),$Y+$YOffset+$YSpace,floor($X1),$Y+$YOffset+$YSize-$YSpace,$Line0Color);
  3927. }
  3928. }
  3929. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3930. {
  3931. if ( $DisplayShadow ) { $this->Shadow = TRUE; }
  3932. $Caption = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
  3933. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3934. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"] + $TxtMargin;
  3935. if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtWidth) < abs($BarWidth) )
  3936. {
  3937. $CenterX = ($X2-$X1)/2 + $X1;
  3938. $CenterY = (($Y+$YOffset+$YSize-$YSpace)-($Y+$YOffset+$YSpace))/2 + ($Y+$YOffset+$YSpace);
  3939. $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize));
  3940. }
  3941. else
  3942. {
  3943. if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
  3944. $this->drawText($X2+$Offset,$Y+$YOffset+$YSize/2,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align,"FontSize"=>$DisplaySize));
  3945. }
  3946. $this->Shadow = $RestoreShadow;
  3947. }
  3948. }
  3949. $Y = $Y + $YStep;
  3950. $ID++;
  3951. }
  3952. }
  3953. $CurrentSerie++;
  3954. }
  3955. }
  3956. }
  3957. /* Draw a bar chart */
  3958. function drawStackedBarChart($Format=NULL)
  3959. {
  3960. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3961. $DisplayOrientation = isset($Format["DisplayOrientation"]) ? $Format["DisplayOrientation"] : ORIENTATION_AUTO;
  3962. $DisplayRound = isset($Format["DisplayRound"]) ? $Format["DisplayRound"] : 0;
  3963. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3964. $DisplayFont = isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;
  3965. $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
  3966. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3967. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3968. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3969. $Interleave = isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
  3970. $Rounded = isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
  3971. $RoundRadius = isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
  3972. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  3973. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  3974. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  3975. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  3976. $Gradient = isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
  3977. $GradientMode = isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
  3978. $GradientAlpha = isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
  3979. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  3980. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  3981. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  3982. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
  3983. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
  3984. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
  3985. $InnerSurrounding = isset($Format["InnerSurrounding"]) ? $Format["InnerSurrounding"] : NULL;
  3986. $InnerBorderR = isset($Format["InnerBorderR"]) ? $Format["InnerBorderR"] : -1;
  3987. $InnerBorderG = isset($Format["InnerBorderG"]) ? $Format["InnerBorderG"] : -1;
  3988. $InnerBorderB = isset($Format["InnerBorderB"]) ? $Format["InnerBorderB"] : -1;
  3989. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3990. $FontFactor = isset($Format["FontFactor"]) ? $Format["FontFactor"] : 8;
  3991. $this->LastChartLayout = CHART_LAST_LAYOUT_STACKED;
  3992. $Data = $this->DataSet->getData();
  3993. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3994. $RestoreShadow = $this->Shadow;
  3995. $LastX = ""; $LastY = "";
  3996. foreach($Data["Series"] as $SerieName => $Serie)
  3997. {
  3998. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3999. {
  4000. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  4001. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = 255; $DisplayG = 255; $DisplayB = 255; }
  4002. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  4003. if ( $InnerSurrounding != NULL ) { $InnerBorderR = $R+$InnerSurrounding; $InnerBorderG = $G+$InnerSurrounding; $InnerBorderB = $B+$InnerSurrounding; }
  4004. if ( $InnerBorderR == -1 ) { $InnerColor = NULL; } else { $InnerColor = array("R"=>$InnerBorderR,"G"=>$InnerBorderG,"B"=>$InnerBorderB); }
  4005. $AxisID = $Serie["Axis"];
  4006. $Mode = $Data["Axis"][$AxisID]["Display"];
  4007. $Format = $Data["Axis"][$AxisID]["Format"];
  4008. $Unit = $Data["Axis"][$AxisID]["Unit"];
  4009. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  4010. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
  4011. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  4012. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  4013. $Color = array("TransCorner"=>TRUE,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);
  4014. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4015. {
  4016. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  4017. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  4018. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4019. $X = $this->GraphAreaX1 + $XMargin;
  4020. $XSize = ($XStep / (1+$Interleave) );
  4021. $XOffset = -($XSize/2);
  4022. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4023. foreach($PosArray as $Key => $Height)
  4024. {
  4025. if ( $Height != VOID && $Serie["Data"][$Key] != 0 )
  4026. {
  4027. if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }
  4028. if ( !isset($LastY[$Key] ) ) { $LastY[$Key] = ""; }
  4029. if ( !isset($LastY[$Key][$Pos] ) ) { $LastY[$Key][$Pos] = $YZero; }
  4030. $Y1 = $LastY[$Key][$Pos];
  4031. $Y2 = $Y1 - $Height;
  4032. if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $Y1 != $YZero) ) { $YSpaceUp = 1; } else { $YSpaceUp = 0; }
  4033. if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $Y1 != $YZero) ) { $YSpaceDown = 1; } else { $YSpaceDown = 0; }
  4034. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X+$XOffset).",".floor($Y1-$YSpaceUp+$YSpaceDown).",".floor($X+$XOffset+$XSize).",".floor($Y2),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  4035. if ( $Rounded )
  4036. $this->drawRoundedFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$RoundRadius,$Color);
  4037. else
  4038. {
  4039. $this->drawFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$Color);
  4040. if ( $InnerColor != NULL ) { $RestoreShadow = $this->Shadow; $this->Shadow = FALSE; $this->drawRectangle(min($X+$XOffset+1,$X+$XOffset+$XSize),min($Y1-$YSpaceUp+$YSpaceDown,$Y2)+1,max($X+$XOffset+1,$X+$XOffset+$XSize)-1,max($Y1-$YSpaceUp+$YSpaceDown,$Y2)-1,$InnerColor); $this->Shadow = $RestoreShadow;}
  4041. if ( $Gradient )
  4042. {
  4043. $this->Shadow = FALSE;
  4044. if ( $GradientMode == GRADIENT_SIMPLE )
  4045. {
  4046. $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4047. $this->drawGradientArea($X+$XOffset,$Y1-1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+1,DIRECTION_VERTICAL,$GradientColor);
  4048. }
  4049. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  4050. {
  4051. $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  4052. $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4053. $XSpan = floor($XSize / 3);
  4054. $this->drawGradientArea($X+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSpan,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor1);
  4055. $this->drawGradientArea($X+$XSpan+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor2);
  4056. }
  4057. $this->Shadow = $RestoreShadow;
  4058. }
  4059. }
  4060. if ( $DisplayValues )
  4061. {
  4062. $BarHeight = abs($Y2-$Y1)-2;
  4063. $BarWidth = $XSize+($XOffset/2)-$FontFactor;
  4064. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  4065. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  4066. $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
  4067. $TxtWidth = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);
  4068. $XCenter = ( ($X+$XOffset+$XSize) - ($X+$XOffset) ) / 2 + $X+$XOffset;
  4069. $YCenter = ( ($Y2) - ($Y1-$YSpaceUp+$YSpaceDown) ) / 2 + $Y1-$YSpaceUp+$YSpaceDown;
  4070. $Done = FALSE;
  4071. if ( $DisplayOrientation == ORIENTATION_HORIZONTAL || $DisplayOrientation == ORIENTATION_AUTO )
  4072. {
  4073. if ( $TxtHeight < $BarHeight && $TxtWidth < $BarWidth )
  4074. {
  4075. $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));
  4076. $Done = TRUE;
  4077. }
  4078. }
  4079. if ( $DisplayOrientation == ORIENTATION_VERTICAL || ( $DisplayOrientation == ORIENTATION_AUTO && !$Done) )
  4080. {
  4081. if ( $TxtHeight < $BarWidth && $TxtWidth < $BarHeight )
  4082. $this->drawText($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Angle"=>90,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  4083. }
  4084. }
  4085. $LastY[$Key][$Pos] = $Y2;
  4086. }
  4087. $X = $X + $XStep;
  4088. }
  4089. }
  4090. else
  4091. {
  4092. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  4093. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  4094. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4095. $Y = $this->GraphAreaY1 + $XMargin;
  4096. $YSize = $YStep / (1+$Interleave);
  4097. $YOffset = -($YSize/2);
  4098. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4099. foreach($PosArray as $Key => $Width)
  4100. {
  4101. if ( $Width != VOID && $Serie["Data"][$Key] != 0 )
  4102. {
  4103. if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }
  4104. if ( !isset($LastX[$Key] ) ) { $LastX[$Key] = ""; }
  4105. if ( !isset($LastX[$Key][$Pos] ) ) { $LastX[$Key][$Pos] = $YZero; }
  4106. $X1 = $LastX[$Key][$Pos];
  4107. $X2 = $X1 + $Width;
  4108. if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $X1 != $YZero) ) { $XSpaceLeft = 2; } else { $XSpaceLeft = 0; }
  4109. if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $X1 != $YZero) ) { $XSpaceRight = 2; } else { $XSpaceRight = 0; }
  4110. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X1+$XSpaceLeft).",".floor($Y+$YOffset).",".floor($X2-$XSpaceRight).",".floor($Y+$YOffset+$YSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  4111. if ( $Rounded )
  4112. $this->drawRoundedFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$RoundRadius,$Color);
  4113. else
  4114. {
  4115. $this->drawFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$Color);
  4116. if ( $InnerColor != NULL ) { $RestoreShadow = $this->Shadow; $this->Shadow = FALSE; $this->drawRectangle(min($X1+$XSpaceLeft,$X2-$XSpaceRight)+1,min($Y+$YOffset,$Y+$YOffset+$YSize)+1,max($X1+$XSpaceLeft,$X2-$XSpaceRight)-1,max($Y+$YOffset,$Y+$YOffset+$YSize)-1,$InnerColor); $this->Shadow = $RestoreShadow;}
  4117. if ( $Gradient )
  4118. {
  4119. $this->Shadow = FALSE;
  4120. if ( $GradientMode == GRADIENT_SIMPLE )
  4121. {
  4122. $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4123. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_HORIZONTAL,$GradientColor);
  4124. }
  4125. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  4126. {
  4127. $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  4128. $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4129. $YSpan = floor($YSize / 3);
  4130. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSpan,DIRECTION_VERTICAL,$GradientColor1);
  4131. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset+$YSpan,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_VERTICAL,$GradientColor2);
  4132. }
  4133. $this->Shadow = $RestoreShadow;
  4134. }
  4135. }
  4136. if ( $DisplayValues )
  4137. {
  4138. $BarWidth = abs($X2-$X1)-$FontFactor;
  4139. $BarHeight = $YSize+($YOffset/2)-$FontFactor/2;
  4140. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  4141. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  4142. $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
  4143. $TxtWidth = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);
  4144. $XCenter = ( $X2 - $X1 ) / 2 + $X1;
  4145. $YCenter = ( ($Y+$YOffset+$YSize) - ($Y+$YOffset) ) / 2 + $Y+$YOffset;
  4146. $Done = FALSE;
  4147. if ( $DisplayOrientation == ORIENTATION_HORIZONTAL || $DisplayOrientation == ORIENTATION_AUTO )
  4148. {
  4149. if ( $TxtHeight < $BarHeight && $TxtWidth < $BarWidth )
  4150. {
  4151. $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));
  4152. $Done = TRUE;
  4153. }
  4154. }
  4155. if ( $DisplayOrientation == ORIENTATION_VERTICAL || ( $DisplayOrientation == ORIENTATION_AUTO && !$Done) )
  4156. {
  4157. if ( $TxtHeight < $BarWidth && $TxtWidth < $BarHeight )
  4158. $this->drawText($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Angle"=>90,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  4159. }
  4160. }
  4161. $LastX[$Key][$Pos] = $X2;
  4162. }
  4163. $Y = $Y + $YStep;
  4164. }
  4165. }
  4166. }
  4167. }
  4168. }
  4169. /* Draw a stacked area chart */
  4170. function drawStackedAreaChart($Format=NULL)
  4171. {
  4172. $DrawLine = isset($Format["DrawLine"]) ? $Format["DrawLine"] : FALSE;
  4173. $LineSurrounding = isset($Format["LineSurrounding"]) ? $Format["LineSurrounding"] : NULL;
  4174. $LineR = isset($Format["LineR"]) ? $Format["LineR"] : VOID;
  4175. $LineG = isset($Format["LineG"]) ? $Format["LineG"] : VOID;
  4176. $LineB = isset($Format["LineB"]) ? $Format["LineB"] : VOID;
  4177. $LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 100;
  4178. $DrawPlot = isset($Format["DrawPlot"]) ? $Format["DrawPlot"] : FALSE;
  4179. $PlotRadius = isset($Format["PlotRadius"]) ? $Format["PlotRadius"] : 2;
  4180. $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : 1;
  4181. $PlotBorderSurrounding = isset($Format["PlotBorderSurrounding"]) ? $Format["PlotBorderSurrounding"] : NULL;
  4182. $PlotBorderR = isset($Format["PlotBorderR"]) ? $Format["PlotBorderR"] : 0;
  4183. $PlotBorderG = isset($Format["PlotBorderG"]) ? $Format["PlotBorderG"] : 0;
  4184. $PlotBorderB = isset($Format["PlotBorderB"]) ? $Format["PlotBorderB"] : 0;
  4185. $PlotBorderAlpha = isset($Format["PlotBorderAlpha"]) ? $Format["PlotBorderAlpha"] : 50;
  4186. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
  4187. $this->LastChartLayout = CHART_LAST_LAYOUT_STACKED;
  4188. $Data = $this->DataSet->getData();
  4189. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4190. $RestoreShadow = $this->Shadow;
  4191. $this->Shadow = FALSE;
  4192. /* Build the offset data series */
  4193. $OffsetData = "";
  4194. $OverallOffset = "";
  4195. $SerieOrder = "";
  4196. foreach($Data["Series"] as $SerieName => $Serie)
  4197. {
  4198. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4199. {
  4200. $SerieOrder[] = $SerieName;
  4201. foreach($Serie["Data"] as $Key => $Value)
  4202. {
  4203. if ( $Value == VOID ) { $Value = 0; }
  4204. if ($Value >= 0) { $Sign = "+"; } else { $Sign = "-"; }
  4205. if ( !isset($OverallOffset[$Key]) || !isset($OverallOffset[$Key][$Sign]) ) { $OverallOffset[$Key][$Sign] = 0; }
  4206. if ( $Sign == "+" )
  4207. { $Data["Series"][$SerieName]["Data"][$Key] = $Value + $OverallOffset[$Key][$Sign]; }
  4208. else
  4209. { $Data["Series"][$SerieName]["Data"][$Key] = $Value - $OverallOffset[$Key][$Sign]; }
  4210. $OverallOffset[$Key][$Sign] = $OverallOffset[$Key][$Sign] + abs($Value);
  4211. }
  4212. }
  4213. }
  4214. $SerieOrder = array_reverse($SerieOrder);
  4215. $LastX = ""; $LastY = "";
  4216. foreach($SerieOrder as $Key => $SerieName)
  4217. {
  4218. $Serie = $Data["Series"][$SerieName];
  4219. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4220. {
  4221. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  4222. if ( $ForceTransparency != NULL ) { $Alpha = $ForceTransparency; }
  4223. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  4224. if ( $LineSurrounding != NULL )
  4225. $LineColor = array("R"=>$R+$LineSurrounding,"G"=>$G+$LineSurrounding,"B"=>$B+$LineSurrounding,"Alpha"=>$Alpha);
  4226. elseif ( $LineR != VOID )
  4227. $LineColor = array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha);
  4228. else
  4229. $LineColor = $Color;
  4230. if ( $PlotBorderSurrounding != NULL )
  4231. $PlotBorderColor = array("R"=>$R+$PlotBorderSurrounding,"G"=>$G+$PlotBorderSurrounding,"B"=>$B+$PlotBorderSurrounding,"Alpha"=>$PlotBorderAlpha);
  4232. else
  4233. $PlotBorderColor = array("R"=>$PlotBorderR,"G"=>$PlotBorderG,"B"=>$PlotBorderB,"Alpha"=>$PlotBorderAlpha);
  4234. $AxisID = $Serie["Axis"];
  4235. $Mode = $Data["Axis"][$AxisID]["Display"];
  4236. $Format = $Data["Axis"][$AxisID]["Format"];
  4237. $Unit = $Data["Axis"][$AxisID]["Unit"];
  4238. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
  4239. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  4240. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  4241. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4242. {
  4243. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  4244. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  4245. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4246. $X = $this->GraphAreaX1 + $XMargin;
  4247. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4248. $Plots = ""; $Plots[] = $X; $Plots[] = $YZero;
  4249. foreach($PosArray as $Key => $Height)
  4250. {
  4251. if ( $Height != VOID ) { $Plots[] = $X; $Plots[] = $YZero-$Height; }
  4252. $X = $X + $XStep;
  4253. }
  4254. $Plots[] = $X-$XStep; $Plots[] = $YZero;
  4255. $this->drawPolygon($Plots,$Color);
  4256. $this->Shadow = $RestoreShadow;
  4257. if ( $DrawLine ) { for($i=2; $i<=count($Plots)-6; $i=$i+2) { $this->drawLine($Plots[$i],$Plots[$i+1],$Plots[$i+2],$Plots[$i+3],$LineColor); } }
  4258. if ( $DrawPlot )
  4259. {
  4260. for($i=2; $i<=count($Plots)-4; $i=$i+2)
  4261. {
  4262. if ( $PlotBorder != 0 )
  4263. { $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius+$PlotBorder,$PlotBorderColor); }
  4264. $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius,$Color);
  4265. }
  4266. }
  4267. $this->Shadow = FALSE;
  4268. }
  4269. elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  4270. {
  4271. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  4272. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  4273. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4274. $Y = $this->GraphAreaY1 + $XMargin;
  4275. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4276. $Plots = ""; $Plots[] = $YZero; $Plots[] = $Y;
  4277. foreach($PosArray as $Key => $Height)
  4278. {
  4279. if ( $Height != VOID ) { $Plots[] = $YZero+$Height; $Plots[] = $Y; }
  4280. $Y = $Y + $YStep;
  4281. }
  4282. $Plots[] = $YZero; $Plots[] = $Y-$YStep;
  4283. $this->drawPolygon($Plots,$Color);
  4284. $this->Shadow = $RestoreShadow;
  4285. if ( $DrawLine ) { for($i=2; $i<=count($Plots)-6; $i=$i+2) { $this->drawLine($Plots[$i],$Plots[$i+1],$Plots[$i+2],$Plots[$i+3],$LineColor); } }
  4286. if ( $DrawPlot )
  4287. {
  4288. for($i=2; $i<=count($Plots)-4; $i=$i+2)
  4289. {
  4290. if ( $PlotBorder != 0 )
  4291. { $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius+$PlotBorder,$PlotBorderColor); }
  4292. $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius,$Color);
  4293. }
  4294. }
  4295. $this->Shadow = FALSE;
  4296. }
  4297. }
  4298. }
  4299. $this->Shadow = $RestoreShadow;
  4300. }
  4301. /* Returns a random color */
  4302. function getRandomColor($Alpha=100)
  4303. { return(array("R"=>rand(0,255),"G"=>rand(0,255),"B"=>rand(0,255),"Alpha"=>$Alpha)); }
  4304. /* Validate a palette */
  4305. function validatePalette($Colors,$Surrounding=NULL)
  4306. {
  4307. $Result = "";
  4308. if ( !is_array($Colors) ) { return($this->getRandomColor()); }
  4309. foreach($Colors as $Key => $Values)
  4310. {
  4311. if ( isset($Values["R"]) ) { $Result[$Key]["R"] = $Values["R"]; } else { $Result[$Key]["R"] = rand(0,255); }
  4312. if ( isset($Values["G"]) ) { $Result[$Key]["G"] = $Values["G"]; } else { $Result[$Key]["G"] = rand(0,255); }
  4313. if ( isset($Values["B"]) ) { $Result[$Key]["B"] = $Values["B"]; } else { $Result[$Key]["B"] = rand(0,255); }
  4314. if ( isset($Values["Alpha"]) ) { $Result[$Key]["Alpha"] = $Values["Alpha"]; } else { $Result[$Key]["Alpha"] = 100; }
  4315. if ( $Surrounding != NULL )
  4316. {
  4317. $Result[$Key]["BorderR"] = $Result[$Key]["R"] + $Surrounding;
  4318. $Result[$Key]["BorderG"] = $Result[$Key]["G"] + $Surrounding;
  4319. $Result[$Key]["BorderB"] = $Result[$Key]["B"] + $Surrounding;
  4320. }
  4321. else
  4322. {
  4323. if ( isset($Values["BorderR"]) ) { $Result[$Key]["BorderR"] = $Values["BorderR"]; } else { $Result[$Key]["BorderR"] = $Result[$Key]["R"]; }
  4324. if ( isset($Values["BorderG"]) ) { $Result[$Key]["BorderG"] = $Values["BorderG"]; } else { $Result[$Key]["BorderG"] = $Result[$Key]["G"]; }
  4325. if ( isset($Values["BorderB"]) ) { $Result[$Key]["BorderB"] = $Values["BorderB"]; } else { $Result[$Key]["BorderB"] = $Result[$Key]["B"]; }
  4326. if ( isset($Values["BorderAlpha"]) ) { $Result[$Key]["BorderAlpha"] = $Values["BorderAlpha"]; } else { $Result[$Key]["BorderAlpha"] = $Result[$Key]["Alpha"]; }
  4327. }
  4328. }
  4329. return($Result);
  4330. }
  4331. /* Draw the derivative chart associated to the data series */
  4332. function drawDerivative($Format=NULL)
  4333. {
  4334. $Offset = isset($Format["Offset"]) ? $Format["Offset"] : 10;
  4335. $SerieSpacing = isset($Format["SerieSpacing"]) ? $Format["SerieSpacing"] : 3;
  4336. $DerivativeHeight = isset($Format["DerivativeHeight"]) ? $Format["DerivativeHeight"] : 4;
  4337. $ShadedSlopeBox = isset($Format["ShadedSlopeBox"]) ? $Format["ShadedSlopeBox"] : FALSE;
  4338. $DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE;
  4339. $BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255;
  4340. $BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255;
  4341. $BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255;
  4342. $BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 20;
  4343. $DrawBorder = isset($Format["DrawBorder"]) ? $Format["DrawBorder"] : TRUE;
  4344. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 0;
  4345. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 0;
  4346. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 0;
  4347. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 100;
  4348. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : TRUE;
  4349. $CaptionHeight = isset($Format["CaptionHeight"]) ? $Format["CaptionHeight"] : 10;
  4350. $CaptionWidth = isset($Format["CaptionWidth"]) ? $Format["CaptionWidth"] : 20;
  4351. $CaptionMargin = isset($Format["CaptionMargin"]) ? $Format["CaptionMargin"] : 4;
  4352. $CaptionLine = isset($Format["CaptionLine"]) ? $Format["CaptionLine"] : FALSE;
  4353. $CaptionBox = isset($Format["CaptionBox"]) ? $Format["CaptionBox"] : FALSE;
  4354. $CaptionBorderR = isset($Format["CaptionBorderR"]) ? $Format["CaptionBorderR"] : 0;
  4355. $CaptionBorderG = isset($Format["CaptionBorderG"]) ? $Format["CaptionBorderG"] : 0;
  4356. $CaptionBorderB = isset($Format["CaptionBorderB"]) ? $Format["CaptionBorderB"] : 0;
  4357. $CaptionFillR = isset($Format["CaptionFillR"]) ? $Format["CaptionFillR"] : 255;
  4358. $CaptionFillG = isset($Format["CaptionFillG"]) ? $Format["CaptionFillG"] : 255;
  4359. $CaptionFillB = isset($Format["CaptionFillB"]) ? $Format["CaptionFillB"] : 255;
  4360. $CaptionFillAlpha = isset($Format["CaptionFillAlpha"]) ? $Format["CaptionFillAlpha"] : 80;
  4361. $PositiveSlopeStartR = isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 184;
  4362. $PositiveSlopeStartG = isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 234;
  4363. $PositiveSlopeStartB = isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 88;
  4364. $PositiveSlopeEndR = isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 239;
  4365. $PositiveSlopeEndG = isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 31;
  4366. $PositiveSlopeEndB = isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 36;
  4367. $NegativeSlopeStartR = isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 184;
  4368. $NegativeSlopeStartG = isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 234;
  4369. $NegativeSlopeStartB = isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 88;
  4370. $NegativeSlopeEndR = isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 67;
  4371. $NegativeSlopeEndG = isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 124;
  4372. $NegativeSlopeEndB = isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 227;
  4373. $Data = $this->DataSet->getData();
  4374. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4375. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4376. $YPos = $this->DataSet->Data["GraphArea"]["Y2"] + $Offset;
  4377. else
  4378. $XPos = $this->DataSet->Data["GraphArea"]["X2"] + $Offset;
  4379. foreach($Data["Series"] as $SerieName => $Serie)
  4380. {
  4381. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4382. {
  4383. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  4384. $AxisID = $Serie["Axis"];
  4385. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  4386. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4387. {
  4388. if ( $Caption )
  4389. {
  4390. if ( $CaptionLine )
  4391. {
  4392. $StartX = floor($this->GraphAreaX1-$CaptionWidth+$XMargin-$CaptionMargin);
  4393. $EndX = floor($this->GraphAreaX1-$CaptionMargin+$XMargin);
  4394. $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  4395. if ( $CaptionBox ) { $this->drawFilledRectangle($StartX,$YPos,$EndX,$YPos+$CaptionHeight,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
  4396. $this->drawLine($StartX+2,$YPos+($CaptionHeight/2),$EndX-2,$YPos+($CaptionHeight/2),$CaptionSettings);
  4397. }
  4398. else
  4399. $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));
  4400. }
  4401. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4402. $X = $this->GraphAreaX1 + $XMargin;
  4403. $TopY = $YPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
  4404. $BottomY = $YPos + ($CaptionHeight/2) + ($DerivativeHeight/2);
  4405. $StartX = floor($this->GraphAreaX1+$XMargin);
  4406. $EndX = floor($this->GraphAreaX2-$XMargin);
  4407. if ( $DrawBackground ) { $this->drawFilledRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
  4408. if ( $DrawBorder ) { $this->drawRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4409. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4410. $RestoreShadow = $this->Shadow;
  4411. $this->Shadow = FALSE;
  4412. /* Determine the Max slope index */
  4413. $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
  4414. foreach($PosArray as $Key => $Y)
  4415. {
  4416. if ( $Y != VOID && $LastX != NULL )
  4417. { $Slope = ($LastY - $Y); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }
  4418. if ( $Y == VOID )
  4419. { $LastX = NULL; $LastY = NULL; }
  4420. else
  4421. { $LastX = $X; $LastY = $Y; }
  4422. }
  4423. $LastX = NULL; $LastY = NULL; $LastColor = NULL;
  4424. foreach($PosArray as $Key => $Y)
  4425. {
  4426. if ( $Y != VOID && $LastY != NULL )
  4427. {
  4428. $Slope = ($LastY - $Y);
  4429. if ( $Slope >= 0 )
  4430. {
  4431. $SlopeIndex = (100 / $MaxSlope) * $Slope;
  4432. $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
  4433. $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
  4434. $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
  4435. }
  4436. elseif ( $Slope < 0 )
  4437. {
  4438. $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
  4439. $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
  4440. $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
  4441. $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
  4442. }
  4443. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  4444. if ( $ShadedSlopeBox && $LastColor != NULL ) // && $Slope != 0
  4445. {
  4446. $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  4447. $this->drawGradientArea($LastX,$TopY,$X,$BottomY,DIRECTION_HORIZONTAL,$GradientSettings);
  4448. }
  4449. elseif ( !$ShadedSlopeBox || $LastColor == NULL ) // || $Slope == 0
  4450. $this->drawFilledRectangle(floor($LastX),$TopY,floor($X),$BottomY,$Color);
  4451. $LastColor = $Color;
  4452. }
  4453. if ( $Y == VOID )
  4454. { $LastY = NULL; }
  4455. else
  4456. { $LastX = $X; $LastY = $Y; }
  4457. $X = $X + $XStep;
  4458. }
  4459. $YPos = $YPos + $CaptionHeight + $SerieSpacing;
  4460. }
  4461. else
  4462. {
  4463. if ( $Caption )
  4464. {
  4465. $StartY = floor($this->GraphAreaY1-$CaptionWidth+$XMargin-$CaptionMargin);
  4466. $EndY = floor($this->GraphAreaY1-$CaptionMargin+$XMargin);
  4467. if ( $CaptionLine )
  4468. {
  4469. $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  4470. if ( $CaptionBox ) { $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
  4471. $this->drawLine($XPos+($CaptionHeight/2),$StartY+2,$XPos+($CaptionHeight/2),$EndY-2,$CaptionSettings);
  4472. }
  4473. else
  4474. $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB));
  4475. }
  4476. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4477. $Y = $this->GraphAreaY1 + $XMargin;
  4478. $TopX = $XPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
  4479. $BottomX = $XPos + ($CaptionHeight/2) + ($DerivativeHeight/2);
  4480. $StartY = floor($this->GraphAreaY1+$XMargin);
  4481. $EndY = floor($this->GraphAreaY2-$XMargin);
  4482. if ( $DrawBackground ) { $this->drawFilledRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
  4483. if ( $DrawBorder ) { $this->drawRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4484. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4485. $RestoreShadow = $this->Shadow;
  4486. $this->Shadow = FALSE;
  4487. /* Determine the Max slope index */
  4488. $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
  4489. foreach($PosArray as $Key => $X)
  4490. {
  4491. if ( $X != VOID && $LastX != NULL )
  4492. { $Slope = ($X - $LastX); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }
  4493. if ( $X == VOID )
  4494. { $LastX = NULL; }
  4495. else
  4496. { $LastX = $X; }
  4497. }
  4498. $LastX = NULL; $LastY = NULL; $LastColor = NULL;
  4499. foreach($PosArray as $Key => $X)
  4500. {
  4501. if ( $X != VOID && $LastX != NULL )
  4502. {
  4503. $Slope = ($X - $LastX);
  4504. if ( $Slope >= 0 )
  4505. {
  4506. $SlopeIndex = (100 / $MaxSlope) * $Slope;
  4507. $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
  4508. $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
  4509. $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
  4510. }
  4511. elseif ( $Slope < 0 )
  4512. {
  4513. $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
  4514. $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
  4515. $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
  4516. $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
  4517. }
  4518. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  4519. if ( $ShadedSlopeBox && $LastColor != NULL )
  4520. {
  4521. $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  4522. $this->drawGradientArea($TopX,$LastY,$BottomX,$Y,DIRECTION_VERTICAL,$GradientSettings);
  4523. }
  4524. elseif ( !$ShadedSlopeBox || $LastColor == NULL )
  4525. $this->drawFilledRectangle($TopX,floor($LastY),$BottomX,floor($Y),$Color);
  4526. $LastColor = $Color;
  4527. }
  4528. if ( $X == VOID )
  4529. { $LastX = NULL; }
  4530. else
  4531. { $LastX = $X; $LastY = $Y; }
  4532. $Y = $Y + $XStep;
  4533. }
  4534. $XPos = $XPos + $CaptionHeight + $SerieSpacing;
  4535. }
  4536. $this->Shadow = $RestoreShadow;
  4537. }
  4538. }
  4539. }
  4540. /* Draw the line of best fit */
  4541. function drawBestFit($Format="")
  4542. {
  4543. $OverrideTicks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  4544. $OverrideR = isset($Format["R"]) ? $Format["R"] : VOID;
  4545. $OverrideG = isset($Format["G"]) ? $Format["G"] : VOID;
  4546. $OverrideB = isset($Format["B"]) ? $Format["B"] : VOID;
  4547. $OverrideAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : VOID;
  4548. $Data = $this->DataSet->getData();
  4549. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4550. foreach($Data["Series"] as $SerieName => $Serie)
  4551. {
  4552. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4553. {
  4554. 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"]; }
  4555. if ( $OverrideTicks == NULL ) { $Ticks = $Serie["Ticks"]; } else { $Ticks = $OverrideTicks; }
  4556. if ( $OverrideAlpha == VOID ) { $Alpha = $Serie["Color"]["Alpha"]; } else { $Alpha = $OverrideAlpha; }
  4557. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks);
  4558. $AxisID = $Serie["Axis"];
  4559. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  4560. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4561. {
  4562. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4563. $X = $this->GraphAreaX1 + $XMargin;
  4564. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4565. $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
  4566. foreach($PosArray as $Key => $Y)
  4567. {
  4568. if ( $Y != VOID )
  4569. {
  4570. $Sxy = $Sxy + $X*$Y;
  4571. $Sx = $Sx + $X;
  4572. $Sy = $Sy + $Y;
  4573. $Sxx = $Sxx + $X*$X;
  4574. }
  4575. $X = $X + $XStep;
  4576. }
  4577. $n = count($this->DataSet->stripVOID($PosArray)); //$n = count($PosArray);
  4578. $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
  4579. $B = (($Sy)-($M*$Sx))/($n);
  4580. $X1 = $this->GraphAreaX1 + $XMargin;
  4581. $Y1 = $M * $X1 + $B;
  4582. $X2 = $this->GraphAreaX2 - $XMargin;
  4583. $Y2 = $M * $X2 + $B;
  4584. if ( $Y1 < $this->GraphAreaY1 ) { $X1 = $X1 + ($this->GraphAreaY1-$Y1); $Y1 = $this->GraphAreaY1; }
  4585. if ( $Y1 > $this->GraphAreaY2 ) { $X1 = $X1 + ($Y1-$this->GraphAreaY2); $Y1 = $this->GraphAreaY2; }
  4586. if ( $Y2 < $this->GraphAreaY1 ) { $X2 = $X2 - ($this->GraphAreaY1-$Y2); $Y2 = $this->GraphAreaY1; }
  4587. if ( $Y2 > $this->GraphAreaY2 ) { $X2 = $X2 - ($Y2-$this->GraphAreaY2); $Y2 = $this->GraphAreaY2; }
  4588. $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
  4589. }
  4590. else
  4591. {
  4592. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4593. $Y = $this->GraphAreaY1 + $XMargin;
  4594. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4595. $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
  4596. foreach($PosArray as $Key => $X)
  4597. {
  4598. if ( $X != VOID )
  4599. {
  4600. $Sxy = $Sxy + $X*$Y;
  4601. $Sx = $Sx + $Y;
  4602. $Sy = $Sy + $X;
  4603. $Sxx = $Sxx + $Y*$Y;
  4604. }
  4605. $Y = $Y + $YStep;
  4606. }
  4607. $n = count($this->DataSet->stripVOID($PosArray)); //$n = count($PosArray);
  4608. $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
  4609. $B = (($Sy)-($M*$Sx))/($n);
  4610. $Y1 = $this->GraphAreaY1 + $XMargin;
  4611. $X1 = $M * $Y1 + $B;
  4612. $Y2 = $this->GraphAreaY2 - $XMargin;
  4613. $X2 = $M * $Y2 + $B;
  4614. if ( $X1 < $this->GraphAreaX1 ) { $Y1 = $Y1 + ($this->GraphAreaX1-$X1); $X1 = $this->GraphAreaX1; }
  4615. if ( $X1 > $this->GraphAreaX2 ) { $Y1 = $Y1 + ($X1-$this->GraphAreaX2); $X1 = $this->GraphAreaX2; }
  4616. if ( $X2 < $this->GraphAreaX1 ) { $Y2 = $Y2 - ($this->GraphAreaY1-$X2); $X2 = $this->GraphAreaX1; }
  4617. if ( $X2 > $this->GraphAreaX2 ) { $Y2 = $Y2 - ($X2-$this->GraphAreaX2); $X2 = $this->GraphAreaX2; }
  4618. $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
  4619. }
  4620. }
  4621. }
  4622. }
  4623. /* Write labels */
  4624. function writeLabel($SeriesName,$Indexes,$Format="")
  4625. {
  4626. $OverrideTitle = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
  4627. $ForceLabels = isset($Format["ForceLabels"]) ? $Format["ForceLabels"] : NULL;
  4628. $DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
  4629. $DrawVerticalLine = isset($Format["DrawVerticalLine"]) ? $Format["DrawVerticalLine"] : FALSE;
  4630. $VerticalLineR = isset($Format["VerticalLineR"]) ? $Format["VerticalLineR"] : 0;
  4631. $VerticalLineG = isset($Format["VerticalLineG"]) ? $Format["VerticalLineG"] : 0;
  4632. $VerticalLineB = isset($Format["VerticalLineB"]) ? $Format["VerticalLineB"] : 0;
  4633. $VerticalLineAlpha = isset($Format["VerticalLineAlpha"]) ? $Format["VerticalLineAlpha"] : 40;
  4634. $VerticalLineTicks = isset($Format["VerticalLineTicks"]) ? $Format["VerticalLineTicks"] : 2;
  4635. $Data = $this->DataSet->getData();
  4636. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4637. if ( !is_array($Indexes) ) { $Index = $Indexes; $Indexes = ""; $Indexes[] = $Index; }
  4638. if ( !is_array($SeriesName) ) { $SerieName = $SeriesName; $SeriesName = ""; $SeriesName[] = $SerieName; }
  4639. if ( $ForceLabels != NULL && !is_array($ForceLabels) ) { $ForceLabel = $ForceLabels; $ForceLabels = ""; $ForceLabels[] = $ForceLabel; }
  4640. foreach ($Indexes as $Key => $Index)
  4641. {
  4642. $Series = "";
  4643. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4644. {
  4645. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4646. $X = $this->GraphAreaX1 + $XMargin + $Index * $XStep;
  4647. 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)); }
  4648. $MinY = $this->GraphAreaY2;
  4649. foreach ($SeriesName as $iKey => $SerieName)
  4650. {
  4651. if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
  4652. {
  4653. $AxisID = $Data["Series"][$SerieName]["Axis"];
  4654. $XAxisMode = $Data["XAxisDisplay"];
  4655. $XAxisFormat = $Data["XAxisFormat"];
  4656. $XAxisUnit = $Data["XAxisUnit"];
  4657. $AxisMode = $Data["Axis"][$AxisID]["Display"];
  4658. $AxisFormat = $Data["Axis"][$AxisID]["Format"];
  4659. $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
  4660. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4661. $XLabel = $this->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index],$XAxisMode,$XAxisFormat,$XAxisUnit);
  4662. else
  4663. $XLabel = "";
  4664. if ( $OverrideTitle != NULL)
  4665. $Description = $OverrideTitle;
  4666. elseif ( count($SeriesName) == 1 )
  4667. {
  4668. $Description = $Data["Series"][$SerieName]["Description"]." - ".$XLabel;
  4669. }
  4670. elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4671. $Description = $XLabel;
  4672. $Serie = "";
  4673. $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
  4674. $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
  4675. $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
  4676. $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
  4677. if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
  4678. $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
  4679. else
  4680. $SerieOffset = 0;
  4681. $Value = $Data["Series"][$SerieName]["Data"][$Index];
  4682. if ( $Value == VOID ) { $Value = "NaN"; }
  4683. if ( $ForceLabels != NULL )
  4684. $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
  4685. else
  4686. $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
  4687. if ( $this->LastChartLayout == CHART_LAST_LAYOUT_STACKED )
  4688. {
  4689. if ( $Value >=0 ) { $LookFor = "+"; } else { $LookFor = "-"; }
  4690. $Value = 0; $Done = FALSE;
  4691. foreach($Data["Series"] as $Name => $SerieLookup)
  4692. {
  4693. if ( $SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done )
  4694. {
  4695. if ( isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID )
  4696. {
  4697. if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+" ) { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; }
  4698. if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-" ) { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; }
  4699. if ($Name == $SerieName ) { $Done = TRUE; }
  4700. }
  4701. }
  4702. }
  4703. }
  4704. $X = floor($this->GraphAreaX1 + $XMargin + $Index * $XStep + $SerieOffset);
  4705. $Y = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
  4706. if ($Y < $MinY) { $MinY = $Y; }
  4707. if ( $DrawPoint == LABEL_POINT_CIRCLE )
  4708. $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4709. elseif ( $DrawPoint == LABEL_POINT_BOX )
  4710. $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4711. $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
  4712. }
  4713. }
  4714. $this->drawLabelBox($X,$MinY-3,$Description,$Series,$Format);
  4715. }
  4716. else
  4717. {
  4718. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4719. $Y = $this->GraphAreaY1 + $XMargin + $Index * $XStep;
  4720. 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)); }
  4721. $MinX = $this->GraphAreaX2;
  4722. foreach ($SeriesName as $Key => $SerieName)
  4723. {
  4724. if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
  4725. {
  4726. $AxisID = $Data["Series"][$SerieName]["Axis"];
  4727. $XAxisMode = $Data["XAxisDisplay"];
  4728. $XAxisFormat = $Data["XAxisFormat"];
  4729. $XAxisUnit = $Data["XAxisUnit"];
  4730. $AxisMode = $Data["Axis"][$AxisID]["Display"];
  4731. $AxisFormat = $Data["Axis"][$AxisID]["Format"];
  4732. $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
  4733. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4734. $XLabel = $this->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index],$XAxisMode,$XAxisFormat,$XAxisUnit);
  4735. else
  4736. $XLabel = "";
  4737. if ( $OverrideTitle != NULL)
  4738. $Description = $OverrideTitle;
  4739. elseif ( count($SeriesName) == 1 )
  4740. {
  4741. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4742. $Description = $Data["Series"][$SerieName]["Description"]." - ".$XLabel;
  4743. }
  4744. elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4745. $Description = $XLabel;
  4746. $Serie = "";
  4747. if ( isset($Data["Extended"]["Palette"][$Index] ) )
  4748. {
  4749. $Serie["R"] = $Data["Extended"]["Palette"][$Index]["R"];
  4750. $Serie["G"] = $Data["Extended"]["Palette"][$Index]["G"];
  4751. $Serie["B"] = $Data["Extended"]["Palette"][$Index]["B"];
  4752. $Serie["Alpha"] = $Data["Extended"]["Palette"][$Index]["Alpha"];
  4753. }
  4754. else
  4755. {
  4756. $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
  4757. $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
  4758. $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
  4759. $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
  4760. }
  4761. if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
  4762. $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
  4763. else
  4764. $SerieOffset = 0;
  4765. $Value = $Data["Series"][$SerieName]["Data"][$Index];
  4766. if ( $ForceLabels != NULL )
  4767. $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
  4768. else
  4769. $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
  4770. if ( $Value == VOID ) { $Value = "NaN"; }
  4771. if ( $this->LastChartLayout == CHART_LAST_LAYOUT_STACKED )
  4772. {
  4773. if ( $Value >=0 ) { $LookFor = "+"; } else { $LookFor = "-"; }
  4774. $Value = 0; $Done = FALSE;
  4775. foreach($Data["Series"] as $Name => $SerieLookup)
  4776. {
  4777. if ( $SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done )
  4778. {
  4779. if ( isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID )
  4780. {
  4781. if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+" ) { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; }
  4782. if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-" ) { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; }
  4783. if ($Name == $SerieName ) { $Done = TRUE; }
  4784. }
  4785. }
  4786. }
  4787. }
  4788. $X = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
  4789. $Y = floor($this->GraphAreaY1 + $XMargin + $Index * $XStep + $SerieOffset);
  4790. if ($X < $MinX) { $MinX = $X; }
  4791. if ( $DrawPoint == LABEL_POINT_CIRCLE )
  4792. $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4793. elseif ( $DrawPoint == LABEL_POINT_BOX )
  4794. $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4795. $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
  4796. }
  4797. }
  4798. $this->drawLabelBox($MinX,$Y-3,$Description,$Series,$Format);
  4799. }
  4800. }
  4801. }
  4802. /* Draw a label box */
  4803. function drawLabelBox($X,$Y,$Title,$Captions,$Format="")
  4804. {
  4805. $NoTitle = isset($Format["NoTitle"]) ? $Format["NoTitle"] : NULL;
  4806. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 50;
  4807. $DrawSerieColor = isset($Format["DrawSerieColor"]) ? $Format["DrawSerieColor"] : TRUE;
  4808. $SerieR = isset($Format["SerieR"]) ? $Format["SerieR"] : NULL;
  4809. $SerieG = isset($Format["SerieG"]) ? $Format["SerieG"] : NULL;
  4810. $SerieB = isset($Format["SerieB"]) ? $Format["SerieB"] : NULL;
  4811. $SerieAlpha = isset($Format["SerieAlpha"]) ? $Format["SerieAlpha"] : NULL;
  4812. $SerieBoxSize = isset($Format["SerieBoxSize"]) ? $Format["SerieBoxSize"] : 6;
  4813. $SerieBoxSpacing = isset($Format["SerieBoxSpacing"]) ? $Format["SerieBoxSpacing"] : 4;
  4814. $VerticalMargin = isset($Format["VerticalMargin"]) ? $Format["VerticalMargin"] : 10;
  4815. $HorizontalMargin = isset($Format["HorizontalMargin"]) ? $Format["HorizontalMargin"] : 8;
  4816. $R = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
  4817. $G = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
  4818. $B = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
  4819. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
  4820. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  4821. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  4822. $TitleMode = isset($Format["TitleMode"]) ? $Format["TitleMode"] : LABEL_TITLE_NOBACKGROUND;
  4823. $TitleR = isset($Format["TitleR"]) ? $Format["TitleR"] : $R;
  4824. $TitleG = isset($Format["TitleG"]) ? $Format["TitleG"] : $G;
  4825. $TitleB = isset($Format["TitleB"]) ? $Format["TitleB"] : $B;
  4826. $TitleAlpha = isset($Format["TitleAlpha"]) ? $Format["TitleAlpha"] : 100;
  4827. $TitleBackgroundR = isset($Format["TitleBackgroundR"]) ? $Format["TitleBackgroundR"] : 0;
  4828. $TitleBackgroundG = isset($Format["TitleBackgroundG"]) ? $Format["TitleBackgroundG"] : 0;
  4829. $TitleBackgroundB = isset($Format["TitleBackgroundB"]) ? $Format["TitleBackgroundB"] : 0;
  4830. $TitleBackgroundAlpha = isset($Format["TitleBackgroundAlpha"]) ? $Format["TitleBackgroundAlpha"] : 100;
  4831. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  4832. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  4833. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  4834. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 220;
  4835. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 220;
  4836. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 220;
  4837. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 100;
  4838. if ( !$DrawSerieColor ) { $SerieBoxSize = 0; $SerieBoxSpacing = 0; }
  4839. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Title);
  4840. $TitleWidth = ($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2;
  4841. $TitleHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);
  4842. if ( $NoTitle ) { $TitleWidth = 0; $TitleHeight = 0; }
  4843. $CaptionWidth = 0; $CaptionHeight = -$HorizontalMargin;
  4844. foreach($Captions as $Key =>$Caption)
  4845. {
  4846. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Caption["Caption"]);
  4847. $CaptionWidth = max($CaptionWidth,($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2);
  4848. $CaptionHeight = $CaptionHeight + max(($TxtPos[0]["Y"] - $TxtPos[2]["Y"]),($SerieBoxSize+2)) + $HorizontalMargin;
  4849. }
  4850. if ( $CaptionHeight <= 5 ) { $CaptionHeight = $CaptionHeight + $HorizontalMargin/2; }
  4851. if ( $DrawSerieColor ) { $CaptionWidth = $CaptionWidth + $SerieBoxSize + $SerieBoxSpacing; }
  4852. $BoxWidth = max($BoxWidth,$TitleWidth,$CaptionWidth);
  4853. $XMin = $X - 5 - floor(($BoxWidth-10) / 2);
  4854. $XMax = $X + 5 + floor(($BoxWidth-10) / 2);
  4855. $RestoreShadow = $this->Shadow;
  4856. if ( $this->Shadow == TRUE )
  4857. {
  4858. $this->Shadow = FALSE;
  4859. $Poly = "";
  4860. $Poly[] = $X+$this->ShadowX; $Poly[] = $Y+$this->ShadowX;
  4861. $Poly[] = $X+5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4862. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4863. if ( $NoTitle )
  4864. {
  4865. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
  4866. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
  4867. }
  4868. else
  4869. {
  4870. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
  4871. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
  4872. }
  4873. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4874. $Poly[] = $X-5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4875. $this->drawPolygon($Poly,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  4876. }
  4877. /* Draw the background */
  4878. $GradientSettings = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$BoxAlpha);
  4879. if ( $NoTitle )
  4880. $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
  4881. else
  4882. $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
  4883. $Poly = ""; $Poly[] = $X; $Poly[] = $Y; $Poly[] = $X-5; $Poly[] = $Y-5; $Poly[] = $X+5; $Poly[] = $Y-5;
  4884. $this->drawPolygon($Poly,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB,"Alpha"=>$BoxAlpha,"NoBorder"=>TRUE));
  4885. /* Outer border */
  4886. $OuterBorderColor = $this->allocateColor($this->Picture,100,100,100,$BoxAlpha);
  4887. imageline($this->Picture,$XMin,$Y-5,$X-5,$Y-5,$OuterBorderColor);
  4888. imageline($this->Picture,$X,$Y,$X-5,$Y-5,$OuterBorderColor);
  4889. imageline($this->Picture,$X,$Y,$X+5,$Y-5,$OuterBorderColor);
  4890. imageline($this->Picture,$X+5,$Y-5,$XMax,$Y-5,$OuterBorderColor);
  4891. if ( $NoTitle )
  4892. {
  4893. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin,$Y-5,$OuterBorderColor);
  4894. imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5,$OuterBorderColor);
  4895. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$OuterBorderColor);
  4896. }
  4897. else
  4898. {
  4899. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin,$Y-5,$OuterBorderColor);
  4900. imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5,$OuterBorderColor);
  4901. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$OuterBorderColor);
  4902. }
  4903. /* Inner border */
  4904. $InnerBorderColor = $this->allocateColor($this->Picture,255,255,255,$BoxAlpha);
  4905. imageline($this->Picture,$XMin+1,$Y-6,$X-5,$Y-6,$InnerBorderColor);
  4906. imageline($this->Picture,$X,$Y-1,$X-5,$Y-6,$InnerBorderColor);
  4907. imageline($this->Picture,$X,$Y-1,$X+5,$Y-6,$InnerBorderColor);
  4908. imageline($this->Picture,$X+5,$Y-6,$XMax-1,$Y-6,$InnerBorderColor);
  4909. if ( $NoTitle )
  4910. {
  4911. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin+1,$Y-6,$InnerBorderColor);
  4912. imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-6,$InnerBorderColor);
  4913. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$InnerBorderColor);
  4914. }
  4915. else
  4916. {
  4917. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin+1,$Y-6,$InnerBorderColor);
  4918. imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-6,$InnerBorderColor);
  4919. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$InnerBorderColor);
  4920. }
  4921. /* Draw the separator line */
  4922. if ( $TitleMode == LABEL_TITLE_NOBACKGROUND && !$NoTitle )
  4923. {
  4924. $YPos = $Y-7-$CaptionHeight-$HorizontalMargin-$HorizontalMargin/2;
  4925. $XMargin = $VerticalMargin / 2;
  4926. $this->drawLine($XMin+$XMargin,$YPos+1,$XMax-$XMargin,$YPos+1,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB,"Alpha"=>$BoxAlpha));
  4927. $this->drawLine($XMin+$XMargin,$YPos,$XMax-$XMargin,$YPos,array("R"=>$GradientStartR,"G"=>$GradientStartG,"B"=>$GradientStartB,"Alpha"=>$BoxAlpha));
  4928. }
  4929. elseif ( $TitleMode == LABEL_TITLE_BACKGROUND )
  4930. {
  4931. $this->drawFilledRectangle($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2,array("R"=>$TitleBackgroundR,"G"=>$TitleBackgroundG,"B"=>$TitleBackgroundB,"Alpha"=>$BoxAlpha));
  4932. imageline($this->Picture,$XMin+1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$XMax-1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$InnerBorderColor);
  4933. }
  4934. /* Write the description */
  4935. if ( !$NoTitle )
  4936. $this->drawText($XMin+$VerticalMargin,$Y-7-$CaptionHeight-$HorizontalMargin*2,$Title,array("Align"=>TEXT_ALIGN_BOTTOMLEFT,"R"=>$TitleR,"G"=>$TitleG,"B"=>$TitleB));
  4937. /* Write the value */
  4938. $YPos = $Y-5-$HorizontalMargin; $XPos = $XMin+$VerticalMargin+$SerieBoxSize+$SerieBoxSpacing;
  4939. foreach($Captions as $Key => $Caption)
  4940. {
  4941. $CaptionTxt = $Caption["Caption"];
  4942. $TxtPos = $this->getTextBox($XPos,$YPos,$FontName,$FontSize,0,$CaptionTxt);
  4943. $CaptionHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);
  4944. /* Write the serie color if needed */
  4945. if ( $DrawSerieColor )
  4946. {
  4947. $BoxSettings = array("R"=>$Caption["Format"]["R"],"G"=>$Caption["Format"]["G"],"B"=>$Caption["Format"]["B"],"Alpha"=>$Caption["Format"]["Alpha"],"BorderR"=>0,"BorderG"=>0,"BorderB"=>0);
  4948. $this->drawFilledRectangle($XMin+$VerticalMargin,$YPos-$SerieBoxSize,$XMin+$VerticalMargin+$SerieBoxSize,$YPos,$BoxSettings);
  4949. }
  4950. $this->drawText($XPos,$YPos,$CaptionTxt,array("Align"=>TEXT_ALIGN_BOTTOMLEFT));
  4951. $YPos = $YPos - $CaptionHeight - $HorizontalMargin;
  4952. }
  4953. $this->Shadow = $RestoreShadow;
  4954. }
  4955. /* Draw a basic shape */
  4956. function drawShape($X,$Y,$Shape,$PlotSize,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha)
  4957. {
  4958. if ( $Shape == SERIE_SHAPE_FILLEDCIRCLE )
  4959. {
  4960. if ( $PlotBorder ) { $this->drawFilledCircle($X,$Y,$PlotSize+$BorderSize,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4961. $this->drawFilledCircle($X,$Y,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4962. }
  4963. elseif ( $Shape == SERIE_SHAPE_FILLEDSQUARE )
  4964. {
  4965. 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)); }
  4966. $this->drawFilledRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4967. }
  4968. elseif ( $Shape == SERIE_SHAPE_FILLEDTRIANGLE )
  4969. {
  4970. if ( $PlotBorder )
  4971. {
  4972. $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize-$BorderSize; $Pos[]=$X-$PlotSize-$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize; $Pos[]=$X+$PlotSize+$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize;
  4973. $this->drawPolygon($Pos,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha));
  4974. }
  4975. $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X-$PlotSize; $Pos[]=$Y+$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y+$PlotSize;
  4976. $this->drawPolygon($Pos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4977. }
  4978. elseif ( $Shape == SERIE_SHAPE_TRIANGLE )
  4979. {
  4980. $this->drawLine($X,$Y-$PlotSize,$X-$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4981. $this->drawLine($X-$PlotSize,$Y+$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4982. $this->drawLine($X+$PlotSize,$Y+$PlotSize,$X,$Y-$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4983. }
  4984. elseif ( $Shape == SERIE_SHAPE_SQUARE )
  4985. $this->drawRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4986. elseif ( $Shape == SERIE_SHAPE_CIRCLE )
  4987. $this->drawCircle($X,$Y,$PlotSize,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4988. elseif ( $Shape == SERIE_SHAPE_DIAMOND )
  4989. {
  4990. $Pos = ""; $Pos[]=$X-$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize;
  4991. $this->drawPolygon($Pos,array("NoFill"=>TRUE,"BorderR"=>$R,"BorderG"=>$G,"BorderB"=>$B,"BorderAlpha"=>$Alpha));
  4992. }
  4993. elseif ( $Shape == SERIE_SHAPE_FILLEDDIAMOND )
  4994. {
  4995. if ( $PlotBorder )
  4996. {
  4997. $Pos = ""; $Pos[]=$X-$PlotSize-$BorderSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize-$BorderSize; $Pos[]=$X+$PlotSize+$BorderSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize+$BorderSize;
  4998. $this->drawPolygon($Pos,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha));
  4999. }
  5000. $Pos = ""; $Pos[]=$X-$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize;
  5001. $this->drawPolygon($Pos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5002. }
  5003. }
  5004. function drawPolygonChart($Points,$Format="")
  5005. {
  5006. $R = isset($Format["R"]) ? $Format["R"] : 0;
  5007. $G = isset($Format["G"]) ? $Format["G"] : 0;
  5008. $B = isset($Format["B"]) ? $Format["B"] : 0;
  5009. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  5010. $NoFill = isset($Format["NoFill"]) ? $Format["NoFill"] : FALSE;
  5011. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  5012. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  5013. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  5014. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  5015. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha / 2;
  5016. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  5017. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  5018. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  5019. $RestoreShadow = $this->Shadow;
  5020. $this->Shadow = FALSE;
  5021. $AllIntegers = TRUE;
  5022. for($i=0;$i<=count($Points)-2;$i=$i+2)
  5023. { if ( $this->getFirstDecimal($Points[$i+1]) != 0 ) { $AllIntegers = FALSE; } }
  5024. /* Convert polygon to segments */
  5025. $Segments = "";
  5026. for($i=2;$i<=count($Points)-2;$i=$i+2)
  5027. { $Segments[] = array("X1"=>$Points[$i-2],"Y1"=>$Points[$i-1],"X2"=>$Points[$i],"Y2"=>$Points[$i+1]); }
  5028. $Segments[] = array("X1"=>$Points[$i-2],"Y1"=>$Points[$i-1],"X2"=>$Points[0],"Y2"=>$Points[1]);
  5029. /* Simplify straight lines */
  5030. $Result = ""; $inHorizon = FALSE; $LastX = VOID;
  5031. foreach($Segments as $Key => $Pos)
  5032. {
  5033. if ( $Pos["Y1"] != $Pos["Y2"] )
  5034. {
  5035. if ( $inHorizon ) { $inHorizon = FALSE; $Result[] = array("X1"=>$LastX,"Y1"=>$Pos["Y1"],"X2"=>$Pos["X1"],"Y2"=>$Pos["Y1"]); }
  5036. $Result[] = array("X1"=>$Pos["X1"],"Y1"=>$Pos["Y1"],"X2"=>$Pos["X2"],"Y2"=>$Pos["Y2"]);
  5037. }
  5038. else { if ( !$inHorizon ) { $inHorizon = TRUE; $LastX = $Pos["X1"];} }
  5039. }
  5040. $Segments = $Result;
  5041. /* Do we have something to draw */
  5042. if ( $Segments == "" ) { return(0); }
  5043. /* For segments debugging purpose */
  5044. //foreach($Segments as $Key => $Pos)
  5045. // echo $Pos["X1"].",".$Pos["Y1"].",".$Pos["X2"].",".$Pos["Y2"]."\r\n";
  5046. /* Find out the min & max Y boundaries */
  5047. $MinY = OUT_OF_SIGHT; $MaxY = OUT_OF_SIGHT;
  5048. foreach($Segments as $Key => $Coords)
  5049. {
  5050. if ( $MinY == OUT_OF_SIGHT || $MinY > min($Coords["Y1"],$Coords["Y2"]) ) { $MinY = min($Coords["Y1"],$Coords["Y2"]); }
  5051. if ( $MaxY == OUT_OF_SIGHT || $MaxY < max($Coords["Y1"],$Coords["Y2"]) ) { $MaxY = max($Coords["Y1"],$Coords["Y2"]); }
  5052. }
  5053. if ( $AllIntegers ) { $YStep = 1; } else { $YStep = .5; }
  5054. $MinY = floor($MinY); $MaxY = floor($MaxY);
  5055. /* Scan each Y lines */
  5056. $DefaultColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  5057. $DebugLine = 0; $DebugColor = $this->allocateColor($this->Picture,255,0,0,100);
  5058. $MinY = floor($MinY); $MaxY = floor($MaxY); $YStep = 1;
  5059. if ( !$NoFill )
  5060. {
  5061. //if ( $DebugLine ) { $MinY = $DebugLine; $MaxY = $DebugLine; }
  5062. for($Y=$MinY;$Y<=$MaxY;$Y=$Y+$YStep)
  5063. {
  5064. $Intersections = ""; $LastSlope = NULL; $RestoreLast = "-";
  5065. foreach($Segments as $Key => $Coords)
  5066. {
  5067. $X1 = $Coords["X1"]; $X2 = $Coords["X2"]; $Y1 = $Coords["Y1"]; $Y2 = $Coords["Y2"];
  5068. if ( min($Y1,$Y2) <= $Y && max($Y1,$Y2) >= $Y )
  5069. {
  5070. if ( $Y1 == $Y2 )
  5071. { $X = $X1; }
  5072. else
  5073. { $X = $X1 + ( ($Y-$Y1)*$X2 - ($Y-$Y1)*$X1 ) / ($Y2-$Y1); }
  5074. $X = floor($X);
  5075. if ( $X2 == $X1 )
  5076. { $Slope = "!"; }
  5077. else
  5078. {
  5079. $SlopeC = ($Y2 - $Y1) / ($X2 - $X1);
  5080. if( $SlopeC == 0 )
  5081. { $Slope = "="; }
  5082. elseif( $SlopeC > 0 )
  5083. { $Slope = "+"; }
  5084. elseif ( $SlopeC < 0 )
  5085. { $Slope = "-"; }
  5086. }
  5087. if ( !is_array($Intersections) )
  5088. { $Intersections[] = $X; }
  5089. elseif( !in_array($X,$Intersections) )
  5090. { $Intersections[] = $X; }
  5091. elseif( in_array($X,$Intersections) )
  5092. {
  5093. if ($Y == $DebugLine) { echo $Slope."/".$LastSlope."(".$X.") "; }
  5094. if ( $Slope == "=" && $LastSlope == "-" ) { $Intersections[] = $X; }
  5095. if ( $Slope != $LastSlope && $LastSlope != "!" && $LastSlope != "=" ) { $Intersections[] = $X; }
  5096. if ( $Slope != $LastSlope && $LastSlope == "!" && $Slope == "+" ) { $Intersections[] = $X; }
  5097. }
  5098. if ( is_array($Intersections) && in_array($X,$Intersections) && $LastSlope == "=" && ($Slope == "-" )) { $Intersections[] = $X; }
  5099. $LastSlope = $Slope;
  5100. }
  5101. }
  5102. if ( $RestoreLast != "-" ) { $Intersections[] = $RestoreLast; echo "@".$Y."\r\n"; }
  5103. if ( is_array($Intersections) )
  5104. {
  5105. sort($Intersections);
  5106. if ($Y == $DebugLine) { print_r($Intersections); }
  5107. /* Remove NULL plots */
  5108. $Result = "";
  5109. for($i=0;$i<=count($Intersections)-1;$i=$i+2)
  5110. {
  5111. if ( isset($Intersections[$i+1]) )
  5112. { if ( $Intersections[$i] != $Intersections[$i+1] ) { $Result[] = $Intersections[$i]; $Result[] = $Intersections[$i+1]; } }
  5113. }
  5114. if ( is_array($Result) )
  5115. {
  5116. $Intersections = $Result;
  5117. $LastX = OUT_OF_SIGHT;
  5118. foreach($Intersections as $Key => $X)
  5119. {
  5120. if ( $LastX == OUT_OF_SIGHT )
  5121. $LastX = $X;
  5122. elseif ( $LastX != OUT_OF_SIGHT )
  5123. {
  5124. if ( $this->getFirstDecimal($LastX) > 1 ) { $LastX++; }
  5125. $Color = $DefaultColor;
  5126. if ( $Threshold != NULL )
  5127. {
  5128. foreach($Threshold as $Key => $Parameters)
  5129. {
  5130. if ( $Y <= $Parameters["MinX"] && $Y >= $Parameters["MaxX"])
  5131. {
  5132. if ( isset($Parameters["R"]) ) { $R = $Parameters["R"]; } else { $R = 0; }
  5133. if ( isset($Parameters["G"]) ) { $G = $Parameters["G"]; } else { $G = 0; }
  5134. if ( isset($Parameters["B"]) ) { $B = $Parameters["B"]; } else { $B = 0; }
  5135. if ( isset($Parameters["Alpha"]) ) { $Alpha = $Parameters["Alpha"]; } else { $Alpha = 100; }
  5136. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  5137. }
  5138. }
  5139. }
  5140. imageline($this->Picture,$LastX,$Y,$X,$Y,$Color);
  5141. if ( $Y == $DebugLine) { imageline($this->Picture,$LastX,$Y,$X,$Y,$DebugColor); }
  5142. $LastX = OUT_OF_SIGHT;
  5143. }
  5144. }
  5145. }
  5146. }
  5147. }
  5148. }
  5149. /* Draw the polygon border, if required */
  5150. if ( !$NoBorder)
  5151. {
  5152. foreach($Segments as $Key => $Coords)
  5153. $this->drawLine($Coords["X1"],$Coords["Y1"],$Coords["X2"],$Coords["Y2"],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Threshold"=>$Threshold));
  5154. }
  5155. $this->Shadow = $RestoreShadow;
  5156. }
  5157. /* Return the abscissa margin */
  5158. function getAbscissaMargin($Data)
  5159. {
  5160. foreach($Data["Axis"] as $AxisID => $Values) { if ( $Values["Identity"] == AXIS_X ) { return($Values["Margin"]); } }
  5161. return(0);
  5162. }
  5163. }
  5164. ?>