pChart.class.php 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489
  1. <?php
  2. /*
  3. pChart - a PHP class to build charts!
  4. Copyright (C) 2008 Jean-Damien POGOLOTTI
  5. Version 1.27d last updated on 09/30/08
  6. http://pchart.sourceforge.net
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 1,2,3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. Class initialisation :
  18. pChart($XSize,$YSize)
  19. Draw methods :
  20. drawBackground($R,$G,$B)
  21. drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B)
  22. drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B,$DrawBorder=TRUE,$Alpha=100)
  23. drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
  24. drawFilledRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
  25. drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
  26. drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
  27. drawEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
  28. drawFilledEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
  29. drawLine($X1,$Y1,$X2,$Y2,$R,$G,$B,$GraphFunction=FALSE)
  30. drawDottedLine($X1,$Y1,$X2,$Y2,$DotSize,$R,$G,$B)
  31. drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
  32. drawFromPNG($FileName,$X,$Y,$Alpha=100)
  33. drawFromGIF($FileName,$X,$Y,$Alpha=100)
  34. drawFromJPG($FileName,$X,$Y,$Alpha=100)
  35. Graph setup methods :
  36. addBorder($Width=3,$R=0,$G=0,$B=0)
  37. clearScale()
  38. clearShadow()
  39. createColorGradientPalette($R1,$G1,$B1,$R2,$G2,$B2,$Shades)
  40. drawGraphArea($R,$G,$B,$Stripe=FALSE)
  41. drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE)
  42. drawRightScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1)
  43. drawXYScale($Data,$DataDescription,$YSerieName,$XSerieName,$R,$G,$B,$WithMargin=0,$Angle=0,$Decimals=1)
  44. drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=100)
  45. drawLegend($XPos,$YPos,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-1,$Rt=0,$Gt=0,$Bt=0,$Border=FALSE)
  46. drawPieLegend($XPos,$YPos,$Data,$DataDescription,$R,$G,$B)
  47. drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE)
  48. drawTreshold($Value,$R,$G,$B,$ShowLabel=FALSE,$ShowOnRight=FALSE,$TickWidth=4,$FreeText=NULL)
  49. drawArea($Data,$Serie1,$Serie2,$R,$G,$B,$Alpha = 50)
  50. drawRadarAxis($Data,$DataDescription,$Mosaic=TRUE,$BorderOffset=10,$A_R=60,$A_G=60,$A_B=60,$S_R=200,$S_G=200,$S_B=200,$MaxValue=-1)
  51. drawGraphAreaGradient($R,$G,$B,$Decay,$Target=TARGET_GRAPHAREA)
  52. drawTextBox($X1,$Y1,$X2,$Y2,$Text,$Angle=0,$R=255,$G=255,$B=255,$Align=ALIGN_LEFT,$Shadow=TRUE,$BgR=-1,$BgG=-1,$BgB=-1,$Alpha=100)
  53. getLegendBoxSize($DataDescription)
  54. loadColorPalette($FileName,$Delimiter=",")
  55. reportWarnings($Interface="CLI")
  56. setGraphArea($X1,$Y1,$X2,$Y2)
  57. setLabel($Data,$DataDescription,$SerieName,$ValueName,$Caption,$R=210,$G=210,$B=210)
  58. setColorPalette($ID,$R,$G,$B)
  59. setCurrency($Currency)
  60. setDateFormat($Format)
  61. setFontProperties($FontName,$FontSize)
  62. setLineStyle($Width=1,$DotSize=0)
  63. setFixedScale($VMin,$VMax,$Divisions=5,$VXMin=0,$VXMin=0,$XDivisions=5)
  64. setShadowProperties($XDistance=1,$YDistance=1,$R=60,$G=60,$B=60,$Alpha)
  65. writeValues($Data,$DataDescription,$Series)
  66. Graphs methods :
  67. drawPlotGraph($Data,$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=FALSE)
  68. drawXYPlotGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1)
  69. drawLineGraph($Data,$DataDescription,$SerieName="")
  70. drawXYGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0)
  71. drawFilledLineGraph($Data,$DataDescription,$Alpha=100,$AroundZero=FALSE)
  72. drawCubicCurve($Data,$DataDescription,$Accuracy=.1,$SerieName="")
  73. drawFilledCubicCurve($Data,$DataDescription,$Accuracy=.1,$Alpha=100,$AroundZero=FALSE)
  74. drawOverlayBarGraph($Data,$DataDescription,$Alpha=50)
  75. drawBarGraph($Data,$DataDescription,$Shadow=FALSE)
  76. drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE)
  77. drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0)
  78. drawRadar($Data,$DataDescription,$BorderOffset=10,$MaxValue=-1)
  79. drawFilledRadar($Data,$DataDescription,$Alpha=50,$BorderOffset=10,$MaxValue=-1)
  80. drawBasicPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$R=255,$G=255,$B=255,$Decimals=0)
  81. drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals = 0)
  82. drawFlatPieGraphWithShadow($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals = 0)
  83. drawPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$EnhanceColors=TRUE,$Skew=60,$SpliceHeight=20,$SpliceDistance=0,$Decimals=0)
  84. Other methods :
  85. setImageMap($Mode=TRUE,$GraphID="MyGraph")
  86. getImageMap($MapName,$Flush=TRUE)
  87. Render($FileName)
  88. Stroke()
  89. */
  90. /* Declare some script wide constants */
  91. define("SCALE_NORMAL",1);
  92. define("SCALE_ADDALL",2);
  93. define("SCALE_START0",3);
  94. define("SCALE_ADDALLSTART0",4);
  95. define("PIE_PERCENTAGE", 1);
  96. define("PIE_LABELS",2);
  97. define("PIE_NOLABEL",3);
  98. define("PIE_PERCENTAGE_LABEL", 4);
  99. define("TARGET_GRAPHAREA",1);
  100. define("TARGET_BACKGROUND",2);
  101. define("ALIGN_TOP_LEFT",1);
  102. define("ALIGN_TOP_CENTER",2);
  103. define("ALIGN_TOP_RIGHT",3);
  104. define("ALIGN_LEFT",4);
  105. define("ALIGN_CENTER",5);
  106. define("ALIGN_RIGHT",6);
  107. define("ALIGN_BOTTOM_LEFT",7);
  108. define("ALIGN_BOTTOM_CENTER",8);
  109. define("ALIGN_BOTTOM_RIGHT",9);
  110. /* pChart class definition */
  111. class pChart
  112. {
  113. /* Palettes definition */
  114. var $Palette = array("0"=>array("R"=>188,"G"=>224,"B"=>46),
  115. "1"=>array("R"=>224,"G"=>100,"B"=>46),
  116. "2"=>array("R"=>224,"G"=>214,"B"=>46),
  117. "3"=>array("R"=>46,"G"=>151,"B"=>224),
  118. "4"=>array("R"=>176,"G"=>46,"B"=>224),
  119. "5"=>array("R"=>224,"G"=>46,"B"=>117),
  120. "6"=>array("R"=>92,"G"=>224,"B"=>46),
  121. "7"=>array("R"=>224,"G"=>176,"B"=>46));
  122. /* Some static vars used in the class */
  123. var $XSize = NULL;
  124. var $YSize = NULL;
  125. var $Picture = NULL;
  126. var $ImageMap = NULL;
  127. /* Error management */
  128. var $ErrorReporting = FALSE;
  129. var $ErrorInterface = "CLI";
  130. var $Errors = NULL;
  131. var $ErrorFontName = "Fonts/pf_arma_five.ttf";
  132. var $ErrorFontSize = 6;
  133. /* vars related to the graphing area */
  134. var $GArea_X1 = NULL;
  135. var $GArea_Y1 = NULL;
  136. var $GArea_X2 = NULL;
  137. var $GArea_Y2 = NULL;
  138. var $GAreaXOffset = NULL;
  139. var $VMax = NULL;
  140. var $VMin = NULL;
  141. var $VXMax = NULL;
  142. var $VXMin = NULL;
  143. var $Divisions = NULL;
  144. var $XDivisions = NULL;
  145. var $DivisionHeight = NULL;
  146. var $XDivisionHeight = NULL;
  147. var $DivisionCount = NULL;
  148. var $XDivisionCount = NULL;
  149. var $DivisionRatio = NULL;
  150. var $XDivisionRatio = NULL;
  151. var $DivisionWidth = NULL;
  152. var $DataCount = NULL;
  153. var $Currency = "\$";
  154. /* Text format related vars */
  155. var $FontName = NULL;
  156. var $FontSize = NULL;
  157. var $DateFormat = "d/m/Y";
  158. /* Lines format related vars */
  159. var $LineWidth = 1;
  160. var $LineDotSize = 0;
  161. /* Layer related vars */
  162. var $Layers = NULL;
  163. /* Set antialias quality : 0 is maximum, 100 minimum*/
  164. var $AntialiasQuality = 0;
  165. /* Shadow settings */
  166. var $ShadowActive = FALSE;
  167. var $ShadowXDistance = 1;
  168. var $ShadowYDistance = 1;
  169. var $ShadowRColor = 60;
  170. var $ShadowGColor = 60;
  171. var $ShadowBColor = 60;
  172. var $ShadowAlpha = 50;
  173. var $ShadowBlur = 0;
  174. /* Image Map settings */
  175. var $BuildMap = FALSE;
  176. var $MapFunction = NULL;
  177. var $tmpFolder = "tmp/";
  178. var $MapID = NULL;
  179. /* This function create the background picture */
  180. function pChart($XSize,$YSize)
  181. {
  182. $this->XSize = $XSize;
  183. $this->YSize = $YSize;
  184. $this->Picture = imagecreatetruecolor($XSize,$YSize);
  185. $C_White =$this->AllocateColor($this->Picture,255,255,255);
  186. imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C_White);
  187. imagecolortransparent($this->Picture,$C_White);
  188. $this->setFontProperties("tahoma.ttf",8);
  189. }
  190. /* Set if warnings should be reported */
  191. function reportWarnings($Interface="CLI")
  192. {
  193. $this->ErrorReporting = TRUE;
  194. $this->ErrorInterface = $Interface;
  195. }
  196. /* Set the font properties */
  197. function setFontProperties($FontName,$FontSize)
  198. {
  199. $this->FontName = $FontName;
  200. $this->FontSize = $FontSize;
  201. }
  202. /* Set the shadow properties */
  203. function setShadowProperties($XDistance=1,$YDistance=1,$R=60,$G=60,$B=60,$Alpha=50,$Blur=0)
  204. {
  205. $this->ShadowActive = TRUE;
  206. $this->ShadowXDistance = $XDistance;
  207. $this->ShadowYDistance = $YDistance;
  208. $this->ShadowRColor = $R;
  209. $this->ShadowGColor = $G;
  210. $this->ShadowBColor = $B;
  211. $this->ShadowAlpha = $Alpha;
  212. $this->ShadowBlur = $Blur;
  213. }
  214. /* Remove shadow option */
  215. function clearShadow()
  216. {
  217. $this->ShadowActive = FALSE;
  218. }
  219. /* Set Palette color */
  220. function setColorPalette($ID,$R,$G,$B)
  221. {
  222. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  223. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  224. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  225. $this->Palette[$ID]["R"] = $R;
  226. $this->Palette[$ID]["G"] = $G;
  227. $this->Palette[$ID]["B"] = $B;
  228. }
  229. /* Create a color palette shading from one color to another */
  230. function createColorGradientPalette($R1,$G1,$B1,$R2,$G2,$B2,$Shades)
  231. {
  232. $RFactor = ($R2-$R1)/$Shades;
  233. $GFactor = ($G2-$G1)/$Shades;
  234. $BFactor = ($B2-$B1)/$Shades;
  235. for($i=0;$i<=$Shades-1;$i++)
  236. {
  237. $this->Palette[$i]["R"] = $R1+$RFactor*$i;
  238. $this->Palette[$i]["G"] = $G1+$GFactor*$i;
  239. $this->Palette[$i]["B"] = $B1+$BFactor*$i;
  240. }
  241. }
  242. /* Load Color Palette from file */
  243. function loadColorPalette($FileName,$Delimiter=",")
  244. {
  245. $handle = @fopen($FileName,"r");
  246. $ColorID = 0;
  247. if ($handle)
  248. {
  249. while (!feof($handle))
  250. {
  251. $buffer = fgets($handle, 4096);
  252. $buffer = str_replace(chr(10),"",$buffer);
  253. $buffer = str_replace(chr(13),"",$buffer);
  254. $Values = split($Delimiter,$buffer);
  255. if ( count($Values) == 3 )
  256. {
  257. $this->Palette[$ColorID]["R"] = $Values[0];
  258. $this->Palette[$ColorID]["G"] = $Values[1];
  259. $this->Palette[$ColorID]["B"] = $Values[2];
  260. $ColorID++;
  261. }
  262. }
  263. }
  264. }
  265. /* Set line style */
  266. function setLineStyle($Width=1,$DotSize=0)
  267. {
  268. $this->LineWidth = $Width;
  269. $this->LineDotSize = $DotSize;
  270. }
  271. /* Set currency symbol */
  272. function setCurrency($Currency)
  273. {
  274. $this->Currency = $Currency;
  275. }
  276. /* Set the graph area location */
  277. function setGraphArea($X1,$Y1,$X2,$Y2)
  278. {
  279. $this->GArea_X1 = $X1;
  280. $this->GArea_Y1 = $Y1;
  281. $this->GArea_X2 = $X2;
  282. $this->GArea_Y2 = $Y2;
  283. }
  284. /* Prepare the graph area */
  285. function drawGraphArea($R,$G,$B,$Stripe=FALSE)
  286. {
  287. $this->drawFilledRectangle($this->GArea_X1,$this->GArea_Y1,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B,FALSE);
  288. $this->drawRectangle($this->GArea_X1,$this->GArea_Y1,$this->GArea_X2,$this->GArea_Y2,$R-40,$G-40,$B-40);
  289. if ( $Stripe )
  290. {
  291. $R2 = $R-15; if ( $R2 < 0 ) { $R2 = 0; }
  292. $G2 = $R-15; if ( $G2 < 0 ) { $G2 = 0; }
  293. $B2 = $R-15; if ( $B2 < 0 ) { $B2 = 0; }
  294. $LineColor =$this->AllocateColor($this->Picture,$R2,$G2,$B2);
  295. $SkewWidth = $this->GArea_Y2-$this->GArea_Y1-1;
  296. for($i=$this->GArea_X1-$SkewWidth;$i<=$this->GArea_X2;$i=$i+4)
  297. {
  298. $X1 = $i; $Y1 = $this->GArea_Y2;
  299. $X2 = $i+$SkewWidth; $Y2 = $this->GArea_Y1;
  300. if ( $X1 < $this->GArea_X1 )
  301. { $X1 = $this->GArea_X1; $Y1 = $this->GArea_Y1 + $X2 - $this->GArea_X1 + 1; }
  302. if ( $X2 >= $this->GArea_X2 )
  303. { $Y2 = $this->GArea_Y1 + $X2 - $this->GArea_X2 +1; $X2 = $this->GArea_X2 - 1; }
  304. // * Fixed in 1.27 * { $X2 = $this->GArea_X2 - 1; $Y2 = $this->GArea_Y2 - ($this->GArea_X2 - $X1); }
  305. imageline($this->Picture,$X1,$Y1,$X2,$Y2+1,$LineColor);
  306. }
  307. }
  308. }
  309. /* Allow you to clear the scale : used if drawing multiple charts */
  310. function clearScale()
  311. {
  312. $this->VMin = NULL;
  313. $this->VMax = NULL;
  314. $this->VXMin = NULL;
  315. $this->VXMax = NULL;
  316. $this->Divisions = NULL;
  317. $this->XDivisions = NULL; }
  318. /* Allow you to fix the scale, use this to bypass the automatic scaling */
  319. function setFixedScale($VMin,$VMax,$Divisions=5,$VXMin=0,$VXMax=0,$XDivisions=5)
  320. {
  321. $this->VMin = $VMin;
  322. $this->VMax = $VMax;
  323. $this->Divisions = $Divisions;
  324. if ( !$VXMin == 0 )
  325. {
  326. $this->VXMin = $VXMin;
  327. $this->VXMax = $VXMax;
  328. $this->XDivisions = $XDivisions;
  329. }
  330. }
  331. /* Wrapper to the drawScale() function allowing a second scale to be drawn */
  332. function drawRightScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1)
  333. {
  334. $this->drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks,$Angle,$Decimals,$WithMargin,$SkipLabels,TRUE);
  335. }
  336. /* Compute and draw the scale */
  337. function drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE)
  338. {
  339. /* Validate the Data and DataDescription array */
  340. $this->validateData("drawScale",$Data);
  341. $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
  342. $this->drawLine($this->GArea_X1,$this->GArea_Y1,$this->GArea_X1,$this->GArea_Y2,$R,$G,$B);
  343. $this->drawLine($this->GArea_X1,$this->GArea_Y2,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B);
  344. if ( $this->VMin == NULL && $this->VMax == NULL)
  345. {
  346. if (isset($DataDescription["Values"][0]))
  347. {
  348. $this->VMin = $Data[0][$DataDescription["Values"][0]];
  349. $this->VMax = $Data[0][$DataDescription["Values"][0]];
  350. }
  351. else { $this->VMin = 2147483647; $this->VMax = -2147483647; }
  352. /* Compute Min and Max values */
  353. if ( $ScaleMode == SCALE_NORMAL || $ScaleMode == SCALE_START0 )
  354. {
  355. if ( $ScaleMode == SCALE_START0 ) { $this->VMin = 0; }
  356. foreach ( $Data as $Key => $Values )
  357. {
  358. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  359. {
  360. if (isset($Data[$Key][$ColName]))
  361. {
  362. $Value = $Data[$Key][$ColName];
  363. if ( is_numeric($Value) )
  364. {
  365. if ( $this->VMax < $Value) { $this->VMax = $Value; }
  366. if ( $this->VMin > $Value) { $this->VMin = $Value; }
  367. }
  368. }
  369. }
  370. }
  371. }
  372. elseif ( $ScaleMode == SCALE_ADDALL || $ScaleMode == SCALE_ADDALLSTART0 ) /* Experimental */
  373. {
  374. if ( $ScaleMode == SCALE_ADDALLSTART0 ) { $this->VMin = 0; }
  375. foreach ( $Data as $Key => $Values )
  376. {
  377. $Sum = 0;
  378. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  379. {
  380. if (isset($Data[$Key][$ColName]))
  381. {
  382. $Value = $Data[$Key][$ColName];
  383. if ( is_numeric($Value) )
  384. $Sum += $Value;
  385. }
  386. }
  387. if ( $this->VMax < $Sum) { $this->VMax = $Sum; }
  388. if ( $this->VMin > $Sum) { $this->VMin = $Sum; }
  389. }
  390. }
  391. if ( $this->VMax > preg_replace('/\.[0-9]+/','',$this->VMax) )
  392. $this->VMax = preg_replace('/\.[0-9]+/','',$this->VMax)+1;
  393. /* If all values are the same */
  394. if ( $this->VMax == $this->VMin )
  395. {
  396. if ( $this->VMax >= 0 ) { $this->VMax++; }
  397. else { $this->VMin--; }
  398. }
  399. $DataRange = $this->VMax - $this->VMin;
  400. if ( $DataRange == 0 ) { $DataRange = .1; }
  401. /* Compute automatic scaling */
  402. $ScaleOk = FALSE; $Factor = 1;
  403. $MinDivHeight = 25; $MaxDivs = ($this->GArea_Y2 - $this->GArea_Y1) / $MinDivHeight;
  404. if ( $this->VMin == 0 && $this->VMax == 0 )
  405. { $this->VMin = 0; $this->VMax = 2; $Scale = 1; $Divisions = 2;}
  406. elseif ($MaxDivs > 1)
  407. {
  408. while(!$ScaleOk)
  409. {
  410. $Scale1 = ( $this->VMax - $this->VMin ) / $Factor;
  411. $Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2;
  412. $Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4;
  413. if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}
  414. if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
  415. if (!$ScaleOk)
  416. {
  417. if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
  418. if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
  419. }
  420. }
  421. if ( floor($this->VMax / $Scale / $Factor) != $this->VMax / $Scale / $Factor)
  422. {
  423. $GridID = floor ( $this->VMax / $Scale / $Factor) + 1;
  424. $this->VMax = $GridID * $Scale * $Factor;
  425. $Divisions++;
  426. }
  427. if ( floor($this->VMin / $Scale / $Factor) != $this->VMin / $Scale / $Factor)
  428. {
  429. $GridID = floor( $this->VMin / $Scale / $Factor);
  430. $this->VMin = $GridID * $Scale * $Factor;
  431. $Divisions++;
  432. }
  433. }
  434. else /* Can occurs for small graphs */
  435. $Scale = 1;
  436. if ( !isset($Divisions) )
  437. $Divisions = 2;
  438. if ($Scale == 1 && $Divisions%2 == 1)
  439. $Divisions--;
  440. }
  441. else
  442. $Divisions = $this->Divisions;
  443. $this->DivisionCount = $Divisions;
  444. $DataRange = $this->VMax - $this->VMin;
  445. if ( $DataRange == 0 ) { $DataRange = .1; }
  446. $this->DivisionHeight = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $Divisions;
  447. $this->DivisionRatio = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $DataRange;
  448. $this->GAreaXOffset = 0;
  449. if ( count($Data) > 1 )
  450. {
  451. if ( $WithMargin == FALSE )
  452. $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / (count($Data)-1);
  453. else
  454. {
  455. $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / (count($Data));
  456. $this->GAreaXOffset = $this->DivisionWidth / 2;
  457. }
  458. }
  459. else
  460. {
  461. $this->DivisionWidth = $this->GArea_X2 - $this->GArea_X1;
  462. $this->GAreaXOffset = $this->DivisionWidth / 2;
  463. }
  464. $this->DataCount = count($Data);
  465. if ( $DrawTicks == FALSE )
  466. return(0);
  467. $YPos = $this->GArea_Y2; $XMin = NULL;
  468. for($i=1;$i<=$Divisions+1;$i++)
  469. {
  470. if ( $RightScale )
  471. $this->drawLine($this->GArea_X2,$YPos,$this->GArea_X2+5,$YPos,$R,$G,$B);
  472. else
  473. $this->drawLine($this->GArea_X1,$YPos,$this->GArea_X1-5,$YPos,$R,$G,$B);
  474. $Value = $this->VMin + ($i-1) * (( $this->VMax - $this->VMin ) / $Divisions);
  475. $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals);
  476. if ( $DataDescription["Format"]["Y"] == "number" )
  477. $Value = $Value.$DataDescription["Unit"]["Y"];
  478. if ( $DataDescription["Format"]["Y"] == "time" )
  479. $Value = $this->ToTime($Value);
  480. if ( $DataDescription["Format"]["Y"] == "date" )
  481. $Value = $this->ToDate($Value);
  482. if ( $DataDescription["Format"]["Y"] == "metric" )
  483. $Value = $this->ToMetric($Value);
  484. if ( $DataDescription["Format"]["Y"] == "currency" )
  485. $Value = $this->ToCurrency($Value);
  486. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  487. $TextWidth = $Position[2]-$Position[0];
  488. if ( $RightScale )
  489. {
  490. imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X2+10,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value);
  491. if ( $XMin < $this->GArea_X2+15+$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X2+15+$TextWidth; }
  492. }
  493. else
  494. {
  495. imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1-10-$TextWidth,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value);
  496. if ( $XMin > $this->GArea_X1-10-$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X1-10-$TextWidth; }
  497. }
  498. $YPos = $YPos - $this->DivisionHeight;
  499. }
  500. /* Write the Y Axis caption if set */
  501. if ( isset($DataDescription["Axis"]["Y"]) )
  502. {
  503. $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["Y"]);
  504. $TextHeight = abs($Position[1])+abs($Position[3]);
  505. $TextTop = (($this->GArea_Y2 - $this->GArea_Y1) / 2) + $this->GArea_Y1 + ($TextHeight/2);
  506. if ( $RightScale )
  507. imagettftext($this->Picture,$this->FontSize,90,$XMin+$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]);
  508. else
  509. imagettftext($this->Picture,$this->FontSize,90,$XMin-$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]);
  510. }
  511. /* Horizontal Axis */
  512. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  513. $ID = 1; $YMax = NULL;
  514. foreach ( $Data as $Key => $Values )
  515. {
  516. if ( $ID % $SkipLabels == 0 )
  517. {
  518. $this->drawLine(floor($XPos),$this->GArea_Y2,floor($XPos),$this->GArea_Y2+5,$R,$G,$B);
  519. $Value = $Data[$Key][$DataDescription["Position"]];
  520. if ( $DataDescription["Format"]["X"] == "number" )
  521. $Value = $Value.$DataDescription["Unit"]["X"];
  522. if ( $DataDescription["Format"]["X"] == "time" )
  523. $Value = $this->ToTime($Value);
  524. if ( $DataDescription["Format"]["X"] == "date" )
  525. $Value = $this->ToDate($Value);
  526. if ( $DataDescription["Format"]["X"] == "metric" )
  527. $Value = $this->ToMetric($Value);
  528. if ( $DataDescription["Format"]["X"] == "currency" )
  529. $Value = $this->ToCurrency($Value);
  530. $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Value);
  531. $TextWidth = abs($Position[2])+abs($Position[0]);
  532. $TextHeight = abs($Position[1])+abs($Position[3]);
  533. if ( $Angle == 0 )
  534. {
  535. $YPos = $this->GArea_Y2+18;
  536. imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-floor($TextWidth/2),$YPos,$C_TextColor,$this->FontName,$Value);
  537. }
  538. else
  539. {
  540. $YPos = $this->GArea_Y2+10+$TextHeight;
  541. if ( $Angle <= 90 )
  542. imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
  543. else
  544. imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)+$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
  545. }
  546. if ( $YMax < $YPos || $YMax == NULL ) { $YMax = $YPos; }
  547. }
  548. $XPos = $XPos + $this->DivisionWidth;
  549. $ID++;
  550. }
  551. /* Write the X Axis caption if set */
  552. if ( isset($DataDescription["Axis"]["X"]) )
  553. {
  554. $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["X"]);
  555. $TextWidth = abs($Position[2])+abs($Position[0]);
  556. $TextLeft = (($this->GArea_X2 - $this->GArea_X1) / 2) + $this->GArea_X1 + ($TextWidth/2);
  557. imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]);
  558. }
  559. }
  560. /* Compute and draw the scale for X/Y charts */
  561. function drawXYScale($Data,$DataDescription,$YSerieName,$XSerieName,$R,$G,$B,$WithMargin=0,$Angle=0,$Decimals=1)
  562. {
  563. /* Validate the Data and DataDescription array */
  564. $this->validateData("drawScale",$Data);
  565. $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
  566. $this->drawLine($this->GArea_X1,$this->GArea_Y1,$this->GArea_X1,$this->GArea_Y2,$R,$G,$B);
  567. $this->drawLine($this->GArea_X1,$this->GArea_Y2,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B);
  568. /* Process Y scale */
  569. if ( $this->VMin == NULL && $this->VMax == NULL)
  570. {
  571. $this->VMin = $Data[0][$YSerieName];
  572. $this->VMax = $Data[0][$YSerieName];
  573. foreach ( $Data as $Key => $Values )
  574. {
  575. if (isset($Data[$Key][$YSerieName]))
  576. {
  577. $Value = $Data[$Key][$YSerieName];
  578. if ( $this->VMax < $Value) { $this->VMax = $Value; }
  579. if ( $this->VMin > $Value) { $this->VMin = $Value; }
  580. }
  581. }
  582. if ( $this->VMax > preg_replace('/\.[0-9]+/','',$this->VMax) )
  583. $this->VMax = preg_replace('/\.[0-9]+/','',$this->VMax)+1;
  584. $DataRange = $this->VMax - $this->VMin;
  585. if ( $DataRange == 0 ) { $DataRange = .1; }
  586. /* Compute automatic scaling */
  587. $ScaleOk = FALSE; $Factor = 1;
  588. $MinDivHeight = 25; $MaxDivs = ($this->GArea_Y2 - $this->GArea_Y1) / $MinDivHeight;
  589. if ( $this->VMin == 0 && $this->VMax == 0 )
  590. { $this->VMin = 0; $this->VMax = 2; $Scale = 1; $Divisions = 2;}
  591. elseif ($MaxDivs > 1)
  592. {
  593. while(!$ScaleOk)
  594. {
  595. $Scale1 = ( $this->VMax - $this->VMin ) / $Factor;
  596. $Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2;
  597. $Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4;
  598. if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}
  599. if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
  600. if (!$ScaleOk)
  601. {
  602. if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
  603. if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
  604. }
  605. }
  606. if ( floor($this->VMax / $Scale / $Factor) != $this->VMax / $Scale / $Factor)
  607. {
  608. $GridID = floor ( $this->VMax / $Scale / $Factor) + 1;
  609. $this->VMax = $GridID * $Scale * $Factor;
  610. $Divisions++;
  611. }
  612. if ( floor($this->VMin / $Scale / $Factor) != $this->VMin / $Scale / $Factor)
  613. {
  614. $GridID = floor( $this->VMin / $Scale / $Factor);
  615. $this->VMin = $GridID * $Scale * $Factor;
  616. $Divisions++;
  617. }
  618. }
  619. else /* Can occurs for small graphs */
  620. $Scale = 1;
  621. if ( !isset($Divisions) )
  622. $Divisions = 2;
  623. if ( $this->isRealInt(($this->VMax-$this->VMin)/($Divisions-1)))
  624. $Divisions--;
  625. elseif ( $this->isRealInt(($this->VMax-$this->VMin)/($Divisions+1)))
  626. $Divisions++;
  627. }
  628. else
  629. $Divisions = $this->Divisions;
  630. $this->DivisionCount = $Divisions;
  631. $DataRange = $this->VMax - $this->VMin;
  632. if ( $DataRange == 0 ) { $DataRange = .1; }
  633. $this->DivisionHeight = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $Divisions;
  634. $this->DivisionRatio = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $DataRange;
  635. $YPos = $this->GArea_Y2; $XMin = NULL;
  636. for($i=1;$i<=$Divisions+1;$i++)
  637. {
  638. $this->drawLine($this->GArea_X1,$YPos,$this->GArea_X1-5,$YPos,$R,$G,$B);
  639. $Value = $this->VMin + ($i-1) * (( $this->VMax - $this->VMin ) / $Divisions);
  640. $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals);
  641. if ( $DataDescription["Format"]["Y"] == "number" )
  642. $Value = $Value.$DataDescription["Unit"]["Y"];
  643. if ( $DataDescription["Format"]["Y"] == "time" )
  644. $Value = $this->ToTime($Value);
  645. if ( $DataDescription["Format"]["Y"] == "date" )
  646. $Value = $this->ToDate($Value);
  647. if ( $DataDescription["Format"]["Y"] == "metric" )
  648. $Value = $this->ToMetric($Value);
  649. if ( $DataDescription["Format"]["Y"] == "currency" )
  650. $Value = $this->ToCurrency($Value);
  651. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  652. $TextWidth = $Position[2]-$Position[0];
  653. imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1-10-$TextWidth,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value);
  654. if ( $XMin > $this->GArea_X1-10-$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X1-10-$TextWidth; }
  655. $YPos = $YPos - $this->DivisionHeight;
  656. }
  657. /* Process X scale */
  658. if ( $this->VXMin == NULL && $this->VXMax == NULL)
  659. {
  660. $this->VXMin = $Data[0][$XSerieName];
  661. $this->VXMax = $Data[0][$XSerieName];
  662. foreach ( $Data as $Key => $Values )
  663. {
  664. if (isset($Data[$Key][$XSerieName]))
  665. {
  666. $Value = $Data[$Key][$XSerieName];
  667. if ( $this->VXMax < $Value) { $this->VXMax = $Value; }
  668. if ( $this->VXMin > $Value) { $this->VXMin = $Value; }
  669. }
  670. }
  671. if ( $this->VXMax > preg_replace('/\.[0-9]+/','',$this->VXMax) )
  672. $this->VXMax = preg_replace('/\.[0-9]+/','',$this->VXMax)+1;
  673. $DataRange = $this->VMax - $this->VMin;
  674. if ( $DataRange == 0 ) { $DataRange = .1; }
  675. /* Compute automatic scaling */
  676. $ScaleOk = FALSE; $Factor = 1;
  677. $MinDivWidth = 25; $MaxDivs = ($this->GArea_X2 - $this->GArea_X1) / $MinDivWidth;
  678. if ( $this->VXMin == 0 && $this->VXMax == 0 )
  679. { $this->VXMin = 0; $this->VXMax = 2; $Scale = 1; $XDivisions = 2;}
  680. elseif ($MaxDivs > 1)
  681. {
  682. while(!$ScaleOk)
  683. {
  684. $Scale1 = ( $this->VXMax - $this->VXMin ) / $Factor;
  685. $Scale2 = ( $this->VXMax - $this->VXMin ) / $Factor / 2;
  686. $Scale4 = ( $this->VXMax - $this->VXMin ) / $Factor / 4;
  687. if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $XDivisions = floor($Scale1); $Scale = 1;}
  688. if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $XDivisions = floor($Scale2); $Scale = 2;}
  689. if (!$ScaleOk)
  690. {
  691. if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
  692. if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
  693. }
  694. }
  695. if ( floor($this->VXMax / $Scale / $Factor) != $this->VXMax / $Scale / $Factor)
  696. {
  697. $GridID = floor ( $this->VXMax / $Scale / $Factor) + 1;
  698. $this->VXMax = $GridID * $Scale * $Factor;
  699. $XDivisions++;
  700. }
  701. if ( floor($this->VXMin / $Scale / $Factor) != $this->VXMin / $Scale / $Factor)
  702. {
  703. $GridID = floor( $this->VXMin / $Scale / $Factor);
  704. $this->VXMin = $GridID * $Scale * $Factor;
  705. $XDivisions++;
  706. }
  707. }
  708. else /* Can occurs for small graphs */
  709. $Scale = 1;
  710. if ( !isset($XDivisions) )
  711. $XDivisions = 2;
  712. if ( $this->isRealInt(($this->VXMax-$this->VXMin)/($XDivisions-1)))
  713. $XDivisions--;
  714. elseif ( $this->isRealInt(($this->VXMax-$this->VXMin)/($XDivisions+1)))
  715. $XDivisions++;
  716. }
  717. else
  718. $XDivisions = $this->XDivisions;
  719. $this->XDivisionCount = $Divisions;
  720. $this->DataCount = $Divisions + 2;
  721. $XDataRange = $this->VXMax - $this->VXMin;
  722. if ( $XDataRange == 0 ) { $XDataRange = .1; }
  723. $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / $XDivisions;
  724. $this->XDivisionRatio = ( $this->GArea_X2 - $this->GArea_X1 ) / $XDataRange;
  725. $XPos = $this->GArea_X1; $YMax = NULL;
  726. for($i=1;$i<=$XDivisions+1;$i++)
  727. {
  728. $this->drawLine($XPos,$this->GArea_Y2,$XPos,$this->GArea_Y2+5,$R,$G,$B);
  729. $Value = $this->VXMin + ($i-1) * (( $this->VXMax - $this->VXMin ) / $XDivisions);
  730. $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals);
  731. if ( $DataDescription["Format"]["Y"] == "number" )
  732. $Value = $Value.$DataDescription["Unit"]["Y"];
  733. if ( $DataDescription["Format"]["Y"] == "time" )
  734. $Value = $this->ToTime($Value);
  735. if ( $DataDescription["Format"]["Y"] == "date" )
  736. $Value = $this->ToDate($Value);
  737. if ( $DataDescription["Format"]["Y"] == "metric" )
  738. $Value = $this->ToMetric($Value);
  739. if ( $DataDescription["Format"]["Y"] == "currency" )
  740. $Value = $this->ToCurrency($Value);
  741. $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Value);
  742. $TextWidth = abs($Position[2])+abs($Position[0]);
  743. $TextHeight = abs($Position[1])+abs($Position[3]);
  744. if ( $Angle == 0 )
  745. {
  746. $YPos = $this->GArea_Y2+18;
  747. imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-floor($TextWidth/2),$YPos,$C_TextColor,$this->FontName,$Value);
  748. }
  749. else
  750. {
  751. $YPos = $this->GArea_Y2+10+$TextHeight;
  752. if ( $Angle <= 90 )
  753. imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
  754. else
  755. imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)+$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
  756. }
  757. if ( $YMax < $YPos || $YMax == NULL ) { $YMax = $YPos; }
  758. $XPos = $XPos + $this->DivisionWidth;
  759. }
  760. /* Write the Y Axis caption if set */
  761. if ( isset($DataDescription["Axis"]["Y"]) )
  762. {
  763. $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["Y"]);
  764. $TextHeight = abs($Position[1])+abs($Position[3]);
  765. $TextTop = (($this->GArea_Y2 - $this->GArea_Y1) / 2) + $this->GArea_Y1 + ($TextHeight/2);
  766. imagettftext($this->Picture,$this->FontSize,90,$XMin-$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]);
  767. }
  768. /* Write the X Axis caption if set */
  769. if ( isset($DataDescription["Axis"]["X"]) )
  770. {
  771. $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["X"]);
  772. $TextWidth = abs($Position[2])+abs($Position[0]);
  773. $TextLeft = (($this->GArea_X2 - $this->GArea_X1) / 2) + $this->GArea_X1 + ($TextWidth/2);
  774. imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]);
  775. }
  776. }
  777. /* Compute and draw the scale */
  778. function drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=100)
  779. {
  780. /* Draw mosaic */
  781. if ( $Mosaic )
  782. {
  783. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  784. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  785. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  786. $C_White =$this->AllocateColor($this->Layers[0],255,255,255);
  787. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  788. imagecolortransparent($this->Layers[0],$C_White);
  789. $C_Rectangle =$this->AllocateColor($this->Layers[0],250,250,250);
  790. $YPos = $LayerHeight; //$this->GArea_Y2-1;
  791. $LastY = $YPos;
  792. for($i=0;$i<=$this->DivisionCount;$i++)
  793. {
  794. $LastY = $YPos;
  795. $YPos = $YPos - $this->DivisionHeight;
  796. if ( $YPos <= 0 ) { $YPos = 1; }
  797. if ( $i % 2 == 0 )
  798. {
  799. imagefilledrectangle($this->Layers[0],1,$YPos,$LayerWidth-1,$LastY,$C_Rectangle);
  800. }
  801. }
  802. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  803. imagedestroy($this->Layers[0]);
  804. }
  805. /* Horizontal lines */
  806. $YPos = $this->GArea_Y2 - $this->DivisionHeight;
  807. for($i=1;$i<=$this->DivisionCount;$i++)
  808. {
  809. if ( $YPos > $this->GArea_Y1 && $YPos < $this->GArea_Y2 )
  810. $this->drawDottedLine($this->GArea_X1,$YPos,$this->GArea_X2,$YPos,$LineWidth,$R,$G,$B);
  811. $YPos = $YPos - $this->DivisionHeight;
  812. }
  813. /* Vertical lines */
  814. if ( $this->GAreaXOffset == 0 )
  815. { $XPos = $this->GArea_X1 + $this->DivisionWidth + $this->GAreaXOffset; $ColCount = $this->DataCount-2; }
  816. else
  817. { $XPos = $this->GArea_X1 + $this->GAreaXOffset; $ColCount = floor( ($this->GArea_X2 - $this->GArea_X1) / $this->DivisionWidth ); }
  818. for($i=1;$i<=$ColCount;$i++)
  819. {
  820. if ( $XPos > $this->GArea_X1 && $XPos < $this->GArea_X2 )
  821. $this->drawDottedLine(floor($XPos),$this->GArea_Y1,floor($XPos),$this->GArea_Y2,$LineWidth,$R,$G,$B);
  822. $XPos = $XPos + $this->DivisionWidth;
  823. }
  824. }
  825. /* retrieve the legends size */
  826. function getLegendBoxSize($DataDescription)
  827. {
  828. if ( !isset($DataDescription["Description"]) )
  829. return(-1);
  830. /* <-10->[8]<-4->Text<-10-> */
  831. $MaxWidth = 0; $MaxHeight = 8;
  832. foreach($DataDescription["Description"] as $Key => $Value)
  833. {
  834. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  835. $TextWidth = $Position[2]-$Position[0];
  836. $TextHeight = $Position[1]-$Position[7];
  837. if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; }
  838. $MaxHeight = $MaxHeight + $TextHeight + 4;
  839. }
  840. $MaxHeight = $MaxHeight - 3;
  841. $MaxWidth = $MaxWidth + 32;
  842. return(array($MaxWidth,$MaxHeight));
  843. }
  844. /* Draw the data legends */
  845. function drawLegend($XPos,$YPos,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-1,$Rt=0,$Gt=0,$Bt=0,$Border=TRUE)
  846. {
  847. /* Validate the Data and DataDescription array */
  848. $this->validateDataDescription("drawLegend",$DataDescription);
  849. if ( !isset($DataDescription["Description"]) )
  850. return(-1);
  851. $C_TextColor =$this->AllocateColor($this->Picture,$Rt,$Gt,$Bt);
  852. /* <-10->[8]<-4->Text<-10-> */
  853. $MaxWidth = 0; $MaxHeight = 8;
  854. foreach($DataDescription["Description"] as $Key => $Value)
  855. {
  856. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  857. $TextWidth = $Position[2]-$Position[0];
  858. $TextHeight = $Position[1]-$Position[7];
  859. if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; }
  860. $MaxHeight = $MaxHeight + $TextHeight + 4;
  861. }
  862. $MaxHeight = $MaxHeight - 5;
  863. $MaxWidth = $MaxWidth + 32;
  864. if ( $Rs == -1 || $Gs == -1 || $Bs == -1 )
  865. { $Rs = $R-30; $Gs = $G-30; $Bs = $B-30; }
  866. if ( $Border )
  867. {
  868. $this->drawFilledRoundedRectangle($XPos+1,$YPos+1,$XPos+$MaxWidth+1,$YPos+$MaxHeight+1,5,$Rs,$Gs,$Bs);
  869. $this->drawFilledRoundedRectangle($XPos,$YPos,$XPos+$MaxWidth,$YPos+$MaxHeight,5,$R,$G,$B);
  870. }
  871. $YOffset = 4 + $this->FontSize; $ID = 0;
  872. foreach($DataDescription["Description"] as $Key => $Value)
  873. {
  874. $this->drawFilledRoundedRectangle($XPos+10,$YPos+$YOffset-4,$XPos+14,$YPos+$YOffset-4,2,$this->Palette[$ID]["R"],$this->Palette[$ID]["G"],$this->Palette[$ID]["B"]);
  875. imagettftext($this->Picture,$this->FontSize,0,$XPos+22,$YPos+$YOffset,$C_TextColor,$this->FontName,$Value);
  876. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  877. $TextHeight = $Position[1]-$Position[7];
  878. $YOffset = $YOffset + $TextHeight + 4;
  879. $ID++;
  880. }
  881. }
  882. /* Draw the data legends */
  883. function drawPieLegend($XPos,$YPos,$Data,$DataDescription,$R,$G,$B)
  884. {
  885. /* Validate the Data and DataDescription array */
  886. $this->validateDataDescription("drawPieLegend",$DataDescription,FALSE);
  887. $this->validateData("drawPieLegend",$Data);
  888. if ( !isset($DataDescription["Position"]) )
  889. return(-1);
  890. $C_TextColor =$this->AllocateColor($this->Picture,0,0,0);
  891. /* <-10->[8]<-4->Text<-10-> */
  892. $MaxWidth = 0; $MaxHeight = 8;
  893. foreach($Data as $Key => $Value)
  894. {
  895. $Value2 = $Value[$DataDescription["Position"]];
  896. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value2);
  897. $TextWidth = $Position[2]-$Position[0];
  898. $TextHeight = $Position[1]-$Position[7];
  899. if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; }
  900. $MaxHeight = $MaxHeight + $TextHeight + 4;
  901. }
  902. $MaxHeight = $MaxHeight - 3;
  903. $MaxWidth = $MaxWidth + 32;
  904. $this->drawFilledRoundedRectangle($XPos+1,$YPos+1,$XPos+$MaxWidth+1,$YPos+$MaxHeight+1,5,$R-30,$G-30,$B-30);
  905. $this->drawFilledRoundedRectangle($XPos,$YPos,$XPos+$MaxWidth,$YPos+$MaxHeight,5,$R,$G,$B);
  906. $YOffset = 4 + $this->FontSize; $ID = 0;
  907. foreach($Data as $Key => $Value)
  908. {
  909. $Value2 = $Value[$DataDescription["Position"]];
  910. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value2);
  911. $TextHeight = $Position[1]-$Position[7];
  912. $this->drawFilledRectangle($XPos+10,$YPos+$YOffset-6,$XPos+14,$YPos+$YOffset-2,$this->Palette[$ID]["R"],$this->Palette[$ID]["G"],$this->Palette[$ID]["B"]);
  913. imagettftext($this->Picture,$this->FontSize,0,$XPos+22,$YPos+$YOffset,$C_TextColor,$this->FontName,$Value2);
  914. $YOffset = $YOffset + $TextHeight + 4;
  915. $ID++;
  916. }
  917. }
  918. /* Draw the graph title */
  919. function drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE)
  920. {
  921. $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B);
  922. if ( $XPos2 != -1 )
  923. {
  924. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  925. $TextWidth = $Position[2]-$Position[0];
  926. $XPos = floor(( $XPos2 - $XPos - $TextWidth ) / 2 ) + $XPos;
  927. }
  928. if ( $YPos2 != -1 )
  929. {
  930. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  931. $TextHeight = $Position[5]-$Position[3];
  932. $YPos = floor(( $YPos2 - $YPos - $TextHeight ) / 2 ) + $YPos;
  933. }
  934. if ( $Shadow )
  935. {
  936. $C_ShadowColor = $this->AllocateColor($this->Picture,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor);
  937. imagettftext($this->Picture,$this->FontSize,0,$XPos+$this->ShadowXDistance,$YPos+$this->ShadowYDistance,$C_ShadowColor,$this->FontName,$Value);
  938. }
  939. imagettftext($this->Picture,$this->FontSize,0,$XPos,$YPos,$C_TextColor,$this->FontName,$Value);
  940. }
  941. /* Draw a text box with text align & alpha properties */
  942. function drawTextBox($X1,$Y1,$X2,$Y2,$Text,$Angle=0,$R=255,$G=255,$B=255,$Align=ALIGN_LEFT,$Shadow=TRUE,$BgR=-1,$BgG=-1,$BgB=-1,$Alpha=100)
  943. {
  944. $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Text);
  945. $TextWidth = $Position[2]-$Position[0];
  946. $TextHeight = $Position[5]-$Position[3];
  947. $AreaWidth = $X2 - $X1;
  948. $AreaHeight = $Y2 - $Y1;
  949. if ( $BgR != -1 && $BgG != -1 && $BgB != -1 )
  950. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$BgR,$BgG,$BgB,FALSE,$Alpha);
  951. if ( $Align == ALIGN_TOP_LEFT ) { $X = $X1+1; $Y = $Y1+$this->FontSize+1; }
  952. if ( $Align == ALIGN_TOP_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y1+$this->FontSize+1; }
  953. if ( $Align == ALIGN_TOP_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y1+$this->FontSize+1; }
  954. if ( $Align == ALIGN_LEFT ) { $X = $X1+1; $Y = $Y1+($AreaHeight/2)-($TextHeight/2); }
  955. if ( $Align == ALIGN_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y1+($AreaHeight/2)-($TextHeight/2); }
  956. if ( $Align == ALIGN_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y1+($AreaHeight/2)-($TextHeight/2); }
  957. if ( $Align == ALIGN_BOTTOM_LEFT ) { $X = $X1+1; $Y = $Y2-1; }
  958. if ( $Align == ALIGN_BOTTOM_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y2-1; }
  959. if ( $Align == ALIGN_BOTTOM_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y2-1; }
  960. $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
  961. $C_ShadowColor =$this->AllocateColor($this->Picture,0,0,0);
  962. if ( $Shadow )
  963. imagettftext($this->Picture,$this->FontSize,$Angle,$X+1,$Y+1,$C_ShadowColor,$this->FontName,$Text);
  964. imagettftext($this->Picture,$this->FontSize,$Angle,$X,$Y,$C_TextColor,$this->FontName,$Text);
  965. }
  966. /* Compute and draw the scale */
  967. function drawTreshold($Value,$R,$G,$B,$ShowLabel=FALSE,$ShowOnRight=FALSE,$TickWidth=4,$FreeText=NULL)
  968. {
  969. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  970. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  971. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  972. $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
  973. $Y = $this->GArea_Y2 - ($Value - $this->VMin) * $this->DivisionRatio;
  974. if ( $Y <= $this->GArea_Y1 || $Y >= $this->GArea_Y2 )
  975. return(-1);
  976. if ( $TickWidth == 0 )
  977. $this->drawLine($this->GArea_X1,$Y,$this->GArea_X2,$Y,$R,$G,$B);
  978. else
  979. $this->drawDottedLine($this->GArea_X1,$Y,$this->GArea_X2,$Y,$TickWidth,$R,$G,$B);
  980. if ( $ShowLabel )
  981. {
  982. if ( $FreeText == NULL )
  983. { $Label = $Value; } else { $Label = $FreeText; }
  984. if ( $ShowOnRight )
  985. imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X2+2,$Y+($this->FontSize/2),$C_TextColor,$this->FontName,$Label);
  986. else
  987. imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1+2,$Y-($this->FontSize/2),$C_TextColor,$this->FontName,$Label);
  988. }
  989. }
  990. /* This function put a label on a specific point */
  991. function setLabel($Data,$DataDescription,$SerieName,$ValueName,$Caption,$R=210,$G=210,$B=210)
  992. {
  993. /* Validate the Data and DataDescription array */
  994. $this->validateDataDescription("setLabel",$DataDescription);
  995. $this->validateData("setLabel",$Data);
  996. $ShadowFactor = 100;
  997. $C_Label =$this->AllocateColor($this->Picture,$R,$G,$B);
  998. $C_Shadow =$this->AllocateColor($this->Picture,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
  999. $C_TextColor =$this->AllocateColor($this->Picture,0,0,0);
  1000. $Cp = 0; $Found = FALSE;
  1001. foreach ( $Data as $Key => $Value )
  1002. {
  1003. if ( $Data[$Key][$DataDescription["Position"]] == $ValueName )
  1004. { $NumericalValue = $Data[$Key][$SerieName]; $Found = TRUE; }
  1005. if ( !$Found )
  1006. $Cp++;
  1007. }
  1008. $XPos = $this->GArea_X1 + $this->GAreaXOffset + ( $this->DivisionWidth * $Cp ) + 2;
  1009. $YPos = $this->GArea_Y2 - ($NumericalValue - $this->VMin) * $this->DivisionRatio;
  1010. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  1011. $TextHeight = $Position[3] - $Position[5];
  1012. $TextWidth = $Position[2]-$Position[0] + 2;
  1013. $TextOffset = floor($TextHeight/2);
  1014. // Shadow
  1015. $Poly = array($XPos+1,$YPos+1,$XPos + 9,$YPos - $TextOffset,$XPos + 8,$YPos + $TextOffset + 2);
  1016. imagefilledpolygon($this->Picture,$Poly,3,$C_Shadow);
  1017. $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos - $TextOffset - .2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
  1018. $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
  1019. $this->drawFilledRectangle($XPos + 9,$YPos - $TextOffset-.2,$XPos + 13 + $TextWidth,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
  1020. // Label background
  1021. $Poly = array($XPos,$YPos,$XPos + 8,$YPos - $TextOffset - 1,$XPos + 8,$YPos + $TextOffset + 1);
  1022. imagefilledpolygon($this->Picture,$Poly,3,$C_Label);
  1023. $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos - $TextOffset - 1.2,$R,$G,$B);
  1024. $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos + $TextOffset + 1.2,$R,$G,$B);
  1025. $this->drawFilledRectangle($XPos + 8,$YPos - $TextOffset - 1.2,$XPos + 12 + $TextWidth,$YPos + $TextOffset + 1.2,$R,$G,$B);
  1026. imagettftext($this->Picture,$this->FontSize,0,$XPos + 10,$YPos + $TextOffset,$C_TextColor,$this->FontName,$Caption);
  1027. }
  1028. /* This function draw a plot graph */
  1029. function drawPlotGraph($Data,$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=FALSE)
  1030. {
  1031. /* Validate the Data and DataDescription array */
  1032. $this->validateDataDescription("drawPlotGraph",$DataDescription);
  1033. $this->validateData("drawPlotGraph",$Data);
  1034. $GraphID = 0;
  1035. $Ro = $R2; $Go = $G2; $Bo = $B2;
  1036. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1037. {
  1038. $ID = 0;
  1039. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1040. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1041. $R = $this->Palette[$ColorID]["R"];
  1042. $G = $this->Palette[$ColorID]["G"];
  1043. $B = $this->Palette[$ColorID]["B"];
  1044. $R2 = $Ro; $G2 = $Go; $B2 = $Bo;
  1045. if ( isset($DataDescription["Symbol"][$ColName]) )
  1046. {
  1047. $Is_Alpha = ((ord ( file_get_contents ($DataDescription["Symbol"][$ColName], false, null, 25, 1)) & 6) & 4) == 4;
  1048. $Infos = getimagesize($DataDescription["Symbol"][$ColName]);
  1049. $ImageWidth = $Infos[0];
  1050. $ImageHeight = $Infos[1];
  1051. $Symbol = imagecreatefromgif($DataDescription["Symbol"][$ColName]);
  1052. }
  1053. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1054. $Hsize = round($BigRadius/2);
  1055. $R3 = -1; $G3 = -1; $B3 = -1;
  1056. foreach ( $Data as $Key => $Values )
  1057. {
  1058. $Value = $Data[$Key][$ColName];
  1059. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1060. /* Save point into the image map if option activated */
  1061. if ( $this->BuildMap )
  1062. $this->addToImageMap($XPos-$Hsize,$YPos-$Hsize,$XPos+1+$Hsize,$YPos+$Hsize+1,$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Plot");
  1063. if ( is_numeric($Value) )
  1064. {
  1065. if ( !isset($DataDescription["Symbol"][$ColName]) )
  1066. {
  1067. if ( $Shadow )
  1068. {
  1069. if ( $R3 !=-1 && $G3 !=-1 && $B3 !=-1 )
  1070. $this->drawFilledCircle($XPos+2,$YPos+2,$BigRadius,$R3,$G3,$B3);
  1071. else
  1072. {
  1073. $R3 = $this->Palette[$ColorID]["R"]-20; if ( $R3 < 0 ) { $R3 = 0; }
  1074. $G3 = $this->Palette[$ColorID]["G"]-20; if ( $G3 < 0 ) { $G3 = 0; }
  1075. $B3 = $this->Palette[$ColorID]["B"]-20; if ( $B3 < 0 ) { $B3 = 0; }
  1076. $this->drawFilledCircle($XPos+2,$YPos+2,$BigRadius,$R3,$G3,$B3);
  1077. }
  1078. }
  1079. $this->drawFilledCircle($XPos+1,$YPos+1,$BigRadius,$R,$G,$B);
  1080. if ( $SmallRadius != 0 )
  1081. {
  1082. if ( $R2 !=-1 && $G2 !=-1 && $B2 !=-1 )
  1083. $this->drawFilledCircle($XPos+1,$YPos+1,$SmallRadius,$R2,$G2,$B2);
  1084. else
  1085. {
  1086. $R2 = $this->Palette[$ColorID]["R"]-15; if ( $R2 < 0 ) { $R2 = 0; }
  1087. $G2 = $this->Palette[$ColorID]["G"]-15; if ( $G2 < 0 ) { $G2 = 0; }
  1088. $B2 = $this->Palette[$ColorID]["B"]-15; if ( $B2 < 0 ) { $B2 = 0; }
  1089. $this->drawFilledCircle($XPos+1,$YPos+1,$SmallRadius,$R2,$G2,$B2);
  1090. }
  1091. }
  1092. }
  1093. else
  1094. {
  1095. imagecopymerge($this->Picture,$Symbol,$XPos+1-$ImageWidth/2,$YPos+1-$ImageHeight/2,0,0,$ImageWidth,$ImageHeight,100);
  1096. }
  1097. }
  1098. $XPos = $XPos + $this->DivisionWidth;
  1099. }
  1100. $GraphID++;
  1101. }
  1102. }
  1103. /* This function draw a plot graph in an X/Y space */
  1104. function drawXYPlotGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=TRUE)
  1105. {
  1106. $R = $this->Palette[$PaletteID]["R"];
  1107. $G = $this->Palette[$PaletteID]["G"];
  1108. $B = $this->Palette[$PaletteID]["B"];
  1109. $R3 = -1; $G3 = -1; $B3 = -1;
  1110. $YLast = -1; $XLast = -1;
  1111. foreach ( $Data as $Key => $Values )
  1112. {
  1113. if ( isset($Data[$Key][$YSerieName]) && isset($Data[$Key][$XSerieName]) )
  1114. {
  1115. $X = $Data[$Key][$XSerieName];
  1116. $Y = $Data[$Key][$YSerieName];
  1117. $Y = $this->GArea_Y2 - (($Y-$this->VMin) * $this->DivisionRatio);
  1118. $X = $this->GArea_X1 + (($X-$this->VXMin) * $this->XDivisionRatio);
  1119. if ( $Shadow )
  1120. {
  1121. if ( $R3 !=-1 && $G3 !=-1 && $B3 !=-1 )
  1122. $this->drawFilledCircle($X+2,$Y+2,$BigRadius,$R3,$G3,$B3);
  1123. else
  1124. {
  1125. $R3 = $this->Palette[$PaletteID]["R"]-20; if ( $R < 0 ) { $R = 0; }
  1126. $G3 = $this->Palette[$PaletteID]["G"]-20; if ( $G < 0 ) { $G = 0; }
  1127. $B3 = $this->Palette[$PaletteID]["B"]-20; if ( $B < 0 ) { $B = 0; }
  1128. $this->drawFilledCircle($X+2,$Y+2,$BigRadius,$R3,$G3,$B3);
  1129. }
  1130. }
  1131. $this->drawFilledCircle($X+1,$Y+1,$BigRadius,$R,$G,$B);
  1132. if ( $R2 !=-1 && $G2 !=-1 && $B2 !=-1 )
  1133. $this->drawFilledCircle($X+1,$Y+1,$SmallRadius,$R2,$G2,$B2);
  1134. else
  1135. {
  1136. $R2 = $this->Palette[$PaletteID]["R"]+20; if ( $R > 255 ) { $R = 255; }
  1137. $G2 = $this->Palette[$PaletteID]["G"]+20; if ( $G > 255 ) { $G = 255; }
  1138. $B2 = $this->Palette[$PaletteID]["B"]+20; if ( $B > 255 ) { $B = 255; }
  1139. $this->drawFilledCircle($X+1,$Y+1,$SmallRadius,$R2,$G2,$B2);
  1140. }
  1141. }
  1142. }
  1143. }
  1144. /* This function draw an area between two series */
  1145. function drawArea($Data,$Serie1,$Serie2,$R,$G,$B,$Alpha = 50)
  1146. {
  1147. /* Validate the Data and DataDescription array */
  1148. $this->validateData("drawArea",$Data);
  1149. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1150. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1151. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  1152. $C_White =$this->AllocateColor($this->Layers[0],255,255,255);
  1153. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  1154. imagecolortransparent($this->Layers[0],$C_White);
  1155. $C_Graph =$this->AllocateColor($this->Layers[0],$R,$G,$B);
  1156. $XPos = $this->GAreaXOffset;
  1157. $LastXPos = -1;
  1158. foreach ( $Data as $Key => $Values )
  1159. {
  1160. $Value1 = $Data[$Key][$Serie1];
  1161. $Value2 = $Data[$Key][$Serie2];
  1162. $YPos1 = $LayerHeight - (($Value1-$this->VMin) * $this->DivisionRatio);
  1163. $YPos2 = $LayerHeight - (($Value2-$this->VMin) * $this->DivisionRatio);
  1164. if ( $LastXPos != -1 )
  1165. {
  1166. $Points = "";
  1167. $Points[] = $LastXPos; $Points[] = $LastYPos1;
  1168. $Points[] = $LastXPos; $Points[] = $LastYPos2;
  1169. $Points[] = $XPos; $Points[] = $YPos2;
  1170. $Points[] = $XPos; $Points[] = $YPos1;
  1171. imagefilledpolygon($this->Layers[0],$Points,4,$C_Graph);
  1172. }
  1173. $LastYPos1 = $YPos1;
  1174. $LastYPos2 = $YPos2;
  1175. $LastXPos = $XPos;
  1176. $XPos = $XPos + $this->DivisionWidth;
  1177. }
  1178. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  1179. imagedestroy($this->Layers[0]);
  1180. }
  1181. /* This function write the values of the specified series */
  1182. function writeValues($Data,$DataDescription,$Series)
  1183. {
  1184. /* Validate the Data and DataDescription array */
  1185. $this->validateDataDescription("writeValues",$DataDescription);
  1186. $this->validateData("writeValues",$Data);
  1187. if ( !is_array($Series) ) { $Series = array($Series); }
  1188. foreach($Series as $Key => $Serie)
  1189. {
  1190. $ID = 0;
  1191. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1192. { if ( $keyI == $Serie ) { $ColorID = $ID; }; $ID++; }
  1193. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1194. $XLast = -1;
  1195. foreach ( $Data as $Key => $Values )
  1196. {
  1197. if ( isset($Data[$Key][$Serie]) && is_numeric($Data[$Key][$Serie]))
  1198. {
  1199. $Value = $Data[$Key][$Serie];
  1200. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1201. $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$Value);
  1202. $Width = $Positions[2] - $Positions[6]; $XOffset = $XPos - ($Width/2);
  1203. $Height = $Positions[3] - $Positions[7]; $YOffset = $YPos - 4;
  1204. $C_TextColor =$this->AllocateColor($this->Picture,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1205. imagettftext($this->Picture,$this->FontSize,0,$XOffset,$YOffset,$C_TextColor,$this->FontName,$Value);
  1206. }
  1207. $XPos = $XPos + $this->DivisionWidth;
  1208. }
  1209. }
  1210. }
  1211. /* This function draw a line graph */
  1212. function drawLineGraph($Data,$DataDescription,$SerieName="")
  1213. {
  1214. /* Validate the Data and DataDescription array */
  1215. $this->validateDataDescription("drawLineGraph",$DataDescription);
  1216. $this->validateData("drawLineGraph",$Data);
  1217. $GraphID = 0;
  1218. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1219. {
  1220. $ID = 0;
  1221. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1222. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1223. if ( $SerieName == "" || $SerieName == $ColName )
  1224. {
  1225. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1226. $XLast = -1;
  1227. foreach ( $Data as $Key => $Values )
  1228. {
  1229. if ( isset($Data[$Key][$ColName]))
  1230. {
  1231. $Value = $Data[$Key][$ColName];
  1232. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1233. /* Save point into the image map if option activated */
  1234. if ( $this->BuildMap )
  1235. $this->addToImageMap($XPos-3,$YPos-3,$XPos+3,$YPos+3,$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Line");
  1236. if (!is_numeric($Value)) { $XLast = -1; }
  1237. if ( $XLast != -1 )
  1238. $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE);
  1239. $XLast = $XPos;
  1240. $YLast = $YPos;
  1241. if (!is_numeric($Value)) { $XLast = -1; }
  1242. }
  1243. $XPos = $XPos + $this->DivisionWidth;
  1244. }
  1245. $GraphID++;
  1246. }
  1247. }
  1248. }
  1249. /* This function draw a line graph */
  1250. function drawXYGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0)
  1251. {
  1252. $YLast = -1; $XLast = -1;
  1253. foreach ( $Data as $Key => $Values )
  1254. {
  1255. if ( isset($Data[$Key][$YSerieName]) && isset($Data[$Key][$XSerieName]) )
  1256. {
  1257. $X = $Data[$Key][$XSerieName];
  1258. $Y = $Data[$Key][$YSerieName];
  1259. $Y = $this->GArea_Y2 - (($Y-$this->VMin) * $this->DivisionRatio);
  1260. $X = $this->GArea_X1 + (($X-$this->VXMin) * $this->XDivisionRatio);
  1261. if ($XLast != -1 && $YLast != -1)
  1262. {
  1263. $this->drawLine($XLast,$YLast,$X,$Y,$this->Palette[$PaletteID]["R"],$this->Palette[$PaletteID]["G"],$this->Palette[$PaletteID]["B"],TRUE);
  1264. }
  1265. $XLast = $X;
  1266. $YLast = $Y;
  1267. }
  1268. }
  1269. }
  1270. /* This function draw a cubic curve */
  1271. function drawCubicCurve($Data,$DataDescription,$Accuracy=.1,$SerieName="")
  1272. {
  1273. /* Validate the Data and DataDescription array */
  1274. $this->validateDataDescription("drawCubicCurve",$DataDescription);
  1275. $this->validateData("drawCubicCurve",$Data);
  1276. $GraphID = 0;
  1277. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1278. {
  1279. if ( $SerieName == "" || $SerieName == $ColName )
  1280. {
  1281. $XIn = ""; $Yin = ""; $Yt = ""; $U = "";
  1282. $XIn[0] = 0; $YIn[0] = 0;
  1283. $ID = 0;
  1284. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1285. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1286. $Index = 1;
  1287. $XLast = -1; $Missing = "";
  1288. foreach ( $Data as $Key => $Values )
  1289. {
  1290. if ( isset($Data[$Key][$ColName]) )
  1291. {
  1292. $Value = $Data[$Key][$ColName];
  1293. $XIn[$Index] = $Index;
  1294. $YIn[$Index] = $Value;
  1295. if ( !is_numeric($Value) ) { $Missing[$Index] = TRUE; }
  1296. $Index++;
  1297. }
  1298. }
  1299. $Index--;
  1300. $Yt[0] = 0;
  1301. $Yt[1] = 0;
  1302. $U[1] = 0;
  1303. for($i=2;$i<=$Index-1;$i++)
  1304. {
  1305. $Sig = ($XIn[$i] - $XIn[$i-1]) / ($XIn[$i+1] - $XIn[$i-1]);
  1306. $p = $Sig * $Yt[$i-1] + 2;
  1307. $Yt[$i] = ($Sig - 1) / $p;
  1308. $U[$i] = ($YIn[$i+1] - $YIn[$i]) / ($XIn[$i+1] - $XIn[$i]) - ($YIn[$i] - $YIn[$i-1]) / ($XIn[$i] - $XIn[$i-1]);
  1309. $U[$i] = (6 * $U[$i] / ($XIn[$i+1] - $XIn[$i-1]) - $Sig * $U[$i-1]) / $p;
  1310. }
  1311. $qn = 0;
  1312. $un = 0;
  1313. $Yt[$Index] = ($un - $qn * $U[$Index-1]) / ($qn * $Yt[$Index-1] + 1);
  1314. for($k=$Index-1;$k>=1;$k--)
  1315. $Yt[$k] = $Yt[$k] * $Yt[$k+1] + $U[$k];
  1316. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1317. for($X=1;$X<=$Index;$X=$X+$Accuracy)
  1318. {
  1319. $klo = 1;
  1320. $khi = $Index;
  1321. $k = $khi - $klo;
  1322. while($k > 1)
  1323. {
  1324. $k = $khi - $klo;
  1325. If ( $XIn[$k] >= $X )
  1326. $khi = $k;
  1327. else
  1328. $klo = $k;
  1329. }
  1330. $klo = $khi - 1;
  1331. $h = $XIn[$khi] - $XIn[$klo];
  1332. $a = ($XIn[$khi] - $X) / $h;
  1333. $b = ($X - $XIn[$klo]) / $h;
  1334. $Value = $a * $YIn[$klo] + $b * $YIn[$khi] + (($a*$a*$a - $a) * $Yt[$klo] + ($b*$b*$b - $b) * $Yt[$khi]) * ($h*$h) / 6;
  1335. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1336. if ( $XLast != -1 && !isset($Missing[floor($X)]) && !isset($Missing[floor($X+1)]) )
  1337. $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE);
  1338. $XLast = $XPos;
  1339. $YLast = $YPos;
  1340. $XPos = $XPos + $this->DivisionWidth * $Accuracy;
  1341. }
  1342. // Add potentialy missing values
  1343. $XPos = $XPos - $this->DivisionWidth * $Accuracy;
  1344. if ( $XPos < ($this->GArea_X2 - $this->GAreaXOffset) )
  1345. {
  1346. $YPos = $this->GArea_Y2 - (($YIn[$Index]-$this->VMin) * $this->DivisionRatio);
  1347. $this->drawLine($XLast,$YLast,$this->GArea_X2-$this->GAreaXOffset,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE);
  1348. }
  1349. $GraphID++;
  1350. }
  1351. }
  1352. }
  1353. /* This function draw a filled cubic curve */
  1354. function drawFilledCubicCurve($Data,$DataDescription,$Accuracy=.1,$Alpha=100,$AroundZero=FALSE)
  1355. {
  1356. /* Validate the Data and DataDescription array */
  1357. $this->validateDataDescription("drawFilledCubicCurve",$DataDescription);
  1358. $this->validateData("drawFilledCubicCurve",$Data);
  1359. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1360. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1361. $YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio);
  1362. if ( $YZero > $LayerHeight ) { $YZero = $LayerHeight; }
  1363. $GraphID = 0;
  1364. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1365. {
  1366. $XIn = ""; $Yin = ""; $Yt = ""; $U = "";
  1367. $XIn[0] = 0; $YIn[0] = 0;
  1368. $ID = 0;
  1369. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1370. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1371. $Index = 1;
  1372. $XLast = -1; $Missing = "";
  1373. foreach ( $Data as $Key => $Values )
  1374. {
  1375. $Value = $Data[$Key][$ColName];
  1376. $XIn[$Index] = $Index;
  1377. $YIn[$Index] = $Value;
  1378. if ( !is_numeric($Value) ) { $Missing[$Index] = TRUE; }
  1379. $Index++;
  1380. }
  1381. $Index--;
  1382. $Yt[0] = 0;
  1383. $Yt[1] = 0;
  1384. $U[1] = 0;
  1385. for($i=2;$i<=$Index-1;$i++)
  1386. {
  1387. $Sig = ($XIn[$i] - $XIn[$i-1]) / ($XIn[$i+1] - $XIn[$i-1]);
  1388. $p = $Sig * $Yt[$i-1] + 2;
  1389. $Yt[$i] = ($Sig - 1) / $p;
  1390. $U[$i] = ($YIn[$i+1] - $YIn[$i]) / ($XIn[$i+1] - $XIn[$i]) - ($YIn[$i] - $YIn[$i-1]) / ($XIn[$i] - $XIn[$i-1]);
  1391. $U[$i] = (6 * $U[$i] / ($XIn[$i+1] - $XIn[$i-1]) - $Sig * $U[$i-1]) / $p;
  1392. }
  1393. $qn = 0;
  1394. $un = 0;
  1395. $Yt[$Index] = ($un - $qn * $U[$Index-1]) / ($qn * $Yt[$Index-1] + 1);
  1396. for($k=$Index-1;$k>=1;$k--)
  1397. $Yt[$k] = $Yt[$k] * $Yt[$k+1] + $U[$k];
  1398. $Points = "";
  1399. $Points[] = $this->GAreaXOffset;
  1400. $Points[] = $LayerHeight;
  1401. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  1402. $C_White =$this->AllocateColor($this->Layers[0],255,255,255);
  1403. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  1404. imagecolortransparent($this->Layers[0],$C_White);
  1405. $YLast = NULL;
  1406. $XPos = $this->GAreaXOffset; $PointsCount = 2;
  1407. for($X=1;$X<=$Index;$X=$X+$Accuracy)
  1408. {
  1409. $klo = 1;
  1410. $khi = $Index;
  1411. $k = $khi - $klo;
  1412. while($k > 1)
  1413. {
  1414. $k = $khi - $klo;
  1415. If ( $XIn[$k] >= $X )
  1416. $khi = $k;
  1417. else
  1418. $klo = $k;
  1419. }
  1420. $klo = $khi - 1;
  1421. $h = $XIn[$khi] - $XIn[$klo];
  1422. $a = ($XIn[$khi] - $X) / $h;
  1423. $b = ($X - $XIn[$klo]) / $h;
  1424. $Value = $a * $YIn[$klo] + $b * $YIn[$khi] + (($a*$a*$a - $a) * $Yt[$klo] + ($b*$b*$b - $b) * $Yt[$khi]) * ($h*$h) / 6;
  1425. $YPos = $LayerHeight - (($Value-$this->VMin) * $this->DivisionRatio);
  1426. if ( $YLast != NULL && $AroundZero && !isset($Missing[floor($X)]) && !isset($Missing[floor($X+1)]))
  1427. {
  1428. $aPoints = "";
  1429. $aPoints[] = $XLast;
  1430. $aPoints[] = $YLast;
  1431. $aPoints[] = $XPos;
  1432. $aPoints[] = $YPos;
  1433. $aPoints[] = $XPos;
  1434. $aPoints[] = $YZero;
  1435. $aPoints[] = $XLast;
  1436. $aPoints[] = $YZero;
  1437. $C_Graph =$this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1438. imagefilledpolygon($this->Layers[0],$aPoints,4,$C_Graph);
  1439. }
  1440. if ( !isset($Missing[floor($X)]) || $YLast == NULL )
  1441. {
  1442. $PointsCount++;
  1443. $Points[] = $XPos;
  1444. $Points[] = $YPos;
  1445. }
  1446. else
  1447. {
  1448. $PointsCount++; $Points[] = $XLast; $Points[] = $LayerHeight;
  1449. }
  1450. $YLast = $YPos; $XLast = $XPos;
  1451. $XPos = $XPos + $this->DivisionWidth * $Accuracy;
  1452. }
  1453. // Add potentialy missing values
  1454. $XPos = $XPos - $this->DivisionWidth * $Accuracy;
  1455. if ( $XPos < ($LayerWidth-$this->GAreaXOffset) )
  1456. {
  1457. $YPos = $LayerHeight - (($YIn[$Index]-$this->VMin) * $this->DivisionRatio);
  1458. if ( $YLast != NULL && $AroundZero )
  1459. {
  1460. $aPoints = "";
  1461. $aPoints[] = $XLast;
  1462. $aPoints[] = $YLast;
  1463. $aPoints[] = $LayerWidth-$this->GAreaXOffset;
  1464. $aPoints[] = $YPos;
  1465. $aPoints[] = $LayerWidth-$this->GAreaXOffset;
  1466. $aPoints[] = $YZero;
  1467. $aPoints[] = $XLast;
  1468. $aPoints[] = $YZero;
  1469. $C_Graph =$this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1470. imagefilledpolygon($this->Layers[0],$aPoints,4,$C_Graph);
  1471. }
  1472. if ( $YIn[$klo] != "" && $YIn[$khi] != "" || $YLast == NULL )
  1473. {
  1474. $PointsCount++;
  1475. $Points[] = $LayerWidth-$this->GAreaXOffset;
  1476. $Points[] = $YPos;
  1477. }
  1478. }
  1479. $Points[] = $LayerWidth-$this->GAreaXOffset;
  1480. $Points[] = $LayerHeight;
  1481. if ( !$AroundZero )
  1482. {
  1483. $C_Graph =$this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1484. imagefilledpolygon($this->Layers[0],$Points,$PointsCount,$C_Graph);
  1485. }
  1486. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  1487. imagedestroy($this->Layers[0]);
  1488. $this->drawCubicCurve($Data,$DataDescription,$Accuracy,$ColName);
  1489. $GraphID++;
  1490. }
  1491. }
  1492. /* This function draw a filled line graph */
  1493. function drawFilledLineGraph($Data,$DataDescription,$Alpha=100,$AroundZero=FALSE)
  1494. {
  1495. $Empty = -2147483647;
  1496. /* Validate the Data and DataDescription array */
  1497. $this->validateDataDescription("drawFilledLineGraph",$DataDescription);
  1498. $this->validateData("drawFilledLineGraph",$Data);
  1499. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1500. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1501. $GraphID = 0;
  1502. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1503. {
  1504. $ID = 0;
  1505. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1506. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1507. $aPoints = "";
  1508. $aPoints[] = $this->GAreaXOffset;
  1509. $aPoints[] = $LayerHeight;
  1510. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  1511. $C_White = $this->AllocateColor($this->Layers[0],255,255,255);
  1512. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  1513. imagecolortransparent($this->Layers[0],$C_White);
  1514. $XPos = $this->GAreaXOffset;
  1515. $XLast = -1; $PointsCount = 2;
  1516. $YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio);
  1517. if ( $YZero > $LayerHeight ) { $YZero = $LayerHeight; }
  1518. $YLast = $Empty;
  1519. foreach ( $Data as $Key => $Values )
  1520. {
  1521. $Value = $Data[$Key][$ColName];
  1522. $YPos = $LayerHeight - (($Value-$this->VMin) * $this->DivisionRatio);
  1523. /* Save point into the image map if option activated */
  1524. if ( $this->BuildMap )
  1525. $this->addToImageMap($XPos-3,$YPos-3,$XPos+3,$YPos+3,$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"FLine");
  1526. if ( !is_numeric($Value) )
  1527. {
  1528. $PointsCount++;
  1529. $aPoints[] = $XLast;
  1530. $aPoints[] = $LayerHeight;
  1531. $YLast = $Empty;
  1532. }
  1533. else
  1534. {
  1535. $PointsCount++;
  1536. if ( $YLast <> $Empty )
  1537. { $aPoints[] = $XPos; $aPoints[] = $YPos; }
  1538. else
  1539. { $PointsCount++; $aPoints[] = $XPos; $aPoints[] = $LayerHeight; $aPoints[] = $XPos; $aPoints[] = $YPos; }
  1540. if ($YLast <> $Empty && $AroundZero)
  1541. {
  1542. $Points = "";
  1543. $Points[] = $XLast; $Points[] = $YLast;
  1544. $Points[] = $XPos;
  1545. $Points[] = $YPos;
  1546. $Points[] = $XPos;
  1547. $Points[] = $YZero;
  1548. $Points[] = $XLast;
  1549. $Points[] = $YZero;
  1550. $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1551. imagefilledpolygon($this->Layers[0],$Points,4,$C_Graph);
  1552. }
  1553. $YLast = $YPos;
  1554. }
  1555. $XLast = $XPos;
  1556. $XPos = $XPos + $this->DivisionWidth;
  1557. }
  1558. $aPoints[] = $LayerWidth - $this->GAreaXOffset;
  1559. $aPoints[] = $LayerHeight;
  1560. if ( $AroundZero == FALSE )
  1561. {
  1562. $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1563. imagefilledpolygon($this->Layers[0],$aPoints,$PointsCount,$C_Graph);
  1564. }
  1565. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  1566. imagedestroy($this->Layers[0]);
  1567. $GraphID++;
  1568. $this->drawLineGraph($Data,$DataDescription,$ColName);
  1569. }
  1570. }
  1571. /* This function draw a bar graph */
  1572. function drawOverlayBarGraph($Data,$DataDescription,$Alpha=50)
  1573. {
  1574. /* Validate the Data and DataDescription array */
  1575. $this->validateDataDescription("drawOverlayBarGraph",$DataDescription);
  1576. $this->validateData("drawOverlayBarGraph",$Data);
  1577. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1578. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1579. $GraphID = 0;
  1580. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1581. {
  1582. $ID = 0;
  1583. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1584. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1585. $this->Layers[$GraphID] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  1586. $C_White = $this->AllocateColor($this->Layers[$GraphID],255,255,255);
  1587. $C_Graph = $this->AllocateColor($this->Layers[$GraphID],$this->Palette[$GraphID]["R"],$this->Palette[$GraphID]["G"],$this->Palette[$GraphID]["B"]);
  1588. imagefilledrectangle($this->Layers[$GraphID],0,0,$LayerWidth,$LayerHeight,$C_White);
  1589. imagecolortransparent($this->Layers[$GraphID],$C_White);
  1590. $XWidth = $this->DivisionWidth / 4;
  1591. $XPos = $this->GAreaXOffset;
  1592. $YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio);
  1593. $XLast = -1; $PointsCount = 2;
  1594. foreach ( $Data as $Key => $Values )
  1595. {
  1596. if ( isset($Data[$Key][$ColName]) )
  1597. {
  1598. $Value = $Data[$Key][$ColName];
  1599. if ( is_numeric($Value) )
  1600. {
  1601. $YPos = $LayerHeight - (($Value-$this->VMin) * $this->DivisionRatio);
  1602. imagefilledrectangle($this->Layers[$GraphID],$XPos-$XWidth,$YPos,$XPos+$XWidth,$YZero,$C_Graph);
  1603. $X1 = floor($XPos - $XWidth + $this->GArea_X1); $Y1 = floor($YPos+$this->GArea_Y1) + .2;
  1604. $X2 = floor($XPos + $XWidth + $this->GArea_X1); $Y2 = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio);
  1605. if ( $X1 <= $this->GArea_X1 ) { $X1 = $this->GArea_X1 + 1; }
  1606. if ( $X2 >= $this->GArea_X2 ) { $X2 = $this->GArea_X2 - 1; }
  1607. /* Save point into the image map if option activated */
  1608. if ( $this->BuildMap )
  1609. $this->addToImageMap($X1,min($Y1,$Y2),$X2,max($Y1,$Y2),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"oBar");
  1610. $this->drawLine($X1,$Y1,$X2,$Y1,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE);
  1611. }
  1612. }
  1613. $XPos = $XPos + $this->DivisionWidth;
  1614. }
  1615. $GraphID++;
  1616. }
  1617. for($i=0;$i<=($GraphID-1);$i++)
  1618. {
  1619. imagecopymerge($this->Picture,$this->Layers[$i],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  1620. imagedestroy($this->Layers[$i]);
  1621. }
  1622. }
  1623. /* This function draw a bar graph */
  1624. function drawBarGraph($Data,$DataDescription,$Shadow=FALSE,$Alpha=100)
  1625. {
  1626. /* Validate the Data and DataDescription array */
  1627. $this->validateDataDescription("drawBarGraph",$DataDescription);
  1628. $this->validateData("drawBarGraph",$Data);
  1629. $GraphID = 0;
  1630. $Series = count($DataDescription["Values"]);
  1631. $SeriesWidth = $this->DivisionWidth / ($Series+1);
  1632. $SerieXOffset = $this->DivisionWidth / 2 - $SeriesWidth / 2;
  1633. $YZero = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio);
  1634. if ( $YZero > $this->GArea_Y2 ) { $YZero = $this->GArea_Y2; }
  1635. $SerieID = 0;
  1636. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1637. {
  1638. $ID = 0;
  1639. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1640. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1641. $XPos = $this->GArea_X1 + $this->GAreaXOffset - $SerieXOffset + $SeriesWidth * $SerieID;
  1642. $XLast = -1;
  1643. foreach ( $Data as $Key => $Values )
  1644. {
  1645. if ( isset($Data[$Key][$ColName]))
  1646. {
  1647. if ( is_numeric($Data[$Key][$ColName]) )
  1648. {
  1649. $Value = $Data[$Key][$ColName];
  1650. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1651. /* Save point into the image map if option activated */
  1652. if ( $this->BuildMap )
  1653. {
  1654. $this->addToImageMap($XPos+1,min($YZero,$YPos),$XPos+$SeriesWidth-1,max($YZero,$YPos),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Bar");
  1655. }
  1656. if ( $Shadow && $Alpha == 100 )
  1657. $this->drawRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,25,25,25,TRUE,$Alpha);
  1658. $this->drawFilledRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1659. }
  1660. }
  1661. $XPos = $XPos + $this->DivisionWidth;
  1662. }
  1663. $SerieID++;
  1664. }
  1665. }
  1666. /* This function draw a stacked bar graph */
  1667. function drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE)
  1668. {
  1669. /* Validate the Data and DataDescription array */
  1670. $this->validateDataDescription("drawBarGraph",$DataDescription);
  1671. $this->validateData("drawBarGraph",$Data);
  1672. $GraphID = 0;
  1673. $Series = count($DataDescription["Values"]);
  1674. if ( $Contiguous )
  1675. $SeriesWidth = $this->DivisionWidth;
  1676. else
  1677. $SeriesWidth = $this->DivisionWidth * .8;
  1678. $YZero = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio);
  1679. if ( $YZero > $this->GArea_Y2 ) { $YZero = $this->GArea_Y2; }
  1680. $SerieID = 0; $LastValue = "";
  1681. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1682. {
  1683. $ID = 0;
  1684. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1685. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1686. $XPos = $this->GArea_X1 + $this->GAreaXOffset - $SeriesWidth / 2;
  1687. $XLast = -1;
  1688. foreach ( $Data as $Key => $Values )
  1689. {
  1690. if ( isset($Data[$Key][$ColName]))
  1691. {
  1692. if ( is_numeric($Data[$Key][$ColName]) )
  1693. {
  1694. $Value = $Data[$Key][$ColName];
  1695. if ( isset($LastValue[$Key]) )
  1696. {
  1697. $YPos = $this->GArea_Y2 - ((($Value+$LastValue[$Key])-$this->VMin) * $this->DivisionRatio);
  1698. $YBottom = $this->GArea_Y2 - (($LastValue[$Key]-$this->VMin) * $this->DivisionRatio);
  1699. $LastValue[$Key] += $Value;
  1700. }
  1701. else
  1702. {
  1703. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1704. $YBottom = $YZero;
  1705. $LastValue[$Key] = $Value;
  1706. }
  1707. /* Save point into the image map if option activated */
  1708. if ( $this->BuildMap )
  1709. $this->addToImageMap($XPos+1,min($YBottom,$YPos),$XPos+$SeriesWidth-1,max($YBottom,$YPos),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"sBar");
  1710. $this->drawFilledRectangle($XPos+1,$YBottom,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1711. }
  1712. }
  1713. $XPos = $XPos + $this->DivisionWidth;
  1714. }
  1715. $SerieID++;
  1716. }
  1717. }
  1718. /* This function draw a limits bar graphs */
  1719. function drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0)
  1720. {
  1721. /* Validate the Data and DataDescription array */
  1722. $this->validateDataDescription("drawLimitsGraph",$DataDescription);
  1723. $this->validateData("drawLimitsGraph",$Data);
  1724. $XWidth = $this->DivisionWidth / 4;
  1725. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1726. foreach ( $Data as $Key => $Values )
  1727. {
  1728. $Min = $Data[$Key][$DataDescription["Values"][0]];
  1729. $Max = $Data[$Key][$DataDescription["Values"][0]];
  1730. $GraphID = 0; $MaxID = 0; $MinID = 0;
  1731. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1732. {
  1733. if ( isset($Data[$Key][$ColName]) )
  1734. {
  1735. if ( $Data[$Key][$ColName] > $Max && is_numeric($Data[$Key][$ColName]))
  1736. { $Max = $Data[$Key][$ColName]; $MaxID = $GraphID; }
  1737. }
  1738. if ( isset($Data[$Key][$ColName]) && is_numeric($Data[$Key][$ColName]))
  1739. {
  1740. if ( $Data[$Key][$ColName] < $Min )
  1741. { $Min = $Data[$Key][$ColName]; $MinID = $GraphID; }
  1742. $GraphID++;
  1743. }
  1744. }
  1745. $YPos = $this->GArea_Y2 - (($Max-$this->VMin) * $this->DivisionRatio);
  1746. $X1 = floor($XPos - $XWidth); $Y1 = floor($YPos) - .2;
  1747. $X2 = floor($XPos + $XWidth);
  1748. if ( $X1 <= $this->GArea_X1 ) { $X1 = $this->GArea_X1 + 1; }
  1749. if ( $X2 >= $this->GArea_X2 ) { $X2 = $this->GArea_X2 - 1; }
  1750. $YPos = $this->GArea_Y2 - (($Min-$this->VMin) * $this->DivisionRatio);
  1751. $Y2 = floor($YPos) + .2;
  1752. $this->drawLine(floor($XPos)-.2,$Y1+1,floor($XPos)-.2,$Y2-1,$R,$G,$B,TRUE);
  1753. $this->drawLine(floor($XPos)+.2,$Y1+1,floor($XPos)+.2,$Y2-1,$R,$G,$B,TRUE);
  1754. $this->drawLine($X1,$Y1,$X2,$Y1,$this->Palette[$MaxID]["R"],$this->Palette[$MaxID]["G"],$this->Palette[$MaxID]["B"],FALSE);
  1755. $this->drawLine($X1,$Y2,$X2,$Y2,$this->Palette[$MinID]["R"],$this->Palette[$MinID]["G"],$this->Palette[$MinID]["B"],FALSE);
  1756. $XPos = $XPos + $this->DivisionWidth;
  1757. }
  1758. }
  1759. /* This function draw radar axis centered on the graph area */
  1760. function drawRadarAxis($Data,$DataDescription,$Mosaic=TRUE,$BorderOffset=10,$A_R=60,$A_G=60,$A_B=60,$S_R=200,$S_G=200,$S_B=200,$MaxValue=-1)
  1761. {
  1762. /* Validate the Data and DataDescription array */
  1763. $this->validateDataDescription("drawRadarAxis",$DataDescription);
  1764. $this->validateData("drawRadarAxis",$Data);
  1765. $C_TextColor = $this->AllocateColor($this->Picture,$A_R,$A_G,$A_B);
  1766. /* Draw radar axis */
  1767. $Points = count($Data);
  1768. $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset;
  1769. $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2 + $this->GArea_X1;
  1770. $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 + $this->GArea_Y1;
  1771. /* Search for the max value */
  1772. if ( $MaxValue == -1 )
  1773. {
  1774. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1775. {
  1776. foreach ( $Data as $Key => $Values )
  1777. {
  1778. if ( isset($Data[$Key][$ColName]))
  1779. if ( $Data[$Key][$ColName] > $MaxValue ) { $MaxValue = $Data[$Key][$ColName]; }
  1780. }
  1781. }
  1782. }
  1783. /* Draw the mosaic */
  1784. if ( $Mosaic )
  1785. {
  1786. $RadiusScale = $Radius / $MaxValue;
  1787. for ( $t=1; $t<=$MaxValue-1; $t++)
  1788. {
  1789. $TRadius = $RadiusScale * $t;
  1790. $LastX1 = -1;
  1791. for ( $i=0; $i<=$Points; $i++)
  1792. {
  1793. $Angle = -90 + $i * 360/$Points;
  1794. $X1 = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter;
  1795. $Y1 = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter;
  1796. $X2 = cos($Angle * 3.1418 / 180 ) * ($TRadius+$RadiusScale) + $XCenter;
  1797. $Y2 = sin($Angle * 3.1418 / 180 ) * ($TRadius+$RadiusScale) + $YCenter;
  1798. if ( $t % 2 == 1 && $LastX1 != -1)
  1799. {
  1800. $Plots = "";
  1801. $Plots[] = $X1; $Plots[] = $Y1;
  1802. $Plots[] = $X2; $Plots[] = $Y2;
  1803. $Plots[] = $LastX2; $Plots[] = $LastY2;
  1804. $Plots[] = $LastX1; $Plots[] = $LastY1;
  1805. $C_Graph = $this->AllocateColor($this->Picture,250,250,250);
  1806. imagefilledpolygon($this->Picture,$Plots,(count($Plots)+1)/2,$C_Graph);
  1807. }
  1808. $LastX1 = $X1; $LastY1= $Y1;
  1809. $LastX2 = $X2; $LastY2= $Y2;
  1810. }
  1811. }
  1812. }
  1813. /* Draw the spider web */
  1814. for ( $t=1; $t<=$MaxValue; $t++)
  1815. {
  1816. $TRadius = ( $Radius / $MaxValue ) * $t;
  1817. $LastX = -1;
  1818. for ( $i=0; $i<=$Points; $i++)
  1819. {
  1820. $Angle = -90 + $i * 360/$Points;
  1821. $X = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter;
  1822. $Y = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter;
  1823. if ( $LastX != -1 )
  1824. $this->drawDottedLine($LastX,$LastY,$X,$Y,4,$S_R,$S_G,$S_B);
  1825. $LastX = $X; $LastY= $Y;
  1826. }
  1827. }
  1828. /* Draw the axis */
  1829. for ( $i=0; $i<=$Points; $i++)
  1830. {
  1831. $Angle = -90 + $i * 360/$Points;
  1832. $X = cos($Angle * 3.1418 / 180 ) * $Radius + $XCenter;
  1833. $Y = sin($Angle * 3.1418 / 180 ) * $Radius + $YCenter;
  1834. $this->drawLine($XCenter,$YCenter,$X,$Y,$A_R,$A_G,$A_B);
  1835. $XOffset = 0; $YOffset = 0;
  1836. if (isset($Data[$i][$DataDescription["Position"]]))
  1837. {
  1838. $Label = $Data[$i][$DataDescription["Position"]];
  1839. $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$Label);
  1840. $Width = $Positions[2] - $Positions[6];
  1841. $Height = $Positions[3] - $Positions[7];
  1842. if ( $Angle >= 0 && $Angle <= 90 )
  1843. $YOffset = $Height;
  1844. if ( $Angle > 90 && $Angle <= 180 )
  1845. { $YOffset = $Height; $XOffset = -$Width; }
  1846. if ( $Angle > 180 && $Angle <= 270 )
  1847. { $XOffset = -$Width; }
  1848. imagettftext($this->Picture,$this->FontSize,0,$X+$XOffset,$Y+$YOffset,$C_TextColor,$this->FontName,$Label);
  1849. }
  1850. }
  1851. /* Write the values */
  1852. for ( $t=1; $t<=$MaxValue; $t++)
  1853. {
  1854. $TRadius = ( $Radius / $MaxValue ) * $t;
  1855. $Angle = -90 + 360 / $Points;
  1856. $X1 = $XCenter;
  1857. $Y1 = $YCenter - $TRadius;
  1858. $X2 = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter;
  1859. $Y2 = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter;
  1860. $XPos = floor(($X2-$X1)/2) + $X1;
  1861. $YPos = floor(($Y2-$Y1)/2) + $Y1;
  1862. $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$t);
  1863. $X = $XPos - ( $X+$Positions[2] - $X+$Positions[6] ) / 2;
  1864. $Y = $YPos + $this->FontSize;
  1865. $this->drawFilledRoundedRectangle($X+$Positions[6]-2,$Y+$Positions[7]-1,$X+$Positions[2]+4,$Y+$Positions[3]+1,2,240,240,240);
  1866. $this->drawRoundedRectangle($X+$Positions[6]-2,$Y+$Positions[7]-1,$X+$Positions[2]+4,$Y+$Positions[3]+1,2,220,220,220);
  1867. imagettftext($this->Picture,$this->FontSize,0,$X,$Y,$C_TextColor,$this->FontName,$t);
  1868. }
  1869. }
  1870. /* This function draw a radar graph centered on the graph area */
  1871. function drawRadar($Data,$DataDescription,$BorderOffset=10,$MaxValue=-1)
  1872. {
  1873. /* Validate the Data and DataDescription array */
  1874. $this->validateDataDescription("drawRadar",$DataDescription);
  1875. $this->validateData("drawRadar",$Data);
  1876. $Points = count($Data);
  1877. $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset;
  1878. $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2 + $this->GArea_X1;
  1879. $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 + $this->GArea_Y1;
  1880. /* Search for the max value */
  1881. if ( $MaxValue == -1 )
  1882. {
  1883. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1884. {
  1885. foreach ( $Data as $Key => $Values )
  1886. {
  1887. if ( isset($Data[$Key][$ColName]))
  1888. if ( $Data[$Key][$ColName] > $MaxValue ) { $MaxValue = $Data[$Key][$ColName]; }
  1889. }
  1890. }
  1891. }
  1892. $GraphID = 0;
  1893. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1894. {
  1895. $ID = 0;
  1896. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1897. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1898. $Angle = -90;
  1899. $XLast = -1;
  1900. foreach ( $Data as $Key => $Values )
  1901. {
  1902. if ( isset($Data[$Key][$ColName]))
  1903. {
  1904. $Value = $Data[$Key][$ColName];
  1905. $Strength = ( $Radius / $MaxValue ) * $Value;
  1906. $XPos = cos($Angle * 3.1418 / 180 ) * $Strength + $XCenter;
  1907. $YPos = sin($Angle * 3.1418 / 180 ) * $Strength + $YCenter;
  1908. if ( $XLast != -1 )
  1909. $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1910. if ( $XLast == -1 )
  1911. { $FirstX = $XPos; $FirstY = $YPos; }
  1912. $Angle = $Angle + (360/$Points);
  1913. $XLast = $XPos;
  1914. $YLast = $YPos;
  1915. }
  1916. }
  1917. $this->drawLine($XPos,$YPos,$FirstX,$FirstY,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1918. $GraphID++;
  1919. }
  1920. }
  1921. /* This function draw a radar graph centered on the graph area */
  1922. function drawFilledRadar($Data,$DataDescription,$Alpha=50,$BorderOffset=10,$MaxValue=-1)
  1923. {
  1924. /* Validate the Data and DataDescription array */
  1925. $this->validateDataDescription("drawFilledRadar",$DataDescription);
  1926. $this->validateData("drawFilledRadar",$Data);
  1927. $Points = count($Data);
  1928. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1929. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1930. $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset;
  1931. $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2;
  1932. $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2;
  1933. /* Search for the max value */
  1934. if ( $MaxValue == -1 )
  1935. {
  1936. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1937. {
  1938. foreach ( $Data as $Key => $Values )
  1939. {
  1940. if ( isset($Data[$Key][$ColName]))
  1941. if ( $Data[$Key][$ColName] > $MaxValue && is_numeric($Data[$Key][$ColName])) { $MaxValue = $Data[$Key][$ColName]; }
  1942. }
  1943. }
  1944. }
  1945. $GraphID = 0;
  1946. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1947. {
  1948. $ID = 0;
  1949. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1950. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1951. $Angle = -90;
  1952. $XLast = -1;
  1953. $Plots = "";
  1954. foreach ( $Data as $Key => $Values )
  1955. {
  1956. if ( isset($Data[$Key][$ColName]))
  1957. {
  1958. $Value = $Data[$Key][$ColName];
  1959. if ( !is_numeric($Value) ) { $Value = 0; }
  1960. $Strength = ( $Radius / $MaxValue ) * $Value;
  1961. $XPos = cos($Angle * 3.1418 / 180 ) * $Strength + $XCenter;
  1962. $YPos = sin($Angle * 3.1418 / 180 ) * $Strength + $YCenter;
  1963. $Plots[] = $XPos;
  1964. $Plots[] = $YPos;
  1965. $Angle = $Angle + (360/$Points);
  1966. $XLast = $XPos;
  1967. $YLast = $YPos;
  1968. }
  1969. }
  1970. if (isset($Plots[0]))
  1971. {
  1972. $Plots[] = $Plots[0];
  1973. $Plots[] = $Plots[1];
  1974. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  1975. $C_White = $this->AllocateColor($this->Layers[0],255,255,255);
  1976. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  1977. imagecolortransparent($this->Layers[0],$C_White);
  1978. $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1979. imagefilledpolygon($this->Layers[0],$Plots,(count($Plots)+1)/2,$C_Graph);
  1980. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  1981. imagedestroy($this->Layers[0]);
  1982. for($i=0;$i<=count($Plots)-4;$i=$i+2)
  1983. $this->drawLine($Plots[$i]+$this->GArea_X1,$Plots[$i+1]+$this->GArea_Y1,$Plots[$i+2]+$this->GArea_X1,$Plots[$i+3]+$this->GArea_Y1,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1984. }
  1985. $GraphID++;
  1986. }
  1987. }
  1988. /* This function draw a flat pie chart */
  1989. function drawBasicPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$R=255,$G=255,$B=255,$Decimals=0)
  1990. {
  1991. /* Validate the Data and DataDescription array */
  1992. $this->validateDataDescription("drawBasicPieGraph",$DataDescription,FALSE);
  1993. $this->validateData("drawBasicPieGraph",$Data);
  1994. /* Determine pie sum */
  1995. $Series = 0; $PieSum = 0;
  1996. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1997. {
  1998. if ( $ColName != $DataDescription["Position"] )
  1999. {
  2000. $Series++;
  2001. foreach ( $Data as $Key => $Values )
  2002. {
  2003. if ( isset($Data[$Key][$ColName]))
  2004. $PieSum = $PieSum + $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]];
  2005. }
  2006. }
  2007. }
  2008. /* Validate serie */
  2009. if ( $Series != 1 )
  2010. RaiseFatal("Pie chart can only accept one serie of data.");
  2011. $SpliceRatio = 360 / $PieSum;
  2012. $SplicePercent = 100 / $PieSum;
  2013. /* Calculate all polygons */
  2014. $Angle = 0; $TopPlots = "";
  2015. foreach($iValues as $Key => $Value)
  2016. {
  2017. $TopPlots[$Key][] = $XPos;
  2018. $TopPlots[$Key][] = $YPos;
  2019. /* Process labels position & size */
  2020. $Caption = "";
  2021. if ( !($DrawLabels == PIE_NOLABEL) )
  2022. {
  2023. $TAngle = $Angle+($Value*$SpliceRatio/2);
  2024. if ($DrawLabels == PIE_PERCENTAGE)
  2025. $Caption = (round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2026. elseif ($DrawLabels == PIE_LABELS)
  2027. $Caption = $iLabels[$Key];
  2028. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2029. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2030. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2031. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2032. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  2033. $TextWidth = $Position[2]-$Position[0];
  2034. $TextHeight = abs($Position[1])+abs($Position[3]);
  2035. $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius+10) + $XPos;
  2036. if ( $TAngle > 0 && $TAngle < 180 )
  2037. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+10) + $YPos + 4;
  2038. else
  2039. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+4) + $YPos - ($TextHeight/2);
  2040. if ( $TAngle > 90 && $TAngle < 270 )
  2041. $TX = $TX - $TextWidth;
  2042. $C_TextColor = $this->AllocateColor($this->Picture,70,70,70);
  2043. imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption);
  2044. }
  2045. /* Process pie slices */
  2046. for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5)
  2047. {
  2048. $TopX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos;
  2049. $TopY = sin($iAngle * 3.1418 / 180 ) * $Radius + $YPos;
  2050. $TopPlots[$Key][] = $TopX;
  2051. $TopPlots[$Key][] = $TopY;
  2052. }
  2053. $TopPlots[$Key][] = $XPos;
  2054. $TopPlots[$Key][] = $YPos;
  2055. $Angle = $iAngle;
  2056. }
  2057. $PolyPlots = $TopPlots;
  2058. /* Set array values type to float --- PHP Bug with imagefilledpolygon casting to integer */
  2059. foreach ($TopPlots as $Key => $Value)
  2060. { foreach ($TopPlots[$Key] as $Key2 => $Value2) { settype($TopPlots[$Key][$Key2],"float"); } }
  2061. /* Draw Top polygons */
  2062. foreach ($PolyPlots as $Key => $Value)
  2063. {
  2064. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]);
  2065. imagefilledpolygon($this->Picture,$PolyPlots[$Key],(count($PolyPlots[$Key])+1)/2,$C_GraphLo);
  2066. }
  2067. $this->drawCircle($XPos-.5,$YPos-.5,$Radius,$R,$G,$B);
  2068. $this->drawCircle($XPos-.5,$YPos-.5,$Radius+.5,$R,$G,$B);
  2069. /* Draw Top polygons */
  2070. foreach ($TopPlots as $Key => $Value)
  2071. {
  2072. for($j=0;$j<=count($TopPlots[$Key])-4;$j=$j+2)
  2073. $this->drawLine($TopPlots[$Key][$j],$TopPlots[$Key][$j+1],$TopPlots[$Key][$j+2],$TopPlots[$Key][$j+3],$R,$G,$B);
  2074. }
  2075. }
  2076. function drawFlatPieGraphWithShadow($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals=0)
  2077. {
  2078. $this->drawFlatPieGraph($Data,$DataDescription,$XPos+$this->ShadowXDistance,$YPos+$this->ShadowYDistance,$Radius,PIE_NOLABEL,$SpliceDistance,$Decimals,TRUE);
  2079. $this->drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius,$DrawLabels,$SpliceDistance,$Decimals,FALSE);
  2080. }
  2081. /* This function draw a flat pie chart */
  2082. function drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals=0,$AllBlack=FALSE)
  2083. {
  2084. /* Validate the Data and DataDescription array */
  2085. $this->validateDataDescription("drawFlatPieGraph",$DataDescription,FALSE);
  2086. $this->validateData("drawFlatPieGraph",$Data);
  2087. $ShadowStatus = $this->ShadowActive ; $this->ShadowActive = FALSE;
  2088. /* Determine pie sum */
  2089. $Series = 0; $PieSum = 0;
  2090. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2091. {
  2092. if ( $ColName != $DataDescription["Position"] )
  2093. {
  2094. $Series++;
  2095. foreach ( $Data as $Key => $Values )
  2096. {
  2097. if ( isset($Data[$Key][$ColName]))
  2098. $PieSum = $PieSum + $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]];
  2099. }
  2100. }
  2101. }
  2102. /* Validate serie */
  2103. if ( $Series != 1 )
  2104. {
  2105. RaiseFatal("Pie chart can only accept one serie of data.");
  2106. return(0);
  2107. }
  2108. $SpliceRatio = 360 / $PieSum;
  2109. $SplicePercent = 100 / $PieSum;
  2110. /* Calculate all polygons */
  2111. $Angle = 0; $TopPlots = "";
  2112. foreach($iValues as $Key => $Value)
  2113. {
  2114. $XOffset = cos(($Angle+($Value/2*$SpliceRatio)) * 3.1418 / 180 ) * $SpliceDistance;
  2115. $YOffset = sin(($Angle+($Value/2*$SpliceRatio)) * 3.1418 / 180 ) * $SpliceDistance;
  2116. $TopPlots[$Key][] = round($XPos + $XOffset);
  2117. $TopPlots[$Key][] = round($YPos + $YOffset);
  2118. if ( $AllBlack )
  2119. { $Rc = $this->ShadowRColor; $Gc = $this->ShadowGColor; $Bc = $this->ShadowBColor; }
  2120. else
  2121. { $Rc = $this->Palette[$Key]["R"]; $Gc = $this->Palette[$Key]["G"]; $Bc = $this->Palette[$Key]["B"]; }
  2122. $XLineLast = ""; $YLineLast = "";
  2123. /* Process labels position & size */
  2124. $Caption = "";
  2125. if ( !($DrawLabels == PIE_NOLABEL) )
  2126. {
  2127. $TAngle = $Angle+($Value*$SpliceRatio/2);
  2128. if ($DrawLabels == PIE_PERCENTAGE)
  2129. $Caption = (round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2130. elseif ($DrawLabels == PIE_LABELS)
  2131. $Caption = $iLabels[$Key];
  2132. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2133. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2134. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2135. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2136. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  2137. $TextWidth = $Position[2]-$Position[0];
  2138. $TextHeight = abs($Position[1])+abs($Position[3]);
  2139. $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius+10+$SpliceDistance) + $XPos;
  2140. if ( $TAngle > 0 && $TAngle < 180 )
  2141. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+10+$SpliceDistance) + $YPos + 4;
  2142. else
  2143. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+$SpliceDistance+4) + $YPos - ($TextHeight/2);
  2144. if ( $TAngle > 90 && $TAngle < 270 )
  2145. $TX = $TX - $TextWidth;
  2146. $C_TextColor = $this->AllocateColor($this->Picture,70,70,70);
  2147. imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption);
  2148. }
  2149. /* Process pie slices */
  2150. if ( !$AllBlack )
  2151. $LineColor = $this->AllocateColor($this->Picture,$Rc,$Gc,$Bc);
  2152. else
  2153. $LineColor = $this->AllocateColor($this->Picture,$Rc,$Gc,$Bc);
  2154. $XLineLast = ""; $YLineLast = "";
  2155. for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5)
  2156. {
  2157. $PosX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos + $XOffset;
  2158. $PosY = sin($iAngle * 3.1418 / 180 ) * $Radius + $YPos + $YOffset;
  2159. $TopPlots[$Key][] = round($PosX); $TopPlots[$Key][] = round($PosY);
  2160. if ( $iAngle == $Angle || $iAngle == $Angle+$Value*$SpliceRatio || $iAngle +.5 > $Angle+$Value*$SpliceRatio)
  2161. $this->drawLine($XPos+$XOffset,$YPos+$YOffset,$PosX,$PosY,$Rc,$Gc,$Bc);
  2162. if ( $XLineLast != "" )
  2163. $this->drawLine($XLineLast,$YLineLast,$PosX,$PosY,$Rc,$Gc,$Bc);
  2164. $XLineLast = $PosX; $YLineLast = $PosY;
  2165. }
  2166. $TopPlots[$Key][] = round($XPos + $XOffset); $TopPlots[$Key][] = round($YPos + $YOffset);
  2167. $Angle = $iAngle;
  2168. }
  2169. $PolyPlots = $TopPlots;
  2170. /* Draw Top polygons */
  2171. foreach ($PolyPlots as $Key => $Value)
  2172. {
  2173. if ( !$AllBlack )
  2174. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]);
  2175. else
  2176. $C_GraphLo = $this->AllocateColor($this->Picture,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor);
  2177. imagefilledpolygon($this->Picture,$PolyPlots[$Key],(count($PolyPlots[$Key])+1)/2,$C_GraphLo);
  2178. }
  2179. $this->ShadowActive = $ShadowStatus;
  2180. }
  2181. /* This function draw a pseudo-3D pie chart */
  2182. function drawPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$EnhanceColors=TRUE,$Skew=60,$SpliceHeight=20,$SpliceDistance=0,$Decimals=0)
  2183. {
  2184. /* Validate the Data and DataDescription array */
  2185. $this->validateDataDescription("drawPieGraph",$DataDescription,FALSE);
  2186. $this->validateData("drawPieGraph",$Data);
  2187. /* Determine pie sum */
  2188. $Series = 0; $PieSum = 0; $rPieSum = 0;
  2189. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2190. {
  2191. if ( $ColName != $DataDescription["Position"] )
  2192. {
  2193. $Series++;
  2194. foreach ( $Data as $Key => $Values )
  2195. if ( isset($Data[$Key][$ColName]))
  2196. {
  2197. if ( $Data[$Key][$ColName] == 0 )
  2198. { $iValues[] = 0; $rValues[] = 0; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; }
  2199. // Removed : $PieSum++; $rValues[] = 1;
  2200. else
  2201. { $PieSum += $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; $rValues[] = $Data[$Key][$ColName]; $rPieSum += $Data[$Key][$ColName];}
  2202. }
  2203. }
  2204. }
  2205. /* Validate serie */
  2206. if ( $Series != 1 )
  2207. RaiseFatal("Pie chart can only accept one serie of data.");
  2208. $SpliceDistanceRatio = $SpliceDistance;
  2209. $SkewHeight = ($Radius * $Skew) / 100;
  2210. $SpliceRatio = (360 - $SpliceDistanceRatio * count($iValues) ) / $PieSum;
  2211. $SplicePercent = 100 / $PieSum;
  2212. $rSplicePercent = 100 / $rPieSum;
  2213. /* Calculate all polygons */
  2214. $Angle = 0; $CDev = 5;
  2215. $TopPlots = ""; $BotPlots = "";
  2216. $aTopPlots = ""; $aBotPlots = "";
  2217. foreach($iValues as $Key => $Value)
  2218. {
  2219. $XCenterPos = cos(($Angle-$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $XPos;
  2220. $YCenterPos = sin(($Angle-$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $YPos;
  2221. $XCenterPos2 = cos(($Angle+$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $XPos;
  2222. $YCenterPos2 = sin(($Angle+$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $YPos;
  2223. $TopPlots[$Key][] = round($XCenterPos); $BotPlots[$Key][] = round($XCenterPos);
  2224. $TopPlots[$Key][] = round($YCenterPos); $BotPlots[$Key][] = round($YCenterPos + $SpliceHeight);
  2225. $aTopPlots[$Key][] = $XCenterPos; $aBotPlots[$Key][] = $XCenterPos;
  2226. $aTopPlots[$Key][] = $YCenterPos; $aBotPlots[$Key][] = $YCenterPos + $SpliceHeight;
  2227. /* Process labels position & size */
  2228. $Caption = "";
  2229. if ( !($DrawLabels == PIE_NOLABEL) )
  2230. {
  2231. $TAngle = $Angle+($Value*$SpliceRatio/2);
  2232. if ($DrawLabels == PIE_PERCENTAGE)
  2233. $Caption = (round($rValues[$Key] * pow(10,$Decimals) * $rSplicePercent)/pow(10,$Decimals))."%";
  2234. elseif ($DrawLabels == PIE_LABELS)
  2235. $Caption = $iLabels[$Key];
  2236. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2237. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2238. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  2239. $TextWidth = $Position[2]-$Position[0];
  2240. $TextHeight = abs($Position[1])+abs($Position[3]);
  2241. $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius + 10)+ $XPos;
  2242. if ( $TAngle > 0 && $TAngle < 180 )
  2243. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($SkewHeight + 10) + $YPos + $SpliceHeight + 4;
  2244. else
  2245. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($SkewHeight + 4) + $YPos - ($TextHeight/2);
  2246. if ( $TAngle > 90 && $TAngle < 270 )
  2247. $TX = $TX - $TextWidth;
  2248. $C_TextColor = $this->AllocateColor($this->Picture,70,70,70);
  2249. imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption);
  2250. }
  2251. /* Process pie slices */
  2252. for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5)
  2253. {
  2254. $TopX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos;
  2255. $TopY = sin($iAngle * 3.1418 / 180 ) * $SkewHeight + $YPos;
  2256. $TopPlots[$Key][] = round($TopX); $BotPlots[$Key][] = round($TopX);
  2257. $TopPlots[$Key][] = round($TopY); $BotPlots[$Key][] = round($TopY + $SpliceHeight);
  2258. $aTopPlots[$Key][] = $TopX; $aBotPlots[$Key][] = $TopX;
  2259. $aTopPlots[$Key][] = $TopY; $aBotPlots[$Key][] = $TopY + $SpliceHeight;
  2260. }
  2261. $TopPlots[$Key][] = round($XCenterPos2); $BotPlots[$Key][] = round($XCenterPos2);
  2262. $TopPlots[$Key][] = round($YCenterPos2); $BotPlots[$Key][] = round($YCenterPos2 + $SpliceHeight);
  2263. $aTopPlots[$Key][] = $XCenterPos2; $aBotPlots[$Key][] = $XCenterPos2;
  2264. $aTopPlots[$Key][] = $YCenterPos2; $aBotPlots[$Key][] = $YCenterPos2 + $SpliceHeight;
  2265. $Angle = $iAngle + $SpliceDistanceRatio;
  2266. }
  2267. /* Draw Bottom polygons */
  2268. foreach($iValues as $Key => $Value)
  2269. {
  2270. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"],-20);
  2271. imagefilledpolygon($this->Picture,$BotPlots[$Key],(count($BotPlots[$Key])+1)/2,$C_GraphLo);
  2272. if ( $EnhanceColors ) { $En = -10; } else { $En = 0; }
  2273. for($j=0;$j<=count($aBotPlots[$Key])-4;$j=$j+2)
  2274. $this->drawLine($aBotPlots[$Key][$j],$aBotPlots[$Key][$j+1],$aBotPlots[$Key][$j+2],$aBotPlots[$Key][$j+3],$this->Palette[$Key]["R"]+$En,$this->Palette[$Key]["G"]+$En,$this->Palette[$Key]["B"]+$En);
  2275. }
  2276. /* Draw pie layers */
  2277. if ( $EnhanceColors ) { $ColorRatio = 30 / $SpliceHeight; } else { $ColorRatio = 25 / $SpliceHeight; }
  2278. for($i=$SpliceHeight-1;$i>=1;$i--)
  2279. {
  2280. foreach($iValues as $Key => $Value)
  2281. {
  2282. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"],-10);
  2283. $Plots = ""; $Plot = 0;
  2284. foreach($TopPlots[$Key] as $Key2 => $Value2)
  2285. {
  2286. $Plot++;
  2287. if ( $Plot % 2 == 1 )
  2288. $Plots[] = $Value2;
  2289. else
  2290. $Plots[] = $Value2+$i;
  2291. }
  2292. imagefilledpolygon($this->Picture,$Plots,(count($Plots)+1)/2,$C_GraphLo);
  2293. $Index = count($Plots);
  2294. if ($EnhanceColors ) {$ColorFactor = -20 + ($SpliceHeight - $i) * $ColorRatio; } else { $ColorFactor = 0; }
  2295. $this->drawAntialiasPixel($Plots[0],$Plots[1],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor);
  2296. $this->drawAntialiasPixel($Plots[2],$Plots[3],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor);
  2297. $this->drawAntialiasPixel($Plots[$Index-4],$Plots[$Index-3],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor);
  2298. }
  2299. }
  2300. /* Draw Top polygons */
  2301. for($Key=count($iValues)-1;$Key>=0;$Key--)
  2302. {
  2303. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]);
  2304. imagefilledpolygon($this->Picture,$TopPlots[$Key],(count($TopPlots[$Key])+1)/2,$C_GraphLo);
  2305. if ( $EnhanceColors ) { $En = 10; } else { $En = 0; }
  2306. for($j=0;$j<=count($aTopPlots[$Key])-4;$j=$j+2)
  2307. $this->drawLine($aTopPlots[$Key][$j],$aTopPlots[$Key][$j+1],$aTopPlots[$Key][$j+2],$aTopPlots[$Key][$j+3],$this->Palette[$Key]["R"]+$En,$this->Palette[$Key]["G"]+$En,$this->Palette[$Key]["B"]+$En);
  2308. }
  2309. }
  2310. /* This function can be used to set the background color */
  2311. function drawBackground($R,$G,$B)
  2312. {
  2313. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2314. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2315. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2316. $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B);
  2317. imagefilledrectangle($this->Picture,0,0,$this->XSize,$this->YSize,$C_Background);
  2318. }
  2319. /* This function can be used to set the background color */
  2320. function drawGraphAreaGradient($R,$G,$B,$Decay,$Target=TARGET_GRAPHAREA)
  2321. {
  2322. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2323. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2324. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2325. if ( $Target == TARGET_GRAPHAREA ) { $X1 = $this->GArea_X1+1; $X2 = $this->GArea_X2-1; $Y1 = $this->GArea_Y1+1; $Y2 = $this->GArea_Y2; }
  2326. if ( $Target == TARGET_BACKGROUND ) { $X1 = 0; $X2 = $this->XSize; $Y1 = 0; $Y2 = $this->YSize; }
  2327. /* Positive gradient */
  2328. if ( $Decay > 0 )
  2329. {
  2330. $YStep = ($Y2 - $Y1 - 2) / $Decay;
  2331. for($i=0;$i<=$Decay;$i++)
  2332. {
  2333. $R-=1;$G-=1;$B-=1;
  2334. $Yi1 = $Y1 + ( $i * $YStep );
  2335. $Yi2 = ceil( $Yi1 + ( $i * $YStep ) + $YStep );
  2336. if ( $Yi2 >= $Yi2 ) { $Yi2 = $Y2-1; }
  2337. $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B);
  2338. imagefilledrectangle($this->Picture,$X1,$Yi1,$X2,$Yi2,$C_Background);
  2339. }
  2340. }
  2341. /* Negative gradient */
  2342. if ( $Decay < 0 )
  2343. {
  2344. $YStep = ($Y2 - $Y1 - 2) / -$Decay;
  2345. $Yi1 = $Y1; $Yi2 = $Y1+$YStep;
  2346. for($i=-$Decay;$i>=0;$i--)
  2347. {
  2348. $R+=1;$G+=1;$B+=1;
  2349. $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B);
  2350. imagefilledrectangle($this->Picture,$X1,$Yi1,$X2,$Yi2,$C_Background);
  2351. $Yi1+= $YStep;
  2352. $Yi2+= $YStep;
  2353. if ( $Yi2 >= $Yi2 ) { $Yi2 = $Y2-1; }
  2354. }
  2355. }
  2356. }
  2357. /* This function create a rectangle with antialias */
  2358. function drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B)
  2359. {
  2360. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2361. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2362. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2363. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2364. $X1=$X1-.2;$Y1=$Y1-.2;
  2365. $X2=$X2+.2;$Y2=$Y2+.2;
  2366. $this->drawLine($X1,$Y1,$X2,$Y1,$R,$G,$B);
  2367. $this->drawLine($X2,$Y1,$X2,$Y2,$R,$G,$B);
  2368. $this->drawLine($X2,$Y2,$X1,$Y2,$R,$G,$B);
  2369. $this->drawLine($X1,$Y2,$X1,$Y1,$R,$G,$B);
  2370. }
  2371. /* This function create a filled rectangle with antialias */
  2372. function drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B,$DrawBorder=TRUE,$Alpha=100,$NoFallBack=FALSE)
  2373. {
  2374. if ( $X2 < $X1 ) { list($X1, $X2) = array($X2, $X1); }
  2375. if ( $Y2 < $Y1 ) { list($Y1, $Y2) = array($Y2, $Y1); }
  2376. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2377. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2378. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2379. if ( $Alpha == 100 )
  2380. {
  2381. /* Process shadows */
  2382. if ( $this->ShadowActive && !$NoFallBack )
  2383. {
  2384. $this->drawFilledRectangle($X1+$this->ShadowXDistance,$Y1+$this->ShadowYDistance,$X2+$this->ShadowXDistance,$Y2+$this->ShadowYDistance,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,FALSE,$this->ShadowAlpha,TRUE);
  2385. if ( $this->ShadowBlur != 0 )
  2386. {
  2387. $AlphaDecay = ($this->ShadowAlpha / $this->ShadowBlur);
  2388. for($i=1; $i<=$this->ShadowBlur; $i++)
  2389. $this->drawFilledRectangle($X1+$this->ShadowXDistance-$i/2,$Y1+$this->ShadowYDistance-$i/2,$X2+$this->ShadowXDistance-$i/2,$Y2+$this->ShadowYDistance-$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,FALSE,$this->ShadowAlpha-$AlphaDecay*$i,TRUE);
  2390. for($i=1; $i<=$this->ShadowBlur; $i++)
  2391. $this->drawFilledRectangle($X1+$this->ShadowXDistance+$i/2,$Y1+$this->ShadowYDistance+$i/2,$X2+$this->ShadowXDistance+$i/2,$Y2+$this->ShadowYDistance+$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,FALSE,$this->ShadowAlpha-$AlphaDecay*$i,TRUE);
  2392. }
  2393. }
  2394. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2395. imagefilledrectangle($this->Picture,round($X1),round($Y1),round($X2),round($Y2),$C_Rectangle);
  2396. }
  2397. else
  2398. {
  2399. $LayerWidth = abs($X2-$X1)+2;
  2400. $LayerHeight = abs($Y2-$Y1)+2;
  2401. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  2402. $C_White = $this->AllocateColor($this->Layers[0],255,255,255);
  2403. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  2404. imagecolortransparent($this->Layers[0],$C_White);
  2405. $C_Rectangle = $this->AllocateColor($this->Layers[0],$R,$G,$B);
  2406. imagefilledrectangle($this->Layers[0],round(1),round(1),round($LayerWidth-1),round($LayerHeight-1),$C_Rectangle);
  2407. imagecopymerge($this->Picture,$this->Layers[0],round(min($X1,$X2)-1),round(min($Y1,$Y2)-1),0,0,$LayerWidth,$LayerHeight,$Alpha);
  2408. imagedestroy($this->Layers[0]);
  2409. }
  2410. if ( $DrawBorder )
  2411. {
  2412. $ShadowSettings = $this->ShadowActive; $this->ShadowActive = FALSE;
  2413. $this->drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B);
  2414. $this->ShadowActive = $ShadowSettings;
  2415. }
  2416. }
  2417. /* This function create a rectangle with rounded corners and antialias */
  2418. function drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
  2419. {
  2420. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2421. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2422. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2423. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2424. $Step = 90 / ((3.1418 * $Radius)/2);
  2425. for($i=0;$i<=90;$i=$i+$Step)
  2426. {
  2427. $X = cos(($i+180)*3.1418/180) * $Radius + $X1 + $Radius;
  2428. $Y = sin(($i+180)*3.1418/180) * $Radius + $Y1 + $Radius;
  2429. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2430. $X = cos(($i-90)*3.1418/180) * $Radius + $X2 - $Radius;
  2431. $Y = sin(($i-90)*3.1418/180) * $Radius + $Y1 + $Radius;
  2432. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2433. $X = cos(($i)*3.1418/180) * $Radius + $X2 - $Radius;
  2434. $Y = sin(($i)*3.1418/180) * $Radius + $Y2 - $Radius;
  2435. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2436. $X = cos(($i+90)*3.1418/180) * $Radius + $X1 + $Radius;
  2437. $Y = sin(($i+90)*3.1418/180) * $Radius + $Y2 - $Radius;
  2438. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2439. }
  2440. $X1=$X1-.2;$Y1=$Y1-.2;
  2441. $X2=$X2+.2;$Y2=$Y2+.2;
  2442. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$R,$G,$B);
  2443. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$R,$G,$B);
  2444. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$R,$G,$B);
  2445. $this->drawLine($X1,$Y2-$Radius,$X1,$Y1+$Radius,$R,$G,$B);
  2446. }
  2447. /* This function create a filled rectangle with rounded corners and antialias */
  2448. function drawFilledRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
  2449. {
  2450. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2451. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2452. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2453. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2454. $Step = 90 / ((3.1418 * $Radius)/2);
  2455. for($i=0;$i<=90;$i=$i+$Step)
  2456. {
  2457. $Xi1 = cos(($i+180)*3.1418/180) * $Radius + $X1 + $Radius;
  2458. $Yi1 = sin(($i+180)*3.1418/180) * $Radius + $Y1 + $Radius;
  2459. $Xi2 = cos(($i-90)*3.1418/180) * $Radius + $X2 - $Radius;
  2460. $Yi2 = sin(($i-90)*3.1418/180) * $Radius + $Y1 + $Radius;
  2461. $Xi3 = cos(($i)*3.1418/180) * $Radius + $X2 - $Radius;
  2462. $Yi3 = sin(($i)*3.1418/180) * $Radius + $Y2 - $Radius;
  2463. $Xi4 = cos(($i+90)*3.1418/180) * $Radius + $X1 + $Radius;
  2464. $Yi4 = sin(($i+90)*3.1418/180) * $Radius + $Y2 - $Radius;
  2465. imageline($this->Picture,$Xi1,$Yi1,$X1+$Radius,$Yi1,$C_Rectangle);
  2466. imageline($this->Picture,$X2-$Radius,$Yi2,$Xi2,$Yi2,$C_Rectangle);
  2467. imageline($this->Picture,$X2-$Radius,$Yi3,$Xi3,$Yi3,$C_Rectangle);
  2468. imageline($this->Picture,$Xi4,$Yi4,$X1+$Radius,$Yi4,$C_Rectangle);
  2469. $this->drawAntialiasPixel($Xi1,$Yi1,$R,$G,$B);
  2470. $this->drawAntialiasPixel($Xi2,$Yi2,$R,$G,$B);
  2471. $this->drawAntialiasPixel($Xi3,$Yi3,$R,$G,$B);
  2472. $this->drawAntialiasPixel($Xi4,$Yi4,$R,$G,$B);
  2473. }
  2474. imagefilledrectangle($this->Picture,$X1,$Y1+$Radius,$X2,$Y2-$Radius,$C_Rectangle);
  2475. imagefilledrectangle($this->Picture,$X1+$Radius,$Y1,$X2-$Radius,$Y2,$C_Rectangle);
  2476. $X1=$X1-.2;$Y1=$Y1-.2;
  2477. $X2=$X2+.2;$Y2=$Y2+.2;
  2478. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$R,$G,$B);
  2479. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$R,$G,$B);
  2480. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$R,$G,$B);
  2481. $this->drawLine($X1,$Y2-$Radius,$X1,$Y1+$Radius,$R,$G,$B);
  2482. }
  2483. /* This function create a circle with antialias */
  2484. function drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
  2485. {
  2486. if ( $Width == 0 ) { $Width = $Height; }
  2487. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2488. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2489. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2490. $C_Circle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2491. $Step = 360 / (2 * 3.1418 * max($Width,$Height));
  2492. for($i=0;$i<=360;$i=$i+$Step)
  2493. {
  2494. $X = cos($i*3.1418/180) * $Height + $Xc;
  2495. $Y = sin($i*3.1418/180) * $Width + $Yc;
  2496. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2497. }
  2498. }
  2499. /* This function create a filled circle/ellipse with antialias */
  2500. function drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
  2501. {
  2502. if ( $Width == 0 ) { $Width = $Height; }
  2503. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2504. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2505. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2506. $C_Circle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2507. $Step = 360 / (2 * 3.1418 * max($Width,$Height));
  2508. for($i=90;$i<=270;$i=$i+$Step)
  2509. {
  2510. $X1 = cos($i*3.1418/180) * $Height + $Xc;
  2511. $Y1 = sin($i*3.1418/180) * $Width + $Yc;
  2512. $X2 = cos((180-$i)*3.1418/180) * $Height + $Xc;
  2513. $Y2 = sin((180-$i)*3.1418/180) * $Width + $Yc;
  2514. $this->drawAntialiasPixel($X1-1,$Y1-1,$R,$G,$B);
  2515. $this->drawAntialiasPixel($X2-1,$Y2-1,$R,$G,$B);
  2516. if ( ($Y1-1) > $Yc - max($Width,$Height) )
  2517. imageline($this->Picture,$X1,$Y1-1,$X2-1,$Y2-1,$C_Circle);
  2518. }
  2519. }
  2520. /* This function will draw a filled ellipse */
  2521. function drawEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
  2522. { $this->drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width); }
  2523. /* This function will draw an ellipse */
  2524. function drawFilledEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
  2525. { $this->drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width); }
  2526. /* This function create a line with antialias */
  2527. function drawLine($X1,$Y1,$X2,$Y2,$R,$G,$B,$GraphFunction=FALSE)
  2528. {
  2529. if ( $this->LineDotSize > 1 ) { $this->drawDottedLine($X1,$Y1,$X2,$Y2,$this->LineDotSize,$R,$G,$B,$GraphFunction); return(0); }
  2530. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2531. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2532. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2533. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  2534. if ( $Distance == 0 )
  2535. return(-1);
  2536. $XStep = ($X2-$X1) / $Distance;
  2537. $YStep = ($Y2-$Y1) / $Distance;
  2538. for($i=0;$i<=$Distance;$i++)
  2539. {
  2540. $X = $i * $XStep + $X1;
  2541. $Y = $i * $YStep + $Y1;
  2542. if ( ($X >= $this->GArea_X1 && $X <= $this->GArea_X2 && $Y >= $this->GArea_Y1 && $Y <= $this->GArea_Y2) || !$GraphFunction )
  2543. {
  2544. if ( $this->LineWidth == 1 )
  2545. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2546. else
  2547. {
  2548. $StartOffset = -($this->LineWidth/2); $EndOffset = ($this->LineWidth/2);
  2549. for($j=$StartOffset;$j<=$EndOffset;$j++)
  2550. $this->drawAntialiasPixel($X+$j,$Y+$j,$R,$G,$B);
  2551. }
  2552. }
  2553. }
  2554. }
  2555. /* This function create a line with antialias */
  2556. function drawDottedLine($X1,$Y1,$X2,$Y2,$DotSize,$R,$G,$B,$GraphFunction=FALSE)
  2557. {
  2558. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2559. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2560. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2561. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  2562. $XStep = ($X2-$X1) / $Distance;
  2563. $YStep = ($Y2-$Y1) / $Distance;
  2564. $DotIndex = 0;
  2565. for($i=0;$i<=$Distance;$i++)
  2566. {
  2567. $X = $i * $XStep + $X1;
  2568. $Y = $i * $YStep + $Y1;
  2569. if ( $DotIndex <= $DotSize)
  2570. {
  2571. if ( ($X >= $this->GArea_X1 && $X <= $this->GArea_X2 && $Y >= $this->GArea_Y1 && $Y <= $this->GArea_Y2) || !$GraphFunction )
  2572. {
  2573. if ( $this->LineWidth == 1 )
  2574. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2575. else
  2576. {
  2577. $StartOffset = -($this->LineWidth/2); $EndOffset = ($this->LineWidth/2);
  2578. for($j=$StartOffset;$j<=$EndOffset;$j++)
  2579. $this->drawAntialiasPixel($X+$j,$Y+$j,$R,$G,$B);
  2580. }
  2581. }
  2582. }
  2583. $DotIndex++;
  2584. if ( $DotIndex == $DotSize * 2 )
  2585. $DotIndex = 0;
  2586. }
  2587. }
  2588. /* Load a PNG file and draw it over the chart */
  2589. function drawFromPNG($FileName,$X,$Y,$Alpha=100)
  2590. { $this->drawFromPicture(1,$FileName,$X,$Y,$Alpha); }
  2591. /* Load a GIF file and draw it over the chart */
  2592. function drawFromGIF($FileName,$X,$Y,$Alpha=100)
  2593. { $this->drawFromPicture(2,$FileName,$X,$Y,$Alpha); }
  2594. /* Load a JPEG file and draw it over the chart */
  2595. function drawFromJPG($FileName,$X,$Y,$Alpha=100)
  2596. { $this->drawFromPicture(3,$FileName,$X,$Y,$Alpha); }
  2597. /* Generic loader function for external pictures */
  2598. function drawFromPicture($PicType,$FileName,$X,$Y,$Alpha=100)
  2599. {
  2600. if ( file_exists($FileName))
  2601. {
  2602. $Infos = getimagesize($FileName);
  2603. $Width = $Infos[0];
  2604. $Height = $Infos[1];
  2605. if ( $PicType == 1 ) { $Raster = imagecreatefrompng($FileName); }
  2606. if ( $PicType == 2 ) { $Raster = imagecreatefromgif($FileName); }
  2607. if ( $PicType == 3 ) { $Raster = imagecreatefromjpeg($FileName); }
  2608. imagecopymerge($this->Picture,$Raster,$X,$Y,0,0,$Width,$Height,$Alpha);
  2609. imagedestroy($Raster);
  2610. }
  2611. }
  2612. /* Draw an alpha pixel */
  2613. function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
  2614. {
  2615. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2616. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2617. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2618. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  2619. return(-1);
  2620. $RGB2 = imagecolorat($this->Picture, $X, $Y);
  2621. $R2 = ($RGB2 >> 16) & 0xFF;
  2622. $G2 = ($RGB2 >> 8) & 0xFF;
  2623. $B2 = $RGB2 & 0xFF;
  2624. $iAlpha = (100 - $Alpha)/100;
  2625. $Alpha = $Alpha / 100;
  2626. $Ra = floor($R*$Alpha+$R2*$iAlpha);
  2627. $Ga = floor($G*$Alpha+$G2*$iAlpha);
  2628. $Ba = floor($B*$Alpha+$B2*$iAlpha);
  2629. $C_Aliased = $this->AllocateColor($this->Picture,$Ra,$Ga,$Ba);
  2630. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  2631. }
  2632. /* Color helper */
  2633. function AllocateColor($Picture,$R,$G,$B,$Factor=0)
  2634. {
  2635. $R = $R + $Factor;
  2636. $G = $G + $Factor;
  2637. $B = $B + $Factor;
  2638. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2639. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2640. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2641. return(imagecolorallocate($Picture,$R,$G,$B));
  2642. }
  2643. /* Add a border to the picture */
  2644. function addBorder($Size=3,$R=0,$G=0,$B=0)
  2645. {
  2646. $Width = $this->XSize+2*$Size;
  2647. $Height = $this->YSize+2*$Size;
  2648. $Resampled = imagecreatetruecolor($Width,$Height);
  2649. $C_Background = $this->AllocateColor($Resampled,$R,$G,$B);
  2650. imagefilledrectangle($Resampled,0,0,$Width,$Height,$C_Background);
  2651. imagecopy($Resampled,$this->Picture,$Size,$Size,0,0,$this->XSize,$this->YSize);
  2652. imagedestroy($this->Picture);
  2653. $this->XSize = $Width;
  2654. $this->YSize = $Height;
  2655. $this->Picture = imagecreatetruecolor($this->XSize,$this->YSize);
  2656. $C_White = $this->AllocateColor($this->Picture,255,255,255);
  2657. imagefilledrectangle($this->Picture,0,0,$this->XSize,$this->YSize,$C_White);
  2658. imagecolortransparent($this->Picture,$C_White);
  2659. imagecopy($this->Picture,$Resampled,0,0,0,0,$this->XSize,$this->YSize);
  2660. }
  2661. /* Render the current picture to a file */
  2662. function Render($FileName)
  2663. {
  2664. if ( $this->ErrorReporting )
  2665. $this->printErrors($this->ErrorInterface);
  2666. /* Save image map if requested */
  2667. if ( $this->BuildMap )
  2668. $this->SaveImageMap();
  2669. imagepng($this->Picture,$FileName);
  2670. }
  2671. /* Render the current picture to STDOUT */
  2672. function Stroke()
  2673. {
  2674. if ( $this->ErrorReporting )
  2675. $this->printErrors("GD");
  2676. /* Save image map if requested */
  2677. if ( $this->BuildMap )
  2678. $this->SaveImageMap();
  2679. header('Content-type: image/png');
  2680. imagepng($this->Picture);
  2681. }
  2682. /* Private functions for internal processing */
  2683. function drawAntialiasPixel($X,$Y,$R,$G,$B,$Alpha=100,$NoFallBack=FALSE)
  2684. {
  2685. /* Process shadows */
  2686. if ( $this->ShadowActive && !$NoFallBack )
  2687. {
  2688. $this->drawAntialiasPixel($X+$this->ShadowXDistance,$Y+$this->ShadowYDistance,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha,TRUE);
  2689. if ( $this->ShadowBlur != 0 )
  2690. {
  2691. $AlphaDecay = ($this->ShadowAlpha / $this->ShadowBlur);
  2692. for($i=1; $i<=$this->ShadowBlur; $i++)
  2693. $this->drawAntialiasPixel($X+$this->ShadowXDistance-$i/2,$Y+$this->ShadowYDistance-$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha-$AlphaDecay*$i,TRUE);
  2694. for($i=1; $i<=$this->ShadowBlur; $i++)
  2695. $this->drawAntialiasPixel($X+$this->ShadowXDistance+$i/2,$Y+$this->ShadowYDistance+$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha-$AlphaDecay*$i,TRUE);
  2696. }
  2697. }
  2698. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2699. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2700. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2701. $Plot = "";
  2702. $Xi = floor($X);
  2703. $Yi = floor($Y);
  2704. if ( $Xi == $X && $Yi == $Y)
  2705. {
  2706. if ( $Alpha == 100 )
  2707. {
  2708. $C_Aliased = $this->AllocateColor($this->Picture,$R,$G,$B);
  2709. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  2710. }
  2711. else
  2712. $this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B);
  2713. }
  2714. else
  2715. {
  2716. $Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  2717. if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); }
  2718. $Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  2719. if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); }
  2720. $Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  2721. if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); }
  2722. $Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  2723. if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); }
  2724. }
  2725. }
  2726. /* Validate data contained in the description array */
  2727. function validateDataDescription($FunctionName,&$DataDescription,$DescriptionRequired=TRUE)
  2728. {
  2729. if (!isset($DataDescription["Position"]))
  2730. {
  2731. $this->Errors[] = "[Warning] ".$FunctionName." - Y Labels are not set.";
  2732. $DataDescription["Position"] = "Name";
  2733. }
  2734. if ( $DescriptionRequired )
  2735. {
  2736. if (!isset($DataDescription["Description"]))
  2737. {
  2738. $this->Errors[] = "[Warning] ".$FunctionName." - Series descriptions are not set.";
  2739. foreach($DataDescription["Values"] as $key => $Value)
  2740. {
  2741. $DataDescription["Description"][$Value] = $Value;
  2742. }
  2743. }
  2744. if (count($DataDescription["Description"]) < count($DataDescription["Values"]))
  2745. {
  2746. $this->Errors[] = "[Warning] ".$FunctionName." - Some series descriptions are not set.";
  2747. foreach($DataDescription["Values"] as $key => $Value)
  2748. {
  2749. if ( !isset($DataDescription["Description"][$Value]))
  2750. $DataDescription["Description"][$Value] = $Value;
  2751. }
  2752. }
  2753. }
  2754. }
  2755. /* Validate data contained in the data array */
  2756. function validateData($FunctionName,&$Data)
  2757. {
  2758. $DataSummary = array();
  2759. foreach($Data as $key => $Values)
  2760. {
  2761. foreach($Values as $key2 => $Value)
  2762. {
  2763. if (!isset($DataSummary[$key2]))
  2764. $DataSummary[$key2] = 1;
  2765. else
  2766. $DataSummary[$key2]++;
  2767. }
  2768. }
  2769. if ( max($DataSummary) == 0 )
  2770. $this->Errors[] = "[Warning] ".$FunctionName." - No data set.";
  2771. foreach($DataSummary as $key => $Value)
  2772. {
  2773. if ($Value < max($DataSummary))
  2774. {
  2775. $this->Errors[] = "[Warning] ".$FunctionName." - Missing data in serie ".$key.".";
  2776. }
  2777. }
  2778. }
  2779. /* Print all error messages on the CLI or graphically */
  2780. function printErrors($Mode="CLI")
  2781. {
  2782. if (count($this->Errors) == 0)
  2783. return(0);
  2784. if ( $Mode == "CLI" )
  2785. {
  2786. foreach($this->Errors as $key => $Value)
  2787. echo $Value."\r\n";
  2788. }
  2789. elseif ( $Mode == "GD" )
  2790. {
  2791. $this->setLineStyle($Width=1);
  2792. $MaxWidth = 0;
  2793. foreach($this->Errors as $key => $Value)
  2794. {
  2795. $Position = imageftbbox($this->ErrorFontSize,0,$this->ErrorFontName,$Value);
  2796. $TextWidth = $Position[2]-$Position[0];
  2797. if ( $TextWidth > $MaxWidth ) { $MaxWidth = $TextWidth; }
  2798. }
  2799. $this->drawFilledRoundedRectangle($this->XSize-($MaxWidth+20),$this->YSize-(20+(($this->ErrorFontSize+4)*count($this->Errors))),$this->XSize-10,$this->YSize-10,6,233,185,185);
  2800. $this->drawRoundedRectangle($this->XSize-($MaxWidth+20),$this->YSize-(20+(($this->ErrorFontSize+4)*count($this->Errors))),$this->XSize-10,$this->YSize-10,6,193,145,145);
  2801. $C_TextColor = $this->AllocateColor($this->Picture,133,85,85);
  2802. $YPos = $this->YSize - (18 + (count($this->Errors)-1) * ($this->ErrorFontSize + 4));
  2803. foreach($this->Errors as $key => $Value)
  2804. {
  2805. imagettftext($this->Picture,$this->ErrorFontSize,0,$this->XSize-($MaxWidth+15),$YPos,$C_TextColor,$this->ErrorFontName,$Value);
  2806. $YPos = $YPos + ($this->ErrorFontSize + 4);
  2807. }
  2808. }
  2809. }
  2810. /* Activate the image map creation process */
  2811. function setImageMap($Mode=TRUE,$GraphID="MyGraph")
  2812. {
  2813. $this->BuildMap = $Mode;
  2814. $this->MapID = $GraphID;
  2815. }
  2816. /* Add a box into the image map */
  2817. function addToImageMap($X1,$Y1,$X2,$Y2,$SerieName,$Value,$CallerFunction)
  2818. {
  2819. if ( $this->MapFunction == NULL || $this->MapFunction == $CallerFunction )
  2820. {
  2821. $this->ImageMap[] = round($X1).",".round($Y1).",".round($X2).",".round($Y2).",".$SerieName.",".$Value;
  2822. $this->MapFunction = $CallerFunction;
  2823. }
  2824. }
  2825. /* Load and cleanup the image map from disk */
  2826. function getImageMap($MapName,$Flush=TRUE)
  2827. {
  2828. /* Strip HTML query strings */
  2829. $Values = $this->tmpFolder.$MapName;
  2830. $Value = split("\?",$Values);
  2831. $FileName = $Value[0];
  2832. if ( file_exists($FileName) )
  2833. {
  2834. $Handle = fopen($FileName, "r");
  2835. $MapContent = fread($Handle, filesize($FileName));
  2836. fclose($Handle);
  2837. echo $MapContent;
  2838. if ( $Flush )
  2839. unlink($FileName);
  2840. exit();
  2841. }
  2842. else
  2843. {
  2844. header("HTTP/1.0 404 Not Found");
  2845. exit();
  2846. }
  2847. }
  2848. /* Save the image map to the disk */
  2849. function SaveImageMap()
  2850. {
  2851. if ( !$this->BuildMap ) { return(-1); }
  2852. if ( $this->ImageMap == NULL )
  2853. {
  2854. $this->Errors[] = "[Warning] SaveImageMap - Image map is empty.";
  2855. return(-1);
  2856. }
  2857. $Handle = fopen($this->tmpFolder.$this->MapID, 'w');
  2858. if ( !$Handle )
  2859. {
  2860. $this->Errors[] = "[Warning] SaveImageMap - Cannot save the image map.";
  2861. return(-1);
  2862. }
  2863. else
  2864. {
  2865. foreach($this->ImageMap as $Key => $Value)
  2866. fwrite($Handle, htmlentities($Value)."\r");
  2867. }
  2868. fclose ($Handle);
  2869. }
  2870. /* Convert seconds to a time format string */
  2871. function ToTime($Value)
  2872. {
  2873. $Hour = floor($Value/3600);
  2874. $Minute = floor(($Value - $Hour*3600)/60);
  2875. $Second = floor($Value - $Hour*3600 - $Minute*60);
  2876. if (strlen($Hour) == 1 ) { $Hour = "0".$Hour; }
  2877. if (strlen($Minute) == 1 ) { $Minute = "0".$Minute; }
  2878. if (strlen($Second) == 1 ) { $Second = "0".$Second; }
  2879. return($Hour.":".$Minute.":".$Second);
  2880. }
  2881. /* Convert to metric system */
  2882. function ToMetric($Value)
  2883. {
  2884. $Go = floor($Value/1000000000);
  2885. $Mo = floor(($Value - $Go*1000000000)/1000000);
  2886. $Ko = floor(($Value - $Go*1000000000 - $Mo*1000000)/1000);
  2887. $o = floor($Value - $Go*1000000000 - $Mo*1000000 - $Ko*1000);
  2888. if ($Go != 0) { return($Go.".".$Mo."g"); }
  2889. if ($Mo != 0) { return($Mo.".".$ko."m"); }
  2890. if ($Ko != 0) { return($Ko.".".$o)."k"; }
  2891. return($o);
  2892. }
  2893. /* Convert to curency */
  2894. function ToCurrency($Value)
  2895. {
  2896. $Go = floor($Value/1000000000);
  2897. $Mo = floor(($Value - $Go*1000000000)/1000000);
  2898. $Ko = floor(($Value - $Go*1000000000 - $Mo*1000000)/1000);
  2899. $o = floor($Value - $Go*1000000000 - $Mo*1000000 - $Ko*1000);
  2900. if ( strlen($o) == 1 ) { $o = "00".$o; }
  2901. if ( strlen($o) == 2 ) { $o = "0".$o; }
  2902. $ResultString = $o;
  2903. if ( $Ko != 0 ) { $ResultString = $Ko.".".$ResultString; }
  2904. if ( $Mo != 0 ) { $ResultString = $Mo.".".$ResultString; }
  2905. if ( $Go != 0 ) { $ResultString = $Go.".".$ResultString; }
  2906. $ResultString = $this->Currency.$ResultString;
  2907. return($ResultString);
  2908. }
  2909. /* Set date format for axis labels */
  2910. function setDateFormat($Format)
  2911. {
  2912. $this->DateFormat = $Format;
  2913. }
  2914. /* Convert TS to a date format string */
  2915. function ToDate($Value)
  2916. {
  2917. return(date($this->DateFormat,$Value));
  2918. }
  2919. /* Check if a number is a full integer (for scaling) */
  2920. function isRealInt($Value)
  2921. {
  2922. if ($Value == floor($Value))
  2923. return(TRUE);
  2924. return(FALSE);
  2925. }
  2926. }
  2927. function RaiseFatal($Message)
  2928. {
  2929. echo "[FATAL] ".$Message."\r\n";
  2930. exit();
  2931. }
  2932. ?>