jquery.jqplot.js 454 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381
  1. /**
  2. * Title: jqPlot Charts
  3. *
  4. * Pure JavaScript plotting plugin for jQuery.
  5. *
  6. * About: Version
  7. *
  8. * version: 1.0.4
  9. * revision: 1121
  10. *
  11. * About: Copyright & License
  12. *
  13. * Copyright (c) 2009-2012 Chris Leonello
  14. * jqPlot is currently available for use in all personal or commercial projects
  15. * under both the MIT and GPL version 2.0 licenses. This means that you can
  16. * choose the license that best suits your project and use it accordingly.
  17. *
  18. * See <GPL Version 2> and <MIT License> contained within this distribution for further information.
  19. *
  20. * The author would appreciate an email letting him know of any substantial
  21. * use of jqPlot. You can reach the author at: chris at jqplot dot com
  22. * or see http://www.jqplot.com/info.php. This is, of course, not required.
  23. *
  24. * If you are feeling kind and generous, consider supporting the project by
  25. * making a donation at: http://www.jqplot.com/donate.php.
  26. *
  27. * sprintf functions contained in jqplot.sprintf.js by Ash Searle:
  28. *
  29. * version 2007.04.27
  30. * author Ash Searle
  31. * http://hexmen.com/blog/2007/03/printf-sprintf/
  32. * http://hexmen.com/js/sprintf.js
  33. * The author (Ash Searle) has placed this code in the public domain:
  34. * "This code is unrestricted: you are free to use it however you like."
  35. *
  36. *
  37. * About: Introduction
  38. *
  39. * jqPlot requires jQuery (1.4+ required for certain features). jQuery 1.4.2 is included in the distribution.
  40. * To use jqPlot include jQuery, the jqPlot jQuery plugin, the jqPlot css file and optionally
  41. * the excanvas script for IE support in your web page:
  42. *
  43. * > <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="excanvas.js"></script><![endif]-->
  44. * > <script language="javascript" type="text/javascript" src="jquery-1.4.4.min.js"></script>
  45. * > <script language="javascript" type="text/javascript" src="jquery.jqplot.min.js"></script>
  46. * > <link rel="stylesheet" type="text/css" href="jquery.jqplot.css" />
  47. *
  48. * jqPlot can be customized by overriding the defaults of any of the objects which make
  49. * up the plot. The general usage of jqplot is:
  50. *
  51. * > chart = $.jqplot('targetElemId', [dataArray,...], {optionsObject});
  52. *
  53. * The options available to jqplot are detailed in <jqPlot Options> in the jqPlotOptions.txt file.
  54. *
  55. * An actual call to $.jqplot() may look like the
  56. * examples below:
  57. *
  58. * > chart = $.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
  59. *
  60. * or
  61. *
  62. * > dataArray = [34,12,43,55,77];
  63. * > chart = $.jqplot('targetElemId', [dataArray, ...], {title:'My Plot', axes:{yaxis:{min:20, max:100}}});
  64. *
  65. * For more inforrmation, see <jqPlot Usage>.
  66. *
  67. * About: Usage
  68. *
  69. * See <jqPlot Usage>
  70. *
  71. * About: Available Options
  72. *
  73. * See <jqPlot Options> for a list of options available thorugh the options object (not complete yet!)
  74. *
  75. * About: Options Usage
  76. *
  77. * See <Options Tutorial>
  78. *
  79. * About: Changes
  80. *
  81. * See <Change Log>
  82. *
  83. */
  84. (function($) {
  85. // make sure undefined is undefined
  86. var undefined;
  87. $.fn.emptyForce = function() {
  88. for ( var i = 0, elem; (elem = $(this)[i]) != null; i++ ) {
  89. // Remove element nodes and prevent memory leaks
  90. if ( elem.nodeType === 1 ) {
  91. $.cleanData( elem.getElementsByTagName("*") );
  92. }
  93. // Remove any remaining nodes
  94. if ($.jqplot.use_excanvas) {
  95. elem.outerHTML = "";
  96. }
  97. else {
  98. while ( elem.firstChild ) {
  99. elem.removeChild( elem.firstChild );
  100. }
  101. }
  102. elem = null;
  103. }
  104. return $(this);
  105. };
  106. $.fn.removeChildForce = function(parent) {
  107. while ( parent.firstChild ) {
  108. this.removeChildForce( parent.firstChild );
  109. parent.removeChild( parent.firstChild );
  110. }
  111. };
  112. $.fn.jqplot = function() {
  113. var datas = [];
  114. var options = [];
  115. // see how many data arrays we have
  116. for (var i=0, l=arguments.length; i<l; i++) {
  117. if ($.isArray(arguments[i])) {
  118. datas.push(arguments[i]);
  119. }
  120. else if ($.isPlainObject(arguments[i])) {
  121. options.push(arguments[i]);
  122. }
  123. }
  124. return this.each(function(index) {
  125. var tid,
  126. plot,
  127. $this = $(this),
  128. dl = datas.length,
  129. ol = options.length,
  130. data,
  131. opts;
  132. if (index < dl) {
  133. data = datas[index];
  134. }
  135. else {
  136. data = dl ? datas[dl-1] : null;
  137. }
  138. if (index < ol) {
  139. opts = options[index];
  140. }
  141. else {
  142. opts = ol ? options[ol-1] : null;
  143. }
  144. // does el have an id?
  145. // if not assign it one.
  146. tid = $this.attr('id');
  147. if (tid === undefined) {
  148. tid = 'jqplot_target_' + $.jqplot.targetCounter++;
  149. $this.attr('id', tid);
  150. }
  151. plot = $.jqplot(tid, data, opts);
  152. $this.data('jqplot', plot);
  153. });
  154. };
  155. /**
  156. * Namespace: $.jqplot
  157. * jQuery function called by the user to create a plot.
  158. *
  159. * Parameters:
  160. * target - ID of target element to render the plot into.
  161. * data - an array of data series.
  162. * options - user defined options object. See the individual classes for available options.
  163. *
  164. * Properties:
  165. * config - object to hold configuration information for jqPlot plot object.
  166. *
  167. * attributes:
  168. * enablePlugins - False to disable plugins by default. Plugins must then be explicitly
  169. * enabled in the individual plot options. Default: false.
  170. * This property sets the "show" property of certain plugins to true or false.
  171. * Only plugins that can be immediately active upon loading are affected. This includes
  172. * non-renderer plugins like cursor, dragable, highlighter, and trendline.
  173. * defaultHeight - Default height for plots where no css height specification exists. This
  174. * is a jqplot wide default.
  175. * defaultWidth - Default height for plots where no css height specification exists. This
  176. * is a jqplot wide default.
  177. */
  178. $.jqplot = function(target, data, options) {
  179. var _data = null, _options = null;
  180. if (arguments.length === 3) {
  181. _data = data;
  182. _options = options;
  183. }
  184. else if (arguments.length === 2) {
  185. if ($.isArray(data)) {
  186. _data = data;
  187. }
  188. else if ($.isPlainObject(data)) {
  189. _options = data;
  190. }
  191. }
  192. if (_data === null && _options !== null && _options.data) {
  193. _data = _options.data;
  194. }
  195. var plot = new jqPlot();
  196. // remove any error class that may be stuck on target.
  197. $('#'+target).removeClass('jqplot-error');
  198. if ($.jqplot.config.catchErrors) {
  199. try {
  200. plot.init(target, _data, _options);
  201. plot.draw();
  202. plot.themeEngine.init.call(plot);
  203. return plot;
  204. }
  205. catch(e) {
  206. var msg = $.jqplot.config.errorMessage || e.message;
  207. $('#'+target).append('<div class="jqplot-error-message">'+msg+'</div>');
  208. $('#'+target).addClass('jqplot-error');
  209. document.getElementById(target).style.background = $.jqplot.config.errorBackground;
  210. document.getElementById(target).style.border = $.jqplot.config.errorBorder;
  211. document.getElementById(target).style.fontFamily = $.jqplot.config.errorFontFamily;
  212. document.getElementById(target).style.fontSize = $.jqplot.config.errorFontSize;
  213. document.getElementById(target).style.fontStyle = $.jqplot.config.errorFontStyle;
  214. document.getElementById(target).style.fontWeight = $.jqplot.config.errorFontWeight;
  215. }
  216. }
  217. else {
  218. plot.init(target, _data, _options);
  219. plot.draw();
  220. plot.themeEngine.init.call(plot);
  221. return plot;
  222. }
  223. };
  224. $.jqplot.version = "1.0.4";
  225. $.jqplot.revision = "1121";
  226. $.jqplot.targetCounter = 1;
  227. // canvas manager to reuse canvases on the plot.
  228. // Should help solve problem of canvases not being freed and
  229. // problem of waiting forever for firefox to decide to free memory.
  230. $.jqplot.CanvasManager = function() {
  231. // canvases are managed globally so that they can be reused
  232. // across plots after they have been freed
  233. if (typeof $.jqplot.CanvasManager.canvases == 'undefined') {
  234. $.jqplot.CanvasManager.canvases = [];
  235. $.jqplot.CanvasManager.free = [];
  236. }
  237. var myCanvases = [];
  238. this.getCanvas = function() {
  239. var canvas;
  240. var makeNew = true;
  241. if (!$.jqplot.use_excanvas) {
  242. for (var i = 0, l = $.jqplot.CanvasManager.canvases.length; i < l; i++) {
  243. if ($.jqplot.CanvasManager.free[i] === true) {
  244. makeNew = false;
  245. canvas = $.jqplot.CanvasManager.canvases[i];
  246. // $(canvas).removeClass('jqplot-canvasManager-free').addClass('jqplot-canvasManager-inuse');
  247. $.jqplot.CanvasManager.free[i] = false;
  248. myCanvases.push(i);
  249. break;
  250. }
  251. }
  252. }
  253. if (makeNew) {
  254. canvas = document.createElement('canvas');
  255. myCanvases.push($.jqplot.CanvasManager.canvases.length);
  256. $.jqplot.CanvasManager.canvases.push(canvas);
  257. $.jqplot.CanvasManager.free.push(false);
  258. }
  259. return canvas;
  260. };
  261. // this method has to be used after settings the dimesions
  262. // on the element returned by getCanvas()
  263. this.initCanvas = function(canvas) {
  264. if ($.jqplot.use_excanvas) {
  265. return window.G_vmlCanvasManager.initElement(canvas);
  266. }
  267. return canvas;
  268. };
  269. this.freeAllCanvases = function() {
  270. for (var i = 0, l=myCanvases.length; i < l; i++) {
  271. this.freeCanvas(myCanvases[i]);
  272. }
  273. myCanvases = [];
  274. };
  275. this.freeCanvas = function(idx) {
  276. if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
  277. // excanvas can't be reused, but properly unset
  278. window.G_vmlCanvasManager.uninitElement($.jqplot.CanvasManager.canvases[idx]);
  279. $.jqplot.CanvasManager.canvases[idx] = null;
  280. }
  281. else {
  282. var canvas = $.jqplot.CanvasManager.canvases[idx];
  283. canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
  284. $(canvas).unbind().removeAttr('class').removeAttr('style');
  285. // Style attributes seemed to be still hanging around. wierd. Some ticks
  286. // still retained a left: 0px attribute after reusing a canvas.
  287. $(canvas).css({left: '', top: '', position: ''});
  288. // setting size to 0 may save memory of unused canvases?
  289. canvas.width = 0;
  290. canvas.height = 0;
  291. $.jqplot.CanvasManager.free[idx] = true;
  292. }
  293. };
  294. };
  295. // Convienence function that won't hang IE or FF without FireBug.
  296. $.jqplot.log = function() {
  297. if (window.console) {
  298. window.console.log.apply(window.console, arguments);
  299. }
  300. };
  301. $.jqplot.config = {
  302. addDomReference: false,
  303. enablePlugins:false,
  304. defaultHeight:300,
  305. defaultWidth:400,
  306. UTCAdjust:false,
  307. timezoneOffset: new Date(new Date().getTimezoneOffset() * 60000),
  308. errorMessage: '',
  309. errorBackground: '',
  310. errorBorder: '',
  311. errorFontFamily: '',
  312. errorFontSize: '',
  313. errorFontStyle: '',
  314. errorFontWeight: '',
  315. catchErrors: false,
  316. defaultTickFormatString: "%.1f",
  317. defaultColors: [ "#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"],
  318. defaultNegativeColors: [ "#498991", "#C08840", "#9F9274", "#546D61", "#646C4A", "#6F6621", "#6E3F5F", "#4F64B0", "#A89050", "#C45923", "#187399", "#945381", "#959E5C", "#C7AF7B", "#478396", "#907294"],
  319. dashLength: 4,
  320. gapLength: 4,
  321. dotGapLength: 2.5,
  322. srcLocation: 'jqplot/src/',
  323. pluginLocation: 'jqplot/src/plugins/'
  324. };
  325. $.jqplot.arrayMax = function( array ){
  326. return Math.max.apply( Math, array );
  327. };
  328. $.jqplot.arrayMin = function( array ){
  329. return Math.min.apply( Math, array );
  330. };
  331. $.jqplot.enablePlugins = $.jqplot.config.enablePlugins;
  332. // canvas related tests taken from modernizer:
  333. // Copyright (c) 2009 - 2010 Faruk Ates.
  334. // http://www.modernizr.com
  335. $.jqplot.support_canvas = function() {
  336. if (typeof $.jqplot.support_canvas.result == 'undefined') {
  337. $.jqplot.support_canvas.result = !!document.createElement('canvas').getContext;
  338. }
  339. return $.jqplot.support_canvas.result;
  340. };
  341. $.jqplot.support_canvas_text = function() {
  342. if (typeof $.jqplot.support_canvas_text.result == 'undefined') {
  343. if (window.G_vmlCanvasManager !== undefined && window.G_vmlCanvasManager._version > 887) {
  344. $.jqplot.support_canvas_text.result = true;
  345. }
  346. else {
  347. $.jqplot.support_canvas_text.result = !!(document.createElement('canvas').getContext && typeof document.createElement('canvas').getContext('2d').fillText == 'function');
  348. }
  349. }
  350. return $.jqplot.support_canvas_text.result;
  351. };
  352. $.jqplot.use_excanvas = ($.browser.msie && !$.jqplot.support_canvas()) ? true : false;
  353. /**
  354. *
  355. * Hooks: jqPlot Pugin Hooks
  356. *
  357. * $.jqplot.preInitHooks - called before initialization.
  358. * $.jqplot.postInitHooks - called after initialization.
  359. * $.jqplot.preParseOptionsHooks - called before user options are parsed.
  360. * $.jqplot.postParseOptionsHooks - called after user options are parsed.
  361. * $.jqplot.preDrawHooks - called before plot draw.
  362. * $.jqplot.postDrawHooks - called after plot draw.
  363. * $.jqplot.preDrawSeriesHooks - called before each series is drawn.
  364. * $.jqplot.postDrawSeriesHooks - called after each series is drawn.
  365. * $.jqplot.preDrawLegendHooks - called before the legend is drawn.
  366. * $.jqplot.addLegendRowHooks - called at the end of legend draw, so plugins
  367. * can add rows to the legend table.
  368. * $.jqplot.preSeriesInitHooks - called before series is initialized.
  369. * $.jqplot.postSeriesInitHooks - called after series is initialized.
  370. * $.jqplot.preParseSeriesOptionsHooks - called before series related options
  371. * are parsed.
  372. * $.jqplot.postParseSeriesOptionsHooks - called after series related options
  373. * are parsed.
  374. * $.jqplot.eventListenerHooks - called at the end of plot drawing, binds
  375. * listeners to the event canvas which lays on top of the grid area.
  376. * $.jqplot.preDrawSeriesShadowHooks - called before series shadows are drawn.
  377. * $.jqplot.postDrawSeriesShadowHooks - called after series shadows are drawn.
  378. *
  379. */
  380. $.jqplot.preInitHooks = [];
  381. $.jqplot.postInitHooks = [];
  382. $.jqplot.preParseOptionsHooks = [];
  383. $.jqplot.postParseOptionsHooks = [];
  384. $.jqplot.preDrawHooks = [];
  385. $.jqplot.postDrawHooks = [];
  386. $.jqplot.preDrawSeriesHooks = [];
  387. $.jqplot.postDrawSeriesHooks = [];
  388. $.jqplot.preDrawLegendHooks = [];
  389. $.jqplot.addLegendRowHooks = [];
  390. $.jqplot.preSeriesInitHooks = [];
  391. $.jqplot.postSeriesInitHooks = [];
  392. $.jqplot.preParseSeriesOptionsHooks = [];
  393. $.jqplot.postParseSeriesOptionsHooks = [];
  394. $.jqplot.eventListenerHooks = [];
  395. $.jqplot.preDrawSeriesShadowHooks = [];
  396. $.jqplot.postDrawSeriesShadowHooks = [];
  397. // A superclass holding some common properties and methods.
  398. $.jqplot.ElemContainer = function() {
  399. this._elem;
  400. this._plotWidth;
  401. this._plotHeight;
  402. this._plotDimensions = {height:null, width:null};
  403. };
  404. $.jqplot.ElemContainer.prototype.createElement = function(el, offsets, clss, cssopts, attrib) {
  405. this._offsets = offsets;
  406. var klass = clss || 'jqplot';
  407. var elem = document.createElement(el);
  408. this._elem = $(elem);
  409. this._elem.addClass(klass);
  410. this._elem.css(cssopts);
  411. this._elem.attr(attrib);
  412. // avoid memory leak;
  413. elem = null;
  414. return this._elem;
  415. };
  416. $.jqplot.ElemContainer.prototype.getWidth = function() {
  417. if (this._elem) {
  418. return this._elem.outerWidth(true);
  419. }
  420. else {
  421. return null;
  422. }
  423. };
  424. $.jqplot.ElemContainer.prototype.getHeight = function() {
  425. if (this._elem) {
  426. return this._elem.outerHeight(true);
  427. }
  428. else {
  429. return null;
  430. }
  431. };
  432. $.jqplot.ElemContainer.prototype.getPosition = function() {
  433. if (this._elem) {
  434. return this._elem.position();
  435. }
  436. else {
  437. return {top:null, left:null, bottom:null, right:null};
  438. }
  439. };
  440. $.jqplot.ElemContainer.prototype.getTop = function() {
  441. return this.getPosition().top;
  442. };
  443. $.jqplot.ElemContainer.prototype.getLeft = function() {
  444. return this.getPosition().left;
  445. };
  446. $.jqplot.ElemContainer.prototype.getBottom = function() {
  447. return this._elem.css('bottom');
  448. };
  449. $.jqplot.ElemContainer.prototype.getRight = function() {
  450. return this._elem.css('right');
  451. };
  452. /**
  453. * Class: Axis
  454. * An individual axis object. Cannot be instantiated directly, but created
  455. * by the Plot oject. Axis properties can be set or overriden by the
  456. * options passed in from the user.
  457. *
  458. */
  459. function Axis(name) {
  460. $.jqplot.ElemContainer.call(this);
  461. // Group: Properties
  462. //
  463. // Axes options are specified within an axes object at the top level of the
  464. // plot options like so:
  465. // > {
  466. // > axes: {
  467. // > xaxis: {min: 5},
  468. // > yaxis: {min: 2, max: 8, numberTicks:4},
  469. // > x2axis: {pad: 1.5},
  470. // > y2axis: {ticks:[22, 44, 66, 88]}
  471. // > }
  472. // > }
  473. // There are 2 x axes, 'xaxis' and 'x2axis', and
  474. // 9 yaxes, 'yaxis', 'y2axis'. 'y3axis', ... Any or all of which may be specified.
  475. this.name = name;
  476. this._series = [];
  477. // prop: show
  478. // Wether to display the axis on the graph.
  479. this.show = false;
  480. // prop: tickRenderer
  481. // A class of a rendering engine for creating the ticks labels displayed on the plot,
  482. // See <$.jqplot.AxisTickRenderer>.
  483. this.tickRenderer = $.jqplot.AxisTickRenderer;
  484. // prop: tickOptions
  485. // Options that will be passed to the tickRenderer, see <$.jqplot.AxisTickRenderer> options.
  486. this.tickOptions = {};
  487. // prop: labelRenderer
  488. // A class of a rendering engine for creating an axis label.
  489. this.labelRenderer = $.jqplot.AxisLabelRenderer;
  490. // prop: labelOptions
  491. // Options passed to the label renderer.
  492. this.labelOptions = {};
  493. // prop: label
  494. // Label for the axis
  495. this.label = null;
  496. // prop: showLabel
  497. // true to show the axis label.
  498. this.showLabel = true;
  499. // prop: min
  500. // minimum value of the axis (in data units, not pixels).
  501. this.min = null;
  502. // prop: max
  503. // maximum value of the axis (in data units, not pixels).
  504. this.max = null;
  505. // prop: autoscale
  506. // DEPRECATED
  507. // the default scaling algorithm produces superior results.
  508. this.autoscale = false;
  509. // prop: pad
  510. // Padding to extend the range above and below the data bounds.
  511. // The data range is multiplied by this factor to determine minimum and maximum axis bounds.
  512. // A value of 0 will be interpreted to mean no padding, and pad will be set to 1.0.
  513. this.pad = 1.2;
  514. // prop: padMax
  515. // Padding to extend the range above data bounds.
  516. // The top of the data range is multiplied by this factor to determine maximum axis bounds.
  517. // A value of 0 will be interpreted to mean no padding, and padMax will be set to 1.0.
  518. this.padMax = null;
  519. // prop: padMin
  520. // Padding to extend the range below data bounds.
  521. // The bottom of the data range is multiplied by this factor to determine minimum axis bounds.
  522. // A value of 0 will be interpreted to mean no padding, and padMin will be set to 1.0.
  523. this.padMin = null;
  524. // prop: ticks
  525. // 1D [val, val, ...] or 2D [[val, label], [val, label], ...] array of ticks for the axis.
  526. // If no label is specified, the value is formatted into an appropriate label.
  527. this.ticks = [];
  528. // prop: numberTicks
  529. // Desired number of ticks. Default is to compute automatically.
  530. this.numberTicks;
  531. // prop: tickInterval
  532. // number of units between ticks. Mutually exclusive with numberTicks.
  533. this.tickInterval;
  534. // prop: renderer
  535. // A class of a rendering engine that handles tick generation,
  536. // scaling input data to pixel grid units and drawing the axis element.
  537. this.renderer = $.jqplot.LinearAxisRenderer;
  538. // prop: rendererOptions
  539. // renderer specific options. See <$.jqplot.LinearAxisRenderer> for options.
  540. this.rendererOptions = {};
  541. // prop: showTicks
  542. // Wether to show the ticks (both marks and labels) or not.
  543. // Will not override showMark and showLabel options if specified on the ticks themselves.
  544. this.showTicks = true;
  545. // prop: showTickMarks
  546. // Wether to show the tick marks (line crossing grid) or not.
  547. // Overridden by showTicks and showMark option of tick itself.
  548. this.showTickMarks = true;
  549. // prop: showMinorTicks
  550. // Wether or not to show minor ticks. This is renderer dependent.
  551. this.showMinorTicks = true;
  552. // prop: drawMajorGridlines
  553. // True to draw gridlines for major axis ticks.
  554. this.drawMajorGridlines = true;
  555. // prop: drawMinorGridlines
  556. // True to draw gridlines for minor ticks.
  557. this.drawMinorGridlines = false;
  558. // prop: drawMajorTickMarks
  559. // True to draw tick marks for major axis ticks.
  560. this.drawMajorTickMarks = true;
  561. // prop: drawMinorTickMarks
  562. // True to draw tick marks for minor ticks. This is renderer dependent.
  563. this.drawMinorTickMarks = true;
  564. // prop: useSeriesColor
  565. // Use the color of the first series associated with this axis for the
  566. // tick marks and line bordering this axis.
  567. this.useSeriesColor = false;
  568. // prop: borderWidth
  569. // width of line stroked at the border of the axis. Defaults
  570. // to the width of the grid boarder.
  571. this.borderWidth = null;
  572. // prop: borderColor
  573. // color of the border adjacent to the axis. Defaults to grid border color.
  574. this.borderColor = null;
  575. // prop: scaleToHiddenSeries
  576. // True to include hidden series when computing axes bounds and scaling.
  577. this.scaleToHiddenSeries = false;
  578. // minimum and maximum values on the axis.
  579. this._dataBounds = {min:null, max:null};
  580. // statistics (min, max, mean) as well as actual data intervals for each series attached to axis.
  581. // holds collection of {intervals:[], min:, max:, mean: } objects for each series on axis.
  582. this._intervalStats = [];
  583. // pixel position from the top left of the min value and max value on the axis.
  584. this._offsets = {min:null, max:null};
  585. this._ticks=[];
  586. this._label = null;
  587. // prop: syncTicks
  588. // true to try and synchronize tick spacing across multiple axes so that ticks and
  589. // grid lines line up. This has an impact on autoscaling algorithm, however.
  590. // In general, autoscaling an individual axis will work better if it does not
  591. // have to sync ticks.
  592. this.syncTicks = null;
  593. // prop: tickSpacing
  594. // Approximate pixel spacing between ticks on graph. Used during autoscaling.
  595. // This number will be an upper bound, actual spacing will be less.
  596. this.tickSpacing = 75;
  597. // Properties to hold the original values for min, max, ticks, tickInterval and numberTicks
  598. // so they can be restored if altered by plugins.
  599. this._min = null;
  600. this._max = null;
  601. this._tickInterval = null;
  602. this._numberTicks = null;
  603. this.__ticks = null;
  604. // hold original user options.
  605. this._options = {};
  606. }
  607. Axis.prototype = new $.jqplot.ElemContainer();
  608. Axis.prototype.constructor = Axis;
  609. Axis.prototype.init = function() {
  610. if ($.isFunction(this.renderer)) {
  611. this.renderer = new this.renderer();
  612. }
  613. // set the axis name
  614. this.tickOptions.axis = this.name;
  615. // if showMark or showLabel tick options not specified, use value of axis option.
  616. // showTicks overrides showTickMarks.
  617. if (this.tickOptions.showMark == null) {
  618. this.tickOptions.showMark = this.showTicks;
  619. }
  620. if (this.tickOptions.showMark == null) {
  621. this.tickOptions.showMark = this.showTickMarks;
  622. }
  623. if (this.tickOptions.showLabel == null) {
  624. this.tickOptions.showLabel = this.showTicks;
  625. }
  626. if (this.label == null || this.label == '') {
  627. this.showLabel = false;
  628. }
  629. else {
  630. this.labelOptions.label = this.label;
  631. }
  632. if (this.showLabel == false) {
  633. this.labelOptions.show = false;
  634. }
  635. // set the default padMax, padMin if not specified
  636. // special check, if no padding desired, padding
  637. // should be set to 1.0
  638. if (this.pad == 0) {
  639. this.pad = 1.0;
  640. }
  641. if (this.padMax == 0) {
  642. this.padMax = 1.0;
  643. }
  644. if (this.padMin == 0) {
  645. this.padMin = 1.0;
  646. }
  647. if (this.padMax == null) {
  648. this.padMax = (this.pad-1)/2 + 1;
  649. }
  650. if (this.padMin == null) {
  651. this.padMin = (this.pad-1)/2 + 1;
  652. }
  653. // now that padMin and padMax are correctly set, reset pad in case user has supplied
  654. // padMin and/or padMax
  655. this.pad = this.padMax + this.padMin - 1;
  656. if (this.min != null || this.max != null) {
  657. this.autoscale = false;
  658. }
  659. // if not set, sync ticks for y axes but not x by default.
  660. if (this.syncTicks == null && this.name.indexOf('y') > -1) {
  661. this.syncTicks = true;
  662. }
  663. else if (this.syncTicks == null){
  664. this.syncTicks = false;
  665. }
  666. this.renderer.init.call(this, this.rendererOptions);
  667. };
  668. Axis.prototype.draw = function(ctx, plot) {
  669. // Memory Leaks patch
  670. if (this.__ticks) {
  671. this.__ticks = null;
  672. }
  673. return this.renderer.draw.call(this, ctx, plot);
  674. };
  675. Axis.prototype.set = function() {
  676. this.renderer.set.call(this);
  677. };
  678. Axis.prototype.pack = function(pos, offsets) {
  679. if (this.show) {
  680. this.renderer.pack.call(this, pos, offsets);
  681. }
  682. // these properties should all be available now.
  683. if (this._min == null) {
  684. this._min = this.min;
  685. this._max = this.max;
  686. this._tickInterval = this.tickInterval;
  687. this._numberTicks = this.numberTicks;
  688. this.__ticks = this._ticks;
  689. }
  690. };
  691. // reset the axis back to original values if it has been scaled, zoomed, etc.
  692. Axis.prototype.reset = function() {
  693. this.renderer.reset.call(this);
  694. };
  695. Axis.prototype.resetScale = function(opts) {
  696. $.extend(true, this, {min: null, max: null, numberTicks: null, tickInterval: null, _ticks: [], ticks: []}, opts);
  697. this.resetDataBounds();
  698. };
  699. Axis.prototype.resetDataBounds = function() {
  700. // Go through all the series attached to this axis and find
  701. // the min/max bounds for this axis.
  702. var db = this._dataBounds;
  703. db.min = null;
  704. db.max = null;
  705. var l, s, d;
  706. // check for when to force min 0 on bar series plots.
  707. var doforce = (this.show) ? true : false;
  708. for (var i=0; i<this._series.length; i++) {
  709. s = this._series[i];
  710. if (s.show || this.scaleToHiddenSeries) {
  711. d = s._plotData;
  712. if (s._type === 'line' && s.renderer.bands.show && this.name.charAt(0) !== 'x') {
  713. d = [[0, s.renderer.bands._min], [1, s.renderer.bands._max]];
  714. }
  715. var minyidx = 1, maxyidx = 1;
  716. if (s._type != null && s._type == 'ohlc') {
  717. minyidx = 3;
  718. maxyidx = 2;
  719. }
  720. for (var j=0, l=d.length; j<l; j++) {
  721. if (this.name == 'xaxis' || this.name == 'x2axis') {
  722. if ((d[j][0] != null && d[j][0] < db.min) || db.min == null) {
  723. db.min = d[j][0];
  724. }
  725. if ((d[j][0] != null && d[j][0] > db.max) || db.max == null) {
  726. db.max = d[j][0];
  727. }
  728. }
  729. else {
  730. if ((d[j][minyidx] != null && d[j][minyidx] < db.min) || db.min == null) {
  731. db.min = d[j][minyidx];
  732. }
  733. if ((d[j][maxyidx] != null && d[j][maxyidx] > db.max) || db.max == null) {
  734. db.max = d[j][maxyidx];
  735. }
  736. }
  737. }
  738. // Hack to not pad out bottom of bar plots unless user has specified a padding.
  739. // every series will have a chance to set doforce to false. once it is set to
  740. // false, it cannot be reset to true.
  741. // If any series attached to axis is not a bar, wont force 0.
  742. if (doforce && s.renderer.constructor !== $.jqplot.BarRenderer) {
  743. doforce = false;
  744. }
  745. else if (doforce && this._options.hasOwnProperty('forceTickAt0') && this._options.forceTickAt0 == false) {
  746. doforce = false;
  747. }
  748. else if (doforce && s.renderer.constructor === $.jqplot.BarRenderer) {
  749. if (s.barDirection == 'vertical' && this.name != 'xaxis' && this.name != 'x2axis') {
  750. if (this._options.pad != null || this._options.padMin != null) {
  751. doforce = false;
  752. }
  753. }
  754. else if (s.barDirection == 'horizontal' && (this.name == 'xaxis' || this.name == 'x2axis')) {
  755. if (this._options.pad != null || this._options.padMin != null) {
  756. doforce = false;
  757. }
  758. }
  759. }
  760. }
  761. }
  762. if (doforce && this.renderer.constructor === $.jqplot.LinearAxisRenderer && db.min >= 0) {
  763. this.padMin = 1.0;
  764. this.forceTickAt0 = true;
  765. }
  766. };
  767. /**
  768. * Class: Legend
  769. * Legend object. Cannot be instantiated directly, but created
  770. * by the Plot oject. Legend properties can be set or overriden by the
  771. * options passed in from the user.
  772. */
  773. function Legend(options) {
  774. $.jqplot.ElemContainer.call(this);
  775. // Group: Properties
  776. // prop: show
  777. // Wether to display the legend on the graph.
  778. this.show = false;
  779. // prop: location
  780. // Placement of the legend. one of the compass directions: nw, n, ne, e, se, s, sw, w
  781. this.location = 'ne';
  782. // prop: labels
  783. // Array of labels to use. By default the renderer will look for labels on the series.
  784. // Labels specified in this array will override labels specified on the series.
  785. this.labels = [];
  786. // prop: showLabels
  787. // true to show the label text on the legend.
  788. this.showLabels = true;
  789. // prop: showSwatch
  790. // true to show the color swatches on the legend.
  791. this.showSwatches = true;
  792. // prop: placement
  793. // "insideGrid" places legend inside the grid area of the plot.
  794. // "outsideGrid" places the legend outside the grid but inside the plot container,
  795. // shrinking the grid to accomodate the legend.
  796. // "inside" synonym for "insideGrid",
  797. // "outside" places the legend ouside the grid area, but does not shrink the grid which
  798. // can cause the legend to overflow the plot container.
  799. this.placement = "insideGrid";
  800. // prop: xoffset
  801. // DEPRECATED. Set the margins on the legend using the marginTop, marginLeft, etc.
  802. // properties or via CSS margin styling of the .jqplot-table-legend class.
  803. this.xoffset = 0;
  804. // prop: yoffset
  805. // DEPRECATED. Set the margins on the legend using the marginTop, marginLeft, etc.
  806. // properties or via CSS margin styling of the .jqplot-table-legend class.
  807. this.yoffset = 0;
  808. // prop: border
  809. // css spec for the border around the legend box.
  810. this.border;
  811. // prop: background
  812. // css spec for the background of the legend box.
  813. this.background;
  814. // prop: textColor
  815. // css color spec for the legend text.
  816. this.textColor;
  817. // prop: fontFamily
  818. // css font-family spec for the legend text.
  819. this.fontFamily;
  820. // prop: fontSize
  821. // css font-size spec for the legend text.
  822. this.fontSize ;
  823. // prop: rowSpacing
  824. // css padding-top spec for the rows in the legend.
  825. this.rowSpacing = '0.5em';
  826. // renderer
  827. // A class that will create a DOM object for the legend,
  828. // see <$.jqplot.TableLegendRenderer>.
  829. this.renderer = $.jqplot.TableLegendRenderer;
  830. // prop: rendererOptions
  831. // renderer specific options passed to the renderer.
  832. this.rendererOptions = {};
  833. // prop: predraw
  834. // Wether to draw the legend before the series or not.
  835. // Used with series specific legend renderers for pie, donut, mekko charts, etc.
  836. this.preDraw = false;
  837. // prop: marginTop
  838. // CSS margin for the legend DOM element. This will set an element
  839. // CSS style for the margin which will override any style sheet setting.
  840. // The default will be taken from the stylesheet.
  841. this.marginTop = null;
  842. // prop: marginRight
  843. // CSS margin for the legend DOM element. This will set an element
  844. // CSS style for the margin which will override any style sheet setting.
  845. // The default will be taken from the stylesheet.
  846. this.marginRight = null;
  847. // prop: marginBottom
  848. // CSS margin for the legend DOM element. This will set an element
  849. // CSS style for the margin which will override any style sheet setting.
  850. // The default will be taken from the stylesheet.
  851. this.marginBottom = null;
  852. // prop: marginLeft
  853. // CSS margin for the legend DOM element. This will set an element
  854. // CSS style for the margin which will override any style sheet setting.
  855. // The default will be taken from the stylesheet.
  856. this.marginLeft = null;
  857. // prop: escapeHtml
  858. // True to escape special characters with their html entity equivalents
  859. // in legend text. "<" becomes &lt; and so on, so html tags are not rendered.
  860. this.escapeHtml = false;
  861. this._series = [];
  862. $.extend(true, this, options);
  863. }
  864. Legend.prototype = new $.jqplot.ElemContainer();
  865. Legend.prototype.constructor = Legend;
  866. Legend.prototype.setOptions = function(options) {
  867. $.extend(true, this, options);
  868. // Try to emulate deprecated behaviour
  869. // if user has specified xoffset or yoffset, copy these to
  870. // the margin properties.
  871. if (this.placement == 'inside') {
  872. this.placement = 'insideGrid';
  873. }
  874. if (this.xoffset >0) {
  875. if (this.placement == 'insideGrid') {
  876. switch (this.location) {
  877. case 'nw':
  878. case 'w':
  879. case 'sw':
  880. if (this.marginLeft == null) {
  881. this.marginLeft = this.xoffset + 'px';
  882. }
  883. this.marginRight = '0px';
  884. break;
  885. case 'ne':
  886. case 'e':
  887. case 'se':
  888. default:
  889. if (this.marginRight == null) {
  890. this.marginRight = this.xoffset + 'px';
  891. }
  892. this.marginLeft = '0px';
  893. break;
  894. }
  895. }
  896. else if (this.placement == 'outside') {
  897. switch (this.location) {
  898. case 'nw':
  899. case 'w':
  900. case 'sw':
  901. if (this.marginRight == null) {
  902. this.marginRight = this.xoffset + 'px';
  903. }
  904. this.marginLeft = '0px';
  905. break;
  906. case 'ne':
  907. case 'e':
  908. case 'se':
  909. default:
  910. if (this.marginLeft == null) {
  911. this.marginLeft = this.xoffset + 'px';
  912. }
  913. this.marginRight = '0px';
  914. break;
  915. }
  916. }
  917. this.xoffset = 0;
  918. }
  919. if (this.yoffset >0) {
  920. if (this.placement == 'outside') {
  921. switch (this.location) {
  922. case 'sw':
  923. case 's':
  924. case 'se':
  925. if (this.marginTop == null) {
  926. this.marginTop = this.yoffset + 'px';
  927. }
  928. this.marginBottom = '0px';
  929. break;
  930. case 'ne':
  931. case 'n':
  932. case 'nw':
  933. default:
  934. if (this.marginBottom == null) {
  935. this.marginBottom = this.yoffset + 'px';
  936. }
  937. this.marginTop = '0px';
  938. break;
  939. }
  940. }
  941. else if (this.placement == 'insideGrid') {
  942. switch (this.location) {
  943. case 'sw':
  944. case 's':
  945. case 'se':
  946. if (this.marginBottom == null) {
  947. this.marginBottom = this.yoffset + 'px';
  948. }
  949. this.marginTop = '0px';
  950. break;
  951. case 'ne':
  952. case 'n':
  953. case 'nw':
  954. default:
  955. if (this.marginTop == null) {
  956. this.marginTop = this.yoffset + 'px';
  957. }
  958. this.marginBottom = '0px';
  959. break;
  960. }
  961. }
  962. this.yoffset = 0;
  963. }
  964. // TO-DO:
  965. // Handle case where offsets are < 0.
  966. //
  967. };
  968. Legend.prototype.init = function() {
  969. if ($.isFunction(this.renderer)) {
  970. this.renderer = new this.renderer();
  971. }
  972. this.renderer.init.call(this, this.rendererOptions);
  973. };
  974. Legend.prototype.draw = function(offsets, plot) {
  975. for (var i=0; i<$.jqplot.preDrawLegendHooks.length; i++){
  976. $.jqplot.preDrawLegendHooks[i].call(this, offsets);
  977. }
  978. return this.renderer.draw.call(this, offsets, plot);
  979. };
  980. Legend.prototype.pack = function(offsets) {
  981. this.renderer.pack.call(this, offsets);
  982. };
  983. /**
  984. * Class: Title
  985. * Plot Title object. Cannot be instantiated directly, but created
  986. * by the Plot oject. Title properties can be set or overriden by the
  987. * options passed in from the user.
  988. *
  989. * Parameters:
  990. * text - text of the title.
  991. */
  992. function Title(text) {
  993. $.jqplot.ElemContainer.call(this);
  994. // Group: Properties
  995. // prop: text
  996. // text of the title;
  997. this.text = text;
  998. // prop: show
  999. // wether or not to show the title
  1000. this.show = true;
  1001. // prop: fontFamily
  1002. // css font-family spec for the text.
  1003. this.fontFamily;
  1004. // prop: fontSize
  1005. // css font-size spec for the text.
  1006. this.fontSize ;
  1007. // prop: textAlign
  1008. // css text-align spec for the text.
  1009. this.textAlign;
  1010. // prop: textColor
  1011. // css color spec for the text.
  1012. this.textColor;
  1013. // prop: renderer
  1014. // A class for creating a DOM element for the title,
  1015. // see <$.jqplot.DivTitleRenderer>.
  1016. this.renderer = $.jqplot.DivTitleRenderer;
  1017. // prop: rendererOptions
  1018. // renderer specific options passed to the renderer.
  1019. this.rendererOptions = {};
  1020. // prop: escapeHtml
  1021. // True to escape special characters with their html entity equivalents
  1022. // in title text. "<" becomes &lt; and so on, so html tags are not rendered.
  1023. this.escapeHtml = false;
  1024. }
  1025. Title.prototype = new $.jqplot.ElemContainer();
  1026. Title.prototype.constructor = Title;
  1027. Title.prototype.init = function() {
  1028. if ($.isFunction(this.renderer)) {
  1029. this.renderer = new this.renderer();
  1030. }
  1031. this.renderer.init.call(this, this.rendererOptions);
  1032. };
  1033. Title.prototype.draw = function(width) {
  1034. return this.renderer.draw.call(this, width);
  1035. };
  1036. Title.prototype.pack = function() {
  1037. this.renderer.pack.call(this);
  1038. };
  1039. /**
  1040. * Class: Series
  1041. * An individual data series object. Cannot be instantiated directly, but created
  1042. * by the Plot oject. Series properties can be set or overriden by the
  1043. * options passed in from the user.
  1044. */
  1045. function Series(options) {
  1046. options = options || {};
  1047. $.jqplot.ElemContainer.call(this);
  1048. // Group: Properties
  1049. // Properties will be assigned from a series array at the top level of the
  1050. // options. If you had two series and wanted to change the color and line
  1051. // width of the first and set the second to use the secondary y axis with
  1052. // no shadow and supply custom labels for each:
  1053. // > {
  1054. // > series:[
  1055. // > {color: '#ff4466', lineWidth: 5, label:'good line'},
  1056. // > {yaxis: 'y2axis', shadow: false, label:'bad line'}
  1057. // > ]
  1058. // > }
  1059. // prop: show
  1060. // wether or not to draw the series.
  1061. this.show = true;
  1062. // prop: xaxis
  1063. // which x axis to use with this series, either 'xaxis' or 'x2axis'.
  1064. this.xaxis = 'xaxis';
  1065. this._xaxis;
  1066. // prop: yaxis
  1067. // which y axis to use with this series, either 'yaxis' or 'y2axis'.
  1068. this.yaxis = 'yaxis';
  1069. this._yaxis;
  1070. this.gridBorderWidth = 2.0;
  1071. // prop: renderer
  1072. // A class of a renderer which will draw the series,
  1073. // see <$.jqplot.LineRenderer>.
  1074. this.renderer = $.jqplot.LineRenderer;
  1075. // prop: rendererOptions
  1076. // Options to pass on to the renderer.
  1077. this.rendererOptions = {};
  1078. this.data = [];
  1079. this.gridData = [];
  1080. // prop: label
  1081. // Line label to use in the legend.
  1082. this.label = '';
  1083. // prop: showLabel
  1084. // true to show label for this series in the legend.
  1085. this.showLabel = true;
  1086. // prop: color
  1087. // css color spec for the series
  1088. this.color;
  1089. // prop: negativeColor
  1090. // css color spec used for filled (area) plots that are filled to zero and
  1091. // the "useNegativeColors" option is true.
  1092. this.negativeColor;
  1093. // prop: lineWidth
  1094. // width of the line in pixels. May have different meanings depending on renderer.
  1095. this.lineWidth = 2.5;
  1096. // prop: lineJoin
  1097. // Canvas lineJoin style between segments of series.
  1098. this.lineJoin = 'round';
  1099. // prop: lineCap
  1100. // Canvas lineCap style at ends of line.
  1101. this.lineCap = 'round';
  1102. // prop: linePattern
  1103. // line pattern 'dashed', 'dotted', 'solid', some combination
  1104. // of '-' and '.' characters such as '.-.' or a numerical array like
  1105. // [draw, skip, draw, skip, ...] such as [1, 10] to draw a dotted line,
  1106. // [1, 10, 20, 10] to draw a dot-dash line, and so on.
  1107. this.linePattern = 'solid';
  1108. this.shadow = true;
  1109. // prop: shadowAngle
  1110. // Shadow angle in degrees
  1111. this.shadowAngle = 45;
  1112. // prop: shadowOffset
  1113. // Shadow offset from line in pixels
  1114. this.shadowOffset = 1.25;
  1115. // prop: shadowDepth
  1116. // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
  1117. this.shadowDepth = 3;
  1118. // prop: shadowAlpha
  1119. // Alpha channel transparency of shadow. 0 = transparent.
  1120. this.shadowAlpha = '0.1';
  1121. // prop: breakOnNull
  1122. // Wether line segments should be be broken at null value.
  1123. // False will join point on either side of line.
  1124. this.breakOnNull = false;
  1125. // prop: markerRenderer
  1126. // A class of a renderer which will draw marker (e.g. circle, square, ...) at the data points,
  1127. // see <$.jqplot.MarkerRenderer>.
  1128. this.markerRenderer = $.jqplot.MarkerRenderer;
  1129. // prop: markerOptions
  1130. // renderer specific options to pass to the markerRenderer,
  1131. // see <$.jqplot.MarkerRenderer>.
  1132. this.markerOptions = {};
  1133. // prop: showLine
  1134. // wether to actually draw the line or not. Series will still be renderered, even if no line is drawn.
  1135. this.showLine = true;
  1136. // prop: showMarker
  1137. // wether or not to show the markers at the data points.
  1138. this.showMarker = true;
  1139. // prop: index
  1140. // 0 based index of this series in the plot series array.
  1141. this.index;
  1142. // prop: fill
  1143. // true or false, wether to fill under lines or in bars.
  1144. // May not be implemented in all renderers.
  1145. this.fill = false;
  1146. // prop: fillColor
  1147. // CSS color spec to use for fill under line. Defaults to line color.
  1148. this.fillColor;
  1149. // prop: fillAlpha
  1150. // Alpha transparency to apply to the fill under the line.
  1151. // Use this to adjust alpha separate from fill color.
  1152. this.fillAlpha;
  1153. // prop: fillAndStroke
  1154. // If true will stroke the line (with color this.color) as well as fill under it.
  1155. // Applies only when fill is true.
  1156. this.fillAndStroke = false;
  1157. // prop: disableStack
  1158. // true to not stack this series with other series in the plot.
  1159. // To render properly, non-stacked series must come after any stacked series
  1160. // in the plot's data series array. So, the plot's data series array would look like:
  1161. // > [stackedSeries1, stackedSeries2, ..., nonStackedSeries1, nonStackedSeries2, ...]
  1162. // disableStack will put a gap in the stacking order of series, and subsequent
  1163. // stacked series will not fill down through the non-stacked series and will
  1164. // most likely not stack properly on top of the non-stacked series.
  1165. this.disableStack = false;
  1166. // _stack is set by the Plot if the plot is a stacked chart.
  1167. // will stack lines or bars on top of one another to build a "mountain" style chart.
  1168. // May not be implemented in all renderers.
  1169. this._stack = false;
  1170. // prop: neighborThreshold
  1171. // how close or far (in pixels) the cursor must be from a point marker to detect the point.
  1172. this.neighborThreshold = 4;
  1173. // prop: fillToZero
  1174. // true will force bar and filled series to fill toward zero on the fill Axis.
  1175. this.fillToZero = false;
  1176. // prop: fillToValue
  1177. // fill a filled series to this value on the fill axis.
  1178. // Works in conjunction with fillToZero, so that must be true.
  1179. this.fillToValue = 0;
  1180. // prop: fillAxis
  1181. // Either 'x' or 'y'. Which axis to fill the line toward if fillToZero is true.
  1182. // 'y' means fill up/down to 0 on the y axis for this series.
  1183. this.fillAxis = 'y';
  1184. // prop: useNegativeColors
  1185. // true to color negative values differently in filled and bar charts.
  1186. this.useNegativeColors = true;
  1187. this._stackData = [];
  1188. // _plotData accounts for stacking. If plots not stacked, _plotData and data are same. If
  1189. // stacked, _plotData is accumulation of stacking data.
  1190. this._plotData = [];
  1191. // _plotValues hold the individual x and y values that will be plotted for this series.
  1192. this._plotValues = {x:[], y:[]};
  1193. // statistics about the intervals between data points. Used for auto scaling.
  1194. this._intervals = {x:{}, y:{}};
  1195. // data from the previous series, for stacked charts.
  1196. this._prevPlotData = [];
  1197. this._prevGridData = [];
  1198. this._stackAxis = 'y';
  1199. this._primaryAxis = '_xaxis';
  1200. // give each series a canvas to draw on. This should allow for redrawing speedups.
  1201. this.canvas = new $.jqplot.GenericCanvas();
  1202. this.shadowCanvas = new $.jqplot.GenericCanvas();
  1203. this.plugins = {};
  1204. // sum of y values in this series.
  1205. this._sumy = 0;
  1206. this._sumx = 0;
  1207. this._type = '';
  1208. }
  1209. Series.prototype = new $.jqplot.ElemContainer();
  1210. Series.prototype.constructor = Series;
  1211. Series.prototype.init = function(index, gridbw, plot) {
  1212. // weed out any null values in the data.
  1213. this.index = index;
  1214. this.gridBorderWidth = gridbw;
  1215. var d = this.data;
  1216. var temp = [], i, l;
  1217. for (i=0, l=d.length; i<l; i++) {
  1218. if (! this.breakOnNull) {
  1219. if (d[i] == null || d[i][0] == null || d[i][1] == null) {
  1220. continue;
  1221. }
  1222. else {
  1223. temp.push(d[i]);
  1224. }
  1225. }
  1226. else {
  1227. // TODO: figure out what to do with null values
  1228. // probably involve keeping nulls in data array
  1229. // and then updating renderers to break line
  1230. // when it hits null value.
  1231. // For now, just keep value.
  1232. temp.push(d[i]);
  1233. }
  1234. }
  1235. this.data = temp;
  1236. // parse the renderer options and apply default colors if not provided
  1237. // Set color even if not shown, so series don't change colors when other
  1238. // series on plot shown/hidden.
  1239. if (!this.color) {
  1240. this.color = plot.colorGenerator.get(this.index);
  1241. }
  1242. if (!this.negativeColor) {
  1243. this.negativeColor = plot.negativeColorGenerator.get(this.index);
  1244. }
  1245. if (!this.fillColor) {
  1246. this.fillColor = this.color;
  1247. }
  1248. if (this.fillAlpha) {
  1249. var comp = $.jqplot.normalize2rgb(this.fillColor);
  1250. var comp = $.jqplot.getColorComponents(comp);
  1251. this.fillColor = 'rgba('+comp[0]+','+comp[1]+','+comp[2]+','+this.fillAlpha+')';
  1252. }
  1253. if ($.isFunction(this.renderer)) {
  1254. this.renderer = new this.renderer();
  1255. }
  1256. this.renderer.init.call(this, this.rendererOptions, plot);
  1257. this.markerRenderer = new this.markerRenderer();
  1258. if (!this.markerOptions.color) {
  1259. this.markerOptions.color = this.color;
  1260. }
  1261. if (this.markerOptions.show == null) {
  1262. this.markerOptions.show = this.showMarker;
  1263. }
  1264. this.showMarker = this.markerOptions.show;
  1265. // the markerRenderer is called within it's own scaope, don't want to overwrite series options!!
  1266. this.markerRenderer.init(this.markerOptions);
  1267. };
  1268. // data - optional data point array to draw using this series renderer
  1269. // gridData - optional grid data point array to draw using this series renderer
  1270. // stackData - array of cumulative data for stacked plots.
  1271. Series.prototype.draw = function(sctx, opts, plot) {
  1272. var options = (opts == undefined) ? {} : opts;
  1273. sctx = (sctx == undefined) ? this.canvas._ctx : sctx;
  1274. var j, data, gridData;
  1275. // hooks get called even if series not shown
  1276. // we don't clear canvas here, it would wipe out all other series as well.
  1277. for (j=0; j<$.jqplot.preDrawSeriesHooks.length; j++) {
  1278. $.jqplot.preDrawSeriesHooks[j].call(this, sctx, options);
  1279. }
  1280. if (this.show) {
  1281. this.renderer.setGridData.call(this, plot);
  1282. if (!options.preventJqPlotSeriesDrawTrigger) {
  1283. $(sctx.canvas).trigger('jqplotSeriesDraw', [this.data, this.gridData]);
  1284. }
  1285. data = [];
  1286. if (options.data) {
  1287. data = options.data;
  1288. }
  1289. else if (!this._stack) {
  1290. data = this.data;
  1291. }
  1292. else {
  1293. data = this._plotData;
  1294. }
  1295. gridData = options.gridData || this.renderer.makeGridData.call(this, data, plot);
  1296. if (this._type === 'line' && this.renderer.smooth && this.renderer._smoothedData.length) {
  1297. gridData = this.renderer._smoothedData;
  1298. }
  1299. this.renderer.draw.call(this, sctx, gridData, options, plot);
  1300. }
  1301. for (j=0; j<$.jqplot.postDrawSeriesHooks.length; j++) {
  1302. $.jqplot.postDrawSeriesHooks[j].call(this, sctx, options, plot);
  1303. }
  1304. sctx = opts = plot = j = data = gridData = null;
  1305. };
  1306. Series.prototype.drawShadow = function(sctx, opts, plot) {
  1307. var options = (opts == undefined) ? {} : opts;
  1308. sctx = (sctx == undefined) ? this.shadowCanvas._ctx : sctx;
  1309. var j, data, gridData;
  1310. // hooks get called even if series not shown
  1311. // we don't clear canvas here, it would wipe out all other series as well.
  1312. for (j=0; j<$.jqplot.preDrawSeriesShadowHooks.length; j++) {
  1313. $.jqplot.preDrawSeriesShadowHooks[j].call(this, sctx, options);
  1314. }
  1315. if (this.shadow) {
  1316. this.renderer.setGridData.call(this, plot);
  1317. data = [];
  1318. if (options.data) {
  1319. data = options.data;
  1320. }
  1321. else if (!this._stack) {
  1322. data = this.data;
  1323. }
  1324. else {
  1325. data = this._plotData;
  1326. }
  1327. gridData = options.gridData || this.renderer.makeGridData.call(this, data, plot);
  1328. this.renderer.drawShadow.call(this, sctx, gridData, options, plot);
  1329. }
  1330. for (j=0; j<$.jqplot.postDrawSeriesShadowHooks.length; j++) {
  1331. $.jqplot.postDrawSeriesShadowHooks[j].call(this, sctx, options);
  1332. }
  1333. sctx = opts = plot = j = data = gridData = null;
  1334. };
  1335. // toggles series display on plot, e.g. show/hide series
  1336. Series.prototype.toggleDisplay = function(ev, callback) {
  1337. var s, speed;
  1338. if (ev.data.series) {
  1339. s = ev.data.series;
  1340. }
  1341. else {
  1342. s = this;
  1343. }
  1344. if (ev.data.speed) {
  1345. speed = ev.data.speed;
  1346. }
  1347. if (speed) {
  1348. // this can be tricky because series may not have a canvas element if replotting.
  1349. if (s.canvas._elem.is(':hidden') || !s.show) {
  1350. s.show = true;
  1351. s.canvas._elem.removeClass('jqplot-series-hidden');
  1352. if (s.shadowCanvas._elem) {
  1353. s.shadowCanvas._elem.fadeIn(speed);
  1354. }
  1355. s.canvas._elem.fadeIn(speed, callback);
  1356. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).fadeIn(speed);
  1357. }
  1358. else {
  1359. s.show = false;
  1360. s.canvas._elem.addClass('jqplot-series-hidden');
  1361. if (s.shadowCanvas._elem) {
  1362. s.shadowCanvas._elem.fadeOut(speed);
  1363. }
  1364. s.canvas._elem.fadeOut(speed, callback);
  1365. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).fadeOut(speed);
  1366. }
  1367. }
  1368. else {
  1369. // this can be tricky because series may not have a canvas element if replotting.
  1370. if (s.canvas._elem.is(':hidden') || !s.show) {
  1371. s.show = true;
  1372. s.canvas._elem.removeClass('jqplot-series-hidden');
  1373. if (s.shadowCanvas._elem) {
  1374. s.shadowCanvas._elem.show();
  1375. }
  1376. s.canvas._elem.show(0, callback);
  1377. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).show();
  1378. }
  1379. else {
  1380. s.show = false;
  1381. s.canvas._elem.addClass('jqplot-series-hidden');
  1382. if (s.shadowCanvas._elem) {
  1383. s.shadowCanvas._elem.hide();
  1384. }
  1385. s.canvas._elem.hide(0, callback);
  1386. s.canvas._elem.nextAll('.jqplot-point-label.jqplot-series-'+s.index).hide();
  1387. }
  1388. }
  1389. };
  1390. /**
  1391. * Class: Grid
  1392. *
  1393. * Object representing the grid on which the plot is drawn. The grid in this
  1394. * context is the area bounded by the axes, the area which will contain the series.
  1395. * Note, the series are drawn on their own canvas.
  1396. * The Grid object cannot be instantiated directly, but is created by the Plot oject.
  1397. * Grid properties can be set or overriden by the options passed in from the user.
  1398. */
  1399. function Grid() {
  1400. $.jqplot.ElemContainer.call(this);
  1401. // Group: Properties
  1402. // prop: drawGridlines
  1403. // wether to draw the gridlines on the plot.
  1404. this.drawGridlines = true;
  1405. // prop: gridLineColor
  1406. // color of the grid lines.
  1407. this.gridLineColor = '#cccccc';
  1408. // prop: gridLineWidth
  1409. // width of the grid lines.
  1410. this.gridLineWidth = 1.0;
  1411. // prop: background
  1412. // css spec for the background color.
  1413. this.background = '#fffdf6';
  1414. // prop: borderColor
  1415. // css spec for the color of the grid border.
  1416. this.borderColor = '#999999';
  1417. // prop: borderWidth
  1418. // width of the border in pixels.
  1419. this.borderWidth = 2.0;
  1420. // prop: drawBorder
  1421. // True to draw border around grid.
  1422. this.drawBorder = true;
  1423. // prop: shadow
  1424. // wether to show a shadow behind the grid.
  1425. this.shadow = true;
  1426. // prop: shadowAngle
  1427. // shadow angle in degrees
  1428. this.shadowAngle = 45;
  1429. // prop: shadowOffset
  1430. // Offset of each shadow stroke from the border in pixels
  1431. this.shadowOffset = 1.5;
  1432. // prop: shadowWidth
  1433. // width of the stoke for the shadow
  1434. this.shadowWidth = 3;
  1435. // prop: shadowDepth
  1436. // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
  1437. this.shadowDepth = 3;
  1438. // prop: shadowColor
  1439. // an optional css color spec for the shadow in 'rgba(n, n, n, n)' form
  1440. this.shadowColor = null;
  1441. // prop: shadowAlpha
  1442. // Alpha channel transparency of shadow. 0 = transparent.
  1443. this.shadowAlpha = '0.07';
  1444. this._left;
  1445. this._top;
  1446. this._right;
  1447. this._bottom;
  1448. this._width;
  1449. this._height;
  1450. this._axes = [];
  1451. // prop: renderer
  1452. // Instance of a renderer which will actually render the grid,
  1453. // see <$.jqplot.CanvasGridRenderer>.
  1454. this.renderer = $.jqplot.CanvasGridRenderer;
  1455. // prop: rendererOptions
  1456. // Options to pass on to the renderer,
  1457. // see <$.jqplot.CanvasGridRenderer>.
  1458. this.rendererOptions = {};
  1459. this._offsets = {top:null, bottom:null, left:null, right:null};
  1460. }
  1461. Grid.prototype = new $.jqplot.ElemContainer();
  1462. Grid.prototype.constructor = Grid;
  1463. Grid.prototype.init = function() {
  1464. if ($.isFunction(this.renderer)) {
  1465. this.renderer = new this.renderer();
  1466. }
  1467. this.renderer.init.call(this, this.rendererOptions);
  1468. };
  1469. Grid.prototype.createElement = function(offsets,plot) {
  1470. this._offsets = offsets;
  1471. return this.renderer.createElement.call(this, plot);
  1472. };
  1473. Grid.prototype.draw = function() {
  1474. this.renderer.draw.call(this);
  1475. };
  1476. $.jqplot.GenericCanvas = function() {
  1477. $.jqplot.ElemContainer.call(this);
  1478. this._ctx;
  1479. };
  1480. $.jqplot.GenericCanvas.prototype = new $.jqplot.ElemContainer();
  1481. $.jqplot.GenericCanvas.prototype.constructor = $.jqplot.GenericCanvas;
  1482. $.jqplot.GenericCanvas.prototype.createElement = function(offsets, clss, plotDimensions, plot) {
  1483. this._offsets = offsets;
  1484. var klass = 'jqplot';
  1485. if (clss != undefined) {
  1486. klass = clss;
  1487. }
  1488. var elem;
  1489. elem = plot.canvasManager.getCanvas();
  1490. // if new plotDimensions supplied, use them.
  1491. if (plotDimensions != null) {
  1492. this._plotDimensions = plotDimensions;
  1493. }
  1494. elem.width = this._plotDimensions.width - this._offsets.left - this._offsets.right;
  1495. elem.height = this._plotDimensions.height - this._offsets.top - this._offsets.bottom;
  1496. this._elem = $(elem);
  1497. this._elem.css({ position: 'absolute', left: this._offsets.left, top: this._offsets.top });
  1498. this._elem.addClass(klass);
  1499. elem = plot.canvasManager.initCanvas(elem);
  1500. elem = null;
  1501. return this._elem;
  1502. };
  1503. $.jqplot.GenericCanvas.prototype.setContext = function() {
  1504. this._ctx = this._elem.get(0).getContext("2d");
  1505. return this._ctx;
  1506. };
  1507. // Memory Leaks patch
  1508. $.jqplot.GenericCanvas.prototype.resetCanvas = function() {
  1509. if (this._elem) {
  1510. if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
  1511. window.G_vmlCanvasManager.uninitElement(this._elem.get(0));
  1512. }
  1513. //this._elem.remove();
  1514. this._elem.emptyForce();
  1515. }
  1516. this._ctx = null;
  1517. };
  1518. $.jqplot.HooksManager = function () {
  1519. this.hooks =[];
  1520. this.args = [];
  1521. };
  1522. $.jqplot.HooksManager.prototype.addOnce = function(fn, args) {
  1523. args = args || [];
  1524. var havehook = false;
  1525. for (var i=0, l=this.hooks.length; i<l; i++) {
  1526. if (this.hooks[i] == fn) {
  1527. havehook = true;
  1528. }
  1529. }
  1530. if (!havehook) {
  1531. this.hooks.push(fn);
  1532. this.args.push(args);
  1533. }
  1534. };
  1535. $.jqplot.HooksManager.prototype.add = function(fn, args) {
  1536. args = args || [];
  1537. this.hooks.push(fn);
  1538. this.args.push(args);
  1539. };
  1540. $.jqplot.EventListenerManager = function () {
  1541. this.hooks =[];
  1542. };
  1543. $.jqplot.EventListenerManager.prototype.addOnce = function(ev, fn) {
  1544. var havehook = false, h, i;
  1545. for (var i=0, l=this.hooks.length; i<l; i++) {
  1546. h = this.hooks[i];
  1547. if (h[0] == ev && h[1] == fn) {
  1548. havehook = true;
  1549. }
  1550. }
  1551. if (!havehook) {
  1552. this.hooks.push([ev, fn]);
  1553. }
  1554. };
  1555. $.jqplot.EventListenerManager.prototype.add = function(ev, fn) {
  1556. this.hooks.push([ev, fn]);
  1557. };
  1558. var _axisNames = ['yMidAxis', 'xaxis', 'yaxis', 'x2axis', 'y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
  1559. /**
  1560. * Class: jqPlot
  1561. * Plot object returned by call to $.jqplot. Handles parsing user options,
  1562. * creating sub objects (Axes, legend, title, series) and rendering the plot.
  1563. */
  1564. function jqPlot() {
  1565. // Group: Properties
  1566. // These properties are specified at the top of the options object
  1567. // like so:
  1568. // > {
  1569. // > axesDefaults:{min:0},
  1570. // > series:[{color:'#6633dd'}],
  1571. // > title: 'A Plot'
  1572. // > }
  1573. //
  1574. // prop: animate
  1575. // True to animate the series on initial plot draw (renderer dependent).
  1576. // Actual animation functionality must be supported in the renderer.
  1577. this.animate = false;
  1578. // prop: animateReplot
  1579. // True to animate series after a call to the replot() method.
  1580. // Use with caution! Replots can happen very frequently under
  1581. // certain circumstances (e.g. resizing, dragging points) and
  1582. // animation in these situations can cause problems.
  1583. this.animateReplot = false;
  1584. // prop: axes
  1585. // up to 4 axes are supported, each with it's own options,
  1586. // See <Axis> for axis specific options.
  1587. 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'), yMidAxis: new Axis('yMidAxis')};
  1588. this.baseCanvas = new $.jqplot.GenericCanvas();
  1589. // true to intercept right click events and fire a 'jqplotRightClick' event.
  1590. // this will also block the context menu.
  1591. this.captureRightClick = false;
  1592. // prop: data
  1593. // user's data. Data should *NOT* be specified in the options object,
  1594. // but be passed in as the second argument to the $.jqplot() function.
  1595. // The data property is described here soley for reference.
  1596. // The data should be in the form of an array of 2D or 1D arrays like
  1597. // > [ [[x1, y1], [x2, y2],...], [y1, y2, ...] ].
  1598. this.data = [];
  1599. // prop: dataRenderer
  1600. // A callable which can be used to preprocess data passed into the plot.
  1601. // Will be called with 2 arguments, the plot data and a reference to the plot.
  1602. this.dataRenderer;
  1603. // prop: dataRendererOptions
  1604. // Options that will be passed to the dataRenderer.
  1605. // Can be of any type.
  1606. this.dataRendererOptions;
  1607. this.defaults = {
  1608. // prop: axesDefaults
  1609. // default options that will be applied to all axes.
  1610. // see <Axis> for axes options.
  1611. axesDefaults: {},
  1612. axes: {xaxis:{}, yaxis:{}, x2axis:{}, y2axis:{}, y3axis:{}, y4axis:{}, y5axis:{}, y6axis:{}, y7axis:{}, y8axis:{}, y9axis:{}, yMidAxis:{}},
  1613. // prop: seriesDefaults
  1614. // default options that will be applied to all series.
  1615. // see <Series> for series options.
  1616. seriesDefaults: {},
  1617. series:[]
  1618. };
  1619. // prop: defaultAxisStart
  1620. // 1-D data series are internally converted into 2-D [x,y] data point arrays
  1621. // by jqPlot. This is the default starting value for the missing x or y value.
  1622. // The added data will be a monotonically increasing series (e.g. [1, 2, 3, ...])
  1623. // starting at this value.
  1624. this.defaultAxisStart = 1;
  1625. // this.doCustomEventBinding = true;
  1626. // prop: drawIfHidden
  1627. // True to execute the draw method even if the plot target is hidden.
  1628. // Generally, this should be false. Most plot elements will not be sized/
  1629. // positioned correclty if renderered into a hidden container. To render into
  1630. // a hidden container, call the replot method when the container is shown.
  1631. this.drawIfHidden = false;
  1632. this.eventCanvas = new $.jqplot.GenericCanvas();
  1633. // prop: fillBetween
  1634. // Fill between 2 line series in a plot.
  1635. // Options object:
  1636. // {
  1637. // series1: first index (0 based) of series in fill
  1638. // series2: second index (0 based) of series in fill
  1639. // color: color of fill [default fillColor of series1]
  1640. // baseSeries: fill will be drawn below this series (0 based index)
  1641. // fill: false to turn off fill [default true].
  1642. // }
  1643. this.fillBetween = {
  1644. series1: null,
  1645. series2: null,
  1646. color: null,
  1647. baseSeries: 0,
  1648. fill: true
  1649. };
  1650. // prop; fontFamily
  1651. // css spec for the font-family attribute. Default for the entire plot.
  1652. this.fontFamily;
  1653. // prop: fontSize
  1654. // css spec for the font-size attribute. Default for the entire plot.
  1655. this.fontSize;
  1656. // prop: grid
  1657. // See <Grid> for grid specific options.
  1658. this.grid = new Grid();
  1659. // prop: legend
  1660. // see <$.jqplot.TableLegendRenderer>
  1661. this.legend = new Legend();
  1662. // prop: noDataIndicator
  1663. // Options to set up a mock plot with a data loading indicator if no data is specified.
  1664. this.negativeSeriesColors = $.jqplot.config.defaultNegativeColors;
  1665. this.noDataIndicator = {
  1666. show: false,
  1667. indicator: 'Loading Data...',
  1668. axes: {
  1669. xaxis: {
  1670. min: 0,
  1671. max: 10,
  1672. tickInterval: 2,
  1673. show: true
  1674. },
  1675. yaxis: {
  1676. min: 0,
  1677. max: 12,
  1678. tickInterval: 3,
  1679. show: true
  1680. }
  1681. }
  1682. };
  1683. // container to hold all of the merged options. Convienence for plugins.
  1684. this.options = {};
  1685. this.previousSeriesStack = [];
  1686. // Namespece to hold plugins. Generally non-renderer plugins add themselves to here.
  1687. this.plugins = {};
  1688. // prop: series
  1689. // Array of series object options.
  1690. // see <Series> for series specific options.
  1691. this.series = [];
  1692. // array of series indicies. Keep track of order
  1693. // which series canvases are displayed, lowest
  1694. // to highest, back to front.
  1695. this.seriesStack = [];
  1696. // prop: seriesColors
  1697. // Ann array of CSS color specifications that will be applied, in order,
  1698. // to the series in the plot. Colors will wrap around so, if their
  1699. // are more series than colors, colors will be reused starting at the
  1700. // beginning. For pie charts, this specifies the colors of the slices.
  1701. this.seriesColors = $.jqplot.config.defaultColors;
  1702. // prop: sortData
  1703. // false to not sort the data passed in by the user.
  1704. // Many bar, stakced and other graphs as well as many plugins depend on
  1705. // having sorted data.
  1706. this.sortData = true;
  1707. // prop: stackSeries
  1708. // true or false, creates a stack or "mountain" plot.
  1709. // Not all series renderers may implement this option.
  1710. this.stackSeries = false;
  1711. // a shortcut for axis syncTicks options. Not implemented yet.
  1712. this.syncXTicks = true;
  1713. // a shortcut for axis syncTicks options. Not implemented yet.
  1714. this.syncYTicks = true;
  1715. // the jquery object for the dom target.
  1716. this.target = null;
  1717. // The id of the dom element to render the plot into
  1718. this.targetId = null;
  1719. // prop textColor
  1720. // css spec for the css color attribute. Default for the entire plot.
  1721. this.textColor;
  1722. // prop: title
  1723. // Title object. See <Title> for specific options. As a shortcut, you
  1724. // can specify the title option as just a string like: title: 'My Plot'
  1725. // and this will create a new title object with the specified text.
  1726. this.title = new Title();
  1727. // Count how many times the draw method has been called while the plot is visible.
  1728. // Mostly used to test if plot has never been dran (=0), has been successfully drawn
  1729. // into a visible container once (=1) or draw more than once into a visible container.
  1730. // Can use this in tests to see if plot has been visibly drawn at least one time.
  1731. // After plot has been visibly drawn once, it generally doesn't need redrawn if its
  1732. // container is hidden and shown.
  1733. this._drawCount = 0;
  1734. // sum of y values for all series in plot.
  1735. // used in mekko chart.
  1736. this._sumy = 0;
  1737. this._sumx = 0;
  1738. // array to hold the cumulative stacked series data.
  1739. // used to ajust the individual series data, which won't have access to other
  1740. // series data.
  1741. this._stackData = [];
  1742. // array that holds the data to be plotted. This will be the series data
  1743. // merged with the the appropriate data from _stackData according to the stackAxis.
  1744. this._plotData = [];
  1745. this._width = null;
  1746. this._height = null;
  1747. this._plotDimensions = {height:null, width:null};
  1748. this._gridPadding = {top:null, right:null, bottom:null, left:null};
  1749. this._defaultGridPadding = {top:10, right:10, bottom:23, left:10};
  1750. this._addDomReference = $.jqplot.config.addDomReference;
  1751. this.preInitHooks = new $.jqplot.HooksManager();
  1752. this.postInitHooks = new $.jqplot.HooksManager();
  1753. this.preParseOptionsHooks = new $.jqplot.HooksManager();
  1754. this.postParseOptionsHooks = new $.jqplot.HooksManager();
  1755. this.preDrawHooks = new $.jqplot.HooksManager();
  1756. this.postDrawHooks = new $.jqplot.HooksManager();
  1757. this.preDrawSeriesHooks = new $.jqplot.HooksManager();
  1758. this.postDrawSeriesHooks = new $.jqplot.HooksManager();
  1759. this.preDrawLegendHooks = new $.jqplot.HooksManager();
  1760. this.addLegendRowHooks = new $.jqplot.HooksManager();
  1761. this.preSeriesInitHooks = new $.jqplot.HooksManager();
  1762. this.postSeriesInitHooks = new $.jqplot.HooksManager();
  1763. this.preParseSeriesOptionsHooks = new $.jqplot.HooksManager();
  1764. this.postParseSeriesOptionsHooks = new $.jqplot.HooksManager();
  1765. this.eventListenerHooks = new $.jqplot.EventListenerManager();
  1766. this.preDrawSeriesShadowHooks = new $.jqplot.HooksManager();
  1767. this.postDrawSeriesShadowHooks = new $.jqplot.HooksManager();
  1768. this.colorGenerator = new $.jqplot.ColorGenerator();
  1769. this.negativeColorGenerator = new $.jqplot.ColorGenerator();
  1770. this.canvasManager = new $.jqplot.CanvasManager();
  1771. this.themeEngine = new $.jqplot.ThemeEngine();
  1772. var seriesColorsIndex = 0;
  1773. // Group: methods
  1774. //
  1775. // method: init
  1776. // sets the plot target, checks data and applies user
  1777. // options to plot.
  1778. this.init = function(target, data, options) {
  1779. options = options || {};
  1780. for (var i=0; i<$.jqplot.preInitHooks.length; i++) {
  1781. $.jqplot.preInitHooks[i].call(this, target, data, options);
  1782. }
  1783. for (var i=0; i<this.preInitHooks.hooks.length; i++) {
  1784. this.preInitHooks.hooks[i].call(this, target, data, options);
  1785. }
  1786. this.targetId = '#'+target;
  1787. this.target = $('#'+target);
  1788. //////
  1789. // Add a reference to plot
  1790. //////
  1791. if (this._addDomReference) {
  1792. this.target.data('jqplot', this);
  1793. }
  1794. // remove any error class that may be stuck on target.
  1795. this.target.removeClass('jqplot-error');
  1796. if (!this.target.get(0)) {
  1797. throw "No plot target specified";
  1798. }
  1799. // make sure the target is positioned by some means and set css
  1800. if (this.target.css('position') == 'static') {
  1801. this.target.css('position', 'relative');
  1802. }
  1803. if (!this.target.hasClass('jqplot-target')) {
  1804. this.target.addClass('jqplot-target');
  1805. }
  1806. // if no height or width specified, use a default.
  1807. if (!this.target.height()) {
  1808. var h;
  1809. if (options && options.height) {
  1810. h = parseInt(options.height, 10);
  1811. }
  1812. else if (this.target.attr('data-height')) {
  1813. h = parseInt(this.target.attr('data-height'), 10);
  1814. }
  1815. else {
  1816. h = parseInt($.jqplot.config.defaultHeight, 10);
  1817. }
  1818. this._height = h;
  1819. this.target.css('height', h+'px');
  1820. }
  1821. else {
  1822. this._height = h = this.target.height();
  1823. }
  1824. if (!this.target.width()) {
  1825. var w;
  1826. if (options && options.width) {
  1827. w = parseInt(options.width, 10);
  1828. }
  1829. else if (this.target.attr('data-width')) {
  1830. w = parseInt(this.target.attr('data-width'), 10);
  1831. }
  1832. else {
  1833. w = parseInt($.jqplot.config.defaultWidth, 10);
  1834. }
  1835. this._width = w;
  1836. this.target.css('width', w+'px');
  1837. }
  1838. else {
  1839. this._width = w = this.target.width();
  1840. }
  1841. for (var i=0, l=_axisNames.length; i<l; i++) {
  1842. this.axes[_axisNames[i]] = new Axis(_axisNames[i]);
  1843. }
  1844. this._plotDimensions.height = this._height;
  1845. this._plotDimensions.width = this._width;
  1846. this.grid._plotDimensions = this._plotDimensions;
  1847. this.title._plotDimensions = this._plotDimensions;
  1848. this.baseCanvas._plotDimensions = this._plotDimensions;
  1849. this.eventCanvas._plotDimensions = this._plotDimensions;
  1850. this.legend._plotDimensions = this._plotDimensions;
  1851. if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
  1852. throw "Canvas dimension not set";
  1853. }
  1854. if (options.dataRenderer && $.isFunction(options.dataRenderer)) {
  1855. if (options.dataRendererOptions) {
  1856. this.dataRendererOptions = options.dataRendererOptions;
  1857. }
  1858. this.dataRenderer = options.dataRenderer;
  1859. data = this.dataRenderer(data, this, this.dataRendererOptions);
  1860. }
  1861. if (options.noDataIndicator && $.isPlainObject(options.noDataIndicator)) {
  1862. $.extend(true, this.noDataIndicator, options.noDataIndicator);
  1863. }
  1864. if (data == null || $.isArray(data) == false || data.length == 0 || $.isArray(data[0]) == false || data[0].length == 0) {
  1865. if (this.noDataIndicator.show == false) {
  1866. throw "No Data";
  1867. }
  1868. else {
  1869. // have to be descructive here in order for plot to not try and render series.
  1870. // This means that $.jqplot() will have to be called again when there is data.
  1871. //delete options.series;
  1872. for (var ax in this.noDataIndicator.axes) {
  1873. for (var prop in this.noDataIndicator.axes[ax]) {
  1874. this.axes[ax][prop] = this.noDataIndicator.axes[ax][prop];
  1875. }
  1876. }
  1877. this.postDrawHooks.add(function() {
  1878. var eh = this.eventCanvas.getHeight();
  1879. var ew = this.eventCanvas.getWidth();
  1880. var temp = $('<div class="jqplot-noData-container" style="position:absolute;"></div>');
  1881. this.target.append(temp);
  1882. temp.height(eh);
  1883. temp.width(ew);
  1884. temp.css('top', this.eventCanvas._offsets.top);
  1885. temp.css('left', this.eventCanvas._offsets.left);
  1886. var temp2 = $('<div class="jqplot-noData-contents" style="text-align:center; position:relative; margin-left:auto; margin-right:auto;"></div>');
  1887. temp.append(temp2);
  1888. temp2.html(this.noDataIndicator.indicator);
  1889. var th = temp2.height();
  1890. var tw = temp2.width();
  1891. temp2.height(th);
  1892. temp2.width(tw);
  1893. temp2.css('top', (eh - th)/2 + 'px');
  1894. });
  1895. }
  1896. }
  1897. // make a copy of the data
  1898. this.data = $.extend(true, [], data);
  1899. this.parseOptions(options);
  1900. if (this.textColor) {
  1901. this.target.css('color', this.textColor);
  1902. }
  1903. if (this.fontFamily) {
  1904. this.target.css('font-family', this.fontFamily);
  1905. }
  1906. if (this.fontSize) {
  1907. this.target.css('font-size', this.fontSize);
  1908. }
  1909. this.title.init();
  1910. this.legend.init();
  1911. this._sumy = 0;
  1912. this._sumx = 0;
  1913. this.computePlotData();
  1914. for (var i=0; i<this.series.length; i++) {
  1915. // set default stacking order for series canvases
  1916. this.seriesStack.push(i);
  1917. this.previousSeriesStack.push(i);
  1918. this.series[i].shadowCanvas._plotDimensions = this._plotDimensions;
  1919. this.series[i].canvas._plotDimensions = this._plotDimensions;
  1920. for (var j=0; j<$.jqplot.preSeriesInitHooks.length; j++) {
  1921. $.jqplot.preSeriesInitHooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  1922. }
  1923. for (var j=0; j<this.preSeriesInitHooks.hooks.length; j++) {
  1924. this.preSeriesInitHooks.hooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  1925. }
  1926. // this.populatePlotData(this.series[i], i);
  1927. this.series[i]._plotDimensions = this._plotDimensions;
  1928. this.series[i].init(i, this.grid.borderWidth, this);
  1929. for (var j=0; j<$.jqplot.postSeriesInitHooks.length; j++) {
  1930. $.jqplot.postSeriesInitHooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  1931. }
  1932. for (var j=0; j<this.postSeriesInitHooks.hooks.length; j++) {
  1933. this.postSeriesInitHooks.hooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  1934. }
  1935. this._sumy += this.series[i]._sumy;
  1936. this._sumx += this.series[i]._sumx;
  1937. }
  1938. var name,
  1939. axis;
  1940. for (var i=0, l=_axisNames.length; i<l; i++) {
  1941. name = _axisNames[i];
  1942. axis = this.axes[name];
  1943. axis._plotDimensions = this._plotDimensions;
  1944. axis.init();
  1945. if (this.axes[name].borderColor == null) {
  1946. if (name.charAt(0) !== 'x' && axis.useSeriesColor === true && axis.show) {
  1947. axis.borderColor = axis._series[0].color;
  1948. }
  1949. else {
  1950. axis.borderColor = this.grid.borderColor;
  1951. }
  1952. }
  1953. }
  1954. if (this.sortData) {
  1955. sortData(this.series);
  1956. }
  1957. this.grid.init();
  1958. this.grid._axes = this.axes;
  1959. this.legend._series = this.series;
  1960. for (var i=0; i<$.jqplot.postInitHooks.length; i++) {
  1961. $.jqplot.postInitHooks[i].call(this, target, this.data, options);
  1962. }
  1963. for (var i=0; i<this.postInitHooks.hooks.length; i++) {
  1964. this.postInitHooks.hooks[i].call(this, target, this.data, options);
  1965. }
  1966. };
  1967. // method: resetAxesScale
  1968. // Reset the specified axes min, max, numberTicks and tickInterval properties to null
  1969. // or reset these properties on all axes if no list of axes is provided.
  1970. //
  1971. // Parameters:
  1972. // axes - Boolean to reset or not reset all axes or an array or object of axis names to reset.
  1973. this.resetAxesScale = function(axes, options) {
  1974. var opts = options || {};
  1975. var ax = axes || this.axes;
  1976. if (ax === true) {
  1977. ax = this.axes;
  1978. }
  1979. if ($.isArray(ax)) {
  1980. for (var i = 0; i < ax.length; i++) {
  1981. this.axes[ax[i]].resetScale(opts[ax[i]]);
  1982. }
  1983. }
  1984. else if (typeof(ax) === 'object') {
  1985. for (var name in ax) {
  1986. this.axes[name].resetScale(opts[name]);
  1987. }
  1988. }
  1989. };
  1990. // method: reInitialize
  1991. // reinitialize plot for replotting.
  1992. // not called directly.
  1993. this.reInitialize = function (data, opts) {
  1994. // Plot should be visible and have a height and width.
  1995. // If plot doesn't have height and width for some
  1996. // reason, set it by other means. Plot must not have
  1997. // a display:none attribute, however.
  1998. var options = $.extend(true, {}, this.options, opts);
  1999. var target = this.targetId.substr(1);
  2000. var tdata = (data == null) ? this.data : data;
  2001. for (var i=0; i<$.jqplot.preInitHooks.length; i++) {
  2002. $.jqplot.preInitHooks[i].call(this, target, tdata, options);
  2003. }
  2004. for (var i=0; i<this.preInitHooks.hooks.length; i++) {
  2005. this.preInitHooks.hooks[i].call(this, target, tdata, options);
  2006. }
  2007. this._height = this.target.height();
  2008. this._width = this.target.width();
  2009. if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
  2010. throw "Target dimension not set";
  2011. }
  2012. this._plotDimensions.height = this._height;
  2013. this._plotDimensions.width = this._width;
  2014. this.grid._plotDimensions = this._plotDimensions;
  2015. this.title._plotDimensions = this._plotDimensions;
  2016. this.baseCanvas._plotDimensions = this._plotDimensions;
  2017. this.eventCanvas._plotDimensions = this._plotDimensions;
  2018. this.legend._plotDimensions = this._plotDimensions;
  2019. var name,
  2020. t,
  2021. j,
  2022. axis;
  2023. for (var i=0, l=_axisNames.length; i<l; i++) {
  2024. name = _axisNames[i];
  2025. axis = this.axes[name];
  2026. // Memory Leaks patch : clear ticks elements
  2027. t = axis._ticks;
  2028. for (var j = 0, tlen = t.length; j < tlen; j++) {
  2029. var el = t[j]._elem;
  2030. if (el) {
  2031. // if canvas renderer
  2032. if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
  2033. window.G_vmlCanvasManager.uninitElement(el.get(0));
  2034. }
  2035. el.emptyForce();
  2036. el = null;
  2037. t._elem = null;
  2038. }
  2039. }
  2040. t = null;
  2041. delete axis.ticks;
  2042. delete axis._ticks;
  2043. this.axes[name] = new Axis(name);
  2044. this.axes[name]._plotWidth = this._width;
  2045. this.axes[name]._plotHeight = this._height;
  2046. }
  2047. if (data) {
  2048. if (options.dataRenderer && $.isFunction(options.dataRenderer)) {
  2049. if (options.dataRendererOptions) {
  2050. this.dataRendererOptions = options.dataRendererOptions;
  2051. }
  2052. this.dataRenderer = options.dataRenderer;
  2053. data = this.dataRenderer(data, this, this.dataRendererOptions);
  2054. }
  2055. // make a copy of the data
  2056. this.data = $.extend(true, [], data);
  2057. }
  2058. if (opts) {
  2059. this.parseOptions(options);
  2060. }
  2061. this.title._plotWidth = this._width;
  2062. if (this.textColor) {
  2063. this.target.css('color', this.textColor);
  2064. }
  2065. if (this.fontFamily) {
  2066. this.target.css('font-family', this.fontFamily);
  2067. }
  2068. if (this.fontSize) {
  2069. this.target.css('font-size', this.fontSize);
  2070. }
  2071. this.title.init();
  2072. this.legend.init();
  2073. this._sumy = 0;
  2074. this._sumx = 0;
  2075. this.seriesStack = [];
  2076. this.previousSeriesStack = [];
  2077. this.computePlotData();
  2078. for (var i=0, l=this.series.length; i<l; i++) {
  2079. // set default stacking order for series canvases
  2080. this.seriesStack.push(i);
  2081. this.previousSeriesStack.push(i);
  2082. this.series[i].shadowCanvas._plotDimensions = this._plotDimensions;
  2083. this.series[i].canvas._plotDimensions = this._plotDimensions;
  2084. for (var j=0; j<$.jqplot.preSeriesInitHooks.length; j++) {
  2085. $.jqplot.preSeriesInitHooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  2086. }
  2087. for (var j=0; j<this.preSeriesInitHooks.hooks.length; j++) {
  2088. this.preSeriesInitHooks.hooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  2089. }
  2090. // this.populatePlotData(this.series[i], i);
  2091. this.series[i]._plotDimensions = this._plotDimensions;
  2092. this.series[i].init(i, this.grid.borderWidth, this);
  2093. for (var j=0; j<$.jqplot.postSeriesInitHooks.length; j++) {
  2094. $.jqplot.postSeriesInitHooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  2095. }
  2096. for (var j=0; j<this.postSeriesInitHooks.hooks.length; j++) {
  2097. this.postSeriesInitHooks.hooks[j].call(this.series[i], target, this.data, this.options.seriesDefaults, this.options.series[i], this);
  2098. }
  2099. this._sumy += this.series[i]._sumy;
  2100. this._sumx += this.series[i]._sumx;
  2101. }
  2102. for (var i=0, l=_axisNames.length; i<l; i++) {
  2103. name = _axisNames[i];
  2104. axis = this.axes[name];
  2105. axis._plotDimensions = this._plotDimensions;
  2106. axis.init();
  2107. if (axis.borderColor == null) {
  2108. if (name.charAt(0) !== 'x' && axis.useSeriesColor === true && axis.show) {
  2109. axis.borderColor = axis._series[0].color;
  2110. }
  2111. else {
  2112. axis.borderColor = this.grid.borderColor;
  2113. }
  2114. }
  2115. }
  2116. if (this.sortData) {
  2117. sortData(this.series);
  2118. }
  2119. this.grid.init();
  2120. this.grid._axes = this.axes;
  2121. this.legend._series = this.series;
  2122. for (var i=0, l=$.jqplot.postInitHooks.length; i<l; i++) {
  2123. $.jqplot.postInitHooks[i].call(this, target, this.data, options);
  2124. }
  2125. for (var i=0, l=this.postInitHooks.hooks.length; i<l; i++) {
  2126. this.postInitHooks.hooks[i].call(this, target, this.data, options);
  2127. }
  2128. };
  2129. // method: quickInit
  2130. //
  2131. // Quick reinitialization plot for replotting.
  2132. // Does not parse options ore recreate axes and series.
  2133. // not called directly.
  2134. this.quickInit = function () {
  2135. // Plot should be visible and have a height and width.
  2136. // If plot doesn't have height and width for some
  2137. // reason, set it by other means. Plot must not have
  2138. // a display:none attribute, however.
  2139. this._height = this.target.height();
  2140. this._width = this.target.width();
  2141. if (this._height <=0 || this._width <=0 || !this._height || !this._width) {
  2142. throw "Target dimension not set";
  2143. }
  2144. this._plotDimensions.height = this._height;
  2145. this._plotDimensions.width = this._width;
  2146. this.grid._plotDimensions = this._plotDimensions;
  2147. this.title._plotDimensions = this._plotDimensions;
  2148. this.baseCanvas._plotDimensions = this._plotDimensions;
  2149. this.eventCanvas._plotDimensions = this._plotDimensions;
  2150. this.legend._plotDimensions = this._plotDimensions;
  2151. for (var n in this.axes) {
  2152. this.axes[n]._plotWidth = this._width;
  2153. this.axes[n]._plotHeight = this._height;
  2154. }
  2155. this.title._plotWidth = this._width;
  2156. if (this.textColor) {
  2157. this.target.css('color', this.textColor);
  2158. }
  2159. if (this.fontFamily) {
  2160. this.target.css('font-family', this.fontFamily);
  2161. }
  2162. if (this.fontSize) {
  2163. this.target.css('font-size', this.fontSize);
  2164. }
  2165. this._sumy = 0;
  2166. this._sumx = 0;
  2167. this.computePlotData();
  2168. for (var i=0; i<this.series.length; i++) {
  2169. // this.populatePlotData(this.series[i], i);
  2170. if (this.series[i]._type === 'line' && this.series[i].renderer.bands.show) {
  2171. this.series[i].renderer.initBands.call(this.series[i], this.series[i].renderer.options, this);
  2172. }
  2173. this.series[i]._plotDimensions = this._plotDimensions;
  2174. this.series[i].canvas._plotDimensions = this._plotDimensions;
  2175. //this.series[i].init(i, this.grid.borderWidth);
  2176. this._sumy += this.series[i]._sumy;
  2177. this._sumx += this.series[i]._sumx;
  2178. }
  2179. var name;
  2180. for (var j=0; j<12; j++) {
  2181. name = _axisNames[j];
  2182. // Memory Leaks patch : clear ticks elements
  2183. var t = this.axes[name]._ticks;
  2184. for (var i = 0; i < t.length; i++) {
  2185. var el = t[i]._elem;
  2186. if (el) {
  2187. // if canvas renderer
  2188. if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
  2189. window.G_vmlCanvasManager.uninitElement(el.get(0));
  2190. }
  2191. el.emptyForce();
  2192. el = null;
  2193. t._elem = null;
  2194. }
  2195. }
  2196. t = null;
  2197. this.axes[name]._plotDimensions = this._plotDimensions;
  2198. this.axes[name]._ticks = [];
  2199. // this.axes[name].renderer.init.call(this.axes[name], {});
  2200. }
  2201. if (this.sortData) {
  2202. sortData(this.series);
  2203. }
  2204. this.grid._axes = this.axes;
  2205. this.legend._series = this.series;
  2206. };
  2207. // sort the series data in increasing order.
  2208. function sortData(series) {
  2209. var d, sd, pd, ppd, ret;
  2210. for (var i=0; i<series.length; i++) {
  2211. var check;
  2212. var bat = [series[i].data, series[i]._stackData, series[i]._plotData, series[i]._prevPlotData];
  2213. for (var n=0; n<4; n++) {
  2214. check = true;
  2215. d = bat[n];
  2216. if (series[i]._stackAxis == 'x') {
  2217. for (var j = 0; j < d.length; j++) {
  2218. if (typeof(d[j][1]) != "number") {
  2219. check = false;
  2220. break;
  2221. }
  2222. }
  2223. if (check) {
  2224. d.sort(function(a,b) { return a[1] - b[1]; });
  2225. }
  2226. }
  2227. else {
  2228. for (var j = 0; j < d.length; j++) {
  2229. if (typeof(d[j][0]) != "number") {
  2230. check = false;
  2231. break;
  2232. }
  2233. }
  2234. if (check) {
  2235. d.sort(function(a,b) { return a[0] - b[0]; });
  2236. }
  2237. }
  2238. }
  2239. }
  2240. }
  2241. this.computePlotData = function() {
  2242. this._plotData = [];
  2243. this._stackData = [];
  2244. var series,
  2245. index,
  2246. l;
  2247. for (index=0, l=this.series.length; index<l; index++) {
  2248. series = this.series[index];
  2249. this._plotData.push([]);
  2250. this._stackData.push([]);
  2251. var cd = series.data;
  2252. this._plotData[index] = $.extend(true, [], cd);
  2253. this._stackData[index] = $.extend(true, [], cd);
  2254. series._plotData = this._plotData[index];
  2255. series._stackData = this._stackData[index];
  2256. var plotValues = {x:[], y:[]};
  2257. if (this.stackSeries && !series.disableStack) {
  2258. series._stack = true;
  2259. ///////////////////////////
  2260. // have to check for nulls
  2261. ///////////////////////////
  2262. var sidx = (series._stackAxis === 'x') ? 0 : 1;
  2263. for (var k=0, cdl=cd.length; k<cdl; k++) {
  2264. var temp = cd[k][sidx];
  2265. if (temp == null) {
  2266. temp = 0;
  2267. }
  2268. this._plotData[index][k][sidx] = temp;
  2269. this._stackData[index][k][sidx] = temp;
  2270. if (index > 0) {
  2271. for (var j=index; j--;) {
  2272. var prevval = this._plotData[j][k][sidx];
  2273. // only need to sum up the stack axis column of data
  2274. // and only sum if it is of same sign.
  2275. // if previous series isn't same sign, keep looking
  2276. // at earlier series untill we find one of same sign.
  2277. if (temp * prevval >= 0) {
  2278. this._plotData[index][k][sidx] += prevval;
  2279. this._stackData[index][k][sidx] += prevval;
  2280. break;
  2281. }
  2282. }
  2283. }
  2284. }
  2285. }
  2286. else {
  2287. for (var i=0; i<series.data.length; i++) {
  2288. plotValues.x.push(series.data[i][0]);
  2289. plotValues.y.push(series.data[i][1]);
  2290. }
  2291. this._stackData.push(series.data);
  2292. this.series[index]._stackData = series.data;
  2293. this._plotData.push(series.data);
  2294. series._plotData = series.data;
  2295. series._plotValues = plotValues;
  2296. }
  2297. if (index>0) {
  2298. series._prevPlotData = this.series[index-1]._plotData;
  2299. }
  2300. series._sumy = 0;
  2301. series._sumx = 0;
  2302. for (i=series.data.length-1; i>-1; i--) {
  2303. series._sumy += series.data[i][1];
  2304. series._sumx += series.data[i][0];
  2305. }
  2306. }
  2307. };
  2308. // populate the _stackData and _plotData arrays for the plot and the series.
  2309. this.populatePlotData = function(series, index) {
  2310. // if a stacked chart, compute the stacked data
  2311. this._plotData = [];
  2312. this._stackData = [];
  2313. series._stackData = [];
  2314. series._plotData = [];
  2315. var plotValues = {x:[], y:[]};
  2316. if (this.stackSeries && !series.disableStack) {
  2317. series._stack = true;
  2318. var sidx = (series._stackAxis === 'x') ? 0 : 1;
  2319. // var idx = sidx ? 0 : 1;
  2320. // push the current data into stackData
  2321. //this._stackData.push(this.series[i].data);
  2322. var temp = $.extend(true, [], series.data);
  2323. // create the data that will be plotted for this series
  2324. var plotdata = $.extend(true, [], series.data);
  2325. var tempx, tempy, dval, stackval, comparator;
  2326. // for first series, nothing to add to stackData.
  2327. for (var j=0; j<index; j++) {
  2328. var cd = this.series[j].data;
  2329. for (var k=0; k<cd.length; k++) {
  2330. dval = cd[k];
  2331. tempx = (dval[0] != null) ? dval[0] : 0;
  2332. tempy = (dval[1] != null) ? dval[1] : 0;
  2333. temp[k][0] += tempx;
  2334. temp[k][1] += tempy;
  2335. stackval = (sidx) ? tempy : tempx;
  2336. // only need to sum up the stack axis column of data
  2337. // and only sum if it is of same sign.
  2338. if (series.data[k][sidx] * stackval >= 0) {
  2339. plotdata[k][sidx] += stackval;
  2340. }
  2341. }
  2342. }
  2343. for (var i=0; i<plotdata.length; i++) {
  2344. plotValues.x.push(plotdata[i][0]);
  2345. plotValues.y.push(plotdata[i][1]);
  2346. }
  2347. this._plotData.push(plotdata);
  2348. this._stackData.push(temp);
  2349. series._stackData = temp;
  2350. series._plotData = plotdata;
  2351. series._plotValues = plotValues;
  2352. }
  2353. else {
  2354. for (var i=0; i<series.data.length; i++) {
  2355. plotValues.x.push(series.data[i][0]);
  2356. plotValues.y.push(series.data[i][1]);
  2357. }
  2358. this._stackData.push(series.data);
  2359. this.series[index]._stackData = series.data;
  2360. this._plotData.push(series.data);
  2361. series._plotData = series.data;
  2362. series._plotValues = plotValues;
  2363. }
  2364. if (index>0) {
  2365. series._prevPlotData = this.series[index-1]._plotData;
  2366. }
  2367. series._sumy = 0;
  2368. series._sumx = 0;
  2369. for (i=series.data.length-1; i>-1; i--) {
  2370. series._sumy += series.data[i][1];
  2371. series._sumx += series.data[i][0];
  2372. }
  2373. };
  2374. // function to safely return colors from the color array and wrap around at the end.
  2375. this.getNextSeriesColor = (function(t) {
  2376. var idx = 0;
  2377. var sc = t.seriesColors;
  2378. return function () {
  2379. if (idx < sc.length) {
  2380. return sc[idx++];
  2381. }
  2382. else {
  2383. idx = 0;
  2384. return sc[idx++];
  2385. }
  2386. };
  2387. })(this);
  2388. this.parseOptions = function(options){
  2389. for (var i=0; i<this.preParseOptionsHooks.hooks.length; i++) {
  2390. this.preParseOptionsHooks.hooks[i].call(this, options);
  2391. }
  2392. for (var i=0; i<$.jqplot.preParseOptionsHooks.length; i++) {
  2393. $.jqplot.preParseOptionsHooks[i].call(this, options);
  2394. }
  2395. this.options = $.extend(true, {}, this.defaults, options);
  2396. var opts = this.options;
  2397. this.animate = opts.animate;
  2398. this.animateReplot = opts.animateReplot;
  2399. this.stackSeries = opts.stackSeries;
  2400. if ($.isPlainObject(opts.fillBetween)) {
  2401. var temp = ['series1', 'series2', 'color', 'baseSeries', 'fill'],
  2402. tempi;
  2403. for (var i=0, l=temp.length; i<l; i++) {
  2404. tempi = temp[i];
  2405. if (opts.fillBetween[tempi] != null) {
  2406. this.fillBetween[tempi] = opts.fillBetween[tempi];
  2407. }
  2408. }
  2409. }
  2410. if (opts.seriesColors) {
  2411. this.seriesColors = opts.seriesColors;
  2412. }
  2413. if (opts.negativeSeriesColors) {
  2414. this.negativeSeriesColors = opts.negativeSeriesColors;
  2415. }
  2416. if (opts.captureRightClick) {
  2417. this.captureRightClick = opts.captureRightClick;
  2418. }
  2419. this.defaultAxisStart = (options && options.defaultAxisStart != null) ? options.defaultAxisStart : this.defaultAxisStart;
  2420. this.colorGenerator.setColors(this.seriesColors);
  2421. this.negativeColorGenerator.setColors(this.negativeSeriesColors);
  2422. // var cg = new this.colorGenerator(this.seriesColors);
  2423. // var ncg = new this.colorGenerator(this.negativeSeriesColors);
  2424. // this._gridPadding = this.options.gridPadding;
  2425. $.extend(true, this._gridPadding, opts.gridPadding);
  2426. this.sortData = (opts.sortData != null) ? opts.sortData : this.sortData;
  2427. for (var i=0; i<12; i++) {
  2428. var n = _axisNames[i];
  2429. var axis = this.axes[n];
  2430. axis._options = $.extend(true, {}, opts.axesDefaults, opts.axes[n]);
  2431. $.extend(true, axis, opts.axesDefaults, opts.axes[n]);
  2432. axis._plotWidth = this._width;
  2433. axis._plotHeight = this._height;
  2434. }
  2435. // if (this.data.length == 0) {
  2436. // this.data = [];
  2437. // for (var i=0; i<this.options.series.length; i++) {
  2438. // this.data.push(this.options.series.data);
  2439. // }
  2440. // }
  2441. var normalizeData = function(data, dir, start) {
  2442. // return data as an array of point arrays,
  2443. // in form [[x1,y1...], [x2,y2...], ...]
  2444. var temp = [];
  2445. var i, l;
  2446. dir = dir || 'vertical';
  2447. if (!$.isArray(data[0])) {
  2448. // we have a series of scalars. One line with just y values.
  2449. // turn the scalar list of data into a data array of form:
  2450. // [[1, data[0]], [2, data[1]], ...]
  2451. for (i=0, l=data.length; i<l; i++) {
  2452. if (dir == 'vertical') {
  2453. temp.push([start + i, data[i]]);
  2454. }
  2455. else {
  2456. temp.push([data[i], start+i]);
  2457. }
  2458. }
  2459. }
  2460. else {
  2461. // we have a properly formatted data series, copy it.
  2462. $.extend(true, temp, data);
  2463. }
  2464. return temp;
  2465. };
  2466. var colorIndex = 0;
  2467. this.series = [];
  2468. for (var i=0; i<this.data.length; i++) {
  2469. var sopts = $.extend(true, {index: i}, {seriesColors:this.seriesColors, negativeSeriesColors:this.negativeSeriesColors}, this.options.seriesDefaults, this.options.series[i], {rendererOptions:{animation:{show: this.animate}}});
  2470. // pass in options in case something needs set prior to initialization.
  2471. var temp = new Series(sopts);
  2472. for (var j=0; j<$.jqplot.preParseSeriesOptionsHooks.length; j++) {
  2473. $.jqplot.preParseSeriesOptionsHooks[j].call(temp, this.options.seriesDefaults, this.options.series[i]);
  2474. }
  2475. for (var j=0; j<this.preParseSeriesOptionsHooks.hooks.length; j++) {
  2476. this.preParseSeriesOptionsHooks.hooks[j].call(temp, this.options.seriesDefaults, this.options.series[i]);
  2477. }
  2478. // Now go back and apply the options to the series. Really should just do this during initializaiton, but don't want to
  2479. // mess up preParseSeriesOptionsHooks at this point.
  2480. $.extend(true, temp, sopts);
  2481. var dir = 'vertical';
  2482. if (temp.renderer === $.jqplot.BarRenderer && temp.rendererOptions && temp.rendererOptions.barDirection == 'horizontal') {
  2483. dir = 'horizontal';
  2484. temp._stackAxis = 'x';
  2485. temp._primaryAxis = '_yaxis';
  2486. }
  2487. temp.data = normalizeData(this.data[i], dir, this.defaultAxisStart);
  2488. switch (temp.xaxis) {
  2489. case 'xaxis':
  2490. temp._xaxis = this.axes.xaxis;
  2491. break;
  2492. case 'x2axis':
  2493. temp._xaxis = this.axes.x2axis;
  2494. break;
  2495. default:
  2496. break;
  2497. }
  2498. temp._yaxis = this.axes[temp.yaxis];
  2499. temp._xaxis._series.push(temp);
  2500. temp._yaxis._series.push(temp);
  2501. if (temp.show) {
  2502. temp._xaxis.show = true;
  2503. temp._yaxis.show = true;
  2504. }
  2505. else {
  2506. if (temp._xaxis.scaleToHiddenSeries) {
  2507. temp._xaxis.show = true;
  2508. }
  2509. if (temp._yaxis.scaleToHiddenSeries) {
  2510. temp._yaxis.show = true;
  2511. }
  2512. }
  2513. // // parse the renderer options and apply default colors if not provided
  2514. // if (!temp.color && temp.show != false) {
  2515. // temp.color = cg.next();
  2516. // colorIndex = cg.getIndex() - 1;;
  2517. // }
  2518. // if (!temp.negativeColor && temp.show != false) {
  2519. // temp.negativeColor = ncg.get(colorIndex);
  2520. // ncg.setIndex(colorIndex);
  2521. // }
  2522. if (!temp.label) {
  2523. temp.label = 'Series '+ (i+1).toString();
  2524. }
  2525. // temp.rendererOptions.show = temp.show;
  2526. // $.extend(true, temp.renderer, {color:this.seriesColors[i]}, this.rendererOptions);
  2527. this.series.push(temp);
  2528. for (var j=0; j<$.jqplot.postParseSeriesOptionsHooks.length; j++) {
  2529. $.jqplot.postParseSeriesOptionsHooks[j].call(this.series[i], this.options.seriesDefaults, this.options.series[i]);
  2530. }
  2531. for (var j=0; j<this.postParseSeriesOptionsHooks.hooks.length; j++) {
  2532. this.postParseSeriesOptionsHooks.hooks[j].call(this.series[i], this.options.seriesDefaults, this.options.series[i]);
  2533. }
  2534. }
  2535. // copy the grid and title options into this object.
  2536. $.extend(true, this.grid, this.options.grid);
  2537. // if axis border properties aren't set, set default.
  2538. for (var i=0, l=_axisNames.length; i<l; i++) {
  2539. var n = _axisNames[i];
  2540. var axis = this.axes[n];
  2541. if (axis.borderWidth == null) {
  2542. axis.borderWidth =this.grid.borderWidth;
  2543. }
  2544. }
  2545. if (typeof this.options.title == 'string') {
  2546. this.title.text = this.options.title;
  2547. }
  2548. else if (typeof this.options.title == 'object') {
  2549. $.extend(true, this.title, this.options.title);
  2550. }
  2551. this.title._plotWidth = this._width;
  2552. this.legend.setOptions(this.options.legend);
  2553. for (var i=0; i<$.jqplot.postParseOptionsHooks.length; i++) {
  2554. $.jqplot.postParseOptionsHooks[i].call(this, options);
  2555. }
  2556. for (var i=0; i<this.postParseOptionsHooks.hooks.length; i++) {
  2557. this.postParseOptionsHooks.hooks[i].call(this, options);
  2558. }
  2559. };
  2560. // method: destroy
  2561. // Releases all resources occupied by the plot
  2562. this.destroy = function() {
  2563. this.canvasManager.freeAllCanvases();
  2564. if (this.eventCanvas && this.eventCanvas._elem) {
  2565. this.eventCanvas._elem.unbind();
  2566. }
  2567. // Couple of posts on Stack Overflow indicate that empty() doesn't
  2568. // always cear up the dom and release memory. Sometimes setting
  2569. // innerHTML property to null is needed. Particularly on IE, may
  2570. // have to directly set it to null, bypassing $.
  2571. this.target.empty();
  2572. this.target[0].innerHTML = '';
  2573. };
  2574. // method: replot
  2575. // Does a reinitialization of the plot followed by
  2576. // a redraw. Method could be used to interactively
  2577. // change plot characteristics and then replot.
  2578. //
  2579. // Parameters:
  2580. // options - Options used for replotting.
  2581. //
  2582. // Properties:
  2583. // clear - false to not clear (empty) the plot container before replotting (default: true).
  2584. // resetAxes - true to reset all axes min, max, numberTicks and tickInterval setting so axes will rescale themselves.
  2585. // optionally pass in list of axes to reset (e.g. ['xaxis', 'y2axis']) (default: false).
  2586. this.replot = function(options) {
  2587. var opts = options || {};
  2588. var data = opts.data || null;
  2589. var clear = (opts.clear === false) ? false : true;
  2590. var resetAxes = opts.resetAxes || false;
  2591. delete opts.data;
  2592. delete opts.clear;
  2593. delete opts.resetAxes;
  2594. this.target.trigger('jqplotPreReplot');
  2595. if (clear) {
  2596. this.destroy();
  2597. }
  2598. // if have data or other options, full reinit.
  2599. // otherwise, quickinit.
  2600. if (data || !$.isEmptyObject(opts)) {
  2601. this.reInitialize(data, opts);
  2602. }
  2603. else {
  2604. this.quickInit();
  2605. }
  2606. if (resetAxes) {
  2607. this.resetAxesScale(resetAxes, opts.axes);
  2608. }
  2609. this.draw();
  2610. this.target.trigger('jqplotPostReplot');
  2611. };
  2612. // method: redraw
  2613. // Empties the plot target div and redraws the plot.
  2614. // This enables plot data and properties to be changed
  2615. // and then to comletely clear the plot and redraw.
  2616. // redraw *will not* reinitialize any plot elements.
  2617. // That is, axes will not be autoscaled and defaults
  2618. // will not be reapplied to any plot elements. redraw
  2619. // is used primarily with zooming.
  2620. //
  2621. // Parameters:
  2622. // clear - false to not clear (empty) the plot container before redrawing (default: true).
  2623. this.redraw = function(clear) {
  2624. clear = (clear != null) ? clear : true;
  2625. this.target.trigger('jqplotPreRedraw');
  2626. if (clear) {
  2627. this.canvasManager.freeAllCanvases();
  2628. this.eventCanvas._elem.unbind();
  2629. // Dont think I bind any events to the target, this shouldn't be necessary.
  2630. // It will remove user's events.
  2631. // this.target.unbind();
  2632. this.target.empty();
  2633. }
  2634. for (var ax in this.axes) {
  2635. this.axes[ax]._ticks = [];
  2636. }
  2637. this.computePlotData();
  2638. // for (var i=0; i<this.series.length; i++) {
  2639. // this.populatePlotData(this.series[i], i);
  2640. // }
  2641. this._sumy = 0;
  2642. this._sumx = 0;
  2643. for (var i=0, tsl = this.series.length; i<tsl; i++) {
  2644. this._sumy += this.series[i]._sumy;
  2645. this._sumx += this.series[i]._sumx;
  2646. }
  2647. this.draw();
  2648. this.target.trigger('jqplotPostRedraw');
  2649. };
  2650. // method: draw
  2651. // Draws all elements of the plot into the container.
  2652. // Does not clear the container before drawing.
  2653. this.draw = function(){
  2654. if (this.drawIfHidden || this.target.is(':visible')) {
  2655. this.target.trigger('jqplotPreDraw');
  2656. var i,
  2657. j,
  2658. l,
  2659. tempseries;
  2660. for (i=0, l=$.jqplot.preDrawHooks.length; i<l; i++) {
  2661. $.jqplot.preDrawHooks[i].call(this);
  2662. }
  2663. for (i=0, l=this.preDrawHooks.length; i<l; i++) {
  2664. this.preDrawHooks.hooks[i].apply(this, this.preDrawSeriesHooks.args[i]);
  2665. }
  2666. // create an underlying canvas to be used for special features.
  2667. this.target.append(this.baseCanvas.createElement({left:0, right:0, top:0, bottom:0}, 'jqplot-base-canvas', null, this));
  2668. this.baseCanvas.setContext();
  2669. this.target.append(this.title.draw());
  2670. this.title.pack({top:0, left:0});
  2671. // make room for the legend between the grid and the edge.
  2672. // pass a dummy offsets object and a reference to the plot.
  2673. var legendElem = this.legend.draw({}, this);
  2674. var gridPadding = {top:0, left:0, bottom:0, right:0};
  2675. if (this.legend.placement == "outsideGrid") {
  2676. // temporarily append the legend to get dimensions
  2677. this.target.append(legendElem);
  2678. switch (this.legend.location) {
  2679. case 'n':
  2680. gridPadding.top += this.legend.getHeight();
  2681. break;
  2682. case 's':
  2683. gridPadding.bottom += this.legend.getHeight();
  2684. break;
  2685. case 'ne':
  2686. case 'e':
  2687. case 'se':
  2688. gridPadding.right += this.legend.getWidth();
  2689. break;
  2690. case 'nw':
  2691. case 'w':
  2692. case 'sw':
  2693. gridPadding.left += this.legend.getWidth();
  2694. break;
  2695. default: // same as 'ne'
  2696. gridPadding.right += this.legend.getWidth();
  2697. break;
  2698. }
  2699. legendElem = legendElem.detach();
  2700. }
  2701. var ax = this.axes;
  2702. var name;
  2703. // draw the yMidAxis first, so xaxis of pyramid chart can adjust itself if needed.
  2704. for (i=0; i<12; i++) {
  2705. name = _axisNames[i];
  2706. this.target.append(ax[name].draw(this.baseCanvas._ctx, this));
  2707. ax[name].set();
  2708. }
  2709. if (ax.yaxis.show) {
  2710. gridPadding.left += ax.yaxis.getWidth();
  2711. }
  2712. var ra = ['y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];
  2713. var rapad = [0, 0, 0, 0, 0, 0, 0, 0];
  2714. var gpr = 0;
  2715. var n;
  2716. for (n=0; n<8; n++) {
  2717. if (ax[ra[n]].show) {
  2718. gpr += ax[ra[n]].getWidth();
  2719. rapad[n] = gpr;
  2720. }
  2721. }
  2722. gridPadding.right += gpr;
  2723. if (ax.x2axis.show) {
  2724. gridPadding.top += ax.x2axis.getHeight();
  2725. }
  2726. if (this.title.show) {
  2727. gridPadding.top += this.title.getHeight();
  2728. }
  2729. if (ax.xaxis.show) {
  2730. gridPadding.bottom += ax.xaxis.getHeight();
  2731. }
  2732. // end of gridPadding adjustments.
  2733. // if user passed in gridDimensions option, check against calculated gridPadding
  2734. if (this.options.gridDimensions && $.isPlainObject(this.options.gridDimensions)) {
  2735. var gdw = parseInt(this.options.gridDimensions.width, 10) || 0;
  2736. var gdh = parseInt(this.options.gridDimensions.height, 10) || 0;
  2737. var widthAdj = (this._width - gridPadding.left - gridPadding.right - gdw)/2;
  2738. var heightAdj = (this._height - gridPadding.top - gridPadding.bottom - gdh)/2;
  2739. if (heightAdj >= 0 && widthAdj >= 0) {
  2740. gridPadding.top += heightAdj;
  2741. gridPadding.bottom += heightAdj;
  2742. gridPadding.left += widthAdj;
  2743. gridPadding.right += widthAdj;
  2744. }
  2745. }
  2746. var arr = ['top', 'bottom', 'left', 'right'];
  2747. for (var n in arr) {
  2748. if (this._gridPadding[arr[n]] == null && gridPadding[arr[n]] > 0) {
  2749. this._gridPadding[arr[n]] = gridPadding[arr[n]];
  2750. }
  2751. else if (this._gridPadding[arr[n]] == null) {
  2752. this._gridPadding[arr[n]] = this._defaultGridPadding[arr[n]];
  2753. }
  2754. }
  2755. var legendPadding = this._gridPadding;
  2756. if (this.legend.placement === 'outsideGrid') {
  2757. legendPadding = {top:this.title.getHeight(), left: 0, right: 0, bottom: 0};
  2758. if (this.legend.location === 's') {
  2759. legendPadding.left = this._gridPadding.left;
  2760. legendPadding.right = this._gridPadding.right;
  2761. }
  2762. }
  2763. 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});
  2764. 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});
  2765. 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});
  2766. for (i=8; i>0; i--) {
  2767. 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});
  2768. }
  2769. var ltemp = (this._width - this._gridPadding.left - this._gridPadding.right)/2.0 + this._gridPadding.left - ax.yMidAxis.getWidth()/2.0;
  2770. ax.yMidAxis.pack({position:'absolute', top:0, left:ltemp, zIndex:9, textAlign: 'center'}, {min:this._height - this._gridPadding.bottom, max: this._gridPadding.top});
  2771. this.target.append(this.grid.createElement(this._gridPadding, this));
  2772. this.grid.draw();
  2773. var series = this.series;
  2774. var seriesLength = series.length;
  2775. // put the shadow canvases behind the series canvases so shadows don't overlap on stacked bars.
  2776. for (i=0, l=seriesLength; i<l; i++) {
  2777. // draw series in order of stacking. This affects only
  2778. // order in which canvases are added to dom.
  2779. j = this.seriesStack[i];
  2780. this.target.append(series[j].shadowCanvas.createElement(this._gridPadding, 'jqplot-series-shadowCanvas', null, this));
  2781. series[j].shadowCanvas.setContext();
  2782. series[j].shadowCanvas._elem.data('seriesIndex', j);
  2783. }
  2784. for (i=0, l=seriesLength; i<l; i++) {
  2785. // draw series in order of stacking. This affects only
  2786. // order in which canvases are added to dom.
  2787. j = this.seriesStack[i];
  2788. this.target.append(series[j].canvas.createElement(this._gridPadding, 'jqplot-series-canvas', null, this));
  2789. series[j].canvas.setContext();
  2790. series[j].canvas._elem.data('seriesIndex', j);
  2791. }
  2792. // Need to use filled canvas to capture events in IE.
  2793. // Also, canvas seems to block selection of other elements in document on FF.
  2794. this.target.append(this.eventCanvas.createElement(this._gridPadding, 'jqplot-event-canvas', null, this));
  2795. this.eventCanvas.setContext();
  2796. this.eventCanvas._ctx.fillStyle = 'rgba(0,0,0,0)';
  2797. this.eventCanvas._ctx.fillRect(0,0,this.eventCanvas._ctx.canvas.width, this.eventCanvas._ctx.canvas.height);
  2798. // bind custom event handlers to regular events.
  2799. this.bindCustomEvents();
  2800. // draw legend before series if the series needs to know the legend dimensions.
  2801. if (this.legend.preDraw) {
  2802. this.eventCanvas._elem.before(legendElem);
  2803. this.legend.pack(legendPadding);
  2804. if (this.legend._elem) {
  2805. 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}});
  2806. }
  2807. else {
  2808. this.drawSeries();
  2809. }
  2810. }
  2811. else { // draw series before legend
  2812. this.drawSeries();
  2813. if (seriesLength) {
  2814. $(series[seriesLength-1].canvas._elem).after(legendElem);
  2815. }
  2816. this.legend.pack(legendPadding);
  2817. }
  2818. // register event listeners on the overlay canvas
  2819. for (var i=0, l=$.jqplot.eventListenerHooks.length; i<l; i++) {
  2820. // in the handler, this will refer to the eventCanvas dom element.
  2821. // make sure there are references back into plot objects.
  2822. this.eventCanvas._elem.bind($.jqplot.eventListenerHooks[i][0], {plot:this}, $.jqplot.eventListenerHooks[i][1]);
  2823. }
  2824. // register event listeners on the overlay canvas
  2825. for (var i=0, l=this.eventListenerHooks.hooks.length; i<l; i++) {
  2826. // in the handler, this will refer to the eventCanvas dom element.
  2827. // make sure there are references back into plot objects.
  2828. this.eventCanvas._elem.bind(this.eventListenerHooks.hooks[i][0], {plot:this}, this.eventListenerHooks.hooks[i][1]);
  2829. }
  2830. var fb = this.fillBetween;
  2831. if (fb.fill && fb.series1 !== fb.series2 && fb.series1 < seriesLength && fb.series2 < seriesLength && series[fb.series1]._type === 'line' && series[fb.series2]._type === 'line') {
  2832. this.doFillBetweenLines();
  2833. }
  2834. for (var i=0, l=$.jqplot.postDrawHooks.length; i<l; i++) {
  2835. $.jqplot.postDrawHooks[i].call(this);
  2836. }
  2837. for (var i=0, l=this.postDrawHooks.hooks.length; i<l; i++) {
  2838. this.postDrawHooks.hooks[i].apply(this, this.postDrawHooks.args[i]);
  2839. }
  2840. if (this.target.is(':visible')) {
  2841. this._drawCount += 1;
  2842. }
  2843. var temps,
  2844. tempr,
  2845. sel,
  2846. _els;
  2847. // ughh. ideally would hide all series then show them.
  2848. for (i=0, l=seriesLength; i<l; i++) {
  2849. temps = series[i];
  2850. tempr = temps.renderer;
  2851. sel = '.jqplot-point-label.jqplot-series-'+i;
  2852. if (tempr.animation && tempr.animation._supported && tempr.animation.show && (this._drawCount < 2 || this.animateReplot)) {
  2853. _els = this.target.find(sel);
  2854. _els.stop(true, true).hide();
  2855. temps.canvas._elem.stop(true, true).hide();
  2856. temps.shadowCanvas._elem.stop(true, true).hide();
  2857. temps.canvas._elem.jqplotEffect('blind', {mode: 'show', direction: tempr.animation.direction}, tempr.animation.speed);
  2858. temps.shadowCanvas._elem.jqplotEffect('blind', {mode: 'show', direction: tempr.animation.direction}, tempr.animation.speed);
  2859. _els.fadeIn(tempr.animation.speed*0.8);
  2860. }
  2861. }
  2862. _els = null;
  2863. this.target.trigger('jqplotPostDraw', [this]);
  2864. }
  2865. };
  2866. jqPlot.prototype.doFillBetweenLines = function () {
  2867. var fb = this.fillBetween;
  2868. var sid1 = fb.series1;
  2869. var sid2 = fb.series2;
  2870. // first series should always be lowest index
  2871. var id1 = (sid1 < sid2) ? sid1 : sid2;
  2872. var id2 = (sid2 > sid1) ? sid2 : sid1;
  2873. var series1 = this.series[id1];
  2874. var series2 = this.series[id2];
  2875. if (series2.renderer.smooth) {
  2876. var tempgd = series2.renderer._smoothedData.slice(0).reverse();
  2877. }
  2878. else {
  2879. var tempgd = series2.gridData.slice(0).reverse();
  2880. }
  2881. if (series1.renderer.smooth) {
  2882. var gd = series1.renderer._smoothedData.concat(tempgd);
  2883. }
  2884. else {
  2885. var gd = series1.gridData.concat(tempgd);
  2886. }
  2887. var color = (fb.color !== null) ? fb.color : this.series[sid1].fillColor;
  2888. var baseSeries = (fb.baseSeries !== null) ? fb.baseSeries : id1;
  2889. // now apply a fill to the shape on the lower series shadow canvas,
  2890. // so it is behind both series.
  2891. var sr = this.series[baseSeries].renderer.shapeRenderer;
  2892. var opts = {fillStyle: color, fill: true, closePath: true};
  2893. sr.draw(series1.shadowCanvas._ctx, gd, opts);
  2894. };
  2895. this.bindCustomEvents = function() {
  2896. this.eventCanvas._elem.bind('click', {plot:this}, this.onClick);
  2897. this.eventCanvas._elem.bind('dblclick', {plot:this}, this.onDblClick);
  2898. this.eventCanvas._elem.bind('mousedown', {plot:this}, this.onMouseDown);
  2899. this.eventCanvas._elem.bind('mousemove', {plot:this}, this.onMouseMove);
  2900. this.eventCanvas._elem.bind('mouseenter', {plot:this}, this.onMouseEnter);
  2901. this.eventCanvas._elem.bind('mouseleave', {plot:this}, this.onMouseLeave);
  2902. if (this.captureRightClick) {
  2903. this.eventCanvas._elem.bind('mouseup', {plot:this}, this.onRightClick);
  2904. this.eventCanvas._elem.get(0).oncontextmenu = function() {
  2905. return false;
  2906. };
  2907. }
  2908. else {
  2909. this.eventCanvas._elem.bind('mouseup', {plot:this}, this.onMouseUp);
  2910. }
  2911. };
  2912. function getEventPosition(ev) {
  2913. var plot = ev.data.plot;
  2914. var go = plot.eventCanvas._elem.offset();
  2915. var gridPos = {x:ev.pageX - go.left, y:ev.pageY - go.top};
  2916. var dataPos = {xaxis:null, yaxis:null, x2axis:null, y2axis:null, y3axis:null, y4axis:null, y5axis:null, y6axis:null, y7axis:null, y8axis:null, y9axis:null, yMidAxis:null};
  2917. var an = ['xaxis', 'yaxis', 'x2axis', 'y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis', 'yMidAxis'];
  2918. var ax = plot.axes;
  2919. var n, axis;
  2920. for (n=11; n>0; n--) {
  2921. axis = an[n-1];
  2922. if (ax[axis].show) {
  2923. dataPos[axis] = ax[axis].series_p2u(gridPos[axis.charAt(0)]);
  2924. }
  2925. }
  2926. return {offsets:go, gridPos:gridPos, dataPos:dataPos};
  2927. }
  2928. // function to check if event location is over a area area
  2929. function checkIntersection(gridpos, plot) {
  2930. var series = plot.series;
  2931. var i, j, k, s, r, x, y, theta, sm, sa, minang, maxang;
  2932. var d0, d, p, pp, points, bw, hp;
  2933. var threshold, t;
  2934. for (k=plot.seriesStack.length-1; k>=0; k--) {
  2935. i = plot.seriesStack[k];
  2936. s = series[i];
  2937. hp = s._highlightThreshold;
  2938. switch (s.renderer.constructor) {
  2939. case $.jqplot.BarRenderer:
  2940. x = gridpos.x;
  2941. y = gridpos.y;
  2942. for (j=0; j<s._barPoints.length; j++) {
  2943. points = s._barPoints[j];
  2944. p = s.gridData[j];
  2945. if (x>points[0][0] && x<points[2][0] && y>points[2][1] && y<points[0][1]) {
  2946. return {seriesIndex:s.index, pointIndex:j, gridData:p, data:s.data[j], points:s._barPoints[j]};
  2947. }
  2948. }
  2949. break;
  2950. case $.jqplot.PyramidRenderer:
  2951. x = gridpos.x;
  2952. y = gridpos.y;
  2953. for (j=0; j<s._barPoints.length; j++) {
  2954. points = s._barPoints[j];
  2955. p = s.gridData[j];
  2956. if (x > points[0][0] + hp[0][0] && x < points[2][0] + hp[2][0] && y > points[2][1] && y < points[0][1]) {
  2957. return {seriesIndex:s.index, pointIndex:j, gridData:p, data:s.data[j], points:s._barPoints[j]};
  2958. }
  2959. }
  2960. break;
  2961. case $.jqplot.DonutRenderer:
  2962. sa = s.startAngle/180*Math.PI;
  2963. x = gridpos.x - s._center[0];
  2964. y = gridpos.y - s._center[1];
  2965. r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  2966. if (x > 0 && -y >= 0) {
  2967. theta = 2*Math.PI - Math.atan(-y/x);
  2968. }
  2969. else if (x > 0 && -y < 0) {
  2970. theta = -Math.atan(-y/x);
  2971. }
  2972. else if (x < 0) {
  2973. theta = Math.PI - Math.atan(-y/x);
  2974. }
  2975. else if (x == 0 && -y > 0) {
  2976. theta = 3*Math.PI/2;
  2977. }
  2978. else if (x == 0 && -y < 0) {
  2979. theta = Math.PI/2;
  2980. }
  2981. else if (x == 0 && y == 0) {
  2982. theta = 0;
  2983. }
  2984. if (sa) {
  2985. theta -= sa;
  2986. if (theta < 0) {
  2987. theta += 2*Math.PI;
  2988. }
  2989. else if (theta > 2*Math.PI) {
  2990. theta -= 2*Math.PI;
  2991. }
  2992. }
  2993. sm = s.sliceMargin/180*Math.PI;
  2994. if (r < s._radius && r > s._innerRadius) {
  2995. for (j=0; j<s.gridData.length; j++) {
  2996. minang = (j>0) ? s.gridData[j-1][1]+sm : sm;
  2997. maxang = s.gridData[j][1];
  2998. if (theta > minang && theta < maxang) {
  2999. return {seriesIndex:s.index, pointIndex:j, gridData:s.gridData[j], data:s.data[j]};
  3000. }
  3001. }
  3002. }
  3003. break;
  3004. case $.jqplot.PieRenderer:
  3005. sa = s.startAngle/180*Math.PI;
  3006. x = gridpos.x - s._center[0];
  3007. y = gridpos.y - s._center[1];
  3008. r = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  3009. if (x > 0 && -y >= 0) {
  3010. theta = 2*Math.PI - Math.atan(-y/x);
  3011. }
  3012. else if (x > 0 && -y < 0) {
  3013. theta = -Math.atan(-y/x);
  3014. }
  3015. else if (x < 0) {
  3016. theta = Math.PI - Math.atan(-y/x);
  3017. }
  3018. else if (x == 0 && -y > 0) {
  3019. theta = 3*Math.PI/2;
  3020. }
  3021. else if (x == 0 && -y < 0) {
  3022. theta = Math.PI/2;
  3023. }
  3024. else if (x == 0 && y == 0) {
  3025. theta = 0;
  3026. }
  3027. if (sa) {
  3028. theta -= sa;
  3029. if (theta < 0) {
  3030. theta += 2*Math.PI;
  3031. }
  3032. else if (theta > 2*Math.PI) {
  3033. theta -= 2*Math.PI;
  3034. }
  3035. }
  3036. sm = s.sliceMargin/180*Math.PI;
  3037. if (r < s._radius) {
  3038. for (j=0; j<s.gridData.length; j++) {
  3039. minang = (j>0) ? s.gridData[j-1][1]+sm : sm;
  3040. maxang = s.gridData[j][1];
  3041. if (theta > minang && theta < maxang) {
  3042. return {seriesIndex:s.index, pointIndex:j, gridData:s.gridData[j], data:s.data[j]};
  3043. }
  3044. }
  3045. }
  3046. break;
  3047. case $.jqplot.BubbleRenderer:
  3048. x = gridpos.x;
  3049. y = gridpos.y;
  3050. var ret = null;
  3051. if (s.show) {
  3052. for (var j=0; j<s.gridData.length; j++) {
  3053. p = s.gridData[j];
  3054. d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
  3055. if (d <= p[2] && (d <= d0 || d0 == null)) {
  3056. d0 = d;
  3057. ret = {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3058. }
  3059. }
  3060. if (ret != null) {
  3061. return ret;
  3062. }
  3063. }
  3064. break;
  3065. case $.jqplot.FunnelRenderer:
  3066. x = gridpos.x;
  3067. y = gridpos.y;
  3068. var v = s._vertices,
  3069. vfirst = v[0],
  3070. vlast = v[v.length-1],
  3071. lex,
  3072. rex,
  3073. cv;
  3074. // equations of right and left sides, returns x, y values given height of section (y value and 2 points)
  3075. function findedge (l, p1 , p2) {
  3076. var m = (p1[1] - p2[1])/(p1[0] - p2[0]);
  3077. var b = p1[1] - m*p1[0];
  3078. var y = l + p1[1];
  3079. return [(y - b)/m, y];
  3080. }
  3081. // check each section
  3082. lex = findedge(y, vfirst[0], vlast[3]);
  3083. rex = findedge(y, vfirst[1], vlast[2]);
  3084. for (j=0; j<v.length; j++) {
  3085. cv = v[j];
  3086. if (y >= cv[0][1] && y <= cv[3][1] && x >= lex[0] && x <= rex[0]) {
  3087. return {seriesIndex:s.index, pointIndex:j, gridData:null, data:s.data[j]};
  3088. }
  3089. }
  3090. break;
  3091. case $.jqplot.LineRenderer:
  3092. x = gridpos.x;
  3093. y = gridpos.y;
  3094. r = s.renderer;
  3095. if (s.show) {
  3096. if ((s.fill || (s.renderer.bands.show && s.renderer.bands.fill)) && (!plot.plugins.highlighter || !plot.plugins.highlighter.show)) {
  3097. // first check if it is in bounding box
  3098. var inside = false;
  3099. if (x>s._boundingBox[0][0] && x<s._boundingBox[1][0] && y>s._boundingBox[1][1] && y<s._boundingBox[0][1]) {
  3100. // now check the crossing number
  3101. var numPoints = s._areaPoints.length;
  3102. var ii;
  3103. var j = numPoints-1;
  3104. for(var ii=0; ii < numPoints; ii++) {
  3105. var vertex1 = [s._areaPoints[ii][0], s._areaPoints[ii][1]];
  3106. var vertex2 = [s._areaPoints[j][0], s._areaPoints[j][1]];
  3107. if (vertex1[1] < y && vertex2[1] >= y || vertex2[1] < y && vertex1[1] >= y) {
  3108. if (vertex1[0] + (y - vertex1[1]) / (vertex2[1] - vertex1[1]) * (vertex2[0] - vertex1[0]) < x) {
  3109. inside = !inside;
  3110. }
  3111. }
  3112. j = ii;
  3113. }
  3114. }
  3115. if (inside) {
  3116. return {seriesIndex:i, pointIndex:null, gridData:s.gridData, data:s.data, points:s._areaPoints};
  3117. }
  3118. break;
  3119. }
  3120. else {
  3121. t = s.markerRenderer.size/2+s.neighborThreshold;
  3122. threshold = (t > 0) ? t : 0;
  3123. for (var j=0; j<s.gridData.length; j++) {
  3124. p = s.gridData[j];
  3125. // neighbor looks different to OHLC chart.
  3126. if (r.constructor == $.jqplot.OHLCRenderer) {
  3127. if (r.candleStick) {
  3128. var yp = s._yaxis.series_u2p;
  3129. 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])) {
  3130. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3131. }
  3132. }
  3133. // if an open hi low close chart
  3134. else if (!r.hlc){
  3135. var yp = s._yaxis.series_u2p;
  3136. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  3137. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3138. }
  3139. }
  3140. // a hi low close chart
  3141. else {
  3142. var yp = s._yaxis.series_u2p;
  3143. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][1]) && y <= yp(s.data[j][2])) {
  3144. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3145. }
  3146. }
  3147. }
  3148. else if (p[0] != null && p[1] != null){
  3149. d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
  3150. if (d <= threshold && (d <= d0 || d0 == null)) {
  3151. d0 = d;
  3152. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3153. }
  3154. }
  3155. }
  3156. }
  3157. }
  3158. break;
  3159. default:
  3160. x = gridpos.x;
  3161. y = gridpos.y;
  3162. r = s.renderer;
  3163. if (s.show) {
  3164. t = s.markerRenderer.size/2+s.neighborThreshold;
  3165. threshold = (t > 0) ? t : 0;
  3166. for (var j=0; j<s.gridData.length; j++) {
  3167. p = s.gridData[j];
  3168. // neighbor looks different to OHLC chart.
  3169. if (r.constructor == $.jqplot.OHLCRenderer) {
  3170. if (r.candleStick) {
  3171. var yp = s._yaxis.series_u2p;
  3172. 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])) {
  3173. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3174. }
  3175. }
  3176. // if an open hi low close chart
  3177. else if (!r.hlc){
  3178. var yp = s._yaxis.series_u2p;
  3179. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][2]) && y <= yp(s.data[j][3])) {
  3180. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3181. }
  3182. }
  3183. // a hi low close chart
  3184. else {
  3185. var yp = s._yaxis.series_u2p;
  3186. if (x >= p[0]-r._tickLength && x <= p[0]+r._tickLength && y >= yp(s.data[j][1]) && y <= yp(s.data[j][2])) {
  3187. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3188. }
  3189. }
  3190. }
  3191. else {
  3192. d = Math.sqrt( (x-p[0]) * (x-p[0]) + (y-p[1]) * (y-p[1]) );
  3193. if (d <= threshold && (d <= d0 || d0 == null)) {
  3194. d0 = d;
  3195. return {seriesIndex: i, pointIndex:j, gridData:p, data:s.data[j]};
  3196. }
  3197. }
  3198. }
  3199. }
  3200. break;
  3201. }
  3202. }
  3203. return null;
  3204. }
  3205. this.onClick = function(ev) {
  3206. // Event passed in is normalized and will have data attribute.
  3207. // Event passed out is unnormalized.
  3208. var positions = getEventPosition(ev);
  3209. var p = ev.data.plot;
  3210. var neighbor = checkIntersection(positions.gridPos, p);
  3211. var evt = $.Event('jqplotClick');
  3212. evt.pageX = ev.pageX;
  3213. evt.pageY = ev.pageY;
  3214. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3215. };
  3216. this.onDblClick = function(ev) {
  3217. // Event passed in is normalized and will have data attribute.
  3218. // Event passed out is unnormalized.
  3219. var positions = getEventPosition(ev);
  3220. var p = ev.data.plot;
  3221. var neighbor = checkIntersection(positions.gridPos, p);
  3222. var evt = $.Event('jqplotDblClick');
  3223. evt.pageX = ev.pageX;
  3224. evt.pageY = ev.pageY;
  3225. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3226. };
  3227. this.onMouseDown = function(ev) {
  3228. var positions = getEventPosition(ev);
  3229. var p = ev.data.plot;
  3230. var neighbor = checkIntersection(positions.gridPos, p);
  3231. var evt = $.Event('jqplotMouseDown');
  3232. evt.pageX = ev.pageX;
  3233. evt.pageY = ev.pageY;
  3234. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3235. };
  3236. this.onMouseUp = function(ev) {
  3237. var positions = getEventPosition(ev);
  3238. var evt = $.Event('jqplotMouseUp');
  3239. evt.pageX = ev.pageX;
  3240. evt.pageY = ev.pageY;
  3241. $(this).trigger(evt, [positions.gridPos, positions.dataPos, null, ev.data.plot]);
  3242. };
  3243. this.onRightClick = function(ev) {
  3244. var positions = getEventPosition(ev);
  3245. var p = ev.data.plot;
  3246. var neighbor = checkIntersection(positions.gridPos, p);
  3247. if (p.captureRightClick) {
  3248. if (ev.which == 3) {
  3249. var evt = $.Event('jqplotRightClick');
  3250. evt.pageX = ev.pageX;
  3251. evt.pageY = ev.pageY;
  3252. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3253. }
  3254. else {
  3255. var evt = $.Event('jqplotMouseUp');
  3256. evt.pageX = ev.pageX;
  3257. evt.pageY = ev.pageY;
  3258. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3259. }
  3260. }
  3261. };
  3262. this.onMouseMove = function(ev) {
  3263. var positions = getEventPosition(ev);
  3264. var p = ev.data.plot;
  3265. var neighbor = checkIntersection(positions.gridPos, p);
  3266. var evt = $.Event('jqplotMouseMove');
  3267. evt.pageX = ev.pageX;
  3268. evt.pageY = ev.pageY;
  3269. $(this).trigger(evt, [positions.gridPos, positions.dataPos, neighbor, p]);
  3270. };
  3271. this.onMouseEnter = function(ev) {
  3272. var positions = getEventPosition(ev);
  3273. var p = ev.data.plot;
  3274. var evt = $.Event('jqplotMouseEnter');
  3275. evt.pageX = ev.pageX;
  3276. evt.pageY = ev.pageY;
  3277. evt.relatedTarget = ev.relatedTarget;
  3278. $(this).trigger(evt, [positions.gridPos, positions.dataPos, null, p]);
  3279. };
  3280. this.onMouseLeave = function(ev) {
  3281. var positions = getEventPosition(ev);
  3282. var p = ev.data.plot;
  3283. var evt = $.Event('jqplotMouseLeave');
  3284. evt.pageX = ev.pageX;
  3285. evt.pageY = ev.pageY;
  3286. evt.relatedTarget = ev.relatedTarget;
  3287. $(this).trigger(evt, [positions.gridPos, positions.dataPos, null, p]);
  3288. };
  3289. // method: drawSeries
  3290. // Redraws all or just one series on the plot. No axis scaling
  3291. // is performed and no other elements on the plot are redrawn.
  3292. // options is an options object to pass on to the series renderers.
  3293. // It can be an empty object {}. idx is the series index
  3294. // to redraw if only one series is to be redrawn.
  3295. this.drawSeries = function(options, idx){
  3296. var i, series, ctx;
  3297. // if only one argument passed in and it is a number, use it ad idx.
  3298. idx = (typeof(options) === "number" && idx == null) ? options : idx;
  3299. options = (typeof(options) === "object") ? options : {};
  3300. // draw specified series
  3301. if (idx != undefined) {
  3302. series = this.series[idx];
  3303. ctx = series.shadowCanvas._ctx;
  3304. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  3305. series.drawShadow(ctx, options, this);
  3306. ctx = series.canvas._ctx;
  3307. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  3308. series.draw(ctx, options, this);
  3309. if (series.renderer.constructor == $.jqplot.BezierCurveRenderer) {
  3310. if (idx < this.series.length - 1) {
  3311. this.drawSeries(idx+1);
  3312. }
  3313. }
  3314. }
  3315. else {
  3316. // if call series drawShadow method first, in case all series shadows
  3317. // should be drawn before any series. This will ensure, like for
  3318. // stacked bar plots, that shadows don't overlap series.
  3319. for (i=0; i<this.series.length; i++) {
  3320. // first clear the canvas
  3321. series = this.series[i];
  3322. ctx = series.shadowCanvas._ctx;
  3323. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  3324. series.drawShadow(ctx, options, this);
  3325. ctx = series.canvas._ctx;
  3326. ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  3327. series.draw(ctx, options, this);
  3328. }
  3329. }
  3330. options = idx = i = series = ctx = null;
  3331. };
  3332. // method: moveSeriesToFront
  3333. // This method requires jQuery 1.4+
  3334. // Moves the specified series canvas in front of all other series canvases.
  3335. // This effectively "draws" the specified series on top of all other series,
  3336. // although it is performed through DOM manipulation, no redrawing is performed.
  3337. //
  3338. // Parameters:
  3339. // idx - 0 based index of the series to move. This will be the index of the series
  3340. // as it was first passed into the jqplot function.
  3341. this.moveSeriesToFront = function (idx) {
  3342. idx = parseInt(idx, 10);
  3343. var stackIndex = $.inArray(idx, this.seriesStack);
  3344. // if already in front, return
  3345. if (stackIndex == -1) {
  3346. return;
  3347. }
  3348. if (stackIndex == this.seriesStack.length -1) {
  3349. this.previousSeriesStack = this.seriesStack.slice(0);
  3350. return;
  3351. }
  3352. var opidx = this.seriesStack[this.seriesStack.length -1];
  3353. var serelem = this.series[idx].canvas._elem.detach();
  3354. var shadelem = this.series[idx].shadowCanvas._elem.detach();
  3355. this.series[opidx].shadowCanvas._elem.after(shadelem);
  3356. this.series[opidx].canvas._elem.after(serelem);
  3357. this.previousSeriesStack = this.seriesStack.slice(0);
  3358. this.seriesStack.splice(stackIndex, 1);
  3359. this.seriesStack.push(idx);
  3360. };
  3361. // method: moveSeriesToBack
  3362. // This method requires jQuery 1.4+
  3363. // Moves the specified series canvas behind all other series canvases.
  3364. //
  3365. // Parameters:
  3366. // idx - 0 based index of the series to move. This will be the index of the series
  3367. // as it was first passed into the jqplot function.
  3368. this.moveSeriesToBack = function (idx) {
  3369. idx = parseInt(idx, 10);
  3370. var stackIndex = $.inArray(idx, this.seriesStack);
  3371. // if already in back, return
  3372. if (stackIndex == 0 || stackIndex == -1) {
  3373. return;
  3374. }
  3375. var opidx = this.seriesStack[0];
  3376. var serelem = this.series[idx].canvas._elem.detach();
  3377. var shadelem = this.series[idx].shadowCanvas._elem.detach();
  3378. this.series[opidx].shadowCanvas._elem.before(shadelem);
  3379. this.series[opidx].canvas._elem.before(serelem);
  3380. this.previousSeriesStack = this.seriesStack.slice(0);
  3381. this.seriesStack.splice(stackIndex, 1);
  3382. this.seriesStack.unshift(idx);
  3383. };
  3384. // method: restorePreviousSeriesOrder
  3385. // This method requires jQuery 1.4+
  3386. // Restore the series canvas order to its previous state.
  3387. // Useful to put a series back where it belongs after moving
  3388. // it to the front.
  3389. this.restorePreviousSeriesOrder = function () {
  3390. var i, j, serelem, shadelem, temp, move, keep;
  3391. // if no change, return.
  3392. if (this.seriesStack == this.previousSeriesStack) {
  3393. return;
  3394. }
  3395. for (i=1; i<this.previousSeriesStack.length; i++) {
  3396. move = this.previousSeriesStack[i];
  3397. keep = this.previousSeriesStack[i-1];
  3398. serelem = this.series[move].canvas._elem.detach();
  3399. shadelem = this.series[move].shadowCanvas._elem.detach();
  3400. this.series[keep].shadowCanvas._elem.after(shadelem);
  3401. this.series[keep].canvas._elem.after(serelem);
  3402. }
  3403. temp = this.seriesStack.slice(0);
  3404. this.seriesStack = this.previousSeriesStack.slice(0);
  3405. this.previousSeriesStack = temp;
  3406. };
  3407. // method: restoreOriginalSeriesOrder
  3408. // This method requires jQuery 1.4+
  3409. // Restore the series canvas order to its original order
  3410. // when the plot was created.
  3411. this.restoreOriginalSeriesOrder = function () {
  3412. var i, j, arr=[], serelem, shadelem;
  3413. for (i=0; i<this.series.length; i++) {
  3414. arr.push(i);
  3415. }
  3416. if (this.seriesStack == arr) {
  3417. return;
  3418. }
  3419. this.previousSeriesStack = this.seriesStack.slice(0);
  3420. this.seriesStack = arr;
  3421. for (i=1; i<this.seriesStack.length; i++) {
  3422. serelem = this.series[i].canvas._elem.detach();
  3423. shadelem = this.series[i].shadowCanvas._elem.detach();
  3424. this.series[i-1].shadowCanvas._elem.after(shadelem);
  3425. this.series[i-1].canvas._elem.after(serelem);
  3426. }
  3427. };
  3428. this.activateTheme = function (name) {
  3429. this.themeEngine.activate(this, name);
  3430. };
  3431. }
  3432. // conpute a highlight color or array of highlight colors from given colors.
  3433. $.jqplot.computeHighlightColors = function(colors) {
  3434. var ret;
  3435. if ($.isArray(colors)) {
  3436. ret = [];
  3437. for (var i=0; i<colors.length; i++){
  3438. var rgba = $.jqplot.getColorComponents(colors[i]);
  3439. var newrgb = [rgba[0], rgba[1], rgba[2]];
  3440. var sum = newrgb[0] + newrgb[1] + newrgb[2];
  3441. for (var j=0; j<3; j++) {
  3442. // when darkening, lowest color component can be is 60.
  3443. newrgb[j] = (sum > 660) ? newrgb[j] * 0.85 : 0.73 * newrgb[j] + 90;
  3444. newrgb[j] = parseInt(newrgb[j], 10);
  3445. (newrgb[j] > 255) ? 255 : newrgb[j];
  3446. }
  3447. // newrgb[3] = (rgba[3] > 0.4) ? rgba[3] * 0.4 : rgba[3] * 1.5;
  3448. // newrgb[3] = (rgba[3] > 0.5) ? 0.8 * rgba[3] - .1 : rgba[3] + 0.2;
  3449. newrgb[3] = 0.3 + 0.35 * rgba[3];
  3450. ret.push('rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+newrgb[3]+')');
  3451. }
  3452. }
  3453. else {
  3454. var rgba = $.jqplot.getColorComponents(colors);
  3455. var newrgb = [rgba[0], rgba[1], rgba[2]];
  3456. var sum = newrgb[0] + newrgb[1] + newrgb[2];
  3457. for (var j=0; j<3; j++) {
  3458. // when darkening, lowest color component can be is 60.
  3459. // newrgb[j] = (sum > 570) ? newrgb[j] * 0.8 : newrgb[j] + 0.3 * (255 - newrgb[j]);
  3460. // newrgb[j] = parseInt(newrgb[j], 10);
  3461. newrgb[j] = (sum > 660) ? newrgb[j] * 0.85 : 0.73 * newrgb[j] + 90;
  3462. newrgb[j] = parseInt(newrgb[j], 10);
  3463. (newrgb[j] > 255) ? 255 : newrgb[j];
  3464. }
  3465. // newrgb[3] = (rgba[3] > 0.4) ? rgba[3] * 0.4 : rgba[3] * 1.5;
  3466. // newrgb[3] = (rgba[3] > 0.5) ? 0.8 * rgba[3] - .1 : rgba[3] + 0.2;
  3467. newrgb[3] = 0.3 + 0.35 * rgba[3];
  3468. ret = 'rgba('+newrgb[0]+','+newrgb[1]+','+newrgb[2]+','+newrgb[3]+')';
  3469. }
  3470. return ret;
  3471. };
  3472. $.jqplot.ColorGenerator = function(colors) {
  3473. colors = colors || $.jqplot.config.defaultColors;
  3474. var idx = 0;
  3475. this.next = function () {
  3476. if (idx < colors.length) {
  3477. return colors[idx++];
  3478. }
  3479. else {
  3480. idx = 0;
  3481. return colors[idx++];
  3482. }
  3483. };
  3484. this.previous = function () {
  3485. if (idx > 0) {
  3486. return colors[idx--];
  3487. }
  3488. else {
  3489. idx = colors.length-1;
  3490. return colors[idx];
  3491. }
  3492. };
  3493. // get a color by index without advancing pointer.
  3494. this.get = function(i) {
  3495. var idx = i - colors.length * Math.floor(i/colors.length);
  3496. return colors[idx];
  3497. };
  3498. this.setColors = function(c) {
  3499. colors = c;
  3500. };
  3501. this.reset = function() {
  3502. idx = 0;
  3503. };
  3504. this.getIndex = function() {
  3505. return idx;
  3506. };
  3507. this.setIndex = function(index) {
  3508. idx = index;
  3509. };
  3510. };
  3511. // convert a hex color string to rgb string.
  3512. // h - 3 or 6 character hex string, with or without leading #
  3513. // a - optional alpha
  3514. $.jqplot.hex2rgb = function(h, a) {
  3515. h = h.replace('#', '');
  3516. if (h.length == 3) {
  3517. h = h.charAt(0)+h.charAt(0)+h.charAt(1)+h.charAt(1)+h.charAt(2)+h.charAt(2);
  3518. }
  3519. var rgb;
  3520. rgb = 'rgba('+parseInt(h.slice(0,2), 16)+', '+parseInt(h.slice(2,4), 16)+', '+parseInt(h.slice(4,6), 16);
  3521. if (a) {
  3522. rgb += ', '+a;
  3523. }
  3524. rgb += ')';
  3525. return rgb;
  3526. };
  3527. // convert an rgb color spec to a hex spec. ignore any alpha specification.
  3528. $.jqplot.rgb2hex = function(s) {
  3529. var pat = /rgba?\( *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *(?:, *[0-9.]*)?\)/;
  3530. var m = s.match(pat);
  3531. var h = '#';
  3532. for (var i=1; i<4; i++) {
  3533. var temp;
  3534. if (m[i].search(/%/) != -1) {
  3535. temp = parseInt(255*m[i]/100, 10).toString(16);
  3536. if (temp.length == 1) {
  3537. temp = '0'+temp;
  3538. }
  3539. }
  3540. else {
  3541. temp = parseInt(m[i], 10).toString(16);
  3542. if (temp.length == 1) {
  3543. temp = '0'+temp;
  3544. }
  3545. }
  3546. h += temp;
  3547. }
  3548. return h;
  3549. };
  3550. // given a css color spec, return an rgb css color spec
  3551. $.jqplot.normalize2rgb = function(s, a) {
  3552. if (s.search(/^ *rgba?\(/) != -1) {
  3553. return s;
  3554. }
  3555. else if (s.search(/^ *#?[0-9a-fA-F]?[0-9a-fA-F]/) != -1) {
  3556. return $.jqplot.hex2rgb(s, a);
  3557. }
  3558. else {
  3559. throw 'invalid color spec';
  3560. }
  3561. };
  3562. // extract the r, g, b, a color components out of a css color spec.
  3563. $.jqplot.getColorComponents = function(s) {
  3564. // check to see if a color keyword.
  3565. s = $.jqplot.colorKeywordMap[s] || s;
  3566. var rgb = $.jqplot.normalize2rgb(s);
  3567. var pat = /rgba?\( *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *, *([0-9]{1,3}\.?[0-9]*%?) *,? *([0-9.]* *)?\)/;
  3568. var m = rgb.match(pat);
  3569. var ret = [];
  3570. for (var i=1; i<4; i++) {
  3571. if (m[i].search(/%/) != -1) {
  3572. ret[i-1] = parseInt(255*m[i]/100, 10);
  3573. }
  3574. else {
  3575. ret[i-1] = parseInt(m[i], 10);
  3576. }
  3577. }
  3578. ret[3] = parseFloat(m[4]) ? parseFloat(m[4]) : 1.0;
  3579. return ret;
  3580. };
  3581. $.jqplot.colorKeywordMap = {
  3582. aliceblue: 'rgb(240, 248, 255)',
  3583. antiquewhite: 'rgb(250, 235, 215)',
  3584. aqua: 'rgb( 0, 255, 255)',
  3585. aquamarine: 'rgb(127, 255, 212)',
  3586. azure: 'rgb(240, 255, 255)',
  3587. beige: 'rgb(245, 245, 220)',
  3588. bisque: 'rgb(255, 228, 196)',
  3589. black: 'rgb( 0, 0, 0)',
  3590. blanchedalmond: 'rgb(255, 235, 205)',
  3591. blue: 'rgb( 0, 0, 255)',
  3592. blueviolet: 'rgb(138, 43, 226)',
  3593. brown: 'rgb(165, 42, 42)',
  3594. burlywood: 'rgb(222, 184, 135)',
  3595. cadetblue: 'rgb( 95, 158, 160)',
  3596. chartreuse: 'rgb(127, 255, 0)',
  3597. chocolate: 'rgb(210, 105, 30)',
  3598. coral: 'rgb(255, 127, 80)',
  3599. cornflowerblue: 'rgb(100, 149, 237)',
  3600. cornsilk: 'rgb(255, 248, 220)',
  3601. crimson: 'rgb(220, 20, 60)',
  3602. cyan: 'rgb( 0, 255, 255)',
  3603. darkblue: 'rgb( 0, 0, 139)',
  3604. darkcyan: 'rgb( 0, 139, 139)',
  3605. darkgoldenrod: 'rgb(184, 134, 11)',
  3606. darkgray: 'rgb(169, 169, 169)',
  3607. darkgreen: 'rgb( 0, 100, 0)',
  3608. darkgrey: 'rgb(169, 169, 169)',
  3609. darkkhaki: 'rgb(189, 183, 107)',
  3610. darkmagenta: 'rgb(139, 0, 139)',
  3611. darkolivegreen: 'rgb( 85, 107, 47)',
  3612. darkorange: 'rgb(255, 140, 0)',
  3613. darkorchid: 'rgb(153, 50, 204)',
  3614. darkred: 'rgb(139, 0, 0)',
  3615. darksalmon: 'rgb(233, 150, 122)',
  3616. darkseagreen: 'rgb(143, 188, 143)',
  3617. darkslateblue: 'rgb( 72, 61, 139)',
  3618. darkslategray: 'rgb( 47, 79, 79)',
  3619. darkslategrey: 'rgb( 47, 79, 79)',
  3620. darkturquoise: 'rgb( 0, 206, 209)',
  3621. darkviolet: 'rgb(148, 0, 211)',
  3622. deeppink: 'rgb(255, 20, 147)',
  3623. deepskyblue: 'rgb( 0, 191, 255)',
  3624. dimgray: 'rgb(105, 105, 105)',
  3625. dimgrey: 'rgb(105, 105, 105)',
  3626. dodgerblue: 'rgb( 30, 144, 255)',
  3627. firebrick: 'rgb(178, 34, 34)',
  3628. floralwhite: 'rgb(255, 250, 240)',
  3629. forestgreen: 'rgb( 34, 139, 34)',
  3630. fuchsia: 'rgb(255, 0, 255)',
  3631. gainsboro: 'rgb(220, 220, 220)',
  3632. ghostwhite: 'rgb(248, 248, 255)',
  3633. gold: 'rgb(255, 215, 0)',
  3634. goldenrod: 'rgb(218, 165, 32)',
  3635. gray: 'rgb(128, 128, 128)',
  3636. grey: 'rgb(128, 128, 128)',
  3637. green: 'rgb( 0, 128, 0)',
  3638. greenyellow: 'rgb(173, 255, 47)',
  3639. honeydew: 'rgb(240, 255, 240)',
  3640. hotpink: 'rgb(255, 105, 180)',
  3641. indianred: 'rgb(205, 92, 92)',
  3642. indigo: 'rgb( 75, 0, 130)',
  3643. ivory: 'rgb(255, 255, 240)',
  3644. khaki: 'rgb(240, 230, 140)',
  3645. lavender: 'rgb(230, 230, 250)',
  3646. lavenderblush: 'rgb(255, 240, 245)',
  3647. lawngreen: 'rgb(124, 252, 0)',
  3648. lemonchiffon: 'rgb(255, 250, 205)',
  3649. lightblue: 'rgb(173, 216, 230)',
  3650. lightcoral: 'rgb(240, 128, 128)',
  3651. lightcyan: 'rgb(224, 255, 255)',
  3652. lightgoldenrodyellow: 'rgb(250, 250, 210)',
  3653. lightgray: 'rgb(211, 211, 211)',
  3654. lightgreen: 'rgb(144, 238, 144)',
  3655. lightgrey: 'rgb(211, 211, 211)',
  3656. lightpink: 'rgb(255, 182, 193)',
  3657. lightsalmon: 'rgb(255, 160, 122)',
  3658. lightseagreen: 'rgb( 32, 178, 170)',
  3659. lightskyblue: 'rgb(135, 206, 250)',
  3660. lightslategray: 'rgb(119, 136, 153)',
  3661. lightslategrey: 'rgb(119, 136, 153)',
  3662. lightsteelblue: 'rgb(176, 196, 222)',
  3663. lightyellow: 'rgb(255, 255, 224)',
  3664. lime: 'rgb( 0, 255, 0)',
  3665. limegreen: 'rgb( 50, 205, 50)',
  3666. linen: 'rgb(250, 240, 230)',
  3667. magenta: 'rgb(255, 0, 255)',
  3668. maroon: 'rgb(128, 0, 0)',
  3669. mediumaquamarine: 'rgb(102, 205, 170)',
  3670. mediumblue: 'rgb( 0, 0, 205)',
  3671. mediumorchid: 'rgb(186, 85, 211)',
  3672. mediumpurple: 'rgb(147, 112, 219)',
  3673. mediumseagreen: 'rgb( 60, 179, 113)',
  3674. mediumslateblue: 'rgb(123, 104, 238)',
  3675. mediumspringgreen: 'rgb( 0, 250, 154)',
  3676. mediumturquoise: 'rgb( 72, 209, 204)',
  3677. mediumvioletred: 'rgb(199, 21, 133)',
  3678. midnightblue: 'rgb( 25, 25, 112)',
  3679. mintcream: 'rgb(245, 255, 250)',
  3680. mistyrose: 'rgb(255, 228, 225)',
  3681. moccasin: 'rgb(255, 228, 181)',
  3682. navajowhite: 'rgb(255, 222, 173)',
  3683. navy: 'rgb( 0, 0, 128)',
  3684. oldlace: 'rgb(253, 245, 230)',
  3685. olive: 'rgb(128, 128, 0)',
  3686. olivedrab: 'rgb(107, 142, 35)',
  3687. orange: 'rgb(255, 165, 0)',
  3688. orangered: 'rgb(255, 69, 0)',
  3689. orchid: 'rgb(218, 112, 214)',
  3690. palegoldenrod: 'rgb(238, 232, 170)',
  3691. palegreen: 'rgb(152, 251, 152)',
  3692. paleturquoise: 'rgb(175, 238, 238)',
  3693. palevioletred: 'rgb(219, 112, 147)',
  3694. papayawhip: 'rgb(255, 239, 213)',
  3695. peachpuff: 'rgb(255, 218, 185)',
  3696. peru: 'rgb(205, 133, 63)',
  3697. pink: 'rgb(255, 192, 203)',
  3698. plum: 'rgb(221, 160, 221)',
  3699. powderblue: 'rgb(176, 224, 230)',
  3700. purple: 'rgb(128, 0, 128)',
  3701. red: 'rgb(255, 0, 0)',
  3702. rosybrown: 'rgb(188, 143, 143)',
  3703. royalblue: 'rgb( 65, 105, 225)',
  3704. saddlebrown: 'rgb(139, 69, 19)',
  3705. salmon: 'rgb(250, 128, 114)',
  3706. sandybrown: 'rgb(244, 164, 96)',
  3707. seagreen: 'rgb( 46, 139, 87)',
  3708. seashell: 'rgb(255, 245, 238)',
  3709. sienna: 'rgb(160, 82, 45)',
  3710. silver: 'rgb(192, 192, 192)',
  3711. skyblue: 'rgb(135, 206, 235)',
  3712. slateblue: 'rgb(106, 90, 205)',
  3713. slategray: 'rgb(112, 128, 144)',
  3714. slategrey: 'rgb(112, 128, 144)',
  3715. snow: 'rgb(255, 250, 250)',
  3716. springgreen: 'rgb( 0, 255, 127)',
  3717. steelblue: 'rgb( 70, 130, 180)',
  3718. tan: 'rgb(210, 180, 140)',
  3719. teal: 'rgb( 0, 128, 128)',
  3720. thistle: 'rgb(216, 191, 216)',
  3721. tomato: 'rgb(255, 99, 71)',
  3722. turquoise: 'rgb( 64, 224, 208)',
  3723. violet: 'rgb(238, 130, 238)',
  3724. wheat: 'rgb(245, 222, 179)',
  3725. white: 'rgb(255, 255, 255)',
  3726. whitesmoke: 'rgb(245, 245, 245)',
  3727. yellow: 'rgb(255, 255, 0)',
  3728. yellowgreen: 'rgb(154, 205, 50)'
  3729. };
  3730. // class: $.jqplot.AxisLabelRenderer
  3731. // Renderer to place labels on the axes.
  3732. $.jqplot.AxisLabelRenderer = function(options) {
  3733. // Group: Properties
  3734. $.jqplot.ElemContainer.call(this);
  3735. // name of the axis associated with this tick
  3736. this.axis;
  3737. // prop: show
  3738. // wether or not to show the tick (mark and label).
  3739. this.show = true;
  3740. // prop: label
  3741. // The text or html for the label.
  3742. this.label = '';
  3743. this.fontFamily = null;
  3744. this.fontSize = null;
  3745. this.textColor = null;
  3746. this._elem;
  3747. // prop: escapeHTML
  3748. // true to escape HTML entities in the label.
  3749. this.escapeHTML = false;
  3750. $.extend(true, this, options);
  3751. };
  3752. $.jqplot.AxisLabelRenderer.prototype = new $.jqplot.ElemContainer();
  3753. $.jqplot.AxisLabelRenderer.prototype.constructor = $.jqplot.AxisLabelRenderer;
  3754. $.jqplot.AxisLabelRenderer.prototype.init = function(options) {
  3755. $.extend(true, this, options);
  3756. };
  3757. $.jqplot.AxisLabelRenderer.prototype.draw = function(ctx, plot) {
  3758. // Memory Leaks patch
  3759. if (this._elem) {
  3760. this._elem.emptyForce();
  3761. this._elem = null;
  3762. }
  3763. this._elem = $('<div style="position:absolute;" class="jqplot-'+this.axis+'-label"></div>');
  3764. if (Number(this.label)) {
  3765. this._elem.css('white-space', 'nowrap');
  3766. }
  3767. if (!this.escapeHTML) {
  3768. this._elem.html(this.label);
  3769. }
  3770. else {
  3771. this._elem.text(this.label);
  3772. }
  3773. if (this.fontFamily) {
  3774. this._elem.css('font-family', this.fontFamily);
  3775. }
  3776. if (this.fontSize) {
  3777. this._elem.css('font-size', this.fontSize);
  3778. }
  3779. if (this.textColor) {
  3780. this._elem.css('color', this.textColor);
  3781. }
  3782. return this._elem;
  3783. };
  3784. $.jqplot.AxisLabelRenderer.prototype.pack = function() {
  3785. };
  3786. // class: $.jqplot.AxisTickRenderer
  3787. // A "tick" object showing the value of a tick/gridline on the plot.
  3788. $.jqplot.AxisTickRenderer = function(options) {
  3789. // Group: Properties
  3790. $.jqplot.ElemContainer.call(this);
  3791. // prop: mark
  3792. // tick mark on the axis. One of 'inside', 'outside', 'cross', '' or null.
  3793. this.mark = 'outside';
  3794. // name of the axis associated with this tick
  3795. this.axis;
  3796. // prop: showMark
  3797. // wether or not to show the mark on the axis.
  3798. this.showMark = true;
  3799. // prop: showGridline
  3800. // wether or not to draw the gridline on the grid at this tick.
  3801. this.showGridline = true;
  3802. // prop: isMinorTick
  3803. // if this is a minor tick.
  3804. this.isMinorTick = false;
  3805. // prop: size
  3806. // Length of the tick beyond the grid in pixels.
  3807. // DEPRECATED: This has been superceeded by markSize
  3808. this.size = 4;
  3809. // prop: markSize
  3810. // Length of the tick marks in pixels. For 'cross' style, length
  3811. // will be stoked above and below axis, so total length will be twice this.
  3812. this.markSize = 6;
  3813. // prop: show
  3814. // wether or not to show the tick (mark and label).
  3815. // Setting this to false requires more testing. It is recommended
  3816. // to set showLabel and showMark to false instead.
  3817. this.show = true;
  3818. // prop: showLabel
  3819. // wether or not to show the label.
  3820. this.showLabel = true;
  3821. this.label = null;
  3822. this.value = null;
  3823. this._styles = {};
  3824. // prop: formatter
  3825. // A class of a formatter for the tick text. sprintf by default.
  3826. this.formatter = $.jqplot.DefaultTickFormatter;
  3827. // prop: prefix
  3828. // String to prepend to the tick label.
  3829. // Prefix is prepended to the formatted tick label.
  3830. this.prefix = '';
  3831. // prop: suffix
  3832. // String to append to the tick label.
  3833. // Suffix is appended to the formatted tick label.
  3834. this.suffix = '';
  3835. // prop: formatString
  3836. // string passed to the formatter.
  3837. this.formatString = '';
  3838. // prop: fontFamily
  3839. // css spec for the font-family css attribute.
  3840. this.fontFamily;
  3841. // prop: fontSize
  3842. // css spec for the font-size css attribute.
  3843. this.fontSize;
  3844. // prop: textColor
  3845. // css spec for the color attribute.
  3846. this.textColor;
  3847. // prop: escapeHTML
  3848. // true to escape HTML entities in the label.
  3849. this.escapeHTML = false;
  3850. this._elem;
  3851. this._breakTick = false;
  3852. $.extend(true, this, options);
  3853. };
  3854. $.jqplot.AxisTickRenderer.prototype.init = function(options) {
  3855. $.extend(true, this, options);
  3856. };
  3857. $.jqplot.AxisTickRenderer.prototype = new $.jqplot.ElemContainer();
  3858. $.jqplot.AxisTickRenderer.prototype.constructor = $.jqplot.AxisTickRenderer;
  3859. $.jqplot.AxisTickRenderer.prototype.setTick = function(value, axisName, isMinor) {
  3860. this.value = value;
  3861. this.axis = axisName;
  3862. if (isMinor) {
  3863. this.isMinorTick = true;
  3864. }
  3865. return this;
  3866. };
  3867. $.jqplot.AxisTickRenderer.prototype.draw = function() {
  3868. if (this.label === null) {
  3869. this.label = this.prefix + this.formatter(this.formatString, this.value) + this.suffix;
  3870. }
  3871. var style = {position: 'absolute'};
  3872. if (Number(this.label)) {
  3873. style['whitSpace'] = 'nowrap';
  3874. }
  3875. // Memory Leaks patch
  3876. if (this._elem) {
  3877. this._elem.emptyForce();
  3878. this._elem = null;
  3879. }
  3880. this._elem = $(document.createElement('div'));
  3881. this._elem.addClass("jqplot-"+this.axis+"-tick");
  3882. if (!this.escapeHTML) {
  3883. this._elem.html(this.label);
  3884. }
  3885. else {
  3886. this._elem.text(this.label);
  3887. }
  3888. this._elem.css(style);
  3889. for (var s in this._styles) {
  3890. this._elem.css(s, this._styles[s]);
  3891. }
  3892. if (this.fontFamily) {
  3893. this._elem.css('font-family', this.fontFamily);
  3894. }
  3895. if (this.fontSize) {
  3896. this._elem.css('font-size', this.fontSize);
  3897. }
  3898. if (this.textColor) {
  3899. this._elem.css('color', this.textColor);
  3900. }
  3901. if (this._breakTick) {
  3902. this._elem.addClass('jqplot-breakTick');
  3903. }
  3904. return this._elem;
  3905. };
  3906. $.jqplot.DefaultTickFormatter = function (format, val) {
  3907. if (typeof val == 'number') {
  3908. if (!format) {
  3909. format = $.jqplot.config.defaultTickFormatString;
  3910. }
  3911. return $.jqplot.sprintf(format, val);
  3912. }
  3913. else {
  3914. return String(val);
  3915. }
  3916. };
  3917. $.jqplot.PercentTickFormatter = function (format, val) {
  3918. if (typeof val == 'number') {
  3919. val = 100 * val;
  3920. if (!format) {
  3921. format = $.jqplot.config.defaultTickFormatString;
  3922. }
  3923. return $.jqplot.sprintf(format, val);
  3924. }
  3925. else {
  3926. return String(val);
  3927. }
  3928. };
  3929. $.jqplot.AxisTickRenderer.prototype.pack = function() {
  3930. };
  3931. // Class: $.jqplot.CanvasGridRenderer
  3932. // The default jqPlot grid renderer, creating a grid on a canvas element.
  3933. // The renderer has no additional options beyond the <Grid> class.
  3934. $.jqplot.CanvasGridRenderer = function(){
  3935. this.shadowRenderer = new $.jqplot.ShadowRenderer();
  3936. };
  3937. // called with context of Grid object
  3938. $.jqplot.CanvasGridRenderer.prototype.init = function(options) {
  3939. this._ctx;
  3940. $.extend(true, this, options);
  3941. // set the shadow renderer options
  3942. 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};
  3943. this.renderer.shadowRenderer.init(sopts);
  3944. };
  3945. // called with context of Grid.
  3946. $.jqplot.CanvasGridRenderer.prototype.createElement = function(plot) {
  3947. var elem;
  3948. // Memory Leaks patch
  3949. if (this._elem) {
  3950. if ($.jqplot.use_excanvas && window.G_vmlCanvasManager.uninitElement !== undefined) {
  3951. elem = this._elem.get(0);
  3952. window.G_vmlCanvasManager.uninitElement(elem);
  3953. elem = null;
  3954. }
  3955. this._elem.emptyForce();
  3956. this._elem = null;
  3957. }
  3958. elem = plot.canvasManager.getCanvas();
  3959. var w = this._plotDimensions.width;
  3960. var h = this._plotDimensions.height;
  3961. elem.width = w;
  3962. elem.height = h;
  3963. this._elem = $(elem);
  3964. this._elem.addClass('jqplot-grid-canvas');
  3965. this._elem.css({ position: 'absolute', left: 0, top: 0 });
  3966. elem = plot.canvasManager.initCanvas(elem);
  3967. this._top = this._offsets.top;
  3968. this._bottom = h - this._offsets.bottom;
  3969. this._left = this._offsets.left;
  3970. this._right = w - this._offsets.right;
  3971. this._width = this._right - this._left;
  3972. this._height = this._bottom - this._top;
  3973. // avoid memory leak
  3974. elem = null;
  3975. return this._elem;
  3976. };
  3977. $.jqplot.CanvasGridRenderer.prototype.draw = function() {
  3978. this._ctx = this._elem.get(0).getContext("2d");
  3979. var ctx = this._ctx;
  3980. var axes = this._axes;
  3981. // Add the grid onto the grid canvas. This is the bottom most layer.
  3982. ctx.save();
  3983. ctx.clearRect(0, 0, this._plotDimensions.width, this._plotDimensions.height);
  3984. ctx.fillStyle = this.backgroundColor || this.background;
  3985. ctx.fillRect(this._left, this._top, this._width, this._height);
  3986. ctx.save();
  3987. ctx.lineJoin = 'miter';
  3988. ctx.lineCap = 'butt';
  3989. ctx.lineWidth = this.gridLineWidth;
  3990. ctx.strokeStyle = this.gridLineColor;
  3991. var b, e, s, m;
  3992. var ax = ['xaxis', 'yaxis', 'x2axis', 'y2axis'];
  3993. for (var i=4; i>0; i--) {
  3994. var name = ax[i-1];
  3995. var axis = axes[name];
  3996. var ticks = axis._ticks;
  3997. var numticks = ticks.length;
  3998. if (axis.show) {
  3999. if (axis.drawBaseline) {
  4000. var bopts = {};
  4001. if (axis.baselineWidth !== null) {
  4002. bopts.lineWidth = axis.baselineWidth;
  4003. }
  4004. if (axis.baselineColor !== null) {
  4005. bopts.strokeStyle = axis.baselineColor;
  4006. }
  4007. switch (name) {
  4008. case 'xaxis':
  4009. drawLine (this._left, this._bottom, this._right, this._bottom, bopts);
  4010. break;
  4011. case 'yaxis':
  4012. drawLine (this._left, this._bottom, this._left, this._top, bopts);
  4013. break;
  4014. case 'x2axis':
  4015. drawLine (this._left, this._bottom, this._right, this._bottom, bopts);
  4016. break;
  4017. case 'y2axis':
  4018. drawLine (this._right, this._bottom, this._right, this._top, bopts);
  4019. break;
  4020. }
  4021. }
  4022. for (var j=numticks; j>0; j--) {
  4023. var t = ticks[j-1];
  4024. if (t.show) {
  4025. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  4026. switch (name) {
  4027. case 'xaxis':
  4028. // draw the grid line if we should
  4029. if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) {
  4030. drawLine(pos, this._top, pos, this._bottom);
  4031. }
  4032. // draw the mark
  4033. if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) {
  4034. s = t.markSize;
  4035. m = t.mark;
  4036. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  4037. switch (m) {
  4038. case 'outside':
  4039. b = this._bottom;
  4040. e = this._bottom+s;
  4041. break;
  4042. case 'inside':
  4043. b = this._bottom-s;
  4044. e = this._bottom;
  4045. break;
  4046. case 'cross':
  4047. b = this._bottom-s;
  4048. e = this._bottom+s;
  4049. break;
  4050. default:
  4051. b = this._bottom;
  4052. e = this._bottom+s;
  4053. break;
  4054. }
  4055. // draw the shadow
  4056. if (this.shadow) {
  4057. 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});
  4058. }
  4059. // draw the line
  4060. drawLine(pos, b, pos, e);
  4061. }
  4062. break;
  4063. case 'yaxis':
  4064. // draw the grid line
  4065. if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) {
  4066. drawLine(this._right, pos, this._left, pos);
  4067. }
  4068. // draw the mark
  4069. if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) {
  4070. s = t.markSize;
  4071. m = t.mark;
  4072. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  4073. switch (m) {
  4074. case 'outside':
  4075. b = this._left-s;
  4076. e = this._left;
  4077. break;
  4078. case 'inside':
  4079. b = this._left;
  4080. e = this._left+s;
  4081. break;
  4082. case 'cross':
  4083. b = this._left-s;
  4084. e = this._left+s;
  4085. break;
  4086. default:
  4087. b = this._left-s;
  4088. e = this._left;
  4089. break;
  4090. }
  4091. // draw the shadow
  4092. if (this.shadow) {
  4093. 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});
  4094. }
  4095. drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
  4096. }
  4097. break;
  4098. case 'x2axis':
  4099. // draw the grid line
  4100. if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) {
  4101. drawLine(pos, this._bottom, pos, this._top);
  4102. }
  4103. // draw the mark
  4104. if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) {
  4105. s = t.markSize;
  4106. m = t.mark;
  4107. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  4108. switch (m) {
  4109. case 'outside':
  4110. b = this._top-s;
  4111. e = this._top;
  4112. break;
  4113. case 'inside':
  4114. b = this._top;
  4115. e = this._top+s;
  4116. break;
  4117. case 'cross':
  4118. b = this._top-s;
  4119. e = this._top+s;
  4120. break;
  4121. default:
  4122. b = this._top-s;
  4123. e = this._top;
  4124. break;
  4125. }
  4126. // draw the shadow
  4127. if (this.shadow) {
  4128. 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});
  4129. }
  4130. drawLine(pos, b, pos, e);
  4131. }
  4132. break;
  4133. case 'y2axis':
  4134. // draw the grid line
  4135. if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) {
  4136. drawLine(this._left, pos, this._right, pos);
  4137. }
  4138. // draw the mark
  4139. if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) {
  4140. s = t.markSize;
  4141. m = t.mark;
  4142. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  4143. switch (m) {
  4144. case 'outside':
  4145. b = this._right;
  4146. e = this._right+s;
  4147. break;
  4148. case 'inside':
  4149. b = this._right-s;
  4150. e = this._right;
  4151. break;
  4152. case 'cross':
  4153. b = this._right-s;
  4154. e = this._right+s;
  4155. break;
  4156. default:
  4157. b = this._right;
  4158. e = this._right+s;
  4159. break;
  4160. }
  4161. // draw the shadow
  4162. if (this.shadow) {
  4163. 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});
  4164. }
  4165. drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
  4166. }
  4167. break;
  4168. default:
  4169. break;
  4170. }
  4171. }
  4172. }
  4173. t = null;
  4174. }
  4175. axis = null;
  4176. ticks = null;
  4177. }
  4178. // Now draw grid lines for additional y axes
  4179. //////
  4180. // TO DO: handle yMidAxis
  4181. //////
  4182. ax = ['y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis', 'yMidAxis'];
  4183. for (var i=7; i>0; i--) {
  4184. var axis = axes[ax[i-1]];
  4185. var ticks = axis._ticks;
  4186. if (axis.show) {
  4187. var tn = ticks[axis.numberTicks-1];
  4188. var t0 = ticks[0];
  4189. var left = axis.getLeft();
  4190. var points = [[left, tn.getTop() + tn.getHeight()/2], [left, t0.getTop() + t0.getHeight()/2 + 1.0]];
  4191. // draw the shadow
  4192. if (this.shadow) {
  4193. this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', fill:false, closePath:false});
  4194. }
  4195. // draw the line
  4196. drawLine(points[0][0], points[0][1], points[1][0], points[1][1], {lineCap:'butt', strokeStyle:axis.borderColor, lineWidth:axis.borderWidth});
  4197. // draw the tick marks
  4198. for (var j=ticks.length; j>0; j--) {
  4199. var t = ticks[j-1];
  4200. s = t.markSize;
  4201. m = t.mark;
  4202. var pos = Math.round(axis.u2p(t.value)) + 0.5;
  4203. if (t.showMark && t.mark) {
  4204. switch (m) {
  4205. case 'outside':
  4206. b = left;
  4207. e = left+s;
  4208. break;
  4209. case 'inside':
  4210. b = left-s;
  4211. e = left;
  4212. break;
  4213. case 'cross':
  4214. b = left-s;
  4215. e = left+s;
  4216. break;
  4217. default:
  4218. b = left;
  4219. e = left+s;
  4220. break;
  4221. }
  4222. points = [[b,pos], [e,pos]];
  4223. // draw the shadow
  4224. if (this.shadow) {
  4225. this.renderer.shadowRenderer.draw(ctx, points, {lineCap:'butt', lineWidth:this.gridLineWidth*1.5, offset:this.gridLineWidth*0.75, fill:false, closePath:false});
  4226. }
  4227. // draw the line
  4228. drawLine(b, pos, e, pos, {strokeStyle:axis.borderColor});
  4229. }
  4230. t = null;
  4231. }
  4232. t0 = null;
  4233. }
  4234. axis = null;
  4235. ticks = null;
  4236. }
  4237. ctx.restore();
  4238. function drawLine(bx, by, ex, ey, opts) {
  4239. ctx.save();
  4240. opts = opts || {};
  4241. if (opts.lineWidth == null || opts.lineWidth != 0){
  4242. $.extend(true, ctx, opts);
  4243. ctx.beginPath();
  4244. ctx.moveTo(bx, by);
  4245. ctx.lineTo(ex, ey);
  4246. ctx.stroke();
  4247. ctx.restore();
  4248. }
  4249. }
  4250. if (this.shadow) {
  4251. var points = [[this._left, this._bottom], [this._right, this._bottom], [this._right, this._top]];
  4252. this.renderer.shadowRenderer.draw(ctx, points);
  4253. }
  4254. // Now draw border around grid. Use axis border definitions. start at
  4255. // upper left and go clockwise.
  4256. if (this.borderWidth != 0 && this.drawBorder) {
  4257. drawLine (this._left, this._top, this._right, this._top, {lineCap:'round', strokeStyle:axes.x2axis.borderColor, lineWidth:axes.x2axis.borderWidth});
  4258. drawLine (this._right, this._top, this._right, this._bottom, {lineCap:'round', strokeStyle:axes.y2axis.borderColor, lineWidth:axes.y2axis.borderWidth});
  4259. drawLine (this._right, this._bottom, this._left, this._bottom, {lineCap:'round', strokeStyle:axes.xaxis.borderColor, lineWidth:axes.xaxis.borderWidth});
  4260. drawLine (this._left, this._bottom, this._left, this._top, {lineCap:'round', strokeStyle:axes.yaxis.borderColor, lineWidth:axes.yaxis.borderWidth});
  4261. }
  4262. // ctx.lineWidth = this.borderWidth;
  4263. // ctx.strokeStyle = this.borderColor;
  4264. // ctx.strokeRect(this._left, this._top, this._width, this._height);
  4265. ctx.restore();
  4266. ctx = null;
  4267. axes = null;
  4268. };
  4269. // Class: $.jqplot.DivTitleRenderer
  4270. // The default title renderer for jqPlot. This class has no options beyond the <Title> class.
  4271. $.jqplot.DivTitleRenderer = function() {
  4272. };
  4273. $.jqplot.DivTitleRenderer.prototype.init = function(options) {
  4274. $.extend(true, this, options);
  4275. };
  4276. $.jqplot.DivTitleRenderer.prototype.draw = function() {
  4277. // Memory Leaks patch
  4278. if (this._elem) {
  4279. this._elem.emptyForce();
  4280. this._elem = null;
  4281. }
  4282. var r = this.renderer;
  4283. var elem = document.createElement('div');
  4284. this._elem = $(elem);
  4285. this._elem.addClass('jqplot-title');
  4286. if (!this.text) {
  4287. this.show = false;
  4288. this._elem.height(0);
  4289. this._elem.width(0);
  4290. }
  4291. else if (this.text) {
  4292. var color;
  4293. if (this.color) {
  4294. color = this.color;
  4295. }
  4296. else if (this.textColor) {
  4297. color = this.textColor;
  4298. }
  4299. // don't trust that a stylesheet is present, set the position.
  4300. var styles = {position:'absolute', top:'0px', left:'0px'};
  4301. if (this._plotWidth) {
  4302. styles['width'] = this._plotWidth+'px';
  4303. }
  4304. if (this.fontSize) {
  4305. styles['fontSize'] = this.fontSize;
  4306. }
  4307. if (typeof this.textAlign === 'string') {
  4308. styles['textAlign'] = this.textAlign;
  4309. }
  4310. else {
  4311. styles['textAlign'] = 'center';
  4312. }
  4313. if (color) {
  4314. styles['color'] = color;
  4315. }
  4316. if (this.paddingBottom) {
  4317. styles['paddingBottom'] = this.paddingBottom;
  4318. }
  4319. if (this.fontFamily) {
  4320. styles['fontFamily'] = this.fontFamily;
  4321. }
  4322. this._elem.css(styles);
  4323. if (this.escapeHtml) {
  4324. this._elem.text(this.text);
  4325. }
  4326. else {
  4327. this._elem.html(this.text);
  4328. }
  4329. // styletext += (this._plotWidth) ? 'width:'+this._plotWidth+'px;' : '';
  4330. // styletext += (this.fontSize) ? 'font-size:'+this.fontSize+';' : '';
  4331. // styletext += (this.textAlign) ? 'text-align:'+this.textAlign+';' : 'text-align:center;';
  4332. // styletext += (color) ? 'color:'+color+';' : '';
  4333. // styletext += (this.paddingBottom) ? 'padding-bottom:'+this.paddingBottom+';' : '';
  4334. // this._elem = $('<div class="jqplot-title" style="'+styletext+'">'+this.text+'</div>');
  4335. // if (this.fontFamily) {
  4336. // this._elem.css('font-family', this.fontFamily);
  4337. // }
  4338. }
  4339. elem = null;
  4340. return this._elem;
  4341. };
  4342. $.jqplot.DivTitleRenderer.prototype.pack = function() {
  4343. // nothing to do here
  4344. };
  4345. var dotlen = 0.1;
  4346. $.jqplot.LinePattern = function (ctx, pattern) {
  4347. var defaultLinePatterns = {
  4348. dotted: [ dotlen, $.jqplot.config.dotGapLength ],
  4349. dashed: [ $.jqplot.config.dashLength, $.jqplot.config.gapLength ],
  4350. solid: null
  4351. };
  4352. if (typeof pattern === 'string') {
  4353. if (pattern[0] === '.' || pattern[0] === '-') {
  4354. var s = pattern;
  4355. pattern = [];
  4356. for (var i=0, imax=s.length; i<imax; i++) {
  4357. if (s[i] === '.') {
  4358. pattern.push( dotlen );
  4359. }
  4360. else if (s[i] === '-') {
  4361. pattern.push( $.jqplot.config.dashLength );
  4362. }
  4363. else {
  4364. continue;
  4365. }
  4366. pattern.push( $.jqplot.config.gapLength );
  4367. }
  4368. }
  4369. else {
  4370. pattern = defaultLinePatterns[pattern];
  4371. }
  4372. }
  4373. if (!(pattern && pattern.length)) {
  4374. return ctx;
  4375. }
  4376. var patternIndex = 0;
  4377. var patternDistance = pattern[0];
  4378. var px = 0;
  4379. var py = 0;
  4380. var pathx0 = 0;
  4381. var pathy0 = 0;
  4382. var moveTo = function (x, y) {
  4383. ctx.moveTo( x, y );
  4384. px = x;
  4385. py = y;
  4386. pathx0 = x;
  4387. pathy0 = y;
  4388. };
  4389. var lineTo = function (x, y) {
  4390. var scale = ctx.lineWidth;
  4391. var dx = x - px;
  4392. var dy = y - py;
  4393. var dist = Math.sqrt(dx*dx+dy*dy);
  4394. if ((dist > 0) && (scale > 0)) {
  4395. dx /= dist;
  4396. dy /= dist;
  4397. while (true) {
  4398. var dp = scale * patternDistance;
  4399. if (dp < dist) {
  4400. px += dp * dx;
  4401. py += dp * dy;
  4402. if ((patternIndex & 1) == 0) {
  4403. ctx.lineTo( px, py );
  4404. }
  4405. else {
  4406. ctx.moveTo( px, py );
  4407. }
  4408. dist -= dp;
  4409. patternIndex++;
  4410. if (patternIndex >= pattern.length) {
  4411. patternIndex = 0;
  4412. }
  4413. patternDistance = pattern[patternIndex];
  4414. }
  4415. else {
  4416. px = x;
  4417. py = y;
  4418. if ((patternIndex & 1) == 0) {
  4419. ctx.lineTo( px, py );
  4420. }
  4421. else {
  4422. ctx.moveTo( px, py );
  4423. }
  4424. patternDistance -= dist / scale;
  4425. break;
  4426. }
  4427. }
  4428. }
  4429. };
  4430. var beginPath = function () {
  4431. ctx.beginPath();
  4432. };
  4433. var closePath = function () {
  4434. lineTo( pathx0, pathy0 );
  4435. };
  4436. return {
  4437. moveTo: moveTo,
  4438. lineTo: lineTo,
  4439. beginPath: beginPath,
  4440. closePath: closePath
  4441. };
  4442. };
  4443. // Class: $.jqplot.LineRenderer
  4444. // The default line renderer for jqPlot, this class has no options beyond the <Series> class.
  4445. // Draws series as a line.
  4446. $.jqplot.LineRenderer = function(){
  4447. this.shapeRenderer = new $.jqplot.ShapeRenderer();
  4448. this.shadowRenderer = new $.jqplot.ShadowRenderer();
  4449. };
  4450. // called with scope of series.
  4451. $.jqplot.LineRenderer.prototype.init = function(options, plot) {
  4452. // Group: Properties
  4453. //
  4454. options = options || {};
  4455. this._type='line';
  4456. this.renderer.animation = {
  4457. show: false,
  4458. direction: 'left',
  4459. speed: 2500,
  4460. _supported: true
  4461. };
  4462. // prop: smooth
  4463. // True to draw a smoothed (interpolated) line through the data points
  4464. // with automatically computed number of smoothing points.
  4465. // Set to an integer number > 2 to specify number of smoothing points
  4466. // to use between each data point.
  4467. this.renderer.smooth = false; // true or a number > 2 for smoothing.
  4468. this.renderer.tension = null; // null to auto compute or a number typically > 6. Fewer points requires higher tension.
  4469. // prop: constrainSmoothing
  4470. // True to use a more accurate smoothing algorithm that will
  4471. // not overshoot any data points. False to allow overshoot but
  4472. // produce a smoother looking line.
  4473. this.renderer.constrainSmoothing = true;
  4474. // this is smoothed data in grid coordinates, like gridData
  4475. this.renderer._smoothedData = [];
  4476. // this is smoothed data in plot units (plot coordinates), like plotData.
  4477. this.renderer._smoothedPlotData = [];
  4478. this.renderer._hiBandGridData = [];
  4479. this.renderer._lowBandGridData = [];
  4480. this.renderer._hiBandSmoothedData = [];
  4481. this.renderer._lowBandSmoothedData = [];
  4482. // prop: bandData
  4483. // Data used to draw error bands or confidence intervals above/below a line.
  4484. //
  4485. // bandData can be input in 3 forms. jqPlot will figure out which is the
  4486. // low band line and which is the high band line for all forms:
  4487. //
  4488. // A 2 dimensional array like [[yl1, yl2, ...], [yu1, yu2, ...]] where
  4489. // [yl1, yl2, ...] are y values of the lower line and
  4490. // [yu1, yu2, ...] are y values of the upper line.
  4491. // In this case there must be the same number of y data points as data points
  4492. // in the series and the bands will inherit the x values of the series.
  4493. //
  4494. // A 2 dimensional array like [[[xl1, yl1], [xl2, yl2], ...], [[xh1, yh1], [xh2, yh2], ...]]
  4495. // where [xl1, yl1] are x,y data points for the lower line and
  4496. // [xh1, yh1] are x,y data points for the high line.
  4497. // x values do not have to correspond to the x values of the series and can
  4498. // be of any arbitrary length.
  4499. //
  4500. // Can be of form [[yl1, yu1], [yl2, yu2], [yl3, yu3], ...] where
  4501. // there must be 3 or more arrays and there must be the same number of arrays
  4502. // as there are data points in the series. In this case,
  4503. // [yl1, yu1] specifies the lower and upper y values for the 1st
  4504. // data point and so on. The bands will inherit the x
  4505. // values from the series.
  4506. this.renderer.bandData = [];
  4507. // Group: bands
  4508. // Banding around line, e.g error bands or confidence intervals.
  4509. this.renderer.bands = {
  4510. // prop: show
  4511. // true to show the bands. If bandData or interval is
  4512. // supplied, show will be set to true by default.
  4513. show: false,
  4514. hiData: [],
  4515. lowData: [],
  4516. // prop: color
  4517. // color of lines at top and bottom of bands [default: series color].
  4518. color: this.color,
  4519. // prop: showLines
  4520. // True to show lines at top and bottom of bands [default: false].
  4521. showLines: false,
  4522. // prop: fill
  4523. // True to fill area between bands [default: true].
  4524. fill: true,
  4525. // prop: fillColor
  4526. // css color spec for filled area. [default: series color].
  4527. fillColor: null,
  4528. _min: null,
  4529. _max: null,
  4530. // prop: interval
  4531. // User specified interval above and below line for bands [default: '3%''].
  4532. // Can be a value like 3 or a string like '3%'
  4533. // or an upper/lower array like [1, -2] or ['2%', '-1.5%']
  4534. interval: '3%'
  4535. };
  4536. var lopts = {highlightMouseOver: options.highlightMouseOver, highlightMouseDown: options.highlightMouseDown, highlightColor: options.highlightColor};
  4537. delete (options.highlightMouseOver);
  4538. delete (options.highlightMouseDown);
  4539. delete (options.highlightColor);
  4540. $.extend(true, this.renderer, options);
  4541. this.renderer.options = options;
  4542. // if we are given some band data, and bands aren't explicity set to false in options, turn them on.
  4543. if (this.renderer.bandData.length > 1 && (!options.bands || options.bands.show == null)) {
  4544. this.renderer.bands.show = true;
  4545. }
  4546. // if we are given an interval, and bands aren't explicity set to false in options, turn them on.
  4547. else if (options.bands && options.bands.show == null && options.bands.interval != null) {
  4548. this.renderer.bands.show = true;
  4549. }
  4550. // if plot is filled, turn off bands.
  4551. if (this.fill) {
  4552. this.renderer.bands.show = false;
  4553. }
  4554. if (this.renderer.bands.show) {
  4555. this.renderer.initBands.call(this, this.renderer.options, plot);
  4556. }
  4557. // smoothing is not compatible with stacked lines, disable
  4558. if (this._stack) {
  4559. this.renderer.smooth = false;
  4560. }
  4561. // set the shape renderer options
  4562. var opts = {lineJoin:this.lineJoin, lineCap:this.lineCap, fill:this.fill, isarc:false, strokeStyle:this.color, fillStyle:this.fillColor, lineWidth:this.lineWidth, linePattern:this.linePattern, closePath:this.fill};
  4563. this.renderer.shapeRenderer.init(opts);
  4564. var shadow_offset = options.shadowOffset;
  4565. // set the shadow renderer options
  4566. if (shadow_offset == null) {
  4567. // scale the shadowOffset to the width of the line.
  4568. if (this.lineWidth > 2.5) {
  4569. shadow_offset = 1.25 * (1 + (Math.atan((this.lineWidth/2.5))/0.785398163 - 1)*0.6);
  4570. // var shadow_offset = this.shadowOffset;
  4571. }
  4572. // for skinny lines, don't make such a big shadow.
  4573. else {
  4574. shadow_offset = 1.25 * Math.atan((this.lineWidth/2.5))/0.785398163;
  4575. }
  4576. }
  4577. var sopts = {lineJoin:this.lineJoin, lineCap:this.lineCap, fill:this.fill, isarc:false, angle:this.shadowAngle, offset:shadow_offset, alpha:this.shadowAlpha, depth:this.shadowDepth, lineWidth:this.lineWidth, linePattern:this.linePattern, closePath:this.fill};
  4578. this.renderer.shadowRenderer.init(sopts);
  4579. this._areaPoints = [];
  4580. this._boundingBox = [[],[]];
  4581. if (!this.isTrendline && this.fill || this.renderer.bands.show) {
  4582. // Group: Properties
  4583. //
  4584. // prop: highlightMouseOver
  4585. // True to highlight area on a filled plot when moused over.
  4586. // This must be false to enable highlightMouseDown to highlight when clicking on an area on a filled plot.
  4587. this.highlightMouseOver = true;
  4588. // prop: highlightMouseDown
  4589. // True to highlight when a mouse button is pressed over an area on a filled plot.
  4590. // This will be disabled if highlightMouseOver is true.
  4591. this.highlightMouseDown = false;
  4592. // prop: highlightColor
  4593. // color to use when highlighting an area on a filled plot.
  4594. this.highlightColor = null;
  4595. // if user has passed in highlightMouseDown option and not set highlightMouseOver, disable highlightMouseOver
  4596. if (lopts.highlightMouseDown && lopts.highlightMouseOver == null) {
  4597. lopts.highlightMouseOver = false;
  4598. }
  4599. $.extend(true, this, {highlightMouseOver: lopts.highlightMouseOver, highlightMouseDown: lopts.highlightMouseDown, highlightColor: lopts.highlightColor});
  4600. if (!this.highlightColor) {
  4601. var fc = (this.renderer.bands.show) ? this.renderer.bands.fillColor : this.fillColor;
  4602. this.highlightColor = $.jqplot.computeHighlightColors(fc);
  4603. }
  4604. // turn off (disable) the highlighter plugin
  4605. if (this.highlighter) {
  4606. this.highlighter.show = false;
  4607. }
  4608. }
  4609. if (!this.isTrendline && plot) {
  4610. plot.plugins.lineRenderer = {};
  4611. plot.postInitHooks.addOnce(postInit);
  4612. plot.postDrawHooks.addOnce(postPlotDraw);
  4613. plot.eventListenerHooks.addOnce('jqplotMouseMove', handleMove);
  4614. plot.eventListenerHooks.addOnce('jqplotMouseDown', handleMouseDown);
  4615. plot.eventListenerHooks.addOnce('jqplotMouseUp', handleMouseUp);
  4616. plot.eventListenerHooks.addOnce('jqplotClick', handleClick);
  4617. plot.eventListenerHooks.addOnce('jqplotRightClick', handleRightClick);
  4618. }
  4619. };
  4620. $.jqplot.LineRenderer.prototype.initBands = function(options, plot) {
  4621. // use bandData if no data specified in bands option
  4622. //var bd = this.renderer.bandData;
  4623. var bd = options.bandData || [];
  4624. var bands = this.renderer.bands;
  4625. bands.hiData = [];
  4626. bands.lowData = [];
  4627. var data = this.data;
  4628. bands._max = null;
  4629. bands._min = null;
  4630. // If 2 arrays, and each array greater than 2 elements, assume it is hi and low data bands of y values.
  4631. if (bd.length == 2) {
  4632. // Do we have an array of x,y values?
  4633. // like [[[1,1], [2,4], [3,3]], [[1,3], [2,6], [3,5]]]
  4634. if ($.isArray(bd[0][0])) {
  4635. // since an arbitrary array of points, spin through all of them to determine max and min lines.
  4636. var p;
  4637. var bdminidx = 0, bdmaxidx = 0;
  4638. for (var i = 0, l = bd[0].length; i<l; i++) {
  4639. p = bd[0][i];
  4640. if ((p[1] != null && p[1] > bands._max) || bands._max == null) {
  4641. bands._max = p[1];
  4642. }
  4643. if ((p[1] != null && p[1] < bands._min) || bands._min == null) {
  4644. bands._min = p[1];
  4645. }
  4646. }
  4647. for (var i = 0, l = bd[1].length; i<l; i++) {
  4648. p = bd[1][i];
  4649. if ((p[1] != null && p[1] > bands._max) || bands._max == null) {
  4650. bands._max = p[1];
  4651. bdmaxidx = 1;
  4652. }
  4653. if ((p[1] != null && p[1] < bands._min) || bands._min == null) {
  4654. bands._min = p[1];
  4655. bdminidx = 1;
  4656. }
  4657. }
  4658. if (bdmaxidx === bdminidx) {
  4659. bands.show = false;
  4660. }
  4661. bands.hiData = bd[bdmaxidx];
  4662. bands.lowData = bd[bdminidx];
  4663. }
  4664. // else data is arrays of y values
  4665. // like [[1,4,3], [3,6,5]]
  4666. // must have same number of band data points as points in series
  4667. else if (bd[0].length === data.length && bd[1].length === data.length) {
  4668. var hi = (bd[0][0] > bd[1][0]) ? 0 : 1;
  4669. var low = (hi) ? 0 : 1;
  4670. for (var i=0, l=data.length; i < l; i++) {
  4671. bands.hiData.push([data[i][0], bd[hi][i]]);
  4672. bands.lowData.push([data[i][0], bd[low][i]]);
  4673. }
  4674. }
  4675. // we don't have proper data array, don't show bands.
  4676. else {
  4677. bands.show = false;
  4678. }
  4679. }
  4680. // if more than 2 arrays, have arrays of [ylow, yhi] values.
  4681. // note, can't distinguish case of [[ylow, yhi], [ylow, yhi]] from [[ylow, ylow], [yhi, yhi]]
  4682. // this is assumed to be of the latter form.
  4683. else if (bd.length > 2 && !$.isArray(bd[0][0])) {
  4684. var hi = (bd[0][0] > bd[0][1]) ? 0 : 1;
  4685. var low = (hi) ? 0 : 1;
  4686. for (var i=0, l=bd.length; i<l; i++) {
  4687. bands.hiData.push([data[i][0], bd[i][hi]]);
  4688. bands.lowData.push([data[i][0], bd[i][low]]);
  4689. }
  4690. }
  4691. // don't have proper data, auto calculate
  4692. else {
  4693. var intrv = bands.interval;
  4694. var a = null;
  4695. var b = null;
  4696. var afunc = null;
  4697. var bfunc = null;
  4698. if ($.isArray(intrv)) {
  4699. a = intrv[0];
  4700. b = intrv[1];
  4701. }
  4702. else {
  4703. a = intrv;
  4704. }
  4705. if (isNaN(a)) {
  4706. // we have a string
  4707. if (a.charAt(a.length - 1) === '%') {
  4708. afunc = 'multiply';
  4709. a = parseFloat(a)/100 + 1;
  4710. }
  4711. }
  4712. else {
  4713. a = parseFloat(a);
  4714. afunc = 'add';
  4715. }
  4716. if (b !== null && isNaN(b)) {
  4717. // we have a string
  4718. if (b.charAt(b.length - 1) === '%') {
  4719. bfunc = 'multiply';
  4720. b = parseFloat(b)/100 + 1;
  4721. }
  4722. }
  4723. else if (b !== null) {
  4724. b = parseFloat(b);
  4725. bfunc = 'add';
  4726. }
  4727. if (a !== null) {
  4728. if (b === null) {
  4729. b = -a;
  4730. bfunc = afunc;
  4731. if (bfunc === 'multiply') {
  4732. b += 2;
  4733. }
  4734. }
  4735. // make sure a always applies to hi band.
  4736. if (a < b) {
  4737. var temp = a;
  4738. a = b;
  4739. b = temp;
  4740. temp = afunc;
  4741. afunc = bfunc;
  4742. bfunc = temp;
  4743. }
  4744. for (var i=0, l = data.length; i < l; i++) {
  4745. switch (afunc) {
  4746. case 'add':
  4747. bands.hiData.push([data[i][0], data[i][1] + a]);
  4748. break;
  4749. case 'multiply':
  4750. bands.hiData.push([data[i][0], data[i][1] * a]);
  4751. break;
  4752. }
  4753. switch (bfunc) {
  4754. case 'add':
  4755. bands.lowData.push([data[i][0], data[i][1] + b]);
  4756. break;
  4757. case 'multiply':
  4758. bands.lowData.push([data[i][0], data[i][1] * b]);
  4759. break;
  4760. }
  4761. }
  4762. }
  4763. else {
  4764. bands.show = false;
  4765. }
  4766. }
  4767. var hd = bands.hiData;
  4768. var ld = bands.lowData;
  4769. for (var i = 0, l = hd.length; i<l; i++) {
  4770. if ((hd[i][1] != null && hd[i][1] > bands._max) || bands._max == null) {
  4771. bands._max = hd[i][1];
  4772. }
  4773. }
  4774. for (var i = 0, l = ld.length; i<l; i++) {
  4775. if ((ld[i][1] != null && ld[i][1] < bands._min) || bands._min == null) {
  4776. bands._min = ld[i][1];
  4777. }
  4778. }
  4779. // one last check for proper data
  4780. // these don't apply any more since allowing arbitrary x,y values
  4781. // if (bands.hiData.length != bands.lowData.length) {
  4782. // bands.show = false;
  4783. // }
  4784. // if (bands.hiData.length != this.data.length) {
  4785. // bands.show = false;
  4786. // }
  4787. if (bands.fillColor === null) {
  4788. var c = $.jqplot.getColorComponents(bands.color);
  4789. // now adjust alpha to differentiate fill
  4790. c[3] = c[3] * 0.5;
  4791. bands.fillColor = 'rgba(' + c[0] +', '+ c[1] +', '+ c[2] +', '+ c[3] + ')';
  4792. }
  4793. };
  4794. function getSteps (d, f) {
  4795. return (3.4182054+f) * Math.pow(d, -0.3534992);
  4796. }
  4797. function computeSteps (d1, d2) {
  4798. var s = Math.sqrt(Math.pow((d2[0]- d1[0]), 2) + Math.pow ((d2[1] - d1[1]), 2));
  4799. return 5.7648 * Math.log(s) + 7.4456;
  4800. }
  4801. function tanh (x) {
  4802. var a = (Math.exp(2*x) - 1) / (Math.exp(2*x) + 1);
  4803. return a;
  4804. }
  4805. //////////
  4806. // computeConstrainedSmoothedData
  4807. // An implementation of the constrained cubic spline interpolation
  4808. // method as presented in:
  4809. //
  4810. // Kruger, CJC, Constrained Cubic Spine Interpolation for Chemical Engineering Applications
  4811. // http://www.korf.co.uk/spline.pdf
  4812. //
  4813. // The implementation below borrows heavily from the sample Visual Basic
  4814. // implementation by CJC Kruger found in http://www.korf.co.uk/spline.xls
  4815. //
  4816. /////////
  4817. // called with scope of series
  4818. function computeConstrainedSmoothedData (gd) {
  4819. var smooth = this.renderer.smooth;
  4820. var dim = this.canvas.getWidth();
  4821. var xp = this._xaxis.series_p2u;
  4822. var yp = this._yaxis.series_p2u;
  4823. var steps =null;
  4824. var _steps = null;
  4825. var dist = gd.length/dim;
  4826. var _smoothedData = [];
  4827. var _smoothedPlotData = [];
  4828. if (!isNaN(parseFloat(smooth))) {
  4829. steps = parseFloat(smooth);
  4830. }
  4831. else {
  4832. steps = getSteps(dist, 0.5);
  4833. }
  4834. var yy = [];
  4835. var xx = [];
  4836. for (var i=0, l = gd.length; i<l; i++) {
  4837. yy.push(gd[i][1]);
  4838. xx.push(gd[i][0]);
  4839. }
  4840. function dxx(x1, x0) {
  4841. if (x1 - x0 == 0) {
  4842. return Math.pow(10,10);
  4843. }
  4844. else {
  4845. return x1 - x0;
  4846. }
  4847. }
  4848. var A, B, C, D;
  4849. // loop through each line segment. Have # points - 1 line segments. Nmber segments starting at 1.
  4850. var nmax = gd.length - 1;
  4851. for (var num = 1, gdl = gd.length; num<gdl; num++) {
  4852. var gxx = [];
  4853. var ggxx = [];
  4854. // point at each end of segment.
  4855. for (var j = 0; j < 2; j++) {
  4856. var i = num - 1 + j; // point number, 0 to # points.
  4857. if (i == 0 || i == nmax) {
  4858. gxx[j] = Math.pow(10, 10);
  4859. }
  4860. else if (yy[i+1] - yy[i] == 0 || yy[i] - yy[i-1] == 0) {
  4861. gxx[j] = 0;
  4862. }
  4863. else if (((xx[i+1] - xx[i]) / (yy[i+1] - yy[i]) + (xx[i] - xx[i-1]) / (yy[i] - yy[i-1])) == 0 ) {
  4864. gxx[j] = 0;
  4865. }
  4866. else if ( (yy[i+1] - yy[i]) * (yy[i] - yy[i-1]) < 0 ) {
  4867. gxx[j] = 0;
  4868. }
  4869. else {
  4870. gxx[j] = 2 / (dxx(xx[i + 1], xx[i]) / (yy[i + 1] - yy[i]) + dxx(xx[i], xx[i - 1]) / (yy[i] - yy[i - 1]));
  4871. }
  4872. }
  4873. // Reset first derivative (slope) at first and last point
  4874. if (num == 1) {
  4875. // First point has 0 2nd derivative
  4876. gxx[0] = 3 / 2 * (yy[1] - yy[0]) / dxx(xx[1], xx[0]) - gxx[1] / 2;
  4877. }
  4878. else if (num == nmax) {
  4879. // Last point has 0 2nd derivative
  4880. gxx[1] = 3 / 2 * (yy[nmax] - yy[nmax - 1]) / dxx(xx[nmax], xx[nmax - 1]) - gxx[0] / 2;
  4881. }
  4882. // Calc second derivative at points
  4883. ggxx[0] = -2 * (gxx[1] + 2 * gxx[0]) / dxx(xx[num], xx[num - 1]) + 6 * (yy[num] - yy[num - 1]) / Math.pow(dxx(xx[num], xx[num - 1]), 2);
  4884. ggxx[1] = 2 * (2 * gxx[1] + gxx[0]) / dxx(xx[num], xx[num - 1]) - 6 * (yy[num] - yy[num - 1]) / Math.pow(dxx(xx[num], xx[num - 1]), 2);
  4885. // Calc constants for cubic interpolation
  4886. D = 1 / 6 * (ggxx[1] - ggxx[0]) / dxx(xx[num], xx[num - 1]);
  4887. C = 1 / 2 * (xx[num] * ggxx[0] - xx[num - 1] * ggxx[1]) / dxx(xx[num], xx[num - 1]);
  4888. B = (yy[num] - yy[num - 1] - C * (Math.pow(xx[num], 2) - Math.pow(xx[num - 1], 2)) - D * (Math.pow(xx[num], 3) - Math.pow(xx[num - 1], 3))) / dxx(xx[num], xx[num - 1]);
  4889. A = yy[num - 1] - B * xx[num - 1] - C * Math.pow(xx[num - 1], 2) - D * Math.pow(xx[num - 1], 3);
  4890. var increment = (xx[num] - xx[num - 1]) / steps;
  4891. var temp, tempx;
  4892. for (var j = 0, l = steps; j < l; j++) {
  4893. temp = [];
  4894. tempx = xx[num - 1] + j * increment;
  4895. temp.push(tempx);
  4896. temp.push(A + B * tempx + C * Math.pow(tempx, 2) + D * Math.pow(tempx, 3));
  4897. _smoothedData.push(temp);
  4898. _smoothedPlotData.push([xp(temp[0]), yp(temp[1])]);
  4899. }
  4900. }
  4901. _smoothedData.push(gd[i]);
  4902. _smoothedPlotData.push([xp(gd[i][0]), yp(gd[i][1])]);
  4903. return [_smoothedData, _smoothedPlotData];
  4904. }
  4905. ///////
  4906. // computeHermiteSmoothedData
  4907. // A hermite spline smoothing of the plot data.
  4908. // This implementation is derived from the one posted
  4909. // by krypin on the jqplot-users mailing list:
  4910. //
  4911. // http://groups.google.com/group/jqplot-users/browse_thread/thread/748be6a445723cea?pli=1
  4912. //
  4913. // with a blog post:
  4914. //
  4915. // http://blog.statscollector.com/a-plugin-renderer-for-jqplot-to-draw-a-hermite-spline/
  4916. //
  4917. // and download of the original plugin:
  4918. //
  4919. // http://blog.statscollector.com/wp-content/uploads/2010/02/jqplot.hermiteSplineRenderer.js
  4920. //////////
  4921. // called with scope of series
  4922. function computeHermiteSmoothedData (gd) {
  4923. var smooth = this.renderer.smooth;
  4924. var tension = this.renderer.tension;
  4925. var dim = this.canvas.getWidth();
  4926. var xp = this._xaxis.series_p2u;
  4927. var yp = this._yaxis.series_p2u;
  4928. var steps =null;
  4929. var _steps = null;
  4930. var a = null;
  4931. var a1 = null;
  4932. var a2 = null;
  4933. var slope = null;
  4934. var slope2 = null;
  4935. var temp = null;
  4936. var t, s, h1, h2, h3, h4;
  4937. var TiX, TiY, Ti1X, Ti1Y;
  4938. var pX, pY, p;
  4939. var sd = [];
  4940. var spd = [];
  4941. var dist = gd.length/dim;
  4942. var min, max, stretch, scale, shift;
  4943. var _smoothedData = [];
  4944. var _smoothedPlotData = [];
  4945. if (!isNaN(parseFloat(smooth))) {
  4946. steps = parseFloat(smooth);
  4947. }
  4948. else {
  4949. steps = getSteps(dist, 0.5);
  4950. }
  4951. if (!isNaN(parseFloat(tension))) {
  4952. tension = parseFloat(tension);
  4953. }
  4954. for (var i=0, l = gd.length-1; i < l; i++) {
  4955. if (tension === null) {
  4956. slope = Math.abs((gd[i+1][1] - gd[i][1]) / (gd[i+1][0] - gd[i][0]));
  4957. min = 0.3;
  4958. max = 0.6;
  4959. stretch = (max - min)/2.0;
  4960. scale = 2.5;
  4961. shift = -1.4;
  4962. temp = slope/scale + shift;
  4963. a1 = stretch * tanh(temp) - stretch * tanh(shift) + min;
  4964. // if have both left and right line segments, will use minimum tension.
  4965. if (i > 0) {
  4966. slope2 = Math.abs((gd[i][1] - gd[i-1][1]) / (gd[i][0] - gd[i-1][0]));
  4967. }
  4968. temp = slope2/scale + shift;
  4969. a2 = stretch * tanh(temp) - stretch * tanh(shift) + min;
  4970. a = (a1 + a2)/2.0;
  4971. }
  4972. else {
  4973. a = tension;
  4974. }
  4975. for (t=0; t < steps; t++) {
  4976. s = t / steps;
  4977. h1 = (1 + 2*s)*Math.pow((1-s),2);
  4978. h2 = s*Math.pow((1-s),2);
  4979. h3 = Math.pow(s,2)*(3-2*s);
  4980. h4 = Math.pow(s,2)*(s-1);
  4981. if (gd[i-1]) {
  4982. TiX = a * (gd[i+1][0] - gd[i-1][0]);
  4983. TiY = a * (gd[i+1][1] - gd[i-1][1]);
  4984. } else {
  4985. TiX = a * (gd[i+1][0] - gd[i][0]);
  4986. TiY = a * (gd[i+1][1] - gd[i][1]);
  4987. }
  4988. if (gd[i+2]) {
  4989. Ti1X = a * (gd[i+2][0] - gd[i][0]);
  4990. Ti1Y = a * (gd[i+2][1] - gd[i][1]);
  4991. } else {
  4992. Ti1X = a * (gd[i+1][0] - gd[i][0]);
  4993. Ti1Y = a * (gd[i+1][1] - gd[i][1]);
  4994. }
  4995. pX = h1*gd[i][0] + h3*gd[i+1][0] + h2*TiX + h4*Ti1X;
  4996. pY = h1*gd[i][1] + h3*gd[i+1][1] + h2*TiY + h4*Ti1Y;
  4997. p = [pX, pY];
  4998. _smoothedData.push(p);
  4999. _smoothedPlotData.push([xp(pX), yp(pY)]);
  5000. }
  5001. }
  5002. _smoothedData.push(gd[l]);
  5003. _smoothedPlotData.push([xp(gd[l][0]), yp(gd[l][1])]);
  5004. return [_smoothedData, _smoothedPlotData];
  5005. }
  5006. // setGridData
  5007. // converts the user data values to grid coordinates and stores them
  5008. // in the gridData array.
  5009. // Called with scope of a series.
  5010. $.jqplot.LineRenderer.prototype.setGridData = function(plot) {
  5011. // recalculate the grid data
  5012. var xp = this._xaxis.series_u2p;
  5013. var yp = this._yaxis.series_u2p;
  5014. var data = this._plotData;
  5015. var pdata = this._prevPlotData;
  5016. this.gridData = [];
  5017. this._prevGridData = [];
  5018. this.renderer._smoothedData = [];
  5019. this.renderer._smoothedPlotData = [];
  5020. this.renderer._hiBandGridData = [];
  5021. this.renderer._lowBandGridData = [];
  5022. this.renderer._hiBandSmoothedData = [];
  5023. this.renderer._lowBandSmoothedData = [];
  5024. var bands = this.renderer.bands;
  5025. var hasNull = false;
  5026. for (var i=0, l=data.length; i < l; i++) {
  5027. // if not a line series or if no nulls in data, push the converted point onto the array.
  5028. if (data[i][0] != null && data[i][1] != null) {
  5029. this.gridData.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
  5030. }
  5031. // else if there is a null, preserve it.
  5032. else if (data[i][0] == null) {
  5033. hasNull = true;
  5034. this.gridData.push([null, yp.call(this._yaxis, data[i][1])]);
  5035. }
  5036. else if (data[i][1] == null) {
  5037. hasNull = true;
  5038. this.gridData.push([xp.call(this._xaxis, data[i][0]), null]);
  5039. }
  5040. // if not a line series or if no nulls in data, push the converted point onto the array.
  5041. if (pdata[i] != null && pdata[i][0] != null && pdata[i][1] != null) {
  5042. this._prevGridData.push([xp.call(this._xaxis, pdata[i][0]), yp.call(this._yaxis, pdata[i][1])]);
  5043. }
  5044. // else if there is a null, preserve it.
  5045. else if (pdata[i] != null && pdata[i][0] == null) {
  5046. this._prevGridData.push([null, yp.call(this._yaxis, pdata[i][1])]);
  5047. }
  5048. else if (pdata[i] != null && pdata[i][0] != null && pdata[i][1] == null) {
  5049. this._prevGridData.push([xp.call(this._xaxis, pdata[i][0]), null]);
  5050. }
  5051. }
  5052. // don't do smoothing or bands on broken lines.
  5053. if (hasNull) {
  5054. this.renderer.smooth = false;
  5055. if (this._type === 'line') {
  5056. bands.show = false;
  5057. }
  5058. }
  5059. if (this._type === 'line' && bands.show) {
  5060. for (var i=0, l=bands.hiData.length; i<l; i++) {
  5061. this.renderer._hiBandGridData.push([xp.call(this._xaxis, bands.hiData[i][0]), yp.call(this._yaxis, bands.hiData[i][1])]);
  5062. }
  5063. for (var i=0, l=bands.lowData.length; i<l; i++) {
  5064. this.renderer._lowBandGridData.push([xp.call(this._xaxis, bands.lowData[i][0]), yp.call(this._yaxis, bands.lowData[i][1])]);
  5065. }
  5066. }
  5067. // calculate smoothed data if enough points and no nulls
  5068. if (this._type === 'line' && this.renderer.smooth && this.gridData.length > 2) {
  5069. var ret;
  5070. if (this.renderer.constrainSmoothing) {
  5071. ret = computeConstrainedSmoothedData.call(this, this.gridData);
  5072. this.renderer._smoothedData = ret[0];
  5073. this.renderer._smoothedPlotData = ret[1];
  5074. if (bands.show) {
  5075. ret = computeConstrainedSmoothedData.call(this, this.renderer._hiBandGridData);
  5076. this.renderer._hiBandSmoothedData = ret[0];
  5077. ret = computeConstrainedSmoothedData.call(this, this.renderer._lowBandGridData);
  5078. this.renderer._lowBandSmoothedData = ret[0];
  5079. }
  5080. ret = null;
  5081. }
  5082. else {
  5083. ret = computeHermiteSmoothedData.call(this, this.gridData);
  5084. this.renderer._smoothedData = ret[0];
  5085. this.renderer._smoothedPlotData = ret[1];
  5086. if (bands.show) {
  5087. ret = computeHermiteSmoothedData.call(this, this.renderer._hiBandGridData);
  5088. this.renderer._hiBandSmoothedData = ret[0];
  5089. ret = computeHermiteSmoothedData.call(this, this.renderer._lowBandGridData);
  5090. this.renderer._lowBandSmoothedData = ret[0];
  5091. }
  5092. ret = null;
  5093. }
  5094. }
  5095. };
  5096. // makeGridData
  5097. // converts any arbitrary data values to grid coordinates and
  5098. // returns them. This method exists so that plugins can use a series'
  5099. // linerenderer to generate grid data points without overwriting the
  5100. // grid data associated with that series.
  5101. // Called with scope of a series.
  5102. $.jqplot.LineRenderer.prototype.makeGridData = function(data, plot) {
  5103. // recalculate the grid data
  5104. var xp = this._xaxis.series_u2p;
  5105. var yp = this._yaxis.series_u2p;
  5106. var gd = [];
  5107. var pgd = [];
  5108. this.renderer._smoothedData = [];
  5109. this.renderer._smoothedPlotData = [];
  5110. this.renderer._hiBandGridData = [];
  5111. this.renderer._lowBandGridData = [];
  5112. this.renderer._hiBandSmoothedData = [];
  5113. this.renderer._lowBandSmoothedData = [];
  5114. var bands = this.renderer.bands;
  5115. var hasNull = false;
  5116. for (var i=0; i<data.length; i++) {
  5117. // if not a line series or if no nulls in data, push the converted point onto the array.
  5118. if (data[i][0] != null && data[i][1] != null) {
  5119. gd.push([xp.call(this._xaxis, data[i][0]), yp.call(this._yaxis, data[i][1])]);
  5120. }
  5121. // else if there is a null, preserve it.
  5122. else if (data[i][0] == null) {
  5123. hasNull = true;
  5124. gd.push([null, yp.call(this._yaxis, data[i][1])]);
  5125. }
  5126. else if (data[i][1] == null) {
  5127. hasNull = true;
  5128. gd.push([xp.call(this._xaxis, data[i][0]), null]);
  5129. }
  5130. }
  5131. // don't do smoothing or bands on broken lines.
  5132. if (hasNull) {
  5133. this.renderer.smooth = false;
  5134. if (this._type === 'line') {
  5135. bands.show = false;
  5136. }
  5137. }
  5138. if (this._type === 'line' && bands.show) {
  5139. for (var i=0, l=bands.hiData.length; i<l; i++) {
  5140. this.renderer._hiBandGridData.push([xp.call(this._xaxis, bands.hiData[i][0]), yp.call(this._yaxis, bands.hiData[i][1])]);
  5141. }
  5142. for (var i=0, l=bands.lowData.length; i<l; i++) {
  5143. this.renderer._lowBandGridData.push([xp.call(this._xaxis, bands.lowData[i][0]), yp.call(this._yaxis, bands.lowData[i][1])]);
  5144. }
  5145. }
  5146. if (this._type === 'line' && this.renderer.smooth && gd.length > 2) {
  5147. var ret;
  5148. if (this.renderer.constrainSmoothing) {
  5149. ret = computeConstrainedSmoothedData.call(this, gd);
  5150. this.renderer._smoothedData = ret[0];
  5151. this.renderer._smoothedPlotData = ret[1];
  5152. if (bands.show) {
  5153. ret = computeConstrainedSmoothedData.call(this, this.renderer._hiBandGridData);
  5154. this.renderer._hiBandSmoothedData = ret[0];
  5155. ret = computeConstrainedSmoothedData.call(this, this.renderer._lowBandGridData);
  5156. this.renderer._lowBandSmoothedData = ret[0];
  5157. }
  5158. ret = null;
  5159. }
  5160. else {
  5161. ret = computeHermiteSmoothedData.call(this, gd);
  5162. this.renderer._smoothedData = ret[0];
  5163. this.renderer._smoothedPlotData = ret[1];
  5164. if (bands.show) {
  5165. ret = computeHermiteSmoothedData.call(this, this.renderer._hiBandGridData);
  5166. this.renderer._hiBandSmoothedData = ret[0];
  5167. ret = computeHermiteSmoothedData.call(this, this.renderer._lowBandGridData);
  5168. this.renderer._lowBandSmoothedData = ret[0];
  5169. }
  5170. ret = null;
  5171. }
  5172. }
  5173. return gd;
  5174. };
  5175. // called within scope of series.
  5176. $.jqplot.LineRenderer.prototype.draw = function(ctx, gd, options, plot) {
  5177. var i;
  5178. // get a copy of the options, so we don't modify the original object.
  5179. var opts = $.extend(true, {}, options);
  5180. var shadow = (opts.shadow != undefined) ? opts.shadow : this.shadow;
  5181. var showLine = (opts.showLine != undefined) ? opts.showLine : this.showLine;
  5182. var fill = (opts.fill != undefined) ? opts.fill : this.fill;
  5183. var fillAndStroke = (opts.fillAndStroke != undefined) ? opts.fillAndStroke : this.fillAndStroke;
  5184. var xmin, ymin, xmax, ymax;
  5185. ctx.save();
  5186. if (gd.length) {
  5187. if (showLine) {
  5188. // if we fill, we'll have to add points to close the curve.
  5189. if (fill) {
  5190. if (this.fillToZero) {
  5191. // have to break line up into shapes at axis crossings
  5192. var negativeColor = this.negativeColor;
  5193. if (! this.useNegativeColors) {
  5194. negativeColor = opts.fillStyle;
  5195. }
  5196. var isnegative = false;
  5197. var posfs = opts.fillStyle;
  5198. // if stoking line as well as filling, get a copy of line data.
  5199. if (fillAndStroke) {
  5200. var fasgd = gd.slice(0);
  5201. }
  5202. // if not stacked, fill down to axis
  5203. if (this.index == 0 || !this._stack) {
  5204. var tempgd = [];
  5205. var pd = (this.renderer.smooth) ? this.renderer._smoothedPlotData : this._plotData;
  5206. this._areaPoints = [];
  5207. var pyzero = this._yaxis.series_u2p(this.fillToValue);
  5208. var pxzero = this._xaxis.series_u2p(this.fillToValue);
  5209. opts.closePath = true;
  5210. if (this.fillAxis == 'y') {
  5211. tempgd.push([gd[0][0], pyzero]);
  5212. this._areaPoints.push([gd[0][0], pyzero]);
  5213. for (var i=0; i<gd.length-1; i++) {
  5214. tempgd.push(gd[i]);
  5215. this._areaPoints.push(gd[i]);
  5216. // do we have an axis crossing?
  5217. if (pd[i][1] * pd[i+1][1] < 0) {
  5218. if (pd[i][1] < 0) {
  5219. isnegative = true;
  5220. opts.fillStyle = negativeColor;
  5221. }
  5222. else {
  5223. isnegative = false;
  5224. opts.fillStyle = posfs;
  5225. }
  5226. var xintercept = gd[i][0] + (gd[i+1][0] - gd[i][0]) * (pyzero-gd[i][1])/(gd[i+1][1] - gd[i][1]);
  5227. tempgd.push([xintercept, pyzero]);
  5228. this._areaPoints.push([xintercept, pyzero]);
  5229. // now draw this shape and shadow.
  5230. if (shadow) {
  5231. this.renderer.shadowRenderer.draw(ctx, tempgd, opts);
  5232. }
  5233. this.renderer.shapeRenderer.draw(ctx, tempgd, opts);
  5234. // now empty temp array and continue
  5235. tempgd = [[xintercept, pyzero]];
  5236. // this._areaPoints = [[xintercept, pyzero]];
  5237. }
  5238. }
  5239. if (pd[gd.length-1][1] < 0) {
  5240. isnegative = true;
  5241. opts.fillStyle = negativeColor;
  5242. }
  5243. else {
  5244. isnegative = false;
  5245. opts.fillStyle = posfs;
  5246. }
  5247. tempgd.push(gd[gd.length-1]);
  5248. this._areaPoints.push(gd[gd.length-1]);
  5249. tempgd.push([gd[gd.length-1][0], pyzero]);
  5250. this._areaPoints.push([gd[gd.length-1][0], pyzero]);
  5251. }
  5252. // now draw the last area.
  5253. if (shadow) {
  5254. this.renderer.shadowRenderer.draw(ctx, tempgd, opts);
  5255. }
  5256. this.renderer.shapeRenderer.draw(ctx, tempgd, opts);
  5257. // var gridymin = this._yaxis.series_u2p(0);
  5258. // // IE doesn't return new length on unshift
  5259. // gd.unshift([gd[0][0], gridymin]);
  5260. // len = gd.length;
  5261. // gd.push([gd[len - 1][0], gridymin]);
  5262. }
  5263. // if stacked, fill to line below
  5264. else {
  5265. var prev = this._prevGridData;
  5266. for (var i=prev.length; i>0; i--) {
  5267. gd.push(prev[i-1]);
  5268. // this._areaPoints.push(prev[i-1]);
  5269. }
  5270. if (shadow) {
  5271. this.renderer.shadowRenderer.draw(ctx, gd, opts);
  5272. }
  5273. this._areaPoints = gd;
  5274. this.renderer.shapeRenderer.draw(ctx, gd, opts);
  5275. }
  5276. }
  5277. /////////////////////////
  5278. // Not filled to zero
  5279. ////////////////////////
  5280. else {
  5281. // if stoking line as well as filling, get a copy of line data.
  5282. if (fillAndStroke) {
  5283. var fasgd = gd.slice(0);
  5284. }
  5285. // if not stacked, fill down to axis
  5286. if (this.index == 0 || !this._stack) {
  5287. // var gridymin = this._yaxis.series_u2p(this._yaxis.min) - this.gridBorderWidth / 2;
  5288. var gridymin = ctx.canvas.height;
  5289. // IE doesn't return new length on unshift
  5290. gd.unshift([gd[0][0], gridymin]);
  5291. var len = gd.length;
  5292. gd.push([gd[len - 1][0], gridymin]);
  5293. }
  5294. // if stacked, fill to line below
  5295. else {
  5296. var prev = this._prevGridData;
  5297. for (var i=prev.length; i>0; i--) {
  5298. gd.push(prev[i-1]);
  5299. }
  5300. }
  5301. this._areaPoints = gd;
  5302. if (shadow) {
  5303. this.renderer.shadowRenderer.draw(ctx, gd, opts);
  5304. }
  5305. this.renderer.shapeRenderer.draw(ctx, gd, opts);
  5306. }
  5307. if (fillAndStroke) {
  5308. var fasopts = $.extend(true, {}, opts, {fill:false, closePath:false});
  5309. this.renderer.shapeRenderer.draw(ctx, fasgd, fasopts);
  5310. //////////
  5311. // TODO: figure out some way to do shadows nicely
  5312. // if (shadow) {
  5313. // this.renderer.shadowRenderer.draw(ctx, fasgd, fasopts);
  5314. // }
  5315. // now draw the markers
  5316. if (this.markerRenderer.show) {
  5317. if (this.renderer.smooth) {
  5318. fasgd = this.gridData;
  5319. }
  5320. for (i=0; i<fasgd.length; i++) {
  5321. this.markerRenderer.draw(fasgd[i][0], fasgd[i][1], ctx, opts.markerOptions);
  5322. }
  5323. }
  5324. }
  5325. }
  5326. else {
  5327. if (this.renderer.bands.show) {
  5328. var bdat;
  5329. var bopts = $.extend(true, {}, opts);
  5330. if (this.renderer.bands.showLines) {
  5331. bdat = (this.renderer.smooth) ? this.renderer._hiBandSmoothedData : this.renderer._hiBandGridData;
  5332. this.renderer.shapeRenderer.draw(ctx, bdat, opts);
  5333. bdat = (this.renderer.smooth) ? this.renderer._lowBandSmoothedData : this.renderer._lowBandGridData;
  5334. this.renderer.shapeRenderer.draw(ctx, bdat, bopts);
  5335. }
  5336. if (this.renderer.bands.fill) {
  5337. if (this.renderer.smooth) {
  5338. bdat = this.renderer._hiBandSmoothedData.concat(this.renderer._lowBandSmoothedData.reverse());
  5339. }
  5340. else {
  5341. bdat = this.renderer._hiBandGridData.concat(this.renderer._lowBandGridData.reverse());
  5342. }
  5343. this._areaPoints = bdat;
  5344. bopts.closePath = true;
  5345. bopts.fill = true;
  5346. bopts.fillStyle = this.renderer.bands.fillColor;
  5347. this.renderer.shapeRenderer.draw(ctx, bdat, bopts);
  5348. }
  5349. }
  5350. if (shadow) {
  5351. this.renderer.shadowRenderer.draw(ctx, gd, opts);
  5352. }
  5353. this.renderer.shapeRenderer.draw(ctx, gd, opts);
  5354. }
  5355. }
  5356. // calculate the bounding box
  5357. var xmin = xmax = ymin = ymax = null;
  5358. for (i=0; i<this._areaPoints.length; i++) {
  5359. var p = this._areaPoints[i];
  5360. if (xmin > p[0] || xmin == null) {
  5361. xmin = p[0];
  5362. }
  5363. if (ymax < p[1] || ymax == null) {
  5364. ymax = p[1];
  5365. }
  5366. if (xmax < p[0] || xmax == null) {
  5367. xmax = p[0];
  5368. }
  5369. if (ymin > p[1] || ymin == null) {
  5370. ymin = p[1];
  5371. }
  5372. }
  5373. if (this.type === 'line' && this.renderer.bands.show) {
  5374. ymax = this._yaxis.series_u2p(this.renderer.bands._min);
  5375. ymin = this._yaxis.series_u2p(this.renderer.bands._max);
  5376. }
  5377. this._boundingBox = [[xmin, ymax], [xmax, ymin]];
  5378. // now draw the markers
  5379. if (this.markerRenderer.show && !fill) {
  5380. if (this.renderer.smooth) {
  5381. gd = this.gridData;
  5382. }
  5383. for (i=0; i<gd.length; i++) {
  5384. if (gd[i][0] != null && gd[i][1] != null) {
  5385. this.markerRenderer.draw(gd[i][0], gd[i][1], ctx, opts.markerOptions);
  5386. }
  5387. }
  5388. }
  5389. }
  5390. ctx.restore();
  5391. };
  5392. $.jqplot.LineRenderer.prototype.drawShadow = function(ctx, gd, options) {
  5393. // This is a no-op, shadows drawn with lines.
  5394. };
  5395. // called with scope of plot.
  5396. // make sure to not leave anything highlighted.
  5397. function postInit(target, data, options) {
  5398. for (var i=0; i<this.series.length; i++) {
  5399. if (this.series[i].renderer.constructor == $.jqplot.LineRenderer) {
  5400. // don't allow mouseover and mousedown at same time.
  5401. if (this.series[i].highlightMouseOver) {
  5402. this.series[i].highlightMouseDown = false;
  5403. }
  5404. }
  5405. }
  5406. }
  5407. // called within context of plot
  5408. // create a canvas which we can draw on.
  5409. // insert it before the eventCanvas, so eventCanvas will still capture events.
  5410. function postPlotDraw() {
  5411. // Memory Leaks patch
  5412. if (this.plugins.lineRenderer && this.plugins.lineRenderer.highlightCanvas) {
  5413. this.plugins.lineRenderer.highlightCanvas.resetCanvas();
  5414. this.plugins.lineRenderer.highlightCanvas = null;
  5415. }
  5416. this.plugins.lineRenderer.highlightedSeriesIndex = null;
  5417. this.plugins.lineRenderer.highlightCanvas = new $.jqplot.GenericCanvas();
  5418. this.eventCanvas._elem.before(this.plugins.lineRenderer.highlightCanvas.createElement(this._gridPadding, 'jqplot-lineRenderer-highlight-canvas', this._plotDimensions, this));
  5419. this.plugins.lineRenderer.highlightCanvas.setContext();
  5420. this.eventCanvas._elem.bind('mouseleave', {plot:this}, function (ev) { unhighlight(ev.data.plot); });
  5421. }
  5422. function highlight (plot, sidx, pidx, points) {
  5423. var s = plot.series[sidx];
  5424. var canvas = plot.plugins.lineRenderer.highlightCanvas;
  5425. canvas._ctx.clearRect(0,0,canvas._ctx.canvas.width, canvas._ctx.canvas.height);
  5426. s._highlightedPoint = pidx;
  5427. plot.plugins.lineRenderer.highlightedSeriesIndex = sidx;
  5428. var opts = {fillStyle: s.highlightColor};
  5429. if (s.type === 'line' && s.renderer.bands.show) {
  5430. opts.fill = true;
  5431. opts.closePath = true;
  5432. }
  5433. s.renderer.shapeRenderer.draw(canvas._ctx, points, opts);
  5434. canvas = null;
  5435. }
  5436. function unhighlight (plot) {
  5437. var canvas = plot.plugins.lineRenderer.highlightCanvas;
  5438. canvas._ctx.clearRect(0,0, canvas._ctx.canvas.width, canvas._ctx.canvas.height);
  5439. for (var i=0; i<plot.series.length; i++) {
  5440. plot.series[i]._highlightedPoint = null;
  5441. }
  5442. plot.plugins.lineRenderer.highlightedSeriesIndex = null;
  5443. plot.target.trigger('jqplotDataUnhighlight');
  5444. canvas = null;
  5445. }
  5446. function handleMove(ev, gridpos, datapos, neighbor, plot) {
  5447. if (neighbor) {
  5448. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  5449. var evt1 = jQuery.Event('jqplotDataMouseOver');
  5450. evt1.pageX = ev.pageX;
  5451. evt1.pageY = ev.pageY;
  5452. plot.target.trigger(evt1, ins);
  5453. if (plot.series[ins[0]].highlightMouseOver && !(ins[0] == plot.plugins.lineRenderer.highlightedSeriesIndex)) {
  5454. var evt = jQuery.Event('jqplotDataHighlight');
  5455. evt.which = ev.which;
  5456. evt.pageX = ev.pageX;
  5457. evt.pageY = ev.pageY;
  5458. plot.target.trigger(evt, ins);
  5459. highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
  5460. }
  5461. }
  5462. else if (neighbor == null) {
  5463. unhighlight (plot);
  5464. }
  5465. }
  5466. function handleMouseDown(ev, gridpos, datapos, neighbor, plot) {
  5467. if (neighbor) {
  5468. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  5469. if (plot.series[ins[0]].highlightMouseDown && !(ins[0] == plot.plugins.lineRenderer.highlightedSeriesIndex)) {
  5470. var evt = jQuery.Event('jqplotDataHighlight');
  5471. evt.which = ev.which;
  5472. evt.pageX = ev.pageX;
  5473. evt.pageY = ev.pageY;
  5474. plot.target.trigger(evt, ins);
  5475. highlight (plot, neighbor.seriesIndex, neighbor.pointIndex, neighbor.points);
  5476. }
  5477. }
  5478. else if (neighbor == null) {
  5479. unhighlight (plot);
  5480. }
  5481. }
  5482. function handleMouseUp(ev, gridpos, datapos, neighbor, plot) {
  5483. var idx = plot.plugins.lineRenderer.highlightedSeriesIndex;
  5484. if (idx != null && plot.series[idx].highlightMouseDown) {
  5485. unhighlight(plot);
  5486. }
  5487. }
  5488. function handleClick(ev, gridpos, datapos, neighbor, plot) {
  5489. if (neighbor) {
  5490. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  5491. var evt = jQuery.Event('jqplotDataClick');
  5492. evt.which = ev.which;
  5493. evt.pageX = ev.pageX;
  5494. evt.pageY = ev.pageY;
  5495. plot.target.trigger(evt, ins);
  5496. }
  5497. }
  5498. function handleRightClick(ev, gridpos, datapos, neighbor, plot) {
  5499. if (neighbor) {
  5500. var ins = [neighbor.seriesIndex, neighbor.pointIndex, neighbor.data];
  5501. var idx = plot.plugins.lineRenderer.highlightedSeriesIndex;
  5502. if (idx != null && plot.series[idx].highlightMouseDown) {
  5503. unhighlight(plot);
  5504. }
  5505. var evt = jQuery.Event('jqplotDataRightClick');
  5506. evt.which = ev.which;
  5507. evt.pageX = ev.pageX;
  5508. evt.pageY = ev.pageY;
  5509. plot.target.trigger(evt, ins);
  5510. }
  5511. }
  5512. // class: $.jqplot.LinearAxisRenderer
  5513. // The default jqPlot axis renderer, creating a numeric axis.
  5514. $.jqplot.LinearAxisRenderer = function() {
  5515. };
  5516. // called with scope of axis object.
  5517. $.jqplot.LinearAxisRenderer.prototype.init = function(options){
  5518. // prop: breakPoints
  5519. // EXPERIMENTAL!! Use at your own risk!
  5520. // Works only with linear axes and the default tick renderer.
  5521. // Array of [start, stop] points to create a broken axis.
  5522. // Broken axes have a "jump" in them, which is an immediate
  5523. // transition from a smaller value to a larger value.
  5524. // Currently, axis ticks MUST be manually assigned if using breakPoints
  5525. // by using the axis ticks array option.
  5526. this.breakPoints = null;
  5527. // prop: breakTickLabel
  5528. // Label to use at the axis break if breakPoints are specified.
  5529. this.breakTickLabel = "&asymp;";
  5530. // prop: drawBaseline
  5531. // True to draw the axis baseline.
  5532. this.drawBaseline = true;
  5533. // prop: baselineWidth
  5534. // width of the baseline in pixels.
  5535. this.baselineWidth = null;
  5536. // prop: baselineColor
  5537. // CSS color spec for the baseline.
  5538. this.baselineColor = null;
  5539. // prop: forceTickAt0
  5540. // This will ensure that there is always a tick mark at 0.
  5541. // If data range is strictly positive or negative,
  5542. // this will force 0 to be inside the axis bounds unless
  5543. // the appropriate axis pad (pad, padMin or padMax) is set
  5544. // to 0, then this will force an axis min or max value at 0.
  5545. // This has know effect when any of the following options
  5546. // are set: autoscale, min, max, numberTicks or tickInterval.
  5547. this.forceTickAt0 = false;
  5548. // prop: forceTickAt100
  5549. // This will ensure that there is always a tick mark at 100.
  5550. // If data range is strictly above or below 100,
  5551. // this will force 100 to be inside the axis bounds unless
  5552. // the appropriate axis pad (pad, padMin or padMax) is set
  5553. // to 0, then this will force an axis min or max value at 100.
  5554. // This has know effect when any of the following options
  5555. // are set: autoscale, min, max, numberTicks or tickInterval.
  5556. this.forceTickAt100 = false;
  5557. // prop: tickInset
  5558. // Controls the amount to inset the first and last ticks from
  5559. // the edges of the grid, in multiples of the tick interval.
  5560. // 0 is no inset, 0.5 is one half a tick interval, 1 is a full
  5561. // tick interval, etc.
  5562. this.tickInset = 0;
  5563. // prop: minorTicks
  5564. // Number of ticks to add between "major" ticks.
  5565. // Major ticks are ticks supplied by user or auto computed.
  5566. // Minor ticks cannot be created by user.
  5567. this.minorTicks = 0;
  5568. // prop: alignTicks
  5569. // true to align tick marks across opposed axes
  5570. // such as from the y2axis to yaxis.
  5571. this.alignTicks = false;
  5572. this._autoFormatString = '';
  5573. this._overrideFormatString = false;
  5574. this._scalefact = 1.0;
  5575. $.extend(true, this, options);
  5576. if (this.breakPoints) {
  5577. if (!$.isArray(this.breakPoints)) {
  5578. this.breakPoints = null;
  5579. }
  5580. else if (this.breakPoints.length < 2 || this.breakPoints[1] <= this.breakPoints[0]) {
  5581. this.breakPoints = null;
  5582. }
  5583. }
  5584. if (this.numberTicks != null && this.numberTicks < 2) {
  5585. this.numberTicks = 2;
  5586. }
  5587. this.resetDataBounds();
  5588. };
  5589. // called with scope of axis
  5590. $.jqplot.LinearAxisRenderer.prototype.draw = function(ctx, plot) {
  5591. if (this.show) {
  5592. // populate the axis label and value properties.
  5593. // createTicks is a method on the renderer, but
  5594. // call it within the scope of the axis.
  5595. this.renderer.createTicks.call(this, plot);
  5596. // fill a div with axes labels in the right direction.
  5597. // Need to pregenerate each axis to get it's bounds and
  5598. // position it and the labels correctly on the plot.
  5599. var dim=0;
  5600. var temp;
  5601. // Added for theming.
  5602. if (this._elem) {
  5603. // Memory Leaks patch
  5604. //this._elem.empty();
  5605. this._elem.emptyForce();
  5606. this._elem = null;
  5607. }
  5608. this._elem = $(document.createElement('div'));
  5609. this._elem.addClass('jqplot-axis jqplot-'+this.name);
  5610. this._elem.css('position', 'absolute');
  5611. if (this.name == 'xaxis' || this.name == 'x2axis') {
  5612. this._elem.width(this._plotDimensions.width);
  5613. }
  5614. else {
  5615. this._elem.height(this._plotDimensions.height);
  5616. }
  5617. // create a _label object.
  5618. this.labelOptions.axis = this.name;
  5619. this._label = new this.labelRenderer(this.labelOptions);
  5620. if (this._label.show) {
  5621. var elem = this._label.draw(ctx, plot);
  5622. elem.appendTo(this._elem);
  5623. elem = null;
  5624. }
  5625. var t = this._ticks;
  5626. var tick;
  5627. for (var i=0; i<t.length; i++) {
  5628. tick = t[i];
  5629. if (tick.show && tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
  5630. this._elem.append(tick.draw(ctx, plot));
  5631. }
  5632. }
  5633. tick = null;
  5634. t = null;
  5635. }
  5636. return this._elem;
  5637. };
  5638. // called with scope of an axis
  5639. $.jqplot.LinearAxisRenderer.prototype.reset = function() {
  5640. this.min = this._options.min;
  5641. this.max = this._options.max;
  5642. this.tickInterval = this._options.tickInterval;
  5643. this.numberTicks = this._options.numberTicks;
  5644. this._autoFormatString = '';
  5645. if (this._overrideFormatString && this.tickOptions && this.tickOptions.formatString) {
  5646. this.tickOptions.formatString = '';
  5647. }
  5648. // this._ticks = this.__ticks;
  5649. };
  5650. // called with scope of axis
  5651. $.jqplot.LinearAxisRenderer.prototype.set = function() {
  5652. var dim = 0;
  5653. var temp;
  5654. var w = 0;
  5655. var h = 0;
  5656. var lshow = (this._label == null) ? false : this._label.show;
  5657. if (this.show) {
  5658. var t = this._ticks;
  5659. var tick;
  5660. for (var i=0; i<t.length; i++) {
  5661. tick = t[i];
  5662. if (!tick._breakTick && tick.show && tick.showLabel && (!tick.isMinorTick || this.showMinorTicks)) {
  5663. if (this.name == 'xaxis' || this.name == 'x2axis') {
  5664. temp = tick._elem.outerHeight(true);
  5665. }
  5666. else {
  5667. temp = tick._elem.outerWidth(true);
  5668. }
  5669. if (temp > dim) {
  5670. dim = temp;
  5671. }
  5672. }
  5673. }
  5674. tick = null;
  5675. t = null;
  5676. if (lshow) {
  5677. w = this._label._elem.outerWidth(true);
  5678. h = this._label._elem.outerHeight(true);
  5679. }
  5680. if (this.name == 'xaxis') {
  5681. dim = dim + h;
  5682. this._elem.css({'height':dim+'px', left:'0px', bottom:'0px'});
  5683. }
  5684. else if (this.name == 'x2axis') {
  5685. dim = dim + h;
  5686. this._elem.css({'height':dim+'px', left:'0px', top:'0px'});
  5687. }
  5688. else if (this.name == 'yaxis') {
  5689. dim = dim + w;
  5690. this._elem.css({'width':dim+'px', left:'0px', top:'0px'});
  5691. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  5692. this._label._elem.css('width', w+'px');
  5693. }
  5694. }
  5695. else {
  5696. dim = dim + w;
  5697. this._elem.css({'width':dim+'px', right:'0px', top:'0px'});
  5698. if (lshow && this._label.constructor == $.jqplot.AxisLabelRenderer) {
  5699. this._label._elem.css('width', w+'px');
  5700. }
  5701. }
  5702. }
  5703. };
  5704. // called with scope of axis
  5705. $.jqplot.LinearAxisRenderer.prototype.createTicks = function(plot) {
  5706. // we're are operating on an axis here
  5707. var ticks = this._ticks;
  5708. var userTicks = this.ticks;
  5709. var name = this.name;
  5710. // databounds were set on axis initialization.
  5711. var db = this._dataBounds;
  5712. var dim = (this.name.charAt(0) === 'x') ? this._plotDimensions.width : this._plotDimensions.height;
  5713. var interval;
  5714. var min, max;
  5715. var pos1, pos2;
  5716. var tt, i;
  5717. // get a copy of user's settings for min/max.
  5718. var userMin = this.min;
  5719. var userMax = this.max;
  5720. var userNT = this.numberTicks;
  5721. var userTI = this.tickInterval;
  5722. var threshold = 30;
  5723. this._scalefact = (Math.max(dim, threshold+1) - threshold)/300.0;
  5724. // if we already have ticks, use them.
  5725. // ticks must be in order of increasing value.
  5726. if (userTicks.length) {
  5727. // ticks could be 1D or 2D array of [val, val, ,,,] or [[val, label], [val, label], ...] or mixed
  5728. for (i=0; i<userTicks.length; i++){
  5729. var ut = userTicks[i];
  5730. var t = new this.tickRenderer(this.tickOptions);
  5731. if ($.isArray(ut)) {
  5732. t.value = ut[0];
  5733. if (this.breakPoints) {
  5734. if (ut[0] == this.breakPoints[0]) {
  5735. t.label = this.breakTickLabel;
  5736. t._breakTick = true;
  5737. t.showGridline = false;
  5738. t.showMark = false;
  5739. }
  5740. else if (ut[0] > this.breakPoints[0] && ut[0] <= this.breakPoints[1]) {
  5741. t.show = false;
  5742. t.showGridline = false;
  5743. t.label = ut[1];
  5744. }
  5745. else {
  5746. t.label = ut[1];
  5747. }
  5748. }
  5749. else {
  5750. t.label = ut[1];
  5751. }
  5752. t.setTick(ut[0], this.name);
  5753. this._ticks.push(t);
  5754. }
  5755. else if ($.isPlainObject(ut)) {
  5756. $.extend(true, t, ut);
  5757. t.axis = this.name;
  5758. this._ticks.push(t);
  5759. }
  5760. else {
  5761. t.value = ut;
  5762. if (this.breakPoints) {
  5763. if (ut == this.breakPoints[0]) {
  5764. t.label = this.breakTickLabel;
  5765. t._breakTick = true;
  5766. t.showGridline = false;
  5767. t.showMark = false;
  5768. }
  5769. else if (ut > this.breakPoints[0] && ut <= this.breakPoints[1]) {
  5770. t.show = false;
  5771. t.showGridline = false;
  5772. }
  5773. }
  5774. t.setTick(ut, this.name);
  5775. this._ticks.push(t);
  5776. }
  5777. }
  5778. this.numberTicks = userTicks.length;
  5779. this.min = this._ticks[0].value;
  5780. this.max = this._ticks[this.numberTicks-1].value;
  5781. this.tickInterval = (this.max - this.min) / (this.numberTicks - 1);
  5782. }
  5783. // we don't have any ticks yet, let's make some!
  5784. else {
  5785. if (name == 'xaxis' || name == 'x2axis') {
  5786. dim = this._plotDimensions.width;
  5787. }
  5788. else {
  5789. dim = this._plotDimensions.height;
  5790. }
  5791. var _numberTicks = this.numberTicks;
  5792. // if aligning this axis, use number of ticks from previous axis.
  5793. // Do I need to reset somehow if alignTicks is changed and then graph is replotted??
  5794. if (this.alignTicks) {
  5795. if (this.name === 'x2axis' && plot.axes.xaxis.show) {
  5796. _numberTicks = plot.axes.xaxis.numberTicks;
  5797. }
  5798. else if (this.name.charAt(0) === 'y' && this.name !== 'yaxis' && this.name !== 'yMidAxis' && plot.axes.yaxis.show) {
  5799. _numberTicks = plot.axes.yaxis.numberTicks;
  5800. }
  5801. }
  5802. min = ((this.min != null) ? this.min : db.min);
  5803. max = ((this.max != null) ? this.max : db.max);
  5804. var range = max - min;
  5805. var rmin, rmax;
  5806. var temp;
  5807. if (this.tickOptions == null || !this.tickOptions.formatString) {
  5808. this._overrideFormatString = true;
  5809. }
  5810. // Doing complete autoscaling
  5811. if (this.min == null || this.max == null && this.tickInterval == null && !this.autoscale) {
  5812. // Check if user must have tick at 0 or 100 and ensure they are in range.
  5813. // The autoscaling algorithm will always place ticks at 0 and 100 if they are in range.
  5814. if (this.forceTickAt0) {
  5815. if (min > 0) {
  5816. min = 0;
  5817. }
  5818. if (max < 0) {
  5819. max = 0;
  5820. }
  5821. }
  5822. if (this.forceTickAt100) {
  5823. if (min > 100) {
  5824. min = 100;
  5825. }
  5826. if (max < 100) {
  5827. max = 100;
  5828. }
  5829. }
  5830. var keepMin = false,
  5831. keepMax = false;
  5832. if (this.min != null) {
  5833. keepMin = true;
  5834. }
  5835. else if (this.max != null) {
  5836. keepMax = true;
  5837. }
  5838. // var threshold = 30;
  5839. // var tdim = Math.max(dim, threshold+1);
  5840. // this._scalefact = (tdim-threshold)/300.0;
  5841. var ret = $.jqplot.LinearTickGenerator(min, max, this._scalefact, _numberTicks, keepMin, keepMax);
  5842. // calculate a padded max and min, points should be less than these
  5843. // so that they aren't too close to the edges of the plot.
  5844. // User can adjust how much padding is allowed with pad, padMin and PadMax options.
  5845. // If min or max is set, don't pad that end of axis.
  5846. var tumin = (this.min != null) ? min : min + range*(this.padMin - 1);
  5847. var tumax = (this.max != null) ? max : max - range*(this.padMax - 1);
  5848. // if they're equal, we shouldn't have to do anything, right?
  5849. // if (min <=tumin || max >= tumax) {
  5850. if (min <tumin || max > tumax) {
  5851. tumin = (this.min != null) ? min : min - range*(this.padMin - 1);
  5852. tumax = (this.max != null) ? max : max + range*(this.padMax - 1);
  5853. ret = $.jqplot.LinearTickGenerator(tumin, tumax, this._scalefact, _numberTicks, keepMin, keepMax);
  5854. }
  5855. this.min = ret[0];
  5856. this.max = ret[1];
  5857. // if numberTicks specified, it should return the same.
  5858. this.numberTicks = ret[2];
  5859. this._autoFormatString = ret[3];
  5860. this.tickInterval = ret[4];
  5861. }
  5862. // User has specified some axis scale related option, can use auto algorithm
  5863. else {
  5864. // if min and max are same, space them out a bit
  5865. if (min == max) {
  5866. var adj = 0.05;
  5867. if (min > 0) {
  5868. adj = Math.max(Math.log(min)/Math.LN10, 0.05);
  5869. }
  5870. min -= adj;
  5871. max += adj;
  5872. }
  5873. // autoscale. Can't autoscale if min or max is supplied.
  5874. // Will use numberTicks and tickInterval if supplied. Ticks
  5875. // across multiple axes may not line up depending on how
  5876. // bars are to be plotted.
  5877. if (this.autoscale && this.min == null && this.max == null) {
  5878. var rrange, ti, margin;
  5879. var forceMinZero = false;
  5880. var forceZeroLine = false;
  5881. var intervals = {min:null, max:null, average:null, stddev:null};
  5882. // if any series are bars, or if any are fill to zero, and if this
  5883. // is the axis to fill toward, check to see if we can start axis at zero.
  5884. for (var i=0; i<this._series.length; i++) {
  5885. var s = this._series[i];
  5886. var faname = (s.fillAxis == 'x') ? s._xaxis.name : s._yaxis.name;
  5887. // check to see if this is the fill axis
  5888. if (this.name == faname) {
  5889. var vals = s._plotValues[s.fillAxis];
  5890. var vmin = vals[0];
  5891. var vmax = vals[0];
  5892. for (var j=1; j<vals.length; j++) {
  5893. if (vals[j] < vmin) {
  5894. vmin = vals[j];
  5895. }
  5896. else if (vals[j] > vmax) {
  5897. vmax = vals[j];
  5898. }
  5899. }
  5900. var dp = (vmax - vmin) / vmax;
  5901. // is this sries a bar?
  5902. if (s.renderer.constructor == $.jqplot.BarRenderer) {
  5903. // if no negative values and could also check range.
  5904. if (vmin >= 0 && (s.fillToZero || dp > 0.1)) {
  5905. forceMinZero = true;
  5906. }
  5907. else {
  5908. forceMinZero = false;
  5909. if (s.fill && s.fillToZero && vmin < 0 && vmax > 0) {
  5910. forceZeroLine = true;
  5911. }
  5912. else {
  5913. forceZeroLine = false;
  5914. }
  5915. }
  5916. }
  5917. // if not a bar and filling, use appropriate method.
  5918. else if (s.fill) {
  5919. if (vmin >= 0 && (s.fillToZero || dp > 0.1)) {
  5920. forceMinZero = true;
  5921. }
  5922. else if (vmin < 0 && vmax > 0 && s.fillToZero) {
  5923. forceMinZero = false;
  5924. forceZeroLine = true;
  5925. }
  5926. else {
  5927. forceMinZero = false;
  5928. forceZeroLine = false;
  5929. }
  5930. }
  5931. // if not a bar and not filling, only change existing state
  5932. // if it doesn't make sense
  5933. else if (vmin < 0) {
  5934. forceMinZero = false;
  5935. }
  5936. }
  5937. }
  5938. // check if we need make axis min at 0.
  5939. if (forceMinZero) {
  5940. // compute number of ticks
  5941. this.numberTicks = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
  5942. this.min = 0;
  5943. userMin = 0;
  5944. // what order is this range?
  5945. // what tick interval does that give us?
  5946. ti = max/(this.numberTicks-1);
  5947. temp = Math.pow(10, Math.abs(Math.floor(Math.log(ti)/Math.LN10)));
  5948. if (ti/temp == parseInt(ti/temp, 10)) {
  5949. ti += temp;
  5950. }
  5951. this.tickInterval = Math.ceil(ti/temp) * temp;
  5952. this.max = this.tickInterval * (this.numberTicks - 1);
  5953. }
  5954. // check if we need to make sure there is a tick at 0.
  5955. else if (forceZeroLine) {
  5956. // compute number of ticks
  5957. this.numberTicks = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
  5958. var ntmin = Math.ceil(Math.abs(min)/range*(this.numberTicks-1));
  5959. var ntmax = this.numberTicks - 1 - ntmin;
  5960. ti = Math.max(Math.abs(min/ntmin), Math.abs(max/ntmax));
  5961. temp = Math.pow(10, Math.abs(Math.floor(Math.log(ti)/Math.LN10)));
  5962. this.tickInterval = Math.ceil(ti/temp) * temp;
  5963. this.max = this.tickInterval * ntmax;
  5964. this.min = -this.tickInterval * ntmin;
  5965. }
  5966. // if nothing else, do autoscaling which will try to line up ticks across axes.
  5967. else {
  5968. if (this.numberTicks == null){
  5969. if (this.tickInterval) {
  5970. this.numberTicks = 3 + Math.ceil(range / this.tickInterval);
  5971. }
  5972. else {
  5973. this.numberTicks = 2 + Math.ceil((dim-(this.tickSpacing-1))/this.tickSpacing);
  5974. }
  5975. }
  5976. if (this.tickInterval == null) {
  5977. // get a tick interval
  5978. ti = range/(this.numberTicks - 1);
  5979. if (ti < 1) {
  5980. temp = Math.pow(10, Math.abs(Math.floor(Math.log(ti)/Math.LN10)));
  5981. }
  5982. else {
  5983. temp = 1;
  5984. }
  5985. this.tickInterval = Math.ceil(ti*temp*this.pad)/temp;
  5986. }
  5987. else {
  5988. temp = 1 / this.tickInterval;
  5989. }
  5990. // try to compute a nicer, more even tick interval
  5991. // temp = Math.pow(10, Math.floor(Math.log(ti)/Math.LN10));
  5992. // this.tickInterval = Math.ceil(ti/temp) * temp;
  5993. rrange = this.tickInterval * (this.numberTicks - 1);
  5994. margin = (rrange - range)/2;
  5995. if (this.min == null) {
  5996. this.min = Math.floor(temp*(min-margin))/temp;
  5997. }
  5998. if (this.max == null) {
  5999. this.max = this.min + rrange;
  6000. }
  6001. }
  6002. // Compute a somewhat decent format string if it is needed.
  6003. // get precision of interval and determine a format string.
  6004. var sf = $.jqplot.getSignificantFigures(this.tickInterval);
  6005. var fstr;
  6006. // if we have only a whole number, use integer formatting
  6007. if (sf.digitsLeft >= sf.significantDigits) {
  6008. fstr = '%d';
  6009. }
  6010. else {
  6011. var temp = Math.max(0, 5 - sf.digitsLeft);
  6012. temp = Math.min(temp, sf.digitsRight);
  6013. fstr = '%.'+ temp + 'f';
  6014. }
  6015. this._autoFormatString = fstr;
  6016. }
  6017. // Use the default algorithm which pads each axis to make the chart
  6018. // centered nicely on the grid.
  6019. else {
  6020. rmin = (this.min != null) ? this.min : min - range*(this.padMin - 1);
  6021. rmax = (this.max != null) ? this.max : max + range*(this.padMax - 1);
  6022. range = rmax - rmin;
  6023. if (this.numberTicks == null){
  6024. // if tickInterval is specified by user, we will ignore computed maximum.
  6025. // max will be equal or greater to fit even # of ticks.
  6026. if (this.tickInterval != null) {
  6027. this.numberTicks = Math.ceil((rmax - rmin)/this.tickInterval)+1;
  6028. }
  6029. else if (dim > 100) {
  6030. this.numberTicks = parseInt(3+(dim-100)/75, 10);
  6031. }
  6032. else {
  6033. this.numberTicks = 2;
  6034. }
  6035. }
  6036. if (this.tickInterval == null) {
  6037. this.tickInterval = range / (this.numberTicks-1);
  6038. }
  6039. if (this.max == null) {
  6040. rmax = rmin + this.tickInterval*(this.numberTicks - 1);
  6041. }
  6042. if (this.min == null) {
  6043. rmin = rmax - this.tickInterval*(this.numberTicks - 1);
  6044. }
  6045. // get precision of interval and determine a format string.
  6046. var sf = $.jqplot.getSignificantFigures(this.tickInterval);
  6047. var fstr;
  6048. // if we have only a whole number, use integer formatting
  6049. if (sf.digitsLeft >= sf.significantDigits) {
  6050. fstr = '%d';
  6051. }
  6052. else {
  6053. var temp = Math.max(0, 5 - sf.digitsLeft);
  6054. temp = Math.min(temp, sf.digitsRight);
  6055. fstr = '%.'+ temp + 'f';
  6056. }
  6057. this._autoFormatString = fstr;
  6058. this.min = rmin;
  6059. this.max = rmax;
  6060. }
  6061. if (this.renderer.constructor == $.jqplot.LinearAxisRenderer && this._autoFormatString == '') {
  6062. // fix for misleading tick display with small range and low precision.
  6063. range = this.max - this.min;
  6064. // figure out precision
  6065. var temptick = new this.tickRenderer(this.tickOptions);
  6066. // use the tick formatString or, the default.
  6067. var fs = temptick.formatString || $.jqplot.config.defaultTickFormatString;
  6068. var fs = fs.match($.jqplot.sprintf.regex)[0];
  6069. var precision = 0;
  6070. if (fs) {
  6071. if (fs.search(/[fFeEgGpP]/) > -1) {
  6072. var m = fs.match(/\%\.(\d{0,})?[eEfFgGpP]/);
  6073. if (m) {
  6074. precision = parseInt(m[1], 10);
  6075. }
  6076. else {
  6077. precision = 6;
  6078. }
  6079. }
  6080. else if (fs.search(/[di]/) > -1) {
  6081. precision = 0;
  6082. }
  6083. // fact will be <= 1;
  6084. var fact = Math.pow(10, -precision);
  6085. if (this.tickInterval < fact) {
  6086. // need to correct underrange
  6087. if (userNT == null && userTI == null) {
  6088. this.tickInterval = fact;
  6089. if (userMax == null && userMin == null) {
  6090. // this.min = Math.floor((this._dataBounds.min - this.tickInterval)/fact) * fact;
  6091. this.min = Math.floor(this._dataBounds.min/fact) * fact;
  6092. if (this.min == this._dataBounds.min) {
  6093. this.min = this._dataBounds.min - this.tickInterval;
  6094. }
  6095. // this.max = Math.ceil((this._dataBounds.max + this.tickInterval)/fact) * fact;
  6096. this.max = Math.ceil(this._dataBounds.max/fact) * fact;
  6097. if (this.max == this._dataBounds.max) {
  6098. this.max = this._dataBounds.max + this.tickInterval;
  6099. }
  6100. var n = (this.max - this.min)/this.tickInterval;
  6101. n = n.toFixed(11);
  6102. n = Math.ceil(n);
  6103. this.numberTicks = n + 1;
  6104. }
  6105. else if (userMax == null) {
  6106. // add one tick for top of range.
  6107. var n = (this._dataBounds.max - this.min) / this.tickInterval;
  6108. n = n.toFixed(11);
  6109. this.numberTicks = Math.ceil(n) + 2;
  6110. this.max = this.min + this.tickInterval * (this.numberTicks-1);
  6111. }
  6112. else if (userMin == null) {
  6113. // add one tick for bottom of range.
  6114. var n = (this.max - this._dataBounds.min) / this.tickInterval;
  6115. n = n.toFixed(11);
  6116. this.numberTicks = Math.ceil(n) + 2;
  6117. this.min = this.max - this.tickInterval * (this.numberTicks-1);
  6118. }
  6119. else {
  6120. // calculate a number of ticks so max is within axis scale
  6121. this.numberTicks = Math.ceil((userMax - userMin)/this.tickInterval) + 1;
  6122. // if user's min and max don't fit evenly in ticks, adjust.
  6123. // This takes care of cases such as user min set to 0, max set to 3.5 but tick
  6124. // format string set to %d (integer ticks)
  6125. this.min = Math.floor(userMin*Math.pow(10, precision))/Math.pow(10, precision);
  6126. this.max = Math.ceil(userMax*Math.pow(10, precision))/Math.pow(10, precision);
  6127. // this.max = this.min + this.tickInterval*(this.numberTicks-1);
  6128. this.numberTicks = Math.ceil((this.max - this.min)/this.tickInterval) + 1;
  6129. }
  6130. }
  6131. }
  6132. }
  6133. }
  6134. }
  6135. if (this._overrideFormatString && this._autoFormatString != '') {
  6136. this.tickOptions = this.tickOptions || {};
  6137. this.tickOptions.formatString = this._autoFormatString;
  6138. }
  6139. var t, to;
  6140. for (var i=0; i<this.numberTicks; i++){
  6141. tt = this.min + i * this.tickInterval;
  6142. t = new this.tickRenderer(this.tickOptions);
  6143. // var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
  6144. t.setTick(tt, this.name);
  6145. this._ticks.push(t);
  6146. if (i < this.numberTicks - 1) {
  6147. for (var j=0; j<this.minorTicks; j++) {
  6148. tt += this.tickInterval/(this.minorTicks+1);
  6149. to = $.extend(true, {}, this.tickOptions, {name:this.name, value:tt, label:'', isMinorTick:true});
  6150. t = new this.tickRenderer(to);
  6151. this._ticks.push(t);
  6152. }
  6153. }
  6154. t = null;
  6155. }
  6156. }
  6157. if (this.tickInset) {
  6158. this.min = this.min - this.tickInset * this.tickInterval;
  6159. this.max = this.max + this.tickInset * this.tickInterval;
  6160. }
  6161. ticks = null;
  6162. };
  6163. // Used to reset just the values of the ticks and then repack, which will
  6164. // recalculate the positioning functions. It is assuemd that the
  6165. // number of ticks is the same and the values of the new array are at the
  6166. // proper interval.
  6167. // This method needs to be called with the scope of an axis object, like:
  6168. //
  6169. // > plot.axes.yaxis.renderer.resetTickValues.call(plot.axes.yaxis, yarr);
  6170. //
  6171. $.jqplot.LinearAxisRenderer.prototype.resetTickValues = function(opts) {
  6172. if ($.isArray(opts) && opts.length == this._ticks.length) {
  6173. var t;
  6174. for (var i=0; i<opts.length; i++) {
  6175. t = this._ticks[i];
  6176. t.value = opts[i];
  6177. t.label = t.formatter(t.formatString, opts[i]);
  6178. t.label = t.prefix + t.label;
  6179. t._elem.html(t.label);
  6180. }
  6181. t = null;
  6182. this.min = $.jqplot.arrayMin(opts);
  6183. this.max = $.jqplot.arrayMax(opts);
  6184. this.pack();
  6185. }
  6186. // Not implemented yet.
  6187. // else if ($.isPlainObject(opts)) {
  6188. //
  6189. // }
  6190. };
  6191. // called with scope of axis
  6192. $.jqplot.LinearAxisRenderer.prototype.pack = function(pos, offsets) {
  6193. // Add defaults for repacking from resetTickValues function.
  6194. pos = pos || {};
  6195. offsets = offsets || this._offsets;
  6196. var ticks = this._ticks;
  6197. var max = this.max;
  6198. var min = this.min;
  6199. var offmax = offsets.max;
  6200. var offmin = offsets.min;
  6201. var lshow = (this._label == null) ? false : this._label.show;
  6202. for (var p in pos) {
  6203. this._elem.css(p, pos[p]);
  6204. }
  6205. this._offsets = offsets;
  6206. // pixellength will be + for x axes and - for y axes becasue pixels always measured from top left.
  6207. var pixellength = offmax - offmin;
  6208. var unitlength = max - min;
  6209. // point to unit and unit to point conversions references to Plot DOM element top left corner.
  6210. if (this.breakPoints) {
  6211. unitlength = unitlength - this.breakPoints[1] + this.breakPoints[0];
  6212. this.p2u = function(p){
  6213. return (p - offmin) * unitlength / pixellength + min;
  6214. };
  6215. this.u2p = function(u){
  6216. if (u > this.breakPoints[0] && u < this.breakPoints[1]){
  6217. u = this.breakPoints[0];
  6218. }
  6219. if (u <= this.breakPoints[0]) {
  6220. return (u - min) * pixellength / unitlength + offmin;
  6221. }
  6222. else {
  6223. return (u - this.breakPoints[1] + this.breakPoints[0] - min) * pixellength / unitlength + offmin;
  6224. }
  6225. };
  6226. if (this.name.charAt(0) == 'x'){
  6227. this.series_u2p = function(u){
  6228. if (u > this.breakPoints[0] && u < this.breakPoints[1]){
  6229. u = this.breakPoints[0];
  6230. }
  6231. if (u <= this.breakPoints[0]) {
  6232. return (u - min) * pixellength / unitlength;
  6233. }
  6234. else {
  6235. return (u - this.breakPoints[1] + this.breakPoints[0] - min) * pixellength / unitlength;
  6236. }
  6237. };
  6238. this.series_p2u = function(p){
  6239. return p * unitlength / pixellength + min;
  6240. };
  6241. }
  6242. else {
  6243. this.series_u2p = function(u){
  6244. if (u > this.breakPoints[0] && u < this.breakPoints[1]){
  6245. u = this.breakPoints[0];
  6246. }
  6247. if (u >= this.breakPoints[1]) {
  6248. return (u - max) * pixellength / unitlength;
  6249. }
  6250. else {
  6251. return (u + this.breakPoints[1] - this.breakPoints[0] - max) * pixellength / unitlength;
  6252. }
  6253. };
  6254. this.series_p2u = function(p){
  6255. return p * unitlength / pixellength + max;
  6256. };
  6257. }
  6258. }
  6259. else {
  6260. this.p2u = function(p){
  6261. return (p - offmin) * unitlength / pixellength + min;
  6262. };
  6263. this.u2p = function(u){
  6264. return (u - min) * pixellength / unitlength + offmin;
  6265. };
  6266. if (this.name == 'xaxis' || this.name == 'x2axis'){
  6267. this.series_u2p = function(u){
  6268. return (u - min) * pixellength / unitlength;
  6269. };
  6270. this.series_p2u = function(p){
  6271. return p * unitlength / pixellength + min;
  6272. };
  6273. }
  6274. else {
  6275. this.series_u2p = function(u){
  6276. return (u - max) * pixellength / unitlength;
  6277. };
  6278. this.series_p2u = function(p){
  6279. return p * unitlength / pixellength + max;
  6280. };
  6281. }
  6282. }
  6283. if (this.show) {
  6284. if (this.name == 'xaxis' || this.name == 'x2axis') {
  6285. for (var i=0; i<ticks.length; i++) {
  6286. var t = ticks[i];
  6287. if (t.show && t.showLabel) {
  6288. var shim;
  6289. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  6290. // will need to adjust auto positioning based on which axis this is.
  6291. var temp = (this.name == 'xaxis') ? 1 : -1;
  6292. switch (t.labelPosition) {
  6293. case 'auto':
  6294. // position at end
  6295. if (temp * t.angle < 0) {
  6296. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  6297. }
  6298. // position at start
  6299. else {
  6300. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  6301. }
  6302. break;
  6303. case 'end':
  6304. shim = -t.getWidth() + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  6305. break;
  6306. case 'start':
  6307. shim = -t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  6308. break;
  6309. case 'middle':
  6310. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  6311. break;
  6312. default:
  6313. shim = -t.getWidth()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  6314. break;
  6315. }
  6316. }
  6317. else {
  6318. shim = -t.getWidth()/2;
  6319. }
  6320. var val = this.u2p(t.value) + shim + 'px';
  6321. t._elem.css('left', val);
  6322. t.pack();
  6323. }
  6324. }
  6325. if (lshow) {
  6326. var w = this._label._elem.outerWidth(true);
  6327. this._label._elem.css('left', offmin + pixellength/2 - w/2 + 'px');
  6328. if (this.name == 'xaxis') {
  6329. this._label._elem.css('bottom', '0px');
  6330. }
  6331. else {
  6332. this._label._elem.css('top', '0px');
  6333. }
  6334. this._label.pack();
  6335. }
  6336. }
  6337. else {
  6338. for (var i=0; i<ticks.length; i++) {
  6339. var t = ticks[i];
  6340. if (t.show && t.showLabel) {
  6341. var shim;
  6342. if (t.constructor == $.jqplot.CanvasAxisTickRenderer && t.angle) {
  6343. // will need to adjust auto positioning based on which axis this is.
  6344. var temp = (this.name == 'yaxis') ? 1 : -1;
  6345. switch (t.labelPosition) {
  6346. case 'auto':
  6347. // position at end
  6348. case 'end':
  6349. if (temp * t.angle < 0) {
  6350. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  6351. }
  6352. else {
  6353. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  6354. }
  6355. break;
  6356. case 'start':
  6357. if (t.angle > 0) {
  6358. shim = -t._textRenderer.height * Math.cos(-t._textRenderer.angle) / 2;
  6359. }
  6360. else {
  6361. shim = -t.getHeight() + t._textRenderer.height * Math.cos(t._textRenderer.angle) / 2;
  6362. }
  6363. break;
  6364. case 'middle':
  6365. // if (t.angle > 0) {
  6366. // shim = -t.getHeight()/2 + t._textRenderer.height * Math.sin(-t._textRenderer.angle) / 2;
  6367. // }
  6368. // else {
  6369. // shim = -t.getHeight()/2 - t._textRenderer.height * Math.sin(t._textRenderer.angle) / 2;
  6370. // }
  6371. shim = -t.getHeight()/2;
  6372. break;
  6373. default:
  6374. shim = -t.getHeight()/2;
  6375. break;
  6376. }
  6377. }
  6378. else {
  6379. shim = -t.getHeight()/2;
  6380. }
  6381. var val = this.u2p(t.value) + shim + 'px';
  6382. t._elem.css('top', val);
  6383. t.pack();
  6384. }
  6385. }
  6386. if (lshow) {
  6387. var h = this._label._elem.outerHeight(true);
  6388. this._label._elem.css('top', offmax - pixellength/2 - h/2 + 'px');
  6389. if (this.name == 'yaxis') {
  6390. this._label._elem.css('left', '0px');
  6391. }
  6392. else {
  6393. this._label._elem.css('right', '0px');
  6394. }
  6395. this._label.pack();
  6396. }
  6397. }
  6398. }
  6399. ticks = null;
  6400. };
  6401. /**
  6402. * The following code was generaously given to me a while back by Scott Prahl.
  6403. * He did a good job at computing axes min, max and number of ticks for the
  6404. * case where the user has not set any scale related parameters (tickInterval,
  6405. * numberTicks, min or max). I had ignored this use case for a long time,
  6406. * focusing on the more difficult case where user has set some option controlling
  6407. * tick generation. Anyway, about time I got this into jqPlot.
  6408. * Thanks Scott!!
  6409. */
  6410. /**
  6411. * Copyright (c) 2010 Scott Prahl
  6412. * The next three routines are currently available for use in all personal
  6413. * or commercial projects under both the MIT and GPL version 2.0 licenses.
  6414. * This means that you can choose the license that best suits your project
  6415. * and use it accordingly.
  6416. */
  6417. // A good format string depends on the interval. If the interval is greater
  6418. // than 1 then there is no need to show any decimal digits. If it is < 1.0, then
  6419. // use the magnitude of the interval to determine the number of digits to show.
  6420. function bestFormatString (interval)
  6421. {
  6422. var fstr;
  6423. interval = Math.abs(interval);
  6424. if (interval >= 10) {
  6425. fstr = '%d';
  6426. }
  6427. else if (interval > 1) {
  6428. if (interval === parseInt(interval, 10)) {
  6429. fstr = '%d';
  6430. }
  6431. else {
  6432. fstr = '%.1f';
  6433. }
  6434. }
  6435. else {
  6436. var expv = -Math.floor(Math.log(interval)/Math.LN10);
  6437. fstr = '%.' + expv + 'f';
  6438. }
  6439. return fstr;
  6440. }
  6441. var _factors = [0.1, 0.2, 0.3, 0.4, 0.5, 0.8, 1, 2, 3, 4, 5];
  6442. var _getLowerFactor = function(f) {
  6443. var i = _factors.indexOf(f);
  6444. if (i > 0) {
  6445. return _factors[i-1];
  6446. }
  6447. else {
  6448. return _factors[_factors.length - 1] / 100;
  6449. }
  6450. };
  6451. var _getHigherFactor = function(f) {
  6452. var i = _factors.indexOf(f);
  6453. if (i < _factors.length-1) {
  6454. return _factors[i+1];
  6455. }
  6456. else {
  6457. return _factors[0] * 100;
  6458. }
  6459. };
  6460. // Given a fixed minimum and maximum and a target number ot ticks
  6461. // figure out the best interval and
  6462. // return min, max, number ticks, format string and tick interval
  6463. function bestConstrainedInterval(min, max, nttarget) {
  6464. // run through possible number to ticks and see which interval is best
  6465. var low = Math.floor(nttarget/2);
  6466. var hi = Math.ceil(nttarget*1.5);
  6467. var badness = Number.MAX_VALUE;
  6468. var r = (max - min);
  6469. var temp;
  6470. var sd;
  6471. var bestNT;
  6472. var gsf = $.jqplot.getSignificantFigures;
  6473. var fsd;
  6474. var fs;
  6475. var currentNT;
  6476. var bestPrec;
  6477. for (var i=0, l=hi-low+1; i<l; i++) {
  6478. currentNT = low + i;
  6479. temp = r/(currentNT-1);
  6480. sd = gsf(temp);
  6481. temp = Math.abs(nttarget - currentNT) + sd.digitsRight;
  6482. if (temp < badness) {
  6483. badness = temp;
  6484. bestNT = currentNT;
  6485. bestPrec = sd.digitsRight;
  6486. }
  6487. else if (temp === badness) {
  6488. // let nicer ticks trump number ot ticks
  6489. if (sd.digitsRight < bestPrec) {
  6490. bestNT = currentNT;
  6491. bestPrec = sd.digitsRight;
  6492. }
  6493. }
  6494. }
  6495. fsd = Math.max(bestPrec, Math.max(gsf(min).digitsRight, gsf(max).digitsRight));
  6496. if (fsd === 0) {
  6497. fs = '%d';
  6498. }
  6499. else {
  6500. fs = '%.' + fsd + 'f';
  6501. }
  6502. temp = r / (bestNT - 1);
  6503. // min, max, number ticks, format string, tick interval
  6504. return [min, max, bestNT, fs, temp];
  6505. }
  6506. // This will return an interval of form 2 * 10^n, 5 * 10^n or 10 * 10^n
  6507. // it is based soley on the range and number of ticks. So if user specifies
  6508. // number of ticks, use this.
  6509. function bestInterval(range, numberTicks) {
  6510. numberTicks = numberTicks || 7;
  6511. var minimum = range / (numberTicks - 1);
  6512. var magnitude = Math.pow(10, Math.floor(Math.log(minimum) / Math.LN10));
  6513. var residual = minimum / magnitude;
  6514. var interval;
  6515. // "nicest" ranges are 1, 2, 5 or powers of these.
  6516. // for magnitudes below 1, only allow these.
  6517. if (magnitude < 1) {
  6518. if (residual > 5) {
  6519. interval = 10 * magnitude;
  6520. }
  6521. else if (residual > 2) {
  6522. interval = 5 * magnitude;
  6523. }
  6524. else if (residual > 1) {
  6525. interval = 2 * magnitude;
  6526. }
  6527. else {
  6528. interval = magnitude;
  6529. }
  6530. }
  6531. // for large ranges (whole integers), allow intervals like 3, 4 or powers of these.
  6532. // this helps a lot with poor choices for number of ticks.
  6533. else {
  6534. if (residual > 5) {
  6535. interval = 10 * magnitude;
  6536. }
  6537. else if (residual > 4) {
  6538. interval = 5 * magnitude;
  6539. }
  6540. else if (residual > 3) {
  6541. interval = 4 * magnitude;
  6542. }
  6543. else if (residual > 2) {
  6544. interval = 3 * magnitude;
  6545. }
  6546. else if (residual > 1) {
  6547. interval = 2 * magnitude;
  6548. }
  6549. else {
  6550. interval = magnitude;
  6551. }
  6552. }
  6553. return interval;
  6554. }
  6555. // This will return an interval of form 2 * 10^n, 5 * 10^n or 10 * 10^n
  6556. // it is based soley on the range of data, number of ticks must be computed later.
  6557. function bestLinearInterval(range, scalefact) {
  6558. scalefact = scalefact || 1;
  6559. var expv = Math.floor(Math.log(range)/Math.LN10);
  6560. var magnitude = Math.pow(10, expv);
  6561. // 0 < f < 10
  6562. var f = range / magnitude;
  6563. var fact;
  6564. // for large plots, scalefact will decrease f and increase number of ticks.
  6565. // for small plots, scalefact will increase f and decrease number of ticks.
  6566. f = f/scalefact;
  6567. // for large plots, smaller interval, more ticks.
  6568. if (f<=0.38) {
  6569. fact = 0.1;
  6570. }
  6571. else if (f<=1.6) {
  6572. fact = 0.2;
  6573. }
  6574. else if (f<=4.0) {
  6575. fact = 0.5;
  6576. }
  6577. else if (f<=8.0) {
  6578. fact = 1.0;
  6579. }
  6580. // for very small plots, larger interval, less ticks in number ticks
  6581. else if (f<=16.0) {
  6582. fact = 2;
  6583. }
  6584. else {
  6585. fact = 5;
  6586. }
  6587. return fact*magnitude;
  6588. }
  6589. function bestLinearComponents(range, scalefact) {
  6590. var expv = Math.floor(Math.log(range)/Math.LN10);
  6591. var magnitude = Math.pow(10, expv);
  6592. // 0 < f < 10
  6593. var f = range / magnitude;
  6594. var interval;
  6595. var fact;
  6596. // for large plots, scalefact will decrease f and increase number of ticks.
  6597. // for small plots, scalefact will increase f and decrease number of ticks.
  6598. f = f/scalefact;
  6599. // for large plots, smaller interval, more ticks.
  6600. if (f<=0.38) {
  6601. fact = 0.1;
  6602. }
  6603. else if (f<=1.6) {
  6604. fact = 0.2;
  6605. }
  6606. else if (f<=4.0) {
  6607. fact = 0.5;
  6608. }
  6609. else if (f<=8.0) {
  6610. fact = 1.0;
  6611. }
  6612. // for very small plots, larger interval, less ticks in number ticks
  6613. else if (f<=16.0) {
  6614. fact = 2;
  6615. }
  6616. // else if (f<=20.0) {
  6617. // fact = 3;
  6618. // }
  6619. // else if (f<=24.0) {
  6620. // fact = 4;
  6621. // }
  6622. else {
  6623. fact = 5;
  6624. }
  6625. interval = fact * magnitude;
  6626. return [interval, fact, magnitude];
  6627. }
  6628. // Given the min and max for a dataset, return suitable endpoints
  6629. // for the graphing, a good number for the number of ticks, and a
  6630. // format string so that extraneous digits are not displayed.
  6631. // returned is an array containing [min, max, nTicks, format]
  6632. $.jqplot.LinearTickGenerator = function(axis_min, axis_max, scalefact, numberTicks, keepMin, keepMax) {
  6633. // Set to preserve EITHER min OR max.
  6634. // If min is preserved, max must be free.
  6635. keepMin = (keepMin === null) ? false : keepMin;
  6636. keepMax = (keepMax === null || keepMin) ? false : keepMax;
  6637. // if endpoints are equal try to include zero otherwise include one
  6638. if (axis_min === axis_max) {
  6639. axis_max = (axis_max) ? 0 : 1;
  6640. }
  6641. scalefact = scalefact || 1.0;
  6642. // make sure range is positive
  6643. if (axis_max < axis_min) {
  6644. var a = axis_max;
  6645. axis_max = axis_min;
  6646. axis_min = a;
  6647. }
  6648. var r = [];
  6649. var ss = bestLinearInterval(axis_max - axis_min, scalefact);
  6650. var gsf = $.jqplot.getSignificantFigures;
  6651. if (numberTicks == null) {
  6652. // Figure out the axis min, max and number of ticks
  6653. // the min and max will be some multiple of the tick interval,
  6654. // 1*10^n, 2*10^n or 5*10^n. This gaurantees that, if the
  6655. // axis min is negative, 0 will be a tick.
  6656. if (!keepMin && !keepMax) {
  6657. r[0] = Math.floor(axis_min / ss) * ss; // min
  6658. r[1] = Math.ceil(axis_max / ss) * ss; // max
  6659. r[2] = Math.round((r[1]-r[0])/ss+1.0); // number of ticks
  6660. r[3] = bestFormatString(ss); // format string
  6661. r[4] = ss; // tick Interval
  6662. }
  6663. else if (keepMin) {
  6664. r[0] = axis_min; // min
  6665. r[2] = Math.ceil((axis_max - axis_min) / ss + 1.0); // number of ticks
  6666. r[1] = axis_min + (r[2] - 1) * ss; // max
  6667. var digitsMin = gsf(axis_min).digitsRight;
  6668. var digitsSS = gsf(ss).digitsRight;
  6669. if (digitsMin < digitsSS) {
  6670. r[3] = bestFormatString(ss); // format string
  6671. }
  6672. else {
  6673. r[3] = '%.' + digitsMin + 'f';
  6674. }
  6675. r[4] = ss; // tick Interval
  6676. }
  6677. else if (keepMax) {
  6678. r[1] = axis_max; // max
  6679. r[2] = Math.ceil((axis_max - axis_min) / ss + 1.0); // number of ticks
  6680. r[0] = axis_max - (r[2] - 1) * ss; // min
  6681. var digitsMax = gsf(axis_max).digitsRight;
  6682. var digitsSS = gsf(ss).digitsRight;
  6683. if (digitsMax < digitsSS) {
  6684. r[3] = bestFormatString(ss); // format string
  6685. }
  6686. else {
  6687. r[3] = '%.' + digitsMax + 'f';
  6688. }
  6689. r[4] = ss; // tick Interval
  6690. }
  6691. }
  6692. else {
  6693. var tempr = [];
  6694. // Figure out the axis min, max and number of ticks
  6695. // the min and max will be some multiple of the tick interval,
  6696. // 1*10^n, 2*10^n or 5*10^n. This gaurantees that, if the
  6697. // axis min is negative, 0 will be a tick.
  6698. tempr[0] = Math.floor(axis_min / ss) * ss; // min
  6699. tempr[1] = Math.ceil(axis_max / ss) * ss; // max
  6700. tempr[2] = Math.round((tempr[1]-tempr[0])/ss+1.0); // number of ticks
  6701. tempr[3] = bestFormatString(ss); // format string
  6702. tempr[4] = ss; // tick Interval
  6703. // first, see if we happen to get the right number of ticks
  6704. if (tempr[2] === numberTicks) {
  6705. r = tempr;
  6706. }
  6707. else {
  6708. var newti = bestInterval(tempr[1] - tempr[0], numberTicks);
  6709. r[0] = tempr[0]; // min
  6710. r[2] = numberTicks; // number of ticks
  6711. r[4] = newti; // tick interval
  6712. r[3] = bestFormatString(newti); // format string
  6713. r[1] = r[0] + (r[2] - 1) * r[4]; // max
  6714. }
  6715. }
  6716. return r;
  6717. };
  6718. $.jqplot.LinearTickGenerator.bestLinearInterval = bestLinearInterval;
  6719. $.jqplot.LinearTickGenerator.bestInterval = bestInterval;
  6720. $.jqplot.LinearTickGenerator.bestLinearComponents = bestLinearComponents;
  6721. $.jqplot.LinearTickGenerator.bestConstrainedInterval = bestConstrainedInterval;
  6722. // class: $.jqplot.MarkerRenderer
  6723. // The default jqPlot marker renderer, rendering the points on the line.
  6724. $.jqplot.MarkerRenderer = function(options){
  6725. // Group: Properties
  6726. // prop: show
  6727. // wether or not to show the marker.
  6728. this.show = true;
  6729. // prop: style
  6730. // One of diamond, circle, square, x, plus, dash, filledDiamond, filledCircle, filledSquare
  6731. this.style = 'filledCircle';
  6732. // prop: lineWidth
  6733. // size of the line for non-filled markers.
  6734. this.lineWidth = 2;
  6735. // prop: size
  6736. // Size of the marker (diameter or circle, length of edge of square, etc.)
  6737. this.size = 9.0;
  6738. // prop: color
  6739. // color of marker. Will be set to color of series by default on init.
  6740. this.color = '#666666';
  6741. // prop: shadow
  6742. // wether or not to draw a shadow on the line
  6743. this.shadow = true;
  6744. // prop: shadowAngle
  6745. // Shadow angle in degrees
  6746. this.shadowAngle = 45;
  6747. // prop: shadowOffset
  6748. // Shadow offset from line in pixels
  6749. this.shadowOffset = 1;
  6750. // prop: shadowDepth
  6751. // Number of times shadow is stroked, each stroke offset shadowOffset from the last.
  6752. this.shadowDepth = 3;
  6753. // prop: shadowAlpha
  6754. // Alpha channel transparency of shadow. 0 = transparent.
  6755. this.shadowAlpha = '0.07';
  6756. // prop: shadowRenderer
  6757. // Renderer that will draws the shadows on the marker.
  6758. this.shadowRenderer = new $.jqplot.ShadowRenderer();
  6759. // prop: shapeRenderer
  6760. // Renderer that will draw the marker.
  6761. this.shapeRenderer = new $.jqplot.ShapeRenderer();
  6762. $.extend(true, this, options);
  6763. };
  6764. $.jqplot.MarkerRenderer.prototype.init = function(options) {
  6765. $.extend(true, this, options);
  6766. var sdopt = {angle:this.shadowAngle, offset:this.shadowOffset, alpha:this.shadowAlpha, lineWidth:this.lineWidth, depth:this.shadowDepth, closePath:true};
  6767. if (this.style.indexOf('filled') != -1) {
  6768. sdopt.fill = true;
  6769. }
  6770. if (this.style.indexOf('ircle') != -1) {
  6771. sdopt.isarc = true;
  6772. sdopt.closePath = false;
  6773. }
  6774. this.shadowRenderer.init(sdopt);
  6775. var shopt = {fill:false, isarc:false, strokeStyle:this.color, fillStyle:this.color, lineWidth:this.lineWidth, closePath:true};
  6776. if (this.style.indexOf('filled') != -1) {
  6777. shopt.fill = true;
  6778. }
  6779. if (this.style.indexOf('ircle') != -1) {
  6780. shopt.isarc = true;
  6781. shopt.closePath = false;
  6782. }
  6783. this.shapeRenderer.init(shopt);
  6784. };
  6785. $.jqplot.MarkerRenderer.prototype.drawDiamond = function(x, y, ctx, fill, options) {
  6786. var stretch = 1.2;
  6787. var dx = this.size/2/stretch;
  6788. var dy = this.size/2*stretch;
  6789. var points = [[x-dx, y], [x, y+dy], [x+dx, y], [x, y-dy]];
  6790. if (this.shadow) {
  6791. this.shadowRenderer.draw(ctx, points);
  6792. }
  6793. this.shapeRenderer.draw(ctx, points, options);
  6794. };
  6795. $.jqplot.MarkerRenderer.prototype.drawPlus = function(x, y, ctx, fill, options) {
  6796. var stretch = 1.0;
  6797. var dx = this.size/2*stretch;
  6798. var dy = this.size/2*stretch;
  6799. var points1 = [[x, y-dy], [x, y+dy]];
  6800. var points2 = [[x+dx, y], [x-dx, y]];
  6801. var opts = $.extend(true, {}, this.options, {closePath:false});
  6802. if (this.shadow) {
  6803. this.shadowRenderer.draw(ctx, points1, {closePath:false});
  6804. this.shadowRenderer.draw(ctx, points2, {closePath:false});
  6805. }
  6806. this.shapeRenderer.draw(ctx, points1, opts);
  6807. this.shapeRenderer.draw(ctx, points2, opts);
  6808. };
  6809. $.jqplot.MarkerRenderer.prototype.drawX = function(x, y, ctx, fill, options) {
  6810. var stretch = 1.0;
  6811. var dx = this.size/2*stretch;
  6812. var dy = this.size/2*stretch;
  6813. var opts = $.extend(true, {}, this.options, {closePath:false});
  6814. var points1 = [[x-dx, y-dy], [x+dx, y+dy]];
  6815. var points2 = [[x-dx, y+dy], [x+dx, y-dy]];
  6816. if (this.shadow) {
  6817. this.shadowRenderer.draw(ctx, points1, {closePath:false});
  6818. this.shadowRenderer.draw(ctx, points2, {closePath:false});
  6819. }
  6820. this.shapeRenderer.draw(ctx, points1, opts);
  6821. this.shapeRenderer.draw(ctx, points2, opts);
  6822. };
  6823. $.jqplot.MarkerRenderer.prototype.drawDash = function(x, y, ctx, fill, options) {
  6824. var stretch = 1.0;
  6825. var dx = this.size/2*stretch;
  6826. var dy = this.size/2*stretch;
  6827. var points = [[x-dx, y], [x+dx, y]];
  6828. if (this.shadow) {
  6829. this.shadowRenderer.draw(ctx, points);
  6830. }
  6831. this.shapeRenderer.draw(ctx, points, options);
  6832. };
  6833. $.jqplot.MarkerRenderer.prototype.drawLine = function(p1, p2, ctx, fill, options) {
  6834. var points = [p1, p2];
  6835. if (this.shadow) {
  6836. this.shadowRenderer.draw(ctx, points);
  6837. }
  6838. this.shapeRenderer.draw(ctx, points, options);
  6839. };
  6840. $.jqplot.MarkerRenderer.prototype.drawSquare = function(x, y, ctx, fill, options) {
  6841. var stretch = 1.0;
  6842. var dx = this.size/2/stretch;
  6843. var dy = this.size/2*stretch;
  6844. var points = [[x-dx, y-dy], [x-dx, y+dy], [x+dx, y+dy], [x+dx, y-dy]];
  6845. if (this.shadow) {
  6846. this.shadowRenderer.draw(ctx, points);
  6847. }
  6848. this.shapeRenderer.draw(ctx, points, options);
  6849. };
  6850. $.jqplot.MarkerRenderer.prototype.drawCircle = function(x, y, ctx, fill, options) {
  6851. var radius = this.size/2;
  6852. var end = 2*Math.PI;
  6853. var points = [x, y, radius, 0, end, true];
  6854. if (this.shadow) {
  6855. this.shadowRenderer.draw(ctx, points);
  6856. }
  6857. this.shapeRenderer.draw(ctx, points, options);
  6858. };
  6859. $.jqplot.MarkerRenderer.prototype.draw = function(x, y, ctx, options) {
  6860. options = options || {};
  6861. // hack here b/c shape renderer uses canvas based color style options
  6862. // and marker uses css style names.
  6863. if (options.show == null || options.show != false) {
  6864. if (options.color && !options.fillStyle) {
  6865. options.fillStyle = options.color;
  6866. }
  6867. if (options.color && !options.strokeStyle) {
  6868. options.strokeStyle = options.color;
  6869. }
  6870. switch (this.style) {
  6871. case 'diamond':
  6872. this.drawDiamond(x,y,ctx, false, options);
  6873. break;
  6874. case 'filledDiamond':
  6875. this.drawDiamond(x,y,ctx, true, options);
  6876. break;
  6877. case 'circle':
  6878. this.drawCircle(x,y,ctx, false, options);
  6879. break;
  6880. case 'filledCircle':
  6881. this.drawCircle(x,y,ctx, true, options);
  6882. break;
  6883. case 'square':
  6884. this.drawSquare(x,y,ctx, false, options);
  6885. break;
  6886. case 'filledSquare':
  6887. this.drawSquare(x,y,ctx, true, options);
  6888. break;
  6889. case 'x':
  6890. this.drawX(x,y,ctx, true, options);
  6891. break;
  6892. case 'plus':
  6893. this.drawPlus(x,y,ctx, true, options);
  6894. break;
  6895. case 'dash':
  6896. this.drawDash(x,y,ctx, true, options);
  6897. break;
  6898. case 'line':
  6899. this.drawLine(x, y, ctx, false, options);
  6900. break;
  6901. default:
  6902. this.drawDiamond(x,y,ctx, false, options);
  6903. break;
  6904. }
  6905. }
  6906. };
  6907. // class: $.jqplot.shadowRenderer
  6908. // The default jqPlot shadow renderer, rendering shadows behind shapes.
  6909. $.jqplot.ShadowRenderer = function(options){
  6910. // Group: Properties
  6911. // prop: angle
  6912. // Angle of the shadow in degrees. Measured counter-clockwise from the x axis.
  6913. this.angle = 45;
  6914. // prop: offset
  6915. // Pixel offset at the given shadow angle of each shadow stroke from the last stroke.
  6916. this.offset = 1;
  6917. // prop: alpha
  6918. // alpha transparency of shadow stroke.
  6919. this.alpha = 0.07;
  6920. // prop: lineWidth
  6921. // width of the shadow line stroke.
  6922. this.lineWidth = 1.5;
  6923. // prop: lineJoin
  6924. // How line segments of the shadow are joined.
  6925. this.lineJoin = 'miter';
  6926. // prop: lineCap
  6927. // how ends of the shadow line are rendered.
  6928. this.lineCap = 'round';
  6929. // prop; closePath
  6930. // whether line path segment is closed upon itself.
  6931. this.closePath = false;
  6932. // prop: fill
  6933. // whether to fill the shape.
  6934. this.fill = false;
  6935. // prop: depth
  6936. // how many times the shadow is stroked. Each stroke will be offset by offset at angle degrees.
  6937. this.depth = 3;
  6938. this.strokeStyle = 'rgba(0,0,0,0.1)';
  6939. // prop: isarc
  6940. // wether the shadow is an arc or not.
  6941. this.isarc = false;
  6942. $.extend(true, this, options);
  6943. };
  6944. $.jqplot.ShadowRenderer.prototype.init = function(options) {
  6945. $.extend(true, this, options);
  6946. };
  6947. // function: draw
  6948. // draws an transparent black (i.e. gray) shadow.
  6949. //
  6950. // ctx - canvas drawing context
  6951. // points - array of points or [x, y, radius, start angle (rad), end angle (rad)]
  6952. $.jqplot.ShadowRenderer.prototype.draw = function(ctx, points, options) {
  6953. ctx.save();
  6954. var opts = (options != null) ? options : {};
  6955. var fill = (opts.fill != null) ? opts.fill : this.fill;
  6956. var fillRect = (opts.fillRect != null) ? opts.fillRect : this.fillRect;
  6957. var closePath = (opts.closePath != null) ? opts.closePath : this.closePath;
  6958. var offset = (opts.offset != null) ? opts.offset : this.offset;
  6959. var alpha = (opts.alpha != null) ? opts.alpha : this.alpha;
  6960. var depth = (opts.depth != null) ? opts.depth : this.depth;
  6961. var isarc = (opts.isarc != null) ? opts.isarc : this.isarc;
  6962. var linePattern = (opts.linePattern != null) ? opts.linePattern : this.linePattern;
  6963. ctx.lineWidth = (opts.lineWidth != null) ? opts.lineWidth : this.lineWidth;
  6964. ctx.lineJoin = (opts.lineJoin != null) ? opts.lineJoin : this.lineJoin;
  6965. ctx.lineCap = (opts.lineCap != null) ? opts.lineCap : this.lineCap;
  6966. ctx.strokeStyle = opts.strokeStyle || this.strokeStyle || 'rgba(0,0,0,'+alpha+')';
  6967. ctx.fillStyle = opts.fillStyle || this.fillStyle || 'rgba(0,0,0,'+alpha+')';
  6968. for (var j=0; j<depth; j++) {
  6969. var ctxPattern = $.jqplot.LinePattern(ctx, linePattern);
  6970. ctx.translate(Math.cos(this.angle*Math.PI/180)*offset, Math.sin(this.angle*Math.PI/180)*offset);
  6971. ctxPattern.beginPath();
  6972. if (isarc) {
  6973. ctx.arc(points[0], points[1], points[2], points[3], points[4], true);
  6974. }
  6975. else if (fillRect) {
  6976. if (fillRect) {
  6977. ctx.fillRect(points[0], points[1], points[2], points[3]);
  6978. }
  6979. }
  6980. else if (points && points.length){
  6981. var move = true;
  6982. for (var i=0; i<points.length; i++) {
  6983. // skip to the first non-null point and move to it.
  6984. if (points[i][0] != null && points[i][1] != null) {
  6985. if (move) {
  6986. ctxPattern.moveTo(points[i][0], points[i][1]);
  6987. move = false;
  6988. }
  6989. else {
  6990. ctxPattern.lineTo(points[i][0], points[i][1]);
  6991. }
  6992. }
  6993. else {
  6994. move = true;
  6995. }
  6996. }
  6997. }
  6998. if (closePath) {
  6999. ctxPattern.closePath();
  7000. }
  7001. if (fill) {
  7002. ctx.fill();
  7003. }
  7004. else {
  7005. ctx.stroke();
  7006. }
  7007. }
  7008. ctx.restore();
  7009. };
  7010. // class: $.jqplot.shapeRenderer
  7011. // The default jqPlot shape renderer. Given a set of points will
  7012. // plot them and either stroke a line (fill = false) or fill them (fill = true).
  7013. // If a filled shape is desired, closePath = true must also be set to close
  7014. // the shape.
  7015. $.jqplot.ShapeRenderer = function(options){
  7016. this.lineWidth = 1.5;
  7017. // prop: linePattern
  7018. // line pattern 'dashed', 'dotted', 'solid', some combination
  7019. // of '-' and '.' characters such as '.-.' or a numerical array like
  7020. // [draw, skip, draw, skip, ...] such as [1, 10] to draw a dotted line,
  7021. // [1, 10, 20, 10] to draw a dot-dash line, and so on.
  7022. this.linePattern = 'solid';
  7023. // prop: lineJoin
  7024. // How line segments of the shadow are joined.
  7025. this.lineJoin = 'miter';
  7026. // prop: lineCap
  7027. // how ends of the shadow line are rendered.
  7028. this.lineCap = 'round';
  7029. // prop; closePath
  7030. // whether line path segment is closed upon itself.
  7031. this.closePath = false;
  7032. // prop: fill
  7033. // whether to fill the shape.
  7034. this.fill = false;
  7035. // prop: isarc
  7036. // wether the shadow is an arc or not.
  7037. this.isarc = false;
  7038. // prop: fillRect
  7039. // true to draw shape as a filled rectangle.
  7040. this.fillRect = false;
  7041. // prop: strokeRect
  7042. // true to draw shape as a stroked rectangle.
  7043. this.strokeRect = false;
  7044. // prop: clearRect
  7045. // true to cear a rectangle.
  7046. this.clearRect = false;
  7047. // prop: strokeStyle
  7048. // css color spec for the stoke style
  7049. this.strokeStyle = '#999999';
  7050. // prop: fillStyle
  7051. // css color spec for the fill style.
  7052. this.fillStyle = '#999999';
  7053. $.extend(true, this, options);
  7054. };
  7055. $.jqplot.ShapeRenderer.prototype.init = function(options) {
  7056. $.extend(true, this, options);
  7057. };
  7058. // function: draw
  7059. // draws the shape.
  7060. //
  7061. // ctx - canvas drawing context
  7062. // points - array of points for shapes or
  7063. // [x, y, width, height] for rectangles or
  7064. // [x, y, radius, start angle (rad), end angle (rad)] for circles and arcs.
  7065. $.jqplot.ShapeRenderer.prototype.draw = function(ctx, points, options) {
  7066. ctx.save();
  7067. var opts = (options != null) ? options : {};
  7068. var fill = (opts.fill != null) ? opts.fill : this.fill;
  7069. var closePath = (opts.closePath != null) ? opts.closePath : this.closePath;
  7070. var fillRect = (opts.fillRect != null) ? opts.fillRect : this.fillRect;
  7071. var strokeRect = (opts.strokeRect != null) ? opts.strokeRect : this.strokeRect;
  7072. var clearRect = (opts.clearRect != null) ? opts.clearRect : this.clearRect;
  7073. var isarc = (opts.isarc != null) ? opts.isarc : this.isarc;
  7074. var linePattern = (opts.linePattern != null) ? opts.linePattern : this.linePattern;
  7075. var ctxPattern = $.jqplot.LinePattern(ctx, linePattern);
  7076. ctx.lineWidth = opts.lineWidth || this.lineWidth;
  7077. ctx.lineJoin = opts.lineJoin || this.lineJoin;
  7078. ctx.lineCap = opts.lineCap || this.lineCap;
  7079. ctx.strokeStyle = (opts.strokeStyle || opts.color) || this.strokeStyle;
  7080. ctx.fillStyle = opts.fillStyle || this.fillStyle;
  7081. ctx.beginPath();
  7082. if (isarc) {
  7083. ctx.arc(points[0], points[1], points[2], points[3], points[4], true);
  7084. if (closePath) {
  7085. ctx.closePath();
  7086. }
  7087. if (fill) {
  7088. ctx.fill();
  7089. }
  7090. else {
  7091. ctx.stroke();
  7092. }
  7093. ctx.restore();
  7094. return;
  7095. }
  7096. else if (clearRect) {
  7097. ctx.clearRect(points[0], points[1], points[2], points[3]);
  7098. ctx.restore();
  7099. return;
  7100. }
  7101. else if (fillRect || strokeRect) {
  7102. if (fillRect) {
  7103. ctx.fillRect(points[0], points[1], points[2], points[3]);
  7104. }
  7105. if (strokeRect) {
  7106. ctx.strokeRect(points[0], points[1], points[2], points[3]);
  7107. ctx.restore();
  7108. return;
  7109. }
  7110. }
  7111. else if (points && points.length){
  7112. var move = true;
  7113. for (var i=0; i<points.length; i++) {
  7114. // skip to the first non-null point and move to it.
  7115. if (points[i][0] != null && points[i][1] != null) {
  7116. if (move) {
  7117. ctxPattern.moveTo(points[i][0], points[i][1]);
  7118. move = false;
  7119. }
  7120. else {
  7121. ctxPattern.lineTo(points[i][0], points[i][1]);
  7122. }
  7123. }
  7124. else {
  7125. move = true;
  7126. }
  7127. }
  7128. if (closePath) {
  7129. ctxPattern.closePath();
  7130. }
  7131. if (fill) {
  7132. ctx.fill();
  7133. }
  7134. else {
  7135. ctx.stroke();
  7136. }
  7137. }
  7138. ctx.restore();
  7139. };
  7140. // class $.jqplot.TableLegendRenderer
  7141. // The default legend renderer for jqPlot.
  7142. $.jqplot.TableLegendRenderer = function(){
  7143. //
  7144. };
  7145. $.jqplot.TableLegendRenderer.prototype.init = function(options) {
  7146. $.extend(true, this, options);
  7147. };
  7148. $.jqplot.TableLegendRenderer.prototype.addrow = function (label, color, pad, reverse) {
  7149. var rs = (pad) ? this.rowSpacing+'px' : '0px';
  7150. var tr;
  7151. var td;
  7152. var elem;
  7153. var div0;
  7154. var div1;
  7155. elem = document.createElement('tr');
  7156. tr = $(elem);
  7157. tr.addClass('jqplot-table-legend');
  7158. elem = null;
  7159. if (reverse){
  7160. tr.prependTo(this._elem);
  7161. }
  7162. else{
  7163. tr.appendTo(this._elem);
  7164. }
  7165. if (this.showSwatches) {
  7166. td = $(document.createElement('td'));
  7167. td.addClass('jqplot-table-legend jqplot-table-legend-swatch');
  7168. td.css({textAlign: 'center', paddingTop: rs});
  7169. div0 = $(document.createElement('div'));
  7170. div0.addClass('jqplot-table-legend-swatch-outline');
  7171. div1 = $(document.createElement('div'));
  7172. div1.addClass('jqplot-table-legend-swatch');
  7173. div1.css({backgroundColor: color, borderColor: color});
  7174. tr.append(td.append(div0.append(div1)));
  7175. // $('<td class="jqplot-table-legend" style="text-align:center;padding-top:'+rs+';">'+
  7176. // '<div><div class="jqplot-table-legend-swatch" style="background-color:'+color+';border-color:'+color+';"></div>'+
  7177. // '</div></td>').appendTo(tr);
  7178. }
  7179. if (this.showLabels) {
  7180. td = $(document.createElement('td'));
  7181. td.addClass('jqplot-table-legend jqplot-table-legend-label');
  7182. td.css('paddingTop', rs);
  7183. tr.append(td);
  7184. // elem = $('<td class="jqplot-table-legend" style="padding-top:'+rs+';"></td>');
  7185. // elem.appendTo(tr);
  7186. if (this.escapeHtml) {
  7187. td.text(label);
  7188. }
  7189. else {
  7190. td.html(label);
  7191. }
  7192. }
  7193. td = null;
  7194. div0 = null;
  7195. div1 = null;
  7196. tr = null;
  7197. elem = null;
  7198. };
  7199. // called with scope of legend
  7200. $.jqplot.TableLegendRenderer.prototype.draw = function() {
  7201. if (this._elem) {
  7202. this._elem.emptyForce();
  7203. this._elem = null;
  7204. }
  7205. if (this.show) {
  7206. var series = this._series;
  7207. // make a table. one line label per row.
  7208. var elem = document.createElement('table');
  7209. this._elem = $(elem);
  7210. this._elem.addClass('jqplot-table-legend');
  7211. var ss = {position:'absolute'};
  7212. if (this.background) {
  7213. ss['background'] = this.background;
  7214. }
  7215. if (this.border) {
  7216. ss['border'] = this.border;
  7217. }
  7218. if (this.fontSize) {
  7219. ss['fontSize'] = this.fontSize;
  7220. }
  7221. if (this.fontFamily) {
  7222. ss['fontFamily'] = this.fontFamily;
  7223. }
  7224. if (this.textColor) {
  7225. ss['textColor'] = this.textColor;
  7226. }
  7227. if (this.marginTop != null) {
  7228. ss['marginTop'] = this.marginTop;
  7229. }
  7230. if (this.marginBottom != null) {
  7231. ss['marginBottom'] = this.marginBottom;
  7232. }
  7233. if (this.marginLeft != null) {
  7234. ss['marginLeft'] = this.marginLeft;
  7235. }
  7236. if (this.marginRight != null) {
  7237. ss['marginRight'] = this.marginRight;
  7238. }
  7239. var pad = false,
  7240. reverse = false,
  7241. s;
  7242. for (var i = 0; i< series.length; i++) {
  7243. s = series[i];
  7244. if (s._stack || s.renderer.constructor == $.jqplot.BezierCurveRenderer){
  7245. reverse = true;
  7246. }
  7247. if (s.show && s.showLabel) {
  7248. var lt = this.labels[i] || s.label.toString();
  7249. if (lt) {
  7250. var color = s.color;
  7251. if (reverse && i < series.length - 1){
  7252. pad = true;
  7253. }
  7254. else if (reverse && i == series.length - 1){
  7255. pad = false;
  7256. }
  7257. this.renderer.addrow.call(this, lt, color, pad, reverse);
  7258. pad = true;
  7259. }
  7260. // let plugins add more rows to legend. Used by trend line plugin.
  7261. for (var j=0; j<$.jqplot.addLegendRowHooks.length; j++) {
  7262. var item = $.jqplot.addLegendRowHooks[j].call(this, s);
  7263. if (item) {
  7264. this.renderer.addrow.call(this, item.label, item.color, pad);
  7265. pad = true;
  7266. }
  7267. }
  7268. lt = null;
  7269. }
  7270. }
  7271. }
  7272. return this._elem;
  7273. };
  7274. $.jqplot.TableLegendRenderer.prototype.pack = function(offsets) {
  7275. if (this.show) {
  7276. if (this.placement == 'insideGrid') {
  7277. switch (this.location) {
  7278. case 'nw':
  7279. var a = offsets.left;
  7280. var b = offsets.top;
  7281. this._elem.css('left', a);
  7282. this._elem.css('top', b);
  7283. break;
  7284. case 'n':
  7285. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  7286. var b = offsets.top;
  7287. this._elem.css('left', a);
  7288. this._elem.css('top', b);
  7289. break;
  7290. case 'ne':
  7291. var a = offsets.right;
  7292. var b = offsets.top;
  7293. this._elem.css({right:a, top:b});
  7294. break;
  7295. case 'e':
  7296. var a = offsets.right;
  7297. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  7298. this._elem.css({right:a, top:b});
  7299. break;
  7300. case 'se':
  7301. var a = offsets.right;
  7302. var b = offsets.bottom;
  7303. this._elem.css({right:a, bottom:b});
  7304. break;
  7305. case 's':
  7306. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  7307. var b = offsets.bottom;
  7308. this._elem.css({left:a, bottom:b});
  7309. break;
  7310. case 'sw':
  7311. var a = offsets.left;
  7312. var b = offsets.bottom;
  7313. this._elem.css({left:a, bottom:b});
  7314. break;
  7315. case 'w':
  7316. var a = offsets.left;
  7317. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  7318. this._elem.css({left:a, top:b});
  7319. break;
  7320. default: // same as 'se'
  7321. var a = offsets.right;
  7322. var b = offsets.bottom;
  7323. this._elem.css({right:a, bottom:b});
  7324. break;
  7325. }
  7326. }
  7327. else if (this.placement == 'outside'){
  7328. switch (this.location) {
  7329. case 'nw':
  7330. var a = this._plotDimensions.width - offsets.left;
  7331. var b = offsets.top;
  7332. this._elem.css('right', a);
  7333. this._elem.css('top', b);
  7334. break;
  7335. case 'n':
  7336. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  7337. var b = this._plotDimensions.height - offsets.top;
  7338. this._elem.css('left', a);
  7339. this._elem.css('bottom', b);
  7340. break;
  7341. case 'ne':
  7342. var a = this._plotDimensions.width - offsets.right;
  7343. var b = offsets.top;
  7344. this._elem.css({left:a, top:b});
  7345. break;
  7346. case 'e':
  7347. var a = this._plotDimensions.width - offsets.right;
  7348. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  7349. this._elem.css({left:a, top:b});
  7350. break;
  7351. case 'se':
  7352. var a = this._plotDimensions.width - offsets.right;
  7353. var b = offsets.bottom;
  7354. this._elem.css({left:a, bottom:b});
  7355. break;
  7356. case 's':
  7357. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  7358. var b = this._plotDimensions.height - offsets.bottom;
  7359. this._elem.css({left:a, top:b});
  7360. break;
  7361. case 'sw':
  7362. var a = this._plotDimensions.width - offsets.left;
  7363. var b = offsets.bottom;
  7364. this._elem.css({right:a, bottom:b});
  7365. break;
  7366. case 'w':
  7367. var a = this._plotDimensions.width - offsets.left;
  7368. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  7369. this._elem.css({right:a, top:b});
  7370. break;
  7371. default: // same as 'se'
  7372. var a = offsets.right;
  7373. var b = offsets.bottom;
  7374. this._elem.css({right:a, bottom:b});
  7375. break;
  7376. }
  7377. }
  7378. else {
  7379. switch (this.location) {
  7380. case 'nw':
  7381. this._elem.css({left:0, top:offsets.top});
  7382. break;
  7383. case 'n':
  7384. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  7385. this._elem.css({left: a, top:offsets.top});
  7386. break;
  7387. case 'ne':
  7388. this._elem.css({right:0, top:offsets.top});
  7389. break;
  7390. case 'e':
  7391. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  7392. this._elem.css({right:offsets.right, top:b});
  7393. break;
  7394. case 'se':
  7395. this._elem.css({right:offsets.right, bottom:offsets.bottom});
  7396. break;
  7397. case 's':
  7398. var a = (offsets.left + (this._plotDimensions.width - offsets.right))/2 - this.getWidth()/2;
  7399. this._elem.css({left: a, bottom:offsets.bottom});
  7400. break;
  7401. case 'sw':
  7402. this._elem.css({left:offsets.left, bottom:offsets.bottom});
  7403. break;
  7404. case 'w':
  7405. var b = (offsets.top + (this._plotDimensions.height - offsets.bottom))/2 - this.getHeight()/2;
  7406. this._elem.css({left:offsets.left, top:b});
  7407. break;
  7408. default: // same as 'se'
  7409. this._elem.css({right:offsets.right, bottom:offsets.bottom});
  7410. break;
  7411. }
  7412. }
  7413. }
  7414. };
  7415. /**
  7416. * Class: $.jqplot.ThemeEngine
  7417. * Theme Engine provides a programatic way to change some of the more
  7418. * common jqplot styling options such as fonts, colors and grid options.
  7419. * A theme engine instance is created with each plot. The theme engine
  7420. * manages a collection of themes which can be modified, added to, or
  7421. * applied to the plot.
  7422. *
  7423. * The themeEngine class is not instantiated directly.
  7424. * When a plot is initialized, the current plot options are scanned
  7425. * an a default theme named "Default" is created. This theme is
  7426. * used as the basis for other themes added to the theme engine and
  7427. * is always available.
  7428. *
  7429. * A theme is a simple javascript object with styling parameters for
  7430. * various entities of the plot. A theme has the form:
  7431. *
  7432. *
  7433. * > {
  7434. * > _name:f "Default",
  7435. * > target: {
  7436. * > backgroundColor: "transparent"
  7437. * > },
  7438. * > legend: {
  7439. * > textColor: null,
  7440. * > fontFamily: null,
  7441. * > fontSize: null,
  7442. * > border: null,
  7443. * > background: null
  7444. * > },
  7445. * > title: {
  7446. * > textColor: "rgb(102, 102, 102)",
  7447. * > fontFamily: "'Trebuchet MS',Arial,Helvetica,sans-serif",
  7448. * > fontSize: "19.2px",
  7449. * > textAlign: "center"
  7450. * > },
  7451. * > seriesStyles: {},
  7452. * > series: [{
  7453. * > color: "#4bb2c5",
  7454. * > lineWidth: 2.5,
  7455. * > linePattern: "solid",
  7456. * > shadow: true,
  7457. * > fillColor: "#4bb2c5",
  7458. * > showMarker: true,
  7459. * > markerOptions: {
  7460. * > color: "#4bb2c5",
  7461. * > show: true,
  7462. * > style: 'filledCircle',
  7463. * > lineWidth: 1.5,
  7464. * > size: 4,
  7465. * > shadow: true
  7466. * > }
  7467. * > }],
  7468. * > grid: {
  7469. * > drawGridlines: true,
  7470. * > gridLineColor: "#cccccc",
  7471. * > gridLineWidth: 1,
  7472. * > backgroundColor: "#fffdf6",
  7473. * > borderColor: "#999999",
  7474. * > borderWidth: 2,
  7475. * > shadow: true
  7476. * > },
  7477. * > axesStyles: {
  7478. * > label: {},
  7479. * > ticks: {}
  7480. * > },
  7481. * > axes: {
  7482. * > xaxis: {
  7483. * > borderColor: "#999999",
  7484. * > borderWidth: 2,
  7485. * > ticks: {
  7486. * > show: true,
  7487. * > showGridline: true,
  7488. * > showLabel: true,
  7489. * > showMark: true,
  7490. * > size: 4,
  7491. * > textColor: "",
  7492. * > whiteSpace: "nowrap",
  7493. * > fontSize: "12px",
  7494. * > fontFamily: "'Trebuchet MS',Arial,Helvetica,sans-serif"
  7495. * > },
  7496. * > label: {
  7497. * > textColor: "rgb(102, 102, 102)",
  7498. * > whiteSpace: "normal",
  7499. * > fontSize: "14.6667px",
  7500. * > fontFamily: "'Trebuchet MS',Arial,Helvetica,sans-serif",
  7501. * > fontWeight: "400"
  7502. * > }
  7503. * > },
  7504. * > yaxis: {
  7505. * > borderColor: "#999999",
  7506. * > borderWidth: 2,
  7507. * > ticks: {
  7508. * > show: true,
  7509. * > showGridline: true,
  7510. * > showLabel: true,
  7511. * > showMark: true,
  7512. * > size: 4,
  7513. * > textColor: "",
  7514. * > whiteSpace: "nowrap",
  7515. * > fontSize: "12px",
  7516. * > fontFamily: "'Trebuchet MS',Arial,Helvetica,sans-serif"
  7517. * > },
  7518. * > label: {
  7519. * > textColor: null,
  7520. * > whiteSpace: null,
  7521. * > fontSize: null,
  7522. * > fontFamily: null,
  7523. * > fontWeight: null
  7524. * > }
  7525. * > },
  7526. * > x2axis: {...
  7527. * > },
  7528. * > ...
  7529. * > y9axis: {...
  7530. * > }
  7531. * > }
  7532. * > }
  7533. *
  7534. * "seriesStyles" is a style object that will be applied to all series in the plot.
  7535. * It will forcibly override any styles applied on the individual series. "axesStyles" is
  7536. * a style object that will be applied to all axes in the plot. It will also forcibly
  7537. * override any styles on the individual axes.
  7538. *
  7539. * The example shown above has series options for a line series. Options for other
  7540. * series types are shown below:
  7541. *
  7542. * Bar Series:
  7543. *
  7544. * > {
  7545. * > color: "#4bb2c5",
  7546. * > seriesColors: ["#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"],
  7547. * > lineWidth: 2.5,
  7548. * > shadow: true,
  7549. * > barPadding: 2,
  7550. * > barMargin: 10,
  7551. * > barWidth: 15.09375,
  7552. * > 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)"]
  7553. * > }
  7554. *
  7555. * Pie Series:
  7556. *
  7557. * > {
  7558. * > seriesColors: ["#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"],
  7559. * > padding: 20,
  7560. * > sliceMargin: 0,
  7561. * > fill: true,
  7562. * > shadow: true,
  7563. * > startAngle: 0,
  7564. * > lineWidth: 2.5,
  7565. * > 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)"]
  7566. * > }
  7567. *
  7568. * Funnel Series:
  7569. *
  7570. * > {
  7571. * > color: "#4bb2c5",
  7572. * > lineWidth: 2,
  7573. * > shadow: true,
  7574. * > padding: {
  7575. * > top: 20,
  7576. * > right: 20,
  7577. * > bottom: 20,
  7578. * > left: 20
  7579. * > },
  7580. * > sectionMargin: 6,
  7581. * > seriesColors: ["#4bb2c5", "#EAA228", "#c5b47f", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc", "#c747a3", "#cddf54", "#FBD178", "#26B4E3", "#bd70c7"],
  7582. * > 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)"]
  7583. * > }
  7584. *
  7585. */
  7586. $.jqplot.ThemeEngine = function(){
  7587. // Group: Properties
  7588. //
  7589. // prop: themes
  7590. // hash of themes managed by the theme engine.
  7591. // Indexed by theme name.
  7592. this.themes = {};
  7593. // prop: activeTheme
  7594. // Pointer to currently active theme
  7595. this.activeTheme=null;
  7596. };
  7597. // called with scope of plot
  7598. $.jqplot.ThemeEngine.prototype.init = function() {
  7599. // get the Default theme from the current plot settings.
  7600. var th = new $.jqplot.Theme({_name:'Default'});
  7601. var n, i, nn;
  7602. for (n in th.target) {
  7603. if (n == "textColor") {
  7604. th.target[n] = this.target.css('color');
  7605. }
  7606. else {
  7607. th.target[n] = this.target.css(n);
  7608. }
  7609. }
  7610. if (this.title.show && this.title._elem) {
  7611. for (n in th.title) {
  7612. if (n == "textColor") {
  7613. th.title[n] = this.title._elem.css('color');
  7614. }
  7615. else {
  7616. th.title[n] = this.title._elem.css(n);
  7617. }
  7618. }
  7619. }
  7620. for (n in th.grid) {
  7621. th.grid[n] = this.grid[n];
  7622. }
  7623. if (th.grid.backgroundColor == null && this.grid.background != null) {
  7624. th.grid.backgroundColor = this.grid.background;
  7625. }
  7626. if (this.legend.show && this.legend._elem) {
  7627. for (n in th.legend) {
  7628. if (n == 'textColor') {
  7629. th.legend[n] = this.legend._elem.css('color');
  7630. }
  7631. else {
  7632. th.legend[n] = this.legend._elem.css(n);
  7633. }
  7634. }
  7635. }
  7636. var s;
  7637. for (i=0; i<this.series.length; i++) {
  7638. s = this.series[i];
  7639. if (s.renderer.constructor == $.jqplot.LineRenderer) {
  7640. th.series.push(new LineSeriesProperties());
  7641. }
  7642. else if (s.renderer.constructor == $.jqplot.BarRenderer) {
  7643. th.series.push(new BarSeriesProperties());
  7644. }
  7645. else if (s.renderer.constructor == $.jqplot.PieRenderer) {
  7646. th.series.push(new PieSeriesProperties());
  7647. }
  7648. else if (s.renderer.constructor == $.jqplot.DonutRenderer) {
  7649. th.series.push(new DonutSeriesProperties());
  7650. }
  7651. else if (s.renderer.constructor == $.jqplot.FunnelRenderer) {
  7652. th.series.push(new FunnelSeriesProperties());
  7653. }
  7654. else if (s.renderer.constructor == $.jqplot.MeterGaugeRenderer) {
  7655. th.series.push(new MeterSeriesProperties());
  7656. }
  7657. else {
  7658. th.series.push({});
  7659. }
  7660. for (n in th.series[i]) {
  7661. th.series[i][n] = s[n];
  7662. }
  7663. }
  7664. var a, ax;
  7665. for (n in this.axes) {
  7666. ax = this.axes[n];
  7667. a = th.axes[n] = new AxisProperties();
  7668. a.borderColor = ax.borderColor;
  7669. a.borderWidth = ax.borderWidth;
  7670. if (ax._ticks && ax._ticks[0]) {
  7671. for (nn in a.ticks) {
  7672. if (ax._ticks[0].hasOwnProperty(nn)) {
  7673. a.ticks[nn] = ax._ticks[0][nn];
  7674. }
  7675. else if (ax._ticks[0]._elem){
  7676. a.ticks[nn] = ax._ticks[0]._elem.css(nn);
  7677. }
  7678. }
  7679. }
  7680. if (ax._label && ax._label.show) {
  7681. for (nn in a.label) {
  7682. // a.label[nn] = ax._label._elem.css(nn);
  7683. if (ax._label[nn]) {
  7684. a.label[nn] = ax._label[nn];
  7685. }
  7686. else if (ax._label._elem){
  7687. if (nn == 'textColor') {
  7688. a.label[nn] = ax._label._elem.css('color');
  7689. }
  7690. else {
  7691. a.label[nn] = ax._label._elem.css(nn);
  7692. }
  7693. }
  7694. }
  7695. }
  7696. }
  7697. this.themeEngine._add(th);
  7698. this.themeEngine.activeTheme = this.themeEngine.themes[th._name];
  7699. };
  7700. /**
  7701. * Group: methods
  7702. *
  7703. * method: get
  7704. *
  7705. * Get and return the named theme or the active theme if no name given.
  7706. *
  7707. * parameter:
  7708. *
  7709. * name - name of theme to get.
  7710. *
  7711. * returns:
  7712. *
  7713. * Theme instance of given name.
  7714. */
  7715. $.jqplot.ThemeEngine.prototype.get = function(name) {
  7716. if (!name) {
  7717. // return the active theme
  7718. return this.activeTheme;
  7719. }
  7720. else {
  7721. return this.themes[name];
  7722. }
  7723. };
  7724. function numericalOrder(a,b) { return a-b; }
  7725. /**
  7726. * method: getThemeNames
  7727. *
  7728. * Return the list of theme names in this manager in alpha-numerical order.
  7729. *
  7730. * parameter:
  7731. *
  7732. * None
  7733. *
  7734. * returns:
  7735. *
  7736. * A the list of theme names in this manager in alpha-numerical order.
  7737. */
  7738. $.jqplot.ThemeEngine.prototype.getThemeNames = function() {
  7739. var tn = [];
  7740. for (var n in this.themes) {
  7741. tn.push(n);
  7742. }
  7743. return tn.sort(numericalOrder);
  7744. };
  7745. /**
  7746. * method: getThemes
  7747. *
  7748. * Return a list of themes in alpha-numerical order by name.
  7749. *
  7750. * parameter:
  7751. *
  7752. * None
  7753. *
  7754. * returns:
  7755. *
  7756. * A list of themes in alpha-numerical order by name.
  7757. */
  7758. $.jqplot.ThemeEngine.prototype.getThemes = function() {
  7759. var tn = [];
  7760. var themes = [];
  7761. for (var n in this.themes) {
  7762. tn.push(n);
  7763. }
  7764. tn.sort(numericalOrder);
  7765. for (var i=0; i<tn.length; i++) {
  7766. themes.push(this.themes[tn[i]]);
  7767. }
  7768. return themes;
  7769. };
  7770. $.jqplot.ThemeEngine.prototype.activate = function(plot, name) {
  7771. // sometimes need to redraw whole plot.
  7772. var redrawPlot = false;
  7773. if (!name && this.activeTheme && this.activeTheme._name) {
  7774. name = this.activeTheme._name;
  7775. }
  7776. if (!this.themes.hasOwnProperty(name)) {
  7777. throw new Error("No theme of that name");
  7778. }
  7779. else {
  7780. var th = this.themes[name];
  7781. this.activeTheme = th;
  7782. var val, checkBorderColor = false, checkBorderWidth = false;
  7783. var arr = ['xaxis', 'x2axis', 'yaxis', 'y2axis'];
  7784. for (i=0; i<arr.length; i++) {
  7785. var ax = arr[i];
  7786. if (th.axesStyles.borderColor != null) {
  7787. plot.axes[ax].borderColor = th.axesStyles.borderColor;
  7788. }
  7789. if (th.axesStyles.borderWidth != null) {
  7790. plot.axes[ax].borderWidth = th.axesStyles.borderWidth;
  7791. }
  7792. }
  7793. for (var axname in plot.axes) {
  7794. var axis = plot.axes[axname];
  7795. if (axis.show) {
  7796. var thaxis = th.axes[axname] || {};
  7797. var thaxstyle = th.axesStyles;
  7798. var thax = $.jqplot.extend(true, {}, thaxis, thaxstyle);
  7799. val = (th.axesStyles.borderColor != null) ? th.axesStyles.borderColor : thax.borderColor;
  7800. if (thax.borderColor != null) {
  7801. axis.borderColor = thax.borderColor;
  7802. redrawPlot = true;
  7803. }
  7804. val = (th.axesStyles.borderWidth != null) ? th.axesStyles.borderWidth : thax.borderWidth;
  7805. if (thax.borderWidth != null) {
  7806. axis.borderWidth = thax.borderWidth;
  7807. redrawPlot = true;
  7808. }
  7809. if (axis._ticks && axis._ticks[0]) {
  7810. for (var nn in thax.ticks) {
  7811. // val = null;
  7812. // if (th.axesStyles.ticks && th.axesStyles.ticks[nn] != null) {
  7813. // val = th.axesStyles.ticks[nn];
  7814. // }
  7815. // else if (thax.ticks[nn] != null){
  7816. // val = thax.ticks[nn]
  7817. // }
  7818. val = thax.ticks[nn];
  7819. if (val != null) {
  7820. axis.tickOptions[nn] = val;
  7821. axis._ticks = [];
  7822. redrawPlot = true;
  7823. }
  7824. }
  7825. }
  7826. if (axis._label && axis._label.show) {
  7827. for (var nn in thax.label) {
  7828. // val = null;
  7829. // if (th.axesStyles.label && th.axesStyles.label[nn] != null) {
  7830. // val = th.axesStyles.label[nn];
  7831. // }
  7832. // else if (thax.label && thax.label[nn] != null){
  7833. // val = thax.label[nn]
  7834. // }
  7835. val = thax.label[nn];
  7836. if (val != null) {
  7837. axis.labelOptions[nn] = val;
  7838. redrawPlot = true;
  7839. }
  7840. }
  7841. }
  7842. }
  7843. }
  7844. for (var n in th.grid) {
  7845. if (th.grid[n] != null) {
  7846. plot.grid[n] = th.grid[n];
  7847. }
  7848. }
  7849. if (!redrawPlot) {
  7850. plot.grid.draw();
  7851. }
  7852. if (plot.legend.show) {
  7853. for (n in th.legend) {
  7854. if (th.legend[n] != null) {
  7855. plot.legend[n] = th.legend[n];
  7856. }
  7857. }
  7858. }
  7859. if (plot.title.show) {
  7860. for (n in th.title) {
  7861. if (th.title[n] != null) {
  7862. plot.title[n] = th.title[n];
  7863. }
  7864. }
  7865. }
  7866. var i;
  7867. for (i=0; i<th.series.length; i++) {
  7868. var opts = {};
  7869. var redrawSeries = false;
  7870. for (n in th.series[i]) {
  7871. val = (th.seriesStyles[n] != null) ? th.seriesStyles[n] : th.series[i][n];
  7872. if (val != null) {
  7873. opts[n] = val;
  7874. if (n == 'color') {
  7875. plot.series[i].renderer.shapeRenderer.fillStyle = val;
  7876. plot.series[i].renderer.shapeRenderer.strokeStyle = val;
  7877. plot.series[i][n] = val;
  7878. }
  7879. else if ((n == 'lineWidth') || (n == 'linePattern')) {
  7880. plot.series[i].renderer.shapeRenderer[n] = val;
  7881. plot.series[i][n] = val;
  7882. }
  7883. else if (n == 'markerOptions') {
  7884. merge (plot.series[i].markerOptions, val);
  7885. merge (plot.series[i].markerRenderer, val);
  7886. }
  7887. else {
  7888. plot.series[i][n] = val;
  7889. }
  7890. redrawPlot = true;
  7891. }
  7892. }
  7893. }
  7894. if (redrawPlot) {
  7895. plot.target.empty();
  7896. plot.draw();
  7897. }
  7898. for (n in th.target) {
  7899. if (th.target[n] != null) {
  7900. plot.target.css(n, th.target[n]);
  7901. }
  7902. }
  7903. }
  7904. };
  7905. $.jqplot.ThemeEngine.prototype._add = function(theme, name) {
  7906. if (name) {
  7907. theme._name = name;
  7908. }
  7909. if (!theme._name) {
  7910. theme._name = Date.parse(new Date());
  7911. }
  7912. if (!this.themes.hasOwnProperty(theme._name)) {
  7913. this.themes[theme._name] = theme;
  7914. }
  7915. else {
  7916. throw new Error("jqplot.ThemeEngine Error: Theme already in use");
  7917. }
  7918. };
  7919. // method remove
  7920. // Delete the named theme, return true on success, false on failure.
  7921. /**
  7922. * method: remove
  7923. *
  7924. * Remove the given theme from the themeEngine.
  7925. *
  7926. * parameters:
  7927. *
  7928. * name - name of the theme to remove.
  7929. *
  7930. * returns:
  7931. *
  7932. * true on success, false on failure.
  7933. */
  7934. $.jqplot.ThemeEngine.prototype.remove = function(name) {
  7935. if (name == 'Default') {
  7936. return false;
  7937. }
  7938. return delete this.themes[name];
  7939. };
  7940. /**
  7941. * method: newTheme
  7942. *
  7943. * Create a new theme based on the default theme, adding it the themeEngine.
  7944. *
  7945. * parameters:
  7946. *
  7947. * name - name of the new theme.
  7948. * obj - optional object of styles to be applied to this new theme.
  7949. *
  7950. * returns:
  7951. *
  7952. * new Theme object.
  7953. */
  7954. $.jqplot.ThemeEngine.prototype.newTheme = function(name, obj) {
  7955. if (typeof(name) == 'object') {
  7956. obj = obj || name;
  7957. name = null;
  7958. }
  7959. if (obj && obj._name) {
  7960. name = obj._name;
  7961. }
  7962. else {
  7963. name = name || Date.parse(new Date());
  7964. }
  7965. // var th = new $.jqplot.Theme(name);
  7966. var th = this.copy(this.themes['Default']._name, name);
  7967. $.jqplot.extend(th, obj);
  7968. return th;
  7969. };
  7970. // function clone(obj) {
  7971. // return eval(obj.toSource());
  7972. // }
  7973. function clone(obj){
  7974. if(obj == null || typeof(obj) != 'object'){
  7975. return obj;
  7976. }
  7977. var temp = new obj.constructor();
  7978. for(var key in obj){
  7979. temp[key] = clone(obj[key]);
  7980. }
  7981. return temp;
  7982. }
  7983. $.jqplot.clone = clone;
  7984. function merge(obj1, obj2) {
  7985. if (obj2 == null || typeof(obj2) != 'object') {
  7986. return;
  7987. }
  7988. for (var key in obj2) {
  7989. if (key == 'highlightColors') {
  7990. obj1[key] = clone(obj2[key]);
  7991. }
  7992. if (obj2[key] != null && typeof(obj2[key]) == 'object') {
  7993. if (!obj1.hasOwnProperty(key)) {
  7994. obj1[key] = {};
  7995. }
  7996. merge(obj1[key], obj2[key]);
  7997. }
  7998. else {
  7999. obj1[key] = obj2[key];
  8000. }
  8001. }
  8002. }
  8003. $.jqplot.merge = merge;
  8004. // Use the jQuery 1.3.2 extend function since behaviour in jQuery 1.4 seems problematic
  8005. $.jqplot.extend = function() {
  8006. // copy reference to target object
  8007. var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
  8008. // Handle a deep copy situation
  8009. if ( typeof target === "boolean" ) {
  8010. deep = target;
  8011. target = arguments[1] || {};
  8012. // skip the boolean and the target
  8013. i = 2;
  8014. }
  8015. // Handle case when target is a string or something (possible in deep copy)
  8016. if ( typeof target !== "object" && !toString.call(target) === "[object Function]" ) {
  8017. target = {};
  8018. }
  8019. for ( ; i < length; i++ ){
  8020. // Only deal with non-null/undefined values
  8021. if ( (options = arguments[ i ]) != null ) {
  8022. // Extend the base object
  8023. for ( var name in options ) {
  8024. var src = target[ name ], copy = options[ name ];
  8025. // Prevent never-ending loop
  8026. if ( target === copy ) {
  8027. continue;
  8028. }
  8029. // Recurse if we're merging object values
  8030. if ( deep && copy && typeof copy === "object" && !copy.nodeType ) {
  8031. target[ name ] = $.jqplot.extend( deep,
  8032. // Never move original objects, clone them
  8033. src || ( copy.length != null ? [ ] : { } )
  8034. , copy );
  8035. }
  8036. // Don't bring in undefined values
  8037. else if ( copy !== undefined ) {
  8038. target[ name ] = copy;
  8039. }
  8040. }
  8041. }
  8042. }
  8043. // Return the modified object
  8044. return target;
  8045. };
  8046. /**
  8047. * method: rename
  8048. *
  8049. * Rename a theme.
  8050. *
  8051. * parameters:
  8052. *
  8053. * oldName - current name of the theme.
  8054. * newName - desired name of the theme.
  8055. *
  8056. * returns:
  8057. *
  8058. * new Theme object.
  8059. */
  8060. $.jqplot.ThemeEngine.prototype.rename = function (oldName, newName) {
  8061. if (oldName == 'Default' || newName == 'Default') {
  8062. throw new Error ("jqplot.ThemeEngine Error: Cannot rename from/to Default");
  8063. }
  8064. if (this.themes.hasOwnProperty(newName)) {
  8065. throw new Error ("jqplot.ThemeEngine Error: New name already in use.");
  8066. }
  8067. else if (this.themes.hasOwnProperty(oldName)) {
  8068. var th = this.copy (oldName, newName);
  8069. this.remove(oldName);
  8070. return th;
  8071. }
  8072. throw new Error("jqplot.ThemeEngine Error: Old name or new name invalid");
  8073. };
  8074. /**
  8075. * method: copy
  8076. *
  8077. * Create a copy of an existing theme in the themeEngine, adding it the themeEngine.
  8078. *
  8079. * parameters:
  8080. *
  8081. * sourceName - name of the existing theme.
  8082. * targetName - name of the copy.
  8083. * obj - optional object of style parameter to apply to the new theme.
  8084. *
  8085. * returns:
  8086. *
  8087. * new Theme object.
  8088. */
  8089. $.jqplot.ThemeEngine.prototype.copy = function (sourceName, targetName, obj) {
  8090. if (targetName == 'Default') {
  8091. throw new Error ("jqplot.ThemeEngine Error: Cannot copy over Default theme");
  8092. }
  8093. if (!this.themes.hasOwnProperty(sourceName)) {
  8094. var s = "jqplot.ThemeEngine Error: Source name invalid";
  8095. throw new Error(s);
  8096. }
  8097. if (this.themes.hasOwnProperty(targetName)) {
  8098. var s = "jqplot.ThemeEngine Error: Target name invalid";
  8099. throw new Error(s);
  8100. }
  8101. else {
  8102. var th = clone(this.themes[sourceName]);
  8103. th._name = targetName;
  8104. $.jqplot.extend(true, th, obj);
  8105. this._add(th);
  8106. return th;
  8107. }
  8108. };
  8109. $.jqplot.Theme = function(name, obj) {
  8110. if (typeof(name) == 'object') {
  8111. obj = obj || name;
  8112. name = null;
  8113. }
  8114. name = name || Date.parse(new Date());
  8115. this._name = name;
  8116. this.target = {
  8117. backgroundColor: null
  8118. };
  8119. this.legend = {
  8120. textColor: null,
  8121. fontFamily: null,
  8122. fontSize: null,
  8123. border: null,
  8124. background: null
  8125. };
  8126. this.title = {
  8127. textColor: null,
  8128. fontFamily: null,
  8129. fontSize: null,
  8130. textAlign: null
  8131. };
  8132. this.seriesStyles = {};
  8133. this.series = [];
  8134. this.grid = {
  8135. drawGridlines: null,
  8136. gridLineColor: null,
  8137. gridLineWidth: null,
  8138. backgroundColor: null,
  8139. borderColor: null,
  8140. borderWidth: null,
  8141. shadow: null
  8142. };
  8143. this.axesStyles = {label:{}, ticks:{}};
  8144. this.axes = {};
  8145. if (typeof(obj) == 'string') {
  8146. this._name = obj;
  8147. }
  8148. else if(typeof(obj) == 'object') {
  8149. $.jqplot.extend(true, this, obj);
  8150. }
  8151. };
  8152. var AxisProperties = function() {
  8153. this.borderColor = null;
  8154. this.borderWidth = null;
  8155. this.ticks = new AxisTicks();
  8156. this.label = new AxisLabel();
  8157. };
  8158. var AxisTicks = function() {
  8159. this.show = null;
  8160. this.showGridline = null;
  8161. this.showLabel = null;
  8162. this.showMark = null;
  8163. this.size = null;
  8164. this.textColor = null;
  8165. this.whiteSpace = null;
  8166. this.fontSize = null;
  8167. this.fontFamily = null;
  8168. };
  8169. var AxisLabel = function() {
  8170. this.textColor = null;
  8171. this.whiteSpace = null;
  8172. this.fontSize = null;
  8173. this.fontFamily = null;
  8174. this.fontWeight = null;
  8175. };
  8176. var LineSeriesProperties = function() {
  8177. this.color=null;
  8178. this.lineWidth=null;
  8179. this.linePattern=null;
  8180. this.shadow=null;
  8181. this.fillColor=null;
  8182. this.showMarker=null;
  8183. this.markerOptions = new MarkerOptions();
  8184. };
  8185. var MarkerOptions = function() {
  8186. this.show = null;
  8187. this.style = null;
  8188. this.lineWidth = null;
  8189. this.size = null;
  8190. this.color = null;
  8191. this.shadow = null;
  8192. };
  8193. var BarSeriesProperties = function() {
  8194. this.color=null;
  8195. this.seriesColors=null;
  8196. this.lineWidth=null;
  8197. this.shadow=null;
  8198. this.barPadding=null;
  8199. this.barMargin=null;
  8200. this.barWidth=null;
  8201. this.highlightColors=null;
  8202. };
  8203. var PieSeriesProperties = function() {
  8204. this.seriesColors=null;
  8205. this.padding=null;
  8206. this.sliceMargin=null;
  8207. this.fill=null;
  8208. this.shadow=null;
  8209. this.startAngle=null;
  8210. this.lineWidth=null;
  8211. this.highlightColors=null;
  8212. };
  8213. var DonutSeriesProperties = function() {
  8214. this.seriesColors=null;
  8215. this.padding=null;
  8216. this.sliceMargin=null;
  8217. this.fill=null;
  8218. this.shadow=null;
  8219. this.startAngle=null;
  8220. this.lineWidth=null;
  8221. this.innerDiameter=null;
  8222. this.thickness=null;
  8223. this.ringMargin=null;
  8224. this.highlightColors=null;
  8225. };
  8226. var FunnelSeriesProperties = function() {
  8227. this.color=null;
  8228. this.lineWidth=null;
  8229. this.shadow=null;
  8230. this.padding=null;
  8231. this.sectionMargin=null;
  8232. this.seriesColors=null;
  8233. this.highlightColors=null;
  8234. };
  8235. var MeterSeriesProperties = function() {
  8236. this.padding=null;
  8237. this.backgroundColor=null;
  8238. this.ringColor=null;
  8239. this.tickColor=null;
  8240. this.ringWidth=null;
  8241. this.intervalColors=null;
  8242. this.intervalInnerRadius=null;
  8243. this.intervalOuterRadius=null;
  8244. this.hubRadius=null;
  8245. this.needleThickness=null;
  8246. this.needlePad=null;
  8247. };
  8248. $.fn.jqplotChildText = function() {
  8249. return $(this).contents().filter(function() {
  8250. return this.nodeType == 3; // Node.TEXT_NODE not defined in I7
  8251. }).text();
  8252. };
  8253. // Returns font style as abbreviation for "font" property.
  8254. $.fn.jqplotGetComputedFontStyle = function() {
  8255. var css = window.getComputedStyle ? window.getComputedStyle(this[0], "") : this[0].currentStyle;
  8256. var attrs = css['font-style'] ? ['font-style', 'font-weight', 'font-size', 'font-family'] : ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily'];
  8257. var style = [];
  8258. for (var i=0 ; i < attrs.length; ++i) {
  8259. var attr = String(css[attrs[i]]);
  8260. if (attr && attr != 'normal') {
  8261. style.push(attr);
  8262. }
  8263. }
  8264. return style.join(' ');
  8265. };
  8266. /**
  8267. * Namespace: $.fn
  8268. * jQuery namespace to attach functions to jQuery elements.
  8269. *
  8270. */
  8271. $.fn.jqplotToImageCanvas = function(options) {
  8272. options = options || {};
  8273. var x_offset = (options.x_offset == null) ? 0 : options.x_offset;
  8274. var y_offset = (options.y_offset == null) ? 0 : options.y_offset;
  8275. var backgroundColor = (options.backgroundColor == null) ? 'rgb(255,255,255)' : options.backgroundColor;
  8276. if ($(this).width() == 0 || $(this).height() == 0) {
  8277. return null;
  8278. }
  8279. // excanvas and hence IE < 9 do not support toDataURL and cannot export images.
  8280. if ($.jqplot.use_excanvas) {
  8281. return null;
  8282. }
  8283. var newCanvas = document.createElement("canvas");
  8284. var h = $(this).outerHeight(true);
  8285. var w = $(this).outerWidth(true);
  8286. var offs = $(this).offset();
  8287. var plotleft = offs.left;
  8288. var plottop = offs.top;
  8289. var transx = 0, transy = 0;
  8290. // have to check if any elements are hanging outside of plot area before rendering,
  8291. // since changing width of canvas will erase canvas.
  8292. var clses = ['jqplot-table-legend', 'jqplot-xaxis-tick', 'jqplot-x2axis-tick', 'jqplot-yaxis-tick', 'jqplot-y2axis-tick', 'jqplot-y3axis-tick',
  8293. 'jqplot-y4axis-tick', 'jqplot-y5axis-tick', 'jqplot-y6axis-tick', 'jqplot-y7axis-tick', 'jqplot-y8axis-tick', 'jqplot-y9axis-tick',
  8294. 'jqplot-xaxis-label', 'jqplot-x2axis-label', 'jqplot-yaxis-label', 'jqplot-y2axis-label', 'jqplot-y3axis-label', 'jqplot-y4axis-label',
  8295. 'jqplot-y5axis-label', 'jqplot-y6axis-label', 'jqplot-y7axis-label', 'jqplot-y8axis-label', 'jqplot-y9axis-label' ];
  8296. var temptop, templeft, tempbottom, tempright;
  8297. for (var i = 0; i < clses.length; i++) {
  8298. $(this).find('.'+clses[i]).each(function() {
  8299. temptop = $(this).offset().top - plottop;
  8300. templeft = $(this).offset().left - plotleft;
  8301. tempright = templeft + $(this).outerWidth(true) + transx;
  8302. tempbottom = temptop + $(this).outerHeight(true) + transy;
  8303. if (templeft < -transx) {
  8304. w = w - transx - templeft;
  8305. transx = -templeft;
  8306. }
  8307. if (temptop < -transy) {
  8308. h = h - transy - temptop;
  8309. transy = - temptop;
  8310. }
  8311. if (tempright > w) {
  8312. w = tempright;
  8313. }
  8314. if (tempbottom > h) {
  8315. h = tempbottom;
  8316. }
  8317. });
  8318. }
  8319. newCanvas.width = w + Number(x_offset);
  8320. newCanvas.height = h + Number(y_offset);
  8321. var newContext = newCanvas.getContext("2d");
  8322. newContext.save();
  8323. newContext.fillStyle = backgroundColor;
  8324. newContext.fillRect(0,0, newCanvas.width, newCanvas.height);
  8325. newContext.restore();
  8326. newContext.translate(transx, transy);
  8327. newContext.textAlign = 'left';
  8328. newContext.textBaseline = 'top';
  8329. function getLineheight(el) {
  8330. var lineheight = parseInt($(el).css('line-height'), 10);
  8331. if (isNaN(lineheight)) {
  8332. lineheight = parseInt($(el).css('font-size'), 10) * 1.2;
  8333. }
  8334. return lineheight;
  8335. }
  8336. function writeWrappedText (el, context, text, left, top, canvasWidth) {
  8337. var lineheight = getLineheight(el);
  8338. var tagwidth = $(el).innerWidth();
  8339. var tagheight = $(el).innerHeight();
  8340. var words = text.split(/\s+/);
  8341. var wl = words.length;
  8342. var w = '';
  8343. var breaks = [];
  8344. var temptop = top;
  8345. var templeft = left;
  8346. for (var i=0; i<wl; i++) {
  8347. w += words[i];
  8348. if (context.measureText(w).width > tagwidth) {
  8349. breaks.push(i);
  8350. w = '';
  8351. i--;
  8352. }
  8353. }
  8354. if (breaks.length === 0) {
  8355. // center text if necessary
  8356. if ($(el).css('textAlign') === 'center') {
  8357. templeft = left + (canvasWidth - context.measureText(w).width)/2 - transx;
  8358. }
  8359. context.fillText(text, templeft, top);
  8360. }
  8361. else {
  8362. w = words.slice(0, breaks[0]).join(' ');
  8363. // center text if necessary
  8364. if ($(el).css('textAlign') === 'center') {
  8365. templeft = left + (canvasWidth - context.measureText(w).width)/2 - transx;
  8366. }
  8367. context.fillText(w, templeft, temptop);
  8368. temptop += lineheight;
  8369. for (var i=1, l=breaks.length; i<l; i++) {
  8370. w = words.slice(breaks[i-1], breaks[i]).join(' ');
  8371. // center text if necessary
  8372. if ($(el).css('textAlign') === 'center') {
  8373. templeft = left + (canvasWidth - context.measureText(w).width)/2 - transx;
  8374. }
  8375. context.fillText(w, templeft, temptop);
  8376. temptop += lineheight;
  8377. }
  8378. w = words.slice(breaks[i-1], words.length).join(' ');
  8379. // center text if necessary
  8380. if ($(el).css('textAlign') === 'center') {
  8381. templeft = left + (canvasWidth - context.measureText(w).width)/2 - transx;
  8382. }
  8383. context.fillText(w, templeft, temptop);
  8384. }
  8385. }
  8386. function _jqpToImage(el, x_offset, y_offset) {
  8387. var tagname = el.tagName.toLowerCase();
  8388. var p = $(el).position();
  8389. var css = window.getComputedStyle ? window.getComputedStyle(el, "") : el.currentStyle; // for IE < 9
  8390. var left = x_offset + p.left + parseInt(css.marginLeft, 10) + parseInt(css.borderLeftWidth, 10) + parseInt(css.paddingLeft, 10);
  8391. var top = y_offset + p.top + parseInt(css.marginTop, 10) + parseInt(css.borderTopWidth, 10)+ parseInt(css.paddingTop, 10);
  8392. var w = newCanvas.width;
  8393. // var left = x_offset + p.left + $(el).css('marginLeft') + $(el).css('borderLeftWidth')
  8394. // somehow in here, for divs within divs, the width of the inner div should be used instead of the canvas.
  8395. if ((tagname == 'div' || tagname == 'span') && !$(el).hasClass('jqplot-highlighter-tooltip')) {
  8396. $(el).children().each(function() {
  8397. _jqpToImage(this, left, top);
  8398. });
  8399. var text = $(el).jqplotChildText();
  8400. if (text) {
  8401. newContext.font = $(el).jqplotGetComputedFontStyle();
  8402. newContext.fillStyle = $(el).css('color');
  8403. writeWrappedText(el, newContext, text, left, top, w);
  8404. }
  8405. }
  8406. // handle the standard table legend
  8407. else if (tagname === 'table' && $(el).hasClass('jqplot-table-legend')) {
  8408. newContext.strokeStyle = $(el).css('border-top-color');
  8409. newContext.fillStyle = $(el).css('background-color');
  8410. newContext.fillRect(left, top, $(el).innerWidth(), $(el).innerHeight());
  8411. if (parseInt($(el).css('border-top-width'), 10) > 0) {
  8412. newContext.strokeRect(left, top, $(el).innerWidth(), $(el).innerHeight());
  8413. }
  8414. // find all the swatches
  8415. $(el).find('div.jqplot-table-legend-swatch-outline').each(function() {
  8416. // get the first div and stroke it
  8417. var elem = $(this);
  8418. newContext.strokeStyle = elem.css('border-top-color');
  8419. var l = left + elem.position().left;
  8420. var t = top + elem.position().top;
  8421. newContext.strokeRect(l, t, elem.innerWidth(), elem.innerHeight());
  8422. // now fill the swatch
  8423. l += parseInt(elem.css('padding-left'), 10);
  8424. t += parseInt(elem.css('padding-top'), 10);
  8425. var h = elem.innerHeight() - 2 * parseInt(elem.css('padding-top'), 10);
  8426. var w = elem.innerWidth() - 2 * parseInt(elem.css('padding-left'), 10);
  8427. var swatch = elem.children('div.jqplot-table-legend-swatch');
  8428. newContext.fillStyle = swatch.css('background-color');
  8429. newContext.fillRect(l, t, w, h);
  8430. });
  8431. // now add text
  8432. $(el).find('td.jqplot-table-legend-label').each(function(){
  8433. var elem = $(this);
  8434. var l = left + elem.position().left;
  8435. var t = top + elem.position().top + parseInt(elem.css('padding-top'), 10);
  8436. newContext.font = elem.jqplotGetComputedFontStyle();
  8437. newContext.fillStyle = elem.css('color');
  8438. writeWrappedText(elem, newContext, elem.text(), l, t, w);
  8439. });
  8440. var elem = null;
  8441. }
  8442. else if (tagname == 'canvas') {
  8443. newContext.drawImage(el, left, top);
  8444. }
  8445. }
  8446. $(this).children().each(function() {
  8447. _jqpToImage(this, x_offset, y_offset);
  8448. });
  8449. return newCanvas;
  8450. };
  8451. // return the raw image data string.
  8452. // Should work on canvas supporting browsers.
  8453. $.fn.jqplotToImageStr = function(options) {
  8454. var imgCanvas = $(this).jqplotToImageCanvas(options);
  8455. if (imgCanvas) {
  8456. return imgCanvas.toDataURL("image/png");
  8457. }
  8458. else {
  8459. return null;
  8460. }
  8461. };
  8462. // return a DOM <img> element and return it.
  8463. // Should work on canvas supporting browsers.
  8464. $.fn.jqplotToImageElem = function(options) {
  8465. var elem = document.createElement("img");
  8466. var str = $(this).jqplotToImageStr(options);
  8467. elem.src = str;
  8468. return elem;
  8469. };
  8470. // return a string for an <img> element and return it.
  8471. // Should work on canvas supporting browsers.
  8472. $.fn.jqplotToImageElemStr = function(options) {
  8473. var str = '<img src='+$(this).jqplotToImageStr(options)+' />';
  8474. return str;
  8475. };
  8476. // Not gauranteed to work, even on canvas supporting browsers due to
  8477. // limitations with location.href and browser support.
  8478. $.fn.jqplotSaveImage = function() {
  8479. var imgData = $(this).jqplotToImageStr({});
  8480. if (imgData) {
  8481. window.location.href = imgData.replace("image/png", "image/octet-stream");
  8482. }
  8483. };
  8484. // Not gauranteed to work, even on canvas supporting browsers due to
  8485. // limitations with window.open and arbitrary data.
  8486. $.fn.jqplotViewImage = function() {
  8487. var imgStr = $(this).jqplotToImageElemStr({});
  8488. var imgData = $(this).jqplotToImageStr({});
  8489. if (imgStr) {
  8490. var w = window.open('');
  8491. w.document.open("image/png");
  8492. w.document.write(imgStr);
  8493. w.document.close();
  8494. w = null;
  8495. }
  8496. };
  8497. /**
  8498. * @description
  8499. * <p>Object with extended date parsing and formatting capabilities.
  8500. * This library borrows many concepts and ideas from the Date Instance
  8501. * Methods by Ken Snyder along with some parts of Ken's actual code.</p>
  8502. *
  8503. * <p>jsDate takes a different approach by not extending the built-in
  8504. * Date Object, improving date parsing, allowing for multiple formatting
  8505. * syntaxes and multiple and more easily expandable localization.</p>
  8506. *
  8507. * @author Chris Leonello
  8508. * @date #date#
  8509. * @version #VERSION#
  8510. * @copyright (c) 2010 Chris Leonello
  8511. * jsDate is currently available for use in all personal or commercial projects
  8512. * under both the MIT and GPL version 2.0 licenses. This means that you can
  8513. * choose the license that best suits your project and use it accordingly.
  8514. *
  8515. * <p>Ken's origianl Date Instance Methods and copyright notice:</p>
  8516. * <pre>
  8517. * Ken Snyder (ken d snyder at gmail dot com)
  8518. * 2008-09-10
  8519. * version 2.0.2 (http://kendsnyder.com/sandbox/date/)
  8520. * Creative Commons Attribution License 3.0 (http://creativecommons.org/licenses/by/3.0/)
  8521. * </pre>
  8522. *
  8523. * @class
  8524. * @name jsDate
  8525. * @param {String | Number | Array | Date&nbsp;Object | Options&nbsp;Object} arguments Optional arguments, either a parsable date/time string,
  8526. * a JavaScript timestamp, an array of numbers of form [year, month, day, hours, minutes, seconds, milliseconds],
  8527. * a Date object, or an options object of form {syntax: "perl", date:some Date} where all options are optional.
  8528. */
  8529. var jsDate = function () {
  8530. this.syntax = jsDate.config.syntax;
  8531. this._type = "jsDate";
  8532. this.proxy = new Date();
  8533. this.options = {};
  8534. this.locale = jsDate.regional.getLocale();
  8535. this.formatString = '';
  8536. this.defaultCentury = jsDate.config.defaultCentury;
  8537. switch ( arguments.length ) {
  8538. case 0:
  8539. break;
  8540. case 1:
  8541. // other objects either won't have a _type property or,
  8542. // if they do, it shouldn't be set to "jsDate", so
  8543. // assume it is an options argument.
  8544. if (get_type(arguments[0]) == "[object Object]" && arguments[0]._type != "jsDate") {
  8545. var opts = this.options = arguments[0];
  8546. this.syntax = opts.syntax || this.syntax;
  8547. this.defaultCentury = opts.defaultCentury || this.defaultCentury;
  8548. this.proxy = jsDate.createDate(opts.date);
  8549. }
  8550. else {
  8551. this.proxy = jsDate.createDate(arguments[0]);
  8552. }
  8553. break;
  8554. default:
  8555. var a = [];
  8556. for ( var i=0; i<arguments.length; i++ ) {
  8557. a.push(arguments[i]);
  8558. }
  8559. // this should be the current date/time?
  8560. this.proxy = new Date();
  8561. this.proxy.setFullYear.apply( this.proxy, a.slice(0,3) );
  8562. if ( a.slice(3).length ) {
  8563. this.proxy.setHours.apply( this.proxy, a.slice(3) );
  8564. }
  8565. break;
  8566. }
  8567. };
  8568. /**
  8569. * @namespace Configuration options that will be used as defaults for all instances on the page.
  8570. * @property {String} defaultLocale The default locale to use [en].
  8571. * @property {String} syntax The default syntax to use [perl].
  8572. * @property {Number} defaultCentury The default centry for 2 digit dates.
  8573. */
  8574. jsDate.config = {
  8575. defaultLocale: 'en',
  8576. syntax: 'perl',
  8577. defaultCentury: 1900
  8578. };
  8579. /**
  8580. * Add an arbitrary amount to the currently stored date
  8581. *
  8582. * @param {Number} number
  8583. * @param {String} unit
  8584. * @returns {jsDate}
  8585. */
  8586. jsDate.prototype.add = function(number, unit) {
  8587. var factor = multipliers[unit] || multipliers.day;
  8588. if (typeof factor == 'number') {
  8589. this.proxy.setTime(this.proxy.getTime() + (factor * number));
  8590. } else {
  8591. factor.add(this, number);
  8592. }
  8593. return this;
  8594. };
  8595. /**
  8596. * Create a new jqplot.date object with the same date
  8597. *
  8598. * @returns {jsDate}
  8599. */
  8600. jsDate.prototype.clone = function() {
  8601. return new jsDate(this.proxy.getTime());
  8602. };
  8603. /**
  8604. * Get the UTC TimeZone Offset of this date in milliseconds.
  8605. *
  8606. * @returns {Number}
  8607. */
  8608. jsDate.prototype.getUtcOffset = function() {
  8609. return this.proxy.getTimezoneOffset() * 60000;
  8610. };
  8611. /**
  8612. * Find the difference between this jsDate and another date.
  8613. *
  8614. * @param {String| Number| Array| jsDate&nbsp;Object| Date&nbsp;Object} dateObj
  8615. * @param {String} unit
  8616. * @param {Boolean} allowDecimal
  8617. * @returns {Number} Number of units difference between dates.
  8618. */
  8619. jsDate.prototype.diff = function(dateObj, unit, allowDecimal) {
  8620. // ensure we have a Date object
  8621. dateObj = new jsDate(dateObj);
  8622. if (dateObj === null) {
  8623. return null;
  8624. }
  8625. // get the multiplying factor integer or factor function
  8626. var factor = multipliers[unit] || multipliers.day;
  8627. if (typeof factor == 'number') {
  8628. // multiply
  8629. var unitDiff = (this.proxy.getTime() - dateObj.proxy.getTime()) / factor;
  8630. } else {
  8631. // run function
  8632. var unitDiff = factor.diff(this.proxy, dateObj.proxy);
  8633. }
  8634. // if decimals are not allowed, round toward zero
  8635. return (allowDecimal ? unitDiff : Math[unitDiff > 0 ? 'floor' : 'ceil'](unitDiff));
  8636. };
  8637. /**
  8638. * Get the abbreviated name of the current week day
  8639. *
  8640. * @returns {String}
  8641. */
  8642. jsDate.prototype.getAbbrDayName = function() {
  8643. return jsDate.regional[this.locale]["dayNamesShort"][this.proxy.getDay()];
  8644. };
  8645. /**
  8646. * Get the abbreviated name of the current month
  8647. *
  8648. * @returns {String}
  8649. */
  8650. jsDate.prototype.getAbbrMonthName = function() {
  8651. return jsDate.regional[this.locale]["monthNamesShort"][this.proxy.getMonth()];
  8652. };
  8653. /**
  8654. * Get UPPER CASE AM or PM for the current time
  8655. *
  8656. * @returns {String}
  8657. */
  8658. jsDate.prototype.getAMPM = function() {
  8659. return this.proxy.getHours() >= 12 ? 'PM' : 'AM';
  8660. };
  8661. /**
  8662. * Get lower case am or pm for the current time
  8663. *
  8664. * @returns {String}
  8665. */
  8666. jsDate.prototype.getAmPm = function() {
  8667. return this.proxy.getHours() >= 12 ? 'pm' : 'am';
  8668. };
  8669. /**
  8670. * Get the century (19 for 20th Century)
  8671. *
  8672. * @returns {Integer} Century (19 for 20th century).
  8673. */
  8674. jsDate.prototype.getCentury = function() {
  8675. return parseInt(this.proxy.getFullYear()/100, 10);
  8676. };
  8677. /**
  8678. * Implements Date functionality
  8679. */
  8680. jsDate.prototype.getDate = function() {
  8681. return this.proxy.getDate();
  8682. };
  8683. /**
  8684. * Implements Date functionality
  8685. */
  8686. jsDate.prototype.getDay = function() {
  8687. return this.proxy.getDay();
  8688. };
  8689. /**
  8690. * Get the Day of week 1 (Monday) thru 7 (Sunday)
  8691. *
  8692. * @returns {Integer} Day of week 1 (Monday) thru 7 (Sunday)
  8693. */
  8694. jsDate.prototype.getDayOfWeek = function() {
  8695. var dow = this.proxy.getDay();
  8696. return dow===0?7:dow;
  8697. };
  8698. /**
  8699. * Get the day of the year
  8700. *
  8701. * @returns {Integer} 1 - 366, day of the year
  8702. */
  8703. jsDate.prototype.getDayOfYear = function() {
  8704. var d = this.proxy;
  8705. var ms = d - new Date('' + d.getFullYear() + '/1/1 GMT');
  8706. ms += d.getTimezoneOffset()*60000;
  8707. d = null;
  8708. return parseInt(ms/60000/60/24, 10)+1;
  8709. };
  8710. /**
  8711. * Get the name of the current week day
  8712. *
  8713. * @returns {String}
  8714. */
  8715. jsDate.prototype.getDayName = function() {
  8716. return jsDate.regional[this.locale]["dayNames"][this.proxy.getDay()];
  8717. };
  8718. /**
  8719. * Get the week number of the given year, starting with the first Sunday as the first week
  8720. * @returns {Integer} Week number (13 for the 13th full week of the year).
  8721. */
  8722. jsDate.prototype.getFullWeekOfYear = function() {
  8723. var d = this.proxy;
  8724. var doy = this.getDayOfYear();
  8725. var rdow = 6-d.getDay();
  8726. var woy = parseInt((doy+rdow)/7, 10);
  8727. return woy;
  8728. };
  8729. /**
  8730. * Implements Date functionality
  8731. */
  8732. jsDate.prototype.getFullYear = function() {
  8733. return this.proxy.getFullYear();
  8734. };
  8735. /**
  8736. * Get the GMT offset in hours and minutes (e.g. +06:30)
  8737. *
  8738. * @returns {String}
  8739. */
  8740. jsDate.prototype.getGmtOffset = function() {
  8741. // divide the minutes offset by 60
  8742. var hours = this.proxy.getTimezoneOffset() / 60;
  8743. // decide if we are ahead of or behind GMT
  8744. var prefix = hours < 0 ? '+' : '-';
  8745. // remove the negative sign if any
  8746. hours = Math.abs(hours);
  8747. // add the +/- to the padded number of hours to : to the padded minutes
  8748. return prefix + addZeros(Math.floor(hours), 2) + ':' + addZeros((hours % 1) * 60, 2);
  8749. };
  8750. /**
  8751. * Implements Date functionality
  8752. */
  8753. jsDate.prototype.getHours = function() {
  8754. return this.proxy.getHours();
  8755. };
  8756. /**
  8757. * Get the current hour on a 12-hour scheme
  8758. *
  8759. * @returns {Integer}
  8760. */
  8761. jsDate.prototype.getHours12 = function() {
  8762. var hours = this.proxy.getHours();
  8763. return hours > 12 ? hours - 12 : (hours == 0 ? 12 : hours);
  8764. };
  8765. jsDate.prototype.getIsoWeek = function() {
  8766. var d = this.proxy;
  8767. var woy = d.getWeekOfYear();
  8768. var dow1_1 = (new Date('' + d.getFullYear() + '/1/1')).getDay();
  8769. // First week is 01 and not 00 as in the case of %U and %W,
  8770. // so we add 1 to the final result except if day 1 of the year
  8771. // is a Monday (then %W returns 01).
  8772. // We also need to subtract 1 if the day 1 of the year is
  8773. // Friday-Sunday, so the resulting equation becomes:
  8774. var idow = woy + (dow1_1 > 4 || dow1_1 <= 1 ? 0 : 1);
  8775. if(idow == 53 && (new Date('' + d.getFullYear() + '/12/31')).getDay() < 4)
  8776. {
  8777. idow = 1;
  8778. }
  8779. else if(idow === 0)
  8780. {
  8781. d = new jsDate(new Date('' + (d.getFullYear()-1) + '/12/31'));
  8782. idow = d.getIsoWeek();
  8783. }
  8784. d = null;
  8785. return idow;
  8786. };
  8787. /**
  8788. * Implements Date functionality
  8789. */
  8790. jsDate.prototype.getMilliseconds = function() {
  8791. return this.proxy.getMilliseconds();
  8792. };
  8793. /**
  8794. * Implements Date functionality
  8795. */
  8796. jsDate.prototype.getMinutes = function() {
  8797. return this.proxy.getMinutes();
  8798. };
  8799. /**
  8800. * Implements Date functionality
  8801. */
  8802. jsDate.prototype.getMonth = function() {
  8803. return this.proxy.getMonth();
  8804. };
  8805. /**
  8806. * Get the name of the current month
  8807. *
  8808. * @returns {String}
  8809. */
  8810. jsDate.prototype.getMonthName = function() {
  8811. return jsDate.regional[this.locale]["monthNames"][this.proxy.getMonth()];
  8812. };
  8813. /**
  8814. * Get the number of the current month, 1-12
  8815. *
  8816. * @returns {Integer}
  8817. */
  8818. jsDate.prototype.getMonthNumber = function() {
  8819. return this.proxy.getMonth() + 1;
  8820. };
  8821. /**
  8822. * Implements Date functionality
  8823. */
  8824. jsDate.prototype.getSeconds = function() {
  8825. return this.proxy.getSeconds();
  8826. };
  8827. /**
  8828. * Return a proper two-digit year integer
  8829. *
  8830. * @returns {Integer}
  8831. */
  8832. jsDate.prototype.getShortYear = function() {
  8833. return this.proxy.getYear() % 100;
  8834. };
  8835. /**
  8836. * Implements Date functionality
  8837. */
  8838. jsDate.prototype.getTime = function() {
  8839. return this.proxy.getTime();
  8840. };
  8841. /**
  8842. * Get the timezone abbreviation
  8843. *
  8844. * @returns {String} Abbreviation for the timezone
  8845. */
  8846. jsDate.prototype.getTimezoneAbbr = function() {
  8847. return this.proxy.toString().replace(/^.*\(([^)]+)\)$/, '$1');
  8848. };
  8849. /**
  8850. * Get the browser-reported name for the current timezone (e.g. MDT, Mountain Daylight Time)
  8851. *
  8852. * @returns {String}
  8853. */
  8854. jsDate.prototype.getTimezoneName = function() {
  8855. var match = /(?:\((.+)\)$| ([A-Z]{3}) )/.exec(this.toString());
  8856. return match[1] || match[2] || 'GMT' + this.getGmtOffset();
  8857. };
  8858. /**
  8859. * Implements Date functionality
  8860. */
  8861. jsDate.prototype.getTimezoneOffset = function() {
  8862. return this.proxy.getTimezoneOffset();
  8863. };
  8864. /**
  8865. * Get the week number of the given year, starting with the first Monday as the first week
  8866. * @returns {Integer} Week number (13 for the 13th week of the year).
  8867. */
  8868. jsDate.prototype.getWeekOfYear = function() {
  8869. var doy = this.getDayOfYear();
  8870. var rdow = 7 - this.getDayOfWeek();
  8871. var woy = parseInt((doy+rdow)/7, 10);
  8872. return woy;
  8873. };
  8874. /**
  8875. * Get the current date as a Unix timestamp
  8876. *
  8877. * @returns {Integer}
  8878. */
  8879. jsDate.prototype.getUnix = function() {
  8880. return Math.round(this.proxy.getTime() / 1000, 0);
  8881. };
  8882. /**
  8883. * Implements Date functionality
  8884. */
  8885. jsDate.prototype.getYear = function() {
  8886. return this.proxy.getYear();
  8887. };
  8888. /**
  8889. * Return a date one day ahead (or any other unit)
  8890. *
  8891. * @param {String} unit Optional, year | month | day | week | hour | minute | second | millisecond
  8892. * @returns {jsDate}
  8893. */
  8894. jsDate.prototype.next = function(unit) {
  8895. unit = unit || 'day';
  8896. return this.clone().add(1, unit);
  8897. };
  8898. /**
  8899. * Set the jsDate instance to a new date.
  8900. *
  8901. * @param {String | Number | Array | Date Object | jsDate Object | Options Object} arguments Optional arguments,
  8902. * either a parsable date/time string,
  8903. * a JavaScript timestamp, an array of numbers of form [year, month, day, hours, minutes, seconds, milliseconds],
  8904. * a Date object, jsDate Object or an options object of form {syntax: "perl", date:some Date} where all options are optional.
  8905. */
  8906. jsDate.prototype.set = function() {
  8907. switch ( arguments.length ) {
  8908. case 0:
  8909. this.proxy = new Date();
  8910. break;
  8911. case 1:
  8912. // other objects either won't have a _type property or,
  8913. // if they do, it shouldn't be set to "jsDate", so
  8914. // assume it is an options argument.
  8915. if (get_type(arguments[0]) == "[object Object]" && arguments[0]._type != "jsDate") {
  8916. var opts = this.options = arguments[0];
  8917. this.syntax = opts.syntax || this.syntax;
  8918. this.defaultCentury = opts.defaultCentury || this.defaultCentury;
  8919. this.proxy = jsDate.createDate(opts.date);
  8920. }
  8921. else {
  8922. this.proxy = jsDate.createDate(arguments[0]);
  8923. }
  8924. break;
  8925. default:
  8926. var a = [];
  8927. for ( var i=0; i<arguments.length; i++ ) {
  8928. a.push(arguments[i]);
  8929. }
  8930. // this should be the current date/time
  8931. this.proxy = new Date();
  8932. this.proxy.setFullYear.apply( this.proxy, a.slice(0,3) );
  8933. if ( a.slice(3).length ) {
  8934. this.proxy.setHours.apply( this.proxy, a.slice(3) );
  8935. }
  8936. break;
  8937. }
  8938. return this;
  8939. };
  8940. /**
  8941. * Sets the day of the month for a specified date according to local time.
  8942. * @param {Integer} dayValue An integer from 1 to 31, representing the day of the month.
  8943. */
  8944. jsDate.prototype.setDate = function(n) {
  8945. this.proxy.setDate(n);
  8946. return this;
  8947. };
  8948. /**
  8949. * Sets the full year for a specified date according to local time.
  8950. * @param {Integer} yearValue The numeric value of the year, for example, 1995.
  8951. * @param {Integer} monthValue Optional, between 0 and 11 representing the months January through December.
  8952. * @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.
  8953. */
  8954. jsDate.prototype.setFullYear = function() {
  8955. this.proxy.setFullYear.apply(this.proxy, arguments);
  8956. return this;
  8957. };
  8958. /**
  8959. * Sets the hours for a specified date according to local time.
  8960. *
  8961. * @param {Integer} hoursValue An integer between 0 and 23, representing the hour.
  8962. * @param {Integer} minutesValue Optional, An integer between 0 and 59, representing the minutes.
  8963. * @param {Integer} secondsValue Optional, An integer between 0 and 59, representing the seconds.
  8964. * If you specify the secondsValue parameter, you must also specify the minutesValue.
  8965. * @param {Integer} msValue Optional, A number between 0 and 999, representing the milliseconds.
  8966. * If you specify the msValue parameter, you must also specify the minutesValue and secondsValue.
  8967. */
  8968. jsDate.prototype.setHours = function() {
  8969. this.proxy.setHours.apply(this.proxy, arguments);
  8970. return this;
  8971. };
  8972. /**
  8973. * Implements Date functionality
  8974. */
  8975. jsDate.prototype.setMilliseconds = function(n) {
  8976. this.proxy.setMilliseconds(n);
  8977. return this;
  8978. };
  8979. /**
  8980. * Implements Date functionality
  8981. */
  8982. jsDate.prototype.setMinutes = function() {
  8983. this.proxy.setMinutes.apply(this.proxy, arguments);
  8984. return this;
  8985. };
  8986. /**
  8987. * Implements Date functionality
  8988. */
  8989. jsDate.prototype.setMonth = function() {
  8990. this.proxy.setMonth.apply(this.proxy, arguments);
  8991. return this;
  8992. };
  8993. /**
  8994. * Implements Date functionality
  8995. */
  8996. jsDate.prototype.setSeconds = function() {
  8997. this.proxy.setSeconds.apply(this.proxy, arguments);
  8998. return this;
  8999. };
  9000. /**
  9001. * Implements Date functionality
  9002. */
  9003. jsDate.prototype.setTime = function(n) {
  9004. this.proxy.setTime(n);
  9005. return this;
  9006. };
  9007. /**
  9008. * Implements Date functionality
  9009. */
  9010. jsDate.prototype.setYear = function() {
  9011. this.proxy.setYear.apply(this.proxy, arguments);
  9012. return this;
  9013. };
  9014. /**
  9015. * Provide a formatted string representation of this date.
  9016. *
  9017. * @param {String} formatString A format string.
  9018. * See: {@link jsDate.formats}.
  9019. * @returns {String} Date String.
  9020. */
  9021. jsDate.prototype.strftime = function(formatString) {
  9022. formatString = formatString || this.formatString || jsDate.regional[this.locale]['formatString'];
  9023. return jsDate.strftime(this, formatString, this.syntax);
  9024. };
  9025. /**
  9026. * Return a String representation of this jsDate object.
  9027. * @returns {String} Date string.
  9028. */
  9029. jsDate.prototype.toString = function() {
  9030. return this.proxy.toString();
  9031. };
  9032. /**
  9033. * Convert the current date to an 8-digit integer (%Y%m%d)
  9034. *
  9035. * @returns {Integer}
  9036. */
  9037. jsDate.prototype.toYmdInt = function() {
  9038. return (this.proxy.getFullYear() * 10000) + (this.getMonthNumber() * 100) + this.proxy.getDate();
  9039. };
  9040. /**
  9041. * @namespace Holds localizations for month/day names.
  9042. * <p>jsDate attempts to detect locale when loaded and defaults to 'en'.
  9043. * If a localization is detected which is not available, jsDate defaults to 'en'.
  9044. * Additional localizations can be added after jsDate loads. After adding a localization,
  9045. * call the jsDate.regional.getLocale() method. Currently, en, fr and de are defined.</p>
  9046. *
  9047. * <p>Localizations must be an object and have the following properties defined: monthNames, monthNamesShort, dayNames, dayNamesShort and Localizations are added like:</p>
  9048. * <pre class="code">
  9049. * jsDate.regional['en'] = {
  9050. * monthNames : 'January February March April May June July August September October November December'.split(' '),
  9051. * monthNamesShort : 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' '),
  9052. * dayNames : 'Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split(' '),
  9053. * dayNamesShort : 'Sun Mon Tue Wed Thu Fri Sat'.split(' ')
  9054. * };
  9055. * </pre>
  9056. * <p>After adding localizations, call <code>jsDate.regional.getLocale();</code> to update the locale setting with the
  9057. * new localizations.</p>
  9058. */
  9059. jsDate.regional = {
  9060. 'en': {
  9061. monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December'],
  9062. monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  9063. dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  9064. dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  9065. formatString: '%Y-%m-%d %H:%M:%S'
  9066. },
  9067. 'fr': {
  9068. monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
  9069. monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun','Jul','Aoû','Sep','Oct','Nov','Déc'],
  9070. dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
  9071. dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
  9072. formatString: '%Y-%m-%d %H:%M:%S'
  9073. },
  9074. 'de': {
  9075. monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'],
  9076. monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'],
  9077. dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
  9078. dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
  9079. formatString: '%Y-%m-%d %H:%M:%S'
  9080. },
  9081. 'es': {
  9082. monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio', 'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
  9083. monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun', 'Jul','Ago','Sep','Oct','Nov','Dic'],
  9084. dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
  9085. dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
  9086. formatString: '%Y-%m-%d %H:%M:%S'
  9087. },
  9088. 'ru': {
  9089. monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
  9090. monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн','Июл','Авг','Сен','Окт','Ноя','Дек'],
  9091. dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
  9092. dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
  9093. formatString: '%Y-%m-%d %H:%M:%S'
  9094. },
  9095. 'ar': {
  9096. monthNames: ['كانون الثاني', 'شباط', 'آذار', 'نيسان', 'آذار', 'حزيران','تموز', 'آب', 'أيلول', 'تشرين الأول', 'تشرين الثاني', 'كانون الأول'],
  9097. monthNamesShort: ['1','2','3','4','5','6','7','8','9','10','11','12'],
  9098. dayNames: ['السبت', 'الأحد', 'الاثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة'],
  9099. dayNamesShort: ['سبت', 'أحد', 'اثنين', 'ثلاثاء', 'أربعاء', 'خميس', 'جمعة'],
  9100. formatString: '%Y-%m-%d %H:%M:%S'
  9101. },
  9102. 'pt': {
  9103. monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
  9104. monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
  9105. dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','S&aacute;bado'],
  9106. dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','S&aacute;b'],
  9107. formatString: '%Y-%m-%d %H:%M:%S'
  9108. },
  9109. 'pt-BR': {
  9110. monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho', 'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
  9111. monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
  9112. dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','S&aacute;bado'],
  9113. dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','S&aacute;b'],
  9114. formatString: '%Y-%m-%d %H:%M:%S'
  9115. }
  9116. };
  9117. // Set english variants to 'en'
  9118. jsDate.regional['en-US'] = jsDate.regional['en-GB'] = jsDate.regional['en'];
  9119. /**
  9120. * Try to determine the users locale based on the lang attribute of the html page. Defaults to 'en'
  9121. * if it cannot figure out a locale of if the locale does not have a localization defined.
  9122. * @returns {String} locale
  9123. */
  9124. jsDate.regional.getLocale = function () {
  9125. var l = jsDate.config.defaultLocale;
  9126. if ( document && document.getElementsByTagName('html') && document.getElementsByTagName('html')[0].lang ) {
  9127. l = document.getElementsByTagName('html')[0].lang;
  9128. if (!jsDate.regional.hasOwnProperty(l)) {
  9129. l = jsDate.config.defaultLocale;
  9130. }
  9131. }
  9132. return l;
  9133. };
  9134. // ms in day
  9135. var day = 24 * 60 * 60 * 1000;
  9136. // padd a number with zeros
  9137. var addZeros = function(num, digits) {
  9138. num = String(num);
  9139. var i = digits - num.length;
  9140. var s = String(Math.pow(10, i)).slice(1);
  9141. return s.concat(num);
  9142. };
  9143. // representations used for calculating differences between dates.
  9144. // This borrows heavily from Ken Snyder's work.
  9145. var multipliers = {
  9146. millisecond: 1,
  9147. second: 1000,
  9148. minute: 60 * 1000,
  9149. hour: 60 * 60 * 1000,
  9150. day: day,
  9151. week: 7 * day,
  9152. month: {
  9153. // add a number of months
  9154. add: function(d, number) {
  9155. // add any years needed (increments of 12)
  9156. multipliers.year.add(d, Math[number > 0 ? 'floor' : 'ceil'](number / 12));
  9157. // ensure that we properly wrap betwen December and January
  9158. // 11 % 12 = 11
  9159. // 12 % 12 = 0
  9160. var prevMonth = d.getMonth() + (number % 12);
  9161. if (prevMonth == 12) {
  9162. prevMonth = 0;
  9163. d.setYear(d.getFullYear() + 1);
  9164. } else if (prevMonth == -1) {
  9165. prevMonth = 11;
  9166. d.setYear(d.getFullYear() - 1);
  9167. }
  9168. d.setMonth(prevMonth);
  9169. },
  9170. // get the number of months between two Date objects (decimal to the nearest day)
  9171. diff: function(d1, d2) {
  9172. // get the number of years
  9173. var diffYears = d1.getFullYear() - d2.getFullYear();
  9174. // get the number of remaining months
  9175. var diffMonths = d1.getMonth() - d2.getMonth() + (diffYears * 12);
  9176. // get the number of remaining days
  9177. var diffDays = d1.getDate() - d2.getDate();
  9178. // return the month difference with the days difference as a decimal
  9179. return diffMonths + (diffDays / 30);
  9180. }
  9181. },
  9182. year: {
  9183. // add a number of years
  9184. add: function(d, number) {
  9185. d.setYear(d.getFullYear() + Math[number > 0 ? 'floor' : 'ceil'](number));
  9186. },
  9187. // get the number of years between two Date objects (decimal to the nearest day)
  9188. diff: function(d1, d2) {
  9189. return multipliers.month.diff(d1, d2) / 12;
  9190. }
  9191. }
  9192. };
  9193. //
  9194. // Alias each multiplier with an 's' to allow 'year' and 'years' for example.
  9195. // This comes from Ken Snyders work.
  9196. //
  9197. for (var unit in multipliers) {
  9198. if (unit.substring(unit.length - 1) != 's') { // IE will iterate newly added properties :|
  9199. multipliers[unit + 's'] = multipliers[unit];
  9200. }
  9201. }
  9202. //
  9203. // take a jsDate instance and a format code and return the formatted value.
  9204. // This is a somewhat modified version of Ken Snyder's method.
  9205. //
  9206. var format = function(d, code, syntax) {
  9207. // if shorcut codes are used, recursively expand those.
  9208. if (jsDate.formats[syntax]["shortcuts"][code]) {
  9209. return jsDate.strftime(d, jsDate.formats[syntax]["shortcuts"][code], syntax);
  9210. } else {
  9211. // get the format code function and addZeros() argument
  9212. var getter = (jsDate.formats[syntax]["codes"][code] || '').split('.');
  9213. var nbr = d['get' + getter[0]] ? d['get' + getter[0]]() : '';
  9214. if (getter[1]) {
  9215. nbr = addZeros(nbr, getter[1]);
  9216. }
  9217. return nbr;
  9218. }
  9219. };
  9220. /**
  9221. * @static
  9222. * Static function for convert a date to a string according to a given format. Also acts as namespace for strftime format codes.
  9223. * <p>strftime formatting can be accomplished without creating a jsDate object by calling jsDate.strftime():</p>
  9224. * <pre class="code">
  9225. * var formattedDate = jsDate.strftime('Feb 8, 2006 8:48:32', '%Y-%m-%d %H:%M:%S');
  9226. * </pre>
  9227. * @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.
  9228. * @param {String} formatString String with embedded date formatting codes.
  9229. * See: {@link jsDate.formats}.
  9230. * @param {String} syntax Optional syntax to use [default perl].
  9231. * @param {String} locale Optional locale to use.
  9232. * @returns {String} Formatted representation of the date.
  9233. */
  9234. //
  9235. // Logic as implemented here is very similar to Ken Snyder's Date Instance Methods.
  9236. //
  9237. jsDate.strftime = function(d, formatString, syntax, locale) {
  9238. var syn = 'perl';
  9239. var loc = jsDate.regional.getLocale();
  9240. // check if syntax and locale are available or reversed
  9241. if (syntax && jsDate.formats.hasOwnProperty(syntax)) {
  9242. syn = syntax;
  9243. }
  9244. else if (syntax && jsDate.regional.hasOwnProperty(syntax)) {
  9245. loc = syntax;
  9246. }
  9247. if (locale && jsDate.formats.hasOwnProperty(locale)) {
  9248. syn = locale;
  9249. }
  9250. else if (locale && jsDate.regional.hasOwnProperty(locale)) {
  9251. loc = locale;
  9252. }
  9253. if (get_type(d) != "[object Object]" || d._type != "jsDate") {
  9254. d = new jsDate(d);
  9255. d.locale = loc;
  9256. }
  9257. if (!formatString) {
  9258. formatString = d.formatString || jsDate.regional[loc]['formatString'];
  9259. }
  9260. // default the format string to year-month-day
  9261. var source = formatString || '%Y-%m-%d',
  9262. result = '',
  9263. match;
  9264. // replace each format code
  9265. while (source.length > 0) {
  9266. if (match = source.match(jsDate.formats[syn].codes.matcher)) {
  9267. result += source.slice(0, match.index);
  9268. result += (match[1] || '') + format(d, match[2], syn);
  9269. source = source.slice(match.index + match[0].length);
  9270. } else {
  9271. result += source;
  9272. source = '';
  9273. }
  9274. }
  9275. return result;
  9276. };
  9277. /**
  9278. * @namespace
  9279. * Namespace to hold format codes and format shortcuts. "perl" and "php" format codes
  9280. * and shortcuts are defined by default. Additional codes and shortcuts can be
  9281. * added like:
  9282. *
  9283. * <pre class="code">
  9284. * jsDate.formats["perl"] = {
  9285. * "codes": {
  9286. * matcher: /someregex/,
  9287. * Y: "fullYear", // name of "get" method without the "get",
  9288. * ..., // more codes
  9289. * },
  9290. * "shortcuts": {
  9291. * F: '%Y-%m-%d',
  9292. * ..., // more shortcuts
  9293. * }
  9294. * };
  9295. * </pre>
  9296. *
  9297. * <p>Additionally, ISO and SQL shortcuts are defined and can be accesses via:
  9298. * <code>jsDate.formats.ISO</code> and <code>jsDate.formats.SQL</code>
  9299. */
  9300. jsDate.formats = {
  9301. ISO:'%Y-%m-%dT%H:%M:%S.%N%G',
  9302. SQL:'%Y-%m-%d %H:%M:%S'
  9303. };
  9304. /**
  9305. * Perl format codes and shortcuts for strftime.
  9306. *
  9307. * A hash (object) of codes where each code must be an array where the first member is
  9308. * the name of a Date.prototype or jsDate.prototype function to call
  9309. * and optionally a second member indicating the number to pass to addZeros()
  9310. *
  9311. * <p>The following format codes are defined:</p>
  9312. *
  9313. * <pre class="code">
  9314. * Code Result Description
  9315. * == Years ==
  9316. * %Y 2008 Four-digit year
  9317. * %y 08 Two-digit year
  9318. *
  9319. * == Months ==
  9320. * %m 09 Two-digit month
  9321. * %#m 9 One or two-digit month
  9322. * %B September Full month name
  9323. * %b Sep Abbreviated month name
  9324. *
  9325. * == Days ==
  9326. * %d 05 Two-digit day of month
  9327. * %#d 5 One or two-digit day of month
  9328. * %e 5 One or two-digit day of month
  9329. * %A Sunday Full name of the day of the week
  9330. * %a Sun Abbreviated name of the day of the week
  9331. * %w 0 Number of the day of the week (0 = Sunday, 6 = Saturday)
  9332. *
  9333. * == Hours ==
  9334. * %H 23 Hours in 24-hour format (two digits)
  9335. * %#H 3 Hours in 24-hour integer format (one or two digits)
  9336. * %I 11 Hours in 12-hour format (two digits)
  9337. * %#I 3 Hours in 12-hour integer format (one or two digits)
  9338. * %p PM AM or PM
  9339. *
  9340. * == Minutes ==
  9341. * %M 09 Minutes (two digits)
  9342. * %#M 9 Minutes (one or two digits)
  9343. *
  9344. * == Seconds ==
  9345. * %S 02 Seconds (two digits)
  9346. * %#S 2 Seconds (one or two digits)
  9347. * %s 1206567625723 Unix timestamp (Seconds past 1970-01-01 00:00:00)
  9348. *
  9349. * == Milliseconds ==
  9350. * %N 008 Milliseconds (three digits)
  9351. * %#N 8 Milliseconds (one to three digits)
  9352. *
  9353. * == Timezone ==
  9354. * %O 360 difference in minutes between local time and GMT
  9355. * %Z Mountain Standard Time Name of timezone as reported by browser
  9356. * %G 06:00 Hours and minutes between GMT
  9357. *
  9358. * == Shortcuts ==
  9359. * %F 2008-03-26 %Y-%m-%d
  9360. * %T 05:06:30 %H:%M:%S
  9361. * %X 05:06:30 %H:%M:%S
  9362. * %x 03/26/08 %m/%d/%y
  9363. * %D 03/26/08 %m/%d/%y
  9364. * %#c Wed Mar 26 15:31:00 2008 %a %b %e %H:%M:%S %Y
  9365. * %v 3-Sep-2008 %e-%b-%Y
  9366. * %R 15:31 %H:%M
  9367. * %r 03:31:00 PM %I:%M:%S %p
  9368. *
  9369. * == Characters ==
  9370. * %n \n Newline
  9371. * %t \t Tab
  9372. * %% % Percent Symbol
  9373. * </pre>
  9374. *
  9375. * <p>Formatting shortcuts that will be translated into their longer version.
  9376. * Be sure that format shortcuts do not refer to themselves: this will cause an infinite loop.</p>
  9377. *
  9378. * <p>Format codes and format shortcuts can be redefined after the jsDate
  9379. * module is imported.</p>
  9380. *
  9381. * <p>Note that if you redefine the whole hash (object), you must supply a "matcher"
  9382. * regex for the parser. The default matcher is:</p>
  9383. *
  9384. * <code>/()%(#?(%|[a-z]))/i</code>
  9385. *
  9386. * <p>which corresponds to the Perl syntax used by default.</p>
  9387. *
  9388. * <p>By customizing the matcher and format codes, nearly any strftime functionality is possible.</p>
  9389. */
  9390. jsDate.formats.perl = {
  9391. codes: {
  9392. //
  9393. // 2-part regex matcher for format codes
  9394. //
  9395. // first match must be the character before the code (to account for escaping)
  9396. // second match must be the format code character(s)
  9397. //
  9398. matcher: /()%(#?(%|[a-z]))/i,
  9399. // year
  9400. Y: 'FullYear',
  9401. y: 'ShortYear.2',
  9402. // month
  9403. m: 'MonthNumber.2',
  9404. '#m': 'MonthNumber',
  9405. B: 'MonthName',
  9406. b: 'AbbrMonthName',
  9407. // day
  9408. d: 'Date.2',
  9409. '#d': 'Date',
  9410. e: 'Date',
  9411. A: 'DayName',
  9412. a: 'AbbrDayName',
  9413. w: 'Day',
  9414. // hours
  9415. H: 'Hours.2',
  9416. '#H': 'Hours',
  9417. I: 'Hours12.2',
  9418. '#I': 'Hours12',
  9419. p: 'AMPM',
  9420. // minutes
  9421. M: 'Minutes.2',
  9422. '#M': 'Minutes',
  9423. // seconds
  9424. S: 'Seconds.2',
  9425. '#S': 'Seconds',
  9426. s: 'Unix',
  9427. // milliseconds
  9428. N: 'Milliseconds.3',
  9429. '#N': 'Milliseconds',
  9430. // timezone
  9431. O: 'TimezoneOffset',
  9432. Z: 'TimezoneName',
  9433. G: 'GmtOffset'
  9434. },
  9435. shortcuts: {
  9436. // date
  9437. F: '%Y-%m-%d',
  9438. // time
  9439. T: '%H:%M:%S',
  9440. X: '%H:%M:%S',
  9441. // local format date
  9442. x: '%m/%d/%y',
  9443. D: '%m/%d/%y',
  9444. // local format extended
  9445. '#c': '%a %b %e %H:%M:%S %Y',
  9446. // local format short
  9447. v: '%e-%b-%Y',
  9448. R: '%H:%M',
  9449. r: '%I:%M:%S %p',
  9450. // tab and newline
  9451. t: '\t',
  9452. n: '\n',
  9453. '%': '%'
  9454. }
  9455. };
  9456. /**
  9457. * PHP format codes and shortcuts for strftime.
  9458. *
  9459. * A hash (object) of codes where each code must be an array where the first member is
  9460. * the name of a Date.prototype or jsDate.prototype function to call
  9461. * and optionally a second member indicating the number to pass to addZeros()
  9462. *
  9463. * <p>The following format codes are defined:</p>
  9464. *
  9465. * <pre class="code">
  9466. * Code Result Description
  9467. * === Days ===
  9468. * %a Sun through Sat An abbreviated textual representation of the day
  9469. * %A Sunday - Saturday A full textual representation of the day
  9470. * %d 01 to 31 Two-digit day of the month (with leading zeros)
  9471. * %e 1 to 31 Day of the month, with a space preceding single digits.
  9472. * %j 001 to 366 Day of the year, 3 digits with leading zeros
  9473. * %u 1 - 7 (Mon - Sun) ISO-8601 numeric representation of the day of the week
  9474. * %w 0 - 6 (Sun - Sat) Numeric representation of the day of the week
  9475. *
  9476. * === Week ===
  9477. * %U 13 Full Week number, starting with the first Sunday as the first week
  9478. * %V 01 through 53 ISO-8601:1988 week number, starting with the first week of the year
  9479. * with at least 4 weekdays, with Monday being the start of the week
  9480. * %W 46 A numeric representation of the week of the year,
  9481. * starting with the first Monday as the first week
  9482. * === Month ===
  9483. * %b Jan through Dec Abbreviated month name, based on the locale
  9484. * %B January - December Full month name, based on the locale
  9485. * %h Jan through Dec Abbreviated month name, based on the locale (an alias of %b)
  9486. * %m 01 - 12 (Jan - Dec) Two digit representation of the month
  9487. *
  9488. * === Year ===
  9489. * %C 19 Two digit century (year/100, truncated to an integer)
  9490. * %y 09 for 2009 Two digit year
  9491. * %Y 2038 Four digit year
  9492. *
  9493. * === Time ===
  9494. * %H 00 through 23 Two digit representation of the hour in 24-hour format
  9495. * %I 01 through 12 Two digit representation of the hour in 12-hour format
  9496. * %l 1 through 12 Hour in 12-hour format, with a space preceeding single digits
  9497. * %M 00 through 59 Two digit representation of the minute
  9498. * %p AM/PM UPPER-CASE 'AM' or 'PM' based on the given time
  9499. * %P am/pm lower-case 'am' or 'pm' based on the given time
  9500. * %r 09:34:17 PM Same as %I:%M:%S %p
  9501. * %R 00:35 Same as %H:%M
  9502. * %S 00 through 59 Two digit representation of the second
  9503. * %T 21:34:17 Same as %H:%M:%S
  9504. * %X 03:59:16 Preferred time representation based on locale, without the date
  9505. * %z -0500 or EST Either the time zone offset from UTC or the abbreviation
  9506. * %Z -0500 or EST The time zone offset/abbreviation option NOT given by %z
  9507. *
  9508. * === Time and Date ===
  9509. * %D 02/05/09 Same as %m/%d/%y
  9510. * %F 2009-02-05 Same as %Y-%m-%d (commonly used in database datestamps)
  9511. * %s 305815200 Unix Epoch Time timestamp (same as the time() function)
  9512. * %x 02/05/09 Preferred date representation, without the time
  9513. *
  9514. * === Miscellaneous ===
  9515. * %n --- A newline character (\n)
  9516. * %t --- A Tab character (\t)
  9517. * %% --- A literal percentage character (%)
  9518. * </pre>
  9519. */
  9520. jsDate.formats.php = {
  9521. codes: {
  9522. //
  9523. // 2-part regex matcher for format codes
  9524. //
  9525. // first match must be the character before the code (to account for escaping)
  9526. // second match must be the format code character(s)
  9527. //
  9528. matcher: /()%((%|[a-z]))/i,
  9529. // day
  9530. a: 'AbbrDayName',
  9531. A: 'DayName',
  9532. d: 'Date.2',
  9533. e: 'Date',
  9534. j: 'DayOfYear.3',
  9535. u: 'DayOfWeek',
  9536. w: 'Day',
  9537. // week
  9538. U: 'FullWeekOfYear.2',
  9539. V: 'IsoWeek.2',
  9540. W: 'WeekOfYear.2',
  9541. // month
  9542. b: 'AbbrMonthName',
  9543. B: 'MonthName',
  9544. m: 'MonthNumber.2',
  9545. h: 'AbbrMonthName',
  9546. // year
  9547. C: 'Century.2',
  9548. y: 'ShortYear.2',
  9549. Y: 'FullYear',
  9550. // time
  9551. H: 'Hours.2',
  9552. I: 'Hours12.2',
  9553. l: 'Hours12',
  9554. p: 'AMPM',
  9555. P: 'AmPm',
  9556. M: 'Minutes.2',
  9557. S: 'Seconds.2',
  9558. s: 'Unix',
  9559. O: 'TimezoneOffset',
  9560. z: 'GmtOffset',
  9561. Z: 'TimezoneAbbr'
  9562. },
  9563. shortcuts: {
  9564. D: '%m/%d/%y',
  9565. F: '%Y-%m-%d',
  9566. T: '%H:%M:%S',
  9567. X: '%H:%M:%S',
  9568. x: '%m/%d/%y',
  9569. R: '%H:%M',
  9570. r: '%I:%M:%S %p',
  9571. t: '\t',
  9572. n: '\n',
  9573. '%': '%'
  9574. }
  9575. };
  9576. //
  9577. // Conceptually, the logic implemented here is similar to Ken Snyder's Date Instance Methods.
  9578. // I use his idea of a set of parsers which can be regular expressions or functions,
  9579. // iterating through those, and then seeing if Date.parse() will create a date.
  9580. // The parser expressions and functions are a little different and some bugs have been
  9581. // worked out. Also, a lot of "pre-parsing" is done to fix implementation
  9582. // variations of Date.parse() between browsers.
  9583. //
  9584. jsDate.createDate = function(date) {
  9585. // if passing in multiple arguments, try Date constructor
  9586. if (date == null) {
  9587. return new Date();
  9588. }
  9589. // If the passed value is already a date object, return it
  9590. if (date instanceof Date) {
  9591. return date;
  9592. }
  9593. // if (typeof date == 'number') return new Date(date * 1000);
  9594. // If the passed value is an integer, interpret it as a javascript timestamp
  9595. if (typeof date == 'number') {
  9596. return new Date(date);
  9597. }
  9598. // Before passing strings into Date.parse(), have to normalize them for certain conditions.
  9599. // If strings are not formatted staccording to the EcmaScript spec, results from Date parse will be implementation dependent.
  9600. //
  9601. // For example:
  9602. // * FF and Opera assume 2 digit dates are pre y2k, Chome assumes <50 is pre y2k, 50+ is 21st century.
  9603. // * Chrome will correctly parse '1984-1-25' into localtime, FF and Opera will not parse.
  9604. // * Both FF, Chrome and Opera will parse '1984/1/25' into localtime.
  9605. // remove leading and trailing spaces
  9606. var parsable = String(date).replace(/^\s*(.+)\s*$/g, '$1');
  9607. // replace dahses (-) with slashes (/) in dates like n[nnn]/n[n]/n[nnn]
  9608. parsable = parsable.replace(/^([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,4})/, "$1/$2/$3");
  9609. /////////
  9610. // Need to check for '15-Dec-09' also.
  9611. // FF will not parse, but Chrome will.
  9612. // Chrome will set date to 2009 as well.
  9613. /////////
  9614. // first check for 'dd-mmm-yyyy' or 'dd/mmm/yyyy' like '15-Dec-2010'
  9615. parsable = parsable.replace(/^(3[01]|[0-2]?\d)[-\/]([a-z]{3,})[-\/](\d{4})/i, "$1 $2 $3");
  9616. // Now check for 'dd-mmm-yy' or 'dd/mmm/yy' and normalize years to default century.
  9617. var match = parsable.match(/^(3[01]|[0-2]?\d)[-\/]([a-z]{3,})[-\/](\d{2})\D*/i);
  9618. if (match && match.length > 3) {
  9619. var m3 = parseFloat(match[3]);
  9620. var ny = jsDate.config.defaultCentury + m3;
  9621. ny = String(ny);
  9622. // now replace 2 digit year with 4 digit year
  9623. parsable = parsable.replace(/^(3[01]|[0-2]?\d)[-\/]([a-z]{3,})[-\/](\d{2})\D*/i, match[1] +' '+ match[2] +' '+ ny);
  9624. }
  9625. // Check for '1/19/70 8:14PM'
  9626. // where starts with mm/dd/yy or yy/mm/dd and have something after
  9627. // Check if 1st postiion is greater than 31, assume it is year.
  9628. // Assme all 2 digit years are 1900's.
  9629. // Finally, change them into US style mm/dd/yyyy representations.
  9630. match = parsable.match(/^([0-9]{1,2})[-\/]([0-9]{1,2})[-\/]([0-9]{1,2})[^0-9]/);
  9631. function h1(parsable, match) {
  9632. var m1 = parseFloat(match[1]);
  9633. var m2 = parseFloat(match[2]);
  9634. var m3 = parseFloat(match[3]);
  9635. var cent = jsDate.config.defaultCentury;
  9636. var ny, nd, nm, str;
  9637. if (m1 > 31) { // first number is a year
  9638. nd = m3;
  9639. nm = m2;
  9640. ny = cent + m1;
  9641. }
  9642. else { // last number is the year
  9643. nd = m2;
  9644. nm = m1;
  9645. ny = cent + m3;
  9646. }
  9647. str = nm+'/'+nd+'/'+ny;
  9648. // now replace 2 digit year with 4 digit year
  9649. return parsable.replace(/^([0-9]{1,2})[-\/]([0-9]{1,2})[-\/]([0-9]{1,2})/, str);
  9650. }
  9651. if (match && match.length > 3) {
  9652. parsable = h1(parsable, match);
  9653. }
  9654. // Now check for '1/19/70' with nothing after and do as above
  9655. var match = parsable.match(/^([0-9]{1,2})[-\/]([0-9]{1,2})[-\/]([0-9]{1,2})$/);
  9656. if (match && match.length > 3) {
  9657. parsable = h1(parsable, match);
  9658. }
  9659. var i = 0;
  9660. var length = jsDate.matchers.length;
  9661. var pattern,
  9662. ms,
  9663. current = parsable,
  9664. obj;
  9665. while (i < length) {
  9666. ms = Date.parse(current);
  9667. if (!isNaN(ms)) {
  9668. return new Date(ms);
  9669. }
  9670. pattern = jsDate.matchers[i];
  9671. if (typeof pattern == 'function') {
  9672. obj = pattern.call(jsDate, current);
  9673. if (obj instanceof Date) {
  9674. return obj;
  9675. }
  9676. } else {
  9677. current = parsable.replace(pattern[0], pattern[1]);
  9678. }
  9679. i++;
  9680. }
  9681. return NaN;
  9682. };
  9683. /**
  9684. * @static
  9685. * Handy static utility function to return the number of days in a given month.
  9686. * @param {Integer} year Year
  9687. * @param {Integer} month Month (1-12)
  9688. * @returns {Integer} Number of days in the month.
  9689. */
  9690. //
  9691. // handy utility method Borrowed right from Ken Snyder's Date Instance Mehtods.
  9692. //
  9693. jsDate.daysInMonth = function(year, month) {
  9694. if (month == 2) {
  9695. return new Date(year, 1, 29).getDate() == 29 ? 29 : 28;
  9696. }
  9697. return [undefined,31,undefined,31,30,31,30,31,31,30,31,30,31][month];
  9698. };
  9699. //
  9700. // An Array of regular expressions or functions that will attempt to match the date string.
  9701. // Functions are called with scope of a jsDate instance.
  9702. //
  9703. jsDate.matchers = [
  9704. // convert dd.mmm.yyyy to mm/dd/yyyy (world date to US date).
  9705. [/(3[01]|[0-2]\d)\s*\.\s*(1[0-2]|0\d)\s*\.\s*([1-9]\d{3})/, '$2/$1/$3'],
  9706. // convert yyyy-mm-dd to mm/dd/yyyy (ISO date to US date).
  9707. [/([1-9]\d{3})\s*-\s*(1[0-2]|0\d)\s*-\s*(3[01]|[0-2]\d)/, '$2/$3/$1'],
  9708. // Handle 12 hour or 24 hour time with milliseconds am/pm and optional date part.
  9709. function(str) {
  9710. var match = str.match(/^(?:(.+)\s+)?([012]?\d)(?:\s*\:\s*(\d\d))?(?:\s*\:\s*(\d\d(\.\d*)?))?\s*(am|pm)?\s*$/i);
  9711. // opt. date hour opt. minute opt. second opt. msec opt. am or pm
  9712. if (match) {
  9713. if (match[1]) {
  9714. var d = this.createDate(match[1]);
  9715. if (isNaN(d)) {
  9716. return;
  9717. }
  9718. } else {
  9719. var d = new Date();
  9720. d.setMilliseconds(0);
  9721. }
  9722. var hour = parseFloat(match[2]);
  9723. if (match[6]) {
  9724. hour = match[6].toLowerCase() == 'am' ? (hour == 12 ? 0 : hour) : (hour == 12 ? 12 : hour + 12);
  9725. }
  9726. d.setHours(hour, parseInt(match[3] || 0, 10), parseInt(match[4] || 0, 10), ((parseFloat(match[5] || 0)) || 0)*1000);
  9727. return d;
  9728. }
  9729. else {
  9730. return str;
  9731. }
  9732. },
  9733. // Handle ISO timestamp with time zone.
  9734. function(str) {
  9735. var match = str.match(/^(?:(.+))[T|\s+]([012]\d)(?:\:(\d\d))(?:\:(\d\d))(?:\.\d+)([\+\-]\d\d\:\d\d)$/i);
  9736. if (match) {
  9737. if (match[1]) {
  9738. var d = this.createDate(match[1]);
  9739. if (isNaN(d)) {
  9740. return;
  9741. }
  9742. } else {
  9743. var d = new Date();
  9744. d.setMilliseconds(0);
  9745. }
  9746. var hour = parseFloat(match[2]);
  9747. d.setHours(hour, parseInt(match[3], 10), parseInt(match[4], 10), parseFloat(match[5])*1000);
  9748. return d;
  9749. }
  9750. else {
  9751. return str;
  9752. }
  9753. },
  9754. // Try to match ambiguous strings like 12/8/22.
  9755. // Use FF date assumption that 2 digit years are 20th century (i.e. 1900's).
  9756. // This may be redundant with pre processing of date already performed.
  9757. function(str) {
  9758. var match = str.match(/^([0-3]?\d)\s*[-\/.\s]{1}\s*([a-zA-Z]{3,9})\s*[-\/.\s]{1}\s*([0-3]?\d)$/);
  9759. if (match) {
  9760. var d = new Date();
  9761. var cent = jsDate.config.defaultCentury;
  9762. var m1 = parseFloat(match[1]);
  9763. var m3 = parseFloat(match[3]);
  9764. var ny, nd, nm;
  9765. if (m1 > 31) { // first number is a year
  9766. nd = m3;
  9767. ny = cent + m1;
  9768. }
  9769. else { // last number is the year
  9770. nd = m1;
  9771. ny = cent + m3;
  9772. }
  9773. var nm = inArray(match[2], jsDate.regional[jsDate.regional.getLocale()]["monthNamesShort"]);
  9774. if (nm == -1) {
  9775. nm = inArray(match[2], jsDate.regional[jsDate.regional.getLocale()]["monthNames"]);
  9776. }
  9777. d.setFullYear(ny, nm, nd);
  9778. d.setHours(0,0,0,0);
  9779. return d;
  9780. }
  9781. else {
  9782. return str;
  9783. }
  9784. }
  9785. ];
  9786. //
  9787. // I think John Reisig published this method on his blog, ejohn.
  9788. //
  9789. function inArray( elem, array ) {
  9790. if ( array.indexOf ) {
  9791. return array.indexOf( elem );
  9792. }
  9793. for ( var i = 0, length = array.length; i < length; i++ ) {
  9794. if ( array[ i ] === elem ) {
  9795. return i;
  9796. }
  9797. }
  9798. return -1;
  9799. }
  9800. //
  9801. // Thanks to Kangax, Christian Sciberras and Stack Overflow for this method.
  9802. //
  9803. function get_type(thing){
  9804. if(thing===null) return "[object Null]"; // special case
  9805. return Object.prototype.toString.call(thing);
  9806. }
  9807. $.jsDate = jsDate;
  9808. /**
  9809. * JavaScript printf/sprintf functions.
  9810. *
  9811. * This code has been adapted from the publicly available sprintf methods
  9812. * by Ash Searle. His original header follows:
  9813. *
  9814. * This code is unrestricted: you are free to use it however you like.
  9815. *
  9816. * The functions should work as expected, performing left or right alignment,
  9817. * truncating strings, outputting numbers with a required precision etc.
  9818. *
  9819. * For complex cases, these functions follow the Perl implementations of
  9820. * (s)printf, allowing arguments to be passed out-of-order, and to set the
  9821. * precision or length of the output based on arguments instead of fixed
  9822. * numbers.
  9823. *
  9824. * See http://perldoc.perl.org/functions/sprintf.html for more information.
  9825. *
  9826. * Implemented:
  9827. * - zero and space-padding
  9828. * - right and left-alignment,
  9829. * - base X prefix (binary, octal and hex)
  9830. * - positive number prefix
  9831. * - (minimum) width
  9832. * - precision / truncation / maximum width
  9833. * - out of order arguments
  9834. *
  9835. * Not implemented (yet):
  9836. * - vector flag
  9837. * - size (bytes, words, long-words etc.)
  9838. *
  9839. * Will not implement:
  9840. * - %n or %p (no pass-by-reference in JavaScript)
  9841. *
  9842. * @version 2007.04.27
  9843. * @author Ash Searle
  9844. *
  9845. * You can see the original work and comments on his blog:
  9846. * http://hexmen.com/blog/2007/03/printf-sprintf/
  9847. * http://hexmen.com/js/sprintf.js
  9848. */
  9849. /**
  9850. * @Modifications 2009.05.26
  9851. * @author Chris Leonello
  9852. *
  9853. * Added %p %P specifier
  9854. * Acts like %g or %G but will not add more significant digits to the output than present in the input.
  9855. * Example:
  9856. * Format: '%.3p', Input: 0.012, Output: 0.012
  9857. * Format: '%.3g', Input: 0.012, Output: 0.0120
  9858. * Format: '%.4p', Input: 12.0, Output: 12.0
  9859. * Format: '%.4g', Input: 12.0, Output: 12.00
  9860. * Format: '%.4p', Input: 4.321e-5, Output: 4.321e-5
  9861. * Format: '%.4g', Input: 4.321e-5, Output: 4.3210e-5
  9862. *
  9863. * Example:
  9864. * >>> $.jqplot.sprintf('%.2f, %d', 23.3452, 43.23)
  9865. * "23.35, 43"
  9866. * >>> $.jqplot.sprintf("no value: %n, decimal with thousands separator: %'d", 23.3452, 433524)
  9867. * "no value: , decimal with thousands separator: 433,524"
  9868. */
  9869. $.jqplot.sprintf = function() {
  9870. function pad(str, len, chr, leftJustify) {
  9871. var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
  9872. return leftJustify ? str + padding : padding + str;
  9873. }
  9874. function thousand_separate(value) {
  9875. var value_str = new String(value);
  9876. for (var i=10; i>0; i--) {
  9877. if (value_str == (value_str = value_str.replace(/^(\d+)(\d{3})/, "$1"+$.jqplot.sprintf.thousandsSeparator+"$2"))) break;
  9878. }
  9879. return value_str;
  9880. }
  9881. function justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace) {
  9882. var diff = minWidth - value.length;
  9883. if (diff > 0) {
  9884. var spchar = ' ';
  9885. if (htmlSpace) { spchar = '&nbsp;'; }
  9886. if (leftJustify || !zeroPad) {
  9887. value = pad(value, minWidth, spchar, leftJustify);
  9888. } else {
  9889. value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
  9890. }
  9891. }
  9892. return value;
  9893. }
  9894. function formatBaseX(value, base, prefix, leftJustify, minWidth, precision, zeroPad, htmlSpace) {
  9895. // Note: casts negative numbers to positive ones
  9896. var number = value >>> 0;
  9897. prefix = prefix && number && {'2': '0b', '8': '0', '16': '0x'}[base] || '';
  9898. value = prefix + pad(number.toString(base), precision || 0, '0', false);
  9899. return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace);
  9900. }
  9901. function formatString(value, leftJustify, minWidth, precision, zeroPad, htmlSpace) {
  9902. if (precision != null) {
  9903. value = value.slice(0, precision);
  9904. }
  9905. return justify(value, '', leftJustify, minWidth, zeroPad, htmlSpace);
  9906. }
  9907. var a = arguments, i = 0, format = a[i++];
  9908. return format.replace($.jqplot.sprintf.regex, function(substring, valueIndex, flags, minWidth, _, precision, type) {
  9909. if (substring == '%%') { return '%'; }
  9910. // parse flags
  9911. var leftJustify = false, positivePrefix = '', zeroPad = false, prefixBaseX = false, htmlSpace = false, thousandSeparation = false;
  9912. for (var j = 0; flags && j < flags.length; j++) switch (flags.charAt(j)) {
  9913. case ' ': positivePrefix = ' '; break;
  9914. case '+': positivePrefix = '+'; break;
  9915. case '-': leftJustify = true; break;
  9916. case '0': zeroPad = true; break;
  9917. case '#': prefixBaseX = true; break;
  9918. case '&': htmlSpace = true; break;
  9919. case '\'': thousandSeparation = true; break;
  9920. }
  9921. // parameters may be null, undefined, empty-string or real valued
  9922. // we want to ignore null, undefined and empty-string values
  9923. if (!minWidth) {
  9924. minWidth = 0;
  9925. }
  9926. else if (minWidth == '*') {
  9927. minWidth = +a[i++];
  9928. }
  9929. else if (minWidth.charAt(0) == '*') {
  9930. minWidth = +a[minWidth.slice(1, -1)];
  9931. }
  9932. else {
  9933. minWidth = +minWidth;
  9934. }
  9935. // Note: undocumented perl feature:
  9936. if (minWidth < 0) {
  9937. minWidth = -minWidth;
  9938. leftJustify = true;
  9939. }
  9940. if (!isFinite(minWidth)) {
  9941. throw new Error('$.jqplot.sprintf: (minimum-)width must be finite');
  9942. }
  9943. if (!precision) {
  9944. precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : void(0);
  9945. }
  9946. else if (precision == '*') {
  9947. precision = +a[i++];
  9948. }
  9949. else if (precision.charAt(0) == '*') {
  9950. precision = +a[precision.slice(1, -1)];
  9951. }
  9952. else {
  9953. precision = +precision;
  9954. }
  9955. // grab value using valueIndex if required?
  9956. var value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];
  9957. switch (type) {
  9958. case 's': {
  9959. if (value == null) {
  9960. return '';
  9961. }
  9962. return formatString(String(value), leftJustify, minWidth, precision, zeroPad, htmlSpace);
  9963. }
  9964. case 'c': return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad, htmlSpace);
  9965. case 'b': return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad,htmlSpace);
  9966. case 'o': return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace);
  9967. case 'x': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace);
  9968. case 'X': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace).toUpperCase();
  9969. case 'u': return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad, htmlSpace);
  9970. case 'i': {
  9971. var number = parseInt(+value, 10);
  9972. if (isNaN(number)) {
  9973. return '';
  9974. }
  9975. var prefix = number < 0 ? '-' : positivePrefix;
  9976. var number_str = thousandSeparation ? thousand_separate(String(Math.abs(number))): String(Math.abs(number));
  9977. value = prefix + pad(number_str, precision, '0', false);
  9978. //value = prefix + pad(String(Math.abs(number)), precision, '0', false);
  9979. return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace);
  9980. }
  9981. case 'd': {
  9982. var number = Math.round(+value);
  9983. if (isNaN(number)) {
  9984. return '';
  9985. }
  9986. var prefix = number < 0 ? '-' : positivePrefix;
  9987. var number_str = thousandSeparation ? thousand_separate(String(Math.abs(number))): String(Math.abs(number));
  9988. value = prefix + pad(number_str, precision, '0', false);
  9989. return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace);
  9990. }
  9991. case 'e':
  9992. case 'E':
  9993. case 'f':
  9994. case 'F':
  9995. case 'g':
  9996. case 'G':
  9997. {
  9998. var number = +value;
  9999. if (isNaN(number)) {
  10000. return '';
  10001. }
  10002. var prefix = number < 0 ? '-' : positivePrefix;
  10003. var method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
  10004. var textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];
  10005. var number_str = Math.abs(number)[method](precision);
  10006. number_str = thousandSeparation ? thousand_separate(number_str): number_str;
  10007. value = prefix + number_str;
  10008. var justified = justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace)[textTransform]();
  10009. if ($.jqplot.sprintf.decimalMark !== '.' && $.jqplot.sprintf.decimalMark !== $.jqplot.sprintf.thousandsSeparator) {
  10010. return justified.replace(/\./, $.jqplot.sprintf.decimalMark);
  10011. } else {
  10012. return justified;
  10013. }
  10014. }
  10015. case 'p':
  10016. case 'P':
  10017. {
  10018. // make sure number is a number
  10019. var number = +value;
  10020. if (isNaN(number)) {
  10021. return '';
  10022. }
  10023. var prefix = number < 0 ? '-' : positivePrefix;
  10024. var parts = String(Number(Math.abs(number)).toExponential()).split(/e|E/);
  10025. var sd = (parts[0].indexOf('.') != -1) ? parts[0].length - 1 : parts[0].length;
  10026. var zeros = (parts[1] < 0) ? -parts[1] - 1 : 0;
  10027. if (Math.abs(number) < 1) {
  10028. if (sd + zeros <= precision) {
  10029. value = prefix + Math.abs(number).toPrecision(sd);
  10030. }
  10031. else {
  10032. if (sd <= precision - 1) {
  10033. value = prefix + Math.abs(number).toExponential(sd-1);
  10034. }
  10035. else {
  10036. value = prefix + Math.abs(number).toExponential(precision-1);
  10037. }
  10038. }
  10039. }
  10040. else {
  10041. var prec = (sd <= precision) ? sd : precision;
  10042. value = prefix + Math.abs(number).toPrecision(prec);
  10043. }
  10044. var textTransform = ['toString', 'toUpperCase']['pP'.indexOf(type) % 2];
  10045. return justify(value, prefix, leftJustify, minWidth, zeroPad, htmlSpace)[textTransform]();
  10046. }
  10047. case 'n': return '';
  10048. default: return substring;
  10049. }
  10050. });
  10051. };
  10052. $.jqplot.sprintf.thousandsSeparator = ',';
  10053. // Specifies the decimal mark for floating point values. By default a period '.'
  10054. // is used. If you change this value to for example a comma be sure to also
  10055. // change the thousands separator or else this won't work since a simple String
  10056. // replace is used (replacing all periods with the mark specified here).
  10057. $.jqplot.sprintf.decimalMark = '.';
  10058. $.jqplot.sprintf.regex = /%%|%(\d+\$)?([-+#0&\' ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([nAscboxXuidfegpEGP])/g;
  10059. $.jqplot.getSignificantFigures = function(number) {
  10060. var parts = String(Number(Math.abs(number)).toExponential()).split(/e|E/);
  10061. // total significant digits
  10062. var sd = (parts[0].indexOf('.') != -1) ? parts[0].length - 1 : parts[0].length;
  10063. var zeros = (parts[1] < 0) ? -parts[1] - 1 : 0;
  10064. // exponent
  10065. var expn = parseInt(parts[1], 10);
  10066. // digits to the left of the decimal place
  10067. var dleft = (expn + 1 > 0) ? expn + 1 : 0;
  10068. // digits to the right of the decimal place
  10069. var dright = (sd <= dleft) ? 0 : sd - expn - 1;
  10070. return {significantDigits: sd, digitsLeft: dleft, digitsRight: dright, zeros: zeros, exponent: expn} ;
  10071. };
  10072. $.jqplot.getPrecision = function(number) {
  10073. return $.jqplot.getSignificantFigures(number).digitsRight;
  10074. };
  10075. })(jQuery);
  10076. var backCompat = $.uiBackCompat !== false;
  10077. $.jqplot.effects = {
  10078. effect: {}
  10079. };
  10080. // prefix used for storing data on .data()
  10081. var dataSpace = "jqplot.storage.";
  10082. /******************************************************************************/
  10083. /*********************************** EFFECTS **********************************/
  10084. /******************************************************************************/
  10085. $.extend( $.jqplot.effects, {
  10086. version: "1.9pre",
  10087. // Saves a set of properties in a data storage
  10088. save: function( element, set ) {
  10089. for( var i=0; i < set.length; i++ ) {
  10090. if ( set[ i ] !== null ) {
  10091. element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );
  10092. }
  10093. }
  10094. },
  10095. // Restores a set of previously saved properties from a data storage
  10096. restore: function( element, set ) {
  10097. for( var i=0; i < set.length; i++ ) {
  10098. if ( set[ i ] !== null ) {
  10099. element.css( set[ i ], element.data( dataSpace + set[ i ] ) );
  10100. }
  10101. }
  10102. },
  10103. setMode: function( el, mode ) {
  10104. if (mode === "toggle") {
  10105. mode = el.is( ":hidden" ) ? "show" : "hide";
  10106. }
  10107. return mode;
  10108. },
  10109. // Wraps the element around a wrapper that copies position properties
  10110. createWrapper: function( element ) {
  10111. // if the element is already wrapped, return it
  10112. if ( element.parent().is( ".ui-effects-wrapper" )) {
  10113. return element.parent();
  10114. }
  10115. // wrap the element
  10116. var props = {
  10117. width: element.outerWidth(true),
  10118. height: element.outerHeight(true),
  10119. "float": element.css( "float" )
  10120. },
  10121. wrapper = $( "<div></div>" )
  10122. .addClass( "ui-effects-wrapper" )
  10123. .css({
  10124. fontSize: "100%",
  10125. background: "transparent",
  10126. border: "none",
  10127. margin: 0,
  10128. padding: 0
  10129. }),
  10130. // Store the size in case width/height are defined in % - Fixes #5245
  10131. size = {
  10132. width: element.width(),
  10133. height: element.height()
  10134. },
  10135. active = document.activeElement;
  10136. element.wrap( wrapper );
  10137. // Fixes #7595 - Elements lose focus when wrapped.
  10138. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  10139. $( active ).focus();
  10140. }
  10141. wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually loose the reference to the wrapped element
  10142. // transfer positioning properties to the wrapper
  10143. if ( element.css( "position" ) === "static" ) {
  10144. wrapper.css({ position: "relative" });
  10145. element.css({ position: "relative" });
  10146. } else {
  10147. $.extend( props, {
  10148. position: element.css( "position" ),
  10149. zIndex: element.css( "z-index" )
  10150. });
  10151. $.each([ "top", "left", "bottom", "right" ], function(i, pos) {
  10152. props[ pos ] = element.css( pos );
  10153. if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
  10154. props[ pos ] = "auto";
  10155. }
  10156. });
  10157. element.css({
  10158. position: "relative",
  10159. top: 0,
  10160. left: 0,
  10161. right: "auto",
  10162. bottom: "auto"
  10163. });
  10164. }
  10165. element.css(size);
  10166. return wrapper.css( props ).show();
  10167. },
  10168. removeWrapper: function( element ) {
  10169. var active = document.activeElement;
  10170. if ( element.parent().is( ".ui-effects-wrapper" ) ) {
  10171. element.parent().replaceWith( element );
  10172. // Fixes #7595 - Elements lose focus when wrapped.
  10173. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  10174. $( active ).focus();
  10175. }
  10176. }
  10177. return element;
  10178. }
  10179. });
  10180. // return an effect options object for the given parameters:
  10181. function _normalizeArguments( effect, options, speed, callback ) {
  10182. // short path for passing an effect options object:
  10183. if ( $.isPlainObject( effect ) ) {
  10184. return effect;
  10185. }
  10186. // convert to an object
  10187. effect = { effect: effect };
  10188. // catch (effect)
  10189. if ( options === undefined ) {
  10190. options = {};
  10191. }
  10192. // catch (effect, callback)
  10193. if ( $.isFunction( options ) ) {
  10194. callback = options;
  10195. speed = null;
  10196. options = {};
  10197. }
  10198. // catch (effect, speed, ?)
  10199. if ( $.type( options ) === "number" || $.fx.speeds[ options ]) {
  10200. callback = speed;
  10201. speed = options;
  10202. options = {};
  10203. }
  10204. // catch (effect, options, callback)
  10205. if ( $.isFunction( speed ) ) {
  10206. callback = speed;
  10207. speed = null;
  10208. }
  10209. // add options to effect
  10210. if ( options ) {
  10211. $.extend( effect, options );
  10212. }
  10213. speed = speed || options.duration;
  10214. effect.duration = $.fx.off ? 0 : typeof speed === "number"
  10215. ? speed : speed in $.fx.speeds ? $.fx.speeds[ speed ] : $.fx.speeds._default;
  10216. effect.complete = callback || options.complete;
  10217. return effect;
  10218. }
  10219. function standardSpeed( speed ) {
  10220. // valid standard speeds
  10221. if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) {
  10222. return true;
  10223. }
  10224. // invalid strings - treat as "normal" speed
  10225. if ( typeof speed === "string" && !$.jqplot.effects.effect[ speed ] ) {
  10226. // TODO: remove in 2.0 (#7115)
  10227. if ( backCompat && $.jqplot.effects[ speed ] ) {
  10228. return false;
  10229. }
  10230. return true;
  10231. }
  10232. return false;
  10233. }
  10234. $.fn.extend({
  10235. jqplotEffect: function( effect, options, speed, callback ) {
  10236. var args = _normalizeArguments.apply( this, arguments ),
  10237. mode = args.mode,
  10238. queue = args.queue,
  10239. effectMethod = $.jqplot.effects.effect[ args.effect ],
  10240. // DEPRECATED: remove in 2.0 (#7115)
  10241. oldEffectMethod = !effectMethod && backCompat && $.jqplot.effects[ args.effect ];
  10242. if ( $.fx.off || !( effectMethod || oldEffectMethod ) ) {
  10243. // delegate to the original method (e.g., .show()) if possible
  10244. if ( mode ) {
  10245. return this[ mode ]( args.duration, args.complete );
  10246. } else {
  10247. return this.each( function() {
  10248. if ( args.complete ) {
  10249. args.complete.call( this );
  10250. }
  10251. });
  10252. }
  10253. }
  10254. function run( next ) {
  10255. var elem = $( this ),
  10256. complete = args.complete,
  10257. mode = args.mode;
  10258. function done() {
  10259. if ( $.isFunction( complete ) ) {
  10260. complete.call( elem[0] );
  10261. }
  10262. if ( $.isFunction( next ) ) {
  10263. next();
  10264. }
  10265. }
  10266. // if the element is hiddden and mode is hide,
  10267. // or element is visible and mode is show
  10268. if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
  10269. done();
  10270. } else {
  10271. effectMethod.call( elem[0], args, done );
  10272. }
  10273. }
  10274. // TODO: remove this check in 2.0, effectMethod will always be true
  10275. if ( effectMethod ) {
  10276. return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
  10277. } else {
  10278. // DEPRECATED: remove in 2.0 (#7115)
  10279. return oldEffectMethod.call(this, {
  10280. options: args,
  10281. duration: args.duration,
  10282. callback: args.complete,
  10283. mode: args.mode
  10284. });
  10285. }
  10286. }
  10287. });
  10288. var rvertical = /up|down|vertical/,
  10289. rpositivemotion = /up|left|vertical|horizontal/;
  10290. $.jqplot.effects.effect.blind = function( o, done ) {
  10291. // Create element
  10292. var el = $( this ),
  10293. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  10294. mode = $.jqplot.effects.setMode( el, o.mode || "hide" ),
  10295. direction = o.direction || "up",
  10296. vertical = rvertical.test( direction ),
  10297. ref = vertical ? "height" : "width",
  10298. ref2 = vertical ? "top" : "left",
  10299. motion = rpositivemotion.test( direction ),
  10300. animation = {},
  10301. show = mode === "show",
  10302. wrapper, distance, top;
  10303. // // if already wrapped, the wrapper's properties are my property. #6245
  10304. if ( el.parent().is( ".ui-effects-wrapper" ) ) {
  10305. $.jqplot.effects.save( el.parent(), props );
  10306. } else {
  10307. $.jqplot.effects.save( el, props );
  10308. }
  10309. el.show();
  10310. top = parseInt(el.css('top'), 10);
  10311. wrapper = $.jqplot.effects.createWrapper( el ).css({
  10312. overflow: "hidden"
  10313. });
  10314. distance = vertical ? wrapper[ ref ]() + top : wrapper[ ref ]();
  10315. animation[ ref ] = show ? String(distance) : '0';
  10316. if ( !motion ) {
  10317. el
  10318. .css( vertical ? "bottom" : "right", 0 )
  10319. .css( vertical ? "top" : "left", "" )
  10320. .css({ position: "absolute" });
  10321. animation[ ref2 ] = show ? '0' : String(distance);
  10322. }
  10323. // // start at 0 if we are showing
  10324. if ( show ) {
  10325. wrapper.css( ref, 0 );
  10326. if ( ! motion ) {
  10327. wrapper.css( ref2, distance );
  10328. }
  10329. }
  10330. // // Animate
  10331. wrapper.animate( animation, {
  10332. duration: o.duration,
  10333. easing: o.easing,
  10334. queue: false,
  10335. complete: function() {
  10336. if ( mode === "hide" ) {
  10337. el.hide();
  10338. }
  10339. $.jqplot.effects.restore( el, props );
  10340. $.jqplot.effects.removeWrapper( el );
  10341. done();
  10342. }
  10343. });
  10344. };