pDraw.class.php

Constants

NameDescription
ALL
AUTO
BOUND_BOTH
BOUND_LABEL_POS_AUTO
BOUND_LABEL_POS_BOTTOM
BOUND_LABEL_POS_TOP
BOUND_MAX
BOUND_MIN
CAPTION_LEFT_TOP
CAPTION_RIGHT_BOTTOM
DIRECTION_HORIZONTAL
DIRECTION_VERTICAL
DISPLAY_AUTO
DISPLAY_MANUAL
GRADIENT_EFFECT_CAN
GRADIENT_SIMPLE
LABELING_ALL
LABELING_DIFFERENT
LABEL_POINT_BOX
LABEL_POINT_CIRCLE
LABEL_POINT_NONE
LABEL_POS_BOTTOM
LABEL_POS_CENTER
LABEL_POS_INSIDE
LABEL_POS_LEFT
LABEL_POS_OUTSIDE
LABEL_POS_RIGHT
LABEL_POS_TOP
LABEL_TITLE_BACKGROUND
LABEL_TITLE_NOBACKGROUND
LEGEND_BOX
LEGEND_FAMILY_BOX
LEGEND_FAMILY_CIRCLE
LEGEND_FAMILY_LINE
LEGEND_HORIZONTAL
LEGEND_NOBORDER
LEGEND_ROUND
LEGEND_VERTICAL
NONE
ORIENTATION_AUTO
ORIENTATION_HORIZONTAL
ORIENTATION_VERTICAL
OUT_OF_SIGHT
PI
POSITION_BOTTOM
POSITION_TOP
SCALE_MODE_ADDALL
SCALE_MODE_ADDALL_START0
SCALE_MODE_FLOATING
SCALE_MODE_MANUAL
SCALE_MODE_START0
SCALE_POS_LEFTRIGHT
SCALE_POS_TOPBOTTOM
SCALE_SKIP_NONE
SCALE_SKIP_NUMBERS
SCALE_SKIP_SAME
TEXT_ALIGN_BOTTOMLEFT
TEXT_ALIGN_BOTTOMMIDDLE
TEXT_ALIGN_BOTTOMRIGHT
TEXT_ALIGN_MIDDLELEFT
TEXT_ALIGN_MIDDLEMIDDLE
TEXT_ALIGN_MIDDLERIGHT
TEXT_ALIGN_TOPLEFT
TEXT_ALIGN_TOPMIDDLE
TEXT_ALIGN_TOPRIGHT
ZONE_NAME_ANGLE_AUTO

Classes

NameDescription
pDraw

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,