pScatter.class.php 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. <?php
  2. /*
  3. pScatter - class to draw scatter charts
  4. Version : 2.1.4
  5. Made by : Jean-Damien POGOLOTTI
  6. Last Update : 19/01/2014
  7. This file can be distributed under the license you can find at :
  8. http://www.pchart.net/license
  9. You can find the whole class documentation on the pChart web site.
  10. */
  11. define("SCATTER_MISSING_X_SERIE" , 190001);
  12. define("SCATTER_MISSING_Y_SERIE" , 190002);
  13. /* pScatter class definition */
  14. class pScatter
  15. {
  16. var $pChartObject;
  17. var $pDataObject;
  18. /* Class creator */
  19. function pScatter($pChartObject,$pDataObject)
  20. {
  21. $this->pChartObject = $pChartObject;
  22. $this->pDataObject = $pDataObject;
  23. }
  24. /* Prepare the scale */
  25. function drawScatterScale($Format="")
  26. {
  27. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : SCALE_MODE_FLOATING;
  28. $Floating = isset($Format["Floating"]) ? $Format["Floating"] : FALSE;
  29. $XLabelsRotation = isset($Format["XLabelsRotation"]) ? $Format["XLabelsRotation"] : 90;
  30. $MinDivHeight = isset($Format["MinDivHeight"]) ? $Format["MinDivHeight"] : 20;
  31. $Factors = isset($Format["Factors"]) ? $Format["Factors"] : array(1,2,5);
  32. $ManualScale = isset($Format["ManualScale"]) ? $Format["ManualScale"] : array("0"=>array("Min"=>-100,"Max"=>100));
  33. $XMargin = isset($Format["XMargin"]) ? $Format["XMargin"] : 0;
  34. $YMargin = isset($Format["YMargin"]) ? $Format["YMargin"] : 0;
  35. $ScaleSpacing = isset($Format["ScaleSpacing"]) ? $Format["ScaleSpacing"] : 15;
  36. $InnerTickWidth = isset($Format["InnerTickWidth"]) ? $Format["InnerTickWidth"] : 2;
  37. $OuterTickWidth = isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2;
  38. $DrawXLines = isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : ALL;
  39. $DrawYLines = isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL;
  40. $GridTicks = isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4;
  41. $GridR = isset($Format["GridR"]) ? $Format["GridR"] : 255;
  42. $GridG = isset($Format["GridG"]) ? $Format["GridG"] : 255;
  43. $GridB = isset($Format["GridB"]) ? $Format["GridB"] : 255;
  44. $GridAlpha = isset($Format["GridAlpha"]) ? $Format["GridAlpha"] : 40;
  45. $AxisRo = isset($Format["AxisR"]) ? $Format["AxisR"] : 0;
  46. $AxisGo = isset($Format["AxisG"]) ? $Format["AxisG"] : 0;
  47. $AxisBo = isset($Format["AxisB"]) ? $Format["AxisB"] : 0;
  48. $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100;
  49. $TickRo = isset($Format["TickR"]) ? $Format["TickR"] : 0;
  50. $TickGo = isset($Format["TickG"]) ? $Format["TickG"] : 0;
  51. $TickBo = isset($Format["TickB"]) ? $Format["TickB"] : 0;
  52. $TickAlpha = isset($Format["TickAlpha"]) ? $Format["TickAlpha"] : 100;
  53. $DrawSubTicks = isset($Format["DrawSubTicks"]) ? $Format["DrawSubTicks"] : FALSE;
  54. $InnerSubTickWidth = isset($Format["InnerSubTickWidth"]) ? $Format["InnerSubTickWidth"] : 0;
  55. $OuterSubTickWidth = isset($Format["OuterSubTickWidth"]) ? $Format["OuterSubTickWidth"] : 2;
  56. $SubTickR = isset($Format["SubTickR"]) ? $Format["SubTickR"] : 255;
  57. $SubTickG = isset($Format["SubTickG"]) ? $Format["SubTickG"] : 0;
  58. $SubTickB = isset($Format["SubTickB"]) ? $Format["SubTickB"] : 0;
  59. $SubTickAlpha = isset($Format["SubTickAlpha"]) ? $Format["SubTickAlpha"] : 100;
  60. $XReleasePercent = isset($Format["XReleasePercent"]) ? $Format["XReleasePercent"] : 1;
  61. $DrawArrows = isset($Format["DrawArrows"]) ? $Format["DrawArrows"] : FALSE;
  62. $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 8;
  63. $CycleBackground = isset($Format["CycleBackground"]) ? $Format["CycleBackground"] : FALSE;
  64. $BackgroundR1 = isset($Format["BackgroundR1"]) ? $Format["BackgroundR1"] : 255;
  65. $BackgroundG1 = isset($Format["BackgroundG1"]) ? $Format["BackgroundG1"] : 255;
  66. $BackgroundB1 = isset($Format["BackgroundB1"]) ? $Format["BackgroundB1"] : 255;
  67. $BackgroundAlpha1 = isset($Format["BackgroundAlpha1"]) ? $Format["BackgroundAlpha1"] : 10;
  68. $BackgroundR2 = isset($Format["BackgroundR2"]) ? $Format["BackgroundR2"] : 230;
  69. $BackgroundG2 = isset($Format["BackgroundG2"]) ? $Format["BackgroundG2"] : 230;
  70. $BackgroundB2 = isset($Format["BackgroundB2"]) ? $Format["BackgroundB2"] : 230;
  71. $BackgroundAlpha2 = isset($Format["BackgroundAlpha2"]) ? $Format["BackgroundAlpha2"] : 10;
  72. /* Check if we have at least both one X and Y axis */
  73. $GotXAxis = FALSE; $GotYAxis = FALSE;
  74. foreach($this->pDataObject->Data["Axis"] as $AxisID => $AxisSettings)
  75. {
  76. if ( $AxisSettings["Identity"] == AXIS_X ) { $GotXAxis = TRUE; }
  77. if ( $AxisSettings["Identity"] == AXIS_Y ) { $GotYAxis = TRUE; }
  78. }
  79. if ( !$GotXAxis ) { return(SCATTER_MISSING_X_SERIE); }
  80. if ( !$GotYAxis ) { return(SCATTER_MISSING_Y_SERIE); }
  81. /* Skip a NOTICE event in case of an empty array */
  82. if ( $DrawYLines == NONE ) { $DrawYLines = array("zarma"=>"31"); }
  83. $Data = $this->pDataObject->getData();
  84. foreach($Data["Axis"] as $AxisID => $AxisSettings)
  85. {
  86. if ( $AxisSettings["Identity"] == AXIS_X)
  87. { $Width = $this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1 - $XMargin*2; }
  88. else
  89. { $Width = $this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1 - $YMargin*2; }
  90. $AxisMin = ABSOLUTE_MAX; $AxisMax = OUT_OF_SIGHT;
  91. if ( $Mode == SCALE_MODE_FLOATING )
  92. {
  93. foreach($Data["Series"] as $SerieID => $SerieParameter)
  94. {
  95. if ( $SerieParameter["Axis"] == $AxisID && $Data["Series"][$SerieID]["isDrawable"] )
  96. {
  97. $AxisMax = max($AxisMax,$Data["Series"][$SerieID]["Max"]);
  98. $AxisMin = min($AxisMin,$Data["Series"][$SerieID]["Min"]);
  99. }
  100. }
  101. $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
  102. $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
  103. }
  104. elseif ( $Mode == SCALE_MODE_MANUAL )
  105. {
  106. if ( isset($ManualScale[$AxisID]["Min"]) && isset($ManualScale[$AxisID]["Max"]) )
  107. {
  108. $Data["Axis"][$AxisID]["Min"] = $ManualScale[$AxisID]["Min"];
  109. $Data["Axis"][$AxisID]["Max"] = $ManualScale[$AxisID]["Max"];
  110. }
  111. else
  112. { echo "Manual scale boundaries not set."; exit(); }
  113. }
  114. /* Full manual scale */
  115. if ( isset($ManualScale[$AxisID]["Rows"]) && isset($ManualScale[$AxisID]["RowHeight"]) )
  116. $Scale = array("Rows"=>$ManualScale[$AxisID]["Rows"],"RowHeight"=>$ManualScale[$AxisID]["RowHeight"],"XMin"=>$ManualScale[$AxisID]["Min"],"XMax"=>$ManualScale[$AxisID]["Max"]);
  117. else
  118. {
  119. $MaxDivs = floor($Width/$MinDivHeight);
  120. $Scale = $this->pChartObject->computeScale($Data["Axis"][$AxisID]["Min"],$Data["Axis"][$AxisID]["Max"],$MaxDivs,$Factors,$AxisID);
  121. }
  122. $Data["Axis"][$AxisID]["Margin"] = $AxisSettings["Identity"] == AXIS_X ? $XMargin : $YMargin;
  123. $Data["Axis"][$AxisID]["ScaleMin"] = $Scale["XMin"];
  124. $Data["Axis"][$AxisID]["ScaleMax"] = $Scale["XMax"];
  125. $Data["Axis"][$AxisID]["Rows"] = $Scale["Rows"];
  126. $Data["Axis"][$AxisID]["RowHeight"] = $Scale["RowHeight"];
  127. if ( isset($Scale["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = $Scale["Format"]; }
  128. if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
  129. if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
  130. if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
  131. }
  132. /* Get the default font color */
  133. $FontColorRo = $this->pChartObject->FontColorR; $FontColorGo = $this->pChartObject->FontColorG; $FontColorBo = $this->pChartObject->FontColorB;
  134. /* Set the original boundaries */
  135. $AxisPos["L"] = $this->pChartObject->GraphAreaX1; $AxisPos["R"] = $this->pChartObject->GraphAreaX2; $AxisPos["T"] = $this->pChartObject->GraphAreaY1; $AxisPos["B"] = $this->pChartObject->GraphAreaY2;
  136. foreach($Data["Axis"] as $AxisID => $AxisSettings)
  137. {
  138. if ( isset($AxisSettings["Color"]) )
  139. {
  140. $AxisR = $AxisSettings["Color"]["R"]; $AxisG = $AxisSettings["Color"]["G"]; $AxisB = $AxisSettings["Color"]["B"];
  141. $TickR = $AxisSettings["Color"]["R"]; $TickG = $AxisSettings["Color"]["G"]; $TickB = $AxisSettings["Color"]["B"];
  142. $this->pChartObject->setFontProperties(array("R"=>$AxisSettings["Color"]["R"],"G"=>$AxisSettings["Color"]["G"],"B"=>$AxisSettings["Color"]["B"]));
  143. }
  144. else
  145. {
  146. $AxisR = $AxisRo; $AxisG = $AxisGo; $AxisB = $AxisBo;
  147. $TickR = $TickRo; $TickG = $TickGo; $TickB = $TickBo;
  148. $this->pChartObject->setFontProperties(array("R"=>$FontColorRo,"G"=>$FontColorGo,"B"=>$FontColorBo));
  149. }
  150. $LastValue = "w00t"; $ID = 1;
  151. if ( $AxisSettings["Identity"] == AXIS_X )
  152. {
  153. if ( $AxisSettings["Position"] == AXIS_POSITION_BOTTOM )
  154. {
  155. if ( $XLabelsRotation == 0 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $LabelOffset = 2; }
  156. if ( $XLabelsRotation > 0 && $XLabelsRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $LabelOffset = 5; }
  157. if ( $XLabelsRotation == 180 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $LabelOffset = 5; }
  158. if ( $XLabelsRotation > 180 && $XLabelsRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $LabelOffset = 2; }
  159. if ( $Floating )
  160. { $FloatingOffset = $YMargin; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$AxisSettings["Margin"],$AxisPos["B"],$this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  161. else
  162. { $FloatingOffset = 0; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1,$AxisPos["B"],$this->pChartObject->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  163. if ( $DrawArrows ) { $this->pChartObject->drawArrow($this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["B"],$this->pChartObject->GraphAreaX2+($ArrowSize*2),$AxisPos["B"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  164. $Width = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) - $AxisSettings["Margin"]*2;
  165. $Step = $Width / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MaxBottom = $AxisPos["B"];
  166. $LastX = NULL;
  167. for($i=0;$i<=$AxisSettings["Rows"];$i++)
  168. {
  169. $XPos = $this->pChartObject->GraphAreaX1 + $AxisSettings["Margin"] + $Step*$i;
  170. $YPos = $AxisPos["B"];
  171. $Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
  172. 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); }
  173. if ( $LastX != NULL && $CycleBackground && ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) )) { $this->pChartObject->drawFilledRectangle($LastX,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,$BGColor); }
  174. if ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) ) { $this->pChartObject->drawLine($XPos,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  175. if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
  176. $this->pChartObject->drawLine($XPos+$SubTicksSize,$YPos-$InnerSubTickWidth,$XPos+$SubTicksSize,$YPos+$OuterSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  177. $this->pChartObject->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  178. $Bounds = $this->pChartObject->drawText($XPos,$YPos+$OuterTickWidth+$LabelOffset,$Value,array("Angle"=>$XLabelsRotation,"Align"=>$LabelAlign));
  179. $TxtBottom = $YPos+2+$OuterTickWidth+2+($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  180. $MaxBottom = max($MaxBottom,$TxtBottom);
  181. $LastX = $XPos;
  182. }
  183. if ( isset($AxisSettings["Name"]) )
  184. {
  185. $YPos = $MaxBottom+2;
  186. $XPos = $this->pChartObject->GraphAreaX1+($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1)/2;
  187. $Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  188. $MaxBottom = $Bounds[0]["Y"];
  189. $this->pDataObject->Data["GraphArea"]["Y2"] = $MaxBottom + $this->pChartObject->FontSize;
  190. }
  191. $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
  192. }
  193. elseif ( $AxisSettings["Position"] == AXIS_POSITION_TOP )
  194. {
  195. if ( $XLabelsRotation == 0 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $LabelOffset = 2; }
  196. if ( $XLabelsRotation > 0 && $XLabelsRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $LabelOffset = 2; }
  197. if ( $XLabelsRotation == 180 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $LabelOffset = 5; }
  198. if ( $XLabelsRotation > 180 && $SLabelxRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $LabelOffset = 5; }
  199. if ( $Floating )
  200. { $FloatingOffset = $YMargin; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$AxisSettings["Margin"],$AxisPos["T"],$this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  201. else
  202. { $FloatingOffset = 0; $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1,$AxisPos["T"],$this->pChartObject->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  203. if ( $DrawArrows ) { $this->pChartObject->drawArrow($this->pChartObject->GraphAreaX2-$AxisSettings["Margin"],$AxisPos["T"],$this->pChartObject->GraphAreaX2+($ArrowSize*2),$AxisPos["T"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  204. $Width = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) - $AxisSettings["Margin"]*2;
  205. $Step = $Width / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MinTop = $AxisPos["T"];
  206. $LastX = NULL;
  207. for($i=0;$i<=$AxisSettings["Rows"];$i++)
  208. {
  209. $XPos = $this->pChartObject->GraphAreaX1 + $AxisSettings["Margin"] + $Step*$i;
  210. $YPos = $AxisPos["T"];
  211. $Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
  212. 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); }
  213. if ( $LastX != NULL && $CycleBackground && ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) )) { $this->pChartObject->drawFilledRectangle($LastX,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,$BGColor); }
  214. if ( $DrawXLines == ALL || in_array($AxisID,$DrawXLines) ) { $this->pChartObject->drawLine($XPos,$this->pChartObject->GraphAreaY1+$FloatingOffset,$XPos,$this->pChartObject->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  215. if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
  216. $this->pChartObject->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  217. $this->pChartObject->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  218. $Bounds = $this->pChartObject->drawText($XPos,$YPos-$OuterTickWidth-$LabelOffset,$Value,array("Angle"=>$XLabelsRotation,"Align"=>$LabelAlign));
  219. $TxtBox = $YPos-$OuterTickWidth-4-($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  220. $MinTop = min($MinTop,$TxtBox);
  221. $LastX = $XPos;
  222. }
  223. if ( isset($AxisSettings["Name"]) )
  224. {
  225. $YPos = $MinTop-2;
  226. $XPos = $this->pChartObject->GraphAreaX1+($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1)/2;
  227. $Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  228. $MinTop = $Bounds[2]["Y"];
  229. $this->pDataObject->Data["GraphArea"]["Y1"] = $MinTop;
  230. }
  231. $AxisPos["T"] = $MinTop - $ScaleSpacing;
  232. }
  233. }
  234. elseif ( $AxisSettings["Identity"] == AXIS_Y )
  235. {
  236. if ( $AxisSettings["Position"] == AXIS_POSITION_LEFT )
  237. {
  238. if ( $Floating )
  239. { $FloatingOffset = $XMargin; $this->pChartObject->drawLine($AxisPos["L"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["L"],$this->pChartObject->GraphAreaY2-$AxisSettings["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  240. else
  241. { $FloatingOffset = 0; $this->pChartObject->drawLine($AxisPos["L"],$this->pChartObject->GraphAreaY1,$AxisPos["L"],$this->pChartObject->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  242. if ( $DrawArrows ) { $this->pChartObject->drawArrow($AxisPos["L"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["L"],$this->pChartObject->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  243. $Height = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) - $AxisSettings["Margin"]*2;
  244. $Step = $Height / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MinLeft = $AxisPos["L"];
  245. $LastY = NULL;
  246. for($i=0;$i<=$AxisSettings["Rows"];$i++)
  247. {
  248. $YPos = $this->pChartObject->GraphAreaY2 - $AxisSettings["Margin"] - $Step*$i;
  249. $XPos = $AxisPos["L"];
  250. $Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
  251. 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); }
  252. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->pChartObject->drawFilledRectangle($this->pChartObject->GraphAreaX1+$FloatingOffset,$LastY,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  253. if ( ($YPos != $this->pChartObject->GraphAreaY1 && $YPos != $this->pChartObject->GraphAreaY2) && ($DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$FloatingOffset,$YPos,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  254. if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
  255. $this->pChartObject->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  256. $this->pChartObject->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  257. $Bounds = $this->pChartObject->drawText($XPos-$OuterTickWidth-2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLERIGHT));
  258. $TxtLeft = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
  259. $MinLeft = min($MinLeft,$TxtLeft);
  260. $LastY = $YPos;
  261. }
  262. if ( isset($AxisSettings["Name"]) )
  263. {
  264. $XPos = $MinLeft-2;
  265. $YPos = $this->pChartObject->GraphAreaY1+($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1)/2;
  266. $Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
  267. $MinLeft = $Bounds[2]["X"];
  268. $this->pDataObject->Data["GraphArea"]["X1"] = $MinLeft;
  269. }
  270. $AxisPos["L"] = $MinLeft - $ScaleSpacing;
  271. }
  272. elseif ( $AxisSettings["Position"] == AXIS_POSITION_RIGHT )
  273. {
  274. if ( $Floating )
  275. { $FloatingOffset = $XMargin; $this->pChartObject->drawLine($AxisPos["R"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["R"],$this->pChartObject->GraphAreaY2-$AxisSettings["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  276. else
  277. { $FloatingOffset = 0; $this->pChartObject->drawLine($AxisPos["R"],$this->pChartObject->GraphAreaY1,$AxisPos["R"],$this->pChartObject->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  278. if ( $DrawArrows ) { $this->pChartObject->drawArrow($AxisPos["R"],$this->pChartObject->GraphAreaY1+$AxisSettings["Margin"],$AxisPos["R"],$this->pChartObject->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  279. $Height = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) - $AxisSettings["Margin"]*2;
  280. $Step = $Height / $AxisSettings["Rows"]; $SubTicksSize = $Step /2; $MaxLeft = $AxisPos["R"];
  281. $LastY = NULL;
  282. for($i=0;$i<=$AxisSettings["Rows"];$i++)
  283. {
  284. $YPos = $this->pChartObject->GraphAreaY2 - $AxisSettings["Margin"] - $Step*$i;
  285. $XPos = $AxisPos["R"];
  286. $Value = $this->pChartObject->scaleFormat($AxisSettings["ScaleMin"] + $AxisSettings["RowHeight"]*$i,$AxisSettings["Display"],$AxisSettings["Format"],$AxisSettings["Unit"]);
  287. 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); }
  288. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->pChartObject->drawFilledRectangle($this->pChartObject->GraphAreaX1+$FloatingOffset,$LastY,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  289. if ( ($YPos != $this->pChartObject->GraphAreaY1 && $YPos != $this->pChartObject->GraphAreaY2) && ($DrawYLines == ALL || in_array($AxisID,$DrawYLines)) ) { $this->pChartObject->drawLine($this->pChartObject->GraphAreaX1+$FloatingOffset,$YPos,$this->pChartObject->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  290. if ( $DrawSubTicks && $i != $AxisSettings["Rows"] )
  291. $this->pChartObject->drawLine($XPos-$InnerSubTickWidth,$YPos-$SubTicksSize,$XPos+$OuterSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  292. $this->pChartObject->drawLine($XPos-$InnerTickWidth,$YPos,$XPos+$OuterTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  293. $Bounds = $this->pChartObject->drawText($XPos+$OuterTickWidth+2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
  294. $TxtLeft = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
  295. $MaxLeft = max($MaxLeft,$TxtLeft);
  296. $LastY = $YPos;
  297. }
  298. if ( isset($AxisSettings["Name"]) )
  299. {
  300. $XPos = $MaxLeft+6;
  301. $YPos = $this->pChartObject->GraphAreaY1+($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1)/2;
  302. $Bounds = $this->pChartObject->drawText($XPos,$YPos,$AxisSettings["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
  303. $MaxLeft = $Bounds[2]["X"];
  304. $this->pDataObject->Data["GraphArea"]["X2"] = $MaxLeft + $this->pChartObject->FontSize;
  305. }
  306. $AxisPos["R"] = $MaxLeft + $ScaleSpacing;
  307. }
  308. }
  309. }
  310. $this->pDataObject->saveAxisConfig($Data["Axis"]);
  311. }
  312. /* Draw a scatter plot chart */
  313. function drawScatterPlotChart($Format=NULL)
  314. {
  315. $PlotSize = isset($Format["PlotSize"]) ? $Format["PlotSize"] : 3;
  316. $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : FALSE;
  317. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 250;
  318. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 250;
  319. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 250;
  320. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
  321. $BorderSize = isset($Format["BorderSize"]) ? $Format["BorderSize"] : 1;
  322. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  323. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  324. $ImageMapTitle = isset($Format["ImageMapTitle"]) ? $Format["ImageMapTitle"] : NULL;
  325. $ImageMapPrecision = isset($Format["ImageMapPrecision"]) ? $Format["ImageMapPrecision"] : 2;
  326. $Data = $this->pDataObject->getData();
  327. $Palette = $this->pDataObject->getPalette();
  328. $BorderColor = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha);
  329. foreach($Data["ScatterSeries"] as $Key => $Series)
  330. {
  331. if ( $Series["isDrawable"] == TRUE )
  332. {
  333. $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
  334. $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
  335. if ( $ImageMapTitle == NULL ) { $Description = $Data["Series"][$Series["X"]]["Description"]." / ".$Data["Series"][$Series["Y"]]["Description"]; } else { $Description = $ImageMapTitle; }
  336. if ( isset($Series["Picture"]) && $Series["Picture"] != "" )
  337. { $Picture = $Series["Picture"]; list($PicWidth,$PicHeight,$PicType) = $this->pChartObject->getPicInfo($Picture); }
  338. else
  339. { $Picture = NULL; }
  340. $PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
  341. if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
  342. $PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
  343. if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
  344. $Color = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
  345. foreach($PosArrayX as $Key => $Value)
  346. {
  347. $X = $Value; $Y = $PosArrayY[$Key];
  348. if ( $X != VOID && $Y != VOID )
  349. {
  350. $RealValue = round($Data["Series"][$Series["X"]]["Data"][$Key],2)." / ".round($Data["Series"][$Series["Y"]]["Data"][$Key],2);
  351. if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".floor($PlotSize+$BorderSize),$this->pChartObject->toHTMLColor($Series["Color"]["R"],$Series["Color"]["G"],$Series["Color"]["B"]),$Description,$RealValue); }
  352. if( isset($Series["Shape"]) )
  353. { $this->pChartObject->drawShape($X,$Y,$Series["Shape"],$PlotSize,$PlotBorder,$BorderSize,$Series["Color"]["R"],$Series["Color"]["G"],$Series["Color"]["B"],$Series["Color"]["Alpha"],$BorderR,$BorderG,$BorderB,$BorderAlpha); }
  354. elseif ( $Picture == NULL )
  355. {
  356. if ( $PlotBorder ) { $this->pChartObject->drawFilledCircle($X,$Y,$PlotSize+$BorderSize,$BorderColor); }
  357. $this->pChartObject->drawFilledCircle($X,$Y,$PlotSize,$Color);
  358. }
  359. else
  360. { $this->pChartObject->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
  361. }
  362. }
  363. }
  364. }
  365. }
  366. /* Draw a scatter line chart */
  367. function drawScatterLineChart($Format=NULL)
  368. {
  369. $Data = $this->pDataObject->getData();
  370. $Palette = $this->pDataObject->getPalette();
  371. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  372. $ImageMapTitle = isset($Format["ImageMapTitle"]) ? $Format["ImageMapTitle"] : NULL;
  373. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 10;
  374. $ImageMapPrecision = isset($Format["ImageMapPrecision"]) ? $Format["ImageMapPrecision"] : 2;
  375. /* Parse all the series to draw */
  376. foreach($Data["ScatterSeries"] as $Key => $Series)
  377. {
  378. if ( $Series["isDrawable"] == TRUE )
  379. {
  380. $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
  381. $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
  382. $Ticks = $Series["Ticks"];
  383. $Weight = $Series["Weight"];
  384. if ( $ImageMapTitle == NULL ) { $Description = $Data["Series"][$Series["X"]]["Description"]." / ".$Data["Series"][$Series["Y"]]["Description"]; } else { $Description = $ImageMapTitle; }
  385. $PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
  386. if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
  387. $PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
  388. if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
  389. $Color = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
  390. if ( $Ticks != 0 ) { $Color["Ticks"] = $Ticks; }
  391. if ( $Weight != 0 ) { $Color["Weight"] = $Weight; }
  392. $LastX = VOID; $LastY = VOID;
  393. foreach($PosArrayX as $Key => $Value)
  394. {
  395. $X = $Value; $Y = $PosArrayY[$Key];
  396. if ( $X != VOID && $Y != VOID )
  397. {
  398. $RealValue = round($Data["Series"][$Series["X"]]["Data"][$Key],2)." / ".round($Data["Series"][$Series["Y"]]["Data"][$Key],2);
  399. if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->pChartObject->toHTMLColor($Series["Color"]["R"],$Series["Color"]["G"],$Series["Color"]["B"]),$Description,$RealValue); }
  400. }
  401. if ( $X != VOID && $Y != VOID && $LastX != VOID && $LastY != VOID)
  402. $this->pChartObject->drawLine($LastX,$LastY,$X,$Y,$Color);
  403. $LastX = $X; $LastY = $Y;
  404. }
  405. }
  406. }
  407. }
  408. /* Draw a scatter spline chart */
  409. function drawScatterSplineChart($Format=NULL)
  410. {
  411. $Data = $this->pDataObject->getData();
  412. $Palette = $this->pDataObject->getPalette();
  413. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  414. $ImageMapTitle = isset($Format["ImageMapTitle"]) ? $Format["ImageMapTitle"] : NULL;
  415. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 10;
  416. $ImageMapPrecision = isset($Format["ImageMapPrecision"]) ? $Format["ImageMapPrecision"] : 2;
  417. foreach($Data["ScatterSeries"] as $Key => $Series)
  418. {
  419. if ( $Series["isDrawable"] == TRUE )
  420. {
  421. $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
  422. $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
  423. $Ticks = $Series["Ticks"];
  424. $Weight = $Series["Weight"];
  425. if ( $ImageMapTitle == NULL ) { $Description = $Data["Series"][$Series["X"]]["Description"]." / ".$Data["Series"][$Series["Y"]]["Description"]; } else { $Description = $ImageMapTitle; }
  426. $PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
  427. if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
  428. $PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
  429. if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
  430. $SplineSettings = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
  431. if ( $Ticks != 0 ) { $SplineSettings["Ticks"] = $Ticks; }
  432. if ( $Weight != 0 ) { $SplineSettings["Weight"] = $Weight; }
  433. $LastX = VOID; $LastY = VOID; $WayPoints = ""; $Forces = "";
  434. foreach($PosArrayX as $Key => $Value)
  435. {
  436. $X = $Value; $Y = $PosArrayY[$Key];
  437. $Force = $this->pChartObject->getLength($LastX,$LastY,$X,$Y)/5;
  438. if ( $X != VOID && $Y != VOID )
  439. {
  440. $RealValue = round($Data["Series"][$Series["X"]]["Data"][$Key],2)." / ".round($Data["Series"][$Series["Y"]]["Data"][$Key],2);
  441. if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->pChartObject->toHTMLColor($Series["Color"]["R"],$Series["Color"]["G"],$Series["Color"]["B"]),$Description,$RealValue); }
  442. }
  443. if ( $X != VOID && $Y != VOID )
  444. { $WayPoints[] = array($X,$Y); $Forces[] = $Force; }
  445. if ( $Y == VOID || $X == VOID )
  446. { $SplineSettings["Forces"] = $Forces; $this->pChartObject->drawSpline($WayPoints,$SplineSettings); $WayPoints = ""; $Forces = "";}
  447. $LastX = $X; $LastY = $Y;
  448. }
  449. $SplineSettings["Forces"] = $Forces;
  450. $this->pChartObject->drawSpline($WayPoints,$SplineSettings);
  451. }
  452. }
  453. }
  454. /* Return the scaled plot position */
  455. function getPosArray($Values,$AxisID)
  456. {
  457. $Data = $this->pDataObject->getData();
  458. if ( !is_array($Values) ) { $Values = array($Values); }
  459. if ( $Data["Axis"][$AxisID]["Identity"] == AXIS_X )
  460. {
  461. $Height = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) - $Data["Axis"][$AxisID]["Margin"]*2;
  462. $ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  463. $Step = $Height / $ScaleHeight;
  464. $Result = "";
  465. foreach($Values as $Key => $Value)
  466. {
  467. if ( $Value == VOID )
  468. $Result[] = VOID;
  469. else
  470. $Result[] = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"]));
  471. }
  472. if ( count($Result) == 1 ) { return($Result[0]); } else { return($Result); }
  473. }
  474. else
  475. {
  476. $Height = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) - $Data["Axis"][$AxisID]["Margin"]*2;
  477. $ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  478. $Step = $Height / $ScaleHeight;
  479. $Result = "";
  480. foreach($Values as $Key => $Value)
  481. {
  482. if ( $Value == VOID )
  483. $Result[] = VOID;
  484. else
  485. $Result[] = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"]));
  486. }
  487. if ( count($Result) == 1 ) { return($Result[0]); } else { return($Result); }
  488. }
  489. }
  490. /* Draw the legend of the active series */
  491. function drawScatterLegend($X,$Y,$Format="")
  492. {
  493. $Family = isset($Format["Family"]) ? $Format["Family"] : LEGEND_FAMILY_BOX;
  494. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
  495. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
  496. $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->pChartObject->FontColorR;
  497. $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->pChartObject->FontColorG;
  498. $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->pChartObject->FontColorB;
  499. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
  500. $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
  501. $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
  502. $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
  503. $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
  504. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  505. $R = isset($Format["R"]) ? $Format["R"] : 200;
  506. $G = isset($Format["G"]) ? $Format["G"] : 200;
  507. $B = isset($Format["B"]) ? $Format["B"] : 200;
  508. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  509. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
  510. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
  511. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
  512. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  513. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  514. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  515. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  516. $Data = $this->pDataObject->getData();
  517. foreach($Data["ScatterSeries"] as $Key => $Series)
  518. {
  519. if ( $Series["isDrawable"] == TRUE && isset($Series["Picture"]))
  520. {
  521. list($PicWidth,$PicHeight) = $this->pChartObject->getPicInfo($Series["Picture"]);
  522. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  523. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  524. }
  525. }
  526. $YStep = max($this->pChartObject->FontSize,$IconAreaHeight) + 5;
  527. $XStep = $IconAreaWidth + 5;
  528. $XStep = $XSpacing;
  529. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  530. foreach($Data["ScatterSeries"] as $Key => $Series)
  531. {
  532. if ( $Series["isDrawable"] == TRUE )
  533. {
  534. if ( $Mode == LEGEND_VERTICAL )
  535. {
  536. $BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Series["Description"]);
  537. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  538. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  539. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  540. $Lines = preg_split("/\n/",$Series["Description"]);
  541. $vY = $vY + max($this->pChartObject->FontSize*count($Lines),$IconAreaHeight) + 5;
  542. }
  543. elseif ( $Mode == LEGEND_HORIZONTAL )
  544. {
  545. $Lines = preg_split("/\n/",$Series["Description"]);
  546. $Width = "";
  547. foreach($Lines as $Key => $Value)
  548. {
  549. $BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  550. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  551. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  552. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  553. $Width[] = $BoxArray[1]["X"];
  554. }
  555. $vX=max($Width)+$XStep;
  556. }
  557. }
  558. }
  559. $vY=$vY-$YStep; $vX=$vX-$XStep;
  560. $TopOffset = $Y - $Boundaries["T"];
  561. if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
  562. if ( $Style == LEGEND_ROUND )
  563. $this->pChartObject->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));
  564. elseif ( $Style == LEGEND_BOX )
  565. $this->pChartObject->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));
  566. $RestoreShadow = $this->pChartObject->Shadow; $this->Shadow = FALSE;
  567. foreach($Data["ScatterSeries"] as $Key => $Series)
  568. {
  569. if ( $Series["isDrawable"] == TRUE )
  570. {
  571. $R = $Series["Color"]["R"]; $G = $Series["Color"]["G"]; $B = $Series["Color"]["B"];
  572. $Ticks = $Series["Ticks"]; $Weight = $Series["Weight"];
  573. if ( isset($Series["Picture"]) )
  574. {
  575. $Picture = $Series["Picture"];
  576. list($PicWidth,$PicHeight) = $this->pChartObject->getPicInfo($Picture);
  577. $PicX = $X+$IconAreaWidth/2; $PicY = $Y+$IconAreaHeight/2;
  578. $this->pChartObject->drawFromPNG($PicX-$PicWidth/2,$PicY-$PicHeight/2,$Picture);
  579. }
  580. else
  581. {
  582. if ( $Family == LEGEND_FAMILY_BOX )
  583. {
  584. if ( $BoxWidth != $IconAreaWidth ) { $XOffset = floor(($IconAreaWidth-$BoxWidth)/2); } else { $XOffset = 0; }
  585. if ( $BoxHeight != $IconAreaHeight ) { $YOffset = floor(($IconAreaHeight-$BoxHeight)/2); } else { $YOffset = 0; }
  586. $this->pChartObject->drawFilledRectangle($X+1+$XOffset,$Y+1+$YOffset,$X+$BoxWidth+$XOffset+1,$Y+$BoxHeight+1+$YOffset,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
  587. $this->pChartObject->drawFilledRectangle($X+$XOffset,$Y+$YOffset,$X+$BoxWidth+$XOffset,$Y+$BoxHeight+$YOffset,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
  588. }
  589. elseif ( $Family == LEGEND_FAMILY_CIRCLE )
  590. {
  591. $this->pChartObject->drawFilledCircle($X+1+$IconAreaWidth/2,$Y+1+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
  592. $this->pChartObject->drawFilledCircle($X+$IconAreaWidth/2,$Y+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
  593. }
  594. elseif ( $Family == LEGEND_FAMILY_LINE )
  595. {
  596. $this->pChartObject->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));
  597. $this->pChartObject->drawLine($X,$Y+$IconAreaHeight/2,$X+$IconAreaWidth,$Y+$IconAreaHeight/2,array("R"=>$R,"G"=>$G,"B"=>$B,"Ticks"=>$Ticks,"Weight"=>$Weight));
  598. }
  599. }
  600. if ( $Mode == LEGEND_VERTICAL )
  601. {
  602. $Lines = preg_split("/\n/",$Series["Description"]);
  603. foreach($Lines as $Key => $Value)
  604. $this->pChartObject->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
  605. $Y=$Y+max($this->pChartObject->FontSize*count($Lines),$IconAreaHeight) + 5;
  606. }
  607. elseif ( $Mode == LEGEND_HORIZONTAL )
  608. {
  609. $Lines = preg_split("/\n/",$Series["Description"]);
  610. $Width = "";
  611. foreach($Lines as $Key => $Value)
  612. {
  613. $BoxArray = $this->pChartObject->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
  614. $Width[] = $BoxArray[1]["X"];
  615. }
  616. $X=max($Width)+2+$XStep;
  617. }
  618. }
  619. }
  620. $this->Shadow = $RestoreShadow;
  621. }
  622. /* Get the legend box size */
  623. function getScatterLegendSize($Format="")
  624. {
  625. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
  626. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
  627. $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
  628. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  629. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  630. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  631. $YStep = max($this->pChartObject->FontSize,$BoxSize) + 5;
  632. $XStep = $BoxSize + 5;
  633. $X=100; $Y=100;
  634. $Data = $this->pDataObject->getData();
  635. foreach($Data["ScatterSeries"] as $Key => $Series)
  636. {
  637. if ( $Series["isDrawable"] == TRUE && isset($Series["Picture"]))
  638. {
  639. list($PicWidth,$PicHeight) = $this->pChartObject->getPicInfo($Series["Picture"]);
  640. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  641. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  642. }
  643. }
  644. $YStep = max($this->pChartObject->FontSize,$IconAreaHeight) + 5;
  645. $XStep = $IconAreaWidth + 5;
  646. $XStep = $XSpacing;
  647. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  648. foreach($Data["ScatterSeries"] as $Key => $Series)
  649. {
  650. if ( $Series["isDrawable"] == TRUE )
  651. {
  652. if ( $Mode == LEGEND_VERTICAL )
  653. {
  654. $BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Series["Description"]);
  655. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  656. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  657. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  658. $Lines = preg_split("/\n/",$Series["Description"]);
  659. $vY = $vY + max($this->pChartObject->FontSize*count($Lines),$IconAreaHeight) + 5;
  660. }
  661. elseif ( $Mode == LEGEND_HORIZONTAL )
  662. {
  663. $Lines = preg_split("/\n/",$Series["Description"]);
  664. $Width = "";
  665. foreach($Lines as $Key => $Value)
  666. {
  667. $BoxArray = $this->pChartObject->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->pChartObject->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  668. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  669. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  670. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  671. $Width[] = $BoxArray[1]["X"];
  672. }
  673. $vX=max($Width)+$XStep;
  674. }
  675. }
  676. }
  677. $vY=$vY-$YStep; $vX=$vX-$XStep;
  678. $TopOffset = $Y - $Boundaries["T"];
  679. if ( $Boundaries["B"]-($vY+$BoxSize) < $TopOffset ) { $Boundaries["B"] = $vY+$BoxSize+$TopOffset; }
  680. $Width = ($Boundaries["R"]+$Margin) - ($Boundaries["L"]-$Margin);
  681. $Height = ($Boundaries["B"]+$Margin) - ($Boundaries["T"]-$Margin);
  682. return(array("Width"=>$Width,"Height"=>$Height));
  683. }
  684. /* Draw the line of best fit */
  685. function drawScatterBestFit($Format="")
  686. {
  687. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 0;
  688. $Data = $this->pDataObject->getData();
  689. foreach($Data["ScatterSeries"] as $Key => $Series)
  690. {
  691. if ( $Series["isDrawable"] == TRUE )
  692. {
  693. $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
  694. $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
  695. $Color = array("R"=>$Series["Color"]["R"],"G"=>$Series["Color"]["G"],"B"=>$Series["Color"]["B"],"Alpha"=>$Series["Color"]["Alpha"]);
  696. $Color["Ticks"] = $Ticks;
  697. $PosArrayX = $Data["Series"][$Series["X"]]["Data"];
  698. $PosArrayY = $Data["Series"][$Series["Y"]]["Data"];
  699. $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
  700. foreach($PosArrayX as $Key => $Value)
  701. {
  702. $X = $Value; $Y = $PosArrayY[$Key];
  703. $Sxy = $Sxy + $X*$Y;
  704. $Sx = $Sx + $X;
  705. $Sy = $Sy + $Y;
  706. $Sxx = $Sxx + $X*$X;
  707. }
  708. $n = count($PosArrayX);
  709. if ((($n*$Sxx) == ($Sx*$Sx)))
  710. {
  711. $X1 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMin"],$SerieXAxis);
  712. $X2 = $X1;
  713. $Y1 = $this->pChartObject->GraphAreaY1;
  714. $Y2 = $this->pChartObject->GraphAreaY2;
  715. }
  716. else
  717. {
  718. $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
  719. $B = (($Sy)-($M*$Sx))/($n);
  720. $X1 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMin"],$SerieXAxis);
  721. $Y1 = $this->getPosArray($M * $Data["Axis"][$SerieXAxis]["ScaleMin"] + $B,$SerieYAxis);
  722. $X2 = $this->getPosArray($Data["Axis"][$SerieXAxis]["ScaleMax"],$SerieXAxis);
  723. $Y2 = $this->getPosArray($M * $Data["Axis"][$SerieXAxis]["ScaleMax"] + $B,$SerieYAxis);
  724. $RealM = -($Y2-$Y1)/($X2-$X1);
  725. if ( $Y1 < $this->pChartObject->GraphAreaY1 ) { $X1 = $X1 + ($this->pChartObject->GraphAreaY1-$Y1/$RealM); $Y1 = $this->pChartObject->GraphAreaY1; }
  726. if ( $Y1 > $this->pChartObject->GraphAreaY2 ) { $X1 = $X1 + ($Y1-$this->pChartObject->GraphAreaY2)/$RealM; $Y1 = $this->pChartObject->GraphAreaY2; }
  727. if ( $Y2 < $this->pChartObject->GraphAreaY1 ) { $X2 = $X2 - ($this->pChartObject->GraphAreaY1-$Y2)/$RealM; $Y2 = $this->pChartObject->GraphAreaY1; }
  728. if ( $Y2 > $this->pChartObject->GraphAreaY2 ) { $X2 = $X2 - ($Y2-$this->pChartObject->GraphAreaY2)/$RealM; $Y2 = $this->pChartObject->GraphAreaY2; }
  729. }
  730. $this->pChartObject->drawLine($X1,$Y1,$X2,$Y2,$Color);
  731. }
  732. }
  733. }
  734. function writeScatterLabel($ScatterSerieID,$Points,$Format="")
  735. {
  736. $OverrideTitle = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
  737. $DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
  738. $Decimals = isset($Format["Decimals"]) ? $Format["Decimals"] : NULL;
  739. $Data = $this->pDataObject->getData();
  740. $Palette = $this->pDataObject->getPalette();
  741. if ( !is_array($Points) ) { $Point = $Points; $Points = ""; $Points[0] = $Point; }
  742. if ( !isset($Data["ScatterSeries"][$ScatterSerieID]) )
  743. return(0);
  744. $Series = $Data["ScatterSeries"][$ScatterSerieID];
  745. $SerieX = $Series["X"]; $SerieValuesX = $Data["Series"][$SerieX]["Data"]; $SerieXAxis = $Data["Series"][$SerieX]["Axis"];
  746. $SerieY = $Series["Y"]; $SerieValuesY = $Data["Series"][$SerieY]["Data"]; $SerieYAxis = $Data["Series"][$SerieY]["Axis"];
  747. $PosArrayX = $this->getPosArray($SerieValuesX,$SerieXAxis);
  748. if ( !is_array($PosArrayX) ) { $Value = $PosArrayX; $PosArrayX = ""; $PosArrayX[0] = $Value; }
  749. $PosArrayY = $this->getPosArray($SerieValuesY,$SerieYAxis);
  750. if ( !is_array($PosArrayY) ) { $Value = $PosArrayY; $PosArrayY = ""; $PosArrayY[0] = $Value; }
  751. foreach($Points as $Key => $Point)
  752. {
  753. if ( isset($PosArrayX[$Point]) && isset($PosArrayY[$Point]) )
  754. {
  755. $X = floor($PosArrayX[$Point]);
  756. $Y = floor($PosArrayY[$Point]);
  757. if ( $DrawPoint == LABEL_POINT_CIRCLE )
  758. $this->pChartObject->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  759. elseif ( $DrawPoint == LABEL_POINT_BOX )
  760. $this->pChartObject->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  761. $Serie = "";
  762. $Serie["R"] = $Series["Color"]["R"];
  763. $Serie["G"] = $Series["Color"]["G"];
  764. $Serie["B"] = $Series["Color"]["B"];
  765. $Serie["Alpha"] = $Series["Color"]["Alpha"];
  766. $XAxisMode = $Data["Axis"][$SerieXAxis]["Display"];
  767. $XAxisFormat = $Data["Axis"][$SerieXAxis]["Format"];
  768. $XAxisUnit = $Data["Axis"][$SerieXAxis]["Unit"];
  769. if ( $Decimals == NULL ) { $XValue = $SerieValuesX[$Point]; } else { $XValue = round($SerieValuesX[$Point],$Decimals); }
  770. $XValue = $this->pChartObject->scaleFormat($XValue,$XAxisMode,$XAxisFormat,$XAxisUnit);
  771. $YAxisMode = $Data["Axis"][$SerieYAxis]["Display"];
  772. $YAxisFormat = $Data["Axis"][$SerieYAxis]["Format"];
  773. $YAxisUnit = $Data["Axis"][$SerieYAxis]["Unit"];
  774. if ( $Decimals == NULL ) { $YValue = $SerieValuesY[$Point]; } else { $YValue = round($SerieValuesY[$Point],$Decimals); }
  775. $YValue = $this->pChartObject->scaleFormat($YValue,$YAxisMode,$YAxisFormat,$YAxisUnit);
  776. $Caption = $XValue." / ".$YValue;
  777. if ( isset($Series["Description"]) )
  778. $Description = $Series["Description"];
  779. else
  780. $Description = "No description";
  781. $Series = "";
  782. $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
  783. $this->pChartObject->drawLabelBox($X,$Y-3,$Description,$Series,$Format);
  784. }
  785. }
  786. }
  787. /* Draw a Scatter threshold */
  788. function drawScatterThreshold($Value,$Format="")
  789. {
  790. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  791. $R = isset($Format["R"]) ? $Format["R"] : 255;
  792. $G = isset($Format["G"]) ? $Format["G"] : 0;
  793. $B = isset($Format["B"]) ? $Format["B"] : 0;
  794. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
  795. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  796. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 3;
  797. $Wide = isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
  798. $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
  799. $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
  800. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : NULL;
  801. $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
  802. $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
  803. $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
  804. $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
  805. $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
  806. $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
  807. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  808. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  809. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
  810. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  811. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  812. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  813. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  814. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  815. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
  816. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  817. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  818. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  819. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  820. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  821. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  822. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  823. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
  824. "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);
  825. if ( $Caption == NULL ) { $Caption = $Value; }
  826. $Data = $this->pDataObject->getData();
  827. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  828. if ( $Data["Axis"][$AxisID]["Identity"] == AXIS_Y )
  829. {
  830. $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"];
  831. $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"];
  832. $Y = $this->getPosArray($Value,$AxisID);
  833. $this->pChartObject->drawLine($X1,$Y,$X2,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  834. if ( $Wide )
  835. {
  836. $this->pChartObject->drawLine($X1,$Y-1,$X2,$Y-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  837. $this->pChartObject->drawLine($X1,$Y+1,$X2,$Y+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  838. }
  839. if ( $WriteCaption )
  840. {
  841. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  842. { $X = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
  843. else
  844. { $X = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"] - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
  845. $this->pChartObject->drawText($X,$Y,$Caption,$CaptionSettings);
  846. }
  847. return(array("Y"=>$Y));
  848. }
  849. elseif ( $Data["Axis"][$AxisID]["Identity"] == AXIS_X )
  850. {
  851. $X = $this->getPosArray($Value,$AxisID);
  852. $Y1 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"];
  853. $Y2 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"];
  854. $this->pChartObject->drawLine($X,$Y1,$X,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  855. if ( $Wide )
  856. {
  857. $this->pChartObject->drawLine($X-1,$Y1,$X-1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  858. $this->pChartObject->drawLine($X+1,$Y1,$X+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  859. }
  860. if ( $WriteCaption )
  861. {
  862. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  863. { $Y = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"] + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
  864. else
  865. { $Y = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
  866. $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
  867. $this->pChartObject->drawText($X,$Y,$Caption,$CaptionSettings);
  868. }
  869. return(array("X"=>$X));
  870. }
  871. }
  872. /* Draw a Scatter threshold area */
  873. function drawScatterThresholdArea($Value1,$Value2,$Format="")
  874. {
  875. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  876. $R = isset($Format["R"]) ? $Format["R"] : 255;
  877. $G = isset($Format["G"]) ? $Format["G"] : 0;
  878. $B = isset($Format["B"]) ? $Format["B"] : 0;
  879. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
  880. $Border = isset($Format["Border"]) ? $Format["Border"] : TRUE;
  881. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  882. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  883. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  884. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
  885. $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
  886. $AreaName = isset($Format["AreaName"]) ? $Format["AreaName"] : "La ouate de phoque"; //NULL;
  887. $NameAngle = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
  888. $NameR = isset($Format["NameR"]) ? $Format["NameR"] : 255;
  889. $NameG = isset($Format["NameG"]) ? $Format["NameG"] : 255;
  890. $NameB = isset($Format["NameB"]) ? $Format["NameB"] : 255;
  891. $NameAlpha = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
  892. $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : TRUE;
  893. if ($Value1 > $Value2) { list($Value1, $Value2) = array($Value2, $Value1); }
  894. $RestoreShadow = $this->pChartObject->Shadow;
  895. if ( $DisableShadowOnArea && $this->pChartObject->Shadow ) { $this->pChartObject->Shadow = FALSE; }
  896. if ($BorderAlpha >100) { $BorderAlpha = 100;}
  897. $Data = $this->pDataObject->getData();
  898. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  899. if ( $Data["Axis"][$AxisID]["Identity"] == AXIS_X )
  900. {
  901. $Y1 = $this->pChartObject->GraphAreaY1 + $Data["Axis"][$AxisID]["Margin"];
  902. $Y2 = $this->pChartObject->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"];
  903. $X1 = $this->getPosArray($Value1,$AxisID);
  904. $X2 = $this->getPosArray($Value2,$AxisID);
  905. if ( $X1 <= $this->pChartObject->GraphAreaX1 ) { $X1 = $this->pChartObject->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"]; }
  906. if ( $X2 >= $this->pChartObject->GraphAreaX2 ) { $X2 = $this->pChartObject->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"]; }
  907. $this->pChartObject->drawFilledRectangle($X1,$Y1,$X2,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  908. if ( $Border )
  909. {
  910. $this->pChartObject->drawLine($X1,$Y1,$X1,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  911. $this->pChartObject->drawLine($X2,$Y1,$X2,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  912. }
  913. if ( $AreaName != NULL )
  914. {
  915. $XPos = ($X2-$X1)/2 + $X1;
  916. $YPos = ($Y2-$Y1)/2 + $Y1;
  917. if ( $NameAngle == ZONE_NAME_ANGLE_AUTO )
  918. {
  919. $TxtPos = $this->pChartObject->getTextBox($XPos,$YPos,$this->pChartObject->FontName,$this->pChartObject->FontSize,0,$AreaName);
  920. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
  921. if ( abs($X2 - $X1) > $TxtWidth ) { $NameAngle = 0; } else { $NameAngle = 90; }
  922. }
  923. $this->pChartObject->Shadow = $RestoreShadow;
  924. $this->pChartObject->drawText($XPos,$YPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>$NameAngle,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  925. if ( $DisableShadowOnArea ) { $this->pChartObject->Shadow = FALSE; }
  926. }
  927. $this->pChartObject->Shadow = $RestoreShadow;
  928. return(array("X1"=>$X1,"X2"=>$X2));
  929. }
  930. elseif ( $Data["Axis"][$AxisID]["Identity"] == AXIS_Y )
  931. {
  932. $X1 = $this->pChartObject->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"];
  933. $X2 = $this->pChartObject->GraphAreaX2 - $Data["Axis"][$AxisID]["Margin"];
  934. $Y1 = $this->getPosArray($Value1,$AxisID);
  935. $Y2 = $this->getPosArray($Value2,$AxisID);
  936. if ( $Y1 >= $this->pChartObject->GraphAreaY2 ) { $Y1 = $this->pChartObject->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"]; }
  937. if ( $Y2 <= $this->pChartObject->GraphAreaY1 ) { $Y2 = $this->pChartObject->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"]; }
  938. $this->pChartObject->drawFilledRectangle($X1,$Y1,$X2,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  939. if ( $Border )
  940. {
  941. $this->pChartObject->drawLine($X1,$Y1,$X2,$Y1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  942. $this->pChartObject->drawLine($X1,$Y2,$X2,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  943. }
  944. if ( $AreaName != NULL )
  945. {
  946. $XPos = ($X2-$X1)/2 + $X1;
  947. $YPos = ($Y2-$Y1)/2 + $Y1;
  948. $this->pChartObject->Shadow = $RestoreShadow;
  949. $this->pChartObject->drawText($YPos,$XPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  950. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  951. }
  952. $this->pChartObject->Shadow = $RestoreShadow;
  953. return(array("Y1"=>$Y1,"Y2"=>$Y2));
  954. }
  955. }
  956. }
  957. ?>