pChart.class.php 135 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563
  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 drawHorizontalBarGraph($Data,$DataDescription,$Shadow=FALSE,$Alpha=100)
  1625. {
  1626. /* Validate the Data and DataDescription array */
  1627. $this->validateDataDescription("drawHorizontalBarGraph",$DataDescription);
  1628. $this->validateData("drawHorizontalBarGraph",$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. $X1 = $YZero;
  1658. $Y1 = $XPos+1;
  1659. $X2 = $YPos;
  1660. $Y2 = $XPos+$SeriesWidth-1;
  1661. $this->drawRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,25,25,25,TRUE,$Alpha);
  1662. $this->drawFilledRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1663. //$this->drawRectangle($X1,$Y1,$X2,$Y2,$YPos,25,25,25,TRUE,$Alpha);
  1664. //$this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1665. }
  1666. }
  1667. $XPos = $XPos + $this->DivisionWidth;
  1668. }
  1669. $SerieID++;
  1670. }
  1671. }
  1672. /* This function draw a bar graph */
  1673. function drawBarGraph($Data,$DataDescription,$Shadow=FALSE,$Alpha=100)
  1674. {
  1675. /* Validate the Data and DataDescription array */
  1676. $this->validateDataDescription("drawBarGraph",$DataDescription);
  1677. $this->validateData("drawBarGraph",$Data);
  1678. $GraphID = 0;
  1679. $Series = count($DataDescription["Values"]);
  1680. $SeriesWidth = $this->DivisionWidth / ($Series+1);
  1681. $SerieXOffset = $this->DivisionWidth / 2 - $SeriesWidth / 2;
  1682. $YZero = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio);
  1683. if ( $YZero > $this->GArea_Y2 ) { $YZero = $this->GArea_Y2; }
  1684. $SerieID = 0;
  1685. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1686. {
  1687. $ID = 0;
  1688. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1689. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1690. $XPos = $this->GArea_X1 + $this->GAreaXOffset - $SerieXOffset + $SeriesWidth * $SerieID;
  1691. $XLast = -1;
  1692. foreach ( $Data as $Key => $Values )
  1693. {
  1694. if ( isset($Data[$Key][$ColName]))
  1695. {
  1696. if ( is_numeric($Data[$Key][$ColName]) )
  1697. {
  1698. $Value = $Data[$Key][$ColName];
  1699. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1700. /* Save point into the image map if option activated */
  1701. if ( $this->BuildMap )
  1702. {
  1703. $this->addToImageMap($XPos+1,min($YZero,$YPos),$XPos+$SeriesWidth-1,max($YZero,$YPos),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Bar");
  1704. }
  1705. if ( $Shadow && $Alpha == 100 )
  1706. $this->drawRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,25,25,25,TRUE,$Alpha);
  1707. $this->drawFilledRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1708. }
  1709. }
  1710. $XPos = $XPos + $this->DivisionWidth;
  1711. }
  1712. $SerieID++;
  1713. }
  1714. }
  1715. /* This function draw a stacked bar graph */
  1716. function drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE)
  1717. {
  1718. /* Validate the Data and DataDescription array */
  1719. $this->validateDataDescription("drawBarGraph",$DataDescription);
  1720. $this->validateData("drawBarGraph",$Data);
  1721. $GraphID = 0;
  1722. $Series = count($DataDescription["Values"]);
  1723. if ( $Contiguous )
  1724. $SeriesWidth = $this->DivisionWidth;
  1725. else
  1726. $SeriesWidth = $this->DivisionWidth * .8;
  1727. $YZero = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio);
  1728. if ( $YZero > $this->GArea_Y2 ) { $YZero = $this->GArea_Y2; }
  1729. $SerieID = 0; $LastValue = "";
  1730. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1731. {
  1732. $ID = 0;
  1733. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1734. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1735. $XPos = $this->GArea_X1 + $this->GAreaXOffset - $SeriesWidth / 2;
  1736. $XLast = -1;
  1737. foreach ( $Data as $Key => $Values )
  1738. {
  1739. if ( isset($Data[$Key][$ColName]))
  1740. {
  1741. if ( is_numeric($Data[$Key][$ColName]) )
  1742. {
  1743. $Value = $Data[$Key][$ColName];
  1744. if ( isset($LastValue[$Key]) )
  1745. {
  1746. $YPos = $this->GArea_Y2 - ((($Value+$LastValue[$Key])-$this->VMin) * $this->DivisionRatio);
  1747. $YBottom = $this->GArea_Y2 - (($LastValue[$Key]-$this->VMin) * $this->DivisionRatio);
  1748. $LastValue[$Key] += $Value;
  1749. }
  1750. else
  1751. {
  1752. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1753. $YBottom = $YZero;
  1754. $LastValue[$Key] = $Value;
  1755. }
  1756. /* Save point into the image map if option activated */
  1757. if ( $this->BuildMap )
  1758. $this->addToImageMap($XPos+1,min($YBottom,$YPos),$XPos+$SeriesWidth-1,max($YBottom,$YPos),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"sBar");
  1759. $this->drawFilledRectangle($XPos+1,$YBottom,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1760. }
  1761. }
  1762. $XPos = $XPos + $this->DivisionWidth;
  1763. }
  1764. $SerieID++;
  1765. }
  1766. }
  1767. /* This function draw a limits bar graphs */
  1768. function drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0)
  1769. {
  1770. /* Validate the Data and DataDescription array */
  1771. $this->validateDataDescription("drawLimitsGraph",$DataDescription);
  1772. $this->validateData("drawLimitsGraph",$Data);
  1773. $XWidth = $this->DivisionWidth / 4;
  1774. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1775. foreach ( $Data as $Key => $Values )
  1776. {
  1777. $Min = $Data[$Key][$DataDescription["Values"][0]];
  1778. $Max = $Data[$Key][$DataDescription["Values"][0]];
  1779. $GraphID = 0; $MaxID = 0; $MinID = 0;
  1780. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1781. {
  1782. if ( isset($Data[$Key][$ColName]) )
  1783. {
  1784. if ( $Data[$Key][$ColName] > $Max && is_numeric($Data[$Key][$ColName]))
  1785. { $Max = $Data[$Key][$ColName]; $MaxID = $GraphID; }
  1786. }
  1787. if ( isset($Data[$Key][$ColName]) && is_numeric($Data[$Key][$ColName]))
  1788. {
  1789. if ( $Data[$Key][$ColName] < $Min )
  1790. { $Min = $Data[$Key][$ColName]; $MinID = $GraphID; }
  1791. $GraphID++;
  1792. }
  1793. }
  1794. $YPos = $this->GArea_Y2 - (($Max-$this->VMin) * $this->DivisionRatio);
  1795. $X1 = floor($XPos - $XWidth); $Y1 = floor($YPos) - .2;
  1796. $X2 = floor($XPos + $XWidth);
  1797. if ( $X1 <= $this->GArea_X1 ) { $X1 = $this->GArea_X1 + 1; }
  1798. if ( $X2 >= $this->GArea_X2 ) { $X2 = $this->GArea_X2 - 1; }
  1799. $YPos = $this->GArea_Y2 - (($Min-$this->VMin) * $this->DivisionRatio);
  1800. $Y2 = floor($YPos) + .2;
  1801. $this->drawLine(floor($XPos)-.2,$Y1+1,floor($XPos)-.2,$Y2-1,$R,$G,$B,TRUE);
  1802. $this->drawLine(floor($XPos)+.2,$Y1+1,floor($XPos)+.2,$Y2-1,$R,$G,$B,TRUE);
  1803. $this->drawLine($X1,$Y1,$X2,$Y1,$this->Palette[$MaxID]["R"],$this->Palette[$MaxID]["G"],$this->Palette[$MaxID]["B"],FALSE);
  1804. $this->drawLine($X1,$Y2,$X2,$Y2,$this->Palette[$MinID]["R"],$this->Palette[$MinID]["G"],$this->Palette[$MinID]["B"],FALSE);
  1805. $XPos = $XPos + $this->DivisionWidth;
  1806. }
  1807. }
  1808. /* This function draw radar axis centered on the graph area */
  1809. 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)
  1810. {
  1811. /* Validate the Data and DataDescription array */
  1812. $this->validateDataDescription("drawRadarAxis",$DataDescription);
  1813. $this->validateData("drawRadarAxis",$Data);
  1814. $C_TextColor = $this->AllocateColor($this->Picture,$A_R,$A_G,$A_B);
  1815. /* Draw radar axis */
  1816. $Points = count($Data);
  1817. $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset;
  1818. $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2 + $this->GArea_X1;
  1819. $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 + $this->GArea_Y1;
  1820. /* Search for the max value */
  1821. if ( $MaxValue == -1 )
  1822. {
  1823. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1824. {
  1825. foreach ( $Data as $Key => $Values )
  1826. {
  1827. if ( isset($Data[$Key][$ColName]))
  1828. if ( $Data[$Key][$ColName] > $MaxValue ) { $MaxValue = $Data[$Key][$ColName]; }
  1829. }
  1830. }
  1831. }
  1832. /* Draw the mosaic */
  1833. if ( $Mosaic )
  1834. {
  1835. $RadiusScale = $Radius / $MaxValue;
  1836. for ( $t=1; $t<=$MaxValue-1; $t++)
  1837. {
  1838. $TRadius = $RadiusScale * $t;
  1839. $LastX1 = -1;
  1840. for ( $i=0; $i<=$Points; $i++)
  1841. {
  1842. $Angle = -90 + $i * 360/$Points;
  1843. $X1 = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter;
  1844. $Y1 = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter;
  1845. $X2 = cos($Angle * 3.1418 / 180 ) * ($TRadius+$RadiusScale) + $XCenter;
  1846. $Y2 = sin($Angle * 3.1418 / 180 ) * ($TRadius+$RadiusScale) + $YCenter;
  1847. if ( $t % 2 == 1 && $LastX1 != -1)
  1848. {
  1849. $Plots = "";
  1850. $Plots[] = $X1; $Plots[] = $Y1;
  1851. $Plots[] = $X2; $Plots[] = $Y2;
  1852. $Plots[] = $LastX2; $Plots[] = $LastY2;
  1853. $Plots[] = $LastX1; $Plots[] = $LastY1;
  1854. $C_Graph = $this->AllocateColor($this->Picture,250,250,250);
  1855. imagefilledpolygon($this->Picture,$Plots,(count($Plots)+1)/2,$C_Graph);
  1856. }
  1857. $LastX1 = $X1; $LastY1= $Y1;
  1858. $LastX2 = $X2; $LastY2= $Y2;
  1859. }
  1860. }
  1861. }
  1862. /* Draw the spider web */
  1863. for ( $t=1; $t<=$MaxValue; $t++)
  1864. {
  1865. $TRadius = ( $Radius / $MaxValue ) * $t;
  1866. $LastX = -1;
  1867. for ( $i=0; $i<=$Points; $i++)
  1868. {
  1869. $Angle = -90 + $i * 360/$Points;
  1870. $X = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter;
  1871. $Y = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter;
  1872. if ( $LastX != -1 )
  1873. $this->drawDottedLine($LastX,$LastY,$X,$Y,4,$S_R,$S_G,$S_B);
  1874. $LastX = $X; $LastY= $Y;
  1875. }
  1876. }
  1877. /* Draw the axis */
  1878. for ( $i=0; $i<=$Points; $i++)
  1879. {
  1880. $Angle = -90 + $i * 360/$Points;
  1881. $X = cos($Angle * 3.1418 / 180 ) * $Radius + $XCenter;
  1882. $Y = sin($Angle * 3.1418 / 180 ) * $Radius + $YCenter;
  1883. $this->drawLine($XCenter,$YCenter,$X,$Y,$A_R,$A_G,$A_B);
  1884. $XOffset = 0; $YOffset = 0;
  1885. if (isset($Data[$i][$DataDescription["Position"]]))
  1886. {
  1887. $Label = $Data[$i][$DataDescription["Position"]];
  1888. $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$Label);
  1889. $Width = $Positions[2] - $Positions[6];
  1890. $Height = $Positions[3] - $Positions[7];
  1891. if ( $Angle >= 0 && $Angle <= 90 )
  1892. $YOffset = $Height;
  1893. if ( $Angle > 90 && $Angle <= 180 )
  1894. { $YOffset = $Height; $XOffset = -$Width; }
  1895. if ( $Angle > 180 && $Angle <= 270 )
  1896. { $XOffset = -$Width; }
  1897. imagettftext($this->Picture,$this->FontSize,0,$X+$XOffset,$Y+$YOffset,$C_TextColor,$this->FontName,$Label);
  1898. }
  1899. }
  1900. /* Write the values */
  1901. for ( $t=1; $t<=$MaxValue; $t++)
  1902. {
  1903. $TRadius = ( $Radius / $MaxValue ) * $t;
  1904. $Angle = -90 + 360 / $Points;
  1905. $X1 = $XCenter;
  1906. $Y1 = $YCenter - $TRadius;
  1907. $X2 = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter;
  1908. $Y2 = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter;
  1909. $XPos = floor(($X2-$X1)/2) + $X1;
  1910. $YPos = floor(($Y2-$Y1)/2) + $Y1;
  1911. $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$t);
  1912. $X = $XPos - ( $X+$Positions[2] - $X+$Positions[6] ) / 2;
  1913. $Y = $YPos + $this->FontSize;
  1914. $this->drawFilledRoundedRectangle($X+$Positions[6]-2,$Y+$Positions[7]-1,$X+$Positions[2]+4,$Y+$Positions[3]+1,2,240,240,240);
  1915. $this->drawRoundedRectangle($X+$Positions[6]-2,$Y+$Positions[7]-1,$X+$Positions[2]+4,$Y+$Positions[3]+1,2,220,220,220);
  1916. imagettftext($this->Picture,$this->FontSize,0,$X,$Y,$C_TextColor,$this->FontName,$t);
  1917. }
  1918. }
  1919. /* This function draw a radar graph centered on the graph area */
  1920. function drawRadar($Data,$DataDescription,$BorderOffset=10,$MaxValue=-1)
  1921. {
  1922. /* Validate the Data and DataDescription array */
  1923. $this->validateDataDescription("drawRadar",$DataDescription);
  1924. $this->validateData("drawRadar",$Data);
  1925. $Points = count($Data);
  1926. $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset;
  1927. $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2 + $this->GArea_X1;
  1928. $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 + $this->GArea_Y1;
  1929. /* Search for the max value */
  1930. if ( $MaxValue == -1 )
  1931. {
  1932. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1933. {
  1934. foreach ( $Data as $Key => $Values )
  1935. {
  1936. if ( isset($Data[$Key][$ColName]))
  1937. if ( $Data[$Key][$ColName] > $MaxValue ) { $MaxValue = $Data[$Key][$ColName]; }
  1938. }
  1939. }
  1940. }
  1941. $GraphID = 0;
  1942. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1943. {
  1944. $ID = 0;
  1945. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1946. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1947. $Angle = -90;
  1948. $XLast = -1;
  1949. foreach ( $Data as $Key => $Values )
  1950. {
  1951. if ( isset($Data[$Key][$ColName]))
  1952. {
  1953. $Value = $Data[$Key][$ColName];
  1954. $Strength = ( $Radius / $MaxValue ) * $Value;
  1955. $XPos = cos($Angle * 3.1418 / 180 ) * $Strength + $XCenter;
  1956. $YPos = sin($Angle * 3.1418 / 180 ) * $Strength + $YCenter;
  1957. if ( $XLast != -1 )
  1958. $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1959. if ( $XLast == -1 )
  1960. { $FirstX = $XPos; $FirstY = $YPos; }
  1961. $Angle = $Angle + (360/$Points);
  1962. $XLast = $XPos;
  1963. $YLast = $YPos;
  1964. }
  1965. }
  1966. $this->drawLine($XPos,$YPos,$FirstX,$FirstY,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1967. $GraphID++;
  1968. }
  1969. }
  1970. /* This function draw a radar graph centered on the graph area */
  1971. function drawFilledRadar($Data,$DataDescription,$Alpha=50,$BorderOffset=10,$MaxValue=-1)
  1972. {
  1973. /* Validate the Data and DataDescription array */
  1974. $this->validateDataDescription("drawFilledRadar",$DataDescription);
  1975. $this->validateData("drawFilledRadar",$Data);
  1976. $Points = count($Data);
  1977. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1978. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1979. $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset;
  1980. $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2;
  1981. $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2;
  1982. /* Search for the max value */
  1983. if ( $MaxValue == -1 )
  1984. {
  1985. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1986. {
  1987. foreach ( $Data as $Key => $Values )
  1988. {
  1989. if ( isset($Data[$Key][$ColName]))
  1990. if ( $Data[$Key][$ColName] > $MaxValue && is_numeric($Data[$Key][$ColName])) { $MaxValue = $Data[$Key][$ColName]; }
  1991. }
  1992. }
  1993. }
  1994. $GraphID = 0;
  1995. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1996. {
  1997. $ID = 0;
  1998. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1999. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  2000. $Angle = -90;
  2001. $XLast = -1;
  2002. $Plots = "";
  2003. foreach ( $Data as $Key => $Values )
  2004. {
  2005. if ( isset($Data[$Key][$ColName]))
  2006. {
  2007. $Value = $Data[$Key][$ColName];
  2008. if ( !is_numeric($Value) ) { $Value = 0; }
  2009. $Strength = ( $Radius / $MaxValue ) * $Value;
  2010. $XPos = cos($Angle * 3.1418 / 180 ) * $Strength + $XCenter;
  2011. $YPos = sin($Angle * 3.1418 / 180 ) * $Strength + $YCenter;
  2012. $Plots[] = $XPos;
  2013. $Plots[] = $YPos;
  2014. $Angle = $Angle + (360/$Points);
  2015. $XLast = $XPos;
  2016. $YLast = $YPos;
  2017. }
  2018. }
  2019. if (isset($Plots[0]))
  2020. {
  2021. $Plots[] = $Plots[0];
  2022. $Plots[] = $Plots[1];
  2023. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  2024. $C_White = $this->AllocateColor($this->Layers[0],255,255,255);
  2025. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  2026. imagecolortransparent($this->Layers[0],$C_White);
  2027. $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  2028. imagefilledpolygon($this->Layers[0],$Plots,(count($Plots)+1)/2,$C_Graph);
  2029. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  2030. imagedestroy($this->Layers[0]);
  2031. for($i=0;$i<=count($Plots)-4;$i=$i+2)
  2032. $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"]);
  2033. }
  2034. $GraphID++;
  2035. }
  2036. }
  2037. /* This function draw a flat pie chart */
  2038. function drawBasicPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$R=255,$G=255,$B=255,$Decimals=0)
  2039. {
  2040. /* Validate the Data and DataDescription array */
  2041. $this->validateDataDescription("drawBasicPieGraph",$DataDescription,FALSE);
  2042. $this->validateData("drawBasicPieGraph",$Data);
  2043. /* Determine pie sum */
  2044. $Series = 0; $PieSum = 0;
  2045. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2046. {
  2047. if ( $ColName != $DataDescription["Position"] )
  2048. {
  2049. $Series++;
  2050. foreach ( $Data as $Key => $Values )
  2051. {
  2052. if ( isset($Data[$Key][$ColName]))
  2053. $PieSum = $PieSum + $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]];
  2054. }
  2055. }
  2056. }
  2057. /* Validate serie */
  2058. if ( $Series != 1 )
  2059. RaiseFatal("Pie chart can only accept one serie of data.");
  2060. $SpliceRatio = 360 / $PieSum;
  2061. $SplicePercent = 100 / $PieSum;
  2062. /* Calculate all polygons */
  2063. $Angle = 0; $TopPlots = "";
  2064. foreach($iValues as $Key => $Value)
  2065. {
  2066. $TopPlots[$Key][] = $XPos;
  2067. $TopPlots[$Key][] = $YPos;
  2068. /* Process labels position & size */
  2069. $Caption = "";
  2070. if ( !($DrawLabels == PIE_NOLABEL) )
  2071. {
  2072. $TAngle = $Angle+($Value*$SpliceRatio/2);
  2073. if ($DrawLabels == PIE_PERCENTAGE)
  2074. $Caption = (round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2075. elseif ($DrawLabels == PIE_LABELS)
  2076. $Caption = $iLabels[$Key];
  2077. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2078. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2079. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2080. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2081. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  2082. $TextWidth = $Position[2]-$Position[0];
  2083. $TextHeight = abs($Position[1])+abs($Position[3]);
  2084. $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius+10) + $XPos;
  2085. if ( $TAngle > 0 && $TAngle < 180 )
  2086. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+10) + $YPos + 4;
  2087. else
  2088. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+4) + $YPos - ($TextHeight/2);
  2089. if ( $TAngle > 90 && $TAngle < 270 )
  2090. $TX = $TX - $TextWidth;
  2091. $C_TextColor = $this->AllocateColor($this->Picture,70,70,70);
  2092. imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption);
  2093. }
  2094. /* Process pie slices */
  2095. for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5)
  2096. {
  2097. $TopX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos;
  2098. $TopY = sin($iAngle * 3.1418 / 180 ) * $Radius + $YPos;
  2099. $TopPlots[$Key][] = $TopX;
  2100. $TopPlots[$Key][] = $TopY;
  2101. }
  2102. $TopPlots[$Key][] = $XPos;
  2103. $TopPlots[$Key][] = $YPos;
  2104. $Angle = $iAngle;
  2105. }
  2106. $PolyPlots = $TopPlots;
  2107. /* Set array values type to float --- PHP Bug with imagefilledpolygon casting to integer */
  2108. foreach ($TopPlots as $Key => $Value)
  2109. { foreach ($TopPlots[$Key] as $Key2 => $Value2) { settype($TopPlots[$Key][$Key2],"float"); } }
  2110. /* Draw Top polygons */
  2111. foreach ($PolyPlots as $Key => $Value)
  2112. {
  2113. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]);
  2114. imagefilledpolygon($this->Picture,$PolyPlots[$Key],(count($PolyPlots[$Key])+1)/2,$C_GraphLo);
  2115. }
  2116. $this->drawCircle($XPos-.5,$YPos-.5,$Radius,$R,$G,$B);
  2117. $this->drawCircle($XPos-.5,$YPos-.5,$Radius+.5,$R,$G,$B);
  2118. /* Draw Top polygons */
  2119. foreach ($TopPlots as $Key => $Value)
  2120. {
  2121. for($j=0;$j<=count($TopPlots[$Key])-4;$j=$j+2)
  2122. $this->drawLine($TopPlots[$Key][$j],$TopPlots[$Key][$j+1],$TopPlots[$Key][$j+2],$TopPlots[$Key][$j+3],$R,$G,$B);
  2123. }
  2124. }
  2125. function drawFlatPieGraphWithShadow($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals=0)
  2126. {
  2127. $this->drawFlatPieGraph($Data,$DataDescription,$XPos+$this->ShadowXDistance,$YPos+$this->ShadowYDistance,$Radius,PIE_NOLABEL,$SpliceDistance,$Decimals,TRUE);
  2128. $this->drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius,$DrawLabels,$SpliceDistance,$Decimals,FALSE);
  2129. }
  2130. /* This function draw a flat pie chart */
  2131. function drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals=0,$AllBlack=FALSE)
  2132. {
  2133. /* Validate the Data and DataDescription array */
  2134. $this->validateDataDescription("drawFlatPieGraph",$DataDescription,FALSE);
  2135. $this->validateData("drawFlatPieGraph",$Data);
  2136. $ShadowStatus = $this->ShadowActive ; $this->ShadowActive = FALSE;
  2137. /* Determine pie sum */
  2138. $Series = 0; $PieSum = 0;
  2139. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2140. {
  2141. if ( $ColName != $DataDescription["Position"] )
  2142. {
  2143. $Series++;
  2144. foreach ( $Data as $Key => $Values )
  2145. {
  2146. if ( isset($Data[$Key][$ColName]))
  2147. $PieSum = $PieSum + $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]];
  2148. }
  2149. }
  2150. }
  2151. /* Validate serie */
  2152. if ( $Series != 1 )
  2153. {
  2154. RaiseFatal("Pie chart can only accept one serie of data.");
  2155. return(0);
  2156. }
  2157. $SpliceRatio = 360 / $PieSum;
  2158. $SplicePercent = 100 / $PieSum;
  2159. /* Calculate all polygons */
  2160. $Angle = 0; $TopPlots = "";
  2161. foreach($iValues as $Key => $Value)
  2162. {
  2163. $XOffset = cos(($Angle+($Value/2*$SpliceRatio)) * 3.1418 / 180 ) * $SpliceDistance;
  2164. $YOffset = sin(($Angle+($Value/2*$SpliceRatio)) * 3.1418 / 180 ) * $SpliceDistance;
  2165. $TopPlots[$Key][] = round($XPos + $XOffset);
  2166. $TopPlots[$Key][] = round($YPos + $YOffset);
  2167. if ( $AllBlack )
  2168. { $Rc = $this->ShadowRColor; $Gc = $this->ShadowGColor; $Bc = $this->ShadowBColor; }
  2169. else
  2170. { $Rc = $this->Palette[$Key]["R"]; $Gc = $this->Palette[$Key]["G"]; $Bc = $this->Palette[$Key]["B"]; }
  2171. $XLineLast = ""; $YLineLast = "";
  2172. /* Process labels position & size */
  2173. $Caption = "";
  2174. if ( !($DrawLabels == PIE_NOLABEL) )
  2175. {
  2176. $TAngle = $Angle+($Value*$SpliceRatio/2);
  2177. if ($DrawLabels == PIE_PERCENTAGE)
  2178. $Caption = (round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2179. elseif ($DrawLabels == PIE_LABELS)
  2180. $Caption = $iLabels[$Key];
  2181. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2182. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2183. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2184. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2185. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  2186. $TextWidth = $Position[2]-$Position[0];
  2187. $TextHeight = abs($Position[1])+abs($Position[3]);
  2188. $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius+10+$SpliceDistance) + $XPos;
  2189. if ( $TAngle > 0 && $TAngle < 180 )
  2190. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+10+$SpliceDistance) + $YPos + 4;
  2191. else
  2192. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+$SpliceDistance+4) + $YPos - ($TextHeight/2);
  2193. if ( $TAngle > 90 && $TAngle < 270 )
  2194. $TX = $TX - $TextWidth;
  2195. $C_TextColor = $this->AllocateColor($this->Picture,70,70,70);
  2196. imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption);
  2197. }
  2198. /* Process pie slices */
  2199. if ( !$AllBlack )
  2200. $LineColor = $this->AllocateColor($this->Picture,$Rc,$Gc,$Bc);
  2201. else
  2202. $LineColor = $this->AllocateColor($this->Picture,$Rc,$Gc,$Bc);
  2203. $XLineLast = ""; $YLineLast = "";
  2204. for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5)
  2205. {
  2206. $PosX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos + $XOffset;
  2207. $PosY = sin($iAngle * 3.1418 / 180 ) * $Radius + $YPos + $YOffset;
  2208. $TopPlots[$Key][] = round($PosX); $TopPlots[$Key][] = round($PosY);
  2209. if ( $iAngle == $Angle || $iAngle == $Angle+$Value*$SpliceRatio || $iAngle +.5 > $Angle+$Value*$SpliceRatio)
  2210. $this->drawLine($XPos+$XOffset,$YPos+$YOffset,$PosX,$PosY,$Rc,$Gc,$Bc);
  2211. if ( $XLineLast != "" )
  2212. $this->drawLine($XLineLast,$YLineLast,$PosX,$PosY,$Rc,$Gc,$Bc);
  2213. $XLineLast = $PosX; $YLineLast = $PosY;
  2214. }
  2215. $TopPlots[$Key][] = round($XPos + $XOffset); $TopPlots[$Key][] = round($YPos + $YOffset);
  2216. $Angle = $iAngle;
  2217. }
  2218. $PolyPlots = $TopPlots;
  2219. /* Draw Top polygons */
  2220. foreach ($PolyPlots as $Key => $Value)
  2221. {
  2222. if ( !$AllBlack )
  2223. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]);
  2224. else
  2225. $C_GraphLo = $this->AllocateColor($this->Picture,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor);
  2226. imagefilledpolygon($this->Picture,$PolyPlots[$Key],(count($PolyPlots[$Key])+1)/2,$C_GraphLo);
  2227. }
  2228. $this->ShadowActive = $ShadowStatus;
  2229. }
  2230. /* This function draw a pseudo-3D pie chart */
  2231. function drawPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$EnhanceColors=TRUE,$Skew=60,$SpliceHeight=20,$SpliceDistance=0,$Decimals=0)
  2232. {
  2233. /* Validate the Data and DataDescription array */
  2234. $this->validateDataDescription("drawPieGraph",$DataDescription,FALSE);
  2235. $this->validateData("drawPieGraph",$Data);
  2236. /* Determine pie sum */
  2237. $Series = 0; $PieSum = 0; $rPieSum = 0;
  2238. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2239. {
  2240. if ( $ColName != $DataDescription["Position"] )
  2241. {
  2242. $Series++;
  2243. foreach ( $Data as $Key => $Values )
  2244. if ( isset($Data[$Key][$ColName]))
  2245. {
  2246. if ( $Data[$Key][$ColName] == 0 )
  2247. { $iValues[] = 0; $rValues[] = 0; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; }
  2248. // Removed : $PieSum++; $rValues[] = 1;
  2249. else
  2250. { $PieSum += $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; $rValues[] = $Data[$Key][$ColName]; $rPieSum += $Data[$Key][$ColName];}
  2251. }
  2252. }
  2253. }
  2254. /* Validate serie */
  2255. if ( $Series != 1 )
  2256. RaiseFatal("Pie chart can only accept one serie of data.");
  2257. $SpliceDistanceRatio = $SpliceDistance;
  2258. $SkewHeight = ($Radius * $Skew) / 100;
  2259. $SpliceRatio = (360 - $SpliceDistanceRatio * count($iValues) ) / $PieSum;
  2260. $SplicePercent = 100 / $PieSum;
  2261. $rSplicePercent = 100 / $rPieSum;
  2262. /* Calculate all polygons */
  2263. $Angle = 0; $CDev = 5;
  2264. $TopPlots = ""; $BotPlots = "";
  2265. $aTopPlots = ""; $aBotPlots = "";
  2266. foreach($iValues as $Key => $Value)
  2267. {
  2268. $XCenterPos = cos(($Angle-$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $XPos;
  2269. $YCenterPos = sin(($Angle-$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $YPos;
  2270. $XCenterPos2 = cos(($Angle+$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $XPos;
  2271. $YCenterPos2 = sin(($Angle+$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $YPos;
  2272. $TopPlots[$Key][] = round($XCenterPos); $BotPlots[$Key][] = round($XCenterPos);
  2273. $TopPlots[$Key][] = round($YCenterPos); $BotPlots[$Key][] = round($YCenterPos + $SpliceHeight);
  2274. $aTopPlots[$Key][] = $XCenterPos; $aBotPlots[$Key][] = $XCenterPos;
  2275. $aTopPlots[$Key][] = $YCenterPos; $aBotPlots[$Key][] = $YCenterPos + $SpliceHeight;
  2276. /* Process labels position & size */
  2277. $Caption = "";
  2278. if ( !($DrawLabels == PIE_NOLABEL) )
  2279. {
  2280. $TAngle = $Angle+($Value*$SpliceRatio/2);
  2281. if ($DrawLabels == PIE_PERCENTAGE)
  2282. $Caption = (round($rValues[$Key] * pow(10,$Decimals) * $rSplicePercent)/pow(10,$Decimals))."%";
  2283. elseif ($DrawLabels == PIE_LABELS)
  2284. $Caption = $iLabels[$Key];
  2285. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2286. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2287. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  2288. $TextWidth = $Position[2]-$Position[0];
  2289. $TextHeight = abs($Position[1])+abs($Position[3]);
  2290. $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius + 10)+ $XPos;
  2291. if ( $TAngle > 0 && $TAngle < 180 )
  2292. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($SkewHeight + 10) + $YPos + $SpliceHeight + 4;
  2293. else
  2294. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($SkewHeight + 4) + $YPos - ($TextHeight/2);
  2295. if ( $TAngle > 90 && $TAngle < 270 )
  2296. $TX = $TX - $TextWidth;
  2297. $C_TextColor = $this->AllocateColor($this->Picture,70,70,70);
  2298. imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption);
  2299. }
  2300. /* Process pie slices */
  2301. for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5)
  2302. {
  2303. $TopX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos;
  2304. $TopY = sin($iAngle * 3.1418 / 180 ) * $SkewHeight + $YPos;
  2305. $TopPlots[$Key][] = round($TopX); $BotPlots[$Key][] = round($TopX);
  2306. $TopPlots[$Key][] = round($TopY); $BotPlots[$Key][] = round($TopY + $SpliceHeight);
  2307. $aTopPlots[$Key][] = $TopX; $aBotPlots[$Key][] = $TopX;
  2308. $aTopPlots[$Key][] = $TopY; $aBotPlots[$Key][] = $TopY + $SpliceHeight;
  2309. }
  2310. $TopPlots[$Key][] = round($XCenterPos2); $BotPlots[$Key][] = round($XCenterPos2);
  2311. $TopPlots[$Key][] = round($YCenterPos2); $BotPlots[$Key][] = round($YCenterPos2 + $SpliceHeight);
  2312. $aTopPlots[$Key][] = $XCenterPos2; $aBotPlots[$Key][] = $XCenterPos2;
  2313. $aTopPlots[$Key][] = $YCenterPos2; $aBotPlots[$Key][] = $YCenterPos2 + $SpliceHeight;
  2314. $Angle = $iAngle + $SpliceDistanceRatio;
  2315. }
  2316. /* Draw Bottom polygons */
  2317. foreach($iValues as $Key => $Value)
  2318. {
  2319. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"],-20);
  2320. imagefilledpolygon($this->Picture,$BotPlots[$Key],(count($BotPlots[$Key])+1)/2,$C_GraphLo);
  2321. if ( $EnhanceColors ) { $En = -10; } else { $En = 0; }
  2322. for($j=0;$j<=count($aBotPlots[$Key])-4;$j=$j+2)
  2323. $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);
  2324. }
  2325. /* Draw pie layers */
  2326. if ( $EnhanceColors ) { $ColorRatio = 30 / $SpliceHeight; } else { $ColorRatio = 25 / $SpliceHeight; }
  2327. for($i=$SpliceHeight-1;$i>=1;$i--)
  2328. {
  2329. foreach($iValues as $Key => $Value)
  2330. {
  2331. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"],-10);
  2332. $Plots = ""; $Plot = 0;
  2333. foreach($TopPlots[$Key] as $Key2 => $Value2)
  2334. {
  2335. $Plot++;
  2336. if ( $Plot % 2 == 1 )
  2337. $Plots[] = $Value2;
  2338. else
  2339. $Plots[] = $Value2+$i;
  2340. }
  2341. imagefilledpolygon($this->Picture,$Plots,(count($Plots)+1)/2,$C_GraphLo);
  2342. $Index = count($Plots);
  2343. if ($EnhanceColors ) {$ColorFactor = -20 + ($SpliceHeight - $i) * $ColorRatio; } else { $ColorFactor = 0; }
  2344. $this->drawAntialiasPixel($Plots[0],$Plots[1],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor);
  2345. $this->drawAntialiasPixel($Plots[2],$Plots[3],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor);
  2346. $this->drawAntialiasPixel($Plots[$Index-4],$Plots[$Index-3],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor);
  2347. }
  2348. }
  2349. /* Draw Top polygons */
  2350. for($Key=count($iValues)-1;$Key>=0;$Key--)
  2351. {
  2352. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]);
  2353. imagefilledpolygon($this->Picture,$TopPlots[$Key],(count($TopPlots[$Key])+1)/2,$C_GraphLo);
  2354. if ( $EnhanceColors ) { $En = 10; } else { $En = 0; }
  2355. for($j=0;$j<=count($aTopPlots[$Key])-4;$j=$j+2)
  2356. $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);
  2357. }
  2358. }
  2359. /* This function can be used to set the background color */
  2360. function drawBackground($R,$G,$B)
  2361. {
  2362. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2363. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2364. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2365. $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B);
  2366. imagefilledrectangle($this->Picture,0,0,$this->XSize,$this->YSize,$C_Background);
  2367. }
  2368. /* This function can be used to set the background color */
  2369. function drawGraphAreaGradient($R,$G,$B,$Decay,$Target=TARGET_GRAPHAREA)
  2370. {
  2371. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2372. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2373. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2374. if ( $Target == TARGET_GRAPHAREA ) { $X1 = $this->GArea_X1+1; $X2 = $this->GArea_X2-1; $Y1 = $this->GArea_Y1+1; $Y2 = $this->GArea_Y2; }
  2375. if ( $Target == TARGET_BACKGROUND ) { $X1 = 0; $X2 = $this->XSize; $Y1 = 0; $Y2 = $this->YSize; }
  2376. /* Positive gradient */
  2377. if ( $Decay > 0 )
  2378. {
  2379. $YStep = ($Y2 - $Y1 - 2) / $Decay;
  2380. for($i=0;$i<=$Decay;$i++)
  2381. {
  2382. $R-=1;$G-=1;$B-=1;
  2383. $Yi1 = $Y1 + ( $i * $YStep );
  2384. $Yi2 = ceil( $Yi1 + ( $i * $YStep ) + $YStep );
  2385. if ( $Yi2 >= $Yi2 ) { $Yi2 = $Y2-1; }
  2386. $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B);
  2387. imagefilledrectangle($this->Picture,$X1,$Yi1,$X2,$Yi2,$C_Background);
  2388. }
  2389. }
  2390. /* Negative gradient */
  2391. if ( $Decay < 0 )
  2392. {
  2393. $YStep = ($Y2 - $Y1 - 2) / -$Decay;
  2394. $Yi1 = $Y1; $Yi2 = $Y1+$YStep;
  2395. for($i=-$Decay;$i>=0;$i--)
  2396. {
  2397. $R+=1;$G+=1;$B+=1;
  2398. $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B);
  2399. imagefilledrectangle($this->Picture,$X1,$Yi1,$X2,$Yi2,$C_Background);
  2400. $Yi1+= $YStep;
  2401. $Yi2+= $YStep;
  2402. if ( $Yi2 >= $Yi2 ) { $Yi2 = $Y2-1; }
  2403. }
  2404. }
  2405. }
  2406. /* This function create a rectangle with antialias */
  2407. function drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B)
  2408. {
  2409. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2410. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2411. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2412. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2413. $X1=$X1-.2;$Y1=$Y1-.2;
  2414. $X2=$X2+.2;$Y2=$Y2+.2;
  2415. $this->drawLine($X1,$Y1,$X2,$Y1,$R,$G,$B);
  2416. $this->drawLine($X2,$Y1,$X2,$Y2,$R,$G,$B);
  2417. $this->drawLine($X2,$Y2,$X1,$Y2,$R,$G,$B);
  2418. $this->drawLine($X1,$Y2,$X1,$Y1,$R,$G,$B);
  2419. }
  2420. /* This function create a filled rectangle with antialias */
  2421. function drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B,$DrawBorder=TRUE,$Alpha=100,$NoFallBack=FALSE)
  2422. {
  2423. if ( $X2 < $X1 ) { list($X1, $X2) = array($X2, $X1); }
  2424. if ( $Y2 < $Y1 ) { list($Y1, $Y2) = array($Y2, $Y1); }
  2425. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2426. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2427. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2428. if ( $Alpha == 100 )
  2429. {
  2430. /* Process shadows */
  2431. if ( $this->ShadowActive && !$NoFallBack )
  2432. {
  2433. $this->drawFilledRectangle($X1+$this->ShadowXDistance,$Y1+$this->ShadowYDistance,$X2+$this->ShadowXDistance,$Y2+$this->ShadowYDistance,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,FALSE,$this->ShadowAlpha,TRUE);
  2434. if ( $this->ShadowBlur != 0 )
  2435. {
  2436. $AlphaDecay = ($this->ShadowAlpha / $this->ShadowBlur);
  2437. for($i=1; $i<=$this->ShadowBlur; $i++)
  2438. $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);
  2439. for($i=1; $i<=$this->ShadowBlur; $i++)
  2440. $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);
  2441. }
  2442. }
  2443. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2444. imagefilledrectangle($this->Picture,round($X1),round($Y1),round($X2),round($Y2),$C_Rectangle);
  2445. }
  2446. else
  2447. {
  2448. $LayerWidth = abs($X2-$X1)+2;
  2449. $LayerHeight = abs($Y2-$Y1)+2;
  2450. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  2451. $C_White = $this->AllocateColor($this->Layers[0],255,255,255);
  2452. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  2453. imagecolortransparent($this->Layers[0],$C_White);
  2454. $C_Rectangle = $this->AllocateColor($this->Layers[0],$R,$G,$B);
  2455. imagefilledrectangle($this->Layers[0],round(1),round(1),round($LayerWidth-1),round($LayerHeight-1),$C_Rectangle);
  2456. imagecopymerge($this->Picture,$this->Layers[0],round(min($X1,$X2)-1),round(min($Y1,$Y2)-1),0,0,$LayerWidth,$LayerHeight,$Alpha);
  2457. imagedestroy($this->Layers[0]);
  2458. }
  2459. if ( $DrawBorder )
  2460. {
  2461. $ShadowSettings = $this->ShadowActive; $this->ShadowActive = FALSE;
  2462. $this->drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B);
  2463. $this->ShadowActive = $ShadowSettings;
  2464. }
  2465. }
  2466. /* This function create a rectangle with rounded corners and antialias */
  2467. function drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
  2468. {
  2469. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2470. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2471. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2472. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2473. $Step = 90 / ((3.1418 * $Radius)/2);
  2474. for($i=0;$i<=90;$i=$i+$Step)
  2475. {
  2476. $X = cos(($i+180)*3.1418/180) * $Radius + $X1 + $Radius;
  2477. $Y = sin(($i+180)*3.1418/180) * $Radius + $Y1 + $Radius;
  2478. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2479. $X = cos(($i-90)*3.1418/180) * $Radius + $X2 - $Radius;
  2480. $Y = sin(($i-90)*3.1418/180) * $Radius + $Y1 + $Radius;
  2481. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2482. $X = cos(($i)*3.1418/180) * $Radius + $X2 - $Radius;
  2483. $Y = sin(($i)*3.1418/180) * $Radius + $Y2 - $Radius;
  2484. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2485. $X = cos(($i+90)*3.1418/180) * $Radius + $X1 + $Radius;
  2486. $Y = sin(($i+90)*3.1418/180) * $Radius + $Y2 - $Radius;
  2487. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2488. }
  2489. $X1=$X1-.2;$Y1=$Y1-.2;
  2490. $X2=$X2+.2;$Y2=$Y2+.2;
  2491. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$R,$G,$B);
  2492. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$R,$G,$B);
  2493. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$R,$G,$B);
  2494. $this->drawLine($X1,$Y2-$Radius,$X1,$Y1+$Radius,$R,$G,$B);
  2495. }
  2496. /* This function create a filled rectangle with rounded corners and antialias */
  2497. function drawFilledRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
  2498. {
  2499. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2500. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2501. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2502. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2503. $Step = 90 / ((3.1418 * $Radius)/2);
  2504. for($i=0;$i<=90;$i=$i+$Step)
  2505. {
  2506. $Xi1 = cos(($i+180)*3.1418/180) * $Radius + $X1 + $Radius;
  2507. $Yi1 = sin(($i+180)*3.1418/180) * $Radius + $Y1 + $Radius;
  2508. $Xi2 = cos(($i-90)*3.1418/180) * $Radius + $X2 - $Radius;
  2509. $Yi2 = sin(($i-90)*3.1418/180) * $Radius + $Y1 + $Radius;
  2510. $Xi3 = cos(($i)*3.1418/180) * $Radius + $X2 - $Radius;
  2511. $Yi3 = sin(($i)*3.1418/180) * $Radius + $Y2 - $Radius;
  2512. $Xi4 = cos(($i+90)*3.1418/180) * $Radius + $X1 + $Radius;
  2513. $Yi4 = sin(($i+90)*3.1418/180) * $Radius + $Y2 - $Radius;
  2514. imageline($this->Picture,$Xi1,$Yi1,$X1+$Radius,$Yi1,$C_Rectangle);
  2515. imageline($this->Picture,$X2-$Radius,$Yi2,$Xi2,$Yi2,$C_Rectangle);
  2516. imageline($this->Picture,$X2-$Radius,$Yi3,$Xi3,$Yi3,$C_Rectangle);
  2517. imageline($this->Picture,$Xi4,$Yi4,$X1+$Radius,$Yi4,$C_Rectangle);
  2518. $this->drawAntialiasPixel($Xi1,$Yi1,$R,$G,$B);
  2519. $this->drawAntialiasPixel($Xi2,$Yi2,$R,$G,$B);
  2520. $this->drawAntialiasPixel($Xi3,$Yi3,$R,$G,$B);
  2521. $this->drawAntialiasPixel($Xi4,$Yi4,$R,$G,$B);
  2522. }
  2523. imagefilledrectangle($this->Picture,$X1,$Y1+$Radius,$X2,$Y2-$Radius,$C_Rectangle);
  2524. imagefilledrectangle($this->Picture,$X1+$Radius,$Y1,$X2-$Radius,$Y2,$C_Rectangle);
  2525. $X1=$X1-.2;$Y1=$Y1-.2;
  2526. $X2=$X2+.2;$Y2=$Y2+.2;
  2527. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$R,$G,$B);
  2528. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$R,$G,$B);
  2529. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$R,$G,$B);
  2530. $this->drawLine($X1,$Y2-$Radius,$X1,$Y1+$Radius,$R,$G,$B);
  2531. }
  2532. /* This function create a circle with antialias */
  2533. function drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
  2534. {
  2535. if ( $Width == 0 ) { $Width = $Height; }
  2536. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2537. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2538. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2539. $C_Circle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2540. $Step = 360 / (2 * 3.1418 * max($Width,$Height));
  2541. for($i=0;$i<=360;$i=$i+$Step)
  2542. {
  2543. $X = cos($i*3.1418/180) * $Height + $Xc;
  2544. $Y = sin($i*3.1418/180) * $Width + $Yc;
  2545. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2546. }
  2547. }
  2548. /* This function create a filled circle/ellipse with antialias */
  2549. function drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
  2550. {
  2551. if ( $Width == 0 ) { $Width = $Height; }
  2552. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2553. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2554. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2555. $C_Circle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2556. $Step = 360 / (2 * 3.1418 * max($Width,$Height));
  2557. for($i=90;$i<=270;$i=$i+$Step)
  2558. {
  2559. $X1 = cos($i*3.1418/180) * $Height + $Xc;
  2560. $Y1 = sin($i*3.1418/180) * $Width + $Yc;
  2561. $X2 = cos((180-$i)*3.1418/180) * $Height + $Xc;
  2562. $Y2 = sin((180-$i)*3.1418/180) * $Width + $Yc;
  2563. $this->drawAntialiasPixel($X1-1,$Y1-1,$R,$G,$B);
  2564. $this->drawAntialiasPixel($X2-1,$Y2-1,$R,$G,$B);
  2565. if ( ($Y1-1) > $Yc - max($Width,$Height) )
  2566. imageline($this->Picture,$X1,$Y1-1,$X2-1,$Y2-1,$C_Circle);
  2567. }
  2568. }
  2569. /* This function will draw a filled ellipse */
  2570. function drawEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
  2571. { $this->drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width); }
  2572. /* This function will draw an ellipse */
  2573. function drawFilledEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
  2574. { $this->drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width); }
  2575. /* This function create a line with antialias */
  2576. function drawLine($X1,$Y1,$X2,$Y2,$R,$G,$B,$GraphFunction=FALSE)
  2577. {
  2578. if ( $this->LineDotSize > 1 ) { $this->drawDottedLine($X1,$Y1,$X2,$Y2,$this->LineDotSize,$R,$G,$B,$GraphFunction); return(0); }
  2579. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2580. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2581. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2582. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  2583. if ( $Distance == 0 )
  2584. return(-1);
  2585. $XStep = ($X2-$X1) / $Distance;
  2586. $YStep = ($Y2-$Y1) / $Distance;
  2587. for($i=0;$i<=$Distance;$i++)
  2588. {
  2589. $X = $i * $XStep + $X1;
  2590. $Y = $i * $YStep + $Y1;
  2591. if ( ($X >= $this->GArea_X1 && $X <= $this->GArea_X2 && $Y >= $this->GArea_Y1 && $Y <= $this->GArea_Y2) || !$GraphFunction )
  2592. {
  2593. if ( $this->LineWidth == 1 )
  2594. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2595. else
  2596. {
  2597. $StartOffset = -($this->LineWidth/2); $EndOffset = ($this->LineWidth/2);
  2598. for($j=$StartOffset;$j<=$EndOffset;$j++)
  2599. $this->drawAntialiasPixel($X+$j,$Y+$j,$R,$G,$B);
  2600. }
  2601. }
  2602. }
  2603. }
  2604. /* This function create a line with antialias */
  2605. function drawDottedLine($X1,$Y1,$X2,$Y2,$DotSize,$R,$G,$B,$GraphFunction=FALSE)
  2606. {
  2607. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2608. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2609. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2610. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  2611. $XStep = ($X2-$X1) / $Distance;
  2612. $YStep = ($Y2-$Y1) / $Distance;
  2613. $DotIndex = 0;
  2614. for($i=0;$i<=$Distance;$i++)
  2615. {
  2616. $X = $i * $XStep + $X1;
  2617. $Y = $i * $YStep + $Y1;
  2618. if ( $DotIndex <= $DotSize)
  2619. {
  2620. if ( ($X >= $this->GArea_X1 && $X <= $this->GArea_X2 && $Y >= $this->GArea_Y1 && $Y <= $this->GArea_Y2) || !$GraphFunction )
  2621. {
  2622. if ( $this->LineWidth == 1 )
  2623. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2624. else
  2625. {
  2626. $StartOffset = -($this->LineWidth/2); $EndOffset = ($this->LineWidth/2);
  2627. for($j=$StartOffset;$j<=$EndOffset;$j++)
  2628. $this->drawAntialiasPixel($X+$j,$Y+$j,$R,$G,$B);
  2629. }
  2630. }
  2631. }
  2632. $DotIndex++;
  2633. if ( $DotIndex == $DotSize * 2 )
  2634. $DotIndex = 0;
  2635. }
  2636. }
  2637. /* Load a PNG file and draw it over the chart */
  2638. function drawFromPNG($FileName,$X,$Y,$Alpha=100)
  2639. { $this->drawFromPicture(1,$FileName,$X,$Y,$Alpha); }
  2640. /* Load a GIF file and draw it over the chart */
  2641. function drawFromGIF($FileName,$X,$Y,$Alpha=100)
  2642. { $this->drawFromPicture(2,$FileName,$X,$Y,$Alpha); }
  2643. /* Load a JPEG file and draw it over the chart */
  2644. function drawFromJPG($FileName,$X,$Y,$Alpha=100)
  2645. { $this->drawFromPicture(3,$FileName,$X,$Y,$Alpha); }
  2646. /* Generic loader function for external pictures */
  2647. function drawFromPicture($PicType,$FileName,$X,$Y,$Alpha=100)
  2648. {
  2649. if ( file_exists($FileName))
  2650. {
  2651. $Infos = getimagesize($FileName);
  2652. $Width = $Infos[0];
  2653. $Height = $Infos[1];
  2654. if ( $PicType == 1 ) { $Raster = imagecreatefrompng($FileName); }
  2655. if ( $PicType == 2 ) { $Raster = imagecreatefromgif($FileName); }
  2656. if ( $PicType == 3 ) { $Raster = imagecreatefromjpeg($FileName); }
  2657. imagecopymerge($this->Picture,$Raster,$X,$Y,0,0,$Width,$Height,$Alpha);
  2658. imagedestroy($Raster);
  2659. }
  2660. }
  2661. /* Draw an alpha pixel */
  2662. function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
  2663. {
  2664. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2665. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2666. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2667. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  2668. return(-1);
  2669. $RGB2 = imagecolorat($this->Picture, $X, $Y);
  2670. $R2 = ($RGB2 >> 16) & 0xFF;
  2671. $G2 = ($RGB2 >> 8) & 0xFF;
  2672. $B2 = $RGB2 & 0xFF;
  2673. $iAlpha = (100 - $Alpha)/100;
  2674. $Alpha = $Alpha / 100;
  2675. $Ra = floor($R*$Alpha+$R2*$iAlpha);
  2676. $Ga = floor($G*$Alpha+$G2*$iAlpha);
  2677. $Ba = floor($B*$Alpha+$B2*$iAlpha);
  2678. $C_Aliased = $this->AllocateColor($this->Picture,$Ra,$Ga,$Ba);
  2679. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  2680. }
  2681. /* Color helper */
  2682. function AllocateColor($Picture,$R,$G,$B,$Factor=0)
  2683. {
  2684. $R = $R + $Factor;
  2685. $G = $G + $Factor;
  2686. $B = $B + $Factor;
  2687. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2688. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2689. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2690. return(imagecolorallocate($Picture,$R,$G,$B));
  2691. }
  2692. /* Add a border to the picture */
  2693. function addBorder($Size=3,$R=0,$G=0,$B=0)
  2694. {
  2695. $Width = $this->XSize+2*$Size;
  2696. $Height = $this->YSize+2*$Size;
  2697. $Resampled = imagecreatetruecolor($Width,$Height);
  2698. $C_Background = $this->AllocateColor($Resampled,$R,$G,$B);
  2699. imagefilledrectangle($Resampled,0,0,$Width,$Height,$C_Background);
  2700. imagecopy($Resampled,$this->Picture,$Size,$Size,0,0,$this->XSize,$this->YSize);
  2701. imagedestroy($this->Picture);
  2702. $this->XSize = $Width;
  2703. $this->YSize = $Height;
  2704. $this->Picture = imagecreatetruecolor($this->XSize,$this->YSize);
  2705. $C_White = $this->AllocateColor($this->Picture,255,255,255);
  2706. imagefilledrectangle($this->Picture,0,0,$this->XSize,$this->YSize,$C_White);
  2707. imagecolortransparent($this->Picture,$C_White);
  2708. imagecopy($this->Picture,$Resampled,0,0,0,0,$this->XSize,$this->YSize);
  2709. }
  2710. /* Render the current picture to a file */
  2711. function Render($FileName)
  2712. {
  2713. if ( $this->ErrorReporting )
  2714. $this->printErrors($this->ErrorInterface);
  2715. /* Save image map if requested */
  2716. if ( $this->BuildMap )
  2717. $this->SaveImageMap();
  2718. imagepng($this->Picture,$FileName);
  2719. }
  2720. /* Render the current picture to STDOUT */
  2721. function Stroke()
  2722. {
  2723. if ( $this->ErrorReporting )
  2724. $this->printErrors("GD");
  2725. /* Save image map if requested */
  2726. if ( $this->BuildMap )
  2727. $this->SaveImageMap();
  2728. header('Content-type: image/png');
  2729. imagepng($this->Picture);
  2730. }
  2731. /* Private functions for internal processing */
  2732. function drawAntialiasPixel($X,$Y,$R,$G,$B,$Alpha=100,$NoFallBack=FALSE)
  2733. {
  2734. /* Process shadows */
  2735. if ( $this->ShadowActive && !$NoFallBack )
  2736. {
  2737. $this->drawAntialiasPixel($X+$this->ShadowXDistance,$Y+$this->ShadowYDistance,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha,TRUE);
  2738. if ( $this->ShadowBlur != 0 )
  2739. {
  2740. $AlphaDecay = ($this->ShadowAlpha / $this->ShadowBlur);
  2741. for($i=1; $i<=$this->ShadowBlur; $i++)
  2742. $this->drawAntialiasPixel($X+$this->ShadowXDistance-$i/2,$Y+$this->ShadowYDistance-$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha-$AlphaDecay*$i,TRUE);
  2743. for($i=1; $i<=$this->ShadowBlur; $i++)
  2744. $this->drawAntialiasPixel($X+$this->ShadowXDistance+$i/2,$Y+$this->ShadowYDistance+$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha-$AlphaDecay*$i,TRUE);
  2745. }
  2746. }
  2747. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2748. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2749. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2750. $Plot = "";
  2751. $Xi = floor($X);
  2752. $Yi = floor($Y);
  2753. if ( $Xi == $X && $Yi == $Y)
  2754. {
  2755. if ( $Alpha == 100 )
  2756. {
  2757. $C_Aliased = $this->AllocateColor($this->Picture,$R,$G,$B);
  2758. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  2759. }
  2760. else
  2761. $this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B);
  2762. }
  2763. else
  2764. {
  2765. $Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  2766. if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); }
  2767. $Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  2768. if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); }
  2769. $Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  2770. if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); }
  2771. $Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  2772. if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); }
  2773. }
  2774. }
  2775. /* Validate data contained in the description array */
  2776. function validateDataDescription($FunctionName,&$DataDescription,$DescriptionRequired=TRUE)
  2777. {
  2778. if (!isset($DataDescription["Position"]))
  2779. {
  2780. $this->Errors[] = "[Warning] ".$FunctionName." - Y Labels are not set.";
  2781. $DataDescription["Position"] = "Name";
  2782. }
  2783. if ( $DescriptionRequired )
  2784. {
  2785. if (!isset($DataDescription["Description"]))
  2786. {
  2787. $this->Errors[] = "[Warning] ".$FunctionName." - Series descriptions are not set.";
  2788. foreach($DataDescription["Values"] as $key => $Value)
  2789. {
  2790. $DataDescription["Description"][$Value] = $Value;
  2791. }
  2792. }
  2793. if (count($DataDescription["Description"]) < count($DataDescription["Values"]))
  2794. {
  2795. $this->Errors[] = "[Warning] ".$FunctionName." - Some series descriptions are not set.";
  2796. foreach($DataDescription["Values"] as $key => $Value)
  2797. {
  2798. if ( !isset($DataDescription["Description"][$Value]))
  2799. $DataDescription["Description"][$Value] = $Value;
  2800. }
  2801. }
  2802. }
  2803. }
  2804. /* Validate data contained in the data array */
  2805. function validateData($FunctionName,&$Data)
  2806. {
  2807. $DataSummary = array();
  2808. foreach($Data as $key => $Values)
  2809. {
  2810. foreach($Values as $key2 => $Value)
  2811. {
  2812. if (!isset($DataSummary[$key2]))
  2813. $DataSummary[$key2] = 1;
  2814. else
  2815. $DataSummary[$key2]++;
  2816. }
  2817. }
  2818. if ( max($DataSummary) == 0 )
  2819. $this->Errors[] = "[Warning] ".$FunctionName." - No data set.";
  2820. foreach($DataSummary as $key => $Value)
  2821. {
  2822. if ($Value < max($DataSummary))
  2823. {
  2824. $this->Errors[] = "[Warning] ".$FunctionName." - Missing data in serie ".$key.".";
  2825. }
  2826. }
  2827. }
  2828. /* Print all error messages on the CLI or graphically */
  2829. function printErrors($Mode="CLI")
  2830. {
  2831. if (count($this->Errors) == 0)
  2832. return(0);
  2833. if ( $Mode == "CLI" )
  2834. {
  2835. foreach($this->Errors as $key => $Value)
  2836. echo $Value."\r\n";
  2837. }
  2838. elseif ( $Mode == "GD" )
  2839. {
  2840. $this->setLineStyle($Width=1);
  2841. $MaxWidth = 0;
  2842. foreach($this->Errors as $key => $Value)
  2843. {
  2844. $Position = imageftbbox($this->ErrorFontSize,0,$this->ErrorFontName,$Value);
  2845. $TextWidth = $Position[2]-$Position[0];
  2846. if ( $TextWidth > $MaxWidth ) { $MaxWidth = $TextWidth; }
  2847. }
  2848. $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);
  2849. $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);
  2850. $C_TextColor = $this->AllocateColor($this->Picture,133,85,85);
  2851. $YPos = $this->YSize - (18 + (count($this->Errors)-1) * ($this->ErrorFontSize + 4));
  2852. foreach($this->Errors as $key => $Value)
  2853. {
  2854. imagettftext($this->Picture,$this->ErrorFontSize,0,$this->XSize-($MaxWidth+15),$YPos,$C_TextColor,$this->ErrorFontName,$Value);
  2855. $YPos = $YPos + ($this->ErrorFontSize + 4);
  2856. }
  2857. }
  2858. }
  2859. /* Activate the image map creation process */
  2860. function setImageMap($Mode=TRUE,$GraphID="MyGraph")
  2861. {
  2862. $this->BuildMap = $Mode;
  2863. $this->MapID = $GraphID;
  2864. }
  2865. /* Add a box into the image map */
  2866. function addToImageMap($X1,$Y1,$X2,$Y2,$SerieName,$Value,$CallerFunction)
  2867. {
  2868. if ( $this->MapFunction == NULL || $this->MapFunction == $CallerFunction )
  2869. {
  2870. $this->ImageMap[] = round($X1).",".round($Y1).",".round($X2).",".round($Y2).",".$SerieName.",".$Value;
  2871. $this->MapFunction = $CallerFunction;
  2872. }
  2873. }
  2874. /* Load and cleanup the image map from disk */
  2875. function getImageMap($MapName,$Flush=TRUE)
  2876. {
  2877. /* Strip HTML query strings */
  2878. $Values = $this->tmpFolder.$MapName;
  2879. $Value = split("\?",$Values);
  2880. $FileName = $Value[0];
  2881. if ( file_exists($FileName) )
  2882. {
  2883. $Handle = fopen($FileName, "r");
  2884. $MapContent = fread($Handle, filesize($FileName));
  2885. fclose($Handle);
  2886. echo $MapContent;
  2887. if ( $Flush )
  2888. unlink($FileName);
  2889. exit();
  2890. }
  2891. else
  2892. {
  2893. header("HTTP/1.0 404 Not Found");
  2894. exit();
  2895. }
  2896. }
  2897. /* Save the image map to the disk */
  2898. function SaveImageMap()
  2899. {
  2900. if ( !$this->BuildMap ) { return(-1); }
  2901. if ( $this->ImageMap == NULL )
  2902. {
  2903. $this->Errors[] = "[Warning] SaveImageMap - Image map is empty.";
  2904. return(-1);
  2905. }
  2906. $Handle = fopen($this->tmpFolder.$this->MapID, 'w');
  2907. if ( !$Handle )
  2908. {
  2909. $this->Errors[] = "[Warning] SaveImageMap - Cannot save the image map.";
  2910. return(-1);
  2911. }
  2912. else
  2913. {
  2914. foreach($this->ImageMap as $Key => $Value)
  2915. fwrite($Handle, htmlentities($Value)."\r");
  2916. }
  2917. fclose ($Handle);
  2918. }
  2919. /* Convert seconds to a time format string */
  2920. function ToTime($Value)
  2921. {
  2922. $Hour = floor($Value/3600);
  2923. $Minute = floor(($Value - $Hour*3600)/60);
  2924. $Second = floor($Value - $Hour*3600 - $Minute*60);
  2925. if (strlen($Hour) == 1 ) { $Hour = "0".$Hour; }
  2926. if (strlen($Minute) == 1 ) { $Minute = "0".$Minute; }
  2927. if (strlen($Second) == 1 ) { $Second = "0".$Second; }
  2928. return($Hour.":".$Minute.":".$Second);
  2929. }
  2930. /* Convert to metric system */
  2931. function ToMetric($Value)
  2932. {
  2933. $Go = floor($Value/1000000000);
  2934. $Mo = floor(($Value - $Go*1000000000)/1000000);
  2935. $Ko = floor(($Value - $Go*1000000000 - $Mo*1000000)/1000);
  2936. $o = floor($Value - $Go*1000000000 - $Mo*1000000 - $Ko*1000);
  2937. if ($Go != 0) { return($Go.".".$Mo."g"); }
  2938. if ($Mo != 0) { return($Mo.".".$ko."m"); }
  2939. if ($Ko != 0) { return($Ko.".".$o)."k"; }
  2940. return($o);
  2941. }
  2942. /* Convert to curency */
  2943. function ToCurrency($Value)
  2944. {
  2945. $Go = floor($Value/1000000000);
  2946. $Mo = floor(($Value - $Go*1000000000)/1000000);
  2947. $Ko = floor(($Value - $Go*1000000000 - $Mo*1000000)/1000);
  2948. $o = floor($Value - $Go*1000000000 - $Mo*1000000 - $Ko*1000);
  2949. if ( strlen($o) == 1 ) { $o = "00".$o; }
  2950. if ( strlen($o) == 2 ) { $o = "0".$o; }
  2951. $ResultString = $o;
  2952. if ( $Ko != 0 ) { $ResultString = $Ko.".".$ResultString; }
  2953. if ( $Mo != 0 ) { $ResultString = $Mo.".".$ResultString; }
  2954. if ( $Go != 0 ) { $ResultString = $Go.".".$ResultString; }
  2955. $ResultString = $this->Currency.$ResultString;
  2956. return($ResultString);
  2957. }
  2958. /* Set date format for axis labels */
  2959. function setDateFormat($Format)
  2960. {
  2961. $this->DateFormat = $Format;
  2962. }
  2963. /* Convert TS to a date format string */
  2964. function ToDate($Value)
  2965. {
  2966. return(date($this->DateFormat,$Value));
  2967. }
  2968. /* Check if a number is a full integer (for scaling) */
  2969. function isRealInt($Value)
  2970. {
  2971. if ($Value == floor($Value))
  2972. return(TRUE);
  2973. return(FALSE);
  2974. }
  2975. }
  2976. function RaiseFatal($Message)
  2977. {
  2978. echo "[FATAL] ".$Message."\r\n";
  2979. exit();
  2980. }
  2981. ?>