Chart.bundle.js 435 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591
  1. /*!
  2. * Chart.js
  3. * http://chartjs.org/
  4. * Version: 2.2.1
  5. *
  6. * Copyright 2016 Nick Downie
  7. * Released under the MIT license
  8. * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md
  9. */
  10. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Chart = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  11. /* MIT license */
  12. var colorNames = require(5);
  13. module.exports = {
  14. getRgba: getRgba,
  15. getHsla: getHsla,
  16. getRgb: getRgb,
  17. getHsl: getHsl,
  18. getHwb: getHwb,
  19. getAlpha: getAlpha,
  20. hexString: hexString,
  21. rgbString: rgbString,
  22. rgbaString: rgbaString,
  23. percentString: percentString,
  24. percentaString: percentaString,
  25. hslString: hslString,
  26. hslaString: hslaString,
  27. hwbString: hwbString,
  28. keyword: keyword
  29. }
  30. function getRgba(string) {
  31. if (!string) {
  32. return;
  33. }
  34. var abbr = /^#([a-fA-F0-9]{3})$/,
  35. hex = /^#([a-fA-F0-9]{6})$/,
  36. rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
  37. per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
  38. keyword = /(\w+)/;
  39. var rgb = [0, 0, 0],
  40. a = 1,
  41. match = string.match(abbr);
  42. if (match) {
  43. match = match[1];
  44. for (var i = 0; i < rgb.length; i++) {
  45. rgb[i] = parseInt(match[i] + match[i], 16);
  46. }
  47. }
  48. else if (match = string.match(hex)) {
  49. match = match[1];
  50. for (var i = 0; i < rgb.length; i++) {
  51. rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
  52. }
  53. }
  54. else if (match = string.match(rgba)) {
  55. for (var i = 0; i < rgb.length; i++) {
  56. rgb[i] = parseInt(match[i + 1]);
  57. }
  58. a = parseFloat(match[4]);
  59. }
  60. else if (match = string.match(per)) {
  61. for (var i = 0; i < rgb.length; i++) {
  62. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  63. }
  64. a = parseFloat(match[4]);
  65. }
  66. else if (match = string.match(keyword)) {
  67. if (match[1] == "transparent") {
  68. return [0, 0, 0, 0];
  69. }
  70. rgb = colorNames[match[1]];
  71. if (!rgb) {
  72. return;
  73. }
  74. }
  75. for (var i = 0; i < rgb.length; i++) {
  76. rgb[i] = scale(rgb[i], 0, 255);
  77. }
  78. if (!a && a != 0) {
  79. a = 1;
  80. }
  81. else {
  82. a = scale(a, 0, 1);
  83. }
  84. rgb[3] = a;
  85. return rgb;
  86. }
  87. function getHsla(string) {
  88. if (!string) {
  89. return;
  90. }
  91. var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  92. var match = string.match(hsl);
  93. if (match) {
  94. var alpha = parseFloat(match[4]);
  95. var h = scale(parseInt(match[1]), 0, 360),
  96. s = scale(parseFloat(match[2]), 0, 100),
  97. l = scale(parseFloat(match[3]), 0, 100),
  98. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  99. return [h, s, l, a];
  100. }
  101. }
  102. function getHwb(string) {
  103. if (!string) {
  104. return;
  105. }
  106. var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  107. var match = string.match(hwb);
  108. if (match) {
  109. var alpha = parseFloat(match[4]);
  110. var h = scale(parseInt(match[1]), 0, 360),
  111. w = scale(parseFloat(match[2]), 0, 100),
  112. b = scale(parseFloat(match[3]), 0, 100),
  113. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  114. return [h, w, b, a];
  115. }
  116. }
  117. function getRgb(string) {
  118. var rgba = getRgba(string);
  119. return rgba && rgba.slice(0, 3);
  120. }
  121. function getHsl(string) {
  122. var hsla = getHsla(string);
  123. return hsla && hsla.slice(0, 3);
  124. }
  125. function getAlpha(string) {
  126. var vals = getRgba(string);
  127. if (vals) {
  128. return vals[3];
  129. }
  130. else if (vals = getHsla(string)) {
  131. return vals[3];
  132. }
  133. else if (vals = getHwb(string)) {
  134. return vals[3];
  135. }
  136. }
  137. // generators
  138. function hexString(rgb) {
  139. return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
  140. + hexDouble(rgb[2]);
  141. }
  142. function rgbString(rgba, alpha) {
  143. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  144. return rgbaString(rgba, alpha);
  145. }
  146. return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
  147. }
  148. function rgbaString(rgba, alpha) {
  149. if (alpha === undefined) {
  150. alpha = (rgba[3] !== undefined ? rgba[3] : 1);
  151. }
  152. return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
  153. + ", " + alpha + ")";
  154. }
  155. function percentString(rgba, alpha) {
  156. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  157. return percentaString(rgba, alpha);
  158. }
  159. var r = Math.round(rgba[0]/255 * 100),
  160. g = Math.round(rgba[1]/255 * 100),
  161. b = Math.round(rgba[2]/255 * 100);
  162. return "rgb(" + r + "%, " + g + "%, " + b + "%)";
  163. }
  164. function percentaString(rgba, alpha) {
  165. var r = Math.round(rgba[0]/255 * 100),
  166. g = Math.round(rgba[1]/255 * 100),
  167. b = Math.round(rgba[2]/255 * 100);
  168. return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
  169. }
  170. function hslString(hsla, alpha) {
  171. if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
  172. return hslaString(hsla, alpha);
  173. }
  174. return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
  175. }
  176. function hslaString(hsla, alpha) {
  177. if (alpha === undefined) {
  178. alpha = (hsla[3] !== undefined ? hsla[3] : 1);
  179. }
  180. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
  181. + alpha + ")";
  182. }
  183. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  184. // (hwb have alpha optional & 1 is default value)
  185. function hwbString(hwb, alpha) {
  186. if (alpha === undefined) {
  187. alpha = (hwb[3] !== undefined ? hwb[3] : 1);
  188. }
  189. return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
  190. + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
  191. }
  192. function keyword(rgb) {
  193. return reverseNames[rgb.slice(0, 3)];
  194. }
  195. // helpers
  196. function scale(num, min, max) {
  197. return Math.min(Math.max(min, num), max);
  198. }
  199. function hexDouble(num) {
  200. var str = num.toString(16).toUpperCase();
  201. return (str.length < 2) ? "0" + str : str;
  202. }
  203. //create a list of reverse color names
  204. var reverseNames = {};
  205. for (var name in colorNames) {
  206. reverseNames[colorNames[name]] = name;
  207. }
  208. },{"5":5}],2:[function(require,module,exports){
  209. /* MIT license */
  210. var convert = require(4);
  211. var string = require(1);
  212. var Color = function (obj) {
  213. if (obj instanceof Color) {
  214. return obj;
  215. }
  216. if (!(this instanceof Color)) {
  217. return new Color(obj);
  218. }
  219. this.values = {
  220. rgb: [0, 0, 0],
  221. hsl: [0, 0, 0],
  222. hsv: [0, 0, 0],
  223. hwb: [0, 0, 0],
  224. cmyk: [0, 0, 0, 0],
  225. alpha: 1
  226. };
  227. // parse Color() argument
  228. var vals;
  229. if (typeof obj === 'string') {
  230. vals = string.getRgba(obj);
  231. if (vals) {
  232. this.setValues('rgb', vals);
  233. } else if (vals = string.getHsla(obj)) {
  234. this.setValues('hsl', vals);
  235. } else if (vals = string.getHwb(obj)) {
  236. this.setValues('hwb', vals);
  237. } else {
  238. throw new Error('Unable to parse color from string "' + obj + '"');
  239. }
  240. } else if (typeof obj === 'object') {
  241. vals = obj;
  242. if (vals.r !== undefined || vals.red !== undefined) {
  243. this.setValues('rgb', vals);
  244. } else if (vals.l !== undefined || vals.lightness !== undefined) {
  245. this.setValues('hsl', vals);
  246. } else if (vals.v !== undefined || vals.value !== undefined) {
  247. this.setValues('hsv', vals);
  248. } else if (vals.w !== undefined || vals.whiteness !== undefined) {
  249. this.setValues('hwb', vals);
  250. } else if (vals.c !== undefined || vals.cyan !== undefined) {
  251. this.setValues('cmyk', vals);
  252. } else {
  253. throw new Error('Unable to parse color from object ' + JSON.stringify(obj));
  254. }
  255. }
  256. };
  257. Color.prototype = {
  258. rgb: function () {
  259. return this.setSpace('rgb', arguments);
  260. },
  261. hsl: function () {
  262. return this.setSpace('hsl', arguments);
  263. },
  264. hsv: function () {
  265. return this.setSpace('hsv', arguments);
  266. },
  267. hwb: function () {
  268. return this.setSpace('hwb', arguments);
  269. },
  270. cmyk: function () {
  271. return this.setSpace('cmyk', arguments);
  272. },
  273. rgbArray: function () {
  274. return this.values.rgb;
  275. },
  276. hslArray: function () {
  277. return this.values.hsl;
  278. },
  279. hsvArray: function () {
  280. return this.values.hsv;
  281. },
  282. hwbArray: function () {
  283. var values = this.values;
  284. if (values.alpha !== 1) {
  285. return values.hwb.concat([values.alpha]);
  286. }
  287. return values.hwb;
  288. },
  289. cmykArray: function () {
  290. return this.values.cmyk;
  291. },
  292. rgbaArray: function () {
  293. var values = this.values;
  294. return values.rgb.concat([values.alpha]);
  295. },
  296. hslaArray: function () {
  297. var values = this.values;
  298. return values.hsl.concat([values.alpha]);
  299. },
  300. alpha: function (val) {
  301. if (val === undefined) {
  302. return this.values.alpha;
  303. }
  304. this.setValues('alpha', val);
  305. return this;
  306. },
  307. red: function (val) {
  308. return this.setChannel('rgb', 0, val);
  309. },
  310. green: function (val) {
  311. return this.setChannel('rgb', 1, val);
  312. },
  313. blue: function (val) {
  314. return this.setChannel('rgb', 2, val);
  315. },
  316. hue: function (val) {
  317. if (val) {
  318. val %= 360;
  319. val = val < 0 ? 360 + val : val;
  320. }
  321. return this.setChannel('hsl', 0, val);
  322. },
  323. saturation: function (val) {
  324. return this.setChannel('hsl', 1, val);
  325. },
  326. lightness: function (val) {
  327. return this.setChannel('hsl', 2, val);
  328. },
  329. saturationv: function (val) {
  330. return this.setChannel('hsv', 1, val);
  331. },
  332. whiteness: function (val) {
  333. return this.setChannel('hwb', 1, val);
  334. },
  335. blackness: function (val) {
  336. return this.setChannel('hwb', 2, val);
  337. },
  338. value: function (val) {
  339. return this.setChannel('hsv', 2, val);
  340. },
  341. cyan: function (val) {
  342. return this.setChannel('cmyk', 0, val);
  343. },
  344. magenta: function (val) {
  345. return this.setChannel('cmyk', 1, val);
  346. },
  347. yellow: function (val) {
  348. return this.setChannel('cmyk', 2, val);
  349. },
  350. black: function (val) {
  351. return this.setChannel('cmyk', 3, val);
  352. },
  353. hexString: function () {
  354. return string.hexString(this.values.rgb);
  355. },
  356. rgbString: function () {
  357. return string.rgbString(this.values.rgb, this.values.alpha);
  358. },
  359. rgbaString: function () {
  360. return string.rgbaString(this.values.rgb, this.values.alpha);
  361. },
  362. percentString: function () {
  363. return string.percentString(this.values.rgb, this.values.alpha);
  364. },
  365. hslString: function () {
  366. return string.hslString(this.values.hsl, this.values.alpha);
  367. },
  368. hslaString: function () {
  369. return string.hslaString(this.values.hsl, this.values.alpha);
  370. },
  371. hwbString: function () {
  372. return string.hwbString(this.values.hwb, this.values.alpha);
  373. },
  374. keyword: function () {
  375. return string.keyword(this.values.rgb, this.values.alpha);
  376. },
  377. rgbNumber: function () {
  378. var rgb = this.values.rgb;
  379. return (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
  380. },
  381. luminosity: function () {
  382. // http://www.w3.org/TR/WCAG20/#relativeluminancedef
  383. var rgb = this.values.rgb;
  384. var lum = [];
  385. for (var i = 0; i < rgb.length; i++) {
  386. var chan = rgb[i] / 255;
  387. lum[i] = (chan <= 0.03928) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4);
  388. }
  389. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  390. },
  391. contrast: function (color2) {
  392. // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  393. var lum1 = this.luminosity();
  394. var lum2 = color2.luminosity();
  395. if (lum1 > lum2) {
  396. return (lum1 + 0.05) / (lum2 + 0.05);
  397. }
  398. return (lum2 + 0.05) / (lum1 + 0.05);
  399. },
  400. level: function (color2) {
  401. var contrastRatio = this.contrast(color2);
  402. if (contrastRatio >= 7.1) {
  403. return 'AAA';
  404. }
  405. return (contrastRatio >= 4.5) ? 'AA' : '';
  406. },
  407. dark: function () {
  408. // YIQ equation from http://24ways.org/2010/calculating-color-contrast
  409. var rgb = this.values.rgb;
  410. var yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
  411. return yiq < 128;
  412. },
  413. light: function () {
  414. return !this.dark();
  415. },
  416. negate: function () {
  417. var rgb = [];
  418. for (var i = 0; i < 3; i++) {
  419. rgb[i] = 255 - this.values.rgb[i];
  420. }
  421. this.setValues('rgb', rgb);
  422. return this;
  423. },
  424. lighten: function (ratio) {
  425. var hsl = this.values.hsl;
  426. hsl[2] += hsl[2] * ratio;
  427. this.setValues('hsl', hsl);
  428. return this;
  429. },
  430. darken: function (ratio) {
  431. var hsl = this.values.hsl;
  432. hsl[2] -= hsl[2] * ratio;
  433. this.setValues('hsl', hsl);
  434. return this;
  435. },
  436. saturate: function (ratio) {
  437. var hsl = this.values.hsl;
  438. hsl[1] += hsl[1] * ratio;
  439. this.setValues('hsl', hsl);
  440. return this;
  441. },
  442. desaturate: function (ratio) {
  443. var hsl = this.values.hsl;
  444. hsl[1] -= hsl[1] * ratio;
  445. this.setValues('hsl', hsl);
  446. return this;
  447. },
  448. whiten: function (ratio) {
  449. var hwb = this.values.hwb;
  450. hwb[1] += hwb[1] * ratio;
  451. this.setValues('hwb', hwb);
  452. return this;
  453. },
  454. blacken: function (ratio) {
  455. var hwb = this.values.hwb;
  456. hwb[2] += hwb[2] * ratio;
  457. this.setValues('hwb', hwb);
  458. return this;
  459. },
  460. greyscale: function () {
  461. var rgb = this.values.rgb;
  462. // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
  463. var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  464. this.setValues('rgb', [val, val, val]);
  465. return this;
  466. },
  467. clearer: function (ratio) {
  468. var alpha = this.values.alpha;
  469. this.setValues('alpha', alpha - (alpha * ratio));
  470. return this;
  471. },
  472. opaquer: function (ratio) {
  473. var alpha = this.values.alpha;
  474. this.setValues('alpha', alpha + (alpha * ratio));
  475. return this;
  476. },
  477. rotate: function (degrees) {
  478. var hsl = this.values.hsl;
  479. var hue = (hsl[0] + degrees) % 360;
  480. hsl[0] = hue < 0 ? 360 + hue : hue;
  481. this.setValues('hsl', hsl);
  482. return this;
  483. },
  484. /**
  485. * Ported from sass implementation in C
  486. * https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
  487. */
  488. mix: function (mixinColor, weight) {
  489. var color1 = this;
  490. var color2 = mixinColor;
  491. var p = weight === undefined ? 0.5 : weight;
  492. var w = 2 * p - 1;
  493. var a = color1.alpha() - color2.alpha();
  494. var w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  495. var w2 = 1 - w1;
  496. return this
  497. .rgb(
  498. w1 * color1.red() + w2 * color2.red(),
  499. w1 * color1.green() + w2 * color2.green(),
  500. w1 * color1.blue() + w2 * color2.blue()
  501. )
  502. .alpha(color1.alpha() * p + color2.alpha() * (1 - p));
  503. },
  504. toJSON: function () {
  505. return this.rgb();
  506. },
  507. clone: function () {
  508. // NOTE(SB): using node-clone creates a dependency to Buffer when using browserify,
  509. // making the final build way to big to embed in Chart.js. So let's do it manually,
  510. // assuming that values to clone are 1 dimension arrays containing only numbers,
  511. // except 'alpha' which is a number.
  512. var result = new Color();
  513. var source = this.values;
  514. var target = result.values;
  515. var value, type;
  516. for (var prop in source) {
  517. if (source.hasOwnProperty(prop)) {
  518. value = source[prop];
  519. type = ({}).toString.call(value);
  520. if (type === '[object Array]') {
  521. target[prop] = value.slice(0);
  522. } else if (type === '[object Number]') {
  523. target[prop] = value;
  524. } else {
  525. console.error('unexpected color value:', value);
  526. }
  527. }
  528. }
  529. return result;
  530. }
  531. };
  532. Color.prototype.spaces = {
  533. rgb: ['red', 'green', 'blue'],
  534. hsl: ['hue', 'saturation', 'lightness'],
  535. hsv: ['hue', 'saturation', 'value'],
  536. hwb: ['hue', 'whiteness', 'blackness'],
  537. cmyk: ['cyan', 'magenta', 'yellow', 'black']
  538. };
  539. Color.prototype.maxes = {
  540. rgb: [255, 255, 255],
  541. hsl: [360, 100, 100],
  542. hsv: [360, 100, 100],
  543. hwb: [360, 100, 100],
  544. cmyk: [100, 100, 100, 100]
  545. };
  546. Color.prototype.getValues = function (space) {
  547. var values = this.values;
  548. var vals = {};
  549. for (var i = 0; i < space.length; i++) {
  550. vals[space.charAt(i)] = values[space][i];
  551. }
  552. if (values.alpha !== 1) {
  553. vals.a = values.alpha;
  554. }
  555. // {r: 255, g: 255, b: 255, a: 0.4}
  556. return vals;
  557. };
  558. Color.prototype.setValues = function (space, vals) {
  559. var values = this.values;
  560. var spaces = this.spaces;
  561. var maxes = this.maxes;
  562. var alpha = 1;
  563. var i;
  564. if (space === 'alpha') {
  565. alpha = vals;
  566. } else if (vals.length) {
  567. // [10, 10, 10]
  568. values[space] = vals.slice(0, space.length);
  569. alpha = vals[space.length];
  570. } else if (vals[space.charAt(0)] !== undefined) {
  571. // {r: 10, g: 10, b: 10}
  572. for (i = 0; i < space.length; i++) {
  573. values[space][i] = vals[space.charAt(i)];
  574. }
  575. alpha = vals.a;
  576. } else if (vals[spaces[space][0]] !== undefined) {
  577. // {red: 10, green: 10, blue: 10}
  578. var chans = spaces[space];
  579. for (i = 0; i < space.length; i++) {
  580. values[space][i] = vals[chans[i]];
  581. }
  582. alpha = vals.alpha;
  583. }
  584. values.alpha = Math.max(0, Math.min(1, (alpha === undefined ? values.alpha : alpha)));
  585. if (space === 'alpha') {
  586. return false;
  587. }
  588. var capped;
  589. // cap values of the space prior converting all values
  590. for (i = 0; i < space.length; i++) {
  591. capped = Math.max(0, Math.min(maxes[space][i], values[space][i]));
  592. values[space][i] = Math.round(capped);
  593. }
  594. // convert to all the other color spaces
  595. for (var sname in spaces) {
  596. if (sname !== space) {
  597. values[sname] = convert[space][sname](values[space]);
  598. }
  599. }
  600. return true;
  601. };
  602. Color.prototype.setSpace = function (space, args) {
  603. var vals = args[0];
  604. if (vals === undefined) {
  605. // color.rgb()
  606. return this.getValues(space);
  607. }
  608. // color.rgb(10, 10, 10)
  609. if (typeof vals === 'number') {
  610. vals = Array.prototype.slice.call(args);
  611. }
  612. this.setValues(space, vals);
  613. return this;
  614. };
  615. Color.prototype.setChannel = function (space, index, val) {
  616. var svalues = this.values[space];
  617. if (val === undefined) {
  618. // color.red()
  619. return svalues[index];
  620. } else if (val === svalues[index]) {
  621. // color.red(color.red())
  622. return this;
  623. }
  624. // color.red(100)
  625. svalues[index] = val;
  626. this.setValues(space, svalues);
  627. return this;
  628. };
  629. if (typeof window !== 'undefined') {
  630. window.Color = Color;
  631. }
  632. module.exports = Color;
  633. },{"1":1,"4":4}],3:[function(require,module,exports){
  634. /* MIT license */
  635. module.exports = {
  636. rgb2hsl: rgb2hsl,
  637. rgb2hsv: rgb2hsv,
  638. rgb2hwb: rgb2hwb,
  639. rgb2cmyk: rgb2cmyk,
  640. rgb2keyword: rgb2keyword,
  641. rgb2xyz: rgb2xyz,
  642. rgb2lab: rgb2lab,
  643. rgb2lch: rgb2lch,
  644. hsl2rgb: hsl2rgb,
  645. hsl2hsv: hsl2hsv,
  646. hsl2hwb: hsl2hwb,
  647. hsl2cmyk: hsl2cmyk,
  648. hsl2keyword: hsl2keyword,
  649. hsv2rgb: hsv2rgb,
  650. hsv2hsl: hsv2hsl,
  651. hsv2hwb: hsv2hwb,
  652. hsv2cmyk: hsv2cmyk,
  653. hsv2keyword: hsv2keyword,
  654. hwb2rgb: hwb2rgb,
  655. hwb2hsl: hwb2hsl,
  656. hwb2hsv: hwb2hsv,
  657. hwb2cmyk: hwb2cmyk,
  658. hwb2keyword: hwb2keyword,
  659. cmyk2rgb: cmyk2rgb,
  660. cmyk2hsl: cmyk2hsl,
  661. cmyk2hsv: cmyk2hsv,
  662. cmyk2hwb: cmyk2hwb,
  663. cmyk2keyword: cmyk2keyword,
  664. keyword2rgb: keyword2rgb,
  665. keyword2hsl: keyword2hsl,
  666. keyword2hsv: keyword2hsv,
  667. keyword2hwb: keyword2hwb,
  668. keyword2cmyk: keyword2cmyk,
  669. keyword2lab: keyword2lab,
  670. keyword2xyz: keyword2xyz,
  671. xyz2rgb: xyz2rgb,
  672. xyz2lab: xyz2lab,
  673. xyz2lch: xyz2lch,
  674. lab2xyz: lab2xyz,
  675. lab2rgb: lab2rgb,
  676. lab2lch: lab2lch,
  677. lch2lab: lch2lab,
  678. lch2xyz: lch2xyz,
  679. lch2rgb: lch2rgb
  680. }
  681. function rgb2hsl(rgb) {
  682. var r = rgb[0]/255,
  683. g = rgb[1]/255,
  684. b = rgb[2]/255,
  685. min = Math.min(r, g, b),
  686. max = Math.max(r, g, b),
  687. delta = max - min,
  688. h, s, l;
  689. if (max == min)
  690. h = 0;
  691. else if (r == max)
  692. h = (g - b) / delta;
  693. else if (g == max)
  694. h = 2 + (b - r) / delta;
  695. else if (b == max)
  696. h = 4 + (r - g)/ delta;
  697. h = Math.min(h * 60, 360);
  698. if (h < 0)
  699. h += 360;
  700. l = (min + max) / 2;
  701. if (max == min)
  702. s = 0;
  703. else if (l <= 0.5)
  704. s = delta / (max + min);
  705. else
  706. s = delta / (2 - max - min);
  707. return [h, s * 100, l * 100];
  708. }
  709. function rgb2hsv(rgb) {
  710. var r = rgb[0],
  711. g = rgb[1],
  712. b = rgb[2],
  713. min = Math.min(r, g, b),
  714. max = Math.max(r, g, b),
  715. delta = max - min,
  716. h, s, v;
  717. if (max == 0)
  718. s = 0;
  719. else
  720. s = (delta/max * 1000)/10;
  721. if (max == min)
  722. h = 0;
  723. else if (r == max)
  724. h = (g - b) / delta;
  725. else if (g == max)
  726. h = 2 + (b - r) / delta;
  727. else if (b == max)
  728. h = 4 + (r - g) / delta;
  729. h = Math.min(h * 60, 360);
  730. if (h < 0)
  731. h += 360;
  732. v = ((max / 255) * 1000) / 10;
  733. return [h, s, v];
  734. }
  735. function rgb2hwb(rgb) {
  736. var r = rgb[0],
  737. g = rgb[1],
  738. b = rgb[2],
  739. h = rgb2hsl(rgb)[0],
  740. w = 1/255 * Math.min(r, Math.min(g, b)),
  741. b = 1 - 1/255 * Math.max(r, Math.max(g, b));
  742. return [h, w * 100, b * 100];
  743. }
  744. function rgb2cmyk(rgb) {
  745. var r = rgb[0] / 255,
  746. g = rgb[1] / 255,
  747. b = rgb[2] / 255,
  748. c, m, y, k;
  749. k = Math.min(1 - r, 1 - g, 1 - b);
  750. c = (1 - r - k) / (1 - k) || 0;
  751. m = (1 - g - k) / (1 - k) || 0;
  752. y = (1 - b - k) / (1 - k) || 0;
  753. return [c * 100, m * 100, y * 100, k * 100];
  754. }
  755. function rgb2keyword(rgb) {
  756. return reverseKeywords[JSON.stringify(rgb)];
  757. }
  758. function rgb2xyz(rgb) {
  759. var r = rgb[0] / 255,
  760. g = rgb[1] / 255,
  761. b = rgb[2] / 255;
  762. // assume sRGB
  763. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  764. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  765. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  766. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  767. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  768. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  769. return [x * 100, y *100, z * 100];
  770. }
  771. function rgb2lab(rgb) {
  772. var xyz = rgb2xyz(rgb),
  773. x = xyz[0],
  774. y = xyz[1],
  775. z = xyz[2],
  776. l, a, b;
  777. x /= 95.047;
  778. y /= 100;
  779. z /= 108.883;
  780. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  781. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  782. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  783. l = (116 * y) - 16;
  784. a = 500 * (x - y);
  785. b = 200 * (y - z);
  786. return [l, a, b];
  787. }
  788. function rgb2lch(args) {
  789. return lab2lch(rgb2lab(args));
  790. }
  791. function hsl2rgb(hsl) {
  792. var h = hsl[0] / 360,
  793. s = hsl[1] / 100,
  794. l = hsl[2] / 100,
  795. t1, t2, t3, rgb, val;
  796. if (s == 0) {
  797. val = l * 255;
  798. return [val, val, val];
  799. }
  800. if (l < 0.5)
  801. t2 = l * (1 + s);
  802. else
  803. t2 = l + s - l * s;
  804. t1 = 2 * l - t2;
  805. rgb = [0, 0, 0];
  806. for (var i = 0; i < 3; i++) {
  807. t3 = h + 1 / 3 * - (i - 1);
  808. t3 < 0 && t3++;
  809. t3 > 1 && t3--;
  810. if (6 * t3 < 1)
  811. val = t1 + (t2 - t1) * 6 * t3;
  812. else if (2 * t3 < 1)
  813. val = t2;
  814. else if (3 * t3 < 2)
  815. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  816. else
  817. val = t1;
  818. rgb[i] = val * 255;
  819. }
  820. return rgb;
  821. }
  822. function hsl2hsv(hsl) {
  823. var h = hsl[0],
  824. s = hsl[1] / 100,
  825. l = hsl[2] / 100,
  826. sv, v;
  827. if(l === 0) {
  828. // no need to do calc on black
  829. // also avoids divide by 0 error
  830. return [0, 0, 0];
  831. }
  832. l *= 2;
  833. s *= (l <= 1) ? l : 2 - l;
  834. v = (l + s) / 2;
  835. sv = (2 * s) / (l + s);
  836. return [h, sv * 100, v * 100];
  837. }
  838. function hsl2hwb(args) {
  839. return rgb2hwb(hsl2rgb(args));
  840. }
  841. function hsl2cmyk(args) {
  842. return rgb2cmyk(hsl2rgb(args));
  843. }
  844. function hsl2keyword(args) {
  845. return rgb2keyword(hsl2rgb(args));
  846. }
  847. function hsv2rgb(hsv) {
  848. var h = hsv[0] / 60,
  849. s = hsv[1] / 100,
  850. v = hsv[2] / 100,
  851. hi = Math.floor(h) % 6;
  852. var f = h - Math.floor(h),
  853. p = 255 * v * (1 - s),
  854. q = 255 * v * (1 - (s * f)),
  855. t = 255 * v * (1 - (s * (1 - f))),
  856. v = 255 * v;
  857. switch(hi) {
  858. case 0:
  859. return [v, t, p];
  860. case 1:
  861. return [q, v, p];
  862. case 2:
  863. return [p, v, t];
  864. case 3:
  865. return [p, q, v];
  866. case 4:
  867. return [t, p, v];
  868. case 5:
  869. return [v, p, q];
  870. }
  871. }
  872. function hsv2hsl(hsv) {
  873. var h = hsv[0],
  874. s = hsv[1] / 100,
  875. v = hsv[2] / 100,
  876. sl, l;
  877. l = (2 - s) * v;
  878. sl = s * v;
  879. sl /= (l <= 1) ? l : 2 - l;
  880. sl = sl || 0;
  881. l /= 2;
  882. return [h, sl * 100, l * 100];
  883. }
  884. function hsv2hwb(args) {
  885. return rgb2hwb(hsv2rgb(args))
  886. }
  887. function hsv2cmyk(args) {
  888. return rgb2cmyk(hsv2rgb(args));
  889. }
  890. function hsv2keyword(args) {
  891. return rgb2keyword(hsv2rgb(args));
  892. }
  893. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  894. function hwb2rgb(hwb) {
  895. var h = hwb[0] / 360,
  896. wh = hwb[1] / 100,
  897. bl = hwb[2] / 100,
  898. ratio = wh + bl,
  899. i, v, f, n;
  900. // wh + bl cant be > 1
  901. if (ratio > 1) {
  902. wh /= ratio;
  903. bl /= ratio;
  904. }
  905. i = Math.floor(6 * h);
  906. v = 1 - bl;
  907. f = 6 * h - i;
  908. if ((i & 0x01) != 0) {
  909. f = 1 - f;
  910. }
  911. n = wh + f * (v - wh); // linear interpolation
  912. switch (i) {
  913. default:
  914. case 6:
  915. case 0: r = v; g = n; b = wh; break;
  916. case 1: r = n; g = v; b = wh; break;
  917. case 2: r = wh; g = v; b = n; break;
  918. case 3: r = wh; g = n; b = v; break;
  919. case 4: r = n; g = wh; b = v; break;
  920. case 5: r = v; g = wh; b = n; break;
  921. }
  922. return [r * 255, g * 255, b * 255];
  923. }
  924. function hwb2hsl(args) {
  925. return rgb2hsl(hwb2rgb(args));
  926. }
  927. function hwb2hsv(args) {
  928. return rgb2hsv(hwb2rgb(args));
  929. }
  930. function hwb2cmyk(args) {
  931. return rgb2cmyk(hwb2rgb(args));
  932. }
  933. function hwb2keyword(args) {
  934. return rgb2keyword(hwb2rgb(args));
  935. }
  936. function cmyk2rgb(cmyk) {
  937. var c = cmyk[0] / 100,
  938. m = cmyk[1] / 100,
  939. y = cmyk[2] / 100,
  940. k = cmyk[3] / 100,
  941. r, g, b;
  942. r = 1 - Math.min(1, c * (1 - k) + k);
  943. g = 1 - Math.min(1, m * (1 - k) + k);
  944. b = 1 - Math.min(1, y * (1 - k) + k);
  945. return [r * 255, g * 255, b * 255];
  946. }
  947. function cmyk2hsl(args) {
  948. return rgb2hsl(cmyk2rgb(args));
  949. }
  950. function cmyk2hsv(args) {
  951. return rgb2hsv(cmyk2rgb(args));
  952. }
  953. function cmyk2hwb(args) {
  954. return rgb2hwb(cmyk2rgb(args));
  955. }
  956. function cmyk2keyword(args) {
  957. return rgb2keyword(cmyk2rgb(args));
  958. }
  959. function xyz2rgb(xyz) {
  960. var x = xyz[0] / 100,
  961. y = xyz[1] / 100,
  962. z = xyz[2] / 100,
  963. r, g, b;
  964. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  965. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  966. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  967. // assume sRGB
  968. r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  969. : r = (r * 12.92);
  970. g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  971. : g = (g * 12.92);
  972. b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  973. : b = (b * 12.92);
  974. r = Math.min(Math.max(0, r), 1);
  975. g = Math.min(Math.max(0, g), 1);
  976. b = Math.min(Math.max(0, b), 1);
  977. return [r * 255, g * 255, b * 255];
  978. }
  979. function xyz2lab(xyz) {
  980. var x = xyz[0],
  981. y = xyz[1],
  982. z = xyz[2],
  983. l, a, b;
  984. x /= 95.047;
  985. y /= 100;
  986. z /= 108.883;
  987. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  988. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  989. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  990. l = (116 * y) - 16;
  991. a = 500 * (x - y);
  992. b = 200 * (y - z);
  993. return [l, a, b];
  994. }
  995. function xyz2lch(args) {
  996. return lab2lch(xyz2lab(args));
  997. }
  998. function lab2xyz(lab) {
  999. var l = lab[0],
  1000. a = lab[1],
  1001. b = lab[2],
  1002. x, y, z, y2;
  1003. if (l <= 8) {
  1004. y = (l * 100) / 903.3;
  1005. y2 = (7.787 * (y / 100)) + (16 / 116);
  1006. } else {
  1007. y = 100 * Math.pow((l + 16) / 116, 3);
  1008. y2 = Math.pow(y / 100, 1/3);
  1009. }
  1010. x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
  1011. z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
  1012. return [x, y, z];
  1013. }
  1014. function lab2lch(lab) {
  1015. var l = lab[0],
  1016. a = lab[1],
  1017. b = lab[2],
  1018. hr, h, c;
  1019. hr = Math.atan2(b, a);
  1020. h = hr * 360 / 2 / Math.PI;
  1021. if (h < 0) {
  1022. h += 360;
  1023. }
  1024. c = Math.sqrt(a * a + b * b);
  1025. return [l, c, h];
  1026. }
  1027. function lab2rgb(args) {
  1028. return xyz2rgb(lab2xyz(args));
  1029. }
  1030. function lch2lab(lch) {
  1031. var l = lch[0],
  1032. c = lch[1],
  1033. h = lch[2],
  1034. a, b, hr;
  1035. hr = h / 360 * 2 * Math.PI;
  1036. a = c * Math.cos(hr);
  1037. b = c * Math.sin(hr);
  1038. return [l, a, b];
  1039. }
  1040. function lch2xyz(args) {
  1041. return lab2xyz(lch2lab(args));
  1042. }
  1043. function lch2rgb(args) {
  1044. return lab2rgb(lch2lab(args));
  1045. }
  1046. function keyword2rgb(keyword) {
  1047. return cssKeywords[keyword];
  1048. }
  1049. function keyword2hsl(args) {
  1050. return rgb2hsl(keyword2rgb(args));
  1051. }
  1052. function keyword2hsv(args) {
  1053. return rgb2hsv(keyword2rgb(args));
  1054. }
  1055. function keyword2hwb(args) {
  1056. return rgb2hwb(keyword2rgb(args));
  1057. }
  1058. function keyword2cmyk(args) {
  1059. return rgb2cmyk(keyword2rgb(args));
  1060. }
  1061. function keyword2lab(args) {
  1062. return rgb2lab(keyword2rgb(args));
  1063. }
  1064. function keyword2xyz(args) {
  1065. return rgb2xyz(keyword2rgb(args));
  1066. }
  1067. var cssKeywords = {
  1068. aliceblue: [240,248,255],
  1069. antiquewhite: [250,235,215],
  1070. aqua: [0,255,255],
  1071. aquamarine: [127,255,212],
  1072. azure: [240,255,255],
  1073. beige: [245,245,220],
  1074. bisque: [255,228,196],
  1075. black: [0,0,0],
  1076. blanchedalmond: [255,235,205],
  1077. blue: [0,0,255],
  1078. blueviolet: [138,43,226],
  1079. brown: [165,42,42],
  1080. burlywood: [222,184,135],
  1081. cadetblue: [95,158,160],
  1082. chartreuse: [127,255,0],
  1083. chocolate: [210,105,30],
  1084. coral: [255,127,80],
  1085. cornflowerblue: [100,149,237],
  1086. cornsilk: [255,248,220],
  1087. crimson: [220,20,60],
  1088. cyan: [0,255,255],
  1089. darkblue: [0,0,139],
  1090. darkcyan: [0,139,139],
  1091. darkgoldenrod: [184,134,11],
  1092. darkgray: [169,169,169],
  1093. darkgreen: [0,100,0],
  1094. darkgrey: [169,169,169],
  1095. darkkhaki: [189,183,107],
  1096. darkmagenta: [139,0,139],
  1097. darkolivegreen: [85,107,47],
  1098. darkorange: [255,140,0],
  1099. darkorchid: [153,50,204],
  1100. darkred: [139,0,0],
  1101. darksalmon: [233,150,122],
  1102. darkseagreen: [143,188,143],
  1103. darkslateblue: [72,61,139],
  1104. darkslategray: [47,79,79],
  1105. darkslategrey: [47,79,79],
  1106. darkturquoise: [0,206,209],
  1107. darkviolet: [148,0,211],
  1108. deeppink: [255,20,147],
  1109. deepskyblue: [0,191,255],
  1110. dimgray: [105,105,105],
  1111. dimgrey: [105,105,105],
  1112. dodgerblue: [30,144,255],
  1113. firebrick: [178,34,34],
  1114. floralwhite: [255,250,240],
  1115. forestgreen: [34,139,34],
  1116. fuchsia: [255,0,255],
  1117. gainsboro: [220,220,220],
  1118. ghostwhite: [248,248,255],
  1119. gold: [255,215,0],
  1120. goldenrod: [218,165,32],
  1121. gray: [128,128,128],
  1122. green: [0,128,0],
  1123. greenyellow: [173,255,47],
  1124. grey: [128,128,128],
  1125. honeydew: [240,255,240],
  1126. hotpink: [255,105,180],
  1127. indianred: [205,92,92],
  1128. indigo: [75,0,130],
  1129. ivory: [255,255,240],
  1130. khaki: [240,230,140],
  1131. lavender: [230,230,250],
  1132. lavenderblush: [255,240,245],
  1133. lawngreen: [124,252,0],
  1134. lemonchiffon: [255,250,205],
  1135. lightblue: [173,216,230],
  1136. lightcoral: [240,128,128],
  1137. lightcyan: [224,255,255],
  1138. lightgoldenrodyellow: [250,250,210],
  1139. lightgray: [211,211,211],
  1140. lightgreen: [144,238,144],
  1141. lightgrey: [211,211,211],
  1142. lightpink: [255,182,193],
  1143. lightsalmon: [255,160,122],
  1144. lightseagreen: [32,178,170],
  1145. lightskyblue: [135,206,250],
  1146. lightslategray: [119,136,153],
  1147. lightslategrey: [119,136,153],
  1148. lightsteelblue: [176,196,222],
  1149. lightyellow: [255,255,224],
  1150. lime: [0,255,0],
  1151. limegreen: [50,205,50],
  1152. linen: [250,240,230],
  1153. magenta: [255,0,255],
  1154. maroon: [128,0,0],
  1155. mediumaquamarine: [102,205,170],
  1156. mediumblue: [0,0,205],
  1157. mediumorchid: [186,85,211],
  1158. mediumpurple: [147,112,219],
  1159. mediumseagreen: [60,179,113],
  1160. mediumslateblue: [123,104,238],
  1161. mediumspringgreen: [0,250,154],
  1162. mediumturquoise: [72,209,204],
  1163. mediumvioletred: [199,21,133],
  1164. midnightblue: [25,25,112],
  1165. mintcream: [245,255,250],
  1166. mistyrose: [255,228,225],
  1167. moccasin: [255,228,181],
  1168. navajowhite: [255,222,173],
  1169. navy: [0,0,128],
  1170. oldlace: [253,245,230],
  1171. olive: [128,128,0],
  1172. olivedrab: [107,142,35],
  1173. orange: [255,165,0],
  1174. orangered: [255,69,0],
  1175. orchid: [218,112,214],
  1176. palegoldenrod: [238,232,170],
  1177. palegreen: [152,251,152],
  1178. paleturquoise: [175,238,238],
  1179. palevioletred: [219,112,147],
  1180. papayawhip: [255,239,213],
  1181. peachpuff: [255,218,185],
  1182. peru: [205,133,63],
  1183. pink: [255,192,203],
  1184. plum: [221,160,221],
  1185. powderblue: [176,224,230],
  1186. purple: [128,0,128],
  1187. rebeccapurple: [102, 51, 153],
  1188. red: [255,0,0],
  1189. rosybrown: [188,143,143],
  1190. royalblue: [65,105,225],
  1191. saddlebrown: [139,69,19],
  1192. salmon: [250,128,114],
  1193. sandybrown: [244,164,96],
  1194. seagreen: [46,139,87],
  1195. seashell: [255,245,238],
  1196. sienna: [160,82,45],
  1197. silver: [192,192,192],
  1198. skyblue: [135,206,235],
  1199. slateblue: [106,90,205],
  1200. slategray: [112,128,144],
  1201. slategrey: [112,128,144],
  1202. snow: [255,250,250],
  1203. springgreen: [0,255,127],
  1204. steelblue: [70,130,180],
  1205. tan: [210,180,140],
  1206. teal: [0,128,128],
  1207. thistle: [216,191,216],
  1208. tomato: [255,99,71],
  1209. turquoise: [64,224,208],
  1210. violet: [238,130,238],
  1211. wheat: [245,222,179],
  1212. white: [255,255,255],
  1213. whitesmoke: [245,245,245],
  1214. yellow: [255,255,0],
  1215. yellowgreen: [154,205,50]
  1216. };
  1217. var reverseKeywords = {};
  1218. for (var key in cssKeywords) {
  1219. reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
  1220. }
  1221. },{}],4:[function(require,module,exports){
  1222. var conversions = require(3);
  1223. var convert = function() {
  1224. return new Converter();
  1225. }
  1226. for (var func in conversions) {
  1227. // export Raw versions
  1228. convert[func + "Raw"] = (function(func) {
  1229. // accept array or plain args
  1230. return function(arg) {
  1231. if (typeof arg == "number")
  1232. arg = Array.prototype.slice.call(arguments);
  1233. return conversions[func](arg);
  1234. }
  1235. })(func);
  1236. var pair = /(\w+)2(\w+)/.exec(func),
  1237. from = pair[1],
  1238. to = pair[2];
  1239. // export rgb2hsl and ["rgb"]["hsl"]
  1240. convert[from] = convert[from] || {};
  1241. convert[from][to] = convert[func] = (function(func) {
  1242. return function(arg) {
  1243. if (typeof arg == "number")
  1244. arg = Array.prototype.slice.call(arguments);
  1245. var val = conversions[func](arg);
  1246. if (typeof val == "string" || val === undefined)
  1247. return val; // keyword
  1248. for (var i = 0; i < val.length; i++)
  1249. val[i] = Math.round(val[i]);
  1250. return val;
  1251. }
  1252. })(func);
  1253. }
  1254. /* Converter does lazy conversion and caching */
  1255. var Converter = function() {
  1256. this.convs = {};
  1257. };
  1258. /* Either get the values for a space or
  1259. set the values for a space, depending on args */
  1260. Converter.prototype.routeSpace = function(space, args) {
  1261. var values = args[0];
  1262. if (values === undefined) {
  1263. // color.rgb()
  1264. return this.getValues(space);
  1265. }
  1266. // color.rgb(10, 10, 10)
  1267. if (typeof values == "number") {
  1268. values = Array.prototype.slice.call(args);
  1269. }
  1270. return this.setValues(space, values);
  1271. };
  1272. /* Set the values for a space, invalidating cache */
  1273. Converter.prototype.setValues = function(space, values) {
  1274. this.space = space;
  1275. this.convs = {};
  1276. this.convs[space] = values;
  1277. return this;
  1278. };
  1279. /* Get the values for a space. If there's already
  1280. a conversion for the space, fetch it, otherwise
  1281. compute it */
  1282. Converter.prototype.getValues = function(space) {
  1283. var vals = this.convs[space];
  1284. if (!vals) {
  1285. var fspace = this.space,
  1286. from = this.convs[fspace];
  1287. vals = convert[fspace][space](from);
  1288. this.convs[space] = vals;
  1289. }
  1290. return vals;
  1291. };
  1292. ["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
  1293. Converter.prototype[space] = function(vals) {
  1294. return this.routeSpace(space, arguments);
  1295. }
  1296. });
  1297. module.exports = convert;
  1298. },{"3":3}],5:[function(require,module,exports){
  1299. module.exports = {
  1300. "aliceblue": [240, 248, 255],
  1301. "antiquewhite": [250, 235, 215],
  1302. "aqua": [0, 255, 255],
  1303. "aquamarine": [127, 255, 212],
  1304. "azure": [240, 255, 255],
  1305. "beige": [245, 245, 220],
  1306. "bisque": [255, 228, 196],
  1307. "black": [0, 0, 0],
  1308. "blanchedalmond": [255, 235, 205],
  1309. "blue": [0, 0, 255],
  1310. "blueviolet": [138, 43, 226],
  1311. "brown": [165, 42, 42],
  1312. "burlywood": [222, 184, 135],
  1313. "cadetblue": [95, 158, 160],
  1314. "chartreuse": [127, 255, 0],
  1315. "chocolate": [210, 105, 30],
  1316. "coral": [255, 127, 80],
  1317. "cornflowerblue": [100, 149, 237],
  1318. "cornsilk": [255, 248, 220],
  1319. "crimson": [220, 20, 60],
  1320. "cyan": [0, 255, 255],
  1321. "darkblue": [0, 0, 139],
  1322. "darkcyan": [0, 139, 139],
  1323. "darkgoldenrod": [184, 134, 11],
  1324. "darkgray": [169, 169, 169],
  1325. "darkgreen": [0, 100, 0],
  1326. "darkgrey": [169, 169, 169],
  1327. "darkkhaki": [189, 183, 107],
  1328. "darkmagenta": [139, 0, 139],
  1329. "darkolivegreen": [85, 107, 47],
  1330. "darkorange": [255, 140, 0],
  1331. "darkorchid": [153, 50, 204],
  1332. "darkred": [139, 0, 0],
  1333. "darksalmon": [233, 150, 122],
  1334. "darkseagreen": [143, 188, 143],
  1335. "darkslateblue": [72, 61, 139],
  1336. "darkslategray": [47, 79, 79],
  1337. "darkslategrey": [47, 79, 79],
  1338. "darkturquoise": [0, 206, 209],
  1339. "darkviolet": [148, 0, 211],
  1340. "deeppink": [255, 20, 147],
  1341. "deepskyblue": [0, 191, 255],
  1342. "dimgray": [105, 105, 105],
  1343. "dimgrey": [105, 105, 105],
  1344. "dodgerblue": [30, 144, 255],
  1345. "firebrick": [178, 34, 34],
  1346. "floralwhite": [255, 250, 240],
  1347. "forestgreen": [34, 139, 34],
  1348. "fuchsia": [255, 0, 255],
  1349. "gainsboro": [220, 220, 220],
  1350. "ghostwhite": [248, 248, 255],
  1351. "gold": [255, 215, 0],
  1352. "goldenrod": [218, 165, 32],
  1353. "gray": [128, 128, 128],
  1354. "green": [0, 128, 0],
  1355. "greenyellow": [173, 255, 47],
  1356. "grey": [128, 128, 128],
  1357. "honeydew": [240, 255, 240],
  1358. "hotpink": [255, 105, 180],
  1359. "indianred": [205, 92, 92],
  1360. "indigo": [75, 0, 130],
  1361. "ivory": [255, 255, 240],
  1362. "khaki": [240, 230, 140],
  1363. "lavender": [230, 230, 250],
  1364. "lavenderblush": [255, 240, 245],
  1365. "lawngreen": [124, 252, 0],
  1366. "lemonchiffon": [255, 250, 205],
  1367. "lightblue": [173, 216, 230],
  1368. "lightcoral": [240, 128, 128],
  1369. "lightcyan": [224, 255, 255],
  1370. "lightgoldenrodyellow": [250, 250, 210],
  1371. "lightgray": [211, 211, 211],
  1372. "lightgreen": [144, 238, 144],
  1373. "lightgrey": [211, 211, 211],
  1374. "lightpink": [255, 182, 193],
  1375. "lightsalmon": [255, 160, 122],
  1376. "lightseagreen": [32, 178, 170],
  1377. "lightskyblue": [135, 206, 250],
  1378. "lightslategray": [119, 136, 153],
  1379. "lightslategrey": [119, 136, 153],
  1380. "lightsteelblue": [176, 196, 222],
  1381. "lightyellow": [255, 255, 224],
  1382. "lime": [0, 255, 0],
  1383. "limegreen": [50, 205, 50],
  1384. "linen": [250, 240, 230],
  1385. "magenta": [255, 0, 255],
  1386. "maroon": [128, 0, 0],
  1387. "mediumaquamarine": [102, 205, 170],
  1388. "mediumblue": [0, 0, 205],
  1389. "mediumorchid": [186, 85, 211],
  1390. "mediumpurple": [147, 112, 219],
  1391. "mediumseagreen": [60, 179, 113],
  1392. "mediumslateblue": [123, 104, 238],
  1393. "mediumspringgreen": [0, 250, 154],
  1394. "mediumturquoise": [72, 209, 204],
  1395. "mediumvioletred": [199, 21, 133],
  1396. "midnightblue": [25, 25, 112],
  1397. "mintcream": [245, 255, 250],
  1398. "mistyrose": [255, 228, 225],
  1399. "moccasin": [255, 228, 181],
  1400. "navajowhite": [255, 222, 173],
  1401. "navy": [0, 0, 128],
  1402. "oldlace": [253, 245, 230],
  1403. "olive": [128, 128, 0],
  1404. "olivedrab": [107, 142, 35],
  1405. "orange": [255, 165, 0],
  1406. "orangered": [255, 69, 0],
  1407. "orchid": [218, 112, 214],
  1408. "palegoldenrod": [238, 232, 170],
  1409. "palegreen": [152, 251, 152],
  1410. "paleturquoise": [175, 238, 238],
  1411. "palevioletred": [219, 112, 147],
  1412. "papayawhip": [255, 239, 213],
  1413. "peachpuff": [255, 218, 185],
  1414. "peru": [205, 133, 63],
  1415. "pink": [255, 192, 203],
  1416. "plum": [221, 160, 221],
  1417. "powderblue": [176, 224, 230],
  1418. "purple": [128, 0, 128],
  1419. "rebeccapurple": [102, 51, 153],
  1420. "red": [255, 0, 0],
  1421. "rosybrown": [188, 143, 143],
  1422. "royalblue": [65, 105, 225],
  1423. "saddlebrown": [139, 69, 19],
  1424. "salmon": [250, 128, 114],
  1425. "sandybrown": [244, 164, 96],
  1426. "seagreen": [46, 139, 87],
  1427. "seashell": [255, 245, 238],
  1428. "sienna": [160, 82, 45],
  1429. "silver": [192, 192, 192],
  1430. "skyblue": [135, 206, 235],
  1431. "slateblue": [106, 90, 205],
  1432. "slategray": [112, 128, 144],
  1433. "slategrey": [112, 128, 144],
  1434. "snow": [255, 250, 250],
  1435. "springgreen": [0, 255, 127],
  1436. "steelblue": [70, 130, 180],
  1437. "tan": [210, 180, 140],
  1438. "teal": [0, 128, 128],
  1439. "thistle": [216, 191, 216],
  1440. "tomato": [255, 99, 71],
  1441. "turquoise": [64, 224, 208],
  1442. "violet": [238, 130, 238],
  1443. "wheat": [245, 222, 179],
  1444. "white": [255, 255, 255],
  1445. "whitesmoke": [245, 245, 245],
  1446. "yellow": [255, 255, 0],
  1447. "yellowgreen": [154, 205, 50]
  1448. };
  1449. },{}],6:[function(require,module,exports){
  1450. //! moment.js
  1451. //! version : 2.14.1
  1452. //! authors : Tim Wood, Iskren Chernev, Moment.js contributors
  1453. //! license : MIT
  1454. //! momentjs.com
  1455. ;(function (global, factory) {
  1456. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  1457. typeof define === 'function' && define.amd ? define(factory) :
  1458. global.moment = factory()
  1459. }(this, function () { 'use strict';
  1460. var hookCallback;
  1461. function utils_hooks__hooks () {
  1462. return hookCallback.apply(null, arguments);
  1463. }
  1464. // This is done to register the method called with moment()
  1465. // without creating circular dependencies.
  1466. function setHookCallback (callback) {
  1467. hookCallback = callback;
  1468. }
  1469. function isArray(input) {
  1470. return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
  1471. }
  1472. function isObject(input) {
  1473. return Object.prototype.toString.call(input) === '[object Object]';
  1474. }
  1475. function isObjectEmpty(obj) {
  1476. var k;
  1477. for (k in obj) {
  1478. // even if its not own property I'd still call it non-empty
  1479. return false;
  1480. }
  1481. return true;
  1482. }
  1483. function isDate(input) {
  1484. return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
  1485. }
  1486. function map(arr, fn) {
  1487. var res = [], i;
  1488. for (i = 0; i < arr.length; ++i) {
  1489. res.push(fn(arr[i], i));
  1490. }
  1491. return res;
  1492. }
  1493. function hasOwnProp(a, b) {
  1494. return Object.prototype.hasOwnProperty.call(a, b);
  1495. }
  1496. function extend(a, b) {
  1497. for (var i in b) {
  1498. if (hasOwnProp(b, i)) {
  1499. a[i] = b[i];
  1500. }
  1501. }
  1502. if (hasOwnProp(b, 'toString')) {
  1503. a.toString = b.toString;
  1504. }
  1505. if (hasOwnProp(b, 'valueOf')) {
  1506. a.valueOf = b.valueOf;
  1507. }
  1508. return a;
  1509. }
  1510. function create_utc__createUTC (input, format, locale, strict) {
  1511. return createLocalOrUTC(input, format, locale, strict, true).utc();
  1512. }
  1513. function defaultParsingFlags() {
  1514. // We need to deep clone this object.
  1515. return {
  1516. empty : false,
  1517. unusedTokens : [],
  1518. unusedInput : [],
  1519. overflow : -2,
  1520. charsLeftOver : 0,
  1521. nullInput : false,
  1522. invalidMonth : null,
  1523. invalidFormat : false,
  1524. userInvalidated : false,
  1525. iso : false,
  1526. parsedDateParts : [],
  1527. meridiem : null
  1528. };
  1529. }
  1530. function getParsingFlags(m) {
  1531. if (m._pf == null) {
  1532. m._pf = defaultParsingFlags();
  1533. }
  1534. return m._pf;
  1535. }
  1536. var some;
  1537. if (Array.prototype.some) {
  1538. some = Array.prototype.some;
  1539. } else {
  1540. some = function (fun) {
  1541. var t = Object(this);
  1542. var len = t.length >>> 0;
  1543. for (var i = 0; i < len; i++) {
  1544. if (i in t && fun.call(this, t[i], i, t)) {
  1545. return true;
  1546. }
  1547. }
  1548. return false;
  1549. };
  1550. }
  1551. function valid__isValid(m) {
  1552. if (m._isValid == null) {
  1553. var flags = getParsingFlags(m);
  1554. var parsedParts = some.call(flags.parsedDateParts, function (i) {
  1555. return i != null;
  1556. });
  1557. m._isValid = !isNaN(m._d.getTime()) &&
  1558. flags.overflow < 0 &&
  1559. !flags.empty &&
  1560. !flags.invalidMonth &&
  1561. !flags.invalidWeekday &&
  1562. !flags.nullInput &&
  1563. !flags.invalidFormat &&
  1564. !flags.userInvalidated &&
  1565. (!flags.meridiem || (flags.meridiem && parsedParts));
  1566. if (m._strict) {
  1567. m._isValid = m._isValid &&
  1568. flags.charsLeftOver === 0 &&
  1569. flags.unusedTokens.length === 0 &&
  1570. flags.bigHour === undefined;
  1571. }
  1572. }
  1573. return m._isValid;
  1574. }
  1575. function valid__createInvalid (flags) {
  1576. var m = create_utc__createUTC(NaN);
  1577. if (flags != null) {
  1578. extend(getParsingFlags(m), flags);
  1579. }
  1580. else {
  1581. getParsingFlags(m).userInvalidated = true;
  1582. }
  1583. return m;
  1584. }
  1585. function isUndefined(input) {
  1586. return input === void 0;
  1587. }
  1588. // Plugins that add properties should also add the key here (null value),
  1589. // so we can properly clone ourselves.
  1590. var momentProperties = utils_hooks__hooks.momentProperties = [];
  1591. function copyConfig(to, from) {
  1592. var i, prop, val;
  1593. if (!isUndefined(from._isAMomentObject)) {
  1594. to._isAMomentObject = from._isAMomentObject;
  1595. }
  1596. if (!isUndefined(from._i)) {
  1597. to._i = from._i;
  1598. }
  1599. if (!isUndefined(from._f)) {
  1600. to._f = from._f;
  1601. }
  1602. if (!isUndefined(from._l)) {
  1603. to._l = from._l;
  1604. }
  1605. if (!isUndefined(from._strict)) {
  1606. to._strict = from._strict;
  1607. }
  1608. if (!isUndefined(from._tzm)) {
  1609. to._tzm = from._tzm;
  1610. }
  1611. if (!isUndefined(from._isUTC)) {
  1612. to._isUTC = from._isUTC;
  1613. }
  1614. if (!isUndefined(from._offset)) {
  1615. to._offset = from._offset;
  1616. }
  1617. if (!isUndefined(from._pf)) {
  1618. to._pf = getParsingFlags(from);
  1619. }
  1620. if (!isUndefined(from._locale)) {
  1621. to._locale = from._locale;
  1622. }
  1623. if (momentProperties.length > 0) {
  1624. for (i in momentProperties) {
  1625. prop = momentProperties[i];
  1626. val = from[prop];
  1627. if (!isUndefined(val)) {
  1628. to[prop] = val;
  1629. }
  1630. }
  1631. }
  1632. return to;
  1633. }
  1634. var updateInProgress = false;
  1635. // Moment prototype object
  1636. function Moment(config) {
  1637. copyConfig(this, config);
  1638. this._d = new Date(config._d != null ? config._d.getTime() : NaN);
  1639. // Prevent infinite loop in case updateOffset creates new moment
  1640. // objects.
  1641. if (updateInProgress === false) {
  1642. updateInProgress = true;
  1643. utils_hooks__hooks.updateOffset(this);
  1644. updateInProgress = false;
  1645. }
  1646. }
  1647. function isMoment (obj) {
  1648. return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
  1649. }
  1650. function absFloor (number) {
  1651. if (number < 0) {
  1652. // -0 -> 0
  1653. return Math.ceil(number) || 0;
  1654. } else {
  1655. return Math.floor(number);
  1656. }
  1657. }
  1658. function toInt(argumentForCoercion) {
  1659. var coercedNumber = +argumentForCoercion,
  1660. value = 0;
  1661. if (coercedNumber !== 0 && isFinite(coercedNumber)) {
  1662. value = absFloor(coercedNumber);
  1663. }
  1664. return value;
  1665. }
  1666. // compare two arrays, return the number of differences
  1667. function compareArrays(array1, array2, dontConvert) {
  1668. var len = Math.min(array1.length, array2.length),
  1669. lengthDiff = Math.abs(array1.length - array2.length),
  1670. diffs = 0,
  1671. i;
  1672. for (i = 0; i < len; i++) {
  1673. if ((dontConvert && array1[i] !== array2[i]) ||
  1674. (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
  1675. diffs++;
  1676. }
  1677. }
  1678. return diffs + lengthDiff;
  1679. }
  1680. function warn(msg) {
  1681. if (utils_hooks__hooks.suppressDeprecationWarnings === false &&
  1682. (typeof console !== 'undefined') && console.warn) {
  1683. console.warn('Deprecation warning: ' + msg);
  1684. }
  1685. }
  1686. function deprecate(msg, fn) {
  1687. var firstTime = true;
  1688. return extend(function () {
  1689. if (utils_hooks__hooks.deprecationHandler != null) {
  1690. utils_hooks__hooks.deprecationHandler(null, msg);
  1691. }
  1692. if (firstTime) {
  1693. warn(msg + '\nArguments: ' + Array.prototype.slice.call(arguments).join(', ') + '\n' + (new Error()).stack);
  1694. firstTime = false;
  1695. }
  1696. return fn.apply(this, arguments);
  1697. }, fn);
  1698. }
  1699. var deprecations = {};
  1700. function deprecateSimple(name, msg) {
  1701. if (utils_hooks__hooks.deprecationHandler != null) {
  1702. utils_hooks__hooks.deprecationHandler(name, msg);
  1703. }
  1704. if (!deprecations[name]) {
  1705. warn(msg);
  1706. deprecations[name] = true;
  1707. }
  1708. }
  1709. utils_hooks__hooks.suppressDeprecationWarnings = false;
  1710. utils_hooks__hooks.deprecationHandler = null;
  1711. function isFunction(input) {
  1712. return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
  1713. }
  1714. function locale_set__set (config) {
  1715. var prop, i;
  1716. for (i in config) {
  1717. prop = config[i];
  1718. if (isFunction(prop)) {
  1719. this[i] = prop;
  1720. } else {
  1721. this['_' + i] = prop;
  1722. }
  1723. }
  1724. this._config = config;
  1725. // Lenient ordinal parsing accepts just a number in addition to
  1726. // number + (possibly) stuff coming from _ordinalParseLenient.
  1727. this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\d{1,2}/).source);
  1728. }
  1729. function mergeConfigs(parentConfig, childConfig) {
  1730. var res = extend({}, parentConfig), prop;
  1731. for (prop in childConfig) {
  1732. if (hasOwnProp(childConfig, prop)) {
  1733. if (isObject(parentConfig[prop]) && isObject(childConfig[prop])) {
  1734. res[prop] = {};
  1735. extend(res[prop], parentConfig[prop]);
  1736. extend(res[prop], childConfig[prop]);
  1737. } else if (childConfig[prop] != null) {
  1738. res[prop] = childConfig[prop];
  1739. } else {
  1740. delete res[prop];
  1741. }
  1742. }
  1743. }
  1744. for (prop in parentConfig) {
  1745. if (hasOwnProp(parentConfig, prop) &&
  1746. !hasOwnProp(childConfig, prop) &&
  1747. isObject(parentConfig[prop])) {
  1748. // make sure changes to properties don't modify parent config
  1749. res[prop] = extend({}, res[prop]);
  1750. }
  1751. }
  1752. return res;
  1753. }
  1754. function Locale(config) {
  1755. if (config != null) {
  1756. this.set(config);
  1757. }
  1758. }
  1759. var keys;
  1760. if (Object.keys) {
  1761. keys = Object.keys;
  1762. } else {
  1763. keys = function (obj) {
  1764. var i, res = [];
  1765. for (i in obj) {
  1766. if (hasOwnProp(obj, i)) {
  1767. res.push(i);
  1768. }
  1769. }
  1770. return res;
  1771. };
  1772. }
  1773. var defaultCalendar = {
  1774. sameDay : '[Today at] LT',
  1775. nextDay : '[Tomorrow at] LT',
  1776. nextWeek : 'dddd [at] LT',
  1777. lastDay : '[Yesterday at] LT',
  1778. lastWeek : '[Last] dddd [at] LT',
  1779. sameElse : 'L'
  1780. };
  1781. function locale_calendar__calendar (key, mom, now) {
  1782. var output = this._calendar[key] || this._calendar['sameElse'];
  1783. return isFunction(output) ? output.call(mom, now) : output;
  1784. }
  1785. var defaultLongDateFormat = {
  1786. LTS : 'h:mm:ss A',
  1787. LT : 'h:mm A',
  1788. L : 'MM/DD/YYYY',
  1789. LL : 'MMMM D, YYYY',
  1790. LLL : 'MMMM D, YYYY h:mm A',
  1791. LLLL : 'dddd, MMMM D, YYYY h:mm A'
  1792. };
  1793. function longDateFormat (key) {
  1794. var format = this._longDateFormat[key],
  1795. formatUpper = this._longDateFormat[key.toUpperCase()];
  1796. if (format || !formatUpper) {
  1797. return format;
  1798. }
  1799. this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
  1800. return val.slice(1);
  1801. });
  1802. return this._longDateFormat[key];
  1803. }
  1804. var defaultInvalidDate = 'Invalid date';
  1805. function invalidDate () {
  1806. return this._invalidDate;
  1807. }
  1808. var defaultOrdinal = '%d';
  1809. var defaultOrdinalParse = /\d{1,2}/;
  1810. function ordinal (number) {
  1811. return this._ordinal.replace('%d', number);
  1812. }
  1813. var defaultRelativeTime = {
  1814. future : 'in %s',
  1815. past : '%s ago',
  1816. s : 'a few seconds',
  1817. m : 'a minute',
  1818. mm : '%d minutes',
  1819. h : 'an hour',
  1820. hh : '%d hours',
  1821. d : 'a day',
  1822. dd : '%d days',
  1823. M : 'a month',
  1824. MM : '%d months',
  1825. y : 'a year',
  1826. yy : '%d years'
  1827. };
  1828. function relative__relativeTime (number, withoutSuffix, string, isFuture) {
  1829. var output = this._relativeTime[string];
  1830. return (isFunction(output)) ?
  1831. output(number, withoutSuffix, string, isFuture) :
  1832. output.replace(/%d/i, number);
  1833. }
  1834. function pastFuture (diff, output) {
  1835. var format = this._relativeTime[diff > 0 ? 'future' : 'past'];
  1836. return isFunction(format) ? format(output) : format.replace(/%s/i, output);
  1837. }
  1838. var aliases = {};
  1839. function addUnitAlias (unit, shorthand) {
  1840. var lowerCase = unit.toLowerCase();
  1841. aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;
  1842. }
  1843. function normalizeUnits(units) {
  1844. return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;
  1845. }
  1846. function normalizeObjectUnits(inputObject) {
  1847. var normalizedInput = {},
  1848. normalizedProp,
  1849. prop;
  1850. for (prop in inputObject) {
  1851. if (hasOwnProp(inputObject, prop)) {
  1852. normalizedProp = normalizeUnits(prop);
  1853. if (normalizedProp) {
  1854. normalizedInput[normalizedProp] = inputObject[prop];
  1855. }
  1856. }
  1857. }
  1858. return normalizedInput;
  1859. }
  1860. var priorities = {};
  1861. function addUnitPriority(unit, priority) {
  1862. priorities[unit] = priority;
  1863. }
  1864. function getPrioritizedUnits(unitsObj) {
  1865. var units = [];
  1866. for (var u in unitsObj) {
  1867. units.push({unit: u, priority: priorities[u]});
  1868. }
  1869. units.sort(function (a, b) {
  1870. return a.priority - b.priority;
  1871. });
  1872. return units;
  1873. }
  1874. function makeGetSet (unit, keepTime) {
  1875. return function (value) {
  1876. if (value != null) {
  1877. get_set__set(this, unit, value);
  1878. utils_hooks__hooks.updateOffset(this, keepTime);
  1879. return this;
  1880. } else {
  1881. return get_set__get(this, unit);
  1882. }
  1883. };
  1884. }
  1885. function get_set__get (mom, unit) {
  1886. return mom.isValid() ?
  1887. mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
  1888. }
  1889. function get_set__set (mom, unit, value) {
  1890. if (mom.isValid()) {
  1891. mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
  1892. }
  1893. }
  1894. // MOMENTS
  1895. function stringGet (units) {
  1896. units = normalizeUnits(units);
  1897. if (isFunction(this[units])) {
  1898. return this[units]();
  1899. }
  1900. return this;
  1901. }
  1902. function stringSet (units, value) {
  1903. if (typeof units === 'object') {
  1904. units = normalizeObjectUnits(units);
  1905. var prioritized = getPrioritizedUnits(units);
  1906. for (var i = 0; i < prioritized.length; i++) {
  1907. this[prioritized[i].unit](units[prioritized[i].unit]);
  1908. }
  1909. } else {
  1910. units = normalizeUnits(units);
  1911. if (isFunction(this[units])) {
  1912. return this[units](value);
  1913. }
  1914. }
  1915. return this;
  1916. }
  1917. function zeroFill(number, targetLength, forceSign) {
  1918. var absNumber = '' + Math.abs(number),
  1919. zerosToFill = targetLength - absNumber.length,
  1920. sign = number >= 0;
  1921. return (sign ? (forceSign ? '+' : '') : '-') +
  1922. Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
  1923. }
  1924. var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;
  1925. var localFormattingTokens = /(\[[^\[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g;
  1926. var formatFunctions = {};
  1927. var formatTokenFunctions = {};
  1928. // token: 'M'
  1929. // padded: ['MM', 2]
  1930. // ordinal: 'Mo'
  1931. // callback: function () { this.month() + 1 }
  1932. function addFormatToken (token, padded, ordinal, callback) {
  1933. var func = callback;
  1934. if (typeof callback === 'string') {
  1935. func = function () {
  1936. return this[callback]();
  1937. };
  1938. }
  1939. if (token) {
  1940. formatTokenFunctions[token] = func;
  1941. }
  1942. if (padded) {
  1943. formatTokenFunctions[padded[0]] = function () {
  1944. return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
  1945. };
  1946. }
  1947. if (ordinal) {
  1948. formatTokenFunctions[ordinal] = function () {
  1949. return this.localeData().ordinal(func.apply(this, arguments), token);
  1950. };
  1951. }
  1952. }
  1953. function removeFormattingTokens(input) {
  1954. if (input.match(/\[[\s\S]/)) {
  1955. return input.replace(/^\[|\]$/g, '');
  1956. }
  1957. return input.replace(/\\/g, '');
  1958. }
  1959. function makeFormatFunction(format) {
  1960. var array = format.match(formattingTokens), i, length;
  1961. for (i = 0, length = array.length; i < length; i++) {
  1962. if (formatTokenFunctions[array[i]]) {
  1963. array[i] = formatTokenFunctions[array[i]];
  1964. } else {
  1965. array[i] = removeFormattingTokens(array[i]);
  1966. }
  1967. }
  1968. return function (mom) {
  1969. var output = '', i;
  1970. for (i = 0; i < length; i++) {
  1971. output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];
  1972. }
  1973. return output;
  1974. };
  1975. }
  1976. // format date using native date object
  1977. function formatMoment(m, format) {
  1978. if (!m.isValid()) {
  1979. return m.localeData().invalidDate();
  1980. }
  1981. format = expandFormat(format, m.localeData());
  1982. formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);
  1983. return formatFunctions[format](m);
  1984. }
  1985. function expandFormat(format, locale) {
  1986. var i = 5;
  1987. function replaceLongDateFormatTokens(input) {
  1988. return locale.longDateFormat(input) || input;
  1989. }
  1990. localFormattingTokens.lastIndex = 0;
  1991. while (i >= 0 && localFormattingTokens.test(format)) {
  1992. format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);
  1993. localFormattingTokens.lastIndex = 0;
  1994. i -= 1;
  1995. }
  1996. return format;
  1997. }
  1998. var match1 = /\d/; // 0 - 9
  1999. var match2 = /\d\d/; // 00 - 99
  2000. var match3 = /\d{3}/; // 000 - 999
  2001. var match4 = /\d{4}/; // 0000 - 9999
  2002. var match6 = /[+-]?\d{6}/; // -999999 - 999999
  2003. var match1to2 = /\d\d?/; // 0 - 99
  2004. var match3to4 = /\d\d\d\d?/; // 999 - 9999
  2005. var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
  2006. var match1to3 = /\d{1,3}/; // 0 - 999
  2007. var match1to4 = /\d{1,4}/; // 0 - 9999
  2008. var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
  2009. var matchUnsigned = /\d+/; // 0 - inf
  2010. var matchSigned = /[+-]?\d+/; // -inf - inf
  2011. var matchOffset = /Z|[+-]\d\d:?\d\d/gi; // +00:00 -00:00 +0000 -0000 or Z
  2012. var matchShortOffset = /Z|[+-]\d\d(?::?\d\d)?/gi; // +00 -00 +00:00 -00:00 +0000 -0000 or Z
  2013. var matchTimestamp = /[+-]?\d+(\.\d{1,3})?/; // 123456789 123456789.123
  2014. // any word (or two) characters or numbers including two/three word month in arabic.
  2015. // includes scottish gaelic two word and hyphenated months
  2016. var matchWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i;
  2017. var regexes = {};
  2018. function addRegexToken (token, regex, strictRegex) {
  2019. regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
  2020. return (isStrict && strictRegex) ? strictRegex : regex;
  2021. };
  2022. }
  2023. function getParseRegexForToken (token, config) {
  2024. if (!hasOwnProp(regexes, token)) {
  2025. return new RegExp(unescapeFormat(token));
  2026. }
  2027. return regexes[token](config._strict, config._locale);
  2028. }
  2029. // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
  2030. function unescapeFormat(s) {
  2031. return regexEscape(s.replace('\\', '').replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g, function (matched, p1, p2, p3, p4) {
  2032. return p1 || p2 || p3 || p4;
  2033. }));
  2034. }
  2035. function regexEscape(s) {
  2036. return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  2037. }
  2038. var tokens = {};
  2039. function addParseToken (token, callback) {
  2040. var i, func = callback;
  2041. if (typeof token === 'string') {
  2042. token = [token];
  2043. }
  2044. if (typeof callback === 'number') {
  2045. func = function (input, array) {
  2046. array[callback] = toInt(input);
  2047. };
  2048. }
  2049. for (i = 0; i < token.length; i++) {
  2050. tokens[token[i]] = func;
  2051. }
  2052. }
  2053. function addWeekParseToken (token, callback) {
  2054. addParseToken(token, function (input, array, config, token) {
  2055. config._w = config._w || {};
  2056. callback(input, config._w, config, token);
  2057. });
  2058. }
  2059. function addTimeToArrayFromToken(token, input, config) {
  2060. if (input != null && hasOwnProp(tokens, token)) {
  2061. tokens[token](input, config._a, config, token);
  2062. }
  2063. }
  2064. var YEAR = 0;
  2065. var MONTH = 1;
  2066. var DATE = 2;
  2067. var HOUR = 3;
  2068. var MINUTE = 4;
  2069. var SECOND = 5;
  2070. var MILLISECOND = 6;
  2071. var WEEK = 7;
  2072. var WEEKDAY = 8;
  2073. var indexOf;
  2074. if (Array.prototype.indexOf) {
  2075. indexOf = Array.prototype.indexOf;
  2076. } else {
  2077. indexOf = function (o) {
  2078. // I know
  2079. var i;
  2080. for (i = 0; i < this.length; ++i) {
  2081. if (this[i] === o) {
  2082. return i;
  2083. }
  2084. }
  2085. return -1;
  2086. };
  2087. }
  2088. function daysInMonth(year, month) {
  2089. return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
  2090. }
  2091. // FORMATTING
  2092. addFormatToken('M', ['MM', 2], 'Mo', function () {
  2093. return this.month() + 1;
  2094. });
  2095. addFormatToken('MMM', 0, 0, function (format) {
  2096. return this.localeData().monthsShort(this, format);
  2097. });
  2098. addFormatToken('MMMM', 0, 0, function (format) {
  2099. return this.localeData().months(this, format);
  2100. });
  2101. // ALIASES
  2102. addUnitAlias('month', 'M');
  2103. // PRIORITY
  2104. addUnitPriority('month', 8);
  2105. // PARSING
  2106. addRegexToken('M', match1to2);
  2107. addRegexToken('MM', match1to2, match2);
  2108. addRegexToken('MMM', function (isStrict, locale) {
  2109. return locale.monthsShortRegex(isStrict);
  2110. });
  2111. addRegexToken('MMMM', function (isStrict, locale) {
  2112. return locale.monthsRegex(isStrict);
  2113. });
  2114. addParseToken(['M', 'MM'], function (input, array) {
  2115. array[MONTH] = toInt(input) - 1;
  2116. });
  2117. addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
  2118. var month = config._locale.monthsParse(input, token, config._strict);
  2119. // if we didn't find a month name, mark the date as invalid.
  2120. if (month != null) {
  2121. array[MONTH] = month;
  2122. } else {
  2123. getParsingFlags(config).invalidMonth = input;
  2124. }
  2125. });
  2126. // LOCALES
  2127. var MONTHS_IN_FORMAT = /D[oD]?(\[[^\[\]]*\]|\s+)+MMMM?/;
  2128. var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');
  2129. function localeMonths (m, format) {
  2130. return isArray(this._months) ? this._months[m.month()] :
  2131. this._months[(this._months.isFormat || MONTHS_IN_FORMAT).test(format) ? 'format' : 'standalone'][m.month()];
  2132. }
  2133. var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');
  2134. function localeMonthsShort (m, format) {
  2135. return isArray(this._monthsShort) ? this._monthsShort[m.month()] :
  2136. this._monthsShort[MONTHS_IN_FORMAT.test(format) ? 'format' : 'standalone'][m.month()];
  2137. }
  2138. function units_month__handleStrictParse(monthName, format, strict) {
  2139. var i, ii, mom, llc = monthName.toLocaleLowerCase();
  2140. if (!this._monthsParse) {
  2141. // this is not used
  2142. this._monthsParse = [];
  2143. this._longMonthsParse = [];
  2144. this._shortMonthsParse = [];
  2145. for (i = 0; i < 12; ++i) {
  2146. mom = create_utc__createUTC([2000, i]);
  2147. this._shortMonthsParse[i] = this.monthsShort(mom, '').toLocaleLowerCase();
  2148. this._longMonthsParse[i] = this.months(mom, '').toLocaleLowerCase();
  2149. }
  2150. }
  2151. if (strict) {
  2152. if (format === 'MMM') {
  2153. ii = indexOf.call(this._shortMonthsParse, llc);
  2154. return ii !== -1 ? ii : null;
  2155. } else {
  2156. ii = indexOf.call(this._longMonthsParse, llc);
  2157. return ii !== -1 ? ii : null;
  2158. }
  2159. } else {
  2160. if (format === 'MMM') {
  2161. ii = indexOf.call(this._shortMonthsParse, llc);
  2162. if (ii !== -1) {
  2163. return ii;
  2164. }
  2165. ii = indexOf.call(this._longMonthsParse, llc);
  2166. return ii !== -1 ? ii : null;
  2167. } else {
  2168. ii = indexOf.call(this._longMonthsParse, llc);
  2169. if (ii !== -1) {
  2170. return ii;
  2171. }
  2172. ii = indexOf.call(this._shortMonthsParse, llc);
  2173. return ii !== -1 ? ii : null;
  2174. }
  2175. }
  2176. }
  2177. function localeMonthsParse (monthName, format, strict) {
  2178. var i, mom, regex;
  2179. if (this._monthsParseExact) {
  2180. return units_month__handleStrictParse.call(this, monthName, format, strict);
  2181. }
  2182. if (!this._monthsParse) {
  2183. this._monthsParse = [];
  2184. this._longMonthsParse = [];
  2185. this._shortMonthsParse = [];
  2186. }
  2187. // TODO: add sorting
  2188. // Sorting makes sure if one month (or abbr) is a prefix of another
  2189. // see sorting in computeMonthsParse
  2190. for (i = 0; i < 12; i++) {
  2191. // make the regex if we don't have it already
  2192. mom = create_utc__createUTC([2000, i]);
  2193. if (strict && !this._longMonthsParse[i]) {
  2194. this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');
  2195. this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');
  2196. }
  2197. if (!strict && !this._monthsParse[i]) {
  2198. regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');
  2199. this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');
  2200. }
  2201. // test the regex
  2202. if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {
  2203. return i;
  2204. } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {
  2205. return i;
  2206. } else if (!strict && this._monthsParse[i].test(monthName)) {
  2207. return i;
  2208. }
  2209. }
  2210. }
  2211. // MOMENTS
  2212. function setMonth (mom, value) {
  2213. var dayOfMonth;
  2214. if (!mom.isValid()) {
  2215. // No op
  2216. return mom;
  2217. }
  2218. if (typeof value === 'string') {
  2219. if (/^\d+$/.test(value)) {
  2220. value = toInt(value);
  2221. } else {
  2222. value = mom.localeData().monthsParse(value);
  2223. // TODO: Another silent failure?
  2224. if (typeof value !== 'number') {
  2225. return mom;
  2226. }
  2227. }
  2228. }
  2229. dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));
  2230. mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);
  2231. return mom;
  2232. }
  2233. function getSetMonth (value) {
  2234. if (value != null) {
  2235. setMonth(this, value);
  2236. utils_hooks__hooks.updateOffset(this, true);
  2237. return this;
  2238. } else {
  2239. return get_set__get(this, 'Month');
  2240. }
  2241. }
  2242. function getDaysInMonth () {
  2243. return daysInMonth(this.year(), this.month());
  2244. }
  2245. var defaultMonthsShortRegex = matchWord;
  2246. function monthsShortRegex (isStrict) {
  2247. if (this._monthsParseExact) {
  2248. if (!hasOwnProp(this, '_monthsRegex')) {
  2249. computeMonthsParse.call(this);
  2250. }
  2251. if (isStrict) {
  2252. return this._monthsShortStrictRegex;
  2253. } else {
  2254. return this._monthsShortRegex;
  2255. }
  2256. } else {
  2257. if (!hasOwnProp(this, '_monthsShortRegex')) {
  2258. this._monthsShortRegex = defaultMonthsShortRegex;
  2259. }
  2260. return this._monthsShortStrictRegex && isStrict ?
  2261. this._monthsShortStrictRegex : this._monthsShortRegex;
  2262. }
  2263. }
  2264. var defaultMonthsRegex = matchWord;
  2265. function monthsRegex (isStrict) {
  2266. if (this._monthsParseExact) {
  2267. if (!hasOwnProp(this, '_monthsRegex')) {
  2268. computeMonthsParse.call(this);
  2269. }
  2270. if (isStrict) {
  2271. return this._monthsStrictRegex;
  2272. } else {
  2273. return this._monthsRegex;
  2274. }
  2275. } else {
  2276. if (!hasOwnProp(this, '_monthsRegex')) {
  2277. this._monthsRegex = defaultMonthsRegex;
  2278. }
  2279. return this._monthsStrictRegex && isStrict ?
  2280. this._monthsStrictRegex : this._monthsRegex;
  2281. }
  2282. }
  2283. function computeMonthsParse () {
  2284. function cmpLenRev(a, b) {
  2285. return b.length - a.length;
  2286. }
  2287. var shortPieces = [], longPieces = [], mixedPieces = [],
  2288. i, mom;
  2289. for (i = 0; i < 12; i++) {
  2290. // make the regex if we don't have it already
  2291. mom = create_utc__createUTC([2000, i]);
  2292. shortPieces.push(this.monthsShort(mom, ''));
  2293. longPieces.push(this.months(mom, ''));
  2294. mixedPieces.push(this.months(mom, ''));
  2295. mixedPieces.push(this.monthsShort(mom, ''));
  2296. }
  2297. // Sorting makes sure if one month (or abbr) is a prefix of another it
  2298. // will match the longer piece.
  2299. shortPieces.sort(cmpLenRev);
  2300. longPieces.sort(cmpLenRev);
  2301. mixedPieces.sort(cmpLenRev);
  2302. for (i = 0; i < 12; i++) {
  2303. shortPieces[i] = regexEscape(shortPieces[i]);
  2304. longPieces[i] = regexEscape(longPieces[i]);
  2305. }
  2306. for (i = 0; i < 24; i++) {
  2307. mixedPieces[i] = regexEscape(mixedPieces[i]);
  2308. }
  2309. this._monthsRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  2310. this._monthsShortRegex = this._monthsRegex;
  2311. this._monthsStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  2312. this._monthsShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  2313. }
  2314. // FORMATTING
  2315. addFormatToken('Y', 0, 0, function () {
  2316. var y = this.year();
  2317. return y <= 9999 ? '' + y : '+' + y;
  2318. });
  2319. addFormatToken(0, ['YY', 2], 0, function () {
  2320. return this.year() % 100;
  2321. });
  2322. addFormatToken(0, ['YYYY', 4], 0, 'year');
  2323. addFormatToken(0, ['YYYYY', 5], 0, 'year');
  2324. addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
  2325. // ALIASES
  2326. addUnitAlias('year', 'y');
  2327. // PRIORITIES
  2328. addUnitPriority('year', 1);
  2329. // PARSING
  2330. addRegexToken('Y', matchSigned);
  2331. addRegexToken('YY', match1to2, match2);
  2332. addRegexToken('YYYY', match1to4, match4);
  2333. addRegexToken('YYYYY', match1to6, match6);
  2334. addRegexToken('YYYYYY', match1to6, match6);
  2335. addParseToken(['YYYYY', 'YYYYYY'], YEAR);
  2336. addParseToken('YYYY', function (input, array) {
  2337. array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input);
  2338. });
  2339. addParseToken('YY', function (input, array) {
  2340. array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input);
  2341. });
  2342. addParseToken('Y', function (input, array) {
  2343. array[YEAR] = parseInt(input, 10);
  2344. });
  2345. // HELPERS
  2346. function daysInYear(year) {
  2347. return isLeapYear(year) ? 366 : 365;
  2348. }
  2349. function isLeapYear(year) {
  2350. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  2351. }
  2352. // HOOKS
  2353. utils_hooks__hooks.parseTwoDigitYear = function (input) {
  2354. return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
  2355. };
  2356. // MOMENTS
  2357. var getSetYear = makeGetSet('FullYear', true);
  2358. function getIsLeapYear () {
  2359. return isLeapYear(this.year());
  2360. }
  2361. function createDate (y, m, d, h, M, s, ms) {
  2362. //can't just apply() to create a date:
  2363. //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply
  2364. var date = new Date(y, m, d, h, M, s, ms);
  2365. //the date constructor remaps years 0-99 to 1900-1999
  2366. if (y < 100 && y >= 0 && isFinite(date.getFullYear())) {
  2367. date.setFullYear(y);
  2368. }
  2369. return date;
  2370. }
  2371. function createUTCDate (y) {
  2372. var date = new Date(Date.UTC.apply(null, arguments));
  2373. //the Date.UTC function remaps years 0-99 to 1900-1999
  2374. if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) {
  2375. date.setUTCFullYear(y);
  2376. }
  2377. return date;
  2378. }
  2379. // start-of-first-week - start-of-year
  2380. function firstWeekOffset(year, dow, doy) {
  2381. var // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  2382. fwd = 7 + dow - doy,
  2383. // first-week day local weekday -- which local weekday is fwd
  2384. fwdlw = (7 + createUTCDate(year, 0, fwd).getUTCDay() - dow) % 7;
  2385. return -fwdlw + fwd - 1;
  2386. }
  2387. //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
  2388. function dayOfYearFromWeeks(year, week, weekday, dow, doy) {
  2389. var localWeekday = (7 + weekday - dow) % 7,
  2390. weekOffset = firstWeekOffset(year, dow, doy),
  2391. dayOfYear = 1 + 7 * (week - 1) + localWeekday + weekOffset,
  2392. resYear, resDayOfYear;
  2393. if (dayOfYear <= 0) {
  2394. resYear = year - 1;
  2395. resDayOfYear = daysInYear(resYear) + dayOfYear;
  2396. } else if (dayOfYear > daysInYear(year)) {
  2397. resYear = year + 1;
  2398. resDayOfYear = dayOfYear - daysInYear(year);
  2399. } else {
  2400. resYear = year;
  2401. resDayOfYear = dayOfYear;
  2402. }
  2403. return {
  2404. year: resYear,
  2405. dayOfYear: resDayOfYear
  2406. };
  2407. }
  2408. function weekOfYear(mom, dow, doy) {
  2409. var weekOffset = firstWeekOffset(mom.year(), dow, doy),
  2410. week = Math.floor((mom.dayOfYear() - weekOffset - 1) / 7) + 1,
  2411. resWeek, resYear;
  2412. if (week < 1) {
  2413. resYear = mom.year() - 1;
  2414. resWeek = week + weeksInYear(resYear, dow, doy);
  2415. } else if (week > weeksInYear(mom.year(), dow, doy)) {
  2416. resWeek = week - weeksInYear(mom.year(), dow, doy);
  2417. resYear = mom.year() + 1;
  2418. } else {
  2419. resYear = mom.year();
  2420. resWeek = week;
  2421. }
  2422. return {
  2423. week: resWeek,
  2424. year: resYear
  2425. };
  2426. }
  2427. function weeksInYear(year, dow, doy) {
  2428. var weekOffset = firstWeekOffset(year, dow, doy),
  2429. weekOffsetNext = firstWeekOffset(year + 1, dow, doy);
  2430. return (daysInYear(year) - weekOffset + weekOffsetNext) / 7;
  2431. }
  2432. // FORMATTING
  2433. addFormatToken('w', ['ww', 2], 'wo', 'week');
  2434. addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
  2435. // ALIASES
  2436. addUnitAlias('week', 'w');
  2437. addUnitAlias('isoWeek', 'W');
  2438. // PRIORITIES
  2439. addUnitPriority('week', 5);
  2440. addUnitPriority('isoWeek', 5);
  2441. // PARSING
  2442. addRegexToken('w', match1to2);
  2443. addRegexToken('ww', match1to2, match2);
  2444. addRegexToken('W', match1to2);
  2445. addRegexToken('WW', match1to2, match2);
  2446. addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
  2447. week[token.substr(0, 1)] = toInt(input);
  2448. });
  2449. // HELPERS
  2450. // LOCALES
  2451. function localeWeek (mom) {
  2452. return weekOfYear(mom, this._week.dow, this._week.doy).week;
  2453. }
  2454. var defaultLocaleWeek = {
  2455. dow : 0, // Sunday is the first day of the week.
  2456. doy : 6 // The week that contains Jan 1st is the first week of the year.
  2457. };
  2458. function localeFirstDayOfWeek () {
  2459. return this._week.dow;
  2460. }
  2461. function localeFirstDayOfYear () {
  2462. return this._week.doy;
  2463. }
  2464. // MOMENTS
  2465. function getSetWeek (input) {
  2466. var week = this.localeData().week(this);
  2467. return input == null ? week : this.add((input - week) * 7, 'd');
  2468. }
  2469. function getSetISOWeek (input) {
  2470. var week = weekOfYear(this, 1, 4).week;
  2471. return input == null ? week : this.add((input - week) * 7, 'd');
  2472. }
  2473. // FORMATTING
  2474. addFormatToken('d', 0, 'do', 'day');
  2475. addFormatToken('dd', 0, 0, function (format) {
  2476. return this.localeData().weekdaysMin(this, format);
  2477. });
  2478. addFormatToken('ddd', 0, 0, function (format) {
  2479. return this.localeData().weekdaysShort(this, format);
  2480. });
  2481. addFormatToken('dddd', 0, 0, function (format) {
  2482. return this.localeData().weekdays(this, format);
  2483. });
  2484. addFormatToken('e', 0, 0, 'weekday');
  2485. addFormatToken('E', 0, 0, 'isoWeekday');
  2486. // ALIASES
  2487. addUnitAlias('day', 'd');
  2488. addUnitAlias('weekday', 'e');
  2489. addUnitAlias('isoWeekday', 'E');
  2490. // PRIORITY
  2491. addUnitPriority('day', 11);
  2492. addUnitPriority('weekday', 11);
  2493. addUnitPriority('isoWeekday', 11);
  2494. // PARSING
  2495. addRegexToken('d', match1to2);
  2496. addRegexToken('e', match1to2);
  2497. addRegexToken('E', match1to2);
  2498. addRegexToken('dd', function (isStrict, locale) {
  2499. return locale.weekdaysMinRegex(isStrict);
  2500. });
  2501. addRegexToken('ddd', function (isStrict, locale) {
  2502. return locale.weekdaysShortRegex(isStrict);
  2503. });
  2504. addRegexToken('dddd', function (isStrict, locale) {
  2505. return locale.weekdaysRegex(isStrict);
  2506. });
  2507. addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
  2508. var weekday = config._locale.weekdaysParse(input, token, config._strict);
  2509. // if we didn't get a weekday name, mark the date as invalid
  2510. if (weekday != null) {
  2511. week.d = weekday;
  2512. } else {
  2513. getParsingFlags(config).invalidWeekday = input;
  2514. }
  2515. });
  2516. addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
  2517. week[token] = toInt(input);
  2518. });
  2519. // HELPERS
  2520. function parseWeekday(input, locale) {
  2521. if (typeof input !== 'string') {
  2522. return input;
  2523. }
  2524. if (!isNaN(input)) {
  2525. return parseInt(input, 10);
  2526. }
  2527. input = locale.weekdaysParse(input);
  2528. if (typeof input === 'number') {
  2529. return input;
  2530. }
  2531. return null;
  2532. }
  2533. function parseIsoWeekday(input, locale) {
  2534. if (typeof input === 'string') {
  2535. return locale.weekdaysParse(input) % 7 || 7;
  2536. }
  2537. return isNaN(input) ? null : input;
  2538. }
  2539. // LOCALES
  2540. var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');
  2541. function localeWeekdays (m, format) {
  2542. return isArray(this._weekdays) ? this._weekdays[m.day()] :
  2543. this._weekdays[this._weekdays.isFormat.test(format) ? 'format' : 'standalone'][m.day()];
  2544. }
  2545. var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');
  2546. function localeWeekdaysShort (m) {
  2547. return this._weekdaysShort[m.day()];
  2548. }
  2549. var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');
  2550. function localeWeekdaysMin (m) {
  2551. return this._weekdaysMin[m.day()];
  2552. }
  2553. function day_of_week__handleStrictParse(weekdayName, format, strict) {
  2554. var i, ii, mom, llc = weekdayName.toLocaleLowerCase();
  2555. if (!this._weekdaysParse) {
  2556. this._weekdaysParse = [];
  2557. this._shortWeekdaysParse = [];
  2558. this._minWeekdaysParse = [];
  2559. for (i = 0; i < 7; ++i) {
  2560. mom = create_utc__createUTC([2000, 1]).day(i);
  2561. this._minWeekdaysParse[i] = this.weekdaysMin(mom, '').toLocaleLowerCase();
  2562. this._shortWeekdaysParse[i] = this.weekdaysShort(mom, '').toLocaleLowerCase();
  2563. this._weekdaysParse[i] = this.weekdays(mom, '').toLocaleLowerCase();
  2564. }
  2565. }
  2566. if (strict) {
  2567. if (format === 'dddd') {
  2568. ii = indexOf.call(this._weekdaysParse, llc);
  2569. return ii !== -1 ? ii : null;
  2570. } else if (format === 'ddd') {
  2571. ii = indexOf.call(this._shortWeekdaysParse, llc);
  2572. return ii !== -1 ? ii : null;
  2573. } else {
  2574. ii = indexOf.call(this._minWeekdaysParse, llc);
  2575. return ii !== -1 ? ii : null;
  2576. }
  2577. } else {
  2578. if (format === 'dddd') {
  2579. ii = indexOf.call(this._weekdaysParse, llc);
  2580. if (ii !== -1) {
  2581. return ii;
  2582. }
  2583. ii = indexOf.call(this._shortWeekdaysParse, llc);
  2584. if (ii !== -1) {
  2585. return ii;
  2586. }
  2587. ii = indexOf.call(this._minWeekdaysParse, llc);
  2588. return ii !== -1 ? ii : null;
  2589. } else if (format === 'ddd') {
  2590. ii = indexOf.call(this._shortWeekdaysParse, llc);
  2591. if (ii !== -1) {
  2592. return ii;
  2593. }
  2594. ii = indexOf.call(this._weekdaysParse, llc);
  2595. if (ii !== -1) {
  2596. return ii;
  2597. }
  2598. ii = indexOf.call(this._minWeekdaysParse, llc);
  2599. return ii !== -1 ? ii : null;
  2600. } else {
  2601. ii = indexOf.call(this._minWeekdaysParse, llc);
  2602. if (ii !== -1) {
  2603. return ii;
  2604. }
  2605. ii = indexOf.call(this._weekdaysParse, llc);
  2606. if (ii !== -1) {
  2607. return ii;
  2608. }
  2609. ii = indexOf.call(this._shortWeekdaysParse, llc);
  2610. return ii !== -1 ? ii : null;
  2611. }
  2612. }
  2613. }
  2614. function localeWeekdaysParse (weekdayName, format, strict) {
  2615. var i, mom, regex;
  2616. if (this._weekdaysParseExact) {
  2617. return day_of_week__handleStrictParse.call(this, weekdayName, format, strict);
  2618. }
  2619. if (!this._weekdaysParse) {
  2620. this._weekdaysParse = [];
  2621. this._minWeekdaysParse = [];
  2622. this._shortWeekdaysParse = [];
  2623. this._fullWeekdaysParse = [];
  2624. }
  2625. for (i = 0; i < 7; i++) {
  2626. // make the regex if we don't have it already
  2627. mom = create_utc__createUTC([2000, 1]).day(i);
  2628. if (strict && !this._fullWeekdaysParse[i]) {
  2629. this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
  2630. this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
  2631. this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
  2632. }
  2633. if (!this._weekdaysParse[i]) {
  2634. regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
  2635. this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');
  2636. }
  2637. // test the regex
  2638. if (strict && format === 'dddd' && this._fullWeekdaysParse[i].test(weekdayName)) {
  2639. return i;
  2640. } else if (strict && format === 'ddd' && this._shortWeekdaysParse[i].test(weekdayName)) {
  2641. return i;
  2642. } else if (strict && format === 'dd' && this._minWeekdaysParse[i].test(weekdayName)) {
  2643. return i;
  2644. } else if (!strict && this._weekdaysParse[i].test(weekdayName)) {
  2645. return i;
  2646. }
  2647. }
  2648. }
  2649. // MOMENTS
  2650. function getSetDayOfWeek (input) {
  2651. if (!this.isValid()) {
  2652. return input != null ? this : NaN;
  2653. }
  2654. var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
  2655. if (input != null) {
  2656. input = parseWeekday(input, this.localeData());
  2657. return this.add(input - day, 'd');
  2658. } else {
  2659. return day;
  2660. }
  2661. }
  2662. function getSetLocaleDayOfWeek (input) {
  2663. if (!this.isValid()) {
  2664. return input != null ? this : NaN;
  2665. }
  2666. var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;
  2667. return input == null ? weekday : this.add(input - weekday, 'd');
  2668. }
  2669. function getSetISODayOfWeek (input) {
  2670. if (!this.isValid()) {
  2671. return input != null ? this : NaN;
  2672. }
  2673. // behaves the same as moment#day except
  2674. // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)
  2675. // as a setter, sunday should belong to the previous week.
  2676. if (input != null) {
  2677. var weekday = parseIsoWeekday(input, this.localeData());
  2678. return this.day(this.day() % 7 ? weekday : weekday - 7);
  2679. } else {
  2680. return this.day() || 7;
  2681. }
  2682. }
  2683. var defaultWeekdaysRegex = matchWord;
  2684. function weekdaysRegex (isStrict) {
  2685. if (this._weekdaysParseExact) {
  2686. if (!hasOwnProp(this, '_weekdaysRegex')) {
  2687. computeWeekdaysParse.call(this);
  2688. }
  2689. if (isStrict) {
  2690. return this._weekdaysStrictRegex;
  2691. } else {
  2692. return this._weekdaysRegex;
  2693. }
  2694. } else {
  2695. if (!hasOwnProp(this, '_weekdaysRegex')) {
  2696. this._weekdaysRegex = defaultWeekdaysRegex;
  2697. }
  2698. return this._weekdaysStrictRegex && isStrict ?
  2699. this._weekdaysStrictRegex : this._weekdaysRegex;
  2700. }
  2701. }
  2702. var defaultWeekdaysShortRegex = matchWord;
  2703. function weekdaysShortRegex (isStrict) {
  2704. if (this._weekdaysParseExact) {
  2705. if (!hasOwnProp(this, '_weekdaysRegex')) {
  2706. computeWeekdaysParse.call(this);
  2707. }
  2708. if (isStrict) {
  2709. return this._weekdaysShortStrictRegex;
  2710. } else {
  2711. return this._weekdaysShortRegex;
  2712. }
  2713. } else {
  2714. if (!hasOwnProp(this, '_weekdaysShortRegex')) {
  2715. this._weekdaysShortRegex = defaultWeekdaysShortRegex;
  2716. }
  2717. return this._weekdaysShortStrictRegex && isStrict ?
  2718. this._weekdaysShortStrictRegex : this._weekdaysShortRegex;
  2719. }
  2720. }
  2721. var defaultWeekdaysMinRegex = matchWord;
  2722. function weekdaysMinRegex (isStrict) {
  2723. if (this._weekdaysParseExact) {
  2724. if (!hasOwnProp(this, '_weekdaysRegex')) {
  2725. computeWeekdaysParse.call(this);
  2726. }
  2727. if (isStrict) {
  2728. return this._weekdaysMinStrictRegex;
  2729. } else {
  2730. return this._weekdaysMinRegex;
  2731. }
  2732. } else {
  2733. if (!hasOwnProp(this, '_weekdaysMinRegex')) {
  2734. this._weekdaysMinRegex = defaultWeekdaysMinRegex;
  2735. }
  2736. return this._weekdaysMinStrictRegex && isStrict ?
  2737. this._weekdaysMinStrictRegex : this._weekdaysMinRegex;
  2738. }
  2739. }
  2740. function computeWeekdaysParse () {
  2741. function cmpLenRev(a, b) {
  2742. return b.length - a.length;
  2743. }
  2744. var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [],
  2745. i, mom, minp, shortp, longp;
  2746. for (i = 0; i < 7; i++) {
  2747. // make the regex if we don't have it already
  2748. mom = create_utc__createUTC([2000, 1]).day(i);
  2749. minp = this.weekdaysMin(mom, '');
  2750. shortp = this.weekdaysShort(mom, '');
  2751. longp = this.weekdays(mom, '');
  2752. minPieces.push(minp);
  2753. shortPieces.push(shortp);
  2754. longPieces.push(longp);
  2755. mixedPieces.push(minp);
  2756. mixedPieces.push(shortp);
  2757. mixedPieces.push(longp);
  2758. }
  2759. // Sorting makes sure if one weekday (or abbr) is a prefix of another it
  2760. // will match the longer piece.
  2761. minPieces.sort(cmpLenRev);
  2762. shortPieces.sort(cmpLenRev);
  2763. longPieces.sort(cmpLenRev);
  2764. mixedPieces.sort(cmpLenRev);
  2765. for (i = 0; i < 7; i++) {
  2766. shortPieces[i] = regexEscape(shortPieces[i]);
  2767. longPieces[i] = regexEscape(longPieces[i]);
  2768. mixedPieces[i] = regexEscape(mixedPieces[i]);
  2769. }
  2770. this._weekdaysRegex = new RegExp('^(' + mixedPieces.join('|') + ')', 'i');
  2771. this._weekdaysShortRegex = this._weekdaysRegex;
  2772. this._weekdaysMinRegex = this._weekdaysRegex;
  2773. this._weekdaysStrictRegex = new RegExp('^(' + longPieces.join('|') + ')', 'i');
  2774. this._weekdaysShortStrictRegex = new RegExp('^(' + shortPieces.join('|') + ')', 'i');
  2775. this._weekdaysMinStrictRegex = new RegExp('^(' + minPieces.join('|') + ')', 'i');
  2776. }
  2777. // FORMATTING
  2778. function hFormat() {
  2779. return this.hours() % 12 || 12;
  2780. }
  2781. function kFormat() {
  2782. return this.hours() || 24;
  2783. }
  2784. addFormatToken('H', ['HH', 2], 0, 'hour');
  2785. addFormatToken('h', ['hh', 2], 0, hFormat);
  2786. addFormatToken('k', ['kk', 2], 0, kFormat);
  2787. addFormatToken('hmm', 0, 0, function () {
  2788. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
  2789. });
  2790. addFormatToken('hmmss', 0, 0, function () {
  2791. return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
  2792. zeroFill(this.seconds(), 2);
  2793. });
  2794. addFormatToken('Hmm', 0, 0, function () {
  2795. return '' + this.hours() + zeroFill(this.minutes(), 2);
  2796. });
  2797. addFormatToken('Hmmss', 0, 0, function () {
  2798. return '' + this.hours() + zeroFill(this.minutes(), 2) +
  2799. zeroFill(this.seconds(), 2);
  2800. });
  2801. function meridiem (token, lowercase) {
  2802. addFormatToken(token, 0, 0, function () {
  2803. return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
  2804. });
  2805. }
  2806. meridiem('a', true);
  2807. meridiem('A', false);
  2808. // ALIASES
  2809. addUnitAlias('hour', 'h');
  2810. // PRIORITY
  2811. addUnitPriority('hour', 13);
  2812. // PARSING
  2813. function matchMeridiem (isStrict, locale) {
  2814. return locale._meridiemParse;
  2815. }
  2816. addRegexToken('a', matchMeridiem);
  2817. addRegexToken('A', matchMeridiem);
  2818. addRegexToken('H', match1to2);
  2819. addRegexToken('h', match1to2);
  2820. addRegexToken('HH', match1to2, match2);
  2821. addRegexToken('hh', match1to2, match2);
  2822. addRegexToken('hmm', match3to4);
  2823. addRegexToken('hmmss', match5to6);
  2824. addRegexToken('Hmm', match3to4);
  2825. addRegexToken('Hmmss', match5to6);
  2826. addParseToken(['H', 'HH'], HOUR);
  2827. addParseToken(['a', 'A'], function (input, array, config) {
  2828. config._isPm = config._locale.isPM(input);
  2829. config._meridiem = input;
  2830. });
  2831. addParseToken(['h', 'hh'], function (input, array, config) {
  2832. array[HOUR] = toInt(input);
  2833. getParsingFlags(config).bigHour = true;
  2834. });
  2835. addParseToken('hmm', function (input, array, config) {
  2836. var pos = input.length - 2;
  2837. array[HOUR] = toInt(input.substr(0, pos));
  2838. array[MINUTE] = toInt(input.substr(pos));
  2839. getParsingFlags(config).bigHour = true;
  2840. });
  2841. addParseToken('hmmss', function (input, array, config) {
  2842. var pos1 = input.length - 4;
  2843. var pos2 = input.length - 2;
  2844. array[HOUR] = toInt(input.substr(0, pos1));
  2845. array[MINUTE] = toInt(input.substr(pos1, 2));
  2846. array[SECOND] = toInt(input.substr(pos2));
  2847. getParsingFlags(config).bigHour = true;
  2848. });
  2849. addParseToken('Hmm', function (input, array, config) {
  2850. var pos = input.length - 2;
  2851. array[HOUR] = toInt(input.substr(0, pos));
  2852. array[MINUTE] = toInt(input.substr(pos));
  2853. });
  2854. addParseToken('Hmmss', function (input, array, config) {
  2855. var pos1 = input.length - 4;
  2856. var pos2 = input.length - 2;
  2857. array[HOUR] = toInt(input.substr(0, pos1));
  2858. array[MINUTE] = toInt(input.substr(pos1, 2));
  2859. array[SECOND] = toInt(input.substr(pos2));
  2860. });
  2861. // LOCALES
  2862. function localeIsPM (input) {
  2863. // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays
  2864. // Using charAt should be more compatible.
  2865. return ((input + '').toLowerCase().charAt(0) === 'p');
  2866. }
  2867. var defaultLocaleMeridiemParse = /[ap]\.?m?\.?/i;
  2868. function localeMeridiem (hours, minutes, isLower) {
  2869. if (hours > 11) {
  2870. return isLower ? 'pm' : 'PM';
  2871. } else {
  2872. return isLower ? 'am' : 'AM';
  2873. }
  2874. }
  2875. // MOMENTS
  2876. // Setting the hour should keep the time, because the user explicitly
  2877. // specified which hour he wants. So trying to maintain the same hour (in
  2878. // a new timezone) makes sense. Adding/subtracting hours does not follow
  2879. // this rule.
  2880. var getSetHour = makeGetSet('Hours', true);
  2881. var baseConfig = {
  2882. calendar: defaultCalendar,
  2883. longDateFormat: defaultLongDateFormat,
  2884. invalidDate: defaultInvalidDate,
  2885. ordinal: defaultOrdinal,
  2886. ordinalParse: defaultOrdinalParse,
  2887. relativeTime: defaultRelativeTime,
  2888. months: defaultLocaleMonths,
  2889. monthsShort: defaultLocaleMonthsShort,
  2890. week: defaultLocaleWeek,
  2891. weekdays: defaultLocaleWeekdays,
  2892. weekdaysMin: defaultLocaleWeekdaysMin,
  2893. weekdaysShort: defaultLocaleWeekdaysShort,
  2894. meridiemParse: defaultLocaleMeridiemParse
  2895. };
  2896. // internal storage for locale config files
  2897. var locales = {};
  2898. var globalLocale;
  2899. function normalizeLocale(key) {
  2900. return key ? key.toLowerCase().replace('_', '-') : key;
  2901. }
  2902. // pick the locale from the array
  2903. // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each
  2904. // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root
  2905. function chooseLocale(names) {
  2906. var i = 0, j, next, locale, split;
  2907. while (i < names.length) {
  2908. split = normalizeLocale(names[i]).split('-');
  2909. j = split.length;
  2910. next = normalizeLocale(names[i + 1]);
  2911. next = next ? next.split('-') : null;
  2912. while (j > 0) {
  2913. locale = loadLocale(split.slice(0, j).join('-'));
  2914. if (locale) {
  2915. return locale;
  2916. }
  2917. if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {
  2918. //the next array item is better than a shallower substring of this one
  2919. break;
  2920. }
  2921. j--;
  2922. }
  2923. i++;
  2924. }
  2925. return null;
  2926. }
  2927. function loadLocale(name) {
  2928. var oldLocale = null;
  2929. // TODO: Find a better way to register and load all the locales in Node
  2930. if (!locales[name] && (typeof module !== 'undefined') &&
  2931. module && module.exports) {
  2932. try {
  2933. oldLocale = globalLocale._abbr;
  2934. require('./locale/' + name);
  2935. // because defineLocale currently also sets the global locale, we
  2936. // want to undo that for lazy loaded locales
  2937. locale_locales__getSetGlobalLocale(oldLocale);
  2938. } catch (e) { }
  2939. }
  2940. return locales[name];
  2941. }
  2942. // This function will load locale and then set the global locale. If
  2943. // no arguments are passed in, it will simply return the current global
  2944. // locale key.
  2945. function locale_locales__getSetGlobalLocale (key, values) {
  2946. var data;
  2947. if (key) {
  2948. if (isUndefined(values)) {
  2949. data = locale_locales__getLocale(key);
  2950. }
  2951. else {
  2952. data = defineLocale(key, values);
  2953. }
  2954. if (data) {
  2955. // moment.duration._locale = moment._locale = data;
  2956. globalLocale = data;
  2957. }
  2958. }
  2959. return globalLocale._abbr;
  2960. }
  2961. function defineLocale (name, config) {
  2962. if (config !== null) {
  2963. var parentConfig = baseConfig;
  2964. config.abbr = name;
  2965. if (locales[name] != null) {
  2966. deprecateSimple('defineLocaleOverride',
  2967. 'use moment.updateLocale(localeName, config) to change ' +
  2968. 'an existing locale. moment.defineLocale(localeName, ' +
  2969. 'config) should only be used for creating a new locale ' +
  2970. 'See http://momentjs.com/guides/#/warnings/define-locale/ for more info.');
  2971. parentConfig = locales[name]._config;
  2972. } else if (config.parentLocale != null) {
  2973. if (locales[config.parentLocale] != null) {
  2974. parentConfig = locales[config.parentLocale]._config;
  2975. } else {
  2976. // treat as if there is no base config
  2977. deprecateSimple('parentLocaleUndefined',
  2978. 'specified parentLocale is not defined yet. See http://momentjs.com/guides/#/warnings/parent-locale/');
  2979. }
  2980. }
  2981. locales[name] = new Locale(mergeConfigs(parentConfig, config));
  2982. // backwards compat for now: also set the locale
  2983. locale_locales__getSetGlobalLocale(name);
  2984. return locales[name];
  2985. } else {
  2986. // useful for testing
  2987. delete locales[name];
  2988. return null;
  2989. }
  2990. }
  2991. function updateLocale(name, config) {
  2992. if (config != null) {
  2993. var locale, parentConfig = baseConfig;
  2994. // MERGE
  2995. if (locales[name] != null) {
  2996. parentConfig = locales[name]._config;
  2997. }
  2998. config = mergeConfigs(parentConfig, config);
  2999. locale = new Locale(config);
  3000. locale.parentLocale = locales[name];
  3001. locales[name] = locale;
  3002. // backwards compat for now: also set the locale
  3003. locale_locales__getSetGlobalLocale(name);
  3004. } else {
  3005. // pass null for config to unupdate, useful for tests
  3006. if (locales[name] != null) {
  3007. if (locales[name].parentLocale != null) {
  3008. locales[name] = locales[name].parentLocale;
  3009. } else if (locales[name] != null) {
  3010. delete locales[name];
  3011. }
  3012. }
  3013. }
  3014. return locales[name];
  3015. }
  3016. // returns locale data
  3017. function locale_locales__getLocale (key) {
  3018. var locale;
  3019. if (key && key._locale && key._locale._abbr) {
  3020. key = key._locale._abbr;
  3021. }
  3022. if (!key) {
  3023. return globalLocale;
  3024. }
  3025. if (!isArray(key)) {
  3026. //short-circuit everything else
  3027. locale = loadLocale(key);
  3028. if (locale) {
  3029. return locale;
  3030. }
  3031. key = [key];
  3032. }
  3033. return chooseLocale(key);
  3034. }
  3035. function locale_locales__listLocales() {
  3036. return keys(locales);
  3037. }
  3038. function checkOverflow (m) {
  3039. var overflow;
  3040. var a = m._a;
  3041. if (a && getParsingFlags(m).overflow === -2) {
  3042. overflow =
  3043. a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :
  3044. a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :
  3045. a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :
  3046. a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :
  3047. a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :
  3048. a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :
  3049. -1;
  3050. if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {
  3051. overflow = DATE;
  3052. }
  3053. if (getParsingFlags(m)._overflowWeeks && overflow === -1) {
  3054. overflow = WEEK;
  3055. }
  3056. if (getParsingFlags(m)._overflowWeekday && overflow === -1) {
  3057. overflow = WEEKDAY;
  3058. }
  3059. getParsingFlags(m).overflow = overflow;
  3060. }
  3061. return m;
  3062. }
  3063. // iso 8601 regex
  3064. // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
  3065. var extendedIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
  3066. var basicIsoRegex = /^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?/;
  3067. var tzRegex = /Z|[+-]\d\d(?::?\d\d)?/;
  3068. var isoDates = [
  3069. ['YYYYYY-MM-DD', /[+-]\d{6}-\d\d-\d\d/],
  3070. ['YYYY-MM-DD', /\d{4}-\d\d-\d\d/],
  3071. ['GGGG-[W]WW-E', /\d{4}-W\d\d-\d/],
  3072. ['GGGG-[W]WW', /\d{4}-W\d\d/, false],
  3073. ['YYYY-DDD', /\d{4}-\d{3}/],
  3074. ['YYYY-MM', /\d{4}-\d\d/, false],
  3075. ['YYYYYYMMDD', /[+-]\d{10}/],
  3076. ['YYYYMMDD', /\d{8}/],
  3077. // YYYYMM is NOT allowed by the standard
  3078. ['GGGG[W]WWE', /\d{4}W\d{3}/],
  3079. ['GGGG[W]WW', /\d{4}W\d{2}/, false],
  3080. ['YYYYDDD', /\d{7}/]
  3081. ];
  3082. // iso time formats and regexes
  3083. var isoTimes = [
  3084. ['HH:mm:ss.SSSS', /\d\d:\d\d:\d\d\.\d+/],
  3085. ['HH:mm:ss,SSSS', /\d\d:\d\d:\d\d,\d+/],
  3086. ['HH:mm:ss', /\d\d:\d\d:\d\d/],
  3087. ['HH:mm', /\d\d:\d\d/],
  3088. ['HHmmss.SSSS', /\d\d\d\d\d\d\.\d+/],
  3089. ['HHmmss,SSSS', /\d\d\d\d\d\d,\d+/],
  3090. ['HHmmss', /\d\d\d\d\d\d/],
  3091. ['HHmm', /\d\d\d\d/],
  3092. ['HH', /\d\d/]
  3093. ];
  3094. var aspNetJsonRegex = /^\/?Date\((\-?\d+)/i;
  3095. // date from iso format
  3096. function configFromISO(config) {
  3097. var i, l,
  3098. string = config._i,
  3099. match = extendedIsoRegex.exec(string) || basicIsoRegex.exec(string),
  3100. allowTime, dateFormat, timeFormat, tzFormat;
  3101. if (match) {
  3102. getParsingFlags(config).iso = true;
  3103. for (i = 0, l = isoDates.length; i < l; i++) {
  3104. if (isoDates[i][1].exec(match[1])) {
  3105. dateFormat = isoDates[i][0];
  3106. allowTime = isoDates[i][2] !== false;
  3107. break;
  3108. }
  3109. }
  3110. if (dateFormat == null) {
  3111. config._isValid = false;
  3112. return;
  3113. }
  3114. if (match[3]) {
  3115. for (i = 0, l = isoTimes.length; i < l; i++) {
  3116. if (isoTimes[i][1].exec(match[3])) {
  3117. // match[2] should be 'T' or space
  3118. timeFormat = (match[2] || ' ') + isoTimes[i][0];
  3119. break;
  3120. }
  3121. }
  3122. if (timeFormat == null) {
  3123. config._isValid = false;
  3124. return;
  3125. }
  3126. }
  3127. if (!allowTime && timeFormat != null) {
  3128. config._isValid = false;
  3129. return;
  3130. }
  3131. if (match[4]) {
  3132. if (tzRegex.exec(match[4])) {
  3133. tzFormat = 'Z';
  3134. } else {
  3135. config._isValid = false;
  3136. return;
  3137. }
  3138. }
  3139. config._f = dateFormat + (timeFormat || '') + (tzFormat || '');
  3140. configFromStringAndFormat(config);
  3141. } else {
  3142. config._isValid = false;
  3143. }
  3144. }
  3145. // date from iso format or fallback
  3146. function configFromString(config) {
  3147. var matched = aspNetJsonRegex.exec(config._i);
  3148. if (matched !== null) {
  3149. config._d = new Date(+matched[1]);
  3150. return;
  3151. }
  3152. configFromISO(config);
  3153. if (config._isValid === false) {
  3154. delete config._isValid;
  3155. utils_hooks__hooks.createFromInputFallback(config);
  3156. }
  3157. }
  3158. utils_hooks__hooks.createFromInputFallback = deprecate(
  3159. 'moment construction falls back to js Date. This is ' +
  3160. 'discouraged and will be removed in upcoming major ' +
  3161. 'release. Please refer to ' +
  3162. 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
  3163. function (config) {
  3164. config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
  3165. }
  3166. );
  3167. // Pick the first defined of two or three arguments.
  3168. function defaults(a, b, c) {
  3169. if (a != null) {
  3170. return a;
  3171. }
  3172. if (b != null) {
  3173. return b;
  3174. }
  3175. return c;
  3176. }
  3177. function currentDateArray(config) {
  3178. // hooks is actually the exported moment object
  3179. var nowValue = new Date(utils_hooks__hooks.now());
  3180. if (config._useUTC) {
  3181. return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
  3182. }
  3183. return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()];
  3184. }
  3185. // convert an array to a date.
  3186. // the array should mirror the parameters below
  3187. // note: all values past the year are optional and will default to the lowest possible value.
  3188. // [year, month, day , hour, minute, second, millisecond]
  3189. function configFromArray (config) {
  3190. var i, date, input = [], currentDate, yearToUse;
  3191. if (config._d) {
  3192. return;
  3193. }
  3194. currentDate = currentDateArray(config);
  3195. //compute day of the year from weeks and weekdays
  3196. if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {
  3197. dayOfYearFromWeekInfo(config);
  3198. }
  3199. //if the day of the year is set, figure out what it is
  3200. if (config._dayOfYear) {
  3201. yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);
  3202. if (config._dayOfYear > daysInYear(yearToUse)) {
  3203. getParsingFlags(config)._overflowDayOfYear = true;
  3204. }
  3205. date = createUTCDate(yearToUse, 0, config._dayOfYear);
  3206. config._a[MONTH] = date.getUTCMonth();
  3207. config._a[DATE] = date.getUTCDate();
  3208. }
  3209. // Default to current date.
  3210. // * if no year, month, day of month are given, default to today
  3211. // * if day of month is given, default month and year
  3212. // * if month is given, default only year
  3213. // * if year is given, don't default anything
  3214. for (i = 0; i < 3 && config._a[i] == null; ++i) {
  3215. config._a[i] = input[i] = currentDate[i];
  3216. }
  3217. // Zero out whatever was not defaulted, including time
  3218. for (; i < 7; i++) {
  3219. config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];
  3220. }
  3221. // Check for 24:00:00.000
  3222. if (config._a[HOUR] === 24 &&
  3223. config._a[MINUTE] === 0 &&
  3224. config._a[SECOND] === 0 &&
  3225. config._a[MILLISECOND] === 0) {
  3226. config._nextDay = true;
  3227. config._a[HOUR] = 0;
  3228. }
  3229. config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);
  3230. // Apply timezone offset from input. The actual utcOffset can be changed
  3231. // with parseZone.
  3232. if (config._tzm != null) {
  3233. config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
  3234. }
  3235. if (config._nextDay) {
  3236. config._a[HOUR] = 24;
  3237. }
  3238. }
  3239. function dayOfYearFromWeekInfo(config) {
  3240. var w, weekYear, week, weekday, dow, doy, temp, weekdayOverflow;
  3241. w = config._w;
  3242. if (w.GG != null || w.W != null || w.E != null) {
  3243. dow = 1;
  3244. doy = 4;
  3245. // TODO: We need to take the current isoWeekYear, but that depends on
  3246. // how we interpret now (local, utc, fixed offset). So create
  3247. // a now version of current config (take local/utc/offset flags, and
  3248. // create now).
  3249. weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year);
  3250. week = defaults(w.W, 1);
  3251. weekday = defaults(w.E, 1);
  3252. if (weekday < 1 || weekday > 7) {
  3253. weekdayOverflow = true;
  3254. }
  3255. } else {
  3256. dow = config._locale._week.dow;
  3257. doy = config._locale._week.doy;
  3258. weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year);
  3259. week = defaults(w.w, 1);
  3260. if (w.d != null) {
  3261. // weekday -- low day numbers are considered next week
  3262. weekday = w.d;
  3263. if (weekday < 0 || weekday > 6) {
  3264. weekdayOverflow = true;
  3265. }
  3266. } else if (w.e != null) {
  3267. // local weekday -- counting starts from begining of week
  3268. weekday = w.e + dow;
  3269. if (w.e < 0 || w.e > 6) {
  3270. weekdayOverflow = true;
  3271. }
  3272. } else {
  3273. // default to begining of week
  3274. weekday = dow;
  3275. }
  3276. }
  3277. if (week < 1 || week > weeksInYear(weekYear, dow, doy)) {
  3278. getParsingFlags(config)._overflowWeeks = true;
  3279. } else if (weekdayOverflow != null) {
  3280. getParsingFlags(config)._overflowWeekday = true;
  3281. } else {
  3282. temp = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy);
  3283. config._a[YEAR] = temp.year;
  3284. config._dayOfYear = temp.dayOfYear;
  3285. }
  3286. }
  3287. // constant that refers to the ISO standard
  3288. utils_hooks__hooks.ISO_8601 = function () {};
  3289. // date from string and format string
  3290. function configFromStringAndFormat(config) {
  3291. // TODO: Move this to another part of the creation flow to prevent circular deps
  3292. if (config._f === utils_hooks__hooks.ISO_8601) {
  3293. configFromISO(config);
  3294. return;
  3295. }
  3296. config._a = [];
  3297. getParsingFlags(config).empty = true;
  3298. // This array is used to make a Date, either with `new Date` or `Date.UTC`
  3299. var string = '' + config._i,
  3300. i, parsedInput, tokens, token, skipped,
  3301. stringLength = string.length,
  3302. totalParsedInputLength = 0;
  3303. tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];
  3304. for (i = 0; i < tokens.length; i++) {
  3305. token = tokens[i];
  3306. parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];
  3307. // console.log('token', token, 'parsedInput', parsedInput,
  3308. // 'regex', getParseRegexForToken(token, config));
  3309. if (parsedInput) {
  3310. skipped = string.substr(0, string.indexOf(parsedInput));
  3311. if (skipped.length > 0) {
  3312. getParsingFlags(config).unusedInput.push(skipped);
  3313. }
  3314. string = string.slice(string.indexOf(parsedInput) + parsedInput.length);
  3315. totalParsedInputLength += parsedInput.length;
  3316. }
  3317. // don't parse if it's not a known token
  3318. if (formatTokenFunctions[token]) {
  3319. if (parsedInput) {
  3320. getParsingFlags(config).empty = false;
  3321. }
  3322. else {
  3323. getParsingFlags(config).unusedTokens.push(token);
  3324. }
  3325. addTimeToArrayFromToken(token, parsedInput, config);
  3326. }
  3327. else if (config._strict && !parsedInput) {
  3328. getParsingFlags(config).unusedTokens.push(token);
  3329. }
  3330. }
  3331. // add remaining unparsed input length to the string
  3332. getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;
  3333. if (string.length > 0) {
  3334. getParsingFlags(config).unusedInput.push(string);
  3335. }
  3336. // clear _12h flag if hour is <= 12
  3337. if (config._a[HOUR] <= 12 &&
  3338. getParsingFlags(config).bigHour === true &&
  3339. config._a[HOUR] > 0) {
  3340. getParsingFlags(config).bigHour = undefined;
  3341. }
  3342. getParsingFlags(config).parsedDateParts = config._a.slice(0);
  3343. getParsingFlags(config).meridiem = config._meridiem;
  3344. // handle meridiem
  3345. config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);
  3346. configFromArray(config);
  3347. checkOverflow(config);
  3348. }
  3349. function meridiemFixWrap (locale, hour, meridiem) {
  3350. var isPm;
  3351. if (meridiem == null) {
  3352. // nothing to do
  3353. return hour;
  3354. }
  3355. if (locale.meridiemHour != null) {
  3356. return locale.meridiemHour(hour, meridiem);
  3357. } else if (locale.isPM != null) {
  3358. // Fallback
  3359. isPm = locale.isPM(meridiem);
  3360. if (isPm && hour < 12) {
  3361. hour += 12;
  3362. }
  3363. if (!isPm && hour === 12) {
  3364. hour = 0;
  3365. }
  3366. return hour;
  3367. } else {
  3368. // this is not supposed to happen
  3369. return hour;
  3370. }
  3371. }
  3372. // date from string and array of format strings
  3373. function configFromStringAndArray(config) {
  3374. var tempConfig,
  3375. bestMoment,
  3376. scoreToBeat,
  3377. i,
  3378. currentScore;
  3379. if (config._f.length === 0) {
  3380. getParsingFlags(config).invalidFormat = true;
  3381. config._d = new Date(NaN);
  3382. return;
  3383. }
  3384. for (i = 0; i < config._f.length; i++) {
  3385. currentScore = 0;
  3386. tempConfig = copyConfig({}, config);
  3387. if (config._useUTC != null) {
  3388. tempConfig._useUTC = config._useUTC;
  3389. }
  3390. tempConfig._f = config._f[i];
  3391. configFromStringAndFormat(tempConfig);
  3392. if (!valid__isValid(tempConfig)) {
  3393. continue;
  3394. }
  3395. // if there is any input that was not parsed add a penalty for that format
  3396. currentScore += getParsingFlags(tempConfig).charsLeftOver;
  3397. //or tokens
  3398. currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
  3399. getParsingFlags(tempConfig).score = currentScore;
  3400. if (scoreToBeat == null || currentScore < scoreToBeat) {
  3401. scoreToBeat = currentScore;
  3402. bestMoment = tempConfig;
  3403. }
  3404. }
  3405. extend(config, bestMoment || tempConfig);
  3406. }
  3407. function configFromObject(config) {
  3408. if (config._d) {
  3409. return;
  3410. }
  3411. var i = normalizeObjectUnits(config._i);
  3412. config._a = map([i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond], function (obj) {
  3413. return obj && parseInt(obj, 10);
  3414. });
  3415. configFromArray(config);
  3416. }
  3417. function createFromConfig (config) {
  3418. var res = new Moment(checkOverflow(prepareConfig(config)));
  3419. if (res._nextDay) {
  3420. // Adding is smart enough around DST
  3421. res.add(1, 'd');
  3422. res._nextDay = undefined;
  3423. }
  3424. return res;
  3425. }
  3426. function prepareConfig (config) {
  3427. var input = config._i,
  3428. format = config._f;
  3429. config._locale = config._locale || locale_locales__getLocale(config._l);
  3430. if (input === null || (format === undefined && input === '')) {
  3431. return valid__createInvalid({nullInput: true});
  3432. }
  3433. if (typeof input === 'string') {
  3434. config._i = input = config._locale.preparse(input);
  3435. }
  3436. if (isMoment(input)) {
  3437. return new Moment(checkOverflow(input));
  3438. } else if (isArray(format)) {
  3439. configFromStringAndArray(config);
  3440. } else if (isDate(input)) {
  3441. config._d = input;
  3442. } else if (format) {
  3443. configFromStringAndFormat(config);
  3444. } else {
  3445. configFromInput(config);
  3446. }
  3447. if (!valid__isValid(config)) {
  3448. config._d = null;
  3449. }
  3450. return config;
  3451. }
  3452. function configFromInput(config) {
  3453. var input = config._i;
  3454. if (input === undefined) {
  3455. config._d = new Date(utils_hooks__hooks.now());
  3456. } else if (isDate(input)) {
  3457. config._d = new Date(input.valueOf());
  3458. } else if (typeof input === 'string') {
  3459. configFromString(config);
  3460. } else if (isArray(input)) {
  3461. config._a = map(input.slice(0), function (obj) {
  3462. return parseInt(obj, 10);
  3463. });
  3464. configFromArray(config);
  3465. } else if (typeof(input) === 'object') {
  3466. configFromObject(config);
  3467. } else if (typeof(input) === 'number') {
  3468. // from milliseconds
  3469. config._d = new Date(input);
  3470. } else {
  3471. utils_hooks__hooks.createFromInputFallback(config);
  3472. }
  3473. }
  3474. function createLocalOrUTC (input, format, locale, strict, isUTC) {
  3475. var c = {};
  3476. if (typeof(locale) === 'boolean') {
  3477. strict = locale;
  3478. locale = undefined;
  3479. }
  3480. if ((isObject(input) && isObjectEmpty(input)) ||
  3481. (isArray(input) && input.length === 0)) {
  3482. input = undefined;
  3483. }
  3484. // object construction must be done this way.
  3485. // https://github.com/moment/moment/issues/1423
  3486. c._isAMomentObject = true;
  3487. c._useUTC = c._isUTC = isUTC;
  3488. c._l = locale;
  3489. c._i = input;
  3490. c._f = format;
  3491. c._strict = strict;
  3492. return createFromConfig(c);
  3493. }
  3494. function local__createLocal (input, format, locale, strict) {
  3495. return createLocalOrUTC(input, format, locale, strict, false);
  3496. }
  3497. var prototypeMin = deprecate(
  3498. 'moment().min is deprecated, use moment.max instead. http://momentjs.com/guides/#/warnings/min-max/',
  3499. function () {
  3500. var other = local__createLocal.apply(null, arguments);
  3501. if (this.isValid() && other.isValid()) {
  3502. return other < this ? this : other;
  3503. } else {
  3504. return valid__createInvalid();
  3505. }
  3506. }
  3507. );
  3508. var prototypeMax = deprecate(
  3509. 'moment().max is deprecated, use moment.min instead. http://momentjs.com/guides/#/warnings/min-max/',
  3510. function () {
  3511. var other = local__createLocal.apply(null, arguments);
  3512. if (this.isValid() && other.isValid()) {
  3513. return other > this ? this : other;
  3514. } else {
  3515. return valid__createInvalid();
  3516. }
  3517. }
  3518. );
  3519. // Pick a moment m from moments so that m[fn](other) is true for all
  3520. // other. This relies on the function fn to be transitive.
  3521. //
  3522. // moments should either be an array of moment objects or an array, whose
  3523. // first element is an array of moment objects.
  3524. function pickBy(fn, moments) {
  3525. var res, i;
  3526. if (moments.length === 1 && isArray(moments[0])) {
  3527. moments = moments[0];
  3528. }
  3529. if (!moments.length) {
  3530. return local__createLocal();
  3531. }
  3532. res = moments[0];
  3533. for (i = 1; i < moments.length; ++i) {
  3534. if (!moments[i].isValid() || moments[i][fn](res)) {
  3535. res = moments[i];
  3536. }
  3537. }
  3538. return res;
  3539. }
  3540. // TODO: Use [].sort instead?
  3541. function min () {
  3542. var args = [].slice.call(arguments, 0);
  3543. return pickBy('isBefore', args);
  3544. }
  3545. function max () {
  3546. var args = [].slice.call(arguments, 0);
  3547. return pickBy('isAfter', args);
  3548. }
  3549. var now = function () {
  3550. return Date.now ? Date.now() : +(new Date());
  3551. };
  3552. function Duration (duration) {
  3553. var normalizedInput = normalizeObjectUnits(duration),
  3554. years = normalizedInput.year || 0,
  3555. quarters = normalizedInput.quarter || 0,
  3556. months = normalizedInput.month || 0,
  3557. weeks = normalizedInput.week || 0,
  3558. days = normalizedInput.day || 0,
  3559. hours = normalizedInput.hour || 0,
  3560. minutes = normalizedInput.minute || 0,
  3561. seconds = normalizedInput.second || 0,
  3562. milliseconds = normalizedInput.millisecond || 0;
  3563. // representation for dateAddRemove
  3564. this._milliseconds = +milliseconds +
  3565. seconds * 1e3 + // 1000
  3566. minutes * 6e4 + // 1000 * 60
  3567. hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
  3568. // Because of dateAddRemove treats 24 hours as different from a
  3569. // day when working around DST, we need to store them separately
  3570. this._days = +days +
  3571. weeks * 7;
  3572. // It is impossible translate months into days without knowing
  3573. // which months you are are talking about, so we have to store
  3574. // it separately.
  3575. this._months = +months +
  3576. quarters * 3 +
  3577. years * 12;
  3578. this._data = {};
  3579. this._locale = locale_locales__getLocale();
  3580. this._bubble();
  3581. }
  3582. function isDuration (obj) {
  3583. return obj instanceof Duration;
  3584. }
  3585. // FORMATTING
  3586. function offset (token, separator) {
  3587. addFormatToken(token, 0, 0, function () {
  3588. var offset = this.utcOffset();
  3589. var sign = '+';
  3590. if (offset < 0) {
  3591. offset = -offset;
  3592. sign = '-';
  3593. }
  3594. return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);
  3595. });
  3596. }
  3597. offset('Z', ':');
  3598. offset('ZZ', '');
  3599. // PARSING
  3600. addRegexToken('Z', matchShortOffset);
  3601. addRegexToken('ZZ', matchShortOffset);
  3602. addParseToken(['Z', 'ZZ'], function (input, array, config) {
  3603. config._useUTC = true;
  3604. config._tzm = offsetFromString(matchShortOffset, input);
  3605. });
  3606. // HELPERS
  3607. // timezone chunker
  3608. // '+10:00' > ['10', '00']
  3609. // '-1530' > ['-15', '30']
  3610. var chunkOffset = /([\+\-]|\d\d)/gi;
  3611. function offsetFromString(matcher, string) {
  3612. var matches = ((string || '').match(matcher) || []);
  3613. var chunk = matches[matches.length - 1] || [];
  3614. var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];
  3615. var minutes = +(parts[1] * 60) + toInt(parts[2]);
  3616. return parts[0] === '+' ? minutes : -minutes;
  3617. }
  3618. // Return a moment from input, that is local/utc/zone equivalent to model.
  3619. function cloneWithOffset(input, model) {
  3620. var res, diff;
  3621. if (model._isUTC) {
  3622. res = model.clone();
  3623. diff = (isMoment(input) || isDate(input) ? input.valueOf() : local__createLocal(input).valueOf()) - res.valueOf();
  3624. // Use low-level api, because this fn is low-level api.
  3625. res._d.setTime(res._d.valueOf() + diff);
  3626. utils_hooks__hooks.updateOffset(res, false);
  3627. return res;
  3628. } else {
  3629. return local__createLocal(input).local();
  3630. }
  3631. }
  3632. function getDateOffset (m) {
  3633. // On Firefox.24 Date#getTimezoneOffset returns a floating point.
  3634. // https://github.com/moment/moment/pull/1871
  3635. return -Math.round(m._d.getTimezoneOffset() / 15) * 15;
  3636. }
  3637. // HOOKS
  3638. // This function will be called whenever a moment is mutated.
  3639. // It is intended to keep the offset in sync with the timezone.
  3640. utils_hooks__hooks.updateOffset = function () {};
  3641. // MOMENTS
  3642. // keepLocalTime = true means only change the timezone, without
  3643. // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->
  3644. // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset
  3645. // +0200, so we adjust the time as needed, to be valid.
  3646. //
  3647. // Keeping the time actually adds/subtracts (one hour)
  3648. // from the actual represented time. That is why we call updateOffset
  3649. // a second time. In case it wants us to change the offset again
  3650. // _changeInProgress == true case, then we have to adjust, because
  3651. // there is no such time in the given timezone.
  3652. function getSetOffset (input, keepLocalTime) {
  3653. var offset = this._offset || 0,
  3654. localAdjust;
  3655. if (!this.isValid()) {
  3656. return input != null ? this : NaN;
  3657. }
  3658. if (input != null) {
  3659. if (typeof input === 'string') {
  3660. input = offsetFromString(matchShortOffset, input);
  3661. } else if (Math.abs(input) < 16) {
  3662. input = input * 60;
  3663. }
  3664. if (!this._isUTC && keepLocalTime) {
  3665. localAdjust = getDateOffset(this);
  3666. }
  3667. this._offset = input;
  3668. this._isUTC = true;
  3669. if (localAdjust != null) {
  3670. this.add(localAdjust, 'm');
  3671. }
  3672. if (offset !== input) {
  3673. if (!keepLocalTime || this._changeInProgress) {
  3674. add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false);
  3675. } else if (!this._changeInProgress) {
  3676. this._changeInProgress = true;
  3677. utils_hooks__hooks.updateOffset(this, true);
  3678. this._changeInProgress = null;
  3679. }
  3680. }
  3681. return this;
  3682. } else {
  3683. return this._isUTC ? offset : getDateOffset(this);
  3684. }
  3685. }
  3686. function getSetZone (input, keepLocalTime) {
  3687. if (input != null) {
  3688. if (typeof input !== 'string') {
  3689. input = -input;
  3690. }
  3691. this.utcOffset(input, keepLocalTime);
  3692. return this;
  3693. } else {
  3694. return -this.utcOffset();
  3695. }
  3696. }
  3697. function setOffsetToUTC (keepLocalTime) {
  3698. return this.utcOffset(0, keepLocalTime);
  3699. }
  3700. function setOffsetToLocal (keepLocalTime) {
  3701. if (this._isUTC) {
  3702. this.utcOffset(0, keepLocalTime);
  3703. this._isUTC = false;
  3704. if (keepLocalTime) {
  3705. this.subtract(getDateOffset(this), 'm');
  3706. }
  3707. }
  3708. return this;
  3709. }
  3710. function setOffsetToParsedOffset () {
  3711. if (this._tzm) {
  3712. this.utcOffset(this._tzm);
  3713. } else if (typeof this._i === 'string') {
  3714. this.utcOffset(offsetFromString(matchOffset, this._i));
  3715. }
  3716. return this;
  3717. }
  3718. function hasAlignedHourOffset (input) {
  3719. if (!this.isValid()) {
  3720. return false;
  3721. }
  3722. input = input ? local__createLocal(input).utcOffset() : 0;
  3723. return (this.utcOffset() - input) % 60 === 0;
  3724. }
  3725. function isDaylightSavingTime () {
  3726. return (
  3727. this.utcOffset() > this.clone().month(0).utcOffset() ||
  3728. this.utcOffset() > this.clone().month(5).utcOffset()
  3729. );
  3730. }
  3731. function isDaylightSavingTimeShifted () {
  3732. if (!isUndefined(this._isDSTShifted)) {
  3733. return this._isDSTShifted;
  3734. }
  3735. var c = {};
  3736. copyConfig(c, this);
  3737. c = prepareConfig(c);
  3738. if (c._a) {
  3739. var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a);
  3740. this._isDSTShifted = this.isValid() &&
  3741. compareArrays(c._a, other.toArray()) > 0;
  3742. } else {
  3743. this._isDSTShifted = false;
  3744. }
  3745. return this._isDSTShifted;
  3746. }
  3747. function isLocal () {
  3748. return this.isValid() ? !this._isUTC : false;
  3749. }
  3750. function isUtcOffset () {
  3751. return this.isValid() ? this._isUTC : false;
  3752. }
  3753. function isUtc () {
  3754. return this.isValid() ? this._isUTC && this._offset === 0 : false;
  3755. }
  3756. // ASP.NET json date format regex
  3757. var aspNetRegex = /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/;
  3758. // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html
  3759. // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere
  3760. // and further modified to allow for strings containing both week and day
  3761. var isoRegex = /^(-)?P(?:(-?[0-9,.]*)Y)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)W)?(?:(-?[0-9,.]*)D)?(?:T(?:(-?[0-9,.]*)H)?(?:(-?[0-9,.]*)M)?(?:(-?[0-9,.]*)S)?)?$/;
  3762. function create__createDuration (input, key) {
  3763. var duration = input,
  3764. // matching against regexp is expensive, do it on demand
  3765. match = null,
  3766. sign,
  3767. ret,
  3768. diffRes;
  3769. if (isDuration(input)) {
  3770. duration = {
  3771. ms : input._milliseconds,
  3772. d : input._days,
  3773. M : input._months
  3774. };
  3775. } else if (typeof input === 'number') {
  3776. duration = {};
  3777. if (key) {
  3778. duration[key] = input;
  3779. } else {
  3780. duration.milliseconds = input;
  3781. }
  3782. } else if (!!(match = aspNetRegex.exec(input))) {
  3783. sign = (match[1] === '-') ? -1 : 1;
  3784. duration = {
  3785. y : 0,
  3786. d : toInt(match[DATE]) * sign,
  3787. h : toInt(match[HOUR]) * sign,
  3788. m : toInt(match[MINUTE]) * sign,
  3789. s : toInt(match[SECOND]) * sign,
  3790. ms : toInt(match[MILLISECOND]) * sign
  3791. };
  3792. } else if (!!(match = isoRegex.exec(input))) {
  3793. sign = (match[1] === '-') ? -1 : 1;
  3794. duration = {
  3795. y : parseIso(match[2], sign),
  3796. M : parseIso(match[3], sign),
  3797. w : parseIso(match[4], sign),
  3798. d : parseIso(match[5], sign),
  3799. h : parseIso(match[6], sign),
  3800. m : parseIso(match[7], sign),
  3801. s : parseIso(match[8], sign)
  3802. };
  3803. } else if (duration == null) {// checks for null or undefined
  3804. duration = {};
  3805. } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {
  3806. diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to));
  3807. duration = {};
  3808. duration.ms = diffRes.milliseconds;
  3809. duration.M = diffRes.months;
  3810. }
  3811. ret = new Duration(duration);
  3812. if (isDuration(input) && hasOwnProp(input, '_locale')) {
  3813. ret._locale = input._locale;
  3814. }
  3815. return ret;
  3816. }
  3817. create__createDuration.fn = Duration.prototype;
  3818. function parseIso (inp, sign) {
  3819. // We'd normally use ~~inp for this, but unfortunately it also
  3820. // converts floats to ints.
  3821. // inp may be undefined, so careful calling replace on it.
  3822. var res = inp && parseFloat(inp.replace(',', '.'));
  3823. // apply sign while we're at it
  3824. return (isNaN(res) ? 0 : res) * sign;
  3825. }
  3826. function positiveMomentsDifference(base, other) {
  3827. var res = {milliseconds: 0, months: 0};
  3828. res.months = other.month() - base.month() +
  3829. (other.year() - base.year()) * 12;
  3830. if (base.clone().add(res.months, 'M').isAfter(other)) {
  3831. --res.months;
  3832. }
  3833. res.milliseconds = +other - +(base.clone().add(res.months, 'M'));
  3834. return res;
  3835. }
  3836. function momentsDifference(base, other) {
  3837. var res;
  3838. if (!(base.isValid() && other.isValid())) {
  3839. return {milliseconds: 0, months: 0};
  3840. }
  3841. other = cloneWithOffset(other, base);
  3842. if (base.isBefore(other)) {
  3843. res = positiveMomentsDifference(base, other);
  3844. } else {
  3845. res = positiveMomentsDifference(other, base);
  3846. res.milliseconds = -res.milliseconds;
  3847. res.months = -res.months;
  3848. }
  3849. return res;
  3850. }
  3851. function absRound (number) {
  3852. if (number < 0) {
  3853. return Math.round(-1 * number) * -1;
  3854. } else {
  3855. return Math.round(number);
  3856. }
  3857. }
  3858. // TODO: remove 'name' arg after deprecation is removed
  3859. function createAdder(direction, name) {
  3860. return function (val, period) {
  3861. var dur, tmp;
  3862. //invert the arguments, but complain about it
  3863. if (period !== null && !isNaN(+period)) {
  3864. deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period). ' +
  3865. 'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.');
  3866. tmp = val; val = period; period = tmp;
  3867. }
  3868. val = typeof val === 'string' ? +val : val;
  3869. dur = create__createDuration(val, period);
  3870. add_subtract__addSubtract(this, dur, direction);
  3871. return this;
  3872. };
  3873. }
  3874. function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) {
  3875. var milliseconds = duration._milliseconds,
  3876. days = absRound(duration._days),
  3877. months = absRound(duration._months);
  3878. if (!mom.isValid()) {
  3879. // No op
  3880. return;
  3881. }
  3882. updateOffset = updateOffset == null ? true : updateOffset;
  3883. if (milliseconds) {
  3884. mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
  3885. }
  3886. if (days) {
  3887. get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding);
  3888. }
  3889. if (months) {
  3890. setMonth(mom, get_set__get(mom, 'Month') + months * isAdding);
  3891. }
  3892. if (updateOffset) {
  3893. utils_hooks__hooks.updateOffset(mom, days || months);
  3894. }
  3895. }
  3896. var add_subtract__add = createAdder(1, 'add');
  3897. var add_subtract__subtract = createAdder(-1, 'subtract');
  3898. function getCalendarFormat(myMoment, now) {
  3899. var diff = myMoment.diff(now, 'days', true);
  3900. return diff < -6 ? 'sameElse' :
  3901. diff < -1 ? 'lastWeek' :
  3902. diff < 0 ? 'lastDay' :
  3903. diff < 1 ? 'sameDay' :
  3904. diff < 2 ? 'nextDay' :
  3905. diff < 7 ? 'nextWeek' : 'sameElse';
  3906. }
  3907. function moment_calendar__calendar (time, formats) {
  3908. // We want to compare the start of today, vs this.
  3909. // Getting start-of-today depends on whether we're local/utc/offset or not.
  3910. var now = time || local__createLocal(),
  3911. sod = cloneWithOffset(now, this).startOf('day'),
  3912. format = utils_hooks__hooks.calendarFormat(this, sod) || 'sameElse';
  3913. var output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]);
  3914. return this.format(output || this.localeData().calendar(format, this, local__createLocal(now)));
  3915. }
  3916. function clone () {
  3917. return new Moment(this);
  3918. }
  3919. function isAfter (input, units) {
  3920. var localInput = isMoment(input) ? input : local__createLocal(input);
  3921. if (!(this.isValid() && localInput.isValid())) {
  3922. return false;
  3923. }
  3924. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  3925. if (units === 'millisecond') {
  3926. return this.valueOf() > localInput.valueOf();
  3927. } else {
  3928. return localInput.valueOf() < this.clone().startOf(units).valueOf();
  3929. }
  3930. }
  3931. function isBefore (input, units) {
  3932. var localInput = isMoment(input) ? input : local__createLocal(input);
  3933. if (!(this.isValid() && localInput.isValid())) {
  3934. return false;
  3935. }
  3936. units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
  3937. if (units === 'millisecond') {
  3938. return this.valueOf() < localInput.valueOf();
  3939. } else {
  3940. return this.clone().endOf(units).valueOf() < localInput.valueOf();
  3941. }
  3942. }
  3943. function isBetween (from, to, units, inclusivity) {
  3944. inclusivity = inclusivity || '()';
  3945. return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
  3946. (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
  3947. }
  3948. function isSame (input, units) {
  3949. var localInput = isMoment(input) ? input : local__createLocal(input),
  3950. inputMs;
  3951. if (!(this.isValid() && localInput.isValid())) {
  3952. return false;
  3953. }
  3954. units = normalizeUnits(units || 'millisecond');
  3955. if (units === 'millisecond') {
  3956. return this.valueOf() === localInput.valueOf();
  3957. } else {
  3958. inputMs = localInput.valueOf();
  3959. return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
  3960. }
  3961. }
  3962. function isSameOrAfter (input, units) {
  3963. return this.isSame(input, units) || this.isAfter(input,units);
  3964. }
  3965. function isSameOrBefore (input, units) {
  3966. return this.isSame(input, units) || this.isBefore(input,units);
  3967. }
  3968. function diff (input, units, asFloat) {
  3969. var that,
  3970. zoneDelta,
  3971. delta, output;
  3972. if (!this.isValid()) {
  3973. return NaN;
  3974. }
  3975. that = cloneWithOffset(input, this);
  3976. if (!that.isValid()) {
  3977. return NaN;
  3978. }
  3979. zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4;
  3980. units = normalizeUnits(units);
  3981. if (units === 'year' || units === 'month' || units === 'quarter') {
  3982. output = monthDiff(this, that);
  3983. if (units === 'quarter') {
  3984. output = output / 3;
  3985. } else if (units === 'year') {
  3986. output = output / 12;
  3987. }
  3988. } else {
  3989. delta = this - that;
  3990. output = units === 'second' ? delta / 1e3 : // 1000
  3991. units === 'minute' ? delta / 6e4 : // 1000 * 60
  3992. units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60
  3993. units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst
  3994. units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst
  3995. delta;
  3996. }
  3997. return asFloat ? output : absFloor(output);
  3998. }
  3999. function monthDiff (a, b) {
  4000. // difference in months
  4001. var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),
  4002. // b is in (anchor - 1 month, anchor + 1 month)
  4003. anchor = a.clone().add(wholeMonthDiff, 'months'),
  4004. anchor2, adjust;
  4005. if (b - anchor < 0) {
  4006. anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');
  4007. // linear across the month
  4008. adjust = (b - anchor) / (anchor - anchor2);
  4009. } else {
  4010. anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');
  4011. // linear across the month
  4012. adjust = (b - anchor) / (anchor2 - anchor);
  4013. }
  4014. //check for negative zero, return zero if negative zero
  4015. return -(wholeMonthDiff + adjust) || 0;
  4016. }
  4017. utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  4018. utils_hooks__hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
  4019. function toString () {
  4020. return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  4021. }
  4022. function moment_format__toISOString () {
  4023. var m = this.clone().utc();
  4024. if (0 < m.year() && m.year() <= 9999) {
  4025. if (isFunction(Date.prototype.toISOString)) {
  4026. // native implementation is ~50x faster, use it when we can
  4027. return this.toDate().toISOString();
  4028. } else {
  4029. return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  4030. }
  4031. } else {
  4032. return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  4033. }
  4034. }
  4035. function format (inputString) {
  4036. if (!inputString) {
  4037. inputString = this.isUtc() ? utils_hooks__hooks.defaultFormatUtc : utils_hooks__hooks.defaultFormat;
  4038. }
  4039. var output = formatMoment(this, inputString);
  4040. return this.localeData().postformat(output);
  4041. }
  4042. function from (time, withoutSuffix) {
  4043. if (this.isValid() &&
  4044. ((isMoment(time) && time.isValid()) ||
  4045. local__createLocal(time).isValid())) {
  4046. return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);
  4047. } else {
  4048. return this.localeData().invalidDate();
  4049. }
  4050. }
  4051. function fromNow (withoutSuffix) {
  4052. return this.from(local__createLocal(), withoutSuffix);
  4053. }
  4054. function to (time, withoutSuffix) {
  4055. if (this.isValid() &&
  4056. ((isMoment(time) && time.isValid()) ||
  4057. local__createLocal(time).isValid())) {
  4058. return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);
  4059. } else {
  4060. return this.localeData().invalidDate();
  4061. }
  4062. }
  4063. function toNow (withoutSuffix) {
  4064. return this.to(local__createLocal(), withoutSuffix);
  4065. }
  4066. // If passed a locale key, it will set the locale for this
  4067. // instance. Otherwise, it will return the locale configuration
  4068. // variables for this instance.
  4069. function locale (key) {
  4070. var newLocaleData;
  4071. if (key === undefined) {
  4072. return this._locale._abbr;
  4073. } else {
  4074. newLocaleData = locale_locales__getLocale(key);
  4075. if (newLocaleData != null) {
  4076. this._locale = newLocaleData;
  4077. }
  4078. return this;
  4079. }
  4080. }
  4081. var lang = deprecate(
  4082. 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',
  4083. function (key) {
  4084. if (key === undefined) {
  4085. return this.localeData();
  4086. } else {
  4087. return this.locale(key);
  4088. }
  4089. }
  4090. );
  4091. function localeData () {
  4092. return this._locale;
  4093. }
  4094. function startOf (units) {
  4095. units = normalizeUnits(units);
  4096. // the following switch intentionally omits break keywords
  4097. // to utilize falling through the cases.
  4098. switch (units) {
  4099. case 'year':
  4100. this.month(0);
  4101. /* falls through */
  4102. case 'quarter':
  4103. case 'month':
  4104. this.date(1);
  4105. /* falls through */
  4106. case 'week':
  4107. case 'isoWeek':
  4108. case 'day':
  4109. case 'date':
  4110. this.hours(0);
  4111. /* falls through */
  4112. case 'hour':
  4113. this.minutes(0);
  4114. /* falls through */
  4115. case 'minute':
  4116. this.seconds(0);
  4117. /* falls through */
  4118. case 'second':
  4119. this.milliseconds(0);
  4120. }
  4121. // weeks are a special case
  4122. if (units === 'week') {
  4123. this.weekday(0);
  4124. }
  4125. if (units === 'isoWeek') {
  4126. this.isoWeekday(1);
  4127. }
  4128. // quarters are also special
  4129. if (units === 'quarter') {
  4130. this.month(Math.floor(this.month() / 3) * 3);
  4131. }
  4132. return this;
  4133. }
  4134. function endOf (units) {
  4135. units = normalizeUnits(units);
  4136. if (units === undefined || units === 'millisecond') {
  4137. return this;
  4138. }
  4139. // 'date' is an alias for 'day', so it should be considered as such.
  4140. if (units === 'date') {
  4141. units = 'day';
  4142. }
  4143. return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');
  4144. }
  4145. function to_type__valueOf () {
  4146. return this._d.valueOf() - ((this._offset || 0) * 60000);
  4147. }
  4148. function unix () {
  4149. return Math.floor(this.valueOf() / 1000);
  4150. }
  4151. function toDate () {
  4152. return new Date(this.valueOf());
  4153. }
  4154. function toArray () {
  4155. var m = this;
  4156. return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];
  4157. }
  4158. function toObject () {
  4159. var m = this;
  4160. return {
  4161. years: m.year(),
  4162. months: m.month(),
  4163. date: m.date(),
  4164. hours: m.hours(),
  4165. minutes: m.minutes(),
  4166. seconds: m.seconds(),
  4167. milliseconds: m.milliseconds()
  4168. };
  4169. }
  4170. function toJSON () {
  4171. // new Date(NaN).toJSON() === null
  4172. return this.isValid() ? this.toISOString() : null;
  4173. }
  4174. function moment_valid__isValid () {
  4175. return valid__isValid(this);
  4176. }
  4177. function parsingFlags () {
  4178. return extend({}, getParsingFlags(this));
  4179. }
  4180. function invalidAt () {
  4181. return getParsingFlags(this).overflow;
  4182. }
  4183. function creationData() {
  4184. return {
  4185. input: this._i,
  4186. format: this._f,
  4187. locale: this._locale,
  4188. isUTC: this._isUTC,
  4189. strict: this._strict
  4190. };
  4191. }
  4192. // FORMATTING
  4193. addFormatToken(0, ['gg', 2], 0, function () {
  4194. return this.weekYear() % 100;
  4195. });
  4196. addFormatToken(0, ['GG', 2], 0, function () {
  4197. return this.isoWeekYear() % 100;
  4198. });
  4199. function addWeekYearFormatToken (token, getter) {
  4200. addFormatToken(0, [token, token.length], 0, getter);
  4201. }
  4202. addWeekYearFormatToken('gggg', 'weekYear');
  4203. addWeekYearFormatToken('ggggg', 'weekYear');
  4204. addWeekYearFormatToken('GGGG', 'isoWeekYear');
  4205. addWeekYearFormatToken('GGGGG', 'isoWeekYear');
  4206. // ALIASES
  4207. addUnitAlias('weekYear', 'gg');
  4208. addUnitAlias('isoWeekYear', 'GG');
  4209. // PRIORITY
  4210. addUnitPriority('weekYear', 1);
  4211. addUnitPriority('isoWeekYear', 1);
  4212. // PARSING
  4213. addRegexToken('G', matchSigned);
  4214. addRegexToken('g', matchSigned);
  4215. addRegexToken('GG', match1to2, match2);
  4216. addRegexToken('gg', match1to2, match2);
  4217. addRegexToken('GGGG', match1to4, match4);
  4218. addRegexToken('gggg', match1to4, match4);
  4219. addRegexToken('GGGGG', match1to6, match6);
  4220. addRegexToken('ggggg', match1to6, match6);
  4221. addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {
  4222. week[token.substr(0, 2)] = toInt(input);
  4223. });
  4224. addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
  4225. week[token] = utils_hooks__hooks.parseTwoDigitYear(input);
  4226. });
  4227. // MOMENTS
  4228. function getSetWeekYear (input) {
  4229. return getSetWeekYearHelper.call(this,
  4230. input,
  4231. this.week(),
  4232. this.weekday(),
  4233. this.localeData()._week.dow,
  4234. this.localeData()._week.doy);
  4235. }
  4236. function getSetISOWeekYear (input) {
  4237. return getSetWeekYearHelper.call(this,
  4238. input, this.isoWeek(), this.isoWeekday(), 1, 4);
  4239. }
  4240. function getISOWeeksInYear () {
  4241. return weeksInYear(this.year(), 1, 4);
  4242. }
  4243. function getWeeksInYear () {
  4244. var weekInfo = this.localeData()._week;
  4245. return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
  4246. }
  4247. function getSetWeekYearHelper(input, week, weekday, dow, doy) {
  4248. var weeksTarget;
  4249. if (input == null) {
  4250. return weekOfYear(this, dow, doy).year;
  4251. } else {
  4252. weeksTarget = weeksInYear(input, dow, doy);
  4253. if (week > weeksTarget) {
  4254. week = weeksTarget;
  4255. }
  4256. return setWeekAll.call(this, input, week, weekday, dow, doy);
  4257. }
  4258. }
  4259. function setWeekAll(weekYear, week, weekday, dow, doy) {
  4260. var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
  4261. date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
  4262. this.year(date.getUTCFullYear());
  4263. this.month(date.getUTCMonth());
  4264. this.date(date.getUTCDate());
  4265. return this;
  4266. }
  4267. // FORMATTING
  4268. addFormatToken('Q', 0, 'Qo', 'quarter');
  4269. // ALIASES
  4270. addUnitAlias('quarter', 'Q');
  4271. // PRIORITY
  4272. addUnitPriority('quarter', 7);
  4273. // PARSING
  4274. addRegexToken('Q', match1);
  4275. addParseToken('Q', function (input, array) {
  4276. array[MONTH] = (toInt(input) - 1) * 3;
  4277. });
  4278. // MOMENTS
  4279. function getSetQuarter (input) {
  4280. return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);
  4281. }
  4282. // FORMATTING
  4283. addFormatToken('D', ['DD', 2], 'Do', 'date');
  4284. // ALIASES
  4285. addUnitAlias('date', 'D');
  4286. // PRIOROITY
  4287. addUnitPriority('date', 9);
  4288. // PARSING
  4289. addRegexToken('D', match1to2);
  4290. addRegexToken('DD', match1to2, match2);
  4291. addRegexToken('Do', function (isStrict, locale) {
  4292. return isStrict ? locale._ordinalParse : locale._ordinalParseLenient;
  4293. });
  4294. addParseToken(['D', 'DD'], DATE);
  4295. addParseToken('Do', function (input, array) {
  4296. array[DATE] = toInt(input.match(match1to2)[0], 10);
  4297. });
  4298. // MOMENTS
  4299. var getSetDayOfMonth = makeGetSet('Date', true);
  4300. // FORMATTING
  4301. addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');
  4302. // ALIASES
  4303. addUnitAlias('dayOfYear', 'DDD');
  4304. // PRIORITY
  4305. addUnitPriority('dayOfYear', 4);
  4306. // PARSING
  4307. addRegexToken('DDD', match1to3);
  4308. addRegexToken('DDDD', match3);
  4309. addParseToken(['DDD', 'DDDD'], function (input, array, config) {
  4310. config._dayOfYear = toInt(input);
  4311. });
  4312. // HELPERS
  4313. // MOMENTS
  4314. function getSetDayOfYear (input) {
  4315. var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;
  4316. return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');
  4317. }
  4318. // FORMATTING
  4319. addFormatToken('m', ['mm', 2], 0, 'minute');
  4320. // ALIASES
  4321. addUnitAlias('minute', 'm');
  4322. // PRIORITY
  4323. addUnitPriority('minute', 14);
  4324. // PARSING
  4325. addRegexToken('m', match1to2);
  4326. addRegexToken('mm', match1to2, match2);
  4327. addParseToken(['m', 'mm'], MINUTE);
  4328. // MOMENTS
  4329. var getSetMinute = makeGetSet('Minutes', false);
  4330. // FORMATTING
  4331. addFormatToken('s', ['ss', 2], 0, 'second');
  4332. // ALIASES
  4333. addUnitAlias('second', 's');
  4334. // PRIORITY
  4335. addUnitPriority('second', 15);
  4336. // PARSING
  4337. addRegexToken('s', match1to2);
  4338. addRegexToken('ss', match1to2, match2);
  4339. addParseToken(['s', 'ss'], SECOND);
  4340. // MOMENTS
  4341. var getSetSecond = makeGetSet('Seconds', false);
  4342. // FORMATTING
  4343. addFormatToken('S', 0, 0, function () {
  4344. return ~~(this.millisecond() / 100);
  4345. });
  4346. addFormatToken(0, ['SS', 2], 0, function () {
  4347. return ~~(this.millisecond() / 10);
  4348. });
  4349. addFormatToken(0, ['SSS', 3], 0, 'millisecond');
  4350. addFormatToken(0, ['SSSS', 4], 0, function () {
  4351. return this.millisecond() * 10;
  4352. });
  4353. addFormatToken(0, ['SSSSS', 5], 0, function () {
  4354. return this.millisecond() * 100;
  4355. });
  4356. addFormatToken(0, ['SSSSSS', 6], 0, function () {
  4357. return this.millisecond() * 1000;
  4358. });
  4359. addFormatToken(0, ['SSSSSSS', 7], 0, function () {
  4360. return this.millisecond() * 10000;
  4361. });
  4362. addFormatToken(0, ['SSSSSSSS', 8], 0, function () {
  4363. return this.millisecond() * 100000;
  4364. });
  4365. addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {
  4366. return this.millisecond() * 1000000;
  4367. });
  4368. // ALIASES
  4369. addUnitAlias('millisecond', 'ms');
  4370. // PRIORITY
  4371. addUnitPriority('millisecond', 16);
  4372. // PARSING
  4373. addRegexToken('S', match1to3, match1);
  4374. addRegexToken('SS', match1to3, match2);
  4375. addRegexToken('SSS', match1to3, match3);
  4376. var token;
  4377. for (token = 'SSSS'; token.length <= 9; token += 'S') {
  4378. addRegexToken(token, matchUnsigned);
  4379. }
  4380. function parseMs(input, array) {
  4381. array[MILLISECOND] = toInt(('0.' + input) * 1000);
  4382. }
  4383. for (token = 'S'; token.length <= 9; token += 'S') {
  4384. addParseToken(token, parseMs);
  4385. }
  4386. // MOMENTS
  4387. var getSetMillisecond = makeGetSet('Milliseconds', false);
  4388. // FORMATTING
  4389. addFormatToken('z', 0, 0, 'zoneAbbr');
  4390. addFormatToken('zz', 0, 0, 'zoneName');
  4391. // MOMENTS
  4392. function getZoneAbbr () {
  4393. return this._isUTC ? 'UTC' : '';
  4394. }
  4395. function getZoneName () {
  4396. return this._isUTC ? 'Coordinated Universal Time' : '';
  4397. }
  4398. var momentPrototype__proto = Moment.prototype;
  4399. momentPrototype__proto.add = add_subtract__add;
  4400. momentPrototype__proto.calendar = moment_calendar__calendar;
  4401. momentPrototype__proto.clone = clone;
  4402. momentPrototype__proto.diff = diff;
  4403. momentPrototype__proto.endOf = endOf;
  4404. momentPrototype__proto.format = format;
  4405. momentPrototype__proto.from = from;
  4406. momentPrototype__proto.fromNow = fromNow;
  4407. momentPrototype__proto.to = to;
  4408. momentPrototype__proto.toNow = toNow;
  4409. momentPrototype__proto.get = stringGet;
  4410. momentPrototype__proto.invalidAt = invalidAt;
  4411. momentPrototype__proto.isAfter = isAfter;
  4412. momentPrototype__proto.isBefore = isBefore;
  4413. momentPrototype__proto.isBetween = isBetween;
  4414. momentPrototype__proto.isSame = isSame;
  4415. momentPrototype__proto.isSameOrAfter = isSameOrAfter;
  4416. momentPrototype__proto.isSameOrBefore = isSameOrBefore;
  4417. momentPrototype__proto.isValid = moment_valid__isValid;
  4418. momentPrototype__proto.lang = lang;
  4419. momentPrototype__proto.locale = locale;
  4420. momentPrototype__proto.localeData = localeData;
  4421. momentPrototype__proto.max = prototypeMax;
  4422. momentPrototype__proto.min = prototypeMin;
  4423. momentPrototype__proto.parsingFlags = parsingFlags;
  4424. momentPrototype__proto.set = stringSet;
  4425. momentPrototype__proto.startOf = startOf;
  4426. momentPrototype__proto.subtract = add_subtract__subtract;
  4427. momentPrototype__proto.toArray = toArray;
  4428. momentPrototype__proto.toObject = toObject;
  4429. momentPrototype__proto.toDate = toDate;
  4430. momentPrototype__proto.toISOString = moment_format__toISOString;
  4431. momentPrototype__proto.toJSON = toJSON;
  4432. momentPrototype__proto.toString = toString;
  4433. momentPrototype__proto.unix = unix;
  4434. momentPrototype__proto.valueOf = to_type__valueOf;
  4435. momentPrototype__proto.creationData = creationData;
  4436. // Year
  4437. momentPrototype__proto.year = getSetYear;
  4438. momentPrototype__proto.isLeapYear = getIsLeapYear;
  4439. // Week Year
  4440. momentPrototype__proto.weekYear = getSetWeekYear;
  4441. momentPrototype__proto.isoWeekYear = getSetISOWeekYear;
  4442. // Quarter
  4443. momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter;
  4444. // Month
  4445. momentPrototype__proto.month = getSetMonth;
  4446. momentPrototype__proto.daysInMonth = getDaysInMonth;
  4447. // Week
  4448. momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek;
  4449. momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek;
  4450. momentPrototype__proto.weeksInYear = getWeeksInYear;
  4451. momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear;
  4452. // Day
  4453. momentPrototype__proto.date = getSetDayOfMonth;
  4454. momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek;
  4455. momentPrototype__proto.weekday = getSetLocaleDayOfWeek;
  4456. momentPrototype__proto.isoWeekday = getSetISODayOfWeek;
  4457. momentPrototype__proto.dayOfYear = getSetDayOfYear;
  4458. // Hour
  4459. momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour;
  4460. // Minute
  4461. momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute;
  4462. // Second
  4463. momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond;
  4464. // Millisecond
  4465. momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond;
  4466. // Offset
  4467. momentPrototype__proto.utcOffset = getSetOffset;
  4468. momentPrototype__proto.utc = setOffsetToUTC;
  4469. momentPrototype__proto.local = setOffsetToLocal;
  4470. momentPrototype__proto.parseZone = setOffsetToParsedOffset;
  4471. momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset;
  4472. momentPrototype__proto.isDST = isDaylightSavingTime;
  4473. momentPrototype__proto.isLocal = isLocal;
  4474. momentPrototype__proto.isUtcOffset = isUtcOffset;
  4475. momentPrototype__proto.isUtc = isUtc;
  4476. momentPrototype__proto.isUTC = isUtc;
  4477. // Timezone
  4478. momentPrototype__proto.zoneAbbr = getZoneAbbr;
  4479. momentPrototype__proto.zoneName = getZoneName;
  4480. // Deprecations
  4481. momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);
  4482. momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);
  4483. momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);
  4484. momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/', getSetZone);
  4485. momentPrototype__proto.isDSTShifted = deprecate('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information', isDaylightSavingTimeShifted);
  4486. var momentPrototype = momentPrototype__proto;
  4487. function moment__createUnix (input) {
  4488. return local__createLocal(input * 1000);
  4489. }
  4490. function moment__createInZone () {
  4491. return local__createLocal.apply(null, arguments).parseZone();
  4492. }
  4493. function preParsePostFormat (string) {
  4494. return string;
  4495. }
  4496. var prototype__proto = Locale.prototype;
  4497. prototype__proto.calendar = locale_calendar__calendar;
  4498. prototype__proto.longDateFormat = longDateFormat;
  4499. prototype__proto.invalidDate = invalidDate;
  4500. prototype__proto.ordinal = ordinal;
  4501. prototype__proto.preparse = preParsePostFormat;
  4502. prototype__proto.postformat = preParsePostFormat;
  4503. prototype__proto.relativeTime = relative__relativeTime;
  4504. prototype__proto.pastFuture = pastFuture;
  4505. prototype__proto.set = locale_set__set;
  4506. // Month
  4507. prototype__proto.months = localeMonths;
  4508. prototype__proto.monthsShort = localeMonthsShort;
  4509. prototype__proto.monthsParse = localeMonthsParse;
  4510. prototype__proto.monthsRegex = monthsRegex;
  4511. prototype__proto.monthsShortRegex = monthsShortRegex;
  4512. // Week
  4513. prototype__proto.week = localeWeek;
  4514. prototype__proto.firstDayOfYear = localeFirstDayOfYear;
  4515. prototype__proto.firstDayOfWeek = localeFirstDayOfWeek;
  4516. // Day of Week
  4517. prototype__proto.weekdays = localeWeekdays;
  4518. prototype__proto.weekdaysMin = localeWeekdaysMin;
  4519. prototype__proto.weekdaysShort = localeWeekdaysShort;
  4520. prototype__proto.weekdaysParse = localeWeekdaysParse;
  4521. prototype__proto.weekdaysRegex = weekdaysRegex;
  4522. prototype__proto.weekdaysShortRegex = weekdaysShortRegex;
  4523. prototype__proto.weekdaysMinRegex = weekdaysMinRegex;
  4524. // Hours
  4525. prototype__proto.isPM = localeIsPM;
  4526. prototype__proto.meridiem = localeMeridiem;
  4527. function lists__get (format, index, field, setter) {
  4528. var locale = locale_locales__getLocale();
  4529. var utc = create_utc__createUTC().set(setter, index);
  4530. return locale[field](utc, format);
  4531. }
  4532. function listMonthsImpl (format, index, field) {
  4533. if (typeof format === 'number') {
  4534. index = format;
  4535. format = undefined;
  4536. }
  4537. format = format || '';
  4538. if (index != null) {
  4539. return lists__get(format, index, field, 'month');
  4540. }
  4541. var i;
  4542. var out = [];
  4543. for (i = 0; i < 12; i++) {
  4544. out[i] = lists__get(format, i, field, 'month');
  4545. }
  4546. return out;
  4547. }
  4548. // ()
  4549. // (5)
  4550. // (fmt, 5)
  4551. // (fmt)
  4552. // (true)
  4553. // (true, 5)
  4554. // (true, fmt, 5)
  4555. // (true, fmt)
  4556. function listWeekdaysImpl (localeSorted, format, index, field) {
  4557. if (typeof localeSorted === 'boolean') {
  4558. if (typeof format === 'number') {
  4559. index = format;
  4560. format = undefined;
  4561. }
  4562. format = format || '';
  4563. } else {
  4564. format = localeSorted;
  4565. index = format;
  4566. localeSorted = false;
  4567. if (typeof format === 'number') {
  4568. index = format;
  4569. format = undefined;
  4570. }
  4571. format = format || '';
  4572. }
  4573. var locale = locale_locales__getLocale(),
  4574. shift = localeSorted ? locale._week.dow : 0;
  4575. if (index != null) {
  4576. return lists__get(format, (index + shift) % 7, field, 'day');
  4577. }
  4578. var i;
  4579. var out = [];
  4580. for (i = 0; i < 7; i++) {
  4581. out[i] = lists__get(format, (i + shift) % 7, field, 'day');
  4582. }
  4583. return out;
  4584. }
  4585. function lists__listMonths (format, index) {
  4586. return listMonthsImpl(format, index, 'months');
  4587. }
  4588. function lists__listMonthsShort (format, index) {
  4589. return listMonthsImpl(format, index, 'monthsShort');
  4590. }
  4591. function lists__listWeekdays (localeSorted, format, index) {
  4592. return listWeekdaysImpl(localeSorted, format, index, 'weekdays');
  4593. }
  4594. function lists__listWeekdaysShort (localeSorted, format, index) {
  4595. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysShort');
  4596. }
  4597. function lists__listWeekdaysMin (localeSorted, format, index) {
  4598. return listWeekdaysImpl(localeSorted, format, index, 'weekdaysMin');
  4599. }
  4600. locale_locales__getSetGlobalLocale('en', {
  4601. ordinalParse: /\d{1,2}(th|st|nd|rd)/,
  4602. ordinal : function (number) {
  4603. var b = number % 10,
  4604. output = (toInt(number % 100 / 10) === 1) ? 'th' :
  4605. (b === 1) ? 'st' :
  4606. (b === 2) ? 'nd' :
  4607. (b === 3) ? 'rd' : 'th';
  4608. return number + output;
  4609. }
  4610. });
  4611. // Side effect imports
  4612. utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale);
  4613. utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale);
  4614. var mathAbs = Math.abs;
  4615. function duration_abs__abs () {
  4616. var data = this._data;
  4617. this._milliseconds = mathAbs(this._milliseconds);
  4618. this._days = mathAbs(this._days);
  4619. this._months = mathAbs(this._months);
  4620. data.milliseconds = mathAbs(data.milliseconds);
  4621. data.seconds = mathAbs(data.seconds);
  4622. data.minutes = mathAbs(data.minutes);
  4623. data.hours = mathAbs(data.hours);
  4624. data.months = mathAbs(data.months);
  4625. data.years = mathAbs(data.years);
  4626. return this;
  4627. }
  4628. function duration_add_subtract__addSubtract (duration, input, value, direction) {
  4629. var other = create__createDuration(input, value);
  4630. duration._milliseconds += direction * other._milliseconds;
  4631. duration._days += direction * other._days;
  4632. duration._months += direction * other._months;
  4633. return duration._bubble();
  4634. }
  4635. // supports only 2.0-style add(1, 's') or add(duration)
  4636. function duration_add_subtract__add (input, value) {
  4637. return duration_add_subtract__addSubtract(this, input, value, 1);
  4638. }
  4639. // supports only 2.0-style subtract(1, 's') or subtract(duration)
  4640. function duration_add_subtract__subtract (input, value) {
  4641. return duration_add_subtract__addSubtract(this, input, value, -1);
  4642. }
  4643. function absCeil (number) {
  4644. if (number < 0) {
  4645. return Math.floor(number);
  4646. } else {
  4647. return Math.ceil(number);
  4648. }
  4649. }
  4650. function bubble () {
  4651. var milliseconds = this._milliseconds;
  4652. var days = this._days;
  4653. var months = this._months;
  4654. var data = this._data;
  4655. var seconds, minutes, hours, years, monthsFromDays;
  4656. // if we have a mix of positive and negative values, bubble down first
  4657. // check: https://github.com/moment/moment/issues/2166
  4658. if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||
  4659. (milliseconds <= 0 && days <= 0 && months <= 0))) {
  4660. milliseconds += absCeil(monthsToDays(months) + days) * 864e5;
  4661. days = 0;
  4662. months = 0;
  4663. }
  4664. // The following code bubbles up values, see the tests for
  4665. // examples of what that means.
  4666. data.milliseconds = milliseconds % 1000;
  4667. seconds = absFloor(milliseconds / 1000);
  4668. data.seconds = seconds % 60;
  4669. minutes = absFloor(seconds / 60);
  4670. data.minutes = minutes % 60;
  4671. hours = absFloor(minutes / 60);
  4672. data.hours = hours % 24;
  4673. days += absFloor(hours / 24);
  4674. // convert days to months
  4675. monthsFromDays = absFloor(daysToMonths(days));
  4676. months += monthsFromDays;
  4677. days -= absCeil(monthsToDays(monthsFromDays));
  4678. // 12 months -> 1 year
  4679. years = absFloor(months / 12);
  4680. months %= 12;
  4681. data.days = days;
  4682. data.months = months;
  4683. data.years = years;
  4684. return this;
  4685. }
  4686. function daysToMonths (days) {
  4687. // 400 years have 146097 days (taking into account leap year rules)
  4688. // 400 years have 12 months === 4800
  4689. return days * 4800 / 146097;
  4690. }
  4691. function monthsToDays (months) {
  4692. // the reverse of daysToMonths
  4693. return months * 146097 / 4800;
  4694. }
  4695. function as (units) {
  4696. var days;
  4697. var months;
  4698. var milliseconds = this._milliseconds;
  4699. units = normalizeUnits(units);
  4700. if (units === 'month' || units === 'year') {
  4701. days = this._days + milliseconds / 864e5;
  4702. months = this._months + daysToMonths(days);
  4703. return units === 'month' ? months : months / 12;
  4704. } else {
  4705. // handle milliseconds separately because of floating point math errors (issue #1867)
  4706. days = this._days + Math.round(monthsToDays(this._months));
  4707. switch (units) {
  4708. case 'week' : return days / 7 + milliseconds / 6048e5;
  4709. case 'day' : return days + milliseconds / 864e5;
  4710. case 'hour' : return days * 24 + milliseconds / 36e5;
  4711. case 'minute' : return days * 1440 + milliseconds / 6e4;
  4712. case 'second' : return days * 86400 + milliseconds / 1000;
  4713. // Math.floor prevents floating point math errors here
  4714. case 'millisecond': return Math.floor(days * 864e5) + milliseconds;
  4715. default: throw new Error('Unknown unit ' + units);
  4716. }
  4717. }
  4718. }
  4719. // TODO: Use this.as('ms')?
  4720. function duration_as__valueOf () {
  4721. return (
  4722. this._milliseconds +
  4723. this._days * 864e5 +
  4724. (this._months % 12) * 2592e6 +
  4725. toInt(this._months / 12) * 31536e6
  4726. );
  4727. }
  4728. function makeAs (alias) {
  4729. return function () {
  4730. return this.as(alias);
  4731. };
  4732. }
  4733. var asMilliseconds = makeAs('ms');
  4734. var asSeconds = makeAs('s');
  4735. var asMinutes = makeAs('m');
  4736. var asHours = makeAs('h');
  4737. var asDays = makeAs('d');
  4738. var asWeeks = makeAs('w');
  4739. var asMonths = makeAs('M');
  4740. var asYears = makeAs('y');
  4741. function duration_get__get (units) {
  4742. units = normalizeUnits(units);
  4743. return this[units + 's']();
  4744. }
  4745. function makeGetter(name) {
  4746. return function () {
  4747. return this._data[name];
  4748. };
  4749. }
  4750. var milliseconds = makeGetter('milliseconds');
  4751. var seconds = makeGetter('seconds');
  4752. var minutes = makeGetter('minutes');
  4753. var hours = makeGetter('hours');
  4754. var days = makeGetter('days');
  4755. var months = makeGetter('months');
  4756. var years = makeGetter('years');
  4757. function weeks () {
  4758. return absFloor(this.days() / 7);
  4759. }
  4760. var round = Math.round;
  4761. var thresholds = {
  4762. s: 45, // seconds to minute
  4763. m: 45, // minutes to hour
  4764. h: 22, // hours to day
  4765. d: 26, // days to month
  4766. M: 11 // months to year
  4767. };
  4768. // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize
  4769. function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {
  4770. return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);
  4771. }
  4772. function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) {
  4773. var duration = create__createDuration(posNegDuration).abs();
  4774. var seconds = round(duration.as('s'));
  4775. var minutes = round(duration.as('m'));
  4776. var hours = round(duration.as('h'));
  4777. var days = round(duration.as('d'));
  4778. var months = round(duration.as('M'));
  4779. var years = round(duration.as('y'));
  4780. var a = seconds < thresholds.s && ['s', seconds] ||
  4781. minutes <= 1 && ['m'] ||
  4782. minutes < thresholds.m && ['mm', minutes] ||
  4783. hours <= 1 && ['h'] ||
  4784. hours < thresholds.h && ['hh', hours] ||
  4785. days <= 1 && ['d'] ||
  4786. days < thresholds.d && ['dd', days] ||
  4787. months <= 1 && ['M'] ||
  4788. months < thresholds.M && ['MM', months] ||
  4789. years <= 1 && ['y'] || ['yy', years];
  4790. a[2] = withoutSuffix;
  4791. a[3] = +posNegDuration > 0;
  4792. a[4] = locale;
  4793. return substituteTimeAgo.apply(null, a);
  4794. }
  4795. // This function allows you to set the rounding function for relative time strings
  4796. function duration_humanize__getSetRelativeTimeRounding (roundingFunction) {
  4797. if (roundingFunction === undefined) {
  4798. return round;
  4799. }
  4800. if (typeof(roundingFunction) === 'function') {
  4801. round = roundingFunction;
  4802. return true;
  4803. }
  4804. return false;
  4805. }
  4806. // This function allows you to set a threshold for relative time strings
  4807. function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) {
  4808. if (thresholds[threshold] === undefined) {
  4809. return false;
  4810. }
  4811. if (limit === undefined) {
  4812. return thresholds[threshold];
  4813. }
  4814. thresholds[threshold] = limit;
  4815. return true;
  4816. }
  4817. function humanize (withSuffix) {
  4818. var locale = this.localeData();
  4819. var output = duration_humanize__relativeTime(this, !withSuffix, locale);
  4820. if (withSuffix) {
  4821. output = locale.pastFuture(+this, output);
  4822. }
  4823. return locale.postformat(output);
  4824. }
  4825. var iso_string__abs = Math.abs;
  4826. function iso_string__toISOString() {
  4827. // for ISO strings we do not use the normal bubbling rules:
  4828. // * milliseconds bubble up until they become hours
  4829. // * days do not bubble at all
  4830. // * months bubble up until they become years
  4831. // This is because there is no context-free conversion between hours and days
  4832. // (think of clock changes)
  4833. // and also not between days and months (28-31 days per month)
  4834. var seconds = iso_string__abs(this._milliseconds) / 1000;
  4835. var days = iso_string__abs(this._days);
  4836. var months = iso_string__abs(this._months);
  4837. var minutes, hours, years;
  4838. // 3600 seconds -> 60 minutes -> 1 hour
  4839. minutes = absFloor(seconds / 60);
  4840. hours = absFloor(minutes / 60);
  4841. seconds %= 60;
  4842. minutes %= 60;
  4843. // 12 months -> 1 year
  4844. years = absFloor(months / 12);
  4845. months %= 12;
  4846. // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js
  4847. var Y = years;
  4848. var M = months;
  4849. var D = days;
  4850. var h = hours;
  4851. var m = minutes;
  4852. var s = seconds;
  4853. var total = this.asSeconds();
  4854. if (!total) {
  4855. // this is the same as C#'s (Noda) and python (isodate)...
  4856. // but not other JS (goog.date)
  4857. return 'P0D';
  4858. }
  4859. return (total < 0 ? '-' : '') +
  4860. 'P' +
  4861. (Y ? Y + 'Y' : '') +
  4862. (M ? M + 'M' : '') +
  4863. (D ? D + 'D' : '') +
  4864. ((h || m || s) ? 'T' : '') +
  4865. (h ? h + 'H' : '') +
  4866. (m ? m + 'M' : '') +
  4867. (s ? s + 'S' : '');
  4868. }
  4869. var duration_prototype__proto = Duration.prototype;
  4870. duration_prototype__proto.abs = duration_abs__abs;
  4871. duration_prototype__proto.add = duration_add_subtract__add;
  4872. duration_prototype__proto.subtract = duration_add_subtract__subtract;
  4873. duration_prototype__proto.as = as;
  4874. duration_prototype__proto.asMilliseconds = asMilliseconds;
  4875. duration_prototype__proto.asSeconds = asSeconds;
  4876. duration_prototype__proto.asMinutes = asMinutes;
  4877. duration_prototype__proto.asHours = asHours;
  4878. duration_prototype__proto.asDays = asDays;
  4879. duration_prototype__proto.asWeeks = asWeeks;
  4880. duration_prototype__proto.asMonths = asMonths;
  4881. duration_prototype__proto.asYears = asYears;
  4882. duration_prototype__proto.valueOf = duration_as__valueOf;
  4883. duration_prototype__proto._bubble = bubble;
  4884. duration_prototype__proto.get = duration_get__get;
  4885. duration_prototype__proto.milliseconds = milliseconds;
  4886. duration_prototype__proto.seconds = seconds;
  4887. duration_prototype__proto.minutes = minutes;
  4888. duration_prototype__proto.hours = hours;
  4889. duration_prototype__proto.days = days;
  4890. duration_prototype__proto.weeks = weeks;
  4891. duration_prototype__proto.months = months;
  4892. duration_prototype__proto.years = years;
  4893. duration_prototype__proto.humanize = humanize;
  4894. duration_prototype__proto.toISOString = iso_string__toISOString;
  4895. duration_prototype__proto.toString = iso_string__toISOString;
  4896. duration_prototype__proto.toJSON = iso_string__toISOString;
  4897. duration_prototype__proto.locale = locale;
  4898. duration_prototype__proto.localeData = localeData;
  4899. // Deprecations
  4900. duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString);
  4901. duration_prototype__proto.lang = lang;
  4902. // Side effect imports
  4903. // FORMATTING
  4904. addFormatToken('X', 0, 0, 'unix');
  4905. addFormatToken('x', 0, 0, 'valueOf');
  4906. // PARSING
  4907. addRegexToken('x', matchSigned);
  4908. addRegexToken('X', matchTimestamp);
  4909. addParseToken('X', function (input, array, config) {
  4910. config._d = new Date(parseFloat(input, 10) * 1000);
  4911. });
  4912. addParseToken('x', function (input, array, config) {
  4913. config._d = new Date(toInt(input));
  4914. });
  4915. // Side effect imports
  4916. utils_hooks__hooks.version = '2.14.1';
  4917. setHookCallback(local__createLocal);
  4918. utils_hooks__hooks.fn = momentPrototype;
  4919. utils_hooks__hooks.min = min;
  4920. utils_hooks__hooks.max = max;
  4921. utils_hooks__hooks.now = now;
  4922. utils_hooks__hooks.utc = create_utc__createUTC;
  4923. utils_hooks__hooks.unix = moment__createUnix;
  4924. utils_hooks__hooks.months = lists__listMonths;
  4925. utils_hooks__hooks.isDate = isDate;
  4926. utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale;
  4927. utils_hooks__hooks.invalid = valid__createInvalid;
  4928. utils_hooks__hooks.duration = create__createDuration;
  4929. utils_hooks__hooks.isMoment = isMoment;
  4930. utils_hooks__hooks.weekdays = lists__listWeekdays;
  4931. utils_hooks__hooks.parseZone = moment__createInZone;
  4932. utils_hooks__hooks.localeData = locale_locales__getLocale;
  4933. utils_hooks__hooks.isDuration = isDuration;
  4934. utils_hooks__hooks.monthsShort = lists__listMonthsShort;
  4935. utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin;
  4936. utils_hooks__hooks.defineLocale = defineLocale;
  4937. utils_hooks__hooks.updateLocale = updateLocale;
  4938. utils_hooks__hooks.locales = locale_locales__listLocales;
  4939. utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort;
  4940. utils_hooks__hooks.normalizeUnits = normalizeUnits;
  4941. utils_hooks__hooks.relativeTimeRounding = duration_humanize__getSetRelativeTimeRounding;
  4942. utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold;
  4943. utils_hooks__hooks.calendarFormat = getCalendarFormat;
  4944. utils_hooks__hooks.prototype = momentPrototype;
  4945. var _moment = utils_hooks__hooks;
  4946. return _moment;
  4947. }));
  4948. },{}],7:[function(require,module,exports){
  4949. /**
  4950. * @namespace Chart
  4951. */
  4952. var Chart = require(27)();
  4953. require(26)(Chart);
  4954. require(22)(Chart);
  4955. require(25)(Chart);
  4956. require(21)(Chart);
  4957. require(23)(Chart);
  4958. require(24)(Chart);
  4959. require(28)(Chart);
  4960. require(32)(Chart);
  4961. require(30)(Chart);
  4962. require(31)(Chart);
  4963. require(33)(Chart);
  4964. require(29)(Chart);
  4965. require(34)(Chart);
  4966. require(35)(Chart);
  4967. require(36)(Chart);
  4968. require(37)(Chart);
  4969. require(38)(Chart);
  4970. require(41)(Chart);
  4971. require(39)(Chart);
  4972. require(40)(Chart);
  4973. require(42)(Chart);
  4974. require(43)(Chart);
  4975. require(44)(Chart);
  4976. // Controllers must be loaded after elements
  4977. // See Chart.core.datasetController.dataElementType
  4978. require(15)(Chart);
  4979. require(16)(Chart);
  4980. require(17)(Chart);
  4981. require(18)(Chart);
  4982. require(19)(Chart);
  4983. require(20)(Chart);
  4984. require(8)(Chart);
  4985. require(9)(Chart);
  4986. require(10)(Chart);
  4987. require(11)(Chart);
  4988. require(12)(Chart);
  4989. require(13)(Chart);
  4990. require(14)(Chart);
  4991. window.Chart = module.exports = Chart;
  4992. },{"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"17":17,"18":18,"19":19,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28,"29":29,"30":30,"31":31,"32":32,"33":33,"34":34,"35":35,"36":36,"37":37,"38":38,"39":39,"40":40,"41":41,"42":42,"43":43,"44":44,"8":8,"9":9}],8:[function(require,module,exports){
  4993. "use strict";
  4994. module.exports = function(Chart) {
  4995. Chart.Bar = function(context, config) {
  4996. config.type = 'bar';
  4997. return new Chart(context, config);
  4998. };
  4999. };
  5000. },{}],9:[function(require,module,exports){
  5001. "use strict";
  5002. module.exports = function(Chart) {
  5003. Chart.Bubble = function(context, config) {
  5004. config.type = 'bubble';
  5005. return new Chart(context, config);
  5006. };
  5007. };
  5008. },{}],10:[function(require,module,exports){
  5009. "use strict";
  5010. module.exports = function(Chart) {
  5011. Chart.Doughnut = function(context, config) {
  5012. config.type = 'doughnut';
  5013. return new Chart(context, config);
  5014. };
  5015. };
  5016. },{}],11:[function(require,module,exports){
  5017. "use strict";
  5018. module.exports = function(Chart) {
  5019. Chart.Line = function(context, config) {
  5020. config.type = 'line';
  5021. return new Chart(context, config);
  5022. };
  5023. };
  5024. },{}],12:[function(require,module,exports){
  5025. "use strict";
  5026. module.exports = function(Chart) {
  5027. Chart.PolarArea = function(context, config) {
  5028. config.type = 'polarArea';
  5029. return new Chart(context, config);
  5030. };
  5031. };
  5032. },{}],13:[function(require,module,exports){
  5033. "use strict";
  5034. module.exports = function(Chart) {
  5035. Chart.Radar = function(context, config) {
  5036. config.options = Chart.helpers.configMerge({ aspectRatio: 1 }, config.options);
  5037. config.type = 'radar';
  5038. return new Chart(context, config);
  5039. };
  5040. };
  5041. },{}],14:[function(require,module,exports){
  5042. "use strict";
  5043. module.exports = function(Chart) {
  5044. var defaultConfig = {
  5045. hover: {
  5046. mode: 'single'
  5047. },
  5048. scales: {
  5049. xAxes: [{
  5050. type: "linear", // scatter should not use a category axis
  5051. position: "bottom",
  5052. id: "x-axis-1" // need an ID so datasets can reference the scale
  5053. }],
  5054. yAxes: [{
  5055. type: "linear",
  5056. position: "left",
  5057. id: "y-axis-1"
  5058. }]
  5059. },
  5060. tooltips: {
  5061. callbacks: {
  5062. title: function() {
  5063. // Title doesn't make sense for scatter since we format the data as a point
  5064. return '';
  5065. },
  5066. label: function(tooltipItem) {
  5067. return '(' + tooltipItem.xLabel + ', ' + tooltipItem.yLabel + ')';
  5068. }
  5069. }
  5070. }
  5071. };
  5072. // Register the default config for this type
  5073. Chart.defaults.scatter = defaultConfig;
  5074. // Scatter charts use line controllers
  5075. Chart.controllers.scatter = Chart.controllers.line;
  5076. Chart.Scatter = function(context, config) {
  5077. config.type = 'scatter';
  5078. return new Chart(context, config);
  5079. };
  5080. };
  5081. },{}],15:[function(require,module,exports){
  5082. "use strict";
  5083. module.exports = function(Chart) {
  5084. var helpers = Chart.helpers;
  5085. Chart.defaults.bar = {
  5086. hover: {
  5087. mode: "label"
  5088. },
  5089. scales: {
  5090. xAxes: [{
  5091. type: "category",
  5092. // Specific to Bar Controller
  5093. categoryPercentage: 0.8,
  5094. barPercentage: 0.9,
  5095. // grid line settings
  5096. gridLines: {
  5097. offsetGridLines: true
  5098. }
  5099. }],
  5100. yAxes: [{
  5101. type: "linear"
  5102. }]
  5103. }
  5104. };
  5105. Chart.controllers.bar = Chart.DatasetController.extend({
  5106. dataElementType: Chart.elements.Rectangle,
  5107. initialize: function(chart, datasetIndex) {
  5108. Chart.DatasetController.prototype.initialize.call(this, chart, datasetIndex);
  5109. // Use this to indicate that this is a bar dataset.
  5110. this.getMeta().bar = true;
  5111. },
  5112. // Get the number of datasets that display bars. We use this to correctly calculate the bar width
  5113. getBarCount: function() {
  5114. var me = this;
  5115. var barCount = 0;
  5116. helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
  5117. var meta = me.chart.getDatasetMeta(datasetIndex);
  5118. if (meta.bar && me.chart.isDatasetVisible(datasetIndex)) {
  5119. ++barCount;
  5120. }
  5121. }, me);
  5122. return barCount;
  5123. },
  5124. update: function(reset) {
  5125. var me = this;
  5126. helpers.each(me.getMeta().data, function(rectangle, index) {
  5127. me.updateElement(rectangle, index, reset);
  5128. }, me);
  5129. },
  5130. updateElement: function(rectangle, index, reset) {
  5131. var me = this;
  5132. var meta = me.getMeta();
  5133. var xScale = me.getScaleForId(meta.xAxisID);
  5134. var yScale = me.getScaleForId(meta.yAxisID);
  5135. var scaleBase = yScale.getBasePixel();
  5136. var rectangleElementOptions = me.chart.options.elements.rectangle;
  5137. var custom = rectangle.custom || {};
  5138. var dataset = me.getDataset();
  5139. helpers.extend(rectangle, {
  5140. // Utility
  5141. _xScale: xScale,
  5142. _yScale: yScale,
  5143. _datasetIndex: me.index,
  5144. _index: index,
  5145. // Desired view properties
  5146. _model: {
  5147. x: me.calculateBarX(index, me.index),
  5148. y: reset ? scaleBase : me.calculateBarY(index, me.index),
  5149. // Tooltip
  5150. label: me.chart.data.labels[index],
  5151. datasetLabel: dataset.label,
  5152. // Appearance
  5153. base: reset ? scaleBase : me.calculateBarBase(me.index, index),
  5154. width: me.calculateBarWidth(index),
  5155. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor),
  5156. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
  5157. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
  5158. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth)
  5159. }
  5160. });
  5161. rectangle.pivot();
  5162. },
  5163. calculateBarBase: function(datasetIndex, index) {
  5164. var me = this;
  5165. var meta = me.getMeta();
  5166. var yScale = me.getScaleForId(meta.yAxisID);
  5167. var base = 0;
  5168. if (yScale.options.stacked) {
  5169. var chart = me.chart;
  5170. var datasets = chart.data.datasets;
  5171. var value = Number(datasets[datasetIndex].data[index]);
  5172. for (var i = 0; i < datasetIndex; i++) {
  5173. var currentDs = datasets[i];
  5174. var currentDsMeta = chart.getDatasetMeta(i);
  5175. if (currentDsMeta.bar && currentDsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  5176. var currentVal = Number(currentDs.data[index]);
  5177. base += value < 0 ? Math.min(currentVal, 0) : Math.max(currentVal, 0);
  5178. }
  5179. }
  5180. return yScale.getPixelForValue(base);
  5181. }
  5182. return yScale.getBasePixel();
  5183. },
  5184. getRuler: function(index) {
  5185. var me = this;
  5186. var meta = me.getMeta();
  5187. var xScale = me.getScaleForId(meta.xAxisID);
  5188. var datasetCount = me.getBarCount();
  5189. var tickWidth;
  5190. if (xScale.options.type === 'category') {
  5191. tickWidth = xScale.getPixelForTick(index + 1) - xScale.getPixelForTick(index);
  5192. } else {
  5193. // Average width
  5194. tickWidth = xScale.width / xScale.ticks.length;
  5195. }
  5196. var categoryWidth = tickWidth * xScale.options.categoryPercentage;
  5197. var categorySpacing = (tickWidth - (tickWidth * xScale.options.categoryPercentage)) / 2;
  5198. var fullBarWidth = categoryWidth / datasetCount;
  5199. if (xScale.ticks.length !== me.chart.data.labels.length) {
  5200. var perc = xScale.ticks.length / me.chart.data.labels.length;
  5201. fullBarWidth = fullBarWidth * perc;
  5202. }
  5203. var barWidth = fullBarWidth * xScale.options.barPercentage;
  5204. var barSpacing = fullBarWidth - (fullBarWidth * xScale.options.barPercentage);
  5205. return {
  5206. datasetCount: datasetCount,
  5207. tickWidth: tickWidth,
  5208. categoryWidth: categoryWidth,
  5209. categorySpacing: categorySpacing,
  5210. fullBarWidth: fullBarWidth,
  5211. barWidth: barWidth,
  5212. barSpacing: barSpacing
  5213. };
  5214. },
  5215. calculateBarWidth: function(index) {
  5216. var xScale = this.getScaleForId(this.getMeta().xAxisID);
  5217. if (xScale.options.barThickness) {
  5218. return xScale.options.barThickness;
  5219. }
  5220. var ruler = this.getRuler(index);
  5221. return xScale.options.stacked ? ruler.categoryWidth : ruler.barWidth;
  5222. },
  5223. // Get bar index from the given dataset index accounting for the fact that not all bars are visible
  5224. getBarIndex: function(datasetIndex) {
  5225. var barIndex = 0;
  5226. var meta, j;
  5227. for (j = 0; j < datasetIndex; ++j) {
  5228. meta = this.chart.getDatasetMeta(j);
  5229. if (meta.bar && this.chart.isDatasetVisible(j)) {
  5230. ++barIndex;
  5231. }
  5232. }
  5233. return barIndex;
  5234. },
  5235. calculateBarX: function(index, datasetIndex) {
  5236. var me = this;
  5237. var meta = me.getMeta();
  5238. var xScale = me.getScaleForId(meta.xAxisID);
  5239. var barIndex = me.getBarIndex(datasetIndex);
  5240. var ruler = me.getRuler(index);
  5241. var leftTick = xScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
  5242. leftTick -= me.chart.isCombo ? (ruler.tickWidth / 2) : 0;
  5243. if (xScale.options.stacked) {
  5244. return leftTick + (ruler.categoryWidth / 2) + ruler.categorySpacing;
  5245. }
  5246. return leftTick +
  5247. (ruler.barWidth / 2) +
  5248. ruler.categorySpacing +
  5249. (ruler.barWidth * barIndex) +
  5250. (ruler.barSpacing / 2) +
  5251. (ruler.barSpacing * barIndex);
  5252. },
  5253. calculateBarY: function(index, datasetIndex) {
  5254. var me = this;
  5255. var meta = me.getMeta();
  5256. var yScale = me.getScaleForId(meta.yAxisID);
  5257. var value = Number(me.getDataset().data[index]);
  5258. if (yScale.options.stacked) {
  5259. var sumPos = 0,
  5260. sumNeg = 0;
  5261. for (var i = 0; i < datasetIndex; i++) {
  5262. var ds = me.chart.data.datasets[i];
  5263. var dsMeta = me.chart.getDatasetMeta(i);
  5264. if (dsMeta.bar && dsMeta.yAxisID === yScale.id && me.chart.isDatasetVisible(i)) {
  5265. var stackedVal = Number(ds.data[index]);
  5266. if (stackedVal < 0) {
  5267. sumNeg += stackedVal || 0;
  5268. } else {
  5269. sumPos += stackedVal || 0;
  5270. }
  5271. }
  5272. }
  5273. if (value < 0) {
  5274. return yScale.getPixelForValue(sumNeg + value);
  5275. } else {
  5276. return yScale.getPixelForValue(sumPos + value);
  5277. }
  5278. }
  5279. return yScale.getPixelForValue(value);
  5280. },
  5281. draw: function(ease) {
  5282. var me = this;
  5283. var easingDecimal = ease || 1;
  5284. helpers.each(me.getMeta().data, function(rectangle, index) {
  5285. var d = me.getDataset().data[index];
  5286. if (d !== null && d !== undefined && !isNaN(d)) {
  5287. rectangle.transition(easingDecimal).draw();
  5288. }
  5289. }, me);
  5290. },
  5291. setHoverStyle: function(rectangle) {
  5292. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  5293. var index = rectangle._index;
  5294. var custom = rectangle.custom || {};
  5295. var model = rectangle._model;
  5296. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  5297. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  5298. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  5299. },
  5300. removeHoverStyle: function(rectangle) {
  5301. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  5302. var index = rectangle._index;
  5303. var custom = rectangle.custom || {};
  5304. var model = rectangle._model;
  5305. var rectangleElementOptions = this.chart.options.elements.rectangle;
  5306. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor);
  5307. model.borderColor = custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor);
  5308. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth);
  5309. }
  5310. });
  5311. // including horizontalBar in the bar file, instead of a file of its own
  5312. // it extends bar (like pie extends doughnut)
  5313. Chart.defaults.horizontalBar = {
  5314. hover: {
  5315. mode: "label"
  5316. },
  5317. scales: {
  5318. xAxes: [{
  5319. type: "linear",
  5320. position: "bottom"
  5321. }],
  5322. yAxes: [{
  5323. position: "left",
  5324. type: "category",
  5325. // Specific to Horizontal Bar Controller
  5326. categoryPercentage: 0.8,
  5327. barPercentage: 0.9,
  5328. // grid line settings
  5329. gridLines: {
  5330. offsetGridLines: true
  5331. }
  5332. }]
  5333. },
  5334. elements: {
  5335. rectangle: {
  5336. borderSkipped: 'left'
  5337. }
  5338. },
  5339. tooltips: {
  5340. callbacks: {
  5341. title: function(tooltipItems, data) {
  5342. // Pick first xLabel for now
  5343. var title = '';
  5344. if (tooltipItems.length > 0) {
  5345. if (tooltipItems[0].yLabel) {
  5346. title = tooltipItems[0].yLabel;
  5347. } else if (data.labels.length > 0 && tooltipItems[0].index < data.labels.length) {
  5348. title = data.labels[tooltipItems[0].index];
  5349. }
  5350. }
  5351. return title;
  5352. },
  5353. label: function(tooltipItem, data) {
  5354. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  5355. return datasetLabel + ': ' + tooltipItem.xLabel;
  5356. }
  5357. }
  5358. }
  5359. };
  5360. Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
  5361. updateElement: function(rectangle, index, reset) {
  5362. var me = this;
  5363. var meta = me.getMeta();
  5364. var xScale = me.getScaleForId(meta.xAxisID);
  5365. var yScale = me.getScaleForId(meta.yAxisID);
  5366. var scaleBase = xScale.getBasePixel();
  5367. var custom = rectangle.custom || {};
  5368. var dataset = me.getDataset();
  5369. var rectangleElementOptions = me.chart.options.elements.rectangle;
  5370. helpers.extend(rectangle, {
  5371. // Utility
  5372. _xScale: xScale,
  5373. _yScale: yScale,
  5374. _datasetIndex: me.index,
  5375. _index: index,
  5376. // Desired view properties
  5377. _model: {
  5378. x: reset ? scaleBase : me.calculateBarX(index, me.index),
  5379. y: me.calculateBarY(index, me.index),
  5380. // Tooltip
  5381. label: me.chart.data.labels[index],
  5382. datasetLabel: dataset.label,
  5383. // Appearance
  5384. base: reset ? scaleBase : me.calculateBarBase(me.index, index),
  5385. height: me.calculateBarHeight(index),
  5386. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor),
  5387. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
  5388. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
  5389. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth)
  5390. },
  5391. draw: function () {
  5392. var ctx = this._chart.ctx;
  5393. var vm = this._view;
  5394. var halfHeight = vm.height / 2,
  5395. topY = vm.y - halfHeight,
  5396. bottomY = vm.y + halfHeight,
  5397. right = vm.base - (vm.base - vm.x),
  5398. halfStroke = vm.borderWidth / 2;
  5399. // Canvas doesn't allow us to stroke inside the width so we can
  5400. // adjust the sizes to fit if we're setting a stroke on the line
  5401. if (vm.borderWidth) {
  5402. topY += halfStroke;
  5403. bottomY -= halfStroke;
  5404. right += halfStroke;
  5405. }
  5406. ctx.beginPath();
  5407. ctx.fillStyle = vm.backgroundColor;
  5408. ctx.strokeStyle = vm.borderColor;
  5409. ctx.lineWidth = vm.borderWidth;
  5410. // Corner points, from bottom-left to bottom-right clockwise
  5411. // | 1 2 |
  5412. // | 0 3 |
  5413. var corners = [
  5414. [vm.base, bottomY],
  5415. [vm.base, topY],
  5416. [right, topY],
  5417. [right, bottomY]
  5418. ];
  5419. // Find first (starting) corner with fallback to 'bottom'
  5420. var borders = ['bottom', 'left', 'top', 'right'];
  5421. var startCorner = borders.indexOf(vm.borderSkipped, 0);
  5422. if (startCorner === -1)
  5423. startCorner = 0;
  5424. function cornerAt(index) {
  5425. return corners[(startCorner + index) % 4];
  5426. }
  5427. // Draw rectangle from 'startCorner'
  5428. ctx.moveTo.apply(ctx, cornerAt(0));
  5429. for (var i = 1; i < 4; i++)
  5430. ctx.lineTo.apply(ctx, cornerAt(i));
  5431. ctx.fill();
  5432. if (vm.borderWidth) {
  5433. ctx.stroke();
  5434. }
  5435. },
  5436. inRange: function (mouseX, mouseY) {
  5437. var vm = this._view;
  5438. var inRange = false;
  5439. if (vm) {
  5440. if (vm.x < vm.base) {
  5441. inRange = (mouseY >= vm.y - vm.height / 2 && mouseY <= vm.y + vm.height / 2) && (mouseX >= vm.x && mouseX <= vm.base);
  5442. } else {
  5443. inRange = (mouseY >= vm.y - vm.height / 2 && mouseY <= vm.y + vm.height / 2) && (mouseX >= vm.base && mouseX <= vm.x);
  5444. }
  5445. }
  5446. return inRange;
  5447. }
  5448. });
  5449. rectangle.pivot();
  5450. },
  5451. calculateBarBase: function (datasetIndex, index) {
  5452. var me = this;
  5453. var meta = me.getMeta();
  5454. var xScale = me.getScaleForId(meta.xAxisID);
  5455. var base = 0;
  5456. if (xScale.options.stacked) {
  5457. var chart = me.chart;
  5458. var datasets = chart.data.datasets;
  5459. var value = Number(datasets[datasetIndex].data[index]);
  5460. for (var i = 0; i < datasetIndex; i++) {
  5461. var currentDs = datasets[i];
  5462. var currentDsMeta = chart.getDatasetMeta(i);
  5463. if (currentDsMeta.bar && currentDsMeta.xAxisID === xScale.id && chart.isDatasetVisible(i)) {
  5464. var currentVal = Number(currentDs.data[index]);
  5465. base += value < 0 ? Math.min(currentVal, 0) : Math.max(currentVal, 0);
  5466. }
  5467. }
  5468. return xScale.getPixelForValue(base);
  5469. }
  5470. return xScale.getBasePixel();
  5471. },
  5472. getRuler: function (index) {
  5473. var me = this;
  5474. var meta = me.getMeta();
  5475. var yScale = me.getScaleForId(meta.yAxisID);
  5476. var datasetCount = me.getBarCount();
  5477. var tickHeight;
  5478. if (yScale.options.type === 'category') {
  5479. tickHeight = yScale.getPixelForTick(index + 1) - yScale.getPixelForTick(index);
  5480. } else {
  5481. // Average width
  5482. tickHeight = yScale.width / yScale.ticks.length;
  5483. }
  5484. var categoryHeight = tickHeight * yScale.options.categoryPercentage;
  5485. var categorySpacing = (tickHeight - (tickHeight * yScale.options.categoryPercentage)) / 2;
  5486. var fullBarHeight = categoryHeight / datasetCount;
  5487. if (yScale.ticks.length !== me.chart.data.labels.length) {
  5488. var perc = yScale.ticks.length / me.chart.data.labels.length;
  5489. fullBarHeight = fullBarHeight * perc;
  5490. }
  5491. var barHeight = fullBarHeight * yScale.options.barPercentage;
  5492. var barSpacing = fullBarHeight - (fullBarHeight * yScale.options.barPercentage);
  5493. return {
  5494. datasetCount: datasetCount,
  5495. tickHeight: tickHeight,
  5496. categoryHeight: categoryHeight,
  5497. categorySpacing: categorySpacing,
  5498. fullBarHeight: fullBarHeight,
  5499. barHeight: barHeight,
  5500. barSpacing: barSpacing,
  5501. };
  5502. },
  5503. calculateBarHeight: function (index) {
  5504. var me = this;
  5505. var yScale = me.getScaleForId(me.getMeta().yAxisID);
  5506. if (yScale.options.barThickness) {
  5507. return yScale.options.barThickness;
  5508. }
  5509. var ruler = me.getRuler(index);
  5510. return yScale.options.stacked ? ruler.categoryHeight : ruler.barHeight;
  5511. },
  5512. calculateBarX: function (index, datasetIndex) {
  5513. var me = this;
  5514. var meta = me.getMeta();
  5515. var xScale = me.getScaleForId(meta.xAxisID);
  5516. var value = Number(me.getDataset().data[index]);
  5517. if (xScale.options.stacked) {
  5518. var sumPos = 0,
  5519. sumNeg = 0;
  5520. for (var i = 0; i < datasetIndex; i++) {
  5521. var ds = me.chart.data.datasets[i];
  5522. var dsMeta = me.chart.getDatasetMeta(i);
  5523. if (dsMeta.bar && dsMeta.xAxisID === xScale.id && me.chart.isDatasetVisible(i)) {
  5524. var stackedVal = Number(ds.data[index]);
  5525. if (stackedVal < 0) {
  5526. sumNeg += stackedVal || 0;
  5527. } else {
  5528. sumPos += stackedVal || 0;
  5529. }
  5530. }
  5531. }
  5532. if (value < 0) {
  5533. return xScale.getPixelForValue(sumNeg + value);
  5534. } else {
  5535. return xScale.getPixelForValue(sumPos + value);
  5536. }
  5537. }
  5538. return xScale.getPixelForValue(value);
  5539. },
  5540. calculateBarY: function (index, datasetIndex) {
  5541. var me = this;
  5542. var meta = me.getMeta();
  5543. var yScale = me.getScaleForId(meta.yAxisID);
  5544. var barIndex = me.getBarIndex(datasetIndex);
  5545. var ruler = me.getRuler(index);
  5546. var topTick = yScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
  5547. topTick -= me.chart.isCombo ? (ruler.tickHeight / 2) : 0;
  5548. if (yScale.options.stacked) {
  5549. return topTick + (ruler.categoryHeight / 2) + ruler.categorySpacing;
  5550. }
  5551. return topTick +
  5552. (ruler.barHeight / 2) +
  5553. ruler.categorySpacing +
  5554. (ruler.barHeight * barIndex) +
  5555. (ruler.barSpacing / 2) +
  5556. (ruler.barSpacing * barIndex);
  5557. }
  5558. });
  5559. };
  5560. },{}],16:[function(require,module,exports){
  5561. "use strict";
  5562. module.exports = function(Chart) {
  5563. var helpers = Chart.helpers;
  5564. Chart.defaults.bubble = {
  5565. hover: {
  5566. mode: "single"
  5567. },
  5568. scales: {
  5569. xAxes: [{
  5570. type: "linear", // bubble should probably use a linear scale by default
  5571. position: "bottom",
  5572. id: "x-axis-0" // need an ID so datasets can reference the scale
  5573. }],
  5574. yAxes: [{
  5575. type: "linear",
  5576. position: "left",
  5577. id: "y-axis-0"
  5578. }]
  5579. },
  5580. tooltips: {
  5581. callbacks: {
  5582. title: function() {
  5583. // Title doesn't make sense for scatter since we format the data as a point
  5584. return '';
  5585. },
  5586. label: function(tooltipItem, data) {
  5587. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  5588. var dataPoint = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  5589. return datasetLabel + ': (' + dataPoint.x + ', ' + dataPoint.y + ', ' + dataPoint.r + ')';
  5590. }
  5591. }
  5592. }
  5593. };
  5594. Chart.controllers.bubble = Chart.DatasetController.extend({
  5595. dataElementType: Chart.elements.Point,
  5596. update: function(reset) {
  5597. var me = this;
  5598. var meta = me.getMeta();
  5599. var points = meta.data;
  5600. // Update Points
  5601. helpers.each(points, function(point, index) {
  5602. me.updateElement(point, index, reset);
  5603. });
  5604. },
  5605. updateElement: function(point, index, reset) {
  5606. var me = this;
  5607. var meta = me.getMeta();
  5608. var xScale = me.getScaleForId(meta.xAxisID);
  5609. var yScale = me.getScaleForId(meta.yAxisID);
  5610. var custom = point.custom || {};
  5611. var dataset = me.getDataset();
  5612. var data = dataset.data[index];
  5613. var pointElementOptions = me.chart.options.elements.point;
  5614. var dsIndex = me.index;
  5615. helpers.extend(point, {
  5616. // Utility
  5617. _xScale: xScale,
  5618. _yScale: yScale,
  5619. _datasetIndex: dsIndex,
  5620. _index: index,
  5621. // Desired view properties
  5622. _model: {
  5623. x: reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex, me.chart.isCombo),
  5624. y: reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex),
  5625. // Appearance
  5626. radius: reset ? 0 : custom.radius ? custom.radius : me.getRadius(data),
  5627. // Tooltip
  5628. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.hitRadius, index, pointElementOptions.hitRadius)
  5629. }
  5630. });
  5631. // Trick to reset the styles of the point
  5632. Chart.DatasetController.prototype.removeHoverStyle.call(me, point, pointElementOptions);
  5633. var model = point._model;
  5634. model.skip = custom.skip ? custom.skip : (isNaN(model.x) || isNaN(model.y));
  5635. point.pivot();
  5636. },
  5637. getRadius: function(value) {
  5638. return value.r || this.chart.options.elements.point.radius;
  5639. },
  5640. setHoverStyle: function(point) {
  5641. var me = this;
  5642. Chart.DatasetController.prototype.setHoverStyle.call(me, point);
  5643. // Radius
  5644. var dataset = me.chart.data.datasets[point._datasetIndex];
  5645. var index = point._index;
  5646. var custom = point.custom || {};
  5647. var model = point._model;
  5648. model.radius = custom.hoverRadius ? custom.hoverRadius : (helpers.getValueAtIndexOrDefault(dataset.hoverRadius, index, me.chart.options.elements.point.hoverRadius)) + me.getRadius(dataset.data[index]);
  5649. },
  5650. removeHoverStyle: function(point) {
  5651. var me = this;
  5652. Chart.DatasetController.prototype.removeHoverStyle.call(me, point, me.chart.options.elements.point);
  5653. var dataVal = me.chart.data.datasets[point._datasetIndex].data[point._index];
  5654. var custom = point.custom || {};
  5655. var model = point._model;
  5656. model.radius = custom.radius ? custom.radius : me.getRadius(dataVal);
  5657. }
  5658. });
  5659. };
  5660. },{}],17:[function(require,module,exports){
  5661. "use strict";
  5662. module.exports = function(Chart) {
  5663. var helpers = Chart.helpers,
  5664. defaults = Chart.defaults;
  5665. defaults.doughnut = {
  5666. animation: {
  5667. //Boolean - Whether we animate the rotation of the Doughnut
  5668. animateRotate: true,
  5669. //Boolean - Whether we animate scaling the Doughnut from the centre
  5670. animateScale: false
  5671. },
  5672. aspectRatio: 1,
  5673. hover: {
  5674. mode: 'single'
  5675. },
  5676. legendCallback: function(chart) {
  5677. var text = [];
  5678. text.push('<ul class="' + chart.id + '-legend">');
  5679. var data = chart.data;
  5680. var datasets = data.datasets;
  5681. var labels = data.labels;
  5682. if (datasets.length) {
  5683. for (var i = 0; i < datasets[0].data.length; ++i) {
  5684. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  5685. if (labels[i]) {
  5686. text.push(labels[i]);
  5687. }
  5688. text.push('</li>');
  5689. }
  5690. }
  5691. text.push('</ul>');
  5692. return text.join("");
  5693. },
  5694. legend: {
  5695. labels: {
  5696. generateLabels: function(chart) {
  5697. var data = chart.data;
  5698. if (data.labels.length && data.datasets.length) {
  5699. return data.labels.map(function(label, i) {
  5700. var meta = chart.getDatasetMeta(0);
  5701. var ds = data.datasets[0];
  5702. var arc = meta.data[i];
  5703. var custom = arc && arc.custom || {};
  5704. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  5705. var arcOpts = chart.options.elements.arc;
  5706. var fill = custom.backgroundColor ? custom.backgroundColor : getValueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  5707. var stroke = custom.borderColor ? custom.borderColor : getValueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  5708. var bw = custom.borderWidth ? custom.borderWidth : getValueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  5709. return {
  5710. text: label,
  5711. fillStyle: fill,
  5712. strokeStyle: stroke,
  5713. lineWidth: bw,
  5714. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  5715. // Extra data used for toggling the correct item
  5716. index: i
  5717. };
  5718. });
  5719. } else {
  5720. return [];
  5721. }
  5722. }
  5723. },
  5724. onClick: function(e, legendItem) {
  5725. var index = legendItem.index;
  5726. var chart = this.chart;
  5727. var i, ilen, meta;
  5728. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  5729. meta = chart.getDatasetMeta(i);
  5730. meta.data[index].hidden = !meta.data[index].hidden;
  5731. }
  5732. chart.update();
  5733. }
  5734. },
  5735. //The percentage of the chart that we cut out of the middle.
  5736. cutoutPercentage: 50,
  5737. //The rotation of the chart, where the first data arc begins.
  5738. rotation: Math.PI * -0.5,
  5739. //The total circumference of the chart.
  5740. circumference: Math.PI * 2.0,
  5741. // Need to override these to give a nice default
  5742. tooltips: {
  5743. callbacks: {
  5744. title: function() {
  5745. return '';
  5746. },
  5747. label: function(tooltipItem, data) {
  5748. return data.labels[tooltipItem.index] + ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  5749. }
  5750. }
  5751. }
  5752. };
  5753. defaults.pie = helpers.clone(defaults.doughnut);
  5754. helpers.extend(defaults.pie, {
  5755. cutoutPercentage: 0
  5756. });
  5757. Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
  5758. dataElementType: Chart.elements.Arc,
  5759. linkScales: helpers.noop,
  5760. // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
  5761. getRingIndex: function(datasetIndex) {
  5762. var ringIndex = 0;
  5763. for (var j = 0; j < datasetIndex; ++j) {
  5764. if (this.chart.isDatasetVisible(j)) {
  5765. ++ringIndex;
  5766. }
  5767. }
  5768. return ringIndex;
  5769. },
  5770. update: function(reset) {
  5771. var me = this;
  5772. var chart = me.chart,
  5773. chartArea = chart.chartArea,
  5774. opts = chart.options,
  5775. arcOpts = opts.elements.arc,
  5776. availableWidth = chartArea.right - chartArea.left - arcOpts.borderWidth,
  5777. availableHeight = chartArea.bottom - chartArea.top - arcOpts.borderWidth,
  5778. minSize = Math.min(availableWidth, availableHeight),
  5779. offset = {
  5780. x: 0,
  5781. y: 0
  5782. },
  5783. meta = me.getMeta(),
  5784. cutoutPercentage = opts.cutoutPercentage,
  5785. circumference = opts.circumference;
  5786. // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
  5787. if (circumference < Math.PI * 2.0) {
  5788. var startAngle = opts.rotation % (Math.PI * 2.0);
  5789. startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
  5790. var endAngle = startAngle + circumference;
  5791. var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
  5792. var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
  5793. var contains0 = (startAngle <= 0 && 0 <= endAngle) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
  5794. var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
  5795. var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
  5796. var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
  5797. var cutout = cutoutPercentage / 100.0;
  5798. var min = {x: contains180 ? -1 : Math.min(start.x * (start.x < 0 ? 1 : cutout), end.x * (end.x < 0 ? 1 : cutout)), y: contains270 ? -1 : Math.min(start.y * (start.y < 0 ? 1 : cutout), end.y * (end.y < 0 ? 1 : cutout))};
  5799. var max = {x: contains0 ? 1 : Math.max(start.x * (start.x > 0 ? 1 : cutout), end.x * (end.x > 0 ? 1 : cutout)), y: contains90 ? 1 : Math.max(start.y * (start.y > 0 ? 1 : cutout), end.y * (end.y > 0 ? 1 : cutout))};
  5800. var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
  5801. minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
  5802. offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
  5803. }
  5804. chart.borderWidth = me.getMaxBorderWidth(meta.data);
  5805. chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
  5806. chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 1, 0);
  5807. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  5808. chart.offsetX = offset.x * chart.outerRadius;
  5809. chart.offsetY = offset.y * chart.outerRadius;
  5810. meta.total = me.calculateTotal();
  5811. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
  5812. me.innerRadius = me.outerRadius - chart.radiusLength;
  5813. helpers.each(meta.data, function(arc, index) {
  5814. me.updateElement(arc, index, reset);
  5815. });
  5816. },
  5817. updateElement: function(arc, index, reset) {
  5818. var me = this;
  5819. var chart = me.chart,
  5820. chartArea = chart.chartArea,
  5821. opts = chart.options,
  5822. animationOpts = opts.animation,
  5823. centerX = (chartArea.left + chartArea.right) / 2,
  5824. centerY = (chartArea.top + chartArea.bottom) / 2,
  5825. startAngle = opts.rotation, // non reset case handled later
  5826. endAngle = opts.rotation, // non reset case handled later
  5827. dataset = me.getDataset(),
  5828. circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI)),
  5829. innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius,
  5830. outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius,
  5831. valueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  5832. helpers.extend(arc, {
  5833. // Utility
  5834. _datasetIndex: me.index,
  5835. _index: index,
  5836. // Desired view properties
  5837. _model: {
  5838. x: centerX + chart.offsetX,
  5839. y: centerY + chart.offsetY,
  5840. startAngle: startAngle,
  5841. endAngle: endAngle,
  5842. circumference: circumference,
  5843. outerRadius: outerRadius,
  5844. innerRadius: innerRadius,
  5845. label: valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index])
  5846. }
  5847. });
  5848. var model = arc._model;
  5849. // Resets the visual styles
  5850. this.removeHoverStyle(arc);
  5851. // Set correct angles if not resetting
  5852. if (!reset || !animationOpts.animateRotate) {
  5853. if (index === 0) {
  5854. model.startAngle = opts.rotation;
  5855. } else {
  5856. model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
  5857. }
  5858. model.endAngle = model.startAngle + model.circumference;
  5859. }
  5860. arc.pivot();
  5861. },
  5862. removeHoverStyle: function(arc) {
  5863. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  5864. },
  5865. calculateTotal: function() {
  5866. var dataset = this.getDataset();
  5867. var meta = this.getMeta();
  5868. var total = 0;
  5869. var value;
  5870. helpers.each(meta.data, function(element, index) {
  5871. value = dataset.data[index];
  5872. if (!isNaN(value) && !element.hidden) {
  5873. total += Math.abs(value);
  5874. }
  5875. });
  5876. /*if (total === 0) {
  5877. total = NaN;
  5878. }*/
  5879. return total;
  5880. },
  5881. calculateCircumference: function(value) {
  5882. var total = this.getMeta().total;
  5883. if (total > 0 && !isNaN(value)) {
  5884. return (Math.PI * 2.0) * (value / total);
  5885. } else {
  5886. return 0;
  5887. }
  5888. },
  5889. //gets the max border or hover width to properly scale pie charts
  5890. getMaxBorderWidth: function (elements) {
  5891. var max = 0,
  5892. index = this.index,
  5893. length = elements.length,
  5894. borderWidth,
  5895. hoverWidth;
  5896. for (var i = 0; i < length; i++) {
  5897. borderWidth = elements[i]._model ? elements[i]._model.borderWidth : 0;
  5898. hoverWidth = elements[i]._chart ? elements[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
  5899. max = borderWidth > max ? borderWidth : max;
  5900. max = hoverWidth > max ? hoverWidth : max;
  5901. }
  5902. return max;
  5903. }
  5904. });
  5905. };
  5906. },{}],18:[function(require,module,exports){
  5907. "use strict";
  5908. module.exports = function(Chart) {
  5909. var helpers = Chart.helpers;
  5910. Chart.defaults.line = {
  5911. showLines: true,
  5912. spanGaps: false,
  5913. hover: {
  5914. mode: "label"
  5915. },
  5916. scales: {
  5917. xAxes: [{
  5918. type: "category",
  5919. id: 'x-axis-0'
  5920. }],
  5921. yAxes: [{
  5922. type: "linear",
  5923. id: 'y-axis-0'
  5924. }]
  5925. }
  5926. };
  5927. function lineEnabled(dataset, options) {
  5928. return helpers.getValueOrDefault(dataset.showLine, options.showLines);
  5929. }
  5930. Chart.controllers.line = Chart.DatasetController.extend({
  5931. datasetElementType: Chart.elements.Line,
  5932. dataElementType: Chart.elements.Point,
  5933. addElementAndReset: function(index) {
  5934. var me = this;
  5935. var options = me.chart.options;
  5936. var meta = me.getMeta();
  5937. Chart.DatasetController.prototype.addElementAndReset.call(me, index);
  5938. // Make sure bezier control points are updated
  5939. if (lineEnabled(me.getDataset(), options) && meta.dataset._model.tension !== 0) {
  5940. me.updateBezierControlPoints();
  5941. }
  5942. },
  5943. update: function(reset) {
  5944. var me = this;
  5945. var meta = me.getMeta();
  5946. var line = meta.dataset;
  5947. var points = meta.data || [];
  5948. var options = me.chart.options;
  5949. var lineElementOptions = options.elements.line;
  5950. var scale = me.getScaleForId(meta.yAxisID);
  5951. var i, ilen, custom;
  5952. var dataset = me.getDataset();
  5953. var showLine = lineEnabled(dataset, options);
  5954. // Update Line
  5955. if (showLine) {
  5956. custom = line.custom || {};
  5957. // Compatibility: If the properties are defined with only the old name, use those values
  5958. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  5959. dataset.lineTension = dataset.tension;
  5960. }
  5961. // Utility
  5962. line._scale = scale;
  5963. line._datasetIndex = me.index;
  5964. // Data
  5965. line._children = points;
  5966. // Model
  5967. line._model = {
  5968. // Appearance
  5969. // The default behavior of lines is to break at null values, according
  5970. // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
  5971. // This option gives linse the ability to span gaps
  5972. spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
  5973. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.lineTension, lineElementOptions.tension),
  5974. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  5975. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  5976. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  5977. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  5978. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  5979. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  5980. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  5981. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  5982. steppedLine: custom.steppedLine ? custom.steppedLine : helpers.getValueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
  5983. // Scale
  5984. scaleTop: scale.top,
  5985. scaleBottom: scale.bottom,
  5986. scaleZero: scale.getBasePixel()
  5987. };
  5988. line.pivot();
  5989. }
  5990. // Update Points
  5991. for (i=0, ilen=points.length; i<ilen; ++i) {
  5992. me.updateElement(points[i], i, reset);
  5993. }
  5994. if (showLine && line._model.tension !== 0) {
  5995. me.updateBezierControlPoints();
  5996. }
  5997. // Now pivot the point for animation
  5998. for (i=0, ilen=points.length; i<ilen; ++i) {
  5999. points[i].pivot();
  6000. }
  6001. },
  6002. getPointBackgroundColor: function(point, index) {
  6003. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  6004. var dataset = this.getDataset();
  6005. var custom = point.custom || {};
  6006. if (custom.backgroundColor) {
  6007. backgroundColor = custom.backgroundColor;
  6008. } else if (dataset.pointBackgroundColor) {
  6009. backgroundColor = helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  6010. } else if (dataset.backgroundColor) {
  6011. backgroundColor = dataset.backgroundColor;
  6012. }
  6013. return backgroundColor;
  6014. },
  6015. getPointBorderColor: function(point, index) {
  6016. var borderColor = this.chart.options.elements.point.borderColor;
  6017. var dataset = this.getDataset();
  6018. var custom = point.custom || {};
  6019. if (custom.borderColor) {
  6020. borderColor = custom.borderColor;
  6021. } else if (dataset.pointBorderColor) {
  6022. borderColor = helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
  6023. } else if (dataset.borderColor) {
  6024. borderColor = dataset.borderColor;
  6025. }
  6026. return borderColor;
  6027. },
  6028. getPointBorderWidth: function(point, index) {
  6029. var borderWidth = this.chart.options.elements.point.borderWidth;
  6030. var dataset = this.getDataset();
  6031. var custom = point.custom || {};
  6032. if (custom.borderWidth) {
  6033. borderWidth = custom.borderWidth;
  6034. } else if (dataset.pointBorderWidth) {
  6035. borderWidth = helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  6036. } else if (dataset.borderWidth) {
  6037. borderWidth = dataset.borderWidth;
  6038. }
  6039. return borderWidth;
  6040. },
  6041. updateElement: function(point, index, reset) {
  6042. var me = this;
  6043. var meta = me.getMeta();
  6044. var custom = point.custom || {};
  6045. var dataset = me.getDataset();
  6046. var datasetIndex = me.index;
  6047. var value = dataset.data[index];
  6048. var yScale = me.getScaleForId(meta.yAxisID);
  6049. var xScale = me.getScaleForId(meta.xAxisID);
  6050. var pointOptions = me.chart.options.elements.point;
  6051. var x, y;
  6052. // Compatibility: If the properties are defined with only the old name, use those values
  6053. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  6054. dataset.pointRadius = dataset.radius;
  6055. }
  6056. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  6057. dataset.pointHitRadius = dataset.hitRadius;
  6058. }
  6059. x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex, me.chart.isCombo);
  6060. y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
  6061. // Utility
  6062. point._xScale = xScale;
  6063. point._yScale = yScale;
  6064. point._datasetIndex = datasetIndex;
  6065. point._index = index;
  6066. // Desired view properties
  6067. point._model = {
  6068. x: x,
  6069. y: y,
  6070. skip: custom.skip || isNaN(x) || isNaN(y),
  6071. // Appearance
  6072. radius: custom.radius || helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
  6073. pointStyle: custom.pointStyle || helpers.getValueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
  6074. backgroundColor: me.getPointBackgroundColor(point, index),
  6075. borderColor: me.getPointBorderColor(point, index),
  6076. borderWidth: me.getPointBorderWidth(point, index),
  6077. tension: meta.dataset._model ? meta.dataset._model.tension : 0,
  6078. steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
  6079. // Tooltip
  6080. hitRadius: custom.hitRadius || helpers.getValueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
  6081. };
  6082. },
  6083. calculatePointY: function(value, index, datasetIndex) {
  6084. var me = this;
  6085. var chart = me.chart;
  6086. var meta = me.getMeta();
  6087. var yScale = me.getScaleForId(meta.yAxisID);
  6088. var sumPos = 0;
  6089. var sumNeg = 0;
  6090. var i, ds, dsMeta;
  6091. if (yScale.options.stacked) {
  6092. for (i = 0; i < datasetIndex; i++) {
  6093. ds = chart.data.datasets[i];
  6094. dsMeta = chart.getDatasetMeta(i);
  6095. if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  6096. var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
  6097. if (stackedRightValue < 0) {
  6098. sumNeg += stackedRightValue || 0;
  6099. } else {
  6100. sumPos += stackedRightValue || 0;
  6101. }
  6102. }
  6103. }
  6104. var rightValue = Number(yScale.getRightValue(value));
  6105. if (rightValue < 0) {
  6106. return yScale.getPixelForValue(sumNeg + rightValue);
  6107. } else {
  6108. return yScale.getPixelForValue(sumPos + rightValue);
  6109. }
  6110. }
  6111. return yScale.getPixelForValue(value);
  6112. },
  6113. updateBezierControlPoints: function() {
  6114. var me = this;
  6115. var meta = me.getMeta();
  6116. var area = me.chart.chartArea;
  6117. // only consider points that are drawn in case the spanGaps option is ued
  6118. var points = (meta.data || []).filter(function(pt) { return !pt._model.skip; });
  6119. var i, ilen, point, model, controlPoints;
  6120. var needToCap = me.chart.options.elements.line.capBezierPoints;
  6121. function capIfNecessary(pt, min, max) {
  6122. return needToCap ? Math.max(Math.min(pt, max), min) : pt;
  6123. }
  6124. for (i=0, ilen=points.length; i<ilen; ++i) {
  6125. point = points[i];
  6126. model = point._model;
  6127. controlPoints = helpers.splineCurve(
  6128. helpers.previousItem(points, i)._model,
  6129. model,
  6130. helpers.nextItem(points, i)._model,
  6131. meta.dataset._model.tension
  6132. );
  6133. model.controlPointPreviousX = capIfNecessary(controlPoints.previous.x, area.left, area.right);
  6134. model.controlPointPreviousY = capIfNecessary(controlPoints.previous.y, area.top, area.bottom);
  6135. model.controlPointNextX = capIfNecessary(controlPoints.next.x, area.left, area.right);
  6136. model.controlPointNextY = capIfNecessary(controlPoints.next.y, area.top, area.bottom);
  6137. }
  6138. },
  6139. draw: function(ease) {
  6140. var me = this;
  6141. var meta = me.getMeta();
  6142. var points = meta.data || [];
  6143. var easingDecimal = ease || 1;
  6144. var i, ilen;
  6145. // Transition Point Locations
  6146. for (i=0, ilen=points.length; i<ilen; ++i) {
  6147. points[i].transition(easingDecimal);
  6148. }
  6149. // Transition and Draw the line
  6150. if (lineEnabled(me.getDataset(), me.chart.options)) {
  6151. meta.dataset.transition(easingDecimal).draw();
  6152. }
  6153. // Draw the points
  6154. for (i=0, ilen=points.length; i<ilen; ++i) {
  6155. points[i].draw();
  6156. }
  6157. },
  6158. setHoverStyle: function(point) {
  6159. // Point
  6160. var dataset = this.chart.data.datasets[point._datasetIndex];
  6161. var index = point._index;
  6162. var custom = point.custom || {};
  6163. var model = point._model;
  6164. model.radius = custom.hoverRadius || helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  6165. model.backgroundColor = custom.hoverBackgroundColor || helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  6166. model.borderColor = custom.hoverBorderColor || helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  6167. model.borderWidth = custom.hoverBorderWidth || helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  6168. },
  6169. removeHoverStyle: function(point) {
  6170. var me = this;
  6171. var dataset = me.chart.data.datasets[point._datasetIndex];
  6172. var index = point._index;
  6173. var custom = point.custom || {};
  6174. var model = point._model;
  6175. // Compatibility: If the properties are defined with only the old name, use those values
  6176. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  6177. dataset.pointRadius = dataset.radius;
  6178. }
  6179. model.radius = custom.radius || helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, me.chart.options.elements.point.radius);
  6180. model.backgroundColor = me.getPointBackgroundColor(point, index);
  6181. model.borderColor = me.getPointBorderColor(point, index);
  6182. model.borderWidth = me.getPointBorderWidth(point, index);
  6183. }
  6184. });
  6185. };
  6186. },{}],19:[function(require,module,exports){
  6187. "use strict";
  6188. module.exports = function(Chart) {
  6189. var helpers = Chart.helpers;
  6190. Chart.defaults.polarArea = {
  6191. scale: {
  6192. type: "radialLinear",
  6193. lineArc: true, // so that lines are circular
  6194. ticks: {
  6195. beginAtZero: true
  6196. }
  6197. },
  6198. //Boolean - Whether to animate the rotation of the chart
  6199. animation: {
  6200. animateRotate: true,
  6201. animateScale: true
  6202. },
  6203. startAngle: -0.5 * Math.PI,
  6204. aspectRatio: 1,
  6205. legendCallback: function(chart) {
  6206. var text = [];
  6207. text.push('<ul class="' + chart.id + '-legend">');
  6208. var data = chart.data;
  6209. var datasets = data.datasets;
  6210. var labels = data.labels;
  6211. if (datasets.length) {
  6212. for (var i = 0; i < datasets[0].data.length; ++i) {
  6213. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '">');
  6214. if (labels[i]) {
  6215. text.push(labels[i]);
  6216. }
  6217. text.push('</span></li>');
  6218. }
  6219. }
  6220. text.push('</ul>');
  6221. return text.join("");
  6222. },
  6223. legend: {
  6224. labels: {
  6225. generateLabels: function(chart) {
  6226. var data = chart.data;
  6227. if (data.labels.length && data.datasets.length) {
  6228. return data.labels.map(function(label, i) {
  6229. var meta = chart.getDatasetMeta(0);
  6230. var ds = data.datasets[0];
  6231. var arc = meta.data[i];
  6232. var custom = arc.custom || {};
  6233. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  6234. var arcOpts = chart.options.elements.arc;
  6235. var fill = custom.backgroundColor ? custom.backgroundColor : getValueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  6236. var stroke = custom.borderColor ? custom.borderColor : getValueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  6237. var bw = custom.borderWidth ? custom.borderWidth : getValueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  6238. return {
  6239. text: label,
  6240. fillStyle: fill,
  6241. strokeStyle: stroke,
  6242. lineWidth: bw,
  6243. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  6244. // Extra data used for toggling the correct item
  6245. index: i
  6246. };
  6247. });
  6248. } else {
  6249. return [];
  6250. }
  6251. }
  6252. },
  6253. onClick: function(e, legendItem) {
  6254. var index = legendItem.index;
  6255. var chart = this.chart;
  6256. var i, ilen, meta;
  6257. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  6258. meta = chart.getDatasetMeta(i);
  6259. meta.data[index].hidden = !meta.data[index].hidden;
  6260. }
  6261. chart.update();
  6262. }
  6263. },
  6264. // Need to override these to give a nice default
  6265. tooltips: {
  6266. callbacks: {
  6267. title: function() {
  6268. return '';
  6269. },
  6270. label: function(tooltipItem, data) {
  6271. return data.labels[tooltipItem.index] + ': ' + tooltipItem.yLabel;
  6272. }
  6273. }
  6274. }
  6275. };
  6276. Chart.controllers.polarArea = Chart.DatasetController.extend({
  6277. dataElementType: Chart.elements.Arc,
  6278. linkScales: helpers.noop,
  6279. update: function(reset) {
  6280. var me = this;
  6281. var chart = me.chart;
  6282. var chartArea = chart.chartArea;
  6283. var meta = me.getMeta();
  6284. var opts = chart.options;
  6285. var arcOpts = opts.elements.arc;
  6286. var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
  6287. chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
  6288. chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
  6289. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  6290. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
  6291. me.innerRadius = me.outerRadius - chart.radiusLength;
  6292. meta.count = me.countVisibleElements();
  6293. helpers.each(meta.data, function(arc, index) {
  6294. me.updateElement(arc, index, reset);
  6295. });
  6296. },
  6297. updateElement: function(arc, index, reset) {
  6298. var me = this;
  6299. var chart = me.chart;
  6300. var dataset = me.getDataset();
  6301. var opts = chart.options;
  6302. var animationOpts = opts.animation;
  6303. var scale = chart.scale;
  6304. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  6305. var labels = chart.data.labels;
  6306. var circumference = me.calculateCircumference(dataset.data[index]);
  6307. var centerX = scale.xCenter;
  6308. var centerY = scale.yCenter;
  6309. // If there is NaN data before us, we need to calculate the starting angle correctly.
  6310. // We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
  6311. var visibleCount = 0;
  6312. var meta = me.getMeta();
  6313. for (var i = 0; i < index; ++i) {
  6314. if (!isNaN(dataset.data[i]) && !meta.data[i].hidden) {
  6315. ++visibleCount;
  6316. }
  6317. }
  6318. //var negHalfPI = -0.5 * Math.PI;
  6319. var datasetStartAngle = opts.startAngle;
  6320. var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  6321. var startAngle = datasetStartAngle + (circumference * visibleCount);
  6322. var endAngle = startAngle + (arc.hidden ? 0 : circumference);
  6323. var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  6324. helpers.extend(arc, {
  6325. // Utility
  6326. _datasetIndex: me.index,
  6327. _index: index,
  6328. _scale: scale,
  6329. // Desired view properties
  6330. _model: {
  6331. x: centerX,
  6332. y: centerY,
  6333. innerRadius: 0,
  6334. outerRadius: reset ? resetRadius : distance,
  6335. startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
  6336. endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
  6337. label: getValueAtIndexOrDefault(labels, index, labels[index])
  6338. }
  6339. });
  6340. // Apply border and fill style
  6341. me.removeHoverStyle(arc);
  6342. arc.pivot();
  6343. },
  6344. removeHoverStyle: function(arc) {
  6345. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  6346. },
  6347. countVisibleElements: function() {
  6348. var dataset = this.getDataset();
  6349. var meta = this.getMeta();
  6350. var count = 0;
  6351. helpers.each(meta.data, function(element, index) {
  6352. if (!isNaN(dataset.data[index]) && !element.hidden) {
  6353. count++;
  6354. }
  6355. });
  6356. return count;
  6357. },
  6358. calculateCircumference: function(value) {
  6359. var count = this.getMeta().count;
  6360. if (count > 0 && !isNaN(value)) {
  6361. return (2 * Math.PI) / count;
  6362. } else {
  6363. return 0;
  6364. }
  6365. }
  6366. });
  6367. };
  6368. },{}],20:[function(require,module,exports){
  6369. "use strict";
  6370. module.exports = function(Chart) {
  6371. var helpers = Chart.helpers;
  6372. Chart.defaults.radar = {
  6373. scale: {
  6374. type: "radialLinear"
  6375. },
  6376. elements: {
  6377. line: {
  6378. tension: 0 // no bezier in radar
  6379. }
  6380. }
  6381. };
  6382. Chart.controllers.radar = Chart.DatasetController.extend({
  6383. datasetElementType: Chart.elements.Line,
  6384. dataElementType: Chart.elements.Point,
  6385. linkScales: helpers.noop,
  6386. addElementAndReset: function(index) {
  6387. Chart.DatasetController.prototype.addElementAndReset.call(this, index);
  6388. // Make sure bezier control points are updated
  6389. this.updateBezierControlPoints();
  6390. },
  6391. update: function(reset) {
  6392. var me = this;
  6393. var meta = me.getMeta();
  6394. var line = meta.dataset;
  6395. var points = meta.data;
  6396. var custom = line.custom || {};
  6397. var dataset = me.getDataset();
  6398. var lineElementOptions = me.chart.options.elements.line;
  6399. var scale = me.chart.scale;
  6400. // Compatibility: If the properties are defined with only the old name, use those values
  6401. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  6402. dataset.lineTension = dataset.tension;
  6403. }
  6404. helpers.extend(meta.dataset, {
  6405. // Utility
  6406. _datasetIndex: me.index,
  6407. // Data
  6408. _children: points,
  6409. _loop: true,
  6410. // Model
  6411. _model: {
  6412. // Appearance
  6413. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.lineTension, lineElementOptions.tension),
  6414. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  6415. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  6416. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  6417. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  6418. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  6419. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  6420. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  6421. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  6422. // Scale
  6423. scaleTop: scale.top,
  6424. scaleBottom: scale.bottom,
  6425. scaleZero: scale.getBasePosition()
  6426. }
  6427. });
  6428. meta.dataset.pivot();
  6429. // Update Points
  6430. helpers.each(points, function(point, index) {
  6431. me.updateElement(point, index, reset);
  6432. }, me);
  6433. // Update bezier control points
  6434. me.updateBezierControlPoints();
  6435. },
  6436. updateElement: function(point, index, reset) {
  6437. var me = this;
  6438. var custom = point.custom || {};
  6439. var dataset = me.getDataset();
  6440. var scale = me.chart.scale;
  6441. var pointElementOptions = me.chart.options.elements.point;
  6442. var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
  6443. helpers.extend(point, {
  6444. // Utility
  6445. _datasetIndex: me.index,
  6446. _index: index,
  6447. _scale: scale,
  6448. // Desired view properties
  6449. _model: {
  6450. x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  6451. y: reset ? scale.yCenter : pointPosition.y,
  6452. // Appearance
  6453. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.tension, me.chart.options.elements.line.tension),
  6454. radius: custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
  6455. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
  6456. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
  6457. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
  6458. pointStyle: custom.pointStyle ? custom.pointStyle : helpers.getValueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
  6459. // Tooltip
  6460. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.hitRadius, index, pointElementOptions.hitRadius)
  6461. }
  6462. });
  6463. point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  6464. },
  6465. updateBezierControlPoints: function() {
  6466. var chartArea = this.chart.chartArea;
  6467. var meta = this.getMeta();
  6468. helpers.each(meta.data, function(point, index) {
  6469. var model = point._model;
  6470. var controlPoints = helpers.splineCurve(
  6471. helpers.previousItem(meta.data, index, true)._model,
  6472. model,
  6473. helpers.nextItem(meta.data, index, true)._model,
  6474. model.tension
  6475. );
  6476. // Prevent the bezier going outside of the bounds of the graph
  6477. model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, chartArea.right), chartArea.left);
  6478. model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, chartArea.bottom), chartArea.top);
  6479. model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, chartArea.right), chartArea.left);
  6480. model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, chartArea.bottom), chartArea.top);
  6481. // Now pivot the point for animation
  6482. point.pivot();
  6483. });
  6484. },
  6485. draw: function(ease) {
  6486. var meta = this.getMeta();
  6487. var easingDecimal = ease || 1;
  6488. // Transition Point Locations
  6489. helpers.each(meta.data, function(point) {
  6490. point.transition(easingDecimal);
  6491. });
  6492. // Transition and Draw the line
  6493. meta.dataset.transition(easingDecimal).draw();
  6494. // Draw the points
  6495. helpers.each(meta.data, function(point) {
  6496. point.draw();
  6497. });
  6498. },
  6499. setHoverStyle: function(point) {
  6500. // Point
  6501. var dataset = this.chart.data.datasets[point._datasetIndex];
  6502. var custom = point.custom || {};
  6503. var index = point._index;
  6504. var model = point._model;
  6505. model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  6506. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  6507. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  6508. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  6509. },
  6510. removeHoverStyle: function(point) {
  6511. var dataset = this.chart.data.datasets[point._datasetIndex];
  6512. var custom = point.custom || {};
  6513. var index = point._index;
  6514. var model = point._model;
  6515. var pointElementOptions = this.chart.options.elements.point;
  6516. model.radius = custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.radius, index, pointElementOptions.radius);
  6517. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor);
  6518. model.borderColor = custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor);
  6519. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth);
  6520. }
  6521. });
  6522. };
  6523. },{}],21:[function(require,module,exports){
  6524. /*global window: false */
  6525. "use strict";
  6526. module.exports = function(Chart) {
  6527. var helpers = Chart.helpers;
  6528. Chart.defaults.global.animation = {
  6529. duration: 1000,
  6530. easing: "easeOutQuart",
  6531. onProgress: helpers.noop,
  6532. onComplete: helpers.noop
  6533. };
  6534. Chart.Animation = Chart.Element.extend({
  6535. currentStep: null, // the current animation step
  6536. numSteps: 60, // default number of steps
  6537. easing: "", // the easing to use for this animation
  6538. render: null, // render function used by the animation service
  6539. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  6540. onAnimationComplete: null // user specified callback to fire when the animation finishes
  6541. });
  6542. Chart.animationService = {
  6543. frameDuration: 17,
  6544. animations: [],
  6545. dropFrames: 0,
  6546. request: null,
  6547. addAnimation: function(chartInstance, animationObject, duration, lazy) {
  6548. var me = this;
  6549. if (!lazy) {
  6550. chartInstance.animating = true;
  6551. }
  6552. for (var index = 0; index < me.animations.length; ++index) {
  6553. if (me.animations[index].chartInstance === chartInstance) {
  6554. // replacing an in progress animation
  6555. me.animations[index].animationObject = animationObject;
  6556. return;
  6557. }
  6558. }
  6559. me.animations.push({
  6560. chartInstance: chartInstance,
  6561. animationObject: animationObject
  6562. });
  6563. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  6564. if (me.animations.length === 1) {
  6565. me.requestAnimationFrame();
  6566. }
  6567. },
  6568. // Cancel the animation for a given chart instance
  6569. cancelAnimation: function(chartInstance) {
  6570. var index = helpers.findIndex(this.animations, function(animationWrapper) {
  6571. return animationWrapper.chartInstance === chartInstance;
  6572. });
  6573. if (index !== -1) {
  6574. this.animations.splice(index, 1);
  6575. chartInstance.animating = false;
  6576. }
  6577. },
  6578. requestAnimationFrame: function() {
  6579. var me = this;
  6580. if (me.request === null) {
  6581. // Skip animation frame requests until the active one is executed.
  6582. // This can happen when processing mouse events, e.g. 'mousemove'
  6583. // and 'mouseout' events will trigger multiple renders.
  6584. me.request = helpers.requestAnimFrame.call(window, function() {
  6585. me.request = null;
  6586. me.startDigest();
  6587. });
  6588. }
  6589. },
  6590. startDigest: function() {
  6591. var me = this;
  6592. var startTime = Date.now();
  6593. var framesToDrop = 0;
  6594. if (me.dropFrames > 1) {
  6595. framesToDrop = Math.floor(me.dropFrames);
  6596. me.dropFrames = me.dropFrames % 1;
  6597. }
  6598. var i = 0;
  6599. while (i < me.animations.length) {
  6600. if (me.animations[i].animationObject.currentStep === null) {
  6601. me.animations[i].animationObject.currentStep = 0;
  6602. }
  6603. me.animations[i].animationObject.currentStep += 1 + framesToDrop;
  6604. if (me.animations[i].animationObject.currentStep > me.animations[i].animationObject.numSteps) {
  6605. me.animations[i].animationObject.currentStep = me.animations[i].animationObject.numSteps;
  6606. }
  6607. me.animations[i].animationObject.render(me.animations[i].chartInstance, me.animations[i].animationObject);
  6608. if (me.animations[i].animationObject.onAnimationProgress && me.animations[i].animationObject.onAnimationProgress.call) {
  6609. me.animations[i].animationObject.onAnimationProgress.call(me.animations[i].chartInstance, me.animations[i]);
  6610. }
  6611. if (me.animations[i].animationObject.currentStep === me.animations[i].animationObject.numSteps) {
  6612. if (me.animations[i].animationObject.onAnimationComplete && me.animations[i].animationObject.onAnimationComplete.call) {
  6613. me.animations[i].animationObject.onAnimationComplete.call(me.animations[i].chartInstance, me.animations[i]);
  6614. }
  6615. // executed the last frame. Remove the animation.
  6616. me.animations[i].chartInstance.animating = false;
  6617. me.animations.splice(i, 1);
  6618. } else {
  6619. ++i;
  6620. }
  6621. }
  6622. var endTime = Date.now();
  6623. var dropFrames = (endTime - startTime) / me.frameDuration;
  6624. me.dropFrames += dropFrames;
  6625. // Do we have more stuff to animate?
  6626. if (me.animations.length > 0) {
  6627. me.requestAnimationFrame();
  6628. }
  6629. }
  6630. };
  6631. };
  6632. },{}],22:[function(require,module,exports){
  6633. "use strict";
  6634. module.exports = function(Chart) {
  6635. // Global Chart canvas helpers object for drawing items to canvas
  6636. var helpers = Chart.canvasHelpers = {};
  6637. helpers.drawPoint = function(ctx, pointStyle, radius, x, y) {
  6638. var type, edgeLength, xOffset, yOffset, height, size;
  6639. if (typeof pointStyle === 'object') {
  6640. type = pointStyle.toString();
  6641. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  6642. ctx.drawImage(pointStyle, x - pointStyle.width / 2, y - pointStyle.height / 2);
  6643. return;
  6644. }
  6645. }
  6646. if (isNaN(radius) || radius <= 0) {
  6647. return;
  6648. }
  6649. switch (pointStyle) {
  6650. // Default includes circle
  6651. default:
  6652. ctx.beginPath();
  6653. ctx.arc(x, y, radius, 0, Math.PI * 2);
  6654. ctx.closePath();
  6655. ctx.fill();
  6656. break;
  6657. case 'triangle':
  6658. ctx.beginPath();
  6659. edgeLength = 3 * radius / Math.sqrt(3);
  6660. height = edgeLength * Math.sqrt(3) / 2;
  6661. ctx.moveTo(x - edgeLength / 2, y + height / 3);
  6662. ctx.lineTo(x + edgeLength / 2, y + height / 3);
  6663. ctx.lineTo(x, y - 2 * height / 3);
  6664. ctx.closePath();
  6665. ctx.fill();
  6666. break;
  6667. case 'rect':
  6668. size = 1 / Math.SQRT2 * radius;
  6669. ctx.beginPath();
  6670. ctx.fillRect(x - size, y - size, 2 * size, 2 * size);
  6671. ctx.strokeRect(x - size, y - size, 2 * size, 2 * size);
  6672. break;
  6673. case 'rectRot':
  6674. size = 1 / Math.SQRT2 * radius;
  6675. ctx.beginPath();
  6676. ctx.moveTo(x - size, y);
  6677. ctx.lineTo(x, y + size);
  6678. ctx.lineTo(x + size, y);
  6679. ctx.lineTo(x, y - size);
  6680. ctx.closePath();
  6681. ctx.fill();
  6682. break;
  6683. case 'cross':
  6684. ctx.beginPath();
  6685. ctx.moveTo(x, y + radius);
  6686. ctx.lineTo(x, y - radius);
  6687. ctx.moveTo(x - radius, y);
  6688. ctx.lineTo(x + radius, y);
  6689. ctx.closePath();
  6690. break;
  6691. case 'crossRot':
  6692. ctx.beginPath();
  6693. xOffset = Math.cos(Math.PI / 4) * radius;
  6694. yOffset = Math.sin(Math.PI / 4) * radius;
  6695. ctx.moveTo(x - xOffset, y - yOffset);
  6696. ctx.lineTo(x + xOffset, y + yOffset);
  6697. ctx.moveTo(x - xOffset, y + yOffset);
  6698. ctx.lineTo(x + xOffset, y - yOffset);
  6699. ctx.closePath();
  6700. break;
  6701. case 'star':
  6702. ctx.beginPath();
  6703. ctx.moveTo(x, y + radius);
  6704. ctx.lineTo(x, y - radius);
  6705. ctx.moveTo(x - radius, y);
  6706. ctx.lineTo(x + radius, y);
  6707. xOffset = Math.cos(Math.PI / 4) * radius;
  6708. yOffset = Math.sin(Math.PI / 4) * radius;
  6709. ctx.moveTo(x - xOffset, y - yOffset);
  6710. ctx.lineTo(x + xOffset, y + yOffset);
  6711. ctx.moveTo(x - xOffset, y + yOffset);
  6712. ctx.lineTo(x + xOffset, y - yOffset);
  6713. ctx.closePath();
  6714. break;
  6715. case 'line':
  6716. ctx.beginPath();
  6717. ctx.moveTo(x - radius, y);
  6718. ctx.lineTo(x + radius, y);
  6719. ctx.closePath();
  6720. break;
  6721. case 'dash':
  6722. ctx.beginPath();
  6723. ctx.moveTo(x, y);
  6724. ctx.lineTo(x + radius, y);
  6725. ctx.closePath();
  6726. break;
  6727. }
  6728. ctx.stroke();
  6729. };
  6730. };
  6731. },{}],23:[function(require,module,exports){
  6732. "use strict";
  6733. module.exports = function(Chart) {
  6734. var helpers = Chart.helpers;
  6735. //Create a dictionary of chart types, to allow for extension of existing types
  6736. Chart.types = {};
  6737. //Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  6738. //Destroy method on the chart will remove the instance of the chart from this reference.
  6739. Chart.instances = {};
  6740. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  6741. Chart.controllers = {};
  6742. /**
  6743. * @class Chart.Controller
  6744. * The main controller of a chart.
  6745. */
  6746. Chart.Controller = function(instance) {
  6747. this.chart = instance;
  6748. this.config = instance.config;
  6749. this.options = this.config.options = helpers.configMerge(Chart.defaults.global, Chart.defaults[this.config.type], this.config.options || {});
  6750. this.id = helpers.uid();
  6751. Object.defineProperty(this, 'data', {
  6752. get: function() {
  6753. return this.config.data;
  6754. }
  6755. });
  6756. //Add the chart instance to the global namespace
  6757. Chart.instances[this.id] = this;
  6758. if (this.options.responsive) {
  6759. // Silent resize before chart draws
  6760. this.resize(true);
  6761. }
  6762. this.initialize();
  6763. return this;
  6764. };
  6765. helpers.extend(Chart.Controller.prototype, /** @lends Chart.Controller */ {
  6766. initialize: function() {
  6767. var me = this;
  6768. // Before init plugin notification
  6769. Chart.plugins.notify('beforeInit', [me]);
  6770. me.bindEvents();
  6771. // Make sure controllers are built first so that each dataset is bound to an axis before the scales
  6772. // are built
  6773. me.ensureScalesHaveIDs();
  6774. me.buildOrUpdateControllers();
  6775. me.buildScales();
  6776. me.updateLayout();
  6777. me.resetElements();
  6778. me.initToolTip();
  6779. me.update();
  6780. // After init plugin notification
  6781. Chart.plugins.notify('afterInit', [me]);
  6782. return me;
  6783. },
  6784. clear: function() {
  6785. helpers.clear(this.chart);
  6786. return this;
  6787. },
  6788. stop: function() {
  6789. // Stops any current animation loop occuring
  6790. Chart.animationService.cancelAnimation(this);
  6791. return this;
  6792. },
  6793. resize: function resize(silent) {
  6794. var me = this;
  6795. var chart = me.chart;
  6796. var canvas = chart.canvas;
  6797. var newWidth = helpers.getMaximumWidth(canvas);
  6798. var aspectRatio = chart.aspectRatio;
  6799. var newHeight = (me.options.maintainAspectRatio && isNaN(aspectRatio) === false && isFinite(aspectRatio) && aspectRatio !== 0) ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas);
  6800. var sizeChanged = chart.width !== newWidth || chart.height !== newHeight;
  6801. if (!sizeChanged) {
  6802. return me;
  6803. }
  6804. canvas.width = chart.width = newWidth;
  6805. canvas.height = chart.height = newHeight;
  6806. helpers.retinaScale(chart);
  6807. // Notify any plugins about the resize
  6808. var newSize = { width: newWidth, height: newHeight };
  6809. Chart.plugins.notify('resize', [me, newSize]);
  6810. // Notify of resize
  6811. if (me.options.onResize) {
  6812. me.options.onResize(me, newSize);
  6813. }
  6814. if (!silent) {
  6815. me.stop();
  6816. me.update(me.options.responsiveAnimationDuration);
  6817. }
  6818. return me;
  6819. },
  6820. ensureScalesHaveIDs: function() {
  6821. var options = this.options;
  6822. var scalesOptions = options.scales || {};
  6823. var scaleOptions = options.scale;
  6824. helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
  6825. xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
  6826. });
  6827. helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
  6828. yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
  6829. });
  6830. if (scaleOptions) {
  6831. scaleOptions.id = scaleOptions.id || 'scale';
  6832. }
  6833. },
  6834. /**
  6835. * Builds a map of scale ID to scale object for future lookup.
  6836. */
  6837. buildScales: function() {
  6838. var me = this;
  6839. var options = me.options;
  6840. var scales = me.scales = {};
  6841. var items = [];
  6842. if (options.scales) {
  6843. items = items.concat(
  6844. (options.scales.xAxes || []).map(function(xAxisOptions) {
  6845. return { options: xAxisOptions, dtype: 'category' }; }),
  6846. (options.scales.yAxes || []).map(function(yAxisOptions) {
  6847. return { options: yAxisOptions, dtype: 'linear' }; }));
  6848. }
  6849. if (options.scale) {
  6850. items.push({ options: options.scale, dtype: 'radialLinear', isDefault: true });
  6851. }
  6852. helpers.each(items, function(item) {
  6853. var scaleOptions = item.options;
  6854. var scaleType = helpers.getValueOrDefault(scaleOptions.type, item.dtype);
  6855. var scaleClass = Chart.scaleService.getScaleConstructor(scaleType);
  6856. if (!scaleClass) {
  6857. return;
  6858. }
  6859. var scale = new scaleClass({
  6860. id: scaleOptions.id,
  6861. options: scaleOptions,
  6862. ctx: me.chart.ctx,
  6863. chart: me
  6864. });
  6865. scales[scale.id] = scale;
  6866. // TODO(SB): I think we should be able to remove this custom case (options.scale)
  6867. // and consider it as a regular scale part of the "scales"" map only! This would
  6868. // make the logic easier and remove some useless? custom code.
  6869. if (item.isDefault) {
  6870. me.scale = scale;
  6871. }
  6872. });
  6873. Chart.scaleService.addScalesToLayout(this);
  6874. },
  6875. updateLayout: function() {
  6876. Chart.layoutService.update(this, this.chart.width, this.chart.height);
  6877. },
  6878. buildOrUpdateControllers: function() {
  6879. var me = this;
  6880. var types = [];
  6881. var newControllers = [];
  6882. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  6883. var meta = me.getDatasetMeta(datasetIndex);
  6884. if (!meta.type) {
  6885. meta.type = dataset.type || me.config.type;
  6886. }
  6887. types.push(meta.type);
  6888. if (meta.controller) {
  6889. meta.controller.updateIndex(datasetIndex);
  6890. } else {
  6891. meta.controller = new Chart.controllers[meta.type](me, datasetIndex);
  6892. newControllers.push(meta.controller);
  6893. }
  6894. }, me);
  6895. if (types.length > 1) {
  6896. for (var i = 1; i < types.length; i++) {
  6897. if (types[i] !== types[i - 1]) {
  6898. me.isCombo = true;
  6899. break;
  6900. }
  6901. }
  6902. }
  6903. return newControllers;
  6904. },
  6905. resetElements: function() {
  6906. var me = this;
  6907. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  6908. me.getDatasetMeta(datasetIndex).controller.reset();
  6909. }, me);
  6910. },
  6911. update: function update(animationDuration, lazy) {
  6912. var me = this;
  6913. Chart.plugins.notify('beforeUpdate', [me]);
  6914. // In case the entire data object changed
  6915. me.tooltip._data = me.data;
  6916. // Make sure dataset controllers are updated and new controllers are reset
  6917. var newControllers = me.buildOrUpdateControllers();
  6918. // Make sure all dataset controllers have correct meta data counts
  6919. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  6920. me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
  6921. }, me);
  6922. Chart.layoutService.update(me, me.chart.width, me.chart.height);
  6923. // Apply changes to the dataets that require the scales to have been calculated i.e BorderColor chages
  6924. Chart.plugins.notify('afterScaleUpdate', [me]);
  6925. // Can only reset the new controllers after the scales have been updated
  6926. helpers.each(newControllers, function(controller) {
  6927. controller.reset();
  6928. });
  6929. me.updateDatasets();
  6930. // Do this before render so that any plugins that need final scale updates can use it
  6931. Chart.plugins.notify('afterUpdate', [me]);
  6932. me.render(animationDuration, lazy);
  6933. },
  6934. /**
  6935. * @method beforeDatasetsUpdate
  6936. * @description Called before all datasets are updated. If a plugin returns false,
  6937. * the datasets update will be cancelled until another chart update is triggered.
  6938. * @param {Object} instance the chart instance being updated.
  6939. * @returns {Boolean} false to cancel the datasets update.
  6940. * @memberof Chart.PluginBase
  6941. * @since version 2.1.5
  6942. * @instance
  6943. */
  6944. /**
  6945. * @method afterDatasetsUpdate
  6946. * @description Called after all datasets have been updated. Note that this
  6947. * extension will not be called if the datasets update has been cancelled.
  6948. * @param {Object} instance the chart instance being updated.
  6949. * @memberof Chart.PluginBase
  6950. * @since version 2.1.5
  6951. * @instance
  6952. */
  6953. /**
  6954. * Updates all datasets unless a plugin returns false to the beforeDatasetsUpdate
  6955. * extension, in which case no datasets will be updated and the afterDatasetsUpdate
  6956. * notification will be skipped.
  6957. * @protected
  6958. * @instance
  6959. */
  6960. updateDatasets: function() {
  6961. var me = this;
  6962. var i, ilen;
  6963. if (Chart.plugins.notify('beforeDatasetsUpdate', [ me ])) {
  6964. for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  6965. me.getDatasetMeta(i).controller.update();
  6966. }
  6967. Chart.plugins.notify('afterDatasetsUpdate', [ me ]);
  6968. }
  6969. },
  6970. render: function render(duration, lazy) {
  6971. var me = this;
  6972. Chart.plugins.notify('beforeRender', [me]);
  6973. var animationOptions = me.options.animation;
  6974. if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
  6975. var animation = new Chart.Animation();
  6976. animation.numSteps = (duration || animationOptions.duration) / 16.66; //60 fps
  6977. animation.easing = animationOptions.easing;
  6978. // render function
  6979. animation.render = function(chartInstance, animationObject) {
  6980. var easingFunction = helpers.easingEffects[animationObject.easing];
  6981. var stepDecimal = animationObject.currentStep / animationObject.numSteps;
  6982. var easeDecimal = easingFunction(stepDecimal);
  6983. chartInstance.draw(easeDecimal, stepDecimal, animationObject.currentStep);
  6984. };
  6985. // user events
  6986. animation.onAnimationProgress = animationOptions.onProgress;
  6987. animation.onAnimationComplete = animationOptions.onComplete;
  6988. Chart.animationService.addAnimation(me, animation, duration, lazy);
  6989. } else {
  6990. me.draw();
  6991. if (animationOptions && animationOptions.onComplete && animationOptions.onComplete.call) {
  6992. animationOptions.onComplete.call(me);
  6993. }
  6994. }
  6995. return me;
  6996. },
  6997. draw: function(ease) {
  6998. var me = this;
  6999. var easingDecimal = ease || 1;
  7000. me.clear();
  7001. Chart.plugins.notify('beforeDraw', [me, easingDecimal]);
  7002. // Draw all the scales
  7003. helpers.each(me.boxes, function(box) {
  7004. box.draw(me.chartArea);
  7005. }, me);
  7006. if (me.scale) {
  7007. me.scale.draw();
  7008. }
  7009. Chart.plugins.notify('beforeDatasetsDraw', [me, easingDecimal]);
  7010. // Draw each dataset via its respective controller (reversed to support proper line stacking)
  7011. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  7012. if (me.isDatasetVisible(datasetIndex)) {
  7013. me.getDatasetMeta(datasetIndex).controller.draw(ease);
  7014. }
  7015. }, me, true);
  7016. Chart.plugins.notify('afterDatasetsDraw', [me, easingDecimal]);
  7017. // Finally draw the tooltip
  7018. me.tooltip.transition(easingDecimal).draw();
  7019. Chart.plugins.notify('afterDraw', [me, easingDecimal]);
  7020. },
  7021. // Get the single element that was clicked on
  7022. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  7023. getElementAtEvent: function(e) {
  7024. var me = this;
  7025. var eventPosition = helpers.getRelativePosition(e, me.chart);
  7026. var elementsArray = [];
  7027. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  7028. if (me.isDatasetVisible(datasetIndex)) {
  7029. var meta = me.getDatasetMeta(datasetIndex);
  7030. helpers.each(meta.data, function(element) {
  7031. if (element.inRange(eventPosition.x, eventPosition.y)) {
  7032. elementsArray.push(element);
  7033. return elementsArray;
  7034. }
  7035. });
  7036. }
  7037. });
  7038. return elementsArray.slice(0, 1);
  7039. },
  7040. getElementsAtEvent: function(e) {
  7041. var me = this;
  7042. var eventPosition = helpers.getRelativePosition(e, me.chart);
  7043. var elementsArray = [];
  7044. var found = (function() {
  7045. if (me.data.datasets) {
  7046. for (var i = 0; i < me.data.datasets.length; i++) {
  7047. var meta = me.getDatasetMeta(i);
  7048. if (me.isDatasetVisible(i)) {
  7049. for (var j = 0; j < meta.data.length; j++) {
  7050. if (meta.data[j].inRange(eventPosition.x, eventPosition.y)) {
  7051. return meta.data[j];
  7052. }
  7053. }
  7054. }
  7055. }
  7056. }
  7057. }).call(me);
  7058. if (!found) {
  7059. return elementsArray;
  7060. }
  7061. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  7062. if (me.isDatasetVisible(datasetIndex)) {
  7063. var meta = me.getDatasetMeta(datasetIndex),
  7064. element = meta.data[found._index];
  7065. if(element && !element._view.skip){
  7066. elementsArray.push(element);
  7067. }
  7068. }
  7069. }, me);
  7070. return elementsArray;
  7071. },
  7072. getElementsAtXAxis: function(e) {
  7073. var me = this;
  7074. var eventPosition = helpers.getRelativePosition(e, me.chart);
  7075. var elementsArray = [];
  7076. var found = (function() {
  7077. if (me.data.datasets) {
  7078. for (var i = 0; i < me.data.datasets.length; i++) {
  7079. var meta = me.getDatasetMeta(i);
  7080. if (me.isDatasetVisible(i)) {
  7081. for (var j = 0; j < meta.data.length; j++) {
  7082. if (meta.data[j].inLabelRange(eventPosition.x, eventPosition.y)) {
  7083. return meta.data[j];
  7084. }
  7085. }
  7086. }
  7087. }
  7088. }
  7089. }).call(me);
  7090. if (!found) {
  7091. return elementsArray;
  7092. }
  7093. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  7094. if (me.isDatasetVisible(datasetIndex)) {
  7095. var meta = me.getDatasetMeta(datasetIndex);
  7096. var index = helpers.findIndex(meta.data, function (it) {
  7097. return found._model.x === it._model.x;
  7098. });
  7099. if(index !== -1 && !meta.data[index]._view.skip) {
  7100. elementsArray.push(meta.data[index]);
  7101. }
  7102. }
  7103. }, me);
  7104. return elementsArray;
  7105. },
  7106. getElementsAtEventForMode: function(e, mode) {
  7107. var me = this;
  7108. switch (mode) {
  7109. case 'single':
  7110. return me.getElementAtEvent(e);
  7111. case 'label':
  7112. return me.getElementsAtEvent(e);
  7113. case 'dataset':
  7114. return me.getDatasetAtEvent(e);
  7115. case 'x-axis':
  7116. return me.getElementsAtXAxis(e);
  7117. default:
  7118. return e;
  7119. }
  7120. },
  7121. getDatasetAtEvent: function(e) {
  7122. var elementsArray = this.getElementAtEvent(e);
  7123. if (elementsArray.length > 0) {
  7124. elementsArray = this.getDatasetMeta(elementsArray[0]._datasetIndex).data;
  7125. }
  7126. return elementsArray;
  7127. },
  7128. getDatasetMeta: function(datasetIndex) {
  7129. var me = this;
  7130. var dataset = me.data.datasets[datasetIndex];
  7131. if (!dataset._meta) {
  7132. dataset._meta = {};
  7133. }
  7134. var meta = dataset._meta[me.id];
  7135. if (!meta) {
  7136. meta = dataset._meta[me.id] = {
  7137. type: null,
  7138. data: [],
  7139. dataset: null,
  7140. controller: null,
  7141. hidden: null, // See isDatasetVisible() comment
  7142. xAxisID: null,
  7143. yAxisID: null
  7144. };
  7145. }
  7146. return meta;
  7147. },
  7148. getVisibleDatasetCount: function() {
  7149. var count = 0;
  7150. for (var i = 0, ilen = this.data.datasets.length; i<ilen; ++i) {
  7151. if (this.isDatasetVisible(i)) {
  7152. count++;
  7153. }
  7154. }
  7155. return count;
  7156. },
  7157. isDatasetVisible: function(datasetIndex) {
  7158. var meta = this.getDatasetMeta(datasetIndex);
  7159. // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
  7160. // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
  7161. return typeof meta.hidden === 'boolean'? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
  7162. },
  7163. generateLegend: function() {
  7164. return this.options.legendCallback(this);
  7165. },
  7166. destroy: function() {
  7167. var me = this;
  7168. me.stop();
  7169. me.clear();
  7170. helpers.unbindEvents(me, me.events);
  7171. helpers.removeResizeListener(me.chart.canvas.parentNode);
  7172. // Reset canvas height/width attributes
  7173. var canvas = me.chart.canvas;
  7174. canvas.width = me.chart.width;
  7175. canvas.height = me.chart.height;
  7176. // if we scaled the canvas in response to a devicePixelRatio !== 1, we need to undo that transform here
  7177. if (me.chart.originalDevicePixelRatio !== undefined) {
  7178. me.chart.ctx.scale(1 / me.chart.originalDevicePixelRatio, 1 / me.chart.originalDevicePixelRatio);
  7179. }
  7180. // Reset to the old style since it may have been changed by the device pixel ratio changes
  7181. canvas.style.width = me.chart.originalCanvasStyleWidth;
  7182. canvas.style.height = me.chart.originalCanvasStyleHeight;
  7183. Chart.plugins.notify('destroy', [me]);
  7184. delete Chart.instances[me.id];
  7185. },
  7186. toBase64Image: function() {
  7187. return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments);
  7188. },
  7189. initToolTip: function() {
  7190. var me = this;
  7191. me.tooltip = new Chart.Tooltip({
  7192. _chart: me.chart,
  7193. _chartInstance: me,
  7194. _data: me.data,
  7195. _options: me.options.tooltips
  7196. }, me);
  7197. },
  7198. bindEvents: function() {
  7199. var me = this;
  7200. helpers.bindEvents(me, me.options.events, function(evt) {
  7201. me.eventHandler(evt);
  7202. });
  7203. },
  7204. updateHoverStyle: function(elements, mode, enabled) {
  7205. var method = enabled? 'setHoverStyle' : 'removeHoverStyle';
  7206. var element, i, ilen;
  7207. switch (mode) {
  7208. case 'single':
  7209. elements = [ elements[0] ];
  7210. break;
  7211. case 'label':
  7212. case 'dataset':
  7213. case 'x-axis':
  7214. // elements = elements;
  7215. break;
  7216. default:
  7217. // unsupported mode
  7218. return;
  7219. }
  7220. for (i=0, ilen=elements.length; i<ilen; ++i) {
  7221. element = elements[i];
  7222. if (element) {
  7223. this.getDatasetMeta(element._datasetIndex).controller[method](element);
  7224. }
  7225. }
  7226. },
  7227. eventHandler: function eventHandler(e) {
  7228. var me = this;
  7229. var tooltip = me.tooltip;
  7230. var options = me.options || {};
  7231. var hoverOptions = options.hover;
  7232. var tooltipsOptions = options.tooltips;
  7233. me.lastActive = me.lastActive || [];
  7234. me.lastTooltipActive = me.lastTooltipActive || [];
  7235. // Find Active Elements for hover and tooltips
  7236. if (e.type === 'mouseout') {
  7237. me.active = [];
  7238. me.tooltipActive = [];
  7239. } else {
  7240. me.active = me.getElementsAtEventForMode(e, hoverOptions.mode);
  7241. me.tooltipActive = me.getElementsAtEventForMode(e, tooltipsOptions.mode);
  7242. }
  7243. // On Hover hook
  7244. if (hoverOptions.onHover) {
  7245. hoverOptions.onHover.call(me, me.active);
  7246. }
  7247. if (e.type === 'mouseup' || e.type === 'click') {
  7248. if (options.onClick) {
  7249. options.onClick.call(me, e, me.active);
  7250. }
  7251. if (me.legend && me.legend.handleEvent) {
  7252. me.legend.handleEvent(e);
  7253. }
  7254. }
  7255. // Remove styling for last active (even if it may still be active)
  7256. if (me.lastActive.length) {
  7257. me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
  7258. }
  7259. // Built in hover styling
  7260. if (me.active.length && hoverOptions.mode) {
  7261. me.updateHoverStyle(me.active, hoverOptions.mode, true);
  7262. }
  7263. // Built in Tooltips
  7264. if (tooltipsOptions.enabled || tooltipsOptions.custom) {
  7265. tooltip.initialize();
  7266. tooltip._active = me.tooltipActive;
  7267. tooltip.update(true);
  7268. }
  7269. // Hover animations
  7270. tooltip.pivot();
  7271. if (!me.animating) {
  7272. // If entering, leaving, or changing elements, animate the change via pivot
  7273. if (!helpers.arrayEquals(me.active, me.lastActive) ||
  7274. !helpers.arrayEquals(me.tooltipActive, me.lastTooltipActive)) {
  7275. me.stop();
  7276. if (tooltipsOptions.enabled || tooltipsOptions.custom) {
  7277. tooltip.update(true);
  7278. }
  7279. // We only need to render at this point. Updating will cause scales to be
  7280. // recomputed generating flicker & using more memory than necessary.
  7281. me.render(hoverOptions.animationDuration, true);
  7282. }
  7283. }
  7284. // Remember Last Actives
  7285. me.lastActive = me.active;
  7286. me.lastTooltipActive = me.tooltipActive;
  7287. return me;
  7288. }
  7289. });
  7290. };
  7291. },{}],24:[function(require,module,exports){
  7292. "use strict";
  7293. module.exports = function(Chart) {
  7294. var helpers = Chart.helpers;
  7295. var noop = helpers.noop;
  7296. // Base class for all dataset controllers (line, bar, etc)
  7297. Chart.DatasetController = function(chart, datasetIndex) {
  7298. this.initialize.call(this, chart, datasetIndex);
  7299. };
  7300. helpers.extend(Chart.DatasetController.prototype, {
  7301. /**
  7302. * Element type used to generate a meta dataset (e.g. Chart.element.Line).
  7303. * @type {Chart.core.element}
  7304. */
  7305. datasetElementType: null,
  7306. /**
  7307. * Element type used to generate a meta data (e.g. Chart.element.Point).
  7308. * @type {Chart.core.element}
  7309. */
  7310. dataElementType: null,
  7311. initialize: function(chart, datasetIndex) {
  7312. var me = this;
  7313. me.chart = chart;
  7314. me.index = datasetIndex;
  7315. me.linkScales();
  7316. me.addElements();
  7317. },
  7318. updateIndex: function(datasetIndex) {
  7319. this.index = datasetIndex;
  7320. },
  7321. linkScales: function() {
  7322. var me = this;
  7323. var meta = me.getMeta();
  7324. var dataset = me.getDataset();
  7325. if (meta.xAxisID === null) {
  7326. meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
  7327. }
  7328. if (meta.yAxisID === null) {
  7329. meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
  7330. }
  7331. },
  7332. getDataset: function() {
  7333. return this.chart.data.datasets[this.index];
  7334. },
  7335. getMeta: function() {
  7336. return this.chart.getDatasetMeta(this.index);
  7337. },
  7338. getScaleForId: function(scaleID) {
  7339. return this.chart.scales[scaleID];
  7340. },
  7341. reset: function() {
  7342. this.update(true);
  7343. },
  7344. createMetaDataset: function() {
  7345. var me = this;
  7346. var type = me.datasetElementType;
  7347. return type && new type({
  7348. _chart: me.chart.chart,
  7349. _datasetIndex: me.index
  7350. });
  7351. },
  7352. createMetaData: function(index) {
  7353. var me = this;
  7354. var type = me.dataElementType;
  7355. return type && new type({
  7356. _chart: me.chart.chart,
  7357. _datasetIndex: me.index,
  7358. _index: index
  7359. });
  7360. },
  7361. addElements: function() {
  7362. var me = this;
  7363. var meta = me.getMeta();
  7364. var data = me.getDataset().data || [];
  7365. var metaData = meta.data;
  7366. var i, ilen;
  7367. for (i=0, ilen=data.length; i<ilen; ++i) {
  7368. metaData[i] = metaData[i] || me.createMetaData(meta, i);
  7369. }
  7370. meta.dataset = meta.dataset || me.createMetaDataset();
  7371. },
  7372. addElementAndReset: function(index) {
  7373. var me = this;
  7374. var element = me.createMetaData(index);
  7375. me.getMeta().data.splice(index, 0, element);
  7376. me.updateElement(element, index, true);
  7377. },
  7378. buildOrUpdateElements: function() {
  7379. // Handle the number of data points changing
  7380. var meta = this.getMeta(),
  7381. md = meta.data,
  7382. numData = this.getDataset().data.length,
  7383. numMetaData = md.length;
  7384. // Make sure that we handle number of datapoints changing
  7385. if (numData < numMetaData) {
  7386. // Remove excess bars for data points that have been removed
  7387. md.splice(numData, numMetaData - numData);
  7388. } else if (numData > numMetaData) {
  7389. // Add new elements
  7390. for (var index = numMetaData; index < numData; ++index) {
  7391. this.addElementAndReset(index);
  7392. }
  7393. }
  7394. },
  7395. update: noop,
  7396. draw: function(ease) {
  7397. var easingDecimal = ease || 1;
  7398. helpers.each(this.getMeta().data, function(element) {
  7399. element.transition(easingDecimal).draw();
  7400. });
  7401. },
  7402. removeHoverStyle: function(element, elementOpts) {
  7403. var dataset = this.chart.data.datasets[element._datasetIndex],
  7404. index = element._index,
  7405. custom = element.custom || {},
  7406. valueOrDefault = helpers.getValueAtIndexOrDefault,
  7407. model = element._model;
  7408. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  7409. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  7410. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  7411. },
  7412. setHoverStyle: function(element) {
  7413. var dataset = this.chart.data.datasets[element._datasetIndex],
  7414. index = element._index,
  7415. custom = element.custom || {},
  7416. valueOrDefault = helpers.getValueAtIndexOrDefault,
  7417. getHoverColor = helpers.getHoverColor,
  7418. model = element._model;
  7419. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
  7420. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
  7421. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  7422. }
  7423. });
  7424. Chart.DatasetController.extend = helpers.inherits;
  7425. };
  7426. },{}],25:[function(require,module,exports){
  7427. "use strict";
  7428. module.exports = function(Chart) {
  7429. var helpers = Chart.helpers;
  7430. Chart.elements = {};
  7431. Chart.Element = function(configuration) {
  7432. helpers.extend(this, configuration);
  7433. this.initialize.apply(this, arguments);
  7434. };
  7435. helpers.extend(Chart.Element.prototype, {
  7436. initialize: function() {
  7437. this.hidden = false;
  7438. },
  7439. pivot: function() {
  7440. var me = this;
  7441. if (!me._view) {
  7442. me._view = helpers.clone(me._model);
  7443. }
  7444. me._start = helpers.clone(me._view);
  7445. return me;
  7446. },
  7447. transition: function(ease) {
  7448. var me = this;
  7449. if (!me._view) {
  7450. me._view = helpers.clone(me._model);
  7451. }
  7452. // No animation -> No Transition
  7453. if (ease === 1) {
  7454. me._view = me._model;
  7455. me._start = null;
  7456. return me;
  7457. }
  7458. if (!me._start) {
  7459. me.pivot();
  7460. }
  7461. helpers.each(me._model, function(value, key) {
  7462. if (key[0] === '_') {
  7463. // Only non-underscored properties
  7464. }
  7465. // Init if doesn't exist
  7466. else if (!me._view.hasOwnProperty(key)) {
  7467. if (typeof value === 'number' && !isNaN(me._view[key])) {
  7468. me._view[key] = value * ease;
  7469. } else {
  7470. me._view[key] = value;
  7471. }
  7472. }
  7473. // No unnecessary computations
  7474. else if (value === me._view[key]) {
  7475. // It's the same! Woohoo!
  7476. }
  7477. // Color transitions if possible
  7478. else if (typeof value === 'string') {
  7479. try {
  7480. var color = helpers.color(me._model[key]).mix(helpers.color(me._start[key]), ease);
  7481. me._view[key] = color.rgbString();
  7482. } catch (err) {
  7483. me._view[key] = value;
  7484. }
  7485. }
  7486. // Number transitions
  7487. else if (typeof value === 'number') {
  7488. var startVal = me._start[key] !== undefined && isNaN(me._start[key]) === false ? me._start[key] : 0;
  7489. me._view[key] = ((me._model[key] - startVal) * ease) + startVal;
  7490. }
  7491. // Everything else
  7492. else {
  7493. me._view[key] = value;
  7494. }
  7495. }, me);
  7496. return me;
  7497. },
  7498. tooltipPosition: function() {
  7499. return {
  7500. x: this._model.x,
  7501. y: this._model.y
  7502. };
  7503. },
  7504. hasValue: function() {
  7505. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  7506. }
  7507. });
  7508. Chart.Element.extend = helpers.inherits;
  7509. };
  7510. },{}],26:[function(require,module,exports){
  7511. /*global window: false */
  7512. /*global document: false */
  7513. "use strict";
  7514. var color = require(2);
  7515. module.exports = function(Chart) {
  7516. //Global Chart helpers object for utility methods and classes
  7517. var helpers = Chart.helpers = {};
  7518. //-- Basic js utility methods
  7519. helpers.each = function(loopable, callback, self, reverse) {
  7520. // Check to see if null or undefined firstly.
  7521. var i, len;
  7522. if (helpers.isArray(loopable)) {
  7523. len = loopable.length;
  7524. if (reverse) {
  7525. for (i = len - 1; i >= 0; i--) {
  7526. callback.call(self, loopable[i], i);
  7527. }
  7528. } else {
  7529. for (i = 0; i < len; i++) {
  7530. callback.call(self, loopable[i], i);
  7531. }
  7532. }
  7533. } else if (typeof loopable === 'object') {
  7534. var keys = Object.keys(loopable);
  7535. len = keys.length;
  7536. for (i = 0; i < len; i++) {
  7537. callback.call(self, loopable[keys[i]], keys[i]);
  7538. }
  7539. }
  7540. };
  7541. helpers.clone = function(obj) {
  7542. var objClone = {};
  7543. helpers.each(obj, function(value, key) {
  7544. if (helpers.isArray(value)) {
  7545. objClone[key] = value.slice(0);
  7546. } else if (typeof value === 'object' && value !== null) {
  7547. objClone[key] = helpers.clone(value);
  7548. } else {
  7549. objClone[key] = value;
  7550. }
  7551. });
  7552. return objClone;
  7553. };
  7554. helpers.extend = function(base) {
  7555. var setFn = function(value, key) { base[key] = value; };
  7556. for (var i = 1, ilen = arguments.length; i < ilen; i++) {
  7557. helpers.each(arguments[i], setFn);
  7558. }
  7559. return base;
  7560. };
  7561. // Need a special merge function to chart configs since they are now grouped
  7562. helpers.configMerge = function(_base) {
  7563. var base = helpers.clone(_base);
  7564. helpers.each(Array.prototype.slice.call(arguments, 1), function(extension) {
  7565. helpers.each(extension, function(value, key) {
  7566. if (key === 'scales') {
  7567. // Scale config merging is complex. Add out own function here for that
  7568. base[key] = helpers.scaleMerge(base.hasOwnProperty(key) ? base[key] : {}, value);
  7569. } else if (key === 'scale') {
  7570. // Used in polar area & radar charts since there is only one scale
  7571. base[key] = helpers.configMerge(base.hasOwnProperty(key) ? base[key] : {}, Chart.scaleService.getScaleDefaults(value.type), value);
  7572. } else if (base.hasOwnProperty(key) && helpers.isArray(base[key]) && helpers.isArray(value)) {
  7573. // In this case we have an array of objects replacing another array. Rather than doing a strict replace,
  7574. // merge. This allows easy scale option merging
  7575. var baseArray = base[key];
  7576. helpers.each(value, function(valueObj, index) {
  7577. if (index < baseArray.length) {
  7578. if (typeof baseArray[index] === 'object' && baseArray[index] !== null && typeof valueObj === 'object' && valueObj !== null) {
  7579. // Two objects are coming together. Do a merge of them.
  7580. baseArray[index] = helpers.configMerge(baseArray[index], valueObj);
  7581. } else {
  7582. // Just overwrite in this case since there is nothing to merge
  7583. baseArray[index] = valueObj;
  7584. }
  7585. } else {
  7586. baseArray.push(valueObj); // nothing to merge
  7587. }
  7588. });
  7589. } else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") {
  7590. // If we are overwriting an object with an object, do a merge of the properties.
  7591. base[key] = helpers.configMerge(base[key], value);
  7592. } else {
  7593. // can just overwrite the value in this case
  7594. base[key] = value;
  7595. }
  7596. });
  7597. });
  7598. return base;
  7599. };
  7600. helpers.scaleMerge = function(_base, extension) {
  7601. var base = helpers.clone(_base);
  7602. helpers.each(extension, function(value, key) {
  7603. if (key === 'xAxes' || key === 'yAxes') {
  7604. // These properties are arrays of items
  7605. if (base.hasOwnProperty(key)) {
  7606. helpers.each(value, function(valueObj, index) {
  7607. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  7608. var axisDefaults = Chart.scaleService.getScaleDefaults(axisType);
  7609. if (index >= base[key].length || !base[key][index].type) {
  7610. base[key].push(helpers.configMerge(axisDefaults, valueObj));
  7611. } else if (valueObj.type && valueObj.type !== base[key][index].type) {
  7612. // Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults
  7613. base[key][index] = helpers.configMerge(base[key][index], axisDefaults, valueObj);
  7614. } else {
  7615. // Type is the same
  7616. base[key][index] = helpers.configMerge(base[key][index], valueObj);
  7617. }
  7618. });
  7619. } else {
  7620. base[key] = [];
  7621. helpers.each(value, function(valueObj) {
  7622. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  7623. base[key].push(helpers.configMerge(Chart.scaleService.getScaleDefaults(axisType), valueObj));
  7624. });
  7625. }
  7626. } else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") {
  7627. // If we are overwriting an object with an object, do a merge of the properties.
  7628. base[key] = helpers.configMerge(base[key], value);
  7629. } else {
  7630. // can just overwrite the value in this case
  7631. base[key] = value;
  7632. }
  7633. });
  7634. return base;
  7635. };
  7636. helpers.getValueAtIndexOrDefault = function(value, index, defaultValue) {
  7637. if (value === undefined || value === null) {
  7638. return defaultValue;
  7639. }
  7640. if (helpers.isArray(value)) {
  7641. return index < value.length ? value[index] : defaultValue;
  7642. }
  7643. return value;
  7644. };
  7645. helpers.getValueOrDefault = function(value, defaultValue) {
  7646. return value === undefined ? defaultValue : value;
  7647. };
  7648. helpers.indexOf = Array.prototype.indexOf?
  7649. function(array, item) { return array.indexOf(item); } :
  7650. function(array, item) {
  7651. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  7652. if (array[i] === item) {
  7653. return i;
  7654. }
  7655. }
  7656. return -1;
  7657. };
  7658. helpers.where = function(collection, filterCallback) {
  7659. if (helpers.isArray(collection) && Array.prototype.filter) {
  7660. return collection.filter(filterCallback);
  7661. } else {
  7662. var filtered = [];
  7663. helpers.each(collection, function(item) {
  7664. if (filterCallback(item)) {
  7665. filtered.push(item);
  7666. }
  7667. });
  7668. return filtered;
  7669. }
  7670. };
  7671. helpers.findIndex = Array.prototype.findIndex?
  7672. function(array, callback, scope) { return array.findIndex(callback, scope); } :
  7673. function(array, callback, scope) {
  7674. scope = scope === undefined? array : scope;
  7675. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  7676. if (callback.call(scope, array[i], i, array)) {
  7677. return i;
  7678. }
  7679. }
  7680. return -1;
  7681. };
  7682. helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
  7683. // Default to start of the array
  7684. if (startIndex === undefined || startIndex === null) {
  7685. startIndex = -1;
  7686. }
  7687. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  7688. var currentItem = arrayToSearch[i];
  7689. if (filterCallback(currentItem)) {
  7690. return currentItem;
  7691. }
  7692. }
  7693. };
  7694. helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
  7695. // Default to end of the array
  7696. if (startIndex === undefined || startIndex === null) {
  7697. startIndex = arrayToSearch.length;
  7698. }
  7699. for (var i = startIndex - 1; i >= 0; i--) {
  7700. var currentItem = arrayToSearch[i];
  7701. if (filterCallback(currentItem)) {
  7702. return currentItem;
  7703. }
  7704. }
  7705. };
  7706. helpers.inherits = function(extensions) {
  7707. //Basic javascript inheritance based on the model created in Backbone.js
  7708. var parent = this;
  7709. var ChartElement = (extensions && extensions.hasOwnProperty("constructor")) ? extensions.constructor : function() {
  7710. return parent.apply(this, arguments);
  7711. };
  7712. var Surrogate = function() {
  7713. this.constructor = ChartElement;
  7714. };
  7715. Surrogate.prototype = parent.prototype;
  7716. ChartElement.prototype = new Surrogate();
  7717. ChartElement.extend = helpers.inherits;
  7718. if (extensions) {
  7719. helpers.extend(ChartElement.prototype, extensions);
  7720. }
  7721. ChartElement.__super__ = parent.prototype;
  7722. return ChartElement;
  7723. };
  7724. helpers.noop = function() {};
  7725. helpers.uid = (function() {
  7726. var id = 0;
  7727. return function() {
  7728. return id++;
  7729. };
  7730. })();
  7731. //-- Math methods
  7732. helpers.isNumber = function(n) {
  7733. return !isNaN(parseFloat(n)) && isFinite(n);
  7734. };
  7735. helpers.almostEquals = function(x, y, epsilon) {
  7736. return Math.abs(x - y) < epsilon;
  7737. };
  7738. helpers.max = function(array) {
  7739. return array.reduce(function(max, value) {
  7740. if (!isNaN(value)) {
  7741. return Math.max(max, value);
  7742. } else {
  7743. return max;
  7744. }
  7745. }, Number.NEGATIVE_INFINITY);
  7746. };
  7747. helpers.min = function(array) {
  7748. return array.reduce(function(min, value) {
  7749. if (!isNaN(value)) {
  7750. return Math.min(min, value);
  7751. } else {
  7752. return min;
  7753. }
  7754. }, Number.POSITIVE_INFINITY);
  7755. };
  7756. helpers.sign = Math.sign?
  7757. function(x) { return Math.sign(x); } :
  7758. function(x) {
  7759. x = +x; // convert to a number
  7760. if (x === 0 || isNaN(x)) {
  7761. return x;
  7762. }
  7763. return x > 0 ? 1 : -1;
  7764. };
  7765. helpers.log10 = Math.log10?
  7766. function(x) { return Math.log10(x); } :
  7767. function(x) {
  7768. return Math.log(x) / Math.LN10;
  7769. };
  7770. helpers.toRadians = function(degrees) {
  7771. return degrees * (Math.PI / 180);
  7772. };
  7773. helpers.toDegrees = function(radians) {
  7774. return radians * (180 / Math.PI);
  7775. };
  7776. // Gets the angle from vertical upright to the point about a centre.
  7777. helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
  7778. var distanceFromXCenter = anglePoint.x - centrePoint.x,
  7779. distanceFromYCenter = anglePoint.y - centrePoint.y,
  7780. radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  7781. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  7782. if (angle < (-0.5 * Math.PI)) {
  7783. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  7784. }
  7785. return {
  7786. angle: angle,
  7787. distance: radialDistanceFromCenter
  7788. };
  7789. };
  7790. helpers.aliasPixel = function(pixelWidth) {
  7791. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  7792. };
  7793. helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
  7794. //Props to Rob Spencer at scaled innovation for his post on splining between points
  7795. //http://scaledinnovation.com/analytics/splines/aboutSplines.html
  7796. // This function must also respect "skipped" points
  7797. var previous = firstPoint.skip ? middlePoint : firstPoint,
  7798. current = middlePoint,
  7799. next = afterPoint.skip ? middlePoint : afterPoint;
  7800. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  7801. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  7802. var s01 = d01 / (d01 + d12);
  7803. var s12 = d12 / (d01 + d12);
  7804. // If all points are the same, s01 & s02 will be inf
  7805. s01 = isNaN(s01) ? 0 : s01;
  7806. s12 = isNaN(s12) ? 0 : s12;
  7807. var fa = t * s01; // scaling factor for triangle Ta
  7808. var fb = t * s12;
  7809. return {
  7810. previous: {
  7811. x: current.x - fa * (next.x - previous.x),
  7812. y: current.y - fa * (next.y - previous.y)
  7813. },
  7814. next: {
  7815. x: current.x + fb * (next.x - previous.x),
  7816. y: current.y + fb * (next.y - previous.y)
  7817. }
  7818. };
  7819. };
  7820. helpers.nextItem = function(collection, index, loop) {
  7821. if (loop) {
  7822. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  7823. }
  7824. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  7825. };
  7826. helpers.previousItem = function(collection, index, loop) {
  7827. if (loop) {
  7828. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  7829. }
  7830. return index <= 0 ? collection[0] : collection[index - 1];
  7831. };
  7832. // Implementation of the nice number algorithm used in determining where axis labels will go
  7833. helpers.niceNum = function(range, round) {
  7834. var exponent = Math.floor(helpers.log10(range));
  7835. var fraction = range / Math.pow(10, exponent);
  7836. var niceFraction;
  7837. if (round) {
  7838. if (fraction < 1.5) {
  7839. niceFraction = 1;
  7840. } else if (fraction < 3) {
  7841. niceFraction = 2;
  7842. } else if (fraction < 7) {
  7843. niceFraction = 5;
  7844. } else {
  7845. niceFraction = 10;
  7846. }
  7847. } else {
  7848. if (fraction <= 1.0) {
  7849. niceFraction = 1;
  7850. } else if (fraction <= 2) {
  7851. niceFraction = 2;
  7852. } else if (fraction <= 5) {
  7853. niceFraction = 5;
  7854. } else {
  7855. niceFraction = 10;
  7856. }
  7857. }
  7858. return niceFraction * Math.pow(10, exponent);
  7859. };
  7860. //Easing functions adapted from Robert Penner's easing equations
  7861. //http://www.robertpenner.com/easing/
  7862. var easingEffects = helpers.easingEffects = {
  7863. linear: function(t) {
  7864. return t;
  7865. },
  7866. easeInQuad: function(t) {
  7867. return t * t;
  7868. },
  7869. easeOutQuad: function(t) {
  7870. return -1 * t * (t - 2);
  7871. },
  7872. easeInOutQuad: function(t) {
  7873. if ((t /= 1 / 2) < 1) {
  7874. return 1 / 2 * t * t;
  7875. }
  7876. return -1 / 2 * ((--t) * (t - 2) - 1);
  7877. },
  7878. easeInCubic: function(t) {
  7879. return t * t * t;
  7880. },
  7881. easeOutCubic: function(t) {
  7882. return 1 * ((t = t / 1 - 1) * t * t + 1);
  7883. },
  7884. easeInOutCubic: function(t) {
  7885. if ((t /= 1 / 2) < 1) {
  7886. return 1 / 2 * t * t * t;
  7887. }
  7888. return 1 / 2 * ((t -= 2) * t * t + 2);
  7889. },
  7890. easeInQuart: function(t) {
  7891. return t * t * t * t;
  7892. },
  7893. easeOutQuart: function(t) {
  7894. return -1 * ((t = t / 1 - 1) * t * t * t - 1);
  7895. },
  7896. easeInOutQuart: function(t) {
  7897. if ((t /= 1 / 2) < 1) {
  7898. return 1 / 2 * t * t * t * t;
  7899. }
  7900. return -1 / 2 * ((t -= 2) * t * t * t - 2);
  7901. },
  7902. easeInQuint: function(t) {
  7903. return 1 * (t /= 1) * t * t * t * t;
  7904. },
  7905. easeOutQuint: function(t) {
  7906. return 1 * ((t = t / 1 - 1) * t * t * t * t + 1);
  7907. },
  7908. easeInOutQuint: function(t) {
  7909. if ((t /= 1 / 2) < 1) {
  7910. return 1 / 2 * t * t * t * t * t;
  7911. }
  7912. return 1 / 2 * ((t -= 2) * t * t * t * t + 2);
  7913. },
  7914. easeInSine: function(t) {
  7915. return -1 * Math.cos(t / 1 * (Math.PI / 2)) + 1;
  7916. },
  7917. easeOutSine: function(t) {
  7918. return 1 * Math.sin(t / 1 * (Math.PI / 2));
  7919. },
  7920. easeInOutSine: function(t) {
  7921. return -1 / 2 * (Math.cos(Math.PI * t / 1) - 1);
  7922. },
  7923. easeInExpo: function(t) {
  7924. return (t === 0) ? 1 : 1 * Math.pow(2, 10 * (t / 1 - 1));
  7925. },
  7926. easeOutExpo: function(t) {
  7927. return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1);
  7928. },
  7929. easeInOutExpo: function(t) {
  7930. if (t === 0) {
  7931. return 0;
  7932. }
  7933. if (t === 1) {
  7934. return 1;
  7935. }
  7936. if ((t /= 1 / 2) < 1) {
  7937. return 1 / 2 * Math.pow(2, 10 * (t - 1));
  7938. }
  7939. return 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
  7940. },
  7941. easeInCirc: function(t) {
  7942. if (t >= 1) {
  7943. return t;
  7944. }
  7945. return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1);
  7946. },
  7947. easeOutCirc: function(t) {
  7948. return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t);
  7949. },
  7950. easeInOutCirc: function(t) {
  7951. if ((t /= 1 / 2) < 1) {
  7952. return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
  7953. }
  7954. return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  7955. },
  7956. easeInElastic: function(t) {
  7957. var s = 1.70158;
  7958. var p = 0;
  7959. var a = 1;
  7960. if (t === 0) {
  7961. return 0;
  7962. }
  7963. if ((t /= 1) === 1) {
  7964. return 1;
  7965. }
  7966. if (!p) {
  7967. p = 1 * 0.3;
  7968. }
  7969. if (a < Math.abs(1)) {
  7970. a = 1;
  7971. s = p / 4;
  7972. } else {
  7973. s = p / (2 * Math.PI) * Math.asin(1 / a);
  7974. }
  7975. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  7976. },
  7977. easeOutElastic: function(t) {
  7978. var s = 1.70158;
  7979. var p = 0;
  7980. var a = 1;
  7981. if (t === 0) {
  7982. return 0;
  7983. }
  7984. if ((t /= 1) === 1) {
  7985. return 1;
  7986. }
  7987. if (!p) {
  7988. p = 1 * 0.3;
  7989. }
  7990. if (a < Math.abs(1)) {
  7991. a = 1;
  7992. s = p / 4;
  7993. } else {
  7994. s = p / (2 * Math.PI) * Math.asin(1 / a);
  7995. }
  7996. return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1;
  7997. },
  7998. easeInOutElastic: function(t) {
  7999. var s = 1.70158;
  8000. var p = 0;
  8001. var a = 1;
  8002. if (t === 0) {
  8003. return 0;
  8004. }
  8005. if ((t /= 1 / 2) === 2) {
  8006. return 1;
  8007. }
  8008. if (!p) {
  8009. p = 1 * (0.3 * 1.5);
  8010. }
  8011. if (a < Math.abs(1)) {
  8012. a = 1;
  8013. s = p / 4;
  8014. } else {
  8015. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8016. }
  8017. if (t < 1) {
  8018. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  8019. }
  8020. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1;
  8021. },
  8022. easeInBack: function(t) {
  8023. var s = 1.70158;
  8024. return 1 * (t /= 1) * t * ((s + 1) * t - s);
  8025. },
  8026. easeOutBack: function(t) {
  8027. var s = 1.70158;
  8028. return 1 * ((t = t / 1 - 1) * t * ((s + 1) * t + s) + 1);
  8029. },
  8030. easeInOutBack: function(t) {
  8031. var s = 1.70158;
  8032. if ((t /= 1 / 2) < 1) {
  8033. return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
  8034. }
  8035. return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  8036. },
  8037. easeInBounce: function(t) {
  8038. return 1 - easingEffects.easeOutBounce(1 - t);
  8039. },
  8040. easeOutBounce: function(t) {
  8041. if ((t /= 1) < (1 / 2.75)) {
  8042. return 1 * (7.5625 * t * t);
  8043. } else if (t < (2 / 2.75)) {
  8044. return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
  8045. } else if (t < (2.5 / 2.75)) {
  8046. return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
  8047. } else {
  8048. return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
  8049. }
  8050. },
  8051. easeInOutBounce: function(t) {
  8052. if (t < 1 / 2) {
  8053. return easingEffects.easeInBounce(t * 2) * 0.5;
  8054. }
  8055. return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
  8056. }
  8057. };
  8058. //Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  8059. helpers.requestAnimFrame = (function() {
  8060. return window.requestAnimationFrame ||
  8061. window.webkitRequestAnimationFrame ||
  8062. window.mozRequestAnimationFrame ||
  8063. window.oRequestAnimationFrame ||
  8064. window.msRequestAnimationFrame ||
  8065. function(callback) {
  8066. return window.setTimeout(callback, 1000 / 60);
  8067. };
  8068. })();
  8069. helpers.cancelAnimFrame = (function() {
  8070. return window.cancelAnimationFrame ||
  8071. window.webkitCancelAnimationFrame ||
  8072. window.mozCancelAnimationFrame ||
  8073. window.oCancelAnimationFrame ||
  8074. window.msCancelAnimationFrame ||
  8075. function(callback) {
  8076. return window.clearTimeout(callback, 1000 / 60);
  8077. };
  8078. })();
  8079. //-- DOM methods
  8080. helpers.getRelativePosition = function(evt, chart) {
  8081. var mouseX, mouseY;
  8082. var e = evt.originalEvent || evt,
  8083. canvas = evt.currentTarget || evt.srcElement,
  8084. boundingRect = canvas.getBoundingClientRect();
  8085. var touches = e.touches;
  8086. if (touches && touches.length > 0) {
  8087. mouseX = touches[0].clientX;
  8088. mouseY = touches[0].clientY;
  8089. } else {
  8090. mouseX = e.clientX;
  8091. mouseY = e.clientY;
  8092. }
  8093. // Scale mouse coordinates into canvas coordinates
  8094. // by following the pattern laid out by 'jerryj' in the comments of
  8095. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  8096. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  8097. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  8098. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  8099. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  8100. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  8101. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  8102. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  8103. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  8104. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  8105. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  8106. return {
  8107. x: mouseX,
  8108. y: mouseY
  8109. };
  8110. };
  8111. helpers.addEvent = function(node, eventType, method) {
  8112. if (node.addEventListener) {
  8113. node.addEventListener(eventType, method);
  8114. } else if (node.attachEvent) {
  8115. node.attachEvent("on" + eventType, method);
  8116. } else {
  8117. node["on" + eventType] = method;
  8118. }
  8119. };
  8120. helpers.removeEvent = function(node, eventType, handler) {
  8121. if (node.removeEventListener) {
  8122. node.removeEventListener(eventType, handler, false);
  8123. } else if (node.detachEvent) {
  8124. node.detachEvent("on" + eventType, handler);
  8125. } else {
  8126. node["on" + eventType] = helpers.noop;
  8127. }
  8128. };
  8129. helpers.bindEvents = function(chartInstance, arrayOfEvents, handler) {
  8130. // Create the events object if it's not already present
  8131. var events = chartInstance.events = chartInstance.events || {};
  8132. helpers.each(arrayOfEvents, function(eventName) {
  8133. events[eventName] = function() {
  8134. handler.apply(chartInstance, arguments);
  8135. };
  8136. helpers.addEvent(chartInstance.chart.canvas, eventName, events[eventName]);
  8137. });
  8138. };
  8139. helpers.unbindEvents = function(chartInstance, arrayOfEvents) {
  8140. var canvas = chartInstance.chart.canvas;
  8141. helpers.each(arrayOfEvents, function(handler, eventName) {
  8142. helpers.removeEvent(canvas, eventName, handler);
  8143. });
  8144. };
  8145. // Private helper function to convert max-width/max-height values that may be percentages into a number
  8146. function parseMaxStyle(styleValue, node, parentProperty) {
  8147. var valueInPixels;
  8148. if (typeof(styleValue) === 'string') {
  8149. valueInPixels = parseInt(styleValue, 10);
  8150. if (styleValue.indexOf('%') != -1) {
  8151. // percentage * size in dimension
  8152. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  8153. }
  8154. } else {
  8155. valueInPixels = styleValue;
  8156. }
  8157. return valueInPixels;
  8158. }
  8159. /**
  8160. * Returns if the given value contains an effective constraint.
  8161. * @private
  8162. */
  8163. function isConstrainedValue(value) {
  8164. return value !== undefined && value !== null && value !== 'none';
  8165. }
  8166. // Private helper to get a constraint dimension
  8167. // @param domNode : the node to check the constraint on
  8168. // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
  8169. // @param percentageProperty : property of parent to use when calculating width as a percentage
  8170. // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
  8171. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  8172. var view = document.defaultView;
  8173. var parentNode = domNode.parentNode;
  8174. var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
  8175. var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
  8176. var hasCNode = isConstrainedValue(constrainedNode);
  8177. var hasCContainer = isConstrainedValue(constrainedContainer);
  8178. var infinity = Number.POSITIVE_INFINITY;
  8179. if (hasCNode || hasCContainer) {
  8180. return Math.min(
  8181. hasCNode? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
  8182. hasCContainer? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
  8183. }
  8184. return 'none';
  8185. }
  8186. // returns Number or undefined if no constraint
  8187. helpers.getConstraintWidth = function(domNode) {
  8188. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  8189. };
  8190. // returns Number or undefined if no constraint
  8191. helpers.getConstraintHeight = function(domNode) {
  8192. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  8193. };
  8194. helpers.getMaximumWidth = function(domNode) {
  8195. var container = domNode.parentNode;
  8196. var padding = parseInt(helpers.getStyle(container, 'padding-left')) + parseInt(helpers.getStyle(container, 'padding-right'));
  8197. var w = container.clientWidth - padding;
  8198. var cw = helpers.getConstraintWidth(domNode);
  8199. return isNaN(cw)? w : Math.min(w, cw);
  8200. };
  8201. helpers.getMaximumHeight = function(domNode) {
  8202. var container = domNode.parentNode;
  8203. var padding = parseInt(helpers.getStyle(container, 'padding-top')) + parseInt(helpers.getStyle(container, 'padding-bottom'));
  8204. var h = container.clientHeight - padding;
  8205. var ch = helpers.getConstraintHeight(domNode);
  8206. return isNaN(ch)? h : Math.min(h, ch);
  8207. };
  8208. helpers.getStyle = function(el, property) {
  8209. return el.currentStyle ?
  8210. el.currentStyle[property] :
  8211. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  8212. };
  8213. helpers.retinaScale = function(chart) {
  8214. var ctx = chart.ctx;
  8215. var canvas = chart.canvas;
  8216. var width = canvas.width;
  8217. var height = canvas.height;
  8218. var pixelRatio = chart.currentDevicePixelRatio = window.devicePixelRatio || 1;
  8219. if (pixelRatio !== 1) {
  8220. canvas.height = height * pixelRatio;
  8221. canvas.width = width * pixelRatio;
  8222. ctx.scale(pixelRatio, pixelRatio);
  8223. // Store the device pixel ratio so that we can go backwards in `destroy`.
  8224. // The devicePixelRatio changes with zoom, so there are no guarantees that it is the same
  8225. // when destroy is called
  8226. chart.originalDevicePixelRatio = chart.originalDevicePixelRatio || pixelRatio;
  8227. }
  8228. canvas.style.width = width + 'px';
  8229. canvas.style.height = height + 'px';
  8230. };
  8231. //-- Canvas methods
  8232. helpers.clear = function(chart) {
  8233. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  8234. };
  8235. helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
  8236. return fontStyle + " " + pixelSize + "px " + fontFamily;
  8237. };
  8238. helpers.longestText = function(ctx, font, arrayOfThings, cache) {
  8239. cache = cache || {};
  8240. var data = cache.data = cache.data || {};
  8241. var gc = cache.garbageCollect = cache.garbageCollect || [];
  8242. if (cache.font !== font) {
  8243. data = cache.data = {};
  8244. gc = cache.garbageCollect = [];
  8245. cache.font = font;
  8246. }
  8247. ctx.font = font;
  8248. var longest = 0;
  8249. helpers.each(arrayOfThings, function(thing) {
  8250. // Undefined strings and arrays should not be measured
  8251. if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
  8252. longest = helpers.measureText(ctx, data, gc, longest, thing);
  8253. } else if (helpers.isArray(thing)) {
  8254. // if it is an array lets measure each element
  8255. // to do maybe simplify this function a bit so we can do this more recursively?
  8256. helpers.each(thing, function(nestedThing) {
  8257. // Undefined strings and arrays should not be measured
  8258. if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
  8259. longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
  8260. }
  8261. });
  8262. }
  8263. });
  8264. var gcLen = gc.length / 2;
  8265. if (gcLen > arrayOfThings.length) {
  8266. for (var i = 0; i < gcLen; i++) {
  8267. delete data[gc[i]];
  8268. }
  8269. gc.splice(0, gcLen);
  8270. }
  8271. return longest;
  8272. };
  8273. helpers.measureText = function (ctx, data, gc, longest, string) {
  8274. var textWidth = data[string];
  8275. if (!textWidth) {
  8276. textWidth = data[string] = ctx.measureText(string).width;
  8277. gc.push(string);
  8278. }
  8279. if (textWidth > longest) {
  8280. longest = textWidth;
  8281. }
  8282. return longest;
  8283. };
  8284. helpers.numberOfLabelLines = function(arrayOfThings) {
  8285. var numberOfLines = 1;
  8286. helpers.each(arrayOfThings, function(thing) {
  8287. if (helpers.isArray(thing)) {
  8288. if (thing.length > numberOfLines) {
  8289. numberOfLines = thing.length;
  8290. }
  8291. }
  8292. });
  8293. return numberOfLines;
  8294. };
  8295. helpers.drawRoundedRectangle = function(ctx, x, y, width, height, radius) {
  8296. ctx.beginPath();
  8297. ctx.moveTo(x + radius, y);
  8298. ctx.lineTo(x + width - radius, y);
  8299. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  8300. ctx.lineTo(x + width, y + height - radius);
  8301. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  8302. ctx.lineTo(x + radius, y + height);
  8303. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  8304. ctx.lineTo(x, y + radius);
  8305. ctx.quadraticCurveTo(x, y, x + radius, y);
  8306. ctx.closePath();
  8307. };
  8308. helpers.color = function(c) {
  8309. if (!color) {
  8310. console.log('Color.js not found!');
  8311. return c;
  8312. }
  8313. /* global CanvasGradient */
  8314. if (c instanceof CanvasGradient) {
  8315. return color(Chart.defaults.global.defaultColor);
  8316. }
  8317. return color(c);
  8318. };
  8319. helpers.addResizeListener = function(node, callback) {
  8320. // Hide an iframe before the node
  8321. var hiddenIframe = document.createElement('iframe');
  8322. var hiddenIframeClass = 'chartjs-hidden-iframe';
  8323. if (hiddenIframe.classlist) {
  8324. // can use classlist
  8325. hiddenIframe.classlist.add(hiddenIframeClass);
  8326. } else {
  8327. hiddenIframe.setAttribute('class', hiddenIframeClass);
  8328. }
  8329. // Set the style
  8330. var style = hiddenIframe.style;
  8331. style.width = '100%';
  8332. style.display = 'block';
  8333. style.border = 0;
  8334. style.height = 0;
  8335. style.margin = 0;
  8336. style.position = 'absolute';
  8337. style.left = 0;
  8338. style.right = 0;
  8339. style.top = 0;
  8340. style.bottom = 0;
  8341. // Insert the iframe so that contentWindow is available
  8342. node.insertBefore(hiddenIframe, node.firstChild);
  8343. (hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
  8344. if (callback) {
  8345. callback();
  8346. }
  8347. };
  8348. };
  8349. helpers.removeResizeListener = function(node) {
  8350. var hiddenIframe = node.querySelector('.chartjs-hidden-iframe');
  8351. // Remove the resize detect iframe
  8352. if (hiddenIframe) {
  8353. hiddenIframe.parentNode.removeChild(hiddenIframe);
  8354. }
  8355. };
  8356. helpers.isArray = Array.isArray?
  8357. function(obj) { return Array.isArray(obj); } :
  8358. function(obj) {
  8359. return Object.prototype.toString.call(obj) === '[object Array]';
  8360. };
  8361. //! @see http://stackoverflow.com/a/14853974
  8362. helpers.arrayEquals = function(a0, a1) {
  8363. var i, ilen, v0, v1;
  8364. if (!a0 || !a1 || a0.length != a1.length) {
  8365. return false;
  8366. }
  8367. for (i = 0, ilen=a0.length; i < ilen; ++i) {
  8368. v0 = a0[i];
  8369. v1 = a1[i];
  8370. if (v0 instanceof Array && v1 instanceof Array) {
  8371. if (!helpers.arrayEquals(v0, v1)) {
  8372. return false;
  8373. }
  8374. } else if (v0 != v1) {
  8375. // NOTE: two different object instances will never be equal: {x:20} != {x:20}
  8376. return false;
  8377. }
  8378. }
  8379. return true;
  8380. };
  8381. helpers.callCallback = function(fn, args, _tArg) {
  8382. if (fn && typeof fn.call === 'function') {
  8383. fn.apply(_tArg, args);
  8384. }
  8385. };
  8386. helpers.getHoverColor = function(color) {
  8387. /* global CanvasPattern */
  8388. return (color instanceof CanvasPattern) ?
  8389. color :
  8390. helpers.color(color).saturate(0.5).darken(0.1).rgbString();
  8391. };
  8392. };
  8393. },{"2":2}],27:[function(require,module,exports){
  8394. "use strict";
  8395. module.exports = function() {
  8396. //Occupy the global variable of Chart, and create a simple base class
  8397. var Chart = function(context, config) {
  8398. var me = this;
  8399. var helpers = Chart.helpers;
  8400. me.config = config || {
  8401. data: {
  8402. datasets: []
  8403. }
  8404. };
  8405. // Support a jQuery'd canvas element
  8406. if (context.length && context[0].getContext) {
  8407. context = context[0];
  8408. }
  8409. // Support a canvas domnode
  8410. if (context.getContext) {
  8411. context = context.getContext("2d");
  8412. }
  8413. me.ctx = context;
  8414. me.canvas = context.canvas;
  8415. context.canvas.style.display = context.canvas.style.display || 'block';
  8416. // Figure out what the size of the chart will be.
  8417. // If the canvas has a specified width and height, we use those else
  8418. // we look to see if the canvas node has a CSS width and height.
  8419. // If there is still no height, fill the parent container
  8420. me.width = context.canvas.width || parseInt(helpers.getStyle(context.canvas, 'width'), 10) || helpers.getMaximumWidth(context.canvas);
  8421. me.height = context.canvas.height || parseInt(helpers.getStyle(context.canvas, 'height'), 10) || helpers.getMaximumHeight(context.canvas);
  8422. me.aspectRatio = me.width / me.height;
  8423. if (isNaN(me.aspectRatio) || isFinite(me.aspectRatio) === false) {
  8424. // If the canvas has no size, try and figure out what the aspect ratio will be.
  8425. // Some charts prefer square canvases (pie, radar, etc). If that is specified, use that
  8426. // else use the canvas default ratio of 2
  8427. me.aspectRatio = config.aspectRatio !== undefined ? config.aspectRatio : 2;
  8428. }
  8429. // Store the original style of the element so we can set it back
  8430. me.originalCanvasStyleWidth = context.canvas.style.width;
  8431. me.originalCanvasStyleHeight = context.canvas.style.height;
  8432. // High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale.
  8433. helpers.retinaScale(me);
  8434. me.controller = new Chart.Controller(me);
  8435. // Always bind this so that if the responsive state changes we still work
  8436. helpers.addResizeListener(context.canvas.parentNode, function() {
  8437. if (me.controller && me.controller.config.options.responsive) {
  8438. me.controller.resize();
  8439. }
  8440. });
  8441. return me.controller ? me.controller : me;
  8442. };
  8443. //Globally expose the defaults to allow for user updating/changing
  8444. Chart.defaults = {
  8445. global: {
  8446. responsive: true,
  8447. responsiveAnimationDuration: 0,
  8448. maintainAspectRatio: true,
  8449. events: ["mousemove", "mouseout", "click", "touchstart", "touchmove"],
  8450. hover: {
  8451. onHover: null,
  8452. mode: 'single',
  8453. animationDuration: 400
  8454. },
  8455. onClick: null,
  8456. defaultColor: 'rgba(0,0,0,0.1)',
  8457. defaultFontColor: '#666',
  8458. defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  8459. defaultFontSize: 12,
  8460. defaultFontStyle: 'normal',
  8461. showLines: true,
  8462. // Element defaults defined in element extensions
  8463. elements: {},
  8464. // Legend callback string
  8465. legendCallback: function(chart) {
  8466. var text = [];
  8467. text.push('<ul class="' + chart.id + '-legend">');
  8468. for (var i = 0; i < chart.data.datasets.length; i++) {
  8469. text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
  8470. if (chart.data.datasets[i].label) {
  8471. text.push(chart.data.datasets[i].label);
  8472. }
  8473. text.push('</li>');
  8474. }
  8475. text.push('</ul>');
  8476. return text.join("");
  8477. }
  8478. }
  8479. };
  8480. Chart.Chart = Chart;
  8481. return Chart;
  8482. };
  8483. },{}],28:[function(require,module,exports){
  8484. "use strict";
  8485. module.exports = function(Chart) {
  8486. var helpers = Chart.helpers;
  8487. // The layout service is very self explanatory. It's responsible for the layout within a chart.
  8488. // Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
  8489. // It is this service's responsibility of carrying out that layout.
  8490. Chart.layoutService = {
  8491. defaults: {},
  8492. // Register a box to a chartInstance. A box is simply a reference to an object that requires layout. eg. Scales, Legend, Plugins.
  8493. addBox: function(chartInstance, box) {
  8494. if (!chartInstance.boxes) {
  8495. chartInstance.boxes = [];
  8496. }
  8497. chartInstance.boxes.push(box);
  8498. },
  8499. removeBox: function(chartInstance, box) {
  8500. if (!chartInstance.boxes) {
  8501. return;
  8502. }
  8503. chartInstance.boxes.splice(chartInstance.boxes.indexOf(box), 1);
  8504. },
  8505. // The most important function
  8506. update: function(chartInstance, width, height) {
  8507. if (!chartInstance) {
  8508. return;
  8509. }
  8510. var xPadding = 0;
  8511. var yPadding = 0;
  8512. var leftBoxes = helpers.where(chartInstance.boxes, function(box) {
  8513. return box.options.position === "left";
  8514. });
  8515. var rightBoxes = helpers.where(chartInstance.boxes, function(box) {
  8516. return box.options.position === "right";
  8517. });
  8518. var topBoxes = helpers.where(chartInstance.boxes, function(box) {
  8519. return box.options.position === "top";
  8520. });
  8521. var bottomBoxes = helpers.where(chartInstance.boxes, function(box) {
  8522. return box.options.position === "bottom";
  8523. });
  8524. // Boxes that overlay the chartarea such as the radialLinear scale
  8525. var chartAreaBoxes = helpers.where(chartInstance.boxes, function(box) {
  8526. return box.options.position === "chartArea";
  8527. });
  8528. // Ensure that full width boxes are at the very top / bottom
  8529. topBoxes.sort(function(a, b) {
  8530. return (b.options.fullWidth ? 1 : 0) - (a.options.fullWidth ? 1 : 0);
  8531. });
  8532. bottomBoxes.sort(function(a, b) {
  8533. return (a.options.fullWidth ? 1 : 0) - (b.options.fullWidth ? 1 : 0);
  8534. });
  8535. // Essentially we now have any number of boxes on each of the 4 sides.
  8536. // Our canvas looks like the following.
  8537. // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
  8538. // B1 is the bottom axis
  8539. // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
  8540. // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
  8541. // an error will be thrown.
  8542. //
  8543. // |----------------------------------------------------|
  8544. // | T1 (Full Width) |
  8545. // |----------------------------------------------------|
  8546. // | | | T2 | |
  8547. // | |----|-------------------------------------|----|
  8548. // | | | C1 | | C2 | |
  8549. // | | |----| |----| |
  8550. // | | | | |
  8551. // | L1 | L2 | ChartArea (C0) | R1 |
  8552. // | | | | |
  8553. // | | |----| |----| |
  8554. // | | | C3 | | C4 | |
  8555. // | |----|-------------------------------------|----|
  8556. // | | | B1 | |
  8557. // |----------------------------------------------------|
  8558. // | B2 (Full Width) |
  8559. // |----------------------------------------------------|
  8560. //
  8561. // What we do to find the best sizing, we do the following
  8562. // 1. Determine the minimum size of the chart area.
  8563. // 2. Split the remaining width equally between each vertical axis
  8564. // 3. Split the remaining height equally between each horizontal axis
  8565. // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
  8566. // 5. Adjust the sizes of each axis based on it's minimum reported size.
  8567. // 6. Refit each axis
  8568. // 7. Position each axis in the final location
  8569. // 8. Tell the chart the final location of the chart area
  8570. // 9. Tell any axes that overlay the chart area the positions of the chart area
  8571. // Step 1
  8572. var chartWidth = width - (2 * xPadding);
  8573. var chartHeight = height - (2 * yPadding);
  8574. var chartAreaWidth = chartWidth / 2; // min 50%
  8575. var chartAreaHeight = chartHeight / 2; // min 50%
  8576. // Step 2
  8577. var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
  8578. // Step 3
  8579. var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
  8580. // Step 4
  8581. var maxChartAreaWidth = chartWidth;
  8582. var maxChartAreaHeight = chartHeight;
  8583. var minBoxSizes = [];
  8584. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  8585. function getMinimumBoxSize(box) {
  8586. var minSize;
  8587. var isHorizontal = box.isHorizontal();
  8588. if (isHorizontal) {
  8589. minSize = box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  8590. maxChartAreaHeight -= minSize.height;
  8591. } else {
  8592. minSize = box.update(verticalBoxWidth, chartAreaHeight);
  8593. maxChartAreaWidth -= minSize.width;
  8594. }
  8595. minBoxSizes.push({
  8596. horizontal: isHorizontal,
  8597. minSize: minSize,
  8598. box: box
  8599. });
  8600. }
  8601. // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
  8602. // be if the axes are drawn at their minimum sizes.
  8603. // Steps 5 & 6
  8604. var totalLeftBoxesWidth = xPadding;
  8605. var totalRightBoxesWidth = xPadding;
  8606. var totalTopBoxesHeight = yPadding;
  8607. var totalBottomBoxesHeight = yPadding;
  8608. // Update, and calculate the left and right margins for the horizontal boxes
  8609. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  8610. helpers.each(leftBoxes, function(box) {
  8611. totalLeftBoxesWidth += box.width;
  8612. });
  8613. helpers.each(rightBoxes, function(box) {
  8614. totalRightBoxesWidth += box.width;
  8615. });
  8616. // Set the Left and Right margins for the horizontal boxes
  8617. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  8618. // Function to fit a box
  8619. function fitBox(box) {
  8620. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
  8621. return minBoxSize.box === box;
  8622. });
  8623. if (minBoxSize) {
  8624. if (box.isHorizontal()) {
  8625. var scaleMargin = {
  8626. left: totalLeftBoxesWidth,
  8627. right: totalRightBoxesWidth,
  8628. top: 0,
  8629. bottom: 0
  8630. };
  8631. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  8632. // on the margin. Sometimes they need to increase in size slightly
  8633. box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  8634. } else {
  8635. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  8636. }
  8637. }
  8638. }
  8639. // Figure out how much margin is on the top and bottom of the vertical boxes
  8640. helpers.each(topBoxes, function(box) {
  8641. totalTopBoxesHeight += box.height;
  8642. });
  8643. helpers.each(bottomBoxes, function(box) {
  8644. totalBottomBoxesHeight += box.height;
  8645. });
  8646. // Let the left layout know the final margin
  8647. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  8648. function finalFitVerticalBox(box) {
  8649. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
  8650. return minBoxSize.box === box;
  8651. });
  8652. var scaleMargin = {
  8653. left: 0,
  8654. right: 0,
  8655. top: totalTopBoxesHeight,
  8656. bottom: totalBottomBoxesHeight
  8657. };
  8658. if (minBoxSize) {
  8659. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  8660. }
  8661. }
  8662. // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
  8663. totalLeftBoxesWidth = xPadding;
  8664. totalRightBoxesWidth = xPadding;
  8665. totalTopBoxesHeight = yPadding;
  8666. totalBottomBoxesHeight = yPadding;
  8667. helpers.each(leftBoxes, function(box) {
  8668. totalLeftBoxesWidth += box.width;
  8669. });
  8670. helpers.each(rightBoxes, function(box) {
  8671. totalRightBoxesWidth += box.width;
  8672. });
  8673. helpers.each(topBoxes, function(box) {
  8674. totalTopBoxesHeight += box.height;
  8675. });
  8676. helpers.each(bottomBoxes, function(box) {
  8677. totalBottomBoxesHeight += box.height;
  8678. });
  8679. // Figure out if our chart area changed. This would occur if the dataset layout label rotation
  8680. // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
  8681. // without calling `fit` again
  8682. var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
  8683. var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
  8684. if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
  8685. helpers.each(leftBoxes, function(box) {
  8686. box.height = newMaxChartAreaHeight;
  8687. });
  8688. helpers.each(rightBoxes, function(box) {
  8689. box.height = newMaxChartAreaHeight;
  8690. });
  8691. helpers.each(topBoxes, function(box) {
  8692. if (!box.options.fullWidth) {
  8693. box.width = newMaxChartAreaWidth;
  8694. }
  8695. });
  8696. helpers.each(bottomBoxes, function(box) {
  8697. if (!box.options.fullWidth) {
  8698. box.width = newMaxChartAreaWidth;
  8699. }
  8700. });
  8701. maxChartAreaHeight = newMaxChartAreaHeight;
  8702. maxChartAreaWidth = newMaxChartAreaWidth;
  8703. }
  8704. // Step 7 - Position the boxes
  8705. var left = xPadding;
  8706. var top = yPadding;
  8707. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  8708. // Account for chart width and height
  8709. left += maxChartAreaWidth;
  8710. top += maxChartAreaHeight;
  8711. helpers.each(rightBoxes, placeBox);
  8712. helpers.each(bottomBoxes, placeBox);
  8713. function placeBox(box) {
  8714. if (box.isHorizontal()) {
  8715. box.left = box.options.fullWidth ? xPadding : totalLeftBoxesWidth;
  8716. box.right = box.options.fullWidth ? width - xPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  8717. box.top = top;
  8718. box.bottom = top + box.height;
  8719. // Move to next point
  8720. top = box.bottom;
  8721. } else {
  8722. box.left = left;
  8723. box.right = left + box.width;
  8724. box.top = totalTopBoxesHeight;
  8725. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  8726. // Move to next point
  8727. left = box.right;
  8728. }
  8729. }
  8730. // Step 8
  8731. chartInstance.chartArea = {
  8732. left: totalLeftBoxesWidth,
  8733. top: totalTopBoxesHeight,
  8734. right: totalLeftBoxesWidth + maxChartAreaWidth,
  8735. bottom: totalTopBoxesHeight + maxChartAreaHeight
  8736. };
  8737. // Step 9
  8738. helpers.each(chartAreaBoxes, function(box) {
  8739. box.left = chartInstance.chartArea.left;
  8740. box.top = chartInstance.chartArea.top;
  8741. box.right = chartInstance.chartArea.right;
  8742. box.bottom = chartInstance.chartArea.bottom;
  8743. box.update(maxChartAreaWidth, maxChartAreaHeight);
  8744. });
  8745. }
  8746. };
  8747. };
  8748. },{}],29:[function(require,module,exports){
  8749. "use strict";
  8750. module.exports = function(Chart) {
  8751. var helpers = Chart.helpers;
  8752. var noop = helpers.noop;
  8753. Chart.defaults.global.legend = {
  8754. display: true,
  8755. position: 'top',
  8756. fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
  8757. reverse: false,
  8758. // a callback that will handle
  8759. onClick: function(e, legendItem) {
  8760. var index = legendItem.datasetIndex;
  8761. var ci = this.chart;
  8762. var meta = ci.getDatasetMeta(index);
  8763. // See controller.isDatasetVisible comment
  8764. meta.hidden = meta.hidden === null? !ci.data.datasets[index].hidden : null;
  8765. // We hid a dataset ... rerender the chart
  8766. ci.update();
  8767. },
  8768. labels: {
  8769. boxWidth: 40,
  8770. padding: 10,
  8771. // Generates labels shown in the legend
  8772. // Valid properties to return:
  8773. // text : text to display
  8774. // fillStyle : fill of coloured box
  8775. // strokeStyle: stroke of coloured box
  8776. // hidden : if this legend item refers to a hidden item
  8777. // lineCap : cap style for line
  8778. // lineDash
  8779. // lineDashOffset :
  8780. // lineJoin :
  8781. // lineWidth :
  8782. generateLabels: function(chart) {
  8783. var data = chart.data;
  8784. return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
  8785. return {
  8786. text: dataset.label,
  8787. fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
  8788. hidden: !chart.isDatasetVisible(i),
  8789. lineCap: dataset.borderCapStyle,
  8790. lineDash: dataset.borderDash,
  8791. lineDashOffset: dataset.borderDashOffset,
  8792. lineJoin: dataset.borderJoinStyle,
  8793. lineWidth: dataset.borderWidth,
  8794. strokeStyle: dataset.borderColor,
  8795. pointStyle: dataset.pointStyle,
  8796. // Below is extra data used for toggling the datasets
  8797. datasetIndex: i
  8798. };
  8799. }, this) : [];
  8800. }
  8801. }
  8802. };
  8803. Chart.Legend = Chart.Element.extend({
  8804. initialize: function(config) {
  8805. helpers.extend(this, config);
  8806. // Contains hit boxes for each dataset (in dataset order)
  8807. this.legendHitBoxes = [];
  8808. // Are we in doughnut mode which has a different data type
  8809. this.doughnutMode = false;
  8810. },
  8811. // These methods are ordered by lifecyle. Utilities then follow.
  8812. // Any function defined here is inherited by all legend types.
  8813. // Any function can be extended by the legend type
  8814. beforeUpdate: noop,
  8815. update: function(maxWidth, maxHeight, margins) {
  8816. var me = this;
  8817. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  8818. me.beforeUpdate();
  8819. // Absorb the master measurements
  8820. me.maxWidth = maxWidth;
  8821. me.maxHeight = maxHeight;
  8822. me.margins = margins;
  8823. // Dimensions
  8824. me.beforeSetDimensions();
  8825. me.setDimensions();
  8826. me.afterSetDimensions();
  8827. // Labels
  8828. me.beforeBuildLabels();
  8829. me.buildLabels();
  8830. me.afterBuildLabels();
  8831. // Fit
  8832. me.beforeFit();
  8833. me.fit();
  8834. me.afterFit();
  8835. //
  8836. me.afterUpdate();
  8837. return me.minSize;
  8838. },
  8839. afterUpdate: noop,
  8840. //
  8841. beforeSetDimensions: noop,
  8842. setDimensions: function() {
  8843. var me = this;
  8844. // Set the unconstrained dimension before label rotation
  8845. if (me.isHorizontal()) {
  8846. // Reset position before calculating rotation
  8847. me.width = me.maxWidth;
  8848. me.left = 0;
  8849. me.right = me.width;
  8850. } else {
  8851. me.height = me.maxHeight;
  8852. // Reset position before calculating rotation
  8853. me.top = 0;
  8854. me.bottom = me.height;
  8855. }
  8856. // Reset padding
  8857. me.paddingLeft = 0;
  8858. me.paddingTop = 0;
  8859. me.paddingRight = 0;
  8860. me.paddingBottom = 0;
  8861. // Reset minSize
  8862. me.minSize = {
  8863. width: 0,
  8864. height: 0
  8865. };
  8866. },
  8867. afterSetDimensions: noop,
  8868. //
  8869. beforeBuildLabels: noop,
  8870. buildLabels: function() {
  8871. var me = this;
  8872. me.legendItems = me.options.labels.generateLabels.call(me, me.chart);
  8873. if(me.options.reverse){
  8874. me.legendItems.reverse();
  8875. }
  8876. },
  8877. afterBuildLabels: noop,
  8878. //
  8879. beforeFit: noop,
  8880. fit: function() {
  8881. var me = this;
  8882. var opts = me.options;
  8883. var labelOpts = opts.labels;
  8884. var display = opts.display;
  8885. var ctx = me.ctx;
  8886. var globalDefault = Chart.defaults.global,
  8887. itemOrDefault = helpers.getValueOrDefault,
  8888. fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize),
  8889. fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle),
  8890. fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily),
  8891. labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  8892. // Reset hit boxes
  8893. var hitboxes = me.legendHitBoxes = [];
  8894. var minSize = me.minSize;
  8895. var isHorizontal = me.isHorizontal();
  8896. if (isHorizontal) {
  8897. minSize.width = me.maxWidth; // fill all the width
  8898. minSize.height = display ? 10 : 0;
  8899. } else {
  8900. minSize.width = display ? 10 : 0;
  8901. minSize.height = me.maxHeight; // fill all the height
  8902. }
  8903. // Increase sizes here
  8904. if (display) {
  8905. ctx.font = labelFont;
  8906. if (isHorizontal) {
  8907. // Labels
  8908. // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
  8909. var lineWidths = me.lineWidths = [0];
  8910. var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0;
  8911. ctx.textAlign = "left";
  8912. ctx.textBaseline = 'top';
  8913. helpers.each(me.legendItems, function(legendItem, i) {
  8914. var boxWidth = labelOpts.usePointStyle ?
  8915. fontSize * Math.sqrt(2) :
  8916. labelOpts.boxWidth;
  8917. var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  8918. if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= me.width) {
  8919. totalHeight += fontSize + (labelOpts.padding);
  8920. lineWidths[lineWidths.length] = me.left;
  8921. }
  8922. // Store the hitbox width and height here. Final position will be updated in `draw`
  8923. hitboxes[i] = {
  8924. left: 0,
  8925. top: 0,
  8926. width: width,
  8927. height: fontSize
  8928. };
  8929. lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
  8930. });
  8931. minSize.height += totalHeight;
  8932. } else {
  8933. var vPadding = labelOpts.padding;
  8934. var columnWidths = me.columnWidths = [];
  8935. var totalWidth = labelOpts.padding;
  8936. var currentColWidth = 0;
  8937. var currentColHeight = 0;
  8938. var itemHeight = fontSize + vPadding;
  8939. helpers.each(me.legendItems, function(legendItem, i) {
  8940. // If usePointStyle is set, multiple boxWidth by 2 since it represents
  8941. // the radius and not truly the width
  8942. var boxWidth = labelOpts.usePointStyle ? 2 * labelOpts.boxWidth : labelOpts.boxWidth;
  8943. var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  8944. // If too tall, go to new column
  8945. if (currentColHeight + itemHeight > minSize.height) {
  8946. totalWidth += currentColWidth + labelOpts.padding;
  8947. columnWidths.push(currentColWidth); // previous column width
  8948. currentColWidth = 0;
  8949. currentColHeight = 0;
  8950. }
  8951. // Get max width
  8952. currentColWidth = Math.max(currentColWidth, itemWidth);
  8953. currentColHeight += itemHeight;
  8954. // Store the hitbox width and height here. Final position will be updated in `draw`
  8955. hitboxes[i] = {
  8956. left: 0,
  8957. top: 0,
  8958. width: itemWidth,
  8959. height: fontSize
  8960. };
  8961. });
  8962. totalWidth += currentColWidth;
  8963. columnWidths.push(currentColWidth);
  8964. minSize.width += totalWidth;
  8965. }
  8966. }
  8967. me.width = minSize.width;
  8968. me.height = minSize.height;
  8969. },
  8970. afterFit: noop,
  8971. // Shared Methods
  8972. isHorizontal: function() {
  8973. return this.options.position === "top" || this.options.position === "bottom";
  8974. },
  8975. // Actualy draw the legend on the canvas
  8976. draw: function() {
  8977. var me = this;
  8978. var opts = me.options;
  8979. var labelOpts = opts.labels;
  8980. var globalDefault = Chart.defaults.global,
  8981. lineDefault = globalDefault.elements.line,
  8982. legendWidth = me.width,
  8983. lineWidths = me.lineWidths;
  8984. if (opts.display) {
  8985. var ctx = me.ctx,
  8986. cursor,
  8987. itemOrDefault = helpers.getValueOrDefault,
  8988. fontColor = itemOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor),
  8989. fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize),
  8990. fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle),
  8991. fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily),
  8992. labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  8993. // Canvas setup
  8994. ctx.textAlign = "left";
  8995. ctx.textBaseline = 'top';
  8996. ctx.lineWidth = 0.5;
  8997. ctx.strokeStyle = fontColor; // for strikethrough effect
  8998. ctx.fillStyle = fontColor; // render in correct colour
  8999. ctx.font = labelFont;
  9000. var boxWidth = labelOpts.boxWidth,
  9001. hitboxes = me.legendHitBoxes;
  9002. // current position
  9003. var drawLegendBox = function(x, y, legendItem) {
  9004. if (isNaN(boxWidth) || boxWidth <= 0) {
  9005. return;
  9006. }
  9007. // Set the ctx for the box
  9008. ctx.save();
  9009. ctx.fillStyle = itemOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
  9010. ctx.lineCap = itemOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
  9011. ctx.lineDashOffset = itemOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
  9012. ctx.lineJoin = itemOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
  9013. ctx.lineWidth = itemOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
  9014. ctx.strokeStyle = itemOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
  9015. if (ctx.setLineDash) {
  9016. // IE 9 and 10 do not support line dash
  9017. ctx.setLineDash(itemOrDefault(legendItem.lineDash, lineDefault.borderDash));
  9018. }
  9019. if (opts.labels && opts.labels.usePointStyle) {
  9020. // Recalulate x and y for drawPoint() because its expecting
  9021. // x and y to be center of figure (instead of top left)
  9022. var radius = fontSize * Math.SQRT2 / 2;
  9023. var offSet = radius / Math.SQRT2;
  9024. var centerX = x + offSet;
  9025. var centerY = y + offSet;
  9026. // Draw pointStyle as legend symbol
  9027. Chart.canvasHelpers.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
  9028. }
  9029. else {
  9030. // Draw box as legend symbol
  9031. ctx.strokeRect(x, y, boxWidth, fontSize);
  9032. ctx.fillRect(x, y, boxWidth, fontSize);
  9033. }
  9034. ctx.restore();
  9035. };
  9036. var fillText = function(x, y, legendItem, textWidth) {
  9037. ctx.fillText(legendItem.text, boxWidth + (fontSize / 2) + x, y);
  9038. if (legendItem.hidden) {
  9039. // Strikethrough the text if hidden
  9040. ctx.beginPath();
  9041. ctx.lineWidth = 2;
  9042. ctx.moveTo(boxWidth + (fontSize / 2) + x, y + (fontSize / 2));
  9043. ctx.lineTo(boxWidth + (fontSize / 2) + x + textWidth, y + (fontSize / 2));
  9044. ctx.stroke();
  9045. }
  9046. };
  9047. // Horizontal
  9048. var isHorizontal = me.isHorizontal();
  9049. if (isHorizontal) {
  9050. cursor = {
  9051. x: me.left + ((legendWidth - lineWidths[0]) / 2),
  9052. y: me.top + labelOpts.padding,
  9053. line: 0
  9054. };
  9055. } else {
  9056. cursor = {
  9057. x: me.left + labelOpts.padding,
  9058. y: me.top + labelOpts.padding,
  9059. line: 0
  9060. };
  9061. }
  9062. var itemHeight = fontSize + labelOpts.padding;
  9063. helpers.each(me.legendItems, function(legendItem, i) {
  9064. var textWidth = ctx.measureText(legendItem.text).width,
  9065. width = labelOpts.usePointStyle ?
  9066. fontSize + (fontSize / 2) + textWidth :
  9067. boxWidth + (fontSize / 2) + textWidth,
  9068. x = cursor.x,
  9069. y = cursor.y;
  9070. if (isHorizontal) {
  9071. if (x + width >= legendWidth) {
  9072. y = cursor.y += itemHeight;
  9073. cursor.line++;
  9074. x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
  9075. }
  9076. } else {
  9077. if (y + itemHeight > me.bottom) {
  9078. x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
  9079. y = cursor.y = me.top;
  9080. cursor.line++;
  9081. }
  9082. }
  9083. drawLegendBox(x, y, legendItem);
  9084. hitboxes[i].left = x;
  9085. hitboxes[i].top = y;
  9086. // Fill the actual label
  9087. fillText(x, y, legendItem, textWidth);
  9088. if (isHorizontal) {
  9089. cursor.x += width + (labelOpts.padding);
  9090. } else {
  9091. cursor.y += itemHeight;
  9092. }
  9093. });
  9094. }
  9095. },
  9096. // Handle an event
  9097. handleEvent: function(e) {
  9098. var me = this;
  9099. var position = helpers.getRelativePosition(e, me.chart.chart),
  9100. x = position.x,
  9101. y = position.y,
  9102. opts = me.options;
  9103. if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
  9104. // See if we are touching one of the dataset boxes
  9105. var lh = me.legendHitBoxes;
  9106. for (var i = 0; i < lh.length; ++i) {
  9107. var hitBox = lh[i];
  9108. if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
  9109. // Touching an element
  9110. if (opts.onClick) {
  9111. opts.onClick.call(me, e, me.legendItems[i]);
  9112. }
  9113. break;
  9114. }
  9115. }
  9116. }
  9117. }
  9118. });
  9119. // Register the legend plugin
  9120. Chart.plugins.register({
  9121. beforeInit: function(chartInstance) {
  9122. var opts = chartInstance.options;
  9123. var legendOpts = opts.legend;
  9124. if (legendOpts) {
  9125. chartInstance.legend = new Chart.Legend({
  9126. ctx: chartInstance.chart.ctx,
  9127. options: legendOpts,
  9128. chart: chartInstance
  9129. });
  9130. Chart.layoutService.addBox(chartInstance, chartInstance.legend);
  9131. }
  9132. }
  9133. });
  9134. };
  9135. },{}],30:[function(require,module,exports){
  9136. "use strict";
  9137. module.exports = function(Chart) {
  9138. var noop = Chart.helpers.noop;
  9139. /**
  9140. * The plugin service singleton
  9141. * @namespace Chart.plugins
  9142. * @since 2.1.0
  9143. */
  9144. Chart.plugins = {
  9145. _plugins: [],
  9146. /**
  9147. * Registers the given plugin(s) if not already registered.
  9148. * @param {Array|Object} plugins plugin instance(s).
  9149. */
  9150. register: function(plugins) {
  9151. var p = this._plugins;
  9152. ([]).concat(plugins).forEach(function(plugin) {
  9153. if (p.indexOf(plugin) === -1) {
  9154. p.push(plugin);
  9155. }
  9156. });
  9157. },
  9158. /**
  9159. * Unregisters the given plugin(s) only if registered.
  9160. * @param {Array|Object} plugins plugin instance(s).
  9161. */
  9162. unregister: function(plugins) {
  9163. var p = this._plugins;
  9164. ([]).concat(plugins).forEach(function(plugin) {
  9165. var idx = p.indexOf(plugin);
  9166. if (idx !== -1) {
  9167. p.splice(idx, 1);
  9168. }
  9169. });
  9170. },
  9171. /**
  9172. * Remove all registered p^lugins.
  9173. * @since 2.1.5
  9174. */
  9175. clear: function() {
  9176. this._plugins = [];
  9177. },
  9178. /**
  9179. * Returns the number of registered plugins?
  9180. * @returns {Number}
  9181. * @since 2.1.5
  9182. */
  9183. count: function() {
  9184. return this._plugins.length;
  9185. },
  9186. /**
  9187. * Returns all registered plugin intances.
  9188. * @returns {Array} array of plugin objects.
  9189. * @since 2.1.5
  9190. */
  9191. getAll: function() {
  9192. return this._plugins;
  9193. },
  9194. /**
  9195. * Calls registered plugins on the specified extension, with the given args. This
  9196. * method immediately returns as soon as a plugin explicitly returns false. The
  9197. * returned value can be used, for instance, to interrupt the current action.
  9198. * @param {String} extension the name of the plugin method to call (e.g. 'beforeUpdate').
  9199. * @param {Array} [args] extra arguments to apply to the extension call.
  9200. * @returns {Boolean} false if any of the plugins return false, else returns true.
  9201. */
  9202. notify: function(extension, args) {
  9203. var plugins = this._plugins;
  9204. var ilen = plugins.length;
  9205. var i, plugin;
  9206. for (i=0; i<ilen; ++i) {
  9207. plugin = plugins[i];
  9208. if (typeof plugin[extension] === 'function') {
  9209. if (plugin[extension].apply(plugin, args || []) === false) {
  9210. return false;
  9211. }
  9212. }
  9213. }
  9214. return true;
  9215. }
  9216. };
  9217. /**
  9218. * Plugin extension methods.
  9219. * @interface Chart.PluginBase
  9220. * @since 2.1.0
  9221. */
  9222. Chart.PluginBase = Chart.Element.extend({
  9223. // Called at start of chart init
  9224. beforeInit: noop,
  9225. // Called at end of chart init
  9226. afterInit: noop,
  9227. // Called at start of update
  9228. beforeUpdate: noop,
  9229. // Called at end of update
  9230. afterUpdate: noop,
  9231. // Called at start of draw
  9232. beforeDraw: noop,
  9233. // Called at end of draw
  9234. afterDraw: noop,
  9235. // Called during destroy
  9236. destroy: noop
  9237. });
  9238. /**
  9239. * Provided for backward compatibility, use Chart.plugins instead
  9240. * @namespace Chart.pluginService
  9241. * @deprecated since version 2.1.5
  9242. * @todo remove me at version 3
  9243. */
  9244. Chart.pluginService = Chart.plugins;
  9245. };
  9246. },{}],31:[function(require,module,exports){
  9247. "use strict";
  9248. module.exports = function(Chart) {
  9249. var helpers = Chart.helpers;
  9250. Chart.defaults.scale = {
  9251. display: true,
  9252. position: "left",
  9253. // grid line settings
  9254. gridLines: {
  9255. display: true,
  9256. color: "rgba(0, 0, 0, 0.1)",
  9257. lineWidth: 1,
  9258. drawBorder: true,
  9259. drawOnChartArea: true,
  9260. drawTicks: true,
  9261. tickMarkLength: 10,
  9262. zeroLineWidth: 1,
  9263. zeroLineColor: "rgba(0,0,0,0.25)",
  9264. offsetGridLines: false
  9265. },
  9266. // scale label
  9267. scaleLabel: {
  9268. // actual label
  9269. labelString: '',
  9270. // display property
  9271. display: false
  9272. },
  9273. // label settings
  9274. ticks: {
  9275. beginAtZero: false,
  9276. minRotation: 0,
  9277. maxRotation: 50,
  9278. mirror: false,
  9279. padding: 10,
  9280. reverse: false,
  9281. display: true,
  9282. autoSkip: true,
  9283. autoSkipPadding: 0,
  9284. labelOffset: 0,
  9285. // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
  9286. callback: function(value) {
  9287. return helpers.isArray(value) ? value : '' + value;
  9288. }
  9289. }
  9290. };
  9291. Chart.Scale = Chart.Element.extend({
  9292. // These methods are ordered by lifecyle. Utilities then follow.
  9293. // Any function defined here is inherited by all scale types.
  9294. // Any function can be extended by the scale type
  9295. beforeUpdate: function() {
  9296. helpers.callCallback(this.options.beforeUpdate, [this]);
  9297. },
  9298. update: function(maxWidth, maxHeight, margins) {
  9299. var me = this;
  9300. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  9301. me.beforeUpdate();
  9302. // Absorb the master measurements
  9303. me.maxWidth = maxWidth;
  9304. me.maxHeight = maxHeight;
  9305. me.margins = helpers.extend({
  9306. left: 0,
  9307. right: 0,
  9308. top: 0,
  9309. bottom: 0
  9310. }, margins);
  9311. // Dimensions
  9312. me.beforeSetDimensions();
  9313. me.setDimensions();
  9314. me.afterSetDimensions();
  9315. // Data min/max
  9316. me.beforeDataLimits();
  9317. me.determineDataLimits();
  9318. me.afterDataLimits();
  9319. // Ticks
  9320. me.beforeBuildTicks();
  9321. me.buildTicks();
  9322. me.afterBuildTicks();
  9323. me.beforeTickToLabelConversion();
  9324. me.convertTicksToLabels();
  9325. me.afterTickToLabelConversion();
  9326. // Tick Rotation
  9327. me.beforeCalculateTickRotation();
  9328. me.calculateTickRotation();
  9329. me.afterCalculateTickRotation();
  9330. // Fit
  9331. me.beforeFit();
  9332. me.fit();
  9333. me.afterFit();
  9334. //
  9335. me.afterUpdate();
  9336. return me.minSize;
  9337. },
  9338. afterUpdate: function() {
  9339. helpers.callCallback(this.options.afterUpdate, [this]);
  9340. },
  9341. //
  9342. beforeSetDimensions: function() {
  9343. helpers.callCallback(this.options.beforeSetDimensions, [this]);
  9344. },
  9345. setDimensions: function() {
  9346. var me = this;
  9347. // Set the unconstrained dimension before label rotation
  9348. if (me.isHorizontal()) {
  9349. // Reset position before calculating rotation
  9350. me.width = me.maxWidth;
  9351. me.left = 0;
  9352. me.right = me.width;
  9353. } else {
  9354. me.height = me.maxHeight;
  9355. // Reset position before calculating rotation
  9356. me.top = 0;
  9357. me.bottom = me.height;
  9358. }
  9359. // Reset padding
  9360. me.paddingLeft = 0;
  9361. me.paddingTop = 0;
  9362. me.paddingRight = 0;
  9363. me.paddingBottom = 0;
  9364. },
  9365. afterSetDimensions: function() {
  9366. helpers.callCallback(this.options.afterSetDimensions, [this]);
  9367. },
  9368. // Data limits
  9369. beforeDataLimits: function() {
  9370. helpers.callCallback(this.options.beforeDataLimits, [this]);
  9371. },
  9372. determineDataLimits: helpers.noop,
  9373. afterDataLimits: function() {
  9374. helpers.callCallback(this.options.afterDataLimits, [this]);
  9375. },
  9376. //
  9377. beforeBuildTicks: function() {
  9378. helpers.callCallback(this.options.beforeBuildTicks, [this]);
  9379. },
  9380. buildTicks: helpers.noop,
  9381. afterBuildTicks: function() {
  9382. helpers.callCallback(this.options.afterBuildTicks, [this]);
  9383. },
  9384. beforeTickToLabelConversion: function() {
  9385. helpers.callCallback(this.options.beforeTickToLabelConversion, [this]);
  9386. },
  9387. convertTicksToLabels: function() {
  9388. var me = this;
  9389. // Convert ticks to strings
  9390. me.ticks = me.ticks.map(function(numericalTick, index, ticks) {
  9391. if (me.options.ticks.userCallback) {
  9392. return me.options.ticks.userCallback(numericalTick, index, ticks);
  9393. }
  9394. return me.options.ticks.callback(numericalTick, index, ticks);
  9395. },
  9396. me);
  9397. },
  9398. afterTickToLabelConversion: function() {
  9399. helpers.callCallback(this.options.afterTickToLabelConversion, [this]);
  9400. },
  9401. //
  9402. beforeCalculateTickRotation: function() {
  9403. helpers.callCallback(this.options.beforeCalculateTickRotation, [this]);
  9404. },
  9405. calculateTickRotation: function() {
  9406. var me = this;
  9407. var context = me.ctx;
  9408. var globalDefaults = Chart.defaults.global;
  9409. var optionTicks = me.options.ticks;
  9410. //Get the width of each grid by calculating the difference
  9411. //between x offsets between 0 and 1.
  9412. var tickFontSize = helpers.getValueOrDefault(optionTicks.fontSize, globalDefaults.defaultFontSize);
  9413. var tickFontStyle = helpers.getValueOrDefault(optionTicks.fontStyle, globalDefaults.defaultFontStyle);
  9414. var tickFontFamily = helpers.getValueOrDefault(optionTicks.fontFamily, globalDefaults.defaultFontFamily);
  9415. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  9416. context.font = tickLabelFont;
  9417. var firstWidth = context.measureText(me.ticks[0]).width;
  9418. var lastWidth = context.measureText(me.ticks[me.ticks.length - 1]).width;
  9419. var firstRotated;
  9420. me.labelRotation = optionTicks.minRotation || 0;
  9421. me.paddingRight = 0;
  9422. me.paddingLeft = 0;
  9423. if (me.options.display) {
  9424. if (me.isHorizontal()) {
  9425. me.paddingRight = lastWidth / 2 + 3;
  9426. me.paddingLeft = firstWidth / 2 + 3;
  9427. if (!me.longestTextCache) {
  9428. me.longestTextCache = {};
  9429. }
  9430. var originalLabelWidth = helpers.longestText(context, tickLabelFont, me.ticks, me.longestTextCache);
  9431. var labelWidth = originalLabelWidth;
  9432. var cosRotation;
  9433. var sinRotation;
  9434. // Allow 3 pixels x2 padding either side for label readability
  9435. // only the index matters for a dataset scale, but we want a consistent interface between scales
  9436. var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
  9437. //Max label rotation can be set or default to 90 - also act as a loop counter
  9438. while (labelWidth > tickWidth && me.labelRotation < optionTicks.maxRotation) {
  9439. cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
  9440. sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
  9441. firstRotated = cosRotation * firstWidth;
  9442. // We're right aligning the text now.
  9443. if (firstRotated + tickFontSize / 2 > me.yLabelWidth) {
  9444. me.paddingLeft = firstRotated + tickFontSize / 2;
  9445. }
  9446. me.paddingRight = tickFontSize / 2;
  9447. if (sinRotation * originalLabelWidth > me.maxHeight) {
  9448. // go back one step
  9449. me.labelRotation--;
  9450. break;
  9451. }
  9452. me.labelRotation++;
  9453. labelWidth = cosRotation * originalLabelWidth;
  9454. }
  9455. }
  9456. }
  9457. if (me.margins) {
  9458. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  9459. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  9460. }
  9461. },
  9462. afterCalculateTickRotation: function() {
  9463. helpers.callCallback(this.options.afterCalculateTickRotation, [this]);
  9464. },
  9465. //
  9466. beforeFit: function() {
  9467. helpers.callCallback(this.options.beforeFit, [this]);
  9468. },
  9469. fit: function() {
  9470. var me = this;
  9471. // Reset
  9472. var minSize = me.minSize = {
  9473. width: 0,
  9474. height: 0
  9475. };
  9476. var opts = me.options;
  9477. var globalDefaults = Chart.defaults.global;
  9478. var tickOpts = opts.ticks;
  9479. var scaleLabelOpts = opts.scaleLabel;
  9480. var display = opts.display;
  9481. var isHorizontal = me.isHorizontal();
  9482. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  9483. var tickFontStyle = helpers.getValueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  9484. var tickFontFamily = helpers.getValueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  9485. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  9486. var scaleLabelFontSize = helpers.getValueOrDefault(scaleLabelOpts.fontSize, globalDefaults.defaultFontSize);
  9487. var tickMarkLength = opts.gridLines.tickMarkLength;
  9488. // Width
  9489. if (isHorizontal) {
  9490. // subtract the margins to line up with the chartArea if we are a full width scale
  9491. minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
  9492. } else {
  9493. minSize.width = display ? tickMarkLength : 0;
  9494. }
  9495. // height
  9496. if (isHorizontal) {
  9497. minSize.height = display ? tickMarkLength : 0;
  9498. } else {
  9499. minSize.height = me.maxHeight; // fill all the height
  9500. }
  9501. // Are we showing a title for the scale?
  9502. if (scaleLabelOpts.display && display) {
  9503. if (isHorizontal) {
  9504. minSize.height += (scaleLabelFontSize * 1.5);
  9505. } else {
  9506. minSize.width += (scaleLabelFontSize * 1.5);
  9507. }
  9508. }
  9509. if (tickOpts.display && display) {
  9510. // Don't bother fitting the ticks if we are not showing them
  9511. if (!me.longestTextCache) {
  9512. me.longestTextCache = {};
  9513. }
  9514. var largestTextWidth = helpers.longestText(me.ctx, tickLabelFont, me.ticks, me.longestTextCache);
  9515. var tallestLabelHeightInLines = helpers.numberOfLabelLines(me.ticks);
  9516. var lineSpace = tickFontSize * 0.5;
  9517. if (isHorizontal) {
  9518. // A horizontal axis is more constrained by the height.
  9519. me.longestLabelWidth = largestTextWidth;
  9520. // TODO - improve this calculation
  9521. var labelHeight = (Math.sin(helpers.toRadians(me.labelRotation)) * me.longestLabelWidth) + (tickFontSize * tallestLabelHeightInLines) + (lineSpace * tallestLabelHeightInLines);
  9522. minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight);
  9523. me.ctx.font = tickLabelFont;
  9524. var firstLabelWidth = me.ctx.measureText(me.ticks[0]).width;
  9525. var lastLabelWidth = me.ctx.measureText(me.ticks[me.ticks.length - 1]).width;
  9526. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
  9527. // by the font height
  9528. var cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
  9529. var sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
  9530. me.paddingLeft = me.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  9531. me.paddingRight = me.labelRotation !== 0 ? (sinRotation * (tickFontSize / 2)) + 3 : lastLabelWidth / 2 + 3; // when rotated
  9532. } else {
  9533. // A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first
  9534. var maxLabelWidth = me.maxWidth - minSize.width;
  9535. // Account for padding
  9536. var mirror = tickOpts.mirror;
  9537. if (!mirror) {
  9538. largestTextWidth += me.options.ticks.padding;
  9539. } else {
  9540. // If mirrored text is on the inside so don't expand
  9541. largestTextWidth = 0;
  9542. }
  9543. if (largestTextWidth < maxLabelWidth) {
  9544. // We don't need all the room
  9545. minSize.width += largestTextWidth;
  9546. } else {
  9547. // Expand to max size
  9548. minSize.width = me.maxWidth;
  9549. }
  9550. me.paddingTop = tickFontSize / 2;
  9551. me.paddingBottom = tickFontSize / 2;
  9552. }
  9553. }
  9554. if (me.margins) {
  9555. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  9556. me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
  9557. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  9558. me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
  9559. }
  9560. me.width = minSize.width;
  9561. me.height = minSize.height;
  9562. },
  9563. afterFit: function() {
  9564. helpers.callCallback(this.options.afterFit, [this]);
  9565. },
  9566. // Shared Methods
  9567. isHorizontal: function() {
  9568. return this.options.position === "top" || this.options.position === "bottom";
  9569. },
  9570. isFullWidth: function() {
  9571. return (this.options.fullWidth);
  9572. },
  9573. // Get the correct value. NaN bad inputs, If the value type is object get the x or y based on whether we are horizontal or not
  9574. getRightValue: function(rawValue) {
  9575. // Null and undefined values first
  9576. if (rawValue === null || typeof(rawValue) === 'undefined') {
  9577. return NaN;
  9578. }
  9579. // isNaN(object) returns true, so make sure NaN is checking for a number
  9580. if (typeof(rawValue) === 'number' && isNaN(rawValue)) {
  9581. return NaN;
  9582. }
  9583. // If it is in fact an object, dive in one more level
  9584. if (typeof(rawValue) === "object") {
  9585. if ((rawValue instanceof Date) || (rawValue.isValid)) {
  9586. return rawValue;
  9587. } else {
  9588. return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
  9589. }
  9590. }
  9591. // Value is good, return it
  9592. return rawValue;
  9593. },
  9594. // Used to get the value to display in the tooltip for the data at the given index
  9595. // function getLabelForIndex(index, datasetIndex)
  9596. getLabelForIndex: helpers.noop,
  9597. // Used to get data value locations. Value can either be an index or a numerical value
  9598. getPixelForValue: helpers.noop,
  9599. // Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  9600. getValueForPixel: helpers.noop,
  9601. // Used for tick location, should
  9602. getPixelForTick: function(index, includeOffset) {
  9603. var me = this;
  9604. if (me.isHorizontal()) {
  9605. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  9606. var tickWidth = innerWidth / Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  9607. var pixel = (tickWidth * index) + me.paddingLeft;
  9608. if (includeOffset) {
  9609. pixel += tickWidth / 2;
  9610. }
  9611. var finalVal = me.left + Math.round(pixel);
  9612. finalVal += me.isFullWidth() ? me.margins.left : 0;
  9613. return finalVal;
  9614. } else {
  9615. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  9616. return me.top + (index * (innerHeight / (me.ticks.length - 1)));
  9617. }
  9618. },
  9619. // Utility for getting the pixel location of a percentage of scale
  9620. getPixelForDecimal: function(decimal /*, includeOffset*/ ) {
  9621. var me = this;
  9622. if (me.isHorizontal()) {
  9623. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  9624. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  9625. var finalVal = me.left + Math.round(valueOffset);
  9626. finalVal += me.isFullWidth() ? me.margins.left : 0;
  9627. return finalVal;
  9628. } else {
  9629. return me.top + (decimal * me.height);
  9630. }
  9631. },
  9632. getBasePixel: function() {
  9633. var me = this;
  9634. var min = me.min;
  9635. var max = me.max;
  9636. return me.getPixelForValue(
  9637. me.beginAtZero? 0:
  9638. min < 0 && max < 0? max :
  9639. min > 0 && max > 0? min :
  9640. 0);
  9641. },
  9642. // Actualy draw the scale on the canvas
  9643. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  9644. draw: function(chartArea) {
  9645. var me = this;
  9646. var options = me.options;
  9647. if (!options.display) {
  9648. return;
  9649. }
  9650. var context = me.ctx;
  9651. var globalDefaults = Chart.defaults.global;
  9652. var optionTicks = options.ticks;
  9653. var gridLines = options.gridLines;
  9654. var scaleLabel = options.scaleLabel;
  9655. var isRotated = me.labelRotation !== 0;
  9656. var skipRatio;
  9657. var useAutoskipper = optionTicks.autoSkip;
  9658. var isHorizontal = me.isHorizontal();
  9659. // figure out the maximum number of gridlines to show
  9660. var maxTicks;
  9661. if (optionTicks.maxTicksLimit) {
  9662. maxTicks = optionTicks.maxTicksLimit;
  9663. }
  9664. var tickFontColor = helpers.getValueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
  9665. var tickFontSize = helpers.getValueOrDefault(optionTicks.fontSize, globalDefaults.defaultFontSize);
  9666. var tickFontStyle = helpers.getValueOrDefault(optionTicks.fontStyle, globalDefaults.defaultFontStyle);
  9667. var tickFontFamily = helpers.getValueOrDefault(optionTicks.fontFamily, globalDefaults.defaultFontFamily);
  9668. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  9669. var tl = gridLines.tickMarkLength;
  9670. var scaleLabelFontColor = helpers.getValueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
  9671. var scaleLabelFontSize = helpers.getValueOrDefault(scaleLabel.fontSize, globalDefaults.defaultFontSize);
  9672. var scaleLabelFontStyle = helpers.getValueOrDefault(scaleLabel.fontStyle, globalDefaults.defaultFontStyle);
  9673. var scaleLabelFontFamily = helpers.getValueOrDefault(scaleLabel.fontFamily, globalDefaults.defaultFontFamily);
  9674. var scaleLabelFont = helpers.fontString(scaleLabelFontSize, scaleLabelFontStyle, scaleLabelFontFamily);
  9675. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  9676. var cosRotation = Math.cos(labelRotationRadians);
  9677. var longestRotatedLabel = me.longestLabelWidth * cosRotation;
  9678. // Make sure we draw text in the correct color and font
  9679. context.fillStyle = tickFontColor;
  9680. var itemsToDraw = [];
  9681. if (isHorizontal) {
  9682. skipRatio = false;
  9683. // Only calculate the skip ratio with the half width of longestRotateLabel if we got an actual rotation
  9684. // See #2584
  9685. if (isRotated) {
  9686. longestRotatedLabel /= 2;
  9687. }
  9688. if ((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length > (me.width - (me.paddingLeft + me.paddingRight))) {
  9689. skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length) / (me.width - (me.paddingLeft + me.paddingRight)));
  9690. }
  9691. // if they defined a max number of optionTicks,
  9692. // increase skipRatio until that number is met
  9693. if (maxTicks && me.ticks.length > maxTicks) {
  9694. while (!skipRatio || me.ticks.length / (skipRatio || 1) > maxTicks) {
  9695. if (!skipRatio) {
  9696. skipRatio = 1;
  9697. }
  9698. skipRatio += 1;
  9699. }
  9700. }
  9701. if (!useAutoskipper) {
  9702. skipRatio = false;
  9703. }
  9704. }
  9705. var xTickStart = options.position === "right" ? me.left : me.right - tl;
  9706. var xTickEnd = options.position === "right" ? me.left + tl : me.right;
  9707. var yTickStart = options.position === "bottom" ? me.top : me.bottom - tl;
  9708. var yTickEnd = options.position === "bottom" ? me.top + tl : me.bottom;
  9709. helpers.each(me.ticks, function(label, index) {
  9710. // If the callback returned a null or undefined value, do not draw this line
  9711. if (label === undefined || label === null) {
  9712. return;
  9713. }
  9714. var isLastTick = me.ticks.length === index + 1;
  9715. // Since we always show the last tick,we need may need to hide the last shown one before
  9716. var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= me.ticks.length);
  9717. if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
  9718. return;
  9719. }
  9720. var lineWidth, lineColor;
  9721. if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
  9722. // Draw the first index specially
  9723. lineWidth = gridLines.zeroLineWidth;
  9724. lineColor = gridLines.zeroLineColor;
  9725. } else {
  9726. lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index);
  9727. lineColor = helpers.getValueAtIndexOrDefault(gridLines.color, index);
  9728. }
  9729. // Common properties
  9730. var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
  9731. var textAlign, textBaseline = 'middle';
  9732. if (isHorizontal) {
  9733. if (!isRotated) {
  9734. textBaseline = options.position === 'top' ? 'bottom' : 'top';
  9735. }
  9736. textAlign = isRotated ? 'right' : 'center';
  9737. var xLineValue = me.getPixelForTick(index) + helpers.aliasPixel(lineWidth); // xvalues for grid lines
  9738. labelX = me.getPixelForTick(index, gridLines.offsetGridLines) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
  9739. labelY = (isRotated) ? me.top + 12 : options.position === 'top' ? me.bottom - tl : me.top + tl;
  9740. tx1 = tx2 = x1 = x2 = xLineValue;
  9741. ty1 = yTickStart;
  9742. ty2 = yTickEnd;
  9743. y1 = chartArea.top;
  9744. y2 = chartArea.bottom;
  9745. } else {
  9746. if (options.position === 'left') {
  9747. if (optionTicks.mirror) {
  9748. labelX = me.right + optionTicks.padding;
  9749. textAlign = 'left';
  9750. } else {
  9751. labelX = me.right - optionTicks.padding;
  9752. textAlign = 'right';
  9753. }
  9754. } else {
  9755. // right side
  9756. if (optionTicks.mirror) {
  9757. labelX = me.left - optionTicks.padding;
  9758. textAlign = 'right';
  9759. } else {
  9760. labelX = me.left + optionTicks.padding;
  9761. textAlign = 'left';
  9762. }
  9763. }
  9764. var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
  9765. yLineValue += helpers.aliasPixel(lineWidth);
  9766. labelY = me.getPixelForTick(index, gridLines.offsetGridLines);
  9767. tx1 = xTickStart;
  9768. tx2 = xTickEnd;
  9769. x1 = chartArea.left;
  9770. x2 = chartArea.right;
  9771. ty1 = ty2 = y1 = y2 = yLineValue;
  9772. }
  9773. itemsToDraw.push({
  9774. tx1: tx1,
  9775. ty1: ty1,
  9776. tx2: tx2,
  9777. ty2: ty2,
  9778. x1: x1,
  9779. y1: y1,
  9780. x2: x2,
  9781. y2: y2,
  9782. labelX: labelX,
  9783. labelY: labelY,
  9784. glWidth: lineWidth,
  9785. glColor: lineColor,
  9786. rotation: -1 * labelRotationRadians,
  9787. label: label,
  9788. textBaseline: textBaseline,
  9789. textAlign: textAlign
  9790. });
  9791. });
  9792. // Draw all of the tick labels, tick marks, and grid lines at the correct places
  9793. helpers.each(itemsToDraw, function(itemToDraw) {
  9794. if (gridLines.display) {
  9795. context.lineWidth = itemToDraw.glWidth;
  9796. context.strokeStyle = itemToDraw.glColor;
  9797. context.beginPath();
  9798. if (gridLines.drawTicks) {
  9799. context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
  9800. context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
  9801. }
  9802. if (gridLines.drawOnChartArea) {
  9803. context.moveTo(itemToDraw.x1, itemToDraw.y1);
  9804. context.lineTo(itemToDraw.x2, itemToDraw.y2);
  9805. }
  9806. context.stroke();
  9807. }
  9808. if (optionTicks.display) {
  9809. context.save();
  9810. context.translate(itemToDraw.labelX, itemToDraw.labelY);
  9811. context.rotate(itemToDraw.rotation);
  9812. context.font = tickLabelFont;
  9813. context.textBaseline = itemToDraw.textBaseline;
  9814. context.textAlign = itemToDraw.textAlign;
  9815. var label = itemToDraw.label;
  9816. if (helpers.isArray(label)) {
  9817. for (var i = 0, y = 0; i < label.length; ++i) {
  9818. // We just make sure the multiline element is a string here..
  9819. context.fillText('' + label[i], 0, y);
  9820. // apply same lineSpacing as calculated @ L#320
  9821. y += (tickFontSize * 1.5);
  9822. }
  9823. } else {
  9824. context.fillText(label, 0, 0);
  9825. }
  9826. context.restore();
  9827. }
  9828. });
  9829. if (scaleLabel.display) {
  9830. // Draw the scale label
  9831. var scaleLabelX;
  9832. var scaleLabelY;
  9833. var rotation = 0;
  9834. if (isHorizontal) {
  9835. scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
  9836. scaleLabelY = options.position === 'bottom' ? me.bottom - (scaleLabelFontSize / 2) : me.top + (scaleLabelFontSize / 2);
  9837. } else {
  9838. var isLeft = options.position === 'left';
  9839. scaleLabelX = isLeft ? me.left + (scaleLabelFontSize / 2) : me.right - (scaleLabelFontSize / 2);
  9840. scaleLabelY = me.top + ((me.bottom - me.top) / 2);
  9841. rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
  9842. }
  9843. context.save();
  9844. context.translate(scaleLabelX, scaleLabelY);
  9845. context.rotate(rotation);
  9846. context.textAlign = 'center';
  9847. context.textBaseline = 'middle';
  9848. context.fillStyle = scaleLabelFontColor; // render in correct colour
  9849. context.font = scaleLabelFont;
  9850. context.fillText(scaleLabel.labelString, 0, 0);
  9851. context.restore();
  9852. }
  9853. if (gridLines.drawBorder) {
  9854. // Draw the line at the edge of the axis
  9855. context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, 0);
  9856. context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, 0);
  9857. var x1 = me.left,
  9858. x2 = me.right,
  9859. y1 = me.top,
  9860. y2 = me.bottom;
  9861. var aliasPixel = helpers.aliasPixel(context.lineWidth);
  9862. if (isHorizontal) {
  9863. y1 = y2 = options.position === 'top' ? me.bottom : me.top;
  9864. y1 += aliasPixel;
  9865. y2 += aliasPixel;
  9866. } else {
  9867. x1 = x2 = options.position === 'left' ? me.right : me.left;
  9868. x1 += aliasPixel;
  9869. x2 += aliasPixel;
  9870. }
  9871. context.beginPath();
  9872. context.moveTo(x1, y1);
  9873. context.lineTo(x2, y2);
  9874. context.stroke();
  9875. }
  9876. }
  9877. });
  9878. };
  9879. },{}],32:[function(require,module,exports){
  9880. "use strict";
  9881. module.exports = function(Chart) {
  9882. var helpers = Chart.helpers;
  9883. Chart.scaleService = {
  9884. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  9885. // use the new chart options to grab the correct scale
  9886. constructors: {},
  9887. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  9888. // old browsers
  9889. // Scale config defaults
  9890. defaults: {},
  9891. registerScaleType: function(type, scaleConstructor, defaults) {
  9892. this.constructors[type] = scaleConstructor;
  9893. this.defaults[type] = helpers.clone(defaults);
  9894. },
  9895. getScaleConstructor: function(type) {
  9896. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  9897. },
  9898. getScaleDefaults: function(type) {
  9899. // Return the scale defaults merged with the global settings so that we always use the latest ones
  9900. return this.defaults.hasOwnProperty(type) ? helpers.scaleMerge(Chart.defaults.scale, this.defaults[type]) : {};
  9901. },
  9902. updateScaleDefaults: function(type, additions) {
  9903. var defaults = this.defaults;
  9904. if (defaults.hasOwnProperty(type)) {
  9905. defaults[type] = helpers.extend(defaults[type], additions);
  9906. }
  9907. },
  9908. addScalesToLayout: function(chartInstance) {
  9909. // Adds each scale to the chart.boxes array to be sized accordingly
  9910. helpers.each(chartInstance.scales, function(scale) {
  9911. Chart.layoutService.addBox(chartInstance, scale);
  9912. });
  9913. }
  9914. };
  9915. };
  9916. },{}],33:[function(require,module,exports){
  9917. "use strict";
  9918. module.exports = function(Chart) {
  9919. var helpers = Chart.helpers;
  9920. Chart.defaults.global.title = {
  9921. display: false,
  9922. position: 'top',
  9923. fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
  9924. fontStyle: 'bold',
  9925. padding: 10,
  9926. // actual title
  9927. text: ''
  9928. };
  9929. var noop = helpers.noop;
  9930. Chart.Title = Chart.Element.extend({
  9931. initialize: function(config) {
  9932. var me = this;
  9933. helpers.extend(me, config);
  9934. me.options = helpers.configMerge(Chart.defaults.global.title, config.options);
  9935. // Contains hit boxes for each dataset (in dataset order)
  9936. me.legendHitBoxes = [];
  9937. },
  9938. // These methods are ordered by lifecyle. Utilities then follow.
  9939. beforeUpdate: function () {
  9940. var chartOpts = this.chart.options;
  9941. if (chartOpts && chartOpts.title) {
  9942. this.options = helpers.configMerge(Chart.defaults.global.title, chartOpts.title);
  9943. }
  9944. },
  9945. update: function(maxWidth, maxHeight, margins) {
  9946. var me = this;
  9947. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  9948. me.beforeUpdate();
  9949. // Absorb the master measurements
  9950. me.maxWidth = maxWidth;
  9951. me.maxHeight = maxHeight;
  9952. me.margins = margins;
  9953. // Dimensions
  9954. me.beforeSetDimensions();
  9955. me.setDimensions();
  9956. me.afterSetDimensions();
  9957. // Labels
  9958. me.beforeBuildLabels();
  9959. me.buildLabels();
  9960. me.afterBuildLabels();
  9961. // Fit
  9962. me.beforeFit();
  9963. me.fit();
  9964. me.afterFit();
  9965. //
  9966. me.afterUpdate();
  9967. return me.minSize;
  9968. },
  9969. afterUpdate: noop,
  9970. //
  9971. beforeSetDimensions: noop,
  9972. setDimensions: function() {
  9973. var me = this;
  9974. // Set the unconstrained dimension before label rotation
  9975. if (me.isHorizontal()) {
  9976. // Reset position before calculating rotation
  9977. me.width = me.maxWidth;
  9978. me.left = 0;
  9979. me.right = me.width;
  9980. } else {
  9981. me.height = me.maxHeight;
  9982. // Reset position before calculating rotation
  9983. me.top = 0;
  9984. me.bottom = me.height;
  9985. }
  9986. // Reset padding
  9987. me.paddingLeft = 0;
  9988. me.paddingTop = 0;
  9989. me.paddingRight = 0;
  9990. me.paddingBottom = 0;
  9991. // Reset minSize
  9992. me.minSize = {
  9993. width: 0,
  9994. height: 0
  9995. };
  9996. },
  9997. afterSetDimensions: noop,
  9998. //
  9999. beforeBuildLabels: noop,
  10000. buildLabels: noop,
  10001. afterBuildLabels: noop,
  10002. //
  10003. beforeFit: noop,
  10004. fit: function() {
  10005. var me = this,
  10006. valueOrDefault = helpers.getValueOrDefault,
  10007. opts = me.options,
  10008. globalDefaults = Chart.defaults.global,
  10009. display = opts.display,
  10010. fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
  10011. minSize = me.minSize;
  10012. if (me.isHorizontal()) {
  10013. minSize.width = me.maxWidth; // fill all the width
  10014. minSize.height = display ? fontSize + (opts.padding * 2) : 0;
  10015. } else {
  10016. minSize.width = display ? fontSize + (opts.padding * 2) : 0;
  10017. minSize.height = me.maxHeight; // fill all the height
  10018. }
  10019. me.width = minSize.width;
  10020. me.height = minSize.height;
  10021. },
  10022. afterFit: noop,
  10023. // Shared Methods
  10024. isHorizontal: function() {
  10025. var pos = this.options.position;
  10026. return pos === "top" || pos === "bottom";
  10027. },
  10028. // Actualy draw the title block on the canvas
  10029. draw: function() {
  10030. var me = this,
  10031. ctx = me.ctx,
  10032. valueOrDefault = helpers.getValueOrDefault,
  10033. opts = me.options,
  10034. globalDefaults = Chart.defaults.global;
  10035. if (opts.display) {
  10036. var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
  10037. fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle),
  10038. fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily),
  10039. titleFont = helpers.fontString(fontSize, fontStyle, fontFamily),
  10040. rotation = 0,
  10041. titleX,
  10042. titleY,
  10043. top = me.top,
  10044. left = me.left,
  10045. bottom = me.bottom,
  10046. right = me.right;
  10047. ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
  10048. ctx.font = titleFont;
  10049. // Horizontal
  10050. if (me.isHorizontal()) {
  10051. titleX = left + ((right - left) / 2); // midpoint of the width
  10052. titleY = top + ((bottom - top) / 2); // midpoint of the height
  10053. } else {
  10054. titleX = opts.position === 'left' ? left + (fontSize / 2) : right - (fontSize / 2);
  10055. titleY = top + ((bottom - top) / 2);
  10056. rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
  10057. }
  10058. ctx.save();
  10059. ctx.translate(titleX, titleY);
  10060. ctx.rotate(rotation);
  10061. ctx.textAlign = 'center';
  10062. ctx.textBaseline = 'middle';
  10063. ctx.fillText(opts.text, 0, 0);
  10064. ctx.restore();
  10065. }
  10066. }
  10067. });
  10068. // Register the title plugin
  10069. Chart.plugins.register({
  10070. beforeInit: function(chartInstance) {
  10071. var opts = chartInstance.options;
  10072. var titleOpts = opts.title;
  10073. if (titleOpts) {
  10074. chartInstance.titleBlock = new Chart.Title({
  10075. ctx: chartInstance.chart.ctx,
  10076. options: titleOpts,
  10077. chart: chartInstance
  10078. });
  10079. Chart.layoutService.addBox(chartInstance, chartInstance.titleBlock);
  10080. }
  10081. }
  10082. });
  10083. };
  10084. },{}],34:[function(require,module,exports){
  10085. "use strict";
  10086. module.exports = function(Chart) {
  10087. var helpers = Chart.helpers;
  10088. Chart.defaults.global.tooltips = {
  10089. enabled: true,
  10090. custom: null,
  10091. mode: 'single',
  10092. backgroundColor: "rgba(0,0,0,0.8)",
  10093. titleFontStyle: "bold",
  10094. titleSpacing: 2,
  10095. titleMarginBottom: 6,
  10096. titleFontColor: "#fff",
  10097. titleAlign: "left",
  10098. bodySpacing: 2,
  10099. bodyFontColor: "#fff",
  10100. bodyAlign: "left",
  10101. footerFontStyle: "bold",
  10102. footerSpacing: 2,
  10103. footerMarginTop: 6,
  10104. footerFontColor: "#fff",
  10105. footerAlign: "left",
  10106. yPadding: 6,
  10107. xPadding: 6,
  10108. yAlign : 'center',
  10109. xAlign : 'center',
  10110. caretSize: 5,
  10111. cornerRadius: 6,
  10112. multiKeyBackground: '#fff',
  10113. callbacks: {
  10114. // Args are: (tooltipItems, data)
  10115. beforeTitle: helpers.noop,
  10116. title: function(tooltipItems, data) {
  10117. // Pick first xLabel for now
  10118. var title = '';
  10119. var labels = data.labels;
  10120. var labelCount = labels ? labels.length : 0;
  10121. if (tooltipItems.length > 0) {
  10122. var item = tooltipItems[0];
  10123. if (item.xLabel) {
  10124. title = item.xLabel;
  10125. } else if (labelCount > 0 && item.index < labelCount) {
  10126. title = labels[item.index];
  10127. }
  10128. }
  10129. return title;
  10130. },
  10131. afterTitle: helpers.noop,
  10132. // Args are: (tooltipItems, data)
  10133. beforeBody: helpers.noop,
  10134. // Args are: (tooltipItem, data)
  10135. beforeLabel: helpers.noop,
  10136. label: function(tooltipItem, data) {
  10137. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  10138. return datasetLabel + ': ' + tooltipItem.yLabel;
  10139. },
  10140. labelColor: function(tooltipItem, chartInstance) {
  10141. var meta = chartInstance.getDatasetMeta(tooltipItem.datasetIndex);
  10142. var activeElement = meta.data[tooltipItem.index];
  10143. var view = activeElement._view;
  10144. return {
  10145. borderColor: view.borderColor,
  10146. backgroundColor: view.backgroundColor
  10147. };
  10148. },
  10149. afterLabel: helpers.noop,
  10150. // Args are: (tooltipItems, data)
  10151. afterBody: helpers.noop,
  10152. // Args are: (tooltipItems, data)
  10153. beforeFooter: helpers.noop,
  10154. footer: helpers.noop,
  10155. afterFooter: helpers.noop
  10156. }
  10157. };
  10158. // Helper to push or concat based on if the 2nd parameter is an array or not
  10159. function pushOrConcat(base, toPush) {
  10160. if (toPush) {
  10161. if (helpers.isArray(toPush)) {
  10162. //base = base.concat(toPush);
  10163. Array.prototype.push.apply(base, toPush);
  10164. } else {
  10165. base.push(toPush);
  10166. }
  10167. }
  10168. return base;
  10169. }
  10170. function getAveragePosition(elements) {
  10171. if (!elements.length) {
  10172. return false;
  10173. }
  10174. var i, len;
  10175. var xPositions = [];
  10176. var yPositions = [];
  10177. for (i = 0, len = elements.length; i < len; ++i) {
  10178. var el = elements[i];
  10179. if (el && el.hasValue()){
  10180. var pos = el.tooltipPosition();
  10181. xPositions.push(pos.x);
  10182. yPositions.push(pos.y);
  10183. }
  10184. }
  10185. var x = 0,
  10186. y = 0;
  10187. for (i = 0; i < xPositions.length; ++i) {
  10188. if (xPositions[ i ]) {
  10189. x += xPositions[i];
  10190. y += yPositions[i];
  10191. }
  10192. }
  10193. return {
  10194. x: Math.round(x / xPositions.length),
  10195. y: Math.round(y / xPositions.length)
  10196. };
  10197. }
  10198. // Private helper to create a tooltip iteam model
  10199. // @param element : the chart element (point, arc, bar) to create the tooltip item for
  10200. // @return : new tooltip item
  10201. function createTooltipItem(element) {
  10202. var xScale = element._xScale;
  10203. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  10204. var index = element._index,
  10205. datasetIndex = element._datasetIndex;
  10206. return {
  10207. xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
  10208. yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
  10209. index: index,
  10210. datasetIndex: datasetIndex
  10211. };
  10212. }
  10213. Chart.Tooltip = Chart.Element.extend({
  10214. initialize: function() {
  10215. var me = this;
  10216. var globalDefaults = Chart.defaults.global;
  10217. var tooltipOpts = me._options;
  10218. var getValueOrDefault = helpers.getValueOrDefault;
  10219. helpers.extend(me, {
  10220. _model: {
  10221. // Positioning
  10222. xPadding: tooltipOpts.xPadding,
  10223. yPadding: tooltipOpts.yPadding,
  10224. xAlign : tooltipOpts.xAlign,
  10225. yAlign : tooltipOpts.yAlign,
  10226. // Body
  10227. bodyFontColor: tooltipOpts.bodyFontColor,
  10228. _bodyFontFamily: getValueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
  10229. _bodyFontStyle: getValueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
  10230. _bodyAlign: tooltipOpts.bodyAlign,
  10231. bodyFontSize: getValueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
  10232. bodySpacing: tooltipOpts.bodySpacing,
  10233. // Title
  10234. titleFontColor: tooltipOpts.titleFontColor,
  10235. _titleFontFamily: getValueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
  10236. _titleFontStyle: getValueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
  10237. titleFontSize: getValueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
  10238. _titleAlign: tooltipOpts.titleAlign,
  10239. titleSpacing: tooltipOpts.titleSpacing,
  10240. titleMarginBottom: tooltipOpts.titleMarginBottom,
  10241. // Footer
  10242. footerFontColor: tooltipOpts.footerFontColor,
  10243. _footerFontFamily: getValueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
  10244. _footerFontStyle: getValueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
  10245. footerFontSize: getValueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
  10246. _footerAlign: tooltipOpts.footerAlign,
  10247. footerSpacing: tooltipOpts.footerSpacing,
  10248. footerMarginTop: tooltipOpts.footerMarginTop,
  10249. // Appearance
  10250. caretSize: tooltipOpts.caretSize,
  10251. cornerRadius: tooltipOpts.cornerRadius,
  10252. backgroundColor: tooltipOpts.backgroundColor,
  10253. opacity: 0,
  10254. legendColorBackground: tooltipOpts.multiKeyBackground
  10255. }
  10256. });
  10257. },
  10258. // Get the title
  10259. // Args are: (tooltipItem, data)
  10260. getTitle: function() {
  10261. var me = this;
  10262. var opts = me._options;
  10263. var callbacks = opts.callbacks;
  10264. var beforeTitle = callbacks.beforeTitle.apply(me, arguments),
  10265. title = callbacks.title.apply(me, arguments),
  10266. afterTitle = callbacks.afterTitle.apply(me, arguments);
  10267. var lines = [];
  10268. lines = pushOrConcat(lines, beforeTitle);
  10269. lines = pushOrConcat(lines, title);
  10270. lines = pushOrConcat(lines, afterTitle);
  10271. return lines;
  10272. },
  10273. // Args are: (tooltipItem, data)
  10274. getBeforeBody: function() {
  10275. var lines = this._options.callbacks.beforeBody.apply(this, arguments);
  10276. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  10277. },
  10278. // Args are: (tooltipItem, data)
  10279. getBody: function(tooltipItems, data) {
  10280. var me = this;
  10281. var callbacks = me._options.callbacks;
  10282. var bodyItems = [];
  10283. helpers.each(tooltipItems, function(tooltipItem) {
  10284. var bodyItem = {
  10285. before: [],
  10286. lines: [],
  10287. after: []
  10288. };
  10289. pushOrConcat(bodyItem.before, callbacks.beforeLabel.call(me, tooltipItem, data));
  10290. pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
  10291. pushOrConcat(bodyItem.after, callbacks.afterLabel.call(me, tooltipItem, data));
  10292. bodyItems.push(bodyItem);
  10293. });
  10294. return bodyItems;
  10295. },
  10296. // Args are: (tooltipItem, data)
  10297. getAfterBody: function() {
  10298. var lines = this._options.callbacks.afterBody.apply(this, arguments);
  10299. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  10300. },
  10301. // Get the footer and beforeFooter and afterFooter lines
  10302. // Args are: (tooltipItem, data)
  10303. getFooter: function() {
  10304. var me = this;
  10305. var callbacks = me._options.callbacks;
  10306. var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
  10307. var footer = callbacks.footer.apply(me, arguments);
  10308. var afterFooter = callbacks.afterFooter.apply(me, arguments);
  10309. var lines = [];
  10310. lines = pushOrConcat(lines, beforeFooter);
  10311. lines = pushOrConcat(lines, footer);
  10312. lines = pushOrConcat(lines, afterFooter);
  10313. return lines;
  10314. },
  10315. update: function(changed) {
  10316. var me = this;
  10317. var opts = me._options;
  10318. var model = me._model;
  10319. var active = me._active;
  10320. var data = me._data;
  10321. var chartInstance = me._chartInstance;
  10322. var i, len;
  10323. if (active.length) {
  10324. model.opacity = 1;
  10325. var labelColors = [],
  10326. tooltipPosition = getAveragePosition(active);
  10327. var tooltipItems = [];
  10328. for (i = 0, len = active.length; i < len; ++i) {
  10329. tooltipItems.push(createTooltipItem(active[i]));
  10330. }
  10331. // If the user provided a sorting function, use it to modify the tooltip items
  10332. if (opts.itemSort) {
  10333. tooltipItems = tooltipItems.sort(opts.itemSort);
  10334. }
  10335. // If there is more than one item, show color items
  10336. if (active.length > 1) {
  10337. helpers.each(tooltipItems, function(tooltipItem) {
  10338. labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, chartInstance));
  10339. });
  10340. }
  10341. // Build the Text Lines
  10342. helpers.extend(model, {
  10343. title: me.getTitle(tooltipItems, data),
  10344. beforeBody: me.getBeforeBody(tooltipItems, data),
  10345. body: me.getBody(tooltipItems, data),
  10346. afterBody: me.getAfterBody(tooltipItems, data),
  10347. footer: me.getFooter(tooltipItems, data),
  10348. x: Math.round(tooltipPosition.x),
  10349. y: Math.round(tooltipPosition.y),
  10350. caretPadding: helpers.getValueOrDefault(tooltipPosition.padding, 2),
  10351. labelColors: labelColors
  10352. });
  10353. // We need to determine alignment of
  10354. var tooltipSize = me.getTooltipSize(model);
  10355. me.determineAlignment(tooltipSize); // Smart Tooltip placement to stay on the canvas
  10356. helpers.extend(model, me.getBackgroundPoint(model, tooltipSize));
  10357. } else {
  10358. me._model.opacity = 0;
  10359. }
  10360. if (changed && opts.custom) {
  10361. opts.custom.call(me, model);
  10362. }
  10363. return me;
  10364. },
  10365. getTooltipSize: function(vm) {
  10366. var ctx = this._chart.ctx;
  10367. var size = {
  10368. height: vm.yPadding * 2, // Tooltip Padding
  10369. width: 0
  10370. };
  10371. // Count of all lines in the body
  10372. var body = vm.body;
  10373. var combinedBodyLength = body.reduce(function(count, bodyItem) {
  10374. return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
  10375. }, 0);
  10376. combinedBodyLength += vm.beforeBody.length + vm.afterBody.length;
  10377. var titleLineCount = vm.title.length;
  10378. var footerLineCount = vm.footer.length;
  10379. var titleFontSize = vm.titleFontSize,
  10380. bodyFontSize = vm.bodyFontSize,
  10381. footerFontSize = vm.footerFontSize;
  10382. size.height += titleLineCount * titleFontSize; // Title Lines
  10383. size.height += (titleLineCount - 1) * vm.titleSpacing; // Title Line Spacing
  10384. size.height += titleLineCount ? vm.titleMarginBottom : 0; // Title's bottom Margin
  10385. size.height += combinedBodyLength * bodyFontSize; // Body Lines
  10386. size.height += combinedBodyLength ? (combinedBodyLength - 1) * vm.bodySpacing : 0; // Body Line Spacing
  10387. size.height += footerLineCount ? vm.footerMarginTop : 0; // Footer Margin
  10388. size.height += footerLineCount * (footerFontSize); // Footer Lines
  10389. size.height += footerLineCount ? (footerLineCount - 1) * vm.footerSpacing : 0; // Footer Line Spacing
  10390. // Title width
  10391. var widthPadding = 0;
  10392. var maxLineWidth = function(line) {
  10393. size.width = Math.max(size.width, ctx.measureText(line).width + widthPadding);
  10394. };
  10395. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  10396. helpers.each(vm.title, maxLineWidth);
  10397. // Body width
  10398. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  10399. helpers.each(vm.beforeBody.concat(vm.afterBody), maxLineWidth);
  10400. // Body lines may include some extra width due to the color box
  10401. widthPadding = body.length > 1 ? (bodyFontSize + 2) : 0;
  10402. helpers.each(body, function(bodyItem) {
  10403. helpers.each(bodyItem.before, maxLineWidth);
  10404. helpers.each(bodyItem.lines, maxLineWidth);
  10405. helpers.each(bodyItem.after, maxLineWidth);
  10406. });
  10407. // Reset back to 0
  10408. widthPadding = 0;
  10409. // Footer width
  10410. ctx.font = helpers.fontString(footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  10411. helpers.each(vm.footer, maxLineWidth);
  10412. // Add padding
  10413. size.width += 2 * vm.xPadding;
  10414. return size;
  10415. },
  10416. determineAlignment: function(size) {
  10417. var me = this;
  10418. var model = me._model;
  10419. var chart = me._chart;
  10420. var chartArea = me._chartInstance.chartArea;
  10421. if (model.y < size.height) {
  10422. model.yAlign = 'top';
  10423. } else if (model.y > (chart.height - size.height)) {
  10424. model.yAlign = 'bottom';
  10425. }
  10426. var lf, rf; // functions to determine left, right alignment
  10427. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  10428. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  10429. var midX = (chartArea.left + chartArea.right) / 2;
  10430. var midY = (chartArea.top + chartArea.bottom) / 2;
  10431. if (model.yAlign === 'center') {
  10432. lf = function(x) {
  10433. return x <= midX;
  10434. };
  10435. rf = function(x) {
  10436. return x > midX;
  10437. };
  10438. } else {
  10439. lf = function(x) {
  10440. return x <= (size.width / 2);
  10441. };
  10442. rf = function(x) {
  10443. return x >= (chart.width - (size.width / 2));
  10444. };
  10445. }
  10446. olf = function(x) {
  10447. return x + size.width > chart.width;
  10448. };
  10449. orf = function(x) {
  10450. return x - size.width < 0;
  10451. };
  10452. yf = function(y) {
  10453. return y <= midY ? 'top' : 'bottom';
  10454. };
  10455. if (lf(model.x)) {
  10456. model.xAlign = 'left';
  10457. // Is tooltip too wide and goes over the right side of the chart.?
  10458. if (olf(model.x)) {
  10459. model.xAlign = 'center';
  10460. model.yAlign = yf(model.y);
  10461. }
  10462. } else if (rf(model.x)) {
  10463. model.xAlign = 'right';
  10464. // Is tooltip too wide and goes outside left edge of canvas?
  10465. if (orf(model.x)) {
  10466. model.xAlign = 'center';
  10467. model.yAlign = yf(model.y);
  10468. }
  10469. }
  10470. },
  10471. getBackgroundPoint: function(vm, size) {
  10472. // Background Position
  10473. var pt = {
  10474. x: vm.x,
  10475. y: vm.y
  10476. };
  10477. var caretSize = vm.caretSize,
  10478. caretPadding = vm.caretPadding,
  10479. cornerRadius = vm.cornerRadius,
  10480. xAlign = vm.xAlign,
  10481. yAlign = vm.yAlign,
  10482. paddingAndSize = caretSize + caretPadding,
  10483. radiusAndPadding = cornerRadius + caretPadding;
  10484. if (xAlign === 'right') {
  10485. pt.x -= size.width;
  10486. } else if (xAlign === 'center') {
  10487. pt.x -= (size.width / 2);
  10488. }
  10489. if (yAlign === 'top') {
  10490. pt.y += paddingAndSize;
  10491. } else if (yAlign === 'bottom') {
  10492. pt.y -= size.height + paddingAndSize;
  10493. } else {
  10494. pt.y -= (size.height / 2);
  10495. }
  10496. if (yAlign === 'center') {
  10497. if (xAlign === 'left') {
  10498. pt.x += paddingAndSize;
  10499. } else if (xAlign === 'right') {
  10500. pt.x -= paddingAndSize;
  10501. }
  10502. } else {
  10503. if (xAlign === 'left') {
  10504. pt.x -= radiusAndPadding;
  10505. } else if (xAlign === 'right') {
  10506. pt.x += radiusAndPadding;
  10507. }
  10508. }
  10509. return pt;
  10510. },
  10511. drawCaret: function(tooltipPoint, size, opacity) {
  10512. var vm = this._view;
  10513. var ctx = this._chart.ctx;
  10514. var x1, x2, x3;
  10515. var y1, y2, y3;
  10516. var caretSize = vm.caretSize;
  10517. var cornerRadius = vm.cornerRadius;
  10518. var xAlign = vm.xAlign,
  10519. yAlign = vm.yAlign;
  10520. var ptX = tooltipPoint.x,
  10521. ptY = tooltipPoint.y;
  10522. var width = size.width,
  10523. height = size.height;
  10524. if (yAlign === 'center') {
  10525. // Left or right side
  10526. if (xAlign === 'left') {
  10527. x1 = ptX;
  10528. x2 = x1 - caretSize;
  10529. x3 = x1;
  10530. } else {
  10531. x1 = ptX + width;
  10532. x2 = x1 + caretSize;
  10533. x3 = x1;
  10534. }
  10535. y2 = ptY + (height / 2);
  10536. y1 = y2 - caretSize;
  10537. y3 = y2 + caretSize;
  10538. } else {
  10539. if (xAlign === 'left') {
  10540. x1 = ptX + cornerRadius;
  10541. x2 = x1 + caretSize;
  10542. x3 = x2 + caretSize;
  10543. } else if (xAlign === 'right') {
  10544. x1 = ptX + width - cornerRadius;
  10545. x2 = x1 - caretSize;
  10546. x3 = x2 - caretSize;
  10547. } else {
  10548. x2 = ptX + (width / 2);
  10549. x1 = x2 - caretSize;
  10550. x3 = x2 + caretSize;
  10551. }
  10552. if (yAlign === 'top') {
  10553. y1 = ptY;
  10554. y2 = y1 - caretSize;
  10555. y3 = y1;
  10556. } else {
  10557. y1 = ptY + height;
  10558. y2 = y1 + caretSize;
  10559. y3 = y1;
  10560. }
  10561. }
  10562. var bgColor = helpers.color(vm.backgroundColor);
  10563. ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
  10564. ctx.beginPath();
  10565. ctx.moveTo(x1, y1);
  10566. ctx.lineTo(x2, y2);
  10567. ctx.lineTo(x3, y3);
  10568. ctx.closePath();
  10569. ctx.fill();
  10570. },
  10571. drawTitle: function(pt, vm, ctx, opacity) {
  10572. var title = vm.title;
  10573. if (title.length) {
  10574. ctx.textAlign = vm._titleAlign;
  10575. ctx.textBaseline = "top";
  10576. var titleFontSize = vm.titleFontSize,
  10577. titleSpacing = vm.titleSpacing;
  10578. var titleFontColor = helpers.color(vm.titleFontColor);
  10579. ctx.fillStyle = titleFontColor.alpha(opacity * titleFontColor.alpha()).rgbString();
  10580. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  10581. var i, len;
  10582. for (i = 0, len = title.length; i < len; ++i) {
  10583. ctx.fillText(title[i], pt.x, pt.y);
  10584. pt.y += titleFontSize + titleSpacing; // Line Height and spacing
  10585. if (i + 1 === title.length) {
  10586. pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
  10587. }
  10588. }
  10589. }
  10590. },
  10591. drawBody: function(pt, vm, ctx, opacity) {
  10592. var bodyFontSize = vm.bodyFontSize;
  10593. var bodySpacing = vm.bodySpacing;
  10594. var body = vm.body;
  10595. ctx.textAlign = vm._bodyAlign;
  10596. ctx.textBaseline = "top";
  10597. var bodyFontColor = helpers.color(vm.bodyFontColor);
  10598. var textColor = bodyFontColor.alpha(opacity * bodyFontColor.alpha()).rgbString();
  10599. ctx.fillStyle = textColor;
  10600. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  10601. // Before Body
  10602. var xLinePadding = 0;
  10603. var fillLineOfText = function(line) {
  10604. ctx.fillText(line, pt.x + xLinePadding, pt.y);
  10605. pt.y += bodyFontSize + bodySpacing;
  10606. };
  10607. // Before body lines
  10608. helpers.each(vm.beforeBody, fillLineOfText);
  10609. var drawColorBoxes = body.length > 1;
  10610. xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
  10611. // Draw body lines now
  10612. helpers.each(body, function(bodyItem, i) {
  10613. helpers.each(bodyItem.before, fillLineOfText);
  10614. helpers.each(bodyItem.lines, function(line) {
  10615. // Draw Legend-like boxes if needed
  10616. if (drawColorBoxes) {
  10617. // Fill a white rect so that colours merge nicely if the opacity is < 1
  10618. ctx.fillStyle = helpers.color(vm.legendColorBackground).alpha(opacity).rgbaString();
  10619. ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  10620. // Border
  10621. ctx.strokeStyle = helpers.color(vm.labelColors[i].borderColor).alpha(opacity).rgbaString();
  10622. ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  10623. // Inner square
  10624. ctx.fillStyle = helpers.color(vm.labelColors[i].backgroundColor).alpha(opacity).rgbaString();
  10625. ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
  10626. ctx.fillStyle = textColor;
  10627. }
  10628. fillLineOfText(line);
  10629. });
  10630. helpers.each(bodyItem.after, fillLineOfText);
  10631. });
  10632. // Reset back to 0 for after body
  10633. xLinePadding = 0;
  10634. // After body lines
  10635. helpers.each(vm.afterBody, fillLineOfText);
  10636. pt.y -= bodySpacing; // Remove last body spacing
  10637. },
  10638. drawFooter: function(pt, vm, ctx, opacity) {
  10639. var footer = vm.footer;
  10640. if (footer.length) {
  10641. pt.y += vm.footerMarginTop;
  10642. ctx.textAlign = vm._footerAlign;
  10643. ctx.textBaseline = "top";
  10644. var footerFontColor = helpers.color(vm.footerFontColor);
  10645. ctx.fillStyle = footerFontColor.alpha(opacity * footerFontColor.alpha()).rgbString();
  10646. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  10647. helpers.each(footer, function(line) {
  10648. ctx.fillText(line, pt.x, pt.y);
  10649. pt.y += vm.footerFontSize + vm.footerSpacing;
  10650. });
  10651. }
  10652. },
  10653. draw: function() {
  10654. var ctx = this._chart.ctx;
  10655. var vm = this._view;
  10656. if (vm.opacity === 0) {
  10657. return;
  10658. }
  10659. var tooltipSize = this.getTooltipSize(vm);
  10660. var pt = {
  10661. x: vm.x,
  10662. y: vm.y
  10663. };
  10664. // IE11/Edge does not like very small opacities, so snap to 0
  10665. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  10666. if (this._options.enabled) {
  10667. // Draw Background
  10668. var bgColor = helpers.color(vm.backgroundColor);
  10669. ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
  10670. helpers.drawRoundedRectangle(ctx, pt.x, pt.y, tooltipSize.width, tooltipSize.height, vm.cornerRadius);
  10671. ctx.fill();
  10672. // Draw Caret
  10673. this.drawCaret(pt, tooltipSize, opacity);
  10674. // Draw Title, Body, and Footer
  10675. pt.x += vm.xPadding;
  10676. pt.y += vm.yPadding;
  10677. // Titles
  10678. this.drawTitle(pt, vm, ctx, opacity);
  10679. // Body
  10680. this.drawBody(pt, vm, ctx, opacity);
  10681. // Footer
  10682. this.drawFooter(pt, vm, ctx, opacity);
  10683. }
  10684. }
  10685. });
  10686. };
  10687. },{}],35:[function(require,module,exports){
  10688. "use strict";
  10689. module.exports = function(Chart) {
  10690. var helpers = Chart.helpers,
  10691. globalOpts = Chart.defaults.global;
  10692. globalOpts.elements.arc = {
  10693. backgroundColor: globalOpts.defaultColor,
  10694. borderColor: "#fff",
  10695. borderWidth: 2
  10696. };
  10697. Chart.elements.Arc = Chart.Element.extend({
  10698. inLabelRange: function(mouseX) {
  10699. var vm = this._view;
  10700. if (vm) {
  10701. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  10702. } else {
  10703. return false;
  10704. }
  10705. },
  10706. inRange: function(chartX, chartY) {
  10707. var vm = this._view;
  10708. if (vm) {
  10709. var pointRelativePosition = helpers.getAngleFromPoint(vm, {
  10710. x: chartX,
  10711. y: chartY
  10712. }),
  10713. angle = pointRelativePosition.angle,
  10714. distance = pointRelativePosition.distance;
  10715. //Sanitise angle range
  10716. var startAngle = vm.startAngle;
  10717. var endAngle = vm.endAngle;
  10718. while (endAngle < startAngle) {
  10719. endAngle += 2.0 * Math.PI;
  10720. }
  10721. while (angle > endAngle) {
  10722. angle -= 2.0 * Math.PI;
  10723. }
  10724. while (angle < startAngle) {
  10725. angle += 2.0 * Math.PI;
  10726. }
  10727. //Check if within the range of the open/close angle
  10728. var betweenAngles = (angle >= startAngle && angle <= endAngle),
  10729. withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
  10730. return (betweenAngles && withinRadius);
  10731. } else {
  10732. return false;
  10733. }
  10734. },
  10735. tooltipPosition: function() {
  10736. var vm = this._view;
  10737. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2),
  10738. rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  10739. return {
  10740. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  10741. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  10742. };
  10743. },
  10744. draw: function() {
  10745. var ctx = this._chart.ctx,
  10746. vm = this._view,
  10747. sA = vm.startAngle,
  10748. eA = vm.endAngle;
  10749. ctx.beginPath();
  10750. ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
  10751. ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
  10752. ctx.closePath();
  10753. ctx.strokeStyle = vm.borderColor;
  10754. ctx.lineWidth = vm.borderWidth;
  10755. ctx.fillStyle = vm.backgroundColor;
  10756. ctx.fill();
  10757. ctx.lineJoin = 'bevel';
  10758. if (vm.borderWidth) {
  10759. ctx.stroke();
  10760. }
  10761. }
  10762. });
  10763. };
  10764. },{}],36:[function(require,module,exports){
  10765. "use strict";
  10766. module.exports = function(Chart) {
  10767. var helpers = Chart.helpers;
  10768. var globalDefaults = Chart.defaults.global;
  10769. Chart.defaults.global.elements.line = {
  10770. tension: 0.4,
  10771. backgroundColor: globalDefaults.defaultColor,
  10772. borderWidth: 3,
  10773. borderColor: globalDefaults.defaultColor,
  10774. borderCapStyle: 'butt',
  10775. borderDash: [],
  10776. borderDashOffset: 0.0,
  10777. borderJoinStyle: 'miter',
  10778. capBezierPoints: true,
  10779. fill: true // do we fill in the area between the line and its base axis
  10780. };
  10781. Chart.elements.Line = Chart.Element.extend({
  10782. draw: function() {
  10783. var me = this;
  10784. var vm = me._view;
  10785. var spanGaps = vm.spanGaps;
  10786. var scaleZero = vm.scaleZero;
  10787. var loop = me._loop;
  10788. var ctx = me._chart.ctx;
  10789. ctx.save();
  10790. // Helper function to draw a line to a point
  10791. function lineToPoint(previousPoint, point) {
  10792. var vm = point._view;
  10793. if (point._view.steppedLine === true) {
  10794. ctx.lineTo(point._view.x, previousPoint._view.y);
  10795. ctx.lineTo(point._view.x, point._view.y);
  10796. } else if (point._view.tension === 0) {
  10797. ctx.lineTo(vm.x, vm.y);
  10798. } else {
  10799. ctx.bezierCurveTo(
  10800. previousPoint._view.controlPointNextX,
  10801. previousPoint._view.controlPointNextY,
  10802. vm.controlPointPreviousX,
  10803. vm.controlPointPreviousY,
  10804. vm.x,
  10805. vm.y
  10806. );
  10807. }
  10808. }
  10809. var points = me._children.slice(); // clone array
  10810. var lastDrawnIndex = -1;
  10811. // If we are looping, adding the first point again
  10812. if (loop && points.length) {
  10813. points.push(points[0]);
  10814. }
  10815. var index, current, previous, currentVM;
  10816. // Fill Line
  10817. if (points.length && vm.fill) {
  10818. ctx.beginPath();
  10819. for (index = 0; index < points.length; ++index) {
  10820. current = points[index];
  10821. previous = helpers.previousItem(points, index);
  10822. currentVM = current._view;
  10823. // First point moves to it's starting position no matter what
  10824. if (index === 0) {
  10825. if (loop) {
  10826. ctx.moveTo(scaleZero.x, scaleZero.y);
  10827. } else {
  10828. ctx.moveTo(currentVM.x, scaleZero);
  10829. }
  10830. if (!currentVM.skip) {
  10831. lastDrawnIndex = index;
  10832. ctx.lineTo(currentVM.x, currentVM.y);
  10833. }
  10834. } else {
  10835. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  10836. if (currentVM.skip) {
  10837. // Only do this if this is the first point that is skipped
  10838. if (!spanGaps && lastDrawnIndex === (index - 1)) {
  10839. if (loop) {
  10840. ctx.lineTo(scaleZero.x, scaleZero.y);
  10841. } else {
  10842. ctx.lineTo(previous._view.x, scaleZero);
  10843. }
  10844. }
  10845. } else {
  10846. if (lastDrawnIndex !== (index - 1)) {
  10847. // There was a gap and this is the first point after the gap. If we've never drawn a point, this is a special case.
  10848. // If the first data point is NaN, then there is no real gap to skip
  10849. if (spanGaps && lastDrawnIndex !== -1) {
  10850. // We are spanning the gap, so simple draw a line to this point
  10851. lineToPoint(previous, current);
  10852. } else {
  10853. if (loop) {
  10854. ctx.lineTo(currentVM.x, currentVM.y);
  10855. } else {
  10856. ctx.lineTo(currentVM.x, scaleZero);
  10857. ctx.lineTo(currentVM.x, currentVM.y);
  10858. }
  10859. }
  10860. } else {
  10861. // Line to next point
  10862. lineToPoint(previous, current);
  10863. }
  10864. lastDrawnIndex = index;
  10865. }
  10866. }
  10867. }
  10868. if (!loop) {
  10869. ctx.lineTo(points[lastDrawnIndex]._view.x, scaleZero);
  10870. }
  10871. ctx.fillStyle = vm.backgroundColor || globalDefaults.defaultColor;
  10872. ctx.closePath();
  10873. ctx.fill();
  10874. }
  10875. // Stroke Line Options
  10876. var globalOptionLineElements = globalDefaults.elements.line;
  10877. ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
  10878. // IE 9 and 10 do not support line dash
  10879. if (ctx.setLineDash) {
  10880. ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
  10881. }
  10882. ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
  10883. ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
  10884. ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
  10885. ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
  10886. // Stroke Line
  10887. ctx.beginPath();
  10888. lastDrawnIndex = -1;
  10889. for (index = 0; index < points.length; ++index) {
  10890. current = points[index];
  10891. previous = helpers.previousItem(points, index);
  10892. currentVM = current._view;
  10893. // First point moves to it's starting position no matter what
  10894. if (index === 0) {
  10895. if (currentVM.skip) {
  10896. } else {
  10897. ctx.moveTo(currentVM.x, currentVM.y);
  10898. lastDrawnIndex = index;
  10899. }
  10900. } else {
  10901. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  10902. if (!currentVM.skip) {
  10903. if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
  10904. // There was a gap and this is the first point after the gap
  10905. ctx.moveTo(currentVM.x, currentVM.y);
  10906. } else {
  10907. // Line to next point
  10908. lineToPoint(previous, current);
  10909. }
  10910. lastDrawnIndex = index;
  10911. }
  10912. }
  10913. }
  10914. ctx.stroke();
  10915. ctx.restore();
  10916. }
  10917. });
  10918. };
  10919. },{}],37:[function(require,module,exports){
  10920. "use strict";
  10921. module.exports = function(Chart) {
  10922. var helpers = Chart.helpers,
  10923. globalOpts = Chart.defaults.global,
  10924. defaultColor = globalOpts.defaultColor;
  10925. globalOpts.elements.point = {
  10926. radius: 3,
  10927. pointStyle: 'circle',
  10928. backgroundColor: defaultColor,
  10929. borderWidth: 1,
  10930. borderColor: defaultColor,
  10931. // Hover
  10932. hitRadius: 1,
  10933. hoverRadius: 4,
  10934. hoverBorderWidth: 1
  10935. };
  10936. Chart.elements.Point = Chart.Element.extend({
  10937. inRange: function(mouseX, mouseY) {
  10938. var vm = this._view;
  10939. return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
  10940. },
  10941. inLabelRange: function(mouseX) {
  10942. var vm = this._view;
  10943. return vm ? (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hitRadius, 2)) : false;
  10944. },
  10945. tooltipPosition: function() {
  10946. var vm = this._view;
  10947. return {
  10948. x: vm.x,
  10949. y: vm.y,
  10950. padding: vm.radius + vm.borderWidth
  10951. };
  10952. },
  10953. draw: function() {
  10954. var vm = this._view;
  10955. var ctx = this._chart.ctx;
  10956. var pointStyle = vm.pointStyle;
  10957. var radius = vm.radius;
  10958. var x = vm.x;
  10959. var y = vm.y;
  10960. if (vm.skip) {
  10961. return;
  10962. }
  10963. ctx.strokeStyle = vm.borderColor || defaultColor;
  10964. ctx.lineWidth = helpers.getValueOrDefault(vm.borderWidth, globalOpts.elements.point.borderWidth);
  10965. ctx.fillStyle = vm.backgroundColor || defaultColor;
  10966. Chart.canvasHelpers.drawPoint(ctx, pointStyle, radius, x, y);
  10967. }
  10968. });
  10969. };
  10970. },{}],38:[function(require,module,exports){
  10971. "use strict";
  10972. module.exports = function(Chart) {
  10973. var globalOpts = Chart.defaults.global;
  10974. globalOpts.elements.rectangle = {
  10975. backgroundColor: globalOpts.defaultColor,
  10976. borderWidth: 0,
  10977. borderColor: globalOpts.defaultColor,
  10978. borderSkipped: 'bottom'
  10979. };
  10980. Chart.elements.Rectangle = Chart.Element.extend({
  10981. draw: function() {
  10982. var ctx = this._chart.ctx;
  10983. var vm = this._view;
  10984. var halfWidth = vm.width / 2,
  10985. leftX = vm.x - halfWidth,
  10986. rightX = vm.x + halfWidth,
  10987. top = vm.base - (vm.base - vm.y),
  10988. halfStroke = vm.borderWidth / 2;
  10989. // Canvas doesn't allow us to stroke inside the width so we can
  10990. // adjust the sizes to fit if we're setting a stroke on the line
  10991. if (vm.borderWidth) {
  10992. leftX += halfStroke;
  10993. rightX -= halfStroke;
  10994. top += halfStroke;
  10995. }
  10996. ctx.beginPath();
  10997. ctx.fillStyle = vm.backgroundColor;
  10998. ctx.strokeStyle = vm.borderColor;
  10999. ctx.lineWidth = vm.borderWidth;
  11000. // Corner points, from bottom-left to bottom-right clockwise
  11001. // | 1 2 |
  11002. // | 0 3 |
  11003. var corners = [
  11004. [leftX, vm.base],
  11005. [leftX, top],
  11006. [rightX, top],
  11007. [rightX, vm.base]
  11008. ];
  11009. // Find first (starting) corner with fallback to 'bottom'
  11010. var borders = ['bottom', 'left', 'top', 'right'];
  11011. var startCorner = borders.indexOf(vm.borderSkipped, 0);
  11012. if (startCorner === -1)
  11013. startCorner = 0;
  11014. function cornerAt(index) {
  11015. return corners[(startCorner + index) % 4];
  11016. }
  11017. // Draw rectangle from 'startCorner'
  11018. ctx.moveTo.apply(ctx, cornerAt(0));
  11019. for (var i = 1; i < 4; i++)
  11020. ctx.lineTo.apply(ctx, cornerAt(i));
  11021. ctx.fill();
  11022. if (vm.borderWidth) {
  11023. ctx.stroke();
  11024. }
  11025. },
  11026. height: function() {
  11027. var vm = this._view;
  11028. return vm.base - vm.y;
  11029. },
  11030. inRange: function(mouseX, mouseY) {
  11031. var vm = this._view;
  11032. return vm ?
  11033. (vm.y < vm.base ?
  11034. (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.y && mouseY <= vm.base) :
  11035. (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.base && mouseY <= vm.y)) :
  11036. false;
  11037. },
  11038. inLabelRange: function(mouseX) {
  11039. var vm = this._view;
  11040. return vm ? (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) : false;
  11041. },
  11042. tooltipPosition: function() {
  11043. var vm = this._view;
  11044. return {
  11045. x: vm.x,
  11046. y: vm.y
  11047. };
  11048. }
  11049. });
  11050. };
  11051. },{}],39:[function(require,module,exports){
  11052. "use strict";
  11053. module.exports = function(Chart) {
  11054. var helpers = Chart.helpers;
  11055. // Default config for a category scale
  11056. var defaultConfig = {
  11057. position: "bottom"
  11058. };
  11059. var DatasetScale = Chart.Scale.extend({
  11060. /**
  11061. * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use tose
  11062. * else fall back to data.labels
  11063. * @private
  11064. */
  11065. getLabels: function() {
  11066. var data = this.chart.data;
  11067. return (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
  11068. },
  11069. // Implement this so that
  11070. determineDataLimits: function() {
  11071. var me = this;
  11072. var labels = me.getLabels();
  11073. me.minIndex = 0;
  11074. me.maxIndex = labels.length - 1;
  11075. var findIndex;
  11076. if (me.options.ticks.min !== undefined) {
  11077. // user specified min value
  11078. findIndex = helpers.indexOf(labels, me.options.ticks.min);
  11079. me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
  11080. }
  11081. if (me.options.ticks.max !== undefined) {
  11082. // user specified max value
  11083. findIndex = helpers.indexOf(labels, me.options.ticks.max);
  11084. me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
  11085. }
  11086. me.min = labels[me.minIndex];
  11087. me.max = labels[me.maxIndex];
  11088. },
  11089. buildTicks: function() {
  11090. var me = this;
  11091. var labels = me.getLabels();
  11092. // If we are viewing some subset of labels, slice the original array
  11093. me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
  11094. },
  11095. getLabelForIndex: function(index) {
  11096. return this.ticks[index];
  11097. },
  11098. // Used to get data value locations. Value can either be an index or a numerical value
  11099. getPixelForValue: function(value, index, datasetIndex, includeOffset) {
  11100. var me = this;
  11101. // 1 is added because we need the length but we have the indexes
  11102. var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  11103. if (value !== undefined) {
  11104. var labels = me.getLabels();
  11105. var idx = labels.indexOf(value);
  11106. index = idx !== -1 ? idx : index;
  11107. }
  11108. if (me.isHorizontal()) {
  11109. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  11110. var valueWidth = innerWidth / offsetAmt;
  11111. var widthOffset = (valueWidth * (index - me.minIndex)) + me.paddingLeft;
  11112. if (me.options.gridLines.offsetGridLines && includeOffset) {
  11113. widthOffset += (valueWidth / 2);
  11114. }
  11115. return me.left + Math.round(widthOffset);
  11116. } else {
  11117. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  11118. var valueHeight = innerHeight / offsetAmt;
  11119. var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop;
  11120. if (me.options.gridLines.offsetGridLines && includeOffset) {
  11121. heightOffset += (valueHeight / 2);
  11122. }
  11123. return me.top + Math.round(heightOffset);
  11124. }
  11125. },
  11126. getPixelForTick: function(index, includeOffset) {
  11127. return this.getPixelForValue(this.ticks[index], index + this.minIndex, null, includeOffset);
  11128. },
  11129. getValueForPixel: function(pixel) {
  11130. var me = this;
  11131. var value;
  11132. var offsetAmt = Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  11133. var horz = me.isHorizontal();
  11134. var innerDimension = horz ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
  11135. var valueDimension = innerDimension / offsetAmt;
  11136. pixel -= horz ? me.left : me.top;
  11137. if (me.options.gridLines.offsetGridLines) {
  11138. pixel -= (valueDimension / 2);
  11139. }
  11140. pixel -= horz ? me.paddingLeft : me.paddingTop;
  11141. if (pixel <= 0) {
  11142. value = 0;
  11143. } else {
  11144. value = Math.round(pixel / valueDimension);
  11145. }
  11146. return value;
  11147. },
  11148. getBasePixel: function() {
  11149. return this.bottom;
  11150. }
  11151. });
  11152. Chart.scaleService.registerScaleType("category", DatasetScale, defaultConfig);
  11153. };
  11154. },{}],40:[function(require,module,exports){
  11155. "use strict";
  11156. module.exports = function(Chart) {
  11157. var helpers = Chart.helpers;
  11158. var defaultConfig = {
  11159. position: "left",
  11160. ticks: {
  11161. callback: function(tickValue, index, ticks) {
  11162. // If we have lots of ticks, don't use the ones
  11163. var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
  11164. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  11165. if (Math.abs(delta) > 1) {
  11166. if (tickValue !== Math.floor(tickValue)) {
  11167. // not an integer
  11168. delta = tickValue - Math.floor(tickValue);
  11169. }
  11170. }
  11171. var logDelta = helpers.log10(Math.abs(delta));
  11172. var tickString = '';
  11173. if (tickValue !== 0) {
  11174. var numDecimal = -1 * Math.floor(logDelta);
  11175. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  11176. tickString = tickValue.toFixed(numDecimal);
  11177. } else {
  11178. tickString = '0'; // never show decimal places for 0
  11179. }
  11180. return tickString;
  11181. }
  11182. }
  11183. };
  11184. var LinearScale = Chart.LinearScaleBase.extend({
  11185. determineDataLimits: function() {
  11186. var me = this;
  11187. var opts = me.options;
  11188. var chart = me.chart;
  11189. var data = chart.data;
  11190. var datasets = data.datasets;
  11191. var isHorizontal = me.isHorizontal();
  11192. function IDMatches(meta) {
  11193. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  11194. }
  11195. // First Calculate the range
  11196. me.min = null;
  11197. me.max = null;
  11198. if (opts.stacked) {
  11199. var valuesPerType = {};
  11200. var hasPositiveValues = false;
  11201. var hasNegativeValues = false;
  11202. helpers.each(datasets, function(dataset, datasetIndex) {
  11203. var meta = chart.getDatasetMeta(datasetIndex);
  11204. if (valuesPerType[meta.type] === undefined) {
  11205. valuesPerType[meta.type] = {
  11206. positiveValues: [],
  11207. negativeValues: []
  11208. };
  11209. }
  11210. // Store these per type
  11211. var positiveValues = valuesPerType[meta.type].positiveValues;
  11212. var negativeValues = valuesPerType[meta.type].negativeValues;
  11213. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  11214. helpers.each(dataset.data, function(rawValue, index) {
  11215. var value = +me.getRightValue(rawValue);
  11216. if (isNaN(value) || meta.data[index].hidden) {
  11217. return;
  11218. }
  11219. positiveValues[index] = positiveValues[index] || 0;
  11220. negativeValues[index] = negativeValues[index] || 0;
  11221. if (opts.relativePoints) {
  11222. positiveValues[index] = 100;
  11223. } else {
  11224. if (value < 0) {
  11225. hasNegativeValues = true;
  11226. negativeValues[index] += value;
  11227. } else {
  11228. hasPositiveValues = true;
  11229. positiveValues[index] += value;
  11230. }
  11231. }
  11232. });
  11233. }
  11234. });
  11235. helpers.each(valuesPerType, function(valuesForType) {
  11236. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  11237. var minVal = helpers.min(values);
  11238. var maxVal = helpers.max(values);
  11239. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  11240. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  11241. });
  11242. } else {
  11243. helpers.each(datasets, function(dataset, datasetIndex) {
  11244. var meta = chart.getDatasetMeta(datasetIndex);
  11245. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  11246. helpers.each(dataset.data, function(rawValue, index) {
  11247. var value = +me.getRightValue(rawValue);
  11248. if (isNaN(value) || meta.data[index].hidden) {
  11249. return;
  11250. }
  11251. if (me.min === null) {
  11252. me.min = value;
  11253. } else if (value < me.min) {
  11254. me.min = value;
  11255. }
  11256. if (me.max === null) {
  11257. me.max = value;
  11258. } else if (value > me.max) {
  11259. me.max = value;
  11260. }
  11261. });
  11262. }
  11263. });
  11264. }
  11265. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  11266. this.handleTickRangeOptions();
  11267. },
  11268. getTickLimit: function() {
  11269. var maxTicks;
  11270. var me = this;
  11271. var tickOpts = me.options.ticks;
  11272. if (me.isHorizontal()) {
  11273. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
  11274. } else {
  11275. // The factor of 2 used to scale the font size has been experimentally determined.
  11276. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, Chart.defaults.global.defaultFontSize);
  11277. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
  11278. }
  11279. return maxTicks;
  11280. },
  11281. // Called after the ticks are built. We need
  11282. handleDirectionalChanges: function() {
  11283. if (!this.isHorizontal()) {
  11284. // We are in a vertical orientation. The top value is the highest. So reverse the array
  11285. this.ticks.reverse();
  11286. }
  11287. },
  11288. getLabelForIndex: function(index, datasetIndex) {
  11289. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11290. },
  11291. // Utils
  11292. getPixelForValue: function(value) {
  11293. // This must be called after fit has been run so that
  11294. // this.left, this.top, this.right, and this.bottom have been defined
  11295. var me = this;
  11296. var paddingLeft = me.paddingLeft;
  11297. var paddingBottom = me.paddingBottom;
  11298. var start = me.start;
  11299. var rightValue = +me.getRightValue(value);
  11300. var pixel;
  11301. var innerDimension;
  11302. var range = me.end - start;
  11303. if (me.isHorizontal()) {
  11304. innerDimension = me.width - (paddingLeft + me.paddingRight);
  11305. pixel = me.left + (innerDimension / range * (rightValue - start));
  11306. return Math.round(pixel + paddingLeft);
  11307. } else {
  11308. innerDimension = me.height - (me.paddingTop + paddingBottom);
  11309. pixel = (me.bottom - paddingBottom) - (innerDimension / range * (rightValue - start));
  11310. return Math.round(pixel);
  11311. }
  11312. },
  11313. getValueForPixel: function(pixel) {
  11314. var me = this;
  11315. var isHorizontal = me.isHorizontal();
  11316. var paddingLeft = me.paddingLeft;
  11317. var paddingBottom = me.paddingBottom;
  11318. var innerDimension = isHorizontal ? me.width - (paddingLeft + me.paddingRight) : me.height - (me.paddingTop + paddingBottom);
  11319. var offset = (isHorizontal ? pixel - me.left - paddingLeft : me.bottom - paddingBottom - pixel) / innerDimension;
  11320. return me.start + ((me.end - me.start) * offset);
  11321. },
  11322. getPixelForTick: function(index) {
  11323. return this.getPixelForValue(this.ticksAsNumbers[index]);
  11324. }
  11325. });
  11326. Chart.scaleService.registerScaleType("linear", LinearScale, defaultConfig);
  11327. };
  11328. },{}],41:[function(require,module,exports){
  11329. "use strict";
  11330. module.exports = function(Chart) {
  11331. var helpers = Chart.helpers,
  11332. noop = helpers.noop;
  11333. Chart.LinearScaleBase = Chart.Scale.extend({
  11334. handleTickRangeOptions: function() {
  11335. var me = this;
  11336. var opts = me.options;
  11337. var tickOpts = opts.ticks;
  11338. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  11339. // do nothing since that would make the chart weird. If the user really wants a weird chart
  11340. // axis, they can manually override it
  11341. if (tickOpts.beginAtZero) {
  11342. var minSign = helpers.sign(me.min);
  11343. var maxSign = helpers.sign(me.max);
  11344. if (minSign < 0 && maxSign < 0) {
  11345. // move the top up to 0
  11346. me.max = 0;
  11347. } else if (minSign > 0 && maxSign > 0) {
  11348. // move the botttom down to 0
  11349. me.min = 0;
  11350. }
  11351. }
  11352. if (tickOpts.min !== undefined) {
  11353. me.min = tickOpts.min;
  11354. } else if (tickOpts.suggestedMin !== undefined) {
  11355. me.min = Math.min(me.min, tickOpts.suggestedMin);
  11356. }
  11357. if (tickOpts.max !== undefined) {
  11358. me.max = tickOpts.max;
  11359. } else if (tickOpts.suggestedMax !== undefined) {
  11360. me.max = Math.max(me.max, tickOpts.suggestedMax);
  11361. }
  11362. if (me.min === me.max) {
  11363. me.max++;
  11364. if (!tickOpts.beginAtZero) {
  11365. me.min--;
  11366. }
  11367. }
  11368. },
  11369. getTickLimit: noop,
  11370. handleDirectionalChanges: noop,
  11371. buildTicks: function() {
  11372. var me = this;
  11373. var opts = me.options;
  11374. var ticks = me.ticks = [];
  11375. var tickOpts = opts.ticks;
  11376. var getValueOrDefault = helpers.getValueOrDefault;
  11377. // Figure out what the max number of ticks we can support it is based on the size of
  11378. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  11379. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  11380. // the graph
  11381. var maxTicks = me.getTickLimit();
  11382. // Make sure we always have at least 2 ticks
  11383. maxTicks = Math.max(2, maxTicks);
  11384. // To get a "nice" value for the tick spacing, we will use the appropriately named
  11385. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  11386. // for details.
  11387. var spacing;
  11388. var fixedStepSizeSet = (tickOpts.fixedStepSize && tickOpts.fixedStepSize > 0) || (tickOpts.stepSize && tickOpts.stepSize > 0);
  11389. if (fixedStepSizeSet) {
  11390. spacing = getValueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize);
  11391. } else {
  11392. var niceRange = helpers.niceNum(me.max - me.min, false);
  11393. spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
  11394. }
  11395. var niceMin = Math.floor(me.min / spacing) * spacing;
  11396. var niceMax = Math.ceil(me.max / spacing) * spacing;
  11397. var numSpaces = (niceMax - niceMin) / spacing;
  11398. // If very close to our rounded value, use it.
  11399. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  11400. numSpaces = Math.round(numSpaces);
  11401. } else {
  11402. numSpaces = Math.ceil(numSpaces);
  11403. }
  11404. // Put the values into the ticks array
  11405. ticks.push(tickOpts.min !== undefined ? tickOpts.min : niceMin);
  11406. for (var j = 1; j < numSpaces; ++j) {
  11407. ticks.push(niceMin + (j * spacing));
  11408. }
  11409. ticks.push(tickOpts.max !== undefined ? tickOpts.max : niceMax);
  11410. me.handleDirectionalChanges();
  11411. // At this point, we need to update our max and min given the tick values since we have expanded the
  11412. // range of the scale
  11413. me.max = helpers.max(ticks);
  11414. me.min = helpers.min(ticks);
  11415. if (tickOpts.reverse) {
  11416. ticks.reverse();
  11417. me.start = me.max;
  11418. me.end = me.min;
  11419. } else {
  11420. me.start = me.min;
  11421. me.end = me.max;
  11422. }
  11423. },
  11424. convertTicksToLabels: function() {
  11425. var me = this;
  11426. me.ticksAsNumbers = me.ticks.slice();
  11427. me.zeroLineIndex = me.ticks.indexOf(0);
  11428. Chart.Scale.prototype.convertTicksToLabels.call(me);
  11429. },
  11430. });
  11431. };
  11432. },{}],42:[function(require,module,exports){
  11433. "use strict";
  11434. module.exports = function(Chart) {
  11435. var helpers = Chart.helpers;
  11436. var defaultConfig = {
  11437. position: "left",
  11438. // label settings
  11439. ticks: {
  11440. callback: function(value, index, arr) {
  11441. var remain = value / (Math.pow(10, Math.floor(helpers.log10(value))));
  11442. if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === arr.length - 1) {
  11443. return value.toExponential();
  11444. } else {
  11445. return '';
  11446. }
  11447. }
  11448. }
  11449. };
  11450. var LogarithmicScale = Chart.Scale.extend({
  11451. determineDataLimits: function() {
  11452. var me = this;
  11453. var opts = me.options;
  11454. var tickOpts = opts.ticks;
  11455. var chart = me.chart;
  11456. var data = chart.data;
  11457. var datasets = data.datasets;
  11458. var getValueOrDefault = helpers.getValueOrDefault;
  11459. var isHorizontal = me.isHorizontal();
  11460. function IDMatches(meta) {
  11461. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  11462. }
  11463. // Calculate Range
  11464. me.min = null;
  11465. me.max = null;
  11466. if (opts.stacked) {
  11467. var valuesPerType = {};
  11468. helpers.each(datasets, function(dataset, datasetIndex) {
  11469. var meta = chart.getDatasetMeta(datasetIndex);
  11470. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  11471. if (valuesPerType[meta.type] === undefined) {
  11472. valuesPerType[meta.type] = [];
  11473. }
  11474. helpers.each(dataset.data, function(rawValue, index) {
  11475. var values = valuesPerType[meta.type];
  11476. var value = +me.getRightValue(rawValue);
  11477. if (isNaN(value) || meta.data[index].hidden) {
  11478. return;
  11479. }
  11480. values[index] = values[index] || 0;
  11481. if (opts.relativePoints) {
  11482. values[index] = 100;
  11483. } else {
  11484. // Don't need to split positive and negative since the log scale can't handle a 0 crossing
  11485. values[index] += value;
  11486. }
  11487. });
  11488. }
  11489. });
  11490. helpers.each(valuesPerType, function(valuesForType) {
  11491. var minVal = helpers.min(valuesForType);
  11492. var maxVal = helpers.max(valuesForType);
  11493. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  11494. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  11495. });
  11496. } else {
  11497. helpers.each(datasets, function(dataset, datasetIndex) {
  11498. var meta = chart.getDatasetMeta(datasetIndex);
  11499. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  11500. helpers.each(dataset.data, function(rawValue, index) {
  11501. var value = +me.getRightValue(rawValue);
  11502. if (isNaN(value) || meta.data[index].hidden) {
  11503. return;
  11504. }
  11505. if (me.min === null) {
  11506. me.min = value;
  11507. } else if (value < me.min) {
  11508. me.min = value;
  11509. }
  11510. if (me.max === null) {
  11511. me.max = value;
  11512. } else if (value > me.max) {
  11513. me.max = value;
  11514. }
  11515. });
  11516. }
  11517. });
  11518. }
  11519. me.min = getValueOrDefault(tickOpts.min, me.min);
  11520. me.max = getValueOrDefault(tickOpts.max, me.max);
  11521. if (me.min === me.max) {
  11522. if (me.min !== 0 && me.min !== null) {
  11523. me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
  11524. me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
  11525. } else {
  11526. me.min = 1;
  11527. me.max = 10;
  11528. }
  11529. }
  11530. },
  11531. buildTicks: function() {
  11532. var me = this;
  11533. var opts = me.options;
  11534. var tickOpts = opts.ticks;
  11535. var getValueOrDefault = helpers.getValueOrDefault;
  11536. // Reset the ticks array. Later on, we will draw a grid line at these positions
  11537. // The array simply contains the numerical value of the spots where ticks will be
  11538. var ticks = me.ticks = [];
  11539. // Figure out what the max number of ticks we can support it is based on the size of
  11540. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  11541. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  11542. // the graph
  11543. var tickVal = getValueOrDefault(tickOpts.min, Math.pow(10, Math.floor(helpers.log10(me.min))));
  11544. while (tickVal < me.max) {
  11545. ticks.push(tickVal);
  11546. var exp = Math.floor(helpers.log10(tickVal));
  11547. var significand = Math.floor(tickVal / Math.pow(10, exp)) + 1;
  11548. if (significand === 10) {
  11549. significand = 1;
  11550. ++exp;
  11551. }
  11552. tickVal = significand * Math.pow(10, exp);
  11553. }
  11554. var lastTick = getValueOrDefault(tickOpts.max, tickVal);
  11555. ticks.push(lastTick);
  11556. if (!me.isHorizontal()) {
  11557. // We are in a vertical orientation. The top value is the highest. So reverse the array
  11558. ticks.reverse();
  11559. }
  11560. // At this point, we need to update our max and min given the tick values since we have expanded the
  11561. // range of the scale
  11562. me.max = helpers.max(ticks);
  11563. me.min = helpers.min(ticks);
  11564. if (tickOpts.reverse) {
  11565. ticks.reverse();
  11566. me.start = me.max;
  11567. me.end = me.min;
  11568. } else {
  11569. me.start = me.min;
  11570. me.end = me.max;
  11571. }
  11572. },
  11573. convertTicksToLabels: function() {
  11574. this.tickValues = this.ticks.slice();
  11575. Chart.Scale.prototype.convertTicksToLabels.call(this);
  11576. },
  11577. // Get the correct tooltip label
  11578. getLabelForIndex: function(index, datasetIndex) {
  11579. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11580. },
  11581. getPixelForTick: function(index) {
  11582. return this.getPixelForValue(this.tickValues[index]);
  11583. },
  11584. getPixelForValue: function(value) {
  11585. var me = this;
  11586. var innerDimension;
  11587. var pixel;
  11588. var start = me.start;
  11589. var newVal = +me.getRightValue(value);
  11590. var range = helpers.log10(me.end) - helpers.log10(start);
  11591. var paddingTop = me.paddingTop;
  11592. var paddingBottom = me.paddingBottom;
  11593. var paddingLeft = me.paddingLeft;
  11594. if (me.isHorizontal()) {
  11595. if (newVal === 0) {
  11596. pixel = me.left + paddingLeft;
  11597. } else {
  11598. innerDimension = me.width - (paddingLeft + me.paddingRight);
  11599. pixel = me.left + (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
  11600. pixel += paddingLeft;
  11601. }
  11602. } else {
  11603. // Bottom - top since pixels increase downard on a screen
  11604. if (newVal === 0) {
  11605. pixel = me.top + paddingTop;
  11606. } else {
  11607. innerDimension = me.height - (paddingTop + paddingBottom);
  11608. pixel = (me.bottom - paddingBottom) - (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
  11609. }
  11610. }
  11611. return pixel;
  11612. },
  11613. getValueForPixel: function(pixel) {
  11614. var me = this;
  11615. var range = helpers.log10(me.end) - helpers.log10(me.start);
  11616. var value, innerDimension;
  11617. if (me.isHorizontal()) {
  11618. innerDimension = me.width - (me.paddingLeft + me.paddingRight);
  11619. value = me.start * Math.pow(10, (pixel - me.left - me.paddingLeft) * range / innerDimension);
  11620. } else {
  11621. innerDimension = me.height - (me.paddingTop + me.paddingBottom);
  11622. value = Math.pow(10, (me.bottom - me.paddingBottom - pixel) * range / innerDimension) / me.start;
  11623. }
  11624. return value;
  11625. }
  11626. });
  11627. Chart.scaleService.registerScaleType("logarithmic", LogarithmicScale, defaultConfig);
  11628. };
  11629. },{}],43:[function(require,module,exports){
  11630. "use strict";
  11631. module.exports = function(Chart) {
  11632. var helpers = Chart.helpers;
  11633. var globalDefaults = Chart.defaults.global;
  11634. var defaultConfig = {
  11635. display: true,
  11636. //Boolean - Whether to animate scaling the chart from the centre
  11637. animate: true,
  11638. lineArc: false,
  11639. position: "chartArea",
  11640. angleLines: {
  11641. display: true,
  11642. color: "rgba(0, 0, 0, 0.1)",
  11643. lineWidth: 1
  11644. },
  11645. // label settings
  11646. ticks: {
  11647. //Boolean - Show a backdrop to the scale label
  11648. showLabelBackdrop: true,
  11649. //String - The colour of the label backdrop
  11650. backdropColor: "rgba(255,255,255,0.75)",
  11651. //Number - The backdrop padding above & below the label in pixels
  11652. backdropPaddingY: 2,
  11653. //Number - The backdrop padding to the side of the label in pixels
  11654. backdropPaddingX: 2
  11655. },
  11656. pointLabels: {
  11657. //Number - Point label font size in pixels
  11658. fontSize: 10,
  11659. //Function - Used to convert point labels
  11660. callback: function(label) {
  11661. return label;
  11662. }
  11663. }
  11664. };
  11665. var LinearRadialScale = Chart.LinearScaleBase.extend({
  11666. getValueCount: function() {
  11667. return this.chart.data.labels.length;
  11668. },
  11669. setDimensions: function() {
  11670. var me = this;
  11671. var opts = me.options;
  11672. var tickOpts = opts.ticks;
  11673. // Set the unconstrained dimension before label rotation
  11674. me.width = me.maxWidth;
  11675. me.height = me.maxHeight;
  11676. me.xCenter = Math.round(me.width / 2);
  11677. me.yCenter = Math.round(me.height / 2);
  11678. var minSize = helpers.min([me.height, me.width]);
  11679. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11680. me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
  11681. },
  11682. determineDataLimits: function() {
  11683. var me = this;
  11684. var chart = me.chart;
  11685. me.min = null;
  11686. me.max = null;
  11687. helpers.each(chart.data.datasets, function(dataset, datasetIndex) {
  11688. if (chart.isDatasetVisible(datasetIndex)) {
  11689. var meta = chart.getDatasetMeta(datasetIndex);
  11690. helpers.each(dataset.data, function(rawValue, index) {
  11691. var value = +me.getRightValue(rawValue);
  11692. if (isNaN(value) || meta.data[index].hidden) {
  11693. return;
  11694. }
  11695. if (me.min === null) {
  11696. me.min = value;
  11697. } else if (value < me.min) {
  11698. me.min = value;
  11699. }
  11700. if (me.max === null) {
  11701. me.max = value;
  11702. } else if (value > me.max) {
  11703. me.max = value;
  11704. }
  11705. });
  11706. }
  11707. });
  11708. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  11709. me.handleTickRangeOptions();
  11710. },
  11711. getTickLimit: function() {
  11712. var tickOpts = this.options.ticks;
  11713. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11714. return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  11715. },
  11716. convertTicksToLabels: function() {
  11717. var me = this;
  11718. Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
  11719. // Point labels
  11720. me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
  11721. },
  11722. getLabelForIndex: function(index, datasetIndex) {
  11723. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11724. },
  11725. fit: function() {
  11726. /*
  11727. * Right, this is really confusing and there is a lot of maths going on here
  11728. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  11729. *
  11730. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  11731. *
  11732. * Solution:
  11733. *
  11734. * We assume the radius of the polygon is half the size of the canvas at first
  11735. * at each index we check if the text overlaps.
  11736. *
  11737. * Where it does, we store that angle and that index.
  11738. *
  11739. * After finding the largest index and angle we calculate how much we need to remove
  11740. * from the shape radius to move the point inwards by that x.
  11741. *
  11742. * We average the left and right distances to get the maximum shape radius that can fit in the box
  11743. * along with labels.
  11744. *
  11745. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  11746. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  11747. *
  11748. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  11749. * and position it in the most space efficient manner
  11750. *
  11751. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  11752. */
  11753. var pointLabels = this.options.pointLabels;
  11754. var pointLabelFontSize = helpers.getValueOrDefault(pointLabels.fontSize, globalDefaults.defaultFontSize);
  11755. var pointLabeFontStyle = helpers.getValueOrDefault(pointLabels.fontStyle, globalDefaults.defaultFontStyle);
  11756. var pointLabeFontFamily = helpers.getValueOrDefault(pointLabels.fontFamily, globalDefaults.defaultFontFamily);
  11757. var pointLabeFont = helpers.fontString(pointLabelFontSize, pointLabeFontStyle, pointLabeFontFamily);
  11758. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  11759. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  11760. var largestPossibleRadius = helpers.min([(this.height / 2 - pointLabelFontSize - 5), this.width / 2]),
  11761. pointPosition,
  11762. i,
  11763. textWidth,
  11764. halfTextWidth,
  11765. furthestRight = this.width,
  11766. furthestRightIndex,
  11767. furthestRightAngle,
  11768. furthestLeft = 0,
  11769. furthestLeftIndex,
  11770. furthestLeftAngle,
  11771. xProtrusionLeft,
  11772. xProtrusionRight,
  11773. radiusReductionRight,
  11774. radiusReductionLeft;
  11775. this.ctx.font = pointLabeFont;
  11776. for (i = 0; i < this.getValueCount(); i++) {
  11777. // 5px to space the text slightly out - similar to what we do in the draw function.
  11778. pointPosition = this.getPointPosition(i, largestPossibleRadius);
  11779. textWidth = this.ctx.measureText(this.pointLabels[i] ? this.pointLabels[i] : '').width + 5;
  11780. // Add quarter circle to make degree 0 mean top of circle
  11781. var angleRadians = this.getIndexAngle(i) + (Math.PI / 2);
  11782. var angle = (angleRadians * 360 / (2 * Math.PI)) % 360;
  11783. if (angle === 0 || angle === 180) {
  11784. // At angle 0 and 180, we're at exactly the top/bottom
  11785. // of the radar chart, so text will be aligned centrally, so we'll half it and compare
  11786. // w/left and right text sizes
  11787. halfTextWidth = textWidth / 2;
  11788. if (pointPosition.x + halfTextWidth > furthestRight) {
  11789. furthestRight = pointPosition.x + halfTextWidth;
  11790. furthestRightIndex = i;
  11791. }
  11792. if (pointPosition.x - halfTextWidth < furthestLeft) {
  11793. furthestLeft = pointPosition.x - halfTextWidth;
  11794. furthestLeftIndex = i;
  11795. }
  11796. } else if (angle < 180) {
  11797. // Less than half the values means we'll left align the text
  11798. if (pointPosition.x + textWidth > furthestRight) {
  11799. furthestRight = pointPosition.x + textWidth;
  11800. furthestRightIndex = i;
  11801. }
  11802. } else {
  11803. // More than half the values means we'll right align the text
  11804. if (pointPosition.x - textWidth < furthestLeft) {
  11805. furthestLeft = pointPosition.x - textWidth;
  11806. furthestLeftIndex = i;
  11807. }
  11808. }
  11809. }
  11810. xProtrusionLeft = furthestLeft;
  11811. xProtrusionRight = Math.ceil(furthestRight - this.width);
  11812. furthestRightAngle = this.getIndexAngle(furthestRightIndex);
  11813. furthestLeftAngle = this.getIndexAngle(furthestLeftIndex);
  11814. radiusReductionRight = xProtrusionRight / Math.sin(furthestRightAngle + Math.PI / 2);
  11815. radiusReductionLeft = xProtrusionLeft / Math.sin(furthestLeftAngle + Math.PI / 2);
  11816. // Ensure we actually need to reduce the size of the chart
  11817. radiusReductionRight = (helpers.isNumber(radiusReductionRight)) ? radiusReductionRight : 0;
  11818. radiusReductionLeft = (helpers.isNumber(radiusReductionLeft)) ? radiusReductionLeft : 0;
  11819. this.drawingArea = Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2);
  11820. this.setCenterPoint(radiusReductionLeft, radiusReductionRight);
  11821. },
  11822. setCenterPoint: function(leftMovement, rightMovement) {
  11823. var me = this;
  11824. var maxRight = me.width - rightMovement - me.drawingArea,
  11825. maxLeft = leftMovement + me.drawingArea;
  11826. me.xCenter = Math.round(((maxLeft + maxRight) / 2) + me.left);
  11827. // Always vertically in the centre as the text height doesn't change
  11828. me.yCenter = Math.round((me.height / 2) + me.top);
  11829. },
  11830. getIndexAngle: function(index) {
  11831. var angleMultiplier = (Math.PI * 2) / this.getValueCount();
  11832. var startAngle = this.chart.options && this.chart.options.startAngle ?
  11833. this.chart.options.startAngle :
  11834. 0;
  11835. var startAngleRadians = startAngle * Math.PI * 2 / 360;
  11836. // Start from the top instead of right, so remove a quarter of the circle
  11837. return index * angleMultiplier - (Math.PI / 2) + startAngleRadians;
  11838. },
  11839. getDistanceFromCenterForValue: function(value) {
  11840. var me = this;
  11841. if (value === null) {
  11842. return 0; // null always in center
  11843. }
  11844. // Take into account half font size + the yPadding of the top value
  11845. var scalingFactor = me.drawingArea / (me.max - me.min);
  11846. if (me.options.reverse) {
  11847. return (me.max - value) * scalingFactor;
  11848. } else {
  11849. return (value - me.min) * scalingFactor;
  11850. }
  11851. },
  11852. getPointPosition: function(index, distanceFromCenter) {
  11853. var me = this;
  11854. var thisAngle = me.getIndexAngle(index);
  11855. return {
  11856. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
  11857. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
  11858. };
  11859. },
  11860. getPointPositionForValue: function(index, value) {
  11861. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  11862. },
  11863. getBasePosition: function() {
  11864. var me = this;
  11865. var min = me.min;
  11866. var max = me.max;
  11867. return me.getPointPositionForValue(0,
  11868. me.beginAtZero? 0:
  11869. min < 0 && max < 0? max :
  11870. min > 0 && max > 0? min :
  11871. 0);
  11872. },
  11873. draw: function() {
  11874. var me = this;
  11875. var opts = me.options;
  11876. var gridLineOpts = opts.gridLines;
  11877. var tickOpts = opts.ticks;
  11878. var angleLineOpts = opts.angleLines;
  11879. var pointLabelOpts = opts.pointLabels;
  11880. var getValueOrDefault = helpers.getValueOrDefault;
  11881. if (opts.display) {
  11882. var ctx = me.ctx;
  11883. // Tick Font
  11884. var tickFontSize = getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11885. var tickFontStyle = getValueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  11886. var tickFontFamily = getValueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  11887. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  11888. helpers.each(me.ticks, function(label, index) {
  11889. // Don't draw a centre value (if it is minimum)
  11890. if (index > 0 || opts.reverse) {
  11891. var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
  11892. var yHeight = me.yCenter - yCenterOffset;
  11893. // Draw circular lines around the scale
  11894. if (gridLineOpts.display && index !== 0) {
  11895. ctx.strokeStyle = helpers.getValueAtIndexOrDefault(gridLineOpts.color, index - 1);
  11896. ctx.lineWidth = helpers.getValueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
  11897. if (opts.lineArc) {
  11898. // Draw circular arcs between the points
  11899. ctx.beginPath();
  11900. ctx.arc(me.xCenter, me.yCenter, yCenterOffset, 0, Math.PI * 2);
  11901. ctx.closePath();
  11902. ctx.stroke();
  11903. } else {
  11904. // Draw straight lines connecting each index
  11905. ctx.beginPath();
  11906. for (var i = 0; i < me.getValueCount(); i++) {
  11907. var pointPosition = me.getPointPosition(i, yCenterOffset);
  11908. if (i === 0) {
  11909. ctx.moveTo(pointPosition.x, pointPosition.y);
  11910. } else {
  11911. ctx.lineTo(pointPosition.x, pointPosition.y);
  11912. }
  11913. }
  11914. ctx.closePath();
  11915. ctx.stroke();
  11916. }
  11917. }
  11918. if (tickOpts.display) {
  11919. var tickFontColor = getValueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
  11920. ctx.font = tickLabelFont;
  11921. if (tickOpts.showLabelBackdrop) {
  11922. var labelWidth = ctx.measureText(label).width;
  11923. ctx.fillStyle = tickOpts.backdropColor;
  11924. ctx.fillRect(
  11925. me.xCenter - labelWidth / 2 - tickOpts.backdropPaddingX,
  11926. yHeight - tickFontSize / 2 - tickOpts.backdropPaddingY,
  11927. labelWidth + tickOpts.backdropPaddingX * 2,
  11928. tickFontSize + tickOpts.backdropPaddingY * 2
  11929. );
  11930. }
  11931. ctx.textAlign = 'center';
  11932. ctx.textBaseline = "middle";
  11933. ctx.fillStyle = tickFontColor;
  11934. ctx.fillText(label, me.xCenter, yHeight);
  11935. }
  11936. }
  11937. });
  11938. if (!opts.lineArc) {
  11939. ctx.lineWidth = angleLineOpts.lineWidth;
  11940. ctx.strokeStyle = angleLineOpts.color;
  11941. var outerDistance = me.getDistanceFromCenterForValue(opts.reverse ? me.min : me.max);
  11942. // Point Label Font
  11943. var pointLabelFontSize = getValueOrDefault(pointLabelOpts.fontSize, globalDefaults.defaultFontSize);
  11944. var pointLabeFontStyle = getValueOrDefault(pointLabelOpts.fontStyle, globalDefaults.defaultFontStyle);
  11945. var pointLabeFontFamily = getValueOrDefault(pointLabelOpts.fontFamily, globalDefaults.defaultFontFamily);
  11946. var pointLabeFont = helpers.fontString(pointLabelFontSize, pointLabeFontStyle, pointLabeFontFamily);
  11947. for (var i = me.getValueCount() - 1; i >= 0; i--) {
  11948. if (angleLineOpts.display) {
  11949. var outerPosition = me.getPointPosition(i, outerDistance);
  11950. ctx.beginPath();
  11951. ctx.moveTo(me.xCenter, me.yCenter);
  11952. ctx.lineTo(outerPosition.x, outerPosition.y);
  11953. ctx.stroke();
  11954. ctx.closePath();
  11955. }
  11956. // Extra 3px out for some label spacing
  11957. var pointLabelPosition = me.getPointPosition(i, outerDistance + 5);
  11958. // Keep this in loop since we may support array properties here
  11959. var pointLabelFontColor = getValueOrDefault(pointLabelOpts.fontColor, globalDefaults.defaultFontColor);
  11960. ctx.font = pointLabeFont;
  11961. ctx.fillStyle = pointLabelFontColor;
  11962. var pointLabels = me.pointLabels;
  11963. // Add quarter circle to make degree 0 mean top of circle
  11964. var angleRadians = this.getIndexAngle(i) + (Math.PI / 2);
  11965. var angle = (angleRadians * 360 / (2 * Math.PI)) % 360;
  11966. if (angle === 0 || angle === 180) {
  11967. ctx.textAlign = 'center';
  11968. } else if (angle < 180) {
  11969. ctx.textAlign = 'left';
  11970. } else {
  11971. ctx.textAlign = 'right';
  11972. }
  11973. // Set the correct text baseline based on outer positioning
  11974. if (angle === 90 || angle === 270) {
  11975. ctx.textBaseline = 'middle';
  11976. } else if (angle > 270 || angle < 90) {
  11977. ctx.textBaseline = 'bottom';
  11978. } else {
  11979. ctx.textBaseline = 'top';
  11980. }
  11981. ctx.fillText(pointLabels[i] ? pointLabels[i] : '', pointLabelPosition.x, pointLabelPosition.y);
  11982. }
  11983. }
  11984. }
  11985. }
  11986. });
  11987. Chart.scaleService.registerScaleType("radialLinear", LinearRadialScale, defaultConfig);
  11988. };
  11989. },{}],44:[function(require,module,exports){
  11990. /*global window: false */
  11991. "use strict";
  11992. var moment = require(6);
  11993. moment = typeof(moment) === 'function' ? moment : window.moment;
  11994. module.exports = function(Chart) {
  11995. var helpers = Chart.helpers;
  11996. var time = {
  11997. units: [{
  11998. name: 'millisecond',
  11999. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  12000. }, {
  12001. name: 'second',
  12002. steps: [1, 2, 5, 10, 30]
  12003. }, {
  12004. name: 'minute',
  12005. steps: [1, 2, 5, 10, 30]
  12006. }, {
  12007. name: 'hour',
  12008. steps: [1, 2, 3, 6, 12]
  12009. }, {
  12010. name: 'day',
  12011. steps: [1, 2, 5]
  12012. }, {
  12013. name: 'week',
  12014. maxStep: 4
  12015. }, {
  12016. name: 'month',
  12017. maxStep: 3
  12018. }, {
  12019. name: 'quarter',
  12020. maxStep: 4
  12021. }, {
  12022. name: 'year',
  12023. maxStep: false
  12024. }]
  12025. };
  12026. var defaultConfig = {
  12027. position: "bottom",
  12028. time: {
  12029. parser: false, // false == a pattern string from http://momentjs.com/docs/#/parsing/string-format/ or a custom callback that converts its argument to a moment
  12030. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  12031. unit: false, // false == automatic or override with week, month, year, etc.
  12032. round: false, // none, or override with week, month, year, etc.
  12033. displayFormat: false, // DEPRECATED
  12034. isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
  12035. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  12036. displayFormats: {
  12037. 'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  12038. 'second': 'h:mm:ss a', // 11:20:01 AM
  12039. 'minute': 'h:mm:ss a', // 11:20:01 AM
  12040. 'hour': 'MMM D, hA', // Sept 4, 5PM
  12041. 'day': 'll', // Sep 4 2015
  12042. 'week': 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  12043. 'month': 'MMM YYYY', // Sept 2015
  12044. 'quarter': '[Q]Q - YYYY', // Q3
  12045. 'year': 'YYYY' // 2015
  12046. }
  12047. },
  12048. ticks: {
  12049. autoSkip: false
  12050. }
  12051. };
  12052. var TimeScale = Chart.Scale.extend({
  12053. initialize: function() {
  12054. if (!moment) {
  12055. throw new Error('Chart.js - Moment.js could not be found! You must include it before Chart.js to use the time scale. Download at https://momentjs.com');
  12056. }
  12057. Chart.Scale.prototype.initialize.call(this);
  12058. },
  12059. getLabelMoment: function(datasetIndex, index) {
  12060. if (typeof this.labelMoments[datasetIndex] != 'undefined') {
  12061. return this.labelMoments[datasetIndex][index];
  12062. }
  12063. return null;
  12064. },
  12065. getMomentStartOf: function(tick) {
  12066. var me = this;
  12067. if (me.options.time.unit === 'week' && me.options.time.isoWeekday !== false) {
  12068. return tick.clone().startOf('isoWeek').isoWeekday(me.options.time.isoWeekday);
  12069. } else {
  12070. return tick.clone().startOf(me.tickUnit);
  12071. }
  12072. },
  12073. determineDataLimits: function() {
  12074. var me = this;
  12075. me.labelMoments = [];
  12076. // Only parse these once. If the dataset does not have data as x,y pairs, we will use
  12077. // these
  12078. var scaleLabelMoments = [];
  12079. if (me.chart.data.labels && me.chart.data.labels.length > 0) {
  12080. helpers.each(me.chart.data.labels, function(label) {
  12081. var labelMoment = me.parseTime(label);
  12082. if (labelMoment.isValid()) {
  12083. if (me.options.time.round) {
  12084. labelMoment.startOf(me.options.time.round);
  12085. }
  12086. scaleLabelMoments.push(labelMoment);
  12087. }
  12088. }, me);
  12089. me.firstTick = moment.min.call(me, scaleLabelMoments);
  12090. me.lastTick = moment.max.call(me, scaleLabelMoments);
  12091. } else {
  12092. me.firstTick = null;
  12093. me.lastTick = null;
  12094. }
  12095. helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
  12096. var momentsForDataset = [];
  12097. var datasetVisible = me.chart.isDatasetVisible(datasetIndex);
  12098. if (typeof dataset.data[0] === 'object' && dataset.data[0] !== null) {
  12099. helpers.each(dataset.data, function(value) {
  12100. var labelMoment = me.parseTime(me.getRightValue(value));
  12101. if (labelMoment.isValid()) {
  12102. if (me.options.time.round) {
  12103. labelMoment.startOf(me.options.time.round);
  12104. }
  12105. momentsForDataset.push(labelMoment);
  12106. if (datasetVisible) {
  12107. // May have gone outside the scale ranges, make sure we keep the first and last ticks updated
  12108. me.firstTick = me.firstTick !== null ? moment.min(me.firstTick, labelMoment) : labelMoment;
  12109. me.lastTick = me.lastTick !== null ? moment.max(me.lastTick, labelMoment) : labelMoment;
  12110. }
  12111. }
  12112. }, me);
  12113. } else {
  12114. // We have no labels. Use the ones from the scale
  12115. momentsForDataset = scaleLabelMoments;
  12116. }
  12117. me.labelMoments.push(momentsForDataset);
  12118. }, me);
  12119. // Set these after we've done all the data
  12120. if (me.options.time.min) {
  12121. me.firstTick = me.parseTime(me.options.time.min);
  12122. }
  12123. if (me.options.time.max) {
  12124. me.lastTick = me.parseTime(me.options.time.max);
  12125. }
  12126. // We will modify these, so clone for later
  12127. me.firstTick = (me.firstTick || moment()).clone();
  12128. me.lastTick = (me.lastTick || moment()).clone();
  12129. },
  12130. buildTicks: function() {
  12131. var me = this;
  12132. me.ctx.save();
  12133. var tickFontSize = helpers.getValueOrDefault(me.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  12134. var tickFontStyle = helpers.getValueOrDefault(me.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
  12135. var tickFontFamily = helpers.getValueOrDefault(me.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
  12136. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  12137. me.ctx.font = tickLabelFont;
  12138. me.ticks = [];
  12139. me.unitScale = 1; // How much we scale the unit by, ie 2 means 2x unit per step
  12140. me.scaleSizeInUnits = 0; // How large the scale is in the base unit (seconds, minutes, etc)
  12141. // Set unit override if applicable
  12142. if (me.options.time.unit) {
  12143. me.tickUnit = me.options.time.unit || 'day';
  12144. me.displayFormat = me.options.time.displayFormats[me.tickUnit];
  12145. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  12146. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, 1);
  12147. } else {
  12148. // Determine the smallest needed unit of the time
  12149. var innerWidth = me.isHorizontal() ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
  12150. // Crude approximation of what the label length might be
  12151. var tempFirstLabel = me.tickFormatFunction(me.firstTick, 0, []);
  12152. var tickLabelWidth = me.ctx.measureText(tempFirstLabel).width;
  12153. var cosRotation = Math.cos(helpers.toRadians(me.options.ticks.maxRotation));
  12154. var sinRotation = Math.sin(helpers.toRadians(me.options.ticks.maxRotation));
  12155. tickLabelWidth = (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  12156. var labelCapacity = innerWidth / (tickLabelWidth);
  12157. // Start as small as possible
  12158. me.tickUnit = 'millisecond';
  12159. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  12160. me.displayFormat = me.options.time.displayFormats[me.tickUnit];
  12161. var unitDefinitionIndex = 0;
  12162. var unitDefinition = time.units[unitDefinitionIndex];
  12163. // While we aren't ideal and we don't have units left
  12164. while (unitDefinitionIndex < time.units.length) {
  12165. // Can we scale this unit. If `false` we can scale infinitely
  12166. me.unitScale = 1;
  12167. if (helpers.isArray(unitDefinition.steps) && Math.ceil(me.scaleSizeInUnits / labelCapacity) < helpers.max(unitDefinition.steps)) {
  12168. // Use one of the prefedined steps
  12169. for (var idx = 0; idx < unitDefinition.steps.length; ++idx) {
  12170. if (unitDefinition.steps[idx] >= Math.ceil(me.scaleSizeInUnits / labelCapacity)) {
  12171. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, unitDefinition.steps[idx]);
  12172. break;
  12173. }
  12174. }
  12175. break;
  12176. } else if ((unitDefinition.maxStep === false) || (Math.ceil(me.scaleSizeInUnits / labelCapacity) < unitDefinition.maxStep)) {
  12177. // We have a max step. Scale this unit
  12178. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, Math.ceil(me.scaleSizeInUnits / labelCapacity));
  12179. break;
  12180. } else {
  12181. // Move to the next unit up
  12182. ++unitDefinitionIndex;
  12183. unitDefinition = time.units[unitDefinitionIndex];
  12184. me.tickUnit = unitDefinition.name;
  12185. var leadingUnitBuffer = me.firstTick.diff(me.getMomentStartOf(me.firstTick), me.tickUnit, true);
  12186. var trailingUnitBuffer = me.getMomentStartOf(me.lastTick.clone().add(1, me.tickUnit)).diff(me.lastTick, me.tickUnit, true);
  12187. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true) + leadingUnitBuffer + trailingUnitBuffer;
  12188. me.displayFormat = me.options.time.displayFormats[unitDefinition.name];
  12189. }
  12190. }
  12191. }
  12192. var roundedStart;
  12193. // Only round the first tick if we have no hard minimum
  12194. if (!me.options.time.min) {
  12195. me.firstTick = me.getMomentStartOf(me.firstTick);
  12196. roundedStart = me.firstTick;
  12197. } else {
  12198. roundedStart = me.getMomentStartOf(me.firstTick);
  12199. }
  12200. // Only round the last tick if we have no hard maximum
  12201. if (!me.options.time.max) {
  12202. var roundedEnd = me.getMomentStartOf(me.lastTick);
  12203. var delta = roundedEnd.diff(me.lastTick, me.tickUnit, true);
  12204. if (delta < 0) {
  12205. // Do not use end of because we need me to be in the next time unit
  12206. me.lastTick = me.getMomentStartOf(me.lastTick.add(1, me.tickUnit));
  12207. } else if (delta >= 0) {
  12208. me.lastTick = roundedEnd;
  12209. }
  12210. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  12211. }
  12212. me.smallestLabelSeparation = me.width;
  12213. helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
  12214. for (var i = 1; i < me.labelMoments[datasetIndex].length; i++) {
  12215. me.smallestLabelSeparation = Math.min(me.smallestLabelSeparation, me.labelMoments[datasetIndex][i].diff(me.labelMoments[datasetIndex][i - 1], me.tickUnit, true));
  12216. }
  12217. }, me);
  12218. // Tick displayFormat override
  12219. if (me.options.time.displayFormat) {
  12220. me.displayFormat = me.options.time.displayFormat;
  12221. }
  12222. // first tick. will have been rounded correctly if options.time.min is not specified
  12223. me.ticks.push(me.firstTick.clone());
  12224. // For every unit in between the first and last moment, create a moment and add it to the ticks tick
  12225. for (var i = 1; i <= me.scaleSizeInUnits; ++i) {
  12226. var newTick = roundedStart.clone().add(i, me.tickUnit);
  12227. // Are we greater than the max time
  12228. if (me.options.time.max && newTick.diff(me.lastTick, me.tickUnit, true) >= 0) {
  12229. break;
  12230. }
  12231. if (i % me.unitScale === 0) {
  12232. me.ticks.push(newTick);
  12233. }
  12234. }
  12235. // Always show the right tick
  12236. var diff = me.ticks[me.ticks.length - 1].diff(me.lastTick, me.tickUnit);
  12237. if (diff !== 0 || me.scaleSizeInUnits === 0) {
  12238. // this is a weird case. If the <max> option is the same as the end option, we can't just diff the times because the tick was created from the roundedStart
  12239. // but the last tick was not rounded.
  12240. if (me.options.time.max) {
  12241. me.ticks.push(me.lastTick.clone());
  12242. me.scaleSizeInUnits = me.lastTick.diff(me.ticks[0], me.tickUnit, true);
  12243. } else {
  12244. me.ticks.push(me.lastTick.clone());
  12245. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  12246. }
  12247. }
  12248. me.ctx.restore();
  12249. },
  12250. // Get tooltip label
  12251. getLabelForIndex: function(index, datasetIndex) {
  12252. var me = this;
  12253. var label = me.chart.data.labels && index < me.chart.data.labels.length ? me.chart.data.labels[index] : '';
  12254. if (typeof me.chart.data.datasets[datasetIndex].data[0] === 'object') {
  12255. label = me.getRightValue(me.chart.data.datasets[datasetIndex].data[index]);
  12256. }
  12257. // Format nicely
  12258. if (me.options.time.tooltipFormat) {
  12259. label = me.parseTime(label).format(me.options.time.tooltipFormat);
  12260. }
  12261. return label;
  12262. },
  12263. // Function to format an individual tick mark
  12264. tickFormatFunction: function(tick, index, ticks) {
  12265. var formattedTick = tick.format(this.displayFormat);
  12266. var tickOpts = this.options.ticks;
  12267. var callback = helpers.getValueOrDefault(tickOpts.callback, tickOpts.userCallback);
  12268. if (callback) {
  12269. return callback(formattedTick, index, ticks);
  12270. } else {
  12271. return formattedTick;
  12272. }
  12273. },
  12274. convertTicksToLabels: function() {
  12275. var me = this;
  12276. me.tickMoments = me.ticks;
  12277. me.ticks = me.ticks.map(me.tickFormatFunction, me);
  12278. },
  12279. getPixelForValue: function(value, index, datasetIndex) {
  12280. var me = this;
  12281. if (!value || !value.isValid) {
  12282. // not already a moment object
  12283. value = moment(me.getRightValue(value));
  12284. }
  12285. var labelMoment = value && value.isValid && value.isValid() ? value : me.getLabelMoment(datasetIndex, index);
  12286. if (labelMoment) {
  12287. var offset = labelMoment.diff(me.firstTick, me.tickUnit, true);
  12288. var decimal = offset !== 0 ? offset / me.scaleSizeInUnits : offset;
  12289. if (me.isHorizontal()) {
  12290. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  12291. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  12292. return me.left + Math.round(valueOffset);
  12293. } else {
  12294. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  12295. var heightOffset = (innerHeight * decimal) + me.paddingTop;
  12296. return me.top + Math.round(heightOffset);
  12297. }
  12298. }
  12299. },
  12300. getPixelForTick: function(index) {
  12301. return this.getPixelForValue(this.tickMoments[index], null, null);
  12302. },
  12303. getValueForPixel: function(pixel) {
  12304. var me = this;
  12305. var innerDimension = me.isHorizontal() ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
  12306. var offset = (pixel - (me.isHorizontal() ? me.left + me.paddingLeft : me.top + me.paddingTop)) / innerDimension;
  12307. offset *= me.scaleSizeInUnits;
  12308. return me.firstTick.clone().add(moment.duration(offset, me.tickUnit).asSeconds(), 'seconds');
  12309. },
  12310. parseTime: function(label) {
  12311. var me = this;
  12312. if (typeof me.options.time.parser === 'string') {
  12313. return moment(label, me.options.time.parser);
  12314. }
  12315. if (typeof me.options.time.parser === 'function') {
  12316. return me.options.time.parser(label);
  12317. }
  12318. // Date objects
  12319. if (typeof label.getMonth === 'function' || typeof label === 'number') {
  12320. return moment(label);
  12321. }
  12322. // Moment support
  12323. if (label.isValid && label.isValid()) {
  12324. return label;
  12325. }
  12326. // Custom parsing (return an instance of moment)
  12327. if (typeof me.options.time.format !== 'string' && me.options.time.format.call) {
  12328. console.warn("options.time.format is deprecated and replaced by options.time.parser. See http://nnnick.github.io/Chart.js/docs-v2/#scales-time-scale");
  12329. return me.options.time.format(label);
  12330. }
  12331. // Moment format parsing
  12332. return moment(label, me.options.time.format);
  12333. }
  12334. });
  12335. Chart.scaleService.registerScaleType("time", TimeScale, defaultConfig);
  12336. };
  12337. },{"6":6}]},{},[7])(7)
  12338. });