pChart.class.php 139 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655
  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. // Will change XY positions to show the right label position
  541. // To detect side of cartesian plane XY where angles ends
  542. // e.g 60 degree is in Quadrant I, 120 degree is Quadrant II
  543. $isYpositive = sin(deg2rad($Angle)) >= 0;
  544. $isXpositive = cos(deg2rad($Angle)) >= 0;
  545. $YPos = $this->GArea_Y2 + 10;
  546. if ($isYpositive && $isXpositive) {
  547. // For Quadrant I
  548. $YPos += $TextHeight;
  549. $XPos -= $TextWidth;
  550. } elseif ($isYpositive && !$isXpositive) {
  551. // For Quadrant II
  552. $YPos += $TextHeight;
  553. $XPos += $TextWidth;
  554. } elseif (!$isYpositive && !$isXpositive) {
  555. // For Quadrant III
  556. // Nothing to do
  557. } else {
  558. // For Quadrant IV
  559. // Nothing to do
  560. }
  561. imagettftext(
  562. $this->Picture,
  563. $this->FontSize,
  564. $Angle,
  565. $XPos,
  566. $YPos,
  567. $C_TextColor,
  568. $this->FontName,
  569. $Value
  570. );
  571. // post update XY position
  572. if ($isYpositive && $isXpositive) {
  573. // For Quadrant I
  574. $XPos += $TextWidth;
  575. } elseif ($isYpositive && !$isXpositive) {
  576. // For Quadrant II
  577. $XPos -= $TextWidth;
  578. } elseif (!$isYpositive && !$isXpositive) {
  579. // For Quadrant III
  580. $YPos += $TextHeight;
  581. } else {
  582. // For Quadrant IV
  583. $YPos += $TextHeight;
  584. }
  585. }
  586. if ( $YMax < $YPos || $YMax == NULL ) { $YMax = $YPos; }
  587. }
  588. $XPos = $XPos + $this->DivisionWidth;
  589. $ID++;
  590. }
  591. /* Write the X Axis caption if set */
  592. if (isset($DataDescription["Axis"]["X"]))
  593. {
  594. $Position = imageftbbox($this->FontSize, 0, $this->FontName, $DataDescription["Axis"]["X"]);
  595. $TextWidth = abs($Position[2]) + abs($Position[0]);
  596. $TextLeft = (($this->GArea_X2 + $this->GArea_X1) / 2) - ($TextWidth/2);
  597. imagettftext(
  598. $this->Picture,
  599. $this->FontSize,
  600. 0,
  601. $TextLeft,
  602. $YMax+$this->FontSize+5,
  603. $C_TextColor,
  604. $this->FontName,
  605. $DataDescription["Axis"]["X"]
  606. );
  607. }
  608. }
  609. /* Compute and draw the scale for X/Y charts */
  610. function drawXYScale($Data,$DataDescription,$YSerieName,$XSerieName,$R,$G,$B,$WithMargin=0,$Angle=0,$Decimals=1)
  611. {
  612. /* Validate the Data and DataDescription array */
  613. $this->validateData("drawScale",$Data);
  614. $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
  615. $this->drawLine($this->GArea_X1,$this->GArea_Y1,$this->GArea_X1,$this->GArea_Y2,$R,$G,$B);
  616. $this->drawLine($this->GArea_X1,$this->GArea_Y2,$this->GArea_X2,$this->GArea_Y2,$R,$G,$B);
  617. /* Process Y scale */
  618. if ( $this->VMin == NULL && $this->VMax == NULL)
  619. {
  620. $this->VMin = $Data[0][$YSerieName];
  621. $this->VMax = $Data[0][$YSerieName];
  622. foreach ( $Data as $Key => $Values )
  623. {
  624. if (isset($Data[$Key][$YSerieName]))
  625. {
  626. $Value = $Data[$Key][$YSerieName];
  627. if ( $this->VMax < $Value) { $this->VMax = $Value; }
  628. if ( $this->VMin > $Value) { $this->VMin = $Value; }
  629. }
  630. }
  631. if ( $this->VMax > preg_replace('/\.[0-9]+/','',$this->VMax) )
  632. $this->VMax = preg_replace('/\.[0-9]+/','',$this->VMax)+1;
  633. $DataRange = $this->VMax - $this->VMin;
  634. if ( $DataRange == 0 ) { $DataRange = .1; }
  635. /* Compute automatic scaling */
  636. $ScaleOk = FALSE; $Factor = 1;
  637. $MinDivHeight = 25; $MaxDivs = ($this->GArea_Y2 - $this->GArea_Y1) / $MinDivHeight;
  638. if ( $this->VMin == 0 && $this->VMax == 0 )
  639. { $this->VMin = 0; $this->VMax = 2; $Scale = 1; $Divisions = 2;}
  640. elseif ($MaxDivs > 1)
  641. {
  642. while(!$ScaleOk)
  643. {
  644. $Scale1 = ( $this->VMax - $this->VMin ) / $Factor;
  645. $Scale2 = ( $this->VMax - $this->VMin ) / $Factor / 2;
  646. $Scale4 = ( $this->VMax - $this->VMin ) / $Factor / 4;
  647. if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale1); $Scale = 1;}
  648. if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $Divisions = floor($Scale2); $Scale = 2;}
  649. if (!$ScaleOk)
  650. {
  651. if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
  652. if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
  653. }
  654. }
  655. if ( floor($this->VMax / $Scale / $Factor) != $this->VMax / $Scale / $Factor)
  656. {
  657. $GridID = floor ( $this->VMax / $Scale / $Factor) + 1;
  658. $this->VMax = $GridID * $Scale * $Factor;
  659. $Divisions++;
  660. }
  661. if ( floor($this->VMin / $Scale / $Factor) != $this->VMin / $Scale / $Factor)
  662. {
  663. $GridID = floor( $this->VMin / $Scale / $Factor);
  664. $this->VMin = $GridID * $Scale * $Factor;
  665. $Divisions++;
  666. }
  667. }
  668. else /* Can occurs for small graphs */
  669. $Scale = 1;
  670. if ( !isset($Divisions) )
  671. $Divisions = 2;
  672. if ( $this->isRealInt(($this->VMax-$this->VMin)/($Divisions-1)))
  673. $Divisions--;
  674. elseif ( $this->isRealInt(($this->VMax-$this->VMin)/($Divisions+1)))
  675. $Divisions++;
  676. }
  677. else
  678. $Divisions = $this->Divisions;
  679. $this->DivisionCount = $Divisions;
  680. $DataRange = $this->VMax - $this->VMin;
  681. if ( $DataRange == 0 ) { $DataRange = .1; }
  682. $this->DivisionHeight = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $Divisions;
  683. $this->DivisionRatio = ( $this->GArea_Y2 - $this->GArea_Y1 ) / $DataRange;
  684. $YPos = $this->GArea_Y2; $XMin = NULL;
  685. for($i=1;$i<=$Divisions+1;$i++)
  686. {
  687. $this->drawLine($this->GArea_X1,$YPos,$this->GArea_X1-5,$YPos,$R,$G,$B);
  688. $Value = $this->VMin + ($i-1) * (( $this->VMax - $this->VMin ) / $Divisions);
  689. $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals);
  690. if ( $DataDescription["Format"]["Y"] == "number" )
  691. $Value = $Value.$DataDescription["Unit"]["Y"];
  692. if ( $DataDescription["Format"]["Y"] == "time" )
  693. $Value = $this->ToTime($Value);
  694. if ( $DataDescription["Format"]["Y"] == "date" )
  695. $Value = $this->ToDate($Value);
  696. if ( $DataDescription["Format"]["Y"] == "metric" )
  697. $Value = $this->ToMetric($Value);
  698. if ( $DataDescription["Format"]["Y"] == "currency" )
  699. $Value = $this->ToCurrency($Value);
  700. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  701. $TextWidth = $Position[2]-$Position[0];
  702. imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1-10-$TextWidth,$YPos+($this->FontSize/2),$C_TextColor,$this->FontName,$Value);
  703. if ( $XMin > $this->GArea_X1-10-$TextWidth || $XMin == NULL ) { $XMin = $this->GArea_X1-10-$TextWidth; }
  704. $YPos = $YPos - $this->DivisionHeight;
  705. }
  706. /* Process X scale */
  707. if ( $this->VXMin == NULL && $this->VXMax == NULL)
  708. {
  709. $this->VXMin = $Data[0][$XSerieName];
  710. $this->VXMax = $Data[0][$XSerieName];
  711. foreach ( $Data as $Key => $Values )
  712. {
  713. if (isset($Data[$Key][$XSerieName]))
  714. {
  715. $Value = $Data[$Key][$XSerieName];
  716. if ( $this->VXMax < $Value) { $this->VXMax = $Value; }
  717. if ( $this->VXMin > $Value) { $this->VXMin = $Value; }
  718. }
  719. }
  720. if ( $this->VXMax > preg_replace('/\.[0-9]+/','',$this->VXMax) )
  721. $this->VXMax = preg_replace('/\.[0-9]+/','',$this->VXMax)+1;
  722. $DataRange = $this->VMax - $this->VMin;
  723. if ( $DataRange == 0 ) { $DataRange = .1; }
  724. /* Compute automatic scaling */
  725. $ScaleOk = FALSE; $Factor = 1;
  726. $MinDivWidth = 25; $MaxDivs = ($this->GArea_X2 - $this->GArea_X1) / $MinDivWidth;
  727. if ( $this->VXMin == 0 && $this->VXMax == 0 )
  728. { $this->VXMin = 0; $this->VXMax = 2; $Scale = 1; $XDivisions = 2;}
  729. elseif ($MaxDivs > 1)
  730. {
  731. while(!$ScaleOk)
  732. {
  733. $Scale1 = ( $this->VXMax - $this->VXMin ) / $Factor;
  734. $Scale2 = ( $this->VXMax - $this->VXMin ) / $Factor / 2;
  735. $Scale4 = ( $this->VXMax - $this->VXMin ) / $Factor / 4;
  736. if ( $Scale1 > 1 && $Scale1 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $XDivisions = floor($Scale1); $Scale = 1;}
  737. if ( $Scale2 > 1 && $Scale2 <= $MaxDivs && !$ScaleOk) { $ScaleOk = TRUE; $XDivisions = floor($Scale2); $Scale = 2;}
  738. if (!$ScaleOk)
  739. {
  740. if ( $Scale2 > 1 ) { $Factor = $Factor * 10; }
  741. if ( $Scale2 < 1 ) { $Factor = $Factor / 10; }
  742. }
  743. }
  744. if ( floor($this->VXMax / $Scale / $Factor) != $this->VXMax / $Scale / $Factor)
  745. {
  746. $GridID = floor ( $this->VXMax / $Scale / $Factor) + 1;
  747. $this->VXMax = $GridID * $Scale * $Factor;
  748. $XDivisions++;
  749. }
  750. if ( floor($this->VXMin / $Scale / $Factor) != $this->VXMin / $Scale / $Factor)
  751. {
  752. $GridID = floor( $this->VXMin / $Scale / $Factor);
  753. $this->VXMin = $GridID * $Scale * $Factor;
  754. $XDivisions++;
  755. }
  756. }
  757. else /* Can occurs for small graphs */
  758. $Scale = 1;
  759. if ( !isset($XDivisions) )
  760. $XDivisions = 2;
  761. if ( $this->isRealInt(($this->VXMax-$this->VXMin)/($XDivisions-1)))
  762. $XDivisions--;
  763. elseif ( $this->isRealInt(($this->VXMax-$this->VXMin)/($XDivisions+1)))
  764. $XDivisions++;
  765. }
  766. else
  767. $XDivisions = $this->XDivisions;
  768. $this->XDivisionCount = $Divisions;
  769. $this->DataCount = $Divisions + 2;
  770. $XDataRange = $this->VXMax - $this->VXMin;
  771. if ( $XDataRange == 0 ) { $XDataRange = .1; }
  772. $this->DivisionWidth = ( $this->GArea_X2 - $this->GArea_X1 ) / $XDivisions;
  773. $this->XDivisionRatio = ( $this->GArea_X2 - $this->GArea_X1 ) / $XDataRange;
  774. $XPos = $this->GArea_X1; $YMax = NULL;
  775. for($i=1;$i<=$XDivisions+1;$i++)
  776. {
  777. $this->drawLine($XPos,$this->GArea_Y2,$XPos,$this->GArea_Y2+5,$R,$G,$B);
  778. $Value = $this->VXMin + ($i-1) * (( $this->VXMax - $this->VXMin ) / $XDivisions);
  779. $Value = round($Value * pow(10,$Decimals)) / pow(10,$Decimals);
  780. if ( $DataDescription["Format"]["Y"] == "number" )
  781. $Value = $Value.$DataDescription["Unit"]["Y"];
  782. if ( $DataDescription["Format"]["Y"] == "time" )
  783. $Value = $this->ToTime($Value);
  784. if ( $DataDescription["Format"]["Y"] == "date" )
  785. $Value = $this->ToDate($Value);
  786. if ( $DataDescription["Format"]["Y"] == "metric" )
  787. $Value = $this->ToMetric($Value);
  788. if ( $DataDescription["Format"]["Y"] == "currency" )
  789. $Value = $this->ToCurrency($Value);
  790. $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Value);
  791. $TextWidth = abs($Position[2])+abs($Position[0]);
  792. $TextHeight = abs($Position[1])+abs($Position[3]);
  793. if ( $Angle == 0 )
  794. {
  795. $YPos = $this->GArea_Y2+18;
  796. imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-floor($TextWidth/2),$YPos,$C_TextColor,$this->FontName,$Value);
  797. }
  798. else
  799. {
  800. $YPos = $this->GArea_Y2+10+$TextHeight;
  801. if ( $Angle <= 90 )
  802. imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)-$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
  803. else
  804. imagettftext($this->Picture,$this->FontSize,$Angle,floor($XPos)+$TextWidth+5,$YPos,$C_TextColor,$this->FontName,$Value);
  805. }
  806. if ( $YMax < $YPos || $YMax == NULL ) { $YMax = $YPos; }
  807. $XPos = $XPos + $this->DivisionWidth;
  808. }
  809. /* Write the Y Axis caption if set */
  810. if ( isset($DataDescription["Axis"]["Y"]) )
  811. {
  812. $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["Y"]);
  813. $TextHeight = abs($Position[1])+abs($Position[3]);
  814. $TextTop = (($this->GArea_Y2 - $this->GArea_Y1) / 2) + $this->GArea_Y1 + ($TextHeight/2);
  815. imagettftext($this->Picture,$this->FontSize,90,$XMin-$this->FontSize,$TextTop,$C_TextColor,$this->FontName,$DataDescription["Axis"]["Y"]);
  816. }
  817. /* Write the X Axis caption if set */
  818. if ( isset($DataDescription["Axis"]["X"]) )
  819. {
  820. $Position = imageftbbox($this->FontSize,90,$this->FontName,$DataDescription["Axis"]["X"]);
  821. $TextWidth = abs($Position[2])+abs($Position[0]);
  822. $TextLeft = (($this->GArea_X2 - $this->GArea_X1) / 2) + $this->GArea_X1 + ($TextWidth/2);
  823. imagettftext($this->Picture,$this->FontSize,0,$TextLeft,$YMax+$this->FontSize+5,$C_TextColor,$this->FontName,$DataDescription["Axis"]["X"]);
  824. }
  825. }
  826. /* Compute and draw the scale */
  827. function drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=100)
  828. {
  829. /* Draw mosaic */
  830. if ( $Mosaic )
  831. {
  832. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  833. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  834. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  835. $C_White =$this->AllocateColor($this->Layers[0],255,255,255);
  836. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  837. imagecolortransparent($this->Layers[0],$C_White);
  838. $C_Rectangle =$this->AllocateColor($this->Layers[0],250,250,250);
  839. $YPos = $LayerHeight; //$this->GArea_Y2-1;
  840. $LastY = $YPos;
  841. for($i=0;$i<=$this->DivisionCount;$i++)
  842. {
  843. $LastY = $YPos;
  844. $YPos = $YPos - $this->DivisionHeight;
  845. if ( $YPos <= 0 ) { $YPos = 1; }
  846. if ( $i % 2 == 0 )
  847. {
  848. imagefilledrectangle($this->Layers[0],1,$YPos,$LayerWidth-1,$LastY,$C_Rectangle);
  849. }
  850. }
  851. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  852. imagedestroy($this->Layers[0]);
  853. }
  854. /* Horizontal lines */
  855. $YPos = $this->GArea_Y2 - $this->DivisionHeight;
  856. for($i=1;$i<=$this->DivisionCount;$i++)
  857. {
  858. if ( $YPos > $this->GArea_Y1 && $YPos < $this->GArea_Y2 )
  859. $this->drawDottedLine($this->GArea_X1,$YPos,$this->GArea_X2,$YPos,$LineWidth,$R,$G,$B);
  860. $YPos = $YPos - $this->DivisionHeight;
  861. }
  862. /* Vertical lines */
  863. if ( $this->GAreaXOffset == 0 )
  864. { $XPos = $this->GArea_X1 + $this->DivisionWidth + $this->GAreaXOffset; $ColCount = $this->DataCount-2; }
  865. else
  866. { $XPos = $this->GArea_X1 + $this->GAreaXOffset; $ColCount = floor( ($this->GArea_X2 - $this->GArea_X1) / $this->DivisionWidth ); }
  867. for($i=1;$i<=$ColCount;$i++)
  868. {
  869. if ( $XPos > $this->GArea_X1 && $XPos < $this->GArea_X2 )
  870. $this->drawDottedLine(floor($XPos),$this->GArea_Y1,floor($XPos),$this->GArea_Y2,$LineWidth,$R,$G,$B);
  871. $XPos = $XPos + $this->DivisionWidth;
  872. }
  873. }
  874. /* retrieve the legends size */
  875. function getLegendBoxSize($DataDescription)
  876. {
  877. if ( !isset($DataDescription["Description"]) )
  878. return(-1);
  879. /* <-10->[8]<-4->Text<-10-> */
  880. $MaxWidth = 0; $MaxHeight = 8;
  881. foreach($DataDescription["Description"] as $Key => $Value)
  882. {
  883. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  884. $TextWidth = $Position[2]-$Position[0];
  885. $TextHeight = $Position[1]-$Position[7];
  886. if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; }
  887. $MaxHeight = $MaxHeight + $TextHeight + 4;
  888. }
  889. $MaxHeight = $MaxHeight - 3;
  890. $MaxWidth = $MaxWidth + 32;
  891. return(array($MaxWidth,$MaxHeight));
  892. }
  893. /* Draw the data legends */
  894. function drawLegend($XPos,$YPos,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-1,$Rt=0,$Gt=0,$Bt=0,$Border=TRUE)
  895. {
  896. /* Validate the Data and DataDescription array */
  897. $this->validateDataDescription("drawLegend",$DataDescription);
  898. if ( !isset($DataDescription["Description"]) )
  899. return(-1);
  900. $C_TextColor =$this->AllocateColor($this->Picture,$Rt,$Gt,$Bt);
  901. /* <-10->[8]<-4->Text<-10-> */
  902. $MaxWidth = 0; $MaxHeight = 8;
  903. foreach($DataDescription["Description"] as $Key => $Value)
  904. {
  905. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  906. $TextWidth = $Position[2]-$Position[0];
  907. $TextHeight = $Position[1]-$Position[7];
  908. if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; }
  909. $MaxHeight = $MaxHeight + $TextHeight + 4;
  910. }
  911. $MaxHeight = $MaxHeight - 5;
  912. $MaxWidth = $MaxWidth + 32;
  913. if ( $Rs == -1 || $Gs == -1 || $Bs == -1 )
  914. { $Rs = $R-30; $Gs = $G-30; $Bs = $B-30; }
  915. if ( $Border )
  916. {
  917. $this->drawFilledRoundedRectangle($XPos+1,$YPos+1,$XPos+$MaxWidth+1,$YPos+$MaxHeight+1,5,$Rs,$Gs,$Bs);
  918. $this->drawFilledRoundedRectangle($XPos,$YPos,$XPos+$MaxWidth,$YPos+$MaxHeight,5,$R,$G,$B);
  919. }
  920. $YOffset = 4 + $this->FontSize; $ID = 0;
  921. foreach($DataDescription["Description"] as $Key => $Value)
  922. {
  923. $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"]);
  924. imagettftext($this->Picture,$this->FontSize,0,$XPos+22,$YPos+$YOffset,$C_TextColor,$this->FontName,$Value);
  925. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  926. $TextHeight = $Position[1]-$Position[7];
  927. $YOffset = $YOffset + $TextHeight + 4;
  928. $ID++;
  929. }
  930. }
  931. /* Draw the data legends */
  932. function drawPieLegend($XPos,$YPos,$Data,$DataDescription,$R,$G,$B)
  933. {
  934. /* Validate the Data and DataDescription array */
  935. $this->validateDataDescription("drawPieLegend",$DataDescription,FALSE);
  936. $this->validateData("drawPieLegend",$Data);
  937. if ( !isset($DataDescription["Position"]) )
  938. return(-1);
  939. $C_TextColor =$this->AllocateColor($this->Picture,0,0,0);
  940. /* <-10->[8]<-4->Text<-10-> */
  941. $MaxWidth = 0; $MaxHeight = 8;
  942. foreach($Data as $Key => $Value)
  943. {
  944. $Value2 = $Value[$DataDescription["Position"]];
  945. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value2);
  946. $TextWidth = $Position[2]-$Position[0];
  947. $TextHeight = $Position[1]-$Position[7];
  948. if ( $TextWidth > $MaxWidth) { $MaxWidth = $TextWidth; }
  949. $MaxHeight = $MaxHeight + $TextHeight + 4;
  950. }
  951. $MaxHeight = $MaxHeight - 3;
  952. $MaxWidth = $MaxWidth + 32;
  953. $this->drawFilledRoundedRectangle($XPos+1,$YPos+1,$XPos+$MaxWidth+1,$YPos+$MaxHeight+1,5,$R-30,$G-30,$B-30);
  954. $this->drawFilledRoundedRectangle($XPos,$YPos,$XPos+$MaxWidth,$YPos+$MaxHeight,5,$R,$G,$B);
  955. $YOffset = 4 + $this->FontSize; $ID = 0;
  956. foreach($Data as $Key => $Value)
  957. {
  958. $Value2 = $Value[$DataDescription["Position"]];
  959. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value2);
  960. $TextHeight = $Position[1]-$Position[7];
  961. $this->drawFilledRectangle($XPos+10,$YPos+$YOffset-6,$XPos+14,$YPos+$YOffset-2,$this->Palette[$ID]["R"],$this->Palette[$ID]["G"],$this->Palette[$ID]["B"]);
  962. imagettftext($this->Picture,$this->FontSize,0,$XPos+22,$YPos+$YOffset,$C_TextColor,$this->FontName,$Value2);
  963. $YOffset = $YOffset + $TextHeight + 4;
  964. $ID++;
  965. }
  966. }
  967. /* Draw the graph title */
  968. function drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE)
  969. {
  970. $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B);
  971. if ( $XPos2 != -1 )
  972. {
  973. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  974. $TextWidth = $Position[2]-$Position[0];
  975. $XPos = floor(( $XPos2 - $XPos - $TextWidth ) / 2 ) + $XPos;
  976. }
  977. if ( $YPos2 != -1 )
  978. {
  979. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Value);
  980. $TextHeight = $Position[5]-$Position[3];
  981. $YPos = floor(( $YPos2 - $YPos - $TextHeight ) / 2 ) + $YPos;
  982. }
  983. if ( $Shadow )
  984. {
  985. $C_ShadowColor = $this->AllocateColor($this->Picture,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor);
  986. imagettftext($this->Picture,$this->FontSize,0,$XPos+$this->ShadowXDistance,$YPos+$this->ShadowYDistance,$C_ShadowColor,$this->FontName,$Value);
  987. }
  988. imagettftext($this->Picture,$this->FontSize,0,$XPos,$YPos,$C_TextColor,$this->FontName,$Value);
  989. }
  990. /* Draw a text box with text align & alpha properties */
  991. 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)
  992. {
  993. $Position = imageftbbox($this->FontSize,$Angle,$this->FontName,$Text);
  994. $TextWidth = $Position[2]-$Position[0];
  995. $TextHeight = $Position[5]-$Position[3];
  996. $AreaWidth = $X2 - $X1;
  997. $AreaHeight = $Y2 - $Y1;
  998. if ( $BgR != -1 && $BgG != -1 && $BgB != -1 )
  999. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$BgR,$BgG,$BgB,FALSE,$Alpha);
  1000. if ( $Align == ALIGN_TOP_LEFT ) { $X = $X1+1; $Y = $Y1+$this->FontSize+1; }
  1001. if ( $Align == ALIGN_TOP_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y1+$this->FontSize+1; }
  1002. if ( $Align == ALIGN_TOP_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y1+$this->FontSize+1; }
  1003. if ( $Align == ALIGN_LEFT ) { $X = $X1+1; $Y = $Y1+($AreaHeight/2)-($TextHeight/2); }
  1004. if ( $Align == ALIGN_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y1+($AreaHeight/2)-($TextHeight/2); }
  1005. if ( $Align == ALIGN_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y1+($AreaHeight/2)-($TextHeight/2); }
  1006. if ( $Align == ALIGN_BOTTOM_LEFT ) { $X = $X1+1; $Y = $Y2-1; }
  1007. if ( $Align == ALIGN_BOTTOM_CENTER ) { $X = $X1+($AreaWidth/2)-($TextWidth/2); $Y = $Y2-1; }
  1008. if ( $Align == ALIGN_BOTTOM_RIGHT ) { $X = $X2-$TextWidth-1; $Y = $Y2-1; }
  1009. $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
  1010. $C_ShadowColor =$this->AllocateColor($this->Picture,0,0,0);
  1011. if ( $Shadow )
  1012. imagettftext($this->Picture,$this->FontSize,$Angle,$X+1,$Y+1,$C_ShadowColor,$this->FontName,$Text);
  1013. imagettftext($this->Picture,$this->FontSize,$Angle,$X,$Y,$C_TextColor,$this->FontName,$Text);
  1014. }
  1015. /* Compute and draw the scale */
  1016. function drawTreshold($Value,$R,$G,$B,$ShowLabel=FALSE,$ShowOnRight=FALSE,$TickWidth=4,$FreeText=NULL)
  1017. {
  1018. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  1019. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  1020. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  1021. $C_TextColor =$this->AllocateColor($this->Picture,$R,$G,$B);
  1022. $Y = $this->GArea_Y2 - ($Value - $this->VMin) * $this->DivisionRatio;
  1023. if ( $Y <= $this->GArea_Y1 || $Y >= $this->GArea_Y2 )
  1024. return(-1);
  1025. if ( $TickWidth == 0 )
  1026. $this->drawLine($this->GArea_X1,$Y,$this->GArea_X2,$Y,$R,$G,$B);
  1027. else
  1028. $this->drawDottedLine($this->GArea_X1,$Y,$this->GArea_X2,$Y,$TickWidth,$R,$G,$B);
  1029. if ( $ShowLabel )
  1030. {
  1031. if ( $FreeText == NULL )
  1032. { $Label = $Value; } else { $Label = $FreeText; }
  1033. if ( $ShowOnRight )
  1034. imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X2+2,$Y+($this->FontSize/2),$C_TextColor,$this->FontName,$Label);
  1035. else
  1036. imagettftext($this->Picture,$this->FontSize,0,$this->GArea_X1+2,$Y-($this->FontSize/2),$C_TextColor,$this->FontName,$Label);
  1037. }
  1038. }
  1039. /* This function put a label on a specific point */
  1040. function setLabel($Data,$DataDescription,$SerieName,$ValueName,$Caption,$R=210,$G=210,$B=210)
  1041. {
  1042. /* Validate the Data and DataDescription array */
  1043. $this->validateDataDescription("setLabel",$DataDescription);
  1044. $this->validateData("setLabel",$Data);
  1045. $ShadowFactor = 100;
  1046. $C_Label =$this->AllocateColor($this->Picture,$R,$G,$B);
  1047. $C_Shadow =$this->AllocateColor($this->Picture,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
  1048. $C_TextColor =$this->AllocateColor($this->Picture,0,0,0);
  1049. $Cp = 0; $Found = FALSE;
  1050. foreach ( $Data as $Key => $Value )
  1051. {
  1052. if ( $Data[$Key][$DataDescription["Position"]] == $ValueName )
  1053. { $NumericalValue = $Data[$Key][$SerieName]; $Found = TRUE; }
  1054. if ( !$Found )
  1055. $Cp++;
  1056. }
  1057. $XPos = $this->GArea_X1 + $this->GAreaXOffset + ( $this->DivisionWidth * $Cp ) + 2;
  1058. $YPos = $this->GArea_Y2 - ($NumericalValue - $this->VMin) * $this->DivisionRatio;
  1059. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  1060. $TextHeight = $Position[3] - $Position[5];
  1061. $TextWidth = $Position[2]-$Position[0] + 2;
  1062. $TextOffset = floor($TextHeight/2);
  1063. // Shadow
  1064. $Poly = array($XPos+1,$YPos+1,$XPos + 9,$YPos - $TextOffset,$XPos + 8,$YPos + $TextOffset + 2);
  1065. imagefilledpolygon($this->Picture,$Poly,3,$C_Shadow);
  1066. $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos - $TextOffset - .2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
  1067. $this->drawLine($XPos,$YPos+1,$XPos + 9,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
  1068. $this->drawFilledRectangle($XPos + 9,$YPos - $TextOffset-.2,$XPos + 13 + $TextWidth,$YPos + $TextOffset + 2.2,$R-$ShadowFactor,$G-$ShadowFactor,$B-$ShadowFactor);
  1069. // Label background
  1070. $Poly = array($XPos,$YPos,$XPos + 8,$YPos - $TextOffset - 1,$XPos + 8,$YPos + $TextOffset + 1);
  1071. imagefilledpolygon($this->Picture,$Poly,3,$C_Label);
  1072. $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos - $TextOffset - 1.2,$R,$G,$B);
  1073. $this->drawLine($XPos-1,$YPos,$XPos + 8,$YPos + $TextOffset + 1.2,$R,$G,$B);
  1074. $this->drawFilledRectangle($XPos + 8,$YPos - $TextOffset - 1.2,$XPos + 12 + $TextWidth,$YPos + $TextOffset + 1.2,$R,$G,$B);
  1075. imagettftext($this->Picture,$this->FontSize,0,$XPos + 10,$YPos + $TextOffset,$C_TextColor,$this->FontName,$Caption);
  1076. }
  1077. /* This function draw a plot graph */
  1078. function drawPlotGraph($Data,$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=FALSE)
  1079. {
  1080. /* Validate the Data and DataDescription array */
  1081. $this->validateDataDescription("drawPlotGraph",$DataDescription);
  1082. $this->validateData("drawPlotGraph",$Data);
  1083. $GraphID = 0;
  1084. $Ro = $R2; $Go = $G2; $Bo = $B2;
  1085. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1086. {
  1087. $ID = 0;
  1088. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1089. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1090. $R = $this->Palette[$ColorID]["R"];
  1091. $G = $this->Palette[$ColorID]["G"];
  1092. $B = $this->Palette[$ColorID]["B"];
  1093. $R2 = $Ro; $G2 = $Go; $B2 = $Bo;
  1094. if ( isset($DataDescription["Symbol"][$ColName]) )
  1095. {
  1096. $Is_Alpha = ((ord ( file_get_contents ($DataDescription["Symbol"][$ColName], false, null, 25, 1)) & 6) & 4) == 4;
  1097. $Infos = getimagesize($DataDescription["Symbol"][$ColName]);
  1098. $ImageWidth = $Infos[0];
  1099. $ImageHeight = $Infos[1];
  1100. $Symbol = imagecreatefromgif($DataDescription["Symbol"][$ColName]);
  1101. }
  1102. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1103. $Hsize = round($BigRadius/2);
  1104. $R3 = -1; $G3 = -1; $B3 = -1;
  1105. foreach ( $Data as $Key => $Values )
  1106. {
  1107. $Value = $Data[$Key][$ColName];
  1108. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1109. /* Save point into the image map if option activated */
  1110. if ( $this->BuildMap )
  1111. $this->addToImageMap($XPos-$Hsize,$YPos-$Hsize,$XPos+1+$Hsize,$YPos+$Hsize+1,$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Plot");
  1112. if ( is_numeric($Value) )
  1113. {
  1114. if ( !isset($DataDescription["Symbol"][$ColName]) )
  1115. {
  1116. if ( $Shadow )
  1117. {
  1118. if ( $R3 !=-1 && $G3 !=-1 && $B3 !=-1 )
  1119. $this->drawFilledCircle($XPos+2,$YPos+2,$BigRadius,$R3,$G3,$B3);
  1120. else
  1121. {
  1122. $R3 = $this->Palette[$ColorID]["R"]-20; if ( $R3 < 0 ) { $R3 = 0; }
  1123. $G3 = $this->Palette[$ColorID]["G"]-20; if ( $G3 < 0 ) { $G3 = 0; }
  1124. $B3 = $this->Palette[$ColorID]["B"]-20; if ( $B3 < 0 ) { $B3 = 0; }
  1125. $this->drawFilledCircle($XPos+2,$YPos+2,$BigRadius,$R3,$G3,$B3);
  1126. }
  1127. }
  1128. $this->drawFilledCircle($XPos+1,$YPos+1,$BigRadius,$R,$G,$B);
  1129. if ( $SmallRadius != 0 )
  1130. {
  1131. if ( $R2 !=-1 && $G2 !=-1 && $B2 !=-1 )
  1132. $this->drawFilledCircle($XPos+1,$YPos+1,$SmallRadius,$R2,$G2,$B2);
  1133. else
  1134. {
  1135. $R2 = $this->Palette[$ColorID]["R"]-15; if ( $R2 < 0 ) { $R2 = 0; }
  1136. $G2 = $this->Palette[$ColorID]["G"]-15; if ( $G2 < 0 ) { $G2 = 0; }
  1137. $B2 = $this->Palette[$ColorID]["B"]-15; if ( $B2 < 0 ) { $B2 = 0; }
  1138. $this->drawFilledCircle($XPos+1,$YPos+1,$SmallRadius,$R2,$G2,$B2);
  1139. }
  1140. }
  1141. }
  1142. else
  1143. {
  1144. imagecopymerge($this->Picture,$Symbol,$XPos+1-$ImageWidth/2,$YPos+1-$ImageHeight/2,0,0,$ImageWidth,$ImageHeight,100);
  1145. }
  1146. }
  1147. $XPos = $XPos + $this->DivisionWidth;
  1148. }
  1149. $GraphID++;
  1150. }
  1151. }
  1152. /* This function draw a plot graph in an X/Y space */
  1153. function drawXYPlotGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=TRUE)
  1154. {
  1155. $R = $this->Palette[$PaletteID]["R"];
  1156. $G = $this->Palette[$PaletteID]["G"];
  1157. $B = $this->Palette[$PaletteID]["B"];
  1158. $R3 = -1; $G3 = -1; $B3 = -1;
  1159. $YLast = -1; $XLast = -1;
  1160. foreach ( $Data as $Key => $Values )
  1161. {
  1162. if ( isset($Data[$Key][$YSerieName]) && isset($Data[$Key][$XSerieName]) )
  1163. {
  1164. $X = $Data[$Key][$XSerieName];
  1165. $Y = $Data[$Key][$YSerieName];
  1166. $Y = $this->GArea_Y2 - (($Y-$this->VMin) * $this->DivisionRatio);
  1167. $X = $this->GArea_X1 + (($X-$this->VXMin) * $this->XDivisionRatio);
  1168. if ( $Shadow )
  1169. {
  1170. if ( $R3 !=-1 && $G3 !=-1 && $B3 !=-1 )
  1171. $this->drawFilledCircle($X+2,$Y+2,$BigRadius,$R3,$G3,$B3);
  1172. else
  1173. {
  1174. $R3 = $this->Palette[$PaletteID]["R"]-20; if ( $R < 0 ) { $R = 0; }
  1175. $G3 = $this->Palette[$PaletteID]["G"]-20; if ( $G < 0 ) { $G = 0; }
  1176. $B3 = $this->Palette[$PaletteID]["B"]-20; if ( $B < 0 ) { $B = 0; }
  1177. $this->drawFilledCircle($X+2,$Y+2,$BigRadius,$R3,$G3,$B3);
  1178. }
  1179. }
  1180. $this->drawFilledCircle($X+1,$Y+1,$BigRadius,$R,$G,$B);
  1181. if ( $R2 !=-1 && $G2 !=-1 && $B2 !=-1 )
  1182. $this->drawFilledCircle($X+1,$Y+1,$SmallRadius,$R2,$G2,$B2);
  1183. else
  1184. {
  1185. $R2 = $this->Palette[$PaletteID]["R"]+20; if ( $R > 255 ) { $R = 255; }
  1186. $G2 = $this->Palette[$PaletteID]["G"]+20; if ( $G > 255 ) { $G = 255; }
  1187. $B2 = $this->Palette[$PaletteID]["B"]+20; if ( $B > 255 ) { $B = 255; }
  1188. $this->drawFilledCircle($X+1,$Y+1,$SmallRadius,$R2,$G2,$B2);
  1189. }
  1190. }
  1191. }
  1192. }
  1193. /* This function draw an area between two series */
  1194. function drawArea($Data,$Serie1,$Serie2,$R,$G,$B,$Alpha = 50)
  1195. {
  1196. /* Validate the Data and DataDescription array */
  1197. $this->validateData("drawArea",$Data);
  1198. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1199. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1200. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  1201. $C_White =$this->AllocateColor($this->Layers[0],255,255,255);
  1202. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  1203. imagecolortransparent($this->Layers[0],$C_White);
  1204. $C_Graph =$this->AllocateColor($this->Layers[0],$R,$G,$B);
  1205. $XPos = $this->GAreaXOffset;
  1206. $LastXPos = -1;
  1207. foreach ( $Data as $Key => $Values )
  1208. {
  1209. $Value1 = $Data[$Key][$Serie1];
  1210. $Value2 = $Data[$Key][$Serie2];
  1211. $YPos1 = $LayerHeight - (($Value1-$this->VMin) * $this->DivisionRatio);
  1212. $YPos2 = $LayerHeight - (($Value2-$this->VMin) * $this->DivisionRatio);
  1213. if ( $LastXPos != -1 )
  1214. {
  1215. $Points = "";
  1216. $Points[] = $LastXPos; $Points[] = $LastYPos1;
  1217. $Points[] = $LastXPos; $Points[] = $LastYPos2;
  1218. $Points[] = $XPos; $Points[] = $YPos2;
  1219. $Points[] = $XPos; $Points[] = $YPos1;
  1220. imagefilledpolygon($this->Layers[0],$Points,4,$C_Graph);
  1221. }
  1222. $LastYPos1 = $YPos1;
  1223. $LastYPos2 = $YPos2;
  1224. $LastXPos = $XPos;
  1225. $XPos = $XPos + $this->DivisionWidth;
  1226. }
  1227. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  1228. imagedestroy($this->Layers[0]);
  1229. }
  1230. /* This function write the values of the specified series */
  1231. function writeValues($Data,$DataDescription,$Series)
  1232. {
  1233. /* Validate the Data and DataDescription array */
  1234. $this->validateDataDescription("writeValues",$DataDescription);
  1235. $this->validateData("writeValues",$Data);
  1236. if ( !is_array($Series) ) { $Series = array($Series); }
  1237. foreach($Series as $Key => $Serie)
  1238. {
  1239. $ID = 0;
  1240. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1241. { if ( $keyI == $Serie ) { $ColorID = $ID; }; $ID++; }
  1242. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1243. $XLast = -1;
  1244. foreach ( $Data as $Key => $Values )
  1245. {
  1246. if ( isset($Data[$Key][$Serie]) && is_numeric($Data[$Key][$Serie]))
  1247. {
  1248. $Value = $Data[$Key][$Serie];
  1249. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1250. $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$Value);
  1251. $Width = $Positions[2] - $Positions[6]; $XOffset = $XPos - ($Width/2);
  1252. $Height = $Positions[3] - $Positions[7]; $YOffset = $YPos - 4;
  1253. $C_TextColor =$this->AllocateColor($this->Picture,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1254. imagettftext($this->Picture,$this->FontSize,0,$XOffset,$YOffset,$C_TextColor,$this->FontName,$Value);
  1255. }
  1256. $XPos = $XPos + $this->DivisionWidth;
  1257. }
  1258. }
  1259. }
  1260. /* This function draw a line graph */
  1261. function drawLineGraph($Data,$DataDescription,$SerieName="")
  1262. {
  1263. /* Validate the Data and DataDescription array */
  1264. $this->validateDataDescription("drawLineGraph",$DataDescription);
  1265. $this->validateData("drawLineGraph",$Data);
  1266. $GraphID = 0;
  1267. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1268. {
  1269. $ID = 0;
  1270. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1271. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1272. if ( $SerieName == "" || $SerieName == $ColName )
  1273. {
  1274. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1275. $XLast = -1;
  1276. foreach ( $Data as $Key => $Values )
  1277. {
  1278. if ( isset($Data[$Key][$ColName]))
  1279. {
  1280. $Value = $Data[$Key][$ColName];
  1281. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1282. /* Save point into the image map if option activated */
  1283. if ( $this->BuildMap )
  1284. $this->addToImageMap($XPos-3,$YPos-3,$XPos+3,$YPos+3,$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Line");
  1285. if (!is_numeric($Value)) { $XLast = -1; }
  1286. if ( $XLast != -1 )
  1287. $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE);
  1288. $XLast = $XPos;
  1289. $YLast = $YPos;
  1290. if (!is_numeric($Value)) { $XLast = -1; }
  1291. }
  1292. $XPos = $XPos + $this->DivisionWidth;
  1293. }
  1294. $GraphID++;
  1295. }
  1296. }
  1297. }
  1298. /* This function draw a line graph */
  1299. function drawXYGraph($Data,$DataDescription,$YSerieName,$XSerieName,$PaletteID=0)
  1300. {
  1301. $YLast = -1; $XLast = -1;
  1302. foreach ( $Data as $Key => $Values )
  1303. {
  1304. if ( isset($Data[$Key][$YSerieName]) && isset($Data[$Key][$XSerieName]) )
  1305. {
  1306. $X = $Data[$Key][$XSerieName];
  1307. $Y = $Data[$Key][$YSerieName];
  1308. $Y = $this->GArea_Y2 - (($Y-$this->VMin) * $this->DivisionRatio);
  1309. $X = $this->GArea_X1 + (($X-$this->VXMin) * $this->XDivisionRatio);
  1310. if ($XLast != -1 && $YLast != -1)
  1311. {
  1312. $this->drawLine($XLast,$YLast,$X,$Y,$this->Palette[$PaletteID]["R"],$this->Palette[$PaletteID]["G"],$this->Palette[$PaletteID]["B"],TRUE);
  1313. }
  1314. $XLast = $X;
  1315. $YLast = $Y;
  1316. }
  1317. }
  1318. }
  1319. /* This function draw a cubic curve */
  1320. function drawCubicCurve($Data,$DataDescription,$Accuracy=.1,$SerieName="")
  1321. {
  1322. /* Validate the Data and DataDescription array */
  1323. $this->validateDataDescription("drawCubicCurve",$DataDescription);
  1324. $this->validateData("drawCubicCurve",$Data);
  1325. $GraphID = 0;
  1326. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1327. {
  1328. if ( $SerieName == "" || $SerieName == $ColName )
  1329. {
  1330. $XIn = ""; $Yin = ""; $Yt = ""; $U = "";
  1331. $XIn[0] = 0; $YIn[0] = 0;
  1332. $ID = 0;
  1333. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1334. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1335. $Index = 1;
  1336. $XLast = -1; $Missing = "";
  1337. foreach ( $Data as $Key => $Values )
  1338. {
  1339. if ( isset($Data[$Key][$ColName]) )
  1340. {
  1341. $Value = $Data[$Key][$ColName];
  1342. $XIn[$Index] = $Index;
  1343. $YIn[$Index] = $Value;
  1344. if ( !is_numeric($Value) ) { $Missing[$Index] = TRUE; }
  1345. $Index++;
  1346. }
  1347. }
  1348. $Index--;
  1349. $Yt[0] = 0;
  1350. $Yt[1] = 0;
  1351. $U[1] = 0;
  1352. for($i=2;$i<=$Index-1;$i++)
  1353. {
  1354. $Sig = ($XIn[$i] - $XIn[$i-1]) / ($XIn[$i+1] - $XIn[$i-1]);
  1355. $p = $Sig * $Yt[$i-1] + 2;
  1356. $Yt[$i] = ($Sig - 1) / $p;
  1357. $U[$i] = ($YIn[$i+1] - $YIn[$i]) / ($XIn[$i+1] - $XIn[$i]) - ($YIn[$i] - $YIn[$i-1]) / ($XIn[$i] - $XIn[$i-1]);
  1358. $U[$i] = (6 * $U[$i] / ($XIn[$i+1] - $XIn[$i-1]) - $Sig * $U[$i-1]) / $p;
  1359. }
  1360. $qn = 0;
  1361. $un = 0;
  1362. $Yt[$Index] = ($un - $qn * $U[$Index-1]) / ($qn * $Yt[$Index-1] + 1);
  1363. for($k=$Index-1;$k>=1;$k--)
  1364. $Yt[$k] = $Yt[$k] * $Yt[$k+1] + $U[$k];
  1365. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1366. for($X=1;$X<=$Index;$X=$X+$Accuracy)
  1367. {
  1368. $klo = 1;
  1369. $khi = $Index;
  1370. $k = $khi - $klo;
  1371. while($k > 1)
  1372. {
  1373. $k = $khi - $klo;
  1374. If ( $XIn[$k] >= $X )
  1375. $khi = $k;
  1376. else
  1377. $klo = $k;
  1378. }
  1379. $klo = $khi - 1;
  1380. $h = $XIn[$khi] - $XIn[$klo];
  1381. $a = ($XIn[$khi] - $X) / $h;
  1382. $b = ($X - $XIn[$klo]) / $h;
  1383. $Value = $a * $YIn[$klo] + $b * $YIn[$khi] + (($a*$a*$a - $a) * $Yt[$klo] + ($b*$b*$b - $b) * $Yt[$khi]) * ($h*$h) / 6;
  1384. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1385. if ( $XLast != -1 && !isset($Missing[floor($X)]) && !isset($Missing[floor($X+1)]) )
  1386. $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE);
  1387. $XLast = $XPos;
  1388. $YLast = $YPos;
  1389. $XPos = $XPos + $this->DivisionWidth * $Accuracy;
  1390. }
  1391. // Add potentialy missing values
  1392. $XPos = $XPos - $this->DivisionWidth * $Accuracy;
  1393. if ( $XPos < ($this->GArea_X2 - $this->GAreaXOffset) )
  1394. {
  1395. $YPos = $this->GArea_Y2 - (($YIn[$Index]-$this->VMin) * $this->DivisionRatio);
  1396. $this->drawLine($XLast,$YLast,$this->GArea_X2-$this->GAreaXOffset,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE);
  1397. }
  1398. $GraphID++;
  1399. }
  1400. }
  1401. }
  1402. /* This function draw a filled cubic curve */
  1403. function drawFilledCubicCurve($Data,$DataDescription,$Accuracy=.1,$Alpha=100,$AroundZero=FALSE)
  1404. {
  1405. /* Validate the Data and DataDescription array */
  1406. $this->validateDataDescription("drawFilledCubicCurve",$DataDescription);
  1407. $this->validateData("drawFilledCubicCurve",$Data);
  1408. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1409. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1410. $YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio);
  1411. if ( $YZero > $LayerHeight ) { $YZero = $LayerHeight; }
  1412. $GraphID = 0;
  1413. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1414. {
  1415. $XIn = ""; $Yin = ""; $Yt = ""; $U = "";
  1416. $XIn[0] = 0; $YIn[0] = 0;
  1417. $ID = 0;
  1418. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1419. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1420. $Index = 1;
  1421. $XLast = -1; $Missing = "";
  1422. foreach ( $Data as $Key => $Values )
  1423. {
  1424. $Value = $Data[$Key][$ColName];
  1425. $XIn[$Index] = $Index;
  1426. $YIn[$Index] = $Value;
  1427. if ( !is_numeric($Value) ) { $Missing[$Index] = TRUE; }
  1428. $Index++;
  1429. }
  1430. $Index--;
  1431. $Yt[0] = 0;
  1432. $Yt[1] = 0;
  1433. $U[1] = 0;
  1434. for($i=2;$i<=$Index-1;$i++)
  1435. {
  1436. $Sig = ($XIn[$i] - $XIn[$i-1]) / ($XIn[$i+1] - $XIn[$i-1]);
  1437. $p = $Sig * $Yt[$i-1] + 2;
  1438. $Yt[$i] = ($Sig - 1) / $p;
  1439. $U[$i] = ($YIn[$i+1] - $YIn[$i]) / ($XIn[$i+1] - $XIn[$i]) - ($YIn[$i] - $YIn[$i-1]) / ($XIn[$i] - $XIn[$i-1]);
  1440. $U[$i] = (6 * $U[$i] / ($XIn[$i+1] - $XIn[$i-1]) - $Sig * $U[$i-1]) / $p;
  1441. }
  1442. $qn = 0;
  1443. $un = 0;
  1444. $Yt[$Index] = ($un - $qn * $U[$Index-1]) / ($qn * $Yt[$Index-1] + 1);
  1445. for($k=$Index-1;$k>=1;$k--)
  1446. $Yt[$k] = $Yt[$k] * $Yt[$k+1] + $U[$k];
  1447. $Points = "";
  1448. $Points[] = $this->GAreaXOffset;
  1449. $Points[] = $LayerHeight;
  1450. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  1451. $C_White =$this->AllocateColor($this->Layers[0],255,255,255);
  1452. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  1453. imagecolortransparent($this->Layers[0],$C_White);
  1454. $YLast = NULL;
  1455. $XPos = $this->GAreaXOffset; $PointsCount = 2;
  1456. for($X=1;$X<=$Index;$X=$X+$Accuracy)
  1457. {
  1458. $klo = 1;
  1459. $khi = $Index;
  1460. $k = $khi - $klo;
  1461. while($k > 1)
  1462. {
  1463. $k = $khi - $klo;
  1464. If ( $XIn[$k] >= $X )
  1465. $khi = $k;
  1466. else
  1467. $klo = $k;
  1468. }
  1469. $klo = $khi - 1;
  1470. $h = $XIn[$khi] - $XIn[$klo];
  1471. $a = ($XIn[$khi] - $X) / $h;
  1472. $b = ($X - $XIn[$klo]) / $h;
  1473. $Value = $a * $YIn[$klo] + $b * $YIn[$khi] + (($a*$a*$a - $a) * $Yt[$klo] + ($b*$b*$b - $b) * $Yt[$khi]) * ($h*$h) / 6;
  1474. $YPos = $LayerHeight - (($Value-$this->VMin) * $this->DivisionRatio);
  1475. if ( $YLast != NULL && $AroundZero && !isset($Missing[floor($X)]) && !isset($Missing[floor($X+1)]))
  1476. {
  1477. $aPoints = "";
  1478. $aPoints[] = $XLast;
  1479. $aPoints[] = $YLast;
  1480. $aPoints[] = $XPos;
  1481. $aPoints[] = $YPos;
  1482. $aPoints[] = $XPos;
  1483. $aPoints[] = $YZero;
  1484. $aPoints[] = $XLast;
  1485. $aPoints[] = $YZero;
  1486. $C_Graph =$this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1487. imagefilledpolygon($this->Layers[0],$aPoints,4,$C_Graph);
  1488. }
  1489. if ( !isset($Missing[floor($X)]) || $YLast == NULL )
  1490. {
  1491. $PointsCount++;
  1492. $Points[] = $XPos;
  1493. $Points[] = $YPos;
  1494. }
  1495. else
  1496. {
  1497. $PointsCount++; $Points[] = $XLast; $Points[] = $LayerHeight;
  1498. }
  1499. $YLast = $YPos; $XLast = $XPos;
  1500. $XPos = $XPos + $this->DivisionWidth * $Accuracy;
  1501. }
  1502. // Add potentialy missing values
  1503. $XPos = $XPos - $this->DivisionWidth * $Accuracy;
  1504. if ( $XPos < ($LayerWidth-$this->GAreaXOffset) )
  1505. {
  1506. $YPos = $LayerHeight - (($YIn[$Index]-$this->VMin) * $this->DivisionRatio);
  1507. if ( $YLast != NULL && $AroundZero )
  1508. {
  1509. $aPoints = "";
  1510. $aPoints[] = $XLast;
  1511. $aPoints[] = $YLast;
  1512. $aPoints[] = $LayerWidth-$this->GAreaXOffset;
  1513. $aPoints[] = $YPos;
  1514. $aPoints[] = $LayerWidth-$this->GAreaXOffset;
  1515. $aPoints[] = $YZero;
  1516. $aPoints[] = $XLast;
  1517. $aPoints[] = $YZero;
  1518. $C_Graph =$this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1519. imagefilledpolygon($this->Layers[0],$aPoints,4,$C_Graph);
  1520. }
  1521. if ( $YIn[$klo] != "" && $YIn[$khi] != "" || $YLast == NULL )
  1522. {
  1523. $PointsCount++;
  1524. $Points[] = $LayerWidth-$this->GAreaXOffset;
  1525. $Points[] = $YPos;
  1526. }
  1527. }
  1528. $Points[] = $LayerWidth-$this->GAreaXOffset;
  1529. $Points[] = $LayerHeight;
  1530. if ( !$AroundZero )
  1531. {
  1532. $C_Graph =$this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1533. imagefilledpolygon($this->Layers[0],$Points,$PointsCount,$C_Graph);
  1534. }
  1535. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  1536. imagedestroy($this->Layers[0]);
  1537. $this->drawCubicCurve($Data,$DataDescription,$Accuracy,$ColName);
  1538. $GraphID++;
  1539. }
  1540. }
  1541. /* This function draw a filled line graph */
  1542. function drawFilledLineGraph($Data,$DataDescription,$Alpha=100,$AroundZero=FALSE)
  1543. {
  1544. $Empty = -2147483647;
  1545. /* Validate the Data and DataDescription array */
  1546. $this->validateDataDescription("drawFilledLineGraph",$DataDescription);
  1547. $this->validateData("drawFilledLineGraph",$Data);
  1548. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1549. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1550. $GraphID = 0;
  1551. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1552. {
  1553. $ID = 0;
  1554. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1555. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1556. $aPoints = "";
  1557. $aPoints[] = $this->GAreaXOffset;
  1558. $aPoints[] = $LayerHeight;
  1559. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  1560. $C_White = $this->AllocateColor($this->Layers[0],255,255,255);
  1561. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  1562. imagecolortransparent($this->Layers[0],$C_White);
  1563. $XPos = $this->GAreaXOffset;
  1564. $XLast = -1; $PointsCount = 2;
  1565. $YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio);
  1566. if ( $YZero > $LayerHeight ) { $YZero = $LayerHeight; }
  1567. $YLast = $Empty;
  1568. foreach ( $Data as $Key => $Values )
  1569. {
  1570. $Value = $Data[$Key][$ColName];
  1571. $YPos = $LayerHeight - (($Value-$this->VMin) * $this->DivisionRatio);
  1572. /* Save point into the image map if option activated */
  1573. if ( $this->BuildMap )
  1574. $this->addToImageMap($XPos-3,$YPos-3,$XPos+3,$YPos+3,$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"FLine");
  1575. if ( !is_numeric($Value) )
  1576. {
  1577. $PointsCount++;
  1578. $aPoints[] = $XLast;
  1579. $aPoints[] = $LayerHeight;
  1580. $YLast = $Empty;
  1581. }
  1582. else
  1583. {
  1584. $PointsCount++;
  1585. if ( $YLast <> $Empty )
  1586. { $aPoints[] = $XPos; $aPoints[] = $YPos; }
  1587. else
  1588. { $PointsCount++; $aPoints[] = $XPos; $aPoints[] = $LayerHeight; $aPoints[] = $XPos; $aPoints[] = $YPos; }
  1589. if ($YLast <> $Empty && $AroundZero)
  1590. {
  1591. $Points = "";
  1592. $Points[] = $XLast; $Points[] = $YLast;
  1593. $Points[] = $XPos;
  1594. $Points[] = $YPos;
  1595. $Points[] = $XPos;
  1596. $Points[] = $YZero;
  1597. $Points[] = $XLast;
  1598. $Points[] = $YZero;
  1599. $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1600. imagefilledpolygon($this->Layers[0],$Points,4,$C_Graph);
  1601. }
  1602. $YLast = $YPos;
  1603. }
  1604. $XLast = $XPos;
  1605. $XPos = $XPos + $this->DivisionWidth;
  1606. }
  1607. $aPoints[] = $LayerWidth - $this->GAreaXOffset;
  1608. $aPoints[] = $LayerHeight;
  1609. if ( $AroundZero == FALSE )
  1610. {
  1611. $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  1612. imagefilledpolygon($this->Layers[0],$aPoints,$PointsCount,$C_Graph);
  1613. }
  1614. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  1615. imagedestroy($this->Layers[0]);
  1616. $GraphID++;
  1617. $this->drawLineGraph($Data,$DataDescription,$ColName);
  1618. }
  1619. }
  1620. /* This function draw a bar graph */
  1621. function drawOverlayBarGraph($Data,$DataDescription,$Alpha=50)
  1622. {
  1623. /* Validate the Data and DataDescription array */
  1624. $this->validateDataDescription("drawOverlayBarGraph",$DataDescription);
  1625. $this->validateData("drawOverlayBarGraph",$Data);
  1626. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  1627. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  1628. $GraphID = 0;
  1629. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1630. {
  1631. $ID = 0;
  1632. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1633. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1634. $this->Layers[$GraphID] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  1635. $C_White = $this->AllocateColor($this->Layers[$GraphID],255,255,255);
  1636. $C_Graph = $this->AllocateColor($this->Layers[$GraphID],$this->Palette[$GraphID]["R"],$this->Palette[$GraphID]["G"],$this->Palette[$GraphID]["B"]);
  1637. imagefilledrectangle($this->Layers[$GraphID],0,0,$LayerWidth,$LayerHeight,$C_White);
  1638. imagecolortransparent($this->Layers[$GraphID],$C_White);
  1639. $XWidth = $this->DivisionWidth / 4;
  1640. $XPos = $this->GAreaXOffset;
  1641. $YZero = $LayerHeight - ((0-$this->VMin) * $this->DivisionRatio);
  1642. $XLast = -1; $PointsCount = 2;
  1643. foreach ( $Data as $Key => $Values )
  1644. {
  1645. if ( isset($Data[$Key][$ColName]) )
  1646. {
  1647. $Value = $Data[$Key][$ColName];
  1648. if ( is_numeric($Value) )
  1649. {
  1650. $YPos = $LayerHeight - (($Value-$this->VMin) * $this->DivisionRatio);
  1651. imagefilledrectangle($this->Layers[$GraphID],$XPos-$XWidth,$YPos,$XPos+$XWidth,$YZero,$C_Graph);
  1652. $X1 = floor($XPos - $XWidth + $this->GArea_X1); $Y1 = floor($YPos+$this->GArea_Y1) + .2;
  1653. $X2 = floor($XPos + $XWidth + $this->GArea_X1); $Y2 = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio);
  1654. if ( $X1 <= $this->GArea_X1 ) { $X1 = $this->GArea_X1 + 1; }
  1655. if ( $X2 >= $this->GArea_X2 ) { $X2 = $this->GArea_X2 - 1; }
  1656. /* Save point into the image map if option activated */
  1657. if ( $this->BuildMap )
  1658. $this->addToImageMap($X1,min($Y1,$Y2),$X2,max($Y1,$Y2),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"oBar");
  1659. $this->drawLine($X1,$Y1,$X2,$Y1,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE);
  1660. }
  1661. }
  1662. $XPos = $XPos + $this->DivisionWidth;
  1663. }
  1664. $GraphID++;
  1665. }
  1666. for($i=0;$i<=($GraphID-1);$i++)
  1667. {
  1668. imagecopymerge($this->Picture,$this->Layers[$i],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  1669. imagedestroy($this->Layers[$i]);
  1670. }
  1671. }
  1672. /* This function draw a bar graph */
  1673. function drawHorizontalBarGraph($Data,$DataDescription,$Shadow=FALSE,$Alpha=100)
  1674. {
  1675. /* Validate the Data and DataDescription array */
  1676. $this->validateDataDescription("drawHorizontalBarGraph",$DataDescription);
  1677. $this->validateData("drawHorizontalBarGraph",$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. $X1 = $YZero;
  1707. $Y1 = $XPos+1;
  1708. $X2 = $YPos;
  1709. $Y2 = $XPos+$SeriesWidth-1;
  1710. $this->drawRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,25,25,25,TRUE,$Alpha);
  1711. $this->drawFilledRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1712. //$this->drawRectangle($X1,$Y1,$X2,$Y2,$YPos,25,25,25,TRUE,$Alpha);
  1713. //$this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1714. }
  1715. }
  1716. $XPos = $XPos + $this->DivisionWidth;
  1717. }
  1718. $SerieID++;
  1719. }
  1720. }
  1721. /* This function draw a bar graph */
  1722. function drawBarGraph($Data,$DataDescription,$Shadow=FALSE,$Alpha=100)
  1723. {
  1724. /* Validate the Data and DataDescription array */
  1725. $this->validateDataDescription("drawBarGraph",$DataDescription);
  1726. $this->validateData("drawBarGraph",$Data);
  1727. $GraphID = 0;
  1728. $Series = count($DataDescription["Values"]);
  1729. $SeriesWidth = $this->DivisionWidth / ($Series+1);
  1730. $SerieXOffset = $this->DivisionWidth / 2 - $SeriesWidth / 2;
  1731. $YZero = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio);
  1732. if ( $YZero > $this->GArea_Y2 ) { $YZero = $this->GArea_Y2; }
  1733. $SerieID = 0;
  1734. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1735. {
  1736. $ID = 0;
  1737. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1738. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1739. $XPos = $this->GArea_X1 + $this->GAreaXOffset - $SerieXOffset + $SeriesWidth * $SerieID;
  1740. $XLast = -1;
  1741. foreach ( $Data as $Key => $Values )
  1742. {
  1743. if ( isset($Data[$Key][$ColName]))
  1744. {
  1745. if ( is_numeric($Data[$Key][$ColName]) )
  1746. {
  1747. $Value = $Data[$Key][$ColName];
  1748. $ValueWidth = strlen("$Value") * 6;
  1749. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1750. /* Save point into the image map if option activated */
  1751. if ( $this->BuildMap )
  1752. {
  1753. $this->addToImageMap($XPos+1,min($YZero,$YPos),$XPos+$SeriesWidth-1,max($YZero,$YPos),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Bar");
  1754. }
  1755. if ( $Shadow && $Alpha == 100 )
  1756. $this->drawRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,25,25,25,TRUE,$Alpha);
  1757. $this->drawFilledRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1758. imagettftext($this->Picture, $this->FontSize, 0, $XPos + ($SeriesWidth / 2) - ($ValueWidth / 2), $YPos - 2, $ColorID, $this->FontName, $Value);
  1759. }
  1760. }
  1761. $XPos = $XPos + $this->DivisionWidth;
  1762. }
  1763. $SerieID++;
  1764. }
  1765. }
  1766. /* This function draw a stacked bar graph */
  1767. function drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE)
  1768. {
  1769. /* Validate the Data and DataDescription array */
  1770. $this->validateDataDescription("drawBarGraph",$DataDescription);
  1771. $this->validateData("drawBarGraph",$Data);
  1772. $GraphID = 0;
  1773. $Series = count($DataDescription["Values"]);
  1774. if ( $Contiguous )
  1775. $SeriesWidth = $this->DivisionWidth;
  1776. else
  1777. $SeriesWidth = $this->DivisionWidth * .8;
  1778. $YZero = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio);
  1779. if ( $YZero > $this->GArea_Y2 ) { $YZero = $this->GArea_Y2; }
  1780. $SerieID = 0; $LastValue = "";
  1781. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1782. {
  1783. $ID = 0;
  1784. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1785. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1786. $XPos = $this->GArea_X1 + $this->GAreaXOffset - $SeriesWidth / 2;
  1787. $XLast = -1;
  1788. foreach ( $Data as $Key => $Values )
  1789. {
  1790. if ( isset($Data[$Key][$ColName]))
  1791. {
  1792. if ( is_numeric($Data[$Key][$ColName]) )
  1793. {
  1794. $Value = $Data[$Key][$ColName];
  1795. if ( isset($LastValue[$Key]) )
  1796. {
  1797. $YPos = $this->GArea_Y2 - ((($Value+$LastValue[$Key])-$this->VMin) * $this->DivisionRatio);
  1798. $YBottom = $this->GArea_Y2 - (($LastValue[$Key]-$this->VMin) * $this->DivisionRatio);
  1799. $LastValue[$Key] += $Value;
  1800. }
  1801. else
  1802. {
  1803. $YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
  1804. $YBottom = $YZero;
  1805. $LastValue[$Key] = $Value;
  1806. }
  1807. /* Save point into the image map if option activated */
  1808. if ( $this->BuildMap )
  1809. $this->addToImageMap($XPos+1,min($YBottom,$YPos),$XPos+$SeriesWidth-1,max($YBottom,$YPos),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"sBar");
  1810. $this->drawFilledRectangle($XPos+1,$YBottom,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
  1811. }
  1812. }
  1813. $XPos = $XPos + $this->DivisionWidth;
  1814. }
  1815. $SerieID++;
  1816. }
  1817. }
  1818. /* This function draw a limits bar graphs */
  1819. function drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0)
  1820. {
  1821. /* Validate the Data and DataDescription array */
  1822. $this->validateDataDescription("drawLimitsGraph",$DataDescription);
  1823. $this->validateData("drawLimitsGraph",$Data);
  1824. $XWidth = $this->DivisionWidth / 4;
  1825. $XPos = $this->GArea_X1 + $this->GAreaXOffset;
  1826. foreach ( $Data as $Key => $Values )
  1827. {
  1828. $Min = $Data[$Key][$DataDescription["Values"][0]];
  1829. $Max = $Data[$Key][$DataDescription["Values"][0]];
  1830. $GraphID = 0; $MaxID = 0; $MinID = 0;
  1831. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1832. {
  1833. if ( isset($Data[$Key][$ColName]) )
  1834. {
  1835. if ( $Data[$Key][$ColName] > $Max && is_numeric($Data[$Key][$ColName]))
  1836. { $Max = $Data[$Key][$ColName]; $MaxID = $GraphID; }
  1837. }
  1838. if ( isset($Data[$Key][$ColName]) && is_numeric($Data[$Key][$ColName]))
  1839. {
  1840. if ( $Data[$Key][$ColName] < $Min )
  1841. { $Min = $Data[$Key][$ColName]; $MinID = $GraphID; }
  1842. $GraphID++;
  1843. }
  1844. }
  1845. $YPos = $this->GArea_Y2 - (($Max-$this->VMin) * $this->DivisionRatio);
  1846. $X1 = floor($XPos - $XWidth); $Y1 = floor($YPos) - .2;
  1847. $X2 = floor($XPos + $XWidth);
  1848. if ( $X1 <= $this->GArea_X1 ) { $X1 = $this->GArea_X1 + 1; }
  1849. if ( $X2 >= $this->GArea_X2 ) { $X2 = $this->GArea_X2 - 1; }
  1850. $YPos = $this->GArea_Y2 - (($Min-$this->VMin) * $this->DivisionRatio);
  1851. $Y2 = floor($YPos) + .2;
  1852. $this->drawLine(floor($XPos)-.2,$Y1+1,floor($XPos)-.2,$Y2-1,$R,$G,$B,TRUE);
  1853. $this->drawLine(floor($XPos)+.2,$Y1+1,floor($XPos)+.2,$Y2-1,$R,$G,$B,TRUE);
  1854. $this->drawLine($X1,$Y1,$X2,$Y1,$this->Palette[$MaxID]["R"],$this->Palette[$MaxID]["G"],$this->Palette[$MaxID]["B"],FALSE);
  1855. $this->drawLine($X1,$Y2,$X2,$Y2,$this->Palette[$MinID]["R"],$this->Palette[$MinID]["G"],$this->Palette[$MinID]["B"],FALSE);
  1856. $XPos = $XPos + $this->DivisionWidth;
  1857. }
  1858. }
  1859. /* This function draw radar axis centered on the graph area */
  1860. 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)
  1861. {
  1862. /* Validate the Data and DataDescription array */
  1863. $this->validateDataDescription("drawRadarAxis",$DataDescription);
  1864. $this->validateData("drawRadarAxis",$Data);
  1865. $C_TextColor = $this->AllocateColor($this->Picture,$A_R,$A_G,$A_B);
  1866. /* Draw radar axis */
  1867. $Points = count($Data);
  1868. $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset;
  1869. $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2 + $this->GArea_X1;
  1870. $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 + $this->GArea_Y1;
  1871. /* Search for the max value */
  1872. if ( $MaxValue == -1 )
  1873. {
  1874. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1875. {
  1876. foreach ( $Data as $Key => $Values )
  1877. {
  1878. if ( isset($Data[$Key][$ColName]))
  1879. if ( $Data[$Key][$ColName] > $MaxValue ) { $MaxValue = $Data[$Key][$ColName]; }
  1880. }
  1881. }
  1882. }
  1883. /* Draw the mosaic */
  1884. if ( $Mosaic )
  1885. {
  1886. $RadiusScale = $Radius / $MaxValue;
  1887. for ( $t=1; $t<=$MaxValue-1; $t++)
  1888. {
  1889. $TRadius = $RadiusScale * $t;
  1890. $LastX1 = -1;
  1891. for ( $i=0; $i<=$Points; $i++)
  1892. {
  1893. $Angle = -90 + $i * 360/$Points;
  1894. $X1 = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter;
  1895. $Y1 = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter;
  1896. $X2 = cos($Angle * 3.1418 / 180 ) * ($TRadius+$RadiusScale) + $XCenter;
  1897. $Y2 = sin($Angle * 3.1418 / 180 ) * ($TRadius+$RadiusScale) + $YCenter;
  1898. if ( $t % 2 == 1 && $LastX1 != -1)
  1899. {
  1900. $Plots = "";
  1901. $Plots[] = $X1; $Plots[] = $Y1;
  1902. $Plots[] = $X2; $Plots[] = $Y2;
  1903. $Plots[] = $LastX2; $Plots[] = $LastY2;
  1904. $Plots[] = $LastX1; $Plots[] = $LastY1;
  1905. $C_Graph = $this->AllocateColor($this->Picture,250,250,250);
  1906. imagefilledpolygon($this->Picture,$Plots,(count($Plots)+1)/2,$C_Graph);
  1907. }
  1908. $LastX1 = $X1; $LastY1= $Y1;
  1909. $LastX2 = $X2; $LastY2= $Y2;
  1910. }
  1911. }
  1912. }
  1913. /* Draw the spider web */
  1914. for ( $t=1; $t<=$MaxValue; $t++)
  1915. {
  1916. $TRadius = ( $Radius / $MaxValue ) * $t;
  1917. $LastX = -1;
  1918. for ( $i=0; $i<=$Points; $i++)
  1919. {
  1920. $Angle = -90 + $i * 360/$Points;
  1921. $X = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter;
  1922. $Y = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter;
  1923. if ( $LastX != -1 )
  1924. $this->drawDottedLine($LastX,$LastY,$X,$Y,4,$S_R,$S_G,$S_B);
  1925. $LastX = $X; $LastY= $Y;
  1926. }
  1927. }
  1928. /* Draw the axis */
  1929. for ( $i=0; $i<=$Points; $i++)
  1930. {
  1931. $Angle = -90 + $i * 360/$Points;
  1932. $X = cos($Angle * 3.1418 / 180 ) * $Radius + $XCenter;
  1933. $Y = sin($Angle * 3.1418 / 180 ) * $Radius + $YCenter;
  1934. $this->drawLine($XCenter,$YCenter,$X,$Y,$A_R,$A_G,$A_B);
  1935. $XOffset = 0; $YOffset = 0;
  1936. if (isset($Data[$i][$DataDescription["Position"]]))
  1937. {
  1938. $Label = $Data[$i][$DataDescription["Position"]];
  1939. $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$Label);
  1940. $Width = $Positions[2] - $Positions[6];
  1941. $Height = $Positions[3] - $Positions[7];
  1942. if ( $Angle >= 0 && $Angle <= 90 )
  1943. $YOffset = $Height;
  1944. if ( $Angle > 90 && $Angle <= 180 )
  1945. { $YOffset = $Height; $XOffset = -$Width; }
  1946. if ( $Angle > 180 && $Angle <= 270 )
  1947. { $XOffset = -$Width; }
  1948. imagettftext($this->Picture,$this->FontSize,0,$X+$XOffset,$Y+$YOffset,$C_TextColor,$this->FontName,$Label);
  1949. }
  1950. }
  1951. /* Write the values */
  1952. for ( $t=1; $t<=$MaxValue; $t++)
  1953. {
  1954. $TRadius = ( $Radius / $MaxValue ) * $t;
  1955. $Angle = -90 + 360 / $Points;
  1956. $X1 = $XCenter;
  1957. $Y1 = $YCenter - $TRadius;
  1958. $X2 = cos($Angle * 3.1418 / 180 ) * $TRadius + $XCenter;
  1959. $Y2 = sin($Angle * 3.1418 / 180 ) * $TRadius + $YCenter;
  1960. $XPos = floor(($X2-$X1)/2) + $X1;
  1961. $YPos = floor(($Y2-$Y1)/2) + $Y1;
  1962. $Positions = imagettfbbox($this->FontSize,0,$this->FontName,$t);
  1963. $X = $XPos - ( $X+$Positions[2] - $X+$Positions[6] ) / 2;
  1964. $Y = $YPos + $this->FontSize;
  1965. $this->drawFilledRoundedRectangle($X+$Positions[6]-2,$Y+$Positions[7]-1,$X+$Positions[2]+4,$Y+$Positions[3]+1,2,240,240,240);
  1966. $this->drawRoundedRectangle($X+$Positions[6]-2,$Y+$Positions[7]-1,$X+$Positions[2]+4,$Y+$Positions[3]+1,2,220,220,220);
  1967. imagettftext($this->Picture,$this->FontSize,0,$X,$Y,$C_TextColor,$this->FontName,$t);
  1968. }
  1969. }
  1970. /* This function draw a radar graph centered on the graph area */
  1971. function drawRadar($Data,$DataDescription,$BorderOffset=10,$MaxValue=-1)
  1972. {
  1973. /* Validate the Data and DataDescription array */
  1974. $this->validateDataDescription("drawRadar",$DataDescription);
  1975. $this->validateData("drawRadar",$Data);
  1976. $Points = count($Data);
  1977. $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset;
  1978. $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2 + $this->GArea_X1;
  1979. $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 + $this->GArea_Y1;
  1980. /* Search for the max value */
  1981. if ( $MaxValue == -1 )
  1982. {
  1983. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1984. {
  1985. foreach ( $Data as $Key => $Values )
  1986. {
  1987. if ( isset($Data[$Key][$ColName]))
  1988. if ( $Data[$Key][$ColName] > $MaxValue ) { $MaxValue = $Data[$Key][$ColName]; }
  1989. }
  1990. }
  1991. }
  1992. $GraphID = 0;
  1993. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  1994. {
  1995. $ID = 0;
  1996. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  1997. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  1998. $Angle = -90;
  1999. $XLast = -1;
  2000. foreach ( $Data as $Key => $Values )
  2001. {
  2002. if ( isset($Data[$Key][$ColName]))
  2003. {
  2004. $Value = $Data[$Key][$ColName];
  2005. $Strength = ( $Radius / $MaxValue ) * $Value;
  2006. $XPos = cos($Angle * 3.1418 / 180 ) * $Strength + $XCenter;
  2007. $YPos = sin($Angle * 3.1418 / 180 ) * $Strength + $YCenter;
  2008. if ( $XLast != -1 )
  2009. $this->drawLine($XLast,$YLast,$XPos,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  2010. if ( $XLast == -1 )
  2011. { $FirstX = $XPos; $FirstY = $YPos; }
  2012. $Angle = $Angle + (360/$Points);
  2013. $XLast = $XPos;
  2014. $YLast = $YPos;
  2015. }
  2016. }
  2017. $this->drawLine($XPos,$YPos,$FirstX,$FirstY,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  2018. $GraphID++;
  2019. }
  2020. }
  2021. /* This function draw a radar graph centered on the graph area */
  2022. function drawFilledRadar($Data,$DataDescription,$Alpha=50,$BorderOffset=10,$MaxValue=-1)
  2023. {
  2024. /* Validate the Data and DataDescription array */
  2025. $this->validateDataDescription("drawFilledRadar",$DataDescription);
  2026. $this->validateData("drawFilledRadar",$Data);
  2027. $Points = count($Data);
  2028. $LayerWidth = $this->GArea_X2-$this->GArea_X1;
  2029. $LayerHeight = $this->GArea_Y2-$this->GArea_Y1;
  2030. $Radius = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2 - $BorderOffset;
  2031. $XCenter = ( $this->GArea_X2 - $this->GArea_X1 ) / 2;
  2032. $YCenter = ( $this->GArea_Y2 - $this->GArea_Y1 ) / 2;
  2033. /* Search for the max value */
  2034. if ( $MaxValue == -1 )
  2035. {
  2036. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2037. {
  2038. foreach ( $Data as $Key => $Values )
  2039. {
  2040. if ( isset($Data[$Key][$ColName]))
  2041. if ( $Data[$Key][$ColName] > $MaxValue && is_numeric($Data[$Key][$ColName])) { $MaxValue = $Data[$Key][$ColName]; }
  2042. }
  2043. }
  2044. }
  2045. $GraphID = 0;
  2046. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2047. {
  2048. $ID = 0;
  2049. foreach ( $DataDescription["Description"] as $keyI => $ValueI )
  2050. { if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
  2051. $Angle = -90;
  2052. $XLast = -1;
  2053. $Plots = "";
  2054. foreach ( $Data as $Key => $Values )
  2055. {
  2056. if ( isset($Data[$Key][$ColName]))
  2057. {
  2058. $Value = $Data[$Key][$ColName];
  2059. if ( !is_numeric($Value) ) { $Value = 0; }
  2060. $Strength = ( $Radius / $MaxValue ) * $Value;
  2061. $XPos = cos($Angle * 3.1418 / 180 ) * $Strength + $XCenter;
  2062. $YPos = sin($Angle * 3.1418 / 180 ) * $Strength + $YCenter;
  2063. $Plots[] = $XPos;
  2064. $Plots[] = $YPos;
  2065. $Angle = $Angle + (360/$Points);
  2066. $XLast = $XPos;
  2067. $YLast = $YPos;
  2068. }
  2069. }
  2070. if (isset($Plots[0]))
  2071. {
  2072. $Plots[] = $Plots[0];
  2073. $Plots[] = $Plots[1];
  2074. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  2075. $C_White = $this->AllocateColor($this->Layers[0],255,255,255);
  2076. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  2077. imagecolortransparent($this->Layers[0],$C_White);
  2078. $C_Graph = $this->AllocateColor($this->Layers[0],$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"]);
  2079. imagefilledpolygon($this->Layers[0],$Plots,(count($Plots)+1)/2,$C_Graph);
  2080. imagecopymerge($this->Picture,$this->Layers[0],$this->GArea_X1,$this->GArea_Y1,0,0,$LayerWidth,$LayerHeight,$Alpha);
  2081. imagedestroy($this->Layers[0]);
  2082. for($i=0;$i<=count($Plots)-4;$i=$i+2)
  2083. $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"]);
  2084. }
  2085. $GraphID++;
  2086. }
  2087. }
  2088. /* This function draw a flat pie chart */
  2089. function drawBasicPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$R=255,$G=255,$B=255,$Decimals=0)
  2090. {
  2091. /* Validate the Data and DataDescription array */
  2092. $this->validateDataDescription("drawBasicPieGraph",$DataDescription,FALSE);
  2093. $this->validateData("drawBasicPieGraph",$Data);
  2094. /* Determine pie sum */
  2095. $Series = 0; $PieSum = 0;
  2096. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2097. {
  2098. if ( $ColName != $DataDescription["Position"] )
  2099. {
  2100. $Series++;
  2101. foreach ( $Data as $Key => $Values )
  2102. {
  2103. if ( isset($Data[$Key][$ColName]))
  2104. $PieSum = $PieSum + $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]];
  2105. }
  2106. }
  2107. }
  2108. /* Validate serie */
  2109. if ( $Series != 1 )
  2110. RaiseFatal("Pie chart can only accept one serie of data.");
  2111. $SpliceRatio = 360 / $PieSum;
  2112. $SplicePercent = 100 / $PieSum;
  2113. /* Calculate all polygons */
  2114. $Angle = 0; $TopPlots = "";
  2115. foreach($iValues as $Key => $Value)
  2116. {
  2117. $TopPlots[$Key][] = $XPos;
  2118. $TopPlots[$Key][] = $YPos;
  2119. /* Process labels position & size */
  2120. $Caption = "";
  2121. if ( !($DrawLabels == PIE_NOLABEL) )
  2122. {
  2123. $TAngle = $Angle+($Value*$SpliceRatio/2);
  2124. if ($DrawLabels == PIE_PERCENTAGE)
  2125. $Caption = (round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2126. elseif ($DrawLabels == PIE_LABELS)
  2127. $Caption = $iLabels[$Key];
  2128. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2129. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2130. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2131. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2132. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  2133. $TextWidth = $Position[2]-$Position[0];
  2134. $TextHeight = abs($Position[1])+abs($Position[3]);
  2135. $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius+10) + $XPos;
  2136. if ( $TAngle > 0 && $TAngle < 180 )
  2137. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+10) + $YPos + 4;
  2138. else
  2139. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+4) + $YPos - ($TextHeight/2);
  2140. if ( $TAngle > 90 && $TAngle < 270 )
  2141. $TX = $TX - $TextWidth;
  2142. $C_TextColor = $this->AllocateColor($this->Picture,70,70,70);
  2143. imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption);
  2144. }
  2145. /* Process pie slices */
  2146. for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5)
  2147. {
  2148. $TopX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos;
  2149. $TopY = sin($iAngle * 3.1418 / 180 ) * $Radius + $YPos;
  2150. $TopPlots[$Key][] = $TopX;
  2151. $TopPlots[$Key][] = $TopY;
  2152. }
  2153. $TopPlots[$Key][] = $XPos;
  2154. $TopPlots[$Key][] = $YPos;
  2155. $Angle = $iAngle;
  2156. }
  2157. $PolyPlots = $TopPlots;
  2158. /* Set array values type to float --- PHP Bug with imagefilledpolygon casting to integer */
  2159. foreach ($TopPlots as $Key => $Value)
  2160. { foreach ($TopPlots[$Key] as $Key2 => $Value2) { settype($TopPlots[$Key][$Key2],"float"); } }
  2161. /* Draw Top polygons */
  2162. foreach ($PolyPlots as $Key => $Value)
  2163. {
  2164. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]);
  2165. imagefilledpolygon($this->Picture,$PolyPlots[$Key],(count($PolyPlots[$Key])+1)/2,$C_GraphLo);
  2166. }
  2167. $this->drawCircle($XPos-.5,$YPos-.5,$Radius,$R,$G,$B);
  2168. $this->drawCircle($XPos-.5,$YPos-.5,$Radius+.5,$R,$G,$B);
  2169. /* Draw Top polygons */
  2170. foreach ($TopPlots as $Key => $Value)
  2171. {
  2172. for($j=0;$j<=count($TopPlots[$Key])-4;$j=$j+2)
  2173. $this->drawLine($TopPlots[$Key][$j],$TopPlots[$Key][$j+1],$TopPlots[$Key][$j+2],$TopPlots[$Key][$j+3],$R,$G,$B);
  2174. }
  2175. }
  2176. function drawFlatPieGraphWithShadow($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals=0)
  2177. {
  2178. $this->drawFlatPieGraph($Data,$DataDescription,$XPos+$this->ShadowXDistance,$YPos+$this->ShadowYDistance,$Radius,PIE_NOLABEL,$SpliceDistance,$Decimals,TRUE);
  2179. $this->drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius,$DrawLabels,$SpliceDistance,$Decimals,FALSE);
  2180. }
  2181. /* This function draw a flat pie chart */
  2182. function drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals=0,$AllBlack=FALSE)
  2183. {
  2184. /* Validate the Data and DataDescription array */
  2185. $this->validateDataDescription("drawFlatPieGraph",$DataDescription,FALSE);
  2186. $this->validateData("drawFlatPieGraph",$Data);
  2187. $ShadowStatus = $this->ShadowActive ; $this->ShadowActive = FALSE;
  2188. /* Determine pie sum */
  2189. $Series = 0; $PieSum = 0;
  2190. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2191. {
  2192. if ( $ColName != $DataDescription["Position"] )
  2193. {
  2194. $Series++;
  2195. foreach ( $Data as $Key => $Values )
  2196. {
  2197. if ( isset($Data[$Key][$ColName]))
  2198. $PieSum = $PieSum + $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]];
  2199. }
  2200. }
  2201. }
  2202. /* Validate serie */
  2203. if ( $Series != 1 )
  2204. {
  2205. RaiseFatal("Pie chart can only accept one serie of data.");
  2206. return(0);
  2207. }
  2208. $SpliceRatio = 360 / $PieSum;
  2209. $SplicePercent = 100 / $PieSum;
  2210. /* Calculate all polygons */
  2211. $Angle = 0; $TopPlots = "";
  2212. foreach($iValues as $Key => $Value)
  2213. {
  2214. $XOffset = cos(($Angle+($Value/2*$SpliceRatio)) * 3.1418 / 180 ) * $SpliceDistance;
  2215. $YOffset = sin(($Angle+($Value/2*$SpliceRatio)) * 3.1418 / 180 ) * $SpliceDistance;
  2216. $TopPlots[$Key][] = round($XPos + $XOffset);
  2217. $TopPlots[$Key][] = round($YPos + $YOffset);
  2218. if ( $AllBlack )
  2219. { $Rc = $this->ShadowRColor; $Gc = $this->ShadowGColor; $Bc = $this->ShadowBColor; }
  2220. else
  2221. { $Rc = $this->Palette[$Key]["R"]; $Gc = $this->Palette[$Key]["G"]; $Bc = $this->Palette[$Key]["B"]; }
  2222. $XLineLast = ""; $YLineLast = "";
  2223. /* Process labels position & size */
  2224. $Caption = "";
  2225. if ( !($DrawLabels == PIE_NOLABEL) )
  2226. {
  2227. $TAngle = $Angle+($Value*$SpliceRatio/2);
  2228. if ($DrawLabels == PIE_PERCENTAGE)
  2229. $Caption = (round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2230. elseif ($DrawLabels == PIE_LABELS)
  2231. $Caption = $iLabels[$Key];
  2232. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2233. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2234. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2235. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2236. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  2237. $TextWidth = $Position[2]-$Position[0];
  2238. $TextHeight = abs($Position[1])+abs($Position[3]);
  2239. $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius+10+$SpliceDistance) + $XPos;
  2240. if ( $TAngle > 0 && $TAngle < 180 )
  2241. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+10+$SpliceDistance) + $YPos + 4;
  2242. else
  2243. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($Radius+$SpliceDistance+4) + $YPos - ($TextHeight/2);
  2244. if ( $TAngle > 90 && $TAngle < 270 )
  2245. $TX = $TX - $TextWidth;
  2246. $C_TextColor = $this->AllocateColor($this->Picture,70,70,70);
  2247. imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption);
  2248. }
  2249. /* Process pie slices */
  2250. if ( !$AllBlack )
  2251. $LineColor = $this->AllocateColor($this->Picture,$Rc,$Gc,$Bc);
  2252. else
  2253. $LineColor = $this->AllocateColor($this->Picture,$Rc,$Gc,$Bc);
  2254. $XLineLast = ""; $YLineLast = "";
  2255. for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5)
  2256. {
  2257. $PosX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos + $XOffset;
  2258. $PosY = sin($iAngle * 3.1418 / 180 ) * $Radius + $YPos + $YOffset;
  2259. $TopPlots[$Key][] = round($PosX); $TopPlots[$Key][] = round($PosY);
  2260. if ( $iAngle == $Angle || $iAngle == $Angle+$Value*$SpliceRatio || $iAngle +.5 > $Angle+$Value*$SpliceRatio)
  2261. $this->drawLine($XPos+$XOffset,$YPos+$YOffset,$PosX,$PosY,$Rc,$Gc,$Bc);
  2262. if ( $XLineLast != "" )
  2263. $this->drawLine($XLineLast,$YLineLast,$PosX,$PosY,$Rc,$Gc,$Bc);
  2264. $XLineLast = $PosX; $YLineLast = $PosY;
  2265. }
  2266. $TopPlots[$Key][] = round($XPos + $XOffset); $TopPlots[$Key][] = round($YPos + $YOffset);
  2267. $Angle = $iAngle;
  2268. }
  2269. $PolyPlots = $TopPlots;
  2270. /* Draw Top polygons */
  2271. foreach ($PolyPlots as $Key => $Value)
  2272. {
  2273. if ( !$AllBlack )
  2274. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]);
  2275. else
  2276. $C_GraphLo = $this->AllocateColor($this->Picture,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor);
  2277. imagefilledpolygon($this->Picture,$PolyPlots[$Key],(count($PolyPlots[$Key])+1)/2,$C_GraphLo);
  2278. }
  2279. $this->ShadowActive = $ShadowStatus;
  2280. }
  2281. /* This function draw a pseudo-3D pie chart */
  2282. function drawPieGraph($Data,$DataDescription,$XPos,$YPos,$Radius=100,$DrawLabels=PIE_NOLABEL,$EnhanceColors=TRUE,$Skew=60,$SpliceHeight=20,$SpliceDistance=0,$Decimals=0)
  2283. {
  2284. /* Validate the Data and DataDescription array */
  2285. $this->validateDataDescription("drawPieGraph",$DataDescription,FALSE);
  2286. $this->validateData("drawPieGraph",$Data);
  2287. /* Determine pie sum */
  2288. $Series = 0; $PieSum = 0; $rPieSum = 0;
  2289. foreach ( $DataDescription["Values"] as $Key2 => $ColName )
  2290. {
  2291. if ( $ColName != $DataDescription["Position"] )
  2292. {
  2293. $Series++;
  2294. foreach ( $Data as $Key => $Values )
  2295. if ( isset($Data[$Key][$ColName]))
  2296. {
  2297. if ( $Data[$Key][$ColName] == 0 )
  2298. { $iValues[] = 0; $rValues[] = 0; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; }
  2299. // Removed : $PieSum++; $rValues[] = 1;
  2300. else
  2301. { $PieSum += $Data[$Key][$ColName]; $iValues[] = $Data[$Key][$ColName]; $iLabels[] = $Data[$Key][$DataDescription["Position"]]; $rValues[] = $Data[$Key][$ColName]; $rPieSum += $Data[$Key][$ColName];}
  2302. }
  2303. }
  2304. }
  2305. /* Validate serie */
  2306. if ( $Series != 1 )
  2307. RaiseFatal("Pie chart can only accept one serie of data.");
  2308. $SpliceDistanceRatio = $SpliceDistance;
  2309. $SkewHeight = ($Radius * $Skew) / 100;
  2310. $SpliceRatio = (360 - $SpliceDistanceRatio * count($iValues) ) / $PieSum;
  2311. $SplicePercent = 100 / $PieSum;
  2312. $rSplicePercent = 100 / $rPieSum;
  2313. /* Calculate all polygons */
  2314. $Angle = 0; $CDev = 5;
  2315. $TopPlots = ""; $BotPlots = "";
  2316. $aTopPlots = ""; $aBotPlots = "";
  2317. foreach($iValues as $Key => $Value)
  2318. {
  2319. $XCenterPos = cos(($Angle-$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $XPos;
  2320. $YCenterPos = sin(($Angle-$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $YPos;
  2321. $XCenterPos2 = cos(($Angle+$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $XPos;
  2322. $YCenterPos2 = sin(($Angle+$CDev+($Value*$SpliceRatio+$SpliceDistanceRatio)/2) * 3.1418 / 180 ) * $SpliceDistance + $YPos;
  2323. $TopPlots[$Key][] = round($XCenterPos); $BotPlots[$Key][] = round($XCenterPos);
  2324. $TopPlots[$Key][] = round($YCenterPos); $BotPlots[$Key][] = round($YCenterPos + $SpliceHeight);
  2325. $aTopPlots[$Key][] = $XCenterPos; $aBotPlots[$Key][] = $XCenterPos;
  2326. $aTopPlots[$Key][] = $YCenterPos; $aBotPlots[$Key][] = $YCenterPos + $SpliceHeight;
  2327. /* Process labels position & size */
  2328. $Caption = "";
  2329. if ( !($DrawLabels == PIE_NOLABEL) )
  2330. {
  2331. $TAngle = $Angle+($Value*$SpliceRatio/2);
  2332. if ($DrawLabels == PIE_PERCENTAGE)
  2333. $Caption = (round($rValues[$Key] * pow(10,$Decimals) * $rSplicePercent)/pow(10,$Decimals))."%";
  2334. elseif ($DrawLabels == PIE_LABELS)
  2335. $Caption = $iLabels[$Key];
  2336. elseif ($DrawLabels == PIE_PERCENTAGE_LABEL)
  2337. $Caption = $iLabels[$Key]."\r\n".(round($Value * pow(10,$Decimals) * $SplicePercent)/pow(10,$Decimals))."%";
  2338. $Position = imageftbbox($this->FontSize,0,$this->FontName,$Caption);
  2339. $TextWidth = $Position[2]-$Position[0];
  2340. $TextHeight = abs($Position[1])+abs($Position[3]);
  2341. $TX = cos(($TAngle) * 3.1418 / 180 ) * ($Radius + 10)+ $XPos;
  2342. if ( $TAngle > 0 && $TAngle < 180 )
  2343. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($SkewHeight + 10) + $YPos + $SpliceHeight + 4;
  2344. else
  2345. $TY = sin(($TAngle) * 3.1418 / 180 ) * ($SkewHeight + 4) + $YPos - ($TextHeight/2);
  2346. if ( $TAngle > 90 && $TAngle < 270 )
  2347. $TX = $TX - $TextWidth;
  2348. $C_TextColor = $this->AllocateColor($this->Picture,70,70,70);
  2349. imagettftext($this->Picture,$this->FontSize,0,$TX,$TY,$C_TextColor,$this->FontName,$Caption);
  2350. }
  2351. /* Process pie slices */
  2352. for($iAngle=$Angle;$iAngle<=$Angle+$Value*$SpliceRatio;$iAngle=$iAngle+.5)
  2353. {
  2354. $TopX = cos($iAngle * 3.1418 / 180 ) * $Radius + $XPos;
  2355. $TopY = sin($iAngle * 3.1418 / 180 ) * $SkewHeight + $YPos;
  2356. $TopPlots[$Key][] = round($TopX); $BotPlots[$Key][] = round($TopX);
  2357. $TopPlots[$Key][] = round($TopY); $BotPlots[$Key][] = round($TopY + $SpliceHeight);
  2358. $aTopPlots[$Key][] = $TopX; $aBotPlots[$Key][] = $TopX;
  2359. $aTopPlots[$Key][] = $TopY; $aBotPlots[$Key][] = $TopY + $SpliceHeight;
  2360. }
  2361. $TopPlots[$Key][] = round($XCenterPos2); $BotPlots[$Key][] = round($XCenterPos2);
  2362. $TopPlots[$Key][] = round($YCenterPos2); $BotPlots[$Key][] = round($YCenterPos2 + $SpliceHeight);
  2363. $aTopPlots[$Key][] = $XCenterPos2; $aBotPlots[$Key][] = $XCenterPos2;
  2364. $aTopPlots[$Key][] = $YCenterPos2; $aBotPlots[$Key][] = $YCenterPos2 + $SpliceHeight;
  2365. $Angle = $iAngle + $SpliceDistanceRatio;
  2366. }
  2367. /* Draw Bottom polygons */
  2368. foreach($iValues as $Key => $Value)
  2369. {
  2370. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"],-20);
  2371. imagefilledpolygon($this->Picture,$BotPlots[$Key],(count($BotPlots[$Key])+1)/2,$C_GraphLo);
  2372. if ( $EnhanceColors ) { $En = -10; } else { $En = 0; }
  2373. for($j=0;$j<=count($aBotPlots[$Key])-4;$j=$j+2)
  2374. $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);
  2375. }
  2376. /* Draw pie layers */
  2377. if ( $EnhanceColors ) { $ColorRatio = 30 / $SpliceHeight; } else { $ColorRatio = 25 / $SpliceHeight; }
  2378. for($i=$SpliceHeight-1;$i>=1;$i--)
  2379. {
  2380. foreach($iValues as $Key => $Value)
  2381. {
  2382. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"],-10);
  2383. $Plots = ""; $Plot = 0;
  2384. foreach($TopPlots[$Key] as $Key2 => $Value2)
  2385. {
  2386. $Plot++;
  2387. if ( $Plot % 2 == 1 )
  2388. $Plots[] = $Value2;
  2389. else
  2390. $Plots[] = $Value2+$i;
  2391. }
  2392. imagefilledpolygon($this->Picture,$Plots,(count($Plots)+1)/2,$C_GraphLo);
  2393. $Index = count($Plots);
  2394. if ($EnhanceColors ) {$ColorFactor = -20 + ($SpliceHeight - $i) * $ColorRatio; } else { $ColorFactor = 0; }
  2395. $this->drawAntialiasPixel($Plots[0],$Plots[1],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor);
  2396. $this->drawAntialiasPixel($Plots[2],$Plots[3],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor);
  2397. $this->drawAntialiasPixel($Plots[$Index-4],$Plots[$Index-3],$this->Palette[$Key]["R"]+$ColorFactor,$this->Palette[$Key]["G"]+$ColorFactor,$this->Palette[$Key]["B"]+$ColorFactor);
  2398. }
  2399. }
  2400. /* Draw Top polygons */
  2401. for($Key=count($iValues)-1;$Key>=0;$Key--)
  2402. {
  2403. $C_GraphLo = $this->AllocateColor($this->Picture,$this->Palette[$Key]["R"],$this->Palette[$Key]["G"],$this->Palette[$Key]["B"]);
  2404. imagefilledpolygon($this->Picture,$TopPlots[$Key],(count($TopPlots[$Key])+1)/2,$C_GraphLo);
  2405. if ( $EnhanceColors ) { $En = 10; } else { $En = 0; }
  2406. for($j=0;$j<=count($aTopPlots[$Key])-4;$j=$j+2)
  2407. $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);
  2408. }
  2409. }
  2410. /* This function can be used to set the background color */
  2411. function drawBackground($R,$G,$B)
  2412. {
  2413. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2414. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2415. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2416. $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B);
  2417. imagefilledrectangle($this->Picture,0,0,$this->XSize,$this->YSize,$C_Background);
  2418. }
  2419. /* This function can be used to set the background color */
  2420. function drawGraphAreaGradient($R,$G,$B,$Decay,$Target=TARGET_GRAPHAREA)
  2421. {
  2422. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2423. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2424. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2425. if ( $Target == TARGET_GRAPHAREA ) { $X1 = $this->GArea_X1+1; $X2 = $this->GArea_X2-1; $Y1 = $this->GArea_Y1+1; $Y2 = $this->GArea_Y2; }
  2426. if ( $Target == TARGET_BACKGROUND ) { $X1 = 0; $X2 = $this->XSize; $Y1 = 0; $Y2 = $this->YSize; }
  2427. /* Positive gradient */
  2428. if ( $Decay > 0 )
  2429. {
  2430. $YStep = ($Y2 - $Y1 - 2) / $Decay;
  2431. for($i=0;$i<=$Decay;$i++)
  2432. {
  2433. $R-=1;$G-=1;$B-=1;
  2434. $Yi1 = $Y1 + ( $i * $YStep );
  2435. $Yi2 = ceil( $Yi1 + ( $i * $YStep ) + $YStep );
  2436. if ( $Yi2 >= $Yi2 ) { $Yi2 = $Y2-1; }
  2437. $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B);
  2438. imagefilledrectangle($this->Picture,$X1,$Yi1,$X2,$Yi2,$C_Background);
  2439. }
  2440. }
  2441. /* Negative gradient */
  2442. if ( $Decay < 0 )
  2443. {
  2444. $YStep = ($Y2 - $Y1 - 2) / -$Decay;
  2445. $Yi1 = $Y1; $Yi2 = $Y1+$YStep;
  2446. for($i=-$Decay;$i>=0;$i--)
  2447. {
  2448. $R+=1;$G+=1;$B+=1;
  2449. $C_Background = $this->AllocateColor($this->Picture,$R,$G,$B);
  2450. imagefilledrectangle($this->Picture,$X1,$Yi1,$X2,$Yi2,$C_Background);
  2451. $Yi1+= $YStep;
  2452. $Yi2+= $YStep;
  2453. if ( $Yi2 >= $Yi2 ) { $Yi2 = $Y2-1; }
  2454. }
  2455. }
  2456. }
  2457. /* This function create a rectangle with antialias */
  2458. function drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B)
  2459. {
  2460. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2461. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2462. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2463. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2464. $X1=$X1-.2;$Y1=$Y1-.2;
  2465. $X2=$X2+.2;$Y2=$Y2+.2;
  2466. $this->drawLine($X1,$Y1,$X2,$Y1,$R,$G,$B);
  2467. $this->drawLine($X2,$Y1,$X2,$Y2,$R,$G,$B);
  2468. $this->drawLine($X2,$Y2,$X1,$Y2,$R,$G,$B);
  2469. $this->drawLine($X1,$Y2,$X1,$Y1,$R,$G,$B);
  2470. }
  2471. /* This function create a filled rectangle with antialias */
  2472. function drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B,$DrawBorder=TRUE,$Alpha=100,$NoFallBack=FALSE)
  2473. {
  2474. if ( $X2 < $X1 ) { list($X1, $X2) = array($X2, $X1); }
  2475. if ( $Y2 < $Y1 ) { list($Y1, $Y2) = array($Y2, $Y1); }
  2476. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2477. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2478. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2479. if ( $Alpha == 100 )
  2480. {
  2481. /* Process shadows */
  2482. if ( $this->ShadowActive && !$NoFallBack )
  2483. {
  2484. $this->drawFilledRectangle($X1+$this->ShadowXDistance,$Y1+$this->ShadowYDistance,$X2+$this->ShadowXDistance,$Y2+$this->ShadowYDistance,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,FALSE,$this->ShadowAlpha,TRUE);
  2485. if ( $this->ShadowBlur != 0 )
  2486. {
  2487. $AlphaDecay = ($this->ShadowAlpha / $this->ShadowBlur);
  2488. for($i=1; $i<=$this->ShadowBlur; $i++)
  2489. $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);
  2490. for($i=1; $i<=$this->ShadowBlur; $i++)
  2491. $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);
  2492. }
  2493. }
  2494. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2495. imagefilledrectangle($this->Picture,round($X1),round($Y1),round($X2),round($Y2),$C_Rectangle);
  2496. }
  2497. else
  2498. {
  2499. $LayerWidth = abs($X2-$X1)+2;
  2500. $LayerHeight = abs($Y2-$Y1)+2;
  2501. $this->Layers[0] = imagecreatetruecolor($LayerWidth,$LayerHeight);
  2502. $C_White = $this->AllocateColor($this->Layers[0],255,255,255);
  2503. imagefilledrectangle($this->Layers[0],0,0,$LayerWidth,$LayerHeight,$C_White);
  2504. imagecolortransparent($this->Layers[0],$C_White);
  2505. $C_Rectangle = $this->AllocateColor($this->Layers[0],$R,$G,$B);
  2506. imagefilledrectangle($this->Layers[0],round(1),round(1),round($LayerWidth-1),round($LayerHeight-1),$C_Rectangle);
  2507. imagecopymerge($this->Picture,$this->Layers[0],round(min($X1,$X2)-1),round(min($Y1,$Y2)-1),0,0,$LayerWidth,$LayerHeight,$Alpha);
  2508. imagedestroy($this->Layers[0]);
  2509. }
  2510. if ( $DrawBorder )
  2511. {
  2512. $ShadowSettings = $this->ShadowActive; $this->ShadowActive = FALSE;
  2513. $this->drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B);
  2514. $this->ShadowActive = $ShadowSettings;
  2515. }
  2516. }
  2517. /* This function create a rectangle with rounded corners and antialias */
  2518. function drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
  2519. {
  2520. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2521. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2522. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2523. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2524. $Step = 90 / ((3.1418 * $Radius)/2);
  2525. for($i=0;$i<=90;$i=$i+$Step)
  2526. {
  2527. $X = cos(($i+180)*3.1418/180) * $Radius + $X1 + $Radius;
  2528. $Y = sin(($i+180)*3.1418/180) * $Radius + $Y1 + $Radius;
  2529. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2530. $X = cos(($i-90)*3.1418/180) * $Radius + $X2 - $Radius;
  2531. $Y = sin(($i-90)*3.1418/180) * $Radius + $Y1 + $Radius;
  2532. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2533. $X = cos(($i)*3.1418/180) * $Radius + $X2 - $Radius;
  2534. $Y = sin(($i)*3.1418/180) * $Radius + $Y2 - $Radius;
  2535. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2536. $X = cos(($i+90)*3.1418/180) * $Radius + $X1 + $Radius;
  2537. $Y = sin(($i+90)*3.1418/180) * $Radius + $Y2 - $Radius;
  2538. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2539. }
  2540. $X1=$X1-.2;$Y1=$Y1-.2;
  2541. $X2=$X2+.2;$Y2=$Y2+.2;
  2542. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$R,$G,$B);
  2543. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$R,$G,$B);
  2544. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$R,$G,$B);
  2545. $this->drawLine($X1,$Y2-$Radius,$X1,$Y1+$Radius,$R,$G,$B);
  2546. }
  2547. /* This function create a filled rectangle with rounded corners and antialias */
  2548. function drawFilledRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
  2549. {
  2550. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2551. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2552. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2553. $C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2554. $Step = 90 / ((3.1418 * $Radius)/2);
  2555. for($i=0;$i<=90;$i=$i+$Step)
  2556. {
  2557. $Xi1 = cos(($i+180)*3.1418/180) * $Radius + $X1 + $Radius;
  2558. $Yi1 = sin(($i+180)*3.1418/180) * $Radius + $Y1 + $Radius;
  2559. $Xi2 = cos(($i-90)*3.1418/180) * $Radius + $X2 - $Radius;
  2560. $Yi2 = sin(($i-90)*3.1418/180) * $Radius + $Y1 + $Radius;
  2561. $Xi3 = cos(($i)*3.1418/180) * $Radius + $X2 - $Radius;
  2562. $Yi3 = sin(($i)*3.1418/180) * $Radius + $Y2 - $Radius;
  2563. $Xi4 = cos(($i+90)*3.1418/180) * $Radius + $X1 + $Radius;
  2564. $Yi4 = sin(($i+90)*3.1418/180) * $Radius + $Y2 - $Radius;
  2565. imageline($this->Picture,$Xi1,$Yi1,$X1+$Radius,$Yi1,$C_Rectangle);
  2566. imageline($this->Picture,$X2-$Radius,$Yi2,$Xi2,$Yi2,$C_Rectangle);
  2567. imageline($this->Picture,$X2-$Radius,$Yi3,$Xi3,$Yi3,$C_Rectangle);
  2568. imageline($this->Picture,$Xi4,$Yi4,$X1+$Radius,$Yi4,$C_Rectangle);
  2569. $this->drawAntialiasPixel($Xi1,$Yi1,$R,$G,$B);
  2570. $this->drawAntialiasPixel($Xi2,$Yi2,$R,$G,$B);
  2571. $this->drawAntialiasPixel($Xi3,$Yi3,$R,$G,$B);
  2572. $this->drawAntialiasPixel($Xi4,$Yi4,$R,$G,$B);
  2573. }
  2574. imagefilledrectangle($this->Picture,$X1,$Y1+$Radius,$X2,$Y2-$Radius,$C_Rectangle);
  2575. imagefilledrectangle($this->Picture,$X1+$Radius,$Y1,$X2-$Radius,$Y2,$C_Rectangle);
  2576. $X1=$X1-.2;$Y1=$Y1-.2;
  2577. $X2=$X2+.2;$Y2=$Y2+.2;
  2578. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$R,$G,$B);
  2579. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$R,$G,$B);
  2580. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$R,$G,$B);
  2581. $this->drawLine($X1,$Y2-$Radius,$X1,$Y1+$Radius,$R,$G,$B);
  2582. }
  2583. /* This function create a circle with antialias */
  2584. function drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
  2585. {
  2586. if ( $Width == 0 ) { $Width = $Height; }
  2587. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2588. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2589. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2590. $C_Circle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2591. $Step = 360 / (2 * 3.1418 * max($Width,$Height));
  2592. for($i=0;$i<=360;$i=$i+$Step)
  2593. {
  2594. $X = cos($i*3.1418/180) * $Height + $Xc;
  2595. $Y = sin($i*3.1418/180) * $Width + $Yc;
  2596. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2597. }
  2598. }
  2599. /* This function create a filled circle/ellipse with antialias */
  2600. function drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
  2601. {
  2602. if ( $Width == 0 ) { $Width = $Height; }
  2603. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2604. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2605. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2606. $C_Circle = $this->AllocateColor($this->Picture,$R,$G,$B);
  2607. $Step = 360 / (2 * 3.1418 * max($Width,$Height));
  2608. for($i=90;$i<=270;$i=$i+$Step)
  2609. {
  2610. $X1 = cos($i*3.1418/180) * $Height + $Xc;
  2611. $Y1 = sin($i*3.1418/180) * $Width + $Yc;
  2612. $X2 = cos((180-$i)*3.1418/180) * $Height + $Xc;
  2613. $Y2 = sin((180-$i)*3.1418/180) * $Width + $Yc;
  2614. $this->drawAntialiasPixel($X1-1,$Y1-1,$R,$G,$B);
  2615. $this->drawAntialiasPixel($X2-1,$Y2-1,$R,$G,$B);
  2616. if ( ($Y1-1) > $Yc - max($Width,$Height) )
  2617. imageline($this->Picture,$X1,$Y1-1,$X2-1,$Y2-1,$C_Circle);
  2618. }
  2619. }
  2620. /* This function will draw a filled ellipse */
  2621. function drawEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
  2622. { $this->drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width); }
  2623. /* This function will draw an ellipse */
  2624. function drawFilledEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
  2625. { $this->drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width); }
  2626. /* This function create a line with antialias */
  2627. function drawLine($X1,$Y1,$X2,$Y2,$R,$G,$B,$GraphFunction=FALSE)
  2628. {
  2629. if ( $this->LineDotSize > 1 ) { $this->drawDottedLine($X1,$Y1,$X2,$Y2,$this->LineDotSize,$R,$G,$B,$GraphFunction); return(0); }
  2630. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2631. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2632. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2633. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  2634. if ( $Distance == 0 )
  2635. return(-1);
  2636. $XStep = ($X2-$X1) / $Distance;
  2637. $YStep = ($Y2-$Y1) / $Distance;
  2638. for($i=0;$i<=$Distance;$i++)
  2639. {
  2640. $X = $i * $XStep + $X1;
  2641. $Y = $i * $YStep + $Y1;
  2642. if ( ($X >= $this->GArea_X1 && $X <= $this->GArea_X2 && $Y >= $this->GArea_Y1 && $Y <= $this->GArea_Y2) || !$GraphFunction )
  2643. {
  2644. if ( $this->LineWidth == 1 )
  2645. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2646. else
  2647. {
  2648. $StartOffset = -($this->LineWidth/2); $EndOffset = ($this->LineWidth/2);
  2649. for($j=$StartOffset;$j<=$EndOffset;$j++)
  2650. $this->drawAntialiasPixel($X+$j,$Y+$j,$R,$G,$B);
  2651. }
  2652. }
  2653. }
  2654. }
  2655. /* This function create a line with antialias */
  2656. function drawDottedLine($X1,$Y1,$X2,$Y2,$DotSize,$R,$G,$B,$GraphFunction=FALSE)
  2657. {
  2658. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2659. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2660. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2661. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  2662. $XStep = ($X2-$X1) / $Distance;
  2663. $YStep = ($Y2-$Y1) / $Distance;
  2664. $DotIndex = 0;
  2665. for($i=0;$i<=$Distance;$i++)
  2666. {
  2667. $X = $i * $XStep + $X1;
  2668. $Y = $i * $YStep + $Y1;
  2669. if ( $DotIndex <= $DotSize)
  2670. {
  2671. if ( ($X >= $this->GArea_X1 && $X <= $this->GArea_X2 && $Y >= $this->GArea_Y1 && $Y <= $this->GArea_Y2) || !$GraphFunction )
  2672. {
  2673. if ( $this->LineWidth == 1 )
  2674. $this->drawAntialiasPixel($X,$Y,$R,$G,$B);
  2675. else
  2676. {
  2677. $StartOffset = -($this->LineWidth/2); $EndOffset = ($this->LineWidth/2);
  2678. for($j=$StartOffset;$j<=$EndOffset;$j++)
  2679. $this->drawAntialiasPixel($X+$j,$Y+$j,$R,$G,$B);
  2680. }
  2681. }
  2682. }
  2683. $DotIndex++;
  2684. if ( $DotIndex == $DotSize * 2 )
  2685. $DotIndex = 0;
  2686. }
  2687. }
  2688. /* Load a PNG file and draw it over the chart */
  2689. function drawFromPNG($FileName,$X,$Y,$Alpha=100)
  2690. { $this->drawFromPicture(1,$FileName,$X,$Y,$Alpha); }
  2691. /* Load a GIF file and draw it over the chart */
  2692. function drawFromGIF($FileName,$X,$Y,$Alpha=100)
  2693. { $this->drawFromPicture(2,$FileName,$X,$Y,$Alpha); }
  2694. /* Load a JPEG file and draw it over the chart */
  2695. function drawFromJPG($FileName,$X,$Y,$Alpha=100)
  2696. { $this->drawFromPicture(3,$FileName,$X,$Y,$Alpha); }
  2697. /* Generic loader function for external pictures */
  2698. function drawFromPicture($PicType,$FileName,$X,$Y,$Alpha=100)
  2699. {
  2700. if ( file_exists($FileName))
  2701. {
  2702. $Infos = getimagesize($FileName);
  2703. $Width = $Infos[0];
  2704. $Height = $Infos[1];
  2705. if ( $PicType == 1 ) { $Raster = imagecreatefrompng($FileName); }
  2706. if ( $PicType == 2 ) { $Raster = imagecreatefromgif($FileName); }
  2707. if ( $PicType == 3 ) { $Raster = imagecreatefromjpeg($FileName); }
  2708. imagecopymerge($this->Picture,$Raster,$X,$Y,0,0,$Width,$Height,$Alpha);
  2709. imagedestroy($Raster);
  2710. }
  2711. }
  2712. /* Draw an alpha pixel */
  2713. function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
  2714. {
  2715. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2716. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2717. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2718. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  2719. return(-1);
  2720. $RGB2 = imagecolorat($this->Picture, $X, $Y);
  2721. $R2 = ($RGB2 >> 16) & 0xFF;
  2722. $G2 = ($RGB2 >> 8) & 0xFF;
  2723. $B2 = $RGB2 & 0xFF;
  2724. $iAlpha = (100 - $Alpha)/100;
  2725. $Alpha = $Alpha / 100;
  2726. $Ra = floor($R*$Alpha+$R2*$iAlpha);
  2727. $Ga = floor($G*$Alpha+$G2*$iAlpha);
  2728. $Ba = floor($B*$Alpha+$B2*$iAlpha);
  2729. $C_Aliased = $this->AllocateColor($this->Picture,$Ra,$Ga,$Ba);
  2730. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  2731. }
  2732. /* Color helper */
  2733. function AllocateColor($Picture,$R,$G,$B,$Factor=0)
  2734. {
  2735. $R = $R + $Factor;
  2736. $G = $G + $Factor;
  2737. $B = $B + $Factor;
  2738. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2739. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2740. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2741. return(imagecolorallocate($Picture,$R,$G,$B));
  2742. }
  2743. /* Add a border to the picture */
  2744. function addBorder($Size=3,$R=0,$G=0,$B=0)
  2745. {
  2746. $Width = $this->XSize+2*$Size;
  2747. $Height = $this->YSize+2*$Size;
  2748. $Resampled = imagecreatetruecolor($Width,$Height);
  2749. $C_Background = $this->AllocateColor($Resampled,$R,$G,$B);
  2750. imagefilledrectangle($Resampled,0,0,$Width,$Height,$C_Background);
  2751. imagecopy($Resampled,$this->Picture,$Size,$Size,0,0,$this->XSize,$this->YSize);
  2752. imagedestroy($this->Picture);
  2753. $this->XSize = $Width;
  2754. $this->YSize = $Height;
  2755. $this->Picture = imagecreatetruecolor($this->XSize,$this->YSize);
  2756. $C_White = $this->AllocateColor($this->Picture,255,255,255);
  2757. imagefilledrectangle($this->Picture,0,0,$this->XSize,$this->YSize,$C_White);
  2758. imagecolortransparent($this->Picture,$C_White);
  2759. imagecopy($this->Picture,$Resampled,0,0,0,0,$this->XSize,$this->YSize);
  2760. }
  2761. /* Render the current picture to a file */
  2762. function Render($FileName)
  2763. {
  2764. if ( $this->ErrorReporting )
  2765. $this->printErrors($this->ErrorInterface);
  2766. /* Save image map if requested */
  2767. if ( $this->BuildMap )
  2768. $this->SaveImageMap();
  2769. imagepng($this->Picture,$FileName);
  2770. }
  2771. /* Render the current picture to STDOUT */
  2772. function Stroke()
  2773. {
  2774. if ( $this->ErrorReporting )
  2775. $this->printErrors("GD");
  2776. /* Save image map if requested */
  2777. if ( $this->BuildMap )
  2778. $this->SaveImageMap();
  2779. header('Content-type: image/png');
  2780. imagepng($this->Picture);
  2781. }
  2782. /* Private functions for internal processing */
  2783. function drawAntialiasPixel($X,$Y,$R,$G,$B,$Alpha=100,$NoFallBack=FALSE)
  2784. {
  2785. /* Process shadows */
  2786. if ( $this->ShadowActive && !$NoFallBack )
  2787. {
  2788. $this->drawAntialiasPixel($X+$this->ShadowXDistance,$Y+$this->ShadowYDistance,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha,TRUE);
  2789. if ( $this->ShadowBlur != 0 )
  2790. {
  2791. $AlphaDecay = ($this->ShadowAlpha / $this->ShadowBlur);
  2792. for($i=1; $i<=$this->ShadowBlur; $i++)
  2793. $this->drawAntialiasPixel($X+$this->ShadowXDistance-$i/2,$Y+$this->ShadowYDistance-$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha-$AlphaDecay*$i,TRUE);
  2794. for($i=1; $i<=$this->ShadowBlur; $i++)
  2795. $this->drawAntialiasPixel($X+$this->ShadowXDistance+$i/2,$Y+$this->ShadowYDistance+$i/2,$this->ShadowRColor,$this->ShadowGColor,$this->ShadowBColor,$this->ShadowAlpha-$AlphaDecay*$i,TRUE);
  2796. }
  2797. }
  2798. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  2799. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  2800. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  2801. $Plot = "";
  2802. $Xi = floor($X);
  2803. $Yi = floor($Y);
  2804. if ( $Xi == $X && $Yi == $Y)
  2805. {
  2806. if ( $Alpha == 100 )
  2807. {
  2808. $C_Aliased = $this->AllocateColor($this->Picture,$R,$G,$B);
  2809. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  2810. }
  2811. else
  2812. $this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B);
  2813. }
  2814. else
  2815. {
  2816. $Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  2817. if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); }
  2818. $Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  2819. if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); }
  2820. $Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  2821. if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); }
  2822. $Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  2823. if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); }
  2824. }
  2825. }
  2826. /* Validate data contained in the description array */
  2827. function validateDataDescription($FunctionName,&$DataDescription,$DescriptionRequired=TRUE)
  2828. {
  2829. if (!isset($DataDescription["Position"]))
  2830. {
  2831. $this->Errors[] = "[Warning] ".$FunctionName." - Y Labels are not set.";
  2832. $DataDescription["Position"] = "Name";
  2833. }
  2834. if ( $DescriptionRequired )
  2835. {
  2836. if (!isset($DataDescription["Description"]))
  2837. {
  2838. $this->Errors[] = "[Warning] ".$FunctionName." - Series descriptions are not set.";
  2839. foreach($DataDescription["Values"] as $key => $Value)
  2840. {
  2841. $DataDescription["Description"][$Value] = $Value;
  2842. }
  2843. }
  2844. if (count($DataDescription["Description"]) < count($DataDescription["Values"]))
  2845. {
  2846. $this->Errors[] = "[Warning] ".$FunctionName." - Some series descriptions are not set.";
  2847. foreach($DataDescription["Values"] as $key => $Value)
  2848. {
  2849. if ( !isset($DataDescription["Description"][$Value]))
  2850. $DataDescription["Description"][$Value] = $Value;
  2851. }
  2852. }
  2853. }
  2854. }
  2855. /* Validate data contained in the data array */
  2856. function validateData($FunctionName,&$Data)
  2857. {
  2858. $DataSummary = array();
  2859. foreach($Data as $key => $Values)
  2860. {
  2861. foreach($Values as $key2 => $Value)
  2862. {
  2863. if (!isset($DataSummary[$key2]))
  2864. $DataSummary[$key2] = 1;
  2865. else
  2866. $DataSummary[$key2]++;
  2867. }
  2868. }
  2869. if ( max($DataSummary) == 0 )
  2870. $this->Errors[] = "[Warning] ".$FunctionName." - No data set.";
  2871. foreach($DataSummary as $key => $Value)
  2872. {
  2873. if ($Value < max($DataSummary))
  2874. {
  2875. $this->Errors[] = "[Warning] ".$FunctionName." - Missing data in serie ".$key.".";
  2876. }
  2877. }
  2878. }
  2879. /* Print all error messages on the CLI or graphically */
  2880. function printErrors($Mode="CLI")
  2881. {
  2882. if (count($this->Errors) == 0)
  2883. return(0);
  2884. if ( $Mode == "CLI" )
  2885. {
  2886. foreach($this->Errors as $key => $Value)
  2887. echo $Value."\r\n";
  2888. }
  2889. elseif ( $Mode == "GD" )
  2890. {
  2891. $this->setLineStyle($Width=1);
  2892. $MaxWidth = 0;
  2893. foreach($this->Errors as $key => $Value)
  2894. {
  2895. $Position = imageftbbox($this->ErrorFontSize,0,$this->ErrorFontName,$Value);
  2896. $TextWidth = $Position[2]-$Position[0];
  2897. if ( $TextWidth > $MaxWidth ) { $MaxWidth = $TextWidth; }
  2898. }
  2899. $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);
  2900. $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);
  2901. $C_TextColor = $this->AllocateColor($this->Picture,133,85,85);
  2902. $YPos = $this->YSize - (18 + (count($this->Errors)-1) * ($this->ErrorFontSize + 4));
  2903. foreach($this->Errors as $key => $Value)
  2904. {
  2905. imagettftext($this->Picture,$this->ErrorFontSize,0,$this->XSize-($MaxWidth+15),$YPos,$C_TextColor,$this->ErrorFontName,$Value);
  2906. $YPos = $YPos + ($this->ErrorFontSize + 4);
  2907. }
  2908. }
  2909. }
  2910. /* Activate the image map creation process */
  2911. function setImageMap($Mode=TRUE,$GraphID="MyGraph")
  2912. {
  2913. $this->BuildMap = $Mode;
  2914. $this->MapID = $GraphID;
  2915. }
  2916. /* Add a box into the image map */
  2917. function addToImageMap($X1,$Y1,$X2,$Y2,$SerieName,$Value,$CallerFunction)
  2918. {
  2919. if ( $this->MapFunction == NULL || $this->MapFunction == $CallerFunction )
  2920. {
  2921. $this->ImageMap[] = round($X1).",".round($Y1).",".round($X2).",".round($Y2).",".$SerieName.",".$Value;
  2922. $this->MapFunction = $CallerFunction;
  2923. }
  2924. }
  2925. /* Load and cleanup the image map from disk */
  2926. function getImageMap($MapName,$Flush=TRUE)
  2927. {
  2928. /* Strip HTML query strings */
  2929. $Values = $this->tmpFolder.$MapName;
  2930. $Value = split("\?",$Values);
  2931. $FileName = $Value[0];
  2932. if ( file_exists($FileName) )
  2933. {
  2934. $Handle = fopen($FileName, "r");
  2935. $MapContent = fread($Handle, filesize($FileName));
  2936. fclose($Handle);
  2937. echo $MapContent;
  2938. if ( $Flush )
  2939. unlink($FileName);
  2940. exit();
  2941. }
  2942. else
  2943. {
  2944. header("HTTP/1.0 404 Not Found");
  2945. exit();
  2946. }
  2947. }
  2948. /* Save the image map to the disk */
  2949. function SaveImageMap()
  2950. {
  2951. if ( !$this->BuildMap ) { return(-1); }
  2952. if ( $this->ImageMap == NULL )
  2953. {
  2954. $this->Errors[] = "[Warning] SaveImageMap - Image map is empty.";
  2955. return(-1);
  2956. }
  2957. $Handle = fopen($this->tmpFolder.$this->MapID, 'w');
  2958. if ( !$Handle )
  2959. {
  2960. $this->Errors[] = "[Warning] SaveImageMap - Cannot save the image map.";
  2961. return(-1);
  2962. }
  2963. else
  2964. {
  2965. foreach($this->ImageMap as $Key => $Value)
  2966. fwrite($Handle, htmlentities($Value)."\r");
  2967. }
  2968. fclose ($Handle);
  2969. }
  2970. /* Convert seconds to a time format string */
  2971. function ToTime($Value)
  2972. {
  2973. $Hour = floor($Value/3600);
  2974. $Minute = floor(($Value - $Hour*3600)/60);
  2975. $Second = floor($Value - $Hour*3600 - $Minute*60);
  2976. if (strlen($Hour) == 1 ) { $Hour = "0".$Hour; }
  2977. if (strlen($Minute) == 1 ) { $Minute = "0".$Minute; }
  2978. if (strlen($Second) == 1 ) { $Second = "0".$Second; }
  2979. return($Hour.":".$Minute.":".$Second);
  2980. }
  2981. /* Convert to metric system */
  2982. function ToMetric($Value)
  2983. {
  2984. $Go = floor($Value/1000000000);
  2985. $Mo = floor(($Value - $Go*1000000000)/1000000);
  2986. $Ko = floor(($Value - $Go*1000000000 - $Mo*1000000)/1000);
  2987. $o = floor($Value - $Go*1000000000 - $Mo*1000000 - $Ko*1000);
  2988. if ($Go != 0) { return($Go.".".$Mo."g"); }
  2989. if ($Mo != 0) { return($Mo.".".$ko."m"); }
  2990. if ($Ko != 0) { return($Ko.".".$o)."k"; }
  2991. return($o);
  2992. }
  2993. /* Convert to curency */
  2994. function ToCurrency($Value)
  2995. {
  2996. $Go = floor($Value/1000000000);
  2997. $Mo = floor(($Value - $Go*1000000000)/1000000);
  2998. $Ko = floor(($Value - $Go*1000000000 - $Mo*1000000)/1000);
  2999. $o = floor($Value - $Go*1000000000 - $Mo*1000000 - $Ko*1000);
  3000. if ( strlen($o) == 1 ) { $o = "00".$o; }
  3001. if ( strlen($o) == 2 ) { $o = "0".$o; }
  3002. $ResultString = $o;
  3003. if ( $Ko != 0 ) { $ResultString = $Ko.".".$ResultString; }
  3004. if ( $Mo != 0 ) { $ResultString = $Mo.".".$ResultString; }
  3005. if ( $Go != 0 ) { $ResultString = $Go.".".$ResultString; }
  3006. $ResultString = $this->Currency.$ResultString;
  3007. return($ResultString);
  3008. }
  3009. /* Set date format for axis labels */
  3010. function setDateFormat($Format)
  3011. {
  3012. $this->DateFormat = $Format;
  3013. }
  3014. /* Convert TS to a date format string */
  3015. function ToDate($Value)
  3016. {
  3017. return(date($this->DateFormat,$Value));
  3018. }
  3019. /* Check if a number is a full integer (for scaling) */
  3020. function isRealInt($Value)
  3021. {
  3022. if ($Value == floor($Value))
  3023. return(TRUE);
  3024. return(FALSE);
  3025. }
  3026. /**
  3027. * Return a new pChart object fixing its height by legend rotations
  3028. * Must be set fonts before call this method
  3029. * @param array $data
  3030. * @param array $dataDescription
  3031. * @param float $angle
  3032. * @return pChart
  3033. */
  3034. function fixHeightByRotation ($data, $dataDescription, $angle)
  3035. {
  3036. $maxTextHeight = 0;
  3037. foreach ($data as $key => $values) {
  3038. // Get legend value
  3039. $value = $data[$key][$dataDescription["Position"]];
  3040. if ($dataDescription["Format"]["X"] == "number") {
  3041. $value = $value.$dataDescription["Unit"]["X"];
  3042. } elseif ($dataDescription["Format"]["X"] == "time") {
  3043. $value = $this->ToTime($value);
  3044. } elseif ($dataDescription["Format"]["X"] == "date") {
  3045. $value = $this->ToDate($value);
  3046. } elseif ($dataDescription["Format"]["X"] == "metric") {
  3047. $value = $this->ToMetric($value);
  3048. } elseif ($dataDescription["Format"]["X"] == "currency") {
  3049. $value = $this->ToCurrency($value);
  3050. }
  3051. // Get positions array from label generated
  3052. $Position = imageftbbox($this->FontSize, $angle, $this->FontName, $value);
  3053. $TextHeight = abs($Position[1]) + abs($Position[3]);
  3054. // Save max height
  3055. if ($maxTextHeight < $TextHeight) {
  3056. $maxTextHeight = $TextHeight;
  3057. }
  3058. }
  3059. $this->YSize += $maxTextHeight;
  3060. $pChart = new pChart($this->XSize, $this->YSize);
  3061. // set font of the axes
  3062. $pChart->setFontProperties($this->FontName, $this->FontSize);
  3063. return $pChart;
  3064. }
  3065. }
  3066. function RaiseFatal($Message)
  3067. {
  3068. echo "[FATAL] ".$Message."\r\n";
  3069. exit();
  3070. }
  3071. ?>