pDraw.class.php

File

inc/pchart/pchart/class/pDraw.class.php
View source
  1. /*
  2. pDraw - class extension with drawing methods
  3. Version : 2.1.4
  4. Made by : Jean-Damien POGOLOTTI
  5. Last Update : 19/01/2014
  6. This file can be distributed under the license you can find at :
  7. http://www.pchart.net/license
  8. You can find the whole class documentation on the pChart web site.
  9. */
  10. define("DIRECTION_VERTICAL" , 690001);
  11. define("DIRECTION_HORIZONTAL" , 690002);
  12. define("SCALE_POS_LEFTRIGHT" , 690101);
  13. define("SCALE_POS_TOPBOTTOM" , 690102);
  14. define("SCALE_MODE_FLOATING" , 690201);
  15. define("SCALE_MODE_START0" , 690202);
  16. define("SCALE_MODE_ADDALL" , 690203);
  17. define("SCALE_MODE_ADDALL_START0" , 690204);
  18. define("SCALE_MODE_MANUAL" , 690205);
  19. define("SCALE_SKIP_NONE" , 690301);
  20. define("SCALE_SKIP_SAME" , 690302);
  21. define("SCALE_SKIP_NUMBERS" , 690303);
  22. define("TEXT_ALIGN_TOPLEFT" , 690401);
  23. define("TEXT_ALIGN_TOPMIDDLE" , 690402);
  24. define("TEXT_ALIGN_TOPRIGHT" , 690403);
  25. define("TEXT_ALIGN_MIDDLELEFT" , 690404);
  26. define("TEXT_ALIGN_MIDDLEMIDDLE" , 690405);
  27. define("TEXT_ALIGN_MIDDLERIGHT" , 690406);
  28. define("TEXT_ALIGN_BOTTOMLEFT" , 690407);
  29. define("TEXT_ALIGN_BOTTOMMIDDLE" , 690408);
  30. define("TEXT_ALIGN_BOTTOMRIGHT" , 690409);
  31. define("POSITION_TOP" , 690501);
  32. define("POSITION_BOTTOM" , 690502);
  33. define("LABEL_POS_LEFT" , 690601);
  34. define("LABEL_POS_CENTER" , 690602);
  35. define("LABEL_POS_RIGHT" , 690603);
  36. define("LABEL_POS_TOP" , 690604);
  37. define("LABEL_POS_BOTTOM" , 690605);
  38. define("LABEL_POS_INSIDE" , 690606);
  39. define("LABEL_POS_OUTSIDE" , 690607);
  40. define("ORIENTATION_HORIZONTAL" , 690701);
  41. define("ORIENTATION_VERTICAL" , 690702);
  42. define("ORIENTATION_AUTO" , 690703);
  43. define("LEGEND_NOBORDER" , 690800);
  44. define("LEGEND_BOX" , 690801);
  45. define("LEGEND_ROUND" , 690802);
  46. define("LEGEND_VERTICAL" , 690901);
  47. define("LEGEND_HORIZONTAL" , 690902);
  48. define("LEGEND_FAMILY_BOX" , 691051);
  49. define("LEGEND_FAMILY_CIRCLE" , 691052);
  50. define("LEGEND_FAMILY_LINE" , 691053);
  51. define("DISPLAY_AUTO" , 691001);
  52. define("DISPLAY_MANUAL" , 691002);
  53. define("LABELING_ALL" , 691011);
  54. define("LABELING_DIFFERENT" , 691012);
  55. define("BOUND_MIN" , 691021);
  56. define("BOUND_MAX" , 691022);
  57. define("BOUND_BOTH" , 691023);
  58. define("BOUND_LABEL_POS_TOP" , 691031);
  59. define("BOUND_LABEL_POS_BOTTOM" , 691032);
  60. define("BOUND_LABEL_POS_AUTO" , 691033);
  61. define("CAPTION_LEFT_TOP" , 691041);
  62. define("CAPTION_RIGHT_BOTTOM" , 691042);
  63. define("GRADIENT_SIMPLE" , 691051);
  64. define("GRADIENT_EFFECT_CAN" , 691052);
  65. define("LABEL_TITLE_NOBACKGROUND" , 691061);
  66. define("LABEL_TITLE_BACKGROUND" , 691062);
  67. define("LABEL_POINT_NONE" , 691071);
  68. define("LABEL_POINT_CIRCLE" , 691072);
  69. define("LABEL_POINT_BOX" , 691073);
  70. define("ZONE_NAME_ANGLE_AUTO" , 691081);
  71. define("PI" , 3.14159265);
  72. define("ALL" , 69);
  73. define("NONE" , 31);
  74. define("AUTO" , 690000);
  75. define("OUT_OF_SIGHT" , -10000000000000);
  76. class pDraw
  77. {
  78. /* Returns the number of drawable series */
  79. function countDrawableSeries()
  80. {
  81. $Results = 0;
  82. $Data = $this->DataSet->getData();
  83. foreach($Data["Series"] as $SerieName => $Serie)
  84. { if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] ) { $Results++; } }
  85. return($Results);
  86. }
  87. /* Fix box coordinates */
  88. function fixBoxCoordinates($Xa,$Ya,$Xb,$Yb)
  89. {
  90. $X1 = min($Xa,$Xb); $Y1 = min($Ya,$Yb);
  91. $X2 = max($Xa,$Xb); $Y2 = max($Ya,$Yb);
  92. return(array($X1,$Y1,$X2,$Y2));
  93. }
  94. /* Draw a polygon */
  95. function drawPolygon($Points,$Format="")
  96. {
  97. $R = isset($Format["R"]) ? $Format["R"] : 0;
  98. $G = isset($Format["G"]) ? $Format["G"] : 0;
  99. $B = isset($Format["B"]) ? $Format["B"] : 0;
  100. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  101. $NoFill = isset($Format["NoFill"]) ? $Format["NoFill"] : FALSE;
  102. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  103. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  104. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  105. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  106. $BorderAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $Alpha / 2;
  107. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  108. $SkipX = isset($Format["SkipX"]) ? $Format["SkipX"] : OUT_OF_SIGHT;
  109. $SkipY = isset($Format["SkipY"]) ? $Format["SkipY"] : OUT_OF_SIGHT;
  110. /* Calling the ImageFilledPolygon() function over the $Points array will round it */
  111. $Backup = $Points;
  112. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  113. if ( $SkipX != OUT_OF_SIGHT ) { $SkipX = floor($SkipX); }
  114. if ( $SkipY != OUT_OF_SIGHT ) { $SkipY = floor($SkipY); }
  115. $RestoreShadow = $this->Shadow;
  116. if ( !$NoFill )
  117. {
  118. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  119. {
  120. $this->Shadow = FALSE;
  121. for($i=0;$i<=count($Points)-1;$i=$i+2)
  122. { $Shadow[] = $Points[$i] + $this->ShadowX; $Shadow[] = $Points[$i+1] + $this->ShadowY; }
  123. $this->drawPolygon($Shadow,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"NoBorder"=>TRUE));
  124. }
  125. $FillColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  126. if ( count($Points) >= 6 )
  127. { ImageFilledPolygon($this->Picture,$Points,count($Points)/2,$FillColor); }
  128. }
  129. if ( !$NoBorder )
  130. {
  131. $Points = $Backup;
  132. if ( $NoFill )
  133. $BorderSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  134. else
  135. $BorderSettings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha);
  136. for($i=0;$i<=count($Points)-1;$i=$i+2)
  137. {
  138. if ( isset($Points[$i+2]) )
  139. {
  140. if ( !($Points[$i] == $Points[$i+2] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[$i+3] && $Points[$i+1] == $SkipY ) )
  141. $this->drawLine($Points[$i],$Points[$i+1],$Points[$i+2],$Points[$i+3],$BorderSettings);
  142. }
  143. else
  144. {
  145. if ( !($Points[$i] == $Points[0] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[1] && $Points[$i+1] == $SkipY ) )
  146. $this->drawLine($Points[$i],$Points[$i+1],$Points[0],$Points[1],$BorderSettings);
  147. }
  148. }
  149. }
  150. $this->Shadow = $RestoreShadow;
  151. }
  152. /* Apply AALias correction to the rounded box boundaries */
  153. function offsetCorrection($Value,$Mode)
  154. {
  155. $Value = round($Value,1);
  156. if ( $Value == 0 && $Mode == 1 ) { return(.9); }
  157. if ( $Value == 0 ) { return(0); }
  158. if ( $Mode == 1)
  159. { 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); }; }
  160. if ( $Mode == 2)
  161. { 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); }; }
  162. if ( $Mode == 3)
  163. { 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); }; }
  164. if ( $Mode == 4)
  165. { 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); }; }
  166. }
  167. /* Draw a rectangle with rounded corners */
  168. function drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  169. {
  170. $R = isset($Format["R"]) ? $Format["R"] : 0;
  171. $G = isset($Format["G"]) ? $Format["G"] : 0;
  172. $B = isset($Format["B"]) ? $Format["B"] : 0;
  173. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  174. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  175. if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1))/2); }
  176. if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1))/2); }
  177. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);
  178. if ( $Radius <= 0 ) { $this->drawRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }
  179. if ( $this->Antialias )
  180. {
  181. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
  182. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
  183. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
  184. $this->drawLine($X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
  185. }
  186. else
  187. {
  188. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  189. imageline($this->Picture,$X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
  190. imageline($this->Picture,$X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
  191. imageline($this->Picture,$X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
  192. imageline($this->Picture,$X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
  193. }
  194. $Step = 360 / (2 * PI * $Radius);
  195. for($i=0;$i<=90;$i=$i+$Step)
  196. {
  197. $X = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  198. $Y = sin(($i+180)*PI/180) * $Radius + $Y1 + $Radius;
  199. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  200. $X = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  201. $Y = sin(($i+90)*PI/180) * $Radius + $Y2 - $Radius;
  202. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  203. $X = cos($i*PI/180) * $Radius + $X2 - $Radius;
  204. $Y = sin($i*PI/180) * $Radius + $Y2 - $Radius;
  205. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  206. $X = cos(($i+270)*PI/180) * $Radius + $X2 - $Radius;
  207. $Y = sin(($i+270)*PI/180) * $Radius + $Y1 + $Radius;
  208. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  209. }
  210. }
  211. /* Draw a rectangle with rounded corners */
  212. function drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  213. {
  214. $R = isset($Format["R"]) ? $Format["R"] : 0;
  215. $G = isset($Format["G"]) ? $Format["G"] : 0;
  216. $B = isset($Format["B"]) ? $Format["B"] : 0;
  217. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  218. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  219. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  220. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  221. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  222. /* Temporary fix for AA issue */
  223. $Y1 = floor($Y1); $Y2 = floor($Y2); $X1 = floor($X1); $X2 = floor($X2);
  224. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  225. if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }
  226. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  227. if ( $X2 - $X1 < $Radius*2 ) { $Radius = floor((($X2-$X1))/4); }
  228. if ( $Y2 - $Y1 < $Radius*2 ) { $Radius = floor((($Y2-$Y1))/4); }
  229. $RestoreShadow = $this->Shadow;
  230. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  231. {
  232. $this->Shadow = FALSE;
  233. $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));
  234. }
  235. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);
  236. if ( $Radius <= 0 ) { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }
  237. $YTop = $Y1+$Radius;
  238. $YBottom = $Y2-$Radius;
  239. $Step = 360 / (2 * PI * $Radius);
  240. $Positions = ""; $Radius--; $MinY = ""; $MaxY = "";
  241. for($i=0;$i<=90;$i=$i+$Step)
  242. {
  243. $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  244. $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
  245. $Yp = floor(sin(($i+180)*PI/180) * $Radius + $YTop);
  246. if ( $MinY == "" || $Yp > $MinY ) { $MinY = $Yp; }
  247. if ( $Xp1 <= floor($X1) ) { $Xp1++; }
  248. if ( $Xp2 >= floor($X2) ) { $Xp2--; }
  249. $Xp1++;
  250. if ( !isset($Positions[$Yp]) )
  251. { $Positions[$Yp]["X1"] = $Xp1; $Positions[$Yp]["X2"] = $Xp2; }
  252. else
  253. { $Positions[$Yp]["X1"] = ($Positions[$Yp]["X1"]+$Xp1)/2; $Positions[$Yp]["X2"] = ($Positions[$Yp]["X2"]+$Xp2)/2; }
  254. $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  255. $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
  256. $Yp = floor(sin(($i+90)*PI/180) * $Radius + $YBottom);
  257. if ( $MaxY == "" || $Yp < $MaxY ) { $MaxY = $Yp; }
  258. if ( $Xp1 <= floor($X1) ) { $Xp1++; }
  259. if ( $Xp2 >= floor($X2) ) { $Xp2--; }
  260. $Xp1++;
  261. if ( !isset($Positions[$Yp]) )
  262. { $Positions[$Yp]["X1"] = $Xp1; $Positions[$Yp]["X2"] = $Xp2; }
  263. else
  264. { $Positions[$Yp]["X1"] = ($Positions[$Yp]["X1"]+$Xp1)/2; $Positions[$Yp]["X2"] = ($Positions[$Yp]["X2"]+$Xp2)/2; }
  265. }
  266. $ManualColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  267. foreach($Positions as $Yp => $Bounds)
  268. {
  269. $X1 = $Bounds["X1"]; $X1Dec = $this->getFirstDecimal($X1); if ( $X1Dec != 0 ) { $X1 = floor($X1)+1; }
  270. $X2 = $Bounds["X2"]; $X2Dec = $this->getFirstDecimal($X2); if ( $X2Dec != 0 ) { $X2 = floor($X2)-1; }
  271. imageline($this->Picture,$X1,$Yp,$X2,$Yp,$ManualColor);
  272. }
  273. $this->drawFilledRectangle($X1,$MinY+1,floor($X2),$MaxY-1,$Color);
  274. $Radius++;
  275. $this->drawRoundedRectangle($X1,$Y1,$X2+1,$Y2-1,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  276. $this->Shadow = $RestoreShadow;
  277. }
  278. /* Draw a rectangle with rounded corners */
  279. function drawRoundedFilledRectangle_deprecated($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  280. {
  281. $R = isset($Format["R"]) ? $Format["R"] : 0;
  282. $G = isset($Format["G"]) ? $Format["G"] : 0;
  283. $B = isset($Format["B"]) ? $Format["B"] : 0;
  284. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  285. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  286. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  287. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  288. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  289. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  290. if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }
  291. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  292. if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1)+2)/2); }
  293. if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1)+2)/2); }
  294. $RestoreShadow = $this->Shadow;
  295. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  296. {
  297. $this->Shadow = FALSE;
  298. $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));
  299. }
  300. if ( $this->getFirstDecimal($X2) >= 5 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  301. if ( $this->getFirstDecimal($X1) <= 5 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  302. if ( !$this->Antialias ) { $XOffset1 = 1; $XOffset2 = 1; }
  303. $YTop = floor($Y1+$Radius);
  304. $YBottom = floor($Y2-$Radius);
  305. $this->drawFilledRectangle($X1-$XOffset1,$YTop,$X2+$XOffset2,$YBottom,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE));
  306. $Step = 360 / (2 * PI * $Radius);
  307. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  308. $Color2 = $this->allocateColor($this->Picture,255,0,0,$Alpha);
  309. $Drawn = "";
  310. if ( $Alpha < 100 ) { $Drawn[$YTop] = FALSE; }
  311. if ( $Alpha < 100 ) { $Drawn[$YBottom] = TRUE; }
  312. for($i=0;$i<=90;$i=$i+$Step)
  313. {
  314. $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  315. $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
  316. $Yp = sin(($i+180)*PI/180) * $Radius + $YTop;
  317. if ( $this->getFirstDecimal($Xp1) > 5 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  318. if ( $this->getFirstDecimal($Xp2) > 5 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  319. if ( $this->getFirstDecimal($Yp) > 5 ) { $YOffset = 1; } else { $YOffset = 0; }
  320. if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
  321. imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);
  322. $Drawn[$Yp+$YOffset] = $Xp2;
  323. $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  324. $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
  325. $Yp = sin(($i+90)*PI/180) * $Radius + $YBottom;
  326. if ( $this->getFirstDecimal($Xp1) > 7 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  327. if ( $this->getFirstDecimal($Xp2) > 7 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  328. if ( $this->getFirstDecimal($Yp) > 5 ) { $YOffset = 1; } else { $YOffset = 0; }
  329. if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
  330. imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);
  331. $Drawn[$Yp+$YOffset] = $Xp2;
  332. }
  333. $this->drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  334. $this->Shadow = $RestoreShadow;
  335. }
  336. /* Draw a rectangle */
  337. function drawRectangle($X1,$Y1,$X2,$Y2,$Format="")
  338. {
  339. $R = isset($Format["R"]) ? $Format["R"] : 0;
  340. $G = isset($Format["G"]) ? $Format["G"] : 0;
  341. $B = isset($Format["B"]) ? $Format["B"] : 0;
  342. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  343. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  344. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;
  345. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  346. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  347. if ( $this->Antialias )
  348. {
  349. if ( $NoAngle )
  350. {
  351. $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  352. $this->drawLine($X2,$Y1+1,$X2,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  353. $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  354. $this->drawLine($X1,$Y1+1,$X1,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  355. }
  356. else
  357. {
  358. $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  359. $this->drawLine($X2,$Y1,$X2,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  360. $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  361. $this->drawLine($X1,$Y1,$X1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  362. }
  363. }
  364. else
  365. {
  366. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  367. imagerectangle($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
  368. }
  369. }
  370. /* Draw a filled rectangle */
  371. function drawFilledRectangle($X1,$Y1,$X2,$Y2,$Format="")
  372. {
  373. $R = isset($Format["R"]) ? $Format["R"] : 0;
  374. $G = isset($Format["G"]) ? $Format["G"] : 0;
  375. $B = isset($Format["B"]) ? $Format["B"] : 0;
  376. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  377. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  378. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  379. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  380. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
  381. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  382. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  383. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : NULL;
  384. $Dash = isset($Format["Dash"]) ? $Format["Dash"] : FALSE;
  385. $DashStep = isset($Format["DashStep"]) ? $Format["DashStep"] : 4;
  386. $DashR = isset($Format["DashR"]) ? $Format["DashR"] : 0;
  387. $DashG = isset($Format["DashG"]) ? $Format["DashG"] : 0;
  388. $DashB = isset($Format["DashB"]) ? $Format["DashB"] : 0;
  389. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  390. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  391. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  392. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  393. $RestoreShadow = $this->Shadow;
  394. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  395. {
  396. $this->Shadow = FALSE;
  397. $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));
  398. }
  399. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  400. if ( $NoAngle )
  401. {
  402. imagefilledrectangle($this->Picture,ceil($X1)+1,ceil($Y1),floor($X2)-1,floor($Y2),$Color);
  403. imageline($this->Picture,ceil($X1),ceil($Y1)+1,ceil($X1),floor($Y2)-1,$Color);
  404. imageline($this->Picture,floor($X2),ceil($Y1)+1,floor($X2),floor($Y2)-1,$Color);
  405. }
  406. else
  407. imagefilledrectangle($this->Picture,ceil($X1),ceil($Y1),floor($X2),floor($Y2),$Color);
  408. if ( $Dash )
  409. {
  410. if ( $BorderR != -1 ) { $iX1=$X1+1; $iY1=$Y1+1; $iX2=$X2-1; $iY2=$Y2-1; } else { $iX1=$X1; $iY1=$Y1; $iX2=$X2; $iY2=$Y2; }
  411. $Color = $this->allocateColor($this->Picture,$DashR,$DashG,$DashB,$Alpha);
  412. $Y=$iY1-$DashStep;
  413. for($X=$iX1; $X<=$iX2+($iY2-$iY1); $X=$X+$DashStep)
  414. {
  415. $Y=$Y+$DashStep;
  416. if ( $X > $iX2 ) { $Xa = $X-($X-$iX2); $Ya = $iY1+($X-$iX2); } else { $Xa = $X; $Ya = $iY1; }
  417. if ( $Y > $iY2 ) { $Xb = $iX1+($Y-$iY2); $Yb = $Y-($Y-$iY2); } else { $Xb = $iX1; $Yb = $Y; }
  418. imageline($this->Picture,$Xa,$Ya,$Xb,$Yb,$Color);
  419. }
  420. }
  421. if ( $this->Antialias && !$NoBorder )
  422. {
  423. if ( $X1 < ceil($X1) )
  424. {
  425. $AlphaA = $Alpha * (ceil($X1) - $X1);
  426. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  427. imageline($this->Picture,ceil($X1)-1,ceil($Y1),ceil($X1)-1,floor($Y2),$Color);
  428. }
  429. if ( $Y1 < ceil($Y1) )
  430. {
  431. $AlphaA = $Alpha * (ceil($Y1) - $Y1);
  432. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  433. imageline($this->Picture,ceil($X1),ceil($Y1)-1,floor($X2),ceil($Y1)-1,$Color);
  434. }
  435. if ( $X2 > floor($X2) )
  436. {
  437. $AlphaA = $Alpha * (.5-($X2 - floor($X2)));
  438. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  439. imageline($this->Picture,floor($X2)+1,ceil($Y1),floor($X2)+1,floor($Y2),$Color);
  440. }
  441. if ( $Y2 > floor($Y2) )
  442. {
  443. $AlphaA = $Alpha * (.5-($Y2 - floor($Y2)));
  444. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  445. imageline($this->Picture,ceil($X1),floor($Y2)+1,floor($X2),floor($Y2)+1,$Color);
  446. }
  447. }
  448. if ( $BorderR != -1 )
  449. $this->drawRectangle($X1,$Y1,$X2,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks,"NoAngle"=>$NoAngle));
  450. $this->Shadow = $RestoreShadow;
  451. }
  452. /* Draw a rectangular marker of the specified size */
  453. function drawRectangleMarker($X,$Y,$Format="")
  454. {
  455. $Size = isset($Format["Size"]) ? $Format["Size"] : 4;
  456. $HalfSize = floor($Size/2);
  457. $this->drawFilledRectangle($X-$HalfSize,$Y-$HalfSize,$X+$HalfSize,$Y+$HalfSize,$Format);
  458. }
  459. /* Drawn a spline based on the bezier function */
  460. function drawSpline($Coordinates,$Format="")
  461. {
  462. $R = isset($Format["R"]) ? $Format["R"] : 0;
  463. $G = isset($Format["G"]) ? $Format["G"] : 0;
  464. $B = isset($Format["B"]) ? $Format["B"] : 0;
  465. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  466. $Force = isset($Format["Force"]) ? $Format["Force"] : 30;
  467. $Forces = isset($Format["Forces"]) ? $Format["Forces"] : NULL;
  468. $ShowC = isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
  469. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  470. $PathOnly = isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
  471. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  472. $Cpt = NULL; $Mode = NULL; $Result = "";
  473. for($i=1;$i<=count($Coordinates)-1;$i++)
  474. {
  475. $X1 = $Coordinates[$i-1][0]; $Y1 = $Coordinates[$i-1][1];
  476. $X2 = $Coordinates[$i][0]; $Y2 = $Coordinates[$i][1];
  477. if ( $Forces != NULL ) { $Force = $Forces[$i]; }
  478. /* First segment */
  479. if ( $i == 1 )
  480. { $Xv1 = $X1; $Yv1 = $Y1; }
  481. else
  482. {
  483. $Angle1 = $this->getAngle($XLast,$YLast,$X1,$Y1);
  484. $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
  485. $XOff = cos($Angle2 * PI / 180) * $Force + $X1;
  486. $YOff = sin($Angle2 * PI / 180) * $Force + $Y1;
  487. $Xv1 = cos($Angle1 * PI / 180) * $Force + $XOff;
  488. $Yv1 = sin($Angle1 * PI / 180) * $Force + $YOff;
  489. }
  490. /* Last segment */
  491. if ( $i == count($Coordinates)-1 )
  492. { $Xv2 = $X2; $Yv2 = $Y2; }
  493. else
  494. {
  495. $Angle1 = $this->getAngle($X2,$Y2,$Coordinates[$i+1][0],$Coordinates[$i+1][1]);
  496. $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
  497. $XOff = cos(($Angle2+180) * PI / 180) * $Force + $X2;
  498. $YOff = sin(($Angle2+180) * PI / 180) * $Force + $Y2;
  499. $Xv2 = cos(($Angle1+180) * PI / 180) * $Force + $XOff;
  500. $Yv2 = sin(($Angle1+180) * PI / 180) * $Force + $YOff;
  501. }
  502. $Path = $this->drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format);
  503. if ($PathOnly) { $Result[] = $Path; }
  504. $XLast = $X1; $YLast = $Y1;
  505. }
  506. return($Result);
  507. }
  508. /* Draw a bezier curve with two controls points */
  509. function drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format="")
  510. {
  511. $R = isset($Format["R"]) ? $Format["R"] : 0;
  512. $G = isset($Format["G"]) ? $Format["G"] : 0;
  513. $B = isset($Format["B"]) ? $Format["B"] : 0;
  514. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  515. $ShowC = isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
  516. $Segments = isset($Format["Segments"]) ? $Format["Segments"] : NULL;
  517. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  518. $NoDraw = isset($Format["NoDraw"]) ? $Format["NoDraw"] : FALSE;
  519. $PathOnly = isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
  520. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  521. $DrawArrow = isset($Format["DrawArrow"]) ? $Format["DrawArrow"] : FALSE;
  522. $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 10;
  523. $ArrowRatio = isset($Format["ArrowRatio"]) ? $Format["ArrowRatio"] : .5;
  524. $ArrowTwoHeads = isset($Format["ArrowTwoHeads"]) ? $Format["ArrowTwoHeads"] : FALSE;
  525. if ( $Segments == NULL )
  526. {
  527. $Length = $this->getLength($X1,$Y1,$X2,$Y2);
  528. $Precision = ($Length*125)/1000;
  529. }
  530. else
  531. $Precision = $Segments;
  532. $P[0]["X"] = $X1; $P[0]["Y"] = $Y1;
  533. $P[1]["X"] = $Xv1; $P[1]["Y"] = $Yv1;
  534. $P[2]["X"] = $Xv2; $P[2]["Y"] = $Yv2;
  535. $P[3]["X"] = $X2; $P[3]["Y"] = $Y2;
  536. /* Compute the bezier points */
  537. $Q = ""; $ID = 0; $Path = "";
  538. for($i=0;$i<=$Precision;$i=$i+1)
  539. {
  540. $u = $i / $Precision;
  541. $C = "";
  542. $C[0] = (1 - $u) * (1 - $u) * (1 - $u);
  543. $C[1] = ($u * 3) * (1 - $u) * (1 - $u);
  544. $C[2] = 3 * $u * $u * (1 - $u);
  545. $C[3] = $u * $u * $u;
  546. for($j=0;$j<=3;$j++)
  547. {
  548. if ( !isset($Q[$ID]) ) { $Q[$ID] = ""; }
  549. if ( !isset($Q[$ID]["X"]) ) { $Q[$ID]["X"] = 0; }
  550. if ( !isset($Q[$ID]["Y"]) ) { $Q[$ID]["Y"] = 0; }
  551. $Q[$ID]["X"] = $Q[$ID]["X"] + $P[$j]["X"] * $C[$j];
  552. $Q[$ID]["Y"] = $Q[$ID]["Y"] + $P[$j]["Y"] * $C[$j];
  553. }
  554. $ID++;
  555. }
  556. $Q[$ID]["X"] = $X2; $Q[$ID]["Y"] = $Y2;
  557. if ( !$NoDraw )
  558. {
  559. /* Display the control points */
  560. if ( $ShowC && !$PathOnly )
  561. {
  562. $Xv1 = floor($Xv1); $Yv1 = floor($Yv1); $Xv2 = floor($Xv2); $Yv2 = floor($Yv2);
  563. $this->drawLine($X1,$Y1,$X2,$Y2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));
  564. $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  565. $this->drawRectangleMarker($Xv1,$Yv1,$MyMarkerSettings);
  566. $this->drawText($Xv1+4,$Yv1,"v1");
  567. $MyMarkerSettings = array("R"=>0,"G"=>0,"B"=>255,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  568. $this->drawRectangleMarker($Xv2,$Yv2,$MyMarkerSettings);
  569. $this->drawText($Xv2+4,$Yv2,"v2");
  570. }
  571. /* Draw the bezier */
  572. $LastX = NULL; $LastY = NULL; $Cpt = NULL; $Mode = NULL; $ArrowS = NULL;
  573. foreach ($Q as $Key => $Point)
  574. {
  575. $X = $Point["X"]; $Y = $Point["Y"];
  576. /* Get the first segment */
  577. if ( $ArrowS == NULL && $LastX != NULL && $LastY != NULL )
  578. { $ArrowS["X2"] = $LastX; $ArrowS["Y2"] = $LastY; $ArrowS["X1"] = $X; $ArrowS["Y1"] = $Y; }
  579. if ( $LastX != NULL && $LastY != NULL && !$PathOnly)
  580. 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));
  581. /* Get the last segment */
  582. $ArrowE["X1"] = $LastX; $ArrowE["Y1"] = $LastY; $ArrowE["X2"] = $X; $ArrowE["Y2"] = $Y;
  583. $LastX = $X; $LastY = $Y;
  584. }
  585. if ( $DrawArrow && !$PathOnly )
  586. {
  587. $ArrowSettings = array("FillR"=>$R,"FillG"=>$G,"FillB"=>$B,"Alpha"=>$Alpha,"Size"=>$ArrowSize,"Ratio"=>$ArrowRatio);
  588. if ( $ArrowTwoHeads )
  589. $this->drawArrow($ArrowS["X1"],$ArrowS["Y1"],$ArrowS["X2"],$ArrowS["Y2"],$ArrowSettings);
  590. $this->drawArrow($ArrowE["X1"],$ArrowE["Y1"],$ArrowE["X2"],$ArrowE["Y2"],$ArrowSettings);
  591. }
  592. }
  593. return($Q);
  594. }
  595. /* Draw a line between two points */
  596. function drawLine($X1,$Y1,$X2,$Y2,$Format="")
  597. {
  598. $R = isset($Format["R"]) ? $Format["R"] : 0;
  599. $G = isset($Format["G"]) ? $Format["G"] : 0;
  600. $B = isset($Format["B"]) ? $Format["B"] : 0;
  601. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  602. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  603. $Cpt = isset($Format["Cpt"]) ? $Format["Cpt"] : 1;
  604. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : 1;
  605. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  606. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  607. if ( $this->Antialias == FALSE && $Ticks == NULL )
  608. {
  609. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  610. {
  611. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  612. imageline($this->Picture,$X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$ShadowColor);
  613. }
  614. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  615. imageline($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
  616. return(0);
  617. }
  618. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  619. if ( $Distance == 0 ) { return(-1); }
  620. /* Derivative algorithm for overweighted lines, re-route to polygons primitives */
  621. if ( $Weight != NULL )
  622. {
  623. $Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
  624. $PolySettings = array ("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderAlpha"=>$Alpha);
  625. if ( $Ticks == NULL )
  626. {
  627. $Points = "";
  628. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y1;
  629. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y1;
  630. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y2;
  631. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y2;
  632. $this->drawPolygon($Points,$PolySettings);
  633. }
  634. else
  635. {
  636. for($i=0;$i<=$Distance;$i=$i+$Ticks*2)
  637. {
  638. $Xa = (($X2-$X1)/$Distance) * $i + $X1; $Ya = (($Y2-$Y1)/$Distance) * $i + $Y1;
  639. $Xb = (($X2-$X1)/$Distance) * ($i+$Ticks) + $X1; $Yb = (($Y2-$Y1)/$Distance) * ($i+$Ticks) + $Y1;
  640. $Points = "";
  641. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Ya;
  642. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Ya;
  643. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Yb;
  644. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Yb;
  645. $this->drawPolygon($Points,$PolySettings);
  646. }
  647. }
  648. return(1);
  649. }
  650. $XStep = ($X2-$X1) / $Distance;
  651. $YStep = ($Y2-$Y1) / $Distance;
  652. for($i=0;$i<=$Distance;$i++)
  653. {
  654. $X = $i * $XStep + $X1;
  655. $Y = $i * $YStep + $Y1;
  656. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  657. if ( $Threshold != NULL )
  658. {
  659. foreach($Threshold as $Key => $Parameters)
  660. {
  661. if ( $Y <= $Parameters["MinX"] && $Y >= $Parameters["MaxX"])
  662. {
  663. if ( isset($Parameters["R"]) ) { $RT = $Parameters["R"]; } else { $RT = 0; }
  664. if ( isset($Parameters["G"]) ) { $GT = $Parameters["G"]; } else { $GT = 0; }
  665. if ( isset($Parameters["B"]) ) { $BT = $Parameters["B"]; } else { $BT = 0; }
  666. if ( isset($Parameters["Alpha"]) ) { $AlphaT = $Parameters["Alpha"]; } else { $AlphaT = 0; }
  667. $Color = array("R"=>$RT,"G"=>$GT,"B"=>$BT,"Alpha"=>$AlphaT);
  668. }
  669. }
  670. }
  671. if ( $Ticks != NULL )
  672. {
  673. if ( $Cpt % $Ticks == 0 )
  674. { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }
  675. if ( $Mode == 1 )
  676. $this->drawAntialiasPixel($X,$Y,$Color);
  677. $Cpt++;
  678. }
  679. else
  680. $this->drawAntialiasPixel($X,$Y,$Color);
  681. }
  682. return(array($Cpt,$Mode));
  683. }
  684. /* Draw a circle */
  685. function drawCircle($Xc,$Yc,$Height,$Width,$Format="")
  686. {
  687. $R = isset($Format["R"]) ? $Format["R"] : 0;
  688. $G = isset($Format["G"]) ? $Format["G"] : 0;
  689. $B = isset($Format["B"]) ? $Format["B"] : 0;
  690. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  691. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  692. $Height = abs($Height);
  693. $Width = abs($Width);
  694. if ( $Height == 0 ) { $Height = 1; }
  695. if ( $Width == 0 ) { $Width = 1; }
  696. $Xc = floor($Xc); $Yc = floor($Yc);
  697. $RestoreShadow = $this->Shadow;
  698. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  699. {
  700. $this->Shadow = FALSE;
  701. $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));
  702. }
  703. if ( $Width == 0 ) { $Width = $Height; }
  704. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  705. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  706. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  707. $Step = 360 / (2 * PI * max($Width,$Height));
  708. $Mode = 1; $Cpt = 1;
  709. for($i=0;$i<=360;$i=$i+$Step)
  710. {
  711. $X = cos($i*PI/180) * $Height + $Xc;
  712. $Y = sin($i*PI/180) * $Width + $Yc;
  713. if ( $Ticks != NULL )
  714. {
  715. if ( $Cpt % $Ticks == 0 )
  716. { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }
  717. if ( $Mode == 1 )
  718. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  719. $Cpt++;
  720. }
  721. else
  722. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  723. }
  724. $this->Shadow = $RestoreShadow;
  725. }
  726. /* Draw a filled circle */
  727. function drawFilledCircle($X,$Y,$Radius,$Format="")
  728. {
  729. $R = isset($Format["R"]) ? $Format["R"] : 0;
  730. $G = isset($Format["G"]) ? $Format["G"] : 0;
  731. $B = isset($Format["B"]) ? $Format["B"] : 0;
  732. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  733. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  734. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  735. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  736. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
  737. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  738. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  739. if ( $Radius == 0 ) { $Radius = 1; }
  740. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  741. $X = floor($X); $Y = floor($Y);
  742. $Radius = abs($Radius);
  743. $RestoreShadow = $this->Shadow;
  744. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  745. {
  746. $this->Shadow = FALSE;
  747. $this->drawFilledCircle($X+$this->ShadowX,$Y+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks));
  748. }
  749. $this->Mask = "";
  750. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  751. for ($i=0; $i<=$Radius*2; $i++)
  752. {
  753. $Slice = sqrt($Radius * $Radius - ($Radius - $i) * ($Radius - $i));
  754. $XPos = floor($Slice);
  755. $YPos = $Y + $i - $Radius;
  756. $AAlias = $Slice - floor($Slice);
  757. $this->Mask[$X-$XPos][$YPos] = TRUE;
  758. $this->Mask[$X+$XPos][$YPos] = TRUE;
  759. imageline($this->Picture,$X-$XPos,$YPos,$X+$XPos,$YPos,$Color);
  760. }
  761. if ( $this->Antialias )
  762. $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  763. $this->Mask = "";
  764. if ( $BorderR != -1 )
  765. $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks));
  766. $this->Shadow = $RestoreShadow;
  767. }
  768. /* Write text */
  769. function drawText($X,$Y,$Text,$Format="")
  770. {
  771. $R = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
  772. $G = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
  773. $B = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
  774. $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
  775. $Align = isset($Format["Align"]) ? $Format["Align"] : TEXT_ALIGN_BOTTOMLEFT;
  776. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
  777. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  778. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  779. $ShowOrigine = isset($Format["ShowOrigine"]) ? $Format["ShowOrigine"] : FALSE;
  780. $TOffset = isset($Format["TOffset"]) ? $Format["TOffset"] : 2;
  781. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : FALSE;
  782. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : TRUE;
  783. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 6;
  784. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : FALSE;
  785. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 6;
  786. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 255;
  787. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 255;
  788. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 255;
  789. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
  790. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  791. $BoxBorderR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  792. $BoxBorderG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  793. $BoxBorderB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  794. $BoxBorderAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
  795. $NoShadow = isset($Format["NoShadow"]) ? $Format["NoShadow"] : FALSE;
  796. $Shadow = $this->Shadow;
  797. if ( $NoShadow ) { $this->Shadow = FALSE; }
  798. if ( $BoxSurrounding != "" ) { $BoxBorderR = $BoxR - $BoxSurrounding; $BoxBorderG = $BoxG - $BoxSurrounding; $BoxBorderB = $BoxB - $BoxSurrounding; $BoxBorderAlpha = $BoxAlpha; }
  799. if ( $ShowOrigine )
  800. {
  801. $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  802. $this->drawRectangleMarker($X,$Y,$MyMarkerSettings);
  803. }
  804. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,$Angle,$Text);
  805. if ( $DrawBox && ($Angle == 0 || $Angle == 90 || $Angle == 180 || $Angle == 270))
  806. {
  807. $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;
  808. 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; }
  809. $X1 = min($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) - $BorderOffset + 3;
  810. $Y1 = min($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) - $BorderOffset;
  811. $X2 = max($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) + $BorderOffset + 3;
  812. $Y2 = max($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) + $BorderOffset - 3;
  813. $X1 = $X1 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
  814. $Y1 = $Y1 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
  815. $X2 = $X2 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
  816. $Y2 = $Y2 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
  817. $Settings = array("R"=>$BoxR,"G"=>$BoxG,"B"=>$BoxB,"Alpha"=>$BoxAlpha,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"BorderAlpha"=>$BoxBorderAlpha);
  818. if ( $BoxRounded )
  819. { $this->drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$RoundedRadius,$Settings); }
  820. else
  821. { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Settings); }
  822. }
  823. $X = $X - $TxtPos[$Align]["X"] + $X;
  824. $Y = $Y - $TxtPos[$Align]["Y"] + $Y;
  825. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  826. {
  827. $C_ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  828. imagettftext($this->Picture,$FontSize,$Angle,$X+$this->ShadowX,$Y+$this->ShadowY,$C_ShadowColor,$FontName,$Text);
  829. }
  830. $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B,$Alpha);
  831. imagettftext($this->Picture,$FontSize,$Angle,$X,$Y,$C_TextColor,$FontName,$Text);
  832. $this->Shadow = $Shadow;
  833. return($TxtPos);
  834. }
  835. /* Draw a gradient within a defined area */
  836. function drawGradientArea($X1,$Y1,$X2,$Y2,$Direction,$Format="")
  837. {
  838. $StartR = isset($Format["StartR"]) ? $Format["StartR"] : 90;
  839. $StartG = isset($Format["StartG"]) ? $Format["StartG"] : 90;
  840. $StartB = isset($Format["StartB"]) ? $Format["StartB"] : 90;
  841. $EndR = isset($Format["EndR"]) ? $Format["EndR"] : 0;
  842. $EndG = isset($Format["EndG"]) ? $Format["EndG"] : 0;
  843. $EndB = isset($Format["EndB"]) ? $Format["EndB"] : 0;
  844. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  845. $Levels = isset($Format["Levels"]) ? $Format["Levels"] : NULL;
  846. $Shadow = $this->Shadow;
  847. $this->Shadow = FALSE;
  848. if ( $StartR == $EndR && $StartG == $EndG && $StartB == $EndB )
  849. {
  850. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,array("R"=>$StartR,"G"=>$StartG,"B"=>$StartB,"Alpha"=>$Alpha));
  851. return(0);
  852. }
  853. if ( $Levels != NULL )
  854. { $EndR=$StartR+$Levels; $EndG=$StartG+$Levels; $EndB=$StartB+$Levels; }
  855. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  856. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  857. if ( $Direction == DIRECTION_VERTICAL ) { $Width = abs($Y2-$Y1); }
  858. if ( $Direction == DIRECTION_HORIZONTAL ) { $Width = abs($X2-$X1); }
  859. $Step = max(abs($EndR-$StartR),abs($EndG-$StartG),abs($EndB-$StartB));
  860. $StepSize = $Width/$Step;
  861. $RStep = ($EndR-$StartR)/$Step;
  862. $GStep = ($EndG-$StartG)/$Step;
  863. $BStep = ($EndB-$StartB)/$Step;
  864. $R=$StartR;$G=$StartG;$B=$StartB;
  865. switch($Direction)
  866. {
  867. case DIRECTION_VERTICAL:
  868. $StartY = $Y1; $EndY = floor($Y2)+1; $LastY2 = $StartY;
  869. for($i=0;$i<=$Step;$i++)
  870. {
  871. $Y2 = floor($StartY + ($i * $StepSize));
  872. if ($Y2 > $EndY) { $Y2 = $EndY; }
  873. if (($Y1 != $Y2 && $Y1 < $Y2) || $Y2 == $EndY)
  874. {
  875. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  876. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
  877. $LastY2 = max($LastY2,$Y2);
  878. $Y1 = $Y2+1;
  879. }
  880. $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep;
  881. }
  882. if ( $LastY2 < $EndY && isset($Color)) { for ($i=$LastY2+1;$i<=$EndY;$i++) { $this->drawLine($X1,$i,$X2,$i,$Color); } }
  883. break;
  884. case DIRECTION_HORIZONTAL:
  885. $StartX = $X1; $EndX = $X2;
  886. for($i=0;$i<=$Step;$i++)
  887. {
  888. $X2 = floor($StartX + ($i * $StepSize));
  889. if ($X2 > $EndX) { $X2 = $EndX; }
  890. if (($X1 != $X2 && $X1 < $X2) || $X2 == $EndX)
  891. {
  892. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  893. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
  894. $X1 = $X2+1;
  895. }
  896. $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep;
  897. }
  898. if ( $X2 < $EndX && isset($Color)) { $this->drawFilledRectangle($X2,$Y1,$EndX,$Y2,$Color); }
  899. break;
  900. }
  901. $this->Shadow = $Shadow;
  902. }
  903. /* Draw an aliased pixel */
  904. function drawAntialiasPixel($X,$Y,$Format="")
  905. {
  906. $R = isset($Format["R"]) ? $Format["R"] : 0;
  907. $G = isset($Format["G"]) ? $Format["G"] : 0;
  908. $B = isset($Format["B"]) ? $Format["B"] : 0;
  909. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  910. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  911. return(-1);
  912. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  913. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  914. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  915. if ( !$this->Antialias )
  916. {
  917. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  918. {
  919. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  920. imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
  921. }
  922. $PlotColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  923. imagesetpixel($this->Picture,$X,$Y,$PlotColor);
  924. return(0);
  925. }
  926. $Plot = "";
  927. $Xi = floor($X);
  928. $Yi = floor($Y);
  929. if ( $Xi == $X && $Yi == $Y)
  930. {
  931. if ( $Alpha == 100 )
  932. $this->drawAlphaPixel($X,$Y,100,$R,$G,$B);
  933. else
  934. $this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B);
  935. }
  936. else
  937. {
  938. $Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  939. if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); }
  940. $Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  941. if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); }
  942. $Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  943. if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); }
  944. $Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  945. if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); }
  946. }
  947. }
  948. /* Draw a semi-transparent pixel */
  949. function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
  950. {
  951. if ( isset($this->Mask[$X])) { if ( isset($this->Mask[$X][$Y]) ) { return(0); } }
  952. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  953. return(-1);
  954. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  955. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  956. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  957. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  958. {
  959. $AlphaFactor = floor(($Alpha / 100) * $this->Shadowa);
  960. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$AlphaFactor);
  961. imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
  962. }
  963. $C_Aliased = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  964. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  965. }
  966. /* Convert apha to base 10 */
  967. function convertAlpha($AlphaValue)
  968. { return((127/100)*(100-$AlphaValue)); }
  969. /* Allocate a color with transparency */
  970. function allocateColor($Picture,$R,$G,$B,$Alpha=100)
  971. {
  972. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  973. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  974. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  975. if ( $Alpha < 0 ) { $Alpha = 0; }
  976. if ( $Alpha > 100) { $Alpha = 100; }
  977. $Alpha = $this->convertAlpha($Alpha);
  978. return(imagecolorallocatealpha($Picture,$R,$G,$B,$Alpha));
  979. }
  980. /* Load a PNG file and draw it over the chart */
  981. function drawFromPNG($X,$Y,$FileName)
  982. { $this->drawFromPicture(1,$FileName,$X,$Y); }
  983. /* Load a GIF file and draw it over the chart */
  984. function drawFromGIF($X,$Y,$FileName)
  985. { $this->drawFromPicture(2,$FileName,$X,$Y); }
  986. /* Load a JPEG file and draw it over the chart */
  987. function drawFromJPG($X,$Y,$FileName)
  988. { $this->drawFromPicture(3,$FileName,$X,$Y); }
  989. function getPicInfo($FileName)
  990. {
  991. $Infos = getimagesize($FileName);
  992. $Width = $Infos[0];
  993. $Height = $Infos[1];
  994. $Type = $Infos["mime"];
  995. if ( $Type == "image/png") { $Type = 1; }
  996. if ( $Type == "image/gif") { $Type = 2; }
  997. if ( $Type == "image/jpeg ") { $Type = 3; }
  998. return(array($Width,$Height,$Type));
  999. }
  1000. /* Generic loader function for external pictures */
  1001. function drawFromPicture($PicType,$FileName,$X,$Y)
  1002. {
  1003. if ( file_exists($FileName))
  1004. {
  1005. list($Width,$Height) = $this->getPicInfo($FileName);
  1006. if ( $PicType == 1 )
  1007. { $Raster = imagecreatefrompng($FileName); }
  1008. elseif ( $PicType == 2 )
  1009. { $Raster = imagecreatefromgif($FileName); }
  1010. elseif ( $PicType == 3 )
  1011. { $Raster = imagecreatefromjpeg($FileName); }
  1012. else
  1013. { return(0); }
  1014. $RestoreShadow = $this->Shadow;
  1015. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  1016. {
  1017. $this->Shadow = FALSE;
  1018. if ( $PicType == 3 )
  1019. $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));
  1020. else
  1021. {
  1022. $TranparentID = imagecolortransparent($Raster);
  1023. for ($Xc=0;$Xc<=$Width-1;$Xc++)
  1024. {
  1025. for ($Yc=0;$Yc<=$Height-1;$Yc++)
  1026. {
  1027. $RGBa = imagecolorat($Raster,$Xc,$Yc);
  1028. $Values = imagecolorsforindex($Raster,$RGBa);
  1029. if ( $Values["alpha"] < 120 )
  1030. {
  1031. $AlphaFactor = floor(($this->Shadowa / 100) * ((100 / 127) * (127-$Values["alpha"])));
  1032. $this->drawAlphaPixel($X+$Xc+$this->ShadowX,$Y+$Yc+$this->ShadowY,$AlphaFactor,$this->ShadowR,$this->ShadowG,$this->ShadowB);
  1033. }
  1034. }
  1035. }
  1036. }
  1037. }
  1038. $this->Shadow = $RestoreShadow;
  1039. imagecopy($this->Picture,$Raster,$X,$Y,0,0,$Width,$Height);
  1040. imagedestroy($Raster);
  1041. }
  1042. }
  1043. /* Draw an arrow */
  1044. function drawArrow($X1,$Y1,$X2,$Y2,$Format="")
  1045. {
  1046. $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
  1047. $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
  1048. $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
  1049. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
  1050. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
  1051. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
  1052. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1053. $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
  1054. $Ratio = isset($Format["Ratio"]) ? $Format["Ratio"] : .5;
  1055. $TwoHeads = isset($Format["TwoHeads"]) ? $Format["TwoHeads"] : FALSE;
  1056. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : FALSE;
  1057. /* Calculate the line angle */
  1058. $Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
  1059. /* Override Shadow support, this will be managed internally */
  1060. $RestoreShadow = $this->Shadow;
  1061. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  1062. {
  1063. $this->Shadow = FALSE;
  1064. $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));
  1065. }
  1066. /* Draw the 1st Head */
  1067. $TailX = cos(($Angle-180)*PI/180)*$Size+$X2;
  1068. $TailY = sin(($Angle-180)*PI/180)*$Size+$Y2;
  1069. $Points = "";
  1070. $Points[] = $X2; $Points[] = $Y2;
  1071. $Points[] = cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY;
  1072. $Points[] = cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY;
  1073. $Points[] = $X2; $Points[] = $Y2;
  1074. /* Visual correction */
  1075. if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
  1076. if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }
  1077. $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
  1078. ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);
  1079. $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1080. $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1081. $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1082. /* Draw the second head */
  1083. if ( $TwoHeads )
  1084. {
  1085. $Angle = $this->getAngle($X2,$Y2,$X1,$Y1);
  1086. $TailX2 = cos(($Angle-180)*PI/180)*$Size+$X1;
  1087. $TailY2 = sin(($Angle-180)*PI/180)*$Size+$Y1;
  1088. $Points = "";
  1089. $Points[] = $X1; $Points[] = $Y1;
  1090. $Points[] = cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY2;
  1091. $Points[] = cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY2;
  1092. $Points[] = $X1; $Points[] = $Y1;
  1093. /* Visual correction */
  1094. if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
  1095. if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }
  1096. $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
  1097. ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);
  1098. $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1099. $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1100. $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1101. $this->drawLine($TailX,$TailY,$TailX2,$TailY2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1102. }
  1103. else
  1104. $this->drawLine($X1,$Y1,$TailX,$TailY,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1105. /* Re-enable shadows */
  1106. $this->Shadow = $RestoreShadow;
  1107. }
  1108. /* Draw a label with associated arrow */
  1109. function drawArrowLabel($X1,$Y1,$Text,$Format="")
  1110. {
  1111. $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
  1112. $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
  1113. $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
  1114. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
  1115. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
  1116. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
  1117. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1118. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1119. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1120. $Length = isset($Format["Length"]) ? $Format["Length"] : 50;
  1121. $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 315;
  1122. $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
  1123. $Position = isset($Format["Position"]) ? $Format["Position"] : POSITION_TOP;
  1124. $RoundPos = isset($Format["RoundPos"]) ? $Format["RoundPos"] : FALSE;
  1125. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  1126. $Angle = $Angle % 360;
  1127. $X2 = sin(($Angle+180)*PI/180)*$Length+$X1;
  1128. $Y2 = cos(($Angle+180)*PI/180)*$Length+$Y1;
  1129. if ( $RoundPos && $Angle > 0 && $Angle < 180 ) { $Y2 = ceil($Y2); }
  1130. if ( $RoundPos && $Angle > 180 ) { $Y2 = floor($Y2); }
  1131. $this->drawArrow($X2,$Y2,$X1,$Y1,$Format);
  1132. $Size = imagettfbbox($FontSize,0,$FontName,$Text);
  1133. $TxtWidth = max(abs($Size[2]-$Size[0]),abs($Size[0]-$Size[6]));
  1134. $TxtHeight = max(abs($Size[1]-$Size[7]),abs($Size[3]-$Size[1]));
  1135. if ( $Angle > 0 && $Angle < 180 )
  1136. {
  1137. $this->drawLine($X2,$Y2,$X2-$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1138. if ( $Position == POSITION_TOP )
  1139. $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_BOTTOMRIGHT));
  1140. else
  1141. $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPRIGHT));
  1142. }
  1143. else
  1144. {
  1145. $this->drawLine($X2,$Y2,$X2+$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1146. if ( $Position == POSITION_TOP )
  1147. $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1148. else
  1149. $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPLEFT));
  1150. }
  1151. }
  1152. /* Draw a progress bar filled with specified % */
  1153. function drawProgress($X,$Y,$Percent,$Format="")
  1154. {
  1155. if ( $Percent > 100 ) { $Percent = 100; }
  1156. if ( $Percent < 0 ) { $Percent = 0; }
  1157. $Width = isset($Format["Width"]) ? $Format["Width"] : 200;
  1158. $Height = isset($Format["Height"]) ? $Format["Height"] : 20;
  1159. $Orientation = isset($Format["Orientation"]) ? $Format["Orientation"] : ORIENTATION_HORIZONTAL;
  1160. $ShowLabel = isset($Format["ShowLabel"]) ? $Format["ShowLabel"] : FALSE;
  1161. $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : LABEL_POS_INSIDE;
  1162. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 10;
  1163. $R = isset($Format["R"]) ? $Format["R"] : 130;
  1164. $G = isset($Format["G"]) ? $Format["G"] : 130;
  1165. $B = isset($Format["B"]) ? $Format["B"] : 130;
  1166. $RFade = isset($Format["RFade"]) ? $Format["RFade"] : -1;
  1167. $GFade = isset($Format["GFade"]) ? $Format["GFade"] : -1;
  1168. $BFade = isset($Format["BFade"]) ? $Format["BFade"] : -1;
  1169. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  1170. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  1171. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  1172. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 0;
  1173. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 0;
  1174. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 0;
  1175. $BoxBackR = isset($Format["BoxBackR"]) ? $Format["BoxBackR"] : 255;
  1176. $BoxBackG = isset($Format["BoxBackG"]) ? $Format["BoxBackG"] : 255;
  1177. $BoxBackB = isset($Format["BoxBackB"]) ? $Format["BoxBackB"] : 255;
  1178. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1179. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  1180. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : NULL;
  1181. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;
  1182. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1183. {
  1184. $RFade = (($RFade-$R)/100)*$Percent+$R;
  1185. $GFade = (($GFade-$G)/100)*$Percent+$G;
  1186. $BFade = (($BFade-$B)/100)*$Percent+$B;
  1187. }
  1188. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  1189. if ( $BoxSurrounding != NULL ) { $BoxBorderR = $BoxBackR + $Surrounding; $BoxBorderG = $BoxBackG + $Surrounding; $BoxBorderB = $BoxBackB + $Surrounding; }
  1190. if ( $Orientation == ORIENTATION_VERTICAL )
  1191. {
  1192. $InnerHeight = (($Height-2)/100)*$Percent;
  1193. $this->drawFilledRectangle($X,$Y,$X+$Width,$Y-$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));
  1194. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1195. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1196. {
  1197. $GradientOptions = array("StartR"=>$RFade,"StartG"=>$GFade,"StartB"=>$BFade,"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  1198. $this->drawGradientArea($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,DIRECTION_VERTICAL,$GradientOptions);
  1199. if ( $Surrounding )
  1200. $this->drawRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
  1201. }
  1202. else
  1203. $this->drawFilledRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1204. $this->Shadow = $RestoreShadow;
  1205. if ( $ShowLabel && $LabelPos == LABEL_POS_BOTTOM ) { $this->drawText($X+($Width/2),$Y+$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_TOPMIDDLE)); }
  1206. if ( $ShowLabel && $LabelPos == LABEL_POS_TOP ) { $this->drawText($X+($Width/2),$Y-$Height-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
  1207. if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE ) { $this->drawText($X+($Width/2),$Y-$InnerHeight-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT,"Angle"=>90)); }
  1208. if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER ) { $this->drawText($X+($Width/2),$Y-($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"Angle"=>90)); }
  1209. }
  1210. else
  1211. {
  1212. if ( $Percent == 100 )
  1213. $InnerWidth = $Width-1;
  1214. else
  1215. $InnerWidth = (($Width-2)/100)*$Percent;
  1216. $this->drawFilledRectangle($X,$Y,$X+$Width,$Y+$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));
  1217. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1218. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1219. {
  1220. $GradientOptions = array("StartR"=>$R,"StartG"=>$G,"StartB"=>$B,"EndR"=>$RFade,"EndG"=>$GFade,"EndB"=>$BFade);
  1221. $this->drawGradientArea($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,DIRECTION_HORIZONTAL,$GradientOptions);
  1222. if ( $Surrounding )
  1223. $this->drawRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
  1224. }
  1225. else
  1226. $this->drawFilledRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1227. $this->Shadow = $RestoreShadow;
  1228. if ( $ShowLabel && $LabelPos == LABEL_POS_LEFT ) { $this->drawText($X-$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); }
  1229. if ( $ShowLabel && $LabelPos == LABEL_POS_RIGHT ) { $this->drawText($X+$Width+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
  1230. if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER ) { $this->drawText($X+($Width/2),$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE)); }
  1231. if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE ) { $this->drawText($X+$InnerWidth+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
  1232. }
  1233. }
  1234. /* Get the legend box size */
  1235. function getLegendSize($Format="")
  1236. {
  1237. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1238. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1239. $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
  1240. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  1241. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  1242. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  1243. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
  1244. $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
  1245. $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
  1246. $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
  1247. $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
  1248. $Data = $this->DataSet->getData();
  1249. foreach($Data["Series"] as $SerieName => $Serie)
  1250. {
  1251. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
  1252. {
  1253. list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
  1254. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  1255. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  1256. }
  1257. }
  1258. $YStep = max($this->FontSize,$IconAreaHeight) + 5;
  1259. $XStep = $IconAreaWidth + 5;
  1260. $XStep = $XSpacing;
  1261. $X=100; $Y=100;
  1262. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  1263. foreach($Data["Series"] as $SerieName => $Serie)
  1264. {
  1265. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1266. {
  1267. if ( $Mode == LEGEND_VERTICAL )
  1268. {
  1269. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);
  1270. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1271. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1272. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1273. $Lines = preg_split("/\n/",$Serie["Description"]);
  1274. $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1275. }
  1276. elseif ( $Mode == LEGEND_HORIZONTAL )
  1277. {
  1278. $Lines = preg_split("/\n/",$Serie["Description"]);
  1279. $Width = "";
  1280. foreach($Lines as $Key => $Value)
  1281. {
  1282. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  1283. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1284. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1285. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1286. $Width[] = $BoxArray[1]["X"];
  1287. }
  1288. $vX=max($Width)+$XStep;
  1289. }
  1290. }
  1291. }
  1292. $vY=$vY-$YStep; $vX=$vX-$XStep;
  1293. $TopOffset = $Y - $Boundaries["T"];
  1294. if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
  1295. $Width = ($Boundaries["R"]+$Margin) - ($Boundaries["L"]-$Margin);
  1296. $Height = ($Boundaries["B"]+$Margin) - ($Boundaries["T"]-$Margin);
  1297. return(array("Width"=>$Width,"Height"=>$Height));
  1298. }
  1299. /* Draw the legend of the active series */
  1300. function drawLegend($X,$Y,$Format="")
  1301. {
  1302. $Family = isset($Format["Family"]) ? $Format["Family"] : LEGEND_FAMILY_BOX;
  1303. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1304. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1305. $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->FontColorR;
  1306. $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->FontColorG;
  1307. $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->FontColorB;
  1308. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
  1309. $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
  1310. $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
  1311. $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
  1312. $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
  1313. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  1314. $R = isset($Format["R"]) ? $Format["R"] : 200;
  1315. $G = isset($Format["G"]) ? $Format["G"] : 200;
  1316. $B = isset($Format["B"]) ? $Format["B"] : 200;
  1317. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1318. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
  1319. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
  1320. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
  1321. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  1322. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  1323. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  1324. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  1325. $Data = $this->DataSet->getData();
  1326. foreach($Data["Series"] as $SerieName => $Serie)
  1327. {
  1328. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
  1329. {
  1330. list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
  1331. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  1332. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  1333. }
  1334. }
  1335. $YStep = max($this->FontSize,$IconAreaHeight) + 5;
  1336. $XStep = $IconAreaWidth + 5;
  1337. $XStep = $XSpacing;
  1338. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  1339. foreach($Data["Series"] as $SerieName => $Serie)
  1340. {
  1341. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1342. {
  1343. if ( $Mode == LEGEND_VERTICAL )
  1344. {
  1345. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);
  1346. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1347. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1348. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1349. $Lines = preg_split("/\n/",$Serie["Description"]);
  1350. $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1351. }
  1352. elseif ( $Mode == LEGEND_HORIZONTAL )
  1353. {
  1354. $Lines = preg_split("/\n/",$Serie["Description"]);
  1355. $Width = "";
  1356. foreach($Lines as $Key => $Value)
  1357. {
  1358. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  1359. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1360. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1361. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1362. $Width[] = $BoxArray[1]["X"];
  1363. }
  1364. $vX=max($Width)+$XStep;
  1365. }
  1366. }
  1367. }
  1368. $vY=$vY-$YStep; $vX=$vX-$XStep;
  1369. $TopOffset = $Y - $Boundaries["T"];
  1370. if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
  1371. if ( $Style == LEGEND_ROUND )
  1372. $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));
  1373. elseif ( $Style == LEGEND_BOX )
  1374. $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));
  1375. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1376. foreach($Data["Series"] as $SerieName => $Serie)
  1377. {
  1378. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1379. {
  1380. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"];
  1381. $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  1382. if ( isset($Serie["Picture"]) )
  1383. {
  1384. $Picture = $Serie["Picture"];
  1385. list($PicWidth,$PicHeight) = $this->getPicInfo($Picture);
  1386. $PicX = $X+$IconAreaWidth/2; $PicY = $Y+$IconAreaHeight/2;
  1387. $this->drawFromPNG($PicX-$PicWidth/2,$PicY-$PicHeight/2,$Picture);
  1388. }
  1389. else
  1390. {
  1391. if ( $Family == LEGEND_FAMILY_BOX )
  1392. {
  1393. if ( $BoxWidth != $IconAreaWidth ) { $XOffset = floor(($IconAreaWidth-$BoxWidth)/2); } else { $XOffset = 0; }
  1394. if ( $BoxHeight != $IconAreaHeight ) { $YOffset = floor(($IconAreaHeight-$BoxHeight)/2); } else { $YOffset = 0; }
  1395. $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));
  1396. $this->drawFilledRectangle($X+$XOffset,$Y+$YOffset,$X+$BoxWidth+$XOffset,$Y+$BoxHeight+$YOffset,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
  1397. }
  1398. elseif ( $Family == LEGEND_FAMILY_CIRCLE )
  1399. {
  1400. $this->drawFilledCircle($X+1+$IconAreaWidth/2,$Y+1+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
  1401. $this->drawFilledCircle($X+$IconAreaWidth/2,$Y+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
  1402. }
  1403. elseif ( $Family == LEGEND_FAMILY_LINE )
  1404. {
  1405. $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));
  1406. $this->drawLine($X,$Y+$IconAreaHeight/2,$X+$IconAreaWidth,$Y+$IconAreaHeight/2,array("R"=>$R,"G"=>$G,"B"=>$B,"Ticks"=>$Ticks,"Weight"=>$Weight));
  1407. }
  1408. }
  1409. if ( $Mode == LEGEND_VERTICAL )
  1410. {
  1411. $Lines = preg_split("/\n/",$Serie["Description"]);
  1412. foreach($Lines as $Key => $Value)
  1413. $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));
  1414. $Y=$Y+max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1415. }
  1416. elseif ( $Mode == LEGEND_HORIZONTAL )
  1417. {
  1418. $Lines = preg_split("/\n/",$Serie["Description"]);
  1419. $Width = "";
  1420. foreach($Lines as $Key => $Value)
  1421. {
  1422. $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));
  1423. $Width[] = $BoxArray[1]["X"];
  1424. }
  1425. $X=max($Width)+2+$XStep;
  1426. }
  1427. }
  1428. }
  1429. $this->Shadow = $RestoreShadow;
  1430. }
  1431. function drawScale($Format="")
  1432. {
  1433. $Pos = isset($Format["Pos"]) ? $Format["Pos"] : SCALE_POS_LEFTRIGHT;
  1434. $Floating = isset($Format["Floating"]) ? $Format["Floating"] : FALSE;
  1435. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : SCALE_MODE_FLOATING;
  1436. $RemoveXAxis = isset($Format["RemoveXAxis"]) ? $Format["RemoveXAxis"] : FALSE;
  1437. $MinDivHeight = isset($Format["MinDivHeight"]) ? $Format["MinDivHeight"] : 20;
  1438. $Factors = isset($Format["Factors"]) ? $Format["Factors"] : array(1,2,5);
  1439. $ManualScale = isset($Format["ManualScale"]) ? $Format["ManualScale"] : array("0"=>array("Min"=>-100,"Max"=>100));
  1440. $XMargin = isset($Format["XMargin"]) ? $Format["XMargin"] : AUTO;
  1441. $YMargin = isset($Format["YMargin"]) ? $Format["YMargin"] : 0;
  1442. $ScaleSpacing = isset($Format["ScaleSpacing"]) ? $Format["ScaleSpacing"] : 15;
  1443. $InnerTickWidth = isset($Format["InnerTickWidth"]) ? $Format["InnerTickWidth"] : 2;
  1444. $OuterTickWidth = isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2;
  1445. $DrawXLines = isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : TRUE;
  1446. $DrawYLines = isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL;
  1447. $GridTicks = isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4;
  1448. $GridR = isset($Format["GridR"]) ? $Format["GridR"] : 255;
  1449. $GridG = isset($Format["GridG"]) ? $Format["GridG"] : 255;
  1450. $GridB = isset($Format["GridB"]) ? $Format["GridB"] : 255;
  1451. $GridAlpha = isset($Format["GridAlpha"]) ? $Format["GridAlpha"] : 40;
  1452. $AxisRo = isset($Format["AxisR"]) ? $Format["AxisR"] : 0;
  1453. $AxisGo = isset($Format["AxisG"]) ? $Format["AxisG"] : 0;
  1454. $AxisBo = isset($Format["AxisB"]) ? $Format["AxisB"] : 0;
  1455. $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100;
  1456. $TickRo = isset($Format["TickR"]) ? $Format["TickR"] : 0;
  1457. $TickGo = isset($Format["TickG"]) ? $Format["TickG"] : 0;
  1458. $TickBo = isset($Format["TickB"]) ? $Format["TickB"] : 0;
  1459. $TickAlpha = isset($Format["TickAlpha"]) ? $Format["TickAlpha"] : 100;
  1460. $DrawSubTicks = isset($Format["DrawSubTicks"]) ? $Format["DrawSubTicks"] : FALSE;
  1461. $InnerSubTickWidth = isset($Format["InnerSubTickWidth"]) ? $Format["InnerSubTickWidth"] : 0;
  1462. $OuterSubTickWidth = isset($Format["OuterSubTickWidth"]) ? $Format["OuterSubTickWidth"] : 2;
  1463. $SubTickR = isset($Format["SubTickR"]) ? $Format["SubTickR"] : 255;
  1464. $SubTickG = isset($Format["SubTickG"]) ? $Format["SubTickG"] : 0;
  1465. $SubTickB = isset($Format["SubTickB"]) ? $Format["SubTickB"] : 0;
  1466. $SubTickAlpha = isset($Format["SubTickAlpha"]) ? $Format["SubTickAlpha"] : 100;
  1467. $AutoAxisLabels = isset($Format["AutoAxisLabels"]) ? $Format["AutoAxisLabels"] : TRUE;
  1468. $XReleasePercent = isset($Format["XReleasePercent"]) ? $Format["XReleasePercent"] : 1;
  1469. $DrawArrows = isset($Format["DrawArrows"]) ? $Format["DrawArrows"] : FALSE;
  1470. $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 8;
  1471. $CycleBackground = isset($Format["CycleBackground"]) ? $Format["CycleBackground"] : FALSE;
  1472. $BackgroundR1 = isset($Format["BackgroundR1"]) ? $Format["BackgroundR1"] : 255;
  1473. $BackgroundG1 = isset($Format["BackgroundG1"]) ? $Format["BackgroundG1"] : 255;
  1474. $BackgroundB1 = isset($Format["BackgroundB1"]) ? $Format["BackgroundB1"] : 255;
  1475. $BackgroundAlpha1 = isset($Format["BackgroundAlpha1"]) ? $Format["BackgroundAlpha1"] : 20;
  1476. $BackgroundR2 = isset($Format["BackgroundR2"]) ? $Format["BackgroundR2"] : 230;
  1477. $BackgroundG2 = isset($Format["BackgroundG2"]) ? $Format["BackgroundG2"] : 230;
  1478. $BackgroundB2 = isset($Format["BackgroundB2"]) ? $Format["BackgroundB2"] : 230;
  1479. $BackgroundAlpha2 = isset($Format["BackgroundAlpha2"]) ? $Format["BackgroundAlpha2"] : 20;
  1480. $LabelingMethod = isset($Format["LabelingMethod"]) ? $Format["LabelingMethod"] : LABELING_ALL;
  1481. $LabelSkip = isset($Format["LabelSkip"]) ? $Format["LabelSkip"] : 0;
  1482. $LabelRotation = isset($Format["LabelRotation"]) ? $Format["LabelRotation"] : 0;
  1483. $RemoveSkippedAxis = isset($Format["RemoveSkippedAxis"]) ? $Format["RemoveSkippedAxis"] : FALSE;
  1484. $SkippedAxisTicks = isset($Format["SkippedAxisTicks"]) ? $Format["SkippedAxisTicks"] : $GridTicks+2;
  1485. $SkippedAxisR = isset($Format["SkippedAxisR"]) ? $Format["SkippedAxisR"] : $GridR;
  1486. $SkippedAxisG = isset($Format["SkippedAxisG"]) ? $Format["SkippedAxisG"] : $GridG;
  1487. $SkippedAxisB = isset($Format["SkippedAxisB"]) ? $Format["SkippedAxisB"] : $GridB;
  1488. $SkippedAxisAlpha = isset($Format["SkippedAxisAlpha"]) ? $Format["SkippedAxisAlpha"] : $GridAlpha-30;
  1489. $SkippedTickR = isset($Format["SkippedTickR"]) ? $Format["SkippedTickR"] : $TickRo;
  1490. $SkippedTickG = isset($Format["SkippedTickG"]) ? $Format["SkippedTickG"] : $TickGo;
  1491. $SkippedTickB = isset($Format["SkippedTicksB"]) ? $Format["SkippedTickB"] : $TickBo;
  1492. $SkippedTickAlpha = isset($Format["SkippedTickAlpha"]) ? $Format["SkippedTickAlpha"] : $TickAlpha-80;
  1493. $SkippedInnerTickWidth = isset($Format["SkippedInnerTickWidth"]) ? $Format["SkippedInnerTickWidth"] : 0;
  1494. $SkippedOuterTickWidth = isset($Format["SkippedOuterTickWidth"]) ? $Format["SkippedOuterTickWidth"] : 2;
  1495. /* Floating scale require X & Y margins to be set manually */
  1496. if ( $Floating && ( $XMargin == AUTO || $YMargin == 0 ) ) { $Floating = FALSE; }
  1497. /* Skip a NOTICE event in case of an empty array */
  1498. if ( $DrawYLines == NONE || $DrawYLines == FALSE ) { $DrawYLines = array("zarma"=>"31"); }
  1499. /* Define the color for the skipped elements */
  1500. $SkippedAxisColor = array("R"=>$SkippedAxisR,"G"=>$SkippedAxisG,"B"=>$SkippedAxisB,"Alpha"=>$SkippedAxisAlpha,"Ticks"=>$SkippedAxisTicks);
  1501. $SkippedTickColor = array("R"=>$SkippedTickR,"G"=>$SkippedTickG,"B"=>$SkippedTickB,"Alpha"=>$SkippedTickAlpha);
  1502. $Data = $this->DataSet->getData();
  1503. if ( isset($Data["Abscissa"]) ) { $Abscissa = $Data["Abscissa"]; } else { $Abscissa = NULL; }
  1504. /* Unset the abscissa axis, needed if we display multiple charts on the same picture */
  1505. if ( $Abscissa != NULL )
  1506. {
  1507. foreach($Data["Axis"] as $AxisID => $Parameters)
  1508. { if ($Parameters["Identity"] == AXIS_X) { unset($Data["Axis"][$AxisID]); } }
  1509. }
  1510. /* Build the scale settings */
  1511. $GotXAxis = FALSE;
  1512. foreach($Data["Axis"] as $AxisID => $AxisParameter)
  1513. {
  1514. if ( $AxisParameter["Identity"] == AXIS_X ) { $GotXAxis = TRUE; }
  1515. if ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_Y)
  1516. { $Height = $this->GraphAreaY2-$this->GraphAreaY1 - $YMargin*2; }
  1517. elseif ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_X)
  1518. { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
  1519. elseif ( $Pos == SCALE_POS_TOPBOTTOM && $AxisParameter["Identity"] == AXIS_Y)
  1520. { $Height = $this->GraphAreaX2-$this->GraphAreaX1 - $YMargin*2;; }
  1521. else
  1522. { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }
  1523. $AxisMin = ABSOLUTE_MAX; $AxisMax = OUT_OF_SIGHT;
  1524. if ( $Mode == SCALE_MODE_FLOATING || $Mode == SCALE_MODE_START0 )
  1525. {
  1526. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1527. {
  1528. if ( $SerieParameter["Axis"] == $AxisID && $Data["Series"][$SerieID]["isDrawable"] && $Data["Abscissa"] != $SerieID)
  1529. {
  1530. $AxisMax = max($AxisMax,$Data["Series"][$SerieID]["Max"]);
  1531. $AxisMin = min($AxisMin,$Data["Series"][$SerieID]["Min"]);
  1532. }
  1533. }
  1534. $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
  1535. $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
  1536. if ( $Mode == SCALE_MODE_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; }
  1537. }
  1538. elseif ( $Mode == SCALE_MODE_MANUAL )
  1539. {
  1540. if ( isset($ManualScale[$AxisID]["Min"]) && isset($ManualScale[$AxisID]["Max"]) )
  1541. {
  1542. $Data["Axis"][$AxisID]["Min"] = $ManualScale[$AxisID]["Min"];
  1543. $Data["Axis"][$AxisID]["Max"] = $ManualScale[$AxisID]["Max"];
  1544. }
  1545. else
  1546. { echo "Manual scale boundaries not set."; exit(); }
  1547. }
  1548. elseif ( $Mode == SCALE_MODE_ADDALL || $Mode == SCALE_MODE_ADDALL_START0 )
  1549. {
  1550. $Series = "";
  1551. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1552. { if ( $SerieParameter["Axis"] == $AxisID && $SerieParameter["isDrawable"] && $Data["Abscissa"] != $SerieID ) { $Series[$SerieID] = count($Data["Series"][$SerieID]["Data"]); } }
  1553. for ($ID=0;$ID<=max($Series)-1;$ID++)
  1554. {
  1555. $PointMin = 0; $PointMax = 0;
  1556. foreach($Series as $SerieID => $ValuesCount )
  1557. {
  1558. if (isset($Data["Series"][$SerieID]["Data"][$ID]) && $Data["Series"][$SerieID]["Data"][$ID] != NULL )
  1559. {
  1560. $Value = $Data["Series"][$SerieID]["Data"][$ID];
  1561. if ( $Value > 0 ) { $PointMax = $PointMax + $Value; } else { $PointMin = $PointMin + $Value; }
  1562. }
  1563. }
  1564. $AxisMax = max($AxisMax,$PointMax);
  1565. $AxisMin = min($AxisMin,$PointMin);
  1566. }
  1567. $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
  1568. $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
  1569. }
  1570. $MaxDivs = floor($Height/$MinDivHeight);
  1571. if ( $Mode == SCALE_MODE_ADDALL_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; }
  1572. $Scale = $this->computeScale($Data["Axis"][$AxisID]["Min"],$Data["Axis"][$AxisID]["Max"],$MaxDivs,$Factors,$AxisID);
  1573. $Data["Axis"][$AxisID]["Margin"] = $AxisParameter["Identity"] == AXIS_X ? $XMargin : $YMargin;
  1574. $Data["Axis"][$AxisID]["ScaleMin"] = $Scale["XMin"];
  1575. $Data["Axis"][$AxisID]["ScaleMax"] = $Scale["XMax"];
  1576. $Data["Axis"][$AxisID]["Rows"] = $Scale["Rows"];
  1577. $Data["Axis"][$AxisID]["RowHeight"] = $Scale["RowHeight"];
  1578. if ( isset($Scale["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = $Scale["Format"]; }
  1579. if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
  1580. if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
  1581. if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
  1582. }
  1583. /* Still no X axis */
  1584. if ( $GotXAxis == FALSE )
  1585. {
  1586. if ( $Abscissa != NULL )
  1587. {
  1588. $Points = count($Data["Series"][$Abscissa]["Data"]);
  1589. if ( $AutoAxisLabels )
  1590. $AxisName = isset($Data["Series"][$Abscissa]["Description"]) ? $Data["Series"][$Abscissa]["Description"] : NULL;
  1591. else
  1592. $AxisName = NULL;
  1593. }
  1594. else
  1595. {
  1596. $Points = 0;
  1597. $AxisName = isset($Data["XAxisName"]) ? $Data["XAxisName"] : NULL;
  1598. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1599. { if ( $SerieParameter["isDrawable"] ) { $Points = max($Points,count($SerieParameter["Data"])); } }
  1600. }
  1601. $AxisID = count($Data["Axis"]);
  1602. $Data["Axis"][$AxisID]["Identity"] = AXIS_X;
  1603. if ( $Pos == SCALE_POS_LEFTRIGHT ) { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_BOTTOM; } else { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_LEFT; }
  1604. if ( isset($Data["AbscissaName"]) ) { $Data["Axis"][$AxisID]["Name"] = $Data["AbscissaName"]; }
  1605. if ( $XMargin == AUTO )
  1606. {
  1607. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1608. { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
  1609. else
  1610. { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }
  1611. if ( $Points == 1 )
  1612. $Data["Axis"][$AxisID]["Margin"] = $Height / 2;
  1613. else
  1614. $Data["Axis"][$AxisID]["Margin"] = ($Height/$Points) / 2;
  1615. }
  1616. else
  1617. { $Data["Axis"][$AxisID]["Margin"] = $XMargin; }
  1618. $Data["Axis"][$AxisID]["Rows"] = $Points-1;
  1619. if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
  1620. if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
  1621. if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
  1622. }
  1623. /* Do we need to reverse the abscissa position? */
  1624. if ( $Pos != SCALE_POS_LEFTRIGHT )
  1625. {
  1626. if ( $Data["AbsicssaPosition"] == AXIS_POSITION_BOTTOM )
  1627. { $Data["AbsicssaPosition"] = AXIS_POSITION_LEFT; }
  1628. else
  1629. { $Data["AbsicssaPosition"] = AXIS_POSITION_RIGHT; }
  1630. }
  1631. $Data["Axis"][$AxisID]["Position"] = $Data["AbsicssaPosition"];
  1632. $this->DataSet->saveOrientation($Pos);
  1633. $this->DataSet->saveAxisConfig($Data["Axis"]);
  1634. $this->DataSet->saveYMargin($YMargin);
  1635. $FontColorRo = $this->FontColorR; $FontColorGo = $this->FontColorG; $FontColorBo = $this->FontColorB;
  1636. $AxisPos["L"] = $this->GraphAreaX1; $AxisPos["R"] = $this->GraphAreaX2; $AxisPos["T"] = $this->GraphAreaY1; $AxisPos["B"] = $this->GraphAreaY2;
  1637. foreach($Data["Axis"] as $AxisID => $Parameters)
  1638. {
  1639. if ( isset($Parameters["Color"]) )
  1640. {
  1641. $AxisR = $Parameters["Color"]["R"]; $AxisG = $Parameters["Color"]["G"]; $AxisB = $Parameters["Color"]["B"];
  1642. $TickR = $Parameters["Color"]["R"]; $TickG = $Parameters["Color"]["G"]; $TickB = $Parameters["Color"]["B"];
  1643. $this->setFontProperties(array("R"=>$Parameters["Color"]["R"],"G"=>$Parameters["Color"]["G"],"B"=>$Parameters["Color"]["B"]));
  1644. }
  1645. else
  1646. {
  1647. $AxisR = $AxisRo; $AxisG = $AxisGo; $AxisB = $AxisBo;
  1648. $TickR = $TickRo; $TickG = $TickGo; $TickB = $TickBo;
  1649. $this->setFontProperties(array("R"=>$FontColorRo,"G"=>$FontColorGo,"B"=>$FontColorBo));
  1650. }
  1651. $LastValue = "w00t"; $ID = 1;
  1652. if ( $Parameters["Identity"] == AXIS_X )
  1653. {
  1654. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1655. {
  1656. if ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
  1657. {
  1658. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 2; }
  1659. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }
  1660. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 5; }
  1661. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }
  1662. if ( !$RemoveXAxis )
  1663. {
  1664. if ( $Floating )
  1665. { $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)); }
  1666. else
  1667. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1668. 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)); }
  1669. }
  1670. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1671. if ($Parameters["Rows"] == 0 ) { $Step = $Width; } else { $Step = $Width / ($Parameters["Rows"]); }
  1672. $MaxBottom = $AxisPos["B"];
  1673. for($i=0;$i<=$Parameters["Rows"];$i++)
  1674. {
  1675. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1676. $YPos = $AxisPos["B"];
  1677. if ( $Abscissa != NULL )
  1678. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1679. else
  1680. {
  1681. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1682. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1683. else
  1684. $Value = $i;
  1685. }
  1686. $ID++; $Skipped = TRUE;
  1687. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1688. {
  1689. $Bounds = $this->drawText($XPos,$YPos+$OuterTickWidth+$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1690. $TxtBottom = $YPos+$OuterTickWidth+2+($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  1691. $MaxBottom = max($MaxBottom,$TxtBottom);
  1692. $LastValue = $Value;
  1693. $Skipped = FALSE;
  1694. }
  1695. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1696. if ( $Skipped )
  1697. {
  1698. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
  1699. if ( ($SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis) { $this->drawLine($XPos,$YPos-$SkippedInnerTickWidth,$XPos,$YPos+$SkippedOuterTickWidth,$SkippedTickColor); }
  1700. }
  1701. else
  1702. {
  1703. 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)); }
  1704. if ( ($InnerTickWidth !=0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1705. }
  1706. }
  1707. if ( isset($Parameters["Name"]) && !$RemoveXAxis)
  1708. {
  1709. $YPos = $MaxBottom+2;
  1710. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1711. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  1712. $MaxBottom = $Bounds[0]["Y"];
  1713. $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
  1714. }
  1715. $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
  1716. }
  1717. elseif ( $Parameters["Position"] == AXIS_POSITION_TOP )
  1718. {
  1719. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 2; }
  1720. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }
  1721. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 5; }
  1722. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }
  1723. if ( !$RemoveXAxis )
  1724. {
  1725. if ( $Floating )
  1726. { $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)); }
  1727. else
  1728. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1729. 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)); }
  1730. }
  1731. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1732. if ($Parameters["Rows"] == 0 ) { $Step = $Width; } else { $Step = $Width / $Parameters["Rows"]; }
  1733. $MinTop = $AxisPos["T"];
  1734. for($i=0;$i<=$Parameters["Rows"];$i++)
  1735. {
  1736. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1737. $YPos = $AxisPos["T"];
  1738. if ( $Abscissa != NULL )
  1739. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1740. else
  1741. {
  1742. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1743. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1744. else
  1745. $Value = $i;
  1746. }
  1747. $ID++; $Skipped = TRUE;
  1748. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1749. {
  1750. $Bounds = $this->drawText($XPos,$YPos-$OuterTickWidth-$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1751. $TxtBox = $YPos-$OuterTickWidth-2-($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  1752. $MinTop = min($MinTop,$TxtBox);
  1753. $LastValue = $Value;
  1754. $Skipped = FALSE;
  1755. }
  1756. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1757. if ( $Skipped )
  1758. {
  1759. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
  1760. if ( ($SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis ) { $this->drawLine($XPos,$YPos+$SkippedInnerTickWidth,$XPos,$YPos-$SkippedOuterTickWidth,$SkippedTickColor); }
  1761. }
  1762. else
  1763. {
  1764. if ( $DrawXLines ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1765. if ( ($InnerTickWidth !=0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos,$YPos+$InnerTickWidth,$XPos,$YPos-$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1766. }
  1767. }
  1768. if ( isset($Parameters["Name"]) && !$RemoveXAxis )
  1769. {
  1770. $YPos = $MinTop-2;
  1771. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1772. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  1773. $MinTop = $Bounds[2]["Y"];
  1774. $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
  1775. }
  1776. $AxisPos["T"] = $MinTop - $ScaleSpacing;
  1777. }
  1778. }
  1779. elseif ( $Pos == SCALE_POS_TOPBOTTOM )
  1780. {
  1781. if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
  1782. {
  1783. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -2; }
  1784. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -6; }
  1785. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -2; }
  1786. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -5; }
  1787. if ( !$RemoveXAxis )
  1788. {
  1789. if ( $Floating )
  1790. { $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)); }
  1791. else
  1792. { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1793. 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)); }
  1794. }
  1795. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1796. if ($Parameters["Rows"] == 0 ) { $Step = $Height; } else { $Step = $Height / $Parameters["Rows"]; }
  1797. $MinLeft = $AxisPos["L"];
  1798. for($i=0;$i<=$Parameters["Rows"];$i++)
  1799. {
  1800. $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
  1801. $XPos = $AxisPos["L"];
  1802. if ( $Abscissa != NULL )
  1803. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1804. else
  1805. {
  1806. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1807. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1808. else
  1809. $Value = $i;
  1810. }
  1811. $ID++; $Skipped = TRUE;
  1812. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1813. {
  1814. $Bounds = $this->drawText($XPos-$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1815. $TxtBox = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
  1816. $MinLeft = min($MinLeft,$TxtBox);
  1817. $LastValue = $Value;
  1818. $Skipped = FALSE;
  1819. }
  1820. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1821. if ( $Skipped )
  1822. {
  1823. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
  1824. if ( ($SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis ) { $this->drawLine($XPos-$SkippedOuterTickWidth,$YPos,$XPos+$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
  1825. }
  1826. else
  1827. {
  1828. 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)); }
  1829. if ( ($InnerTickWidth !=0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1830. }
  1831. }
  1832. if ( isset($Parameters["Name"]) && !$RemoveXAxis )
  1833. {
  1834. $XPos = $MinLeft-2;
  1835. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1836. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
  1837. $MinLeft = $Bounds[0]["X"];
  1838. $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
  1839. }
  1840. $AxisPos["L"] = $MinLeft - $ScaleSpacing;
  1841. }
  1842. elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
  1843. {
  1844. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 2; }
  1845. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 6; }
  1846. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 5; }
  1847. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 7; }
  1848. if ( !$RemoveXAxis )
  1849. {
  1850. if ( $Floating )
  1851. { $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)); }
  1852. else
  1853. { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1854. 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)); }
  1855. }
  1856. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1857. if ($Parameters["Rows"] == 0 ) { $Step = $Height; } else { $Step = $Height / $Parameters["Rows"]; }
  1858. $MaxRight = $AxisPos["R"];
  1859. for($i=0;$i<=$Parameters["Rows"];$i++)
  1860. {
  1861. $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
  1862. $XPos = $AxisPos["R"];
  1863. if ( $Abscissa != NULL )
  1864. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1865. else
  1866. {
  1867. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1868. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1869. else
  1870. $Value = $i;
  1871. }
  1872. $ID++; $Skipped = TRUE;
  1873. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1874. {
  1875. $Bounds = $this->drawText($XPos+$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1876. $TxtBox = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
  1877. $MaxRight = max($MaxRight,$TxtBox);
  1878. $LastValue = $Value;
  1879. $Skipped = FALSE;
  1880. }
  1881. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1882. if ( $Skipped )
  1883. {
  1884. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
  1885. if ( ($SkippedInnerTickWidth != 0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis ) { $this->drawLine($XPos+$SkippedOuterTickWidth,$YPos,$XPos-$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
  1886. }
  1887. else
  1888. {
  1889. if ( $DrawXLines ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1890. if ( ($InnerTickWidth != 0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos+$OuterTickWidth,$YPos,$XPos-$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1891. }
  1892. }
  1893. if ( isset($Parameters["Name"]) && !$RemoveXAxis)
  1894. {
  1895. $XPos = $MaxRight+4;
  1896. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1897. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
  1898. $MaxRight = $Bounds[1]["X"];
  1899. $this->DataSet->Data["GraphArea"]["X2"] = $MaxRight + $this->FontSize;
  1900. }
  1901. $AxisPos["R"] = $MaxRight + $ScaleSpacing;
  1902. }
  1903. }
  1904. }
  1905. if ( $Parameters["Identity"] == AXIS_Y )
  1906. {
  1907. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1908. {
  1909. if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
  1910. {
  1911. if ( $Floating )
  1912. { $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)); }
  1913. else
  1914. { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1915. 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)); }
  1916. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1917. $Step = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinLeft = $AxisPos["L"];
  1918. $LastY = NULL;
  1919. for($i=0;$i<=$Parameters["Rows"];$i++)
  1920. {
  1921. $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
  1922. $XPos = $AxisPos["L"];
  1923. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1924. 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); }
  1925. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  1926. 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)); }
  1927. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1928. $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1929. $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1930. $Bounds = $this->drawText($XPos-$OuterTickWidth-2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLERIGHT));
  1931. $TxtLeft = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
  1932. $MinLeft = min($MinLeft,$TxtLeft);
  1933. $LastY = $YPos;
  1934. }
  1935. if ( isset($Parameters["Name"]) )
  1936. {
  1937. $XPos = $MinLeft-2;
  1938. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1939. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
  1940. $MinLeft = $Bounds[2]["X"];
  1941. $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
  1942. }
  1943. $AxisPos["L"] = $MinLeft - $ScaleSpacing;
  1944. }
  1945. elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
  1946. {
  1947. if ( $Floating )
  1948. { $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)); }
  1949. else
  1950. { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1951. 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)); }
  1952. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1953. $Step = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxLeft = $AxisPos["R"];
  1954. $LastY = NULL;
  1955. for($i=0;$i<=$Parameters["Rows"];$i++)
  1956. {
  1957. $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
  1958. $XPos = $AxisPos["R"];
  1959. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1960. 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); }
  1961. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  1962. 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)); }
  1963. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1964. $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1965. $this->drawLine($XPos-$InnerTickWidth,$YPos,$XPos+$OuterTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1966. $Bounds = $this->drawText($XPos+$OuterTickWidth+2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
  1967. $TxtLeft = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
  1968. $MaxLeft = max($MaxLeft,$TxtLeft);
  1969. $LastY = $YPos;
  1970. }
  1971. if ( isset($Parameters["Name"]) )
  1972. {
  1973. $XPos = $MaxLeft+6;
  1974. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1975. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
  1976. $MaxLeft = $Bounds[2]["X"];
  1977. $this->DataSet->Data["GraphArea"]["X2"] = $MaxLeft + $this->FontSize;
  1978. }
  1979. $AxisPos["R"] = $MaxLeft + $ScaleSpacing;
  1980. }
  1981. }
  1982. elseif ( $Pos == SCALE_POS_TOPBOTTOM )
  1983. {
  1984. if ( $Parameters["Position"] == AXIS_POSITION_TOP )
  1985. {
  1986. if ( $Floating )
  1987. { $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)); }
  1988. else
  1989. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1990. 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)); }
  1991. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1992. $Step = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinTop = $AxisPos["T"];
  1993. $LastX = NULL;
  1994. for($i=0;$i<=$Parameters["Rows"];$i++)
  1995. {
  1996. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1997. $YPos = $AxisPos["T"];
  1998. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1999. 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); }
  2000. if ( $LastX != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }
  2001. 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)); }
  2002. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  2003. $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  2004. $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  2005. $Bounds = $this->drawText($XPos,$YPos-$OuterTickWidth-2,$Value,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2006. $TxtHeight = $YPos-$OuterTickWidth-2-($Bounds[1]["Y"]-$Bounds[2]["Y"]);
  2007. $MinTop = min($MinTop,$TxtHeight);
  2008. $LastX = $XPos;
  2009. }
  2010. if ( isset($Parameters["Name"]) )
  2011. {
  2012. $YPos = $MinTop-2;
  2013. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  2014. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2015. $MinTop = $Bounds[2]["Y"];
  2016. $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
  2017. }
  2018. $AxisPos["T"] = $MinTop - $ScaleSpacing;
  2019. }
  2020. elseif ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
  2021. {
  2022. if ( $Floating )
  2023. { $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)); }
  2024. else
  2025. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  2026. 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)); }
  2027. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  2028. $Step = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxBottom = $AxisPos["B"];
  2029. $LastX = NULL;
  2030. for($i=0;$i<=$Parameters["Rows"];$i++)
  2031. {
  2032. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  2033. $YPos = $AxisPos["B"];
  2034. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  2035. 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); }
  2036. if ( $LastX != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }
  2037. 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)); }
  2038. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  2039. $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  2040. $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  2041. $Bounds = $this->drawText($XPos,$YPos+$OuterTickWidth+2,$Value,array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  2042. $TxtHeight = $YPos+$OuterTickWidth+2+($Bounds[1]["Y"]-$Bounds[2]["Y"]);
  2043. $MaxBottom = max($MaxBottom,$TxtHeight);
  2044. $LastX = $XPos;
  2045. }
  2046. if ( isset($Parameters["Name"]) )
  2047. {
  2048. $YPos = $MaxBottom+2;
  2049. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  2050. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  2051. $MaxBottom = $Bounds[0]["Y"];
  2052. $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
  2053. }
  2054. $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
  2055. }
  2056. }
  2057. }
  2058. }
  2059. }
  2060. function isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip)
  2061. {
  2062. if ( $LabelingMethod == LABELING_DIFFERENT && $Value != $LastValue ) { return(TRUE); }
  2063. if ( $LabelingMethod == LABELING_DIFFERENT && $Value == $LastValue ) { return(FALSE); }
  2064. if ( $LabelingMethod == LABELING_ALL && $LabelSkip == 0 ) { return(TRUE); }
  2065. if ( $LabelingMethod == LABELING_ALL && ($ID+$LabelSkip) % ($LabelSkip+1) != 1 ) { return(FALSE); }
  2066. return(TRUE);
  2067. }
  2068. /* Compute the scale, check for the best visual factors */
  2069. function computeScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID=0)
  2070. {
  2071. /* Compute each factors */
  2072. $Results = "";
  2073. foreach ($Factors as $Key => $Factor)
  2074. $Results[$Factor] = $this->processScale($XMin,$XMax,$MaxDivs,array($Factor),$AxisID);
  2075. /* Remove scales that are creating to much decimals */
  2076. $GoodScaleFactors = "";
  2077. foreach ($Results as $Key => $Result)
  2078. {
  2079. $Decimals = preg_split("/\./",$Result["RowHeight"]);
  2080. if ( (!isset($Decimals[1])) || (strlen($Decimals[1]) < 6) ) { $GoodScaleFactors[] = $Key; }
  2081. }
  2082. /* Found no correct scale, shame,... returns the 1st one as default */
  2083. if ( $GoodScaleFactors == "" ) { return($Results[$Factors[0]]); }
  2084. /* Find the factor that cause the maximum number of Rows */
  2085. $MaxRows = 0; $BestFactor = 0;
  2086. foreach($GoodScaleFactors as $Key => $Factor)
  2087. { if ( $Results[$Factor]["Rows"] > $MaxRows ) { $MaxRows = $Results[$Factor]["Rows"]; $BestFactor = $Factor; } }
  2088. /* Return the best visual scale */
  2089. return($Results[$BestFactor]);
  2090. }
  2091. /* Compute the best matching scale based on size & factors */
  2092. function processScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID)
  2093. {
  2094. $ScaleHeight = abs(ceil($XMax)-floor($XMin));
  2095. if ( isset($this->DataSet->Data["Axis"][$AxisID]["Format"]) )
  2096. $Format = $this->DataSet->Data["Axis"][$AxisID]["Format"];
  2097. else
  2098. $Format = NULL;
  2099. if ( isset($this->DataSet->Data["Axis"][$AxisID]["Display"]) )
  2100. $Mode = $this->DataSet->Data["Axis"][$AxisID]["Display"];
  2101. else
  2102. $Mode = AXIS_FORMAT_DEFAULT;
  2103. $Scale = "";
  2104. if ( $XMin != $XMax )
  2105. {
  2106. $Found = FALSE; $Rescaled = FALSE; $Scaled10Factor = .0001; $Result = 0;
  2107. while(!$Found)
  2108. {
  2109. foreach($Factors as $Key => $Factor)
  2110. {
  2111. if ( !$Found )
  2112. {
  2113. if ( !($this->modulo($XMin,$Factor*$Scaled10Factor) == 0) || ($XMin != floor($XMin))) { $XMinRescaled = floor($XMin/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor; } else { $XMinRescaled = $XMin; }
  2114. if ( !($this->modulo($XMax,$Factor*$Scaled10Factor) == 0) || ($XMax != floor($XMax))) { $XMaxRescaled = floor($XMax/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor+($Factor*$Scaled10Factor); } else { $XMaxRescaled = $XMax; }
  2115. $ScaleHeightRescaled = abs($XMaxRescaled-$XMinRescaled);
  2116. if ( !$Found && floor($ScaleHeightRescaled/($Factor*$Scaled10Factor)) <= $MaxDivs ) { $Found = TRUE; $Rescaled = TRUE; $Result = $Factor * $Scaled10Factor; }
  2117. }
  2118. }
  2119. $Scaled10Factor = $Scaled10Factor * 10;
  2120. }
  2121. /* ReCall Min / Max / Height */
  2122. if ( $Rescaled ) { $XMin = $XMinRescaled; $XMax = $XMaxRescaled; $ScaleHeight = $ScaleHeightRescaled; }
  2123. /* Compute rows size */
  2124. $Rows = floor($ScaleHeight / $Result); if ( $Rows == 0 ) { $Rows = 1; }
  2125. $RowHeight = $ScaleHeight / $Rows;
  2126. /* Return the results */
  2127. $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin; $Scale["XMax"] = $XMax;
  2128. /* Compute the needed decimals for the metric view to avoid repetition of the same X Axis labels */
  2129. if ( $Mode == AXIS_FORMAT_METRIC && $Format == NULL )
  2130. {
  2131. $Done = FALSE; $GoodDecimals = 0;
  2132. for($Decimals=0;$Decimals<=10;$Decimals++)
  2133. {
  2134. if ( !$Done )
  2135. {
  2136. $LastLabel = "zob"; $ScaleOK = TRUE;
  2137. for($i=0;$i<=$Rows;$i++)
  2138. {
  2139. $Value = $XMin + $i*$RowHeight;
  2140. $Label = $this->scaleFormat($Value,AXIS_FORMAT_METRIC,$Decimals);
  2141. if ( $LastLabel == $Label ) { $ScaleOK = FALSE; }
  2142. $LastLabel = $Label;
  2143. }
  2144. if ( $ScaleOK ) { $Done = TRUE; $GoodDecimals = $Decimals; }
  2145. }
  2146. }
  2147. $Scale["Format"] = $GoodDecimals;
  2148. }
  2149. }
  2150. else
  2151. {
  2152. /* If all values are the same we keep a +1/-1 scale */
  2153. $Rows = 2; $XMin = $XMax-1; $XMax = $XMax+1; $RowHeight = 1;
  2154. /* Return the results */
  2155. $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin; $Scale["XMax"] = $XMax;
  2156. }
  2157. return($Scale);
  2158. }
  2159. function modulo($Value1,$Value2)
  2160. {
  2161. if (floor($Value2) == 0) { return(0); }
  2162. if (floor($Value2) != 0) { return($Value1 % $Value2); }
  2163. $MinValue = min($Value1,$Value2); $Factor = 10;
  2164. while ( floor($MinValue*$Factor) == 0 )
  2165. { $Factor = $Factor * 10; }
  2166. return(($Value1*$Factor) % ($Value2*$Factor));
  2167. }
  2168. /* Draw an X threshold */
  2169. function drawXThreshold($Value,$Format="")
  2170. {
  2171. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2172. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2173. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2174. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
  2175. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  2176. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
  2177. $Wide = isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
  2178. $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
  2179. $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
  2180. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : NULL;
  2181. $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
  2182. $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 5;
  2183. $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
  2184. $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
  2185. $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
  2186. $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
  2187. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2188. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2189. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 3;
  2190. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2191. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2192. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2193. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2194. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2195. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 30;
  2196. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2197. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2198. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2199. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2200. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2201. $ValueIsLabel = isset($Format["ValueIsLabel"]) ? $Format["ValueIsLabel"] : FALSE;
  2202. $Data = $this->DataSet->getData();
  2203. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2204. $XScale = $this->scaleGetXSettings();
  2205. if ( is_array($Value) ) { foreach ($Value as $Key => $ID) { $this->drawXThreshold($ID,$Format); } return(0); }
  2206. if ( $ValueIsLabel )
  2207. {
  2208. $Format["ValueIsLabel"] = FALSE;
  2209. foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $SerieValue)
  2210. { if ( $SerieValue == $Value ) { $this->drawXThreshold($Key,$Format); } }
  2211. return(0);
  2212. }
  2213. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2214. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2215. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
  2216. "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);
  2217. if ( $Caption == NULL )
  2218. {
  2219. if ( isset($Data["Abscissa"]) )
  2220. {
  2221. if ( isset($Data["Series"][$Data["Abscissa"]]["Data"][$Value]) )
  2222. $Caption = $Data["Series"][$Data["Abscissa"]]["Data"][$Value];
  2223. else
  2224. $Caption = $Value;
  2225. }
  2226. else
  2227. $Caption = $Value;
  2228. }
  2229. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2230. {
  2231. $XStep = (($this->GraphAreaX2 - $this->GraphAreaX1) - $XScale[0] *2 ) / $XScale[1];
  2232. $XPos = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value;
  2233. $YPos1 = $this->GraphAreaY1 + $Data["YMargin"];
  2234. $YPos2 = $this->GraphAreaY2 - $Data["YMargin"];
  2235. if ( $XPos >= $this->GraphAreaX1 + $AbscissaMargin && $XPos <= $this->GraphAreaX2 - $AbscissaMargin )
  2236. {
  2237. $this->drawLine($XPos,$YPos1,$XPos,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2238. if ( $Wide )
  2239. {
  2240. $this->drawLine($XPos-1,$YPos1,$XPos-1,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2241. $this->drawLine($XPos+1,$YPos1,$XPos+1,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2242. }
  2243. if ( $WriteCaption )
  2244. {
  2245. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2246. { $Y = $YPos1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
  2247. else
  2248. { $Y = $YPos2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
  2249. $this->drawText($XPos,$Y,$Caption,$CaptionSettings);
  2250. }
  2251. return(array("X"=>$XPos));
  2252. }
  2253. }
  2254. elseif( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2255. {
  2256. $XStep = (($this->GraphAreaY2 - $this->GraphAreaY1) - $XScale[0] *2 ) / $XScale[1];
  2257. $XPos = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value;
  2258. $YPos1 = $this->GraphAreaX1 + $Data["YMargin"];
  2259. $YPos2 = $this->GraphAreaX2 - $Data["YMargin"];
  2260. if ( $XPos >= $this->GraphAreaY1 + $AbscissaMargin && $XPos <= $this->GraphAreaY2 - $AbscissaMargin )
  2261. {
  2262. $this->drawLine($YPos1,$XPos,$YPos2,$XPos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2263. if ( $Wide )
  2264. {
  2265. $this->drawLine($YPos1,$XPos-1,$YPos2,$XPos-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2266. $this->drawLine($YPos1,$XPos+1,$YPos2,$XPos+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2267. }
  2268. if ( $WriteCaption )
  2269. {
  2270. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2271. { $Y = $YPos1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
  2272. else
  2273. { $Y = $YPos2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
  2274. $this->drawText($Y,$XPos,$Caption,$CaptionSettings);
  2275. }
  2276. return(array("X"=>$XPos));
  2277. }
  2278. }
  2279. }
  2280. /* Draw an X threshold area */
  2281. function drawXThresholdArea($Value1,$Value2,$Format="")
  2282. {
  2283. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2284. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2285. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2286. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
  2287. $Border = isset($Format["Border"]) ? $Format["Border"] : TRUE;
  2288. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  2289. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  2290. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  2291. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
  2292. $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
  2293. $AreaName = isset($Format["AreaName"]) ? $Format["AreaName"] : NULL;
  2294. $NameAngle = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
  2295. $NameR = isset($Format["NameR"]) ? $Format["NameR"] : 255;
  2296. $NameG = isset($Format["NameG"]) ? $Format["NameG"] : 255;
  2297. $NameB = isset($Format["NameB"]) ? $Format["NameB"] : 255;
  2298. $NameAlpha = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
  2299. $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : TRUE;
  2300. $RestoreShadow = $this->Shadow;
  2301. if ( $DisableShadowOnArea && $this->Shadow ) { $this->Shadow = FALSE; }
  2302. if ($BorderAlpha >100) { $BorderAlpha = 100;}
  2303. $Data = $this->DataSet->getData();
  2304. $XScale = $this->scaleGetXSettings();
  2305. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2306. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2307. {
  2308. $XStep = (($this->GraphAreaX2 - $this->GraphAreaX1) - $XScale[0] *2 ) / $XScale[1];
  2309. $XPos1 = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value1;
  2310. $XPos2 = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value2;
  2311. $YPos1 = $this->GraphAreaY1 + $Data["YMargin"];
  2312. $YPos2 = $this->GraphAreaY2 - $Data["YMargin"];
  2313. if ( $XPos1 < $this->GraphAreaX1 + $XScale[0] ) { $XPos1 = $this->GraphAreaX1 + $XScale[0]; }
  2314. if ( $XPos1 > $this->GraphAreaX2 - $XScale[0] ) { $XPos1 = $this->GraphAreaX2 - $XScale[0]; }
  2315. if ( $XPos2 < $this->GraphAreaX1 + $XScale[0] ) { $XPos2 = $this->GraphAreaX1 + $XScale[0]; }
  2316. if ( $XPos2 > $this->GraphAreaX2 - $XScale[0] ) { $XPos2 = $this->GraphAreaX2 - $XScale[0]; }
  2317. $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2318. if ( $Border )
  2319. {
  2320. $this->drawLine($XPos1,$YPos1,$XPos1,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2321. $this->drawLine($XPos2,$YPos1,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2322. }
  2323. if ( $AreaName != NULL )
  2324. {
  2325. $XPos = ($XPos2-$XPos1)/2 + $XPos1;
  2326. $YPos = ($YPos2-$YPos1)/2 + $YPos1;
  2327. if ( $NameAngle == ZONE_NAME_ANGLE_AUTO )
  2328. {
  2329. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$AreaName);
  2330. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
  2331. if ( abs($XPos2 - $XPos1) > $TxtWidth ) { $NameAngle = 0; } else { $NameAngle = 90; }
  2332. }
  2333. $this->Shadow = $RestoreShadow;
  2334. $this->drawText($XPos,$YPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>$NameAngle,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2335. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2336. }
  2337. $this->Shadow = $RestoreShadow;
  2338. return(array("X1"=>$XPos1,"X2"=>$XPos2));
  2339. }
  2340. elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2341. {
  2342. $XStep = (($this->GraphAreaY2 - $this->GraphAreaY1) - $XScale[0] *2 ) / $XScale[1];
  2343. $XPos1 = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value1;
  2344. $XPos2 = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value2;
  2345. $YPos1 = $this->GraphAreaX1 + $Data["YMargin"];
  2346. $YPos2 = $this->GraphAreaX2 - $Data["YMargin"];
  2347. if ( $XPos1 < $this->GraphAreaY1 + $XScale[0] ) { $XPos1 = $this->GraphAreaY1 + $XScale[0]; }
  2348. if ( $XPos1 > $this->GraphAreaY2 - $XScale[0] ) { $XPos1 = $this->GraphAreaY2 - $XScale[0]; }
  2349. if ( $XPos2 < $this->GraphAreaY1 + $XScale[0] ) { $XPos2 = $this->GraphAreaY1 + $XScale[0]; }
  2350. if ( $XPos2 > $this->GraphAreaY2 - $XScale[0] ) { $XPos2 = $this->GraphAreaY2 - $XScale[0]; }
  2351. $this->drawFilledRectangle($YPos1,$XPos1,$YPos2,$XPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2352. if ( $Border )
  2353. {
  2354. $this->drawLine($YPos1,$XPos1,$YPos2,$XPos1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2355. $this->drawLine($YPos1,$XPos2,$YPos2,$XPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2356. }
  2357. if ( $AreaName != NULL )
  2358. {
  2359. $XPos = ($XPos2-$XPos1)/2 + $XPos1;
  2360. $YPos = ($YPos2-$YPos1)/2 + $YPos1;
  2361. $this->Shadow = $RestoreShadow;
  2362. $this->drawText($YPos,$XPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2363. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2364. }
  2365. $this->Shadow = $RestoreShadow;
  2366. return(array("X1"=>$XPos1,"X2"=>$XPos2));
  2367. }
  2368. }
  2369. /* Draw an Y threshold with the computed scale */
  2370. function drawThreshold($Value,$Format="")
  2371. {
  2372. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  2373. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2374. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2375. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2376. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
  2377. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  2378. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
  2379. $Wide = isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
  2380. $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
  2381. $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
  2382. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : NULL;
  2383. $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
  2384. $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
  2385. $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
  2386. $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
  2387. $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
  2388. $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
  2389. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2390. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2391. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
  2392. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2393. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2394. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2395. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2396. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2397. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
  2398. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2399. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2400. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2401. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2402. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2403. $NoMargin = isset($Format["NoMargin"]) ? $Format["NoMargin"] : FALSE;
  2404. if ( is_array($Value) ) { foreach ($Value as $Key => $ID) { $this->drawThreshold($ID,$Format); } return(0); }
  2405. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2406. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2407. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
  2408. "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);
  2409. $Data = $this->DataSet->getData();
  2410. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2411. if ( $NoMargin ) { $AbscissaMargin = 0; }
  2412. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2413. if ( $Caption == NULL ) { $Caption = $Value; }
  2414. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2415. {
  2416. $YPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
  2417. if ( $YPos >= $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"] && $YPos <= $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"] )
  2418. {
  2419. $X1 = $this->GraphAreaX1 + $AbscissaMargin;
  2420. $X2 = $this->GraphAreaX2 - $AbscissaMargin;
  2421. $this->drawLine($X1,$YPos,$X2,$YPos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2422. if ( $Wide )
  2423. {
  2424. $this->drawLine($X1,$YPos-1,$X2,$YPos-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2425. $this->drawLine($X1,$YPos+1,$X2,$YPos+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2426. }
  2427. if ( $WriteCaption )
  2428. {
  2429. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2430. { $X = $X1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
  2431. else
  2432. { $X = $X2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
  2433. $this->drawText($X,$YPos,$Caption,$CaptionSettings);
  2434. }
  2435. }
  2436. return(array("Y"=>$YPos));
  2437. }
  2438. if ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2439. {
  2440. $XPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
  2441. if ( $XPos >= $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"] && $XPos <= $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"] )
  2442. {
  2443. $Y1 = $this->GraphAreaY1 + $AbscissaMargin;
  2444. $Y2 = $this->GraphAreaY2 - $AbscissaMargin;
  2445. $this->drawLine($XPos,$Y1,$XPos,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2446. if ( $Wide )
  2447. {
  2448. $this->drawLine($XPos-1,$Y1,$XPos-1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2449. $this->drawLine($XPos+1,$Y1,$XPos+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2450. }
  2451. if ( $WriteCaption )
  2452. {
  2453. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2454. { $Y = $Y1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
  2455. else
  2456. { $Y = $Y2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
  2457. $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
  2458. $this->drawText($XPos,$Y,$Caption,$CaptionSettings);
  2459. }
  2460. }
  2461. return(array("Y"=>$XPos));
  2462. }
  2463. }
  2464. /* Draw a threshold with the computed scale */
  2465. function drawThresholdArea($Value1,$Value2,$Format="")
  2466. {
  2467. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  2468. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2469. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2470. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2471. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
  2472. $Border = isset($Format["Border"]) ? $Format["Border"] : TRUE;
  2473. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  2474. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  2475. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  2476. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
  2477. $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
  2478. $AreaName = isset($Format["AreaName"]) ? $Format["AreaName"] : NULL;
  2479. $NameAngle = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
  2480. $NameR = isset($Format["NameR"]) ? $Format["NameR"] : 255;
  2481. $NameG = isset($Format["NameG"]) ? $Format["NameG"] : 255;
  2482. $NameB = isset($Format["NameB"]) ? $Format["NameB"] : 255;
  2483. $NameAlpha = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
  2484. $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : TRUE;
  2485. $NoMargin = isset($Format["NoMargin"]) ? $Format["NoMargin"] : FALSE;
  2486. if ($Value1 > $Value2) { list($Value1, $Value2) = array($Value2, $Value1); }
  2487. $RestoreShadow = $this->Shadow;
  2488. if ( $DisableShadowOnArea && $this->Shadow ) { $this->Shadow = FALSE; }
  2489. if ($BorderAlpha >100) { $BorderAlpha = 100;}
  2490. $Data = $this->DataSet->getData();
  2491. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2492. if ( $NoMargin ) { $AbscissaMargin = 0; }
  2493. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2494. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2495. {
  2496. $XPos1 = $this->GraphAreaX1 + $AbscissaMargin;
  2497. $XPos2 = $this->GraphAreaX2 - $AbscissaMargin;
  2498. $YPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
  2499. $YPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));
  2500. if ( $YPos1 < $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"] ) { $YPos1 = $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"]; }
  2501. if ( $YPos1 > $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"] ) { $YPos1 = $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"]; }
  2502. if ( $YPos2 < $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"] ) { $YPos2 = $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"]; }
  2503. if ( $YPos2 > $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"] ) { $YPos2 = $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"]; }
  2504. $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2505. if ( $Border )
  2506. {
  2507. $this->drawLine($XPos1,$YPos1,$XPos2,$YPos1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2508. $this->drawLine($XPos1,$YPos2,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2509. }
  2510. if ( $AreaName != NULL )
  2511. {
  2512. $XPos = ($XPos2-$XPos1)/2 + $XPos1;
  2513. $YPos = ($YPos2-$YPos1)/2 + $YPos1;
  2514. $this->Shadow = $RestoreShadow;
  2515. $this->drawText($XPos,$YPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2516. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2517. }
  2518. $this->Shadow = $RestoreShadow;
  2519. return(array("Y1"=>$YPos1,"Y2"=>$YPos2));
  2520. }
  2521. elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2522. {
  2523. $YPos1 = $this->GraphAreaY1 + $AbscissaMargin;
  2524. $YPos2 = $this->GraphAreaY2 - $AbscissaMargin;
  2525. $XPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
  2526. $XPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));
  2527. if ( $XPos1 < $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"] ) { $XPos1 = $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"]; }
  2528. if ( $XPos1 > $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"] ) { $XPos1 = $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"]; }
  2529. if ( $XPos2 < $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"] ) { $XPos2 = $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"]; }
  2530. if ( $XPos2 > $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"] ) { $XPos2 = $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"]; }
  2531. $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2532. if ( $Border )
  2533. {
  2534. $this->drawLine($XPos1,$YPos1,$XPos1,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2535. $this->drawLine($XPos2,$YPos1,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2536. }
  2537. if ( $AreaName != NULL )
  2538. {
  2539. $XPos = ($YPos2-$YPos1)/2 + $YPos1;
  2540. $YPos = ($XPos2-$XPos1)/2 + $XPos1;
  2541. if ( $NameAngle == ZONE_NAME_ANGLE_AUTO )
  2542. {
  2543. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$AreaName);
  2544. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
  2545. if ( abs($XPos2 - $XPos1) > $TxtWidth ) { $NameAngle = 0; } else { $NameAngle = 90; }
  2546. }
  2547. $this->Shadow = $RestoreShadow;
  2548. $this->drawText($YPos,$XPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>$NameAngle,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2549. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2550. }
  2551. $this->Shadow = $RestoreShadow;
  2552. return(array("Y1"=>$XPos1,"Y2"=>$XPos2));
  2553. }
  2554. }
  2555. function scaleGetXSettings()
  2556. {
  2557. $Data = $this->DataSet->getData();
  2558. foreach($Data["Axis"] as $AxisID => $Settings)
  2559. {
  2560. if ( $Settings["Identity"] == AXIS_X )
  2561. {
  2562. $Rows = $Settings["Rows"];
  2563. return(array($Settings["Margin"],$Rows));
  2564. }
  2565. }
  2566. }
  2567. function scaleComputeY($Values,$Option="",$ReturnOnly0Height=FALSE)
  2568. {
  2569. $AxisID = isset($Option["AxisID"]) ? $Option["AxisID"] : 0;
  2570. $SerieName = isset($Option["SerieName"]) ? $Option["SerieName"] : NULL;
  2571. $Data = $this->DataSet->getData();
  2572. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2573. if ( $SerieName != NULL ) { $AxisID = $Data["Series"][$SerieName]["Axis"]; }
  2574. if ( !is_array($Values) ) { $tmp = $Values; $Values = ""; $Values[0] = $tmp; }
  2575. $Result = "";
  2576. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2577. {
  2578. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Data["Axis"][$AxisID]["Margin"]*2;
  2579. $ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  2580. $Step = $Height / $ScaleHeight;
  2581. if ( $ReturnOnly0Height )
  2582. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
  2583. else
  2584. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
  2585. }
  2586. else
  2587. {
  2588. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Data["Axis"][$AxisID]["Margin"]*2;
  2589. $ScaleWidth = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  2590. $Step = $Width / $ScaleWidth;
  2591. if ( $ReturnOnly0Height )
  2592. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
  2593. else
  2594. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
  2595. }
  2596. if ( count($Result) == 1 )
  2597. return($Result[0]);
  2598. else
  2599. return($Result);
  2600. }
  2601. /* Format the axis values */
  2602. function scaleFormat($Value,$Mode=NULL,$Format=NULL,$Unit=NULL)
  2603. {
  2604. if ( $Value == VOID ) { return(""); }
  2605. if ( $Mode == AXIS_FORMAT_TRAFFIC )
  2606. {
  2607. if ( $Value == 0 ) { return("0B"); }
  2608. $Units = array("B","KB","MB","GB","TB","PB");
  2609. $Sign = ""; if ( $Value < 0 ) { $Value = abs($Value); $Sign = "-"; }
  2610. $Value = number_format($Value/pow(1024,($Scale=floor(log($Value,1024)))),2,",",".");
  2611. return($Sign.$Value." ".$Units[$Scale]);
  2612. }
  2613. if ( $Mode == AXIS_FORMAT_CUSTOM )
  2614. { if ( function_exists($Format) ) { return(call_user_func($Format,$Value)); } }
  2615. if ( $Mode == AXIS_FORMAT_DATE )
  2616. { if ( $Format == NULL ) { $Pattern = "d/m/Y"; } else { $Pattern = $Format; } return(gmdate($Pattern,$Value)); }
  2617. if ( $Mode == AXIS_FORMAT_TIME )
  2618. { if ( $Format == NULL ) { $Pattern = "H:i:s"; } else { $Pattern = $Format; } return(gmdate($Pattern,$Value)); }
  2619. if ( $Mode == AXIS_FORMAT_CURRENCY )
  2620. { return($Format.number_format($Value,2)); }
  2621. if ( $Mode == AXIS_FORMAT_METRIC )
  2622. {
  2623. if (abs($Value) > 1000000000)
  2624. return(round($Value/1000000000,$Format)."g".$Unit);
  2625. if (abs($Value) > 1000000)
  2626. return(round($Value/1000000,$Format)."m".$Unit);
  2627. elseif (abs($Value) >= 1000)
  2628. return(round($Value/1000,$Format)."k".$Unit);
  2629. }
  2630. return($Value.$Unit);
  2631. }
  2632. /* Write Max value on a chart */
  2633. function writeBounds($Type=BOUND_BOTH,$Format=NULL)
  2634. {
  2635. $MaxLabelTxt = isset($Format["MaxLabelTxt"]) ? $Format["MaxLabelTxt"] : "max=";
  2636. $MinLabelTxt = isset($Format["MinLabelTxt"]) ? $Format["MinLabelTxt"] : "min=";
  2637. $Decimals = isset($Format["Decimals"]) ? $Format["Decimals"] : 1;
  2638. $ExcludedSeries = isset($Format["ExcludedSeries"]) ? $Format["ExcludedSeries"] : "";
  2639. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
  2640. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2641. $MaxDisplayR = isset($Format["MaxDisplayR"]) ? $Format["MaxDisplayR"] : 0;
  2642. $MaxDisplayG = isset($Format["MaxDisplayG"]) ? $Format["MaxDisplayG"] : 0;
  2643. $MaxDisplayB = isset($Format["MaxDisplayB"]) ? $Format["MaxDisplayB"] : 0;
  2644. $MinDisplayR = isset($Format["MinDisplayR"]) ? $Format["MinDisplayR"] : 255;
  2645. $MinDisplayG = isset($Format["MinDisplayG"]) ? $Format["MinDisplayG"] : 255;
  2646. $MinDisplayB = isset($Format["MinDisplayB"]) ? $Format["MinDisplayB"] : 255;
  2647. $MinLabelPos = isset($Format["MinLabelPos"]) ? $Format["MinLabelPos"] : BOUND_LABEL_POS_AUTO;
  2648. $MaxLabelPos = isset($Format["MaxLabelPos"]) ? $Format["MaxLabelPos"] : BOUND_LABEL_POS_AUTO;
  2649. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2650. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2651. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
  2652. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2653. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2654. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2655. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2656. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2657. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
  2658. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2659. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2660. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2661. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2662. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2663. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2664. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2665. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha);
  2666. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2667. $Data = $this->DataSet->getData();
  2668. foreach($Data["Series"] as $SerieName => $Serie)
  2669. {
  2670. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && !isset($ExcludedSeries[$SerieName]))
  2671. {
  2672. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2673. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2674. $MinValue = $this->DataSet->getMin($SerieName);
  2675. $MaxValue = $this->DataSet->getMax($SerieName);
  2676. $MinPos = VOID; $MaxPos = VOID;
  2677. foreach($Serie["Data"] as $Key => $Value)
  2678. {
  2679. if ( $Value == $MinValue && $MinPos == VOID ) { $MinPos = $Key; }
  2680. if ( $Value == $MaxValue ) { $MaxPos = $Key; }
  2681. }
  2682. $AxisID = $Serie["Axis"];
  2683. $Mode = $Data["Axis"][$AxisID]["Display"];
  2684. $Format = $Data["Axis"][$AxisID]["Format"];
  2685. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2686. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2687. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2688. {
  2689. $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs;
  2690. $X = $this->GraphAreaX1 + $XMargin;
  2691. $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
  2692. if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
  2693. {
  2694. if ( $MaxLabelPos == BOUND_LABEL_POS_TOP || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
  2695. if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }
  2696. $XPos = $X + $MaxPos*$XStep + $SerieOffset;
  2697. $Label = $MaxLabelTxt.$this->scaleFormat(round($MaxValue,$Decimals),$Mode,$Format,$Unit);
  2698. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
  2699. $XOffset = 0; $YOffset = 0;
  2700. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
  2701. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
  2702. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
  2703. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }
  2704. $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
  2705. $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;
  2706. $this->drawText($XPos+$XOffset,$YPos+$YOffset,$Label,$CaptionSettings);
  2707. }
  2708. if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
  2709. {
  2710. if ( $MinLabelPos == BOUND_LABEL_POS_TOP || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
  2711. if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }
  2712. $XPos = $X + $MinPos*$XStep + $SerieOffset;
  2713. $Label = $MinLabelTxt.$this->scaleFormat(round($MinValue,$Decimals),$Mode,$Format,$Unit);
  2714. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
  2715. $XOffset = 0; $YOffset = 0;
  2716. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
  2717. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
  2718. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
  2719. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }
  2720. $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
  2721. $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;
  2722. $this->drawText($XPos+$XOffset,$YPos-$DisplayOffset+$YOffset,$Label,$CaptionSettings);
  2723. }
  2724. }
  2725. else
  2726. {
  2727. $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs;
  2728. $X = $this->GraphAreaY1 + $XMargin;
  2729. $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
  2730. if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
  2731. {
  2732. if ( $MaxLabelPos == BOUND_LABEL_POS_TOP || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
  2733. if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }
  2734. $XPos = $X + $MaxPos*$XStep + $SerieOffset;
  2735. $Label = $MaxLabelTxt.$this->scaleFormat($MaxValue,$Mode,$Format,$Unit);
  2736. $TxtPos = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
  2737. $XOffset = 0; $YOffset = 0;
  2738. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
  2739. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
  2740. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
  2741. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}
  2742. $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
  2743. $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;
  2744. $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
  2745. }
  2746. if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
  2747. {
  2748. if ( $MinLabelPos == BOUND_LABEL_POS_TOP || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
  2749. if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }
  2750. $XPos = $X + $MinPos*$XStep + $SerieOffset;
  2751. $Label = $MinLabelTxt.$this->scaleFormat($MinValue,$Mode,$Format,$Unit);
  2752. $TxtPos = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
  2753. $XOffset = 0; $YOffset = 0;
  2754. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
  2755. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
  2756. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
  2757. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}
  2758. $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
  2759. $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;
  2760. $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
  2761. }
  2762. }
  2763. }
  2764. }
  2765. }
  2766. /* Draw a plot chart */
  2767. function drawPlotChart($Format=NULL)
  2768. {
  2769. $PlotSize = isset($Format["PlotSize"]) ? $Format["PlotSize"] : NULL;
  2770. $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : FALSE;
  2771. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 50;
  2772. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 50;
  2773. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 50;
  2774. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
  2775. $BorderSize = isset($Format["BorderSize"]) ? $Format["BorderSize"] : 2;
  2776. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  2777. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2778. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
  2779. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2780. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2781. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2782. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2783. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  2784. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  2785. $Data = $this->DataSet->getData();
  2786. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2787. foreach($Data["Series"] as $SerieName => $Serie)
  2788. {
  2789. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2790. {
  2791. if ( isset($Serie["Weight"]) ) { $SerieWeight = $Serie["Weight"] + 2; } else { $SerieWeight = 2; }
  2792. if ( $PlotSize != NULL ) { $SerieWeight = $PlotSize; }
  2793. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2794. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  2795. if ( isset($Serie["Picture"]) )
  2796. { $Picture = $Serie["Picture"]; list($PicWidth,$PicHeight,$PicType) = $this->getPicInfo($Picture); }
  2797. else { $Picture = NULL; $PicOffset = 0; }
  2798. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2799. $AxisID = $Serie["Axis"];
  2800. $Shape = $Serie["Shape"];
  2801. $Mode = $Data["Axis"][$AxisID]["Display"];
  2802. $Format = $Data["Axis"][$AxisID]["Format"];
  2803. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2804. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  2805. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2806. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2807. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2808. {
  2809. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2810. if ( $Picture != NULL ) { $PicOffset = $PicHeight / 2; $SerieWeight = 0; }
  2811. $X = $this->GraphAreaX1 + $XMargin;
  2812. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2813. foreach($PosArray as $Key => $Y)
  2814. {
  2815. if ( $DisplayValues )
  2816. $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));
  2817. if ( $Y != VOID )
  2818. {
  2819. if ( $RecordImageMap ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$SerieWeight,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2820. if ( $Picture != NULL )
  2821. { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
  2822. else
  2823. { $this->drawShape($X,$Y,$Shape,$SerieWeight,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha); }
  2824. }
  2825. $X = $X + $XStep;
  2826. }
  2827. }
  2828. else
  2829. {
  2830. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2831. if ( $Picture != NULL ) { $PicOffset = $PicWidth / 2; $SerieWeight = 0; }
  2832. $Y = $this->GraphAreaY1 + $XMargin;
  2833. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2834. foreach($PosArray as $Key => $X)
  2835. {
  2836. if ( $DisplayValues )
  2837. $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));
  2838. if ( $X != VOID )
  2839. {
  2840. if ( $RecordImageMap ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$SerieWeight,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2841. if ( $Picture != NULL )
  2842. { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
  2843. else
  2844. { $this->drawShape($X,$Y,$Shape,$SerieWeight,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha); }
  2845. }
  2846. $Y = $Y + $YStep;
  2847. }
  2848. }
  2849. }
  2850. }
  2851. }
  2852. /* Draw a spline chart */
  2853. function drawSplineChart($Format=NULL)
  2854. {
  2855. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
  2856. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  2857. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL; // 234
  2858. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL; // 55
  2859. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL; // 26
  2860. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2861. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2862. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2863. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2864. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2865. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2866. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  2867. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  2868. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  2869. $Data = $this->DataSet->getData();
  2870. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2871. foreach($Data["Series"] as $SerieName => $Serie)
  2872. {
  2873. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2874. {
  2875. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  2876. if ( $BreakR == NULL )
  2877. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks);
  2878. else
  2879. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  2880. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2881. $AxisID = $Serie["Axis"];
  2882. $Mode = $Data["Axis"][$AxisID]["Display"];
  2883. $Format = $Data["Axis"][$AxisID]["Format"];
  2884. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2885. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  2886. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2887. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2888. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2889. {
  2890. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2891. $X = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
  2892. $Force = $XStep / 5;
  2893. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2894. $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
  2895. foreach($PosArray as $Key => $Y)
  2896. {
  2897. if ( $DisplayValues )
  2898. $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2899. 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)); }
  2900. if ( $Y == VOID && $LastY != NULL )
  2901. { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }
  2902. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  2903. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }
  2904. if ( $Y != VOID )
  2905. $WayPoints[] = array($X,$Y);
  2906. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  2907. if ( $Y == VOID ) { $Y = NULL; }
  2908. $LastX = $X; $LastY = $Y;
  2909. $X = $X + $XStep;
  2910. }
  2911. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2912. }
  2913. else
  2914. {
  2915. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2916. $Y = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
  2917. $Force = $YStep / 5;
  2918. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2919. $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
  2920. foreach($PosArray as $Key => $X)
  2921. {
  2922. if ( $DisplayValues )
  2923. $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));
  2924. 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)); }
  2925. if ( $X == VOID && $LastX != NULL )
  2926. { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }
  2927. if ( $X != VOID && $LastX == NULL && $LastGoodX != NULL && !$BreakVoid )
  2928. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }
  2929. if ( $X != VOID )
  2930. $WayPoints[] = array($X,$Y);
  2931. if ( $X != VOID ) { $LastGoodX = $X; $LastGoodY = $Y; }
  2932. if ( $X == VOID ) { $X = NULL; }
  2933. $LastX = $X; $LastY = $Y;
  2934. $Y = $Y + $YStep;
  2935. }
  2936. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2937. }
  2938. }
  2939. }
  2940. }
  2941. /* Draw a filled spline chart */
  2942. function drawFilledSplineChart($Format=NULL)
  2943. {
  2944. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2945. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2946. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2947. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2948. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2949. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2950. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  2951. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  2952. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  2953. $Data = $this->DataSet->getData();
  2954. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2955. foreach($Data["Series"] as $SerieName => $Serie)
  2956. {
  2957. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2958. {
  2959. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2960. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2961. $AxisID = $Serie["Axis"];
  2962. $Mode = $Data["Axis"][$AxisID]["Display"];
  2963. $Format = $Data["Axis"][$AxisID]["Format"];
  2964. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2965. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2966. if ( $AroundZero ) { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }
  2967. if ( $Threshold != NULL )
  2968. {
  2969. foreach($Threshold as $Key => $Params)
  2970. {
  2971. $Threshold[$Key]["MinX"] = $this->scaleComputeY($Params["Min"],array("AxisID"=>$Serie["Axis"]));
  2972. $Threshold[$Key]["MaxX"] = $this->scaleComputeY($Params["Max"],array("AxisID"=>$Serie["Axis"]));
  2973. }
  2974. }
  2975. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2976. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2977. {
  2978. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2979. $X = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
  2980. $Force = $XStep / 5;
  2981. if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }
  2982. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  2983. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  2984. $LastX = ""; $LastY = "";
  2985. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2986. foreach($PosArray as $Key => $Y)
  2987. {
  2988. if ( $DisplayValues )
  2989. $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2990. if ( $Y == VOID )
  2991. {
  2992. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  2993. if ( $Area != "" )
  2994. {
  2995. foreach ($Area as $key => $Points)
  2996. {
  2997. $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
  2998. foreach($Points as $subKey => $Point)
  2999. {
  3000. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3001. $Corners[] = $Point["Y"]+1;
  3002. }
  3003. $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;
  3004. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3005. }
  3006. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3007. }
  3008. $WayPoints = "";
  3009. }
  3010. else
  3011. $WayPoints[] = array($X,$Y-.5); /* -.5 for AA visual fix */
  3012. $X = $X + $XStep;
  3013. }
  3014. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3015. if ( $Area != "" )
  3016. {
  3017. foreach ($Area as $key => $Points)
  3018. {
  3019. $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
  3020. foreach($Points as $subKey => $Point)
  3021. {
  3022. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3023. $Corners[] = $Point["Y"]+1;
  3024. }
  3025. $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;
  3026. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3027. }
  3028. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3029. }
  3030. }
  3031. else
  3032. {
  3033. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3034. $Y = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
  3035. $Force = $YStep / 5;
  3036. if ( !$AroundZero ) { $YZero = $this->GraphAreaX1+1; }
  3037. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3038. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3039. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3040. foreach($PosArray as $Key => $X)
  3041. {
  3042. if ( $DisplayValues )
  3043. $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));
  3044. if ( $X == VOID )
  3045. {
  3046. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3047. if ( $Area != "" )
  3048. {
  3049. foreach ($Area as $key => $Points)
  3050. {
  3051. $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
  3052. foreach($Points as $subKey => $Point)
  3053. {
  3054. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3055. $Corners[] = $Point["Y"];
  3056. }
  3057. $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;
  3058. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3059. }
  3060. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3061. }
  3062. $WayPoints = "";
  3063. }
  3064. else
  3065. $WayPoints[] = array($X,$Y);
  3066. $Y = $Y + $YStep;
  3067. }
  3068. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3069. if ( $Area != "" )
  3070. {
  3071. foreach ($Area as $key => $Points)
  3072. {
  3073. $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
  3074. foreach($Points as $subKey => $Point)
  3075. {
  3076. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3077. $Corners[] = $Point["Y"];
  3078. }
  3079. $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;
  3080. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3081. }
  3082. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3083. }
  3084. }
  3085. }
  3086. }
  3087. }
  3088. /* Draw a line chart */
  3089. function drawLineChart($Format=NULL)
  3090. {
  3091. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
  3092. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  3093. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
  3094. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
  3095. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
  3096. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3097. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3098. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3099. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3100. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3101. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3102. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3103. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  3104. $ForceColor = isset($Format["ForceColor"]) ? $Format["ForceColor"] : FALSE;
  3105. $ForceR = isset($Format["ForceR"]) ? $Format["ForceR"] : 0;
  3106. $ForceG = isset($Format["ForceG"]) ? $Format["ForceG"] : 0;
  3107. $ForceB = isset($Format["ForceB"]) ? $Format["ForceB"] : 0;
  3108. $ForceAlpha = isset($Format["ForceAlpha"]) ? $Format["ForceAlpha"] : 100;
  3109. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3110. $Data = $this->DataSet->getData();
  3111. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3112. foreach($Data["Series"] as $SerieName => $Serie)
  3113. {
  3114. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3115. {
  3116. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3117. if ( $ForceColor )
  3118. { $R = $ForceR; $G = $ForceG; $B = $ForceB; $Alpha = $ForceAlpha; }
  3119. if ( $BreakR == NULL )
  3120. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3121. else
  3122. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3123. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3124. $AxisID = $Serie["Axis"];
  3125. $Mode = $Data["Axis"][$AxisID]["Display"];
  3126. $Format = $Data["Axis"][$AxisID]["Format"];
  3127. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3128. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  3129. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3130. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3131. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3132. {
  3133. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3134. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3135. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3136. $LastGoodY = NULL; $LastGoodX = NULL;
  3137. foreach($PosArray as $Key => $Y)
  3138. {
  3139. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3140. {
  3141. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3142. $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3143. }
  3144. 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)); }
  3145. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  3146. $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  3147. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  3148. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }
  3149. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3150. if ( $Y == VOID ) { $Y = NULL; }
  3151. $LastX = $X; $LastY = $Y;
  3152. $X = $X + $XStep;
  3153. }
  3154. }
  3155. else
  3156. {
  3157. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3158. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3159. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3160. $LastGoodY = NULL; $LastGoodX = NULL;
  3161. foreach($PosArray as $Key => $X)
  3162. {
  3163. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3164. { $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)); }
  3165. 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)); }
  3166. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3167. $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  3168. if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
  3169. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }
  3170. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3171. if ( $X == VOID ) { $X = NULL; }
  3172. $LastX = $X; $LastY = $Y;
  3173. $Y = $Y + $YStep;
  3174. }
  3175. }
  3176. }
  3177. }
  3178. }
  3179. /* Draw a line chart */
  3180. function drawZoneChart($SerieA,$SerieB,$Format=NULL)
  3181. {
  3182. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  3183. $LineR = isset($Format["LineR"]) ? $Format["LineR"] : 150;
  3184. $LineG = isset($Format["LineG"]) ? $Format["LineG"] : 150;
  3185. $LineB = isset($Format["LineB"]) ? $Format["LineB"] : 150;
  3186. $LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 50;
  3187. $LineTicks = isset($Format["LineTicks"]) ? $Format["LineTicks"] : 1;
  3188. $AreaR = isset($Format["AreaR"]) ? $Format["AreaR"] : 150;
  3189. $AreaG = isset($Format["AreaG"]) ? $Format["AreaG"] : 150;
  3190. $AreaB = isset($Format["AreaB"]) ? $Format["AreaB"] : 150;
  3191. $AreaAlpha = isset($Format["AreaAlpha"]) ? $Format["AreaAlpha"] : 5;
  3192. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3193. $Data = $this->DataSet->getData();
  3194. if ( !isset($Data["Series"][$SerieA]["Data"]) || !isset($Data["Series"][$SerieB]["Data"]) ) { return(0); }
  3195. $SerieAData = $Data["Series"][$SerieA]["Data"];
  3196. $SerieBData = $Data["Series"][$SerieB]["Data"];
  3197. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3198. $Mode = $Data["Axis"][$AxisID]["Display"];
  3199. $Format = $Data["Axis"][$AxisID]["Format"];
  3200. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3201. $PosArrayA = $this->scaleComputeY($SerieAData,array("AxisID"=>$AxisID));
  3202. $PosArrayB = $this->scaleComputeY($SerieBData,array("AxisID"=>$AxisID));
  3203. if ( count($PosArrayA) != count($PosArrayB) ) { return(0); }
  3204. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3205. {
  3206. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3207. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3208. $LastX = NULL; $LastY1 = NULL; $LastY2 = NULL;
  3209. $BoundsA = ""; $BoundsB = "";
  3210. foreach($PosArrayA as $Key => $Y1)
  3211. {
  3212. $Y2 = $PosArrayB[$Key];
  3213. $BoundsA[] = $X; $BoundsA[] = $Y1;
  3214. $BoundsB[] = $X; $BoundsB[] = $Y2;
  3215. $LastX = $X;
  3216. $LastY1 = $Y1; $LastY2 = $Y2;
  3217. $X = $X + $XStep;
  3218. }
  3219. $Bounds = array_merge($BoundsA,$this->reversePlots($BoundsB));
  3220. $this->drawPolygonChart($Bounds,array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"Alpha"=>$AreaAlpha));
  3221. for($i=0;$i<=count($BoundsA)-4;$i=$i+2)
  3222. {
  3223. $this->drawLine($BoundsA[$i],$BoundsA[$i+1],$BoundsA[$i+2],$BoundsA[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3224. $this->drawLine($BoundsB[$i],$BoundsB[$i+1],$BoundsB[$i+2],$BoundsB[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3225. }
  3226. }
  3227. else
  3228. {
  3229. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3230. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3231. $LastY = NULL; $LastX1 = NULL; $LastX2 = NULL;
  3232. $BoundsA = ""; $BoundsB = "";
  3233. foreach($PosArrayA as $Key => $X1)
  3234. {
  3235. $X2 = $PosArrayB[$Key];
  3236. $BoundsA[] = $X1; $BoundsA[] = $Y;
  3237. $BoundsB[] = $X2; $BoundsB[] = $Y;
  3238. $LastY = $Y;
  3239. $LastX1 = $X1; $LastX2 = $X2;
  3240. $Y = $Y + $YStep;
  3241. }
  3242. $Bounds = array_merge($BoundsA,$this->reversePlots($BoundsB));
  3243. $this->drawPolygonChart($Bounds,array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"Alpha"=>$AreaAlpha));
  3244. for($i=0;$i<=count($BoundsA)-4;$i=$i+2)
  3245. {
  3246. $this->drawLine($BoundsA[$i],$BoundsA[$i+1],$BoundsA[$i+2],$BoundsA[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3247. $this->drawLine($BoundsB[$i],$BoundsB[$i+1],$BoundsB[$i+2],$BoundsB[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3248. }
  3249. }
  3250. }
  3251. /* Draw a step chart */
  3252. function drawStepChart($Format=NULL)
  3253. {
  3254. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : FALSE;
  3255. $ReCenter = isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
  3256. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  3257. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
  3258. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
  3259. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
  3260. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
  3261. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3262. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3263. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3264. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3265. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3266. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3267. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  3268. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3269. $Data = $this->DataSet->getData();
  3270. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3271. foreach($Data["Series"] as $SerieName => $Serie)
  3272. {
  3273. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3274. {
  3275. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3276. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  3277. if ( $BreakR == NULL )
  3278. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3279. else
  3280. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3281. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3282. $AxisID = $Serie["Axis"];
  3283. $Mode = $Data["Axis"][$AxisID]["Display"];
  3284. $Format = $Data["Axis"][$AxisID]["Format"];
  3285. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3286. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  3287. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3288. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3289. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3290. {
  3291. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3292. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3293. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3294. $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
  3295. foreach($PosArray as $Key => $Y)
  3296. {
  3297. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3298. {
  3299. if ( $Y <= $LastY ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3300. $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3301. }
  3302. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  3303. {
  3304. $this->drawLine($LastX,$LastY,$X,$LastY,$Color);
  3305. $this->drawLine($X,$LastY,$X,$Y,$Color);
  3306. if ( $ReCenter && $X+$XStep < $this->GraphAreaX2 - $XMargin )
  3307. {
  3308. $this->drawLine($X,$Y,$X+$XStep,$Y,$Color);
  3309. 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)); }
  3310. }
  3311. else
  3312. { 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)); } }
  3313. }
  3314. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  3315. {
  3316. if ( $ReCenter )
  3317. {
  3318. $this->drawLine($LastGoodX+$XStep,$LastGoodY,$X,$LastGoodY,$BreakSettings);
  3319. 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)); }
  3320. }
  3321. else
  3322. {
  3323. $this->drawLine($LastGoodX,$LastGoodY,$X,$LastGoodY,$BreakSettings);
  3324. 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)); }
  3325. }
  3326. $this->drawLine($X,$LastGoodY,$X,$Y,$BreakSettings);
  3327. $LastGoodY = NULL;
  3328. }
  3329. elseif( !$BreakVoid && $LastGoodY == NULL && $Y != VOID )
  3330. {
  3331. $this->drawLine($this->GraphAreaX1 + $XMargin,$Y,$X,$Y,$BreakSettings);
  3332. 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)); }
  3333. }
  3334. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3335. if ( $Y == VOID ) { $Y = NULL; }
  3336. if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
  3337. $LastX = $X; $LastY = $Y;
  3338. if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
  3339. $X = $X + $XStep;
  3340. }
  3341. if ( $ReCenter )
  3342. {
  3343. $this->drawLine($LastX,$LastY,$this->GraphAreaX2 - $XMargin,$LastY,$Color);
  3344. 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)); }
  3345. }
  3346. }
  3347. else
  3348. {
  3349. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3350. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3351. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3352. $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
  3353. foreach($PosArray as $Key => $X)
  3354. {
  3355. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3356. {
  3357. if ( $X >= $LastX ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
  3358. $this->drawText($X+$Offset+$Weight,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3359. }
  3360. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3361. {
  3362. $this->drawLine($LastX,$LastY,$LastX,$Y,$Color);
  3363. $this->drawLine($LastX,$Y,$X,$Y,$Color);
  3364. 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)); }
  3365. }
  3366. if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
  3367. {
  3368. $this->drawLine($LastGoodX,$LastGoodY,$LastGoodX,$LastGoodY+$YStep,$Color);
  3369. 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)); }
  3370. $this->drawLine($LastGoodX,$LastGoodY+$YStep,$LastGoodX,$Y,$BreakSettings);
  3371. 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)); }
  3372. $this->drawLine($LastGoodX,$Y,$X,$Y,$BreakSettings);
  3373. $LastGoodY = NULL;
  3374. }
  3375. elseif ( $X != VOID && $LastGoodY == NULL && !$BreakVoid )
  3376. {
  3377. $this->drawLine($X,$this->GraphAreaY1 + $XMargin,$X,$Y,$BreakSettings);
  3378. 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)); }
  3379. }
  3380. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3381. if ( $X == VOID ) { $X = NULL; }
  3382. if ( !$Init && $ReCenter ) { $Y = $Y - $YStep/2; $Init = TRUE; }
  3383. $LastX = $X; $LastY = $Y;
  3384. if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
  3385. $Y = $Y + $YStep;
  3386. }
  3387. if ( $ReCenter )
  3388. {
  3389. $this->drawLine($LastX,$LastY,$LastX,$this->GraphAreaY2 - $XMargin,$Color);
  3390. 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)); }
  3391. }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. /* Draw a step chart */
  3397. function drawFilledStepChart($Format=NULL)
  3398. {
  3399. $ReCenter = isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
  3400. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
  3401. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3402. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3403. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
  3404. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3405. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3406. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3407. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3408. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3409. $Data = $this->DataSet->getData();
  3410. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3411. foreach($Data["Series"] as $SerieName => $Serie)
  3412. {
  3413. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3414. {
  3415. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3416. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3417. $AxisID = $Serie["Axis"];
  3418. $Mode = $Data["Axis"][$AxisID]["Display"];
  3419. $Format = $Data["Axis"][$AxisID]["Format"];
  3420. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3421. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  3422. if ( $ForceTransparency != NULL ) { $Color["Alpha"] = $ForceTransparency; } else { $Color["Alpha"] = $Alpha; }
  3423. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3424. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  3425. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3426. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3427. {
  3428. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3429. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3430. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3431. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3432. if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }
  3433. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3434. $LastGoodY = NULL; $LastGoodX = NULL; $Points = ""; $Init = FALSE;
  3435. foreach($PosArray as $Key => $Y)
  3436. {
  3437. if ( $Y == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
  3438. {
  3439. $Points[] = $LastX; $Points[] = $LastY;
  3440. $Points[] = $X; $Points[] = $LastY;
  3441. $Points[] = $X; $Points[] = $YZero;
  3442. $this->drawPolygon($Points,$Color);
  3443. $Points = "";
  3444. }
  3445. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  3446. {
  3447. if ( $Points == "") { $Points[] = $LastX; $Points[] = $YZero; }
  3448. $Points[] = $LastX; $Points[] = $LastY;
  3449. $Points[] = $X; $Points[] = $LastY;
  3450. $Points[] = $X; $Points[] = $Y;
  3451. }
  3452. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3453. if ( $Y == VOID ) { $Y = NULL; }
  3454. if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
  3455. $LastX = $X; $LastY = $Y;
  3456. if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
  3457. $X = $X + $XStep;
  3458. }
  3459. if ( $ReCenter )
  3460. {
  3461. $Points[] = $LastX+$XStep/2; $Points[] = $LastY;
  3462. $Points[] = $LastX+$XStep/2; $Points[] = $YZero;
  3463. }
  3464. else
  3465. { $Points[] = $LastX; $Points[] = $YZero; }
  3466. $this->drawPolygon($Points,$Color);
  3467. }
  3468. else
  3469. {
  3470. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3471. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3472. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3473. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3474. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3475. $LastGoodY = NULL; $LastGoodX = NULL; $Points = "";
  3476. foreach($PosArray as $Key => $X)
  3477. {
  3478. if ( $X == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
  3479. {
  3480. $Points[] = $LastX; $Points[] = $LastY;
  3481. $Points[] = $LastX; $Points[] = $Y;
  3482. $Points[] = $YZero; $Points[] = $Y;
  3483. $this->drawPolygon($Points,$Color);
  3484. $Points = "";
  3485. }
  3486. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3487. {
  3488. if ( $Points == "") { $Points[] = $YZero; $Points[] = $LastY; }
  3489. $Points[] = $LastX; $Points[] = $LastY;
  3490. $Points[] = $LastX; $Points[] = $Y;
  3491. $Points[] = $X; $Points[] = $Y;
  3492. }
  3493. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3494. if ( $X == VOID ) { $X = NULL; }
  3495. if ( $LastX == NULL && $ReCenter ) { $Y = $Y - $YStep/2; }
  3496. $LastX = $X; $LastY = $Y;
  3497. if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
  3498. $Y = $Y + $YStep;
  3499. }
  3500. if ( $ReCenter )
  3501. {
  3502. $Points[] = $LastX; $Points[] = $LastY+$YStep/2;
  3503. $Points[] = $YZero; $Points[] = $LastY+$YStep/2;
  3504. }
  3505. else
  3506. { $Points[] = $YZero; $Points[] = $LastY; }
  3507. $this->drawPolygon($Points,$Color);
  3508. }
  3509. }
  3510. }
  3511. }
  3512. /* Draw an area chart */
  3513. function drawAreaChart($Format=NULL)
  3514. {
  3515. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3516. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3517. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3518. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3519. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3520. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3521. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : 25;
  3522. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3523. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  3524. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3525. $Data = $this->DataSet->getData();
  3526. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3527. foreach($Data["Series"] as $SerieName => $Serie)
  3528. {
  3529. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3530. {
  3531. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3532. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3533. $AxisID = $Serie["Axis"];
  3534. $Mode = $Data["Axis"][$AxisID]["Display"];
  3535. $Format = $Data["Axis"][$AxisID]["Format"];
  3536. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3537. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3538. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  3539. if ( $Threshold != NULL )
  3540. {
  3541. foreach($Threshold as $Key => $Params)
  3542. {
  3543. $Threshold[$Key]["MinX"] = $this->scaleComputeY($Params["Min"],array("AxisID"=>$Serie["Axis"]));
  3544. $Threshold[$Key]["MaxX"] = $this->scaleComputeY($Params["Max"],array("AxisID"=>$Serie["Axis"]));
  3545. }
  3546. }
  3547. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3548. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3549. {
  3550. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3551. $Areas = ""; $AreaID = 0;
  3552. $Areas[$AreaID][] = $this->GraphAreaX1 + $XMargin;
  3553. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3554. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3555. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3556. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3557. foreach($PosArray as $Key => $Y)
  3558. {
  3559. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3560. {
  3561. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3562. $this->drawText($X,$Y-$Offset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3563. }
  3564. if ( $Y == VOID && isset($Areas[$AreaID]) )
  3565. {
  3566. if($LastX == NULL)
  3567. { $Areas[$AreaID][] = $X; }
  3568. else
  3569. { $Areas[$AreaID][] = $LastX; }
  3570. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3571. $AreaID++;
  3572. }
  3573. elseif ($Y != VOID)
  3574. {
  3575. if ( !isset($Areas[$AreaID]) )
  3576. {
  3577. $Areas[$AreaID][] = $X;
  3578. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3579. }
  3580. $Areas[$AreaID][] = $X;
  3581. $Areas[$AreaID][] = $Y;
  3582. }
  3583. $LastX = $X;
  3584. $X = $X + $XStep;
  3585. }
  3586. $Areas[$AreaID][] = $LastX;
  3587. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3588. /* Handle shadows in the areas */
  3589. if ( $this->Shadow )
  3590. {
  3591. $ShadowArea = "";
  3592. foreach($Areas as $Key => $Points)
  3593. {
  3594. $ShadowArea[$Key] = "";
  3595. foreach($Points as $Key2 => $Value)
  3596. {
  3597. if ( $Key2 % 2 == 0 )
  3598. { $ShadowArea[$Key][] = $Value + $this->ShadowX; }
  3599. else
  3600. { $ShadowArea[$Key][] = $Value + $this->ShadowY; }
  3601. }
  3602. }
  3603. foreach($ShadowArea as $Key => $Points)
  3604. $this->drawPolygonChart($Points,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  3605. }
  3606. $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
  3607. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Threshold"=>$Threshold);
  3608. foreach($Areas as $Key => $Points)
  3609. $this->drawPolygonChart($Points,$Color);
  3610. }
  3611. else
  3612. {
  3613. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3614. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3615. $Areas = ""; $AreaID = 0;
  3616. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3617. $Areas[$AreaID][] = $this->GraphAreaY1 + $XMargin;
  3618. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3619. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3620. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3621. foreach($PosArray as $Key => $X)
  3622. {
  3623. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3624. {
  3625. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3626. $this->drawText($X+$Offset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3627. }
  3628. if ( $X == VOID && isset($Areas[$AreaID]) )
  3629. {
  3630. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3631. if($LastY == NULL)
  3632. { $Areas[$AreaID][] = $Y; }
  3633. else
  3634. { $Areas[$AreaID][] = $LastY; }
  3635. $AreaID++;
  3636. }
  3637. elseif ($X != VOID)
  3638. {
  3639. if ( !isset($Areas[$AreaID]) )
  3640. {
  3641. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3642. $Areas[$AreaID][] = $Y;
  3643. }
  3644. $Areas[$AreaID][] = $X;
  3645. $Areas[$AreaID][] = $Y;
  3646. }
  3647. $LastX = $X; $LastY = $Y;
  3648. $Y = $Y + $YStep;
  3649. }
  3650. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3651. $Areas[$AreaID][] = $LastY;
  3652. /* Handle shadows in the areas */
  3653. if ( $this->Shadow )
  3654. {
  3655. $ShadowArea = "";
  3656. foreach($Areas as $Key => $Points)
  3657. {
  3658. $ShadowArea[$Key] = "";
  3659. foreach($Points as $Key2 => $Value)
  3660. {
  3661. if ( $Key2 % 2 == 0 )
  3662. { $ShadowArea[$Key][] = $Value + $this->ShadowX; }
  3663. else
  3664. { $ShadowArea[$Key][] = $Value + $this->ShadowY; }
  3665. }
  3666. }
  3667. foreach($ShadowArea as $Key => $Points)
  3668. $this->drawPolygonChart($Points,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  3669. }
  3670. $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
  3671. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Threshold"=>$Threshold);
  3672. foreach($Areas as $Key => $Points)
  3673. $this->drawPolygonChart($Points,$Color);
  3674. }
  3675. }
  3676. }
  3677. }
  3678. /* Draw a bar chart */
  3679. function drawBarChart($Format=NULL)
  3680. {
  3681. $Floating0Serie = isset($Format["Floating0Serie"]) ? $Format["Floating0Serie"] : NULL;
  3682. $Floating0Value = isset($Format["Floating0Value"]) ? $Format["Floating0Value"] : NULL;
  3683. $Draw0Line = isset($Format["Draw0Line"]) ? $Format["Draw0Line"] : FALSE;
  3684. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3685. $DisplayOrientation = isset($Format["DisplayOrientation"]) ? $Format["DisplayOrientation"] : ORIENTATION_HORIZONTAL;
  3686. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3687. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3688. $DisplayFont = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontName;
  3689. $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
  3690. $DisplayPos = isset($Format["DisplayPos"]) ? $Format["DisplayPos"] : LABEL_POS_OUTSIDE;
  3691. $DisplayShadow = isset($Format["DisplayShadow"]) ? $Format["DisplayShadow"] : TRUE;
  3692. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3693. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3694. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3695. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3696. $Interleave = isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
  3697. $Rounded = isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
  3698. $RoundRadius = isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
  3699. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  3700. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  3701. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  3702. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  3703. $Gradient = isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
  3704. $GradientMode = isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
  3705. $GradientAlpha = isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
  3706. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  3707. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  3708. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  3709. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
  3710. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
  3711. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
  3712. $TxtMargin = isset($Format["TxtMargin"]) ? $Format["TxtMargin"] : 6;
  3713. $OverrideColors = isset($Format["OverrideColors"]) ? $Format["OverrideColors"] : NULL;
  3714. $OverrideSurrounding = isset($Format["OverrideSurrounding"]) ? $Format["OverrideSurrounding"] : 30;
  3715. $InnerSurrounding = isset($Format["InnerSurrounding"]) ? $Format["InnerSurrounding"] : NULL;
  3716. $InnerBorderR = isset($Format["InnerBorderR"]) ? $Format["InnerBorderR"] : -1;
  3717. $InnerBorderG = isset($Format["InnerBorderG"]) ? $Format["InnerBorderG"] : -1;
  3718. $InnerBorderB = isset($Format["InnerBorderB"]) ? $Format["InnerBorderB"] : -1;
  3719. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3720. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3721. $Data = $this->DataSet->getData();
  3722. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3723. if ( $OverrideColors != NULL )
  3724. {
  3725. $OverrideColors = $this->validatePalette($OverrideColors,$OverrideSurrounding);
  3726. $this->DataSet->saveExtendedData("Palette",$OverrideColors);
  3727. }
  3728. $RestoreShadow = $this->Shadow;
  3729. $SeriesCount = $this->countDrawableSeries();
  3730. $CurrentSerie = 0;
  3731. foreach($Data["Series"] as $SerieName => $Serie)
  3732. {
  3733. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3734. {
  3735. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3736. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3737. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  3738. if ( $InnerSurrounding != NULL ) { $InnerBorderR = $R+$InnerSurrounding; $InnerBorderG = $G+$InnerSurrounding; $InnerBorderB = $B+$InnerSurrounding; }
  3739. if ( $InnerBorderR == -1 ) { $InnerColor = NULL; } else { $InnerColor = array("R"=>$InnerBorderR,"G"=>$InnerBorderG,"B"=>$InnerBorderB); }
  3740. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);
  3741. $AxisID = $Serie["Axis"];
  3742. $Mode = $Data["Axis"][$AxisID]["Display"];
  3743. $Format = $Data["Axis"][$AxisID]["Format"];
  3744. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3745. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  3746. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3747. if ( $Floating0Value != NULL )
  3748. { $YZero = $this->scaleComputeY($Floating0Value,array("AxisID"=>$Serie["Axis"])); }
  3749. else
  3750. { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }
  3751. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3752. {
  3753. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3754. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3755. if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3756. $X = $this->GraphAreaX1 + $XMargin;
  3757. if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
  3758. if ( $XDivs == 0 ) { $XSize = ($this->GraphAreaX2-$this->GraphAreaX1)/($SeriesCount+$Interleave); } else { $XSize = ($XStep / ($SeriesCount+$Interleave) ); }
  3759. $XOffset = -($XSize*$SeriesCount)/2 + $CurrentSerie * $XSize;
  3760. if ( $X + $XOffset <= $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $X + 1 ; }
  3761. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $XOffset + $XSize / 2;
  3762. if ( $Rounded || $BorderR != -1) { $XSpace = 1; } else { $XSpace = 0; }
  3763. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3764. $ID = 0;
  3765. foreach($PosArray as $Key => $Y2)
  3766. {
  3767. if ( $Floating0Serie != NULL )
  3768. {
  3769. if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
  3770. { $Value = $Data["Series"][$Floating0Serie]["Data"][$Key]; }
  3771. else
  3772. { $Value = 0; }
  3773. $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
  3774. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3775. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3776. if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
  3777. }
  3778. if ( $OverrideColors != NULL )
  3779. { 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(); } }
  3780. if ( $Y2 != VOID )
  3781. {
  3782. $BarHeight = $Y1 - $Y2;
  3783. if ( $Serie["Data"][$Key] == 0 )
  3784. {
  3785. $this->drawLine($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y1,$Color);
  3786. 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)); }
  3787. }
  3788. else
  3789. {
  3790. 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)); }
  3791. if ( $Rounded )
  3792. $this->drawRoundedFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$RoundRadius,$Color);
  3793. else
  3794. {
  3795. $this->drawFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$Color);
  3796. if ( $InnerColor != NULL ) { $this->drawRectangle($X+$XOffset+$XSpace+1,min($Y1,$Y2)+1,$X+$XOffset+$XSize-$XSpace-1,max($Y1,$Y2)-1,$InnerColor); }
  3797. if ( $Gradient )
  3798. {
  3799. $this->Shadow = FALSE;
  3800. if ( $GradientMode == GRADIENT_SIMPLE )
  3801. {
  3802. if ( $Serie["Data"][$Key] >= 0 )
  3803. $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3804. else
  3805. $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3806. $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_VERTICAL,$GradienColor);
  3807. }
  3808. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3809. {
  3810. $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3811. $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3812. $XSpan = floor($XSize / 3);
  3813. $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSpan-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor1);
  3814. $this->drawGradientArea($X+$XOffset+$XSpan+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor2);
  3815. }
  3816. $this->Shadow = $RestoreShadow;
  3817. }
  3818. }
  3819. if ( $Draw0Line )
  3820. {
  3821. $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);
  3822. if ( abs($Y1 - $Y2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
  3823. if ( $Y1 - $Y2 < 0 ) { $Line0Width = -$Line0Width; }
  3824. $this->drawFilledRectangle($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1)-$Line0Width,$Line0Color);
  3825. $this->drawLine($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1),$Line0Color);
  3826. }
  3827. }
  3828. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3829. {
  3830. if ( $DisplayShadow ) { $this->Shadow = TRUE; }
  3831. $Caption = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
  3832. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,90,$Caption);
  3833. $TxtHeight = $TxtPos[0]["Y"] - $TxtPos[1]["Y"] + $TxtMargin;
  3834. if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtHeight) < abs($BarHeight) )
  3835. {
  3836. $CenterX = (($X+$XOffset+$XSize-$XSpace)-($X+$XOffset+$XSpace))/2 + $X+$XOffset+$XSpace;
  3837. $CenterY = ($Y2-$Y1)/2 + $Y1;
  3838. $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"Angle"=>90));
  3839. }
  3840. else
  3841. {
  3842. if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3843. $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));
  3844. }
  3845. $this->Shadow = $RestoreShadow;
  3846. }
  3847. }
  3848. $X = $X + $XStep;
  3849. $ID++;
  3850. }
  3851. }
  3852. else
  3853. {
  3854. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3855. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3856. if ( $XDivs == 0 ) { $YStep = 0; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3857. $Y = $this->GraphAreaY1 + $XMargin;
  3858. if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
  3859. if ( $XDivs == 0 ) { $YSize = ($this->GraphAreaY2-$this->GraphAreaY1)/($SeriesCount+$Interleave); } else { $YSize = ($YStep / ($SeriesCount+$Interleave) ); }
  3860. $YOffset = -($YSize*$SeriesCount)/2 + $CurrentSerie * $YSize;
  3861. if ( $Y + $YOffset <= $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $Y + 1 ; }
  3862. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $YOffset + $YSize / 2;
  3863. if ( $Rounded || $BorderR != -1 ) { $YSpace = 1; } else { $YSpace = 0; }
  3864. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3865. $ID = 0 ;
  3866. foreach($PosArray as $Key => $X2)
  3867. {
  3868. if ( $Floating0Serie != NULL )
  3869. {
  3870. if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
  3871. $Value = $Data["Series"][$Floating0Serie]["Data"][$Key];
  3872. else { $Value = 0; }
  3873. $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
  3874. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3875. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3876. if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
  3877. }
  3878. if ( $OverrideColors != NULL )
  3879. { 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(); } }
  3880. if ( $X2 != VOID )
  3881. {
  3882. $BarWidth = $X2 - $X1;
  3883. if ( $Serie["Data"][$Key] == 0 )
  3884. {
  3885. $this->drawLine($X1,$Y+$YOffset+$YSpace,$X1,$Y+$YOffset+$YSize-$YSpace,$Color);
  3886. 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)); }
  3887. }
  3888. else
  3889. {
  3890. 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)); }
  3891. if ( $Rounded )
  3892. $this->drawRoundedFilledRectangle($X1+1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$RoundRadius,$Color);
  3893. else
  3894. {
  3895. $this->drawFilledRectangle($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$Color);
  3896. if ( $InnerColor != NULL ) { $this->drawRectangle(min($X1,$X2)+1,$Y+$YOffset+$YSpace+1,max($X1,$X2)-1,$Y+$YOffset+$YSize-$YSpace-1,$InnerColor); }
  3897. if ( $Gradient )
  3898. {
  3899. $this->Shadow = FALSE;
  3900. if ( $GradientMode == GRADIENT_SIMPLE )
  3901. {
  3902. if ( $Serie["Data"][$Key] >= 0 )
  3903. $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3904. else
  3905. $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3906. $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_HORIZONTAL,$GradienColor);
  3907. }
  3908. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3909. {
  3910. $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3911. $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3912. $YSpan = floor($YSize / 3);
  3913. $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSpan-$YSpace,DIRECTION_VERTICAL,$GradienColor1);
  3914. $this->drawGradientArea($X1,$Y+$YOffset+$YSpan,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_VERTICAL,$GradienColor2);
  3915. }
  3916. $this->Shadow = $RestoreShadow;
  3917. }
  3918. }
  3919. if ( $Draw0Line )
  3920. {
  3921. $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);
  3922. if ( abs($X1 - $X2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
  3923. if ( $X2 - $X1 < 0 ) { $Line0Width = -$Line0Width; }
  3924. $this->drawFilledRectangle(floor($X1),$Y+$YOffset+$YSpace,floor($X1)+$Line0Width,$Y+$YOffset+$YSize-$YSpace,$Line0Color);
  3925. $this->drawLine(floor($X1),$Y+$YOffset+$YSpace,floor($X1),$Y+$YOffset+$YSize-$YSpace,$Line0Color);
  3926. }
  3927. }
  3928. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3929. {
  3930. if ( $DisplayShadow ) { $this->Shadow = TRUE; }
  3931. $Caption = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
  3932. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3933. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"] + $TxtMargin;
  3934. if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtWidth) < abs($BarWidth) )
  3935. {
  3936. $CenterX = ($X2-$X1)/2 + $X1;
  3937. $CenterY = (($Y+$YOffset+$YSize-$YSpace)-($Y+$YOffset+$YSpace))/2 + ($Y+$YOffset+$YSpace);
  3938. $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize));
  3939. }
  3940. else
  3941. {
  3942. if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
  3943. $this->drawText($X2+$Offset,$Y+$YOffset+$YSize/2,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align,"FontSize"=>$DisplaySize));
  3944. }
  3945. $this->Shadow = $RestoreShadow;
  3946. }
  3947. }
  3948. $Y = $Y + $YStep;
  3949. $ID++;
  3950. }
  3951. }
  3952. $CurrentSerie++;
  3953. }
  3954. }
  3955. }
  3956. /* Draw a bar chart */
  3957. function drawStackedBarChart($Format=NULL)
  3958. {
  3959. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3960. $DisplayOrientation = isset($Format["DisplayOrientation"]) ? $Format["DisplayOrientation"] : ORIENTATION_AUTO;
  3961. $DisplayRound = isset($Format["DisplayRound"]) ? $Format["DisplayRound"] : 0;
  3962. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3963. $DisplayFont = isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;
  3964. $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
  3965. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3966. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3967. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3968. $Interleave = isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
  3969. $Rounded = isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
  3970. $RoundRadius = isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
  3971. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  3972. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  3973. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  3974. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  3975. $Gradient = isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
  3976. $GradientMode = isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
  3977. $GradientAlpha = isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
  3978. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  3979. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  3980. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  3981. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
  3982. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
  3983. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
  3984. $InnerSurrounding = isset($Format["InnerSurrounding"]) ? $Format["InnerSurrounding"] : NULL;
  3985. $InnerBorderR = isset($Format["InnerBorderR"]) ? $Format["InnerBorderR"] : -1;
  3986. $InnerBorderG = isset($Format["InnerBorderG"]) ? $Format["InnerBorderG"] : -1;
  3987. $InnerBorderB = isset($Format["InnerBorderB"]) ? $Format["InnerBorderB"] : -1;
  3988. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3989. $FontFactor = isset($Format["FontFactor"]) ? $Format["FontFactor"] : 8;
  3990. $this->LastChartLayout = CHART_LAST_LAYOUT_STACKED;
  3991. $Data = $this->DataSet->getData();
  3992. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3993. $RestoreShadow = $this->Shadow;
  3994. $LastX = ""; $LastY = "";
  3995. foreach($Data["Series"] as $SerieName => $Serie)
  3996. {
  3997. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3998. {
  3999. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  4000. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = 255; $DisplayG = 255; $DisplayB = 255; }
  4001. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  4002. if ( $InnerSurrounding != NULL ) { $InnerBorderR = $R+$InnerSurrounding; $InnerBorderG = $G+$InnerSurrounding; $InnerBorderB = $B+$InnerSurrounding; }
  4003. if ( $InnerBorderR == -1 ) { $InnerColor = NULL; } else { $InnerColor = array("R"=>$InnerBorderR,"G"=>$InnerBorderG,"B"=>$InnerBorderB); }
  4004. $AxisID = $Serie["Axis"];
  4005. $Mode = $Data["Axis"][$AxisID]["Display"];
  4006. $Format = $Data["Axis"][$AxisID]["Format"];
  4007. $Unit = $Data["Axis"][$AxisID]["Unit"];
  4008. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  4009. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
  4010. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  4011. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  4012. $Color = array("TransCorner"=>TRUE,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);
  4013. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4014. {
  4015. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  4016. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  4017. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4018. $X = $this->GraphAreaX1 + $XMargin;
  4019. $XSize = ($XStep / (1+$Interleave) );
  4020. $XOffset = -($XSize/2);
  4021. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4022. foreach($PosArray as $Key => $Height)
  4023. {
  4024. if ( $Height != VOID && $Serie["Data"][$Key] != 0 )
  4025. {
  4026. if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }
  4027. if ( !isset($LastY[$Key] ) ) { $LastY[$Key] = ""; }
  4028. if ( !isset($LastY[$Key][$Pos] ) ) { $LastY[$Key][$Pos] = $YZero; }
  4029. $Y1 = $LastY[$Key][$Pos];
  4030. $Y2 = $Y1 - $Height;
  4031. if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $Y1 != $YZero) ) { $YSpaceUp = 1; } else { $YSpaceUp = 0; }
  4032. if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $Y1 != $YZero) ) { $YSpaceDown = 1; } else { $YSpaceDown = 0; }
  4033. 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)); }
  4034. if ( $Rounded )
  4035. $this->drawRoundedFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$RoundRadius,$Color);
  4036. else
  4037. {
  4038. $this->drawFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$Color);
  4039. 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;}
  4040. if ( $Gradient )
  4041. {
  4042. $this->Shadow = FALSE;
  4043. if ( $GradientMode == GRADIENT_SIMPLE )
  4044. {
  4045. $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4046. $this->drawGradientArea($X+$XOffset,$Y1-1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+1,DIRECTION_VERTICAL,$GradientColor);
  4047. }
  4048. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  4049. {
  4050. $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  4051. $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4052. $XSpan = floor($XSize / 3);
  4053. $this->drawGradientArea($X+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSpan,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor1);
  4054. $this->drawGradientArea($X+$XSpan+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor2);
  4055. }
  4056. $this->Shadow = $RestoreShadow;
  4057. }
  4058. }
  4059. if ( $DisplayValues )
  4060. {
  4061. $BarHeight = abs($Y2-$Y1)-2;
  4062. $BarWidth = $XSize+($XOffset/2)-$FontFactor;
  4063. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  4064. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  4065. $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
  4066. $TxtWidth = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);
  4067. $XCenter = ( ($X+$XOffset+$XSize) - ($X+$XOffset) ) / 2 + $X+$XOffset;
  4068. $YCenter = ( ($Y2) - ($Y1-$YSpaceUp+$YSpaceDown) ) / 2 + $Y1-$YSpaceUp+$YSpaceDown;
  4069. $Done = FALSE;
  4070. if ( $DisplayOrientation == ORIENTATION_HORIZONTAL || $DisplayOrientation == ORIENTATION_AUTO )
  4071. {
  4072. if ( $TxtHeight < $BarHeight && $TxtWidth < $BarWidth )
  4073. {
  4074. $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));
  4075. $Done = TRUE;
  4076. }
  4077. }
  4078. if ( $DisplayOrientation == ORIENTATION_VERTICAL || ( $DisplayOrientation == ORIENTATION_AUTO && !$Done) )
  4079. {
  4080. if ( $TxtHeight < $BarWidth && $TxtWidth < $BarHeight )
  4081. $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));
  4082. }
  4083. }
  4084. $LastY[$Key][$Pos] = $Y2;
  4085. }
  4086. $X = $X + $XStep;
  4087. }
  4088. }
  4089. else
  4090. {
  4091. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  4092. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  4093. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4094. $Y = $this->GraphAreaY1 + $XMargin;
  4095. $YSize = $YStep / (1+$Interleave);
  4096. $YOffset = -($YSize/2);
  4097. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4098. foreach($PosArray as $Key => $Width)
  4099. {
  4100. if ( $Width != VOID && $Serie["Data"][$Key] != 0 )
  4101. {
  4102. if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }
  4103. if ( !isset($LastX[$Key] ) ) { $LastX[$Key] = ""; }
  4104. if ( !isset($LastX[$Key][$Pos] ) ) { $LastX[$Key][$Pos] = $YZero; }
  4105. $X1 = $LastX[$Key][$Pos];
  4106. $X2 = $X1 + $Width;
  4107. if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $X1 != $YZero) ) { $XSpaceLeft = 2; } else { $XSpaceLeft = 0; }
  4108. if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $X1 != $YZero) ) { $XSpaceRight = 2; } else { $XSpaceRight = 0; }
  4109. 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)); }
  4110. if ( $Rounded )
  4111. $this->drawRoundedFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$RoundRadius,$Color);
  4112. else
  4113. {
  4114. $this->drawFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$Color);
  4115. 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;}
  4116. if ( $Gradient )
  4117. {
  4118. $this->Shadow = FALSE;
  4119. if ( $GradientMode == GRADIENT_SIMPLE )
  4120. {
  4121. $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4122. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_HORIZONTAL,$GradientColor);
  4123. }
  4124. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  4125. {
  4126. $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  4127. $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4128. $YSpan = floor($YSize / 3);
  4129. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSpan,DIRECTION_VERTICAL,$GradientColor1);
  4130. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset+$YSpan,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_VERTICAL,$GradientColor2);
  4131. }
  4132. $this->Shadow = $RestoreShadow;
  4133. }
  4134. }
  4135. if ( $DisplayValues )
  4136. {
  4137. $BarWidth = abs($X2-$X1)-$FontFactor;
  4138. $BarHeight = $YSize+($YOffset/2)-$FontFactor/2;
  4139. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  4140. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  4141. $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
  4142. $TxtWidth = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);
  4143. $XCenter = ( $X2 - $X1 ) / 2 + $X1;
  4144. $YCenter = ( ($Y+$YOffset+$YSize) - ($Y+$YOffset) ) / 2 + $Y+$YOffset;
  4145. $Done = FALSE;
  4146. if ( $DisplayOrientation == ORIENTATION_HORIZONTAL || $DisplayOrientation == ORIENTATION_AUTO )
  4147. {
  4148. if ( $TxtHeight < $BarHeight && $TxtWidth < $BarWidth )
  4149. {
  4150. $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));
  4151. $Done = TRUE;
  4152. }
  4153. }
  4154. if ( $DisplayOrientation == ORIENTATION_VERTICAL || ( $DisplayOrientation == ORIENTATION_AUTO && !$Done) )
  4155. {
  4156. if ( $TxtHeight < $BarWidth && $TxtWidth < $BarHeight )
  4157. $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));
  4158. }
  4159. }
  4160. $LastX[$Key][$Pos] = $X2;
  4161. }
  4162. $Y = $Y + $YStep;
  4163. }
  4164. }
  4165. }
  4166. }
  4167. }
  4168. /* Draw a stacked area chart */
  4169. function drawStackedAreaChart($Format=NULL)
  4170. {
  4171. $DrawLine = isset($Format["DrawLine"]) ? $Format["DrawLine"] : FALSE;
  4172. $LineSurrounding = isset($Format["LineSurrounding"]) ? $Format["LineSurrounding"] : NULL;
  4173. $LineR = isset($Format["LineR"]) ? $Format["LineR"] : VOID;
  4174. $LineG = isset($Format["LineG"]) ? $Format["LineG"] : VOID;
  4175. $LineB = isset($Format["LineB"]) ? $Format["LineB"] : VOID;
  4176. $LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 100;
  4177. $DrawPlot = isset($Format["DrawPlot"]) ? $Format["DrawPlot"] : FALSE;
  4178. $PlotRadius = isset($Format["PlotRadius"]) ? $Format["PlotRadius"] : 2;
  4179. $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : 1;
  4180. $PlotBorderSurrounding = isset($Format["PlotBorderSurrounding"]) ? $Format["PlotBorderSurrounding"] : NULL;
  4181. $PlotBorderR = isset($Format["PlotBorderR"]) ? $Format["PlotBorderR"] : 0;
  4182. $PlotBorderG = isset($Format["PlotBorderG"]) ? $Format["PlotBorderG"] : 0;
  4183. $PlotBorderB = isset($Format["PlotBorderB"]) ? $Format["PlotBorderB"] : 0;
  4184. $PlotBorderAlpha = isset($Format["PlotBorderAlpha"]) ? $Format["PlotBorderAlpha"] : 50;
  4185. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
  4186. $this->LastChartLayout = CHART_LAST_LAYOUT_STACKED;
  4187. $Data = $this->DataSet->getData();
  4188. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4189. $RestoreShadow = $this->Shadow;
  4190. $this->Shadow = FALSE;
  4191. /* Build the offset data series */
  4192. $OffsetData = "";
  4193. $OverallOffset = "";
  4194. $SerieOrder = "";
  4195. foreach($Data["Series"] as $SerieName => $Serie)
  4196. {
  4197. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4198. {
  4199. $SerieOrder[] = $SerieName;
  4200. foreach($Serie["Data"] as $Key => $Value)
  4201. {
  4202. if ( $Value == VOID ) { $Value = 0; }
  4203. if ($Value >= 0) { $Sign = "+"; } else { $Sign = "-"; }
  4204. if ( !isset($OverallOffset[$Key]) || !isset($OverallOffset[$Key][$Sign]) ) { $OverallOffset[$Key][$Sign] = 0; }
  4205. if ( $Sign == "+" )
  4206. { $Data["Series"][$SerieName]["Data"][$Key] = $Value + $OverallOffset[$Key][$Sign]; }
  4207. else
  4208. { $Data["Series"][$SerieName]["Data"][$Key] = $Value - $OverallOffset[$Key][$Sign]; }
  4209. $OverallOffset[$Key][$Sign] = $OverallOffset[$Key][$Sign] + abs($Value);
  4210. }
  4211. }
  4212. }
  4213. $SerieOrder = array_reverse($SerieOrder);
  4214. $LastX = ""; $LastY = "";
  4215. foreach($SerieOrder as $Key => $SerieName)
  4216. {
  4217. $Serie = $Data["Series"][$SerieName];
  4218. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4219. {
  4220. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  4221. if ( $ForceTransparency != NULL ) { $Alpha = $ForceTransparency; }
  4222. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  4223. if ( $LineSurrounding != NULL )
  4224. $LineColor = array("R"=>$R+$LineSurrounding,"G"=>$G+$LineSurrounding,"B"=>$B+$LineSurrounding,"Alpha"=>$Alpha);
  4225. elseif ( $LineR != VOID )
  4226. $LineColor = array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha);
  4227. else
  4228. $LineColor = $Color;
  4229. if ( $PlotBorderSurrounding != NULL )
  4230. $PlotBorderColor = array("R"=>$R+$PlotBorderSurrounding,"G"=>$G+$PlotBorderSurrounding,"B"=>$B+$PlotBorderSurrounding,"Alpha"=>$PlotBorderAlpha);
  4231. else
  4232. $PlotBorderColor = array("R"=>$PlotBorderR,"G"=>$PlotBorderG,"B"=>$PlotBorderB,"Alpha"=>$PlotBorderAlpha);
  4233. $AxisID = $Serie["Axis"];
  4234. $Mode = $Data["Axis"][$AxisID]["Display"];
  4235. $Format = $Data["Axis"][$AxisID]["Format"];
  4236. $Unit = $Data["Axis"][$AxisID]["Unit"];
  4237. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
  4238. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  4239. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  4240. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4241. {
  4242. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  4243. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  4244. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4245. $X = $this->GraphAreaX1 + $XMargin;
  4246. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4247. $Plots = ""; $Plots[] = $X; $Plots[] = $YZero;
  4248. foreach($PosArray as $Key => $Height)
  4249. {
  4250. if ( $Height != VOID ) { $Plots[] = $X; $Plots[] = $YZero-$Height; }
  4251. $X = $X + $XStep;
  4252. }
  4253. $Plots[] = $X-$XStep; $Plots[] = $YZero;
  4254. $this->drawPolygon($Plots,$Color);
  4255. $this->Shadow = $RestoreShadow;
  4256. 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); } }
  4257. if ( $DrawPlot )
  4258. {
  4259. for($i=2; $i<=count($Plots)-4; $i=$i+2)
  4260. {
  4261. if ( $PlotBorder != 0 )
  4262. { $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius+$PlotBorder,$PlotBorderColor); }
  4263. $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius,$Color);
  4264. }
  4265. }
  4266. $this->Shadow = FALSE;
  4267. }
  4268. elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  4269. {
  4270. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  4271. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  4272. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4273. $Y = $this->GraphAreaY1 + $XMargin;
  4274. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4275. $Plots = ""; $Plots[] = $YZero; $Plots[] = $Y;
  4276. foreach($PosArray as $Key => $Height)
  4277. {
  4278. if ( $Height != VOID ) { $Plots[] = $YZero+$Height; $Plots[] = $Y; }
  4279. $Y = $Y + $YStep;
  4280. }
  4281. $Plots[] = $YZero; $Plots[] = $Y-$YStep;
  4282. $this->drawPolygon($Plots,$Color);
  4283. $this->Shadow = $RestoreShadow;
  4284. 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); } }
  4285. if ( $DrawPlot )
  4286. {
  4287. for($i=2; $i<=count($Plots)-4; $i=$i+2)
  4288. {
  4289. if ( $PlotBorder != 0 )
  4290. { $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius+$PlotBorder,$PlotBorderColor); }
  4291. $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius,$Color);
  4292. }
  4293. }
  4294. $this->Shadow = FALSE;
  4295. }
  4296. }
  4297. }
  4298. $this->Shadow = $RestoreShadow;
  4299. }
  4300. /* Returns a random color */
  4301. function getRandomColor($Alpha=100)
  4302. { return(array("R"=>rand(0,255),"G"=>rand(0,255),"B"=>rand(0,255),"Alpha"=>$Alpha)); }
  4303. /* Validate a palette */
  4304. function validatePalette($Colors,$Surrounding=NULL)
  4305. {
  4306. $Result = "";
  4307. if ( !is_array($Colors) ) { return($this->getRandomColor()); }
  4308. foreach($Colors as $Key => $Values)
  4309. {
  4310. if ( isset($Values["R"]) ) { $Result[$Key]["R"] = $Values["R"]; } else { $Result[$Key]["R"] = rand(0,255); }
  4311. if ( isset($Values["G"]) ) { $Result[$Key]["G"] = $Values["G"]; } else { $Result[$Key]["G"] = rand(0,255); }
  4312. if ( isset($Values["B"]) ) { $Result[$Key]["B"] = $Values["B"]; } else { $Result[$Key]["B"] = rand(0,255); }
  4313. if ( isset($Values["Alpha"]) ) { $Result[$Key]["Alpha"] = $Values["Alpha"]; } else { $Result[$Key]["Alpha"] = 100; }
  4314. if ( $Surrounding != NULL )
  4315. {
  4316. $Result[$Key]["BorderR"] = $Result[$Key]["R"] + $Surrounding;
  4317. $Result[$Key]["BorderG"] = $Result[$Key]["G"] + $Surrounding;
  4318. $Result[$Key]["BorderB"] = $Result[$Key]["B"] + $Surrounding;
  4319. }
  4320. else
  4321. {
  4322. if ( isset($Values["BorderR"]) ) { $Result[$Key]["BorderR"] = $Values["BorderR"]; } else { $Result[$Key]["BorderR"] = $Result[$Key]["R"]; }
  4323. if ( isset($Values["BorderG"]) ) { $Result[$Key]["BorderG"] = $Values["BorderG"]; } else { $Result[$Key]["BorderG"] = $Result[$Key]["G"]; }
  4324. if ( isset($Values["BorderB"]) ) { $Result[$Key]["BorderB"] = $Values["BorderB"]; } else { $Result[$Key]["BorderB"] = $Result[$Key]["B"]; }
  4325. if ( isset($Values["BorderAlpha"]) ) { $Result[$Key]["BorderAlpha"] = $Values["BorderAlpha"]; } else { $Result[$Key]["BorderAlpha"] = $Result[$Key]["Alpha"]; }
  4326. }
  4327. }
  4328. return($Result);
  4329. }
  4330. /* Draw the derivative chart associated to the data series */
  4331. function drawDerivative($Format=NULL)
  4332. {
  4333. $Offset = isset($Format["Offset"]) ? $Format["Offset"] : 10;
  4334. $SerieSpacing = isset($Format["SerieSpacing"]) ? $Format["SerieSpacing"] : 3;
  4335. $DerivativeHeight = isset($Format["DerivativeHeight"]) ? $Format["DerivativeHeight"] : 4;
  4336. $ShadedSlopeBox = isset($Format["ShadedSlopeBox"]) ? $Format["ShadedSlopeBox"] : FALSE;
  4337. $DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE;
  4338. $BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255;
  4339. $BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255;
  4340. $BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255;
  4341. $BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 20;
  4342. $DrawBorder = isset($Format["DrawBorder"]) ? $Format["DrawBorder"] : TRUE;
  4343. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 0;
  4344. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 0;
  4345. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 0;
  4346. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 100;
  4347. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : TRUE;
  4348. $CaptionHeight = isset($Format["CaptionHeight"]) ? $Format["CaptionHeight"] : 10;
  4349. $CaptionWidth = isset($Format["CaptionWidth"]) ? $Format["CaptionWidth"] : 20;
  4350. $CaptionMargin = isset($Format["CaptionMargin"]) ? $Format["CaptionMargin"] : 4;
  4351. $CaptionLine = isset($Format["CaptionLine"]) ? $Format["CaptionLine"] : FALSE;
  4352. $CaptionBox = isset($Format["CaptionBox"]) ? $Format["CaptionBox"] : FALSE;
  4353. $CaptionBorderR = isset($Format["CaptionBorderR"]) ? $Format["CaptionBorderR"] : 0;
  4354. $CaptionBorderG = isset($Format["CaptionBorderG"]) ? $Format["CaptionBorderG"] : 0;
  4355. $CaptionBorderB = isset($Format["CaptionBorderB"]) ? $Format["CaptionBorderB"] : 0;
  4356. $CaptionFillR = isset($Format["CaptionFillR"]) ? $Format["CaptionFillR"] : 255;
  4357. $CaptionFillG = isset($Format["CaptionFillG"]) ? $Format["CaptionFillG"] : 255;
  4358. $CaptionFillB = isset($Format["CaptionFillB"]) ? $Format["CaptionFillB"] : 255;
  4359. $CaptionFillAlpha = isset($Format["CaptionFillAlpha"]) ? $Format["CaptionFillAlpha"] : 80;
  4360. $PositiveSlopeStartR = isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 184;
  4361. $PositiveSlopeStartG = isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 234;
  4362. $PositiveSlopeStartB = isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 88;
  4363. $PositiveSlopeEndR = isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 239;
  4364. $PositiveSlopeEndG = isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 31;
  4365. $PositiveSlopeEndB = isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 36;
  4366. $NegativeSlopeStartR = isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 184;
  4367. $NegativeSlopeStartG = isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 234;
  4368. $NegativeSlopeStartB = isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 88;
  4369. $NegativeSlopeEndR = isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 67;
  4370. $NegativeSlopeEndG = isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 124;
  4371. $NegativeSlopeEndB = isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 227;
  4372. $Data = $this->DataSet->getData();
  4373. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4374. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4375. $YPos = $this->DataSet->Data["GraphArea"]["Y2"] + $Offset;
  4376. else
  4377. $XPos = $this->DataSet->Data["GraphArea"]["X2"] + $Offset;
  4378. foreach($Data["Series"] as $SerieName => $Serie)
  4379. {
  4380. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4381. {
  4382. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  4383. $AxisID = $Serie["Axis"];
  4384. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  4385. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4386. {
  4387. if ( $Caption )
  4388. {
  4389. if ( $CaptionLine )
  4390. {
  4391. $StartX = floor($this->GraphAreaX1-$CaptionWidth+$XMargin-$CaptionMargin);
  4392. $EndX = floor($this->GraphAreaX1-$CaptionMargin+$XMargin);
  4393. $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  4394. if ( $CaptionBox ) { $this->drawFilledRectangle($StartX,$YPos,$EndX,$YPos+$CaptionHeight,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
  4395. $this->drawLine($StartX+2,$YPos+($CaptionHeight/2),$EndX-2,$YPos+($CaptionHeight/2),$CaptionSettings);
  4396. }
  4397. else
  4398. $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));
  4399. }
  4400. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4401. $X = $this->GraphAreaX1 + $XMargin;
  4402. $TopY = $YPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
  4403. $BottomY = $YPos + ($CaptionHeight/2) + ($DerivativeHeight/2);
  4404. $StartX = floor($this->GraphAreaX1+$XMargin);
  4405. $EndX = floor($this->GraphAreaX2-$XMargin);
  4406. if ( $DrawBackground ) { $this->drawFilledRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
  4407. if ( $DrawBorder ) { $this->drawRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4408. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4409. $RestoreShadow = $this->Shadow;
  4410. $this->Shadow = FALSE;
  4411. /* Determine the Max slope index */
  4412. $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
  4413. foreach($PosArray as $Key => $Y)
  4414. {
  4415. if ( $Y != VOID && $LastX != NULL )
  4416. { $Slope = ($LastY - $Y); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }
  4417. if ( $Y == VOID )
  4418. { $LastX = NULL; $LastY = NULL; }
  4419. else
  4420. { $LastX = $X; $LastY = $Y; }
  4421. }
  4422. $LastX = NULL; $LastY = NULL; $LastColor = NULL;
  4423. foreach($PosArray as $Key => $Y)
  4424. {
  4425. if ( $Y != VOID && $LastY != NULL )
  4426. {
  4427. $Slope = ($LastY - $Y);
  4428. if ( $Slope >= 0 )
  4429. {
  4430. $SlopeIndex = (100 / $MaxSlope) * $Slope;
  4431. $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
  4432. $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
  4433. $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
  4434. }
  4435. elseif ( $Slope < 0 )
  4436. {
  4437. $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
  4438. $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
  4439. $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
  4440. $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
  4441. }
  4442. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  4443. if ( $ShadedSlopeBox && $LastColor != NULL ) // && $Slope != 0
  4444. {
  4445. $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  4446. $this->drawGradientArea($LastX,$TopY,$X,$BottomY,DIRECTION_HORIZONTAL,$GradientSettings);
  4447. }
  4448. elseif ( !$ShadedSlopeBox || $LastColor == NULL ) // || $Slope == 0
  4449. $this->drawFilledRectangle(floor($LastX),$TopY,floor($X),$BottomY,$Color);
  4450. $LastColor = $Color;
  4451. }
  4452. if ( $Y == VOID )
  4453. { $LastY = NULL; }
  4454. else
  4455. { $LastX = $X; $LastY = $Y; }
  4456. $X = $X + $XStep;
  4457. }
  4458. $YPos = $YPos + $CaptionHeight + $SerieSpacing;
  4459. }
  4460. else
  4461. {
  4462. if ( $Caption )
  4463. {
  4464. $StartY = floor($this->GraphAreaY1-$CaptionWidth+$XMargin-$CaptionMargin);
  4465. $EndY = floor($this->GraphAreaY1-$CaptionMargin+$XMargin);
  4466. if ( $CaptionLine )
  4467. {
  4468. $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  4469. if ( $CaptionBox ) { $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
  4470. $this->drawLine($XPos+($CaptionHeight/2),$StartY+2,$XPos+($CaptionHeight/2),$EndY-2,$CaptionSettings);
  4471. }
  4472. else
  4473. $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB));
  4474. }
  4475. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4476. $Y = $this->GraphAreaY1 + $XMargin;
  4477. $TopX = $XPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
  4478. $BottomX = $XPos + ($CaptionHeight/2) + ($DerivativeHeight/2);
  4479. $StartY = floor($this->GraphAreaY1+$XMargin);
  4480. $EndY = floor($this->GraphAreaY2-$XMargin);
  4481. if ( $DrawBackground ) { $this->drawFilledRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
  4482. if ( $DrawBorder ) { $this->drawRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4483. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4484. $RestoreShadow = $this->Shadow;
  4485. $this->Shadow = FALSE;
  4486. /* Determine the Max slope index */
  4487. $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
  4488. foreach($PosArray as $Key => $X)
  4489. {
  4490. if ( $X != VOID && $LastX != NULL )
  4491. { $Slope = ($X - $LastX); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }
  4492. if ( $X == VOID )
  4493. { $LastX = NULL; }
  4494. else
  4495. { $LastX = $X; }
  4496. }
  4497. $LastX = NULL; $LastY = NULL; $LastColor = NULL;
  4498. foreach($PosArray as $Key => $X)
  4499. {
  4500. if ( $X != VOID && $LastX != NULL )
  4501. {
  4502. $Slope = ($X - $LastX);
  4503. if ( $Slope >= 0 )
  4504. {
  4505. $SlopeIndex = (100 / $MaxSlope) * $Slope;
  4506. $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
  4507. $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
  4508. $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
  4509. }
  4510. elseif ( $Slope < 0 )
  4511. {
  4512. $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
  4513. $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
  4514. $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
  4515. $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
  4516. }
  4517. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  4518. if ( $ShadedSlopeBox && $LastColor != NULL )
  4519. {
  4520. $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  4521. $this->drawGradientArea($TopX,$LastY,$BottomX,$Y,DIRECTION_VERTICAL,$GradientSettings);
  4522. }
  4523. elseif ( !$ShadedSlopeBox || $LastColor == NULL )
  4524. $this->drawFilledRectangle($TopX,floor($LastY),$BottomX,floor($Y),$Color);
  4525. $LastColor = $Color;
  4526. }
  4527. if ( $X == VOID )
  4528. { $LastX = NULL; }
  4529. else
  4530. { $LastX = $X; $LastY = $Y; }
  4531. $Y = $Y + $XStep;
  4532. }
  4533. $XPos = $XPos + $CaptionHeight + $SerieSpacing;
  4534. }
  4535. $this->Shadow = $RestoreShadow;
  4536. }
  4537. }
  4538. }
  4539. /* Draw the line of best fit */
  4540. function drawBestFit($Format="")
  4541. {
  4542. $OverrideTicks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  4543. $OverrideR = isset($Format["R"]) ? $Format["R"] : VOID;
  4544. $OverrideG = isset($Format["G"]) ? $Format["G"] : VOID;
  4545. $OverrideB = isset($Format["B"]) ? $Format["B"] : VOID;
  4546. $OverrideAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : VOID;
  4547. $Data = $this->DataSet->getData();
  4548. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4549. foreach($Data["Series"] as $SerieName => $Serie)
  4550. {
  4551. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4552. {
  4553. 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"]; }
  4554. if ( $OverrideTicks == NULL ) { $Ticks = $Serie["Ticks"]; } else { $Ticks = $OverrideTicks; }
  4555. if ( $OverrideAlpha == VOID ) { $Alpha = $Serie["Color"]["Alpha"]; } else { $Alpha = $OverrideAlpha; }
  4556. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks);
  4557. $AxisID = $Serie["Axis"];
  4558. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  4559. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4560. {
  4561. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4562. $X = $this->GraphAreaX1 + $XMargin;
  4563. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4564. $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
  4565. foreach($PosArray as $Key => $Y)
  4566. {
  4567. if ( $Y != VOID )
  4568. {
  4569. $Sxy = $Sxy + $X*$Y;
  4570. $Sx = $Sx + $X;
  4571. $Sy = $Sy + $Y;
  4572. $Sxx = $Sxx + $X*$X;
  4573. }
  4574. $X = $X + $XStep;
  4575. }
  4576. $n = count($this->DataSet->stripVOID($PosArray)); //$n = count($PosArray);
  4577. $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
  4578. $B = (($Sy)-($M*$Sx))/($n);
  4579. $X1 = $this->GraphAreaX1 + $XMargin;
  4580. $Y1 = $M * $X1 + $B;
  4581. $X2 = $this->GraphAreaX2 - $XMargin;
  4582. $Y2 = $M * $X2 + $B;
  4583. if ( $Y1 < $this->GraphAreaY1 ) { $X1 = $X1 + ($this->GraphAreaY1-$Y1); $Y1 = $this->GraphAreaY1; }
  4584. if ( $Y1 > $this->GraphAreaY2 ) { $X1 = $X1 + ($Y1-$this->GraphAreaY2); $Y1 = $this->GraphAreaY2; }
  4585. if ( $Y2 < $this->GraphAreaY1 ) { $X2 = $X2 - ($this->GraphAreaY1-$Y2); $Y2 = $this->GraphAreaY1; }
  4586. if ( $Y2 > $this->GraphAreaY2 ) { $X2 = $X2 - ($Y2-$this->GraphAreaY2); $Y2 = $this->GraphAreaY2; }
  4587. $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
  4588. }
  4589. else
  4590. {
  4591. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4592. $Y = $this->GraphAreaY1 + $XMargin;
  4593. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4594. $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
  4595. foreach($PosArray as $Key => $X)
  4596. {
  4597. if ( $X != VOID )
  4598. {
  4599. $Sxy = $Sxy + $X*$Y;
  4600. $Sx = $Sx + $Y;
  4601. $Sy = $Sy + $X;
  4602. $Sxx = $Sxx + $Y*$Y;
  4603. }
  4604. $Y = $Y + $YStep;
  4605. }
  4606. $n = count($this->DataSet->stripVOID($PosArray)); //$n = count($PosArray);
  4607. $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
  4608. $B = (($Sy)-($M*$Sx))/($n);
  4609. $Y1 = $this->GraphAreaY1 + $XMargin;
  4610. $X1 = $M * $Y1 + $B;
  4611. $Y2 = $this->GraphAreaY2 - $XMargin;
  4612. $X2 = $M * $Y2 + $B;
  4613. if ( $X1 < $this->GraphAreaX1 ) { $Y1 = $Y1 + ($this->GraphAreaX1-$X1); $X1 = $this->GraphAreaX1; }
  4614. if ( $X1 > $this->GraphAreaX2 ) { $Y1 = $Y1 + ($X1-$this->GraphAreaX2); $X1 = $this->GraphAreaX2; }
  4615. if ( $X2 < $this->GraphAreaX1 ) { $Y2 = $Y2 - ($this->GraphAreaY1-$X2); $X2 = $this->GraphAreaX1; }
  4616. if ( $X2 > $this->GraphAreaX2 ) { $Y2 = $Y2 - ($X2-$this->GraphAreaX2); $X2 = $this->GraphAreaX2; }
  4617. $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
  4618. }
  4619. }
  4620. }
  4621. }
  4622. /* Write labels */
  4623. function writeLabel($SeriesName,$Indexes,$Format="")
  4624. {
  4625. $OverrideTitle = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
  4626. $ForceLabels = isset($Format["ForceLabels"]) ? $Format["ForceLabels"] : NULL;
  4627. $DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
  4628. $DrawVerticalLine = isset($Format["DrawVerticalLine"]) ? $Format["DrawVerticalLine"] : FALSE;
  4629. $VerticalLineR = isset($Format["VerticalLineR"]) ? $Format["VerticalLineR"] : 0;
  4630. $VerticalLineG = isset($Format["VerticalLineG"]) ? $Format["VerticalLineG"] : 0;
  4631. $VerticalLineB = isset($Format["VerticalLineB"]) ? $Format["VerticalLineB"] : 0;
  4632. $VerticalLineAlpha = isset($Format["VerticalLineAlpha"]) ? $Format["VerticalLineAlpha"] : 40;
  4633. $VerticalLineTicks = isset($Format["VerticalLineTicks"]) ? $Format["VerticalLineTicks"] : 2;
  4634. $Data = $this->DataSet->getData();
  4635. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4636. if ( !is_array($Indexes) ) { $Index = $Indexes; $Indexes = ""; $Indexes[] = $Index; }
  4637. if ( !is_array($SeriesName) ) { $SerieName = $SeriesName; $SeriesName = ""; $SeriesName[] = $SerieName; }
  4638. if ( $ForceLabels != NULL && !is_array($ForceLabels) ) { $ForceLabel = $ForceLabels; $ForceLabels = ""; $ForceLabels[] = $ForceLabel; }
  4639. foreach ($Indexes as $Key => $Index)
  4640. {
  4641. $Series = "";
  4642. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4643. {
  4644. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4645. $X = $this->GraphAreaX1 + $XMargin + $Index * $XStep;
  4646. 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)); }
  4647. $MinY = $this->GraphAreaY2;
  4648. foreach ($SeriesName as $iKey => $SerieName)
  4649. {
  4650. if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
  4651. {
  4652. $AxisID = $Data["Series"][$SerieName]["Axis"];
  4653. $XAxisMode = $Data["XAxisDisplay"];
  4654. $XAxisFormat = $Data["XAxisFormat"];
  4655. $XAxisUnit = $Data["XAxisUnit"];
  4656. $AxisMode = $Data["Axis"][$AxisID]["Display"];
  4657. $AxisFormat = $Data["Axis"][$AxisID]["Format"];
  4658. $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
  4659. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4660. $XLabel = $this->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index],$XAxisMode,$XAxisFormat,$XAxisUnit);
  4661. else
  4662. $XLabel = "";
  4663. if ( $OverrideTitle != NULL)
  4664. $Description = $OverrideTitle;
  4665. elseif ( count($SeriesName) == 1 )
  4666. {
  4667. $Description = $Data["Series"][$SerieName]["Description"]." - ".$XLabel;
  4668. }
  4669. elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4670. $Description = $XLabel;
  4671. $Serie = "";
  4672. $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
  4673. $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
  4674. $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
  4675. $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
  4676. if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
  4677. $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
  4678. else
  4679. $SerieOffset = 0;
  4680. $Value = $Data["Series"][$SerieName]["Data"][$Index];
  4681. if ( $Value == VOID ) { $Value = "NaN"; }
  4682. if ( $ForceLabels != NULL )
  4683. $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
  4684. else
  4685. $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
  4686. if ( $this->LastChartLayout == CHART_LAST_LAYOUT_STACKED )
  4687. {
  4688. if ( $Value >=0 ) { $LookFor = "+"; } else { $LookFor = "-"; }
  4689. $Value = 0; $Done = FALSE;
  4690. foreach($Data["Series"] as $Name => $SerieLookup)
  4691. {
  4692. if ( $SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done )
  4693. {
  4694. if ( isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID )
  4695. {
  4696. if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+" ) { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; }
  4697. if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-" ) { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; }
  4698. if ($Name == $SerieName ) { $Done = TRUE; }
  4699. }
  4700. }
  4701. }
  4702. }
  4703. $X = floor($this->GraphAreaX1 + $XMargin + $Index * $XStep + $SerieOffset);
  4704. $Y = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
  4705. if ($Y < $MinY) { $MinY = $Y; }
  4706. if ( $DrawPoint == LABEL_POINT_CIRCLE )
  4707. $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4708. elseif ( $DrawPoint == LABEL_POINT_BOX )
  4709. $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4710. $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
  4711. }
  4712. }
  4713. $this->drawLabelBox($X,$MinY-3,$Description,$Series,$Format);
  4714. }
  4715. else
  4716. {
  4717. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4718. $Y = $this->GraphAreaY1 + $XMargin + $Index * $XStep;
  4719. 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)); }
  4720. $MinX = $this->GraphAreaX2;
  4721. foreach ($SeriesName as $Key => $SerieName)
  4722. {
  4723. if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
  4724. {
  4725. $AxisID = $Data["Series"][$SerieName]["Axis"];
  4726. $XAxisMode = $Data["XAxisDisplay"];
  4727. $XAxisFormat = $Data["XAxisFormat"];
  4728. $XAxisUnit = $Data["XAxisUnit"];
  4729. $AxisMode = $Data["Axis"][$AxisID]["Display"];
  4730. $AxisFormat = $Data["Axis"][$AxisID]["Format"];
  4731. $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
  4732. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4733. $XLabel = $this->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index],$XAxisMode,$XAxisFormat,$XAxisUnit);
  4734. else
  4735. $XLabel = "";
  4736. if ( $OverrideTitle != NULL)
  4737. $Description = $OverrideTitle;
  4738. elseif ( count($SeriesName) == 1 )
  4739. {
  4740. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4741. $Description = $Data["Series"][$SerieName]["Description"]." - ".$XLabel;
  4742. }
  4743. elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4744. $Description = $XLabel;
  4745. $Serie = "";
  4746. if ( isset($Data["Extended"]["Palette"][$Index] ) )
  4747. {
  4748. $Serie["R"] = $Data["Extended"]["Palette"][$Index]["R"];
  4749. $Serie["G"] = $Data["Extended"]["Palette"][$Index]["G"];
  4750. $Serie["B"] = $Data["Extended"]["Palette"][$Index]["B"];
  4751. $Serie["Alpha"] = $Data["Extended"]["Palette"][$Index]["Alpha"];
  4752. }
  4753. else
  4754. {
  4755. $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
  4756. $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
  4757. $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
  4758. $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
  4759. }
  4760. if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
  4761. $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
  4762. else
  4763. $SerieOffset = 0;
  4764. $Value = $Data["Series"][$SerieName]["Data"][$Index];
  4765. if ( $ForceLabels != NULL )
  4766. $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
  4767. else
  4768. $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
  4769. if ( $Value == VOID ) { $Value = "NaN"; }
  4770. if ( $this->LastChartLayout == CHART_LAST_LAYOUT_STACKED )
  4771. {
  4772. if ( $Value >=0 ) { $LookFor = "+"; } else { $LookFor = "-"; }
  4773. $Value = 0; $Done = FALSE;
  4774. foreach($Data["Series"] as $Name => $SerieLookup)
  4775. {
  4776. if ( $SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done )
  4777. {
  4778. if ( isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID )
  4779. {
  4780. if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+" ) { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; }
  4781. if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-" ) { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; }
  4782. if ($Name == $SerieName ) { $Done = TRUE; }
  4783. }
  4784. }
  4785. }
  4786. }
  4787. $X = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
  4788. $Y = floor($this->GraphAreaY1 + $XMargin + $Index * $XStep + $SerieOffset);
  4789. if ($X < $MinX) { $MinX = $X; }
  4790. if ( $DrawPoint == LABEL_POINT_CIRCLE )
  4791. $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4792. elseif ( $DrawPoint == LABEL_POINT_BOX )
  4793. $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4794. $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
  4795. }
  4796. }
  4797. $this->drawLabelBox($MinX,$Y-3,$Description,$Series,$Format);
  4798. }
  4799. }
  4800. }
  4801. /* Draw a label box */
  4802. function drawLabelBox($X,$Y,$Title,$Captions,$Format="")
  4803. {
  4804. $NoTitle = isset($Format["NoTitle"]) ? $Format["NoTitle"] : NULL;
  4805. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 50;
  4806. $DrawSerieColor = isset($Format["DrawSerieColor"]) ? $Format["DrawSerieColor"] : TRUE;
  4807. $SerieR = isset($Format["SerieR"]) ? $Format["SerieR"] : NULL;
  4808. $SerieG = isset($Format["SerieG"]) ? $Format["SerieG"] : NULL;
  4809. $SerieB = isset($Format["SerieB"]) ? $Format["SerieB"] : NULL;
  4810. $SerieAlpha = isset($Format["SerieAlpha"]) ? $Format["SerieAlpha"] : NULL;
  4811. $SerieBoxSize = isset($Format["SerieBoxSize"]) ? $Format["SerieBoxSize"] : 6;
  4812. $SerieBoxSpacing = isset($Format["SerieBoxSpacing"]) ? $Format["SerieBoxSpacing"] : 4;
  4813. $VerticalMargin = isset($Format["VerticalMargin"]) ? $Format["VerticalMargin"] : 10;
  4814. $HorizontalMargin = isset($Format["HorizontalMargin"]) ? $Format["HorizontalMargin"] : 8;
  4815. $R = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
  4816. $G = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
  4817. $B = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
  4818. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
  4819. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  4820. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  4821. $TitleMode = isset($Format["TitleMode"]) ? $Format["TitleMode"] : LABEL_TITLE_NOBACKGROUND;
  4822. $TitleR = isset($Format["TitleR"]) ? $Format["TitleR"] : $R;
  4823. $TitleG = isset($Format["TitleG"]) ? $Format["TitleG"] : $G;
  4824. $TitleB = isset($Format["TitleB"]) ? $Format["TitleB"] : $B;
  4825. $TitleAlpha = isset($Format["TitleAlpha"]) ? $Format["TitleAlpha"] : 100;
  4826. $TitleBackgroundR = isset($Format["TitleBackgroundR"]) ? $Format["TitleBackgroundR"] : 0;
  4827. $TitleBackgroundG = isset($Format["TitleBackgroundG"]) ? $Format["TitleBackgroundG"] : 0;
  4828. $TitleBackgroundB = isset($Format["TitleBackgroundB"]) ? $Format["TitleBackgroundB"] : 0;
  4829. $TitleBackgroundAlpha = isset($Format["TitleBackgroundAlpha"]) ? $Format["TitleBackgroundAlpha"] : 100;
  4830. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  4831. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  4832. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  4833. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 220;
  4834. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 220;
  4835. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 220;
  4836. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 100;
  4837. if ( !$DrawSerieColor ) { $SerieBoxSize = 0; $SerieBoxSpacing = 0; }
  4838. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Title);
  4839. $TitleWidth = ($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2;
  4840. $TitleHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);
  4841. if ( $NoTitle ) { $TitleWidth = 0; $TitleHeight = 0; }
  4842. $CaptionWidth = 0; $CaptionHeight = -$HorizontalMargin;
  4843. foreach($Captions as $Key =>$Caption)
  4844. {
  4845. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Caption["Caption"]);
  4846. $CaptionWidth = max($CaptionWidth,($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2);
  4847. $CaptionHeight = $CaptionHeight + max(($TxtPos[0]["Y"] - $TxtPos[2]["Y"]),($SerieBoxSize+2)) + $HorizontalMargin;
  4848. }
  4849. if ( $CaptionHeight <= 5 ) { $CaptionHeight = $CaptionHeight + $HorizontalMargin/2; }
  4850. if ( $DrawSerieColor ) { $CaptionWidth = $CaptionWidth + $SerieBoxSize + $SerieBoxSpacing; }
  4851. $BoxWidth = max($BoxWidth,$TitleWidth,$CaptionWidth);
  4852. $XMin = $X - 5 - floor(($BoxWidth-10) / 2);
  4853. $XMax = $X + 5 + floor(($BoxWidth-10) / 2);
  4854. $RestoreShadow = $this->Shadow;
  4855. if ( $this->Shadow == TRUE )
  4856. {
  4857. $this->Shadow = FALSE;
  4858. $Poly = "";
  4859. $Poly[] = $X+$this->ShadowX; $Poly[] = $Y+$this->ShadowX;
  4860. $Poly[] = $X+5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4861. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4862. if ( $NoTitle )
  4863. {
  4864. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
  4865. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
  4866. }
  4867. else
  4868. {
  4869. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
  4870. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
  4871. }
  4872. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4873. $Poly[] = $X-5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4874. $this->drawPolygon($Poly,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  4875. }
  4876. /* Draw the background */
  4877. $GradientSettings = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$BoxAlpha);
  4878. if ( $NoTitle )
  4879. $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
  4880. else
  4881. $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
  4882. $Poly = ""; $Poly[] = $X; $Poly[] = $Y; $Poly[] = $X-5; $Poly[] = $Y-5; $Poly[] = $X+5; $Poly[] = $Y-5;
  4883. $this->drawPolygon($Poly,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB,"Alpha"=>$BoxAlpha,"NoBorder"=>TRUE));
  4884. /* Outer border */
  4885. $OuterBorderColor = $this->allocateColor($this->Picture,100,100,100,$BoxAlpha);
  4886. imageline($this->Picture,$XMin,$Y-5,$X-5,$Y-5,$OuterBorderColor);
  4887. imageline($this->Picture,$X,$Y,$X-5,$Y-5,$OuterBorderColor);
  4888. imageline($this->Picture,$X,$Y,$X+5,$Y-5,$OuterBorderColor);
  4889. imageline($this->Picture,$X+5,$Y-5,$XMax,$Y-5,$OuterBorderColor);
  4890. if ( $NoTitle )
  4891. {
  4892. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin,$Y-5,$OuterBorderColor);
  4893. imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5,$OuterBorderColor);
  4894. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$OuterBorderColor);
  4895. }
  4896. else
  4897. {
  4898. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin,$Y-5,$OuterBorderColor);
  4899. imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5,$OuterBorderColor);
  4900. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$OuterBorderColor);
  4901. }
  4902. /* Inner border */
  4903. $InnerBorderColor = $this->allocateColor($this->Picture,255,255,255,$BoxAlpha);
  4904. imageline($this->Picture,$XMin+1,$Y-6,$X-5,$Y-6,$InnerBorderColor);
  4905. imageline($this->Picture,$X,$Y-1,$X-5,$Y-6,$InnerBorderColor);
  4906. imageline($this->Picture,$X,$Y-1,$X+5,$Y-6,$InnerBorderColor);
  4907. imageline($this->Picture,$X+5,$Y-6,$XMax-1,$Y-6,$InnerBorderColor);
  4908. if ( $NoTitle )
  4909. {
  4910. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin+1,$Y-6,$InnerBorderColor);
  4911. imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-6,$InnerBorderColor);
  4912. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$InnerBorderColor);
  4913. }
  4914. else
  4915. {
  4916. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin+1,$Y-6,$InnerBorderColor);
  4917. imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-6,$InnerBorderColor);
  4918. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$InnerBorderColor);
  4919. }
  4920. /* Draw the separator line */
  4921. if ( $TitleMode == LABEL_TITLE_NOBACKGROUND && !$NoTitle )
  4922. {
  4923. $YPos = $Y-7-$CaptionHeight-$HorizontalMargin-$HorizontalMargin/2;
  4924. $XMargin = $VerticalMargin / 2;
  4925. $this->drawLine($XMin+$XMargin,$YPos+1,$XMax-$XMargin,$YPos+1,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB,"Alpha"=>$BoxAlpha));
  4926. $this->drawLine($XMin+$XMargin,$YPos,$XMax-$XMargin,$YPos,array("R"=>$GradientStartR,"G"=>$GradientStartG,"B"=>$GradientStartB,"Alpha"=>$BoxAlpha));
  4927. }
  4928. elseif ( $TitleMode == LABEL_TITLE_BACKGROUND )
  4929. {
  4930. $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));
  4931. imageline($this->Picture,$XMin+1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$XMax-1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$InnerBorderColor);
  4932. }
  4933. /* Write the description */
  4934. if ( !$NoTitle )
  4935. $this->drawText($XMin+$VerticalMargin,$Y-7-$CaptionHeight-$HorizontalMargin*2,$Title,array("Align"=>TEXT_ALIGN_BOTTOMLEFT,"R"=>$TitleR,"G"=>$TitleG,"B"=>$TitleB));
  4936. /* Write the value */
  4937. $YPos = $Y-5-$HorizontalMargin; $XPos = $XMin+$VerticalMargin+$SerieBoxSize+$SerieBoxSpacing;
  4938. foreach($Captions as $Key => $Caption)
  4939. {
  4940. $CaptionTxt = $Caption["Caption"];
  4941. $TxtPos = $this->getTextBox($XPos,$YPos,$FontName,$FontSize,0,$CaptionTxt);
  4942. $CaptionHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);
  4943. /* Write the serie color if needed */
  4944. if ( $DrawSerieColor )
  4945. {
  4946. $BoxSettings = array("R"=>$Caption["Format"]["R"],"G"=>$Caption["Format"]["G"],"B"=>$Caption["Format"]["B"],"Alpha"=>$Caption["Format"]["Alpha"],"BorderR"=>0,"BorderG"=>0,"BorderB"=>0);
  4947. $this->drawFilledRectangle($XMin+$VerticalMargin,$YPos-$SerieBoxSize,$XMin+$VerticalMargin+$SerieBoxSize,$YPos,$BoxSettings);
  4948. }
  4949. $this->drawText($XPos,$YPos,$CaptionTxt,array("Align"=>TEXT_ALIGN_BOTTOMLEFT));
  4950. $YPos = $YPos - $CaptionHeight - $HorizontalMargin;
  4951. }
  4952. $this->Shadow = $RestoreShadow;
  4953. }
  4954. /* Draw a basic shape */
  4955. function drawShape($X,$Y,$Shape,$PlotSize,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha)
  4956. {
  4957. if ( $Shape == SERIE_SHAPE_FILLEDCIRCLE )
  4958. {
  4959. if ( $PlotBorder ) { $this->drawFilledCircle($X,$Y,$PlotSize+$BorderSize,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4960. $this->drawFilledCircle($X,$Y,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4961. }
  4962. elseif ( $Shape == SERIE_SHAPE_FILLEDSQUARE )
  4963. {
  4964. 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)); }
  4965. $this->drawFilledRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4966. }
  4967. elseif ( $Shape == SERIE_SHAPE_FILLEDTRIANGLE )
  4968. {
  4969. if ( $PlotBorder )
  4970. {
  4971. $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize-$BorderSize; $Pos[]=$X-$PlotSize-$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize; $Pos[]=$X+$PlotSize+$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize;
  4972. $this->drawPolygon($Pos,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha));
  4973. }
  4974. $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X-$PlotSize; $Pos[]=$Y+$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y+$PlotSize;
  4975. $this->drawPolygon($Pos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4976. }
  4977. elseif ( $Shape == SERIE_SHAPE_TRIANGLE )
  4978. {
  4979. $this->drawLine($X,$Y-$PlotSize,$X-$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4980. $this->drawLine($X-$PlotSize,$Y+$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4981. $this->drawLine($X+$PlotSize,$Y+$PlotSize,$X,$Y-$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4982. }
  4983. elseif ( $Shape == SERIE_SHAPE_SQUARE )
  4984. $this->drawRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4985. elseif ( $Shape == SERIE_SHAPE_CIRCLE )
  4986. $this->drawCircle($X,$Y,$PlotSize,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4987. elseif ( $Shape == SERIE_SHAPE_DIAMOND )
  4988. {
  4989. $Pos = ""; $Pos[]=$X-$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize;
  4990. $this->drawPolygon($Pos,array("NoFill"=>TRUE,"BorderR"=>$R,"BorderG"=>$G,"BorderB"=>$B,"BorderAlpha"=>$Alpha));
  4991. }
  4992. elseif ( $Shape == SERIE_SHAPE_FILLEDDIAMOND )
  4993. {
  4994. if ( $PlotBorder )
  4995. {
  4996. $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;
  4997. $this->drawPolygon($Pos,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha));
  4998. }
  4999. $Pos = ""; $Pos[]=$X-$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize;
  5000. $this->drawPolygon($Pos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5001. }
  5002. }
  5003. function drawPolygonChart($Points,$Format="")
  5004. {
  5005. $R = isset($Format["R"]) ? $Format["R"] : 0;
  5006. $G = isset($Format["G"]) ? $Format["G"] : 0;
  5007. $B = isset($Format["B"]) ? $Format["B"] : 0;
  5008. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  5009. $NoFill = isset($Format["NoFill"]) ? $Format["NoFill"] : FALSE;
  5010. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  5011. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  5012. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  5013. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  5014. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha / 2;
  5015. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  5016. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  5017. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  5018. $RestoreShadow = $this->Shadow;
  5019. $this->Shadow = FALSE;
  5020. $AllIntegers = TRUE;
  5021. for($i=0;$i<=count($Points)-2;$i=$i+2)
  5022. { if ( $this->getFirstDecimal($Points[$i+1]) != 0 ) { $AllIntegers = FALSE; } }
  5023. /* Convert polygon to segments */
  5024. $Segments = "";
  5025. for($i=2;$i<=count($Points)-2;$i=$i+2)
  5026. { $Segments[] = array("X1"=>$Points[$i-2],"Y1"=>$Points[$i-1],"X2"=>$Points[$i],"Y2"=>$Points[$i+1]); }
  5027. $Segments[] = array("X1"=>$Points[$i-2],"Y1"=>$Points[$i-1],"X2"=>$Points[0],"Y2"=>$Points[1]);
  5028. /* Simplify straight lines */
  5029. $Result = ""; $inHorizon = FALSE; $LastX = VOID;
  5030. foreach($Segments as $Key => $Pos)
  5031. {
  5032. if ( $Pos["Y1"] != $Pos["Y2"] )
  5033. {
  5034. if ( $inHorizon ) { $inHorizon = FALSE; $Result[] = array("X1"=>$LastX,"Y1"=>$Pos["Y1"],"X2"=>$Pos["X1"],"Y2"=>$Pos["Y1"]); }
  5035. $Result[] = array("X1"=>$Pos["X1"],"Y1"=>$Pos["Y1"],"X2"=>$Pos["X2"],"Y2"=>$Pos["Y2"]);
  5036. }
  5037. else { if ( !$inHorizon ) { $inHorizon = TRUE; $LastX = $Pos["X1"];} }
  5038. }
  5039. $Segments = $Result;
  5040. /* Do we have something to draw */
  5041. if ( $Segments == "" ) { return(0); }
  5042. /* For segments debugging purpose */
  5043. //foreach($Segments as $Key => $Pos)
  5044. // echo $Pos["X1"].",".$Pos["Y1"].",".$Pos["X2"].",".$Pos["Y2"]."\r\n";
  5045. /* Find out the min & max Y boundaries */
  5046. $MinY = OUT_OF_SIGHT; $MaxY = OUT_OF_SIGHT;
  5047. foreach($Segments as $Key => $Coords)
  5048. {
  5049. if ( $MinY == OUT_OF_SIGHT || $MinY > min($Coords["Y1"],$Coords["Y2"]) ) { $MinY = min($Coords["Y1"],$Coords["Y2"]); }
  5050. if ( $MaxY == OUT_OF_SIGHT || $MaxY < max($Coords["Y1"],$Coords["Y2"]) ) { $MaxY = max($Coords["Y1"],$Coords["Y2"]); }
  5051. }
  5052. if ( $AllIntegers ) { $YStep = 1; } else { $YStep = .5; }
  5053. $MinY = floor($MinY); $MaxY = floor($MaxY);
  5054. /* Scan each Y lines */
  5055. $DefaultColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  5056. $DebugLine = 0; $DebugColor = $this->allocateColor($this->Picture,255,0,0,100);
  5057. $MinY = floor($MinY); $MaxY = floor($MaxY); $YStep = 1;
  5058. if ( !$NoFill )
  5059. {
  5060. //if ( $DebugLine ) { $MinY = $DebugLine; $MaxY = $DebugLine; }
  5061. for($Y=$MinY;$Y<=$MaxY;$Y=$Y+$YStep)
  5062. {
  5063. $Intersections = ""; $LastSlope = NULL; $RestoreLast = "-";
  5064. foreach($Segments as $Key => $Coords)
  5065. {
  5066. $X1 = $Coords["X1"]; $X2 = $Coords["X2"]; $Y1 = $Coords["Y1"]; $Y2 = $Coords["Y2"];
  5067. if ( min($Y1,$Y2) <= $Y && max($Y1,$Y2) >= $Y )
  5068. {
  5069. if ( $Y1 == $Y2 )
  5070. { $X = $X1; }
  5071. else
  5072. { $X = $X1 + ( ($Y-$Y1)*$X2 - ($Y-$Y1)*$X1 ) / ($Y2-$Y1); }
  5073. $X = floor($X);
  5074. if ( $X2 == $X1 )
  5075. { $Slope = "!"; }
  5076. else
  5077. {
  5078. $SlopeC = ($Y2 - $Y1) / ($X2 - $X1);
  5079. if( $SlopeC == 0 )
  5080. { $Slope = "="; }
  5081. elseif( $SlopeC > 0 )
  5082. { $Slope = "+"; }
  5083. elseif ( $SlopeC < 0 )
  5084. { $Slope = "-"; }
  5085. }
  5086. if ( !is_array($Intersections) )
  5087. { $Intersections[] = $X; }
  5088. elseif( !in_array($X,$Intersections) )
  5089. { $Intersections[] = $X; }
  5090. elseif( in_array($X,$Intersections) )
  5091. {
  5092. if ($Y == $DebugLine) { echo $Slope."/".$LastSlope."(".$X.") "; }
  5093. if ( $Slope == "=" && $LastSlope == "-" ) { $Intersections[] = $X; }
  5094. if ( $Slope != $LastSlope && $LastSlope != "!" && $LastSlope != "=" ) { $Intersections[] = $X; }
  5095. if ( $Slope != $LastSlope && $LastSlope == "!" && $Slope == "+" ) { $Intersections[] = $X; }
  5096. }
  5097. if ( is_array($Intersections) && in_array($X,$Intersections) && $LastSlope == "=" && ($Slope == "-" )) { $Intersections[] = $X; }
  5098. $LastSlope = $Slope;
  5099. }
  5100. }
  5101. if ( $RestoreLast != "-" ) { $Intersections[] = $RestoreLast; echo "@".$Y."\r\n"; }
  5102. if ( is_array($Intersections) )
  5103. {
  5104. sort($Intersections);
  5105. if ($Y == $DebugLine) { print_r($Intersections); }
  5106. /* Remove NULL plots */
  5107. $Result = "";
  5108. for($i=0;$i<=count($Intersections)-1;$i=$i+2)
  5109. {
  5110. if ( isset($Intersections[$i+1]) )
  5111. { if ( $Intersections[$i] != $Intersections[$i+1] ) { $Result[] = $Intersections[$i]; $Result[] = $Intersections[$i+1]; } }
  5112. }
  5113. if ( is_array($Result) )
  5114. {
  5115. $Intersections = $Result;
  5116. $LastX = OUT_OF_SIGHT;
  5117. foreach($Intersections as $Key => $X)
  5118. {
  5119. if ( $LastX == OUT_OF_SIGHT )
  5120. $LastX = $X;
  5121. elseif ( $LastX != OUT_OF_SIGHT )
  5122. {
  5123. if ( $this->getFirstDecimal($LastX) > 1 ) { $LastX++; }
  5124. $Color = $DefaultColor;
  5125. if ( $Threshold != NULL )
  5126. {
  5127. foreach($Threshold as $Key => $Parameters)
  5128. {
  5129. if ( $Y <= $Parameters["MinX"] && $Y >= $Parameters["MaxX"])
  5130. {
  5131. if ( isset($Parameters["R"]) ) { $R = $Parameters["R"]; } else { $R = 0; }
  5132. if ( isset($Parameters["G"]) ) { $G = $Parameters["G"]; } else { $G = 0; }
  5133. if ( isset($Parameters["B"]) ) { $B = $Parameters["B"]; } else { $B = 0; }
  5134. if ( isset($Parameters["Alpha"]) ) { $Alpha = $Parameters["Alpha"]; } else { $Alpha = 100; }
  5135. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  5136. }
  5137. }
  5138. }
  5139. imageline($this->Picture,$LastX,$Y,$X,$Y,$Color);
  5140. if ( $Y == $DebugLine) { imageline($this->Picture,$LastX,$Y,$X,$Y,$DebugColor); }
  5141. $LastX = OUT_OF_SIGHT;
  5142. }
  5143. }
  5144. }
  5145. }
  5146. }
  5147. }
  5148. /* Draw the polygon border, if required */
  5149. if ( !$NoBorder)
  5150. {
  5151. foreach($Segments as $Key => $Coords)
  5152. $this->drawLine($Coords["X1"],$Coords["Y1"],$Coords["X2"],$Coords["Y2"],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Threshold"=>$Threshold));
  5153. }
  5154. $this->Shadow = $RestoreShadow;
  5155. }
  5156. /* Return the abscissa margin */
  5157. function getAbscissaMargin($Data)
  5158. {
  5159. foreach($Data["Axis"] as $AxisID => $Values) { if ( $Values["Identity"] == AXIS_X ) { return($Values["Margin"]); } }
  5160. return(0);
  5161. }
  5162. }

Constants

Classes

Namesort descending Description
pDraw