jquery.jqplot.js 328 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122
  1. /**
  2. * Title: jqPlot Charts
  3. *
  4. * Pure JavaScript plotting plugin for jQuery.
  5. *
  6. * About: Version
  7. *
  8. * 1.0.0a_r701
  9. *
  10. * About: Copyright & License
  11. *
  12. * Copyright (c) 2009-2011 Chris Leonello
  13. * jqPlot is currently available for use in all personal or commercial projects
  14. * under both the MIT and GPL version 2.0 licenses. This means that you can
  15. * choose the license that best suits your project and use it accordingly.
  16. *
  17. * See <GPL Version 2> and <MIT License> contained within this distribution for further information.
  18. *
  19. * The author would appreciate an email letting him know of any substantial
  20. * use of jqPlot. You can reach the author at: chris at jqplot dot com
  21. * or see http://www.jqplot.com/info.php. This is, of course, not required.
  22. *
  23. * If you are feeling kind and generous, consider supporting the project by
  24. * making a donation at: http://www.jqplot.com/donate.php.
  25. *
  26. * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
  27. *
  28. * version 2007.04.27
  29. * author Ash Searle
  30. * http://hexmen.com/blog/2007/03/printf-sprintf/
  31. * http://hexmen.com/js/sprintf.js
  32. * The author (Ash Searle) has placed this code in the public domain:
  33. * "This code is unrestricted: you are free to use it however you like."
  34. *
  35. *
  36. * About: Introduction
  37. *
  38. * jqPlot requires jQuery (1.4+ required for certain features). jQuery 1.4.2 is included in the distribution.
  39. * To use jqPlot include jQuery, the jqPlot jQuery plugin, the jqPlot css file and optionally
  40. * the excanvas script for IE support in your web page:
  41. *
  42. * > <!--[if IE]><script language="javascript" type="text/javascript" src="excanvas.js"></script><![endif]-->
  43. * > <script language="javascript" type="text/javascript" src="jquery-1.4.4.min.js"></script>
  44. * > <script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
  45. * > <link rel="stylesheet" type="text/css" href="jquery.jqplot.css" />
  46. *
  47. * jqPlot can be customized by overriding the defaults of any of the objects which make
  48. * up the plot. The general usage of jqplot is:
  49. *
  50. * > chart = $.jqplot('targetElemId', [dataArray,...], {optionsObject});
  51. *
  52. * The options available to jqplot are detailed in <jqPlot Options> in the jqPlotOptions.txt file.
  53. *
  54. * An actual call to $.jqplot() may look like the
  55. * examples below:
  56. *
  57. * > chart = $.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
  58. *
  59. * or
  60. *
  61. * > dataArray = [34,12,43,55,77];
  62. * > chart = $.jqplot('targetElemId', [dataArray, ...], {title:'My Plot', axes:{yaxis:{min:20, max:100}}});
  63. *
  64. * For more inforrmation, see <jqPlot Usage>.
  65. *
  66. * About: Usage
  67. *
  68. * See <jqPlot Usage>
  69. *
  70. * About: Available Options
  71. *
  72. * See <jqPlot Options> for a list of options available thorugh the options object (not complete yet!)
  73. *
  74. * About: Options Usage
  75. *
  76. * See <Options Tutorial>
  77. *
  78. * About: Changes
  79. *
  80. * See <Change Log>
  81. *
  82. */
  83. (function($) {
  84. // make sure undefined is undefined
  85. var undefined;
  86. /**
  87. * Class: $.jqplot
  88. * jQuery function called by the user to create a plot.
  89. *
  90. * Parameters:
  91. * target - ID of target element to render the plot into.
  92. * data - an array of data series.
  93. * options - user defined options object. See the individual classes for available options.
  94. *
  95. * Properties:
  96. * config - object to hold configuration information for jqPlot plot object.
  97. *
  98. * attributes:
  99. * enablePlugins - False to disable plugins by default. Plugins must then be explicitly
  100. * enabled in the individual plot options. Default: false.
  101. * This property sets the "show" property of certain plugins to true or false.
  102. * Only plugins that can be immediately active upon loading are affected. This includes
  103. * non-renderer plugins like cursor, dragable, highlighter, and trendline.
  104. * defaultHeight - Default height for plots where no css height specification exists. This
  105. * is a jqplot wide default.
  106. * defaultWidth - Default height for plots where no css height specification exists. This
  107. * is a jqplot wide default.
  108. */
  109. $.jqplot = function(target, data, options) {
  110. var _data, _options;
  111. if (options == null) {
  112. if (jQuery.isArray(data)) {
  113. _data = data;
  114. _options = null;
  115. }
  116. else if (typeof(data) === 'object') {
  117. _data = null;
  118. _options = data;
  119. }
  120. }
  121. else {
  122. _data = data;
  123. _options = options;
  124. }
  125. var plot = new jqPlot();
  126. // remove any error class that may be stuck on target.
  127. $('#'+target).removeClass('jqplot-error');
  128. if ($.jqplot.config.catchErrors) {
  129. try {
  130. plot.init(target, _data, _options);
  131. plot.draw();
  132. plot.themeEngine.init.call(plot);
  133. return plot;
  134. }
  135. catch(e) {
  136. var msg = $.jqplot.config.errorMessage || e.message;
  137. $('#'+target).append('<div class="jqplot-error-message">'+msg+'</div>');
  138. $('#'+target).addClass('jqplot-error');
  139. document.getElementById(target).style.background = $.jqplot.config.errorBackground;
  140. document.getElementById(target).style.border = $.jqplot.config.errorBorder;
  141. document.getElementById(target).style.fontFamily = $.jqplot.config.errorFontFamily;
  142. document.getElementById(target).style.fontSize = $.jqplot.config.errorFontSize;
  143. document.getElementById(target).style.fontStyle = $.jqplot.config.errorFontStyle;
  144. document.getElementById(target).style.fontWeight = $.jqplot.config.errorFontWeight;
  145. }
  146. }
  147. else {
  148. plot.init(target, _data, _options);
  149. plot.draw();
  150. plot.themeEngine.init.call(plot);
  151. return plot;
  152. }
  153. };
  154. // Convienence function that won't hang IE of FF without FireBug.
  155. $.jqplot.log = function() {
  156. if (window.console) {
  157. console.log.apply(console, arguments);
  158. }
  159. };
  160. $.jqplot.config = {
  161. enablePlugins:false,
  162. defaultHeight:300,
  163. defaultWidth:400,
  164. UTCAdjust:false,
  165. timezoneOffset: new Date(new Date().getTimezoneOffset() * 60000),
  166. errorMessage: '',
  167. errorBackground: '',
  168. errorBorder: '',
  169. errorFontFamily: '',
  170. errorFontSize: '',
  171. errorFontStyle: '',
  172. errorFontWeight: '',
  173. catchErrors: false,
  174. defaultTickFormatString: "%.1f"
  175. };
  176. $.jqplot.arrayMax = function( array ){
  177. return Math.max.apply( Math, array );
  178. };
  179. $.jqplot.arrayMin = function( array ){
  180. return Math.min.apply( Math, array );
  181. };
  182. $.jqplot.enablePlugins = $.jqplot.config.enablePlugins;
  183. // canvas related tests taken from modernizer:
  184. // Copyright © 2009ñ2010 Faruk Ates.
  185. // http://www.modernizr.com
  186. $.jqplot.support_canvas = function() {
  187. return !!document.createElement('canvas').getContext;
  188. };
  189. $.jqplot.support_canvas_text = function() {
  190. return !!(document.createElement('canvas').getContext && typeof document.createElement('canvas').getContext('2d').fillText == 'function');
  191. };
  192. $.jqplot.use_excanvas = ($.browser.msie && !$.jqplot.support_canvas()) ? true : false;
  193. /**
  194. *
  195. * Hooks: jqPlot Pugin Hooks
  196. *
  197. * $.jqplot.preInitHooks - called before initialization.
  198. * $.jqplot.postInitHooks - called after initialization.
  199. * $.jqplot.preParseOptionsHooks - called before user options are parsed.
  200. * $.jqplot.postParseOptionsHooks - called after user options are parsed.
  201. * $.jqplot.preDrawHooks - called before plot draw.
  202. * $.jqplot.postDrawHooks - called after plot draw.
  203. * $.jqplot.preDrawSeriesHooks - called before each series is drawn.
  204. * $.jqplot.postDrawSeriesHooks - called after each series is drawn.
  205. * $.jqplot.preDrawLegendHooks - called before the legend is drawn.
  206. * $.jqplot.addLegendRowHooks - called at the end of legend draw, so plugins
  207. * can add rows to the legend table.
  208. * $.jqplot.preSeriesInitHooks - called before series is initialized.
  209. * $.jqplot.postSeriesInitHooks - called after series is initialized.
  210. * $.jqplot.preParseSeriesOptionsHooks - called before series related options
  211. * are parsed.
  212. * $.jqplot.postParseSeriesOptionsHooks - called after series related options
  213. * are parsed.
  214. * $.jqplot.eventListenerHooks - called at the end of plot drawing, binds
  215. * listeners to the event canvas which lays on top of the grid area.
  216. * $.jqplot.preDrawSeriesShadowHooks - called before series shadows are drawn.
  217. * $.jqplot.postDrawSeriesShadowHooks - called after series shadows are drawn.
  218. *
  219. */
  220. $.jqplot.preInitHooks = [];
  221. $.jqplot.postInitHooks = [];
  222. $.jqplot.preParseOptionsHooks = [];
  223. $.jqplot.postParseOptionsHooks = [];
  224. $.jqplot.preDrawHooks = [];
  225. $.jqplot.postDrawHooks = [];
  226. $.jqplot.preDrawSeriesHooks = [];
  227. $.jqplot.postDrawSeriesHooks = [];
  228. $.jqplot.preDrawLegendHooks = [];
  229. $.jqplot.addLegendRowHooks = [];
  230. $.jqplot.preSeriesInitHooks = [];
  231. $.jqplot.postSeriesInitHooks = [];
  232. $.jqplot.preParseSeriesOptionsHooks = [];
  233. $.jqplot.postParseSeriesOptionsHooks = [];
  234. $.jqplot.eventListenerHooks = [];
  235. $.jqplot.preDrawSeriesShadowHooks = [];
  236. $.jqplot.postDrawSeriesShadowHooks = [];
  237. // A superclass holding some common properties and methods.
  238. $.jqplot.ElemContainer = function() {
  239. this._elem;
  240. this._plotWidth;
  241. this._plotHeight;
  242. this._plotDimensions = {height:null, width:null};
  243. };
  244. $.jqplot.ElemContainer.prototype.createElement = function(el, offsets, clss, cssopts, attrib) {
  245. this._offsets = offsets;
  246. var klass = clss || 'jqplot';
  247. var elem = document.createElement(el);
  248. this._elem = $(elem);
  249. this._elem.addClass(klass);
  250. this._elem.css(cssopts);
  251. this._elem.attr(attrib);
  252. // avoid memory leak;
  253. elem = null;
  254. return this._elem;
  255. };
  256. $.jqplot.ElemContainer.prototype.getWidth = function() {
  257. if (this._elem) {
  258. return this._elem.outerWidth(true);
  259. }
  260. else {
  261. return null;
  262. }
  263. };
  264. $.jqplot.ElemContainer.prototype.getHeight = function() {
  265. if (this._elem) {
  266. return this._elem.outerHeight(true);
  267. }
  268. else {
  269. return null;
  270. }
  271. };
  272. $.jqplot.ElemContainer.prototype.getPosition = function() {
  273. if (this._elem) {
  274. return this._elem.position();
  275. }
  276. else {
  277. return {top:null, left:null, bottom:null, right:null};
  278. }
  279. };
  280. $.jqplot.ElemContainer.prototype.getTop = function() {
  281. return this.getPosition().top;
  282. };
  283. $.jqplot.ElemContainer.prototype.getLeft = function() {
  284. return this.getPosition().left;
  285. };
  286. $.jqplot.ElemContainer.prototype.getBottom = function() {
  287. return this._elem.css('bottom');
  288. };
  289. $.jqplot.ElemContainer.prototype.getRight = function() {
  290. return this._elem.css('right');
  291. };
  292. /**
  293. * Class: Axis
  294. * An individual axis object. Cannot be instantiated directly, but created
  295. * by the Plot oject. Axis properties can be set or overriden by the
  296. * options passed in from the user.
  297. *
  298. */
  299. function Axis(name) {
  300. $.jqplot.ElemContainer.call(this);
  301. // Group: Properties
  302. //
  303. // Axes options are specified within an axes object at the top level of the
  304. // plot options like so:
  305. // > {
  306. // > axes: {
  307. // > xaxis: {min: 5},
  308. // > yaxis: {min: 2, max: 8, numberTicks:4},
  309. // > x2axis: {pad: 1.5},
  310. // > y2axis: {ticks:[22, 44, 66, 88]}
  311. // > }
  312. // > }
  313. // There are 4 axes, 'xaxis', 'yaxis', 'x2axis', 'y2axis'. Any or all of
  314. // which may be specified.
  315. this.name = name;
  316. this._series = [];
  317. // prop: show
  318. // Wether to display the axis on the graph.
  319. this.show = false;
  320. // prop: tickRenderer
  321. // A class of a rendering engine for creating the ticks labels displayed on the plot,
  322. // See <$.jqplot.AxisTickRenderer>.
  323. this.tickRenderer = $.jqplot.AxisTickRenderer;
  324. // prop: tickOptions
  325. // Options that will be passed to the tickRenderer, see <$.jqplot.AxisTickRenderer> options.
  326. this.tickOptions = {};
  327. // prop: labelRenderer
  328. // A class of a rendering engine for creating an axis label.
  329. this.labelRenderer = $.jqplot.AxisLabelRenderer;
  330. // prop: labelOptions
  331. // Options passed to the label renderer.
  332. this.labelOptions = {};
  333. // prop: label
  334. // Label for the axis
  335. this.label = null;
  336. // prop: showLabel
  337. // true to show the axis label.
  338. this.showLabel = true;
  339. // prop: min
  340. // minimum value of the axis (in data units, not pixels).
  341. this.min=null;
  342. // prop: max
  343. // maximum value of the axis (in data units, not pixels).
  344. this.max=null;
  345. // prop: autoscale
  346. // Autoscale the axis min and max values to provide sensible tick spacing.
  347. // If axis min or max are set, autoscale will be turned off.
  348. // The numberTicks, tickInterval and pad options do work with
  349. // autoscale, although tickInterval has not been tested yet.
  350. // padMin and padMax do nothing when autoscale is on.
  351. this.autoscale = false;
  352. // prop: pad
  353. // Padding to extend the range above and below the data bounds.
  354. // The data range is multiplied by this factor to determine minimum and maximum axis bounds.
  355. // A value of 0 will be interpreted to mean no padding, and pad will be set to 1.0.
  356. this.pad = 1.2;
  357. // prop: padMax
  358. // Padding to extend the range above data bounds.
  359. // The top of the data range is multiplied by this factor to determine maximum axis bounds.
  360. // A value of 0 will be interpreted to mean no padding, and padMax will be set to 1.0.
  361. this.padMax = null;
  362. // prop: padMin
  363. // Padding to extend the range below data bounds.
  364. // The bottom of the data range is multiplied by this factor to determine minimum axis bounds.
  365. // A value of 0 will be interpreted to mean no padding, and padMin will be set to 1.0.
  366. this.padMin = null;
  367. // prop: ticks
  368. // 1D [val, val, ...] or 2D [[val, label], [val, label], ...] array of ticks for the axis.
  369. // If no label is specified, the value is formatted into an appropriate label.
  370. this.ticks = [];
  371. // prop: numberTicks
  372. // Desired number of ticks. Default is to compute automatically.
  373. this.numberTicks;
  374. // prop: tickInterval
  375. // number of units between ticks. Mutually exclusive with numberTicks.
  376. this.tickInterval;
  377. // prop: renderer
  378. // A class of a rendering engine that handles tick generation,
  379. // scaling input data to pixel grid units and drawing the axis element.
  380. this.renderer = $.jqplot.LinearAxisRenderer;
  381. // prop: rendererOptions
  382. // renderer specific options. See <$.jqplot.LinearAxisRenderer> for options.
  383. this.rendererOptions = {};
  384. // prop: showTicks
  385. // Wether to show the ticks (both marks and labels) or not.
  386. // Will not override showMark and showLabel options if specified on the ticks themselves.
  387. this.showTicks = true;
  388. // prop: showTickMarks
  389. // Wether to show the tick marks (line crossing grid) or not.
  390. // Overridden by showTicks and showMark option of tick itself.
  391. this.showTickMarks = true;
  392. // prop: showMinorTicks
  393. // Wether or not to show minor ticks. This is renderer dependent.
  394. // The default <$.jqplot.LinearAxisRenderer> does not have minor ticks.
  395. this.showMinorTicks = true;
  396. // prop: useSeriesColor
  397. // Use the color of the first series associated with this axis for the
  398. // tick marks and line bordering this axis.
  399. this.useSeriesColor = false;
  400. // prop: borderWidth
  401. // width of line stroked at the border of the axis. Defaults
  402. // to the width of the grid boarder.
  403. this.borderWidth = null;
  404. // prop: borderColor
  405. // color of the border adjacent to the axis. Defaults to grid border color.
  406. this.borderColor = null;
  407. // minimum and maximum values on the axis.
  408. this._dataBounds = {min:null, max:null};
  409. // statistics (min, max, mean) as well as actual data intervals for each series attached to axis.
  410. // holds collection of {intervals:[], min:, max:, mean: } objects for each series on axis.
  411. this._intervalStats = [];
  412. // pixel position from the top left of the min value and max value on the axis.
  413. this._offsets = {min:null, max:null};
  414. this._ticks=[];
  415. this._label = null;
  416. // prop: syncTicks
  417. // true to try and synchronize tick spacing across multiple axes so that ticks and
  418. // grid lines line up. This has an impact on autoscaling algorithm, however.
  419. // In general, autoscaling an individual axis will work better if it does not
  420. // have to sync ticks.
  421. this.syncTicks = null;
  422. // prop: tickSpacing
  423. // Approximate pixel spacing between ticks on graph. Used during autoscaling.
  424. // This number will be an upper bound, actual spacing will be less.
  425. this.tickSpacing = 75;
  426. // Properties to hold the original values for min, max, ticks, tickInterval and numberTicks
  427. // so they can be restored if altered by plugins.
  428. this._min = null;
  429. this._max = null;
  430. this._tickInterval = null;
  431. this._numberTicks = null;
  432. this.__ticks = null;
  433. }
  434. Axis.prototype = new $.jqplot.ElemContainer();
  435. Axis.prototype.constructor = Axis;
  436. Axis.prototype.init = function() {
  437. this.renderer = new this.renderer();
  438. // set the axis name
  439. this.tickOptions.axis = this.name;
  440. // if showMark or showLabel tick options not specified, use value of axis option.
  441. // showTicks overrides showTickMarks.
  442. if (this.tickOptions.showMark == null) {
  443. this.tickOptions.showMark = this.showTicks;
  444. }
  445. if (this.tickOptions.showMark == null) {
  446. this.tickOptions.showMark = this.showTickMarks;
  447. }
  448. if (this.tickOptions.showLabel == null) {
  449. this.tickOptions.showLabel = this.showTicks;
  450. }
  451. if (this.label == null || this.label == '') {
  452. this.showLabel = false;
  453. }
  454. else {
  455. this.labelOptions.label = this.label;
  456. }
  457. if (this.showLabel == false) {
  458. this.labelOptions.show = false;
  459. }
  460. // set the default padMax, padMin if not specified
  461. // special check, if no padding desired, padding
  462. // should be set to 1.0
  463. if (this.pad == 0) {
  464. this.pad = 1.0;
  465. }
  466. if (this.padMax == 0) {
  467. this.padMax = 1.0;
  468. }
  469. if (this.padMin == 0) {
  470. this.padMin = 1.0;
  471. }
  472. if (this.padMax == null) {
  473. this.padMax = (this.pad-1)/2 + 1;
  474. }
  475. if (this.padMin == null) {
  476. this.padMin = (this.pad-1)/2 + 1;
  477. }
  478. // now that padMin and padMax are correctly set, reset pad in case user has supplied
  479. // padMin and/or padMax
  480. this.pad = this.padMax + this.padMin - 1;
  481. if (this.min != null || this.max != null) {
  482. this.autoscale = false;
  483. }
  484. // if not set, sync ticks for y axes but not x by default.
  485. if (this.syncTicks == null && this.name.indexOf('y') > -1) {
  486. this.syncTicks = true;
  487. }
  488. else if (this.syncTicks == null){
  489. this.syncTicks = false;
  490. }
  491. this.renderer.init.call(this, this.rendererOptions);
  492. };
  493. Axis.prototype.draw = function(ctx) {
  494. return this.renderer.draw.call(this, ctx);
  495. };
  496. Axis.prototype.set = function() {
  497. this.renderer.set.call(this);
  498. };
  499. Axis.prototype.pack = function(pos, offsets) {
  500. if (this.show) {
  501. this.renderer.pack.call(this, pos, offsets);
  502. }
  503. // these properties should all be available now.
  504. if (this._min == null) {
  505. this._min = this.min;
  506. this._max = this.max;
  507. this._tickInterval = this.tickInterval;
  508. this._numberTicks = this.numberTicks;
  509. this.__ticks = this._ticks;
  510. }
  511. };
  512. // reset the axis back to original values if it has been scaled, zoomed, etc.
  513. Axis.prototype.reset = function() {
  514. this.renderer.reset.call(this);
  515. };
  516. Axis.prototype.resetScale = function(opts) {
  517. $.extend(true, this, {min: null, max: null, numberTicks: null, tickInterval: null, _ticks: [], ticks: []}, opts);
  518. this.resetDataBounds();
  519. };
  520. Axis.prototype.resetDataBounds = function() {
  521. // Go through all the series attached to this axis and find
  522. // the min/max bounds for this axis.
  523. var db = this._dataBounds;
  524. db.min = null;
  525. db.max = null;
  526. for (var i=0; i<this._series.length; i++) {
  527. var s = this._series[i];
  528. var d = s._plotData;
  529. for (var j=0; j<d.length; j++) {
  530. if (this.name == 'xaxis' || this.name == 'x2axis') {
  531. if ((d[j][0] != null && d[j][0] < db.min) || db.min == null) {
  532. db.min = d[j][0];
  533. }
  534. if ((d[j][0] != null && d[j][0] > db.max) || db.max == null) {
  535. db.max = d[j][0];
  536. }
  537. }
  538. else {
  539. if ((d[j][1] != null && d[j][1] < db.min) || db.min == null) {
  540. db.min = d[j][1];
  541. }
  542. if ((d[j][1] != null && d[j][1] > db.max) || db.max == null) {
  543. db.max = d[j][1];
  544. }
  545. }
  546. }
  547. }
  548. };
  549. /**
  550. * Class: Legend
  551. * Legend object. Cannot be instantiated directly, but created
  552. * by the Plot oject. Legend properties can be set or overriden by the
  553. * options passed in from the user.
  554. */
  555. function Legend(options) {
  556. $.jqplot.ElemContainer.call(this);
  557. // Group: Properties
  558. // prop: show
  559. // Wether to display the legend on the graph.
  560. this.show = false;
  561. // prop: location
  562. // Placement of the legend. one of the compass directions: nw, n, ne, e, se, s, sw, w
  563. this.location = 'ne';
  564. // prop: labels
  565. // Array of labels to use. By default the renderer will look for labels on the series.
  566. // Labels specified in this array will override labels specified on the series.
  567. this.labels = [];
  568. // prop: showLabels
  569. // true to show the label text on the legend.
  570. this.showLabels = true;
  571. // prop: showSwatch
  572. // true to show the color swatches on the legend.
  573. this.showSwatches = true;
  574. // prop: placement
  575. // "insideGrid" places legend inside the grid area of the plot.
  576. // "outsideGrid" places the legend outside the grid but inside the plot container,
  577. // shrinking the grid to accomodate the legend.
  578. // "inside" synonym for "insideGrid",
  579. // "outside" places the legend ouside the grid area, but does not shrink the grid which
  580. // can cause the legend to overflow the plot container.
  581. this.placement = "insideGrid";
  582. // prop: xoffset
  583. // DEPRECATED. Set the margins on the legend using the marginTop, marginLeft, etc.
  584. // properties or via CSS margin styling of the .jqplot-table-legend class.
  585. this.xoffset = 0;
  586. // prop: yoffset
  587. // DEPRECATED. Set the margins on the legend using the marginTop, marginLeft, etc.
  588. // properties or via CSS margin styling of the .jqplot-table-legend class.
  589. this.yoffset = 0;
  590. // prop: border
  591. // css spec for the border around the legend box.
  592. this.border;
  593. // prop: background
  594. // css spec for the background of the legend box.
  595. this.background;
  596. // prop: textColor
  597. // css color spec for the legend text.
  598. this.textColor;
  599. // prop: fontFamily
  600. // css font-family spec for the legend text.
  601. this.fontFamily;
  602. // prop: fontSize
  603. // css font-size spec for the legend text.
  604. this.fontSize ;
  605. // prop: rowSpacing
  606. // css padding-top spec for the rows in the legend.
  607. this.rowSpacing = '0.5em';
  608. // renderer
  609. // A class that will create a DOM object for the legend,
  610. // see <$.jqplot.TableLegendRenderer>.
  611. this.renderer = $.jqplot.TableLegendRenderer;
  612. // prop: rendererOptions
  613. // renderer specific options passed to the renderer.
  614. this.rendererOptions = {};
  615. // prop: predraw
  616. // Wether to draw the legend before the series or not.
  617. // Used with series specific legend renderers for pie, donut, mekko charts, etc.
  618. this.preDraw = false;
  619. // prop: marginTop
  620. // CSS margin for the legend DOM element. This will set an element
  621. // CSS style for the margin which will override any style sheet setting.
  622. // The default will be taken from the stylesheet.
  623. this.marginTop = null;
  624. // prop: marginRight
  625. // CSS margin for the legend DOM element. This will set an element
  626. // CSS style for the margin which will override any style sheet setting.
  627. // The default will be taken from the stylesheet.
  628. this.marginRight = null;
  629. // prop: marginBottom
  630. // CSS margin for the legend DOM element. This will set an element
  631. // CSS style for the margin which will override any style sheet setting.
  632. // The default will be taken from the stylesheet.
  633. this.marginBottom = null;
  634. // prop: marginLeft
  635. // CSS margin for the legend DOM element. This will set an element
  636. // CSS style for the margin which will override any style sheet setting.
  637. // The default will be taken from the stylesheet.
  638. this.marginLeft = null;
  639. this.escapeHtml = false;
  640. this._series = [];
  641. $.extend(true, this, options);
  642. }
  643. Legend.prototype = new $.jqplot.ElemContainer();
  644. Legend.prototype.constructor = Legend;
  645. Legend.prototype.setOptions = function(options) {
  646. $.extend(true, this, options);
  647. // Try to emulate deprecated behaviour
  648. // if user has specified xoffset or yoffset, copy these to
  649. // the margin properties.
  650. if (this.placement == 'inside') {
  651. this.placement = 'insideGrid';
  652. }
  653. if (this.xoffset >0) {
  654. if (this.placement == 'insideGrid') {
  655. switch (this.location) {
  656. case 'nw':
  657. case 'w':
  658. case 'sw':
  659. if (this.marginLeft == null) {
  660. this.marginLeft = this.xoffset + 'px';
  661. }
  662. this.marginRight = '0px';
  663. break;
  664. case 'ne':
  665. case 'e':
  666. case 'se':
  667. default:
  668. if (this.marginRight == null) {
  669. this.marginRight = this.xoffset + 'px';
  670. }
  671. this.marginLeft = '0px';
  672. break;
  673. }
  674. }
  675. else if (this.placement == 'outside') {
  676. switch (this.location) {
  677. case 'nw':
  678. case 'w':
  679. case 'sw':
  680. if (this.marginRight == null) {
  681. this.marginRight = this.xoffset + 'px';
  682. }
  683. this.marginLeft = '0px';
  684. break;
  685. case 'ne':
  686. case 'e':
  687. case 'se':
  688. default:
  689. if (this.marginLeft == null) {
  690. this.marginLeft = this.xoffset + 'px';
  691. }
  692. this.marginRight = '0px';
  693. break;
  694. }
  695. }
  696. this.xoffset = 0;
  697. }
  698. if (this.yoffset >0) {
  699. if (this.placement == 'outside') {
  700. switch (this.location) {
  701. case 'sw':
  702. case 's':
  703. case 'se':
  704. if (this.marginTop == null) {
  705. this.marginTop = this.yoffset + 'px';
  706. }
  707. this.marginBottom = '0px';
  708. break;
  709. case 'ne':
  710. case 'n':
  711. case 'nw':
  712. default:
  713. if (this.marginBottom == null) {
  714. this.marginBottom = this.yoffset + 'px';
  715. }
  716. this.marginTop = '0px';
  717. break;
  718. }
  719. }
  720. else if (this.placement == 'insideGrid') {
  721. switch (this.location) {
  722. case 'sw':
  723. case 's':
  724. case 'se':
  725. if (this.marginBottom == null) {
  726. this.marginBottom = this.yoffset + 'px';
  727. }
  728. this.marginTop = '0px';
  729. break;
  730. case 'ne':
  731. case 'n':
  732. case 'nw':
  733. default:
  734. if (this.marginTop == null) {
  735. this.marginTop = this.yoffset + 'px';
  736. }
  737. this.marginBottom = '0px';
  738. break;
  739. }
  740. }
  741. this.yoffset = 0;
  742. }
  743. // TO-DO:
  744. // Handle case where offsets are < 0.
  745. //
  746. };
  747. Legend.prototype.init = function() {
  748. this.renderer = new this.renderer();
  749. this.renderer.init.call(this, this.rendererOptions);
  750. };
  751. Legend.prototype.draw = function(offsets) {
  752. for (var i=0; i<$.jqplot.preDrawLegendHooks.length; i++){
  753. $.jqplot.preDrawLegendHooks[i].call(this, offsets);
  754. }
  755. return this.renderer.draw.call(this, offsets);
  756. };
  757. Legend.prototype.pack = function(offsets) {
  758. this.renderer.pack.call(this, offsets);
  759. };
  760. /**
  761. * Class: Title
  762. * Plot Title object. Cannot be instantiated directly, but created
  763. * by the Plot oject. Title properties can be set or overriden by the
  764. * options passed in from the user.
  765. *
  766. * Parameters:
  767. * text - text of the title.
  768. */
  769. function Title(text) {
  770. $.jqplot.ElemContainer.call(this);
  771. // Group: Properties
  772. // prop: text
  773. // text of the title;
  774. this.text = text;
  775. // prop: show
  776. // wether or not to show the title
  777. this.show = true;
  778. // prop: fontFamily
  779. // css font-family spec for the text.
  780. this.fontFamily;
  781. // prop: fontSize
  782. // css font-size spec for the text.
  783. this.fontSize ;
  784. // prop: textAlign
  785. // css text-align spec for the text.
  786. this.textAlign;
  787. // prop: textColor
  788. // css color spec for the text.
  789. this.textColor;
  790. // prop: renderer
  791. // A class for creating a DOM element for the title,
  792. // see <$.jqplot.DivTitleRenderer>.
  793. this.renderer = $.jqplot.DivTitleRenderer;
  794. // prop: rendererOptions
  795. // renderer specific options passed to the renderer.
  796. this.rendererOptions = {};
  797. }
  798. Title.prototype = new $.jqplot.ElemContainer();
  799. Title.prototype.constructor = Title;
  800. Title.prototype.init = function() {
  801. this.renderer = new this.renderer();
  802. this.renderer.init.call(this, this.rendererOptions);
  803. };
  804. Title.prototype.draw = function(width) {
  805. return this.renderer.draw.call(this, width);
  806. };
  807. Title.prototype.pack = function() {
  808. this.renderer.pack.call(this);
  809. };
  810. /**
  811. * Class: Series
  812. * An individual data series object. Cannot be instantiated directly, but created
  813. * by the Plot oject. Series properties can be set or overriden by the
  814. * options passed in from the user.
  815. */
  816. function Series() {
  817. $.jqplot.ElemContainer.call(this);
  818. // Group: Properties
  819. // Properties will be assigned from a series array at the top level of the
  820. // options. If you had two series and wanted to change the color and line
  821. // width of the first and set the second to use the secondary y axis with
  822. // no shadow and supply custom labels for each:
  823. // > {
  824. // > series:[
  825. // > {color: '#ff4466', lineWidth: 5, label:'good line'},
  826. // > {yaxis: 'y2axis', shadow: false, label:'bad line'}
  827. // > ]
  828. // > }
  829. // prop: show
  830. // wether or not to draw the series.
  831. this.show = true;
  832. // prop: xaxis
  833. // which x axis to use with this series, either 'xaxis' or 'x2axis'.
  834. this.xaxis = 'xaxis';
  835. this._xaxis;
  836. // prop: yaxis
  837. // which y axis to use with this series, either 'yaxis' or 'y2axis'.
  838. this.yaxis = 'yaxis';
  839. this._yaxis;
  840. this.gridBorderWidth = 2.0;
  841. // prop: renderer
  842. // A class of a renderer which will draw the series,
  843. // see <$.jqplot.LineRenderer>.
  844. this.renderer = $.jqplot.LineRenderer;
  845. // prop: rendererOptions
  846. // Options to pass on to the renderer.
  847. this.rendererOptions = {};
  848. this.data = [];
  849. this.gridData = [];
  850. // prop: label
  851. // Line label to use in the legend.
  852. this.label = '';
  853. // prop: showLabel
  854. // true to show label for this series in the legend.
  855. this.showLabel = true;
  856. // prop: color
  857. // css color spec for the series
  858. this.color;
  859. // prop: lineWidth
  860. // width of the line in pixels. May have different meanings depending on renderer.
  861. this.lineWidth = 2.5;
  862. // prop: shadow
  863. // wether or not to draw a shadow on the line
  864. this.shadow = true;
  865. // prop: shadowAngle
  866. // Shadow angle in degrees
  867. this.shadowAngle = 45;
  868. // prop: shadowOffset
  869. // Shadow offset from line in pixels
  870. this.shadowOffset = 1.25;
  871. // prop: shadowDepth
  872. // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
  873. this.shadowDepth = 3;
  874. // prop: shadowAlpha
  875. // Alpha channel transparency of shadow. 0 = transparent.
  876. this.shadowAlpha = '0.1';
  877. // prop: breakOnNull
  878. // Not implemented. wether line segments should be be broken at null value.
  879. // False will join point on either side of line.
  880. this.breakOnNull = false;
  881. // prop: markerRenderer
  882. // A class of a renderer which will draw marker (e.g. circle, square, ...) at the data points,
  883. // see <$.jqplot.MarkerRenderer>.
  884. this.markerRenderer = $.jqplot.MarkerRenderer;
  885. // prop: markerOptions
  886. // renderer specific options to pass to the markerRenderer,
  887. // see <$.jqplot.MarkerRenderer>.
  888. this.markerOptions = {};
  889. // prop: showLine
  890. // wether to actually draw the line or not. Series will still be renderered, even if no line is drawn.
  891. this.showLine = true;
  892. // prop: showMarker
  893. // wether or not to show the markers at the data points.
  894. this.showMarker = true;
  895. // prop: index
  896. // 0 based index of this series in the plot series array.
  897. this.index;
  898. // prop: fill
  899. // true or false, wether to fill under lines or in bars.
  900. // May not be implemented in all renderers.
  901. this.fill = false;
  902. // prop: fillColor
  903. // CSS color spec to use for fill under line. Defaults to line color.
  904. this.fillColor;
  905. // prop: fillAlpha
  906. // Alpha transparency to apply to the fill under the line.
  907. // Use this to adjust alpha separate from fill color.
  908. this.fillAlpha;
  909. // prop: fillAndStroke
  910. // If true will stroke the line (with color this.color) as well as fill under it.
  911. // Applies only when fill is true.
  912. this.fillAndStroke = false;
  913. // prop: disableStack
  914. // true to not stack this series with other series in the plot.
  915. // To render properly, non-stacked series must come after any stacked series
  916. // in the plot's data series array. So, the plot's data series array would look like:
  917. // > [stackedSeries1, stackedSeries2, ..., nonStackedSeries1, nonStackedSeries2, ...]
  918. // disableStack will put a gap in the stacking order of series, and subsequent
  919. // stacked series will not fill down through the non-stacked series and will
  920. // most likely not stack properly on top of the non-stacked series.
  921. this.disableStack = false;
  922. // _stack is set by the Plot if the plot is a stacked chart.
  923. // will stack lines or bars on top of one another to build a "mountain" style chart.
  924. // May not be implemented in all renderers.
  925. this._stack = false;
  926. // prop: neighborThreshold
  927. // how close or far (in pixels) the cursor must be from a point marker to detect the point.
  928. this.neighborThreshold = 4;
  929. // prop: fillToZero
  930. // true will force bar and filled series to fill toward zero on the fill Axis.
  931. this.fillToZero = false;
  932. // prop: fillToValue
  933. // fill a filled series to this value on the fill axis.
  934. // Works in conjunction with fillToZero, so that must be true.
  935. this.fillToValue = 0;
  936. // prop: fillAxis
  937. // Either 'x' or 'y'. Which axis to fill the line toward if fillToZero is true.
  938. // 'y' means fill up/down to 0 on the y axis for this series.
  939. this.fillAxis = 'y';
  940. // prop: useNegativeColors
  941. // true to color negative values differently in filled and bar charts.
  942. this.useNegativeColors = true;
  943. this._stackData = [];
  944. // _plotData accounts for stacking. If plots not stacked, _plotData and data are same. If
  945. // stacked, _plotData is accumulation of stacking data.
  946. this._plotData = [];
  947. // _plotValues hold the individual x and y values that will be plotted for this series.
  948. this._plotValues = {x:[], y:[]};
  949. // statistics about the intervals between data points. Used for auto scaling.
  950. this._intervals = {x:{}, y:{}};
  951. // data from the previous series, for stacked charts.
  952. this._prevPlotData = [];
  953. this._prevGridData = [];
  954. this._stackAxis = 'y';
  955. this._primaryAxis = '_xaxis';
  956. // give each series a canvas to draw on. This should allow for redrawing speedups.
  957. this.canvas = new $.jqplot.GenericCanvas();
  958. this.shadowCanvas = new $.jqplot.GenericCanvas();
  959. this.plugins = {};
  960. // sum of y values in this series.
  961. this._sumy = 0;
  962. this._sumx = 0;
  963. }
  964. Series.prototype = new $.jqplot.ElemContainer();
  965. Series.prototype.constructor = Series;
  966. Series.prototype.init = function(index, gridbw, plot) {
  967. // weed out any null values in the data.
  968. this.index = index;
  969. this.gridBorderWidth = gridbw;
  970. var d = this.data;
  971. var temp = [], i;
  972. for (i=0; i<d.length; i++) {
  973. if (! this.breakOnNull) {
  974. if (d[i] == null || d[i][0] == null || d[i][1] == null) {
  975. continue;
  976. }
  977. else {
  978. temp.push(d[i]);
  979. }
  980. }
  981. else {
  982. // TODO: figure out what to do with null values
  983. // probably involve keeping nulls in data array
  984. // and then updating renderers to break line
  985. // when it hits null value.
  986. // For now, just keep value.
  987. temp.push(d[i]);
  988. }
  989. }
  990. this.data = temp;
  991. if (!this.fillColor) {
  992. this.fillColor = this.color;
  993. }
  994. if (this.fillAlpha) {
  995. var comp = $.jqplot.normalize2rgb(this.fillColor);
  996. var comp = $.jqplot.getColorComponents(comp);
  997. this.fillColor = 'rgba('+comp[0]+','+comp[1]+','+comp[2]+','+this.fillAlpha+')';
  998. }
  999. this.renderer = new this.renderer();
  1000. this.renderer.init.call(this, this.rendererOptions, plot);
  1001. this.markerRenderer = new this.markerRenderer();
  1002. if (!this.markerOptions.color) {
  1003. this.markerOptions.color = this.color;
  1004. }
  1005. if (this.markerOptions.show == null) {
  1006. this.markerOptions.show = this.showMarker;
  1007. }
  1008. this.showMarker = this.markerOptions.show;
  1009. // the markerRenderer is called within it's own scaope, don't want to overwrite series options!!
  1010. this.markerRenderer.init(this.markerOptions);
  1011. };
  1012. // data - optional data point array to draw using this series renderer
  1013. // gridData - optional grid data point array to draw using this series renderer
  1014. // stackData - array of cumulative data for stacked plots.
  1015. Series.prototype.draw = function(sctx, opts, plot) {
  1016. var options = (opts == undefined) ? {} : opts;
  1017. sctx = (sctx == undefined) ? this.canvas._ctx : sctx;
  1018. var j, data, gridData;
  1019. // hooks get called even if series not shown
  1020. // we don't clear canvas here, it would wipe out all other series as well.
  1021. for (j=0; j<$.jqplot.preDrawSeriesHooks.length; j++) {
  1022. $.jqplot.preDrawSeriesHooks[j].call(this, sctx, options);
  1023. }
  1024. if (this.show) {
  1025. this.renderer.setGridData.call(this, plot);
  1026. if (!options.preventJqPlotSeriesDrawTrigger) {
  1027. $(sctx.canvas).trigger('jqplotSeriesDraw', [this.data, this.gridData]);
  1028. }
  1029. data = [];
  1030. if (options.data) {
  1031. data = options.data;
  1032. }
  1033. else if (!this._stack) {
  1034. data = this.data;
  1035. }
  1036. else {
  1037. data = this._plotData;
  1038. }
  1039. gridData = options.gridData || this.renderer.makeGridData.call(this, data, plot);
  1040. this.renderer.draw.call(this, sctx, gridData, options, plot);
  1041. }
  1042. for (j=0; j<$.jqplot.postDrawSeriesHooks.length; j++) {
  1043. $.jqplot.postDrawSeriesHooks[j].call(this, sctx, options);
  1044. }
  1045. sctx = opts = plot = j = data = gridData = null;
  1046. };
  1047. Series.prototype.drawShadow = function(sctx, opts, plot) {
  1048. var options = (opts == undefined) ? {} : opts;
  1049. sctx = (sctx == undefined) ? this.shadowCanvas._ctx : sctx;
  1050. var j, data, gridData;
  1051. // hooks get called even if series not shown
  1052. // we don't clear canvas here, it would wipe out all other series as well.
  1053. for (j=0; j<$.jqplot.preDrawSeriesShadowHooks.length; j++) {
  1054. $.jqplot.preDrawSeriesShadowHooks[j].call(this, sctx, options);
  1055. }
  1056. if (this.shadow) {
  1057. this.renderer.setGridData.call(this, plot);
  1058. data = [];
  1059. if (options.data) {
  1060. data = options.data;
  1061. }
  1062. else if (!this._stack) {
  1063. data = this.data;
  1064. }
  1065. else {
  1066. data = this._plotData;
  1067. }
  1068. gridData = options.gridData || this.renderer.makeGridData.call(this, data, plot);
  1069. this.renderer.drawShadow.call(this, sctx, gridData, options);
  1070. }
  1071. for (j=0; j<$.jqplot.postDrawSeriesShadowHooks.length; j++) {
  1072. $.jqplot.postDrawSeriesShadowHooks[j].call(this, sctx, options);
  1073. }
  1074. sctx = opts = plot = j = data = gridData = null;
  1075. };
  1076. // toggles series display on plot, e.g. show/hide series
  1077. Series.prototype.toggleDisplay = function(ev) {
  1078. var s, speed;
  1079. if (ev.data.series) {
  1080. s = ev.data.series;
  1081. }
  1082. else {
  1083. s = this;
  1084. }
  1085. if (ev.data.speed) {
  1086. speed = ev.data.speed;
  1087. }
  1088. if (speed) {
  1089. if (s.canvas._elem.is(':hidden')) {
  1090. if (s.shadowCanvas._elem) {
  1091. s.shadowCanvas._elem.fadeIn(speed);
  1092. }
  1093. s.canvas._elem.fadeIn(speed);
  1094. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).fadeIn(speed);
  1095. }
  1096. else {
  1097. if (s.shadowCanvas._elem) {
  1098. s.shadowCanvas._elem.fadeOut(speed);
  1099. }
  1100. s.canvas._elem.fadeOut(speed);
  1101. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).fadeOut(speed);
  1102. }
  1103. }
  1104. else {
  1105. if (s.canvas._elem.is(':hidden')) {
  1106. if (s.shadowCanvas._elem) {
  1107. s.shadowCanvas._elem.show();
  1108. }
  1109. s.canvas._elem.show();
  1110. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).show();
  1111. }
  1112. else {
  1113. if (s.shadowCanvas._elem) {
  1114. s.shadowCanvas._elem.hide();
  1115. }
  1116. s.canvas._elem.hide();
  1117. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).hide();
  1118. }
  1119. }
  1120. };
  1121. /**
  1122. * Class: Grid
  1123. *
  1124. * Object representing the grid on which the plot is drawn. The grid in this
  1125. * context is the area bounded by the axes, the area which will contain the series.
  1126. * Note, the series are drawn on their own canvas.
  1127. * The Grid object cannot be instantiated directly, but is created by the Plot oject.
  1128. * Grid properties can be set or overriden by the options passed in from the user.
  1129. */
  1130. function Grid() {
  1131. $.jqplot.ElemContainer.call(this);
  1132. // Group: Properties
  1133. // prop: drawGridlines
  1134. // wether to draw the gridlines on the plot.
  1135. this.drawGridlines = true;
  1136. // prop: gridLineColor
  1137. // color of the grid lines.
  1138. this.gridLineColor = '#cccccc';
  1139. // prop: gridLineWidth
  1140. // width of the grid lines.
  1141. this.gridLineWidth = 1.0;
  1142. // prop: background
  1143. // css spec for the background color.
  1144. this.background = '#fffdf6';
  1145. // prop: borderColor
  1146. // css spec for the color of the grid border.
  1147. this.borderColor = '#999999';
  1148. // prop: borderWidth
  1149. // width of the border in pixels.
  1150. this.borderWidth = 2.0;
  1151. // prop: drawBorder
  1152. // True to draw border around grid.
  1153. this.drawBorder = true;
  1154. // prop: shadow
  1155. // wether to show a shadow behind the grid.
  1156. this.shadow = true;
  1157. // prop: shadowAngle
  1158. // shadow angle in degrees
  1159. this.shadowAngle = 45;
  1160. // prop: shadowOffset
  1161. // Offset of each shadow stroke from the border in pixels
  1162. this.shadowOffset = 1.5;
  1163. // prop: shadowWidth
  1164. // width of the stoke for the shadow
  1165. this.shadowWidth = 3;
  1166. // prop: shadowDepth
  1167. // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
  1168. this.shadowDepth = 3;
  1169. // prop: shadowColor
  1170. // an optional css color spec for the shadow in 'rgba(n, n, n, n)' form
  1171. this.shadowColor = null;
  1172. // prop: shadowAlpha
  1173. // Alpha channel transparency of shadow. 0 = transparent.
  1174. this.shadowAlpha = '0.07';
  1175. this._left;
  1176. this._top;
  1177. this._right;
  1178. this._bottom;
  1179. this._width;
  1180. this._height;
  1181. this._axes = [];
  1182. // prop: renderer
  1183. // Instance of a renderer which will actually render the grid,
  1184. // see <$.jqplot.CanvasGridRenderer>.
  1185. this.renderer = $.jqplot.CanvasGridRenderer;
  1186. // prop: rendererOptions
  1187. // Options to pass on to the renderer,
  1188. // see <$.jqplot.CanvasGridRenderer>.
  1189. this.rendererOptions = {};
  1190. this._offsets = {top:null, bottom:null, left:null, right:null};
  1191. }
  1192. Grid.prototype = new $.jqplot.ElemContainer();
  1193. Grid.prototype.constructor = Grid;
  1194. Grid.prototype.init = function() {
  1195. this.renderer = new this.renderer();
  1196. this.renderer.init.call(this, this.rendererOptions);
  1197. };
  1198. Grid.prototype.createElement = function(offsets) {
  1199. this._offsets = offsets;
  1200. return this.renderer.createElement.call(this);
  1201. };
  1202. Grid.prototype.draw = function() {
  1203. this.renderer.draw.call(this);
  1204. };
  1205. $.jqplot.GenericCanvas = function() {
  1206. $.jqplot.ElemContainer.call(this);
  1207. this._ctx;
  1208. };
  1209. $.jqplot.GenericCanvas.prototype = new $.jqplot.ElemContainer();
  1210. $.jqplot.GenericCanvas.prototype.constructor = $.jqplot.GenericCanvas;
  1211. $.jqplot.GenericCanvas.prototype.createElement = function(offsets, clss, plotDimensions) {
  1212. this._offsets = offsets;
  1213. var klass = 'jqplot';
  1214. if (clss != undefined) {
  1215. klass = clss;
  1216. }
  1217. var elem;
  1218. // if this canvas already has a dom element, don't make a new one.
  1219. if (this._elem) {
  1220. elem = this._elem.get(0);
  1221. }
  1222. else {
  1223. elem = document.createElement('canvas');
  1224. }
  1225. // if new plotDimensions supplied, use them.
  1226. if (plotDimensions != undefined) {
  1227. this._plotDimensions = plotDimensions;
  1228. }
  1229. elem.width = this._plotDimensions.width - this._offsets.left - this._offsets.right;
  1230. elem.height = this._plotDimensions.height - this._offsets.top - this._offsets.bottom;
  1231. this._elem = $(elem);
  1232. this._elem.css({ position: 'absolute', left: this._offsets.left, top: this._offsets.top });
  1233. this._elem.addClass(klass);
  1234. if ($.jqplot.use_excanvas) {
  1235. window.G_vmlCanvasManager.init_(document);
  1236. elem = window.G_vmlCanvasManager.initElement(elem);
  1237. }
  1238. // avoid memory leak
  1239. elem = null;
  1240. return this._elem;
  1241. };
  1242. $.jqplot.GenericCanvas.prototype.setContext = function() {
  1243. this._ctx = this._elem.get(0).getContext("2d");
  1244. return this._ctx;
  1245. };
  1246. $.jqplot.HooksManager = function () {
  1247. this.hooks =[];
  1248. };
  1249. $.jqplot.HooksManager.prototype.addOnce = function(fn) {
  1250. var havehook = false, i;
  1251. for (i=0; i<this.hooks.length; i++) {
  1252. if (this.hooks[i][0] == fn) {
  1253. havehook = true;
  1254. }
  1255. }
  1256. if (!havehook) {
  1257. this.hooks.push(fn);
  1258. }
  1259. };
  1260. $.jqplot.HooksManager.prototype.add = function(fn) {
  1261. this.hooks.push(fn);
  1262. };
  1263. $.jqplot.EventListenerManager = function () {
  1264. this.hooks =[];
  1265. };
  1266. $.jqplot.EventListenerManager.prototype.addOnce = function(ev, fn) {
  1267. var havehook = false, h, i;
  1268. for (i=0; i<this.hooks.length; i++) {
  1269. h = this.hooks[i];
  1270. if (h[0] == ev && h[1] == fn) {
  1271. havehook = true;
  1272. }
  1273. }
  1274. if (!havehook) {
  1275. this.hooks.push([ev, fn]);
  1276. }
  1277. };
  1278. $.jqplot.EventListenerManager.prototype.add = function(ev, fn) {
  1279. this.hooks.push([ev, fn]);
  1280. };
  1281. /**
  1282. * Class: jqPlot
  1283. * Plot object returned by call to $.jqplot. Handles parsing user options,
  1284. * creating sub objects (Axes, legend, title, series) and rendering the plot.
  1285. */
  1286. function jqPlot() {
  1287. // Group: Properties
  1288. // These properties are specified at the top of the options object
  1289. // like so:
  1290. // > {
  1291. // > axesDefaults:{min:0},
  1292. // > series:[{color:'#6633dd'}],
  1293. // > title: 'A Plot'
  1294. // > }
  1295. //
  1296. // prop: data
  1297. // user's data. Data should *NOT* be specified in the options object,
  1298. // but be passed in as the second argument to the $.jqplot() function.
  1299. // The data property is described here soley for reference.
  1300. // The data should be in the form of an array of 2D or 1D arrays like
  1301. // > [ [[x1, y1], [x2, y2],...], [y1, y2, ...] ].
  1302. this.data = [];
  1303. // prop dataRenderer
  1304. // A callable which can be used to preprocess data passed into the plot.
  1305. // Will be called with 2 arguments, the plot data and a reference to the plot.
  1306. this.dataRenderer;
  1307. // prop dataRendererOptions
  1308. // Options that will be passed to the dataRenderer.
  1309. // Can be of any type.
  1310. this.dataRendererOptions;
  1311. // prop noDataIndicator
  1312. // Options to set up a mock plot with a data loading indicator if no data is specified.
  1313. this.noDataIndicator = {
  1314. show: false,
  1315. indicator: 'Loading Data...',
  1316. axes: {
  1317. xaxis: {
  1318. min: 0,
  1319. max: 10,
  1320. tickInterval: 2,
  1321. show: true
  1322. },
  1323. yaxis: {
  1324. min: 0,
  1325. max: 12,
  1326. tickInterval: 3,
  1327. show: true
  1328. }
  1329. }
  1330. };
  1331. // The id of the dom element to render the plot into
  1332. this.targetId = null;
  1333. // the jquery object for the dom target.
  1334. this.target = null;
  1335. this.defaults = {
  1336. // prop: axesDefaults
  1337. // default options that will be applied to all axes.
  1338. // see <Axis> for axes options.
  1339. axesDefaults: {},
  1340. axes: {xaxis:{}, yaxis:{}, x2axis:{}, y2axis:{}, y3axis:{}, y4axis:{}, y5axis:{}, y6axis:{}, y7axis:{}, y8axis:{}, y9axis:{}},
  1341. // prop: seriesDefaults
  1342. // default options that will be applied to all series.
  1343. // see <Series> for series options.
  1344. seriesDefaults: {},
  1345. series:[]
  1346. };
  1347. // prop: series
  1348. // Array of series object options.
  1349. // see <Series> for series specific options.
  1350. this.series = [];
  1351. // prop: axes
  1352. // up to 4 axes are supported, each with it's own options,
  1353. // See <Axis> for axis specific options.
  1354. this.axes = {xaxis: new Axis('xaxis'), yaxis: new Axis('yaxis'), x2axis: new Axis('x2axis'), y2axis: new Axis('y2axis'), y3axis: new Axis('y3axis'), y4axis: new Axis('y4axis'), y5axis: new Axis('y5axis'), y6axis: new Axis('y6axis'), y7axis: new Axis('y7axis'), y8axis: new Axis('y8axis'), y9axis: new Axis('y9axis')};
  1355. // prop: grid
  1356. // See <Grid> for grid specific options.
  1357. this.grid = new Grid();
  1358. // prop: legend
  1359. // see <$.jqplot.TableLegendRenderer>
  1360. this.legend = new Legend();
  1361. this.baseCanvas = new $.jqplot.GenericCanvas();
  1362. // array of series indicies. Keep track of order
  1363. // which series canvases are displayed, lowest
  1364. // to highest, back to front.
  1365. this.seriesStack = [];
  1366. this.previousSeriesStack = [];
  1367. this.eventCanvas = new $.jqplot.GenericCanvas();
  1368. this._width = null;
  1369. this._height = null;
  1370. this._plotDimensions = {height:null, width:null};
  1371. this._gridPadding = {top:null, right:null, bottom:null, left:null};
  1372. this._defaultGridPadding = {top:10, right:10, bottom:23, left:10};
  1373. // a shortcut for axis syncTicks options. Not implemented yet.
  1374. this.syncXTicks = true;
  1375. // a shortcut for axis syncTicks options. Not implemented yet.
  1376. this.syncYTicks = true;
  1377. // prop: seriesColors
  1378. // Ann array of CSS color specifications that will be applied, in order,
  1379. // to the series in the plot. Colors will wrap around so, if their
  1380. // are more series than colors, colors will be reused starting at the
  1381. // beginning. For pie charts, this specifies the colors of the slices.
  1382. this.seriesColors = [ "#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"];
  1383. this.negativeSeriesColors = [ "#498991", "#C08840", "#9F9274", "#546D61", "#646C4A", "#6F6621", "#6E3F5F", "#4F64B0", "#A89050", "#C45923", "#187399", "#945381", "#959E5C", "#C7AF7B", "#478396", "#907294"];
  1384. // prop: sortData
  1385. // false to not sort the data passed in by the user.
  1386. // Many bar, stakced and other graphs as well as many plugins depend on
  1387. // having sorted data.
  1388. this.sortData = true;
  1389. var seriesColorsIndex = 0;
  1390. // prop textColor
  1391. // css spec for the css color attribute. Default for the entire plot.
  1392. this.textColor;
  1393. // prop; fontFamily
  1394. // css spec for the font-family attribute. Default for the entire plot.
  1395. this.fontFamily;
  1396. // prop: fontSize
  1397. // css spec for the font-size attribute. Default for the entire plot.
  1398. this.fontSize;
  1399. // prop: title
  1400. // Title object. See <Title> for specific options. As a shortcut, you
  1401. // can specify the title option as just a string like: title: 'My Plot'
  1402. // and this will create a new title object with the specified text.
  1403. this.title = new Title();
  1404. // container to hold all of the merged options. Convienence for plugins.
  1405. this.options = {};
  1406. // prop: stackSeries
  1407. // true or false, creates a stack or "mountain" plot.
  1408. // Not all series renderers may implement this option.
  1409. this.stackSeries = false;
  1410. // prop: defaultAxisStart
  1411. // 1-D data series are internally converted into 2-D [x,y] data point arrays
  1412. // by jqPlot. This is the default starting value for the missing x or y value.
  1413. // The added data will be a monotonically increasing series (e.g. [1, 2, 3, ...])
  1414. // starting at this value.
  1415. this.defaultAxisStart = 1;
  1416. // array to hold the cumulative stacked series data.
  1417. // used to ajust the individual series data, which won't have access to other
  1418. // series data.
  1419. this._stackData = [];
  1420. // array that holds the data to be plotted. This will be the series data
  1421. // merged with the the appropriate data from _stackData according to the stackAxis.
  1422. this._plotData = [];
  1423. // Namespece to hold plugins. Generally non-renderer plugins add themselves to here.
  1424. this.plugins = {};
  1425. // Count how many times the draw method has been called while the plot is visible.
  1426. // Mostly used to test if plot has never been dran (=0), has been successfully drawn
  1427. // into a visible container once (=1) or draw more than once into a visible container.
  1428. // Can use this in tests to see if plot has been visibly drawn at least one time.
  1429. // After plot has been visibly drawn once, it generally doesn't need redrawn if its
  1430. // container is hidden and shown.
  1431. this._drawCount = 0;
  1432. // this.doCustomEventBinding = true;
  1433. // prop: drawIfHidden
  1434. // True to execute the draw method even if the plot target is hidden.
  1435. // Generally, this should be false. Most plot elements will not be sized/
  1436. // positioned correclty if renderered into a hidden container. To render into
  1437. // a hidden container, call the replot method when the container is shown.
  1438. this.drawIfHidden = false;
  1439. // true to intercept right click events and fire a 'jqplotRightClick' event.
  1440. // this will also block the context menu.
  1441. this.captureRightClick = false;
  1442. this.themeEngine = new $.jqplot.ThemeEngine();
  1443. // sum of y values for all series in plot.
  1444. // used in mekko chart.
  1445. this._sumy = 0;
  1446. this._sumx = 0;
  1447. this.preInitHooks = new $.jqplot.HooksManager();
  1448. this.postInitHooks = new $.jqplot.HooksManager();
  1449. this.preParseOptionsHooks = new $.jqplot.HooksManager();
  1450. this.postParseOptionsHooks = new $.jqplot.HooksManager();
  1451. this.preDrawHooks = new $.jqplot.HooksManager();
  1452. this.postDrawHooks = new $.jqplot.HooksManager();
  1453. this.preDrawSeriesHooks = new $.jqplot.HooksManager();
  1454. this.postDrawSeriesHooks = new $.jqplot.HooksManager();
  1455. this.preDrawLegendHooks = new $.jqplot.HooksManager();
  1456. this.addLegendRowHooks = new $.jqplot.HooksManager();
  1457. this.preSeriesInitHooks = new $.jqplot.HooksManager();
  1458. this.postSeriesInitHooks = new $.jqplot.HooksManager();
  1459. this.preParseSeriesOptionsHooks = new $.jqplot.HooksManager();
  1460. this.postParseSeriesOptionsHooks = new $.jqplot.HooksManager();
  1461. this.eventListenerHooks = new $.jqplot.EventListenerManager();
  1462. this.preDrawSeriesShadowHooks = new $.jqplot.HooksManager();
  1463. this.postDrawSeriesShadowHooks = new $.jqplot.HooksManager();
  1464. this.colorGenerator = $.jqplot.ColorGenerator;
  1465. // Group: methods
  1466. //
  1467. // method: init
  1468. // sets the plot target, checks data and applies user
  1469. // options to plot.
  1470. this.init = function(target, data, options) {
  1471. options = options || {};
  1472. for (var i=0; i<$.jqplot.preInitHooks.length; i++) {
  1473. $.jqplot.preInitHooks[i].call(this, target, data, options);
  1474. }
  1475. for (var i=0; i<this.preInitHooks.hooks.length; i++) {
  1476. this.preInitHooks.hooks[i].call(this, target, data, options);
  1477. }
  1478. this.targetId = '#'+target;
  1479. this.target = $('#'+target);
  1480. // remove any error class that may be stuck on target.
  1481. this.target.removeClass('jqplot-error');
  1482. if (!this.target.get(0)) {
  1483. throw "No plot target specified";
  1484. }
  1485. // make sure the target is positioned by some means and set css
  1486. if (this.target.css('position') == 'static') {
  1487. this.target.css('position', 'relative');
  1488. }
  1489. if (!this.target.hasClass('jqplot-target')) {
  1490. this.target.addClass('jqplot-target');
  1491. }
  1492. // if no height or width specified, use a default.
  1493. if (!this.target.height()) {
  1494. var h;
  1495. if (options && options.height) {
  1496. h = parseInt(options.height, 10);
  1497. }
  1498. else if (this.target.attr('data-height')) {
  1499. h = parseInt(this.target.attr('data-height'), 10);
  1500. }
  1501. else {
  1502. h = parseInt($.jqplot.config.defaultHeight, 10);
  1503. }
  1504. this._height = h;
  1505. this.target.css('height', h+'px');
  1506. }
  1507. else {
  1508. this._height = h = this.target.height();
  1509. }
  1510. if (!this.target.width()) {
  1511. var w;
  1512. if (options && options.width) {
  1513. w = parseInt(options.width, 10);
  1514. }
  1515. else if (this.target.attr('data-width')) {
  1516. w = parseInt(this.target.attr('data-width'), 10);
  1517. }
  1518. else {
  1519. w = parseInt($.jqplot.config.defaultWidth, 10);
  1520. }
  1521. this._width = w;
  1522. this.target.css('width', w+'px');
  1523. }
  1524. else {
  1525. this._width = w = this.target.width();
  1526. }
  1527. this._plotDimensions.height = this._height;
  1528. this._plotDimensions.width = this._width;
  1529. this.grid._plotDimensions = this._plotDimensions;
  1530. this.title._plotDimensions = this._plotDimensions;
  1531. this.baseCanvas._plotDimensions = this._plotDimensions;
  1532. this.eventCanvas._plotDimensions = this._plotDimensions;
  1533. this.legend._plotDimensions = this._plotDimensions;
  1534. if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
  1535. throw "Canvas dimension not set";
  1536. }
  1537. if (options.dataRenderer && jQuery.isFunction(options.dataRenderer)) {
  1538. if (options.dataRendererOptions) {
  1539. this.dataRendererOptions = options.dataRendererOptions;
  1540. }
  1541. this.dataRenderer = options.dataRenderer;
  1542. data = this.dataRenderer(data, this, this.dataRendererOptions);
  1543. }
  1544. if (options.noDataIndicator && jQuery.isPlainObject(options.noDataIndicator)) {
  1545. $.extend(true, this.noDataIndicator, options.noDataIndicator);
  1546. }
  1547. if (data == null) {
  1548. throw{
  1549. name: "DataError",
  1550. message: "No data to plot."
  1551. };
  1552. }
  1553. if (jQuery.isArray(data) == false || data.length == 0 || jQuery.isArray(data[0]) == false || data[0].length == 0) {
  1554. if (this.noDataIndicator.show == false) {
  1555. throw{
  1556. name: "DataError",
  1557. message: "No data to plot."
  1558. };
  1559. }
  1560. else {
  1561. for (ax in this.noDataIndicator.axes) {
  1562. for (prop in this.noDataIndicator.axes[ax]) {
  1563. this.axes[ax][prop] = this.noDataIndicator.axes[ax][prop];
  1564. }
  1565. }
  1566. this.postDrawHooks.add(function() {
  1567. var eh = this.eventCanvas.getHeight();
  1568. var ew = this.eventCanvas.getWidth();
  1569. var temp = $('<div class="jqplot-noData-container" style="position:absolute;"></div>');
  1570. this.target.append(temp);
  1571. temp.height(eh);
  1572. temp.width(ew);
  1573. temp.css('top', this.eventCanvas._offsets.top);
  1574. temp.css('left', this.eventCanvas._offsets.left);
  1575. temp2 = $('<div class="jqplot-noData-contents" style="text-align:center; position:relative; margin-left:auto; margin-right:auto;"></div>');
  1576. temp.append(temp2);
  1577. temp2.html(this.noDataIndicator.indicator);
  1578. var th = temp2.height();
  1579. var tw = temp2.width();
  1580. temp2.height(th);
  1581. temp2.width(tw);
  1582. temp2.css('top', (eh - th)/2 + 'px');
  1583. });
  1584. }
  1585. }
  1586. this.data = data;
  1587. this.parseOptions(options);
  1588. if (this.textColor) {
  1589. this.target.css('color', this.textColor);
  1590. }
  1591. if (this.fontFamily) {
  1592. this.target.css('font-family', this.fontFamily);
  1593. }
  1594. if (this.fontSize) {
  1595. this.target.css('font-size', this.fontSize);
  1596. }
  1597. this.title.init();
  1598. this.legend.init();
  1599. this._sumy = 0;
  1600. this._sumx = 0;
  1601. for (var i=0; i<this.series.length; i++) {
  1602. // set default stacking order for series canvases
  1603. this.seriesStack.push(i);
  1604. this.previousSeriesStack.push(i);
  1605. this.series[i].shadowCanvas._plotDimensions = this._plotDimensions;
  1606. this.series[i].canvas._plotDimensions = this._plotDimensions;
  1607. for (var j=0; j<$.jqplot.preSeriesInitHooks.length; j++) {
  1608. $.jqplot.preSeriesInitHooks[j].call(this.series[i], target, data, this.options.seriesDefaults, this.options.series[i], this);
  1609. }
  1610. for (var j=0; j<this.preSeriesInitHooks.hooks.length; j++) {
  1611. this.preSeriesInitHooks.hooks[j].call(this.series[i], target, data, this.options.seriesDefaults, this.options.series[i], this);
  1612. }
  1613. this.populatePlotData(this.series[i], i);
  1614. this.series[i]._plotDimensions = this._plotDimensions;
  1615. this.series[i].init(i, this.grid.borderWidth, this);
  1616. for (var j=0; j<$.jqplot.postSeriesInitHooks.length; j++) {
  1617. $.jqplot.postSeriesInitHooks[j].call(this.series[i], target, data, this.options.seriesDefaults, this.options.series[i], this);
  1618. }
  1619. for (var j=0; j<this.postSeriesInitHooks.hooks.length; j++) {
  1620. this.postSeriesInitHooks.hooks[j].call(this.series[i], target, data, this.options.seriesDefaults, this.options.series[i], this);
  1621. }
  1622. this._sumy += this.series[i]._sumy;
  1623. this._sumx += this.series[i]._sumx;
  1624. }
  1625. for (var name in this.axes) {
  1626. this.axes[name]._plotDimensions = this._plotDimensions;
  1627. this.axes[name].init();
  1628. }
  1629. if (this.sortData) {
  1630. sortData(this.series);
  1631. }
  1632. this.grid.init();
  1633. this.grid._axes = this.axes;
  1634. this.legend._series = this.series;
  1635. for (var i=0; i<$.jqplot.postInitHooks.length; i++) {
  1636. $.jqplot.postInitHooks[i].call(this, target, data, options);
  1637. }
  1638. for (var i=0; i<this.postInitHooks.hooks.length; i++) {
  1639. this.postInitHooks.hooks[i].call(this, target, data, options);
  1640. }
  1641. };
  1642. // method: resetAxesScale
  1643. // Reset the specified axes min, max, numberTicks and tickInterval properties to null
  1644. // or reset these properties on all axes if no list of axes is provided.
  1645. //
  1646. // Parameters:
  1647. // axes - Boolean to reset or not reset all axes or an array or object of axis names to reset.
  1648. this.resetAxesScale = function(axes, options) {
  1649. var opts = options || {};
  1650. var ax = axes || this.axes;
  1651. if (ax === true) {
  1652. ax = this.axes;
  1653. }
  1654. if (jQuery.isArray(ax)) {
  1655. for (var i = 0; i < ax.length; i++) {
  1656. this.axes[ax[i]].resetScale(opts[ax[i]]);
  1657. }
  1658. }
  1659. else if (typeof(ax) === 'object') {
  1660. for (var name in ax) {
  1661. this.axes[name].resetScale(opts[name]);
  1662. }
  1663. }
  1664. };
  1665. // method: reInitialize
  1666. // reinitialize plot for replotting.
  1667. // not called directly.
  1668. this.reInitialize = function () {
  1669. // Plot should be visible and have a height and width.
  1670. // If plot doesn't have height and width for some
  1671. // reason, set it by other means. Plot must not have
  1672. // a display:none attribute, however.
  1673. if (!this.target.height()) {
  1674. var h;
  1675. if (options && options.height) {
  1676. h = parseInt(options.height, 10);
  1677. }
  1678. else if (this.target.attr('data-height')) {
  1679. h = parseInt(this.target.attr('data-height'), 10);
  1680. }
  1681. else {
  1682. h = parseInt($.jqplot.config.defaultHeight, 10);
  1683. }
  1684. this._height = h;
  1685. this.target.css('height', h+'px');
  1686. }
  1687. else {
  1688. this._height = this.target.height();
  1689. }
  1690. if (!this.target.width()) {
  1691. var w;
  1692. if (options && options.width) {
  1693. w = parseInt(options.width, 10);
  1694. }
  1695. else if (this.target.attr('data-width')) {
  1696. w = parseInt(this.target.attr('data-width'), 10);
  1697. }
  1698. else {
  1699. w = parseInt($.jqplot.config.defaultWidth, 10);
  1700. }
  1701. this._width = w;
  1702. this.target.css('width', w+'px');
  1703. }
  1704. else {
  1705. this._width = this.target.width();
  1706. }
  1707. if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
  1708. throw "Target dimension not set";
  1709. }
  1710. this._plotDimensions.height = this._height;
  1711. this._plotDimensions.width = this._width;
  1712. this.grid._plotDimensions = this._plotDimensions;
  1713. this.title._plotDimensions = this._plotDimensions;
  1714. this.baseCanvas._plotDimensions = this._plotDimensions;
  1715. this.eventCanvas._plotDimensions = this._plotDimensions;
  1716. this.legend._plotDimensions = this._plotDimensions;
  1717. for (var n in this.axes) {
  1718. this.axes[n]._plotWidth = this._width;
  1719. this.axes[n]._plotHeight = this._height;
  1720. }
  1721. this.title._plotWidth = this._width;
  1722. if (this.textColor) {
  1723. this.target.css('color', this.textColor);
  1724. }
  1725. if (this.fontFamily) {
  1726. this.target.css('font-family', this.fontFamily);
  1727. }
  1728. if (this.fontSize) {
  1729. this.target.css('font-size', this.fontSize);
  1730. }
  1731. this._sumy = 0;
  1732. this._sumx = 0;
  1733. for (var i=0; i<this.series.length; i++) {
  1734. this.populatePlotData(this.series[i], i);
  1735. this.series[i]._plotDimensions = this._plotDimensions;
  1736. this.series[i].canvas._plotDimensions = this._plotDimensions;
  1737. //this.series[i].init(i, this.grid.borderWidth);
  1738. this._sumy += this.series[i]._sumy;
  1739. this._sumx += this.series[i]._sumx;
  1740. }
  1741. for (var name in this.axes) {
  1742. this.axes[name]._plotDimensions = this._plotDimensions;
  1743. this.axes[name]._ticks = [];
  1744. this.axes[name].renderer.init.call(this.axes[name], {});
  1745. }
  1746. if (this.sortData) {
  1747. sortData(this.series);
  1748. }
  1749. this.grid._axes = this.axes;
  1750. this.legend._series = this.series;
  1751. };
  1752. // sort the series data in increasing order.
  1753. function sortData(series) {
  1754. var d, sd, pd, ppd, ret;
  1755. for (var i=0; i<series.length; i++) {
  1756. // d = series[i].data;
  1757. // sd = series[i]._stackData;
  1758. // pd = series[i]._plotData;
  1759. // ppd = series[i]._prevPlotData;
  1760. var check;
  1761. var bat = [series[i].data, series[i]._stackData, series[i]._plotData, series[i]._prevPlotData];
  1762. for (var n=0; n<4; n++) {
  1763. check = true;
  1764. d = bat[n];
  1765. if (series[i]._stackAxis == 'x') {
  1766. for (var j = 0; j < d.length; j++) {
  1767. if (typeof(d[j][1]) != "number") {
  1768. check = false;
  1769. break;
  1770. }
  1771. }
  1772. if (check) {
  1773. d.sort(function(a,b) { return a[1] - b[1]; });
  1774. // sd.sort(function(a,b) { return a[1] - b[1]; });
  1775. // pd.sort(function(a,b) { return a[1] - b[1]; });
  1776. // ppd.sort(function(a,b) { return a[1] - b[1]; });
  1777. }
  1778. }
  1779. else {
  1780. for (var j = 0; j < d.length; j++) {
  1781. if (typeof(d[j][0]) != "number") {
  1782. check = false;
  1783. break;
  1784. }
  1785. }
  1786. if (check) {
  1787. d.sort(function(a,b) { return a[0] - b[0]; });
  1788. // sd.sort(function(a,b) { return a[0] - b[0]; });
  1789. // pd.sort(function(a,b) { return a[0] - b[0]; });
  1790. // ppd.sort(function(a,b) { return a[0] - b[0]; });
  1791. }
  1792. }
  1793. }
  1794. }
  1795. }
  1796. // populate the _stackData and _plotData arrays for the plot and the series.
  1797. this.populatePlotData = function(series, index) {
  1798. // if a stacked chart, compute the stacked data
  1799. this._plotData = [];
  1800. this._stackData = [];
  1801. series._stackData = [];
  1802. series._plotData = [];
  1803. var plotValues = {x:[], y:[]};
  1804. if (this.stackSeries && !series.disableStack) {
  1805. series._stack = true;
  1806. var sidx = series._stackAxis == 'x' ? 0 : 1;
  1807. var idx = sidx ? 0 : 1;
  1808. // push the current data into stackData
  1809. //this._stackData.push(this.series[i].data);
  1810. var temp = $.extend(true, [], series.data);
  1811. // create the data that will be plotted for this series
  1812. var plotdata = $.extend(true, [], series.data);
  1813. // for first series, nothing to add to stackData.
  1814. for (var j=0; j<index; j++) {
  1815. var cd = this.series[j].data;
  1816. for (var k=0; k<cd.length; k++) {
  1817. temp[k][0] += cd[k][0];
  1818. temp[k][1] += cd[k][1];
  1819. // only need to sum up the stack axis column of data
  1820. plotdata[k][sidx] += cd[k][sidx];
  1821. }
  1822. }
  1823. for (var i=0; i<plotdata.length; i++) {
  1824. plotValues.x.push(plotdata[i][0]);
  1825. plotValues.y.push(plotdata[i][1]);
  1826. }
  1827. this._plotData.push(plotdata);
  1828. this._stackData.push(temp);
  1829. series._stackData = temp;
  1830. series._plotData = plotdata;
  1831. series._plotValues = plotValues;
  1832. }
  1833. else {
  1834. for (var i=0; i<series.data.length; i++) {
  1835. plotValues.x.push(series.data[i][0]);
  1836. plotValues.y.push(series.data[i][1]);
  1837. }
  1838. this._stackData.push(series.data);
  1839. this.series[index]._stackData = series.data;
  1840. this._plotData.push(series.data);
  1841. series._plotData = series.data;
  1842. series._plotValues = plotValues;
  1843. }
  1844. if (index>0) {
  1845. series._prevPlotData = this.series[index-1]._plotData;
  1846. }
  1847. series._sumy = 0;
  1848. series._sumx = 0;
  1849. for (i=series.data.length-1; i>-1; i--) {
  1850. series._sumy += series.data[i][1];
  1851. series._sumx += series.data[i][0];
  1852. }
  1853. };
  1854. // function to safely return colors from the color array and wrap around at the end.
  1855. this.getNextSeriesColor = (function(t) {
  1856. var idx = 0;
  1857. var sc = t.seriesColors;
  1858. return function () {
  1859. if (idx < sc.length) {
  1860. return sc[idx++];
  1861. }
  1862. else {
  1863. idx = 0;
  1864. return sc[idx++];
  1865. }
  1866. };
  1867. })(this);
  1868. this.parseOptions = function(options){
  1869. for (var i=0; i<this.preParseOptionsHooks.hooks.length; i++) {
  1870. this.preParseOptionsHooks.hooks[i].call(this, options);
  1871. }
  1872. for (var i=0; i<$.jqplot.preParseOptionsHooks.length; i++) {
  1873. $.jqplot.preParseOptionsHooks[i].call(this, options);
  1874. }
  1875. this.options = $.extend(true, {}, this.defaults, options);
  1876. this.stackSeries = this.options.stackSeries;
  1877. if (this.options.seriesColors) {
  1878. this.seriesColors = this.options.seriesColors;
  1879. }
  1880. if (this.options.negativeSeriesColors) {
  1881. this.negativeSeriesColors = this.options.negativeSeriesColors;
  1882. }
  1883. if (this.options.captureRightClick) {
  1884. this.captureRightClick = this.options.captureRightClick;
  1885. }
  1886. this.defaultAxisStart = (options && options.defaultAxisStart != null) ? options.defaultAxisStart : this.defaultAxisStart;
  1887. var cg = new this.colorGenerator(this.seriesColors);
  1888. // this._gridPadding = this.options.gridPadding;
  1889. $.extend(true, this._gridPadding, this.options.gridPadding);
  1890. this.sortData = (this.options.sortData != null) ? this.options.sortData : this.sortData;
  1891. for (var n in this.axes) {
  1892. var axis = this.axes[n];
  1893. $.extend(true, axis, this.options.axesDefaults, this.options.axes[n]);
  1894. axis._plotWidth = this._width;
  1895. axis._plotHeight = this._height;
  1896. }
  1897. if (this.data.length == 0) {
  1898. this.data = [];
  1899. for (var i=0; i<this.options.series.length; i++) {
  1900. this.data.push(this.options.series.data);
  1901. }
  1902. }
  1903. var normalizeData = function(data, dir, start) {
  1904. // return data as an array of point arrays,
  1905. // in form [[x1,y1...], [x2,y2...], ...]
  1906. var temp = [];
  1907. var i;
  1908. dir = dir || 'vertical';
  1909. if (!jQuery.isArray(data[0])) {
  1910. // we have a series of scalars. One line with just y values.
  1911. // turn the scalar list of data into a data array of form:
  1912. // [[1, data[0]], [2, data[1]], ...]
  1913. for (i=0; i<data.length; i++) {
  1914. if (dir == 'vertical') {
  1915. temp.push([start + i, data[i]]);
  1916. }
  1917. else {
  1918. temp.push([data[i], start+i]);
  1919. }
  1920. }
  1921. }
  1922. else {
  1923. // we have a properly formatted data series, copy it.
  1924. $.extend(true, temp, data);
  1925. }
  1926. return temp;
  1927. };
  1928. for (var i=0; i<this.data.length; i++) {
  1929. var temp = new Series();
  1930. for (var j=0; j<$.jqplot.preParseSeriesOptionsHooks.length; j++) {
  1931. $.jqplot.preParseSeriesOptionsHooks[j].call(temp, this.options.seriesDefaults, this.options.series[i]);
  1932. }
  1933. for (var j=0; j<this.preParseSeriesOptionsHooks.hooks.length; j++) {
  1934. this.preParseSeriesOptionsHooks.hooks[j].call(temp, this.options.seriesDefaults, this.options.series[i]);
  1935. }
  1936. $.extend(true, temp, {seriesColors:this.seriesColors, negativeSeriesColors:this.negativeSeriesColors}, this.options.seriesDefaults, this.options.series[i]);
  1937. var dir = 'vertical';
  1938. if (temp.renderer.constructor == $.jqplot.barRenderer && temp.rendererOptions && temp.rendererOptions.barDirection == 'horizontal') {
  1939. dir = 'horizontal';
  1940. }
  1941. temp.data = normalizeData(this.data[i], dir, this.defaultAxisStart);
  1942. switch (temp.xaxis) {
  1943. case 'xaxis':
  1944. temp._xaxis = this.axes.xaxis;
  1945. break;
  1946. case 'x2axis':
  1947. temp._xaxis = this.axes.x2axis;
  1948. break;
  1949. default:
  1950. break;
  1951. }
  1952. temp._yaxis = this.axes[temp.yaxis];
  1953. temp._xaxis._series.push(temp);
  1954. temp._yaxis._series.push(temp);
  1955. if (temp.show) {
  1956. temp._xaxis.show = true;
  1957. temp._yaxis.show = true;
  1958. }
  1959. // parse the renderer options and apply default colors if not provided
  1960. if (!temp.color && temp.show != false) {
  1961. temp.color = cg.next();
  1962. }
  1963. if (!temp.label) {
  1964. temp.label = 'Series '+ (i+1).toString();
  1965. }
  1966. // temp.rendererOptions.show = temp.show;
  1967. // $.extend(true, temp.renderer, {color:this.seriesColors[i]}, this.rendererOptions);
  1968. this.series.push(temp);
  1969. for (var j=0; j<$.jqplot.postParseSeriesOptionsHooks.length; j++) {
  1970. $.jqplot.postParseSeriesOptionsHooks[j].call(this.series[i], this.options.seriesDefaults, this.options.series[i]);
  1971. }
  1972. for (var j=0; j<this.postParseSeriesOptionsHooks.hooks.length; j++) {
  1973. this.postParseSeriesOptionsHooks.hooks[j].call(this.series[i], this.options.seriesDefaults, this.options.series[i]);
  1974. }
  1975. }
  1976. // copy the grid and title options into this object.
  1977. $.extend(true, this.grid, this.options.grid);
  1978. // if axis border properties aren't set, set default.
  1979. for (var n in this.axes) {
  1980. var axis = this.axes[n];
  1981. if (axis.borderWidth == null) {
  1982. axis.borderWidth =this.grid.borderWidth;
  1983. }
  1984. if (axis.borderColor == null) {
  1985. if (n != 'xaxis' && n != 'x2axis' && axis.useSeriesColor === true && axis.show) {
  1986. axis.borderColor = axis._series[0].color;
  1987. }
  1988. else {
  1989. axis.borderColor = this.grid.borderColor;
  1990. }
  1991. }
  1992. }
  1993. if (typeof this.options.title == 'string') {
  1994. this.title.text = this.options.title;
  1995. }
  1996. else if (typeof this.options.title == 'object') {
  1997. $.extend(true, this.title, this.options.title);
  1998. }
  1999. this.title._plotWidth = this._width;
  2000. this.legend.setOptions(this.options.legend);
  2001. for (var i=0; i<$.jqplot.postParseOptionsHooks.length; i++) {
  2002. $.jqplot.postParseOptionsHooks[i].call(this, options);
  2003. }
  2004. for (var i=0; i<this.postParseOptionsHooks.hooks.length; i++) {
  2005. this.postParseOptionsHooks.hooks[i].call(this, options);
  2006. }
  2007. };
  2008. // method: replot
  2009. // Does a reinitialization of the plot followed by
  2010. // a redraw. Method could be used to interactively
  2011. // change plot characteristics and then replot.
  2012. //
  2013. // Parameters:
  2014. // options - Options used for replotting.
  2015. //
  2016. // Properties:
  2017. // clear - false to not clear (empty) the plot container before replotting (default: true).
  2018. // resetAxes - true to reset all axes min, max, numberTicks and tickInterval setting so axes will rescale themselves.
  2019. // optionally pass in list of axes to reset (e.g. ['xaxis', 'y2axis']) (default: false).
  2020. this.replot = function(options) {
  2021. var opts = options || {};
  2022. var clear = opts.clear || true;
  2023. var resetAxes = opts.resetAxes || false;
  2024. this.target.trigger('jqplotPreReplot');
  2025. if (clear) {
  2026. // Couple of posts on Stack Overflow indicate that empty() doesn't
  2027. // always cear up the dom and release memory. Sometimes setting
  2028. // innerHTML property to null is needed. Particularly on IE, may
  2029. // have to directly set it to null, bypassing jQuery.
  2030. this.target.empty();
  2031. }
  2032. if (resetAxes) {
  2033. this.resetAxesScale(resetAxes, opts.axes);
  2034. }
  2035. this.reInitialize();
  2036. this.draw();
  2037. this.target.trigger('jqplotPostReplot');
  2038. };
  2039. // method: redraw
  2040. // Empties the plot target div and redraws the plot.
  2041. // This enables plot data and properties to be changed
  2042. // and then to comletely clear the plot and redraw.
  2043. // redraw *will not* reinitialize any plot elements.
  2044. // That is, axes will not be autoscaled and defaults
  2045. // will not be reapplied to any plot elements. redraw
  2046. // is used primarily with zooming.
  2047. //
  2048. // Parameters:
  2049. // clear - false to not clear (empty) the plot container before redrawing (default: true).
  2050. this.redraw = function(clear) {
  2051. clear = (clear != null) ? clear : true;
  2052. this.target.trigger('jqplotPreRedraw');
  2053. if (clear) {
  2054. // Couple of posts on Stack Overflow indicate that empty() doesn't
  2055. // always cear up the dom and release memory. Sometimes setting
  2056. // innerHTML property to null is needed. Particularly on IE, may
  2057. // have to directly set it to null, bypassing jQuery.
  2058. this.target.empty();
  2059. }
  2060. for (var ax in this.axes) {
  2061. this.axes[ax]._ticks = [];
  2062. }
  2063. for (var i=0; i<this.series.length; i++) {
  2064. this.populatePlotData(this.series[i], i);
  2065. }
  2066. this._sumy = 0;
  2067. this._sumx = 0;
  2068. for (i=0; i<this.series.length; i++) {
  2069. this._sumy += this.series[i]._sumy;
  2070. this._sumx += this.series[i]._sumx;
  2071. }
  2072. this.draw();
  2073. this.target.trigger('jqplotPostRedraw');
  2074. };
  2075. // method: draw
  2076. // Draws all elements of the plot into the container.
  2077. // Does not clear the container before drawing.
  2078. this.draw = function(){
  2079. if (this.drawIfHidden || this.target.is(':visible')) {
  2080. this.target.trigger('jqplotPreDraw');
  2081. var i, j;
  2082. for (i=0; i<$.jqplot.preDrawHooks.length; i++) {
  2083. $.jqplot.preDrawHooks[i].call(this);
  2084. }
  2085. for (i=0; i<this.preDrawHooks.hooks.length; i++) {
  2086. this.preDrawHooks.hooks[i].call(this);
  2087. }
  2088. // create an underlying canvas to be used for special features.
  2089. this.target.append(this.baseCanvas.createElement({left:0, right:0, top:0, bottom:0}, 'jqplot-base-canvas'));
  2090. this.baseCanvas.setContext();
  2091. this.target.append(this.title.draw());
  2092. this.title.pack({top:0, left:0});
  2093. // make room for the legend between the grid and the edge.
  2094. var legendElem = this.legend.draw();
  2095. var gridPadding = {top:0, left:0, bottom:0, right:0};
  2096. if (this.legend.placement == "outsideGrid") {
  2097. // temporarily append the legend to get dimensions
  2098. this.target.append(legendElem);
  2099. switch (this.legend.location) {
  2100. case 'n':
  2101. gridPadding.top += this.legend.getHeight();
  2102. break;
  2103. case 's':
  2104. gridPadding.bottom += this.legend.getHeight();
  2105. break;
  2106. case 'ne':
  2107. case 'e':
  2108. case 'se':
  2109. gridPadding.right += this.legend.getWidth();
  2110. break;
  2111. case 'nw':
  2112. case 'w':
  2113. case 'sw':
  2114. gridPadding.left += this.legend.getWidth();
  2115. break;
  2116. default: // same as 'ne'
  2117. gridPadding.right += this.legend.getWidth();
  2118. break;
  2119. }
  2120. legendElem = legendElem.detach();
  2121. }
  2122. var ax = this.axes;
  2123. for (var name in ax) {
  2124. this.target.append(ax[name].draw(this.baseCanvas._ctx));
  2125. ax[name].set();
  2126. }
  2127. if (ax.yaxis.show) {
  2128. gridPadding.left += ax.yaxis.getWidth();
  2129. }
  2130. var ra = ['y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
  2131. var rapad = [0, 0, 0, 0, 0, 0, 0, 0];
  2132. var gpr = 0;
  2133. var n;
  2134. for (n=0; n<8; n++) {
  2135. if (ax[ra[n]].show) {
  2136. gpr += ax[ra[n]].getWidth();
  2137. rapad[n] = gpr;
  2138. }
  2139. }
  2140. gridPadding.right += gpr;
  2141. if (ax.x2axis.show) {
  2142. gridPadding.top += ax.x2axis.getHeight();
  2143. }
  2144. if (this.title.show) {
  2145. gridPadding.top += this.title.getHeight();
  2146. }
  2147. if (ax.xaxis.show) {
  2148. gridPadding.bottom += ax.xaxis.getHeight();
  2149. }
  2150. // end of gridPadding adjustments.
  2151. var arr = ['top', 'bottom', 'left', 'right'];
  2152. for (var n in arr) {
  2153. if (this._gridPadding[arr[n]] == null && gridPadding[arr[n]] > 0) {
  2154. this._gridPadding[arr[n]] = gridPadding[arr[n]];
  2155. }
  2156. else if (this._gridPadding[arr[n]] == null) {
  2157. this._gridPadding[arr[n]] = this._defaultGridPadding[arr[n]];
  2158. }
  2159. }
  2160. var legendPadding = (this.legend.placement == 'outsideGrid') ? {top:this.title.getHeight(), left: 0, right: 0, bottom: 0} : this._gridPadding;
  2161. ax.xaxis.pack({position:'absolute', bottom:this._gridPadding.bottom - ax.xaxis.getHeight(), left:0, width:this._width}, {min:this._gridPadding.left, max:this._width - this._gridPadding.right});
  2162. ax.yaxis.pack({position:'absolute', top:0, left:this._gridPadding.left - ax.yaxis.getWidth(), height:this._height}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
  2163. ax.x2axis.pack({position:'absolute', top:this._gridPadding.top - ax.x2axis.getHeight(), left:0, width:this._width}, {min:this._gridPadding.left, max:this._width - this._gridPadding.right});
  2164. for (i=8; i>0; i--) {
  2165. ax[ra[i-1]].pack({position:'absolute', top:0, right:this._gridPadding.right - rapad[i-1]}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
  2166. }
  2167. // ax.y2axis.pack({position:'absolute', top:0, right:0}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
  2168. this.target.append(this.grid.createElement(this._gridPadding));
  2169. this.grid.draw();
  2170. // put the shadow canvases behind the series canvases so shadows don't overlap on stacked bars.
  2171. for (i=0; i<this.series.length; i++) {
  2172. // draw series in order of stacking. This affects only
  2173. // order in which canvases are added to dom.
  2174. j = this.seriesStack[i];
  2175. this.target.append(this.series[j].shadowCanvas.createElement(this._gridPadding, 'jqplot-series-shadowCanvas'));
  2176. this.series[j].shadowCanvas.setContext();
  2177. this.series[j].shadowCanvas._elem.data('seriesIndex', j);
  2178. }
  2179. for (i=0; i<this.series.length; i++) {
  2180. // draw series in order of stacking. This affects only
  2181. // order in which canvases are added to dom.
  2182. j = this.seriesStack[i];
  2183. this.target.append(this.series[j].canvas.createElement(this._gridPadding, 'jqplot-series-canvas'));
  2184. this.series[j].canvas.setContext();
  2185. this.series[j].canvas._elem.data('seriesIndex', j);
  2186. }
  2187. // Need to use filled canvas to capture events in IE.
  2188. // Also, canvas seems to block selection of other elements in document on FF.
  2189. this.target.append(this.eventCanvas.createElement(this._gridPadding, 'jqplot-event-canvas'));
  2190. this.eventCanvas.setContext();
  2191. this.eventCanvas._ctx.fillStyle = 'rgba(0,0,0,0)';
  2192. this.eventCanvas._ctx.fillRect(0,0,this.eventCanvas._ctx.canvas.width, this.eventCanvas._ctx.canvas.height);
  2193. // bind custom event handlers to regular events.
  2194. this.bindCustomEvents();
  2195. // draw legend before series if the series needs to know the legend dimensions.
  2196. if (this.legend.preDraw) {
  2197. this.eventCanvas._elem.before(legendElem);
  2198. this.legend.pack(legendPadding);
  2199. if (this.legend._elem) {
  2200. this.drawSeries({legendInfo:{location:this.legend.location, placement:this.legend.placement, width:this.legend.getWidth(), height:this.legend.getHeight(), xoffset:this.legend.xoffset, yoffset:this.legend.yoffset}});
  2201. }
  2202. else {
  2203. this.drawSeries();
  2204. }
  2205. }
  2206. else { // draw series before legend
  2207. this.drawSeries();
  2208. if (this.series.length) {
  2209. $(this.series[this.series.length-1].canvas._elem).after(legendElem);
  2210. }
  2211. this.legend.pack(legendPadding);
  2212. }
  2213. // register event listeners on the overlay canvas
  2214. for (var i=0; i<$.jqplot.eventListenerHooks.length; i++) {
  2215. // in the handler, this will refer to the eventCanvas dom element.
  2216. // make sure there are references back into plot objects.
  2217. this.eventCanvas._elem.bind($.jqplot.eventListenerHooks[i][0], {plot:this}, $.jqplot.eventListenerHooks[i][1]);
  2218. }
  2219. // register event listeners on the overlay canvas
  2220. for (var i=0; i<this.eventListenerHooks.hooks.length; i++) {
  2221. // in the handler, this will refer to the eventCanvas dom element.
  2222. // make sure there are references back into plot objects.
  2223. this.eventCanvas._elem.bind(this.eventListenerHooks.hooks[i][0], {plot:this}, this.eventListenerHooks.hooks[i][1]);
  2224. }
  2225. for (var i=0; i<$.jqplot.postDrawHooks.length; i++) {
  2226. $.jqplot.postDrawHooks[i].call(this);
  2227. }
  2228. for (var i=0; i<this.postDrawHooks.hooks.length; i++) {
  2229. this.postDrawHooks.hooks[i].call(this);
  2230. }
  2231. if (this.target.is(':visible')) {
  2232. this._drawCount += 1;
  2233. }
  2234. this.target.trigger('jqplotPostDraw', [this]);
  2235. }
  2236. };
  2237. this.bindCustomEvents = function() {
  2238. this.eventCanvas._elem.bind('click', {plot:this}, this.onClick);
  2239. this.eventCanvas._elem.bind('dblclick', {plot:this}, this.onDblClick);
  2240. this.eventCanvas._elem.bind('mousedown', {plot:this}, this.onMouseDown);
  2241. this.eventCanvas._elem.bind('mousemove', {plot:this}, this.onMouseMove);
  2242. this.eventCanvas._elem.bind('mouseenter', {plot:this}, this.onMouseEnter);
  2243. this.eventCanvas._elem.bind('mouseleave', {plot:this}, this.onMouseLeave);
  2244. if (this.captureRightClick) {
  2245. this.eventCanvas._elem.bind('mouseup', {plot:this}, this.onRightClick);
  2246. this.eventCanvas._elem.get(0).oncontextmenu = function() {
  2247. return false;
  2248. };
  2249. }
  2250. else {
  2251. this.eventCanvas._elem.bind('mouseup', {plot:this}, this.onMouseUp);
  2252. }
  2253. };
  2254. function getEventPosition(ev) {
  2255. var plot = ev.data.plot;
  2256. var go = plot.eventCanvas._elem.offset();
  2257. var gridPos = {x:ev.pageX - go.left, y:ev.pageY - go.top};
  2258. var dataPos = {xaxis:null, yaxis:null, x2axis:null, y2axis:null, y3axis:null, y4axis:null, y5axis:null, y6axis:null, y7axis:null, y8axis:null, y9axis:null};
  2259. var an = ['xaxis', 'yaxis', 'x2axis', 'y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
  2260. var ax = plot.axes;
  2261. var n, axis;
  2262. for (n=11; n>0; n--) {
  2263. axis = an[n-1];
  2264. if (ax[axis].show) {
  2265. dataPos[axis] = ax[axis].series_p2u(gridPos[axis.charAt(0)]);
  2266. }
  2267. }
  2268. return {offsets:go, gridPos:gridPos, dataPos:dataPos};
  2269. }
  2270. // function to check if event location is over a area area
  2271. function checkIntersection(gridpos, plot) {
  2272. var series = plot.series;
  2273. var i, j, k, s, r, x, y, theta, sm, sa, minang, maxang;
  2274. var d0, d, p, pp, points, bw;
  2275. var threshold, t;
  2276. for (k=plot.seriesStack.length-1; k>=0; k--) {
  2277. i = plot.seriesStack[k];
  2278. s = series[i];
  2279. switch (s.renderer.constructor) {
  2280. case $.jqplot.BarRenderer:
  2281. x = gridpos.x;
  2282. y = gridpos.y;
  2283. for (j=0; j<s._barPoints.length; j++) {
  2284. points = s._barPoints[j];
  2285. if (x>points[0][0] && x<points[2][0] && y>points[2][1] && y<points[0][1]) {
  2286. return {seriesIndex:s.index, pointIndex:j, gridData:p, data:s.data[j], points:s._barPoints[j]};
  2287. }
  2288. }
  2289. break;
  2290. case $.jqplot.DonutRenderer:
  2291. sa = s.startAngle/180*Math.PI;
  2292. x = gridpos.x - s._center[0];
  2293. y = gridpos.y - s._center[1];
  2294. r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  2295. if (x > 0 && -y >= 0) {
  2296. theta = 2*Math.PI - Math.atan(-y/x);
  2297. }
  2298. else if (x > 0 && -y < 0) {
  2299. theta = -Math.atan(-y/x);
  2300. }
  2301. else if (x < 0) {
  2302. theta = Math.PI - Math.atan(-y/x);
  2303. }
  2304. else if (x == 0 && -y > 0) {
  2305. theta = 3*Math.PI/2;
  2306. }
  2307. else if (x == 0 && -y < 0) {
  2308. theta = Math.PI/2;
  2309. }
  2310. else if (x == 0 && y == 0) {
  2311. theta = 0;
  2312. }
  2313. if (sa) {
  2314. theta -= sa;
  2315. if (theta < 0) {
  2316. theta += 2*Math.PI;
  2317. }
  2318. else if (theta > 2*Math.PI) {
  2319. theta -= 2*Math.PI;
  2320. }
  2321. }
  2322. sm = s.sliceMargin/180*Math.PI;
  2323. if (r < s._radius && r > s._innerRadius) {
  2324. for (j=0; j<s.gridData.length; j++) {
  2325. minang = (j>0) ? s.gridData[j-1][1]+sm : sm;
  2326. maxang = s.gridData[j][1];
  2327. if (theta > minang && theta < maxang) {
  2328. return {seriesIndex:s.index, pointIndex:j, gridData:s.gridData[j], data:s.data[j]};
  2329. }
  2330. }
  2331. }
  2332. break;
  2333. case $.jqplot.PieRenderer:
  2334. sa = s.startAngle/180*Math.PI;
  2335. x = gridpos.x - s._center[0];
  2336. y = gridpos.y - s._center[1];
  2337. r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  2338. if (x > 0 && -y >= 0) {
  2339. theta = 2*Math.PI - Math.atan(-y/x);
  2340. }
  2341. else if (x > 0 && -y < 0) {
  2342. theta = -Math.atan(-y/x);
  2343. }
  2344. else if (x < 0) {
  2345. theta = Math.PI - Math.atan(-y/x);
  2346. }
  2347. else if (x == 0 && -y > 0) {
  2348. theta = 3*Math.PI/2;
  2349. }
  2350. else if (x == 0 && -y < 0) {
  2351. theta = Math.PI/2;
  2352. }
  2353. else if (x == 0 && y == 0) {
  2354. theta = 0;
  2355. }
  2356. if (sa) {
  2357. theta -= sa;
  2358. if (theta < 0) {
  2359. theta += 2*Math.PI;
  2360. }
  2361. else if (theta > 2*Math.PI) {
  2362. theta -= 2*Math.PI;
  2363. }
  2364. }
  2365. sm = s.sliceMargin/180*Math.PI;
  2366. if (r < s._radius) {
  2367. for (j=0; j<s.gridData.length; j++) {
  2368. minang = (j>0) ? s.gridData[j-1][1]+sm : sm;
  2369. maxang = s.gridData[j][1];
  2370. if (theta > minang && theta < maxang) {
  2371. return {seriesIndex:s.index, pointIndex:j, gridData:s.gridData[j], data:s.data[j]};
  2372. }
  2373. }
  2374. }
  2375. break;
  2376. case $.jqplot.BubbleRenderer:
  2377. x = gridpos.x;
  2378. y = gridpos.y;
  2379. var ret = null;
  2380. if (s.show) {
  2381. for (var j=0; j<s.gridData.length; j++) {
  2382. p = s.gridData[j];
  2383. d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
  2384. if (d <= p[2] && (d <= d0 || d0 == null)) {
  2385. d0 = d;
  2386. ret = {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  2387. }
  2388. }
  2389. if (ret != null) {
  2390. return ret;
  2391. }
  2392. }
  2393. break;
  2394. case $.jqplot.FunnelRenderer:
  2395. x = gridpos.x;
  2396. y = gridpos.y;
  2397. var v = s._vertices,
  2398. vfirst = v[0],
  2399. vlast = v[v.length-1],
  2400. lex,
  2401. rex;
  2402. // equations of right and left sides, returns x, y values given height of section (y value and 2 points)
  2403. function findedge (l, p1 , p2) {
  2404. var m = (p1[1] - p2[1])/(p1[0] - p2[0]);
  2405. var b = p1[1] - m*p1[0];
  2406. var y = l + p1[1];
  2407. return [(y - b)/m, y];
  2408. }
  2409. // check each section
  2410. lex = findedge(y, vfirst[0], vlast[3]);
  2411. rex = findedge(y, vfirst[1], vlast[2]);
  2412. for (j=0; j<v.length; j++) {
  2413. cv = v[j];
  2414. if (y >= cv[0][1] && y <= cv[3][1] && x >= lex[0] && x <= rex[0]) {
  2415. return {seriesIndex:s.index, pointIndex:j, gridData:null, data:s.data[j]};
  2416. }
  2417. }
  2418. break;
  2419. case $.jqplot.LineRenderer:
  2420. x = gridpos.x;
  2421. y = gridpos.y;
  2422. r = s.renderer;
  2423. if (s.show) {
  2424. if (s.fill) {
  2425. // first check if it is in bounding box
  2426. var inside = false;
  2427. if (x>s._boundingBox[0][0] && x<s._boundingBox[1][0] && y>s._boundingBox[1][1] && y<s._boundingBox[0][1]) {
  2428. // now check the crossing number
  2429. var numPoints = s._areaPoints.length;
  2430. var ii;
  2431. var j = numPoints-1;
  2432. for(var ii=0; ii < numPoints; ii++) {
  2433. var vertex1 = [s._areaPoints[ii][0], s._areaPoints[ii][1]];
  2434. var vertex2 = [s._areaPoints[j][0], s._areaPoints[j][1]];
  2435. if (vertex1[1] < y && vertex2[1] >= y || vertex2[1] < y && vertex1[1] >= y) {
  2436. if (vertex1[0] + (y - vertex1[1]) / (vertex2[1] - vertex1[1]) * (vertex2[0] - vertex1[0]) < x) {
  2437. inside = !inside;
  2438. }
  2439. }
  2440. j = ii;
  2441. }
  2442. }
  2443. if (inside) {
  2444. return {seriesIndex:i, pointIndex:null, gridData:s.gridData, data:s.data, points:s._areaPoints};
  2445. }
  2446. break;
  2447. }
  2448. else {
  2449. t = s.markerRenderer.size/2+s.neighborThreshold;
  2450. threshold = (t > 0) ? t : 0;
  2451. for (var j=0; j<s.gridData.length; j++) {
  2452. p = s.gridData[j];
  2453. // neighbor looks different to OHLC chart.
  2454. if (r.constructor == $.jqplot.OHLCRenderer) {
  2455. if (r.candleStick) {
  2456. var yp = s._yaxis.series_u2p;
  2457. if (x >= p[0]-r._bodyWidth/2 && x <= p[0]+r._bodyWidth/2 && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  2458. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  2459. }
  2460. }
  2461. // if an open hi low close chart
  2462. else if (!r.hlc){
  2463. var yp = s._yaxis.series_u2p;
  2464. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  2465. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  2466. }
  2467. }
  2468. // a hi low close chart
  2469. else {
  2470. var yp = s._yaxis.series_u2p;
  2471. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][1]) && y <= yp(s.data[j][2])) {
  2472. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  2473. }
  2474. }
  2475. }
  2476. else if (p[0] != null && p[1] != null){
  2477. d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
  2478. if (d <= threshold && (d <= d0 || d0 == null)) {
  2479. d0 = d;
  2480. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  2481. }
  2482. }
  2483. }
  2484. }
  2485. }
  2486. break;
  2487. default:
  2488. x = gridpos.x;
  2489. y = gridpos.y;
  2490. r = s.renderer;
  2491. if (s.show) {
  2492. t = s.markerRenderer.size/2+s.neighborThreshold;
  2493. threshold = (t > 0) ? t : 0;
  2494. for (var j=0; j<s.gridData.length; j++) {
  2495. p = s.gridData[j];
  2496. // neighbor looks different to OHLC chart.
  2497. if (r.constructor == $.jqplot.OHLCRenderer) {
  2498. if (r.candleStick) {
  2499. var yp = s._yaxis.series_u2p;
  2500. if (x >= p[0]-r._bodyWidth/2 && x <= p[0]+r._bodyWidth/2 && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  2501. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  2502. }
  2503. }
  2504. // if an open hi low close chart
  2505. else if (!r.hlc){
  2506. var yp = s._yaxis.series_u2p;
  2507. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  2508. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  2509. }
  2510. }
  2511. // a hi low close chart
  2512. else {
  2513. var yp = s._yaxis.series_u2p;
  2514. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][1]) && y <= yp(s.data[j][2])) {
  2515. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  2516. }
  2517. }
  2518. }
  2519. else {
  2520. d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
  2521. if (d <= threshold && (d <= d0 || d0 == null)) {
  2522. d0 = d;
  2523. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  2524. }
  2525. }
  2526. }
  2527. }
  2528. break;
  2529. }
  2530. }
  2531. return null;
  2532. }
  2533. this.onClick = function(ev) {
  2534. // Event passed in is normalized and will have data attribute.
  2535. // Event passed out is unnormalized.
  2536. var positions = getEventPosition(ev);
  2537. var p = ev.data.plot;
  2538. var neighbor = checkIntersection(positions.gridPos, p);
  2539. var evt = jQuery.Event('jqplotClick');
  2540. evt.pageX = ev.pageX;
  2541. evt.pageY = ev.pageY;
  2542. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  2543. };
  2544. this.onDblClick = function(ev) {
  2545. // Event passed in is normalized and will have data attribute.
  2546. // Event passed out is unnormalized.
  2547. var positions = getEventPosition(ev);
  2548. var p = ev.data.plot;
  2549. var neighbor = checkIntersection(positions.gridPos, p);
  2550. var evt = jQuery.Event('jqplotDblClick');
  2551. evt.pageX = ev.pageX;
  2552. evt.pageY = ev.pageY;
  2553. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  2554. };
  2555. this.onMouseDown = function(ev) {
  2556. var positions = getEventPosition(ev);
  2557. var p = ev.data.plot;
  2558. var neighbor = checkIntersection(positions.gridPos, p);
  2559. var evt = jQuery.Event('jqplotMouseDown');
  2560. evt.pageX = ev.pageX;
  2561. evt.pageY = ev.pageY;
  2562. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  2563. };
  2564. this.onMouseUp = function(ev) {
  2565. var positions = getEventPosition(ev);
  2566. var evt = jQuery.Event('jqplotMouseUp');
  2567. evt.pageX = ev.pageX;
  2568. evt.pageY = ev.pageY;
  2569. $(this).trigger(evt, [positions.gridPos, positions.dataPos, null, ev.data.plot]);
  2570. };
  2571. this.onRightClick = function(ev) {
  2572. var positions = getEventPosition(ev);
  2573. var p = ev.data.plot;
  2574. var neighbor = checkIntersection(positions.gridPos, p);
  2575. if (p.captureRightClick) {
  2576. if (ev.which == 3) {
  2577. var evt = jQuery.Event('jqplotRightClick');
  2578. evt.pageX = ev.pageX;
  2579. evt.pageY = ev.pageY;
  2580. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  2581. }
  2582. else {
  2583. var evt = jQuery.Event('jqplotMouseUp');
  2584. evt.pageX = ev.pageX;
  2585. evt.pageY = ev.pageY;
  2586. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  2587. }
  2588. }
  2589. };
  2590. this.onMouseMove = function(ev) {
  2591. var positions = getEventPosition(ev);
  2592. var p = ev.data.plot;
  2593. var neighbor = checkIntersection(positions.gridPos, p);
  2594. var evt = jQuery.Event('jqplotMouseMove');
  2595. evt.pageX = ev.pageX;
  2596. evt.pageY = ev.pageY;
  2597. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  2598. };
  2599. this.onMouseEnter = function(ev) {
  2600. var positions = getEventPosition(ev);
  2601. var p = ev.data.plot;
  2602. var evt = jQuery.Event('jqplotMouseEnter');
  2603. evt.pageX = ev.pageX;
  2604. evt.pageY = ev.pageY;
  2605. $(this).trigger(evt, [positions.gridPos, positions.dataPos, null, p]);
  2606. };
  2607. this.onMouseLeave = function(ev) {
  2608. var positions = getEventPosition(ev);
  2609. var p = ev.data.plot;
  2610. var evt = jQuery.Event('jqplotMouseLeave');
  2611. evt.pageX = ev.pageX;
  2612. evt.pageY = ev.pageY;
  2613. $(this).trigger(evt, [positions.gridPos, positions.dataPos, null, p]);
  2614. };
  2615. // method: drawSeries
  2616. // Redraws all or just one series on the plot. No axis scaling
  2617. // is performed and no other elements on the plot are redrawn.
  2618. // options is an options object to pass on to the series renderers.
  2619. // It can be an empty object {}. idx is the series index
  2620. // to redraw if only one series is to be redrawn.
  2621. this.drawSeries = function(options, idx){
  2622. var i, series, ctx;
  2623. // if only one argument passed in and it is a number, use it ad idx.
  2624. idx = (typeof(options) === "number" && idx == null) ? options : idx;
  2625. options = (typeof(options) === "object") ? options : {};
  2626. // draw specified series
  2627. if (idx != undefined) {
  2628. series = this.series[idx];
  2629. ctx = series.shadowCanvas._ctx;
  2630. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  2631. series.drawShadow(ctx, options, this);
  2632. ctx = series.canvas._ctx;
  2633. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  2634. series.draw(ctx, options, this);
  2635. if (series.renderer.constructor == $.jqplot.BezierCurveRenderer) {
  2636. if (idx < this.series.length - 1) {
  2637. this.drawSeries(idx+1);
  2638. }
  2639. }
  2640. }
  2641. else {
  2642. // if call series drawShadow method first, in case all series shadows
  2643. // should be drawn before any series. This will ensure, like for
  2644. // stacked bar plots, that shadows don't overlap series.
  2645. for (i=0; i<this.series.length; i++) {
  2646. // first clear the canvas
  2647. series = this.series[i];
  2648. ctx = series.shadowCanvas._ctx;
  2649. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  2650. series.drawShadow(ctx, options, this);
  2651. ctx = series.canvas._ctx;
  2652. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  2653. series.draw(ctx, options, this);
  2654. }
  2655. }
  2656. options = idx = i = series = ctx = null;
  2657. };
  2658. // method: moveSeriesToFront
  2659. // This method requires jQuery 1.4+
  2660. // Moves the specified series canvas in front of all other series canvases.
  2661. // This effectively "draws" the specified series on top of all other series,
  2662. // although it is performed through DOM manipulation, no redrawing is performed.
  2663. //
  2664. // Parameters:
  2665. // idx - 0 based index of the series to move. This will be the index of the series
  2666. // as it was first passed into the jqplot function.
  2667. this.moveSeriesToFront = function (idx) {
  2668. idx = parseInt(idx, 10);
  2669. var stackIndex = $.inArray(idx, this.seriesStack);
  2670. // if already in front, return
  2671. if (stackIndex == -1) {
  2672. return;
  2673. }
  2674. if (stackIndex == this.seriesStack.length -1) {
  2675. this.previousSeriesStack = this.seriesStack.slice(0);
  2676. return;
  2677. }
  2678. var opidx = this.seriesStack[this.seriesStack.length -1];
  2679. var serelem = this.series[idx].canvas._elem.detach();
  2680. var shadelem = this.series[idx].shadowCanvas._elem.detach();
  2681. this.series[opidx].shadowCanvas._elem.after(shadelem);
  2682. this.series[opidx].canvas._elem.after(serelem);
  2683. this.previousSeriesStack = this.seriesStack.slice(0);
  2684. this.seriesStack.splice(stackIndex, 1);
  2685. this.seriesStack.push(idx);
  2686. };
  2687. // method: moveSeriesToBack
  2688. // This method requires jQuery 1.4+
  2689. // Moves the specified series canvas behind all other series canvases.
  2690. //
  2691. // Parameters:
  2692. // idx - 0 based index of the series to move. This will be the index of the series
  2693. // as it was first passed into the jqplot function.
  2694. this.moveSeriesToBack = function (idx) {
  2695. idx = parseInt(idx, 10);
  2696. var stackIndex = $.inArray(idx, this.seriesStack);
  2697. // if already in back, return
  2698. if (stackIndex == 0 || stackIndex == -1) {
  2699. return;
  2700. }
  2701. var opidx = this.seriesStack[0];
  2702. var serelem = this.series[idx].canvas._elem.detach();
  2703. var shadelem = this.series[idx].shadowCanvas._elem.detach();
  2704. this.series[opidx].shadowCanvas._elem.before(shadelem);
  2705. this.series[opidx].canvas._elem.before(serelem);
  2706. this.previousSeriesStack = this.seriesStack.slice(0);
  2707. this.seriesStack.splice(stackIndex, 1);
  2708. this.seriesStack.unshift(idx);
  2709. };
  2710. // method: restorePreviousSeriesOrder
  2711. // This method requires jQuery 1.4+
  2712. // Restore the series canvas order to its previous state.
  2713. // Useful to put a series back where it belongs after moving
  2714. // it to the front.
  2715. this.restorePreviousSeriesOrder = function () {
  2716. var i, j, serelem, shadelem, temp;
  2717. // if no change, return.
  2718. if (this.seriesStack == this.previousSeriesStack) {
  2719. return;
  2720. }
  2721. for (i=1; i<this.previousSeriesStack.length; i++) {
  2722. move = this.previousSeriesStack[i];
  2723. keep = this.previousSeriesStack[i-1];
  2724. serelem = this.series[move].canvas._elem.detach();
  2725. shadelem = this.series[move].shadowCanvas._elem.detach();
  2726. this.series[keep].shadowCanvas._elem.after(shadelem);
  2727. this.series[keep].canvas._elem.after(serelem);
  2728. }
  2729. temp = this.seriesStack.slice(0);
  2730. this.seriesStack = this.previousSeriesStack.slice(0);
  2731. this.previousSeriesStack = temp;
  2732. };
  2733. // method: restoreOriginalSeriesOrder
  2734. // This method requires jQuery 1.4+
  2735. // Restore the series canvas order to its original order
  2736. // when the plot was created.
  2737. this.restoreOriginalSeriesOrder = function () {
  2738. var i, j, arr=[];
  2739. for (i=0; i<this.series.length; i++) {
  2740. arr.push(i);
  2741. }
  2742. if (this.seriesStack == arr) {
  2743. return;
  2744. }
  2745. this.previousSeriesStack = this.seriesStack.slice(0);
  2746. this.seriesStack = arr;
  2747. for (i=1; i<this.seriesStack.length; i++) {
  2748. serelem = this.series[i].canvas._elem.detach();
  2749. shadelem = this.series[i].shadowCanvas._elem.detach();
  2750. this.series[i-1].shadowCanvas._elem.after(shadelem);
  2751. this.series[i-1].canvas._elem.after(serelem);
  2752. }
  2753. };
  2754. this.activateTheme = function (name) {
  2755. this.themeEngine.activate(this, name);
  2756. };
  2757. }
  2758. // conpute a highlight color or array of highlight colors from given colors.
  2759. $.jqplot.computeHighlightColors = function(colors) {
  2760. var ret;
  2761. if (jQuery.isArray(colors)) {
  2762. ret = [];
  2763. for (var i=0; i<colors.length; i++){
  2764. var rgba = $.jqplot.getColorComponents(colors[i]);
  2765. var newrgb = [rgba[0], rgba[1], rgba[2]];
  2766. var sum = newrgb[0] + newrgb[1] + newrgb[2];
  2767. for (var j=0; j<3; j++) {
  2768. // when darkening, lowest color component can be is 60.
  2769. newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
  2770. newrgb[j] = parseInt(newrgb[j], 10);
  2771. }
  2772. ret.push('rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')');
  2773. }
  2774. }
  2775. else {
  2776. var rgba = $.jqplot.getColorComponents(colors);
  2777. var newrgb = [rgba[0], rgba[1], rgba[2]];
  2778. var sum = newrgb[0] + newrgb[1] + newrgb[2];
  2779. for (var j=0; j<3; j++) {
  2780. // when darkening, lowest color component can be is 60.
  2781. newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
  2782. newrgb[j] = parseInt(newrgb[j], 10);
  2783. }
  2784. ret = 'rgb('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+')';
  2785. }
  2786. return ret;
  2787. };
  2788. $.jqplot.ColorGenerator = function(colors) {
  2789. var idx = 0;
  2790. this.next = function () {
  2791. if (idx < colors.length) {
  2792. return colors[idx++];
  2793. }
  2794. else {
  2795. idx = 0;
  2796. return colors[idx++];
  2797. }
  2798. };
  2799. this.previous = function () {
  2800. if (idx > 0) {
  2801. return colors[idx--];
  2802. }
  2803. else {
  2804. idx = colors.length-1;
  2805. return colors[idx];
  2806. }
  2807. };
  2808. // get a color by index without advancing pointer.
  2809. this.get = function(i) {
  2810. var idx = i - colors.length * Math.floor(i/colors.length);
  2811. return colors[idx];
  2812. };
  2813. this.setColors = function(c) {
  2814. colors = c;
  2815. };
  2816. this.reset = function() {
  2817. idx = 0;
  2818. };
  2819. };
  2820. // convert a hex color string to rgb string.
  2821. // h - 3 or 6 character hex string, with or without leading #
  2822. // a - optional alpha
  2823. $.jqplot.hex2rgb = function(h, a) {
  2824. h = h.replace('#', '');
  2825. if (h.length == 3) {
  2826. h = h.charAt(0)+h.charAt(0)+h.charAt(1)+h.charAt(1)+h.charAt(2)+h.charAt(2);
  2827. }
  2828. var rgb;
  2829. rgb = 'rgba('+parseInt(h.slice(0,2), 16)+', '+parseInt(h.slice(2,4), 16)+', '+parseInt(h.slice(4,6), 16);
  2830. if (a) {
  2831. rgb += ', '+a;
  2832. }
  2833. rgb += ')';
  2834. return rgb;
  2835. };
  2836. // convert an rgb color spec to a hex spec. ignore any alpha specification.
  2837. $.jqplot.rgb2hex = function(s) {
  2838. var pat = /rgba?\( *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *(?:, *[0-9.]*)?\)/;
  2839. var m = s.match(pat);
  2840. var h = '#';
  2841. for (i=1; i<4; i++) {
  2842. var temp;
  2843. if (m[i].search(/%/) != -1) {
  2844. temp = parseInt(255*m[i]/100, 10).toString(16);
  2845. if (temp.length == 1) {
  2846. temp = '0'+temp;
  2847. }
  2848. }
  2849. else {
  2850. temp = parseInt(m[i], 10).toString(16);
  2851. if (temp.length == 1) {
  2852. temp = '0'+temp;
  2853. }
  2854. }
  2855. h += temp;
  2856. }
  2857. return h;
  2858. };
  2859. // given a css color spec, return an rgb css color spec
  2860. $.jqplot.normalize2rgb = function(s, a) {
  2861. if (s.search(/^ *rgba?\(/) != -1) {
  2862. return s;
  2863. }
  2864. else if (s.search(/^ *#?[0-9a-fA-F]?[0-9a-fA-F]/) != -1) {
  2865. return $.jqplot.hex2rgb(s, a);
  2866. }
  2867. else {
  2868. throw 'invalid color spec';
  2869. }
  2870. };
  2871. // extract the r, g, b, a color components out of a css color spec.
  2872. $.jqplot.getColorComponents = function(s) {
  2873. // check to see if a color keyword.
  2874. s = $.jqplot.colorKeywordMap[s] || s;
  2875. var rgb = $.jqplot.normalize2rgb(s);
  2876. var pat = /rgba?\( *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *,? *([0-9.]* *)?\)/;
  2877. var m = rgb.match(pat);
  2878. var ret = [];
  2879. for (i=1; i<4; i++) {
  2880. if (m[i].search(/%/) != -1) {
  2881. ret[i-1] = parseInt(255*m[i]/100, 10);
  2882. }
  2883. else {
  2884. ret[i-1] = parseInt(m[i], 10);
  2885. }
  2886. }
  2887. ret[3] = parseFloat(m[4]) ? parseFloat(m[4]) : 1.0;
  2888. return ret;
  2889. };
  2890. $.jqplot.colorKeywordMap = {aliceblue: 'rgb(240, 248, 255)', antiquewhite: 'rgb(250, 235, 215)', aqua: 'rgb( 0, 255, 255)', aquamarine: 'rgb(127, 255, 212)', azure: 'rgb(240, 255, 255)', beige: 'rgb(245, 245, 220)', bisque: 'rgb(255, 228, 196)', black: 'rgb( 0, 0, 0)', blanchedalmond: 'rgb(255, 235, 205)', blue: 'rgb( 0, 0, 255)', blueviolet: 'rgb(138, 43, 226)', brown: 'rgb(165, 42, 42)', burlywood: 'rgb(222, 184, 135)', cadetblue: 'rgb( 95, 158, 160)', chartreuse: 'rgb(127, 255, 0)', chocolate: 'rgb(210, 105, 30)', coral: 'rgb(255, 127, 80)', cornflowerblue: 'rgb(100, 149, 237)', cornsilk: 'rgb(255, 248, 220)', crimson: 'rgb(220, 20, 60)', cyan: 'rgb( 0, 255, 255)', darkblue: 'rgb( 0, 0, 139)', darkcyan: 'rgb( 0, 139, 139)', darkgoldenrod: 'rgb(184, 134, 11)', darkgray: 'rgb(169, 169, 169)', darkgreen: 'rgb( 0, 100, 0)', darkgrey: 'rgb(169, 169, 169)', darkkhaki: 'rgb(189, 183, 107)', darkmagenta: 'rgb(139, 0, 139)', darkolivegreen: 'rgb( 85, 107, 47)', darkorange: 'rgb(255, 140, 0)', darkorchid: 'rgb(153, 50, 204)', darkred: 'rgb(139, 0, 0)', darksalmon: 'rgb(233, 150, 122)', darkseagreen: 'rgb(143, 188, 143)', darkslateblue: 'rgb( 72, 61, 139)', darkslategray: 'rgb( 47, 79, 79)', darkslategrey: 'rgb( 47, 79, 79)', darkturquoise: 'rgb( 0, 206, 209)', darkviolet: 'rgb(148, 0, 211)', deeppink: 'rgb(255, 20, 147)', deepskyblue: 'rgb( 0, 191, 255)', dimgray: 'rgb(105, 105, 105)', dimgrey: 'rgb(105, 105, 105)', dodgerblue: 'rgb( 30, 144, 255)', firebrick: 'rgb(178, 34, 34)', floralwhite: 'rgb(255, 250, 240)', forestgreen: 'rgb( 34, 139, 34)', fuchsia: 'rgb(255, 0, 255)', gainsboro: 'rgb(220, 220, 220)', ghostwhite: 'rgb(248, 248, 255)', gold: 'rgb(255, 215, 0)', goldenrod: 'rgb(218, 165, 32)', gray: 'rgb(128, 128, 128)', grey: 'rgb(128, 128, 128)', green: 'rgb( 0, 128, 0)', greenyellow: 'rgb(173, 255, 47)', honeydew: 'rgb(240, 255, 240)', hotpink: 'rgb(255, 105, 180)', indianred: 'rgb(205, 92, 92)', indigo: 'rgb( 75, 0, 130)', ivory: 'rgb(255, 255, 240)', khaki: 'rgb(240, 230, 140)', lavender: 'rgb(230, 230, 250)', lavenderblush: 'rgb(255, 240, 245)', lawngreen: 'rgb(124, 252, 0)', lemonchiffon: 'rgb(255, 250, 205)', lightblue: 'rgb(173, 216, 230)', lightcoral: 'rgb(240, 128, 128)', lightcyan: 'rgb(224, 255, 255)', lightgoldenrodyellow: 'rgb(250, 250, 210)', lightgray: 'rgb(211, 211, 211)', lightgreen: 'rgb(144, 238, 144)', lightgrey: 'rgb(211, 211, 211)', lightpink: 'rgb(255, 182, 193)', lightsalmon: 'rgb(255, 160, 122)', lightseagreen: 'rgb( 32, 178, 170)', lightskyblue: 'rgb(135, 206, 250)', lightslategray: 'rgb(119, 136, 153)', lightslategrey: 'rgb(119, 136, 153)', lightsteelblue: 'rgb(176, 196, 222)', lightyellow: 'rgb(255, 255, 224)', lime: 'rgb( 0, 255, 0)', limegreen: 'rgb( 50, 205, 50)', linen: 'rgb(250, 240, 230)', magenta: 'rgb(255, 0, 255)', maroon: 'rgb(128, 0, 0)', mediumaquamarine: 'rgb(102, 205, 170)', mediumblue: 'rgb( 0, 0, 205)', mediumorchid: 'rgb(186, 85, 211)', mediumpurple: 'rgb(147, 112, 219)', mediumseagreen: 'rgb( 60, 179, 113)', mediumslateblue: 'rgb(123, 104, 238)', mediumspringgreen: 'rgb( 0, 250, 154)', mediumturquoise: 'rgb( 72, 209, 204)', mediumvioletred: 'rgb(199, 21, 133)', midnightblue: 'rgb( 25, 25, 112)', mintcream: 'rgb(245, 255, 250)', mistyrose: 'rgb(255, 228, 225)', moccasin: 'rgb(255, 228, 181)', navajowhite: 'rgb(255, 222, 173)', navy: 'rgb( 0, 0, 128)', oldlace: 'rgb(253, 245, 230)', olive: 'rgb(128, 128, 0)', olivedrab: 'rgb(107, 142, 35)', orange: 'rgb(255, 165, 0)', orangered: 'rgb(255, 69, 0)', orchid: 'rgb(218, 112, 214)', palegoldenrod: 'rgb(238, 232, 170)', palegreen: 'rgb(152, 251, 152)', paleturquoise: 'rgb(175, 238, 238)', palevioletred: 'rgb(219, 112, 147)', papayawhip: 'rgb(255, 239, 213)', peachpuff: 'rgb(255, 218, 185)', peru: 'rgb(205, 133, 63)', pink: 'rgb(255, 192, 203)', plum: 'rgb(221, 160, 221)', powderblue: 'rgb(176, 224, 230)', purple: 'rgb(128, 0, 128)', red: 'rgb(255, 0, 0)', rosybrown: 'rgb(188, 143, 143)', royalblue: 'rgb( 65, 105, 225)', saddlebrown: 'rgb(139, 69, 19)', salmon: 'rgb(250, 128, 114)', sandybrown: 'rgb(244, 164, 96)', seagreen: 'rgb( 46, 139, 87)', seashell: 'rgb(255, 245, 238)', sienna: 'rgb(160, 82, 45)', silver: 'rgb(192, 192, 192)', skyblue: 'rgb(135, 206, 235)', slateblue: 'rgb(106, 90, 205)', slategray: 'rgb(112, 128, 144)', slategrey: 'rgb(112, 128, 144)', snow: 'rgb(255, 250, 250)', springgreen: 'rgb( 0, 255, 127)', steelblue: 'rgb( 70, 130, 180)', tan: 'rgb(210, 180, 140)', teal: 'rgb( 0, 128, 128)', thistle: 'rgb(216, 191, 216)', tomato: 'rgb(255, 99, 71)', turquoise: 'rgb( 64, 224, 208)', violet: 'rgb(238, 130, 238)', wheat: 'rgb(245, 222, 179)', white: 'rgb(255, 255, 255)', whitesmoke: 'rgb(245, 245, 245)', yellow: 'rgb(255, 255, 0)', yellowgreen: 'rgb(154, 205, 50)'};
  2891. // class: $.jqplot.AxisLabelRenderer
  2892. // Renderer to place labels on the axes.
  2893. $.jqplot.AxisLabelRenderer = function(options) {
  2894. // Group: Properties
  2895. $.jqplot.ElemContainer.call(this);
  2896. // name of the axis associated with this tick
  2897. this.axis;
  2898. // prop: show
  2899. // wether or not to show the tick (mark and label).
  2900. this.show = true;
  2901. // prop: label
  2902. // The text or html for the label.
  2903. this.label = '';
  2904. this.fontFamily = null;
  2905. this.fontSize = null;
  2906. this.textColor = null;
  2907. this._elem;
  2908. // prop: escapeHTML
  2909. // true to escape HTML entities in the label.
  2910. this.escapeHTML = false;
  2911. $.extend(true, this, options);
  2912. };
  2913. $.jqplot.AxisLabelRenderer.prototype = new $.jqplot.ElemContainer();
  2914. $.jqplot.AxisLabelRenderer.prototype.constructor = $.jqplot.AxisLabelRenderer;
  2915. $.jqplot.AxisLabelRenderer.prototype.init = function(options) {
  2916. $.extend(true, this, options);
  2917. };
  2918. $.jqplot.AxisLabelRenderer.prototype.draw = function() {
  2919. this._elem = $('<div style="position:absolute;" class="jqplot-'+this.axis+'-label"></div>');
  2920. if (Number(this.label)) {
  2921. this._elem.css('white-space', 'nowrap');
  2922. }
  2923. if (!this.escapeHTML) {
  2924. this._elem.html(this.label);
  2925. }
  2926. else {
  2927. this._elem.text(this.label);
  2928. }
  2929. if (this.fontFamily) {
  2930. this._elem.css('font-family', this.fontFamily);
  2931. }
  2932. if (this.fontSize) {
  2933. this._elem.css('font-size', this.fontSize);
  2934. }
  2935. if (this.textColor) {
  2936. this._elem.css('color', this.textColor);
  2937. }
  2938. return this._elem;
  2939. };
  2940. $.jqplot.AxisLabelRenderer.prototype.pack = function() {
  2941. };
  2942. // class: $.jqplot.AxisTickRenderer
  2943. // A "tick" object showing the value of a tick/gridline on the plot.
  2944. $.jqplot.AxisTickRenderer = function(options) {
  2945. // Group: Properties
  2946. $.jqplot.ElemContainer.call(this);
  2947. // prop: mark
  2948. // tick mark on the axis. One of 'inside', 'outside', 'cross', '' or null.
  2949. this.mark = 'outside';
  2950. // name of the axis associated with this tick
  2951. this.axis;
  2952. // prop: showMark
  2953. // wether or not to show the mark on the axis.
  2954. this.showMark = true;
  2955. // prop: showGridline
  2956. // wether or not to draw the gridline on the grid at this tick.
  2957. this.showGridline = true;
  2958. // prop: isMinorTick
  2959. // if this is a minor tick.
  2960. this.isMinorTick = false;
  2961. // prop: size
  2962. // Length of the tick beyond the grid in pixels.
  2963. // DEPRECATED: This has been superceeded by markSize
  2964. this.size = 4;
  2965. // prop: markSize
  2966. // Length of the tick marks in pixels. For 'cross' style, length
  2967. // will be stoked above and below axis, so total length will be twice this.
  2968. this.markSize = 6;
  2969. // prop: show
  2970. // wether or not to show the tick (mark and label).
  2971. // Setting this to false requires more testing. It is recommended
  2972. // to set showLabel and showMark to false instead.
  2973. this.show = true;
  2974. // prop: showLabel
  2975. // wether or not to show the label.
  2976. this.showLabel = true;
  2977. this.label = '';
  2978. this.value = null;
  2979. this._styles = {};
  2980. // prop: formatter
  2981. // A class of a formatter for the tick text. sprintf by default.
  2982. this.formatter = $.jqplot.DefaultTickFormatter;
  2983. // prop: prefix
  2984. // string appended to the tick label if no formatString is specified.
  2985. this.prefix = '';
  2986. // prop: formatString
  2987. // string passed to the formatter.
  2988. this.formatString = '';
  2989. // prop: fontFamily
  2990. // css spec for the font-family css attribute.
  2991. this.fontFamily;
  2992. // prop: fontSize
  2993. // css spec for the font-size css attribute.
  2994. this.fontSize;
  2995. // prop: textColor
  2996. // css spec for the color attribute.
  2997. this.textColor;
  2998. this._elem;
  2999. this._breakTick = false;
  3000. $.extend(true, this, options);
  3001. };
  3002. $.jqplot.AxisTickRenderer.prototype.init = function(options) {
  3003. $.extend(true, this, options);
  3004. };
  3005. $.jqplot.AxisTickRenderer.prototype = new $.jqplot.ElemContainer();
  3006. $.jqplot.AxisTickRenderer.prototype.constructor = $.jqplot.AxisTickRenderer;
  3007. $.jqplot.AxisTickRenderer.prototype.setTick = function(value, axisName, isMinor) {
  3008. this.value = value;
  3009. this.axis = axisName;
  3010. if (isMinor) {
  3011. this.isMinorTick = true;
  3012. }
  3013. return this;
  3014. };
  3015. $.jqplot.AxisTickRenderer.prototype.draw = function() {
  3016. if (!this.label) {
  3017. this.label = this.formatter(this.formatString, this.value);
  3018. }
  3019. // add prefix if needed
  3020. if (this.prefix && !this.formatString) {
  3021. this.label = this.prefix + this.label;
  3022. }
  3023. style ='style="position:absolute;';
  3024. if (Number(this.label)) {
  3025. style +='white-space:nowrap;';
  3026. }
  3027. style += '"';
  3028. this._elem = $('<div '+style+' class="jqplot-'+this.axis+'-tick">'+this.label+'</div>');
  3029. for (var s in this._styles) {
  3030. this._elem.css(s, this._styles[s]);
  3031. }
  3032. if (this.fontFamily) {
  3033. this._elem.css('font-family', this.fontFamily);
  3034. }
  3035. if (this.fontSize) {
  3036. this._elem.css('font-size', this.fontSize);
  3037. }
  3038. if (this.textColor) {
  3039. this._elem.css('color', this.textColor);
  3040. }
  3041. if (this._breakTick) {
  3042. this._elem.addClass('jqplot-breakTick');
  3043. }
  3044. return this._elem;
  3045. };
  3046. $.jqplot.DefaultTickFormatter = function (format, val) {
  3047. if (typeof val == 'number') {
  3048. if (!format) {
  3049. format = $.jqplot.config.defaultTickFormatString;
  3050. }
  3051. return $.jqplot.sprintf(format, val);
  3052. }
  3053. else {
  3054. return String(val);
  3055. }
  3056. };
  3057. $.jqplot.AxisTickRenderer.prototype.pack = function() {
  3058. };
  3059. // Class: $.jqplot.CanvasGridRenderer
  3060. // The default jqPlot grid renderer, creating a grid on a canvas element.
  3061. // The renderer has no additional options beyond the <Grid> class.
  3062. $.jqplot.CanvasGridRenderer = function(){
  3063. this.shadowRenderer = new $.jqplot.ShadowRenderer();
  3064. };
  3065. // called with context of Grid object
  3066. $.jqplot.CanvasGridRenderer.prototype.init = function(options) {
  3067. this._ctx;
  3068. $.extend(true, this, options);
  3069. // set the shadow renderer options
  3070. var sopts = {lineJoin:'miter', lineCap:'round', fill:false, isarc:false, angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, depth:this.shadowDepth, lineWidth:this.shadowWidth, closePath:false, strokeStyle:this.shadowColor};
  3071. this.renderer.shadowRenderer.init(sopts);
  3072. };
  3073. // called with context of Grid.
  3074. $.jqplot.CanvasGridRenderer.prototype.createElement = function() {
  3075. var elem = document.createElement('canvas');
  3076. var w = this._plotDimensions.width;
  3077. var h = this._plotDimensions.height;
  3078. elem.width = w;
  3079. elem.height = h;
  3080. this._elem = $(elem);
  3081. this._elem.addClass('jqplot-grid-canvas');
  3082. this._elem.css({ position: 'absolute', left: 0, top: 0 });
  3083. if ($.jqplot.use_excanvas) {
  3084. window.G_vmlCanvasManager.init_(document);
  3085. }
  3086. if ($.jqplot.use_excanvas) {
  3087. elem = window.G_vmlCanvasManager.initElement(elem);
  3088. }
  3089. this._top = this._offsets.top;
  3090. this._bottom = h - this._offsets.bottom;
  3091. this._left = this._offsets.left;
  3092. this._right = w - this._offsets.right;
  3093. this._width = this._right - this._left;
  3094. this._height = this._bottom - this._top;
  3095. // avoid memory leak
  3096. elem = null;
  3097. return this._elem;
  3098. };
  3099. $.jqplot.CanvasGridRenderer.prototype.draw = function() {
  3100. this._ctx = this._elem.get(0).getContext("2d");
  3101. var ctx = this._ctx;
  3102. var axes = this._axes;
  3103. // Add the grid onto the grid canvas. This is the bottom most layer.
  3104. ctx.save();
  3105. ctx.clearRect(0, 0, this._plotDimensions.width, this._plotDimensions.height);
  3106. ctx.fillStyle = this.backgroundColor || this.background;
  3107. ctx.fillRect(this._left, this._top, this._width, this._height);
  3108. if (true) {
  3109. ctx.save();
  3110. ctx.lineJoin = 'miter';
  3111. ctx.lineCap = 'butt';
  3112. ctx.lineWidth = this.gridLineWidth;
  3113. ctx.strokeStyle = this.gridLineColor;
  3114. var b, e;
  3115. var ax = ['xaxis', 'yaxis', 'x2axis', 'y2axis'];
  3116. for (var i=4; i>0; i--) {
  3117. var name = ax[i-1];
  3118. var axis = axes[name];
  3119. var ticks = axis._ticks;
  3120. if (axis.show) {
  3121. for (var j=ticks.length; j>0; j--) {
  3122. var t = ticks[j-1];
  3123. if (t.show) {
  3124. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  3125. switch (name) {
  3126. case 'xaxis':
  3127. // draw the grid line
  3128. if (t.showGridline && this.drawGridlines) {
  3129. drawLine(pos, this._top, pos, this._bottom);
  3130. }
  3131. // draw the mark
  3132. if (t.showMark && t.mark) {
  3133. s = t.markSize;
  3134. m = t.mark;
  3135. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  3136. switch (m) {
  3137. case 'outside':
  3138. b = this._bottom;
  3139. e = this._bottom+s;
  3140. break;
  3141. case 'inside':
  3142. b = this._bottom-s;
  3143. e = this._bottom;
  3144. break;
  3145. case 'cross':
  3146. b = this._bottom-s;
  3147. e = this._bottom+s;
  3148. break;
  3149. default:
  3150. b = this._bottom;
  3151. e = this._bottom+s;
  3152. break;
  3153. }
  3154. // draw the shadow
  3155. if (this.shadow) {
  3156. this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
  3157. }
  3158. // draw the line
  3159. drawLine(pos, b, pos, e);
  3160. }
  3161. break;
  3162. case 'yaxis':
  3163. // draw the grid line
  3164. if (t.showGridline && this.drawGridlines) {
  3165. drawLine(this._right, pos, this._left, pos);
  3166. }
  3167. // draw the mark
  3168. if (t.showMark && t.mark) {
  3169. s = t.markSize;
  3170. m = t.mark;
  3171. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  3172. switch (m) {
  3173. case 'outside':
  3174. b = this._left-s;
  3175. e = this._left;
  3176. break;
  3177. case 'inside':
  3178. b = this._left;
  3179. e = this._left+s;
  3180. break;
  3181. case 'cross':
  3182. b = this._left-s;
  3183. e = this._left+s;
  3184. break;
  3185. default:
  3186. b = this._left-s;
  3187. e = this._left;
  3188. break;
  3189. }
  3190. // draw the shadow
  3191. if (this.shadow) {
  3192. this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
  3193. }
  3194. drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
  3195. }
  3196. break;
  3197. case 'x2axis':
  3198. // draw the grid line
  3199. if (t.showGridline && this.drawGridlines) {
  3200. drawLine(pos, this._bottom, pos, this._top);
  3201. }
  3202. // draw the mark
  3203. if (t.showMark && t.mark) {
  3204. s = t.markSize;
  3205. m = t.mark;
  3206. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  3207. switch (m) {
  3208. case 'outside':
  3209. b = this._top-s;
  3210. e = this._top;
  3211. break;
  3212. case 'inside':
  3213. b = this._top;
  3214. e = this._top+s;
  3215. break;
  3216. case 'cross':
  3217. b = this._top-s;
  3218. e = this._top+s;
  3219. break;
  3220. default:
  3221. b = this._top-s;
  3222. e = this._top;
  3223. break;
  3224. }
  3225. // draw the shadow
  3226. if (this.shadow) {
  3227. this.renderer.shadowRenderer.draw(ctx, [[pos,b],[pos,e]], {lineCap:'butt', lineWidth:this.gridLineWidth, offset:this.gridLineWidth*0.75, depth:2, fill:false, closePath:false});
  3228. }
  3229. drawLine(pos, b, pos, e);
  3230. }
  3231. break;
  3232. case 'y2axis':
  3233. // draw the grid line
  3234. if (t.showGridline && this.drawGridlines) {
  3235. drawLine(this._left, pos, this._right, pos);
  3236. }
  3237. // draw the mark
  3238. if (t.showMark && t.mark) {
  3239. s = t.markSize;
  3240. m = t.mark;
  3241. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  3242. switch (m) {
  3243. case 'outside':
  3244. b = this._right;
  3245. e = this._right+s;
  3246. break;
  3247. case 'inside':
  3248. b = this._right-s;
  3249. e = this._right;
  3250. break;
  3251. case 'cross':
  3252. b = this._right-s;
  3253. e = this._right+s;
  3254. break;
  3255. default:
  3256. b = this._right;
  3257. e = this._right+s;
  3258. break;
  3259. }
  3260. // draw the shadow
  3261. if (this.shadow) {
  3262. this.renderer.shadowRenderer.draw(ctx, [[b, pos], [e, pos]], {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
  3263. }
  3264. drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
  3265. }
  3266. break;
  3267. default:
  3268. break;
  3269. }
  3270. }
  3271. }
  3272. t = null;
  3273. }
  3274. axis = null;
  3275. ticks = null;
  3276. }
  3277. // Now draw grid lines for additional y axes
  3278. ax = ['y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
  3279. for (var i=7; i>0; i--) {
  3280. var axis = axes[ax[i-1]];
  3281. var ticks = axis._ticks;
  3282. if (axis.show) {
  3283. var tn = ticks[axis.numberTicks-1];
  3284. var t0 = ticks[0];
  3285. var left = axis.getLeft();
  3286. var points = [[left, tn.getTop() + tn.getHeight()/2], [left, t0.getTop() + t0.getHeight()/2 + 1.0]];
  3287. // draw the shadow
  3288. if (this.shadow) {
  3289. this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', fill:false, closePath:false});
  3290. }
  3291. // draw the line
  3292. drawLine(points[0][0], points[0][1], points[1][0], points[1][1], {lineCap:'butt', strokeStyle:axis.borderColor, lineWidth:axis.borderWidth});
  3293. // draw the tick marks
  3294. for (var j=ticks.length; j>0; j--) {
  3295. var t = ticks[j-1];
  3296. s = t.markSize;
  3297. m = t.mark;
  3298. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  3299. if (t.showMark && t.mark) {
  3300. switch (m) {
  3301. case 'outside':
  3302. b = left;
  3303. e = left+s;
  3304. break;
  3305. case 'inside':
  3306. b = left-s;
  3307. e = left;
  3308. break;
  3309. case 'cross':
  3310. b = left-s;
  3311. e = left+s;
  3312. break;
  3313. default:
  3314. b = left;
  3315. e = left+s;
  3316. break;
  3317. }
  3318. points = [[b,pos], [e,pos]];
  3319. // draw the shadow
  3320. if (this.shadow) {
  3321. this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
  3322. }
  3323. // draw the line
  3324. drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
  3325. }
  3326. t = null;
  3327. }
  3328. t0 = null;
  3329. }
  3330. axis = null;
  3331. ticks = null;
  3332. }
  3333. ctx.restore();
  3334. }
  3335. function drawLine(bx, by, ex, ey, opts) {
  3336. ctx.save();
  3337. opts = opts || {};
  3338. if (opts.lineWidth == null || opts.lineWidth != 0){
  3339. $.extend(true, ctx, opts);
  3340. ctx.beginPath();
  3341. ctx.moveTo(bx, by);
  3342. ctx.lineTo(ex, ey);
  3343. ctx.stroke();
  3344. ctx.restore();
  3345. }
  3346. }
  3347. if (this.shadow) {
  3348. var points = [[this._left, this._bottom], [this._right, this._bottom], [this._right, this._top]];
  3349. this.renderer.shadowRenderer.draw(ctx, points);
  3350. }
  3351. // Now draw border around grid. Use axis border definitions. start at
  3352. // upper left and go clockwise.
  3353. if (this.borderWidth != 0 && this.drawBorder) {
  3354. drawLine (this._left, this._top, this._right, this._top, {lineCap:'round', strokeStyle:axes.x2axis.borderColor, lineWidth:axes.x2axis.borderWidth});
  3355. drawLine (this._right, this._top, this._right, this._bottom, {lineCap:'round', strokeStyle:axes.y2axis.borderColor, lineWidth:axes.y2axis.borderWidth});
  3356. drawLine (this._right, this._bottom, this._left, this._bottom, {lineCap:'round', strokeStyle:axes.xaxis.borderColor, lineWidth:axes.xaxis.borderWidth});
  3357. drawLine (this._left, this._bottom, this._left, this._top, {lineCap:'round', strokeStyle:axes.yaxis.borderColor, lineWidth:axes.yaxis.borderWidth});
  3358. }
  3359. // ctx.lineWidth = this.borderWidth;
  3360. // ctx.strokeStyle = this.borderColor;
  3361. // ctx.strokeRect(this._left, this._top, this._width, this._height);
  3362. ctx.restore();
  3363. ctx = null;
  3364. axes = null;
  3365. };
  3366. // Class: $.jqplot.DivTitleRenderer
  3367. // The default title renderer for jqPlot. This class has no options beyond the <Title> class.
  3368. $.jqplot.DivTitleRenderer = function() {
  3369. };
  3370. $.jqplot.DivTitleRenderer.prototype.init = function(options) {
  3371. $.extend(true, this, options);
  3372. };
  3373. $.jqplot.DivTitleRenderer.prototype.draw = function() {
  3374. var r = this.renderer;
  3375. if (!this.text) {
  3376. this.show = false;
  3377. this._elem = $('<div class="jqplot-title" style="height:0px;width:0px;"></div>');
  3378. }
  3379. else if (this.text) {
  3380. var color;
  3381. if (this.color) {
  3382. color = this.color;
  3383. }
  3384. else if (this.textColor) {
  3385. color = this.textColor;
  3386. }
  3387. // don't trust that a stylesheet is present, set the position.
  3388. var styletext = 'position:absolute;top:0px;left:0px;';
  3389. styletext += (this._plotWidth) ? 'width:'+this._plotWidth+'px;' : '';
  3390. styletext += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
  3391. styletext += (this.textAlign) ? 'text-align:'+this.textAlign+';' : 'text-align:center;';
  3392. styletext += (color) ? 'color:'+color+';' : '';
  3393. styletext += (this.paddingBottom) ? 'padding-bottom:'+this.paddingBottom+';' : '';
  3394. this._elem = $('<div class="jqplot-title" style="'+styletext+'">'+this.text+'</div>');
  3395. if (this.fontFamily) {
  3396. this._elem.css('font-family', this.fontFamily);
  3397. }
  3398. }
  3399. return this._elem;
  3400. };
  3401. $.jqplot.DivTitleRenderer.prototype.pack = function() {
  3402. // nothing to do here
  3403. };
  3404. // Class: $.jqplot.LineRenderer
  3405. // The default line renderer for jqPlot, this class has no options beyond the <Series> class.
  3406. // Draws series as a line.
  3407. $.jqplot.LineRenderer = function(){
  3408. this.shapeRenderer = new $.jqplot.ShapeRenderer();
  3409. this.shadowRenderer = new $.jqplot.ShadowRenderer();
  3410. };
  3411. // called with scope of series.
  3412. $.jqplot.LineRenderer.prototype.init = function(options, plot) {
  3413. options = options || {};
  3414. var lopts = {highlightMouseOver: options.highlightMouseOver, highlightMouseDown: options.highlightMouseDown, highlightColor: options.highlightColor};
  3415. delete (options.highlightMouseOver);
  3416. delete (options.highlightMouseDown);
  3417. delete (options.highlightColor);
  3418. $.extend(true, this.renderer, options);
  3419. // set the shape renderer options
  3420. var opts = {lineJoin:'round', lineCap:'round', fill:this.fill, isarc:false, strokeStyle:this.color, fillStyle:this.fillColor, lineWidth:this.lineWidth, closePath:this.fill};
  3421. this.renderer.shapeRenderer.init(opts);
  3422. // set the shadow renderer options
  3423. // scale the shadowOffset to the width of the line.
  3424. if (this.lineWidth > 2.5) {
  3425. var shadow_offset = this.shadowOffset* (1 + (Math.atan((this.lineWidth/2.5))/0.785398163 - 1)*0.6);
  3426. // var shadow_offset = this.shadowOffset;
  3427. }
  3428. // for skinny lines, don't make such a big shadow.
  3429. else {
  3430. var shadow_offset = this.shadowOffset*Math.atan((this.lineWidth/2.5))/0.785398163;
  3431. }
  3432. var sopts = {lineJoin:'round', lineCap:'round', fill:this.fill, isarc:false, angle:this.shadowAngle, offset:shadow_offset, alpha:this.shadowAlpha, depth:this.shadowDepth, lineWidth:this.lineWidth, closePath:this.fill};
  3433. this.renderer.shadowRenderer.init(sopts);
  3434. this._areaPoints = [];
  3435. this._boundingBox = [[],[]];
  3436. if (!this.isTrendline && this.fill) {
  3437. // prop: highlightMouseOver
  3438. // True to highlight area on a filled plot when moused over.
  3439. // This must be false to enable highlightMouseDown to highlight when clicking on an area on a filled plot.
  3440. this.highlightMouseOver = true;
  3441. // prop: highlightMouseDown
  3442. // True to highlight when a mouse button is pressed over an area on a filled plot.
  3443. // This will be disabled if highlightMouseOver is true.
  3444. this.highlightMouseDown = false;
  3445. // prop: highlightColor
  3446. // color to use when highlighting an area on a filled plot.
  3447. this.highlightColor = null;
  3448. // if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
  3449. if (lopts.highlightMouseDown && lopts.highlightMouseOver == null) {
  3450. lopts.highlightMouseOver = false;
  3451. }
  3452. $.extend(true, this, {highlightMouseOver: lopts.highlightMouseOver, highlightMouseDown: lopts.highlightMouseDown, highlightColor: lopts.highlightColor});
  3453. if (!this.highlightColor) {
  3454. this.highlightColor = $.jqplot.computeHighlightColors(this.fillColor);
  3455. }
  3456. // turn off (disable) the highlighter plugin
  3457. if (this.highlighter) {
  3458. this.highlighter.show = false;
  3459. }
  3460. }
  3461. if (!this.isTrendline && plot) {
  3462. plot.plugins.lineRenderer = {};
  3463. plot.postInitHooks.addOnce(postInit);
  3464. plot.postDrawHooks.addOnce(postPlotDraw);
  3465. plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
  3466. plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
  3467. plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
  3468. plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
  3469. plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
  3470. }
  3471. };
  3472. // Method: setGridData
  3473. // converts the user data values to grid coordinates and stores them
  3474. // in the gridData array.
  3475. // Called with scope of a series.
  3476. $.jqplot.LineRenderer.prototype.setGridData = function(plot) {
  3477. // recalculate the grid data
  3478. var xp = this._xaxis.series_u2p;
  3479. var yp = this._yaxis.series_u2p;
  3480. var data = this._plotData;
  3481. var pdata = this._prevPlotData;
  3482. this.gridData = [];
  3483. this._prevGridData = [];
  3484. for (var i=0; i<this.data.length; i++) {
  3485. // if not a line series or if no nulls in data, push the converted point onto the array.
  3486. if (data[i][0] != null && data[i][1] != null) {
  3487. this.gridData.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
  3488. }
  3489. // else if there is a null, preserve it.
  3490. else if (data[i][0] == null) {
  3491. this.gridData.push([null, yp.call(this._yaxis, data[i][1])]);
  3492. }
  3493. else if (data[i][1] == null) {
  3494. this.gridData.push([xp.call(this._xaxis, data[i][0]), null]);
  3495. }
  3496. // if not a line series or if no nulls in data, push the converted point onto the array.
  3497. if (pdata[i] != null && pdata[i][0] != null && pdata[i][1] != null) {
  3498. this._prevGridData.push([xp.call(this._xaxis, pdata[i][0]), yp.call(this._yaxis, pdata[i][1])]);
  3499. }
  3500. // else if there is a null, preserve it.
  3501. else if (pdata[i] != null && pdata[i][0] == null) {
  3502. this._prevGridData.push([null, yp.call(this._yaxis, pdata[i][1])]);
  3503. }
  3504. else if (pdata[i] != null && pdata[i][0] != null && pdata[i][1] == null) {
  3505. this._prevGridData.push([xp.call(this._xaxis, pdata[i][0]), null]);
  3506. }
  3507. }
  3508. };
  3509. // Method: makeGridData
  3510. // converts any arbitrary data values to grid coordinates and
  3511. // returns them. This method exists so that plugins can use a series'
  3512. // linerenderer to generate grid data points without overwriting the
  3513. // grid data associated with that series.
  3514. // Called with scope of a series.
  3515. $.jqplot.LineRenderer.prototype.makeGridData = function(data, plot) {
  3516. // recalculate the grid data
  3517. var xp = this._xaxis.series_u2p;
  3518. var yp = this._yaxis.series_u2p;
  3519. var gd = [];
  3520. var pgd = [];
  3521. for (var i=0; i<data.length; i++) {
  3522. // if not a line series or if no nulls in data, push the converted point onto the array.
  3523. if (data[i][0] != null && data[i][1] != null) {
  3524. gd.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
  3525. }
  3526. // else if there is a null, preserve it.
  3527. else if (data[i][0] == null) {
  3528. gd.push([null, yp.call(this._yaxis, data[i][1])]);
  3529. }
  3530. else if (data[i][1] == null) {
  3531. gd.push([xp.call(this._xaxis, data[i][0]), null]);
  3532. }
  3533. }
  3534. return gd;
  3535. };
  3536. // called within scope of series.
  3537. $.jqplot.LineRenderer.prototype.draw = function(ctx, gd, options) {
  3538. var i;
  3539. var opts = (options != undefined) ? options : {};
  3540. var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
  3541. var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
  3542. var fill = (opts.fill != undefined) ? opts.fill : this.fill;
  3543. var fillAndStroke = (opts.fillAndStroke != undefined) ? opts.fillAndStroke : this.fillAndStroke;
  3544. var xmin, ymin, xmax, ymax;
  3545. ctx.save();
  3546. if (gd.length) {
  3547. if (showLine) {
  3548. // if we fill, we'll have to add points to close the curve.
  3549. if (fill) {
  3550. if (this.fillToZero) {
  3551. // have to break line up into shapes at axis crossings
  3552. var negativeColors = new $.jqplot.ColorGenerator(this.negativeSeriesColors);
  3553. var negativeColor = negativeColors.get(this.index);
  3554. if (! this.useNegativeColors) {
  3555. negativeColor = opts.fillStyle;
  3556. }
  3557. var isnegative = false;
  3558. var posfs = opts.fillStyle;
  3559. // if stoking line as well as filling, get a copy of line data.
  3560. if (fillAndStroke) {
  3561. var fasgd = gd.slice(0);
  3562. }
  3563. // if not stacked, fill down to axis
  3564. if (this.index == 0 || !this._stack) {
  3565. var tempgd = [];
  3566. this._areaPoints = [];
  3567. var pyzero = this._yaxis.series_u2p(this.fillToValue);
  3568. var pxzero = this._xaxis.series_u2p(this.fillToValue);
  3569. if (this.fillAxis == 'y') {
  3570. tempgd.push([gd[0][0], pyzero]);
  3571. this._areaPoints.push([gd[0][0], pyzero]);
  3572. for (var i=0; i<gd.length-1; i++) {
  3573. tempgd.push(gd[i]);
  3574. this._areaPoints.push(gd[i]);
  3575. // do we have an axis crossing?
  3576. if (this._plotData[i][1] * this._plotData[i+1][1] < 0) {
  3577. if (this._plotData[i][1] < 0) {
  3578. isnegative = true;
  3579. opts.fillStyle = negativeColor;
  3580. }
  3581. else {
  3582. isnegative = false;
  3583. opts.fillStyle = posfs;
  3584. }
  3585. var xintercept = gd[i][0] + (gd[i+1][0] - gd[i][0]) * (pyzero-gd[i][1])/(gd[i+1][1] - gd[i][1]);
  3586. tempgd.push([xintercept, pyzero]);
  3587. this._areaPoints.push([xintercept, pyzero]);
  3588. // now draw this shape and shadow.
  3589. if (shadow) {
  3590. this.renderer.shadowRenderer.draw(ctx, tempgd, opts);
  3591. }
  3592. this.renderer.shapeRenderer.draw(ctx, tempgd, opts);
  3593. // now empty temp array and continue
  3594. tempgd = [[xintercept, pyzero]];
  3595. // this._areaPoints = [[xintercept, pyzero]];
  3596. }
  3597. }
  3598. if (this._plotData[gd.length-1][1] < 0) {
  3599. isnegative = true;
  3600. opts.fillStyle = negativeColor;
  3601. }
  3602. else {
  3603. isnegative = false;
  3604. opts.fillStyle = posfs;
  3605. }
  3606. tempgd.push(gd[gd.length-1]);
  3607. this._areaPoints.push(gd[gd.length-1]);
  3608. tempgd.push([gd[gd.length-1][0], pyzero]);
  3609. this._areaPoints.push([gd[gd.length-1][0], pyzero]);
  3610. }
  3611. // now draw this shape and shadow.
  3612. if (shadow) {
  3613. this.renderer.shadowRenderer.draw(ctx, tempgd, opts);
  3614. }
  3615. this.renderer.shapeRenderer.draw(ctx, tempgd, opts);
  3616. // var gridymin = this._yaxis.series_u2p(0);
  3617. // // IE doesn't return new length on unshift
  3618. // gd.unshift([gd[0][0], gridymin]);
  3619. // len = gd.length;
  3620. // gd.push([gd[len - 1][0], gridymin]);
  3621. }
  3622. // if stacked, fill to line below
  3623. else {
  3624. var prev = this._prevGridData;
  3625. for (var i=prev.length; i>0; i--) {
  3626. gd.push(prev[i-1]);
  3627. // this._areaPoints.push(prev[i-1]);
  3628. }
  3629. if (shadow) {
  3630. this.renderer.shadowRenderer.draw(ctx, gd, opts);
  3631. }
  3632. this._areaPoints = gd;
  3633. this.renderer.shapeRenderer.draw(ctx, gd, opts);
  3634. }
  3635. }
  3636. /////////////////////////
  3637. // Not filled to zero
  3638. ////////////////////////
  3639. else {
  3640. // if stoking line as well as filling, get a copy of line data.
  3641. if (fillAndStroke) {
  3642. var fasgd = gd.slice(0);
  3643. }
  3644. // if not stacked, fill down to axis
  3645. if (this.index == 0 || !this._stack) {
  3646. // var gridymin = this._yaxis.series_u2p(this._yaxis.min) - this.gridBorderWidth / 2;
  3647. var gridymin = ctx.canvas.height;
  3648. // IE doesn't return new length on unshift
  3649. gd.unshift([gd[0][0], gridymin]);
  3650. len = gd.length;
  3651. gd.push([gd[len - 1][0], gridymin]);
  3652. }
  3653. // if stacked, fill to line below
  3654. else {
  3655. var prev = this._prevGridData;
  3656. for (var i=prev.length; i>0; i--) {
  3657. gd.push(prev[i-1]);
  3658. }
  3659. }
  3660. this._areaPoints = gd;
  3661. if (shadow) {
  3662. this.renderer.shadowRenderer.draw(ctx, gd, opts);
  3663. }
  3664. this.renderer.shapeRenderer.draw(ctx, gd, opts);
  3665. }
  3666. if (fillAndStroke) {
  3667. var fasopts = $.extend(true, {}, opts, {fill:false, closePath:false});
  3668. this.renderer.shapeRenderer.draw(ctx, fasgd, fasopts);
  3669. //////////
  3670. // TODO: figure out some way to do shadows nicely
  3671. // if (shadow) {
  3672. // this.renderer.shadowRenderer.draw(ctx, fasgd, fasopts);
  3673. // }
  3674. // now draw the markers
  3675. if (this.markerRenderer.show) {
  3676. for (i=0; i<fasgd.length; i++) {
  3677. this.markerRenderer.draw(fasgd[i][0], fasgd[i][1], ctx, opts.markerOptions);
  3678. }
  3679. }
  3680. }
  3681. }
  3682. else {
  3683. if (shadow) {
  3684. this.renderer.shadowRenderer.draw(ctx, gd, opts);
  3685. }
  3686. this.renderer.shapeRenderer.draw(ctx, gd, opts);
  3687. }
  3688. }
  3689. // calculate the bounding box
  3690. var xmin = xmax = ymin = ymax = null;
  3691. for (i=0; i<this._areaPoints.length; i++) {
  3692. var p = this._areaPoints[i];
  3693. if (xmin > p[0] || xmin == null) {
  3694. xmin = p[0];
  3695. }
  3696. if (ymax < p[1] || ymax == null) {
  3697. ymax = p[1];
  3698. }
  3699. if (xmax < p[0] || xmax == null) {
  3700. xmax = p[0];
  3701. }
  3702. if (ymin > p[1] || ymin == null) {
  3703. ymin = p[1];
  3704. }
  3705. }
  3706. this._boundingBox = [[xmin, ymax], [xmax, ymin]];
  3707. // now draw the markers
  3708. if (this.markerRenderer.show && !fill) {
  3709. for (i=0; i<gd.length; i++) {
  3710. if (gd[i][0] != null && gd[i][1] != null) {
  3711. this.markerRenderer.draw(gd[i][0], gd[i][1], ctx, opts.markerOptions);
  3712. }
  3713. }
  3714. }
  3715. }
  3716. ctx.restore();
  3717. };
  3718. $.jqplot.LineRenderer.prototype.drawShadow = function(ctx, gd, options) {
  3719. // This is a no-op, shadows drawn with lines.
  3720. };
  3721. // called with scope of plot.
  3722. // make sure to not leave anything highlighted.
  3723. function postInit(target, data, options) {
  3724. for (i=0; i<this.series.length; i++) {
  3725. if (this.series[i].renderer.constructor == $.jqplot.LineRenderer) {
  3726. // don't allow mouseover and mousedown at same time.
  3727. if (this.series[i].highlightMouseOver) {
  3728. this.series[i].highlightMouseDown = false;
  3729. }
  3730. }
  3731. }
  3732. this.target.bind('mouseout', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
  3733. }
  3734. // called within context of plot
  3735. // create a canvas which we can draw on.
  3736. // insert it before the eventCanvas, so eventCanvas will still capture events.
  3737. function postPlotDraw() {
  3738. this.plugins.lineRenderer.highlightedSeriesIndex = null;
  3739. this.plugins.lineRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
  3740. this.eventCanvas._elem.before(this.plugins.lineRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-lineRenderer-highlight-canvas', this._plotDimensions));
  3741. this.plugins.lineRenderer.highlightCanvas.setContext();
  3742. }
  3743. function highlight (plot, sidx, pidx, points) {
  3744. var s = plot.series[sidx];
  3745. var canvas = plot.plugins.lineRenderer.highlightCanvas;
  3746. canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
  3747. s._highlightedPoint = pidx;
  3748. plot.plugins.lineRenderer.highlightedSeriesIndex = sidx;
  3749. var opts = {fillStyle: s.highlightColor};
  3750. s.renderer.shapeRenderer.draw(canvas._ctx, points, opts);
  3751. canvas = null;
  3752. }
  3753. function unhighlight (plot) {
  3754. var canvas = plot.plugins.lineRenderer.highlightCanvas;
  3755. canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
  3756. for (var i=0; i<plot.series.length; i++) {
  3757. plot.series[i]._highlightedPoint = null;
  3758. }
  3759. plot.plugins.lineRenderer.highlightedSeriesIndex = null;
  3760. plot.target.trigger('jqplotDataUnhighlight');
  3761. canvas = null;
  3762. }
  3763. function handleMove(ev, gridpos, datapos, neighbor, plot) {
  3764. if (neighbor) {
  3765. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  3766. var evt1 = jQuery.Event('jqplotDataMouseOver');
  3767. evt1.pageX = ev.pageX;
  3768. evt1.pageY = ev.pageY;
  3769. plot.target.trigger(evt1, ins);
  3770. if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.lineRenderer.highlightedSeriesIndex)) {
  3771. var evt = jQuery.Event('jqplotDataHighlight');
  3772. evt.pageX = ev.pageX;
  3773. evt.pageY = ev.pageY;
  3774. plot.target.trigger(evt, ins);
  3775. highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
  3776. }
  3777. }
  3778. else if (neighbor == null) {
  3779. unhighlight (plot);
  3780. }
  3781. }
  3782. function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
  3783. if (neighbor) {
  3784. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  3785. if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.lineRenderer.highlightedSeriesIndex)) {
  3786. var evt = jQuery.Event('jqplotDataHighlight');
  3787. evt.pageX = ev.pageX;
  3788. evt.pageY = ev.pageY;
  3789. plot.target.trigger(evt, ins);
  3790. highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
  3791. }
  3792. }
  3793. else if (neighbor == null) {
  3794. unhighlight (plot);
  3795. }
  3796. }
  3797. function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
  3798. var idx = plot.plugins.lineRenderer.highlightedSeriesIndex;
  3799. if (idx != null && plot.series[idx].highlightMouseDown) {
  3800. unhighlight(plot);
  3801. }
  3802. }
  3803. function handleClick(ev, gridpos, datapos, neighbor, plot) {
  3804. if (neighbor) {
  3805. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  3806. var evt = jQuery.Event('jqplotDataClick');
  3807. evt.pageX = ev.pageX;
  3808. evt.pageY = ev.pageY;
  3809. plot.target.trigger(evt, ins);
  3810. }
  3811. }
  3812. function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
  3813. if (neighbor) {
  3814. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  3815. var idx = plot.plugins.lineRenderer.highlightedSeriesIndex;
  3816. if (idx != null && plot.series[idx].highlightMouseDown) {
  3817. unhighlight(plot);
  3818. }
  3819. var evt = jQuery.Event('jqplotDataRightClick');
  3820. evt.pageX = ev.pageX;
  3821. evt.pageY = ev.pageY;
  3822. plot.target.trigger(evt, ins);
  3823. }
  3824. }
  3825. // class: $.jqplot.LinearAxisRenderer
  3826. // The default jqPlot axis renderer, creating a numeric axis.
  3827. // The renderer has no additional options beyond the <Axis> object.
  3828. $.jqplot.LinearAxisRenderer = function() {
  3829. };
  3830. // called with scope of axis object.
  3831. $.jqplot.LinearAxisRenderer.prototype.init = function(options){
  3832. // prop: breakPoints
  3833. // EXPERIMENTAL!! Use at your own risk!
  3834. // Works only with linear axes and the default tick renderer.
  3835. // Array of [start, stop] points to create a broken axis.
  3836. // Broken axes have a "jump" in them, which is an immediate
  3837. // transition from a smaller value to a larger value.
  3838. // Currently, axis ticks MUST be manually assigned if using breakPoints
  3839. // by using the axis ticks array option.
  3840. this.breakPoints = null;
  3841. // prop: breakTickLabel
  3842. // Label to use at the axis break if breakPoints are specified.
  3843. this.breakTickLabel = "&asymp;";
  3844. $.extend(true, this, options);
  3845. if (this.breakPoints) {
  3846. if (!$.isArray(this.breakPoints)) {
  3847. this.breakPoints = null;
  3848. }
  3849. else if (this.breakPoints.length < 2 || this.breakPoints[1] <= this.breakPoints[0]) {
  3850. this.breakPoints = null;
  3851. }
  3852. }
  3853. this.resetDataBounds();
  3854. };
  3855. // called with scope of axis
  3856. $.jqplot.LinearAxisRenderer.prototype.draw = function(ctx) {
  3857. if (this.show) {
  3858. // populate the axis label and value properties.
  3859. // createTicks is a method on the renderer, but
  3860. // call it within the scope of the axis.
  3861. this.renderer.createTicks.call(this);
  3862. // fill a div with axes labels in the right direction.
  3863. // Need to pregenerate each axis to get it's bounds and
  3864. // position it and the labels correctly on the plot.
  3865. var dim=0;
  3866. var temp;
  3867. // Added for theming.
  3868. if (this._elem) {
  3869. this._elem.empty();
  3870. }
  3871. this._elem = $('<div class="jqplot-axis jqplot-'+this.name+'" style="position:absolute;"></div>');
  3872. if (this.name == 'xaxis' || this.name == 'x2axis') {
  3873. this._elem.width(this._plotDimensions.width);
  3874. }
  3875. else {
  3876. this._elem.height(this._plotDimensions.height);
  3877. }
  3878. // create a _label object.
  3879. this.labelOptions.axis = this.name;
  3880. this._label = new this.labelRenderer(this.labelOptions);
  3881. var elem;
  3882. if (this._label.show) {
  3883. elem = this._label.draw(ctx);
  3884. elem.appendTo(this._elem);
  3885. }
  3886. var t = this._ticks;
  3887. for (var i=0; i<t.length; i++) {
  3888. var tick = t[i];
  3889. if (tick.show && tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
  3890. elem = tick.draw(ctx);
  3891. elem.appendTo(this._elem);
  3892. }
  3893. }
  3894. elem = null;
  3895. }
  3896. return this._elem;
  3897. };
  3898. // called with scope of an axis
  3899. $.jqplot.LinearAxisRenderer.prototype.reset = function() {
  3900. this.min = this._min;
  3901. this.max = this._max;
  3902. this.tickInterval = this._tickInterval;
  3903. this.numberTicks = this._numberTicks;
  3904. // this._ticks = this.__ticks;
  3905. };
  3906. // called with scope of axis
  3907. $.jqplot.LinearAxisRenderer.prototype.set = function() {
  3908. var dim = 0;
  3909. var temp;
  3910. var w = 0;
  3911. var h = 0;
  3912. var lshow = (this._label == null) ? false : this._label.show;
  3913. if (this.show) {
  3914. var t = this._ticks;
  3915. for (var i=0; i<t.length; i++) {
  3916. var tick = t[i];
  3917. if (!tick._breakTick && tick.show && tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
  3918. if (this.name == 'xaxis' || this.name == 'x2axis') {
  3919. temp = tick._elem.outerHeight(true);
  3920. }
  3921. else {
  3922. temp = tick._elem.outerWidth(true);
  3923. }
  3924. if (temp > dim) {
  3925. dim = temp;
  3926. }
  3927. }
  3928. }
  3929. if (lshow) {
  3930. w = this._label._elem.outerWidth(true);
  3931. h = this._label._elem.outerHeight(true);
  3932. }
  3933. if (this.name == 'xaxis') {
  3934. dim = dim + h;
  3935. this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
  3936. }
  3937. else if (this.name == 'x2axis') {
  3938. dim = dim + h;
  3939. this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
  3940. }
  3941. else if (this.name == 'yaxis') {
  3942. dim = dim + w;
  3943. this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
  3944. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  3945. this._label._elem.css('width', w+'px');
  3946. }
  3947. }
  3948. else {
  3949. dim = dim + w;
  3950. this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
  3951. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  3952. this._label._elem.css('width', w+'px');
  3953. }
  3954. }
  3955. }
  3956. };
  3957. // called with scope of axis
  3958. $.jqplot.LinearAxisRenderer.prototype.createTicks = function() {
  3959. // we're are operating on an axis here
  3960. var ticks = this._ticks;
  3961. var userTicks = this.ticks;
  3962. var name = this.name;
  3963. // databounds were set on axis initialization.
  3964. var db = this._dataBounds;
  3965. var dim, interval;
  3966. var min, max;
  3967. var pos1, pos2;
  3968. var tt, i;
  3969. // get a copy of user's settings for min/max.
  3970. var userMin = this.min;
  3971. var userMax = this.max;
  3972. var userNT = this.numberTicks;
  3973. var userTI = this.tickInterval;
  3974. // if we already have ticks, use them.
  3975. // ticks must be in order of increasing value.
  3976. if (userTicks.length) {
  3977. // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
  3978. for (i=0; i<userTicks.length; i++){
  3979. var ut = userTicks[i];
  3980. var t = new this.tickRenderer(this.tickOptions);
  3981. if (ut.constructor == Array) {
  3982. t.value = ut[0];
  3983. if (this.breakPoints) {
  3984. if (ut[0] == this.breakPoints[0]) {
  3985. t.label = this.breakTickLabel;
  3986. t._breakTick = true;
  3987. t.showGridline = false;
  3988. t.showMark = false;
  3989. }
  3990. else if (ut[0] > this.breakPoints[0] && ut[0] <= this.breakPoints[1]) {
  3991. t.show = false;
  3992. t.showGridline = false;
  3993. t.label = ut[1];
  3994. }
  3995. else {
  3996. t.label = ut[1];
  3997. }
  3998. }
  3999. else {
  4000. t.label = ut[1];
  4001. }
  4002. t.setTick(ut[0], this.name);
  4003. this._ticks.push(t);
  4004. }
  4005. else {
  4006. t.value = ut;
  4007. if (this.breakPoints) {
  4008. if (ut == this.breakPoints[0]) {
  4009. t.label = this.breakTickLabel;
  4010. t._breakTick = true;
  4011. t.showGridline = false;
  4012. t.showMark = false;
  4013. }
  4014. else if (ut > this.breakPoints[0] && ut <= this.breakPoints[1]) {
  4015. t.show = false;
  4016. t.showGridline = false;
  4017. }
  4018. }
  4019. t.setTick(ut, this.name);
  4020. this._ticks.push(t);
  4021. }
  4022. }
  4023. this.numberTicks = userTicks.length;
  4024. this.min = this._ticks[0].value;
  4025. this.max = this._ticks[this.numberTicks-1].value;
  4026. this.tickInterval = (this.max - this.min) / (this.numberTicks - 1);
  4027. }
  4028. // we don't have any ticks yet, let's make some!
  4029. else {
  4030. if (name == 'xaxis' || name == 'x2axis') {
  4031. dim = this._plotDimensions.width;
  4032. }
  4033. else {
  4034. dim = this._plotDimensions.height;
  4035. }
  4036. // if min, max and number of ticks specified, user can't specify interval.
  4037. if (!this.autoscale && this.min != null && this.max != null && this.numberTicks != null) {
  4038. this.tickInterval = null;
  4039. }
  4040. // if max, min, and interval specified and interval won't fit, ignore interval.
  4041. // if (this.min != null && this.max != null && this.tickInterval != null) {
  4042. // if (parseInt((this.max-this.min)/this.tickInterval, 10) != (this.max-this.min)/this.tickInterval) {
  4043. // this.tickInterval = null;
  4044. // }
  4045. // }
  4046. min = ((this.min != null) ? this.min : db.min);
  4047. max = ((this.max != null) ? this.max : db.max);
  4048. // if min and max are same, space them out a bit
  4049. if (min == max) {
  4050. var adj = 0.05;
  4051. if (min > 0) {
  4052. adj = Math.max(Math.log(min)/Math.LN10, 0.05);
  4053. }
  4054. min -= adj;
  4055. max += adj;
  4056. }
  4057. var range = max - min;
  4058. var rmin, rmax;
  4059. var temp;
  4060. // autoscale. Can't autoscale if min or max is supplied.
  4061. // Will use numberTicks and tickInterval if supplied. Ticks
  4062. // across multiple axes may not line up depending on how
  4063. // bars are to be plotted.
  4064. if (this.autoscale && this.min == null && this.max == null) {
  4065. var rrange, ti, margin;
  4066. var forceMinZero = false;
  4067. var forceZeroLine = false;
  4068. var intervals = {min:null, max:null, average:null, stddev:null};
  4069. // if any series are bars, or if any are fill to zero, and if this
  4070. // is the axis to fill toward, check to see if we can start axis at zero.
  4071. for (var i=0; i<this._series.length; i++) {
  4072. var s = this._series[i];
  4073. var faname = (s.fillAxis == 'x') ? s._xaxis.name : s._yaxis.name;
  4074. // check to see if this is the fill axis
  4075. if (this.name == faname) {
  4076. var vals = s._plotValues[s.fillAxis];
  4077. var vmin = vals[0];
  4078. var vmax = vals[0];
  4079. for (var j=1; j<vals.length; j++) {
  4080. if (vals[j] < vmin) {
  4081. vmin = vals[j];
  4082. }
  4083. else if (vals[j] > vmax) {
  4084. vmax = vals[j];
  4085. }
  4086. }
  4087. var dp = (vmax - vmin) / vmax;
  4088. // is this sries a bar?
  4089. if (s.renderer.constructor == $.jqplot.BarRenderer) {
  4090. // if no negative values and could also check range.
  4091. if (vmin >= 0 && (s.fillToZero || dp > 0.1)) {
  4092. forceMinZero = true;
  4093. }
  4094. else {
  4095. forceMinZero = false;
  4096. if (s.fill && s.fillToZero && vmin < 0 && vmax > 0) {
  4097. forceZeroLine = true;
  4098. }
  4099. else {
  4100. forceZeroLine = false;
  4101. }
  4102. }
  4103. }
  4104. // if not a bar and filling, use appropriate method.
  4105. else if (s.fill) {
  4106. if (vmin >= 0 && (s.fillToZero || dp > 0.1)) {
  4107. forceMinZero = true;
  4108. }
  4109. else if (vmin < 0 && vmax > 0 && s.fillToZero) {
  4110. forceMinZero = false;
  4111. forceZeroLine = true;
  4112. }
  4113. else {
  4114. forceMinZero = false;
  4115. forceZeroLine = false;
  4116. }
  4117. }
  4118. // if not a bar and not filling, only change existing state
  4119. // if it doesn't make sense
  4120. else if (vmin < 0) {
  4121. forceMinZero = false;
  4122. }
  4123. }
  4124. }
  4125. // check if we need make axis min at 0.
  4126. if (forceMinZero) {
  4127. // compute number of ticks
  4128. this.numberTicks = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
  4129. this.min = 0;
  4130. userMin = 0;
  4131. // what order is this range?
  4132. // what tick interval does that give us?
  4133. ti = max/(this.numberTicks-1);
  4134. temp = Math.pow(10, Math.abs(Math.floor(Math.log(ti)/Math.LN10)));
  4135. if (ti/temp == parseInt(ti/temp, 10)) {
  4136. ti += temp;
  4137. }
  4138. this.tickInterval = Math.ceil(ti/temp) * temp;
  4139. this.max = this.tickInterval * (this.numberTicks - 1);
  4140. }
  4141. // check if we need to make sure there is a tick at 0.
  4142. else if (forceZeroLine) {
  4143. // compute number of ticks
  4144. this.numberTicks = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
  4145. var ntmin = Math.ceil(Math.abs(min)/range*(this.numberTicks-1));
  4146. var ntmax = this.numberTicks - 1 - ntmin;
  4147. ti = Math.max(Math.abs(min/ntmin), Math.abs(max/ntmax));
  4148. temp = Math.pow(10, Math.abs(Math.floor(Math.log(ti)/Math.LN10)));
  4149. this.tickInterval = Math.ceil(ti/temp) * temp;
  4150. this.max = this.tickInterval * ntmax;
  4151. this.min = -this.tickInterval * ntmin;
  4152. }
  4153. // if nothing else, do autoscaling which will try to line up ticks across axes.
  4154. else {
  4155. if (this.numberTicks == null){
  4156. if (this.tickInterval) {
  4157. this.numberTicks = 3 + Math.ceil(range / this.tickInterval);
  4158. }
  4159. else {
  4160. this.numberTicks = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
  4161. }
  4162. }
  4163. if (this.tickInterval == null) {
  4164. // get a tick interval
  4165. ti = range/(this.numberTicks - 1);
  4166. if (ti < 1) {
  4167. temp = Math.pow(10, Math.abs(Math.floor(Math.log(ti)/Math.LN10)));
  4168. }
  4169. else {
  4170. temp = 1;
  4171. }
  4172. this.tickInterval = Math.ceil(ti*temp*this.pad)/temp;
  4173. }
  4174. else {
  4175. temp = 1 / this.tickInterval;
  4176. }
  4177. // try to compute a nicer, more even tick interval
  4178. // temp = Math.pow(10, Math.floor(Math.log(ti)/Math.LN10));
  4179. // this.tickInterval = Math.ceil(ti/temp) * temp;
  4180. rrange = this.tickInterval * (this.numberTicks - 1);
  4181. margin = (rrange - range)/2;
  4182. if (this.min == null) {
  4183. this.min = Math.floor(temp*(min-margin))/temp;
  4184. }
  4185. if (this.max == null) {
  4186. this.max = this.min + rrange;
  4187. }
  4188. }
  4189. }
  4190. // Use the default algorithm which pads each axis to make the chart
  4191. // centered nicely on the grid.
  4192. else {
  4193. rmin = (this.min != null) ? this.min : min - range*(this.padMin - 1);
  4194. rmax = (this.max != null) ? this.max : max + range*(this.padMax - 1);
  4195. this.min = rmin;
  4196. this.max = rmax;
  4197. range = this.max - this.min;
  4198. if (this.numberTicks == null){
  4199. // if tickInterval is specified by user, we will ignore computed maximum.
  4200. // max will be equal or greater to fit even # of ticks.
  4201. if (this.tickInterval != null) {
  4202. this.numberTicks = Math.ceil((this.max - this.min)/this.tickInterval)+1;
  4203. this.max = this.min + this.tickInterval*(this.numberTicks-1);
  4204. }
  4205. else if (dim > 100) {
  4206. this.numberTicks = parseInt(3+(dim-100)/75, 10);
  4207. }
  4208. else {
  4209. this.numberTicks = 2;
  4210. }
  4211. }
  4212. if (this.tickInterval == null) {
  4213. this.tickInterval = range / (this.numberTicks-1);
  4214. }
  4215. }
  4216. if (this.renderer.constructor == $.jqplot.LinearAxisRenderer) {
  4217. // fix for misleading tick display with small range and low precision.
  4218. range = this.max - this.min;
  4219. // figure out precision
  4220. var temptick = new this.tickRenderer(this.tickOptions);
  4221. // use the tick formatString or, the default.
  4222. var fs = temptick.formatString || $.jqplot.config.defaultTickFormatString;
  4223. var fs = fs.match($.jqplot.sprintf.regex)[0];
  4224. var precision = 0;
  4225. if (fs) {
  4226. if (fs.search(/[fFeEgGpP]/) > -1) {
  4227. var m = fs.match(/\%\.(\d{0,})?[eEfFgGpP]/);
  4228. if (m) {
  4229. precision = parseInt(m[1], 10);
  4230. }
  4231. else {
  4232. precision = 6;
  4233. }
  4234. }
  4235. else if (fs.search(/[di]/) > -1) {
  4236. precision = 0;
  4237. }
  4238. // fact will be <= 1;
  4239. var fact = Math.pow(10, -precision);
  4240. if (this.tickInterval < fact) {
  4241. // need to correct underrange
  4242. if (userNT == null && userTI == null) {
  4243. this.tickInterval = fact;
  4244. if (userMax == null && userMin == null) {
  4245. // this.min = Math.floor((this._dataBounds.min - this.tickInterval)/fact) * fact;
  4246. this.min = Math.floor(this._dataBounds.min/fact) * fact;
  4247. if (this.min == this._dataBounds.min) {
  4248. this.min = this._dataBounds.min - this.tickInterval;
  4249. }
  4250. // this.max = Math.ceil((this._dataBounds.max + this.tickInterval)/fact) * fact;
  4251. this.max = Math.ceil(this._dataBounds.max/fact) * fact;
  4252. if (this.max == this._dataBounds.max) {
  4253. this.max = this._dataBounds.max + this.tickInterval;
  4254. }
  4255. var n = (this.max - this.min)/this.tickInterval;
  4256. n = n.toFixed(11);
  4257. n = Math.ceil(n);
  4258. this.numberTicks = n + 1;
  4259. }
  4260. else if (userMax == null) {
  4261. // add one tick for top of range.
  4262. var n = (this._dataBounds.max - this.min) / this.tickInterval;
  4263. n = n.toFixed(11);
  4264. this.numberTicks = Math.ceil(n) + 2;
  4265. this.max = this.min + this.tickInterval * (this.numberTicks-1);
  4266. }
  4267. else if (userMin == null) {
  4268. // add one tick for bottom of range.
  4269. var n = (this.max - this._dataBounds.min) / this.tickInterval;
  4270. n = n.toFixed(11);
  4271. this.numberTicks = Math.ceil(n) + 2;
  4272. this.min = this.max - this.tickInterval * (this.numberTicks-1);
  4273. }
  4274. else {
  4275. // calculate a number of ticks so max is within axis scale
  4276. this.numberTicks = Math.ceil((userMax - userMin)/this.tickInterval) + 1;
  4277. // if user's min and max don't fit evenly in ticks, adjust.
  4278. // This takes care of cases such as user min set to 0, max set to 3.5 but tick
  4279. // format string set to %d (integer ticks)
  4280. this.min = Math.floor(userMin*Math.pow(10, precision))/Math.pow(10, precision);
  4281. this.max = Math.ceil(userMax*Math.pow(10, precision))/Math.pow(10, precision);
  4282. // this.max = this.min + this.tickInterval*(this.numberTicks-1);
  4283. this.numberTicks = Math.ceil((this.max - this.min)/this.tickInterval) + 1;
  4284. }
  4285. }
  4286. }
  4287. }
  4288. }
  4289. for (var i=0; i<this.numberTicks; i++){
  4290. tt = this.min + i * this.tickInterval;
  4291. var t = new this.tickRenderer(this.tickOptions);
  4292. // var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
  4293. t.setTick(tt, this.name);
  4294. this._ticks.push(t);
  4295. }
  4296. }
  4297. };
  4298. // Used to reset just the values of the ticks and then repack, which will
  4299. // recalculate the positioning functions. It is assuemd that the
  4300. // number of ticks is the same and the values of the new array are at the
  4301. // proper interval.
  4302. // This method needs to be called with the scope of an axis object, like:
  4303. //
  4304. // > plot.axes.yaxis.renderer.resetTickValues.call(plot.axes.yaxis, yarr);
  4305. //
  4306. $.jqplot.LinearAxisRenderer.prototype.resetTickValues = function(opts) {
  4307. if ($.isArray(opts) && opts.length == this._ticks.length) {
  4308. var t;
  4309. for (var i=0; i<opts.length; i++) {
  4310. t = this._ticks[i];
  4311. t.value = opts[i];
  4312. t.label = t.formatter(t.formatString, opts[i]);
  4313. // add prefix if needed
  4314. if (t.prefix && !t.formatString) {
  4315. t.label = t.prefix + t.label;
  4316. }
  4317. t._elem.html(t.label);
  4318. }
  4319. this.min = $.jqplot.arrayMin(opts);
  4320. this.max = $.jqplot.arrayMax(opts);
  4321. this.pack();
  4322. }
  4323. // Not implemented yet.
  4324. // else if ($.isPlainObject(opts)) {
  4325. //
  4326. // }
  4327. };
  4328. // called with scope of axis
  4329. $.jqplot.LinearAxisRenderer.prototype.pack = function(pos, offsets) {
  4330. // Add defaults for repacking from resetTickValues function.
  4331. pos = pos || {};
  4332. offsets = offsets || this._offsets;
  4333. var ticks = this._ticks;
  4334. var max = this.max;
  4335. var min = this.min;
  4336. var offmax = offsets.max;
  4337. var offmin = offsets.min;
  4338. var lshow = (this._label == null) ? false : this._label.show;
  4339. for (var p in pos) {
  4340. this._elem.css(p, pos[p]);
  4341. }
  4342. this._offsets = offsets;
  4343. // pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
  4344. var pixellength = offmax - offmin;
  4345. var unitlength = max - min;
  4346. // point to unit and unit to point conversions references to Plot DOM element top left corner.
  4347. if (this.breakPoints) {
  4348. unitlength = unitlength - this.breakPoints[1] + this.breakPoints[0];
  4349. this.p2u = function(p){
  4350. return (p - offmin) * unitlength / pixellength + min;
  4351. };
  4352. this.u2p = function(u){
  4353. if (u > this.breakPoints[0] && u < this.breakPoints[1]){
  4354. u = this.breakPoints[0];
  4355. }
  4356. if (u <= this.breakPoints[0]) {
  4357. return (u - min) * pixellength / unitlength + offmin;
  4358. }
  4359. else {
  4360. return (u - this.breakPoints[1] + this.breakPoints[0] - min) * pixellength / unitlength + offmin;
  4361. }
  4362. };
  4363. if (this.name.charAt(0) == 'x'){
  4364. this.series_u2p = function(u){
  4365. if (u > this.breakPoints[0] && u < this.breakPoints[1]){
  4366. u = this.breakPoints[0];
  4367. }
  4368. if (u <= this.breakPoints[0]) {
  4369. return (u - min) * pixellength / unitlength;
  4370. }
  4371. else {
  4372. return (u - this.breakPoints[1] + this.breakPoints[0] - min) * pixellength / unitlength;
  4373. }
  4374. };
  4375. this.series_p2u = function(p){
  4376. return p * unitlength / pixellength + min;
  4377. };
  4378. }
  4379. else {
  4380. this.series_u2p = function(u){
  4381. if (u > this.breakPoints[0] && u < this.breakPoints[1]){
  4382. u = this.breakPoints[0];
  4383. }
  4384. if (u >= this.breakPoints[1]) {
  4385. return (u - max) * pixellength / unitlength;
  4386. }
  4387. else {
  4388. return (u + this.breakPoints[1] - this.breakPoints[0] - max) * pixellength / unitlength;
  4389. }
  4390. };
  4391. this.series_p2u = function(p){
  4392. return p * unitlength / pixellength + max;
  4393. };
  4394. }
  4395. }
  4396. else {
  4397. this.p2u = function(p){
  4398. return (p - offmin) * unitlength / pixellength + min;
  4399. };
  4400. this.u2p = function(u){
  4401. return (u - min) * pixellength / unitlength + offmin;
  4402. };
  4403. if (this.name == 'xaxis' || this.name == 'x2axis'){
  4404. this.series_u2p = function(u){
  4405. return (u - min) * pixellength / unitlength;
  4406. };
  4407. this.series_p2u = function(p){
  4408. return p * unitlength / pixellength + min;
  4409. };
  4410. }
  4411. else {
  4412. this.series_u2p = function(u){
  4413. return (u - max) * pixellength / unitlength;
  4414. };
  4415. this.series_p2u = function(p){
  4416. return p * unitlength / pixellength + max;
  4417. };
  4418. }
  4419. }
  4420. if (this.show) {
  4421. if (this.name == 'xaxis' || this.name == 'x2axis') {
  4422. for (i=0; i<ticks.length; i++) {
  4423. var t = ticks[i];
  4424. if (t.show && t.showLabel) {
  4425. var shim;
  4426. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  4427. // will need to adjust auto positioning based on which axis this is.
  4428. var temp = (this.name == 'xaxis') ? 1 : -1;
  4429. switch (t.labelPosition) {
  4430. case 'auto':
  4431. // position at end
  4432. if (temp * t.angle < 0) {
  4433. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  4434. }
  4435. // position at start
  4436. else {
  4437. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  4438. }
  4439. break;
  4440. case 'end':
  4441. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  4442. break;
  4443. case 'start':
  4444. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  4445. break;
  4446. case 'middle':
  4447. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  4448. break;
  4449. default:
  4450. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  4451. break;
  4452. }
  4453. }
  4454. else {
  4455. shim = -t.getWidth()/2;
  4456. }
  4457. var val = this.u2p(t.value) + shim + 'px';
  4458. t._elem.css('left', val);
  4459. t.pack();
  4460. }
  4461. }
  4462. if (lshow) {
  4463. var w = this._label._elem.outerWidth(true);
  4464. this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
  4465. if (this.name == 'xaxis') {
  4466. this._label._elem.css('bottom', '0px');
  4467. }
  4468. else {
  4469. this._label._elem.css('top', '0px');
  4470. }
  4471. this._label.pack();
  4472. }
  4473. }
  4474. else {
  4475. for (i=0; i<ticks.length; i++) {
  4476. var t = ticks[i];
  4477. if (t.show && t.showLabel) {
  4478. var shim;
  4479. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  4480. // will need to adjust auto positioning based on which axis this is.
  4481. var temp = (this.name == 'yaxis') ? 1 : -1;
  4482. switch (t.labelPosition) {
  4483. case 'auto':
  4484. // position at end
  4485. case 'end':
  4486. if (temp * t.angle < 0) {
  4487. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  4488. }
  4489. else {
  4490. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  4491. }
  4492. break;
  4493. case 'start':
  4494. if (t.angle > 0) {
  4495. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  4496. }
  4497. else {
  4498. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  4499. }
  4500. break;
  4501. case 'middle':
  4502. // if (t.angle > 0) {
  4503. // shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  4504. // }
  4505. // else {
  4506. // shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  4507. // }
  4508. shim = -t.getHeight()/2;
  4509. break;
  4510. default:
  4511. shim = -t.getHeight()/2;
  4512. break;
  4513. }
  4514. }
  4515. else {
  4516. shim = -t.getHeight()/2;
  4517. }
  4518. var val = this.u2p(t.value) + shim + 'px';
  4519. t._elem.css('top', val);
  4520. t.pack();
  4521. }
  4522. }
  4523. if (lshow) {
  4524. var h = this._label._elem.outerHeight(true);
  4525. this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
  4526. if (this.name == 'yaxis') {
  4527. this._label._elem.css('left', '0px');
  4528. }
  4529. else {
  4530. this._label._elem.css('right', '0px');
  4531. }
  4532. this._label.pack();
  4533. }
  4534. }
  4535. }
  4536. };
  4537. // class: $.jqplot.MarkerRenderer
  4538. // The default jqPlot marker renderer, rendering the points on the line.
  4539. $.jqplot.MarkerRenderer = function(options){
  4540. // Group: Properties
  4541. // prop: show
  4542. // wether or not to show the marker.
  4543. this.show = true;
  4544. // prop: style
  4545. // One of diamond, circle, square, x, plus, dash, filledDiamond, filledCircle, filledSquare
  4546. this.style = 'filledCircle';
  4547. // prop: lineWidth
  4548. // size of the line for non-filled markers.
  4549. this.lineWidth = 2;
  4550. // prop: size
  4551. // Size of the marker (diameter or circle, length of edge of square, etc.)
  4552. this.size = 9.0;
  4553. // prop: color
  4554. // color of marker. Will be set to color of series by default on init.
  4555. this.color = '#666666';
  4556. // prop: shadow
  4557. // wether or not to draw a shadow on the line
  4558. this.shadow = true;
  4559. // prop: shadowAngle
  4560. // Shadow angle in degrees
  4561. this.shadowAngle = 45;
  4562. // prop: shadowOffset
  4563. // Shadow offset from line in pixels
  4564. this.shadowOffset = 1;
  4565. // prop: shadowDepth
  4566. // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
  4567. this.shadowDepth = 3;
  4568. // prop: shadowAlpha
  4569. // Alpha channel transparency of shadow. 0 = transparent.
  4570. this.shadowAlpha = '0.07';
  4571. // prop: shadowRenderer
  4572. // Renderer that will draws the shadows on the marker.
  4573. this.shadowRenderer = new $.jqplot.ShadowRenderer();
  4574. // prop: shapeRenderer
  4575. // Renderer that will draw the marker.
  4576. this.shapeRenderer = new $.jqplot.ShapeRenderer();
  4577. $.extend(true, this, options);
  4578. };
  4579. $.jqplot.MarkerRenderer.prototype.init = function(options) {
  4580. $.extend(true, this, options);
  4581. var sdopt = {angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, lineWidth:this.lineWidth, depth:this.shadowDepth, closePath:true};
  4582. if (this.style.indexOf('filled') != -1) {
  4583. sdopt.fill = true;
  4584. }
  4585. if (this.style.indexOf('ircle') != -1) {
  4586. sdopt.isarc = true;
  4587. sdopt.closePath = false;
  4588. }
  4589. this.shadowRenderer.init(sdopt);
  4590. var shopt = {fill:false, isarc:false, strokeStyle:this.color, fillStyle:this.color, lineWidth:this.lineWidth, closePath:true};
  4591. if (this.style.indexOf('filled') != -1) {
  4592. shopt.fill = true;
  4593. }
  4594. if (this.style.indexOf('ircle') != -1) {
  4595. shopt.isarc = true;
  4596. shopt.closePath = false;
  4597. }
  4598. this.shapeRenderer.init(shopt);
  4599. };
  4600. $.jqplot.MarkerRenderer.prototype.drawDiamond = function(x, y, ctx, fill, options) {
  4601. var stretch = 1.2;
  4602. var dx = this.size/2/stretch;
  4603. var dy = this.size/2*stretch;
  4604. var points = [[x-dx, y], [x, y+dy], [x+dx, y], [x, y-dy]];
  4605. if (this.shadow) {
  4606. this.shadowRenderer.draw(ctx, points);
  4607. }
  4608. this.shapeRenderer.draw(ctx, points, options);
  4609. };
  4610. $.jqplot.MarkerRenderer.prototype.drawPlus = function(x, y, ctx, fill, options) {
  4611. var stretch = 1.0;
  4612. var dx = this.size/2*stretch;
  4613. var dy = this.size/2*stretch;
  4614. var points1 = [[x, y-dy], [x, y+dy]];
  4615. var points2 = [[x+dx, y], [x-dx, y]];
  4616. var opts = $.extend(true, {}, this.options, {closePath:false});
  4617. if (this.shadow) {
  4618. this.shadowRenderer.draw(ctx, points1, {closePath:false});
  4619. this.shadowRenderer.draw(ctx, points2, {closePath:false});
  4620. }
  4621. this.shapeRenderer.draw(ctx, points1, opts);
  4622. this.shapeRenderer.draw(ctx, points2, opts);
  4623. };
  4624. $.jqplot.MarkerRenderer.prototype.drawX = function(x, y, ctx, fill, options) {
  4625. var stretch = 1.0;
  4626. var dx = this.size/2*stretch;
  4627. var dy = this.size/2*stretch;
  4628. var opts = $.extend(true, {}, this.options, {closePath:false});
  4629. var points1 = [[x-dx, y-dy], [x+dx, y+dy]];
  4630. var points2 = [[x-dx, y+dy], [x+dx, y-dy]];
  4631. if (this.shadow) {
  4632. this.shadowRenderer.draw(ctx, points1, {closePath:false});
  4633. this.shadowRenderer.draw(ctx, points2, {closePath:false});
  4634. }
  4635. this.shapeRenderer.draw(ctx, points1, opts);
  4636. this.shapeRenderer.draw(ctx, points2, opts);
  4637. };
  4638. $.jqplot.MarkerRenderer.prototype.drawDash = function(x, y, ctx, fill, options) {
  4639. var stretch = 1.0;
  4640. var dx = this.size/2*stretch;
  4641. var dy = this.size/2*stretch;
  4642. var points = [[x-dx, y], [x+dx, y]];
  4643. if (this.shadow) {
  4644. this.shadowRenderer.draw(ctx, points);
  4645. }
  4646. this.shapeRenderer.draw(ctx, points, options);
  4647. };
  4648. $.jqplot.MarkerRenderer.prototype.drawLine = function(p1, p2, ctx, fill, options) {
  4649. var points = [p1, p2];
  4650. if (this.shadow) {
  4651. this.shadowRenderer.draw(ctx, points);
  4652. }
  4653. this.shapeRenderer.draw(ctx, points, options);
  4654. };
  4655. $.jqplot.MarkerRenderer.prototype.drawSquare = function(x, y, ctx, fill, options) {
  4656. var stretch = 1.0;
  4657. var dx = this.size/2/stretch;
  4658. var dy = this.size/2*stretch;
  4659. var points = [[x-dx, y-dy], [x-dx, y+dy], [x+dx, y+dy], [x+dx, y-dy]];
  4660. if (this.shadow) {
  4661. this.shadowRenderer.draw(ctx, points);
  4662. }
  4663. this.shapeRenderer.draw(ctx, points, options);
  4664. };
  4665. $.jqplot.MarkerRenderer.prototype.drawCircle = function(x, y, ctx, fill, options) {
  4666. var radius = this.size/2;
  4667. var end = 2*Math.PI;
  4668. var points = [x, y, radius, 0, end, true];
  4669. if (this.shadow) {
  4670. this.shadowRenderer.draw(ctx, points);
  4671. }
  4672. this.shapeRenderer.draw(ctx, points, options);
  4673. };
  4674. $.jqplot.MarkerRenderer.prototype.draw = function(x, y, ctx, options) {
  4675. options = options || {};
  4676. // hack here b/c shape renderer uses canvas based color style options
  4677. // and marker uses css style names.
  4678. if (options.show == null || options.show != false) {
  4679. if (options.color && !options.fillStyle) {
  4680. options.fillStyle = options.color;
  4681. }
  4682. if (options.color && !options.strokeStyle) {
  4683. options.strokeStyle = options.color;
  4684. }
  4685. switch (this.style) {
  4686. case 'diamond':
  4687. this.drawDiamond(x,y,ctx, false, options);
  4688. break;
  4689. case 'filledDiamond':
  4690. this.drawDiamond(x,y,ctx, true, options);
  4691. break;
  4692. case 'circle':
  4693. this.drawCircle(x,y,ctx, false, options);
  4694. break;
  4695. case 'filledCircle':
  4696. this.drawCircle(x,y,ctx, true, options);
  4697. break;
  4698. case 'square':
  4699. this.drawSquare(x,y,ctx, false, options);
  4700. break;
  4701. case 'filledSquare':
  4702. this.drawSquare(x,y,ctx, true, options);
  4703. break;
  4704. case 'x':
  4705. this.drawX(x,y,ctx, true, options);
  4706. break;
  4707. case 'plus':
  4708. this.drawPlus(x,y,ctx, true, options);
  4709. break;
  4710. case 'dash':
  4711. this.drawDash(x,y,ctx, true, options);
  4712. break;
  4713. case 'line':
  4714. this.drawLine(x, y, ctx, false, options);
  4715. break;
  4716. default:
  4717. this.drawDiamond(x,y,ctx, false, options);
  4718. break;
  4719. }
  4720. }
  4721. };
  4722. // class: $.jqplot.shadowRenderer
  4723. // The default jqPlot shadow renderer, rendering shadows behind shapes.
  4724. $.jqplot.ShadowRenderer = function(options){
  4725. // Group: Properties
  4726. // prop: angle
  4727. // Angle of the shadow in degrees. Measured counter-clockwise from the x axis.
  4728. this.angle = 45;
  4729. // prop: offset
  4730. // Pixel offset at the given shadow angle of each shadow stroke from the last stroke.
  4731. this.offset = 1;
  4732. // prop: alpha
  4733. // alpha transparency of shadow stroke.
  4734. this.alpha = 0.07;
  4735. // prop: lineWidth
  4736. // width of the shadow line stroke.
  4737. this.lineWidth = 1.5;
  4738. // prop: lineJoin
  4739. // How line segments of the shadow are joined.
  4740. this.lineJoin = 'miter';
  4741. // prop: lineCap
  4742. // how ends of the shadow line are rendered.
  4743. this.lineCap = 'round';
  4744. // prop; closePath
  4745. // whether line path segment is closed upon itself.
  4746. this.closePath = false;
  4747. // prop: fill
  4748. // whether to fill the shape.
  4749. this.fill = false;
  4750. // prop: depth
  4751. // how many times the shadow is stroked. Each stroke will be offset by offset at angle degrees.
  4752. this.depth = 3;
  4753. this.strokeStyle = 'rgba(0,0,0,0.1)';
  4754. // prop: isarc
  4755. // wether the shadow is an arc or not.
  4756. this.isarc = false;
  4757. $.extend(true, this, options);
  4758. };
  4759. $.jqplot.ShadowRenderer.prototype.init = function(options) {
  4760. $.extend(true, this, options);
  4761. };
  4762. // function: draw
  4763. // draws an transparent black (i.e. gray) shadow.
  4764. //
  4765. // ctx - canvas drawing context
  4766. // points - array of points or [x, y, radius, start angle (rad), end angle (rad)]
  4767. $.jqplot.ShadowRenderer.prototype.draw = function(ctx, points, options) {
  4768. ctx.save();
  4769. var opts = (options != null) ? options : {};
  4770. var fill = (opts.fill != null) ? opts.fill : this.fill;
  4771. var closePath = (opts.closePath != null) ? opts.closePath : this.closePath;
  4772. var offset = (opts.offset != null) ? opts.offset : this.offset;
  4773. var alpha = (opts.alpha != null) ? opts.alpha : this.alpha;
  4774. var depth = (opts.depth != null) ? opts.depth : this.depth;
  4775. var isarc = (opts.isarc != null) ? opts.isarc : this.isarc;
  4776. ctx.lineWidth = (opts.lineWidth != null) ? opts.lineWidth : this.lineWidth;
  4777. ctx.lineJoin = (opts.lineJoin != null) ? opts.lineJoin : this.lineJoin;
  4778. ctx.lineCap = (opts.lineCap != null) ? opts.lineCap : this.lineCap;
  4779. ctx.strokeStyle = opts.strokeStyle || this.strokeStyle || 'rgba(0,0,0,'+alpha+')';
  4780. ctx.fillStyle = opts.fillStyle || this.fillStyle || 'rgba(0,0,0,'+alpha+')';
  4781. for (var j=0; j<depth; j++) {
  4782. ctx.translate(Math.cos(this.angle*Math.PI/180)*offset, Math.sin(this.angle*Math.PI/180)*offset);
  4783. ctx.beginPath();
  4784. if (isarc) {
  4785. ctx.arc(points[0], points[1], points[2], points[3], points[4], true);
  4786. }
  4787. else if (points && points.length){
  4788. var move = true;
  4789. for (var i=0; i<points.length; i++) {
  4790. // skip to the first non-null point and move to it.
  4791. if (points[i][0] != null && points[i][1] != null) {
  4792. if (move) {
  4793. ctx.moveTo(points[i][0], points[i][1]);
  4794. move = false;
  4795. }
  4796. else {
  4797. ctx.lineTo(points[i][0], points[i][1]);
  4798. }
  4799. }
  4800. else {
  4801. move = true;
  4802. }
  4803. }
  4804. }
  4805. if (closePath) {
  4806. ctx.closePath();
  4807. }
  4808. if (fill) {
  4809. ctx.fill();
  4810. }
  4811. else {
  4812. ctx.stroke();
  4813. }
  4814. }
  4815. ctx.restore();
  4816. };
  4817. // class: $.jqplot.shapeRenderer
  4818. // The default jqPlot shape renderer. Given a set of points will
  4819. // plot them and either stroke a line (fill = false) or fill them (fill = true).
  4820. // If a filled shape is desired, closePath = true must also be set to close
  4821. // the shape.
  4822. $.jqplot.ShapeRenderer = function(options){
  4823. this.lineWidth = 1.5;
  4824. // prop: lineJoin
  4825. // How line segments of the shadow are joined.
  4826. this.lineJoin = 'miter';
  4827. // prop: lineCap
  4828. // how ends of the shadow line are rendered.
  4829. this.lineCap = 'round';
  4830. // prop; closePath
  4831. // whether line path segment is closed upon itself.
  4832. this.closePath = false;
  4833. // prop: fill
  4834. // whether to fill the shape.
  4835. this.fill = false;
  4836. // prop: isarc
  4837. // wether the shadow is an arc or not.
  4838. this.isarc = false;
  4839. // prop: fillRect
  4840. // true to draw shape as a filled rectangle.
  4841. this.fillRect = false;
  4842. // prop: strokeRect
  4843. // true to draw shape as a stroked rectangle.
  4844. this.strokeRect = false;
  4845. // prop: clearRect
  4846. // true to cear a rectangle.
  4847. this.clearRect = false;
  4848. // prop: strokeStyle
  4849. // css color spec for the stoke style
  4850. this.strokeStyle = '#999999';
  4851. // prop: fillStyle
  4852. // css color spec for the fill style.
  4853. this.fillStyle = '#999999';
  4854. $.extend(true, this, options);
  4855. };
  4856. $.jqplot.ShapeRenderer.prototype.init = function(options) {
  4857. $.extend(true, this, options);
  4858. };
  4859. // function: draw
  4860. // draws the shape.
  4861. //
  4862. // ctx - canvas drawing context
  4863. // points - array of points for shapes or
  4864. // [x, y, width, height] for rectangles or
  4865. // [x, y, radius, start angle (rad), end angle (rad)] for circles and arcs.
  4866. $.jqplot.ShapeRenderer.prototype.draw = function(ctx, points, options) {
  4867. ctx.save();
  4868. var opts = (options != null) ? options : {};
  4869. var fill = (opts.fill != null) ? opts.fill : this.fill;
  4870. var closePath = (opts.closePath != null) ? opts.closePath : this.closePath;
  4871. var fillRect = (opts.fillRect != null) ? opts.fillRect : this.fillRect;
  4872. var strokeRect = (opts.strokeRect != null) ? opts.strokeRect : this.strokeRect;
  4873. var clearRect = (opts.clearRect != null) ? opts.clearRect : this.clearRect;
  4874. var isarc = (opts.isarc != null) ? opts.isarc : this.isarc;
  4875. ctx.lineWidth = opts.lineWidth || this.lineWidth;
  4876. ctx.lineJoin = opts.lineJoing || this.lineJoin;
  4877. ctx.lineCap = opts.lineCap || this.lineCap;
  4878. ctx.strokeStyle = (opts.strokeStyle || opts.color) || this.strokeStyle;
  4879. ctx.fillStyle = opts.fillStyle || this.fillStyle;
  4880. ctx.beginPath();
  4881. if (isarc) {
  4882. ctx.arc(points[0], points[1], points[2], points[3], points[4], true);
  4883. if (closePath) {
  4884. ctx.closePath();
  4885. }
  4886. if (fill) {
  4887. ctx.fill();
  4888. }
  4889. else {
  4890. ctx.stroke();
  4891. }
  4892. ctx.restore();
  4893. return;
  4894. }
  4895. else if (clearRect) {
  4896. ctx.clearRect(points[0], points[1], points[2], points[3]);
  4897. ctx.restore();
  4898. return;
  4899. }
  4900. else if (fillRect || strokeRect) {
  4901. if (fillRect) {
  4902. ctx.fillRect(points[0], points[1], points[2], points[3]);
  4903. }
  4904. if (strokeRect) {
  4905. ctx.strokeRect(points[0], points[1], points[2], points[3]);
  4906. ctx.restore();
  4907. return;
  4908. }
  4909. }
  4910. else if (points && points.length){
  4911. var move = true;
  4912. for (var i=0; i<points.length; i++) {
  4913. // skip to the first non-null point and move to it.
  4914. if (points[i][0] != null && points[i][1] != null) {
  4915. if (move) {
  4916. ctx.moveTo(points[i][0], points[i][1]);
  4917. move = false;
  4918. }
  4919. else {
  4920. ctx.lineTo(points[i][0], points[i][1]);
  4921. }
  4922. }
  4923. else {
  4924. move = true;
  4925. }
  4926. }
  4927. if (closePath) {
  4928. ctx.closePath();
  4929. }
  4930. if (fill) {
  4931. ctx.fill();
  4932. }
  4933. else {
  4934. ctx.stroke();
  4935. }
  4936. }
  4937. ctx.restore();
  4938. };
  4939. // class $.jqplot.TableLegendRenderer
  4940. // The default legend renderer for jqPlot.
  4941. $.jqplot.TableLegendRenderer = function(){
  4942. //
  4943. };
  4944. $.jqplot.TableLegendRenderer.prototype.init = function(options) {
  4945. $.extend(true, this, options);
  4946. };
  4947. $.jqplot.TableLegendRenderer.prototype.addrow = function (label, color, pad, reverse) {
  4948. var rs = (pad) ? this.rowSpacing : '0';
  4949. var tr,
  4950. elem;
  4951. if (reverse){
  4952. tr = $('<tr class="jqplot-table-legend"></tr>').prependTo(this._elem);
  4953. }
  4954. else{
  4955. tr = $('<tr class="jqplot-table-legend"></tr>').appendTo(this._elem);
  4956. }
  4957. if (this.showSwatches) {
  4958. $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
  4959. '<div><div class="jqplot-table-legend-swatch" style="background-color:'+color+';border-color:'+color+';"></div>'+
  4960. '</div></td>').appendTo(tr);
  4961. }
  4962. if (this.showLabels) {
  4963. elem = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
  4964. elem.appendTo(tr);
  4965. if (this.escapeHtml) {
  4966. elem.text(label);
  4967. }
  4968. else {
  4969. elem.html(label);
  4970. }
  4971. }
  4972. tr = null;
  4973. elem = null;
  4974. };
  4975. // called with scope of legend
  4976. $.jqplot.TableLegendRenderer.prototype.draw = function() {
  4977. var legend = this;
  4978. if (this.show) {
  4979. var series = this._series;
  4980. // make a table. one line label per row.
  4981. var ss = 'position:absolute;';
  4982. ss += (this.background) ? 'background:'+this.background+';' : '';
  4983. ss += (this.border) ? 'border:'+this.border+';' : '';
  4984. ss += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
  4985. ss += (this.fontFamily) ? 'font-family:'+this.fontFamily+';' : '';
  4986. ss += (this.textColor) ? 'color:'+this.textColor+';' : '';
  4987. ss += (this.marginTop != null) ? 'margin-top:'+this.marginTop+';' : '';
  4988. ss += (this.marginBottom != null) ? 'margin-bottom:'+this.marginBottom+';' : '';
  4989. ss += (this.marginLeft != null) ? 'margin-left:'+this.marginLeft+';' : '';
  4990. ss += (this.marginRight != null) ? 'margin-right:'+this.marginRight+';' : '';
  4991. this._elem = $('<table class="jqplot-table-legend" style="'+ss+'"></table>');
  4992. var pad = false,
  4993. reverse = false;
  4994. for (var i = 0; i< series.length; i++) {
  4995. s = series[i];
  4996. if (s._stack || s.renderer.constructor == $.jqplot.BezierCurveRenderer){
  4997. reverse = true;
  4998. }
  4999. if (s.show && s.showLabel) {
  5000. var lt = this.labels[i] || s.label.toString();
  5001. if (lt) {
  5002. var color = s.color;
  5003. if (reverse && i < series.length - 1){
  5004. pad = true;
  5005. }
  5006. else if (reverse && i == series.length - 1){
  5007. pad = false;
  5008. }
  5009. this.renderer.addrow.call(this, lt, color, pad, reverse);
  5010. pad = true;
  5011. }
  5012. // let plugins add more rows to legend. Used by trend line plugin.
  5013. for (var j=0; j<$.jqplot.addLegendRowHooks.length; j++) {
  5014. var item = $.jqplot.addLegendRowHooks[j].call(this, s);
  5015. if (item) {
  5016. this.renderer.addrow.call(this, item.label, item.color, pad);
  5017. pad = true;
  5018. }
  5019. }
  5020. lt = null;
  5021. }
  5022. }
  5023. }
  5024. return this._elem;
  5025. };
  5026. $.jqplot.TableLegendRenderer.prototype.pack = function(offsets) {
  5027. if (this.show) {
  5028. if (this.placement == 'insideGrid') {
  5029. switch (this.location) {
  5030. case 'nw':
  5031. var a = offsets.left;
  5032. var b = offsets.top;
  5033. this._elem.css('left', a);
  5034. this._elem.css('top', b);
  5035. break;
  5036. case 'n':
  5037. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  5038. var b = offsets.top;
  5039. this._elem.css('left', a);
  5040. this._elem.css('top', b);
  5041. break;
  5042. case 'ne':
  5043. var a = offsets.right;
  5044. var b = offsets.top;
  5045. this._elem.css({right:a, top:b});
  5046. break;
  5047. case 'e':
  5048. var a = offsets.right;
  5049. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  5050. this._elem.css({right:a, top:b});
  5051. break;
  5052. case 'se':
  5053. var a = offsets.right;
  5054. var b = offsets.bottom;
  5055. this._elem.css({right:a, bottom:b});
  5056. break;
  5057. case 's':
  5058. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  5059. var b = offsets.bottom;
  5060. this._elem.css({left:a, bottom:b});
  5061. break;
  5062. case 'sw':
  5063. var a = offsets.left;
  5064. var b = offsets.bottom;
  5065. this._elem.css({left:a, bottom:b});
  5066. break;
  5067. case 'w':
  5068. var a = offsets.left;
  5069. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  5070. this._elem.css({left:a, top:b});
  5071. break;
  5072. default: // same as 'se'
  5073. var a = offsets.right;
  5074. var b = offsets.bottom;
  5075. this._elem.css({right:a, bottom:b});
  5076. break;
  5077. }
  5078. }
  5079. else if (this.placement == 'outside'){
  5080. switch (this.location) {
  5081. case 'nw':
  5082. var a = this._plotDimensions.width - offsets.left;
  5083. var b = offsets.top;
  5084. this._elem.css('right', a);
  5085. this._elem.css('top', b);
  5086. break;
  5087. case 'n':
  5088. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  5089. var b = this._plotDimensions.height - offsets.top;
  5090. this._elem.css('left', a);
  5091. this._elem.css('bottom', b);
  5092. break;
  5093. case 'ne':
  5094. var a = this._plotDimensions.width - offsets.right;
  5095. var b = offsets.top;
  5096. this._elem.css({left:a, top:b});
  5097. break;
  5098. case 'e':
  5099. var a = this._plotDimensions.width - offsets.right;
  5100. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  5101. this._elem.css({left:a, top:b});
  5102. break;
  5103. case 'se':
  5104. var a = this._plotDimensions.width - offsets.right;
  5105. var b = offsets.bottom;
  5106. this._elem.css({left:a, bottom:b});
  5107. break;
  5108. case 's':
  5109. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  5110. var b = this._plotDimensions.height - offsets.bottom;
  5111. this._elem.css({left:a, top:b});
  5112. break;
  5113. case 'sw':
  5114. var a = this._plotDimensions.width - offsets.left;
  5115. var b = offsets.bottom;
  5116. this._elem.css({right:a, bottom:b});
  5117. break;
  5118. case 'w':
  5119. var a = this._plotDimensions.width - offsets.left;
  5120. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  5121. this._elem.css({right:a, top:b});
  5122. break;
  5123. default: // same as 'se'
  5124. var a = offsets.right;
  5125. var b = offsets.bottom;
  5126. this._elem.css({right:a, bottom:b});
  5127. break;
  5128. }
  5129. }
  5130. else {
  5131. switch (this.location) {
  5132. case 'nw':
  5133. this._elem.css({left:0, top:offsets.top});
  5134. break;
  5135. case 'n':
  5136. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  5137. this._elem.css({left: a, top:offsets.top});
  5138. break;
  5139. case 'ne':
  5140. this._elem.css({right:0, top:offsets.top});
  5141. break;
  5142. case 'e':
  5143. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  5144. this._elem.css({right:offsets.right, top:b});
  5145. break;
  5146. case 'se':
  5147. this._elem.css({right:offsets.right, bottom:offsets.bottom});
  5148. break;
  5149. case 's':
  5150. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  5151. this._elem.css({left: a, bottom:offsets.bottom});
  5152. break;
  5153. case 'sw':
  5154. this._elem.css({left:offsets.left, bottom:offsets.bottom});
  5155. break;
  5156. case 'w':
  5157. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  5158. this._elem.css({left:offsets.left, top:b});
  5159. break;
  5160. default: // same as 'se'
  5161. this._elem.css({right:offsets.right, bottom:offsets.bottom});
  5162. break;
  5163. }
  5164. }
  5165. }
  5166. };
  5167. /**
  5168. * Class: $.jqplot.ThemeEngine
  5169. * Theme Engine provides a programatic way to change some of the more
  5170. * common jqplot styling options such as fonts, colors and grid options.
  5171. * A theme engine instance is created with each plot. The theme engine
  5172. * manages a collection of themes which can be modified, added to, or
  5173. * applied to the plot.
  5174. *
  5175. * The themeEngine class is not instantiated directly.
  5176. * When a plot is initialized, the current plot options are scanned
  5177. * an a default theme named "Default" is created. This theme is
  5178. * used as the basis for other themes added to the theme engine and
  5179. * is always available.
  5180. *
  5181. * A theme is a simple javascript object with styling parameters for
  5182. * various entities of the plot. A theme has the form:
  5183. *
  5184. *
  5185. * > {
  5186. * > _name:f "Default",
  5187. * > target: {
  5188. * > backgroundColor: "transparent"
  5189. * > },
  5190. * > legend: {
  5191. * > textColor: null,
  5192. * > fontFamily: null,
  5193. * > fontSize: null,
  5194. * > border: null,
  5195. * > background: null
  5196. * > },
  5197. * > title: {
  5198. * > textColor: "rgb(102, 102, 102)",
  5199. * > fontFamily: "'Trebuchet MS',Arial,Helvetica,sans-serif",
  5200. * > fontSize: "19.2px",
  5201. * > textAlign: "center"
  5202. * > },
  5203. * > seriesStyles: {},
  5204. * > series: [{
  5205. * > color: "#4bb2c5",
  5206. * > lineWidth: 2.5,
  5207. * > shadow: true,
  5208. * > fillColor: "#4bb2c5",
  5209. * > showMarker: true,
  5210. * > markerOptions: {
  5211. * > color: "#4bb2c5",
  5212. * > show: true,
  5213. * > style: 'filledCircle',
  5214. * > lineWidth: 1.5,
  5215. * > size: 4,
  5216. * > shadow: true
  5217. * > }
  5218. * > }],
  5219. * > grid: {
  5220. * > drawGridlines: true,
  5221. * > gridLineColor: "#cccccc",
  5222. * > gridLineWidth: 1,
  5223. * > backgroundColor: "#fffdf6",
  5224. * > borderColor: "#999999",
  5225. * > borderWidth: 2,
  5226. * > shadow: true
  5227. * > },
  5228. * > axesStyles: {
  5229. * > label: {},
  5230. * > ticks: {}
  5231. * > },
  5232. * > axes: {
  5233. * > xaxis: {
  5234. * > borderColor: "#999999",
  5235. * > borderWidth: 2,
  5236. * > ticks: {
  5237. * > show: true,
  5238. * > showGridline: true,
  5239. * > showLabel: true,
  5240. * > showMark: true,
  5241. * > size: 4,
  5242. * > textColor: "",
  5243. * > whiteSpace: "nowrap",
  5244. * > fontSize: "12px",
  5245. * > fontFamily: "'Trebuchet MS',Arial,Helvetica,sans-serif"
  5246. * > },
  5247. * > label: {
  5248. * > textColor: "rgb(102, 102, 102)",
  5249. * > whiteSpace: "normal",
  5250. * > fontSize: "14.6667px",
  5251. * > fontFamily: "'Trebuchet MS',Arial,Helvetica,sans-serif",
  5252. * > fontWeight: "400"
  5253. * > }
  5254. * > },
  5255. * > yaxis: {
  5256. * > borderColor: "#999999",
  5257. * > borderWidth: 2,
  5258. * > ticks: {
  5259. * > show: true,
  5260. * > showGridline: true,
  5261. * > showLabel: true,
  5262. * > showMark: true,
  5263. * > size: 4,
  5264. * > textColor: "",
  5265. * > whiteSpace: "nowrap",
  5266. * > fontSize: "12px",
  5267. * > fontFamily: "'Trebuchet MS',Arial,Helvetica,sans-serif"
  5268. * > },
  5269. * > label: {
  5270. * > textColor: null,
  5271. * > whiteSpace: null,
  5272. * > fontSize: null,
  5273. * > fontFamily: null,
  5274. * > fontWeight: null
  5275. * > }
  5276. * > },
  5277. * > x2axis: {...
  5278. * > },
  5279. * > ...
  5280. * > y9axis: {...
  5281. * > }
  5282. * > }
  5283. * > }
  5284. *
  5285. * "seriesStyles" is a style object that will be applied to all series in the plot.
  5286. * It will forcibly override any styles applied on the individual series. "axesStyles" is
  5287. * a style object that will be applied to all axes in the plot. It will also forcibly
  5288. * override any styles on the individual axes.
  5289. *
  5290. * The example shown above has series options for a line series. Options for other
  5291. * series types are shown below:
  5292. *
  5293. * Bar Series:
  5294. *
  5295. * > {
  5296. * > color: "#4bb2c5",
  5297. * > seriesColors: ["#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"],
  5298. * > lineWidth: 2.5,
  5299. * > shadow: true,
  5300. * > barPadding: 2,
  5301. * > barMargin: 10,
  5302. * > barWidth: 15.09375,
  5303. * > highlightColors: ["rgb(129,201,214)", "rgb(129,201,214)", "rgb(129,201,214)", "rgb(129,201,214)", "rgb(129,201,214)", "rgb(129,201,214)", "rgb(129,201,214)", "rgb(129,201,214)"]
  5304. * > }
  5305. *
  5306. * Pie Series:
  5307. *
  5308. * > {
  5309. * > seriesColors: ["#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"],
  5310. * > padding: 20,
  5311. * > sliceMargin: 0,
  5312. * > fill: true,
  5313. * > shadow: true,
  5314. * > startAngle: 0,
  5315. * > lineWidth: 2.5,
  5316. * > highlightColors: ["rgb(129,201,214)", "rgb(240,189,104)", "rgb(214,202,165)", "rgb(137,180,158)", "rgb(168,180,137)", "rgb(180,174,89)", "rgb(180,113,161)", "rgb(129,141,236)", "rgb(227,205,120)", "rgb(255,138,76)", "rgb(76,169,219)", "rgb(215,126,190)", "rgb(220,232,135)", "rgb(200,167,96)", "rgb(103,202,235)", "rgb(208,154,215)"]
  5317. * > }
  5318. *
  5319. * Funnel Series:
  5320. *
  5321. * > {
  5322. * > color: "#4bb2c5",
  5323. * > lineWidth: 2,
  5324. * > shadow: true,
  5325. * > padding: {
  5326. * > top: 20,
  5327. * > right: 20,
  5328. * > bottom: 20,
  5329. * > left: 20
  5330. * > },
  5331. * > sectionMargin: 6,
  5332. * > seriesColors: ["#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"],
  5333. * > highlightColors: ["rgb(147,208,220)", "rgb(242,199,126)", "rgb(220,210,178)", "rgb(154,191,172)", "rgb(180,191,154)", "rgb(191,186,112)", "rgb(191,133,174)", "rgb(147,157,238)", "rgb(231,212,139)", "rgb(255,154,102)", "rgb(102,181,224)", "rgb(221,144,199)", "rgb(225,235,152)", "rgb(200,167,96)", "rgb(124,210,238)", "rgb(215,169,221)"]
  5334. * > }
  5335. *
  5336. */
  5337. $.jqplot.ThemeEngine = function(){
  5338. // Group: Properties
  5339. //
  5340. // prop: themes
  5341. // hash of themes managed by the theme engine.
  5342. // Indexed by theme name.
  5343. this.themes = {};
  5344. // prop: activeTheme
  5345. // Pointer to currently active theme
  5346. this.activeTheme=null;
  5347. };
  5348. // called with scope of plot
  5349. $.jqplot.ThemeEngine.prototype.init = function() {
  5350. // get the Default theme from the current plot settings.
  5351. var th = new $.jqplot.Theme({_name:'Default'});
  5352. var n, i;
  5353. for (n in th.target) {
  5354. if (n == "textColor") {
  5355. th.target[n] = this.target.css('color');
  5356. }
  5357. else {
  5358. th.target[n] = this.target.css(n);
  5359. }
  5360. }
  5361. if (this.title.show && this.title._elem) {
  5362. for (n in th.title) {
  5363. if (n == "textColor") {
  5364. th.title[n] = this.title._elem.css('color');
  5365. }
  5366. else {
  5367. th.title[n] = this.title._elem.css(n);
  5368. }
  5369. }
  5370. }
  5371. for (n in th.grid) {
  5372. th.grid[n] = this.grid[n];
  5373. }
  5374. if (th.grid.backgroundColor == null && this.grid.background != null) {
  5375. th.grid.backgroundColor = this.grid.background;
  5376. }
  5377. if (this.legend.show && this.legend._elem) {
  5378. for (n in th.legend) {
  5379. if (n == 'textColor') {
  5380. th.legend[n] = this.legend._elem.css('color');
  5381. }
  5382. else {
  5383. th.legend[n] = this.legend._elem.css(n);
  5384. }
  5385. }
  5386. }
  5387. var s;
  5388. for (i=0; i<this.series.length; i++) {
  5389. s = this.series[i];
  5390. if (s.renderer.constructor == $.jqplot.LineRenderer) {
  5391. th.series.push(new LineSeriesProperties());
  5392. }
  5393. else if (s.renderer.constructor == $.jqplot.BarRenderer) {
  5394. th.series.push(new BarSeriesProperties());
  5395. }
  5396. else if (s.renderer.constructor == $.jqplot.PieRenderer) {
  5397. th.series.push(new PieSeriesProperties());
  5398. }
  5399. else if (s.renderer.constructor == $.jqplot.DonutRenderer) {
  5400. th.series.push(new DonutSeriesProperties());
  5401. }
  5402. else if (s.renderer.constructor == $.jqplot.FunnelRenderer) {
  5403. th.series.push(new FunnelSeriesProperties());
  5404. }
  5405. else if (s.renderer.constructor == $.jqplot.MeterGaugeRenderer) {
  5406. th.series.push(new MeterSeriesProperties());
  5407. }
  5408. else {
  5409. th.series.push({});
  5410. }
  5411. for (n in th.series[i]) {
  5412. th.series[i][n] = s[n];
  5413. }
  5414. }
  5415. var a, ax;
  5416. for (n in this.axes) {
  5417. ax = this.axes[n];
  5418. a = th.axes[n] = new AxisProperties();
  5419. a.borderColor = ax.borderColor;
  5420. a.borderWidth = ax.borderWidth;
  5421. if (ax._ticks && ax._ticks[0]) {
  5422. for (nn in a.ticks) {
  5423. if (ax._ticks[0].hasOwnProperty(nn)) {
  5424. a.ticks[nn] = ax._ticks[0][nn];
  5425. }
  5426. else if (ax._ticks[0]._elem){
  5427. a.ticks[nn] = ax._ticks[0]._elem.css(nn);
  5428. }
  5429. }
  5430. }
  5431. if (ax._label && ax._label.show) {
  5432. for (nn in a.label) {
  5433. // a.label[nn] = ax._label._elem.css(nn);
  5434. if (ax._label[nn]) {
  5435. a.label[nn] = ax._label[nn];
  5436. }
  5437. else if (ax._label._elem){
  5438. if (nn == 'textColor') {
  5439. a.label[nn] = ax._label._elem.css('color');
  5440. }
  5441. else {
  5442. a.label[nn] = ax._label._elem.css(nn);
  5443. }
  5444. }
  5445. }
  5446. }
  5447. }
  5448. this.themeEngine._add(th);
  5449. this.themeEngine.activeTheme = this.themeEngine.themes[th._name];
  5450. };
  5451. /**
  5452. * Group: methods
  5453. *
  5454. * method: get
  5455. *
  5456. * Get and return the named theme or the active theme if no name given.
  5457. *
  5458. * parameter:
  5459. *
  5460. * name - name of theme to get.
  5461. *
  5462. * returns:
  5463. *
  5464. * Theme instance of given name.
  5465. */
  5466. $.jqplot.ThemeEngine.prototype.get = function(name) {
  5467. if (!name) {
  5468. // return the active theme
  5469. return this.activeTheme;
  5470. }
  5471. else {
  5472. return this.themes[name];
  5473. }
  5474. };
  5475. function numericalOrder(a,b) { return a-b; }
  5476. /**
  5477. * method: getThemeNames
  5478. *
  5479. * Return the list of theme names in this manager in alpha-numerical order.
  5480. *
  5481. * parameter:
  5482. *
  5483. * None
  5484. *
  5485. * returns:
  5486. *
  5487. * A the list of theme names in this manager in alpha-numerical order.
  5488. */
  5489. $.jqplot.ThemeEngine.prototype.getThemeNames = function() {
  5490. var tn = [];
  5491. for (var n in this.themes) {
  5492. tn.push(n);
  5493. }
  5494. return tn.sort(numericalOrder);
  5495. };
  5496. /**
  5497. * method: getThemes
  5498. *
  5499. * Return a list of themes in alpha-numerical order by name.
  5500. *
  5501. * parameter:
  5502. *
  5503. * None
  5504. *
  5505. * returns:
  5506. *
  5507. * A list of themes in alpha-numerical order by name.
  5508. */
  5509. $.jqplot.ThemeEngine.prototype.getThemes = function() {
  5510. var tn = [];
  5511. var themes = [];
  5512. for (var n in this.themes) {
  5513. tn.push(n);
  5514. }
  5515. tn.sort(numericalOrder);
  5516. for (var i=0; i<tn.length; i++) {
  5517. themes.push(this.themes[tn[i]]);
  5518. }
  5519. return themes;
  5520. };
  5521. $.jqplot.ThemeEngine.prototype.activate = function(plot, name) {
  5522. // sometimes need to redraw whole plot.
  5523. var redrawPlot = false;
  5524. if (!name && this.activeTheme && this.activeTheme._name) {
  5525. name = this.activeTheme._name;
  5526. }
  5527. if (!this.themes.hasOwnProperty(name)) {
  5528. throw new Error("No theme of that name");
  5529. }
  5530. else {
  5531. var th = this.themes[name];
  5532. this.activeTheme = th;
  5533. var val, checkBorderColor = false, checkBorderWidth = false;
  5534. var arr = ['xaxis', 'x2axis', 'yaxis', 'y2axis'];
  5535. for (i=0; i<arr.length; i++) {
  5536. var ax = arr[i];
  5537. if (th.axesStyles.borderColor != null) {
  5538. plot.axes[ax].borderColor = th.axesStyles.borderColor;
  5539. }
  5540. if (th.axesStyles.borderWidth != null) {
  5541. plot.axes[ax].borderWidth = th.axesStyles.borderWidth;
  5542. }
  5543. }
  5544. for (axname in plot.axes) {
  5545. var axis = plot.axes[axname];
  5546. if (axis.show) {
  5547. var thaxis = th.axes[axname] || {};
  5548. var thaxstyle = th.axesStyles;
  5549. var thax = $.jqplot.extend(true, {}, thaxis, thaxstyle);
  5550. val = (th.axesStyles.borderColor != null) ? th.axesStyles.borderColor : thax.borderColor;
  5551. if (thax.borderColor != null) {
  5552. axis.borderColor = thax.borderColor;
  5553. redrawPlot = true;
  5554. }
  5555. val = (th.axesStyles.borderWidth != null) ? th.axesStyles.borderWidth : thax.borderWidth;
  5556. if (thax.borderWidth != null) {
  5557. axis.borderWidth = thax.borderWidth;
  5558. redrawPlot = true;
  5559. }
  5560. if (axis._ticks && axis._ticks[0]) {
  5561. for (nn in thax.ticks) {
  5562. // val = null;
  5563. // if (th.axesStyles.ticks && th.axesStyles.ticks[nn] != null) {
  5564. // val = th.axesStyles.ticks[nn];
  5565. // }
  5566. // else if (thax.ticks[nn] != null){
  5567. // val = thax.ticks[nn]
  5568. // }
  5569. val = thax.ticks[nn];
  5570. if (val != null) {
  5571. axis.tickOptions[nn] = val;
  5572. axis._ticks = [];
  5573. redrawPlot = true;
  5574. }
  5575. }
  5576. }
  5577. if (axis._label && axis._label.show) {
  5578. for (nn in thax.label) {
  5579. // val = null;
  5580. // if (th.axesStyles.label && th.axesStyles.label[nn] != null) {
  5581. // val = th.axesStyles.label[nn];
  5582. // }
  5583. // else if (thax.label && thax.label[nn] != null){
  5584. // val = thax.label[nn]
  5585. // }
  5586. val = thax.label[nn];
  5587. if (val != null) {
  5588. axis.labelOptions[nn] = val;
  5589. redrawPlot = true;
  5590. }
  5591. }
  5592. }
  5593. }
  5594. }
  5595. for (var n in th.grid) {
  5596. if (th.grid[n] != null) {
  5597. plot.grid[n] = th.grid[n];
  5598. }
  5599. }
  5600. if (!redrawPlot) {
  5601. plot.grid.draw();
  5602. }
  5603. if (plot.legend.show) {
  5604. for (n in th.legend) {
  5605. if (th.legend[n] != null) {
  5606. plot.legend[n] = th.legend[n];
  5607. }
  5608. }
  5609. }
  5610. if (plot.title.show) {
  5611. for (n in th.title) {
  5612. if (th.title[n] != null) {
  5613. plot.title[n] = th.title[n];
  5614. }
  5615. }
  5616. }
  5617. var i;
  5618. for (i=0; i<th.series.length; i++) {
  5619. var opts = {};
  5620. var redrawSeries = false;
  5621. for (n in th.series[i]) {
  5622. val = (th.seriesStyles[n] != null) ? th.seriesStyles[n] : th.series[i][n];
  5623. if (val != null) {
  5624. opts[n] = val;
  5625. if (n == 'color') {
  5626. plot.series[i].renderer.shapeRenderer.fillStyle = val;
  5627. plot.series[i].renderer.shapeRenderer.strokeStyle = val;
  5628. plot.series[i][n] = val;
  5629. }
  5630. else if (n == 'lineWidth') {
  5631. plot.series[i].renderer.shapeRenderer.lineWidth = val;
  5632. plot.series[i][n] = val;
  5633. }
  5634. else if (n == 'markerOptions') {
  5635. merge (plot.series[i].markerOptions, val);
  5636. merge (plot.series[i].markerRenderer, val);
  5637. }
  5638. else {
  5639. plot.series[i][n] = val;
  5640. }
  5641. redrawPlot = true;
  5642. }
  5643. }
  5644. }
  5645. if (redrawPlot) {
  5646. plot.target.empty();
  5647. plot.draw();
  5648. }
  5649. for (n in th.target) {
  5650. if (th.target[n] != null) {
  5651. plot.target.css(n, th.target[n]);
  5652. }
  5653. }
  5654. }
  5655. };
  5656. $.jqplot.ThemeEngine.prototype._add = function(theme, name) {
  5657. if (name) {
  5658. theme._name = name;
  5659. }
  5660. if (!theme._name) {
  5661. theme._name = Date.parse(new Date());
  5662. }
  5663. if (!this.themes.hasOwnProperty(theme._name)) {
  5664. this.themes[theme._name] = theme;
  5665. }
  5666. else {
  5667. throw new Error("jqplot.ThemeEngine Error: Theme already in use");
  5668. }
  5669. };
  5670. // method remove
  5671. // Delete the named theme, return true on success, false on failure.
  5672. /**
  5673. * method: remove
  5674. *
  5675. * Remove the given theme from the themeEngine.
  5676. *
  5677. * parameters:
  5678. *
  5679. * name - name of the theme to remove.
  5680. *
  5681. * returns:
  5682. *
  5683. * true on success, false on failure.
  5684. */
  5685. $.jqplot.ThemeEngine.prototype.remove = function(name) {
  5686. if (name == 'Default') {
  5687. return false;
  5688. }
  5689. return delete this.themes[name];
  5690. };
  5691. /**
  5692. * method: newTheme
  5693. *
  5694. * Create a new theme based on the default theme, adding it the themeEngine.
  5695. *
  5696. * parameters:
  5697. *
  5698. * name - name of the new theme.
  5699. * obj - optional object of styles to be applied to this new theme.
  5700. *
  5701. * returns:
  5702. *
  5703. * new Theme object.
  5704. */
  5705. $.jqplot.ThemeEngine.prototype.newTheme = function(name, obj) {
  5706. if (typeof(name) == 'object') {
  5707. obj = obj || name;
  5708. name = null;
  5709. }
  5710. if (obj && obj._name) {
  5711. name = obj._name;
  5712. }
  5713. else {
  5714. name = name || Date.parse(new Date());
  5715. }
  5716. // var th = new $.jqplot.Theme(name);
  5717. var th = this.copy(this.themes['Default']._name, name);
  5718. $.jqplot.extend(th, obj);
  5719. return th;
  5720. };
  5721. // function clone(obj) {
  5722. // return eval(obj.toSource());
  5723. // }
  5724. function clone(obj){
  5725. if(obj == null || typeof(obj) != 'object'){
  5726. return obj;
  5727. }
  5728. var temp = new obj.constructor();
  5729. for(var key in obj){
  5730. temp[key] = clone(obj[key]);
  5731. }
  5732. return temp;
  5733. }
  5734. $.jqplot.clone = clone;
  5735. function merge(obj1, obj2) {
  5736. if (obj2 == null || typeof(obj2) != 'object') {
  5737. return;
  5738. }
  5739. for (var key in obj2) {
  5740. if (key == 'highlightColors') {
  5741. obj1[key] = clone(obj2[key]);
  5742. }
  5743. if (obj2[key] != null && typeof(obj2[key]) == 'object') {
  5744. if (!obj1.hasOwnProperty(key)) {
  5745. obj1[key] = {};
  5746. }
  5747. merge(obj1[key], obj2[key]);
  5748. }
  5749. else {
  5750. obj1[key] = obj2[key];
  5751. }
  5752. }
  5753. }
  5754. $.jqplot.merge = merge;
  5755. // Use the jQuery 1.3.2 extend function since behaviour in jQuery 1.4 seems problematic
  5756. $.jqplot.extend = function() {
  5757. // copy reference to target object
  5758. var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
  5759. // Handle a deep copy situation
  5760. if ( typeof target === "boolean" ) {
  5761. deep = target;
  5762. target = arguments[1] || {};
  5763. // skip the boolean and the target
  5764. i = 2;
  5765. }
  5766. // Handle case when target is a string or something (possible in deep copy)
  5767. if ( typeof target !== "object" && !toString.call(target) === "[object Function]" ) {
  5768. target = {};
  5769. }
  5770. for ( ; i < length; i++ ){
  5771. // Only deal with non-null/undefined values
  5772. if ( (options = arguments[ i ]) != null ) {
  5773. // Extend the base object
  5774. for ( var name in options ) {
  5775. var src = target[ name ], copy = options[ name ];
  5776. // Prevent never-ending loop
  5777. if ( target === copy ) {
  5778. continue;
  5779. }
  5780. // Recurse if we're merging object values
  5781. if ( deep && copy && typeof copy === "object" && !copy.nodeType ) {
  5782. target[ name ] = $.jqplot.extend( deep,
  5783. // Never move original objects, clone them
  5784. src || ( copy.length != null ? [ ] : { } )
  5785. , copy );
  5786. }
  5787. // Don't bring in undefined values
  5788. else if ( copy !== undefined ) {
  5789. target[ name ] = copy;
  5790. }
  5791. }
  5792. }
  5793. }
  5794. // Return the modified object
  5795. return target;
  5796. };
  5797. /**
  5798. * method: rename
  5799. *
  5800. * Rename a theme.
  5801. *
  5802. * parameters:
  5803. *
  5804. * oldName - current name of the theme.
  5805. * newName - desired name of the theme.
  5806. *
  5807. * returns:
  5808. *
  5809. * new Theme object.
  5810. */
  5811. $.jqplot.ThemeEngine.prototype.rename = function (oldName, newName) {
  5812. if (oldName == 'Default' || newName == 'Default') {
  5813. throw new Error ("jqplot.ThemeEngine Error: Cannot rename from/to Default");
  5814. }
  5815. if (this.themes.hasOwnProperty(newName)) {
  5816. throw new Error ("jqplot.ThemeEngine Error: New name already in use.");
  5817. }
  5818. else if (this.themes.hasOwnProperty(oldName)) {
  5819. var th = this.copy (oldName, newName);
  5820. this.remove(oldName);
  5821. return th;
  5822. }
  5823. throw new Error("jqplot.ThemeEngine Error: Old name or new name invalid");
  5824. };
  5825. /**
  5826. * method: copy
  5827. *
  5828. * Create a copy of an existing theme in the themeEngine, adding it the themeEngine.
  5829. *
  5830. * parameters:
  5831. *
  5832. * sourceName - name of the existing theme.
  5833. * targetName - name of the copy.
  5834. * obj - optional object of style parameter to apply to the new theme.
  5835. *
  5836. * returns:
  5837. *
  5838. * new Theme object.
  5839. */
  5840. $.jqplot.ThemeEngine.prototype.copy = function (sourceName, targetName, obj) {
  5841. if (targetName == 'Default') {
  5842. throw new Error ("jqplot.ThemeEngine Error: Cannot copy over Default theme");
  5843. }
  5844. if (!this.themes.hasOwnProperty(sourceName)) {
  5845. var s = "jqplot.ThemeEngine Error: Source name invalid";
  5846. throw new Error(s);
  5847. }
  5848. if (this.themes.hasOwnProperty(targetName)) {
  5849. var s = "jqplot.ThemeEngine Error: Target name invalid";
  5850. throw new Error(s);
  5851. }
  5852. else {
  5853. var th = clone(this.themes[sourceName]);
  5854. th._name = targetName;
  5855. $.jqplot.extend(true, th, obj);
  5856. this._add(th);
  5857. return th;
  5858. }
  5859. };
  5860. $.jqplot.Theme = function(name, obj) {
  5861. if (typeof(name) == 'object') {
  5862. obj = obj || name;
  5863. name = null;
  5864. }
  5865. name = name || Date.parse(new Date());
  5866. this._name = name;
  5867. this.target = {
  5868. backgroundColor: null
  5869. };
  5870. this.legend = {
  5871. textColor: null,
  5872. fontFamily: null,
  5873. fontSize: null,
  5874. border: null,
  5875. background: null
  5876. };
  5877. this.title = {
  5878. textColor: null,
  5879. fontFamily: null,
  5880. fontSize: null,
  5881. textAlign: null
  5882. };
  5883. this.seriesStyles = {};
  5884. this.series = [];
  5885. this.grid = {
  5886. drawGridlines: null,
  5887. gridLineColor: null,
  5888. gridLineWidth: null,
  5889. backgroundColor: null,
  5890. borderColor: null,
  5891. borderWidth: null,
  5892. shadow: null
  5893. };
  5894. this.axesStyles = {label:{}, ticks:{}};
  5895. this.axes = {};
  5896. if (typeof(obj) == 'string') {
  5897. this._name = obj;
  5898. }
  5899. else if(typeof(obj) == 'object') {
  5900. $.jqplot.extend(true, this, obj);
  5901. }
  5902. };
  5903. var AxisProperties = function() {
  5904. this.borderColor = null;
  5905. this.borderWidth = null;
  5906. this.ticks = new AxisTicks();
  5907. this.label = new AxisLabel();
  5908. };
  5909. var AxisTicks = function() {
  5910. this.show = null;
  5911. this.showGridline = null;
  5912. this.showLabel = null;
  5913. this.showMark = null;
  5914. this.size = null;
  5915. this.textColor = null;
  5916. this.whiteSpace = null;
  5917. this.fontSize = null;
  5918. this.fontFamily = null;
  5919. };
  5920. var AxisLabel = function() {
  5921. this.textColor = null;
  5922. this.whiteSpace = null;
  5923. this.fontSize = null;
  5924. this.fontFamily = null;
  5925. this.fontWeight = null;
  5926. };
  5927. var LineSeriesProperties = function() {
  5928. this.color=null;
  5929. this.lineWidth=null;
  5930. this.shadow=null;
  5931. this.fillColor=null;
  5932. this.showMarker=null;
  5933. this.markerOptions = new MarkerOptions();
  5934. };
  5935. var MarkerOptions = function() {
  5936. this.show = null;
  5937. this.style = null;
  5938. this.lineWidth = null;
  5939. this.size = null;
  5940. this.color = null;
  5941. this.shadow = null;
  5942. };
  5943. var BarSeriesProperties = function() {
  5944. this.color=null;
  5945. this.seriesColors=null;
  5946. this.lineWidth=null;
  5947. this.shadow=null;
  5948. this.barPadding=null;
  5949. this.barMargin=null;
  5950. this.barWidth=null;
  5951. this.highlightColors=null;
  5952. };
  5953. var PieSeriesProperties = function() {
  5954. this.seriesColors=null;
  5955. this.padding=null;
  5956. this.sliceMargin=null;
  5957. this.fill=null;
  5958. this.shadow=null;
  5959. this.startAngle=null;
  5960. this.lineWidth=null;
  5961. this.highlightColors=null;
  5962. };
  5963. var DonutSeriesProperties = function() {
  5964. this.seriesColors=null;
  5965. this.padding=null;
  5966. this.sliceMargin=null;
  5967. this.fill=null;
  5968. this.shadow=null;
  5969. this.startAngle=null;
  5970. this.lineWidth=null;
  5971. this.innerDiameter=null;
  5972. this.thickness=null;
  5973. this.ringMargin=null;
  5974. this.highlightColors=null;
  5975. };
  5976. var FunnelSeriesProperties = function() {
  5977. this.color=null;
  5978. this.lineWidth=null;
  5979. this.shadow=null;
  5980. this.padding=null;
  5981. this.sectionMargin=null;
  5982. this.seriesColors=null;
  5983. this.highlightColors=null;
  5984. };
  5985. var MeterSeriesProperties = function() {
  5986. this.padding=null;
  5987. this.backgroundColor=null;
  5988. this.ringColor=null;
  5989. this.tickColor=null;
  5990. this.ringWidth=null;
  5991. this.intervalColors=null;
  5992. this.intervalInnerRadius=null;
  5993. this.intervalOuterRadius=null;
  5994. this.hubRadius=null;
  5995. this.needleThickness=null;
  5996. this.needlePad=null;
  5997. };
  5998. /**
  5999. * @description
  6000. * <p>Object with extended date parsing and formatting capabilities.
  6001. * This library borrows many concepts and ideas from the Date Instance
  6002. * Methods by Ken Snyder along with some parts of Ken's actual code.</p>
  6003. *
  6004. * <p>jsDate takes a different approach by not extending the built-in
  6005. * Date Object, improving date parsing, allowing for multiple formatting
  6006. * syntaxes and multiple and more easily expandable localization.</p>
  6007. *
  6008. * @author Chris Leonello
  6009. * @date #date#
  6010. * @version #VERSION#
  6011. * @copyright (c) 2010 Chris Leonello
  6012. * jsDate is currently available for use in all personal or commercial projects
  6013. * under both the MIT and GPL version 2.0 licenses. This means that you can
  6014. * choose the license that best suits your project and use it accordingly.
  6015. *
  6016. * <p>Ken's origianl Date Instance Methods and copyright notice:</p>
  6017. * <pre>
  6018. * Ken Snyder (ken d snyder at gmail dot com)
  6019. * 2008-09-10
  6020. * version 2.0.2 (http://kendsnyder.com/sandbox/date/)
  6021. * Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
  6022. * </pre>
  6023. *
  6024. * @class
  6025. * @name jsDate
  6026. * @param {String | Number | Array | Date&nbsp;Object | Options&nbsp;Object} arguments Optional arguments, either a parsable date/time string,
  6027. * a JavaScript timestamp, an array of numbers of form [year, month, day, hours, minutes, seconds, milliseconds],
  6028. * a Date object, or an options object of form {syntax: "perl", date:some Date} where all options are optional.
  6029. */
  6030. var jsDate = function () {
  6031. this.syntax = jsDate.config.syntax;
  6032. this._type = "jsDate";
  6033. this.utcOffset = new Date().getTimezoneOffset * 60000;
  6034. this.proxy = new Date();
  6035. this.options = {};
  6036. this.locale = jsDate.regional.getLocale();
  6037. this.formatString = '';
  6038. this.defaultCentury = jsDate.config.defaultCentury;
  6039. switch ( arguments.length ) {
  6040. case 0:
  6041. break;
  6042. case 1:
  6043. // other objects either won't have a _type property or,
  6044. // if they do, it shouldn't be set to "jsDate", so
  6045. // assume it is an options argument.
  6046. if (get_type(arguments[0]) == "[object Object]" && arguments[0]._type != "jsDate") {
  6047. var opts = this.options = arguments[0];
  6048. this.syntax = opts.syntax || this.syntax;
  6049. this.defaultCentury = opts.defaultCentury || this.defaultCentury;
  6050. this.proxy = jsDate.createDate(opts.date);
  6051. }
  6052. else {
  6053. this.proxy = jsDate.createDate(arguments[0]);
  6054. }
  6055. break;
  6056. default:
  6057. var a = [];
  6058. for ( var i=0; i<arguments.length; i++ ) {
  6059. a.push(arguments[i]);
  6060. }
  6061. this.proxy = new Date( this.utcOffset );
  6062. this.proxy.setFullYear.apply( this.proxy, a.slice(0,3) );
  6063. if ( a.slice(3).length ) {
  6064. this.proxy.setHours.apply( this.proxy, a.slice(3) );
  6065. }
  6066. break;
  6067. }
  6068. };
  6069. /**
  6070. * @namespace Configuration options that will be used as defaults for all instances on the page.
  6071. * @property {String} defaultLocale The default locale to use [en].
  6072. * @property {String} syntax The default syntax to use [perl].
  6073. */
  6074. jsDate.config = {
  6075. defaultLocale: 'en',
  6076. syntax: 'perl',
  6077. defaultCentury: 1900
  6078. };
  6079. /**
  6080. * Add an arbitrary amount to the currently stored date
  6081. *
  6082. * @param {Number} number
  6083. * @param {String} unit
  6084. * @returns {jsDate}
  6085. */
  6086. jsDate.prototype.add = function(number, unit) {
  6087. var factor = multipliers[unit] || multipliers.day;
  6088. if (typeof factor == 'number') {
  6089. this.proxy.setTime(this.proxy.getTime() + (factor * number));
  6090. } else {
  6091. factor.add(this, number);
  6092. }
  6093. return this;
  6094. };
  6095. /**
  6096. * Create a new jqplot.date object with the same date
  6097. *
  6098. * @returns {jsDate}
  6099. */
  6100. jsDate.prototype.clone = function() {
  6101. return new jsDate(this.proxy.getTime());
  6102. };
  6103. /**
  6104. * Find the difference between this jsDate and another date.
  6105. *
  6106. * @param {String| Number| Array| jsDate&nbsp;Object| Date&nbsp;Object} dateObj
  6107. * @param {String} unit
  6108. * @param {Boolean} allowDecimal
  6109. * @returns {Number} Number of units difference between dates.
  6110. */
  6111. jsDate.prototype.diff = function(dateObj, unit, allowDecimal) {
  6112. // ensure we have a Date object
  6113. dateObj = new jsDate(dateObj);
  6114. if (dateObj === null) {
  6115. return null;
  6116. }
  6117. // get the multiplying factor integer or factor function
  6118. var factor = multipliers[unit] || multipliers.day;
  6119. if (typeof factor == 'number') {
  6120. // multiply
  6121. var unitDiff = (this.proxy.getTime() - dateObj.proxy.getTime()) / factor;
  6122. } else {
  6123. // run function
  6124. var unitDiff = factor.diff(this.proxy, dateObj.proxy);
  6125. }
  6126. // if decimals are not allowed, round toward zero
  6127. return (allowDecimal ? unitDiff : Math[unitDiff > 0 ? 'floor' : 'ceil'](unitDiff));
  6128. };
  6129. /**
  6130. * Get the abbreviated name of the current week day
  6131. *
  6132. * @returns {String}
  6133. */
  6134. jsDate.prototype.getAbbrDayName = function() {
  6135. return jsDate.regional[this.locale]["dayNamesShort"][this.proxy.getDay()];
  6136. };
  6137. /**
  6138. * Get the abbreviated name of the current month
  6139. *
  6140. * @returns {String}
  6141. */
  6142. jsDate.prototype.getAbbrMonthName = function() {
  6143. return jsDate.regional[this.locale]["monthNamesShort"][this.proxy.getMonth()];
  6144. };
  6145. /**
  6146. * Get UPPER CASE AM or PM for the current time
  6147. *
  6148. * @returns {String}
  6149. */
  6150. jsDate.prototype.getAMPM = function() {
  6151. return this.proxy.getHours() >= 12 ? 'PM' : 'AM';
  6152. };
  6153. /**
  6154. * Get lower case am or pm for the current time
  6155. *
  6156. * @returns {String}
  6157. */
  6158. jsDate.prototype.getAmPm = function() {
  6159. return this.proxy.getHours() >= 12 ? 'pm' : 'am';
  6160. };
  6161. /**
  6162. * Get the century (19 for 20th Century)
  6163. *
  6164. * @returns {Integer} Century (19 for 20th century).
  6165. */
  6166. jsDate.prototype.getCentury = function() {
  6167. return parseInt(this.proxy.getFullYear()/100, 10);
  6168. };
  6169. /**
  6170. * Implements Date functionality
  6171. */
  6172. jsDate.prototype.getDate = function() {
  6173. return this.proxy.getDate();
  6174. };
  6175. /**
  6176. * Implements Date functionality
  6177. */
  6178. jsDate.prototype.getDay = function() {
  6179. return this.proxy.getDay();
  6180. };
  6181. /**
  6182. * Get the Day of week 1 (Monday) thru 7 (Sunday)
  6183. *
  6184. * @returns {Integer} Day of week 1 (Monday) thru 7 (Sunday)
  6185. */
  6186. jsDate.prototype.getDayOfWeek = function() {
  6187. var dow = this.proxy.getDay();
  6188. return dow===0?7:dow;
  6189. };
  6190. /**
  6191. * Get the day of the year
  6192. *
  6193. * @returns {Integer} 1 - 366, day of the year
  6194. */
  6195. jsDate.prototype.getDayOfYear = function() {
  6196. var d = this.proxy;
  6197. var ms = d - new Date('' + d.getFullYear() + '/1/1 GMT');
  6198. ms += d.getTimezoneOffset()*60000;
  6199. d = null;
  6200. return parseInt(ms/60000/60/24, 10)+1;
  6201. };
  6202. /**
  6203. * Get the name of the current week day
  6204. *
  6205. * @returns {String}
  6206. */
  6207. jsDate.prototype.getDayName = function() {
  6208. return jsDate.regional[this.locale]["dayNames"][this.proxy.getDay()];
  6209. };
  6210. /**
  6211. * Get the week number of the given year, starting with the first Sunday as the first week
  6212. * @returns {Integer} Week number (13 for the 13th full week of the year).
  6213. */
  6214. jsDate.prototype.getFullWeekOfYear = function() {
  6215. var d = this.proxy;
  6216. var doy = this.getDayOfYear();
  6217. var rdow = 6-d.getDay();
  6218. var woy = parseInt((doy+rdow)/7, 10);
  6219. return woy;
  6220. };
  6221. /**
  6222. * Implements Date functionality
  6223. */
  6224. jsDate.prototype.getFullYear = function() {
  6225. return this.proxy.getFullYear();
  6226. };
  6227. /**
  6228. * Get the GMT offset in hours and minutes (e.g. +06:30)
  6229. *
  6230. * @returns {String}
  6231. */
  6232. jsDate.prototype.getGmtOffset = function() {
  6233. // divide the minutes offset by 60
  6234. var hours = this.proxy.getTimezoneOffset() / 60;
  6235. // decide if we are ahead of or behind GMT
  6236. var prefix = hours < 0 ? '+' : '-';
  6237. // remove the negative sign if any
  6238. hours = Math.abs(hours);
  6239. // add the +/- to the padded number of hours to : to the padded minutes
  6240. return prefix + addZeros(Math.floor(hours), 2) + ':' + addZeros((hours % 1) * 60, 2);
  6241. };
  6242. /**
  6243. * Implements Date functionality
  6244. */
  6245. jsDate.prototype.getHours = function() {
  6246. return this.proxy.getHours();
  6247. };
  6248. /**
  6249. * Get the current hour on a 12-hour scheme
  6250. *
  6251. * @returns {Integer}
  6252. */
  6253. jsDate.prototype.getHours12 = function() {
  6254. var hours = this.proxy.getHours();
  6255. return hours > 12 ? hours - 12 : (hours == 0 ? 12 : hours);
  6256. };
  6257. jsDate.prototype.getIsoWeek = function() {
  6258. var d = this.proxy;
  6259. var woy = d.getWeekOfYear();
  6260. var dow1_1 = (new Date('' + d.getFullYear() + '/1/1')).getDay();
  6261. // First week is 01 and not 00 as in the case of %U and %W,
  6262. // so we add 1 to the final result except if day 1 of the year
  6263. // is a Monday (then %W returns 01).
  6264. // We also need to subtract 1 if the day 1 of the year is
  6265. // Friday-Sunday, so the resulting equation becomes:
  6266. var idow = woy + (dow1_1 > 4 || dow1_1 <= 1 ? 0 : 1);
  6267. if(idow == 53 && (new Date('' + d.getFullYear() + '/12/31')).getDay() < 4)
  6268. {
  6269. idow = 1;
  6270. }
  6271. else if(idow === 0)
  6272. {
  6273. d = new jsDate(new Date('' + (d.getFullYear()-1) + '/12/31'));
  6274. idow = d.getIsoWeek();
  6275. }
  6276. d = null;
  6277. return idow;
  6278. };
  6279. /**
  6280. * Implements Date functionality
  6281. */
  6282. jsDate.prototype.getMilliseconds = function() {
  6283. return this.proxy.getMilliseconds();
  6284. };
  6285. /**
  6286. * Implements Date functionality
  6287. */
  6288. jsDate.prototype.getMinutes = function() {
  6289. return this.proxy.getMinutes();
  6290. };
  6291. /**
  6292. * Implements Date functionality
  6293. */
  6294. jsDate.prototype.getMonth = function() {
  6295. return this.proxy.getMonth();
  6296. };
  6297. /**
  6298. * Get the name of the current month
  6299. *
  6300. * @returns {String}
  6301. */
  6302. jsDate.prototype.getMonthName = function() {
  6303. return jsDate.regional[this.locale]["monthNames"][this.proxy.getMonth()];
  6304. };
  6305. /**
  6306. * Get the number of the current month, 1-12
  6307. *
  6308. * @returns {Integer}
  6309. */
  6310. jsDate.prototype.getMonthNumber = function() {
  6311. return this.proxy.getMonth() + 1;
  6312. };
  6313. /**
  6314. * Implements Date functionality
  6315. */
  6316. jsDate.prototype.getSeconds = function() {
  6317. return this.proxy.getSeconds();
  6318. };
  6319. /**
  6320. * Return a proper two-digit year integer
  6321. *
  6322. * @returns {Integer}
  6323. */
  6324. jsDate.prototype.getShortYear = function() {
  6325. return this.proxy.getYear() % 100;
  6326. };
  6327. /**
  6328. * Implements Date functionality
  6329. */
  6330. jsDate.prototype.getTime = function() {
  6331. return this.proxy.getTime();
  6332. };
  6333. /**
  6334. * Get the timezone abbreviation
  6335. *
  6336. * @returns {String} Abbreviation for the timezone
  6337. */
  6338. jsDate.prototype.getTimezoneAbbr = function() {
  6339. return this.proxy.toString().replace(/^.*\(([^)]+)\)$/, '$1');
  6340. };
  6341. /**
  6342. * Get the browser-reported name for the current timezone (e.g. MDT, Mountain Daylight Time)
  6343. *
  6344. * @returns {String}
  6345. */
  6346. jsDate.prototype.getTimezoneName = function() {
  6347. var match = /(?:\((.+)\)$| ([A-Z]{3}) )/.exec(this.toString());
  6348. return match[1] || match[2] || 'GMT' + this.getGmtOffset();
  6349. };
  6350. /**
  6351. * Implements Date functionality
  6352. */
  6353. jsDate.prototype.getTimezoneOffset = function() {
  6354. return this.proxy.getTimezoneOffset();
  6355. };
  6356. /**
  6357. * Get the week number of the given year, starting with the first Monday as the first week
  6358. * @returns {Integer} Week number (13 for the 13th week of the year).
  6359. */
  6360. jsDate.prototype.getWeekOfYear = function() {
  6361. var doy = this.getDayOfYear();
  6362. var rdow = 7 - this.getDayOfWeek();
  6363. var woy = parseInt((doy+rdow)/7, 10);
  6364. return woy;
  6365. };
  6366. /**
  6367. * Get the current date as a Unix timestamp
  6368. *
  6369. * @returns {Integer}
  6370. */
  6371. jsDate.prototype.getUnix = function() {
  6372. return Math.round(this.proxy.getTime() / 1000, 0);
  6373. };
  6374. /**
  6375. * Implements Date functionality
  6376. */
  6377. jsDate.prototype.getYear = function() {
  6378. return this.proxy.getYear();
  6379. };
  6380. /**
  6381. * Return a date one day ahead (or any other unit)
  6382. *
  6383. * @param {String} unit Optional, year | month | day | week | hour | minute | second | millisecond
  6384. * @returns {jsDate}
  6385. */
  6386. jsDate.prototype.next = function(unit) {
  6387. unit = unit || 'day';
  6388. return this.clone().add(1, unit);
  6389. };
  6390. /**
  6391. * Set the jsDate instance to a new date.
  6392. *
  6393. * @param {String | Number | Array | Date Object | jsDate Object | Options Object} arguments Optional arguments,
  6394. * either a parsable date/time string,
  6395. * a JavaScript timestamp, an array of numbers of form [year, month, day, hours, minutes, seconds, milliseconds],
  6396. * a Date object, jsDate Object or an options object of form {syntax: "perl", date:some Date} where all options are optional.
  6397. */
  6398. jsDate.prototype.set = function() {
  6399. switch ( arguments.length ) {
  6400. case 0:
  6401. this.proxy = new Date();
  6402. break;
  6403. case 1:
  6404. // other objects either won't have a _type property or,
  6405. // if they do, it shouldn't be set to "jsDate", so
  6406. // assume it is an options argument.
  6407. if (get_type(arguments[0]) == "[object Object]" && arguments[0]._type != "jsDate") {
  6408. var opts = this.options = arguments[0];
  6409. this.syntax = opts.syntax || this.syntax;
  6410. this.defaultCentury = opts.defaultCentury || this.defaultCentury;
  6411. this.proxy = jsDate.createDate(opts.date);
  6412. }
  6413. else {
  6414. this.proxy = jsDate.createDate(arguments[0]);
  6415. }
  6416. break;
  6417. default:
  6418. var a = [];
  6419. for ( var i=0; i<arguments.length; i++ ) {
  6420. a.push(arguments[i]);
  6421. }
  6422. this.proxy = new Date( this.utcOffset );
  6423. this.proxy.setFullYear.apply( this.proxy, a.slice(0,3) );
  6424. if ( a.slice(3).length ) {
  6425. this.proxy.setHours.apply( this.proxy, a.slice(3) );
  6426. }
  6427. break;
  6428. }
  6429. };
  6430. /**
  6431. * Sets the day of the month for a specified date according to local time.
  6432. * @param {Integer} dayValue An integer from 1 to 31, representing the day of the month.
  6433. */
  6434. jsDate.prototype.setDate = function(n) {
  6435. return this.proxy.setDate(n);
  6436. };
  6437. /**
  6438. * Sets the full year for a specified date according to local time.
  6439. * @param {Integer} yearValue The numeric value of the year, for example, 1995.
  6440. * @param {Integer} monthValue Optional, between 0 and 11 representing the months January through December.
  6441. * @param {Integer} dayValue Optional, between 1 and 31 representing the day of the month. If you specify the dayValue parameter, you must also specify the monthValue.
  6442. */
  6443. jsDate.prototype.setFullYear = function() {
  6444. return this.proxy.setFullYear.apply(this.proxy, arguments);
  6445. };
  6446. /**
  6447. * Sets the hours for a specified date according to local time.
  6448. *
  6449. * @param {Integer} hoursValue An integer between 0 and 23, representing the hour.
  6450. * @param {Integer} minutesValue Optional, An integer between 0 and 59, representing the minutes.
  6451. * @param {Integer} secondsValue Optional, An integer between 0 and 59, representing the seconds.
  6452. * If you specify the secondsValue parameter, you must also specify the minutesValue.
  6453. * @param {Integer} msValue Optional, A number between 0 and 999, representing the milliseconds.
  6454. * If you specify the msValue parameter, you must also specify the minutesValue and secondsValue.
  6455. */
  6456. jsDate.prototype.setHours = function() {
  6457. return this.proxy.setHours.apply(this.proxy, arguments);
  6458. };
  6459. /**
  6460. * Implements Date functionality
  6461. */
  6462. jsDate.prototype.setMilliseconds = function(n) {
  6463. return this.proxy.setMilliseconds(n);
  6464. };
  6465. /**
  6466. * Implements Date functionality
  6467. */
  6468. jsDate.prototype.setMinutes = function() {
  6469. return this.proxy.setMinutes.apply(this.proxy, arguments);
  6470. };
  6471. /**
  6472. * Implements Date functionality
  6473. */
  6474. jsDate.prototype.setMonth = function() {
  6475. return this.proxy.setMonth.apply(this.proxy, arguments);
  6476. };
  6477. /**
  6478. * Implements Date functionality
  6479. */
  6480. jsDate.prototype.setSeconds = function() {
  6481. return this.proxy.setSeconds.apply(this.proxy, arguments);
  6482. };
  6483. /**
  6484. * Implements Date functionality
  6485. */
  6486. jsDate.prototype.setTime = function(n) {
  6487. return this.proxy.setTime(n);
  6488. };
  6489. /**
  6490. * Implements Date functionality
  6491. */
  6492. jsDate.prototype.setYear = function() {
  6493. return this.proxy.setYear.apply(this.proxy, arguments);
  6494. };
  6495. /**
  6496. * Provide a formatted string representation of this date.
  6497. *
  6498. * @param {String} formatString A format string.
  6499. * See: {@link jsDate.formats}.
  6500. * @returns {String} Date String.
  6501. */
  6502. jsDate.prototype.strftime = function(formatString) {
  6503. formatString = formatString || this.formatString || jsDate.regional[this.locale]['formatString'];
  6504. return jsDate.strftime(this, formatString, this.syntax);
  6505. };
  6506. /**
  6507. * Return a String representation of this jsDate object.
  6508. * @returns {String} Date string.
  6509. */
  6510. jsDate.prototype.toString = function() {
  6511. return this.proxy.toString();
  6512. };
  6513. /**
  6514. * Convert the current date to an 8-digit integer (%Y%m%d)
  6515. *
  6516. * @returns {Integer}
  6517. */
  6518. jsDate.prototype.toYmdInt = function() {
  6519. return (this.proxy.getFullYear() * 10000) + (this.getMonthNumber() * 100) + this.proxy.getDate();
  6520. };
  6521. /**
  6522. * @namespace Holds localizations for month/day names.
  6523. * <p>jsDate attempts to detect locale when loaded and defaults to 'en'.
  6524. * If a localization is detected which is not available, jsDate defaults to 'en'.
  6525. * Additional localizations can be added after jsDate loads. After adding a localization,
  6526. * call the jsDate.regional.getLocale() method. Currently, en, fr and de are defined.</p>
  6527. *
  6528. * <p>Localizations must be an object and have the following properties defined: monthNames, monthNamesShort, dayNames, dayNamesShort and Localizations are added like:</p>
  6529. * <pre class="code">
  6530. * jsDate.regional['en'] = {
  6531. * monthNames : 'January February March April May June July August September October November December'.split(' '),
  6532. * monthNamesShort : 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' '),
  6533. * dayNames : 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split(' '),
  6534. * dayNamesShort : 'Sun Mon Tue Wed Thu Fri Sat'.split(' ')
  6535. * };
  6536. * </pre>
  6537. * <p>After adding localizations, call <code>jsDate.regional.getLocale();</code> to update the locale setting with the
  6538. * new localizations.</p>
  6539. */
  6540. jsDate.regional = {
  6541. 'en': {
  6542. monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December'],
  6543. monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  6544. dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  6545. dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  6546. formatString: '%Y-%m-%d %H:%M:%S'
  6547. },
  6548. 'fr': {
  6549. monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
  6550. monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun','Jul','Aoû','Sep','Oct','Nov','Déc'],
  6551. dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
  6552. dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
  6553. formatString: '%Y-%m-%d %H:%M:%S'
  6554. },
  6555. 'de': {
  6556. monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
  6557. monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'],
  6558. dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
  6559. dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
  6560. formatString: '%Y-%m-%d %H:%M:%S'
  6561. },
  6562. 'es': {
  6563. monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio', 'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
  6564. monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun', 'Jul','Ago','Sep','Oct','Nov','Dic'],
  6565. dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
  6566. dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
  6567. formatString: '%Y-%m-%d %H:%M:%S'
  6568. },
  6569. 'ru': {
  6570. monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
  6571. monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн','Июл','Авг','Сен','Окт','Ноя','Дек'],
  6572. dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
  6573. dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
  6574. formatString: '%Y-%m-%d %H:%M:%S'
  6575. },
  6576. 'ar': {
  6577. monthNames: ['كانون الثاني', 'شباط', 'آذار', 'نيسان', 'آذار', 'حزيران','تموز', 'آب', 'أيلول', 'تشرين الأول', 'تشرين الثاني', 'كانون الأول'],
  6578. monthNamesShort: ['1','2','3','4','5','6','7','8','9','10','11','12'],
  6579. dayNames: ['السبت', 'الأحد', 'الاثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة'],
  6580. dayNamesShort: ['سبت', 'أحد', 'اثنين', 'ثلاثاء', 'أربعاء', 'خميس', 'جمعة'],
  6581. formatString: '%Y-%m-%d %H:%M:%S'
  6582. },
  6583. 'pt': {
  6584. monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
  6585. monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
  6586. dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','S&aacute;bado'],
  6587. dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','S&aacute;b'],
  6588. formatString: '%Y-%m-%d %H:%M:%S'
  6589. },
  6590. 'pt-BR': {
  6591. monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho', 'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
  6592. monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
  6593. dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','S&aacute;bado'],
  6594. dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','S&aacute;b'],
  6595. formatString: '%Y-%m-%d %H:%M:%S'
  6596. }
  6597. };
  6598. // Set english variants to 'en'
  6599. jsDate.regional['en-US'] = jsDate.regional['en-GB'] = jsDate.regional['en'];
  6600. /**
  6601. * Try to determine the users locale based on the lang attribute of the html page. Defaults to 'en'
  6602. * if it cannot figure out a locale of if the locale does not have a localization defined.
  6603. * @returns {String} locale
  6604. */
  6605. jsDate.regional.getLocale = function () {
  6606. var l = jsDate.config.defaultLocale;
  6607. if ( document && document.getElementsByTagName('html') && document.getElementsByTagName('html')[0].lang ) {
  6608. l = document.getElementsByTagName('html')[0].lang;
  6609. if (!jsDate.regional.hasOwnProperty(l)) {
  6610. l = jsDate.config.defaultLocale;
  6611. }
  6612. }
  6613. return l;
  6614. };
  6615. // ms in day
  6616. var day = 24 * 60 * 60 * 1000;
  6617. // padd a number with zeros
  6618. var addZeros = function(num, digits) {
  6619. num = String(num);
  6620. var i = digits - num.length;
  6621. var s = String(Math.pow(10, i)).slice(1);
  6622. return s.concat(num);
  6623. };
  6624. // representations used for calculating differences between dates.
  6625. // This borrows heavily from Ken Snyder's work.
  6626. var multipliers = {
  6627. millisecond: 1,
  6628. second: 1000,
  6629. minute: 60 * 1000,
  6630. hour: 60 * 60 * 1000,
  6631. day: day,
  6632. week: 7 * day,
  6633. month: {
  6634. // add a number of months
  6635. add: function(d, number) {
  6636. // add any years needed (increments of 12)
  6637. multipliers.year.add(d, Math[number > 0 ? 'floor' : 'ceil'](number / 12));
  6638. // ensure that we properly wrap betwen December and January
  6639. var prevMonth = d.getMonth() + (number % 12);
  6640. if (prevMonth == 12) {
  6641. prevMonth = 0;
  6642. d.setYear(d.getFullYear() + 1);
  6643. } else if (prevMonth == -1) {
  6644. prevMonth = 11;
  6645. d.setYear(d.getFullYear() - 1);
  6646. }
  6647. d.setMonth(prevMonth);
  6648. },
  6649. // get the number of months between two Date objects (decimal to the nearest day)
  6650. diff: function(d1, d2) {
  6651. // get the number of years
  6652. var diffYears = d1.getFullYear() - d2.getFullYear();
  6653. // get the number of remaining months
  6654. var diffMonths = d1.getMonth() - d2.getMonth() + (diffYears * 12);
  6655. // get the number of remaining days
  6656. var diffDays = d1.getDate() - d2.getDate();
  6657. // return the month difference with the days difference as a decimal
  6658. return diffMonths + (diffDays / 30);
  6659. }
  6660. },
  6661. year: {
  6662. // add a number of years
  6663. add: function(d, number) {
  6664. d.setYear(d.getFullYear() + Math[number > 0 ? 'floor' : 'ceil'](number));
  6665. },
  6666. // get the number of years between two Date objects (decimal to the nearest day)
  6667. diff: function(d1, d2) {
  6668. return multipliers.month.diff(d1, d2) / 12;
  6669. }
  6670. }
  6671. };
  6672. //
  6673. // Alias each multiplier with an 's' to allow 'year' and 'years' for example.
  6674. // This comes from Ken Snyders work.
  6675. //
  6676. for (var unit in multipliers) {
  6677. if (unit.substring(unit.length - 1) != 's') { // IE will iterate newly added properties :|
  6678. multipliers[unit + 's'] = multipliers[unit];
  6679. }
  6680. }
  6681. //
  6682. // take a jsDate instance and a format code and return the formatted value.
  6683. // This is a somewhat modified version of Ken Snyder's method.
  6684. //
  6685. var format = function(d, code, syntax) {
  6686. // if shorcut codes are used, recursively expand those.
  6687. if (jsDate.formats[syntax]["shortcuts"][code]) {
  6688. return jsDate.strftime(d, jsDate.formats[syntax]["shortcuts"][code], syntax);
  6689. } else {
  6690. // get the format code function and addZeros() argument
  6691. var getter = (jsDate.formats[syntax]["codes"][code] || '').split('.');
  6692. var nbr = d['get' + getter[0]] ? d['get' + getter[0]]() : '';
  6693. if (getter[1]) {
  6694. nbr = addZeros(nbr, getter[1]);
  6695. }
  6696. return nbr;
  6697. }
  6698. };
  6699. /**
  6700. * @static
  6701. * Static function for convert a date to a string according to a given format. Also acts as namespace for strftime format codes.
  6702. * <p>strftime formatting can be accomplished without creating a jsDate object by calling jsDate.strftime():</p>
  6703. * <pre class="code">
  6704. * var formattedDate = jsDate.strftime('Feb 8, 2006 8:48:32', '%Y-%m-%d %H:%M:%S');
  6705. * </pre>
  6706. * @param {String | Number | Array | jsDate&nbsp;Object | Date&nbsp;Object} date A parsable date string, JavaScript time stamp, Array of form [year, month, day, hours, minutes, seconds, milliseconds], jsDate Object or Date object.
  6707. * @param {String} formatString String with embedded date formatting codes.
  6708. * See: {@link jsDate.formats}.
  6709. * @param {String} syntax Optional syntax to use [default perl].
  6710. * @param {String} locale Optional locale to use.
  6711. * @returns {String} Formatted representation of the date.
  6712. */
  6713. //
  6714. // Logic as implemented here is very similar to Ken Snyder's Date Instance Methods.
  6715. //
  6716. jsDate.strftime = function(d, formatString, syntax, locale) {
  6717. var syn = 'perl';
  6718. var loc = jsDate.regional.getLocale();
  6719. // check if syntax and locale are available or reversed
  6720. if (syntax && jsDate.formats.hasOwnProperty(syntax)) {
  6721. syn = syntax;
  6722. }
  6723. else if (syntax && jsDate.regional.hasOwnProperty(syntax)) {
  6724. loc = syntax;
  6725. }
  6726. if (locale && jsDate.formats.hasOwnProperty(locale)) {
  6727. syn = locale;
  6728. }
  6729. else if (locale && jsDate.regional.hasOwnProperty(locale)) {
  6730. loc = locale;
  6731. }
  6732. if (get_type(d) != "[object Object]" || d._type != "jsDate") {
  6733. d = new jsDate(d);
  6734. d.locale = loc;
  6735. }
  6736. if (!formatString) {
  6737. formatString = d.formatString || jsDate.regional[loc]['formatString'];
  6738. }
  6739. // default the format string to year-month-day
  6740. var source = formatString || '%Y-%m-%d',
  6741. result = '',
  6742. match;
  6743. // replace each format code
  6744. while (source.length > 0) {
  6745. if (match = source.match(jsDate.formats[syn].codes.matcher)) {
  6746. result += source.slice(0, match.index);
  6747. result += (match[1] || '') + format(d, match[2], syn);
  6748. source = source.slice(match.index + match[0].length);
  6749. } else {
  6750. result += source;
  6751. source = '';
  6752. }
  6753. }
  6754. return result;
  6755. };
  6756. /**
  6757. * @namespace
  6758. * Namespace to hold format codes and format shortcuts. "perl" and "php" format codes
  6759. * and shortcuts are defined by default. Additional codes and shortcuts can be
  6760. * added like:
  6761. *
  6762. * <pre class="code">
  6763. * jsDate.formats["perl"] = {
  6764. * "codes": {
  6765. * matcher: /someregex/,
  6766. * Y: "fullYear", // name of "get" method without the "get",
  6767. * ..., // more codes
  6768. * },
  6769. * "shortcuts": {
  6770. * F: '%Y-%m-%d',
  6771. * ..., // more shortcuts
  6772. * }
  6773. * };
  6774. * </pre>
  6775. *
  6776. * <p>Additionally, ISO and SQL shortcuts are defined and can be accesses via:
  6777. * <code>jsDate.formats.ISO</code> and <code>jsDate.formats.SQL</code>
  6778. */
  6779. jsDate.formats = {
  6780. ISO:'%Y-%m-%dT%H:%M:%S.%N%G',
  6781. SQL:'%Y-%m-%d %H:%M:%S'
  6782. };
  6783. /**
  6784. * Perl format codes and shortcuts for strftime.
  6785. *
  6786. * A hash (object) of codes where each code must be an array where the first member is
  6787. * the name of a Date.prototype or jsDate.prototype function to call
  6788. * and optionally a second member indicating the number to pass to addZeros()
  6789. *
  6790. * <p>The following format codes are defined:</p>
  6791. *
  6792. * <pre class="code">
  6793. * Code Result Description
  6794. * == Years ==
  6795. * %Y 2008 Four-digit year
  6796. * %y 08 Two-digit year
  6797. *
  6798. * == Months ==
  6799. * %m 09 Two-digit month
  6800. * %#m 9 One or two-digit month
  6801. * %B September Full month name
  6802. * %b Sep Abbreviated month name
  6803. *
  6804. * == Days ==
  6805. * %d 05 Two-digit day of month
  6806. * %#d 5 One or two-digit day of month
  6807. * %e 5 One or two-digit day of month
  6808. * %A Sunday Full name of the day of the week
  6809. * %a Sun Abbreviated name of the day of the week
  6810. * %w 0 Number of the day of the week (0 = Sunday, 6 = Saturday)
  6811. *
  6812. * == Hours ==
  6813. * %H 23 Hours in 24-hour format (two digits)
  6814. * %#H 3 Hours in 24-hour integer format (one or two digits)
  6815. * %I 11 Hours in 12-hour format (two digits)
  6816. * %#I 3 Hours in 12-hour integer format (one or two digits)
  6817. * %p PM AM or PM
  6818. *
  6819. * == Minutes ==
  6820. * %M 09 Minutes (two digits)
  6821. * %#M 9 Minutes (one or two digits)
  6822. *
  6823. * == Seconds ==
  6824. * %S 02 Seconds (two digits)
  6825. * %#S 2 Seconds (one or two digits)
  6826. * %s 1206567625723 Unix timestamp (Seconds past 1970-01-01 00:00:00)
  6827. *
  6828. * == Milliseconds ==
  6829. * %N 008 Milliseconds (three digits)
  6830. * %#N 8 Milliseconds (one to three digits)
  6831. *
  6832. * == Timezone ==
  6833. * %O 360 difference in minutes between local time and GMT
  6834. * %Z Mountain Standard Time Name of timezone as reported by browser
  6835. * %G 06:00 Hours and minutes between GMT
  6836. *
  6837. * == Shortcuts ==
  6838. * %F 2008-03-26 %Y-%m-%d
  6839. * %T 05:06:30 %H:%M:%S
  6840. * %X 05:06:30 %H:%M:%S
  6841. * %x 03/26/08 %m/%d/%y
  6842. * %D 03/26/08 %m/%d/%y
  6843. * %#c Wed Mar 26 15:31:00 2008 %a %b %e %H:%M:%S %Y
  6844. * %v 3-Sep-2008 %e-%b-%Y
  6845. * %R 15:31 %H:%M
  6846. * %r 03:31:00 PM %I:%M:%S %p
  6847. *
  6848. * == Characters ==
  6849. * %n \n Newline
  6850. * %t \t Tab
  6851. * %% % Percent Symbol
  6852. * </pre>
  6853. *
  6854. * <p>Formatting shortcuts that will be translated into their longer version.
  6855. * Be sure that format shortcuts do not refer to themselves: this will cause an infinite loop.</p>
  6856. *
  6857. * <p>Format codes and format shortcuts can be redefined after the jsDate
  6858. * module is imported.</p>
  6859. *
  6860. * <p>Note that if you redefine the whole hash (object), you must supply a "matcher"
  6861. * regex for the parser. The default matcher is:</p>
  6862. *
  6863. * <code>/()%(#?(%|[a-z]))/i</code>
  6864. *
  6865. * <p>which corresponds to the Perl syntax used by default.</p>
  6866. *
  6867. * <p>By customizing the matcher and format codes, nearly any strftime functionality is possible.</p>
  6868. */
  6869. jsDate.formats.perl = {
  6870. codes: {
  6871. //
  6872. // 2-part regex matcher for format codes
  6873. //
  6874. // first match must be the character before the code (to account for escaping)
  6875. // second match must be the format code character(s)
  6876. //
  6877. matcher: /()%(#?(%|[a-z]))/i,
  6878. // year
  6879. Y: 'FullYear',
  6880. y: 'ShortYear.2',
  6881. // month
  6882. m: 'MonthNumber.2',
  6883. '#m': 'MonthNumber',
  6884. B: 'MonthName',
  6885. b: 'AbbrMonthName',
  6886. // day
  6887. d: 'Date.2',
  6888. '#d': 'Date',
  6889. e: 'Date',
  6890. A: 'DayName',
  6891. a: 'AbbrDayName',
  6892. w: 'Day',
  6893. // hours
  6894. H: 'Hours.2',
  6895. '#H': 'Hours',
  6896. I: 'Hours12.2',
  6897. '#I': 'Hours12',
  6898. p: 'AMPM',
  6899. // minutes
  6900. M: 'Minutes.2',
  6901. '#M': 'Minutes',
  6902. // seconds
  6903. S: 'Seconds.2',
  6904. '#S': 'Seconds',
  6905. s: 'Unix',
  6906. // milliseconds
  6907. N: 'Milliseconds.3',
  6908. '#N': 'Milliseconds',
  6909. // timezone
  6910. O: 'TimezoneOffset',
  6911. Z: 'TimezoneName',
  6912. G: 'GmtOffset'
  6913. },
  6914. shortcuts: {
  6915. // date
  6916. F: '%Y-%m-%d',
  6917. // time
  6918. T: '%H:%M:%S',
  6919. X: '%H:%M:%S',
  6920. // local format date
  6921. x: '%m/%d/%y',
  6922. D: '%m/%d/%y',
  6923. // local format extended
  6924. '#c': '%a %b %e %H:%M:%S %Y',
  6925. // local format short
  6926. v: '%e-%b-%Y',
  6927. R: '%H:%M',
  6928. r: '%I:%M:%S %p',
  6929. // tab and newline
  6930. t: '\t',
  6931. n: '\n',
  6932. '%': '%'
  6933. }
  6934. };
  6935. /**
  6936. * PHP format codes and shortcuts for strftime.
  6937. *
  6938. * A hash (object) of codes where each code must be an array where the first member is
  6939. * the name of a Date.prototype or jsDate.prototype function to call
  6940. * and optionally a second member indicating the number to pass to addZeros()
  6941. *
  6942. * <p>The following format codes are defined:</p>
  6943. *
  6944. * <pre class="code">
  6945. * Code Result Description
  6946. * === Days ===
  6947. * %a Sun through Sat An abbreviated textual representation of the day
  6948. * %A Sunday - Saturday A full textual representation of the day
  6949. * %d 01 to 31 Two-digit day of the month (with leading zeros)
  6950. * %e 1 to 31 Day of the month, with a space preceding single digits.
  6951. * %j 001 to 366 Day of the year, 3 digits with leading zeros
  6952. * %u 1 - 7 (Mon - Sun) ISO-8601 numeric representation of the day of the week
  6953. * %w 0 - 6 (Sun - Sat) Numeric representation of the day of the week
  6954. *
  6955. * === Week ===
  6956. * %U 13 Full Week number, starting with the first Sunday as the first week
  6957. * %V 01 through 53 ISO-8601:1988 week number, starting with the first week of the year
  6958. * with at least 4 weekdays, with Monday being the start of the week
  6959. * %W 46 A numeric representation of the week of the year,
  6960. * starting with the first Monday as the first week
  6961. * === Month ===
  6962. * %b Jan through Dec Abbreviated month name, based on the locale
  6963. * %B January - December Full month name, based on the locale
  6964. * %h Jan through Dec Abbreviated month name, based on the locale (an alias of %b)
  6965. * %m 01 - 12 (Jan - Dec) Two digit representation of the month
  6966. *
  6967. * === Year ===
  6968. * %C 19 Two digit century (year/100, truncated to an integer)
  6969. * %y 09 for 2009 Two digit year
  6970. * %Y 2038 Four digit year
  6971. *
  6972. * === Time ===
  6973. * %H 00 through 23 Two digit representation of the hour in 24-hour format
  6974. * %I 01 through 12 Two digit representation of the hour in 12-hour format
  6975. * %l 1 through 12 Hour in 12-hour format, with a space preceeding single digits
  6976. * %M 00 through 59 Two digit representation of the minute
  6977. * %p AM/PM UPPER-CASE 'AM' or 'PM' based on the given time
  6978. * %P am/pm lower-case 'am' or 'pm' based on the given time
  6979. * %r 09:34:17 PM Same as %I:%M:%S %p
  6980. * %R 00:35 Same as %H:%M
  6981. * %S 00 through 59 Two digit representation of the second
  6982. * %T 21:34:17 Same as %H:%M:%S
  6983. * %X 03:59:16 Preferred time representation based on locale, without the date
  6984. * %z -0500 or EST Either the time zone offset from UTC or the abbreviation
  6985. * %Z -0500 or EST The time zone offset/abbreviation option NOT given by %z
  6986. *
  6987. * === Time and Date ===
  6988. * %D 02/05/09 Same as %m/%d/%y
  6989. * %F 2009-02-05 Same as %Y-%m-%d (commonly used in database datestamps)
  6990. * %s 305815200 Unix Epoch Time timestamp (same as the time() function)
  6991. * %x 02/05/09 Preferred date representation, without the time
  6992. *
  6993. * === Miscellaneous ===
  6994. * %n --- A newline character (\n)
  6995. * %t --- A Tab character (\t)
  6996. * %% --- A literal percentage character (%)
  6997. * </pre>
  6998. */
  6999. jsDate.formats.php = {
  7000. codes: {
  7001. //
  7002. // 2-part regex matcher for format codes
  7003. //
  7004. // first match must be the character before the code (to account for escaping)
  7005. // second match must be the format code character(s)
  7006. //
  7007. matcher: /()%((%|[a-z]))/i,
  7008. // day
  7009. a: 'AbbrDayName',
  7010. A: 'DayName',
  7011. d: 'Date.2',
  7012. e: 'Date',
  7013. j: 'DayOfYear.3',
  7014. u: 'DayOfWeek',
  7015. w: 'Day',
  7016. // week
  7017. U: 'FullWeekOfYear.2',
  7018. V: 'IsoWeek.2',
  7019. W: 'WeekOfYear.2',
  7020. // month
  7021. b: 'AbbrMonthName',
  7022. B: 'MonthName',
  7023. m: 'MonthNumber.2',
  7024. h: 'AbbrMonthName',
  7025. // year
  7026. C: 'Century.2',
  7027. y: 'ShortYear.2',
  7028. Y: 'FullYear',
  7029. // time
  7030. H: 'Hours.2',
  7031. I: 'Hours12.2',
  7032. l: 'Hours12',
  7033. p: 'AMPM',
  7034. P: 'AmPm',
  7035. M: 'Minutes.2',
  7036. S: 'Seconds.2',
  7037. s: 'Unix',
  7038. O: 'TimezoneOffset',
  7039. z: 'GmtOffset',
  7040. Z: 'TimezoneAbbr'
  7041. },
  7042. shortcuts: {
  7043. D: '%m/%d/%y',
  7044. F: '%Y-%m-%d',
  7045. T: '%H:%M:%S',
  7046. X: '%H:%M:%S',
  7047. x: '%m/%d/%y',
  7048. R: '%H:%M',
  7049. r: '%I:%M:%S %p',
  7050. t: '\t',
  7051. n: '\n',
  7052. '%': '%'
  7053. }
  7054. };
  7055. //
  7056. // Conceptually, the logic implemented here is similar to Ken Snyder's Date Instance Methods.
  7057. // I use his idea of a set of parsers which can be regular expressions or functions,
  7058. // iterating through those, and then seeing if Date.parse() will create a date.
  7059. // The parser expressions and functions are a little different and some bugs have been
  7060. // worked out. Also, a lot of "pre-parsing" is done to fix implementation
  7061. // variations of Date.parse() between browsers.
  7062. //
  7063. jsDate.createDate = function(date) {
  7064. // if passing in multiple arguments, try Date constructor
  7065. if (date == null) {
  7066. return new Date();
  7067. }
  7068. // If the passed value is already a date object, return it
  7069. if (date instanceof Date) {
  7070. return date;
  7071. }
  7072. // if (typeof date == 'number') return new Date(date * 1000);
  7073. // If the passed value is an integer, interpret it as a javascript timestamp
  7074. if (typeof date == 'number') {
  7075. return new Date(date);
  7076. }
  7077. // Before passing strings into Date.parse(), have to normalize them for certain conditions.
  7078. // If strings are not formatted staccording to the EcmaScript spec, results from Date parse will be implementation dependent.
  7079. //
  7080. // For example:
  7081. // * FF and Opera assume 2 digit dates are pre y2k, Chome assumes <50 is pre y2k, 50+ is 21st century.
  7082. // * Chrome will correctly parse '1984-1-25' into localtime, FF and Opera will not parse.
  7083. // * Both FF, Chrome and Opera will parse '1984/1/25' into localtime.
  7084. // remove leading and trailing spaces
  7085. var parsable = String(date).replace(/^\s*(.+)\s*$/g, '$1');
  7086. // replace dahses (-) with slashes (/) in dates like n[nnn]/n[n]/n[nnn]
  7087. parsable = parsable.replace(/^([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,4})/, "$1/$2/$3");
  7088. /////////
  7089. // Need to check for '15-Dec-09' also.
  7090. // FF will not parse, but Chrome will.
  7091. // Chrome will set date to 2009 as well.
  7092. /////////
  7093. // first check for 'dd-mmm-yyyy' or 'dd/mmm/yyyy' like '15-Dec-2010'
  7094. parsable = parsable.replace(/^(3[01]|[0-2]?\d)[-\/]([a-z]{3,})[-\/](\d{4})/i, "$1 $2 $3");
  7095. // Now check for 'dd-mmm-yy' or 'dd/mmm/yy' and normalize years to default century.
  7096. var match = parsable.match(/^(3[01]|[0-2]?\d)[-\/]([a-z]{3,})[-\/](\d{2})\D*/i);
  7097. if (match && match.length > 3) {
  7098. var m3 = parseFloat(match[3]);
  7099. var ny = jsDate.config.defaultCentury + m3;
  7100. ny = String(ny);
  7101. // now replace 2 digit year with 4 digit year
  7102. parsable = parsable.replace(/^(3[01]|[0-2]?\d)[-\/]([a-z]{3,})[-\/](\d{2})\D*/i, match[1] +' '+ match[2] +' '+ ny);
  7103. }
  7104. // Check for '1/19/70 8:14PM'
  7105. // where starts with mm/dd/yy or yy/mm/dd and have something after
  7106. // Check if 1st postiion is greater than 31, assume it is year.
  7107. // Assme all 2 digit years are 1900's.
  7108. // Finally, change them into US style mm/dd/yyyy representations.
  7109. match = parsable.match(/^([0-9]{1,2})[-\/]([0-9]{1,2})[-\/]([0-9]{1,2})[^0-9]/);
  7110. function h1(parsable, match) {
  7111. var m1 = parseFloat(match[1]);
  7112. var m2 = parseFloat(match[2]);
  7113. var m3 = parseFloat(match[3]);
  7114. var cent = jsDate.config.defaultCentury;
  7115. var ny, nd, nm, str;
  7116. if (m1 > 31) { // first number is a year
  7117. nd = m3;
  7118. nm = m2;
  7119. ny = cent + m1;
  7120. }
  7121. else { // last number is the year
  7122. nd = m2;
  7123. nm = m1;
  7124. ny = cent + m3;
  7125. }
  7126. str = nm+'/'+nd+'/'+ny;
  7127. // now replace 2 digit year with 4 digit year
  7128. return parsable.replace(/^([0-9]{1,2})[-\/]([0-9]{1,2})[-\/]([0-9]{1,2})/, str);
  7129. }
  7130. if (match && match.length > 3) {
  7131. parsable = h1(parsable, match);
  7132. }
  7133. // Now check for '1/19/70' with nothing after and do as above
  7134. var match = parsable.match(/^([0-9]{1,2})[-\/]([0-9]{1,2})[-\/]([0-9]{1,2})$/);
  7135. if (match && match.length > 3) {
  7136. parsable = h1(parsable, match);
  7137. }
  7138. var i = 0;
  7139. var length = jsDate.matchers.length;
  7140. var pattern;
  7141. var current = parsable;
  7142. while (i < length) {
  7143. ms = Date.parse(current);
  7144. if (!isNaN(ms)) {
  7145. return new Date(ms);
  7146. }
  7147. pattern = jsDate.matchers[i];
  7148. if (typeof pattern == 'function') {
  7149. obj = pattern.call(jsDate, current);
  7150. if (obj instanceof Date) {
  7151. return obj;
  7152. }
  7153. } else {
  7154. current = parsable.replace(pattern[0], pattern[1]);
  7155. }
  7156. i++;
  7157. }
  7158. return NaN;
  7159. };
  7160. /**
  7161. * @static
  7162. * Handy static utility function to return the number of days in a given month.
  7163. * @param {Integer} year Year
  7164. * @param {Integer} month Month (1-12)
  7165. * @returns {Integer} Number of days in the month.
  7166. */
  7167. //
  7168. // handy utility method Borrowed right from Ken Snyder's Date Instance Mehtods.
  7169. //
  7170. jsDate.daysInMonth = function(year, month) {
  7171. if (month == 2) {
  7172. return new Date(year, 1, 29).getDate() == 29 ? 29 : 28;
  7173. }
  7174. return [undefined,31,undefined,31,30,31,30,31,31,30,31,30,31][month];
  7175. };
  7176. //
  7177. // An Array of regular expressions or functions that will attempt to match the date string.
  7178. // Functions are called with scope of a jsDate instance.
  7179. //
  7180. jsDate.matchers = [
  7181. // convert dd.mmm.yyyy to mm/dd/yyyy (world date to US date).
  7182. [/(3[01]|[0-2]\d)\s*\.\s*(1[0-2]|0\d)\s*\.\s*([1-9]\d{3})/, '$2/$1/$3'],
  7183. // convert yyyy-mm-dd to mm/dd/yyyy (ISO date to US date).
  7184. [/([1-9]\d{3})\s*-\s*(1[0-2]|0\d)\s*-\s*(3[01]|[0-2]\d)/, '$2/$3/$1'],
  7185. // Handle 12 hour or 24 hour time with milliseconds am/pm and optional date part.
  7186. function(str) {
  7187. var match = str.match(/^(?:(.+)\s+)?([012]?\d)(?:\s*\:\s*(\d\d))?(?:\s*\:\s*(\d\d(\.\d*)?))?\s*(am|pm)?\s*$/i);
  7188. // opt. date hour opt. minute opt. second opt. msec opt. am or pm
  7189. if (match) {
  7190. if (match[1]) {
  7191. var d = this.createDate(match[1]);
  7192. if (isNaN(d)) {
  7193. return;
  7194. }
  7195. } else {
  7196. var d = new Date();
  7197. d.setMilliseconds(0);
  7198. }
  7199. var hour = parseFloat(match[2]);
  7200. if (match[6]) {
  7201. hour = match[6].toLowerCase() == 'am' ? (hour == 12 ? 0 : hour) : (hour == 12 ? 12 : hour + 12);
  7202. }
  7203. d.setHours(hour, parseInt(match[3] || 0, 10), parseInt(match[4] || 0, 10), ((parseFloat(match[5] || 0)) || 0)*1000);
  7204. return d;
  7205. }
  7206. else {
  7207. return str;
  7208. }
  7209. },
  7210. // Handle ISO timestamp with time zone.
  7211. function(str) {
  7212. var match = str.match(/^(?:(.+))[T|\s+]([012]\d)(?:\:(\d\d))(?:\:(\d\d))(?:\.\d+)([\+\-]\d\d\:\d\d)$/i);
  7213. if (match) {
  7214. if (match[1]) {
  7215. var d = this.createDate(match[1]);
  7216. if (isNaN(d)) {
  7217. return;
  7218. }
  7219. } else {
  7220. var d = new Date();
  7221. d.setMilliseconds(0);
  7222. }
  7223. var hour = parseFloat(match[2]);
  7224. d.setHours(hour, parseInt(match[3], 10), parseInt(match[4], 10), parseFloat(match[5])*1000);
  7225. return d;
  7226. }
  7227. else {
  7228. return str;
  7229. }
  7230. },
  7231. // Try to match ambiguous strings like 12/8/22.
  7232. // Use FF date assumption that 2 digit years are 20th century (i.e. 1900's).
  7233. // This may be redundant with pre processing of date already performed.
  7234. function(str) {
  7235. var match = str.match(/^([0-3]?\d)\s*[-\/.\s]{1}\s*([a-zA-Z]{3,9})\s*[-\/.\s]{1}\s*([0-3]?\d)$/);
  7236. if (match) {
  7237. var d = new Date();
  7238. var cent = jsDate.config.defaultCentury;
  7239. var m1 = parseFloat(match[1]);
  7240. var m3 = parseFloat(match[3]);
  7241. var ny, nd, nm;
  7242. if (m1 > 31) { // first number is a year
  7243. nd = m3;
  7244. ny = cent + m1;
  7245. }
  7246. else { // last number is the year
  7247. nd = m1;
  7248. ny = cent + m3;
  7249. }
  7250. var nm = inArray(match[2], jsDate.regional[this.locale]["monthNamesShort"]);
  7251. if (nm == -1) {
  7252. nm = inArray(match[2], jsDate.regional[this.locale]["monthNames"]);
  7253. }
  7254. d.setFullYear(ny, nm, nd);
  7255. d.setHours(0,0,0,0);
  7256. return d;
  7257. }
  7258. else {
  7259. return str;
  7260. }
  7261. }
  7262. ];
  7263. //
  7264. // I think John Reisig published this method on his blog, ejohn.
  7265. //
  7266. function inArray( elem, array ) {
  7267. if ( array.indexOf ) {
  7268. return array.indexOf( elem );
  7269. }
  7270. for ( var i = 0, length = array.length; i < length; i++ ) {
  7271. if ( array[ i ] === elem ) {
  7272. return i;
  7273. }
  7274. }
  7275. return -1;
  7276. }
  7277. //
  7278. // Thanks to Kangax, Christian Sciberras and Stack Overflow for this method.
  7279. //
  7280. function get_type(thing){
  7281. if(thing===null) return "[object Null]"; // special case
  7282. return Object.prototype.toString.call(thing);
  7283. }
  7284. $.jsDate = jsDate;
  7285. /**
  7286. * JavaScript printf/sprintf functions.
  7287. *
  7288. * This code has been adapted from the publicly available sprintf methods
  7289. * by Ash Searle. His original header follows:
  7290. *
  7291. * This code is unrestricted: you are free to use it however you like.
  7292. *
  7293. * The functions should work as expected, performing left or right alignment,
  7294. * truncating strings, outputting numbers with a required precision etc.
  7295. *
  7296. * For complex cases, these functions follow the Perl implementations of
  7297. * (s)printf, allowing arguments to be passed out-of-order, and to set the
  7298. * precision or length of the output based on arguments instead of fixed
  7299. * numbers.
  7300. *
  7301. * See http://perldoc.perl.org/functions/sprintf.html for more information.
  7302. *
  7303. * Implemented:
  7304. * - zero and space-padding
  7305. * - right and left-alignment,
  7306. * - base X prefix (binary, octal and hex)
  7307. * - positive number prefix
  7308. * - (minimum) width
  7309. * - precision / truncation / maximum width
  7310. * - out of order arguments
  7311. *
  7312. * Not implemented (yet):
  7313. * - vector flag
  7314. * - size (bytes, words, long-words etc.)
  7315. *
  7316. * Will not implement:
  7317. * - %n or %p (no pass-by-reference in JavaScript)
  7318. *
  7319. * @version 2007.04.27
  7320. * @author Ash Searle
  7321. *
  7322. * You can see the original work and comments on his blog:
  7323. * http://hexmen.com/blog/2007/03/printf-sprintf/
  7324. * http://hexmen.com/js/sprintf.js
  7325. */
  7326. /**
  7327. * @Modifications 2009.05.26
  7328. * @author Chris Leonello
  7329. *
  7330. * Added %p %P specifier
  7331. * Acts like %g or %G but will not add more significant digits to the output than present in the input.
  7332. * Example:
  7333. * Format: '%.3p', Input: 0.012, Output: 0.012
  7334. * Format: '%.3g', Input: 0.012, Output: 0.0120
  7335. * Format: '%.4p', Input: 12.0, Output: 12.0
  7336. * Format: '%.4g', Input: 12.0, Output: 12.00
  7337. * Format: '%.4p', Input: 4.321e-5, Output: 4.321e-5
  7338. * Format: '%.4g', Input: 4.321e-5, Output: 4.3210e-5
  7339. */
  7340. $.jqplot.sprintf = function() {
  7341. function pad(str, len, chr, leftJustify) {
  7342. var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
  7343. return leftJustify ? str + padding : padding + str;
  7344. }
  7345. function thousand_separate(value) {
  7346. value_str = new String(value);
  7347. for (var i=10; i>0; i--) {
  7348. if (value_str == (value_str = value_str.replace(/^(\d+)(\d{3})/, "$1"+$.jqplot.sprintf.thousandsSeparator+"$2"))) break;
  7349. }
  7350. return value_str;
  7351. }
  7352. function justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace) {
  7353. var diff = minWidth - value.length;
  7354. if (diff > 0) {
  7355. var spchar = ' ';
  7356. if (htmlSpace) { spchar = '&nbsp;'; }
  7357. if (leftJustify || !zeroPad) {
  7358. value = pad(value, minWidth, spchar, leftJustify);
  7359. } else {
  7360. value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
  7361. }
  7362. }
  7363. return value;
  7364. }
  7365. function formatBaseX(value, base, prefix, leftJustify, minWidth, precision, zeroPad, htmlSpace) {
  7366. // Note: casts negative numbers to positive ones
  7367. var number = value >>> 0;
  7368. prefix = prefix && number && {'2': '0b', '8': '0', '16': '0x'}[base] || '';
  7369. value = prefix + pad(number.toString(base), precision || 0, '0', false);
  7370. return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace);
  7371. }
  7372. function formatString(value, leftJustify, minWidth, precision, zeroPad, htmlSpace) {
  7373. if (precision != null) {
  7374. value = value.slice(0, precision);
  7375. }
  7376. return justify(value, '', leftJustify, minWidth, zeroPad, htmlSpace);
  7377. }
  7378. var a = arguments, i = 0, format = a[i++];
  7379. return format.replace($.jqplot.sprintf.regex, function(substring, valueIndex, flags, minWidth, _, precision, type) {
  7380. if (substring == '%%') { return '%'; }
  7381. // parse flags
  7382. var leftJustify = false, positivePrefix = '', zeroPad = false, prefixBaseX = false, htmlSpace = false, thousandSeparation = false;
  7383. for (var j = 0; flags && j < flags.length; j++) switch (flags.charAt(j)) {
  7384. case ' ': positivePrefix = ' '; break;
  7385. case '+': positivePrefix = '+'; break;
  7386. case '-': leftJustify = true; break;
  7387. case '0': zeroPad = true; break;
  7388. case '#': prefixBaseX = true; break;
  7389. case '&': htmlSpace = true; break;
  7390. case '\'': thousandSeparation = true; break;
  7391. }
  7392. // parameters may be null, undefined, empty-string or real valued
  7393. // we want to ignore null, undefined and empty-string values
  7394. if (!minWidth) {
  7395. minWidth = 0;
  7396. }
  7397. else if (minWidth == '*') {
  7398. minWidth = +a[i++];
  7399. }
  7400. else if (minWidth.charAt(0) == '*') {
  7401. minWidth = +a[minWidth.slice(1, -1)];
  7402. }
  7403. else {
  7404. minWidth = +minWidth;
  7405. }
  7406. // Note: undocumented perl feature:
  7407. if (minWidth < 0) {
  7408. minWidth = -minWidth;
  7409. leftJustify = true;
  7410. }
  7411. if (!isFinite(minWidth)) {
  7412. throw new Error('$.jqplot.sprintf: (minimum-)width must be finite');
  7413. }
  7414. if (!precision) {
  7415. precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : void(0);
  7416. }
  7417. else if (precision == '*') {
  7418. precision = +a[i++];
  7419. }
  7420. else if (precision.charAt(0) == '*') {
  7421. precision = +a[precision.slice(1, -1)];
  7422. }
  7423. else {
  7424. precision = +precision;
  7425. }
  7426. // grab value using valueIndex if required?
  7427. var value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];
  7428. switch (type) {
  7429. case 's': {
  7430. if (value == null) {
  7431. return '';
  7432. }
  7433. return formatString(String(value), leftJustify, minWidth, precision, zeroPad, htmlSpace);
  7434. }
  7435. case 'c': return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad, htmlSpace);
  7436. case 'b': return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad,htmlSpace);
  7437. case 'o': return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace);
  7438. case 'x': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace);
  7439. case 'X': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace).toUpperCase();
  7440. case 'u': return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace);
  7441. case 'i': {
  7442. var number = parseInt(+value, 10);
  7443. if (isNaN(number)) {
  7444. return '';
  7445. }
  7446. var prefix = number < 0 ? '-' : positivePrefix;
  7447. number_str = thousandSeparation ? thousand_separate(String(Math.abs(number))): String(Math.abs(number));
  7448. value = prefix + pad(number_str, precision, '0', false);
  7449. //value = prefix + pad(String(Math.abs(number)), precision, '0', false);
  7450. return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace);
  7451. }
  7452. case 'd': {
  7453. var number = Math.round(+value);
  7454. if (isNaN(number)) {
  7455. return '';
  7456. }
  7457. var prefix = number < 0 ? '-' : positivePrefix;
  7458. number_str = thousandSeparation ? thousand_separate(String(Math.abs(number))): String(Math.abs(number));
  7459. value = prefix + pad(number_str, precision, '0', false);
  7460. return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace);
  7461. }
  7462. case 'e':
  7463. case 'E':
  7464. case 'f':
  7465. case 'F':
  7466. case 'g':
  7467. case 'G':
  7468. {
  7469. var number = +value;
  7470. if (isNaN(number)) {
  7471. return '';
  7472. }
  7473. var prefix = number < 0 ? '-' : positivePrefix;
  7474. var method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
  7475. var textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];
  7476. number_str = Math.abs(number)[method](precision);
  7477. number_str = thousandSeparation ? thousand_separate(number_str): number_str;
  7478. value = prefix + number_str;
  7479. return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace)[textTransform]();
  7480. }
  7481. case 'p':
  7482. case 'P':
  7483. {
  7484. // make sure number is a number
  7485. var number = +value;
  7486. if (isNaN(number)) {
  7487. return '';
  7488. }
  7489. var prefix = number < 0 ? '-' : positivePrefix;
  7490. var parts = String(Number(Math.abs(number)).toExponential()).split(/e|E/);
  7491. var sd = (parts[0].indexOf('.') != -1) ? parts[0].length - 1 : parts[0].length;
  7492. var zeros = (parts[1] < 0) ? -parts[1] - 1 : 0;
  7493. if (Math.abs(number) < 1) {
  7494. if (sd + zeros <= precision) {
  7495. value = prefix + Math.abs(number).toPrecision(sd);
  7496. }
  7497. else {
  7498. if (sd <= precision - 1) {
  7499. value = prefix + Math.abs(number).toExponential(sd-1);
  7500. }
  7501. else {
  7502. value = prefix + Math.abs(number).toExponential(precision-1);
  7503. }
  7504. }
  7505. }
  7506. else {
  7507. var prec = (sd <= precision) ? sd : precision;
  7508. value = prefix + Math.abs(number).toPrecision(prec);
  7509. }
  7510. var textTransform = ['toString', 'toUpperCase']['pP'.indexOf(type) % 2];
  7511. return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace)[textTransform]();
  7512. }
  7513. case 'n': return '';
  7514. default: return substring;
  7515. }
  7516. });
  7517. };
  7518. $.jqplot.sprintf.thousandsSeparator = ',';
  7519. $.jqplot.sprintf.regex = /%%|%(\d+\$)?([-+#0&\' ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([nAscboxXuidfegpEGP])/g;
  7520. })(jQuery);