pDraw.class.php 315 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258
  1. <?php
  2. /*
  3. pDraw - class extension with drawing methods
  4. Version : 2.1.4
  5. Made by : Jean-Damien POGOLOTTI
  6. Last Update : 19/01/2014
  7. This file can be distributed under the license you can find at :
  8. http://www.pchart.net/license
  9. You can find the whole class documentation on the pChart web site.
  10. */
  11. define("DIRECTION_VERTICAL" , 690001);
  12. define("DIRECTION_HORIZONTAL" , 690002);
  13. define("SCALE_POS_LEFTRIGHT" , 690101);
  14. define("SCALE_POS_TOPBOTTOM" , 690102);
  15. define("SCALE_MODE_FLOATING" , 690201);
  16. define("SCALE_MODE_START0" , 690202);
  17. define("SCALE_MODE_ADDALL" , 690203);
  18. define("SCALE_MODE_ADDALL_START0" , 690204);
  19. define("SCALE_MODE_MANUAL" , 690205);
  20. define("SCALE_SKIP_NONE" , 690301);
  21. define("SCALE_SKIP_SAME" , 690302);
  22. define("SCALE_SKIP_NUMBERS" , 690303);
  23. define("TEXT_ALIGN_TOPLEFT" , 690401);
  24. define("TEXT_ALIGN_TOPMIDDLE" , 690402);
  25. define("TEXT_ALIGN_TOPRIGHT" , 690403);
  26. define("TEXT_ALIGN_MIDDLELEFT" , 690404);
  27. define("TEXT_ALIGN_MIDDLEMIDDLE" , 690405);
  28. define("TEXT_ALIGN_MIDDLERIGHT" , 690406);
  29. define("TEXT_ALIGN_BOTTOMLEFT" , 690407);
  30. define("TEXT_ALIGN_BOTTOMMIDDLE" , 690408);
  31. define("TEXT_ALIGN_BOTTOMRIGHT" , 690409);
  32. define("POSITION_TOP" , 690501);
  33. define("POSITION_BOTTOM" , 690502);
  34. define("LABEL_POS_LEFT" , 690601);
  35. define("LABEL_POS_CENTER" , 690602);
  36. define("LABEL_POS_RIGHT" , 690603);
  37. define("LABEL_POS_TOP" , 690604);
  38. define("LABEL_POS_BOTTOM" , 690605);
  39. define("LABEL_POS_INSIDE" , 690606);
  40. define("LABEL_POS_OUTSIDE" , 690607);
  41. define("ORIENTATION_HORIZONTAL" , 690701);
  42. define("ORIENTATION_VERTICAL" , 690702);
  43. define("ORIENTATION_AUTO" , 690703);
  44. define("LEGEND_NOBORDER" , 690800);
  45. define("LEGEND_BOX" , 690801);
  46. define("LEGEND_ROUND" , 690802);
  47. define("LEGEND_VERTICAL" , 690901);
  48. define("LEGEND_HORIZONTAL" , 690902);
  49. define("LEGEND_FAMILY_BOX" , 691051);
  50. define("LEGEND_FAMILY_CIRCLE" , 691052);
  51. define("LEGEND_FAMILY_LINE" , 691053);
  52. define("DISPLAY_AUTO" , 691001);
  53. define("DISPLAY_MANUAL" , 691002);
  54. define("LABELING_ALL" , 691011);
  55. define("LABELING_DIFFERENT" , 691012);
  56. define("BOUND_MIN" , 691021);
  57. define("BOUND_MAX" , 691022);
  58. define("BOUND_BOTH" , 691023);
  59. define("BOUND_LABEL_POS_TOP" , 691031);
  60. define("BOUND_LABEL_POS_BOTTOM" , 691032);
  61. define("BOUND_LABEL_POS_AUTO" , 691033);
  62. define("CAPTION_LEFT_TOP" , 691041);
  63. define("CAPTION_RIGHT_BOTTOM" , 691042);
  64. define("GRADIENT_SIMPLE" , 691051);
  65. define("GRADIENT_EFFECT_CAN" , 691052);
  66. define("LABEL_TITLE_NOBACKGROUND" , 691061);
  67. define("LABEL_TITLE_BACKGROUND" , 691062);
  68. define("LABEL_POINT_NONE" , 691071);
  69. define("LABEL_POINT_CIRCLE" , 691072);
  70. define("LABEL_POINT_BOX" , 691073);
  71. define("ZONE_NAME_ANGLE_AUTO" , 691081);
  72. define("PI" , 3.14159265);
  73. define("ALL" , 69);
  74. define("NONE" , 31);
  75. define("AUTO" , 690000);
  76. define("OUT_OF_SIGHT" , -10000000000000);
  77. class pDraw
  78. {
  79. /* Returns the number of drawable series */
  80. function countDrawableSeries()
  81. {
  82. $Results = 0;
  83. $Data = $this->DataSet->getData();
  84. foreach($Data["Series"] as $SerieName => $Serie)
  85. { if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] ) { $Results++; } }
  86. return($Results);
  87. }
  88. /* Fix box coordinates */
  89. function fixBoxCoordinates($Xa,$Ya,$Xb,$Yb)
  90. {
  91. $X1 = min($Xa,$Xb); $Y1 = min($Ya,$Yb);
  92. $X2 = max($Xa,$Xb); $Y2 = max($Ya,$Yb);
  93. return(array($X1,$Y1,$X2,$Y2));
  94. }
  95. /* Draw a polygon */
  96. function drawPolygon($Points,$Format="")
  97. {
  98. $R = isset($Format["R"]) ? $Format["R"] : 0;
  99. $G = isset($Format["G"]) ? $Format["G"] : 0;
  100. $B = isset($Format["B"]) ? $Format["B"] : 0;
  101. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  102. $NoFill = isset($Format["NoFill"]) ? $Format["NoFill"] : FALSE;
  103. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  104. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  105. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  106. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  107. $BorderAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $Alpha / 2;
  108. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  109. $SkipX = isset($Format["SkipX"]) ? $Format["SkipX"] : OUT_OF_SIGHT;
  110. $SkipY = isset($Format["SkipY"]) ? $Format["SkipY"] : OUT_OF_SIGHT;
  111. /* Calling the ImageFilledPolygon() function over the $Points array will round it */
  112. $Backup = $Points;
  113. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  114. if ( $SkipX != OUT_OF_SIGHT ) { $SkipX = floor($SkipX); }
  115. if ( $SkipY != OUT_OF_SIGHT ) { $SkipY = floor($SkipY); }
  116. $RestoreShadow = $this->Shadow;
  117. if ( !$NoFill )
  118. {
  119. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  120. {
  121. $this->Shadow = FALSE;
  122. for($i=0;$i<=count($Points)-1;$i=$i+2)
  123. { $Shadow[] = $Points[$i] + $this->ShadowX; $Shadow[] = $Points[$i+1] + $this->ShadowY; }
  124. $this->drawPolygon($Shadow,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"NoBorder"=>TRUE));
  125. }
  126. $FillColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  127. if ( count($Points) >= 6 )
  128. { ImageFilledPolygon($this->Picture,$Points,count($Points)/2,$FillColor); }
  129. }
  130. if ( !$NoBorder )
  131. {
  132. $Points = $Backup;
  133. if ( $NoFill )
  134. $BorderSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  135. else
  136. $BorderSettings = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha);
  137. for($i=0;$i<=count($Points)-1;$i=$i+2)
  138. {
  139. if ( isset($Points[$i+2]) )
  140. {
  141. if ( !($Points[$i] == $Points[$i+2] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[$i+3] && $Points[$i+1] == $SkipY ) )
  142. $this->drawLine($Points[$i],$Points[$i+1],$Points[$i+2],$Points[$i+3],$BorderSettings);
  143. }
  144. else
  145. {
  146. if ( !($Points[$i] == $Points[0] && $Points[$i] == $SkipX ) && !($Points[$i+1] == $Points[1] && $Points[$i+1] == $SkipY ) )
  147. $this->drawLine($Points[$i],$Points[$i+1],$Points[0],$Points[1],$BorderSettings);
  148. }
  149. }
  150. }
  151. $this->Shadow = $RestoreShadow;
  152. }
  153. /* Apply AALias correction to the rounded box boundaries */
  154. function offsetCorrection($Value,$Mode)
  155. {
  156. $Value = round($Value,1);
  157. if ( $Value == 0 && $Mode == 1 ) { return(.9); }
  158. if ( $Value == 0 ) { return(0); }
  159. if ( $Mode == 1)
  160. { if ( $Value == 1 ) { return(.9); }; if ( $Value == .1 ) { return(.9); }; if ( $Value == .2 ) { return(.8); }; if ( $Value == .3 ) { return(.8); }; if ( $Value == .4 ) { return(.7); }; if ( $Value == .5 ) { return(.5); }; if ( $Value == .6 ) { return(.8); }; if ( $Value == .7 ) { return(.7); }; if ( $Value == .8 ) { return(.6); }; if ( $Value == .9 ) { return(.9); }; }
  161. if ( $Mode == 2)
  162. { if ( $Value == 1 ) { return(.9); }; if ( $Value == .1 ) { return(.1); }; if ( $Value == .2 ) { return(.2); }; if ( $Value == .3 ) { return(.3); }; if ( $Value == .4 ) { return(.4); }; if ( $Value == .5 ) { return(.5); }; if ( $Value == .6 ) { return(.8); }; if ( $Value == .7 ) { return(.7); }; if ( $Value == .8 ) { return(.8); }; if ( $Value == .9 ) { return(.9); }; }
  163. if ( $Mode == 3)
  164. { if ( $Value == 1 ) { return(.1); }; if ( $Value == .1 ) { return(.1); }; if ( $Value == .2 ) { return(.2); }; if ( $Value == .3 ) { return(.3); }; if ( $Value == .4 ) { return(.4); }; if ( $Value == .5 ) { return(.9); }; if ( $Value == .6 ) { return(.6); }; if ( $Value == .7 ) { return(.7); }; if ( $Value == .8 ) { return(.4); }; if ( $Value == .9 ) { return(.5); }; }
  165. if ( $Mode == 4)
  166. { if ( $Value == 1 ) { return(-1); }; if ( $Value == .1 ) { return(.1); }; if ( $Value == .2 ) { return(.2); }; if ( $Value == .3 ) { return(.3); }; if ( $Value == .4 ) { return(.1); }; if ( $Value == .5 ) { return(-.1); }; if ( $Value == .6 ) { return(.8); }; if ( $Value == .7 ) { return(.1); }; if ( $Value == .8 ) { return(.1); }; if ( $Value == .9 ) { return(.1); }; }
  167. }
  168. /* Draw a rectangle with rounded corners */
  169. function drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  170. {
  171. $R = isset($Format["R"]) ? $Format["R"] : 0;
  172. $G = isset($Format["G"]) ? $Format["G"] : 0;
  173. $B = isset($Format["B"]) ? $Format["B"] : 0;
  174. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  175. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  176. if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1))/2); }
  177. if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1))/2); }
  178. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);
  179. if ( $Radius <= 0 ) { $this->drawRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }
  180. if ( $this->Antialias )
  181. {
  182. $this->drawLine($X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
  183. $this->drawLine($X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
  184. $this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
  185. $this->drawLine($X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
  186. }
  187. else
  188. {
  189. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  190. imageline($this->Picture,$X1+$Radius,$Y1,$X2-$Radius,$Y1,$Color);
  191. imageline($this->Picture,$X2,$Y1+$Radius,$X2,$Y2-$Radius,$Color);
  192. imageline($this->Picture,$X2-$Radius,$Y2,$X1+$Radius,$Y2,$Color);
  193. imageline($this->Picture,$X1,$Y1+$Radius,$X1,$Y2-$Radius,$Color);
  194. }
  195. $Step = 360 / (2 * PI * $Radius);
  196. for($i=0;$i<=90;$i=$i+$Step)
  197. {
  198. $X = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  199. $Y = sin(($i+180)*PI/180) * $Radius + $Y1 + $Radius;
  200. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  201. $X = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  202. $Y = sin(($i+90)*PI/180) * $Radius + $Y2 - $Radius;
  203. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  204. $X = cos($i*PI/180) * $Radius + $X2 - $Radius;
  205. $Y = sin($i*PI/180) * $Radius + $Y2 - $Radius;
  206. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  207. $X = cos(($i+270)*PI/180) * $Radius + $X2 - $Radius;
  208. $Y = sin(($i+270)*PI/180) * $Radius + $Y1 + $Radius;
  209. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  210. }
  211. }
  212. /* Draw a rectangle with rounded corners */
  213. function drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  214. {
  215. $R = isset($Format["R"]) ? $Format["R"] : 0;
  216. $G = isset($Format["G"]) ? $Format["G"] : 0;
  217. $B = isset($Format["B"]) ? $Format["B"] : 0;
  218. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  219. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  220. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  221. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  222. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  223. /* Temporary fix for AA issue */
  224. $Y1 = floor($Y1); $Y2 = floor($Y2); $X1 = floor($X1); $X2 = floor($X2);
  225. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  226. if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }
  227. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  228. if ( $X2 - $X1 < $Radius*2 ) { $Radius = floor((($X2-$X1))/4); }
  229. if ( $Y2 - $Y1 < $Radius*2 ) { $Radius = floor((($Y2-$Y1))/4); }
  230. $RestoreShadow = $this->Shadow;
  231. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  232. {
  233. $this->Shadow = FALSE;
  234. $this->drawRoundedFilledRectangle($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  235. }
  236. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE);
  237. if ( $Radius <= 0 ) { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color); return(0); }
  238. $YTop = $Y1+$Radius;
  239. $YBottom = $Y2-$Radius;
  240. $Step = 360 / (2 * PI * $Radius);
  241. $Positions = ""; $Radius--; $MinY = ""; $MaxY = "";
  242. for($i=0;$i<=90;$i=$i+$Step)
  243. {
  244. $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  245. $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
  246. $Yp = floor(sin(($i+180)*PI/180) * $Radius + $YTop);
  247. if ( $MinY == "" || $Yp > $MinY ) { $MinY = $Yp; }
  248. if ( $Xp1 <= floor($X1) ) { $Xp1++; }
  249. if ( $Xp2 >= floor($X2) ) { $Xp2--; }
  250. $Xp1++;
  251. if ( !isset($Positions[$Yp]) )
  252. { $Positions[$Yp]["X1"] = $Xp1; $Positions[$Yp]["X2"] = $Xp2; }
  253. else
  254. { $Positions[$Yp]["X1"] = ($Positions[$Yp]["X1"]+$Xp1)/2; $Positions[$Yp]["X2"] = ($Positions[$Yp]["X2"]+$Xp2)/2; }
  255. $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  256. $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
  257. $Yp = floor(sin(($i+90)*PI/180) * $Radius + $YBottom);
  258. if ( $MaxY == "" || $Yp < $MaxY ) { $MaxY = $Yp; }
  259. if ( $Xp1 <= floor($X1) ) { $Xp1++; }
  260. if ( $Xp2 >= floor($X2) ) { $Xp2--; }
  261. $Xp1++;
  262. if ( !isset($Positions[$Yp]) )
  263. { $Positions[$Yp]["X1"] = $Xp1; $Positions[$Yp]["X2"] = $Xp2; }
  264. else
  265. { $Positions[$Yp]["X1"] = ($Positions[$Yp]["X1"]+$Xp1)/2; $Positions[$Yp]["X2"] = ($Positions[$Yp]["X2"]+$Xp2)/2; }
  266. }
  267. $ManualColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  268. foreach($Positions as $Yp => $Bounds)
  269. {
  270. $X1 = $Bounds["X1"]; $X1Dec = $this->getFirstDecimal($X1); if ( $X1Dec != 0 ) { $X1 = floor($X1)+1; }
  271. $X2 = $Bounds["X2"]; $X2Dec = $this->getFirstDecimal($X2); if ( $X2Dec != 0 ) { $X2 = floor($X2)-1; }
  272. imageline($this->Picture,$X1,$Yp,$X2,$Yp,$ManualColor);
  273. }
  274. $this->drawFilledRectangle($X1,$MinY+1,floor($X2),$MaxY-1,$Color);
  275. $Radius++;
  276. $this->drawRoundedRectangle($X1,$Y1,$X2+1,$Y2-1,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  277. $this->Shadow = $RestoreShadow;
  278. }
  279. /* Draw a rectangle with rounded corners */
  280. function drawRoundedFilledRectangle_deprecated($X1,$Y1,$X2,$Y2,$Radius,$Format="")
  281. {
  282. $R = isset($Format["R"]) ? $Format["R"] : 0;
  283. $G = isset($Format["G"]) ? $Format["G"] : 0;
  284. $B = isset($Format["B"]) ? $Format["B"] : 0;
  285. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  286. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  287. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  288. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  289. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  290. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  291. if ( $BorderR == -1 ) { $BorderR = $R; $BorderG = $G; $BorderB = $B; }
  292. list($X1,$Y1,$X2,$Y2) = $this->fixBoxCoordinates($X1,$Y1,$X2,$Y2);
  293. if ( $X2 - $X1 < $Radius ) { $Radius = floor((($X2-$X1)+2)/2); }
  294. if ( $Y2 - $Y1 < $Radius ) { $Radius = floor((($Y2-$Y1)+2)/2); }
  295. $RestoreShadow = $this->Shadow;
  296. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  297. {
  298. $this->Shadow = FALSE;
  299. $this->drawRoundedFilledRectangle($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  300. }
  301. if ( $this->getFirstDecimal($X2) >= 5 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  302. if ( $this->getFirstDecimal($X1) <= 5 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  303. if ( !$this->Antialias ) { $XOffset1 = 1; $XOffset2 = 1; }
  304. $YTop = floor($Y1+$Radius);
  305. $YBottom = floor($Y2-$Radius);
  306. $this->drawFilledRectangle($X1-$XOffset1,$YTop,$X2+$XOffset2,$YBottom,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"NoBorder"=>TRUE));
  307. $Step = 360 / (2 * PI * $Radius);
  308. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  309. $Color2 = $this->allocateColor($this->Picture,255,0,0,$Alpha);
  310. $Drawn = "";
  311. if ( $Alpha < 100 ) { $Drawn[$YTop] = FALSE; }
  312. if ( $Alpha < 100 ) { $Drawn[$YBottom] = TRUE; }
  313. for($i=0;$i<=90;$i=$i+$Step)
  314. {
  315. $Xp1 = cos(($i+180)*PI/180) * $Radius + $X1 + $Radius;
  316. $Xp2 = cos(((90-$i)+270)*PI/180) * $Radius + $X2 - $Radius;
  317. $Yp = sin(($i+180)*PI/180) * $Radius + $YTop;
  318. if ( $this->getFirstDecimal($Xp1) > 5 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  319. if ( $this->getFirstDecimal($Xp2) > 5 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  320. if ( $this->getFirstDecimal($Yp) > 5 ) { $YOffset = 1; } else { $YOffset = 0; }
  321. if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
  322. imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);
  323. $Drawn[$Yp+$YOffset] = $Xp2;
  324. $Xp1 = cos(($i+90)*PI/180) * $Radius + $X1 + $Radius;
  325. $Xp2 = cos((90-$i)*PI/180) * $Radius + $X2 - $Radius;
  326. $Yp = sin(($i+90)*PI/180) * $Radius + $YBottom;
  327. if ( $this->getFirstDecimal($Xp1) > 7 ) { $XOffset1 = 1; } else { $XOffset1 = 0; }
  328. if ( $this->getFirstDecimal($Xp2) > 7 ) { $XOffset2 = 1; } else { $XOffset2 = 0; }
  329. if ( $this->getFirstDecimal($Yp) > 5 ) { $YOffset = 1; } else { $YOffset = 0; }
  330. if ( !isset($Drawn[$Yp+$YOffset]) || $Alpha == 100 )
  331. imageline($this->Picture,$Xp1+$XOffset1,$Yp+$YOffset,$Xp2+$XOffset2,$Yp+$YOffset,$Color);
  332. $Drawn[$Yp+$YOffset] = $Xp2;
  333. }
  334. $this->drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  335. $this->Shadow = $RestoreShadow;
  336. }
  337. /* Draw a rectangle */
  338. function drawRectangle($X1,$Y1,$X2,$Y2,$Format="")
  339. {
  340. $R = isset($Format["R"]) ? $Format["R"] : 0;
  341. $G = isset($Format["G"]) ? $Format["G"] : 0;
  342. $B = isset($Format["B"]) ? $Format["B"] : 0;
  343. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  344. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  345. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;
  346. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  347. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  348. if ( $this->Antialias )
  349. {
  350. if ( $NoAngle )
  351. {
  352. $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  353. $this->drawLine($X2,$Y1+1,$X2,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  354. $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  355. $this->drawLine($X1,$Y1+1,$X1,$Y2-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  356. }
  357. else
  358. {
  359. $this->drawLine($X1+1,$Y1,$X2-1,$Y1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  360. $this->drawLine($X2,$Y1,$X2,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  361. $this->drawLine($X2-1,$Y2,$X1+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  362. $this->drawLine($X1,$Y1,$X1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  363. }
  364. }
  365. else
  366. {
  367. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  368. imagerectangle($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
  369. }
  370. }
  371. /* Draw a filled rectangle */
  372. function drawFilledRectangle($X1,$Y1,$X2,$Y2,$Format="")
  373. {
  374. $R = isset($Format["R"]) ? $Format["R"] : 0;
  375. $G = isset($Format["G"]) ? $Format["G"] : 0;
  376. $B = isset($Format["B"]) ? $Format["B"] : 0;
  377. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  378. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  379. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  380. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  381. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
  382. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  383. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  384. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : NULL;
  385. $Dash = isset($Format["Dash"]) ? $Format["Dash"] : FALSE;
  386. $DashStep = isset($Format["DashStep"]) ? $Format["DashStep"] : 4;
  387. $DashR = isset($Format["DashR"]) ? $Format["DashR"] : 0;
  388. $DashG = isset($Format["DashG"]) ? $Format["DashG"] : 0;
  389. $DashB = isset($Format["DashB"]) ? $Format["DashB"] : 0;
  390. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  391. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  392. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  393. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  394. $RestoreShadow = $this->Shadow;
  395. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  396. {
  397. $this->Shadow = FALSE;
  398. $this->drawFilledRectangle($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks,"NoAngle"=>$NoAngle));
  399. }
  400. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  401. if ( $NoAngle )
  402. {
  403. imagefilledrectangle($this->Picture,ceil($X1)+1,ceil($Y1),floor($X2)-1,floor($Y2),$Color);
  404. imageline($this->Picture,ceil($X1),ceil($Y1)+1,ceil($X1),floor($Y2)-1,$Color);
  405. imageline($this->Picture,floor($X2),ceil($Y1)+1,floor($X2),floor($Y2)-1,$Color);
  406. }
  407. else
  408. imagefilledrectangle($this->Picture,ceil($X1),ceil($Y1),floor($X2),floor($Y2),$Color);
  409. if ( $Dash )
  410. {
  411. if ( $BorderR != -1 ) { $iX1=$X1+1; $iY1=$Y1+1; $iX2=$X2-1; $iY2=$Y2-1; } else { $iX1=$X1; $iY1=$Y1; $iX2=$X2; $iY2=$Y2; }
  412. $Color = $this->allocateColor($this->Picture,$DashR,$DashG,$DashB,$Alpha);
  413. $Y=$iY1-$DashStep;
  414. for($X=$iX1; $X<=$iX2+($iY2-$iY1); $X=$X+$DashStep)
  415. {
  416. $Y=$Y+$DashStep;
  417. if ( $X > $iX2 ) { $Xa = $X-($X-$iX2); $Ya = $iY1+($X-$iX2); } else { $Xa = $X; $Ya = $iY1; }
  418. if ( $Y > $iY2 ) { $Xb = $iX1+($Y-$iY2); $Yb = $Y-($Y-$iY2); } else { $Xb = $iX1; $Yb = $Y; }
  419. imageline($this->Picture,$Xa,$Ya,$Xb,$Yb,$Color);
  420. }
  421. }
  422. if ( $this->Antialias && !$NoBorder )
  423. {
  424. if ( $X1 < ceil($X1) )
  425. {
  426. $AlphaA = $Alpha * (ceil($X1) - $X1);
  427. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  428. imageline($this->Picture,ceil($X1)-1,ceil($Y1),ceil($X1)-1,floor($Y2),$Color);
  429. }
  430. if ( $Y1 < ceil($Y1) )
  431. {
  432. $AlphaA = $Alpha * (ceil($Y1) - $Y1);
  433. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  434. imageline($this->Picture,ceil($X1),ceil($Y1)-1,floor($X2),ceil($Y1)-1,$Color);
  435. }
  436. if ( $X2 > floor($X2) )
  437. {
  438. $AlphaA = $Alpha * (.5-($X2 - floor($X2)));
  439. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  440. imageline($this->Picture,floor($X2)+1,ceil($Y1),floor($X2)+1,floor($Y2),$Color);
  441. }
  442. if ( $Y2 > floor($Y2) )
  443. {
  444. $AlphaA = $Alpha * (.5-($Y2 - floor($Y2)));
  445. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$AlphaA);
  446. imageline($this->Picture,ceil($X1),floor($Y2)+1,floor($X2),floor($Y2)+1,$Color);
  447. }
  448. }
  449. if ( $BorderR != -1 )
  450. $this->drawRectangle($X1,$Y1,$X2,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks,"NoAngle"=>$NoAngle));
  451. $this->Shadow = $RestoreShadow;
  452. }
  453. /* Draw a rectangular marker of the specified size */
  454. function drawRectangleMarker($X,$Y,$Format="")
  455. {
  456. $Size = isset($Format["Size"]) ? $Format["Size"] : 4;
  457. $HalfSize = floor($Size/2);
  458. $this->drawFilledRectangle($X-$HalfSize,$Y-$HalfSize,$X+$HalfSize,$Y+$HalfSize,$Format);
  459. }
  460. /* Drawn a spline based on the bezier function */
  461. function drawSpline($Coordinates,$Format="")
  462. {
  463. $R = isset($Format["R"]) ? $Format["R"] : 0;
  464. $G = isset($Format["G"]) ? $Format["G"] : 0;
  465. $B = isset($Format["B"]) ? $Format["B"] : 0;
  466. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  467. $Force = isset($Format["Force"]) ? $Format["Force"] : 30;
  468. $Forces = isset($Format["Forces"]) ? $Format["Forces"] : NULL;
  469. $ShowC = isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
  470. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  471. $PathOnly = isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
  472. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  473. $Cpt = NULL; $Mode = NULL; $Result = "";
  474. for($i=1;$i<=count($Coordinates)-1;$i++)
  475. {
  476. $X1 = $Coordinates[$i-1][0]; $Y1 = $Coordinates[$i-1][1];
  477. $X2 = $Coordinates[$i][0]; $Y2 = $Coordinates[$i][1];
  478. if ( $Forces != NULL ) { $Force = $Forces[$i]; }
  479. /* First segment */
  480. if ( $i == 1 )
  481. { $Xv1 = $X1; $Yv1 = $Y1; }
  482. else
  483. {
  484. $Angle1 = $this->getAngle($XLast,$YLast,$X1,$Y1);
  485. $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
  486. $XOff = cos($Angle2 * PI / 180) * $Force + $X1;
  487. $YOff = sin($Angle2 * PI / 180) * $Force + $Y1;
  488. $Xv1 = cos($Angle1 * PI / 180) * $Force + $XOff;
  489. $Yv1 = sin($Angle1 * PI / 180) * $Force + $YOff;
  490. }
  491. /* Last segment */
  492. if ( $i == count($Coordinates)-1 )
  493. { $Xv2 = $X2; $Yv2 = $Y2; }
  494. else
  495. {
  496. $Angle1 = $this->getAngle($X2,$Y2,$Coordinates[$i+1][0],$Coordinates[$i+1][1]);
  497. $Angle2 = $this->getAngle($X1,$Y1,$X2,$Y2);
  498. $XOff = cos(($Angle2+180) * PI / 180) * $Force + $X2;
  499. $YOff = sin(($Angle2+180) * PI / 180) * $Force + $Y2;
  500. $Xv2 = cos(($Angle1+180) * PI / 180) * $Force + $XOff;
  501. $Yv2 = sin(($Angle1+180) * PI / 180) * $Force + $YOff;
  502. }
  503. $Path = $this->drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format);
  504. if ($PathOnly) { $Result[] = $Path; }
  505. $XLast = $X1; $YLast = $Y1;
  506. }
  507. return($Result);
  508. }
  509. /* Draw a bezier curve with two controls points */
  510. function drawBezier($X1,$Y1,$X2,$Y2,$Xv1,$Yv1,$Xv2,$Yv2,$Format="")
  511. {
  512. $R = isset($Format["R"]) ? $Format["R"] : 0;
  513. $G = isset($Format["G"]) ? $Format["G"] : 0;
  514. $B = isset($Format["B"]) ? $Format["B"] : 0;
  515. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  516. $ShowC = isset($Format["ShowControl"]) ? $Format["ShowControl"] : FALSE;
  517. $Segments = isset($Format["Segments"]) ? $Format["Segments"] : NULL;
  518. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  519. $NoDraw = isset($Format["NoDraw"]) ? $Format["NoDraw"] : FALSE;
  520. $PathOnly = isset($Format["PathOnly"]) ? $Format["PathOnly"] : FALSE;
  521. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  522. $DrawArrow = isset($Format["DrawArrow"]) ? $Format["DrawArrow"] : FALSE;
  523. $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 10;
  524. $ArrowRatio = isset($Format["ArrowRatio"]) ? $Format["ArrowRatio"] : .5;
  525. $ArrowTwoHeads = isset($Format["ArrowTwoHeads"]) ? $Format["ArrowTwoHeads"] : FALSE;
  526. if ( $Segments == NULL )
  527. {
  528. $Length = $this->getLength($X1,$Y1,$X2,$Y2);
  529. $Precision = ($Length*125)/1000;
  530. }
  531. else
  532. $Precision = $Segments;
  533. $P[0]["X"] = $X1; $P[0]["Y"] = $Y1;
  534. $P[1]["X"] = $Xv1; $P[1]["Y"] = $Yv1;
  535. $P[2]["X"] = $Xv2; $P[2]["Y"] = $Yv2;
  536. $P[3]["X"] = $X2; $P[3]["Y"] = $Y2;
  537. /* Compute the bezier points */
  538. $Q = ""; $ID = 0; $Path = "";
  539. for($i=0;$i<=$Precision;$i=$i+1)
  540. {
  541. $u = $i / $Precision;
  542. $C = "";
  543. $C[0] = (1 - $u) * (1 - $u) * (1 - $u);
  544. $C[1] = ($u * 3) * (1 - $u) * (1 - $u);
  545. $C[2] = 3 * $u * $u * (1 - $u);
  546. $C[3] = $u * $u * $u;
  547. for($j=0;$j<=3;$j++)
  548. {
  549. if ( !isset($Q[$ID]) ) { $Q[$ID] = ""; }
  550. if ( !isset($Q[$ID]["X"]) ) { $Q[$ID]["X"] = 0; }
  551. if ( !isset($Q[$ID]["Y"]) ) { $Q[$ID]["Y"] = 0; }
  552. $Q[$ID]["X"] = $Q[$ID]["X"] + $P[$j]["X"] * $C[$j];
  553. $Q[$ID]["Y"] = $Q[$ID]["Y"] + $P[$j]["Y"] * $C[$j];
  554. }
  555. $ID++;
  556. }
  557. $Q[$ID]["X"] = $X2; $Q[$ID]["Y"] = $Y2;
  558. if ( !$NoDraw )
  559. {
  560. /* Display the control points */
  561. if ( $ShowC && !$PathOnly )
  562. {
  563. $Xv1 = floor($Xv1); $Yv1 = floor($Yv1); $Xv2 = floor($Xv2); $Yv2 = floor($Yv2);
  564. $this->drawLine($X1,$Y1,$X2,$Y2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>30));
  565. $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  566. $this->drawRectangleMarker($Xv1,$Yv1,$MyMarkerSettings);
  567. $this->drawText($Xv1+4,$Yv1,"v1");
  568. $MyMarkerSettings = array("R"=>0,"G"=>0,"B"=>255,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  569. $this->drawRectangleMarker($Xv2,$Yv2,$MyMarkerSettings);
  570. $this->drawText($Xv2+4,$Yv2,"v2");
  571. }
  572. /* Draw the bezier */
  573. $LastX = NULL; $LastY = NULL; $Cpt = NULL; $Mode = NULL; $ArrowS = NULL;
  574. foreach ($Q as $Key => $Point)
  575. {
  576. $X = $Point["X"]; $Y = $Point["Y"];
  577. /* Get the first segment */
  578. if ( $ArrowS == NULL && $LastX != NULL && $LastY != NULL )
  579. { $ArrowS["X2"] = $LastX; $ArrowS["Y2"] = $LastY; $ArrowS["X1"] = $X; $ArrowS["Y1"] = $Y; }
  580. if ( $LastX != NULL && $LastY != NULL && !$PathOnly)
  581. list($Cpt,$Mode) = $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Cpt"=>$Cpt,"Mode"=>$Mode,"Weight"=>$Weight));
  582. /* Get the last segment */
  583. $ArrowE["X1"] = $LastX; $ArrowE["Y1"] = $LastY; $ArrowE["X2"] = $X; $ArrowE["Y2"] = $Y;
  584. $LastX = $X; $LastY = $Y;
  585. }
  586. if ( $DrawArrow && !$PathOnly )
  587. {
  588. $ArrowSettings = array("FillR"=>$R,"FillG"=>$G,"FillB"=>$B,"Alpha"=>$Alpha,"Size"=>$ArrowSize,"Ratio"=>$ArrowRatio);
  589. if ( $ArrowTwoHeads )
  590. $this->drawArrow($ArrowS["X1"],$ArrowS["Y1"],$ArrowS["X2"],$ArrowS["Y2"],$ArrowSettings);
  591. $this->drawArrow($ArrowE["X1"],$ArrowE["Y1"],$ArrowE["X2"],$ArrowE["Y2"],$ArrowSettings);
  592. }
  593. }
  594. return($Q);
  595. }
  596. /* Draw a line between two points */
  597. function drawLine($X1,$Y1,$X2,$Y2,$Format="")
  598. {
  599. $R = isset($Format["R"]) ? $Format["R"] : 0;
  600. $G = isset($Format["G"]) ? $Format["G"] : 0;
  601. $B = isset($Format["B"]) ? $Format["B"] : 0;
  602. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  603. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  604. $Cpt = isset($Format["Cpt"]) ? $Format["Cpt"] : 1;
  605. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : 1;
  606. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  607. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  608. if ( $this->Antialias == FALSE && $Ticks == NULL )
  609. {
  610. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  611. {
  612. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  613. imageline($this->Picture,$X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,$ShadowColor);
  614. }
  615. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  616. imageline($this->Picture,$X1,$Y1,$X2,$Y2,$Color);
  617. return(0);
  618. }
  619. $Distance = sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1));
  620. if ( $Distance == 0 ) { return(-1); }
  621. /* Derivative algorithm for overweighted lines, re-route to polygons primitives */
  622. if ( $Weight != NULL )
  623. {
  624. $Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
  625. $PolySettings = array ("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderAlpha"=>$Alpha);
  626. if ( $Ticks == NULL )
  627. {
  628. $Points = "";
  629. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y1;
  630. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X1; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y1;
  631. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Y2;
  632. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $X2; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Y2;
  633. $this->drawPolygon($Points,$PolySettings);
  634. }
  635. else
  636. {
  637. for($i=0;$i<=$Distance;$i=$i+$Ticks*2)
  638. {
  639. $Xa = (($X2-$X1)/$Distance) * $i + $X1; $Ya = (($Y2-$Y1)/$Distance) * $i + $Y1;
  640. $Xb = (($X2-$X1)/$Distance) * ($i+$Ticks) + $X1; $Yb = (($Y2-$Y1)/$Distance) * ($i+$Ticks) + $Y1;
  641. $Points = "";
  642. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Ya;
  643. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xa; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Ya;
  644. $Points[] = cos(deg2rad($Angle+90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle+90)) * $Weight + $Yb;
  645. $Points[] = cos(deg2rad($Angle-90)) * $Weight + $Xb; $Points[] = sin(deg2rad($Angle-90)) * $Weight + $Yb;
  646. $this->drawPolygon($Points,$PolySettings);
  647. }
  648. }
  649. return(1);
  650. }
  651. $XStep = ($X2-$X1) / $Distance;
  652. $YStep = ($Y2-$Y1) / $Distance;
  653. for($i=0;$i<=$Distance;$i++)
  654. {
  655. $X = $i * $XStep + $X1;
  656. $Y = $i * $YStep + $Y1;
  657. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  658. if ( $Threshold != NULL )
  659. {
  660. foreach($Threshold as $Key => $Parameters)
  661. {
  662. if ( $Y <= $Parameters["MinX"] && $Y >= $Parameters["MaxX"])
  663. {
  664. if ( isset($Parameters["R"]) ) { $RT = $Parameters["R"]; } else { $RT = 0; }
  665. if ( isset($Parameters["G"]) ) { $GT = $Parameters["G"]; } else { $GT = 0; }
  666. if ( isset($Parameters["B"]) ) { $BT = $Parameters["B"]; } else { $BT = 0; }
  667. if ( isset($Parameters["Alpha"]) ) { $AlphaT = $Parameters["Alpha"]; } else { $AlphaT = 0; }
  668. $Color = array("R"=>$RT,"G"=>$GT,"B"=>$BT,"Alpha"=>$AlphaT);
  669. }
  670. }
  671. }
  672. if ( $Ticks != NULL )
  673. {
  674. if ( $Cpt % $Ticks == 0 )
  675. { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }
  676. if ( $Mode == 1 )
  677. $this->drawAntialiasPixel($X,$Y,$Color);
  678. $Cpt++;
  679. }
  680. else
  681. $this->drawAntialiasPixel($X,$Y,$Color);
  682. }
  683. return(array($Cpt,$Mode));
  684. }
  685. /* Draw a circle */
  686. function drawCircle($Xc,$Yc,$Height,$Width,$Format="")
  687. {
  688. $R = isset($Format["R"]) ? $Format["R"] : 0;
  689. $G = isset($Format["G"]) ? $Format["G"] : 0;
  690. $B = isset($Format["B"]) ? $Format["B"] : 0;
  691. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  692. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  693. $Height = abs($Height);
  694. $Width = abs($Width);
  695. if ( $Height == 0 ) { $Height = 1; }
  696. if ( $Width == 0 ) { $Width = 1; }
  697. $Xc = floor($Xc); $Yc = floor($Yc);
  698. $RestoreShadow = $this->Shadow;
  699. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  700. {
  701. $this->Shadow = FALSE;
  702. $this->drawCircle($Xc+$this->ShadowX,$Yc+$this->ShadowY,$Height,$Width,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks));
  703. }
  704. if ( $Width == 0 ) { $Width = $Height; }
  705. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  706. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  707. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  708. $Step = 360 / (2 * PI * max($Width,$Height));
  709. $Mode = 1; $Cpt = 1;
  710. for($i=0;$i<=360;$i=$i+$Step)
  711. {
  712. $X = cos($i*PI/180) * $Height + $Xc;
  713. $Y = sin($i*PI/180) * $Width + $Yc;
  714. if ( $Ticks != NULL )
  715. {
  716. if ( $Cpt % $Ticks == 0 )
  717. { $Cpt = 0; if ( $Mode == 1 ) { $Mode = 0; } else { $Mode = 1; } }
  718. if ( $Mode == 1 )
  719. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  720. $Cpt++;
  721. }
  722. else
  723. $this->drawAntialiasPixel($X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  724. }
  725. $this->Shadow = $RestoreShadow;
  726. }
  727. /* Draw a filled circle */
  728. function drawFilledCircle($X,$Y,$Radius,$Format="")
  729. {
  730. $R = isset($Format["R"]) ? $Format["R"] : 0;
  731. $G = isset($Format["G"]) ? $Format["G"] : 0;
  732. $B = isset($Format["B"]) ? $Format["B"] : 0;
  733. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  734. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  735. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  736. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  737. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha;
  738. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  739. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  740. if ( $Radius == 0 ) { $Radius = 1; }
  741. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  742. $X = floor($X); $Y = floor($Y);
  743. $Radius = abs($Radius);
  744. $RestoreShadow = $this->Shadow;
  745. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  746. {
  747. $this->Shadow = FALSE;
  748. $this->drawFilledCircle($X+$this->ShadowX,$Y+$this->ShadowY,$Radius,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Ticks"=>$Ticks));
  749. }
  750. $this->Mask = "";
  751. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  752. for ($i=0; $i<=$Radius*2; $i++)
  753. {
  754. $Slice = sqrt($Radius * $Radius - ($Radius - $i) * ($Radius - $i));
  755. $XPos = floor($Slice);
  756. $YPos = $Y + $i - $Radius;
  757. $AAlias = $Slice - floor($Slice);
  758. $this->Mask[$X-$XPos][$YPos] = TRUE;
  759. $this->Mask[$X+$XPos][$YPos] = TRUE;
  760. imageline($this->Picture,$X-$XPos,$YPos,$X+$XPos,$YPos,$Color);
  761. }
  762. if ( $this->Antialias )
  763. $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  764. $this->Mask = "";
  765. if ( $BorderR != -1 )
  766. $this->drawCircle($X,$Y,$Radius,$Radius,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$Ticks));
  767. $this->Shadow = $RestoreShadow;
  768. }
  769. /* Write text */
  770. function drawText($X,$Y,$Text,$Format="")
  771. {
  772. $R = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
  773. $G = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
  774. $B = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
  775. $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
  776. $Align = isset($Format["Align"]) ? $Format["Align"] : TEXT_ALIGN_BOTTOMLEFT;
  777. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
  778. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  779. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  780. $ShowOrigine = isset($Format["ShowOrigine"]) ? $Format["ShowOrigine"] : FALSE;
  781. $TOffset = isset($Format["TOffset"]) ? $Format["TOffset"] : 2;
  782. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : FALSE;
  783. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : TRUE;
  784. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 6;
  785. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : FALSE;
  786. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 6;
  787. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 255;
  788. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 255;
  789. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 255;
  790. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
  791. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  792. $BoxBorderR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  793. $BoxBorderG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  794. $BoxBorderB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  795. $BoxBorderAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 50;
  796. $NoShadow = isset($Format["NoShadow"]) ? $Format["NoShadow"] : FALSE;
  797. $Shadow = $this->Shadow;
  798. if ( $NoShadow ) { $this->Shadow = FALSE; }
  799. if ( $BoxSurrounding != "" ) { $BoxBorderR = $BoxR - $BoxSurrounding; $BoxBorderG = $BoxG - $BoxSurrounding; $BoxBorderB = $BoxB - $BoxSurrounding; $BoxBorderAlpha = $BoxAlpha; }
  800. if ( $ShowOrigine )
  801. {
  802. $MyMarkerSettings = array("R"=>255,"G"=>0,"B"=>0,"BorderR"=>255,"BorderB"=>255,"BorderG"=>255,"Size"=>4);
  803. $this->drawRectangleMarker($X,$Y,$MyMarkerSettings);
  804. }
  805. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,$Angle,$Text);
  806. if ( $DrawBox && ($Angle == 0 || $Angle == 90 || $Angle == 180 || $Angle == 270))
  807. {
  808. $T[0]["X"]=0;$T[0]["Y"]=0;$T[1]["X"]=0;$T[1]["Y"]=0;$T[2]["X"]=0;$T[2]["Y"]=0;$T[3]["X"]=0;$T[3]["Y"]=0;
  809. if ( $Angle == 0 ) { $T[0]["X"]=-$TOffset;$T[0]["Y"]=$TOffset;$T[1]["X"]=$TOffset;$T[1]["Y"]=$TOffset;$T[2]["X"]=$TOffset;$T[2]["Y"]=-$TOffset;$T[3]["X"]=-$TOffset;$T[3]["Y"]=-$TOffset; }
  810. $X1 = min($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) - $BorderOffset + 3;
  811. $Y1 = min($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) - $BorderOffset;
  812. $X2 = max($TxtPos[0]["X"],$TxtPos[1]["X"],$TxtPos[2]["X"],$TxtPos[3]["X"]) + $BorderOffset + 3;
  813. $Y2 = max($TxtPos[0]["Y"],$TxtPos[1]["Y"],$TxtPos[2]["Y"],$TxtPos[3]["Y"]) + $BorderOffset - 3;
  814. $X1 = $X1 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
  815. $Y1 = $Y1 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
  816. $X2 = $X2 - $TxtPos[$Align]["X"] + $X + $T[0]["X"];
  817. $Y2 = $Y2 - $TxtPos[$Align]["Y"] + $Y + $T[0]["Y"];
  818. $Settings = array("R"=>$BoxR,"G"=>$BoxG,"B"=>$BoxB,"Alpha"=>$BoxAlpha,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"BorderAlpha"=>$BoxBorderAlpha);
  819. if ( $BoxRounded )
  820. { $this->drawRoundedFilledRectangle($X1,$Y1,$X2,$Y2,$RoundedRadius,$Settings); }
  821. else
  822. { $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Settings); }
  823. }
  824. $X = $X - $TxtPos[$Align]["X"] + $X;
  825. $Y = $Y - $TxtPos[$Align]["Y"] + $Y;
  826. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  827. {
  828. $C_ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  829. imagettftext($this->Picture,$FontSize,$Angle,$X+$this->ShadowX,$Y+$this->ShadowY,$C_ShadowColor,$FontName,$Text);
  830. }
  831. $C_TextColor = $this->AllocateColor($this->Picture,$R,$G,$B,$Alpha);
  832. imagettftext($this->Picture,$FontSize,$Angle,$X,$Y,$C_TextColor,$FontName,$Text);
  833. $this->Shadow = $Shadow;
  834. return($TxtPos);
  835. }
  836. /* Draw a gradient within a defined area */
  837. function drawGradientArea($X1,$Y1,$X2,$Y2,$Direction,$Format="")
  838. {
  839. $StartR = isset($Format["StartR"]) ? $Format["StartR"] : 90;
  840. $StartG = isset($Format["StartG"]) ? $Format["StartG"] : 90;
  841. $StartB = isset($Format["StartB"]) ? $Format["StartB"] : 90;
  842. $EndR = isset($Format["EndR"]) ? $Format["EndR"] : 0;
  843. $EndG = isset($Format["EndG"]) ? $Format["EndG"] : 0;
  844. $EndB = isset($Format["EndB"]) ? $Format["EndB"] : 0;
  845. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  846. $Levels = isset($Format["Levels"]) ? $Format["Levels"] : NULL;
  847. $Shadow = $this->Shadow;
  848. $this->Shadow = FALSE;
  849. if ( $StartR == $EndR && $StartG == $EndG && $StartB == $EndB )
  850. {
  851. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,array("R"=>$StartR,"G"=>$StartG,"B"=>$StartB,"Alpha"=>$Alpha));
  852. return(0);
  853. }
  854. if ( $Levels != NULL )
  855. { $EndR=$StartR+$Levels; $EndG=$StartG+$Levels; $EndB=$StartB+$Levels; }
  856. if ($X1 > $X2) { list($X1, $X2) = array($X2, $X1); }
  857. if ($Y1 > $Y2) { list($Y1, $Y2) = array($Y2, $Y1); }
  858. if ( $Direction == DIRECTION_VERTICAL ) { $Width = abs($Y2-$Y1); }
  859. if ( $Direction == DIRECTION_HORIZONTAL ) { $Width = abs($X2-$X1); }
  860. $Step = max(abs($EndR-$StartR),abs($EndG-$StartG),abs($EndB-$StartB));
  861. $StepSize = $Width/$Step;
  862. $RStep = ($EndR-$StartR)/$Step;
  863. $GStep = ($EndG-$StartG)/$Step;
  864. $BStep = ($EndB-$StartB)/$Step;
  865. $R=$StartR;$G=$StartG;$B=$StartB;
  866. switch($Direction)
  867. {
  868. case DIRECTION_VERTICAL:
  869. $StartY = $Y1; $EndY = floor($Y2)+1; $LastY2 = $StartY;
  870. for($i=0;$i<=$Step;$i++)
  871. {
  872. $Y2 = floor($StartY + ($i * $StepSize));
  873. if ($Y2 > $EndY) { $Y2 = $EndY; }
  874. if (($Y1 != $Y2 && $Y1 < $Y2) || $Y2 == $EndY)
  875. {
  876. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  877. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
  878. $LastY2 = max($LastY2,$Y2);
  879. $Y1 = $Y2+1;
  880. }
  881. $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep;
  882. }
  883. if ( $LastY2 < $EndY && isset($Color)) { for ($i=$LastY2+1;$i<=$EndY;$i++) { $this->drawLine($X1,$i,$X2,$i,$Color); } }
  884. break;
  885. case DIRECTION_HORIZONTAL:
  886. $StartX = $X1; $EndX = $X2;
  887. for($i=0;$i<=$Step;$i++)
  888. {
  889. $X2 = floor($StartX + ($i * $StepSize));
  890. if ($X2 > $EndX) { $X2 = $EndX; }
  891. if (($X1 != $X2 && $X1 < $X2) || $X2 == $EndX)
  892. {
  893. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  894. $this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$Color);
  895. $X1 = $X2+1;
  896. }
  897. $R = $R + $RStep; $G = $G + $GStep; $B = $B + $BStep;
  898. }
  899. if ( $X2 < $EndX && isset($Color)) { $this->drawFilledRectangle($X2,$Y1,$EndX,$Y2,$Color); }
  900. break;
  901. }
  902. $this->Shadow = $Shadow;
  903. }
  904. /* Draw an aliased pixel */
  905. function drawAntialiasPixel($X,$Y,$Format="")
  906. {
  907. $R = isset($Format["R"]) ? $Format["R"] : 0;
  908. $G = isset($Format["G"]) ? $Format["G"] : 0;
  909. $B = isset($Format["B"]) ? $Format["B"] : 0;
  910. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  911. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  912. return(-1);
  913. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  914. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  915. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  916. if ( !$this->Antialias )
  917. {
  918. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  919. {
  920. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$this->Shadowa);
  921. imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
  922. }
  923. $PlotColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  924. imagesetpixel($this->Picture,$X,$Y,$PlotColor);
  925. return(0);
  926. }
  927. $Plot = "";
  928. $Xi = floor($X);
  929. $Yi = floor($Y);
  930. if ( $Xi == $X && $Yi == $Y)
  931. {
  932. if ( $Alpha == 100 )
  933. $this->drawAlphaPixel($X,$Y,100,$R,$G,$B);
  934. else
  935. $this->drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B);
  936. }
  937. else
  938. {
  939. $Alpha1 = (((1 - ($X - floor($X))) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  940. if ( $Alpha1 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi,$Alpha1,$R,$G,$B); }
  941. $Alpha2 = ((($X - floor($X)) * (1 - ($Y - floor($Y))) * 100) / 100) * $Alpha;
  942. if ( $Alpha2 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi,$Alpha2,$R,$G,$B); }
  943. $Alpha3 = (((1 - ($X - floor($X))) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  944. if ( $Alpha3 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi,$Yi+1,$Alpha3,$R,$G,$B); }
  945. $Alpha4 = ((($X - floor($X)) * ($Y - floor($Y)) * 100) / 100) * $Alpha;
  946. if ( $Alpha4 > $this->AntialiasQuality ) { $this->drawAlphaPixel($Xi+1,$Yi+1,$Alpha4,$R,$G,$B); }
  947. }
  948. }
  949. /* Draw a semi-transparent pixel */
  950. function drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
  951. {
  952. if ( isset($this->Mask[$X])) { if ( isset($this->Mask[$X][$Y]) ) { return(0); } }
  953. if ( $X < 0 || $Y < 0 || $X >= $this->XSize || $Y >= $this->YSize )
  954. return(-1);
  955. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  956. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  957. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  958. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  959. {
  960. $AlphaFactor = floor(($Alpha / 100) * $this->Shadowa);
  961. $ShadowColor = $this->allocateColor($this->Picture,$this->ShadowR,$this->ShadowG,$this->ShadowB,$AlphaFactor);
  962. imagesetpixel($this->Picture,$X+$this->ShadowX,$Y+$this->ShadowY,$ShadowColor);
  963. }
  964. $C_Aliased = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  965. imagesetpixel($this->Picture,$X,$Y,$C_Aliased);
  966. }
  967. /* Convert apha to base 10 */
  968. function convertAlpha($AlphaValue)
  969. { return((127/100)*(100-$AlphaValue)); }
  970. /* Allocate a color with transparency */
  971. function allocateColor($Picture,$R,$G,$B,$Alpha=100)
  972. {
  973. if ( $R < 0 ) { $R = 0; } if ( $R > 255 ) { $R = 255; }
  974. if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
  975. if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
  976. if ( $Alpha < 0 ) { $Alpha = 0; }
  977. if ( $Alpha > 100) { $Alpha = 100; }
  978. $Alpha = $this->convertAlpha($Alpha);
  979. return(imagecolorallocatealpha($Picture,$R,$G,$B,$Alpha));
  980. }
  981. /* Load a PNG file and draw it over the chart */
  982. function drawFromPNG($X,$Y,$FileName)
  983. { $this->drawFromPicture(1,$FileName,$X,$Y); }
  984. /* Load a GIF file and draw it over the chart */
  985. function drawFromGIF($X,$Y,$FileName)
  986. { $this->drawFromPicture(2,$FileName,$X,$Y); }
  987. /* Load a JPEG file and draw it over the chart */
  988. function drawFromJPG($X,$Y,$FileName)
  989. { $this->drawFromPicture(3,$FileName,$X,$Y); }
  990. function getPicInfo($FileName)
  991. {
  992. $Infos = getimagesize($FileName);
  993. $Width = $Infos[0];
  994. $Height = $Infos[1];
  995. $Type = $Infos["mime"];
  996. if ( $Type == "image/png") { $Type = 1; }
  997. if ( $Type == "image/gif") { $Type = 2; }
  998. if ( $Type == "image/jpeg ") { $Type = 3; }
  999. return(array($Width,$Height,$Type));
  1000. }
  1001. /* Generic loader function for external pictures */
  1002. function drawFromPicture($PicType,$FileName,$X,$Y)
  1003. {
  1004. if ( file_exists($FileName))
  1005. {
  1006. list($Width,$Height) = $this->getPicInfo($FileName);
  1007. if ( $PicType == 1 )
  1008. { $Raster = imagecreatefrompng($FileName); }
  1009. elseif ( $PicType == 2 )
  1010. { $Raster = imagecreatefromgif($FileName); }
  1011. elseif ( $PicType == 3 )
  1012. { $Raster = imagecreatefromjpeg($FileName); }
  1013. else
  1014. { return(0); }
  1015. $RestoreShadow = $this->Shadow;
  1016. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  1017. {
  1018. $this->Shadow = FALSE;
  1019. if ( $PicType == 3 )
  1020. $this->drawFilledRectangle($X+$this->ShadowX,$Y+$this->ShadowY,$X+$Width+$this->ShadowX,$Y+$Height+$this->ShadowY,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  1021. else
  1022. {
  1023. $TranparentID = imagecolortransparent($Raster);
  1024. for ($Xc=0;$Xc<=$Width-1;$Xc++)
  1025. {
  1026. for ($Yc=0;$Yc<=$Height-1;$Yc++)
  1027. {
  1028. $RGBa = imagecolorat($Raster,$Xc,$Yc);
  1029. $Values = imagecolorsforindex($Raster,$RGBa);
  1030. if ( $Values["alpha"] < 120 )
  1031. {
  1032. $AlphaFactor = floor(($this->Shadowa / 100) * ((100 / 127) * (127-$Values["alpha"])));
  1033. $this->drawAlphaPixel($X+$Xc+$this->ShadowX,$Y+$Yc+$this->ShadowY,$AlphaFactor,$this->ShadowR,$this->ShadowG,$this->ShadowB);
  1034. }
  1035. }
  1036. }
  1037. }
  1038. }
  1039. $this->Shadow = $RestoreShadow;
  1040. imagecopy($this->Picture,$Raster,$X,$Y,0,0,$Width,$Height);
  1041. imagedestroy($Raster);
  1042. }
  1043. }
  1044. /* Draw an arrow */
  1045. function drawArrow($X1,$Y1,$X2,$Y2,$Format="")
  1046. {
  1047. $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
  1048. $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
  1049. $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
  1050. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
  1051. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
  1052. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
  1053. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1054. $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
  1055. $Ratio = isset($Format["Ratio"]) ? $Format["Ratio"] : .5;
  1056. $TwoHeads = isset($Format["TwoHeads"]) ? $Format["TwoHeads"] : FALSE;
  1057. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : FALSE;
  1058. /* Calculate the line angle */
  1059. $Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
  1060. /* Override Shadow support, this will be managed internally */
  1061. $RestoreShadow = $this->Shadow;
  1062. if ( $this->Shadow && $this->ShadowX != 0 && $this->ShadowY != 0 )
  1063. {
  1064. $this->Shadow = FALSE;
  1065. $this->drawArrow($X1+$this->ShadowX,$Y1+$this->ShadowY,$X2+$this->ShadowX,$Y2+$this->ShadowY,array("FillR"=>$this->ShadowR,"FillG"=>$this->ShadowG,"FillB"=>$this->ShadowB,"Alpha"=>$this->Shadowa,"Size"=>$Size,"Ratio"=>$Ratio,"TwoHeads"=>$TwoHeads,"Ticks"=>$Ticks));
  1066. }
  1067. /* Draw the 1st Head */
  1068. $TailX = cos(($Angle-180)*PI/180)*$Size+$X2;
  1069. $TailY = sin(($Angle-180)*PI/180)*$Size+$Y2;
  1070. $Points = "";
  1071. $Points[] = $X2; $Points[] = $Y2;
  1072. $Points[] = cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY;
  1073. $Points[] = cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY;
  1074. $Points[] = $X2; $Points[] = $Y2;
  1075. /* Visual correction */
  1076. if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
  1077. if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }
  1078. $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
  1079. ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);
  1080. $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1081. $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1082. $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1083. /* Draw the second head */
  1084. if ( $TwoHeads )
  1085. {
  1086. $Angle = $this->getAngle($X2,$Y2,$X1,$Y1);
  1087. $TailX2 = cos(($Angle-180)*PI/180)*$Size+$X1;
  1088. $TailY2 = sin(($Angle-180)*PI/180)*$Size+$Y1;
  1089. $Points = "";
  1090. $Points[] = $X1; $Points[] = $Y1;
  1091. $Points[] = cos(($Angle-90)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-90)*PI/180)*$Size*$Ratio+$TailY2;
  1092. $Points[] = cos(($Angle-270)*PI/180)*$Size*$Ratio+$TailX2; $Points[] = sin(($Angle-270)*PI/180)*$Size*$Ratio+$TailY2;
  1093. $Points[] = $X1; $Points[] = $Y1;
  1094. /* Visual correction */
  1095. if ($Angle == 180 || $Angle == 360 ) { $Points[4] = $Points[2]; }
  1096. if ($Angle == 90 || $Angle == 270 ) { $Points[5] = $Points[3]; }
  1097. $ArrowColor = $this->allocateColor($this->Picture,$FillR,$FillG,$FillB,$Alpha);
  1098. ImageFilledPolygon($this->Picture,$Points,4,$ArrowColor);
  1099. $this->drawLine($Points[0],$Points[1],$Points[2],$Points[3],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1100. $this->drawLine($Points[2],$Points[3],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1101. $this->drawLine($Points[0],$Points[1],$Points[4],$Points[5],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1102. $this->drawLine($TailX,$TailY,$TailX2,$TailY2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1103. }
  1104. else
  1105. $this->drawLine($X1,$Y1,$TailX,$TailY,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1106. /* Re-enable shadows */
  1107. $this->Shadow = $RestoreShadow;
  1108. }
  1109. /* Draw a label with associated arrow */
  1110. function drawArrowLabel($X1,$Y1,$Text,$Format="")
  1111. {
  1112. $FillR = isset($Format["FillR"]) ? $Format["FillR"] : 0;
  1113. $FillG = isset($Format["FillG"]) ? $Format["FillG"] : 0;
  1114. $FillB = isset($Format["FillB"]) ? $Format["FillB"] : 0;
  1115. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $FillR;
  1116. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $FillG;
  1117. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $FillB;
  1118. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1119. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1120. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1121. $Length = isset($Format["Length"]) ? $Format["Length"] : 50;
  1122. $Angle = isset($Format["Angle"]) ? $Format["Angle"] : 315;
  1123. $Size = isset($Format["Size"]) ? $Format["Size"] : 10;
  1124. $Position = isset($Format["Position"]) ? $Format["Position"] : POSITION_TOP;
  1125. $RoundPos = isset($Format["RoundPos"]) ? $Format["RoundPos"] : FALSE;
  1126. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  1127. $Angle = $Angle % 360;
  1128. $X2 = sin(($Angle+180)*PI/180)*$Length+$X1;
  1129. $Y2 = cos(($Angle+180)*PI/180)*$Length+$Y1;
  1130. if ( $RoundPos && $Angle > 0 && $Angle < 180 ) { $Y2 = ceil($Y2); }
  1131. if ( $RoundPos && $Angle > 180 ) { $Y2 = floor($Y2); }
  1132. $this->drawArrow($X2,$Y2,$X1,$Y1,$Format);
  1133. $Size = imagettfbbox($FontSize,0,$FontName,$Text);
  1134. $TxtWidth = max(abs($Size[2]-$Size[0]),abs($Size[0]-$Size[6]));
  1135. $TxtHeight = max(abs($Size[1]-$Size[7]),abs($Size[3]-$Size[1]));
  1136. if ( $Angle > 0 && $Angle < 180 )
  1137. {
  1138. $this->drawLine($X2,$Y2,$X2-$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1139. if ( $Position == POSITION_TOP )
  1140. $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_BOTTOMRIGHT));
  1141. else
  1142. $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPRIGHT));
  1143. }
  1144. else
  1145. {
  1146. $this->drawLine($X2,$Y2,$X2+$TxtWidth,$Y2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  1147. if ( $Position == POSITION_TOP )
  1148. $this->drawText($X2,$Y2-2,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha));
  1149. else
  1150. $this->drawText($X2,$Y2+4,$Text,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$Alpha,"Align"=>TEXT_ALIGN_TOPLEFT));
  1151. }
  1152. }
  1153. /* Draw a progress bar filled with specified % */
  1154. function drawProgress($X,$Y,$Percent,$Format="")
  1155. {
  1156. if ( $Percent > 100 ) { $Percent = 100; }
  1157. if ( $Percent < 0 ) { $Percent = 0; }
  1158. $Width = isset($Format["Width"]) ? $Format["Width"] : 200;
  1159. $Height = isset($Format["Height"]) ? $Format["Height"] : 20;
  1160. $Orientation = isset($Format["Orientation"]) ? $Format["Orientation"] : ORIENTATION_HORIZONTAL;
  1161. $ShowLabel = isset($Format["ShowLabel"]) ? $Format["ShowLabel"] : FALSE;
  1162. $LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : LABEL_POS_INSIDE;
  1163. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 10;
  1164. $R = isset($Format["R"]) ? $Format["R"] : 130;
  1165. $G = isset($Format["G"]) ? $Format["G"] : 130;
  1166. $B = isset($Format["B"]) ? $Format["B"] : 130;
  1167. $RFade = isset($Format["RFade"]) ? $Format["RFade"] : -1;
  1168. $GFade = isset($Format["GFade"]) ? $Format["GFade"] : -1;
  1169. $BFade = isset($Format["BFade"]) ? $Format["BFade"] : -1;
  1170. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  1171. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  1172. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  1173. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 0;
  1174. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 0;
  1175. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 0;
  1176. $BoxBackR = isset($Format["BoxBackR"]) ? $Format["BoxBackR"] : 255;
  1177. $BoxBackG = isset($Format["BoxBackG"]) ? $Format["BoxBackG"] : 255;
  1178. $BoxBackB = isset($Format["BoxBackB"]) ? $Format["BoxBackB"] : 255;
  1179. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1180. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  1181. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : NULL;
  1182. $NoAngle = isset($Format["NoAngle"]) ? $Format["NoAngle"] : FALSE;
  1183. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1184. {
  1185. $RFade = (($RFade-$R)/100)*$Percent+$R;
  1186. $GFade = (($GFade-$G)/100)*$Percent+$G;
  1187. $BFade = (($BFade-$B)/100)*$Percent+$B;
  1188. }
  1189. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  1190. if ( $BoxSurrounding != NULL ) { $BoxBorderR = $BoxBackR + $Surrounding; $BoxBorderG = $BoxBackG + $Surrounding; $BoxBorderB = $BoxBackB + $Surrounding; }
  1191. if ( $Orientation == ORIENTATION_VERTICAL )
  1192. {
  1193. $InnerHeight = (($Height-2)/100)*$Percent;
  1194. $this->drawFilledRectangle($X,$Y,$X+$Width,$Y-$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));
  1195. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1196. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1197. {
  1198. $GradientOptions = array("StartR"=>$RFade,"StartG"=>$GFade,"StartB"=>$BFade,"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  1199. $this->drawGradientArea($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,DIRECTION_VERTICAL,$GradientOptions);
  1200. if ( $Surrounding )
  1201. $this->drawRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
  1202. }
  1203. else
  1204. $this->drawFilledRectangle($X+1,$Y-1,$X+$Width-1,$Y-$InnerHeight,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1205. $this->Shadow = $RestoreShadow;
  1206. if ( $ShowLabel && $LabelPos == LABEL_POS_BOTTOM ) { $this->drawText($X+($Width/2),$Y+$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_TOPMIDDLE)); }
  1207. if ( $ShowLabel && $LabelPos == LABEL_POS_TOP ) { $this->drawText($X+($Width/2),$Y-$Height-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
  1208. if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE ) { $this->drawText($X+($Width/2),$Y-$InnerHeight-$Margin,$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT,"Angle"=>90)); }
  1209. if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER ) { $this->drawText($X+($Width/2),$Y-($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"Angle"=>90)); }
  1210. }
  1211. else
  1212. {
  1213. if ( $Percent == 100 )
  1214. $InnerWidth = $Width-1;
  1215. else
  1216. $InnerWidth = (($Width-2)/100)*$Percent;
  1217. $this->drawFilledRectangle($X,$Y,$X+$Width,$Y+$Height,array("R"=>$BoxBackR,"G"=>$BoxBackG,"B"=>$BoxBackB,"BorderR"=>$BoxBorderR,"BorderG"=>$BoxBorderG,"BorderB"=>$BoxBorderB,"NoAngle"=>$NoAngle));
  1218. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1219. if ( $RFade != -1 && $GFade != -1 && $BFade != -1 )
  1220. {
  1221. $GradientOptions = array("StartR"=>$R,"StartG"=>$G,"StartB"=>$B,"EndR"=>$RFade,"EndG"=>$GFade,"EndB"=>$BFade);
  1222. $this->drawGradientArea($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,DIRECTION_HORIZONTAL,$GradientOptions);
  1223. if ( $Surrounding )
  1224. $this->drawRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>255,"G"=>255,"B"=>255,"Alpha"=>$Surrounding));
  1225. }
  1226. else
  1227. $this->drawFilledRectangle($X+1,$Y+1,$X+$InnerWidth,$Y+$Height-1,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1228. $this->Shadow = $RestoreShadow;
  1229. if ( $ShowLabel && $LabelPos == LABEL_POS_LEFT ) { $this->drawText($X-$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); }
  1230. if ( $ShowLabel && $LabelPos == LABEL_POS_RIGHT ) { $this->drawText($X+$Width+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
  1231. if ( $ShowLabel && $LabelPos == LABEL_POS_CENTER ) { $this->drawText($X+($Width/2),$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE)); }
  1232. if ( $ShowLabel && $LabelPos == LABEL_POS_INSIDE ) { $this->drawText($X+$InnerWidth+$Margin,$Y+($Height/2),$Percent."%",array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
  1233. }
  1234. }
  1235. /* Get the legend box size */
  1236. function getLegendSize($Format="")
  1237. {
  1238. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1239. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1240. $BoxSize = isset($Format["BoxSize"]) ? $Format["BoxSize"] : 5;
  1241. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  1242. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  1243. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  1244. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
  1245. $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
  1246. $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
  1247. $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
  1248. $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
  1249. $Data = $this->DataSet->getData();
  1250. foreach($Data["Series"] as $SerieName => $Serie)
  1251. {
  1252. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
  1253. {
  1254. list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
  1255. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  1256. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  1257. }
  1258. }
  1259. $YStep = max($this->FontSize,$IconAreaHeight) + 5;
  1260. $XStep = $IconAreaWidth + 5;
  1261. $XStep = $XSpacing;
  1262. $X=100; $Y=100;
  1263. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  1264. foreach($Data["Series"] as $SerieName => $Serie)
  1265. {
  1266. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1267. {
  1268. if ( $Mode == LEGEND_VERTICAL )
  1269. {
  1270. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);
  1271. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1272. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1273. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1274. $Lines = preg_split("/\n/",$Serie["Description"]);
  1275. $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1276. }
  1277. elseif ( $Mode == LEGEND_HORIZONTAL )
  1278. {
  1279. $Lines = preg_split("/\n/",$Serie["Description"]);
  1280. $Width = "";
  1281. foreach($Lines as $Key => $Value)
  1282. {
  1283. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  1284. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1285. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1286. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1287. $Width[] = $BoxArray[1]["X"];
  1288. }
  1289. $vX=max($Width)+$XStep;
  1290. }
  1291. }
  1292. }
  1293. $vY=$vY-$YStep; $vX=$vX-$XStep;
  1294. $TopOffset = $Y - $Boundaries["T"];
  1295. if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
  1296. $Width = ($Boundaries["R"]+$Margin) - ($Boundaries["L"]-$Margin);
  1297. $Height = ($Boundaries["B"]+$Margin) - ($Boundaries["T"]-$Margin);
  1298. return(array("Width"=>$Width,"Height"=>$Height));
  1299. }
  1300. /* Draw the legend of the active series */
  1301. function drawLegend($X,$Y,$Format="")
  1302. {
  1303. $Family = isset($Format["Family"]) ? $Format["Family"] : LEGEND_FAMILY_BOX;
  1304. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  1305. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  1306. $FontR = isset($Format["FontR"]) ? $Format["FontR"] : $this->FontColorR;
  1307. $FontG = isset($Format["FontG"]) ? $Format["FontG"] : $this->FontColorG;
  1308. $FontB = isset($Format["FontB"]) ? $Format["FontB"] : $this->FontColorB;
  1309. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 5;
  1310. $BoxHeight = isset($Format["BoxHeight"]) ? $Format["BoxHeight"] : 5;
  1311. $IconAreaWidth = isset($Format["IconAreaWidth"]) ? $Format["IconAreaWidth"] : $BoxWidth;
  1312. $IconAreaHeight = isset($Format["IconAreaHeight"]) ? $Format["IconAreaHeight"] : $BoxHeight;
  1313. $XSpacing = isset($Format["XSpacing"]) ? $Format["XSpacing"] : 5;
  1314. $Margin = isset($Format["Margin"]) ? $Format["Margin"] : 5;
  1315. $R = isset($Format["R"]) ? $Format["R"] : 200;
  1316. $G = isset($Format["G"]) ? $Format["G"] : 200;
  1317. $B = isset($Format["B"]) ? $Format["B"] : 200;
  1318. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  1319. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 255;
  1320. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 255;
  1321. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 255;
  1322. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  1323. $Style = isset($Format["Style"]) ? $Format["Style"] : LEGEND_ROUND;
  1324. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : LEGEND_VERTICAL;
  1325. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  1326. $Data = $this->DataSet->getData();
  1327. foreach($Data["Series"] as $SerieName => $Serie)
  1328. {
  1329. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && isset($Serie["Picture"]))
  1330. {
  1331. list($PicWidth,$PicHeight) = $this->getPicInfo($Serie["Picture"]);
  1332. if ( $IconAreaWidth < $PicWidth ) { $IconAreaWidth = $PicWidth; }
  1333. if ( $IconAreaHeight < $PicHeight ) { $IconAreaHeight = $PicHeight; }
  1334. }
  1335. }
  1336. $YStep = max($this->FontSize,$IconAreaHeight) + 5;
  1337. $XStep = $IconAreaWidth + 5;
  1338. $XStep = $XSpacing;
  1339. $Boundaries = ""; $Boundaries["L"] = $X; $Boundaries["T"] = $Y; $Boundaries["R"] = 0; $Boundaries["B"] = 0; $vY = $Y; $vX = $X;
  1340. foreach($Data["Series"] as $SerieName => $Serie)
  1341. {
  1342. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1343. {
  1344. if ( $Mode == LEGEND_VERTICAL )
  1345. {
  1346. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+4,$vY+$IconAreaHeight/2,$FontName,$FontSize,0,$Serie["Description"]);
  1347. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1348. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1349. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1350. $Lines = preg_split("/\n/",$Serie["Description"]);
  1351. $vY = $vY + max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1352. }
  1353. elseif ( $Mode == LEGEND_HORIZONTAL )
  1354. {
  1355. $Lines = preg_split("/\n/",$Serie["Description"]);
  1356. $Width = "";
  1357. foreach($Lines as $Key => $Value)
  1358. {
  1359. $BoxArray = $this->getTextBox($vX+$IconAreaWidth+6,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$FontName,$FontSize,0,$Value);
  1360. if ( $Boundaries["T"] > $BoxArray[2]["Y"]+$IconAreaHeight/2 ) { $Boundaries["T"] = $BoxArray[2]["Y"]+$IconAreaHeight/2; }
  1361. if ( $Boundaries["R"] < $BoxArray[1]["X"]+2 ) { $Boundaries["R"] = $BoxArray[1]["X"]+2; }
  1362. if ( $Boundaries["B"] < $BoxArray[1]["Y"]+2+$IconAreaHeight/2 ) { $Boundaries["B"] = $BoxArray[1]["Y"]+2+$IconAreaHeight/2; }
  1363. $Width[] = $BoxArray[1]["X"];
  1364. }
  1365. $vX=max($Width)+$XStep;
  1366. }
  1367. }
  1368. }
  1369. $vY=$vY-$YStep; $vX=$vX-$XStep;
  1370. $TopOffset = $Y - $Boundaries["T"];
  1371. if ( $Boundaries["B"]-($vY+$IconAreaHeight) < $TopOffset ) { $Boundaries["B"] = $vY+$IconAreaHeight+$TopOffset; }
  1372. if ( $Style == LEGEND_ROUND )
  1373. $this->drawRoundedFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1374. elseif ( $Style == LEGEND_BOX )
  1375. $this->drawFilledRectangle($Boundaries["L"]-$Margin,$Boundaries["T"]-$Margin,$Boundaries["R"]+$Margin,$Boundaries["B"]+$Margin,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB));
  1376. $RestoreShadow = $this->Shadow; $this->Shadow = FALSE;
  1377. $p_i = 1;
  1378. foreach($Data["Series"] as $SerieName => $Serie)
  1379. {
  1380. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  1381. {
  1382. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"];
  1383. $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  1384. if ( isset($Serie["Picture"]) )
  1385. {
  1386. $Picture = $Serie["Picture"];
  1387. list($PicWidth,$PicHeight) = $this->getPicInfo($Picture);
  1388. $PicX = $X+$IconAreaWidth/2; $PicY = $Y+$IconAreaHeight/2;
  1389. $this->drawFromPNG($PicX-$PicWidth/2,$PicY-$PicHeight/2,$Picture);
  1390. }
  1391. else
  1392. {
  1393. if ( $Family == LEGEND_FAMILY_BOX )
  1394. {
  1395. if ( $BoxWidth != $IconAreaWidth ) { $XOffset = floor(($IconAreaWidth-$BoxWidth)/2); } else { $XOffset = 0; }
  1396. if ( $BoxHeight != $IconAreaHeight ) { $YOffset = floor(($IconAreaHeight-$BoxHeight)/2); } else { $YOffset = 0; }
  1397. $R = $G = $B = 0;
  1398. // $Shape = 681015;
  1399. // $this->drawShape($X+1+$XOffset,$Y+1+$YOffset,$Shape,$SerieWeight,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha);
  1400. $X += 6;
  1401. if($p_i == 2){
  1402. //ling xing
  1403. $Pos = ""; $Pos[]=$X-$BoxWidth; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$BoxWidth; $Pos[]=$X+$BoxWidth; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$BoxWidth;
  1404. $this->drawPolygon($Pos,array("NoFill"=>TRUE,"BorderR"=>$R,"BorderG"=>$G,"BorderB"=>$B,"BorderAlpha"=>$Alpha));
  1405. }elseif($p_i == 1){
  1406. //san jiao xing
  1407. $this->drawLine($X,$Y-$BoxWidth,$X-$BoxWidth,$Y+$BoxWidth,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  1408. $this->drawLine($X-$BoxWidth,$Y+$BoxWidth,$X+$BoxWidth,$Y+$BoxWidth,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  1409. $this->drawLine($X+$BoxWidth,$Y+$BoxWidth,$X,$Y-$BoxWidth,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  1410. }elseif($p_i == 3){
  1411. //zhengfangxing
  1412. $PlotSize = 4;
  1413. $this->drawRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  1414. $this->drawRectangle($X+1+$XOffset,$Y+1+$YOffset,$X+$BoxWidth+$XOffset+1,$Y+$BoxHeight+1+$YOffset,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
  1415. }
  1416. $p_i++;
  1417. }
  1418. elseif ( $Family == LEGEND_FAMILY_CIRCLE )
  1419. {
  1420. $this->drawFilledCircle($X+1+$IconAreaWidth/2,$Y+1+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
  1421. $this->drawFilledCircle($X+$IconAreaWidth/2,$Y+$IconAreaHeight/2,min($IconAreaHeight/2,$IconAreaWidth/2),array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
  1422. }
  1423. elseif ( $Family == LEGEND_FAMILY_LINE )
  1424. {
  1425. $this->drawLine($X+1,$Y+1+$IconAreaHeight/2,$X+1+$IconAreaWidth,$Y+1+$IconAreaHeight/2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20,"Ticks"=>$Ticks,"Weight"=>$Weight));
  1426. $this->drawLine($X,$Y+$IconAreaHeight/2,$X+$IconAreaWidth,$Y+$IconAreaHeight/2,array("R"=>$R,"G"=>$G,"B"=>$B,"Ticks"=>$Ticks,"Weight"=>$Weight));
  1427. }
  1428. }
  1429. if ( $Mode == LEGEND_VERTICAL )
  1430. {
  1431. $Lines = preg_split("/\n/",$Serie["Description"]);
  1432. foreach($Lines as $Key => $Value)
  1433. $this->drawText($X+$IconAreaWidth+4,$Y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontSize"=>$FontSize,"FontName"=>$FontName));
  1434. $Y=$Y+max($this->FontSize*count($Lines),$IconAreaHeight) + 5;
  1435. }
  1436. elseif ( $Mode == LEGEND_HORIZONTAL )
  1437. {
  1438. $Lines = preg_split("/\n/",$Serie["Description"]);
  1439. $Width = "";
  1440. foreach($Lines as $Key => $Value)
  1441. {
  1442. $_y = $Y;
  1443. $_y -= 3;
  1444. $X += 2;
  1445. $BoxArray = $this->drawText($X+$IconAreaWidth+4,$_y+$IconAreaHeight/2+(($this->FontSize+3)*$Key),$Value,array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT,"FontSize"=>$FontSize,"FontName"=>$FontName));
  1446. $Width[] = $BoxArray[1]["X"];
  1447. }
  1448. $X=max($Width)+2+$XStep;
  1449. }
  1450. }
  1451. }
  1452. $this->Shadow = $RestoreShadow;
  1453. }
  1454. function drawScale($Format="")
  1455. {
  1456. $Pos = isset($Format["Pos"]) ? $Format["Pos"] : SCALE_POS_LEFTRIGHT;
  1457. $Floating = isset($Format["Floating"]) ? $Format["Floating"] : FALSE;
  1458. $Mode = isset($Format["Mode"]) ? $Format["Mode"] : SCALE_MODE_FLOATING;
  1459. $RemoveXAxis = isset($Format["RemoveXAxis"]) ? $Format["RemoveXAxis"] : FALSE;
  1460. $MinDivHeight = isset($Format["MinDivHeight"]) ? $Format["MinDivHeight"] : 20;
  1461. $Factors = isset($Format["Factors"]) ? $Format["Factors"] : array(1,2,5);
  1462. $ManualScale = isset($Format["ManualScale"]) ? $Format["ManualScale"] : array("0"=>array("Min"=>-100,"Max"=>100));
  1463. $XMargin = isset($Format["XMargin"]) ? $Format["XMargin"] : AUTO;
  1464. $YMargin = isset($Format["YMargin"]) ? $Format["YMargin"] : 0;
  1465. $ScaleSpacing = isset($Format["ScaleSpacing"]) ? $Format["ScaleSpacing"] : 15;
  1466. $InnerTickWidth = isset($Format["InnerTickWidth"]) ? $Format["InnerTickWidth"] : 2;
  1467. $OuterTickWidth = isset($Format["OuterTickWidth"]) ? $Format["OuterTickWidth"] : 2;
  1468. $DrawXLines = isset($Format["DrawXLines"]) ? $Format["DrawXLines"] : TRUE;
  1469. $DrawYLines = isset($Format["DrawYLines"]) ? $Format["DrawYLines"] : ALL;
  1470. $GridTicks = isset($Format["GridTicks"]) ? $Format["GridTicks"] : 4;
  1471. $GridR = isset($Format["GridR"]) ? $Format["GridR"] : 255;
  1472. $GridG = isset($Format["GridG"]) ? $Format["GridG"] : 255;
  1473. $GridB = isset($Format["GridB"]) ? $Format["GridB"] : 255;
  1474. $GridAlpha = isset($Format["GridAlpha"]) ? $Format["GridAlpha"] : 40;
  1475. $AxisRo = isset($Format["AxisR"]) ? $Format["AxisR"] : 0;
  1476. $AxisGo = isset($Format["AxisG"]) ? $Format["AxisG"] : 0;
  1477. $AxisBo = isset($Format["AxisB"]) ? $Format["AxisB"] : 0;
  1478. $AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 100;
  1479. $TickRo = isset($Format["TickR"]) ? $Format["TickR"] : 0;
  1480. $TickGo = isset($Format["TickG"]) ? $Format["TickG"] : 0;
  1481. $TickBo = isset($Format["TickB"]) ? $Format["TickB"] : 0;
  1482. $TickAlpha = isset($Format["TickAlpha"]) ? $Format["TickAlpha"] : 100;
  1483. $DrawSubTicks = isset($Format["DrawSubTicks"]) ? $Format["DrawSubTicks"] : FALSE;
  1484. $InnerSubTickWidth = isset($Format["InnerSubTickWidth"]) ? $Format["InnerSubTickWidth"] : 0;
  1485. $OuterSubTickWidth = isset($Format["OuterSubTickWidth"]) ? $Format["OuterSubTickWidth"] : 2;
  1486. $SubTickR = isset($Format["SubTickR"]) ? $Format["SubTickR"] : 255;
  1487. $SubTickG = isset($Format["SubTickG"]) ? $Format["SubTickG"] : 0;
  1488. $SubTickB = isset($Format["SubTickB"]) ? $Format["SubTickB"] : 0;
  1489. $SubTickAlpha = isset($Format["SubTickAlpha"]) ? $Format["SubTickAlpha"] : 100;
  1490. $AutoAxisLabels = isset($Format["AutoAxisLabels"]) ? $Format["AutoAxisLabels"] : TRUE;
  1491. $XReleasePercent = isset($Format["XReleasePercent"]) ? $Format["XReleasePercent"] : 1;
  1492. $DrawArrows = isset($Format["DrawArrows"]) ? $Format["DrawArrows"] : FALSE;
  1493. $ArrowSize = isset($Format["ArrowSize"]) ? $Format["ArrowSize"] : 8;
  1494. $CycleBackground = isset($Format["CycleBackground"]) ? $Format["CycleBackground"] : FALSE;
  1495. $BackgroundR1 = isset($Format["BackgroundR1"]) ? $Format["BackgroundR1"] : 255;
  1496. $BackgroundG1 = isset($Format["BackgroundG1"]) ? $Format["BackgroundG1"] : 255;
  1497. $BackgroundB1 = isset($Format["BackgroundB1"]) ? $Format["BackgroundB1"] : 255;
  1498. $BackgroundAlpha1 = isset($Format["BackgroundAlpha1"]) ? $Format["BackgroundAlpha1"] : 20;
  1499. $BackgroundR2 = isset($Format["BackgroundR2"]) ? $Format["BackgroundR2"] : 230;
  1500. $BackgroundG2 = isset($Format["BackgroundG2"]) ? $Format["BackgroundG2"] : 230;
  1501. $BackgroundB2 = isset($Format["BackgroundB2"]) ? $Format["BackgroundB2"] : 230;
  1502. $BackgroundAlpha2 = isset($Format["BackgroundAlpha2"]) ? $Format["BackgroundAlpha2"] : 20;
  1503. $LabelingMethod = isset($Format["LabelingMethod"]) ? $Format["LabelingMethod"] : LABELING_ALL;
  1504. $LabelSkip = isset($Format["LabelSkip"]) ? $Format["LabelSkip"] : 0;
  1505. $LabelRotation = isset($Format["LabelRotation"]) ? $Format["LabelRotation"] : 0;
  1506. $RemoveSkippedAxis = isset($Format["RemoveSkippedAxis"]) ? $Format["RemoveSkippedAxis"] : FALSE;
  1507. $SkippedAxisTicks = isset($Format["SkippedAxisTicks"]) ? $Format["SkippedAxisTicks"] : $GridTicks+2;
  1508. $SkippedAxisR = isset($Format["SkippedAxisR"]) ? $Format["SkippedAxisR"] : $GridR;
  1509. $SkippedAxisG = isset($Format["SkippedAxisG"]) ? $Format["SkippedAxisG"] : $GridG;
  1510. $SkippedAxisB = isset($Format["SkippedAxisB"]) ? $Format["SkippedAxisB"] : $GridB;
  1511. $SkippedAxisAlpha = isset($Format["SkippedAxisAlpha"]) ? $Format["SkippedAxisAlpha"] : $GridAlpha-30;
  1512. $SkippedTickR = isset($Format["SkippedTickR"]) ? $Format["SkippedTickR"] : $TickRo;
  1513. $SkippedTickG = isset($Format["SkippedTickG"]) ? $Format["SkippedTickG"] : $TickGo;
  1514. $SkippedTickB = isset($Format["SkippedTicksB"]) ? $Format["SkippedTickB"] : $TickBo;
  1515. $SkippedTickAlpha = isset($Format["SkippedTickAlpha"]) ? $Format["SkippedTickAlpha"] : $TickAlpha-80;
  1516. $SkippedInnerTickWidth = isset($Format["SkippedInnerTickWidth"]) ? $Format["SkippedInnerTickWidth"] : 0;
  1517. $SkippedOuterTickWidth = isset($Format["SkippedOuterTickWidth"]) ? $Format["SkippedOuterTickWidth"] : 2;
  1518. /* Floating scale require X & Y margins to be set manually */
  1519. if ( $Floating && ( $XMargin == AUTO || $YMargin == 0 ) ) { $Floating = FALSE; }
  1520. /* Skip a NOTICE event in case of an empty array */
  1521. if ( $DrawYLines == NONE || $DrawYLines == FALSE ) { $DrawYLines = array("zarma"=>"31"); }
  1522. /* Define the color for the skipped elements */
  1523. $SkippedAxisColor = array("R"=>$SkippedAxisR,"G"=>$SkippedAxisG,"B"=>$SkippedAxisB,"Alpha"=>$SkippedAxisAlpha,"Ticks"=>$SkippedAxisTicks);
  1524. $SkippedTickColor = array("R"=>$SkippedTickR,"G"=>$SkippedTickG,"B"=>$SkippedTickB,"Alpha"=>$SkippedTickAlpha);
  1525. $Data = $this->DataSet->getData();
  1526. if ( isset($Data["Abscissa"]) ) { $Abscissa = $Data["Abscissa"]; } else { $Abscissa = NULL; }
  1527. /* Unset the abscissa axis, needed if we display multiple charts on the same picture */
  1528. if ( $Abscissa != NULL )
  1529. {
  1530. foreach($Data["Axis"] as $AxisID => $Parameters)
  1531. { if ($Parameters["Identity"] == AXIS_X) { unset($Data["Axis"][$AxisID]); } }
  1532. }
  1533. /* Build the scale settings */
  1534. $GotXAxis = FALSE;
  1535. foreach($Data["Axis"] as $AxisID => $AxisParameter)
  1536. {
  1537. if ( $AxisParameter["Identity"] == AXIS_X ) { $GotXAxis = TRUE; }
  1538. if ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_Y)
  1539. { $Height = $this->GraphAreaY2-$this->GraphAreaY1 - $YMargin*2; }
  1540. elseif ( $Pos == SCALE_POS_LEFTRIGHT && $AxisParameter["Identity"] == AXIS_X)
  1541. { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
  1542. elseif ( $Pos == SCALE_POS_TOPBOTTOM && $AxisParameter["Identity"] == AXIS_Y)
  1543. { $Height = $this->GraphAreaX2-$this->GraphAreaX1 - $YMargin*2;; }
  1544. else
  1545. { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }
  1546. $AxisMin = ABSOLUTE_MAX; $AxisMax = OUT_OF_SIGHT;
  1547. if ( $Mode == SCALE_MODE_FLOATING || $Mode == SCALE_MODE_START0 )
  1548. {
  1549. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1550. {
  1551. if ( $SerieParameter["Axis"] == $AxisID && $Data["Series"][$SerieID]["isDrawable"] && $Data["Abscissa"] != $SerieID)
  1552. {
  1553. $AxisMax = max($AxisMax,$Data["Series"][$SerieID]["Max"]);
  1554. $AxisMin = min($AxisMin,$Data["Series"][$SerieID]["Min"]);
  1555. }
  1556. }
  1557. $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
  1558. $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
  1559. if ( $Mode == SCALE_MODE_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; }
  1560. }
  1561. elseif ( $Mode == SCALE_MODE_MANUAL )
  1562. {
  1563. if ( isset($ManualScale[$AxisID]["Min"]) && isset($ManualScale[$AxisID]["Max"]) )
  1564. {
  1565. $Data["Axis"][$AxisID]["Min"] = $ManualScale[$AxisID]["Min"];
  1566. $Data["Axis"][$AxisID]["Max"] = $ManualScale[$AxisID]["Max"];
  1567. }
  1568. else
  1569. { echo "Manual scale boundaries not set."; exit(); }
  1570. }
  1571. elseif ( $Mode == SCALE_MODE_ADDALL || $Mode == SCALE_MODE_ADDALL_START0 )
  1572. {
  1573. $Series = "";
  1574. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1575. { if ( $SerieParameter["Axis"] == $AxisID && $SerieParameter["isDrawable"] && $Data["Abscissa"] != $SerieID ) { $Series[$SerieID] = count($Data["Series"][$SerieID]["Data"]); } }
  1576. for ($ID=0;$ID<=max($Series)-1;$ID++)
  1577. {
  1578. $PointMin = 0; $PointMax = 0;
  1579. foreach($Series as $SerieID => $ValuesCount )
  1580. {
  1581. if (isset($Data["Series"][$SerieID]["Data"][$ID]) && $Data["Series"][$SerieID]["Data"][$ID] != NULL )
  1582. {
  1583. $Value = $Data["Series"][$SerieID]["Data"][$ID];
  1584. if ( $Value > 0 ) { $PointMax = $PointMax + $Value; } else { $PointMin = $PointMin + $Value; }
  1585. }
  1586. }
  1587. $AxisMax = max($AxisMax,$PointMax);
  1588. $AxisMin = min($AxisMin,$PointMin);
  1589. }
  1590. $AutoMargin = (($AxisMax-$AxisMin)/100)*$XReleasePercent;
  1591. $Data["Axis"][$AxisID]["Min"] = $AxisMin-$AutoMargin; $Data["Axis"][$AxisID]["Max"] = $AxisMax+$AutoMargin;
  1592. }
  1593. $MaxDivs = floor($Height/$MinDivHeight);
  1594. if ( $Mode == SCALE_MODE_ADDALL_START0 ) { $Data["Axis"][$AxisID]["Min"] = 0; }
  1595. $Scale = $this->computeScale($Data["Axis"][$AxisID]["Min"],$Data["Axis"][$AxisID]["Max"],$MaxDivs,$Factors,$AxisID);
  1596. $Data["Axis"][$AxisID]["Margin"] = $AxisParameter["Identity"] == AXIS_X ? $XMargin : $YMargin;
  1597. $Data["Axis"][$AxisID]["ScaleMin"] = $Scale["XMin"];
  1598. $Data["Axis"][$AxisID]["ScaleMax"] = $Scale["XMax"];
  1599. $Data["Axis"][$AxisID]["Rows"] = $Scale["Rows"];
  1600. $Data["Axis"][$AxisID]["RowHeight"] = $Scale["RowHeight"];
  1601. if ( isset($Scale["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = $Scale["Format"]; }
  1602. if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
  1603. if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
  1604. if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
  1605. }
  1606. /* Still no X axis */
  1607. if ( $GotXAxis == FALSE )
  1608. {
  1609. if ( $Abscissa != NULL )
  1610. {
  1611. $Points = count($Data["Series"][$Abscissa]["Data"]);
  1612. if ( $AutoAxisLabels )
  1613. $AxisName = isset($Data["Series"][$Abscissa]["Description"]) ? $Data["Series"][$Abscissa]["Description"] : NULL;
  1614. else
  1615. $AxisName = NULL;
  1616. }
  1617. else
  1618. {
  1619. $Points = 0;
  1620. $AxisName = isset($Data["XAxisName"]) ? $Data["XAxisName"] : NULL;
  1621. foreach($Data["Series"] as $SerieID => $SerieParameter)
  1622. { if ( $SerieParameter["isDrawable"] ) { $Points = max($Points,count($SerieParameter["Data"])); } }
  1623. }
  1624. $AxisID = count($Data["Axis"]);
  1625. $Data["Axis"][$AxisID]["Identity"] = AXIS_X;
  1626. if ( $Pos == SCALE_POS_LEFTRIGHT ) { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_BOTTOM; } else { $Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_LEFT; }
  1627. if ( isset($Data["AbscissaName"]) ) { $Data["Axis"][$AxisID]["Name"] = $Data["AbscissaName"]; }
  1628. if ( $XMargin == AUTO )
  1629. {
  1630. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1631. { $Height = $this->GraphAreaX2-$this->GraphAreaX1; }
  1632. else
  1633. { $Height = $this->GraphAreaY2-$this->GraphAreaY1; }
  1634. if ( $Points == 1 )
  1635. $Data["Axis"][$AxisID]["Margin"] = $Height / 2;
  1636. else
  1637. $Data["Axis"][$AxisID]["Margin"] = ($Height/$Points) / 2;
  1638. }
  1639. else
  1640. { $Data["Axis"][$AxisID]["Margin"] = $XMargin; }
  1641. $Data["Axis"][$AxisID]["Rows"] = $Points-1;
  1642. if ( !isset($Data["Axis"][$AxisID]["Display"]) ) { $Data["Axis"][$AxisID]["Display"] = NULL; }
  1643. if ( !isset($Data["Axis"][$AxisID]["Format"]) ) { $Data["Axis"][$AxisID]["Format"] = NULL; }
  1644. if ( !isset($Data["Axis"][$AxisID]["Unit"]) ) { $Data["Axis"][$AxisID]["Unit"] = NULL; }
  1645. }
  1646. /* Do we need to reverse the abscissa position? */
  1647. if ( $Pos != SCALE_POS_LEFTRIGHT )
  1648. {
  1649. if ( $Data["AbsicssaPosition"] == AXIS_POSITION_BOTTOM )
  1650. { $Data["AbsicssaPosition"] = AXIS_POSITION_LEFT; }
  1651. else
  1652. { $Data["AbsicssaPosition"] = AXIS_POSITION_RIGHT; }
  1653. }
  1654. $Data["Axis"][$AxisID]["Position"] = $Data["AbsicssaPosition"];
  1655. $this->DataSet->saveOrientation($Pos);
  1656. $this->DataSet->saveAxisConfig($Data["Axis"]);
  1657. $this->DataSet->saveYMargin($YMargin);
  1658. $FontColorRo = $this->FontColorR; $FontColorGo = $this->FontColorG; $FontColorBo = $this->FontColorB;
  1659. $AxisPos["L"] = $this->GraphAreaX1; $AxisPos["R"] = $this->GraphAreaX2; $AxisPos["T"] = $this->GraphAreaY1; $AxisPos["B"] = $this->GraphAreaY2;
  1660. foreach($Data["Axis"] as $AxisID => $Parameters)
  1661. {
  1662. if ( isset($Parameters["Color"]) )
  1663. {
  1664. $AxisR = $Parameters["Color"]["R"]; $AxisG = $Parameters["Color"]["G"]; $AxisB = $Parameters["Color"]["B"];
  1665. $TickR = $Parameters["Color"]["R"]; $TickG = $Parameters["Color"]["G"]; $TickB = $Parameters["Color"]["B"];
  1666. $this->setFontProperties(array("R"=>$Parameters["Color"]["R"],"G"=>$Parameters["Color"]["G"],"B"=>$Parameters["Color"]["B"]));
  1667. }
  1668. else
  1669. {
  1670. $AxisR = $AxisRo; $AxisG = $AxisGo; $AxisB = $AxisBo;
  1671. $TickR = $TickRo; $TickG = $TickGo; $TickB = $TickBo;
  1672. $this->setFontProperties(array("R"=>$FontColorRo,"G"=>$FontColorGo,"B"=>$FontColorBo));
  1673. }
  1674. $LastValue = "w00t"; $ID = 1;
  1675. if ( $Parameters["Identity"] == AXIS_X )
  1676. {
  1677. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1678. {
  1679. if ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
  1680. {
  1681. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 2; }
  1682. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }
  1683. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 5; }
  1684. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }
  1685. if ( !$RemoveXAxis )
  1686. {
  1687. if ( $Floating )
  1688. { $FloatingOffset = $YMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1689. else
  1690. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1691. if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["B"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1692. }
  1693. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1694. if ($Parameters["Rows"] == 0 ) { $Step = $Width; } else { $Step = $Width / ($Parameters["Rows"]); }
  1695. $MaxBottom = $AxisPos["B"];
  1696. for($i=0;$i<=$Parameters["Rows"];$i++)
  1697. {
  1698. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1699. $YPos = $AxisPos["B"];
  1700. if ( $Abscissa != NULL )
  1701. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1702. else
  1703. {
  1704. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1705. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1706. else
  1707. $Value = $i;
  1708. }
  1709. $ID++; $Skipped = TRUE;
  1710. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1711. {
  1712. $Bounds = $this->drawText($XPos,$YPos+$OuterTickWidth+$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1713. $TxtBottom = $YPos+$OuterTickWidth+2+($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  1714. $MaxBottom = max($MaxBottom,$TxtBottom);
  1715. $LastValue = $Value;
  1716. $Skipped = FALSE;
  1717. }
  1718. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1719. if ( $Skipped )
  1720. {
  1721. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
  1722. if ( ($SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis) { $this->drawLine($XPos,$YPos-$SkippedInnerTickWidth,$XPos,$YPos+$SkippedOuterTickWidth,$SkippedTickColor); }
  1723. }
  1724. else
  1725. {
  1726. if ( $DrawXLines && ($XPos != $this->GraphAreaX1 && $XPos != $this->GraphAreaX2) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1727. if ( ($InnerTickWidth !=0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos,$YPos-$InnerTickWidth,$XPos,$YPos+$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1728. }
  1729. }
  1730. if ( isset($Parameters["Name"]) && !$RemoveXAxis)
  1731. {
  1732. $YPos = $MaxBottom+2;
  1733. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1734. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  1735. $MaxBottom = $Bounds[0]["Y"];
  1736. $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
  1737. }
  1738. $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
  1739. }
  1740. elseif ( $Parameters["Position"] == AXIS_POSITION_TOP )
  1741. {
  1742. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_BOTTOMMIDDLE; $YLabelOffset = 2; }
  1743. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $YLabelOffset = 2; }
  1744. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_TOPMIDDLE; $YLabelOffset = 5; }
  1745. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $YLabelOffset = 5; }
  1746. if ( !$RemoveXAxis )
  1747. {
  1748. if ( $Floating )
  1749. { $FloatingOffset = $YMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1750. else
  1751. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1752. if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["T"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1753. }
  1754. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  1755. if ($Parameters["Rows"] == 0 ) { $Step = $Width; } else { $Step = $Width / $Parameters["Rows"]; }
  1756. $MinTop = $AxisPos["T"];
  1757. for($i=0;$i<=$Parameters["Rows"];$i++)
  1758. {
  1759. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  1760. $YPos = $AxisPos["T"];
  1761. if ( $Abscissa != NULL )
  1762. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1763. else
  1764. {
  1765. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1766. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1767. else
  1768. $Value = $i;
  1769. }
  1770. $ID++; $Skipped = TRUE;
  1771. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1772. {
  1773. $Bounds = $this->drawText($XPos,$YPos-$OuterTickWidth-$YLabelOffset,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1774. $TxtBox = $YPos-$OuterTickWidth-2-($Bounds[0]["Y"]-$Bounds[2]["Y"]);
  1775. $MinTop = min($MinTop,$TxtBox);
  1776. $LastValue = $Value;
  1777. $Skipped = FALSE;
  1778. }
  1779. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1780. if ( $Skipped )
  1781. {
  1782. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$SkippedAxisColor); }
  1783. if ( ($SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis ) { $this->drawLine($XPos,$YPos+$SkippedInnerTickWidth,$XPos,$YPos-$SkippedOuterTickWidth,$SkippedTickColor); }
  1784. }
  1785. else
  1786. {
  1787. if ( $DrawXLines ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1788. if ( ($InnerTickWidth !=0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos,$YPos+$InnerTickWidth,$XPos,$YPos-$OuterTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1789. }
  1790. }
  1791. if ( isset($Parameters["Name"]) && !$RemoveXAxis )
  1792. {
  1793. $YPos = $MinTop-2;
  1794. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  1795. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  1796. $MinTop = $Bounds[2]["Y"];
  1797. $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
  1798. }
  1799. $AxisPos["T"] = $MinTop - $ScaleSpacing;
  1800. }
  1801. }
  1802. elseif ( $Pos == SCALE_POS_TOPBOTTOM )
  1803. {
  1804. if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
  1805. {
  1806. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -2; }
  1807. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = -6; }
  1808. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -2; }
  1809. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = -5; }
  1810. if ( !$RemoveXAxis )
  1811. {
  1812. if ( $Floating )
  1813. { $FloatingOffset = $YMargin; $this->drawLine($AxisPos["L"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1814. else
  1815. { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1816. if ( $DrawArrows ) { $this->drawArrow($AxisPos["L"],$this->GraphAreaY2-$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY2+($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1817. }
  1818. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1819. if ($Parameters["Rows"] == 0 ) { $Step = $Height; } else { $Step = $Height / $Parameters["Rows"]; }
  1820. $MinLeft = $AxisPos["L"];
  1821. for($i=0;$i<=$Parameters["Rows"];$i++)
  1822. {
  1823. $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
  1824. $XPos = $AxisPos["L"];
  1825. if ( $Abscissa != NULL )
  1826. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1827. else
  1828. {
  1829. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1830. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1831. else
  1832. $Value = $i;
  1833. }
  1834. $ID++; $Skipped = TRUE;
  1835. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1836. {
  1837. $Bounds = $this->drawText($XPos-$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1838. $TxtBox = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
  1839. $MinLeft = min($MinLeft,$TxtBox);
  1840. $LastValue = $Value;
  1841. $Skipped = FALSE;
  1842. }
  1843. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1844. if ( $Skipped )
  1845. {
  1846. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
  1847. if ( ($SkippedInnerTickWidth !=0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis ) { $this->drawLine($XPos-$SkippedOuterTickWidth,$YPos,$XPos+$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
  1848. }
  1849. else
  1850. {
  1851. if ( $DrawXLines && ($YPos != $this->GraphAreaY1 && $YPos != $this->GraphAreaY2) ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1852. if ( ($InnerTickWidth !=0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1853. }
  1854. }
  1855. if ( isset($Parameters["Name"]) && !$RemoveXAxis )
  1856. {
  1857. $XPos = $MinLeft-2;
  1858. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1859. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
  1860. $MinLeft = $Bounds[0]["X"];
  1861. $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
  1862. }
  1863. $AxisPos["L"] = $MinLeft - $ScaleSpacing;
  1864. }
  1865. elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
  1866. {
  1867. if ( $LabelRotation == 0 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 2; }
  1868. if ( $LabelRotation > 0 && $LabelRotation < 190 ) { $LabelAlign = TEXT_ALIGN_MIDDLELEFT; $XLabelOffset = 6; }
  1869. if ( $LabelRotation == 180 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 5; }
  1870. if ( $LabelRotation > 180 && $LabelRotation < 360 ) { $LabelAlign = TEXT_ALIGN_MIDDLERIGHT; $XLabelOffset = 7; }
  1871. if ( !$RemoveXAxis )
  1872. {
  1873. if ( $Floating )
  1874. { $FloatingOffset = $YMargin; $this->drawLine($AxisPos["R"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1875. else
  1876. { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1877. if ( $DrawArrows ) { $this->drawArrow($AxisPos["R"],$this->GraphAreaY2-$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY2+($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1878. }
  1879. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1880. if ($Parameters["Rows"] == 0 ) { $Step = $Height; } else { $Step = $Height / $Parameters["Rows"]; }
  1881. $MaxRight = $AxisPos["R"];
  1882. for($i=0;$i<=$Parameters["Rows"];$i++)
  1883. {
  1884. $YPos = $this->GraphAreaY1 + $Parameters["Margin"] + $Step*$i;
  1885. $XPos = $AxisPos["R"];
  1886. if ( $Abscissa != NULL )
  1887. { if ( isset($Data["Series"][$Abscissa]["Data"][$i]) ) { $Value = $this->scaleFormat($Data["Series"][$Abscissa]["Data"][$i],$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]); } else { $Value = ""; } }
  1888. else
  1889. {
  1890. if ( isset($Parameters["ScaleMin"]) && isset ($Parameters["RowHeight"]) )
  1891. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Data["XAxisDisplay"],$Data["XAxisFormat"],$Data["XAxisUnit"]);
  1892. else
  1893. $Value = $i;
  1894. }
  1895. $ID++; $Skipped = TRUE;
  1896. if ( $this->isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip) && !$RemoveXAxis)
  1897. {
  1898. $Bounds = $this->drawText($XPos+$OuterTickWidth+$XLabelOffset,$YPos,$Value,array("Angle"=>$LabelRotation,"Align"=>$LabelAlign));
  1899. $TxtBox = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
  1900. $MaxRight = max($MaxRight,$TxtBox);
  1901. $LastValue = $Value;
  1902. $Skipped = FALSE;
  1903. }
  1904. if ( $RemoveXAxis ) { $Skipped = FALSE; }
  1905. if ( $Skipped )
  1906. {
  1907. if ( $DrawXLines && !$RemoveSkippedAxis ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,$SkippedAxisColor); }
  1908. if ( ($SkippedInnerTickWidth != 0 || $SkippedOuterTickWidth != 0) && !$RemoveXAxis && !$RemoveSkippedAxis ) { $this->drawLine($XPos+$SkippedOuterTickWidth,$YPos,$XPos-$SkippedInnerTickWidth,$YPos,$SkippedTickColor); }
  1909. }
  1910. else
  1911. {
  1912. if ( $DrawXLines ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1913. if ( ($InnerTickWidth != 0 || $OuterTickWidth != 0) && !$RemoveXAxis ) { $this->drawLine($XPos+$OuterTickWidth,$YPos,$XPos-$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha)); }
  1914. }
  1915. }
  1916. if ( isset($Parameters["Name"]) && !$RemoveXAxis)
  1917. {
  1918. $XPos = $MaxRight+4;
  1919. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1920. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
  1921. $MaxRight = $Bounds[1]["X"];
  1922. $this->DataSet->Data["GraphArea"]["X2"] = $MaxRight + $this->FontSize;
  1923. }
  1924. $AxisPos["R"] = $MaxRight + $ScaleSpacing;
  1925. }
  1926. }
  1927. }
  1928. if ( $Parameters["Identity"] == AXIS_Y )
  1929. {
  1930. if ( $Pos == SCALE_POS_LEFTRIGHT )
  1931. {
  1932. if ( $Parameters["Position"] == AXIS_POSITION_LEFT )
  1933. {
  1934. if ( $Floating )
  1935. { $FloatingOffset = $XMargin; $this->drawLine($AxisPos["L"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1936. else
  1937. { $FloatingOffset = 0; $this->drawLine($AxisPos["L"],$this->GraphAreaY1,$AxisPos["L"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1938. if ( $DrawArrows ) { $this->drawArrow($AxisPos["L"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["L"],$this->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1939. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1940. $Step = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinLeft = $AxisPos["L"];
  1941. $LastY = NULL;
  1942. for($i=0;$i<=$Parameters["Rows"];$i++)
  1943. {
  1944. $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
  1945. $XPos = $AxisPos["L"];
  1946. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1947. if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
  1948. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  1949. if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1950. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1951. $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1952. $this->drawLine($XPos-$OuterTickWidth,$YPos,$XPos+$InnerTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1953. $Bounds = $this->drawText($XPos-$OuterTickWidth-2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLERIGHT));
  1954. $TxtLeft = $XPos-$OuterTickWidth-2-($Bounds[1]["X"]-$Bounds[0]["X"]);
  1955. $MinLeft = min($MinLeft,$TxtLeft);
  1956. $LastY = $YPos;
  1957. }
  1958. if ( isset($Parameters["Name"]) )
  1959. {
  1960. $XPos = $MinLeft-2;
  1961. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1962. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>90));
  1963. $MinLeft = $Bounds[2]["X"];
  1964. $this->DataSet->Data["GraphArea"]["X1"] = $MinLeft;
  1965. }
  1966. $AxisPos["L"] = $MinLeft - $ScaleSpacing;
  1967. }
  1968. elseif ( $Parameters["Position"] == AXIS_POSITION_RIGHT )
  1969. {
  1970. if ( $Floating )
  1971. { $FloatingOffset = $XMargin; $this->drawLine($AxisPos["R"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY2-$Parameters["Margin"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1972. else
  1973. { $FloatingOffset = 0; $this->drawLine($AxisPos["R"],$this->GraphAreaY1,$AxisPos["R"],$this->GraphAreaY2,array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  1974. if ( $DrawArrows ) { $this->drawArrow($AxisPos["R"],$this->GraphAreaY1+$Parameters["Margin"],$AxisPos["R"],$this->GraphAreaY1-($ArrowSize*2),array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  1975. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Parameters["Margin"]*2;
  1976. $Step = $Height / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxLeft = $AxisPos["R"];
  1977. $LastY = NULL;
  1978. for($i=0;$i<=$Parameters["Rows"];$i++)
  1979. {
  1980. $YPos = $this->GraphAreaY2 - $Parameters["Margin"] - $Step*$i;
  1981. $XPos = $AxisPos["R"];
  1982. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  1983. if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
  1984. if ( $LastY != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($this->GraphAreaX1+$FloatingOffset,$LastY,$this->GraphAreaX2-$FloatingOffset,$YPos,$BGColor); }
  1985. if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($this->GraphAreaX1+$FloatingOffset,$YPos,$this->GraphAreaX2-$FloatingOffset,$YPos,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  1986. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  1987. $this->drawLine($XPos-$OuterSubTickWidth,$YPos-$SubTicksSize,$XPos+$InnerSubTickWidth,$YPos-$SubTicksSize,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  1988. $this->drawLine($XPos-$InnerTickWidth,$YPos,$XPos+$OuterTickWidth,$YPos,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  1989. $Bounds = $this->drawText($XPos+$OuterTickWidth+2,$YPos,$Value,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
  1990. $TxtLeft = $XPos+$OuterTickWidth+2+($Bounds[1]["X"]-$Bounds[0]["X"]);
  1991. $MaxLeft = max($MaxLeft,$TxtLeft);
  1992. $LastY = $YPos;
  1993. }
  1994. if ( isset($Parameters["Name"]) )
  1995. {
  1996. $XPos = $MaxLeft+6;
  1997. $YPos = $this->GraphAreaY1+($this->GraphAreaY2-$this->GraphAreaY1)/2;
  1998. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE,"Angle"=>270));
  1999. $MaxLeft = $Bounds[2]["X"];
  2000. $this->DataSet->Data["GraphArea"]["X2"] = $MaxLeft + $this->FontSize;
  2001. }
  2002. $AxisPos["R"] = $MaxLeft + $ScaleSpacing;
  2003. }
  2004. }
  2005. elseif ( $Pos == SCALE_POS_TOPBOTTOM )
  2006. {
  2007. if ( $Parameters["Position"] == AXIS_POSITION_TOP )
  2008. {
  2009. if ( $Floating )
  2010. { $FloatingOffset = $XMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  2011. else
  2012. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["T"],$this->GraphAreaX2,$AxisPos["T"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  2013. if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["T"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["T"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  2014. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  2015. $Step = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MinTop = $AxisPos["T"];
  2016. $LastX = NULL;
  2017. for($i=0;$i<=$Parameters["Rows"];$i++)
  2018. {
  2019. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  2020. $YPos = $AxisPos["T"];
  2021. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  2022. if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
  2023. if ( $LastX != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }
  2024. if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  2025. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  2026. $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  2027. $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  2028. $Bounds = $this->drawText($XPos,$YPos-$OuterTickWidth-2,$Value,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2029. $TxtHeight = $YPos-$OuterTickWidth-2-($Bounds[1]["Y"]-$Bounds[2]["Y"]);
  2030. $MinTop = min($MinTop,$TxtHeight);
  2031. $LastX = $XPos;
  2032. }
  2033. if ( isset($Parameters["Name"]) )
  2034. {
  2035. $YPos = $MinTop-2;
  2036. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  2037. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2038. $MinTop = $Bounds[2]["Y"];
  2039. $this->DataSet->Data["GraphArea"]["Y1"] = $MinTop;
  2040. }
  2041. $AxisPos["T"] = $MinTop - $ScaleSpacing;
  2042. }
  2043. elseif ( $Parameters["Position"] == AXIS_POSITION_BOTTOM )
  2044. {
  2045. if ( $Floating )
  2046. { $FloatingOffset = $XMargin; $this->drawLine($this->GraphAreaX1+$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  2047. else
  2048. { $FloatingOffset = 0; $this->drawLine($this->GraphAreaX1,$AxisPos["B"],$this->GraphAreaX2,$AxisPos["B"],array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha)); }
  2049. if ( $DrawArrows ) { $this->drawArrow($this->GraphAreaX2-$Parameters["Margin"],$AxisPos["B"],$this->GraphAreaX2+($ArrowSize*2),$AxisPos["B"],array("FillR"=>$AxisR,"FillG"=>$AxisG,"FillB"=>$AxisB,"Size"=>$ArrowSize)); }
  2050. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Parameters["Margin"]*2;
  2051. $Step = $Width / $Parameters["Rows"]; $SubTicksSize = $Step /2; $MaxBottom = $AxisPos["B"];
  2052. $LastX = NULL;
  2053. for($i=0;$i<=$Parameters["Rows"];$i++)
  2054. {
  2055. $XPos = $this->GraphAreaX1 + $Parameters["Margin"] + $Step*$i;
  2056. $YPos = $AxisPos["B"];
  2057. $Value = $this->scaleFormat($Parameters["ScaleMin"] + $Parameters["RowHeight"]*$i,$Parameters["Display"],$Parameters["Format"],$Parameters["Unit"]);
  2058. if ( $i%2 == 1 ) { $BGColor = array("R"=>$BackgroundR1,"G"=>$BackgroundG1,"B"=>$BackgroundB1,"Alpha"=>$BackgroundAlpha1); } else { $BGColor = array("R"=>$BackgroundR2,"G"=>$BackgroundG2,"B"=>$BackgroundB2,"Alpha"=>$BackgroundAlpha2); }
  2059. if ( $LastX != NULL && $CycleBackground && ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) )) { $this->drawFilledRectangle($LastX,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,$BGColor); }
  2060. if ( $DrawYLines == ALL || in_array($AxisID,$DrawYLines) ) { $this->drawLine($XPos,$this->GraphAreaY1+$FloatingOffset,$XPos,$this->GraphAreaY2-$FloatingOffset,array("R"=>$GridR,"G"=>$GridG,"B"=>$GridB,"Alpha"=>$GridAlpha,"Ticks"=>$GridTicks)); }
  2061. if ( $DrawSubTicks && $i != $Parameters["Rows"] )
  2062. $this->drawLine($XPos+$SubTicksSize,$YPos-$OuterSubTickWidth,$XPos+$SubTicksSize,$YPos+$InnerSubTickWidth,array("R"=>$SubTickR,"G"=>$SubTickG,"B"=>$SubTickB,"Alpha"=>$SubTickAlpha));
  2063. $this->drawLine($XPos,$YPos-$OuterTickWidth,$XPos,$YPos+$InnerTickWidth,array("R"=>$TickR,"G"=>$TickG,"B"=>$TickB,"Alpha"=>$TickAlpha));
  2064. $Bounds = $this->drawText($XPos,$YPos+$OuterTickWidth+2,$Value,array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  2065. $TxtHeight = $YPos+$OuterTickWidth+2+($Bounds[1]["Y"]-$Bounds[2]["Y"]);
  2066. $MaxBottom = max($MaxBottom,$TxtHeight);
  2067. $LastX = $XPos;
  2068. }
  2069. if ( isset($Parameters["Name"]) )
  2070. {
  2071. $YPos = $MaxBottom+2;
  2072. $XPos = $this->GraphAreaX1+($this->GraphAreaX2-$this->GraphAreaX1)/2;
  2073. $Bounds = $this->drawText($XPos,$YPos,$Parameters["Name"],array("Align"=>TEXT_ALIGN_TOPMIDDLE));
  2074. $MaxBottom = $Bounds[0]["Y"];
  2075. $this->DataSet->Data["GraphArea"]["Y2"] = $MaxBottom + $this->FontSize;
  2076. }
  2077. $AxisPos["B"] = $MaxBottom + $ScaleSpacing;
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. function isValidLabel($Value,$LastValue,$LabelingMethod,$ID,$LabelSkip)
  2084. {
  2085. if ( $LabelingMethod == LABELING_DIFFERENT && $Value != $LastValue ) { return(TRUE); }
  2086. if ( $LabelingMethod == LABELING_DIFFERENT && $Value == $LastValue ) { return(FALSE); }
  2087. if ( $LabelingMethod == LABELING_ALL && $LabelSkip == 0 ) { return(TRUE); }
  2088. if ( $LabelingMethod == LABELING_ALL && ($ID+$LabelSkip) % ($LabelSkip+1) != 1 ) { return(FALSE); }
  2089. return(TRUE);
  2090. }
  2091. /* Compute the scale, check for the best visual factors */
  2092. function computeScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID=0)
  2093. {
  2094. /* Compute each factors */
  2095. $Results = "";
  2096. foreach ($Factors as $Key => $Factor)
  2097. $Results[$Factor] = $this->processScale($XMin,$XMax,$MaxDivs,array($Factor),$AxisID);
  2098. /* Remove scales that are creating to much decimals */
  2099. $GoodScaleFactors = "";
  2100. foreach ($Results as $Key => $Result)
  2101. {
  2102. $Decimals = preg_split("/\./",$Result["RowHeight"]);
  2103. if ( (!isset($Decimals[1])) || (strlen($Decimals[1]) < 6) ) { $GoodScaleFactors[] = $Key; }
  2104. }
  2105. /* Found no correct scale, shame,... returns the 1st one as default */
  2106. if ( $GoodScaleFactors == "" ) { return($Results[$Factors[0]]); }
  2107. /* Find the factor that cause the maximum number of Rows */
  2108. $MaxRows = 0; $BestFactor = 0;
  2109. foreach($GoodScaleFactors as $Key => $Factor)
  2110. { if ( $Results[$Factor]["Rows"] > $MaxRows ) { $MaxRows = $Results[$Factor]["Rows"]; $BestFactor = $Factor; } }
  2111. /* Return the best visual scale */
  2112. return($Results[$BestFactor]);
  2113. }
  2114. /* Compute the best matching scale based on size & factors */
  2115. function processScale($XMin,$XMax,$MaxDivs,$Factors,$AxisID)
  2116. {
  2117. $ScaleHeight = abs(ceil($XMax)-floor($XMin));
  2118. if ( isset($this->DataSet->Data["Axis"][$AxisID]["Format"]) )
  2119. $Format = $this->DataSet->Data["Axis"][$AxisID]["Format"];
  2120. else
  2121. $Format = NULL;
  2122. if ( isset($this->DataSet->Data["Axis"][$AxisID]["Display"]) )
  2123. $Mode = $this->DataSet->Data["Axis"][$AxisID]["Display"];
  2124. else
  2125. $Mode = AXIS_FORMAT_DEFAULT;
  2126. $Scale = "";
  2127. if ( $XMin != $XMax )
  2128. {
  2129. $Found = FALSE; $Rescaled = FALSE; $Scaled10Factor = .0001; $Result = 0;
  2130. while(!$Found)
  2131. {
  2132. foreach($Factors as $Key => $Factor)
  2133. {
  2134. if ( !$Found )
  2135. {
  2136. if ( !($this->modulo($XMin,$Factor*$Scaled10Factor) == 0) || ($XMin != floor($XMin))) { $XMinRescaled = floor($XMin/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor; } else { $XMinRescaled = $XMin; }
  2137. if ( !($this->modulo($XMax,$Factor*$Scaled10Factor) == 0) || ($XMax != floor($XMax))) { $XMaxRescaled = floor($XMax/($Factor*$Scaled10Factor))*$Factor*$Scaled10Factor+($Factor*$Scaled10Factor); } else { $XMaxRescaled = $XMax; }
  2138. $ScaleHeightRescaled = abs($XMaxRescaled-$XMinRescaled);
  2139. if ( !$Found && floor($ScaleHeightRescaled/($Factor*$Scaled10Factor)) <= $MaxDivs ) { $Found = TRUE; $Rescaled = TRUE; $Result = $Factor * $Scaled10Factor; }
  2140. }
  2141. }
  2142. $Scaled10Factor = $Scaled10Factor * 10;
  2143. }
  2144. /* ReCall Min / Max / Height */
  2145. if ( $Rescaled ) { $XMin = $XMinRescaled; $XMax = $XMaxRescaled; $ScaleHeight = $ScaleHeightRescaled; }
  2146. /* Compute rows size */
  2147. $Rows = floor($ScaleHeight / $Result); if ( $Rows == 0 ) { $Rows = 1; }
  2148. $RowHeight = $ScaleHeight / $Rows;
  2149. /* Return the results */
  2150. $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin; $Scale["XMax"] = $XMax;
  2151. /* Compute the needed decimals for the metric view to avoid repetition of the same X Axis labels */
  2152. if ( $Mode == AXIS_FORMAT_METRIC && $Format == NULL )
  2153. {
  2154. $Done = FALSE; $GoodDecimals = 0;
  2155. for($Decimals=0;$Decimals<=10;$Decimals++)
  2156. {
  2157. if ( !$Done )
  2158. {
  2159. $LastLabel = "zob"; $ScaleOK = TRUE;
  2160. for($i=0;$i<=$Rows;$i++)
  2161. {
  2162. $Value = $XMin + $i*$RowHeight;
  2163. $Label = $this->scaleFormat($Value,AXIS_FORMAT_METRIC,$Decimals);
  2164. if ( $LastLabel == $Label ) { $ScaleOK = FALSE; }
  2165. $LastLabel = $Label;
  2166. }
  2167. if ( $ScaleOK ) { $Done = TRUE; $GoodDecimals = $Decimals; }
  2168. }
  2169. }
  2170. $Scale["Format"] = $GoodDecimals;
  2171. }
  2172. }
  2173. else
  2174. {
  2175. /* If all values are the same we keep a +1/-1 scale */
  2176. $Rows = 2; $XMin = $XMax-1; $XMax = $XMax+1; $RowHeight = 1;
  2177. /* Return the results */
  2178. $Scale["Rows"] = $Rows; $Scale["RowHeight"] = $RowHeight; $Scale["XMin"] = $XMin; $Scale["XMax"] = $XMax;
  2179. }
  2180. return($Scale);
  2181. }
  2182. function modulo($Value1,$Value2)
  2183. {
  2184. if (floor($Value2) == 0) { return(0); }
  2185. if (floor($Value2) != 0) { return($Value1 % $Value2); }
  2186. $MinValue = min($Value1,$Value2); $Factor = 10;
  2187. while ( floor($MinValue*$Factor) == 0 )
  2188. { $Factor = $Factor * 10; }
  2189. return(($Value1*$Factor) % ($Value2*$Factor));
  2190. }
  2191. /* Draw an X threshold */
  2192. function drawXThreshold($Value,$Format="")
  2193. {
  2194. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2195. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2196. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2197. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
  2198. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  2199. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
  2200. $Wide = isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
  2201. $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
  2202. $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
  2203. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : NULL;
  2204. $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
  2205. $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 5;
  2206. $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
  2207. $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
  2208. $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
  2209. $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
  2210. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2211. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2212. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 3;
  2213. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2214. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2215. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2216. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2217. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2218. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 30;
  2219. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2220. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2221. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2222. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2223. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2224. $ValueIsLabel = isset($Format["ValueIsLabel"]) ? $Format["ValueIsLabel"] : FALSE;
  2225. $Data = $this->DataSet->getData();
  2226. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2227. $XScale = $this->scaleGetXSettings();
  2228. if ( is_array($Value) ) { foreach ($Value as $Key => $ID) { $this->drawXThreshold($ID,$Format); } return(0); }
  2229. if ( $ValueIsLabel )
  2230. {
  2231. $Format["ValueIsLabel"] = FALSE;
  2232. foreach($Data["Series"][$Data["Abscissa"]]["Data"] as $Key => $SerieValue)
  2233. { if ( $SerieValue == $Value ) { $this->drawXThreshold($Key,$Format); } }
  2234. return(0);
  2235. }
  2236. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2237. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2238. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
  2239. "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);
  2240. if ( $Caption == NULL )
  2241. {
  2242. if ( isset($Data["Abscissa"]) )
  2243. {
  2244. if ( isset($Data["Series"][$Data["Abscissa"]]["Data"][$Value]) )
  2245. $Caption = $Data["Series"][$Data["Abscissa"]]["Data"][$Value];
  2246. else
  2247. $Caption = $Value;
  2248. }
  2249. else
  2250. $Caption = $Value;
  2251. }
  2252. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2253. {
  2254. $XStep = (($this->GraphAreaX2 - $this->GraphAreaX1) - $XScale[0] *2 ) / $XScale[1];
  2255. $XPos = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value;
  2256. $YPos1 = $this->GraphAreaY1 + $Data["YMargin"];
  2257. $YPos2 = $this->GraphAreaY2 - $Data["YMargin"];
  2258. if ( $XPos >= $this->GraphAreaX1 + $AbscissaMargin && $XPos <= $this->GraphAreaX2 - $AbscissaMargin )
  2259. {
  2260. $this->drawLine($XPos,$YPos1,$XPos,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2261. if ( $Wide )
  2262. {
  2263. $this->drawLine($XPos-1,$YPos1,$XPos-1,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2264. $this->drawLine($XPos+1,$YPos1,$XPos+1,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2265. }
  2266. if ( $WriteCaption )
  2267. {
  2268. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2269. { $Y = $YPos1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
  2270. else
  2271. { $Y = $YPos2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
  2272. $this->drawText($XPos,$Y,$Caption,$CaptionSettings);
  2273. }
  2274. return(array("X"=>$XPos));
  2275. }
  2276. }
  2277. elseif( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2278. {
  2279. $XStep = (($this->GraphAreaY2 - $this->GraphAreaY1) - $XScale[0] *2 ) / $XScale[1];
  2280. $XPos = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value;
  2281. $YPos1 = $this->GraphAreaX1 + $Data["YMargin"];
  2282. $YPos2 = $this->GraphAreaX2 - $Data["YMargin"];
  2283. if ( $XPos >= $this->GraphAreaY1 + $AbscissaMargin && $XPos <= $this->GraphAreaY2 - $AbscissaMargin )
  2284. {
  2285. $this->drawLine($YPos1,$XPos,$YPos2,$XPos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2286. if ( $Wide )
  2287. {
  2288. $this->drawLine($YPos1,$XPos-1,$YPos2,$XPos-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2289. $this->drawLine($YPos1,$XPos+1,$YPos2,$XPos+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2290. }
  2291. if ( $WriteCaption )
  2292. {
  2293. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2294. { $Y = $YPos1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
  2295. else
  2296. { $Y = $YPos2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
  2297. $this->drawText($Y,$XPos,$Caption,$CaptionSettings);
  2298. }
  2299. return(array("X"=>$XPos));
  2300. }
  2301. }
  2302. }
  2303. /* Draw an X threshold area */
  2304. function drawXThresholdArea($Value1,$Value2,$Format="")
  2305. {
  2306. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2307. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2308. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2309. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
  2310. $Border = isset($Format["Border"]) ? $Format["Border"] : TRUE;
  2311. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  2312. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  2313. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  2314. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
  2315. $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
  2316. $AreaName = isset($Format["AreaName"]) ? $Format["AreaName"] : NULL;
  2317. $NameAngle = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
  2318. $NameR = isset($Format["NameR"]) ? $Format["NameR"] : 255;
  2319. $NameG = isset($Format["NameG"]) ? $Format["NameG"] : 255;
  2320. $NameB = isset($Format["NameB"]) ? $Format["NameB"] : 255;
  2321. $NameAlpha = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
  2322. $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : TRUE;
  2323. $RestoreShadow = $this->Shadow;
  2324. if ( $DisableShadowOnArea && $this->Shadow ) { $this->Shadow = FALSE; }
  2325. if ($BorderAlpha >100) { $BorderAlpha = 100;}
  2326. $Data = $this->DataSet->getData();
  2327. $XScale = $this->scaleGetXSettings();
  2328. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2329. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2330. {
  2331. $XStep = (($this->GraphAreaX2 - $this->GraphAreaX1) - $XScale[0] *2 ) / $XScale[1];
  2332. $XPos1 = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value1;
  2333. $XPos2 = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value2;
  2334. $YPos1 = $this->GraphAreaY1 + $Data["YMargin"];
  2335. $YPos2 = $this->GraphAreaY2 - $Data["YMargin"];
  2336. if ( $XPos1 < $this->GraphAreaX1 + $XScale[0] ) { $XPos1 = $this->GraphAreaX1 + $XScale[0]; }
  2337. if ( $XPos1 > $this->GraphAreaX2 - $XScale[0] ) { $XPos1 = $this->GraphAreaX2 - $XScale[0]; }
  2338. if ( $XPos2 < $this->GraphAreaX1 + $XScale[0] ) { $XPos2 = $this->GraphAreaX1 + $XScale[0]; }
  2339. if ( $XPos2 > $this->GraphAreaX2 - $XScale[0] ) { $XPos2 = $this->GraphAreaX2 - $XScale[0]; }
  2340. $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2341. if ( $Border )
  2342. {
  2343. $this->drawLine($XPos1,$YPos1,$XPos1,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2344. $this->drawLine($XPos2,$YPos1,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2345. }
  2346. if ( $AreaName != NULL )
  2347. {
  2348. $XPos = ($XPos2-$XPos1)/2 + $XPos1;
  2349. $YPos = ($YPos2-$YPos1)/2 + $YPos1;
  2350. if ( $NameAngle == ZONE_NAME_ANGLE_AUTO )
  2351. {
  2352. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$AreaName);
  2353. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
  2354. if ( abs($XPos2 - $XPos1) > $TxtWidth ) { $NameAngle = 0; } else { $NameAngle = 90; }
  2355. }
  2356. $this->Shadow = $RestoreShadow;
  2357. $this->drawText($XPos,$YPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>$NameAngle,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2358. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2359. }
  2360. $this->Shadow = $RestoreShadow;
  2361. return(array("X1"=>$XPos1,"X2"=>$XPos2));
  2362. }
  2363. elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2364. {
  2365. $XStep = (($this->GraphAreaY2 - $this->GraphAreaY1) - $XScale[0] *2 ) / $XScale[1];
  2366. $XPos1 = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value1;
  2367. $XPos2 = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value2;
  2368. $YPos1 = $this->GraphAreaX1 + $Data["YMargin"];
  2369. $YPos2 = $this->GraphAreaX2 - $Data["YMargin"];
  2370. if ( $XPos1 < $this->GraphAreaY1 + $XScale[0] ) { $XPos1 = $this->GraphAreaY1 + $XScale[0]; }
  2371. if ( $XPos1 > $this->GraphAreaY2 - $XScale[0] ) { $XPos1 = $this->GraphAreaY2 - $XScale[0]; }
  2372. if ( $XPos2 < $this->GraphAreaY1 + $XScale[0] ) { $XPos2 = $this->GraphAreaY1 + $XScale[0]; }
  2373. if ( $XPos2 > $this->GraphAreaY2 - $XScale[0] ) { $XPos2 = $this->GraphAreaY2 - $XScale[0]; }
  2374. $this->drawFilledRectangle($YPos1,$XPos1,$YPos2,$XPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2375. if ( $Border )
  2376. {
  2377. $this->drawLine($YPos1,$XPos1,$YPos2,$XPos1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2378. $this->drawLine($YPos1,$XPos2,$YPos2,$XPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2379. }
  2380. if ( $AreaName != NULL )
  2381. {
  2382. $XPos = ($XPos2-$XPos1)/2 + $XPos1;
  2383. $YPos = ($YPos2-$YPos1)/2 + $YPos1;
  2384. $this->Shadow = $RestoreShadow;
  2385. $this->drawText($YPos,$XPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2386. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2387. }
  2388. $this->Shadow = $RestoreShadow;
  2389. return(array("X1"=>$XPos1,"X2"=>$XPos2));
  2390. }
  2391. }
  2392. /* Draw an Y threshold with the computed scale */
  2393. function drawThreshold($Value,$Format="")
  2394. {
  2395. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  2396. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2397. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2398. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2399. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 50;
  2400. $Weight = isset($Format["Weight"]) ? $Format["Weight"] : NULL;
  2401. $Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 6;
  2402. $Wide = isset($Format["Wide"]) ? $Format["Wide"] : FALSE;
  2403. $WideFactor = isset($Format["WideFactor"]) ? $Format["WideFactor"] : 5;
  2404. $WriteCaption = isset($Format["WriteCaption"]) ? $Format["WriteCaption"] : FALSE;
  2405. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : NULL;
  2406. $CaptionAlign = isset($Format["CaptionAlign"]) ? $Format["CaptionAlign"] : CAPTION_LEFT_TOP;
  2407. $CaptionOffset = isset($Format["CaptionOffset"]) ? $Format["CaptionOffset"] : 10;
  2408. $CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
  2409. $CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
  2410. $CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
  2411. $CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
  2412. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2413. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2414. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
  2415. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2416. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2417. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2418. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2419. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2420. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
  2421. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2422. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2423. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2424. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2425. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2426. $NoMargin = isset($Format["NoMargin"]) ? $Format["NoMargin"] : FALSE;
  2427. if ( is_array($Value) ) { foreach ($Value as $Key => $ID) { $this->drawThreshold($ID,$Format); } return(0); }
  2428. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2429. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2430. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha,
  2431. "R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha);
  2432. $Data = $this->DataSet->getData();
  2433. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2434. if ( $NoMargin ) { $AbscissaMargin = 0; }
  2435. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2436. if ( $Caption == NULL ) { $Caption = $Value; }
  2437. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2438. {
  2439. $YPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
  2440. if ( $YPos >= $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"] && $YPos <= $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"] )
  2441. {
  2442. $X1 = $this->GraphAreaX1 + $AbscissaMargin;
  2443. $X2 = $this->GraphAreaX2 - $AbscissaMargin;
  2444. $this->drawLine($X1,$YPos,$X2,$YPos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2445. if ( $Wide )
  2446. {
  2447. $this->drawLine($X1,$YPos-1,$X2,$YPos-1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2448. $this->drawLine($X1,$YPos+1,$X2,$YPos+1,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2449. }
  2450. if ( $WriteCaption )
  2451. {
  2452. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2453. { $X = $X1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
  2454. else
  2455. { $X = $X2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
  2456. $this->drawText($X,$YPos,$Caption,$CaptionSettings);
  2457. }
  2458. }
  2459. return(array("Y"=>$YPos));
  2460. }
  2461. if ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2462. {
  2463. $XPos = $this->scaleComputeY($Value,array("AxisID"=>$AxisID));
  2464. if ( $XPos >= $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"] && $XPos <= $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"] )
  2465. {
  2466. $Y1 = $this->GraphAreaY1 + $AbscissaMargin;
  2467. $Y2 = $this->GraphAreaY2 - $AbscissaMargin;
  2468. $this->drawLine($XPos,$Y1,$XPos,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2469. if ( $Wide )
  2470. {
  2471. $this->drawLine($XPos-1,$Y1,$XPos-1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2472. $this->drawLine($XPos+1,$Y1,$XPos+1,$Y2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/$WideFactor,"Ticks"=>$Ticks));
  2473. }
  2474. if ( $WriteCaption )
  2475. {
  2476. if ( $CaptionAlign == CAPTION_LEFT_TOP )
  2477. { $Y = $Y1 + $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
  2478. else
  2479. { $Y = $Y2 - $CaptionOffset; $CaptionSettings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
  2480. $CaptionSettings["Align"] = TEXT_ALIGN_TOPMIDDLE;
  2481. $this->drawText($XPos,$Y,$Caption,$CaptionSettings);
  2482. }
  2483. }
  2484. return(array("Y"=>$XPos));
  2485. }
  2486. }
  2487. /* Draw a threshold with the computed scale */
  2488. function drawThresholdArea($Value1,$Value2,$Format="")
  2489. {
  2490. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  2491. $R = isset($Format["R"]) ? $Format["R"] : 255;
  2492. $G = isset($Format["G"]) ? $Format["G"] : 0;
  2493. $B = isset($Format["B"]) ? $Format["B"] : 0;
  2494. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
  2495. $Border = isset($Format["Border"]) ? $Format["Border"] : TRUE;
  2496. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  2497. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  2498. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  2499. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
  2500. $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
  2501. $AreaName = isset($Format["AreaName"]) ? $Format["AreaName"] : NULL;
  2502. $NameAngle = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
  2503. $NameR = isset($Format["NameR"]) ? $Format["NameR"] : 255;
  2504. $NameG = isset($Format["NameG"]) ? $Format["NameG"] : 255;
  2505. $NameB = isset($Format["NameB"]) ? $Format["NameB"] : 255;
  2506. $NameAlpha = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
  2507. $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : TRUE;
  2508. $NoMargin = isset($Format["NoMargin"]) ? $Format["NoMargin"] : FALSE;
  2509. if ($Value1 > $Value2) { list($Value1, $Value2) = array($Value2, $Value1); }
  2510. $RestoreShadow = $this->Shadow;
  2511. if ( $DisableShadowOnArea && $this->Shadow ) { $this->Shadow = FALSE; }
  2512. if ($BorderAlpha >100) { $BorderAlpha = 100;}
  2513. $Data = $this->DataSet->getData();
  2514. $AbscissaMargin = $this->getAbscissaMargin($Data);
  2515. if ( $NoMargin ) { $AbscissaMargin = 0; }
  2516. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2517. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2518. {
  2519. $XPos1 = $this->GraphAreaX1 + $AbscissaMargin;
  2520. $XPos2 = $this->GraphAreaX2 - $AbscissaMargin;
  2521. $YPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
  2522. $YPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));
  2523. if ( $YPos1 < $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"] ) { $YPos1 = $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"]; }
  2524. if ( $YPos1 > $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"] ) { $YPos1 = $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"]; }
  2525. if ( $YPos2 < $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"] ) { $YPos2 = $this->GraphAreaY1+$Data["Axis"][$AxisID]["Margin"]; }
  2526. if ( $YPos2 > $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"] ) { $YPos2 = $this->GraphAreaY2-$Data["Axis"][$AxisID]["Margin"]; }
  2527. $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2528. if ( $Border )
  2529. {
  2530. $this->drawLine($XPos1,$YPos1,$XPos2,$YPos1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2531. $this->drawLine($XPos1,$YPos2,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2532. }
  2533. if ( $AreaName != NULL )
  2534. {
  2535. $XPos = ($XPos2-$XPos1)/2 + $XPos1;
  2536. $YPos = ($YPos2-$YPos1)/2 + $YPos1;
  2537. $this->Shadow = $RestoreShadow;
  2538. $this->drawText($XPos,$YPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2539. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2540. }
  2541. $this->Shadow = $RestoreShadow;
  2542. return(array("Y1"=>$YPos1,"Y2"=>$YPos2));
  2543. }
  2544. elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  2545. {
  2546. $YPos1 = $this->GraphAreaY1 + $AbscissaMargin;
  2547. $YPos2 = $this->GraphAreaY2 - $AbscissaMargin;
  2548. $XPos1 = $this->scaleComputeY($Value1,array("AxisID"=>$AxisID));
  2549. $XPos2 = $this->scaleComputeY($Value2,array("AxisID"=>$AxisID));
  2550. if ( $XPos1 < $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"] ) { $XPos1 = $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"]; }
  2551. if ( $XPos1 > $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"] ) { $XPos1 = $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"]; }
  2552. if ( $XPos2 < $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"] ) { $XPos2 = $this->GraphAreaX1+$Data["Axis"][$AxisID]["Margin"]; }
  2553. if ( $XPos2 > $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"] ) { $XPos2 = $this->GraphAreaX2-$Data["Axis"][$AxisID]["Margin"]; }
  2554. $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  2555. if ( $Border )
  2556. {
  2557. $this->drawLine($XPos1,$YPos1,$XPos1,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2558. $this->drawLine($XPos2,$YPos1,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
  2559. }
  2560. if ( $AreaName != NULL )
  2561. {
  2562. $XPos = ($YPos2-$YPos1)/2 + $YPos1;
  2563. $YPos = ($XPos2-$XPos1)/2 + $XPos1;
  2564. if ( $NameAngle == ZONE_NAME_ANGLE_AUTO )
  2565. {
  2566. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$AreaName);
  2567. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
  2568. if ( abs($XPos2 - $XPos1) > $TxtWidth ) { $NameAngle = 0; } else { $NameAngle = 90; }
  2569. }
  2570. $this->Shadow = $RestoreShadow;
  2571. $this->drawText($YPos,$XPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>$NameAngle,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
  2572. if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
  2573. }
  2574. $this->Shadow = $RestoreShadow;
  2575. return(array("Y1"=>$XPos1,"Y2"=>$XPos2));
  2576. }
  2577. }
  2578. function scaleGetXSettings()
  2579. {
  2580. $Data = $this->DataSet->getData();
  2581. foreach($Data["Axis"] as $AxisID => $Settings)
  2582. {
  2583. if ( $Settings["Identity"] == AXIS_X )
  2584. {
  2585. $Rows = $Settings["Rows"];
  2586. return(array($Settings["Margin"],$Rows));
  2587. }
  2588. }
  2589. }
  2590. function scaleComputeY($Values,$Option="",$ReturnOnly0Height=FALSE)
  2591. {
  2592. $AxisID = isset($Option["AxisID"]) ? $Option["AxisID"] : 0;
  2593. $SerieName = isset($Option["SerieName"]) ? $Option["SerieName"] : NULL;
  2594. $Data = $this->DataSet->getData();
  2595. if ( !isset($Data["Axis"][$AxisID]) ) { return(-1); }
  2596. if ( $SerieName != NULL ) { $AxisID = $Data["Series"][$SerieName]["Axis"]; }
  2597. if ( !is_array($Values) ) { $tmp = $Values; $Values = ""; $Values[0] = $tmp; }
  2598. $Result = "";
  2599. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2600. {
  2601. $Height = ($this->GraphAreaY2 - $this->GraphAreaY1) - $Data["Axis"][$AxisID]["Margin"]*2;
  2602. $ScaleHeight = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  2603. $Step = $Height / $ScaleHeight;
  2604. if ( $ReturnOnly0Height )
  2605. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
  2606. else
  2607. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaY2 - $Data["Axis"][$AxisID]["Margin"] - ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
  2608. }
  2609. else
  2610. {
  2611. $Width = ($this->GraphAreaX2 - $this->GraphAreaX1) - $Data["Axis"][$AxisID]["Margin"]*2;
  2612. $ScaleWidth = $Data["Axis"][$AxisID]["ScaleMax"] - $Data["Axis"][$AxisID]["ScaleMin"];
  2613. $Step = $Width / $ScaleWidth;
  2614. if ( $ReturnOnly0Height )
  2615. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $Step * $Value; } } }
  2616. else
  2617. { foreach($Values as $Key => $Value) { if ( $Value == VOID ) { $Result[] = VOID; } else { $Result[] = $this->GraphAreaX1 + $Data["Axis"][$AxisID]["Margin"] + ($Step * ($Value-$Data["Axis"][$AxisID]["ScaleMin"])); } } }
  2618. }
  2619. if ( count($Result) == 1 )
  2620. return($Result[0]);
  2621. else
  2622. return($Result);
  2623. }
  2624. /* Format the axis values */
  2625. function scaleFormat($Value,$Mode=NULL,$Format=NULL,$Unit=NULL)
  2626. {
  2627. if ( $Value == VOID ) { return(""); }
  2628. if ( $Mode == AXIS_FORMAT_TRAFFIC )
  2629. {
  2630. if ( $Value == 0 ) { return("0B"); }
  2631. $Units = array("B","KB","MB","GB","TB","PB");
  2632. $Sign = ""; if ( $Value < 0 ) { $Value = abs($Value); $Sign = "-"; }
  2633. $Value = number_format($Value/pow(1024,($Scale=floor(log($Value,1024)))),2,",",".");
  2634. return($Sign.$Value." ".$Units[$Scale]);
  2635. }
  2636. if ( $Mode == AXIS_FORMAT_CUSTOM )
  2637. { if ( function_exists($Format) ) { return(call_user_func($Format,$Value)); } }
  2638. if ( $Mode == AXIS_FORMAT_DATE )
  2639. { if ( $Format == NULL ) { $Pattern = "d/m/Y"; } else { $Pattern = $Format; } return(gmdate($Pattern,$Value)); }
  2640. if ( $Mode == AXIS_FORMAT_TIME )
  2641. { if ( $Format == NULL ) { $Pattern = "H:i:s"; } else { $Pattern = $Format; } return(gmdate($Pattern,$Value)); }
  2642. if ( $Mode == AXIS_FORMAT_CURRENCY )
  2643. { return($Format.number_format($Value,2)); }
  2644. if ( $Mode == AXIS_FORMAT_METRIC )
  2645. {
  2646. if (abs($Value) > 1000000000)
  2647. return(round($Value/1000000000,$Format)."g".$Unit);
  2648. if (abs($Value) > 1000000)
  2649. return(round($Value/1000000,$Format)."m".$Unit);
  2650. elseif (abs($Value) >= 1000)
  2651. return(round($Value/1000,$Format)."k".$Unit);
  2652. }
  2653. return($Value.$Unit);
  2654. }
  2655. /* Write Max value on a chart */
  2656. function writeBounds($Type=BOUND_BOTH,$Format=NULL)
  2657. {
  2658. $MaxLabelTxt = isset($Format["MaxLabelTxt"]) ? $Format["MaxLabelTxt"] : "max=";
  2659. $MinLabelTxt = isset($Format["MinLabelTxt"]) ? $Format["MinLabelTxt"] : "min=";
  2660. $Decimals = isset($Format["Decimals"]) ? $Format["Decimals"] : 1;
  2661. $ExcludedSeries = isset($Format["ExcludedSeries"]) ? $Format["ExcludedSeries"] : "";
  2662. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
  2663. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2664. $MaxDisplayR = isset($Format["MaxDisplayR"]) ? $Format["MaxDisplayR"] : 0;
  2665. $MaxDisplayG = isset($Format["MaxDisplayG"]) ? $Format["MaxDisplayG"] : 0;
  2666. $MaxDisplayB = isset($Format["MaxDisplayB"]) ? $Format["MaxDisplayB"] : 0;
  2667. $MinDisplayR = isset($Format["MinDisplayR"]) ? $Format["MinDisplayR"] : 255;
  2668. $MinDisplayG = isset($Format["MinDisplayG"]) ? $Format["MinDisplayG"] : 255;
  2669. $MinDisplayB = isset($Format["MinDisplayB"]) ? $Format["MinDisplayB"] : 255;
  2670. $MinLabelPos = isset($Format["MinLabelPos"]) ? $Format["MinLabelPos"] : BOUND_LABEL_POS_AUTO;
  2671. $MaxLabelPos = isset($Format["MaxLabelPos"]) ? $Format["MaxLabelPos"] : BOUND_LABEL_POS_AUTO;
  2672. $DrawBox = isset($Format["DrawBox"]) ? $Format["DrawBox"] : TRUE;
  2673. $DrawBoxBorder = isset($Format["DrawBoxBorder"]) ? $Format["DrawBoxBorder"] : FALSE;
  2674. $BorderOffset = isset($Format["BorderOffset"]) ? $Format["BorderOffset"] : 5;
  2675. $BoxRounded = isset($Format["BoxRounded"]) ? $Format["BoxRounded"] : TRUE;
  2676. $RoundedRadius = isset($Format["RoundedRadius"]) ? $Format["RoundedRadius"] : 3;
  2677. $BoxR = isset($Format["BoxR"]) ? $Format["BoxR"] : 0;
  2678. $BoxG = isset($Format["BoxG"]) ? $Format["BoxG"] : 0;
  2679. $BoxB = isset($Format["BoxB"]) ? $Format["BoxB"] : 0;
  2680. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 20;
  2681. $BoxSurrounding = isset($Format["BoxSurrounding"]) ? $Format["BoxSurrounding"] : "";
  2682. $BoxBorderR = isset($Format["BoxBorderR"]) ? $Format["BoxBorderR"] : 255;
  2683. $BoxBorderG = isset($Format["BoxBorderG"]) ? $Format["BoxBorderG"] : 255;
  2684. $BoxBorderB = isset($Format["BoxBorderB"]) ? $Format["BoxBorderB"] : 255;
  2685. $BoxBorderAlpha = isset($Format["BoxBorderAlpha"]) ? $Format["BoxBorderAlpha"] : 100;
  2686. $CaptionSettings = array("DrawBox"=>$DrawBox,"DrawBoxBorder"=>$DrawBoxBorder,"BorderOffset"=>$BorderOffset,"BoxRounded"=>$BoxRounded,"RoundedRadius"=>$RoundedRadius,
  2687. "BoxR"=>$BoxR,"BoxG"=>$BoxG,"BoxB"=>$BoxB,"BoxAlpha"=>$BoxAlpha,"BoxSurrounding"=>$BoxSurrounding,
  2688. "BoxBorderR"=>$BoxBorderR,"BoxBorderG"=>$BoxBorderG,"BoxBorderB"=>$BoxBorderB,"BoxBorderAlpha"=>$BoxBorderAlpha);
  2689. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2690. $Data = $this->DataSet->getData();
  2691. foreach($Data["Series"] as $SerieName => $Serie)
  2692. {
  2693. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] && !isset($ExcludedSeries[$SerieName]))
  2694. {
  2695. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2696. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2697. $MinValue = $this->DataSet->getMin($SerieName);
  2698. $MaxValue = $this->DataSet->getMax($SerieName);
  2699. $MinPos = VOID; $MaxPos = VOID;
  2700. foreach($Serie["Data"] as $Key => $Value)
  2701. {
  2702. if ( $Value == $MinValue && $MinPos == VOID ) { $MinPos = $Key; }
  2703. if ( $Value == $MaxValue ) { $MaxPos = $Key; }
  2704. }
  2705. $AxisID = $Serie["Axis"];
  2706. $Mode = $Data["Axis"][$AxisID]["Display"];
  2707. $Format = $Data["Axis"][$AxisID]["Format"];
  2708. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2709. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2710. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2711. {
  2712. $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs;
  2713. $X = $this->GraphAreaX1 + $XMargin;
  2714. $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
  2715. if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
  2716. {
  2717. if ( $MaxLabelPos == BOUND_LABEL_POS_TOP || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
  2718. if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }
  2719. $XPos = $X + $MaxPos*$XStep + $SerieOffset;
  2720. $Label = $MaxLabelTxt.$this->scaleFormat(round($MaxValue,$Decimals),$Mode,$Format,$Unit);
  2721. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
  2722. $XOffset = 0; $YOffset = 0;
  2723. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
  2724. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
  2725. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
  2726. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }
  2727. $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
  2728. $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;
  2729. $this->drawText($XPos+$XOffset,$YPos+$YOffset,$Label,$CaptionSettings);
  2730. }
  2731. if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
  2732. {
  2733. if ( $MinLabelPos == BOUND_LABEL_POS_TOP || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_BOTTOMMIDDLE; }
  2734. if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_TOPMIDDLE; }
  2735. $XPos = $X + $MinPos*$XStep + $SerieOffset;
  2736. $Label = $MinLabelTxt.$this->scaleFormat(round($MinValue,$Decimals),$Mode,$Format,$Unit);
  2737. $TxtPos = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$Label);
  2738. $XOffset = 0; $YOffset = 0;
  2739. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = (($this->GraphAreaX1 - $TxtPos[0]["X"])/2); }
  2740. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -(($TxtPos[1]["X"] - $this->GraphAreaX2)/2); }
  2741. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $TxtPos[2]["Y"]; }
  2742. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -($TxtPos[0]["Y"] - $this->GraphAreaY2); }
  2743. $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
  2744. $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;
  2745. $this->drawText($XPos+$XOffset,$YPos-$DisplayOffset+$YOffset,$Label,$CaptionSettings);
  2746. }
  2747. }
  2748. else
  2749. {
  2750. $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs;
  2751. $X = $this->GraphAreaY1 + $XMargin;
  2752. $SerieOffset = isset($Serie["XOffset"]) ? $Serie["XOffset"] : 0;
  2753. if ( $Type == BOUND_MAX || $Type == BOUND_BOTH )
  2754. {
  2755. if ( $MaxLabelPos == BOUND_LABEL_POS_TOP || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue >= 0) ) { $YPos = $PosArray[$MaxPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
  2756. if ( $MaxLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MaxLabelPos == BOUND_LABEL_POS_AUTO && $MaxValue < 0) ) { $YPos = $PosArray[$MaxPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }
  2757. $XPos = $X + $MaxPos*$XStep + $SerieOffset;
  2758. $Label = $MaxLabelTxt.$this->scaleFormat($MaxValue,$Mode,$Format,$Unit);
  2759. $TxtPos = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
  2760. $XOffset = 0; $YOffset = 0;
  2761. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
  2762. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
  2763. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
  2764. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}
  2765. $CaptionSettings["R"] = $MaxDisplayR; $CaptionSettings["G"] = $MaxDisplayG;
  2766. $CaptionSettings["B"] = $MaxDisplayB; $CaptionSettings["Align"] = $Align;
  2767. $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
  2768. }
  2769. if ( $Type == BOUND_MIN || $Type == BOUND_BOTH )
  2770. {
  2771. if ( $MinLabelPos == BOUND_LABEL_POS_TOP || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue >= 0) ) { $YPos = $PosArray[$MinPos] + $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLELEFT; }
  2772. if ( $MinLabelPos == BOUND_LABEL_POS_BOTTOM || ( $MinLabelPos == BOUND_LABEL_POS_AUTO && $MinValue < 0) ) { $YPos = $PosArray[$MinPos] - $DisplayOffset + 2; $Align = TEXT_ALIGN_MIDDLERIGHT; }
  2773. $XPos = $X + $MinPos*$XStep + $SerieOffset;
  2774. $Label = $MinLabelTxt.$this->scaleFormat($MinValue,$Mode,$Format,$Unit);
  2775. $TxtPos = $this->getTextBox($YPos,$XPos,$this->FontName,$this->FontSize,0,$Label);
  2776. $XOffset = 0; $YOffset = 0;
  2777. if ( $TxtPos[0]["X"] < $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $TxtPos[0]["X"]; }
  2778. if ( $TxtPos[1]["X"] > $this->GraphAreaX2 ) { $XOffset = -($TxtPos[1]["X"] - $this->GraphAreaX2); }
  2779. if ( $TxtPos[2]["Y"] < $this->GraphAreaY1 ) { $YOffset = ($this->GraphAreaY1 - $TxtPos[2]["Y"])/2; }
  2780. if ( $TxtPos[0]["Y"] > $this->GraphAreaY2 ) { $YOffset = -(($TxtPos[0]["Y"] - $this->GraphAreaY2)/2);}
  2781. $CaptionSettings["R"] = $MinDisplayR; $CaptionSettings["G"] = $MinDisplayG;
  2782. $CaptionSettings["B"] = $MinDisplayB; $CaptionSettings["Align"] = $Align;
  2783. $this->drawText($YPos+$XOffset,$XPos+$YOffset,$Label,$CaptionSettings);
  2784. }
  2785. }
  2786. }
  2787. }
  2788. }
  2789. /* Draw a plot chart */
  2790. function drawPlotChart($Format=NULL)
  2791. {
  2792. $PlotSize = isset($Format["PlotSize"]) ? $Format["PlotSize"] : NULL;
  2793. $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : FALSE;
  2794. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 50;
  2795. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 50;
  2796. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 50;
  2797. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
  2798. $BorderSize = isset($Format["BorderSize"]) ? $Format["BorderSize"] : 2;
  2799. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  2800. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2801. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 4;
  2802. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2803. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2804. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2805. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2806. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  2807. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  2808. $Data = $this->DataSet->getData();
  2809. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2810. $num = 1;
  2811. foreach($Data["Series"] as $SerieName => $Serie)
  2812. {
  2813. //crea
  2814. if($num == 1){
  2815. $Serie['Shape'] = SERIE_SHAPE_TRIANGLE;
  2816. }elseif($num == 2){
  2817. // $Serie['Shape'] = SERIE_SHAPE_CIRCLE;
  2818. $Serie['Shape'] = SERIE_SHAPE_DIAMOND;
  2819. }elseif($num == 3){
  2820. $Serie['Shape'] = SERIE_SHAPE_SQUARE;
  2821. }
  2822. $num++;
  2823. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2824. {
  2825. if ( isset($Serie["Weight"]) ) { $SerieWeight = $Serie["Weight"] + 2; } else { $SerieWeight = 2; }
  2826. if ( $PlotSize != NULL ) { $SerieWeight = $PlotSize; }
  2827. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2828. if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
  2829. if ( isset($Serie["Picture"]) )
  2830. { $Picture = $Serie["Picture"]; list($PicWidth,$PicHeight,$PicType) = $this->getPicInfo($Picture); }
  2831. else { $Picture = NULL; $PicOffset = 0; }
  2832. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2833. $AxisID = $Serie["Axis"];
  2834. $Shape = $Serie["Shape"];
  2835. $Mode = $Data["Axis"][$AxisID]["Display"];
  2836. $Format = $Data["Axis"][$AxisID]["Format"];
  2837. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2838. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  2839. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2840. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2841. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2842. {
  2843. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2844. if ( $Picture != NULL ) { $PicOffset = $PicHeight / 2; $SerieWeight = 0; }
  2845. $X = $this->GraphAreaX1 + $XMargin;
  2846. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2847. foreach($PosArray as $Key => $Y)
  2848. {
  2849. if ( $DisplayValues )
  2850. $this->drawText($X,$Y-$DisplayOffset-$SerieWeight-$BorderSize-$PicOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2851. if ( $Y != VOID )
  2852. {
  2853. if ( $RecordImageMap ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$SerieWeight,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2854. if ( $Picture != NULL )
  2855. { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
  2856. else
  2857. {
  2858. $R=$G=$B = 0;//crea
  2859. $SerieWeight = 4;//crea
  2860. $this->drawShape($X,$Y,$Shape,$SerieWeight,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha);
  2861. }
  2862. }
  2863. $X = $X + $XStep;
  2864. }
  2865. }
  2866. else
  2867. {
  2868. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2869. if ( $Picture != NULL ) { $PicOffset = $PicWidth / 2; $SerieWeight = 0; }
  2870. $Y = $this->GraphAreaY1 + $XMargin;
  2871. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2872. foreach($PosArray as $Key => $X)
  2873. {
  2874. if ( $DisplayValues )
  2875. $this->drawText($X+$DisplayOffset+$SerieWeight+$BorderSize+$PicOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2876. if ( $X != VOID )
  2877. {
  2878. if ( $RecordImageMap ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$SerieWeight,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2879. if ( $Picture != NULL )
  2880. { $this->drawFromPicture($PicType,$Picture,$X-$PicWidth/2,$Y-$PicHeight/2); }
  2881. else
  2882. { $this->drawShape($X,$Y,$Shape,$SerieWeight,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha); }
  2883. }
  2884. $Y = $Y + $YStep;
  2885. }
  2886. }
  2887. }
  2888. }
  2889. }
  2890. /* Draw a spline chart */
  2891. function drawSplineChart($Format=NULL)
  2892. {
  2893. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
  2894. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  2895. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL; // 234
  2896. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL; // 55
  2897. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL; // 26
  2898. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2899. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2900. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2901. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2902. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2903. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2904. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  2905. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  2906. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  2907. $Data = $this->DataSet->getData();
  2908. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2909. foreach($Data["Series"] as $SerieName => $Serie)
  2910. {
  2911. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2912. {
  2913. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  2914. if ( $BreakR == NULL )
  2915. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks);
  2916. else
  2917. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  2918. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2919. $AxisID = $Serie["Axis"];
  2920. $Mode = $Data["Axis"][$AxisID]["Display"];
  2921. $Format = $Data["Axis"][$AxisID]["Format"];
  2922. $Unit = $Data["Axis"][$AxisID]["Unit"];
  2923. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  2924. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  2925. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  2926. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  2927. {
  2928. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  2929. $X = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
  2930. $Force = $XStep / 5;
  2931. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2932. $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
  2933. foreach($PosArray as $Key => $Y)
  2934. {
  2935. if ( $DisplayValues )
  2936. $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2937. if ( $RecordImageMap && $Y != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2938. if ( $Y == VOID && $LastY != NULL )
  2939. { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }
  2940. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  2941. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }
  2942. if ( $Y != VOID )
  2943. $WayPoints[] = array($X,$Y);
  2944. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  2945. if ( $Y == VOID ) { $Y = NULL; }
  2946. $LastX = $X; $LastY = $Y;
  2947. $X = $X + $XStep;
  2948. }
  2949. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2950. }
  2951. else
  2952. {
  2953. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  2954. $Y = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
  2955. $Force = $YStep / 5;
  2956. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  2957. $LastGoodY = NULL; $LastGoodX = NULL; $LastX = 1; $LastY = 1;
  2958. foreach($PosArray as $Key => $X)
  2959. {
  2960. if ( $DisplayValues )
  2961. $this->drawText($X+$DisplayOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  2962. if ( $RecordImageMap && $X != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  2963. if ( $X == VOID && $LastX != NULL )
  2964. { $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight)); $WayPoints = ""; }
  2965. if ( $X != VOID && $LastX == NULL && $LastGoodX != NULL && !$BreakVoid )
  2966. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); }
  2967. if ( $X != VOID )
  2968. $WayPoints[] = array($X,$Y);
  2969. if ( $X != VOID ) { $LastGoodX = $X; $LastGoodY = $Y; }
  2970. if ( $X == VOID ) { $X = NULL; }
  2971. $LastX = $X; $LastY = $Y;
  2972. $Y = $Y + $YStep;
  2973. }
  2974. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  2975. }
  2976. }
  2977. }
  2978. }
  2979. /* Draw a filled spline chart */
  2980. function drawFilledSplineChart($Format=NULL)
  2981. {
  2982. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  2983. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  2984. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  2985. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  2986. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  2987. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  2988. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  2989. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  2990. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  2991. $Data = $this->DataSet->getData();
  2992. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  2993. foreach($Data["Series"] as $SerieName => $Serie)
  2994. {
  2995. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  2996. {
  2997. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  2998. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  2999. $AxisID = $Serie["Axis"];
  3000. $Mode = $Data["Axis"][$AxisID]["Display"];
  3001. $Format = $Data["Axis"][$AxisID]["Format"];
  3002. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3003. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3004. if ( $AroundZero ) { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }
  3005. if ( $Threshold != NULL )
  3006. {
  3007. foreach($Threshold as $Key => $Params)
  3008. {
  3009. $Threshold[$Key]["MinX"] = $this->scaleComputeY($Params["Min"],array("AxisID"=>$Serie["Axis"]));
  3010. $Threshold[$Key]["MaxX"] = $this->scaleComputeY($Params["Max"],array("AxisID"=>$Serie["Axis"]));
  3011. }
  3012. }
  3013. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3014. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3015. {
  3016. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3017. $X = $this->GraphAreaX1 + $XMargin; $WayPoints = "";
  3018. $Force = $XStep / 5;
  3019. if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }
  3020. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3021. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3022. $LastX = ""; $LastY = "";
  3023. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3024. foreach($PosArray as $Key => $Y)
  3025. {
  3026. if ( $DisplayValues )
  3027. $this->drawText($X,$Y-$DisplayOffset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  3028. if ( $Y == VOID )
  3029. {
  3030. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3031. if ( $Area != "" )
  3032. {
  3033. foreach ($Area as $key => $Points)
  3034. {
  3035. $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
  3036. foreach($Points as $subKey => $Point)
  3037. {
  3038. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3039. $Corners[] = $Point["Y"]+1;
  3040. }
  3041. $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;
  3042. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3043. }
  3044. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3045. }
  3046. $WayPoints = "";
  3047. }
  3048. else
  3049. $WayPoints[] = array($X,$Y-.5); /* -.5 for AA visual fix */
  3050. $X = $X + $XStep;
  3051. }
  3052. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3053. if ( $Area != "" )
  3054. {
  3055. foreach ($Area as $key => $Points)
  3056. {
  3057. $Corners = ""; $Corners[] = $Area[$key][0]["X"]; $Corners[] = $YZero;
  3058. foreach($Points as $subKey => $Point)
  3059. {
  3060. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3061. $Corners[] = $Point["Y"]+1;
  3062. }
  3063. $Corners[] = $Points[$subKey]["X"]-1; $Corners[] = $YZero;
  3064. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3065. }
  3066. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3067. }
  3068. }
  3069. else
  3070. {
  3071. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3072. $Y = $this->GraphAreaY1 + $XMargin; $WayPoints = "";
  3073. $Force = $YStep / 5;
  3074. if ( !$AroundZero ) { $YZero = $this->GraphAreaX1+1; }
  3075. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3076. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3077. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3078. foreach($PosArray as $Key => $X)
  3079. {
  3080. if ( $DisplayValues )
  3081. $this->drawText($X+$DisplayOffset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
  3082. if ( $X == VOID )
  3083. {
  3084. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3085. if ( $Area != "" )
  3086. {
  3087. foreach ($Area as $key => $Points)
  3088. {
  3089. $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
  3090. foreach($Points as $subKey => $Point)
  3091. {
  3092. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3093. $Corners[] = $Point["Y"];
  3094. }
  3095. $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;
  3096. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3097. }
  3098. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3099. }
  3100. $WayPoints = "";
  3101. }
  3102. else
  3103. $WayPoints[] = array($X,$Y);
  3104. $Y = $Y + $YStep;
  3105. }
  3106. $Area = $this->drawSpline($WayPoints,array("Force"=>$Force,"PathOnly"=>TRUE));
  3107. if ( $Area != "" )
  3108. {
  3109. foreach ($Area as $key => $Points)
  3110. {
  3111. $Corners = ""; $Corners[] = $YZero; $Corners[] = $Area[$key][0]["Y"];
  3112. foreach($Points as $subKey => $Point)
  3113. {
  3114. if ( $subKey == count($Points)-1) { $Corners[] = $Point["X"]-1; } else { $Corners[] = $Point["X"]; }
  3115. $Corners[] = $Point["Y"];
  3116. }
  3117. $Corners[] = $YZero; $Corners[] = $Points[$subKey]["Y"]-1;
  3118. $this->drawPolygonChart($Corners,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha/2,"NoBorder"=>TRUE,"Threshold"=>$Threshold));
  3119. }
  3120. $this->drawSpline($WayPoints,array("Force"=>$Force,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks));
  3121. }
  3122. }
  3123. }
  3124. }
  3125. }
  3126. /* Draw a line chart */
  3127. function drawLineChart($Format=NULL)
  3128. {
  3129. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : TRUE;
  3130. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  3131. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
  3132. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
  3133. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
  3134. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3135. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3136. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3137. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3138. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3139. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3140. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3141. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  3142. $ForceColor = isset($Format["ForceColor"]) ? $Format["ForceColor"] : FALSE;
  3143. $ForceR = isset($Format["ForceR"]) ? $Format["ForceR"] : 0;
  3144. $ForceG = isset($Format["ForceG"]) ? $Format["ForceG"] : 0;
  3145. $ForceB = isset($Format["ForceB"]) ? $Format["ForceB"] : 0;
  3146. $ForceAlpha = isset($Format["ForceAlpha"]) ? $Format["ForceAlpha"] : 100;
  3147. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3148. $Data = $this->DataSet->getData();
  3149. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3150. foreach($Data["Series"] as $SerieName => $Serie)
  3151. {
  3152. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3153. {
  3154. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3155. if ( $ForceColor )
  3156. { $R = $ForceR; $G = $ForceG; $B = $ForceB; $Alpha = $ForceAlpha; }
  3157. if ( $BreakR == NULL )
  3158. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3159. else
  3160. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3161. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3162. $AxisID = $Serie["Axis"];
  3163. $Mode = $Data["Axis"][$AxisID]["Display"];
  3164. $Format = $Data["Axis"][$AxisID]["Format"];
  3165. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3166. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  3167. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3168. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3169. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3170. {
  3171. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3172. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3173. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3174. $LastGoodY = NULL; $LastGoodX = NULL;
  3175. foreach($PosArray as $Key => $Y)
  3176. {
  3177. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3178. {
  3179. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3180. $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3181. }
  3182. if ( $RecordImageMap && $Y != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3183. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  3184. $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  3185. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  3186. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }
  3187. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3188. if ( $Y == VOID ) { $Y = NULL; }
  3189. $LastX = $X; $LastY = $Y;
  3190. $X = $X + $XStep;
  3191. }
  3192. }
  3193. else
  3194. {
  3195. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3196. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3197. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3198. $LastGoodY = NULL; $LastGoodX = NULL;
  3199. foreach($PosArray as $Key => $X)
  3200. {
  3201. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3202. { $this->drawText($X+$DisplayOffset+$Weight,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
  3203. if ( $RecordImageMap && $X != VOID ) { $this->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".$ImageMapPlotSize,$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3204. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3205. $this->drawLine($LastX,$LastY,$X,$Y,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight));
  3206. if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
  3207. { $this->drawLine($LastGoodX,$LastGoodY,$X,$Y,$BreakSettings); $LastGoodY = NULL; }
  3208. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3209. if ( $X == VOID ) { $X = NULL; }
  3210. $LastX = $X; $LastY = $Y;
  3211. $Y = $Y + $YStep;
  3212. }
  3213. }
  3214. }
  3215. }
  3216. }
  3217. /* Draw a line chart */
  3218. function drawZoneChart($SerieA,$SerieB,$Format=NULL)
  3219. {
  3220. $AxisID = isset($Format["AxisID"]) ? $Format["AxisID"] : 0;
  3221. $LineR = isset($Format["LineR"]) ? $Format["LineR"] : 150;
  3222. $LineG = isset($Format["LineG"]) ? $Format["LineG"] : 150;
  3223. $LineB = isset($Format["LineB"]) ? $Format["LineB"] : 150;
  3224. $LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 50;
  3225. $LineTicks = isset($Format["LineTicks"]) ? $Format["LineTicks"] : 1;
  3226. $AreaR = isset($Format["AreaR"]) ? $Format["AreaR"] : 150;
  3227. $AreaG = isset($Format["AreaG"]) ? $Format["AreaG"] : 150;
  3228. $AreaB = isset($Format["AreaB"]) ? $Format["AreaB"] : 150;
  3229. $AreaAlpha = isset($Format["AreaAlpha"]) ? $Format["AreaAlpha"] : 5;
  3230. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3231. $Data = $this->DataSet->getData();
  3232. if ( !isset($Data["Series"][$SerieA]["Data"]) || !isset($Data["Series"][$SerieB]["Data"]) ) { return(0); }
  3233. $SerieAData = $Data["Series"][$SerieA]["Data"];
  3234. $SerieBData = $Data["Series"][$SerieB]["Data"];
  3235. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3236. $Mode = $Data["Axis"][$AxisID]["Display"];
  3237. $Format = $Data["Axis"][$AxisID]["Format"];
  3238. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3239. $PosArrayA = $this->scaleComputeY($SerieAData,array("AxisID"=>$AxisID));
  3240. $PosArrayB = $this->scaleComputeY($SerieBData,array("AxisID"=>$AxisID));
  3241. if ( count($PosArrayA) != count($PosArrayB) ) { return(0); }
  3242. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3243. {
  3244. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3245. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3246. $LastX = NULL; $LastY1 = NULL; $LastY2 = NULL;
  3247. $BoundsA = ""; $BoundsB = "";
  3248. foreach($PosArrayA as $Key => $Y1)
  3249. {
  3250. $Y2 = $PosArrayB[$Key];
  3251. $BoundsA[] = $X; $BoundsA[] = $Y1;
  3252. $BoundsB[] = $X; $BoundsB[] = $Y2;
  3253. $LastX = $X;
  3254. $LastY1 = $Y1; $LastY2 = $Y2;
  3255. $X = $X + $XStep;
  3256. }
  3257. $Bounds = array_merge($BoundsA,$this->reversePlots($BoundsB));
  3258. $this->drawPolygonChart($Bounds,array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"Alpha"=>$AreaAlpha));
  3259. for($i=0;$i<=count($BoundsA)-4;$i=$i+2)
  3260. {
  3261. $this->drawLine($BoundsA[$i],$BoundsA[$i+1],$BoundsA[$i+2],$BoundsA[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3262. $this->drawLine($BoundsB[$i],$BoundsB[$i+1],$BoundsB[$i+2],$BoundsB[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3263. }
  3264. }
  3265. else
  3266. {
  3267. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3268. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3269. $LastY = NULL; $LastX1 = NULL; $LastX2 = NULL;
  3270. $BoundsA = ""; $BoundsB = "";
  3271. foreach($PosArrayA as $Key => $X1)
  3272. {
  3273. $X2 = $PosArrayB[$Key];
  3274. $BoundsA[] = $X1; $BoundsA[] = $Y;
  3275. $BoundsB[] = $X2; $BoundsB[] = $Y;
  3276. $LastY = $Y;
  3277. $LastX1 = $X1; $LastX2 = $X2;
  3278. $Y = $Y + $YStep;
  3279. }
  3280. $Bounds = array_merge($BoundsA,$this->reversePlots($BoundsB));
  3281. $this->drawPolygonChart($Bounds,array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"Alpha"=>$AreaAlpha));
  3282. for($i=0;$i<=count($BoundsA)-4;$i=$i+2)
  3283. {
  3284. $this->drawLine($BoundsA[$i],$BoundsA[$i+1],$BoundsA[$i+2],$BoundsA[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3285. $this->drawLine($BoundsB[$i],$BoundsB[$i+1],$BoundsB[$i+2],$BoundsB[$i+3],array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha,"Ticks"=>$LineTicks));
  3286. }
  3287. }
  3288. }
  3289. /* Draw a step chart */
  3290. function drawStepChart($Format=NULL)
  3291. {
  3292. $BreakVoid = isset($Format["BreakVoid"]) ? $Format["BreakVoid"] : FALSE;
  3293. $ReCenter = isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
  3294. $VoidTicks = isset($Format["VoidTicks"]) ? $Format["VoidTicks"] : 4;
  3295. $BreakR = isset($Format["BreakR"]) ? $Format["BreakR"] : NULL;
  3296. $BreakG = isset($Format["BreakG"]) ? $Format["BreakG"] : NULL;
  3297. $BreakB = isset($Format["BreakB"]) ? $Format["BreakB"] : NULL;
  3298. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
  3299. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3300. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3301. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3302. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3303. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3304. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3305. $ImageMapPlotSize = isset($Format["ImageMapPlotSize"]) ? $Format["ImageMapPlotSize"] : 5;
  3306. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3307. $Data = $this->DataSet->getData();
  3308. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3309. foreach($Data["Series"] as $SerieName => $Serie)
  3310. {
  3311. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3312. {
  3313. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3314. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  3315. if ( $BreakR == NULL )
  3316. $BreakSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3317. else
  3318. $BreakSettings = array("R"=>$BreakR,"G"=>$BreakG,"B"=>$BreakB,"Alpha"=>$Alpha,"Ticks"=>$VoidTicks,"Weight"=>$Weight);
  3319. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3320. $AxisID = $Serie["Axis"];
  3321. $Mode = $Data["Axis"][$AxisID]["Display"];
  3322. $Format = $Data["Axis"][$AxisID]["Format"];
  3323. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3324. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  3325. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3326. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3327. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3328. {
  3329. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3330. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3331. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3332. $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
  3333. foreach($PosArray as $Key => $Y)
  3334. {
  3335. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3336. {
  3337. if ( $Y <= $LastY ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3338. $this->drawText($X,$Y-$Offset-$Weight,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3339. }
  3340. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  3341. {
  3342. $this->drawLine($LastX,$LastY,$X,$LastY,$Color);
  3343. $this->drawLine($X,$LastY,$X,$Y,$Color);
  3344. if ( $ReCenter && $X+$XStep < $this->GraphAreaX2 - $XMargin )
  3345. {
  3346. $this->drawLine($X,$Y,$X+$XStep,$Y,$Color);
  3347. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X-$ImageMapPlotSize).",".floor($Y-$ImageMapPlotSize).",".floor($X+$XStep+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3348. }
  3349. else
  3350. { if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($LastY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); } }
  3351. }
  3352. if ( $Y != VOID && $LastY == NULL && $LastGoodY != NULL && !$BreakVoid )
  3353. {
  3354. if ( $ReCenter )
  3355. {
  3356. $this->drawLine($LastGoodX+$XStep,$LastGoodY,$X,$LastGoodY,$BreakSettings);
  3357. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX+$XStep-$ImageMapPlotSize).",".floor($LastGoodY-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($LastGoodY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3358. }
  3359. else
  3360. {
  3361. $this->drawLine($LastGoodX,$LastGoodY,$X,$LastGoodY,$BreakSettings);
  3362. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX-$ImageMapPlotSize).",".floor($LastGoodY-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($LastGoodY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3363. }
  3364. $this->drawLine($X,$LastGoodY,$X,$Y,$BreakSettings);
  3365. $LastGoodY = NULL;
  3366. }
  3367. elseif( !$BreakVoid && $LastGoodY == NULL && $Y != VOID )
  3368. {
  3369. $this->drawLine($this->GraphAreaX1 + $XMargin,$Y,$X,$Y,$BreakSettings);
  3370. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($this->GraphAreaX1+$XMargin-$ImageMapPlotSize).",".floor($Y-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3371. }
  3372. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3373. if ( $Y == VOID ) { $Y = NULL; }
  3374. if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
  3375. $LastX = $X; $LastY = $Y;
  3376. if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
  3377. $X = $X + $XStep;
  3378. }
  3379. if ( $ReCenter )
  3380. {
  3381. $this->drawLine($LastX,$LastY,$this->GraphAreaX2 - $XMargin,$LastY,$Color);
  3382. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($this->GraphAreaX2-$XMargin+$ImageMapPlotSize).",".floor($LastY+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3383. }
  3384. }
  3385. else
  3386. {
  3387. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3388. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3389. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3390. $LastGoodY = NULL; $LastGoodX = NULL; $Init = FALSE;
  3391. foreach($PosArray as $Key => $X)
  3392. {
  3393. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3394. {
  3395. if ( $X >= $LastX ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
  3396. $this->drawText($X+$Offset+$Weight,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3397. }
  3398. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3399. {
  3400. $this->drawLine($LastX,$LastY,$LastX,$Y,$Color);
  3401. $this->drawLine($LastX,$Y,$X,$Y,$Color);
  3402. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($LastX+$XStep+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3403. }
  3404. if ( $X != VOID && $LastX == NULL && $LastGoodY != NULL && !$BreakVoid )
  3405. {
  3406. $this->drawLine($LastGoodX,$LastGoodY,$LastGoodX,$LastGoodY+$YStep,$Color);
  3407. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX-$ImageMapPlotSize).",".floor($LastGoodY-$ImageMapPlotSize).",".floor($LastGoodX+$ImageMapPlotSize).",".floor($LastGoodY+$YStep+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3408. $this->drawLine($LastGoodX,$LastGoodY+$YStep,$LastGoodX,$Y,$BreakSettings);
  3409. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastGoodX-$ImageMapPlotSize).",".floor($LastGoodY+$YStep-$ImageMapPlotSize).",".floor($LastGoodX+$ImageMapPlotSize).",".floor($YStep+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3410. $this->drawLine($LastGoodX,$Y,$X,$Y,$BreakSettings);
  3411. $LastGoodY = NULL;
  3412. }
  3413. elseif ( $X != VOID && $LastGoodY == NULL && !$BreakVoid )
  3414. {
  3415. $this->drawLine($X,$this->GraphAreaY1 + $XMargin,$X,$Y,$BreakSettings);
  3416. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X-$ImageMapPlotSize).",".floor($this->GraphAreaY1+$XMargin-$ImageMapPlotSize).",".floor($X+$ImageMapPlotSize).",".floor($Y+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3417. }
  3418. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3419. if ( $X == VOID ) { $X = NULL; }
  3420. if ( !$Init && $ReCenter ) { $Y = $Y - $YStep/2; $Init = TRUE; }
  3421. $LastX = $X; $LastY = $Y;
  3422. if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
  3423. $Y = $Y + $YStep;
  3424. }
  3425. if ( $ReCenter )
  3426. {
  3427. $this->drawLine($LastX,$LastY,$LastX,$this->GraphAreaY2 - $XMargin,$Color);
  3428. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($LastX-$ImageMapPlotSize).",".floor($LastY-$ImageMapPlotSize).",".floor($LastX+$ImageMapPlotSize).",".floor($this->GraphAreaY2-$XMargin+$ImageMapPlotSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3429. }
  3430. }
  3431. }
  3432. }
  3433. }
  3434. /* Draw a step chart */
  3435. function drawFilledStepChart($Format=NULL)
  3436. {
  3437. $ReCenter = isset($Format["ReCenter"]) ? $Format["ReCenter"] : TRUE;
  3438. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] :FALSE;
  3439. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3440. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3441. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
  3442. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3443. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3444. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3445. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3446. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3447. $Data = $this->DataSet->getData();
  3448. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3449. foreach($Data["Series"] as $SerieName => $Serie)
  3450. {
  3451. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3452. {
  3453. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  3454. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3455. $AxisID = $Serie["Axis"];
  3456. $Mode = $Data["Axis"][$AxisID]["Display"];
  3457. $Format = $Data["Axis"][$AxisID]["Format"];
  3458. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3459. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  3460. if ( $ForceTransparency != NULL ) { $Color["Alpha"] = $ForceTransparency; } else { $Color["Alpha"] = $Alpha; }
  3461. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3462. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  3463. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3464. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3465. {
  3466. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3467. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3468. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3469. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3470. if ( !$AroundZero ) { $YZero = $this->GraphAreaY2-1; }
  3471. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3472. $LastGoodY = NULL; $LastGoodX = NULL; $Points = ""; $Init = FALSE;
  3473. foreach($PosArray as $Key => $Y)
  3474. {
  3475. if ( $Y == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
  3476. {
  3477. $Points[] = $LastX; $Points[] = $LastY;
  3478. $Points[] = $X; $Points[] = $LastY;
  3479. $Points[] = $X; $Points[] = $YZero;
  3480. $this->drawPolygon($Points,$Color);
  3481. $Points = "";
  3482. }
  3483. if ( $Y != VOID && $LastX != NULL && $LastY != NULL )
  3484. {
  3485. if ( $Points == "") { $Points[] = $LastX; $Points[] = $YZero; }
  3486. $Points[] = $LastX; $Points[] = $LastY;
  3487. $Points[] = $X; $Points[] = $LastY;
  3488. $Points[] = $X; $Points[] = $Y;
  3489. }
  3490. if ( $Y != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3491. if ( $Y == VOID ) { $Y = NULL; }
  3492. if ( !$Init && $ReCenter ) { $X = $X - $XStep/2; $Init = TRUE; }
  3493. $LastX = $X; $LastY = $Y;
  3494. if ( $LastX < $this->GraphAreaX1 + $XMargin ) { $LastX = $this->GraphAreaX1 + $XMargin; }
  3495. $X = $X + $XStep;
  3496. }
  3497. if ( $ReCenter )
  3498. {
  3499. $Points[] = $LastX+$XStep/2; $Points[] = $LastY;
  3500. $Points[] = $LastX+$XStep/2; $Points[] = $YZero;
  3501. }
  3502. else
  3503. { $Points[] = $LastX; $Points[] = $YZero; }
  3504. $this->drawPolygon($Points,$Color);
  3505. }
  3506. else
  3507. {
  3508. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3509. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3510. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3511. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3512. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3513. $LastGoodY = NULL; $LastGoodX = NULL; $Points = "";
  3514. foreach($PosArray as $Key => $X)
  3515. {
  3516. if ( $X == VOID && $LastX != NULL && $LastY != NULL && $Points !="" )
  3517. {
  3518. $Points[] = $LastX; $Points[] = $LastY;
  3519. $Points[] = $LastX; $Points[] = $Y;
  3520. $Points[] = $YZero; $Points[] = $Y;
  3521. $this->drawPolygon($Points,$Color);
  3522. $Points = "";
  3523. }
  3524. if ( $X != VOID && $LastX != NULL && $LastY != NULL )
  3525. {
  3526. if ( $Points == "") { $Points[] = $YZero; $Points[] = $LastY; }
  3527. $Points[] = $LastX; $Points[] = $LastY;
  3528. $Points[] = $LastX; $Points[] = $Y;
  3529. $Points[] = $X; $Points[] = $Y;
  3530. }
  3531. if ( $X != VOID ) { $LastGoodY = $Y; $LastGoodX = $X; }
  3532. if ( $X == VOID ) { $X = NULL; }
  3533. if ( $LastX == NULL && $ReCenter ) { $Y = $Y - $YStep/2; }
  3534. $LastX = $X; $LastY = $Y;
  3535. if ( $LastY < $this->GraphAreaY1 + $XMargin ) { $LastY = $this->GraphAreaY1 + $XMargin; }
  3536. $Y = $Y + $YStep;
  3537. }
  3538. if ( $ReCenter )
  3539. {
  3540. $Points[] = $LastX; $Points[] = $LastY+$YStep/2;
  3541. $Points[] = $YZero; $Points[] = $LastY+$YStep/2;
  3542. }
  3543. else
  3544. { $Points[] = $YZero; $Points[] = $LastY; }
  3545. $this->drawPolygon($Points,$Color);
  3546. }
  3547. }
  3548. }
  3549. }
  3550. /* Draw an area chart */
  3551. function drawAreaChart($Format=NULL)
  3552. {
  3553. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3554. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3555. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3556. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3557. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3558. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3559. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : 25;
  3560. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3561. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  3562. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3563. $Data = $this->DataSet->getData();
  3564. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3565. foreach($Data["Series"] as $SerieName => $Serie)
  3566. {
  3567. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3568. {
  3569. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3570. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3571. $AxisID = $Serie["Axis"];
  3572. $Mode = $Data["Axis"][$AxisID]["Display"];
  3573. $Format = $Data["Axis"][$AxisID]["Format"];
  3574. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3575. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3576. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  3577. if ( $Threshold != NULL )
  3578. {
  3579. foreach($Threshold as $Key => $Params)
  3580. {
  3581. $Threshold[$Key]["MinX"] = $this->scaleComputeY($Params["Min"],array("AxisID"=>$Serie["Axis"]));
  3582. $Threshold[$Key]["MaxX"] = $this->scaleComputeY($Params["Max"],array("AxisID"=>$Serie["Axis"]));
  3583. }
  3584. }
  3585. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  3586. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3587. {
  3588. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3589. $Areas = ""; $AreaID = 0;
  3590. $Areas[$AreaID][] = $this->GraphAreaX1 + $XMargin;
  3591. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3592. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3593. $X = $this->GraphAreaX1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3594. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3595. foreach($PosArray as $Key => $Y)
  3596. {
  3597. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3598. {
  3599. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3600. $this->drawText($X,$Y-$Offset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3601. }
  3602. if ( $Y == VOID && isset($Areas[$AreaID]) )
  3603. {
  3604. if($LastX == NULL)
  3605. { $Areas[$AreaID][] = $X; }
  3606. else
  3607. { $Areas[$AreaID][] = $LastX; }
  3608. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3609. $AreaID++;
  3610. }
  3611. elseif ($Y != VOID)
  3612. {
  3613. if ( !isset($Areas[$AreaID]) )
  3614. {
  3615. $Areas[$AreaID][] = $X;
  3616. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3617. }
  3618. $Areas[$AreaID][] = $X;
  3619. $Areas[$AreaID][] = $Y;
  3620. }
  3621. $LastX = $X;
  3622. $X = $X + $XStep;
  3623. }
  3624. $Areas[$AreaID][] = $LastX;
  3625. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaY2-1; }
  3626. /* Handle shadows in the areas */
  3627. if ( $this->Shadow )
  3628. {
  3629. $ShadowArea = "";
  3630. foreach($Areas as $Key => $Points)
  3631. {
  3632. $ShadowArea[$Key] = "";
  3633. foreach($Points as $Key2 => $Value)
  3634. {
  3635. if ( $Key2 % 2 == 0 )
  3636. { $ShadowArea[$Key][] = $Value + $this->ShadowX; }
  3637. else
  3638. { $ShadowArea[$Key][] = $Value + $this->ShadowY; }
  3639. }
  3640. }
  3641. foreach($ShadowArea as $Key => $Points)
  3642. $this->drawPolygonChart($Points,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  3643. }
  3644. $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
  3645. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Threshold"=>$Threshold);
  3646. foreach($Areas as $Key => $Points)
  3647. $this->drawPolygonChart($Points,$Color);
  3648. }
  3649. else
  3650. {
  3651. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3652. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3653. $Areas = ""; $AreaID = 0;
  3654. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3655. $Areas[$AreaID][] = $this->GraphAreaY1 + $XMargin;
  3656. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3657. $Y = $this->GraphAreaY1 + $XMargin; $LastX = NULL; $LastY = NULL;
  3658. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3659. foreach($PosArray as $Key => $X)
  3660. {
  3661. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3662. {
  3663. if ( $Serie["Data"][$Key] > 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3664. $this->drawText($X+$Offset,$Y,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("Angle"=>270,"R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align));
  3665. }
  3666. if ( $X == VOID && isset($Areas[$AreaID]) )
  3667. {
  3668. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3669. if($LastY == NULL)
  3670. { $Areas[$AreaID][] = $Y; }
  3671. else
  3672. { $Areas[$AreaID][] = $LastY; }
  3673. $AreaID++;
  3674. }
  3675. elseif ($X != VOID)
  3676. {
  3677. if ( !isset($Areas[$AreaID]) )
  3678. {
  3679. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3680. $Areas[$AreaID][] = $Y;
  3681. }
  3682. $Areas[$AreaID][] = $X;
  3683. $Areas[$AreaID][] = $Y;
  3684. }
  3685. $LastX = $X; $LastY = $Y;
  3686. $Y = $Y + $YStep;
  3687. }
  3688. if ( $AroundZero ) { $Areas[$AreaID][] = $YZero; } else { $Areas[$AreaID][] = $this->GraphAreaX1+1; }
  3689. $Areas[$AreaID][] = $LastY;
  3690. /* Handle shadows in the areas */
  3691. if ( $this->Shadow )
  3692. {
  3693. $ShadowArea = "";
  3694. foreach($Areas as $Key => $Points)
  3695. {
  3696. $ShadowArea[$Key] = "";
  3697. foreach($Points as $Key2 => $Value)
  3698. {
  3699. if ( $Key2 % 2 == 0 )
  3700. { $ShadowArea[$Key][] = $Value + $this->ShadowX; }
  3701. else
  3702. { $ShadowArea[$Key][] = $Value + $this->ShadowY; }
  3703. }
  3704. }
  3705. foreach($ShadowArea as $Key => $Points)
  3706. $this->drawPolygonChart($Points,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  3707. }
  3708. $Alpha = $ForceTransparency != NULL ? $ForceTransparency : $Alpha;
  3709. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Threshold"=>$Threshold);
  3710. foreach($Areas as $Key => $Points)
  3711. $this->drawPolygonChart($Points,$Color);
  3712. }
  3713. }
  3714. }
  3715. }
  3716. /* Draw a bar chart */
  3717. function drawBarChart($Format=NULL)
  3718. {
  3719. $Floating0Serie = isset($Format["Floating0Serie"]) ? $Format["Floating0Serie"] : NULL;
  3720. $Floating0Value = isset($Format["Floating0Value"]) ? $Format["Floating0Value"] : NULL;
  3721. $Draw0Line = isset($Format["Draw0Line"]) ? $Format["Draw0Line"] : FALSE;
  3722. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3723. $DisplayOrientation = isset($Format["DisplayOrientation"]) ? $Format["DisplayOrientation"] : ORIENTATION_HORIZONTAL;
  3724. $DisplayOffset = isset($Format["DisplayOffset"]) ? $Format["DisplayOffset"] : 2;
  3725. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  3726. $DisplayFont = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontName;
  3727. $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
  3728. $DisplayPos = isset($Format["DisplayPos"]) ? $Format["DisplayPos"] : LABEL_POS_OUTSIDE;
  3729. $DisplayShadow = isset($Format["DisplayShadow"]) ? $Format["DisplayShadow"] : TRUE;
  3730. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  3731. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  3732. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  3733. $AroundZero = isset($Format["AroundZero"]) ? $Format["AroundZero"] : TRUE;
  3734. $Interleave = isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
  3735. $Rounded = isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
  3736. $RoundRadius = isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
  3737. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  3738. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  3739. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  3740. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  3741. $Gradient = isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
  3742. $GradientMode = isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
  3743. $GradientAlpha = isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
  3744. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  3745. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  3746. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  3747. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
  3748. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
  3749. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
  3750. $TxtMargin = isset($Format["TxtMargin"]) ? $Format["TxtMargin"] : 6;
  3751. $OverrideColors = isset($Format["OverrideColors"]) ? $Format["OverrideColors"] : NULL;
  3752. $OverrideSurrounding = isset($Format["OverrideSurrounding"]) ? $Format["OverrideSurrounding"] : 30;
  3753. $InnerSurrounding = isset($Format["InnerSurrounding"]) ? $Format["InnerSurrounding"] : NULL;
  3754. $InnerBorderR = isset($Format["InnerBorderR"]) ? $Format["InnerBorderR"] : -1;
  3755. $InnerBorderG = isset($Format["InnerBorderG"]) ? $Format["InnerBorderG"] : -1;
  3756. $InnerBorderB = isset($Format["InnerBorderB"]) ? $Format["InnerBorderB"] : -1;
  3757. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  3758. $this->LastChartLayout = CHART_LAST_LAYOUT_REGULAR;
  3759. $Data = $this->DataSet->getData();
  3760. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  3761. if ( $OverrideColors != NULL )
  3762. {
  3763. $OverrideColors = $this->validatePalette($OverrideColors,$OverrideSurrounding);
  3764. $this->DataSet->saveExtendedData("Palette",$OverrideColors);
  3765. }
  3766. $RestoreShadow = $this->Shadow;
  3767. $SeriesCount = $this->countDrawableSeries();
  3768. $CurrentSerie = 0;
  3769. foreach($Data["Series"] as $SerieName => $Serie)
  3770. {
  3771. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  3772. {
  3773. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  3774. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = $R; $DisplayG = $G; $DisplayB = $B; }
  3775. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  3776. if ( $InnerSurrounding != NULL ) { $InnerBorderR = $R+$InnerSurrounding; $InnerBorderG = $G+$InnerSurrounding; $InnerBorderB = $B+$InnerSurrounding; }
  3777. if ( $InnerBorderR == -1 ) { $InnerColor = NULL; } else { $InnerColor = array("R"=>$InnerBorderR,"G"=>$InnerBorderG,"B"=>$InnerBorderB); }
  3778. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);
  3779. $AxisID = $Serie["Axis"];
  3780. $Mode = $Data["Axis"][$AxisID]["Display"];
  3781. $Format = $Data["Axis"][$AxisID]["Format"];
  3782. $Unit = $Data["Axis"][$AxisID]["Unit"];
  3783. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  3784. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  3785. if ( $Floating0Value != NULL )
  3786. { $YZero = $this->scaleComputeY($Floating0Value,array("AxisID"=>$Serie["Axis"])); }
  3787. else
  3788. { $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"])); }
  3789. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  3790. {
  3791. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3792. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3793. if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  3794. $X = $this->GraphAreaX1 + $XMargin;
  3795. if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
  3796. if ( $XDivs == 0 ) { $XSize = ($this->GraphAreaX2-$this->GraphAreaX1)/($SeriesCount+$Interleave); } else { $XSize = ($XStep / ($SeriesCount+$Interleave) ); }
  3797. $XOffset = -($XSize*$SeriesCount)/2 + $CurrentSerie * $XSize;
  3798. if ( $X + $XOffset <= $this->GraphAreaX1 ) { $XOffset = $this->GraphAreaX1 - $X + 1 ; }
  3799. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $XOffset + $XSize / 2;
  3800. if ( $Rounded || $BorderR != -1) { $XSpace = 1; } else { $XSpace = 0; }
  3801. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3802. $ID = 0;
  3803. foreach($PosArray as $Key => $Y2)
  3804. {
  3805. if ( $Floating0Serie != NULL )
  3806. {
  3807. if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
  3808. { $Value = $Data["Series"][$Floating0Serie]["Data"][$Key]; }
  3809. else
  3810. { $Value = 0; }
  3811. $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
  3812. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  3813. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  3814. if ( $AroundZero ) { $Y1 = $YZero; } else { $Y1 = $this->GraphAreaY2-1; }
  3815. }
  3816. if ( $OverrideColors != NULL )
  3817. { if ( isset($OverrideColors[$ID]) ) { $Color = array("R"=>$OverrideColors[$ID]["R"],"G"=>$OverrideColors[$ID]["G"],"B"=>$OverrideColors[$ID]["B"],"Alpha"=>$OverrideColors[$ID]["Alpha"],"BorderR"=>$OverrideColors[$ID]["BorderR"],"BorderG"=>$OverrideColors[$ID]["BorderG"],"BorderB"=>$OverrideColors[$ID]["BorderB"]); } else { $Color = $this->getRandomColor(); } }
  3818. if ( $Y2 != VOID )
  3819. {
  3820. $BarHeight = $Y1 - $Y2;
  3821. if ( $Serie["Data"][$Key] == 0 )
  3822. {
  3823. $this->drawLine($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y1,$Color);
  3824. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X+$XOffset+$XSpace).",".floor($Y1-1).",".floor($X+$XOffset+$XSize-$XSpace).",".floor($Y1+1),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3825. }
  3826. else
  3827. {
  3828. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X+$XOffset+$XSpace).",".floor($Y1).",".floor($X+$XOffset+$XSize-$XSpace).",".floor($Y2),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3829. if ( $Rounded )
  3830. $this->drawRoundedFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$RoundRadius,$Color);
  3831. else
  3832. {
  3833. $this->drawFilledRectangle($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,$Color);
  3834. if ( $InnerColor != NULL ) { $this->drawRectangle($X+$XOffset+$XSpace+1,min($Y1,$Y2)+1,$X+$XOffset+$XSize-$XSpace-1,max($Y1,$Y2)-1,$InnerColor); }
  3835. if ( $Gradient )
  3836. {
  3837. $this->Shadow = FALSE;
  3838. if ( $GradientMode == GRADIENT_SIMPLE )
  3839. {
  3840. if ( $Serie["Data"][$Key] >= 0 )
  3841. $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3842. else
  3843. $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3844. $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_VERTICAL,$GradienColor);
  3845. }
  3846. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3847. {
  3848. $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3849. $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3850. $XSpan = floor($XSize / 3);
  3851. $this->drawGradientArea($X+$XOffset+$XSpace,$Y1,$X+$XOffset+$XSpan-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor1);
  3852. $this->drawGradientArea($X+$XOffset+$XSpan+$XSpace,$Y1,$X+$XOffset+$XSize-$XSpace,$Y2,DIRECTION_HORIZONTAL,$GradienColor2);
  3853. }
  3854. $this->Shadow = $RestoreShadow;
  3855. }
  3856. }
  3857. if ( $Draw0Line )
  3858. {
  3859. $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);
  3860. if ( abs($Y1 - $Y2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
  3861. if ( $Y1 - $Y2 < 0 ) { $Line0Width = -$Line0Width; }
  3862. $this->drawFilledRectangle($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1)-$Line0Width,$Line0Color);
  3863. $this->drawLine($X+$XOffset+$XSpace,floor($Y1),$X+$XOffset+$XSize-$XSpace,floor($Y1),$Line0Color);
  3864. }
  3865. }
  3866. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3867. {
  3868. if ( $DisplayShadow ) { $this->Shadow = TRUE; }
  3869. $Caption = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
  3870. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,90,$Caption);
  3871. $TxtHeight = $TxtPos[0]["Y"] - $TxtPos[1]["Y"] + $TxtMargin;
  3872. if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtHeight) < abs($BarHeight) )
  3873. {
  3874. $CenterX = (($X+$XOffset+$XSize-$XSpace)-($X+$XOffset+$XSpace))/2 + $X+$XOffset+$XSpace;
  3875. $CenterY = ($Y2-$Y1)/2 + $Y1;
  3876. $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"Angle"=>90));
  3877. }
  3878. else
  3879. {
  3880. if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_BOTTOMMIDDLE; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_TOPMIDDLE; $Offset = -$DisplayOffset; }
  3881. $this->drawText($X+$XOffset+$XSize/2,$Y2-$Offset,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align,"FontSize"=>$DisplaySize));
  3882. }
  3883. $this->Shadow = $RestoreShadow;
  3884. }
  3885. }
  3886. $X = $X + $XStep;
  3887. $ID++;
  3888. }
  3889. }
  3890. else
  3891. {
  3892. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3893. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3894. if ( $XDivs == 0 ) { $YStep = 0; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  3895. $Y = $this->GraphAreaY1 + $XMargin;
  3896. if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
  3897. if ( $XDivs == 0 ) { $YSize = ($this->GraphAreaY2-$this->GraphAreaY1)/($SeriesCount+$Interleave); } else { $YSize = ($YStep / ($SeriesCount+$Interleave) ); }
  3898. $YOffset = -($YSize*$SeriesCount)/2 + $CurrentSerie * $YSize;
  3899. if ( $Y + $YOffset <= $this->GraphAreaY1 ) { $YOffset = $this->GraphAreaY1 - $Y + 1 ; }
  3900. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = $YOffset + $YSize / 2;
  3901. if ( $Rounded || $BorderR != -1 ) { $YSpace = 1; } else { $YSpace = 0; }
  3902. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  3903. $ID = 0 ;
  3904. foreach($PosArray as $Key => $X2)
  3905. {
  3906. if ( $Floating0Serie != NULL )
  3907. {
  3908. if ( isset($Data["Series"][$Floating0Serie]["Data"][$Key]) )
  3909. $Value = $Data["Series"][$Floating0Serie]["Data"][$Key];
  3910. else { $Value = 0; }
  3911. $YZero = $this->scaleComputeY($Value,array("AxisID"=>$Serie["Axis"]));
  3912. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  3913. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  3914. if ( $AroundZero ) { $X1 = $YZero; } else { $X1 = $this->GraphAreaX1+1; }
  3915. }
  3916. if ( $OverrideColors != NULL )
  3917. { if ( isset($OverrideColors[$ID]) ) { $Color = array("R"=>$OverrideColors[$ID]["R"],"G"=>$OverrideColors[$ID]["G"],"B"=>$OverrideColors[$ID]["B"],"Alpha"=>$OverrideColors[$ID]["Alpha"],"BorderR"=>$OverrideColors[$ID]["BorderR"],"BorderG"=>$OverrideColors[$ID]["BorderG"],"BorderB"=>$OverrideColors[$ID]["BorderB"]); } else { $Color = $this->getRandomColor(); } }
  3918. if ( $X2 != VOID )
  3919. {
  3920. $BarWidth = $X2 - $X1;
  3921. if ( $Serie["Data"][$Key] == 0 )
  3922. {
  3923. $this->drawLine($X1,$Y+$YOffset+$YSpace,$X1,$Y+$YOffset+$YSize-$YSpace,$Color);
  3924. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X1-1).",".floor($Y+$YOffset+$YSpace).",".floor($X1+1).",".floor($Y+$YOffset+$YSize-$YSpace),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3925. }
  3926. else
  3927. {
  3928. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X1).",".floor($Y+$YOffset+$YSpace).",".floor($X2).",".floor($Y+$YOffset+$YSize-$YSpace),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  3929. if ( $Rounded )
  3930. $this->drawRoundedFilledRectangle($X1+1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$RoundRadius,$Color);
  3931. else
  3932. {
  3933. $this->drawFilledRectangle($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,$Color);
  3934. if ( $InnerColor != NULL ) { $this->drawRectangle(min($X1,$X2)+1,$Y+$YOffset+$YSpace+1,max($X1,$X2)-1,$Y+$YOffset+$YSize-$YSpace-1,$InnerColor); }
  3935. if ( $Gradient )
  3936. {
  3937. $this->Shadow = FALSE;
  3938. if ( $GradientMode == GRADIENT_SIMPLE )
  3939. {
  3940. if ( $Serie["Data"][$Key] >= 0 )
  3941. $GradienColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3942. else
  3943. $GradienColor = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3944. $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_HORIZONTAL,$GradienColor);
  3945. }
  3946. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  3947. {
  3948. $GradienColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  3949. $GradienColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  3950. $YSpan = floor($YSize / 3);
  3951. $this->drawGradientArea($X1,$Y+$YOffset+$YSpace,$X2,$Y+$YOffset+$YSpan-$YSpace,DIRECTION_VERTICAL,$GradienColor1);
  3952. $this->drawGradientArea($X1,$Y+$YOffset+$YSpan,$X2,$Y+$YOffset+$YSize-$YSpace,DIRECTION_VERTICAL,$GradienColor2);
  3953. }
  3954. $this->Shadow = $RestoreShadow;
  3955. }
  3956. }
  3957. if ( $Draw0Line )
  3958. {
  3959. $Line0Color = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20);
  3960. if ( abs($X1 - $X2) > 3 ) { $Line0Width = 3; } else { $Line0Width = 1; }
  3961. if ( $X2 - $X1 < 0 ) { $Line0Width = -$Line0Width; }
  3962. $this->drawFilledRectangle(floor($X1),$Y+$YOffset+$YSpace,floor($X1)+$Line0Width,$Y+$YOffset+$YSize-$YSpace,$Line0Color);
  3963. $this->drawLine(floor($X1),$Y+$YOffset+$YSpace,floor($X1),$Y+$YOffset+$YSize-$YSpace,$Line0Color);
  3964. }
  3965. }
  3966. if ( $DisplayValues && $Serie["Data"][$Key] != VOID )
  3967. {
  3968. if ( $DisplayShadow ) { $this->Shadow = TRUE; }
  3969. $Caption = $this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit);
  3970. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  3971. $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"] + $TxtMargin;
  3972. if ( $DisplayPos == LABEL_POS_INSIDE && abs($TxtWidth) < abs($BarWidth) )
  3973. {
  3974. $CenterX = ($X2-$X1)/2 + $X1;
  3975. $CenterY = (($Y+$YOffset+$YSize-$YSpace)-($Y+$YOffset+$YSpace))/2 + ($Y+$YOffset+$YSpace);
  3976. $this->drawText($CenterX,$CenterY,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize));
  3977. }
  3978. else
  3979. {
  3980. if ( $Serie["Data"][$Key] >= 0 ) { $Align = TEXT_ALIGN_MIDDLELEFT; $Offset = $DisplayOffset; } else { $Align = TEXT_ALIGN_MIDDLERIGHT; $Offset = -$DisplayOffset; }
  3981. $this->drawText($X2+$Offset,$Y+$YOffset+$YSize/2,$Caption,array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>$Align,"FontSize"=>$DisplaySize));
  3982. }
  3983. $this->Shadow = $RestoreShadow;
  3984. }
  3985. }
  3986. $Y = $Y + $YStep;
  3987. $ID++;
  3988. }
  3989. }
  3990. $CurrentSerie++;
  3991. }
  3992. }
  3993. }
  3994. /* Draw a bar chart */
  3995. function drawStackedBarChart($Format=NULL)
  3996. {
  3997. $DisplayValues = isset($Format["DisplayValues"]) ? $Format["DisplayValues"] : FALSE;
  3998. $DisplayOrientation = isset($Format["DisplayOrientation"]) ? $Format["DisplayOrientation"] : ORIENTATION_AUTO;
  3999. $DisplayRound = isset($Format["DisplayRound"]) ? $Format["DisplayRound"] : 0;
  4000. $DisplayColor = isset($Format["DisplayColor"]) ? $Format["DisplayColor"] : DISPLAY_MANUAL;
  4001. $DisplayFont = isset($Format["DisplayFont"]) ? $Format["DisplayFont"] : $this->FontName;
  4002. $DisplaySize = isset($Format["DisplaySize"]) ? $Format["DisplaySize"] : $this->FontSize;
  4003. $DisplayR = isset($Format["DisplayR"]) ? $Format["DisplayR"] : 0;
  4004. $DisplayG = isset($Format["DisplayG"]) ? $Format["DisplayG"] : 0;
  4005. $DisplayB = isset($Format["DisplayB"]) ? $Format["DisplayB"] : 0;
  4006. $Interleave = isset($Format["Interleave"]) ? $Format["Interleave"] : .5;
  4007. $Rounded = isset($Format["Rounded"]) ? $Format["Rounded"] : FALSE;
  4008. $RoundRadius = isset($Format["RoundRadius"]) ? $Format["RoundRadius"] : 4;
  4009. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  4010. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : -1;
  4011. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : -1;
  4012. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : -1;
  4013. $Gradient = isset($Format["Gradient"]) ? $Format["Gradient"] : FALSE;
  4014. $GradientMode = isset($Format["GradientMode"]) ? $Format["GradientMode"] : GRADIENT_SIMPLE;
  4015. $GradientAlpha = isset($Format["GradientAlpha"]) ? $Format["GradientAlpha"] : 20;
  4016. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  4017. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  4018. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  4019. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 0;
  4020. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 0;
  4021. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 0;
  4022. $InnerSurrounding = isset($Format["InnerSurrounding"]) ? $Format["InnerSurrounding"] : NULL;
  4023. $InnerBorderR = isset($Format["InnerBorderR"]) ? $Format["InnerBorderR"] : -1;
  4024. $InnerBorderG = isset($Format["InnerBorderG"]) ? $Format["InnerBorderG"] : -1;
  4025. $InnerBorderB = isset($Format["InnerBorderB"]) ? $Format["InnerBorderB"] : -1;
  4026. $RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
  4027. $FontFactor = isset($Format["FontFactor"]) ? $Format["FontFactor"] : 8;
  4028. $this->LastChartLayout = CHART_LAST_LAYOUT_STACKED;
  4029. $Data = $this->DataSet->getData();
  4030. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4031. $RestoreShadow = $this->Shadow;
  4032. $LastX = ""; $LastY = "";
  4033. foreach($Data["Series"] as $SerieName => $Serie)
  4034. {
  4035. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4036. {
  4037. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  4038. if ( $DisplayColor == DISPLAY_AUTO ) { $DisplayR = 255; $DisplayG = 255; $DisplayB = 255; }
  4039. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  4040. if ( $InnerSurrounding != NULL ) { $InnerBorderR = $R+$InnerSurrounding; $InnerBorderG = $G+$InnerSurrounding; $InnerBorderB = $B+$InnerSurrounding; }
  4041. if ( $InnerBorderR == -1 ) { $InnerColor = NULL; } else { $InnerColor = array("R"=>$InnerBorderR,"G"=>$InnerBorderG,"B"=>$InnerBorderB); }
  4042. $AxisID = $Serie["Axis"];
  4043. $Mode = $Data["Axis"][$AxisID]["Display"];
  4044. $Format = $Data["Axis"][$AxisID]["Format"];
  4045. $Unit = $Data["Axis"][$AxisID]["Unit"];
  4046. if (isset($Serie["Description"])) { $SerieDescription = $Serie["Description"]; } else { $SerieDescription = $SerieName; }
  4047. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
  4048. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  4049. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  4050. $Color = array("TransCorner"=>TRUE,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"BorderR"=>$BorderR,"BorderG"=>$BorderG,"BorderB"=>$BorderB);
  4051. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4052. {
  4053. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  4054. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  4055. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4056. $X = $this->GraphAreaX1 + $XMargin;
  4057. $XSize = ($XStep / (1+$Interleave) );
  4058. $XOffset = -($XSize/2);
  4059. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4060. foreach($PosArray as $Key => $Height)
  4061. {
  4062. if ( $Height != VOID && $Serie["Data"][$Key] != 0 )
  4063. {
  4064. if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }
  4065. if ( !isset($LastY[$Key] ) ) { $LastY[$Key] = ""; }
  4066. if ( !isset($LastY[$Key][$Pos] ) ) { $LastY[$Key][$Pos] = $YZero; }
  4067. $Y1 = $LastY[$Key][$Pos];
  4068. $Y2 = $Y1 - $Height;
  4069. if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $Y1 != $YZero) ) { $YSpaceUp = 1; } else { $YSpaceUp = 0; }
  4070. if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $Y1 != $YZero) ) { $YSpaceDown = 1; } else { $YSpaceDown = 0; }
  4071. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X+$XOffset).",".floor($Y1-$YSpaceUp+$YSpaceDown).",".floor($X+$XOffset+$XSize).",".floor($Y2),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  4072. if ( $Rounded )
  4073. $this->drawRoundedFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$RoundRadius,$Color);
  4074. else
  4075. {
  4076. $this->drawFilledRectangle($X+$XOffset,$Y1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2,$Color);
  4077. if ( $InnerColor != NULL ) { $RestoreShadow = $this->Shadow; $this->Shadow = FALSE; $this->drawRectangle(min($X+$XOffset+1,$X+$XOffset+$XSize),min($Y1-$YSpaceUp+$YSpaceDown,$Y2)+1,max($X+$XOffset+1,$X+$XOffset+$XSize)-1,max($Y1-$YSpaceUp+$YSpaceDown,$Y2)-1,$InnerColor); $this->Shadow = $RestoreShadow;}
  4078. if ( $Gradient )
  4079. {
  4080. $this->Shadow = FALSE;
  4081. if ( $GradientMode == GRADIENT_SIMPLE )
  4082. {
  4083. $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4084. $this->drawGradientArea($X+$XOffset,$Y1-1-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+1,DIRECTION_VERTICAL,$GradientColor);
  4085. }
  4086. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  4087. {
  4088. $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  4089. $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4090. $XSpan = floor($XSize / 3);
  4091. $this->drawGradientArea($X+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSpan,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor1);
  4092. $this->drawGradientArea($X+$XSpan+$XOffset-.5,$Y1-.5-$YSpaceUp+$YSpaceDown,$X+$XOffset+$XSize,$Y2+.5,DIRECTION_HORIZONTAL,$GradientColor2);
  4093. }
  4094. $this->Shadow = $RestoreShadow;
  4095. }
  4096. }
  4097. if ( $DisplayValues )
  4098. {
  4099. $BarHeight = abs($Y2-$Y1)-2;
  4100. $BarWidth = $XSize+($XOffset/2)-$FontFactor;
  4101. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  4102. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  4103. $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
  4104. $TxtWidth = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);
  4105. $XCenter = ( ($X+$XOffset+$XSize) - ($X+$XOffset) ) / 2 + $X+$XOffset;
  4106. $YCenter = ( ($Y2) - ($Y1-$YSpaceUp+$YSpaceDown) ) / 2 + $Y1-$YSpaceUp+$YSpaceDown;
  4107. $Done = FALSE;
  4108. if ( $DisplayOrientation == ORIENTATION_HORIZONTAL || $DisplayOrientation == ORIENTATION_AUTO )
  4109. {
  4110. if ( $TxtHeight < $BarHeight && $TxtWidth < $BarWidth )
  4111. {
  4112. $this->drawText($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  4113. $Done = TRUE;
  4114. }
  4115. }
  4116. if ( $DisplayOrientation == ORIENTATION_VERTICAL || ( $DisplayOrientation == ORIENTATION_AUTO && !$Done) )
  4117. {
  4118. if ( $TxtHeight < $BarWidth && $TxtWidth < $BarHeight )
  4119. $this->drawText($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Angle"=>90,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  4120. }
  4121. }
  4122. $LastY[$Key][$Pos] = $Y2;
  4123. }
  4124. $X = $X + $XStep;
  4125. }
  4126. }
  4127. else
  4128. {
  4129. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  4130. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  4131. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4132. $Y = $this->GraphAreaY1 + $XMargin;
  4133. $YSize = $YStep / (1+$Interleave);
  4134. $YOffset = -($YSize/2);
  4135. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4136. foreach($PosArray as $Key => $Width)
  4137. {
  4138. if ( $Width != VOID && $Serie["Data"][$Key] != 0 )
  4139. {
  4140. if ( $Serie["Data"][$Key] > 0 ) { $Pos = "+"; } else { $Pos = "-"; }
  4141. if ( !isset($LastX[$Key] ) ) { $LastX[$Key] = ""; }
  4142. if ( !isset($LastX[$Key][$Pos] ) ) { $LastX[$Key][$Pos] = $YZero; }
  4143. $X1 = $LastX[$Key][$Pos];
  4144. $X2 = $X1 + $Width;
  4145. if ( ($Rounded || $BorderR != -1) && ($Pos == "+" && $X1 != $YZero) ) { $XSpaceLeft = 2; } else { $XSpaceLeft = 0; }
  4146. if ( ($Rounded || $BorderR != -1) && ($Pos == "-" && $X1 != $YZero) ) { $XSpaceRight = 2; } else { $XSpaceRight = 0; }
  4147. if ( $RecordImageMap ) { $this->addToImageMap("RECT",floor($X1+$XSpaceLeft).",".floor($Y+$YOffset).",".floor($X2-$XSpaceRight).",".floor($Y+$YOffset+$YSize),$this->toHTMLColor($R,$G,$B),$SerieDescription,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit)); }
  4148. if ( $Rounded )
  4149. $this->drawRoundedFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$RoundRadius,$Color);
  4150. else
  4151. {
  4152. $this->drawFilledRectangle($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,$Color);
  4153. if ( $InnerColor != NULL ) { $RestoreShadow = $this->Shadow; $this->Shadow = FALSE; $this->drawRectangle(min($X1+$XSpaceLeft,$X2-$XSpaceRight)+1,min($Y+$YOffset,$Y+$YOffset+$YSize)+1,max($X1+$XSpaceLeft,$X2-$XSpaceRight)-1,max($Y+$YOffset,$Y+$YOffset+$YSize)-1,$InnerColor); $this->Shadow = $RestoreShadow;}
  4154. if ( $Gradient )
  4155. {
  4156. $this->Shadow = FALSE;
  4157. if ( $GradientMode == GRADIENT_SIMPLE )
  4158. {
  4159. $GradientColor = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4160. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_HORIZONTAL,$GradientColor);
  4161. }
  4162. elseif ( $GradientMode == GRADIENT_EFFECT_CAN )
  4163. {
  4164. $GradientColor1 = array("StartR"=>$GradientEndR,"StartG"=>$GradientEndG,"StartB"=>$GradientEndB,"EndR"=>$GradientStartR,"EndG"=>$GradientStartG,"EndB"=>$GradientStartB,"Alpha"=>$GradientAlpha);
  4165. $GradientColor2 = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$GradientAlpha);
  4166. $YSpan = floor($YSize / 3);
  4167. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset,$X2-$XSpaceRight,$Y+$YOffset+$YSpan,DIRECTION_VERTICAL,$GradientColor1);
  4168. $this->drawGradientArea($X1+$XSpaceLeft,$Y+$YOffset+$YSpan,$X2-$XSpaceRight,$Y+$YOffset+$YSize,DIRECTION_VERTICAL,$GradientColor2);
  4169. }
  4170. $this->Shadow = $RestoreShadow;
  4171. }
  4172. }
  4173. if ( $DisplayValues )
  4174. {
  4175. $BarWidth = abs($X2-$X1)-$FontFactor;
  4176. $BarHeight = $YSize+($YOffset/2)-$FontFactor/2;
  4177. $Caption = $this->scaleFormat(round($Serie["Data"][$Key],$DisplayRound),$Mode,$Format,$Unit);
  4178. $TxtPos = $this->getTextBox(0,0,$DisplayFont,$DisplaySize,0,$Caption);
  4179. $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
  4180. $TxtWidth = abs($TxtPos[1]["X"] - $TxtPos[0]["X"]);
  4181. $XCenter = ( $X2 - $X1 ) / 2 + $X1;
  4182. $YCenter = ( ($Y+$YOffset+$YSize) - ($Y+$YOffset) ) / 2 + $Y+$YOffset;
  4183. $Done = FALSE;
  4184. if ( $DisplayOrientation == ORIENTATION_HORIZONTAL || $DisplayOrientation == ORIENTATION_AUTO )
  4185. {
  4186. if ( $TxtHeight < $BarHeight && $TxtWidth < $BarWidth )
  4187. {
  4188. $this->drawText($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  4189. $Done = TRUE;
  4190. }
  4191. }
  4192. if ( $DisplayOrientation == ORIENTATION_VERTICAL || ( $DisplayOrientation == ORIENTATION_AUTO && !$Done) )
  4193. {
  4194. if ( $TxtHeight < $BarWidth && $TxtWidth < $BarHeight )
  4195. $this->drawText($XCenter,$YCenter,$this->scaleFormat($Serie["Data"][$Key],$Mode,$Format,$Unit),array("R"=>$DisplayR,"G"=>$DisplayG,"B"=>$DisplayB,"Angle"=>90,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontSize"=>$DisplaySize,"FontName"=>$DisplayFont));
  4196. }
  4197. }
  4198. $LastX[$Key][$Pos] = $X2;
  4199. }
  4200. $Y = $Y + $YStep;
  4201. }
  4202. }
  4203. }
  4204. }
  4205. }
  4206. /* Draw a stacked area chart */
  4207. function drawStackedAreaChart($Format=NULL)
  4208. {
  4209. $DrawLine = isset($Format["DrawLine"]) ? $Format["DrawLine"] : FALSE;
  4210. $LineSurrounding = isset($Format["LineSurrounding"]) ? $Format["LineSurrounding"] : NULL;
  4211. $LineR = isset($Format["LineR"]) ? $Format["LineR"] : VOID;
  4212. $LineG = isset($Format["LineG"]) ? $Format["LineG"] : VOID;
  4213. $LineB = isset($Format["LineB"]) ? $Format["LineB"] : VOID;
  4214. $LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 100;
  4215. $DrawPlot = isset($Format["DrawPlot"]) ? $Format["DrawPlot"] : FALSE;
  4216. $PlotRadius = isset($Format["PlotRadius"]) ? $Format["PlotRadius"] : 2;
  4217. $PlotBorder = isset($Format["PlotBorder"]) ? $Format["PlotBorder"] : 1;
  4218. $PlotBorderSurrounding = isset($Format["PlotBorderSurrounding"]) ? $Format["PlotBorderSurrounding"] : NULL;
  4219. $PlotBorderR = isset($Format["PlotBorderR"]) ? $Format["PlotBorderR"] : 0;
  4220. $PlotBorderG = isset($Format["PlotBorderG"]) ? $Format["PlotBorderG"] : 0;
  4221. $PlotBorderB = isset($Format["PlotBorderB"]) ? $Format["PlotBorderB"] : 0;
  4222. $PlotBorderAlpha = isset($Format["PlotBorderAlpha"]) ? $Format["PlotBorderAlpha"] : 50;
  4223. $ForceTransparency = isset($Format["ForceTransparency"]) ? $Format["ForceTransparency"] : NULL;
  4224. $this->LastChartLayout = CHART_LAST_LAYOUT_STACKED;
  4225. $Data = $this->DataSet->getData();
  4226. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4227. $RestoreShadow = $this->Shadow;
  4228. $this->Shadow = FALSE;
  4229. /* Build the offset data series */
  4230. $OffsetData = "";
  4231. $OverallOffset = "";
  4232. $SerieOrder = "";
  4233. foreach($Data["Series"] as $SerieName => $Serie)
  4234. {
  4235. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4236. {
  4237. $SerieOrder[] = $SerieName;
  4238. foreach($Serie["Data"] as $Key => $Value)
  4239. {
  4240. if ( $Value == VOID ) { $Value = 0; }
  4241. if ($Value >= 0) { $Sign = "+"; } else { $Sign = "-"; }
  4242. if ( !isset($OverallOffset[$Key]) || !isset($OverallOffset[$Key][$Sign]) ) { $OverallOffset[$Key][$Sign] = 0; }
  4243. if ( $Sign == "+" )
  4244. { $Data["Series"][$SerieName]["Data"][$Key] = $Value + $OverallOffset[$Key][$Sign]; }
  4245. else
  4246. { $Data["Series"][$SerieName]["Data"][$Key] = $Value - $OverallOffset[$Key][$Sign]; }
  4247. $OverallOffset[$Key][$Sign] = $OverallOffset[$Key][$Sign] + abs($Value);
  4248. }
  4249. }
  4250. }
  4251. $SerieOrder = array_reverse($SerieOrder);
  4252. $LastX = ""; $LastY = "";
  4253. foreach($SerieOrder as $Key => $SerieName)
  4254. {
  4255. $Serie = $Data["Series"][$SerieName];
  4256. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4257. {
  4258. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"];
  4259. if ( $ForceTransparency != NULL ) { $Alpha = $ForceTransparency; }
  4260. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
  4261. if ( $LineSurrounding != NULL )
  4262. $LineColor = array("R"=>$R+$LineSurrounding,"G"=>$G+$LineSurrounding,"B"=>$B+$LineSurrounding,"Alpha"=>$Alpha);
  4263. elseif ( $LineR != VOID )
  4264. $LineColor = array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha);
  4265. else
  4266. $LineColor = $Color;
  4267. if ( $PlotBorderSurrounding != NULL )
  4268. $PlotBorderColor = array("R"=>$R+$PlotBorderSurrounding,"G"=>$G+$PlotBorderSurrounding,"B"=>$B+$PlotBorderSurrounding,"Alpha"=>$PlotBorderAlpha);
  4269. else
  4270. $PlotBorderColor = array("R"=>$PlotBorderR,"G"=>$PlotBorderG,"B"=>$PlotBorderB,"Alpha"=>$PlotBorderAlpha);
  4271. $AxisID = $Serie["Axis"];
  4272. $Mode = $Data["Axis"][$AxisID]["Display"];
  4273. $Format = $Data["Axis"][$AxisID]["Format"];
  4274. $Unit = $Data["Axis"][$AxisID]["Unit"];
  4275. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]),TRUE);
  4276. $YZero = $this->scaleComputeY(0,array("AxisID"=>$Serie["Axis"]));
  4277. $this->DataSet->Data["Series"][$SerieName]["XOffset"] = 0;
  4278. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4279. {
  4280. if ( $YZero < $this->GraphAreaY1+1 ) { $YZero = $this->GraphAreaY1+1; }
  4281. if ( $YZero > $this->GraphAreaY2-1 ) { $YZero = $this->GraphAreaY2-1; }
  4282. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4283. $X = $this->GraphAreaX1 + $XMargin;
  4284. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4285. $Plots = ""; $Plots[] = $X; $Plots[] = $YZero;
  4286. foreach($PosArray as $Key => $Height)
  4287. {
  4288. if ( $Height != VOID ) { $Plots[] = $X; $Plots[] = $YZero-$Height; }
  4289. $X = $X + $XStep;
  4290. }
  4291. $Plots[] = $X-$XStep; $Plots[] = $YZero;
  4292. $this->drawPolygon($Plots,$Color);
  4293. $this->Shadow = $RestoreShadow;
  4294. if ( $DrawLine ) { for($i=2; $i<=count($Plots)-6; $i=$i+2) { $this->drawLine($Plots[$i],$Plots[$i+1],$Plots[$i+2],$Plots[$i+3],$LineColor); } }
  4295. if ( $DrawPlot )
  4296. {
  4297. for($i=2; $i<=count($Plots)-4; $i=$i+2)
  4298. {
  4299. if ( $PlotBorder != 0 )
  4300. { $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius+$PlotBorder,$PlotBorderColor); }
  4301. $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius,$Color);
  4302. }
  4303. }
  4304. $this->Shadow = FALSE;
  4305. }
  4306. elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
  4307. {
  4308. if ( $YZero < $this->GraphAreaX1+1 ) { $YZero = $this->GraphAreaX1+1; }
  4309. if ( $YZero > $this->GraphAreaX2-1 ) { $YZero = $this->GraphAreaX2-1; }
  4310. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4311. $Y = $this->GraphAreaY1 + $XMargin;
  4312. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4313. $Plots = ""; $Plots[] = $YZero; $Plots[] = $Y;
  4314. foreach($PosArray as $Key => $Height)
  4315. {
  4316. if ( $Height != VOID ) { $Plots[] = $YZero+$Height; $Plots[] = $Y; }
  4317. $Y = $Y + $YStep;
  4318. }
  4319. $Plots[] = $YZero; $Plots[] = $Y-$YStep;
  4320. $this->drawPolygon($Plots,$Color);
  4321. $this->Shadow = $RestoreShadow;
  4322. if ( $DrawLine ) { for($i=2; $i<=count($Plots)-6; $i=$i+2) { $this->drawLine($Plots[$i],$Plots[$i+1],$Plots[$i+2],$Plots[$i+3],$LineColor); } }
  4323. if ( $DrawPlot )
  4324. {
  4325. for($i=2; $i<=count($Plots)-4; $i=$i+2)
  4326. {
  4327. if ( $PlotBorder != 0 )
  4328. { $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius+$PlotBorder,$PlotBorderColor); }
  4329. $this->drawFilledCircle($Plots[$i],$Plots[$i+1],$PlotRadius,$Color);
  4330. }
  4331. }
  4332. $this->Shadow = FALSE;
  4333. }
  4334. }
  4335. }
  4336. $this->Shadow = $RestoreShadow;
  4337. }
  4338. /* Returns a random color */
  4339. function getRandomColor($Alpha=100)
  4340. { return(array("R"=>rand(0,255),"G"=>rand(0,255),"B"=>rand(0,255),"Alpha"=>$Alpha)); }
  4341. /* Validate a palette */
  4342. function validatePalette($Colors,$Surrounding=NULL)
  4343. {
  4344. $Result = "";
  4345. if ( !is_array($Colors) ) { return($this->getRandomColor()); }
  4346. foreach($Colors as $Key => $Values)
  4347. {
  4348. if ( isset($Values["R"]) ) { $Result[$Key]["R"] = $Values["R"]; } else { $Result[$Key]["R"] = rand(0,255); }
  4349. if ( isset($Values["G"]) ) { $Result[$Key]["G"] = $Values["G"]; } else { $Result[$Key]["G"] = rand(0,255); }
  4350. if ( isset($Values["B"]) ) { $Result[$Key]["B"] = $Values["B"]; } else { $Result[$Key]["B"] = rand(0,255); }
  4351. if ( isset($Values["Alpha"]) ) { $Result[$Key]["Alpha"] = $Values["Alpha"]; } else { $Result[$Key]["Alpha"] = 100; }
  4352. if ( $Surrounding != NULL )
  4353. {
  4354. $Result[$Key]["BorderR"] = $Result[$Key]["R"] + $Surrounding;
  4355. $Result[$Key]["BorderG"] = $Result[$Key]["G"] + $Surrounding;
  4356. $Result[$Key]["BorderB"] = $Result[$Key]["B"] + $Surrounding;
  4357. }
  4358. else
  4359. {
  4360. if ( isset($Values["BorderR"]) ) { $Result[$Key]["BorderR"] = $Values["BorderR"]; } else { $Result[$Key]["BorderR"] = $Result[$Key]["R"]; }
  4361. if ( isset($Values["BorderG"]) ) { $Result[$Key]["BorderG"] = $Values["BorderG"]; } else { $Result[$Key]["BorderG"] = $Result[$Key]["G"]; }
  4362. if ( isset($Values["BorderB"]) ) { $Result[$Key]["BorderB"] = $Values["BorderB"]; } else { $Result[$Key]["BorderB"] = $Result[$Key]["B"]; }
  4363. if ( isset($Values["BorderAlpha"]) ) { $Result[$Key]["BorderAlpha"] = $Values["BorderAlpha"]; } else { $Result[$Key]["BorderAlpha"] = $Result[$Key]["Alpha"]; }
  4364. }
  4365. }
  4366. return($Result);
  4367. }
  4368. /* Draw the derivative chart associated to the data series */
  4369. function drawDerivative($Format=NULL)
  4370. {
  4371. $Offset = isset($Format["Offset"]) ? $Format["Offset"] : 10;
  4372. $SerieSpacing = isset($Format["SerieSpacing"]) ? $Format["SerieSpacing"] : 3;
  4373. $DerivativeHeight = isset($Format["DerivativeHeight"]) ? $Format["DerivativeHeight"] : 4;
  4374. $ShadedSlopeBox = isset($Format["ShadedSlopeBox"]) ? $Format["ShadedSlopeBox"] : FALSE;
  4375. $DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE;
  4376. $BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255;
  4377. $BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255;
  4378. $BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255;
  4379. $BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 20;
  4380. $DrawBorder = isset($Format["DrawBorder"]) ? $Format["DrawBorder"] : TRUE;
  4381. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 0;
  4382. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 0;
  4383. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 0;
  4384. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 100;
  4385. $Caption = isset($Format["Caption"]) ? $Format["Caption"] : TRUE;
  4386. $CaptionHeight = isset($Format["CaptionHeight"]) ? $Format["CaptionHeight"] : 10;
  4387. $CaptionWidth = isset($Format["CaptionWidth"]) ? $Format["CaptionWidth"] : 20;
  4388. $CaptionMargin = isset($Format["CaptionMargin"]) ? $Format["CaptionMargin"] : 4;
  4389. $CaptionLine = isset($Format["CaptionLine"]) ? $Format["CaptionLine"] : FALSE;
  4390. $CaptionBox = isset($Format["CaptionBox"]) ? $Format["CaptionBox"] : FALSE;
  4391. $CaptionBorderR = isset($Format["CaptionBorderR"]) ? $Format["CaptionBorderR"] : 0;
  4392. $CaptionBorderG = isset($Format["CaptionBorderG"]) ? $Format["CaptionBorderG"] : 0;
  4393. $CaptionBorderB = isset($Format["CaptionBorderB"]) ? $Format["CaptionBorderB"] : 0;
  4394. $CaptionFillR = isset($Format["CaptionFillR"]) ? $Format["CaptionFillR"] : 255;
  4395. $CaptionFillG = isset($Format["CaptionFillG"]) ? $Format["CaptionFillG"] : 255;
  4396. $CaptionFillB = isset($Format["CaptionFillB"]) ? $Format["CaptionFillB"] : 255;
  4397. $CaptionFillAlpha = isset($Format["CaptionFillAlpha"]) ? $Format["CaptionFillAlpha"] : 80;
  4398. $PositiveSlopeStartR = isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 184;
  4399. $PositiveSlopeStartG = isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 234;
  4400. $PositiveSlopeStartB = isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 88;
  4401. $PositiveSlopeEndR = isset($Format["PositiveSlopeStartR"]) ? $Format["PositiveSlopeStartR"] : 239;
  4402. $PositiveSlopeEndG = isset($Format["PositiveSlopeStartG"]) ? $Format["PositiveSlopeStartG"] : 31;
  4403. $PositiveSlopeEndB = isset($Format["PositiveSlopeStartB"]) ? $Format["PositiveSlopeStartB"] : 36;
  4404. $NegativeSlopeStartR = isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 184;
  4405. $NegativeSlopeStartG = isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 234;
  4406. $NegativeSlopeStartB = isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 88;
  4407. $NegativeSlopeEndR = isset($Format["NegativeSlopeStartR"]) ? $Format["NegativeSlopeStartR"] : 67;
  4408. $NegativeSlopeEndG = isset($Format["NegativeSlopeStartG"]) ? $Format["NegativeSlopeStartG"] : 124;
  4409. $NegativeSlopeEndB = isset($Format["NegativeSlopeStartB"]) ? $Format["NegativeSlopeStartB"] : 227;
  4410. $Data = $this->DataSet->getData();
  4411. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4412. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4413. $YPos = $this->DataSet->Data["GraphArea"]["Y2"] + $Offset;
  4414. else
  4415. $XPos = $this->DataSet->Data["GraphArea"]["X2"] + $Offset;
  4416. foreach($Data["Series"] as $SerieName => $Serie)
  4417. {
  4418. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4419. {
  4420. $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; $Alpha = $Serie["Color"]["Alpha"]; $Ticks = $Serie["Ticks"]; $Weight = $Serie["Weight"];
  4421. $AxisID = $Serie["Axis"];
  4422. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  4423. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4424. {
  4425. if ( $Caption )
  4426. {
  4427. if ( $CaptionLine )
  4428. {
  4429. $StartX = floor($this->GraphAreaX1-$CaptionWidth+$XMargin-$CaptionMargin);
  4430. $EndX = floor($this->GraphAreaX1-$CaptionMargin+$XMargin);
  4431. $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  4432. if ( $CaptionBox ) { $this->drawFilledRectangle($StartX,$YPos,$EndX,$YPos+$CaptionHeight,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
  4433. $this->drawLine($StartX+2,$YPos+($CaptionHeight/2),$EndX-2,$YPos+($CaptionHeight/2),$CaptionSettings);
  4434. }
  4435. else
  4436. $this->drawFilledRectangle($this->GraphAreaX1-$CaptionWidth+$XMargin-$CaptionMargin,$YPos,$this->GraphAreaX1-$CaptionMargin+$XMargin,$YPos+$CaptionHeight,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB));
  4437. }
  4438. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4439. $X = $this->GraphAreaX1 + $XMargin;
  4440. $TopY = $YPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
  4441. $BottomY = $YPos + ($CaptionHeight/2) + ($DerivativeHeight/2);
  4442. $StartX = floor($this->GraphAreaX1+$XMargin);
  4443. $EndX = floor($this->GraphAreaX2-$XMargin);
  4444. if ( $DrawBackground ) { $this->drawFilledRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
  4445. if ( $DrawBorder ) { $this->drawRectangle($StartX-1,$TopY-1,$EndX+1,$BottomY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4446. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4447. $RestoreShadow = $this->Shadow;
  4448. $this->Shadow = FALSE;
  4449. /* Determine the Max slope index */
  4450. $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
  4451. foreach($PosArray as $Key => $Y)
  4452. {
  4453. if ( $Y != VOID && $LastX != NULL )
  4454. { $Slope = ($LastY - $Y); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }
  4455. if ( $Y == VOID )
  4456. { $LastX = NULL; $LastY = NULL; }
  4457. else
  4458. { $LastX = $X; $LastY = $Y; }
  4459. }
  4460. $LastX = NULL; $LastY = NULL; $LastColor = NULL;
  4461. foreach($PosArray as $Key => $Y)
  4462. {
  4463. if ( $Y != VOID && $LastY != NULL )
  4464. {
  4465. $Slope = ($LastY - $Y);
  4466. if ( $Slope >= 0 )
  4467. {
  4468. $SlopeIndex = (100 / $MaxSlope) * $Slope;
  4469. $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
  4470. $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
  4471. $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
  4472. }
  4473. elseif ( $Slope < 0 )
  4474. {
  4475. $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
  4476. $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
  4477. $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
  4478. $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
  4479. }
  4480. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  4481. if ( $ShadedSlopeBox && $LastColor != NULL ) // && $Slope != 0
  4482. {
  4483. $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  4484. $this->drawGradientArea($LastX,$TopY,$X,$BottomY,DIRECTION_HORIZONTAL,$GradientSettings);
  4485. }
  4486. elseif ( !$ShadedSlopeBox || $LastColor == NULL ) // || $Slope == 0
  4487. $this->drawFilledRectangle(floor($LastX),$TopY,floor($X),$BottomY,$Color);
  4488. $LastColor = $Color;
  4489. }
  4490. if ( $Y == VOID )
  4491. { $LastY = NULL; }
  4492. else
  4493. { $LastX = $X; $LastY = $Y; }
  4494. $X = $X + $XStep;
  4495. }
  4496. $YPos = $YPos + $CaptionHeight + $SerieSpacing;
  4497. }
  4498. else
  4499. {
  4500. if ( $Caption )
  4501. {
  4502. $StartY = floor($this->GraphAreaY1-$CaptionWidth+$XMargin-$CaptionMargin);
  4503. $EndY = floor($this->GraphAreaY1-$CaptionMargin+$XMargin);
  4504. if ( $CaptionLine )
  4505. {
  4506. $CaptionSettings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks,"Weight"=>$Weight);
  4507. if ( $CaptionBox ) { $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$CaptionFillR,"G"=>$CaptionFillG,"B"=>$CaptionFillB,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB,"Alpha"=>$CaptionFillAlpha)); }
  4508. $this->drawLine($XPos+($CaptionHeight/2),$StartY+2,$XPos+($CaptionHeight/2),$EndY-2,$CaptionSettings);
  4509. }
  4510. else
  4511. $this->drawFilledRectangle($XPos,$StartY,$XPos+$CaptionHeight,$EndY,array("R"=>$R,"G"=>$G,"B"=>$B,"BorderR"=>$CaptionBorderR,"BorderG"=>$CaptionBorderG,"BorderB"=>$CaptionBorderB));
  4512. }
  4513. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4514. $Y = $this->GraphAreaY1 + $XMargin;
  4515. $TopX = $XPos + ($CaptionHeight/2) - ($DerivativeHeight/2);
  4516. $BottomX = $XPos + ($CaptionHeight/2) + ($DerivativeHeight/2);
  4517. $StartY = floor($this->GraphAreaY1+$XMargin);
  4518. $EndY = floor($this->GraphAreaY2-$XMargin);
  4519. if ( $DrawBackground ) { $this->drawFilledRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha)); }
  4520. if ( $DrawBorder ) { $this->drawRectangle($TopX-1,$StartY-1,$BottomX+1,$EndY+1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4521. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4522. $RestoreShadow = $this->Shadow;
  4523. $this->Shadow = FALSE;
  4524. /* Determine the Max slope index */
  4525. $LastX = NULL; $LastY = NULL; $MinSlope = 0; $MaxSlope = 1;
  4526. foreach($PosArray as $Key => $X)
  4527. {
  4528. if ( $X != VOID && $LastX != NULL )
  4529. { $Slope = ($X - $LastX); if ( $Slope > $MaxSlope ) { $MaxSlope = $Slope; } if ( $Slope < $MinSlope ) { $MinSlope = $Slope; } }
  4530. if ( $X == VOID )
  4531. { $LastX = NULL; }
  4532. else
  4533. { $LastX = $X; }
  4534. }
  4535. $LastX = NULL; $LastY = NULL; $LastColor = NULL;
  4536. foreach($PosArray as $Key => $X)
  4537. {
  4538. if ( $X != VOID && $LastX != NULL )
  4539. {
  4540. $Slope = ($X - $LastX);
  4541. if ( $Slope >= 0 )
  4542. {
  4543. $SlopeIndex = (100 / $MaxSlope) * $Slope;
  4544. $R = (($PositiveSlopeEndR - $PositiveSlopeStartR)/100)*$SlopeIndex+$PositiveSlopeStartR;
  4545. $G = (($PositiveSlopeEndG - $PositiveSlopeStartG)/100)*$SlopeIndex+$PositiveSlopeStartG;
  4546. $B = (($PositiveSlopeEndB - $PositiveSlopeStartB)/100)*$SlopeIndex+$PositiveSlopeStartB;
  4547. }
  4548. elseif ( $Slope < 0 )
  4549. {
  4550. $SlopeIndex = (100 / abs($MinSlope)) * abs($Slope);
  4551. $R = (($NegativeSlopeEndR - $NegativeSlopeStartR)/100)*$SlopeIndex+$NegativeSlopeStartR;
  4552. $G = (($NegativeSlopeEndG - $NegativeSlopeStartG)/100)*$SlopeIndex+$NegativeSlopeStartG;
  4553. $B = (($NegativeSlopeEndB - $NegativeSlopeStartB)/100)*$SlopeIndex+$NegativeSlopeStartB;
  4554. }
  4555. $Color = array("R"=>$R,"G"=>$G,"B"=>$B);
  4556. if ( $ShadedSlopeBox && $LastColor != NULL )
  4557. {
  4558. $GradientSettings = array("StartR"=>$LastColor["R"],"StartG"=>$LastColor["G"],"StartB"=>$LastColor["B"],"EndR"=>$R,"EndG"=>$G,"EndB"=>$B);
  4559. $this->drawGradientArea($TopX,$LastY,$BottomX,$Y,DIRECTION_VERTICAL,$GradientSettings);
  4560. }
  4561. elseif ( !$ShadedSlopeBox || $LastColor == NULL )
  4562. $this->drawFilledRectangle($TopX,floor($LastY),$BottomX,floor($Y),$Color);
  4563. $LastColor = $Color;
  4564. }
  4565. if ( $X == VOID )
  4566. { $LastX = NULL; }
  4567. else
  4568. { $LastX = $X; $LastY = $Y; }
  4569. $Y = $Y + $XStep;
  4570. }
  4571. $XPos = $XPos + $CaptionHeight + $SerieSpacing;
  4572. }
  4573. $this->Shadow = $RestoreShadow;
  4574. }
  4575. }
  4576. }
  4577. /* Draw the line of best fit */
  4578. function drawBestFit($Format="")
  4579. {
  4580. $OverrideTicks = isset($Format["Ticks"]) ? $Format["Ticks"] : NULL;
  4581. $OverrideR = isset($Format["R"]) ? $Format["R"] : VOID;
  4582. $OverrideG = isset($Format["G"]) ? $Format["G"] : VOID;
  4583. $OverrideB = isset($Format["B"]) ? $Format["B"] : VOID;
  4584. $OverrideAlpha = isset($Format["Alpha"]) ? $Format["Alpha"] : VOID;
  4585. $Data = $this->DataSet->getData();
  4586. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4587. foreach($Data["Series"] as $SerieName => $Serie)
  4588. {
  4589. if ( $Serie["isDrawable"] == TRUE && $SerieName != $Data["Abscissa"] )
  4590. {
  4591. if ( $OverrideR != VOID && $OverrideG != VOID && $OverrideB != VOID ) { $R = $OverrideR; $G = $OverrideG; $B = $OverrideB; } else { $R = $Serie["Color"]["R"]; $G = $Serie["Color"]["G"]; $B = $Serie["Color"]["B"]; }
  4592. if ( $OverrideTicks == NULL ) { $Ticks = $Serie["Ticks"]; } else { $Ticks = $OverrideTicks; }
  4593. if ( $OverrideAlpha == VOID ) { $Alpha = $Serie["Color"]["Alpha"]; } else { $Alpha = $OverrideAlpha; }
  4594. $Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks);
  4595. $AxisID = $Serie["Axis"];
  4596. $PosArray = $this->scaleComputeY($Serie["Data"],array("AxisID"=>$Serie["Axis"]));
  4597. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4598. {
  4599. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4600. $X = $this->GraphAreaX1 + $XMargin;
  4601. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4602. $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
  4603. foreach($PosArray as $Key => $Y)
  4604. {
  4605. if ( $Y != VOID )
  4606. {
  4607. $Sxy = $Sxy + $X*$Y;
  4608. $Sx = $Sx + $X;
  4609. $Sy = $Sy + $Y;
  4610. $Sxx = $Sxx + $X*$X;
  4611. }
  4612. $X = $X + $XStep;
  4613. }
  4614. $n = count($this->DataSet->stripVOID($PosArray)); //$n = count($PosArray);
  4615. $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
  4616. $B = (($Sy)-($M*$Sx))/($n);
  4617. $X1 = $this->GraphAreaX1 + $XMargin;
  4618. $Y1 = $M * $X1 + $B;
  4619. $X2 = $this->GraphAreaX2 - $XMargin;
  4620. $Y2 = $M * $X2 + $B;
  4621. if ( $Y1 < $this->GraphAreaY1 ) { $X1 = $X1 + ($this->GraphAreaY1-$Y1); $Y1 = $this->GraphAreaY1; }
  4622. if ( $Y1 > $this->GraphAreaY2 ) { $X1 = $X1 + ($Y1-$this->GraphAreaY2); $Y1 = $this->GraphAreaY2; }
  4623. if ( $Y2 < $this->GraphAreaY1 ) { $X2 = $X2 - ($this->GraphAreaY1-$Y2); $Y2 = $this->GraphAreaY1; }
  4624. if ( $Y2 > $this->GraphAreaY2 ) { $X2 = $X2 - ($Y2-$this->GraphAreaY2); $Y2 = $this->GraphAreaY2; }
  4625. $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
  4626. }
  4627. else
  4628. {
  4629. if ( $XDivs == 0 ) { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $YStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4630. $Y = $this->GraphAreaY1 + $XMargin;
  4631. if ( !is_array($PosArray) ) { $Value = $PosArray; $PosArray = ""; $PosArray[0] = $Value; }
  4632. $Sxy = 0; $Sx = 0; $Sy = 0; $Sxx = 0;
  4633. foreach($PosArray as $Key => $X)
  4634. {
  4635. if ( $X != VOID )
  4636. {
  4637. $Sxy = $Sxy + $X*$Y;
  4638. $Sx = $Sx + $Y;
  4639. $Sy = $Sy + $X;
  4640. $Sxx = $Sxx + $Y*$Y;
  4641. }
  4642. $Y = $Y + $YStep;
  4643. }
  4644. $n = count($this->DataSet->stripVOID($PosArray)); //$n = count($PosArray);
  4645. $M = (($n*$Sxy)-($Sx*$Sy)) / (($n*$Sxx)-($Sx*$Sx));
  4646. $B = (($Sy)-($M*$Sx))/($n);
  4647. $Y1 = $this->GraphAreaY1 + $XMargin;
  4648. $X1 = $M * $Y1 + $B;
  4649. $Y2 = $this->GraphAreaY2 - $XMargin;
  4650. $X2 = $M * $Y2 + $B;
  4651. if ( $X1 < $this->GraphAreaX1 ) { $Y1 = $Y1 + ($this->GraphAreaX1-$X1); $X1 = $this->GraphAreaX1; }
  4652. if ( $X1 > $this->GraphAreaX2 ) { $Y1 = $Y1 + ($X1-$this->GraphAreaX2); $X1 = $this->GraphAreaX2; }
  4653. if ( $X2 < $this->GraphAreaX1 ) { $Y2 = $Y2 - ($this->GraphAreaY1-$X2); $X2 = $this->GraphAreaX1; }
  4654. if ( $X2 > $this->GraphAreaX2 ) { $Y2 = $Y2 - ($X2-$this->GraphAreaX2); $X2 = $this->GraphAreaX2; }
  4655. $this->drawLine($X1,$Y1,$X2,$Y2,$Color);
  4656. }
  4657. }
  4658. }
  4659. }
  4660. /* Write labels */
  4661. function writeLabel($SeriesName,$Indexes,$Format="")
  4662. {
  4663. $OverrideTitle = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
  4664. $ForceLabels = isset($Format["ForceLabels"]) ? $Format["ForceLabels"] : NULL;
  4665. $DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
  4666. $DrawVerticalLine = isset($Format["DrawVerticalLine"]) ? $Format["DrawVerticalLine"] : FALSE;
  4667. $VerticalLineR = isset($Format["VerticalLineR"]) ? $Format["VerticalLineR"] : 0;
  4668. $VerticalLineG = isset($Format["VerticalLineG"]) ? $Format["VerticalLineG"] : 0;
  4669. $VerticalLineB = isset($Format["VerticalLineB"]) ? $Format["VerticalLineB"] : 0;
  4670. $VerticalLineAlpha = isset($Format["VerticalLineAlpha"]) ? $Format["VerticalLineAlpha"] : 40;
  4671. $VerticalLineTicks = isset($Format["VerticalLineTicks"]) ? $Format["VerticalLineTicks"] : 2;
  4672. $Data = $this->DataSet->getData();
  4673. list($XMargin,$XDivs) = $this->scaleGetXSettings();
  4674. if ( !is_array($Indexes) ) { $Index = $Indexes; $Indexes = ""; $Indexes[] = $Index; }
  4675. if ( !is_array($SeriesName) ) { $SerieName = $SeriesName; $SeriesName = ""; $SeriesName[] = $SerieName; }
  4676. if ( $ForceLabels != NULL && !is_array($ForceLabels) ) { $ForceLabel = $ForceLabels; $ForceLabels = ""; $ForceLabels[] = $ForceLabel; }
  4677. foreach ($Indexes as $Key => $Index)
  4678. {
  4679. $Series = "";
  4680. if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
  4681. {
  4682. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
  4683. $X = $this->GraphAreaX1 + $XMargin + $Index * $XStep;
  4684. if ( $DrawVerticalLine ) { $this->drawLine($X,$this->GraphAreaY1+$Data["YMargin"],$X,$this->GraphAreaY2-$Data["YMargin"],array("R"=>$VerticalLineR,"G"=>$VerticalLineG,"B"=>$VerticalLineB,"Alpha"=>$VerticalLineAlpha,"Ticks"=>$VerticalLineTicks)); }
  4685. $MinY = $this->GraphAreaY2;
  4686. foreach ($SeriesName as $iKey => $SerieName)
  4687. {
  4688. if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
  4689. {
  4690. $AxisID = $Data["Series"][$SerieName]["Axis"];
  4691. $XAxisMode = $Data["XAxisDisplay"];
  4692. $XAxisFormat = $Data["XAxisFormat"];
  4693. $XAxisUnit = $Data["XAxisUnit"];
  4694. $AxisMode = $Data["Axis"][$AxisID]["Display"];
  4695. $AxisFormat = $Data["Axis"][$AxisID]["Format"];
  4696. $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
  4697. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4698. $XLabel = $this->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index],$XAxisMode,$XAxisFormat,$XAxisUnit);
  4699. else
  4700. $XLabel = "";
  4701. if ( $OverrideTitle != NULL)
  4702. $Description = $OverrideTitle;
  4703. elseif ( count($SeriesName) == 1 )
  4704. {
  4705. $Description = $Data["Series"][$SerieName]["Description"]." - ".$XLabel;
  4706. }
  4707. elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4708. $Description = $XLabel;
  4709. $Serie = "";
  4710. $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
  4711. $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
  4712. $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
  4713. $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
  4714. if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
  4715. $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
  4716. else
  4717. $SerieOffset = 0;
  4718. $Value = $Data["Series"][$SerieName]["Data"][$Index];
  4719. if ( $Value == VOID ) { $Value = "NaN"; }
  4720. if ( $ForceLabels != NULL )
  4721. $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
  4722. else
  4723. $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
  4724. if ( $this->LastChartLayout == CHART_LAST_LAYOUT_STACKED )
  4725. {
  4726. if ( $Value >=0 ) { $LookFor = "+"; } else { $LookFor = "-"; }
  4727. $Value = 0; $Done = FALSE;
  4728. foreach($Data["Series"] as $Name => $SerieLookup)
  4729. {
  4730. if ( $SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done )
  4731. {
  4732. if ( isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID )
  4733. {
  4734. if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+" ) { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; }
  4735. if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-" ) { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; }
  4736. if ($Name == $SerieName ) { $Done = TRUE; }
  4737. }
  4738. }
  4739. }
  4740. }
  4741. $X = floor($this->GraphAreaX1 + $XMargin + $Index * $XStep + $SerieOffset);
  4742. $Y = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
  4743. if ($Y < $MinY) { $MinY = $Y; }
  4744. if ( $DrawPoint == LABEL_POINT_CIRCLE )
  4745. $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4746. elseif ( $DrawPoint == LABEL_POINT_BOX )
  4747. $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4748. $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
  4749. }
  4750. }
  4751. $this->drawLabelBox($X,$MinY-3,$Description,$Series,$Format);
  4752. }
  4753. else
  4754. {
  4755. if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
  4756. $Y = $this->GraphAreaY1 + $XMargin + $Index * $XStep;
  4757. if ( $DrawVerticalLine ) { $this->drawLine($this->GraphAreaX1+$Data["YMargin"],$Y,$this->GraphAreaX2-$Data["YMargin"],$Y,array("R"=>$VerticalLineR,"G"=>$VerticalLineG,"B"=>$VerticalLineB,"Alpha"=>$VerticalLineAlpha,"Ticks"=>$VerticalLineTicks)); }
  4758. $MinX = $this->GraphAreaX2;
  4759. foreach ($SeriesName as $Key => $SerieName)
  4760. {
  4761. if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
  4762. {
  4763. $AxisID = $Data["Series"][$SerieName]["Axis"];
  4764. $XAxisMode = $Data["XAxisDisplay"];
  4765. $XAxisFormat = $Data["XAxisFormat"];
  4766. $XAxisUnit = $Data["XAxisUnit"];
  4767. $AxisMode = $Data["Axis"][$AxisID]["Display"];
  4768. $AxisFormat = $Data["Axis"][$AxisID]["Format"];
  4769. $AxisUnit = $Data["Axis"][$AxisID]["Unit"];
  4770. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4771. $XLabel = $this->scaleFormat($Data["Series"][$Data["Abscissa"]]["Data"][$Index],$XAxisMode,$XAxisFormat,$XAxisUnit);
  4772. else
  4773. $XLabel = "";
  4774. if ( $OverrideTitle != NULL)
  4775. $Description = $OverrideTitle;
  4776. elseif ( count($SeriesName) == 1 )
  4777. {
  4778. if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4779. $Description = $Data["Series"][$SerieName]["Description"]." - ".$XLabel;
  4780. }
  4781. elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
  4782. $Description = $XLabel;
  4783. $Serie = "";
  4784. if ( isset($Data["Extended"]["Palette"][$Index] ) )
  4785. {
  4786. $Serie["R"] = $Data["Extended"]["Palette"][$Index]["R"];
  4787. $Serie["G"] = $Data["Extended"]["Palette"][$Index]["G"];
  4788. $Serie["B"] = $Data["Extended"]["Palette"][$Index]["B"];
  4789. $Serie["Alpha"] = $Data["Extended"]["Palette"][$Index]["Alpha"];
  4790. }
  4791. else
  4792. {
  4793. $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
  4794. $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
  4795. $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
  4796. $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
  4797. }
  4798. if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
  4799. $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
  4800. else
  4801. $SerieOffset = 0;
  4802. $Value = $Data["Series"][$SerieName]["Data"][$Index];
  4803. if ( $ForceLabels != NULL )
  4804. $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
  4805. else
  4806. $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
  4807. if ( $Value == VOID ) { $Value = "NaN"; }
  4808. if ( $this->LastChartLayout == CHART_LAST_LAYOUT_STACKED )
  4809. {
  4810. if ( $Value >=0 ) { $LookFor = "+"; } else { $LookFor = "-"; }
  4811. $Value = 0; $Done = FALSE;
  4812. foreach($Data["Series"] as $Name => $SerieLookup)
  4813. {
  4814. if ( $SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done )
  4815. {
  4816. if ( isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID )
  4817. {
  4818. if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+" ) { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; }
  4819. if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-" ) { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; }
  4820. if ($Name == $SerieName ) { $Done = TRUE; }
  4821. }
  4822. }
  4823. }
  4824. }
  4825. $X = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
  4826. $Y = floor($this->GraphAreaY1 + $XMargin + $Index * $XStep + $SerieOffset);
  4827. if ($X < $MinX) { $MinX = $X; }
  4828. if ( $DrawPoint == LABEL_POINT_CIRCLE )
  4829. $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4830. elseif ( $DrawPoint == LABEL_POINT_BOX )
  4831. $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
  4832. $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
  4833. }
  4834. }
  4835. $this->drawLabelBox($MinX,$Y-3,$Description,$Series,$Format);
  4836. }
  4837. }
  4838. }
  4839. /* Draw a label box */
  4840. function drawLabelBox($X,$Y,$Title,$Captions,$Format="")
  4841. {
  4842. $NoTitle = isset($Format["NoTitle"]) ? $Format["NoTitle"] : NULL;
  4843. $BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 50;
  4844. $DrawSerieColor = isset($Format["DrawSerieColor"]) ? $Format["DrawSerieColor"] : TRUE;
  4845. $SerieR = isset($Format["SerieR"]) ? $Format["SerieR"] : NULL;
  4846. $SerieG = isset($Format["SerieG"]) ? $Format["SerieG"] : NULL;
  4847. $SerieB = isset($Format["SerieB"]) ? $Format["SerieB"] : NULL;
  4848. $SerieAlpha = isset($Format["SerieAlpha"]) ? $Format["SerieAlpha"] : NULL;
  4849. $SerieBoxSize = isset($Format["SerieBoxSize"]) ? $Format["SerieBoxSize"] : 6;
  4850. $SerieBoxSpacing = isset($Format["SerieBoxSpacing"]) ? $Format["SerieBoxSpacing"] : 4;
  4851. $VerticalMargin = isset($Format["VerticalMargin"]) ? $Format["VerticalMargin"] : 10;
  4852. $HorizontalMargin = isset($Format["HorizontalMargin"]) ? $Format["HorizontalMargin"] : 8;
  4853. $R = isset($Format["R"]) ? $Format["R"] : $this->FontColorR;
  4854. $G = isset($Format["G"]) ? $Format["G"] : $this->FontColorG;
  4855. $B = isset($Format["B"]) ? $Format["B"] : $this->FontColorB;
  4856. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->FontColorA;
  4857. $FontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->FontName;
  4858. $FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->FontSize;
  4859. $TitleMode = isset($Format["TitleMode"]) ? $Format["TitleMode"] : LABEL_TITLE_NOBACKGROUND;
  4860. $TitleR = isset($Format["TitleR"]) ? $Format["TitleR"] : $R;
  4861. $TitleG = isset($Format["TitleG"]) ? $Format["TitleG"] : $G;
  4862. $TitleB = isset($Format["TitleB"]) ? $Format["TitleB"] : $B;
  4863. $TitleAlpha = isset($Format["TitleAlpha"]) ? $Format["TitleAlpha"] : 100;
  4864. $TitleBackgroundR = isset($Format["TitleBackgroundR"]) ? $Format["TitleBackgroundR"] : 0;
  4865. $TitleBackgroundG = isset($Format["TitleBackgroundG"]) ? $Format["TitleBackgroundG"] : 0;
  4866. $TitleBackgroundB = isset($Format["TitleBackgroundB"]) ? $Format["TitleBackgroundB"] : 0;
  4867. $TitleBackgroundAlpha = isset($Format["TitleBackgroundAlpha"]) ? $Format["TitleBackgroundAlpha"] : 100;
  4868. $GradientStartR = isset($Format["GradientStartR"]) ? $Format["GradientStartR"] : 255;
  4869. $GradientStartG = isset($Format["GradientStartG"]) ? $Format["GradientStartG"] : 255;
  4870. $GradientStartB = isset($Format["GradientStartB"]) ? $Format["GradientStartB"] : 255;
  4871. $GradientEndR = isset($Format["GradientEndR"]) ? $Format["GradientEndR"] : 220;
  4872. $GradientEndG = isset($Format["GradientEndG"]) ? $Format["GradientEndG"] : 220;
  4873. $GradientEndB = isset($Format["GradientEndB"]) ? $Format["GradientEndB"] : 220;
  4874. $BoxAlpha = isset($Format["BoxAlpha"]) ? $Format["BoxAlpha"] : 100;
  4875. if ( !$DrawSerieColor ) { $SerieBoxSize = 0; $SerieBoxSpacing = 0; }
  4876. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Title);
  4877. $TitleWidth = ($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2;
  4878. $TitleHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);
  4879. if ( $NoTitle ) { $TitleWidth = 0; $TitleHeight = 0; }
  4880. $CaptionWidth = 0; $CaptionHeight = -$HorizontalMargin;
  4881. foreach($Captions as $Key =>$Caption)
  4882. {
  4883. $TxtPos = $this->getTextBox($X,$Y,$FontName,$FontSize,0,$Caption["Caption"]);
  4884. $CaptionWidth = max($CaptionWidth,($TxtPos[1]["X"] - $TxtPos[0]["X"])+$VerticalMargin*2);
  4885. $CaptionHeight = $CaptionHeight + max(($TxtPos[0]["Y"] - $TxtPos[2]["Y"]),($SerieBoxSize+2)) + $HorizontalMargin;
  4886. }
  4887. if ( $CaptionHeight <= 5 ) { $CaptionHeight = $CaptionHeight + $HorizontalMargin/2; }
  4888. if ( $DrawSerieColor ) { $CaptionWidth = $CaptionWidth + $SerieBoxSize + $SerieBoxSpacing; }
  4889. $BoxWidth = max($BoxWidth,$TitleWidth,$CaptionWidth);
  4890. $XMin = $X - 5 - floor(($BoxWidth-10) / 2);
  4891. $XMax = $X + 5 + floor(($BoxWidth-10) / 2);
  4892. $RestoreShadow = $this->Shadow;
  4893. if ( $this->Shadow == TRUE )
  4894. {
  4895. $this->Shadow = FALSE;
  4896. $Poly = "";
  4897. $Poly[] = $X+$this->ShadowX; $Poly[] = $Y+$this->ShadowX;
  4898. $Poly[] = $X+5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4899. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4900. if ( $NoTitle )
  4901. {
  4902. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
  4903. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2+$this->ShadowX;
  4904. }
  4905. else
  4906. {
  4907. $Poly[] = $XMax+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
  4908. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3+$this->ShadowX;
  4909. }
  4910. $Poly[] = $XMin+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4911. $Poly[] = $X-5+$this->ShadowX; $Poly[] = $Y-5+$this->ShadowX;
  4912. $this->drawPolygon($Poly,array("R"=>$this->ShadowR,"G"=>$this->ShadowG,"B"=>$this->ShadowB,"Alpha"=>$this->Shadowa));
  4913. }
  4914. /* Draw the background */
  4915. $GradientSettings = array("StartR"=>$GradientStartR,"StartG"=>$GradientStartG,"StartB"=>$GradientStartB,"EndR"=>$GradientEndR,"EndG"=>$GradientEndG,"EndB"=>$GradientEndB,"Alpha"=>$BoxAlpha);
  4916. if ( $NoTitle )
  4917. $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
  4918. else
  4919. $this->drawGradientArea($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-6,DIRECTION_VERTICAL,$GradientSettings);
  4920. $Poly = ""; $Poly[] = $X; $Poly[] = $Y; $Poly[] = $X-5; $Poly[] = $Y-5; $Poly[] = $X+5; $Poly[] = $Y-5;
  4921. $this->drawPolygon($Poly,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB,"Alpha"=>$BoxAlpha,"NoBorder"=>TRUE));
  4922. /* Outer border */
  4923. $OuterBorderColor = $this->allocateColor($this->Picture,100,100,100,$BoxAlpha);
  4924. imageline($this->Picture,$XMin,$Y-5,$X-5,$Y-5,$OuterBorderColor);
  4925. imageline($this->Picture,$X,$Y,$X-5,$Y-5,$OuterBorderColor);
  4926. imageline($this->Picture,$X,$Y,$X+5,$Y-5,$OuterBorderColor);
  4927. imageline($this->Picture,$X+5,$Y-5,$XMax,$Y-5,$OuterBorderColor);
  4928. if ( $NoTitle )
  4929. {
  4930. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin,$Y-5,$OuterBorderColor);
  4931. imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5,$OuterBorderColor);
  4932. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$OuterBorderColor);
  4933. }
  4934. else
  4935. {
  4936. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin,$Y-5,$OuterBorderColor);
  4937. imageline($this->Picture,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5,$OuterBorderColor);
  4938. imageline($this->Picture,$XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$OuterBorderColor);
  4939. }
  4940. /* Inner border */
  4941. $InnerBorderColor = $this->allocateColor($this->Picture,255,255,255,$BoxAlpha);
  4942. imageline($this->Picture,$XMin+1,$Y-6,$X-5,$Y-6,$InnerBorderColor);
  4943. imageline($this->Picture,$X,$Y-1,$X-5,$Y-6,$InnerBorderColor);
  4944. imageline($this->Picture,$X,$Y-1,$X+5,$Y-6,$InnerBorderColor);
  4945. imageline($this->Picture,$X+5,$Y-6,$XMax-1,$Y-6,$InnerBorderColor);
  4946. if ( $NoTitle )
  4947. {
  4948. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMin+1,$Y-6,$InnerBorderColor);
  4949. imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-6,$InnerBorderColor);
  4950. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*2,$InnerBorderColor);
  4951. }
  4952. else
  4953. {
  4954. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMin+1,$Y-6,$InnerBorderColor);
  4955. imageline($this->Picture,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-6,$InnerBorderColor);
  4956. imageline($this->Picture,$XMin+1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax-1,$Y-4-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$InnerBorderColor);
  4957. }
  4958. /* Draw the separator line */
  4959. if ( $TitleMode == LABEL_TITLE_NOBACKGROUND && !$NoTitle )
  4960. {
  4961. $YPos = $Y-7-$CaptionHeight-$HorizontalMargin-$HorizontalMargin/2;
  4962. $XMargin = $VerticalMargin / 2;
  4963. $this->drawLine($XMin+$XMargin,$YPos+1,$XMax-$XMargin,$YPos+1,array("R"=>$GradientEndR,"G"=>$GradientEndG,"B"=>$GradientEndB,"Alpha"=>$BoxAlpha));
  4964. $this->drawLine($XMin+$XMargin,$YPos,$XMax-$XMargin,$YPos,array("R"=>$GradientStartR,"G"=>$GradientStartG,"B"=>$GradientStartB,"Alpha"=>$BoxAlpha));
  4965. }
  4966. elseif ( $TitleMode == LABEL_TITLE_BACKGROUND )
  4967. {
  4968. $this->drawFilledRectangle($XMin,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin*3,$XMax,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2,array("R"=>$TitleBackgroundR,"G"=>$TitleBackgroundG,"B"=>$TitleBackgroundB,"Alpha"=>$BoxAlpha));
  4969. imageline($this->Picture,$XMin+1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$XMax-1,$Y-5-$TitleHeight-$CaptionHeight-$HorizontalMargin+$HorizontalMargin/2+1,$InnerBorderColor);
  4970. }
  4971. /* Write the description */
  4972. if ( !$NoTitle )
  4973. $this->drawText($XMin+$VerticalMargin,$Y-7-$CaptionHeight-$HorizontalMargin*2,$Title,array("Align"=>TEXT_ALIGN_BOTTOMLEFT,"R"=>$TitleR,"G"=>$TitleG,"B"=>$TitleB));
  4974. /* Write the value */
  4975. $YPos = $Y-5-$HorizontalMargin; $XPos = $XMin+$VerticalMargin+$SerieBoxSize+$SerieBoxSpacing;
  4976. foreach($Captions as $Key => $Caption)
  4977. {
  4978. $CaptionTxt = $Caption["Caption"];
  4979. $TxtPos = $this->getTextBox($XPos,$YPos,$FontName,$FontSize,0,$CaptionTxt);
  4980. $CaptionHeight = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]);
  4981. /* Write the serie color if needed */
  4982. if ( $DrawSerieColor )
  4983. {
  4984. $BoxSettings = array("R"=>$Caption["Format"]["R"],"G"=>$Caption["Format"]["G"],"B"=>$Caption["Format"]["B"],"Alpha"=>$Caption["Format"]["Alpha"],"BorderR"=>0,"BorderG"=>0,"BorderB"=>0);
  4985. $this->drawFilledRectangle($XMin+$VerticalMargin,$YPos-$SerieBoxSize,$XMin+$VerticalMargin+$SerieBoxSize,$YPos,$BoxSettings);
  4986. }
  4987. $this->drawText($XPos,$YPos,$CaptionTxt,array("Align"=>TEXT_ALIGN_BOTTOMLEFT));
  4988. $YPos = $YPos - $CaptionHeight - $HorizontalMargin;
  4989. }
  4990. $this->Shadow = $RestoreShadow;
  4991. }
  4992. /* Draw a basic shape */
  4993. function drawShape($X,$Y,$Shape,$PlotSize,$PlotBorder,$BorderSize,$R,$G,$B,$Alpha,$BorderR,$BorderG,$BorderB,$BorderAlpha)
  4994. {
  4995. if ( $Shape == SERIE_SHAPE_FILLEDCIRCLE )
  4996. {
  4997. if ( $PlotBorder ) { $this->drawFilledCircle($X,$Y,$PlotSize+$BorderSize,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  4998. $this->drawFilledCircle($X,$Y,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  4999. }
  5000. elseif ( $Shape == SERIE_SHAPE_FILLEDSQUARE )
  5001. {
  5002. if ( $PlotBorder ) { $this->drawFilledRectangle($X-$PlotSize-$BorderSize,$Y-$PlotSize-$BorderSize,$X+$PlotSize+$BorderSize,$Y+$PlotSize+$BorderSize,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha)); }
  5003. $this->drawFilledRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5004. }
  5005. elseif ( $Shape == SERIE_SHAPE_FILLEDTRIANGLE )
  5006. {
  5007. if ( $PlotBorder )
  5008. {
  5009. $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize-$BorderSize; $Pos[]=$X-$PlotSize-$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize; $Pos[]=$X+$PlotSize+$BorderSize; $Pos[]=$Y+$PlotSize+$BorderSize;
  5010. $this->drawPolygon($Pos,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha));
  5011. }
  5012. $Pos = ""; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X-$PlotSize; $Pos[]=$Y+$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y+$PlotSize;
  5013. $this->drawPolygon($Pos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5014. }
  5015. elseif ( $Shape == SERIE_SHAPE_TRIANGLE )
  5016. {
  5017. $this->drawLine($X,$Y-$PlotSize,$X-$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5018. $this->drawLine($X-$PlotSize,$Y+$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5019. $this->drawLine($X+$PlotSize,$Y+$PlotSize,$X,$Y-$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5020. }
  5021. elseif ( $Shape == SERIE_SHAPE_SQUARE )
  5022. $this->drawRectangle($X-$PlotSize,$Y-$PlotSize,$X+$PlotSize,$Y+$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5023. elseif ( $Shape == SERIE_SHAPE_CIRCLE )
  5024. $this->drawCircle($X,$Y,$PlotSize,$PlotSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5025. elseif ( $Shape == SERIE_SHAPE_DIAMOND )
  5026. {
  5027. $Pos = ""; $Pos[]=$X-$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize;
  5028. $this->drawPolygon($Pos,array("NoFill"=>TRUE,"BorderR"=>$R,"BorderG"=>$G,"BorderB"=>$B,"BorderAlpha"=>$Alpha));
  5029. }
  5030. elseif ( $Shape == SERIE_SHAPE_FILLEDDIAMOND )
  5031. {
  5032. if ( $PlotBorder )
  5033. {
  5034. $Pos = ""; $Pos[]=$X-$PlotSize-$BorderSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize-$BorderSize; $Pos[]=$X+$PlotSize+$BorderSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize+$BorderSize;
  5035. $this->drawPolygon($Pos,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha));
  5036. }
  5037. $Pos = ""; $Pos[]=$X-$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y-$PlotSize; $Pos[]=$X+$PlotSize; $Pos[]=$Y; $Pos[]=$X; $Pos[]=$Y+$PlotSize;
  5038. $this->drawPolygon($Pos,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));
  5039. }
  5040. }
  5041. function drawPolygonChart($Points,$Format="")
  5042. {
  5043. $R = isset($Format["R"]) ? $Format["R"] : 0;
  5044. $G = isset($Format["G"]) ? $Format["G"] : 0;
  5045. $B = isset($Format["B"]) ? $Format["B"] : 0;
  5046. $Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
  5047. $NoFill = isset($Format["NoFill"]) ? $Format["NoFill"] : FALSE;
  5048. $NoBorder = isset($Format["NoBorder"]) ? $Format["NoBorder"] : FALSE;
  5049. $BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
  5050. $BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
  5051. $BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
  5052. $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha / 2;
  5053. $Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
  5054. $Threshold = isset($Format["Threshold"]) ? $Format["Threshold"] : NULL;
  5055. if ( $Surrounding != NULL ) { $BorderR = $R+$Surrounding; $BorderG = $G+$Surrounding; $BorderB = $B+$Surrounding; }
  5056. $RestoreShadow = $this->Shadow;
  5057. $this->Shadow = FALSE;
  5058. $AllIntegers = TRUE;
  5059. for($i=0;$i<=count($Points)-2;$i=$i+2)
  5060. { if ( $this->getFirstDecimal($Points[$i+1]) != 0 ) { $AllIntegers = FALSE; } }
  5061. /* Convert polygon to segments */
  5062. $Segments = "";
  5063. for($i=2;$i<=count($Points)-2;$i=$i+2)
  5064. { $Segments[] = array("X1"=>$Points[$i-2],"Y1"=>$Points[$i-1],"X2"=>$Points[$i],"Y2"=>$Points[$i+1]); }
  5065. $Segments[] = array("X1"=>$Points[$i-2],"Y1"=>$Points[$i-1],"X2"=>$Points[0],"Y2"=>$Points[1]);
  5066. /* Simplify straight lines */
  5067. $Result = ""; $inHorizon = FALSE; $LastX = VOID;
  5068. foreach($Segments as $Key => $Pos)
  5069. {
  5070. if ( $Pos["Y1"] != $Pos["Y2"] )
  5071. {
  5072. if ( $inHorizon ) { $inHorizon = FALSE; $Result[] = array("X1"=>$LastX,"Y1"=>$Pos["Y1"],"X2"=>$Pos["X1"],"Y2"=>$Pos["Y1"]); }
  5073. $Result[] = array("X1"=>$Pos["X1"],"Y1"=>$Pos["Y1"],"X2"=>$Pos["X2"],"Y2"=>$Pos["Y2"]);
  5074. }
  5075. else { if ( !$inHorizon ) { $inHorizon = TRUE; $LastX = $Pos["X1"];} }
  5076. }
  5077. $Segments = $Result;
  5078. /* Do we have something to draw */
  5079. if ( $Segments == "" ) { return(0); }
  5080. /* For segments debugging purpose */
  5081. //foreach($Segments as $Key => $Pos)
  5082. // echo $Pos["X1"].",".$Pos["Y1"].",".$Pos["X2"].",".$Pos["Y2"]."\r\n";
  5083. /* Find out the min & max Y boundaries */
  5084. $MinY = OUT_OF_SIGHT; $MaxY = OUT_OF_SIGHT;
  5085. foreach($Segments as $Key => $Coords)
  5086. {
  5087. if ( $MinY == OUT_OF_SIGHT || $MinY > min($Coords["Y1"],$Coords["Y2"]) ) { $MinY = min($Coords["Y1"],$Coords["Y2"]); }
  5088. if ( $MaxY == OUT_OF_SIGHT || $MaxY < max($Coords["Y1"],$Coords["Y2"]) ) { $MaxY = max($Coords["Y1"],$Coords["Y2"]); }
  5089. }
  5090. if ( $AllIntegers ) { $YStep = 1; } else { $YStep = .5; }
  5091. $MinY = floor($MinY); $MaxY = floor($MaxY);
  5092. /* Scan each Y lines */
  5093. $DefaultColor = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  5094. $DebugLine = 0; $DebugColor = $this->allocateColor($this->Picture,255,0,0,100);
  5095. $MinY = floor($MinY); $MaxY = floor($MaxY); $YStep = 1;
  5096. if ( !$NoFill )
  5097. {
  5098. //if ( $DebugLine ) { $MinY = $DebugLine; $MaxY = $DebugLine; }
  5099. for($Y=$MinY;$Y<=$MaxY;$Y=$Y+$YStep)
  5100. {
  5101. $Intersections = ""; $LastSlope = NULL; $RestoreLast = "-";
  5102. foreach($Segments as $Key => $Coords)
  5103. {
  5104. $X1 = $Coords["X1"]; $X2 = $Coords["X2"]; $Y1 = $Coords["Y1"]; $Y2 = $Coords["Y2"];
  5105. if ( min($Y1,$Y2) <= $Y && max($Y1,$Y2) >= $Y )
  5106. {
  5107. if ( $Y1 == $Y2 )
  5108. { $X = $X1; }
  5109. else
  5110. { $X = $X1 + ( ($Y-$Y1)*$X2 - ($Y-$Y1)*$X1 ) / ($Y2-$Y1); }
  5111. $X = floor($X);
  5112. if ( $X2 == $X1 )
  5113. { $Slope = "!"; }
  5114. else
  5115. {
  5116. $SlopeC = ($Y2 - $Y1) / ($X2 - $X1);
  5117. if( $SlopeC == 0 )
  5118. { $Slope = "="; }
  5119. elseif( $SlopeC > 0 )
  5120. { $Slope = "+"; }
  5121. elseif ( $SlopeC < 0 )
  5122. { $Slope = "-"; }
  5123. }
  5124. if ( !is_array($Intersections) )
  5125. { $Intersections[] = $X; }
  5126. elseif( !in_array($X,$Intersections) )
  5127. { $Intersections[] = $X; }
  5128. elseif( in_array($X,$Intersections) )
  5129. {
  5130. if ($Y == $DebugLine) { echo $Slope."/".$LastSlope."(".$X.") "; }
  5131. if ( $Slope == "=" && $LastSlope == "-" ) { $Intersections[] = $X; }
  5132. if ( $Slope != $LastSlope && $LastSlope != "!" && $LastSlope != "=" ) { $Intersections[] = $X; }
  5133. if ( $Slope != $LastSlope && $LastSlope == "!" && $Slope == "+" ) { $Intersections[] = $X; }
  5134. }
  5135. if ( is_array($Intersections) && in_array($X,$Intersections) && $LastSlope == "=" && ($Slope == "-" )) { $Intersections[] = $X; }
  5136. $LastSlope = $Slope;
  5137. }
  5138. }
  5139. if ( $RestoreLast != "-" ) { $Intersections[] = $RestoreLast; echo "@".$Y."\r\n"; }
  5140. if ( is_array($Intersections) )
  5141. {
  5142. sort($Intersections);
  5143. if ($Y == $DebugLine) { print_r($Intersections); }
  5144. /* Remove NULL plots */
  5145. $Result = "";
  5146. for($i=0;$i<=count($Intersections)-1;$i=$i+2)
  5147. {
  5148. if ( isset($Intersections[$i+1]) )
  5149. { if ( $Intersections[$i] != $Intersections[$i+1] ) { $Result[] = $Intersections[$i]; $Result[] = $Intersections[$i+1]; } }
  5150. }
  5151. if ( is_array($Result) )
  5152. {
  5153. $Intersections = $Result;
  5154. $LastX = OUT_OF_SIGHT;
  5155. foreach($Intersections as $Key => $X)
  5156. {
  5157. if ( $LastX == OUT_OF_SIGHT )
  5158. $LastX = $X;
  5159. elseif ( $LastX != OUT_OF_SIGHT )
  5160. {
  5161. if ( $this->getFirstDecimal($LastX) > 1 ) { $LastX++; }
  5162. $Color = $DefaultColor;
  5163. if ( $Threshold != NULL )
  5164. {
  5165. foreach($Threshold as $Key => $Parameters)
  5166. {
  5167. if ( $Y <= $Parameters["MinX"] && $Y >= $Parameters["MaxX"])
  5168. {
  5169. if ( isset($Parameters["R"]) ) { $R = $Parameters["R"]; } else { $R = 0; }
  5170. if ( isset($Parameters["G"]) ) { $G = $Parameters["G"]; } else { $G = 0; }
  5171. if ( isset($Parameters["B"]) ) { $B = $Parameters["B"]; } else { $B = 0; }
  5172. if ( isset($Parameters["Alpha"]) ) { $Alpha = $Parameters["Alpha"]; } else { $Alpha = 100; }
  5173. $Color = $this->allocateColor($this->Picture,$R,$G,$B,$Alpha);
  5174. }
  5175. }
  5176. }
  5177. imageline($this->Picture,$LastX,$Y,$X,$Y,$Color);
  5178. if ( $Y == $DebugLine) { imageline($this->Picture,$LastX,$Y,$X,$Y,$DebugColor); }
  5179. $LastX = OUT_OF_SIGHT;
  5180. }
  5181. }
  5182. }
  5183. }
  5184. }
  5185. }
  5186. /* Draw the polygon border, if required */
  5187. if ( !$NoBorder)
  5188. {
  5189. foreach($Segments as $Key => $Coords)
  5190. $this->drawLine($Coords["X1"],$Coords["Y1"],$Coords["X2"],$Coords["Y2"],array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Threshold"=>$Threshold));
  5191. }
  5192. $this->Shadow = $RestoreShadow;
  5193. }
  5194. /* Return the abscissa margin */
  5195. function getAbscissaMargin($Data)
  5196. {
  5197. foreach($Data["Axis"] as $AxisID => $Values) { if ( $Values["Identity"] == AXIS_X ) { return($Values["Margin"]); } }
  5198. return(0);
  5199. }
  5200. }
  5201. ?>