Chart.js 306 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584
  1. /*!
  2. * Chart.js
  3. * http://chartjs.org/
  4. * Version: 2.2.2
  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. },{}],2:[function(require,module,exports){
  12. /* MIT license */
  13. var colorNames = require(6);
  14. module.exports = {
  15. getRgba: getRgba,
  16. getHsla: getHsla,
  17. getRgb: getRgb,
  18. getHsl: getHsl,
  19. getHwb: getHwb,
  20. getAlpha: getAlpha,
  21. hexString: hexString,
  22. rgbString: rgbString,
  23. rgbaString: rgbaString,
  24. percentString: percentString,
  25. percentaString: percentaString,
  26. hslString: hslString,
  27. hslaString: hslaString,
  28. hwbString: hwbString,
  29. keyword: keyword
  30. }
  31. function getRgba(string) {
  32. if (!string) {
  33. return;
  34. }
  35. var abbr = /^#([a-fA-F0-9]{3})$/,
  36. hex = /^#([a-fA-F0-9]{6})$/,
  37. rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
  38. per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
  39. keyword = /(\w+)/;
  40. var rgb = [0, 0, 0],
  41. a = 1,
  42. match = string.match(abbr);
  43. if (match) {
  44. match = match[1];
  45. for (var i = 0; i < rgb.length; i++) {
  46. rgb[i] = parseInt(match[i] + match[i], 16);
  47. }
  48. }
  49. else if (match = string.match(hex)) {
  50. match = match[1];
  51. for (var i = 0; i < rgb.length; i++) {
  52. rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
  53. }
  54. }
  55. else if (match = string.match(rgba)) {
  56. for (var i = 0; i < rgb.length; i++) {
  57. rgb[i] = parseInt(match[i + 1]);
  58. }
  59. a = parseFloat(match[4]);
  60. }
  61. else if (match = string.match(per)) {
  62. for (var i = 0; i < rgb.length; i++) {
  63. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  64. }
  65. a = parseFloat(match[4]);
  66. }
  67. else if (match = string.match(keyword)) {
  68. if (match[1] == "transparent") {
  69. return [0, 0, 0, 0];
  70. }
  71. rgb = colorNames[match[1]];
  72. if (!rgb) {
  73. return;
  74. }
  75. }
  76. for (var i = 0; i < rgb.length; i++) {
  77. rgb[i] = scale(rgb[i], 0, 255);
  78. }
  79. if (!a && a != 0) {
  80. a = 1;
  81. }
  82. else {
  83. a = scale(a, 0, 1);
  84. }
  85. rgb[3] = a;
  86. return rgb;
  87. }
  88. function getHsla(string) {
  89. if (!string) {
  90. return;
  91. }
  92. var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  93. var match = string.match(hsl);
  94. if (match) {
  95. var alpha = parseFloat(match[4]);
  96. var h = scale(parseInt(match[1]), 0, 360),
  97. s = scale(parseFloat(match[2]), 0, 100),
  98. l = scale(parseFloat(match[3]), 0, 100),
  99. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  100. return [h, s, l, a];
  101. }
  102. }
  103. function getHwb(string) {
  104. if (!string) {
  105. return;
  106. }
  107. var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  108. var match = string.match(hwb);
  109. if (match) {
  110. var alpha = parseFloat(match[4]);
  111. var h = scale(parseInt(match[1]), 0, 360),
  112. w = scale(parseFloat(match[2]), 0, 100),
  113. b = scale(parseFloat(match[3]), 0, 100),
  114. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  115. return [h, w, b, a];
  116. }
  117. }
  118. function getRgb(string) {
  119. var rgba = getRgba(string);
  120. return rgba && rgba.slice(0, 3);
  121. }
  122. function getHsl(string) {
  123. var hsla = getHsla(string);
  124. return hsla && hsla.slice(0, 3);
  125. }
  126. function getAlpha(string) {
  127. var vals = getRgba(string);
  128. if (vals) {
  129. return vals[3];
  130. }
  131. else if (vals = getHsla(string)) {
  132. return vals[3];
  133. }
  134. else if (vals = getHwb(string)) {
  135. return vals[3];
  136. }
  137. }
  138. // generators
  139. function hexString(rgb) {
  140. return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
  141. + hexDouble(rgb[2]);
  142. }
  143. function rgbString(rgba, alpha) {
  144. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  145. return rgbaString(rgba, alpha);
  146. }
  147. return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
  148. }
  149. function rgbaString(rgba, alpha) {
  150. if (alpha === undefined) {
  151. alpha = (rgba[3] !== undefined ? rgba[3] : 1);
  152. }
  153. return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
  154. + ", " + alpha + ")";
  155. }
  156. function percentString(rgba, alpha) {
  157. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  158. return percentaString(rgba, alpha);
  159. }
  160. var r = Math.round(rgba[0]/255 * 100),
  161. g = Math.round(rgba[1]/255 * 100),
  162. b = Math.round(rgba[2]/255 * 100);
  163. return "rgb(" + r + "%, " + g + "%, " + b + "%)";
  164. }
  165. function percentaString(rgba, alpha) {
  166. var r = Math.round(rgba[0]/255 * 100),
  167. g = Math.round(rgba[1]/255 * 100),
  168. b = Math.round(rgba[2]/255 * 100);
  169. return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
  170. }
  171. function hslString(hsla, alpha) {
  172. if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
  173. return hslaString(hsla, alpha);
  174. }
  175. return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
  176. }
  177. function hslaString(hsla, alpha) {
  178. if (alpha === undefined) {
  179. alpha = (hsla[3] !== undefined ? hsla[3] : 1);
  180. }
  181. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
  182. + alpha + ")";
  183. }
  184. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  185. // (hwb have alpha optional & 1 is default value)
  186. function hwbString(hwb, alpha) {
  187. if (alpha === undefined) {
  188. alpha = (hwb[3] !== undefined ? hwb[3] : 1);
  189. }
  190. return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
  191. + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
  192. }
  193. function keyword(rgb) {
  194. return reverseNames[rgb.slice(0, 3)];
  195. }
  196. // helpers
  197. function scale(num, min, max) {
  198. return Math.min(Math.max(min, num), max);
  199. }
  200. function hexDouble(num) {
  201. var str = num.toString(16).toUpperCase();
  202. return (str.length < 2) ? "0" + str : str;
  203. }
  204. //create a list of reverse color names
  205. var reverseNames = {};
  206. for (var name in colorNames) {
  207. reverseNames[colorNames[name]] = name;
  208. }
  209. },{"6":6}],3:[function(require,module,exports){
  210. /* MIT license */
  211. var convert = require(5);
  212. var string = require(2);
  213. var Color = function (obj) {
  214. if (obj instanceof Color) {
  215. return obj;
  216. }
  217. if (!(this instanceof Color)) {
  218. return new Color(obj);
  219. }
  220. this.values = {
  221. rgb: [0, 0, 0],
  222. hsl: [0, 0, 0],
  223. hsv: [0, 0, 0],
  224. hwb: [0, 0, 0],
  225. cmyk: [0, 0, 0, 0],
  226. alpha: 1
  227. };
  228. // parse Color() argument
  229. var vals;
  230. if (typeof obj === 'string') {
  231. vals = string.getRgba(obj);
  232. if (vals) {
  233. this.setValues('rgb', vals);
  234. } else if (vals = string.getHsla(obj)) {
  235. this.setValues('hsl', vals);
  236. } else if (vals = string.getHwb(obj)) {
  237. this.setValues('hwb', vals);
  238. } else {
  239. throw new Error('Unable to parse color from string "' + obj + '"');
  240. }
  241. } else if (typeof obj === 'object') {
  242. vals = obj;
  243. if (vals.r !== undefined || vals.red !== undefined) {
  244. this.setValues('rgb', vals);
  245. } else if (vals.l !== undefined || vals.lightness !== undefined) {
  246. this.setValues('hsl', vals);
  247. } else if (vals.v !== undefined || vals.value !== undefined) {
  248. this.setValues('hsv', vals);
  249. } else if (vals.w !== undefined || vals.whiteness !== undefined) {
  250. this.setValues('hwb', vals);
  251. } else if (vals.c !== undefined || vals.cyan !== undefined) {
  252. this.setValues('cmyk', vals);
  253. } else {
  254. throw new Error('Unable to parse color from object ' + JSON.stringify(obj));
  255. }
  256. }
  257. };
  258. Color.prototype = {
  259. rgb: function () {
  260. return this.setSpace('rgb', arguments);
  261. },
  262. hsl: function () {
  263. return this.setSpace('hsl', arguments);
  264. },
  265. hsv: function () {
  266. return this.setSpace('hsv', arguments);
  267. },
  268. hwb: function () {
  269. return this.setSpace('hwb', arguments);
  270. },
  271. cmyk: function () {
  272. return this.setSpace('cmyk', arguments);
  273. },
  274. rgbArray: function () {
  275. return this.values.rgb;
  276. },
  277. hslArray: function () {
  278. return this.values.hsl;
  279. },
  280. hsvArray: function () {
  281. return this.values.hsv;
  282. },
  283. hwbArray: function () {
  284. var values = this.values;
  285. if (values.alpha !== 1) {
  286. return values.hwb.concat([values.alpha]);
  287. }
  288. return values.hwb;
  289. },
  290. cmykArray: function () {
  291. return this.values.cmyk;
  292. },
  293. rgbaArray: function () {
  294. var values = this.values;
  295. return values.rgb.concat([values.alpha]);
  296. },
  297. hslaArray: function () {
  298. var values = this.values;
  299. return values.hsl.concat([values.alpha]);
  300. },
  301. alpha: function (val) {
  302. if (val === undefined) {
  303. return this.values.alpha;
  304. }
  305. this.setValues('alpha', val);
  306. return this;
  307. },
  308. red: function (val) {
  309. return this.setChannel('rgb', 0, val);
  310. },
  311. green: function (val) {
  312. return this.setChannel('rgb', 1, val);
  313. },
  314. blue: function (val) {
  315. return this.setChannel('rgb', 2, val);
  316. },
  317. hue: function (val) {
  318. if (val) {
  319. val %= 360;
  320. val = val < 0 ? 360 + val : val;
  321. }
  322. return this.setChannel('hsl', 0, val);
  323. },
  324. saturation: function (val) {
  325. return this.setChannel('hsl', 1, val);
  326. },
  327. lightness: function (val) {
  328. return this.setChannel('hsl', 2, val);
  329. },
  330. saturationv: function (val) {
  331. return this.setChannel('hsv', 1, val);
  332. },
  333. whiteness: function (val) {
  334. return this.setChannel('hwb', 1, val);
  335. },
  336. blackness: function (val) {
  337. return this.setChannel('hwb', 2, val);
  338. },
  339. value: function (val) {
  340. return this.setChannel('hsv', 2, val);
  341. },
  342. cyan: function (val) {
  343. return this.setChannel('cmyk', 0, val);
  344. },
  345. magenta: function (val) {
  346. return this.setChannel('cmyk', 1, val);
  347. },
  348. yellow: function (val) {
  349. return this.setChannel('cmyk', 2, val);
  350. },
  351. black: function (val) {
  352. return this.setChannel('cmyk', 3, val);
  353. },
  354. hexString: function () {
  355. return string.hexString(this.values.rgb);
  356. },
  357. rgbString: function () {
  358. return string.rgbString(this.values.rgb, this.values.alpha);
  359. },
  360. rgbaString: function () {
  361. return string.rgbaString(this.values.rgb, this.values.alpha);
  362. },
  363. percentString: function () {
  364. return string.percentString(this.values.rgb, this.values.alpha);
  365. },
  366. hslString: function () {
  367. return string.hslString(this.values.hsl, this.values.alpha);
  368. },
  369. hslaString: function () {
  370. return string.hslaString(this.values.hsl, this.values.alpha);
  371. },
  372. hwbString: function () {
  373. return string.hwbString(this.values.hwb, this.values.alpha);
  374. },
  375. keyword: function () {
  376. return string.keyword(this.values.rgb, this.values.alpha);
  377. },
  378. rgbNumber: function () {
  379. var rgb = this.values.rgb;
  380. return (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
  381. },
  382. luminosity: function () {
  383. // http://www.w3.org/TR/WCAG20/#relativeluminancedef
  384. var rgb = this.values.rgb;
  385. var lum = [];
  386. for (var i = 0; i < rgb.length; i++) {
  387. var chan = rgb[i] / 255;
  388. lum[i] = (chan <= 0.03928) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4);
  389. }
  390. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  391. },
  392. contrast: function (color2) {
  393. // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  394. var lum1 = this.luminosity();
  395. var lum2 = color2.luminosity();
  396. if (lum1 > lum2) {
  397. return (lum1 + 0.05) / (lum2 + 0.05);
  398. }
  399. return (lum2 + 0.05) / (lum1 + 0.05);
  400. },
  401. level: function (color2) {
  402. var contrastRatio = this.contrast(color2);
  403. if (contrastRatio >= 7.1) {
  404. return 'AAA';
  405. }
  406. return (contrastRatio >= 4.5) ? 'AA' : '';
  407. },
  408. dark: function () {
  409. // YIQ equation from http://24ways.org/2010/calculating-color-contrast
  410. var rgb = this.values.rgb;
  411. var yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
  412. return yiq < 128;
  413. },
  414. light: function () {
  415. return !this.dark();
  416. },
  417. negate: function () {
  418. var rgb = [];
  419. for (var i = 0; i < 3; i++) {
  420. rgb[i] = 255 - this.values.rgb[i];
  421. }
  422. this.setValues('rgb', rgb);
  423. return this;
  424. },
  425. lighten: function (ratio) {
  426. var hsl = this.values.hsl;
  427. hsl[2] += hsl[2] * ratio;
  428. this.setValues('hsl', hsl);
  429. return this;
  430. },
  431. darken: function (ratio) {
  432. var hsl = this.values.hsl;
  433. hsl[2] -= hsl[2] * ratio;
  434. this.setValues('hsl', hsl);
  435. return this;
  436. },
  437. saturate: function (ratio) {
  438. var hsl = this.values.hsl;
  439. hsl[1] += hsl[1] * ratio;
  440. this.setValues('hsl', hsl);
  441. return this;
  442. },
  443. desaturate: function (ratio) {
  444. var hsl = this.values.hsl;
  445. hsl[1] -= hsl[1] * ratio;
  446. this.setValues('hsl', hsl);
  447. return this;
  448. },
  449. whiten: function (ratio) {
  450. var hwb = this.values.hwb;
  451. hwb[1] += hwb[1] * ratio;
  452. this.setValues('hwb', hwb);
  453. return this;
  454. },
  455. blacken: function (ratio) {
  456. var hwb = this.values.hwb;
  457. hwb[2] += hwb[2] * ratio;
  458. this.setValues('hwb', hwb);
  459. return this;
  460. },
  461. greyscale: function () {
  462. var rgb = this.values.rgb;
  463. // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
  464. var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  465. this.setValues('rgb', [val, val, val]);
  466. return this;
  467. },
  468. clearer: function (ratio) {
  469. var alpha = this.values.alpha;
  470. this.setValues('alpha', alpha - (alpha * ratio));
  471. return this;
  472. },
  473. opaquer: function (ratio) {
  474. var alpha = this.values.alpha;
  475. this.setValues('alpha', alpha + (alpha * ratio));
  476. return this;
  477. },
  478. rotate: function (degrees) {
  479. var hsl = this.values.hsl;
  480. var hue = (hsl[0] + degrees) % 360;
  481. hsl[0] = hue < 0 ? 360 + hue : hue;
  482. this.setValues('hsl', hsl);
  483. return this;
  484. },
  485. /**
  486. * Ported from sass implementation in C
  487. * https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
  488. */
  489. mix: function (mixinColor, weight) {
  490. var color1 = this;
  491. var color2 = mixinColor;
  492. var p = weight === undefined ? 0.5 : weight;
  493. var w = 2 * p - 1;
  494. var a = color1.alpha() - color2.alpha();
  495. var w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  496. var w2 = 1 - w1;
  497. return this
  498. .rgb(
  499. w1 * color1.red() + w2 * color2.red(),
  500. w1 * color1.green() + w2 * color2.green(),
  501. w1 * color1.blue() + w2 * color2.blue()
  502. )
  503. .alpha(color1.alpha() * p + color2.alpha() * (1 - p));
  504. },
  505. toJSON: function () {
  506. return this.rgb();
  507. },
  508. clone: function () {
  509. // NOTE(SB): using node-clone creates a dependency to Buffer when using browserify,
  510. // making the final build way to big to embed in Chart.js. So let's do it manually,
  511. // assuming that values to clone are 1 dimension arrays containing only numbers,
  512. // except 'alpha' which is a number.
  513. var result = new Color();
  514. var source = this.values;
  515. var target = result.values;
  516. var value, type;
  517. for (var prop in source) {
  518. if (source.hasOwnProperty(prop)) {
  519. value = source[prop];
  520. type = ({}).toString.call(value);
  521. if (type === '[object Array]') {
  522. target[prop] = value.slice(0);
  523. } else if (type === '[object Number]') {
  524. target[prop] = value;
  525. } else {
  526. console.error('unexpected color value:', value);
  527. }
  528. }
  529. }
  530. return result;
  531. }
  532. };
  533. Color.prototype.spaces = {
  534. rgb: ['red', 'green', 'blue'],
  535. hsl: ['hue', 'saturation', 'lightness'],
  536. hsv: ['hue', 'saturation', 'value'],
  537. hwb: ['hue', 'whiteness', 'blackness'],
  538. cmyk: ['cyan', 'magenta', 'yellow', 'black']
  539. };
  540. Color.prototype.maxes = {
  541. rgb: [255, 255, 255],
  542. hsl: [360, 100, 100],
  543. hsv: [360, 100, 100],
  544. hwb: [360, 100, 100],
  545. cmyk: [100, 100, 100, 100]
  546. };
  547. Color.prototype.getValues = function (space) {
  548. var values = this.values;
  549. var vals = {};
  550. for (var i = 0; i < space.length; i++) {
  551. vals[space.charAt(i)] = values[space][i];
  552. }
  553. if (values.alpha !== 1) {
  554. vals.a = values.alpha;
  555. }
  556. // {r: 255, g: 255, b: 255, a: 0.4}
  557. return vals;
  558. };
  559. Color.prototype.setValues = function (space, vals) {
  560. var values = this.values;
  561. var spaces = this.spaces;
  562. var maxes = this.maxes;
  563. var alpha = 1;
  564. var i;
  565. if (space === 'alpha') {
  566. alpha = vals;
  567. } else if (vals.length) {
  568. // [10, 10, 10]
  569. values[space] = vals.slice(0, space.length);
  570. alpha = vals[space.length];
  571. } else if (vals[space.charAt(0)] !== undefined) {
  572. // {r: 10, g: 10, b: 10}
  573. for (i = 0; i < space.length; i++) {
  574. values[space][i] = vals[space.charAt(i)];
  575. }
  576. alpha = vals.a;
  577. } else if (vals[spaces[space][0]] !== undefined) {
  578. // {red: 10, green: 10, blue: 10}
  579. var chans = spaces[space];
  580. for (i = 0; i < space.length; i++) {
  581. values[space][i] = vals[chans[i]];
  582. }
  583. alpha = vals.alpha;
  584. }
  585. values.alpha = Math.max(0, Math.min(1, (alpha === undefined ? values.alpha : alpha)));
  586. if (space === 'alpha') {
  587. return false;
  588. }
  589. var capped;
  590. // cap values of the space prior converting all values
  591. for (i = 0; i < space.length; i++) {
  592. capped = Math.max(0, Math.min(maxes[space][i], values[space][i]));
  593. values[space][i] = Math.round(capped);
  594. }
  595. // convert to all the other color spaces
  596. for (var sname in spaces) {
  597. if (sname !== space) {
  598. values[sname] = convert[space][sname](values[space]);
  599. }
  600. }
  601. return true;
  602. };
  603. Color.prototype.setSpace = function (space, args) {
  604. var vals = args[0];
  605. if (vals === undefined) {
  606. // color.rgb()
  607. return this.getValues(space);
  608. }
  609. // color.rgb(10, 10, 10)
  610. if (typeof vals === 'number') {
  611. vals = Array.prototype.slice.call(args);
  612. }
  613. this.setValues(space, vals);
  614. return this;
  615. };
  616. Color.prototype.setChannel = function (space, index, val) {
  617. var svalues = this.values[space];
  618. if (val === undefined) {
  619. // color.red()
  620. return svalues[index];
  621. } else if (val === svalues[index]) {
  622. // color.red(color.red())
  623. return this;
  624. }
  625. // color.red(100)
  626. svalues[index] = val;
  627. this.setValues(space, svalues);
  628. return this;
  629. };
  630. if (typeof window !== 'undefined') {
  631. window.Color = Color;
  632. }
  633. module.exports = Color;
  634. },{"2":2,"5":5}],4:[function(require,module,exports){
  635. /* MIT license */
  636. module.exports = {
  637. rgb2hsl: rgb2hsl,
  638. rgb2hsv: rgb2hsv,
  639. rgb2hwb: rgb2hwb,
  640. rgb2cmyk: rgb2cmyk,
  641. rgb2keyword: rgb2keyword,
  642. rgb2xyz: rgb2xyz,
  643. rgb2lab: rgb2lab,
  644. rgb2lch: rgb2lch,
  645. hsl2rgb: hsl2rgb,
  646. hsl2hsv: hsl2hsv,
  647. hsl2hwb: hsl2hwb,
  648. hsl2cmyk: hsl2cmyk,
  649. hsl2keyword: hsl2keyword,
  650. hsv2rgb: hsv2rgb,
  651. hsv2hsl: hsv2hsl,
  652. hsv2hwb: hsv2hwb,
  653. hsv2cmyk: hsv2cmyk,
  654. hsv2keyword: hsv2keyword,
  655. hwb2rgb: hwb2rgb,
  656. hwb2hsl: hwb2hsl,
  657. hwb2hsv: hwb2hsv,
  658. hwb2cmyk: hwb2cmyk,
  659. hwb2keyword: hwb2keyword,
  660. cmyk2rgb: cmyk2rgb,
  661. cmyk2hsl: cmyk2hsl,
  662. cmyk2hsv: cmyk2hsv,
  663. cmyk2hwb: cmyk2hwb,
  664. cmyk2keyword: cmyk2keyword,
  665. keyword2rgb: keyword2rgb,
  666. keyword2hsl: keyword2hsl,
  667. keyword2hsv: keyword2hsv,
  668. keyword2hwb: keyword2hwb,
  669. keyword2cmyk: keyword2cmyk,
  670. keyword2lab: keyword2lab,
  671. keyword2xyz: keyword2xyz,
  672. xyz2rgb: xyz2rgb,
  673. xyz2lab: xyz2lab,
  674. xyz2lch: xyz2lch,
  675. lab2xyz: lab2xyz,
  676. lab2rgb: lab2rgb,
  677. lab2lch: lab2lch,
  678. lch2lab: lch2lab,
  679. lch2xyz: lch2xyz,
  680. lch2rgb: lch2rgb
  681. }
  682. function rgb2hsl(rgb) {
  683. var r = rgb[0]/255,
  684. g = rgb[1]/255,
  685. b = rgb[2]/255,
  686. min = Math.min(r, g, b),
  687. max = Math.max(r, g, b),
  688. delta = max - min,
  689. h, s, l;
  690. if (max == min)
  691. h = 0;
  692. else if (r == max)
  693. h = (g - b) / delta;
  694. else if (g == max)
  695. h = 2 + (b - r) / delta;
  696. else if (b == max)
  697. h = 4 + (r - g)/ delta;
  698. h = Math.min(h * 60, 360);
  699. if (h < 0)
  700. h += 360;
  701. l = (min + max) / 2;
  702. if (max == min)
  703. s = 0;
  704. else if (l <= 0.5)
  705. s = delta / (max + min);
  706. else
  707. s = delta / (2 - max - min);
  708. return [h, s * 100, l * 100];
  709. }
  710. function rgb2hsv(rgb) {
  711. var r = rgb[0],
  712. g = rgb[1],
  713. b = rgb[2],
  714. min = Math.min(r, g, b),
  715. max = Math.max(r, g, b),
  716. delta = max - min,
  717. h, s, v;
  718. if (max == 0)
  719. s = 0;
  720. else
  721. s = (delta/max * 1000)/10;
  722. if (max == min)
  723. h = 0;
  724. else if (r == max)
  725. h = (g - b) / delta;
  726. else if (g == max)
  727. h = 2 + (b - r) / delta;
  728. else if (b == max)
  729. h = 4 + (r - g) / delta;
  730. h = Math.min(h * 60, 360);
  731. if (h < 0)
  732. h += 360;
  733. v = ((max / 255) * 1000) / 10;
  734. return [h, s, v];
  735. }
  736. function rgb2hwb(rgb) {
  737. var r = rgb[0],
  738. g = rgb[1],
  739. b = rgb[2],
  740. h = rgb2hsl(rgb)[0],
  741. w = 1/255 * Math.min(r, Math.min(g, b)),
  742. b = 1 - 1/255 * Math.max(r, Math.max(g, b));
  743. return [h, w * 100, b * 100];
  744. }
  745. function rgb2cmyk(rgb) {
  746. var r = rgb[0] / 255,
  747. g = rgb[1] / 255,
  748. b = rgb[2] / 255,
  749. c, m, y, k;
  750. k = Math.min(1 - r, 1 - g, 1 - b);
  751. c = (1 - r - k) / (1 - k) || 0;
  752. m = (1 - g - k) / (1 - k) || 0;
  753. y = (1 - b - k) / (1 - k) || 0;
  754. return [c * 100, m * 100, y * 100, k * 100];
  755. }
  756. function rgb2keyword(rgb) {
  757. return reverseKeywords[JSON.stringify(rgb)];
  758. }
  759. function rgb2xyz(rgb) {
  760. var r = rgb[0] / 255,
  761. g = rgb[1] / 255,
  762. b = rgb[2] / 255;
  763. // assume sRGB
  764. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  765. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  766. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  767. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  768. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  769. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  770. return [x * 100, y *100, z * 100];
  771. }
  772. function rgb2lab(rgb) {
  773. var xyz = rgb2xyz(rgb),
  774. x = xyz[0],
  775. y = xyz[1],
  776. z = xyz[2],
  777. l, a, b;
  778. x /= 95.047;
  779. y /= 100;
  780. z /= 108.883;
  781. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  782. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  783. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  784. l = (116 * y) - 16;
  785. a = 500 * (x - y);
  786. b = 200 * (y - z);
  787. return [l, a, b];
  788. }
  789. function rgb2lch(args) {
  790. return lab2lch(rgb2lab(args));
  791. }
  792. function hsl2rgb(hsl) {
  793. var h = hsl[0] / 360,
  794. s = hsl[1] / 100,
  795. l = hsl[2] / 100,
  796. t1, t2, t3, rgb, val;
  797. if (s == 0) {
  798. val = l * 255;
  799. return [val, val, val];
  800. }
  801. if (l < 0.5)
  802. t2 = l * (1 + s);
  803. else
  804. t2 = l + s - l * s;
  805. t1 = 2 * l - t2;
  806. rgb = [0, 0, 0];
  807. for (var i = 0; i < 3; i++) {
  808. t3 = h + 1 / 3 * - (i - 1);
  809. t3 < 0 && t3++;
  810. t3 > 1 && t3--;
  811. if (6 * t3 < 1)
  812. val = t1 + (t2 - t1) * 6 * t3;
  813. else if (2 * t3 < 1)
  814. val = t2;
  815. else if (3 * t3 < 2)
  816. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  817. else
  818. val = t1;
  819. rgb[i] = val * 255;
  820. }
  821. return rgb;
  822. }
  823. function hsl2hsv(hsl) {
  824. var h = hsl[0],
  825. s = hsl[1] / 100,
  826. l = hsl[2] / 100,
  827. sv, v;
  828. if(l === 0) {
  829. // no need to do calc on black
  830. // also avoids divide by 0 error
  831. return [0, 0, 0];
  832. }
  833. l *= 2;
  834. s *= (l <= 1) ? l : 2 - l;
  835. v = (l + s) / 2;
  836. sv = (2 * s) / (l + s);
  837. return [h, sv * 100, v * 100];
  838. }
  839. function hsl2hwb(args) {
  840. return rgb2hwb(hsl2rgb(args));
  841. }
  842. function hsl2cmyk(args) {
  843. return rgb2cmyk(hsl2rgb(args));
  844. }
  845. function hsl2keyword(args) {
  846. return rgb2keyword(hsl2rgb(args));
  847. }
  848. function hsv2rgb(hsv) {
  849. var h = hsv[0] / 60,
  850. s = hsv[1] / 100,
  851. v = hsv[2] / 100,
  852. hi = Math.floor(h) % 6;
  853. var f = h - Math.floor(h),
  854. p = 255 * v * (1 - s),
  855. q = 255 * v * (1 - (s * f)),
  856. t = 255 * v * (1 - (s * (1 - f))),
  857. v = 255 * v;
  858. switch(hi) {
  859. case 0:
  860. return [v, t, p];
  861. case 1:
  862. return [q, v, p];
  863. case 2:
  864. return [p, v, t];
  865. case 3:
  866. return [p, q, v];
  867. case 4:
  868. return [t, p, v];
  869. case 5:
  870. return [v, p, q];
  871. }
  872. }
  873. function hsv2hsl(hsv) {
  874. var h = hsv[0],
  875. s = hsv[1] / 100,
  876. v = hsv[2] / 100,
  877. sl, l;
  878. l = (2 - s) * v;
  879. sl = s * v;
  880. sl /= (l <= 1) ? l : 2 - l;
  881. sl = sl || 0;
  882. l /= 2;
  883. return [h, sl * 100, l * 100];
  884. }
  885. function hsv2hwb(args) {
  886. return rgb2hwb(hsv2rgb(args))
  887. }
  888. function hsv2cmyk(args) {
  889. return rgb2cmyk(hsv2rgb(args));
  890. }
  891. function hsv2keyword(args) {
  892. return rgb2keyword(hsv2rgb(args));
  893. }
  894. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  895. function hwb2rgb(hwb) {
  896. var h = hwb[0] / 360,
  897. wh = hwb[1] / 100,
  898. bl = hwb[2] / 100,
  899. ratio = wh + bl,
  900. i, v, f, n;
  901. // wh + bl cant be > 1
  902. if (ratio > 1) {
  903. wh /= ratio;
  904. bl /= ratio;
  905. }
  906. i = Math.floor(6 * h);
  907. v = 1 - bl;
  908. f = 6 * h - i;
  909. if ((i & 0x01) != 0) {
  910. f = 1 - f;
  911. }
  912. n = wh + f * (v - wh); // linear interpolation
  913. switch (i) {
  914. default:
  915. case 6:
  916. case 0: r = v; g = n; b = wh; break;
  917. case 1: r = n; g = v; b = wh; break;
  918. case 2: r = wh; g = v; b = n; break;
  919. case 3: r = wh; g = n; b = v; break;
  920. case 4: r = n; g = wh; b = v; break;
  921. case 5: r = v; g = wh; b = n; break;
  922. }
  923. return [r * 255, g * 255, b * 255];
  924. }
  925. function hwb2hsl(args) {
  926. return rgb2hsl(hwb2rgb(args));
  927. }
  928. function hwb2hsv(args) {
  929. return rgb2hsv(hwb2rgb(args));
  930. }
  931. function hwb2cmyk(args) {
  932. return rgb2cmyk(hwb2rgb(args));
  933. }
  934. function hwb2keyword(args) {
  935. return rgb2keyword(hwb2rgb(args));
  936. }
  937. function cmyk2rgb(cmyk) {
  938. var c = cmyk[0] / 100,
  939. m = cmyk[1] / 100,
  940. y = cmyk[2] / 100,
  941. k = cmyk[3] / 100,
  942. r, g, b;
  943. r = 1 - Math.min(1, c * (1 - k) + k);
  944. g = 1 - Math.min(1, m * (1 - k) + k);
  945. b = 1 - Math.min(1, y * (1 - k) + k);
  946. return [r * 255, g * 255, b * 255];
  947. }
  948. function cmyk2hsl(args) {
  949. return rgb2hsl(cmyk2rgb(args));
  950. }
  951. function cmyk2hsv(args) {
  952. return rgb2hsv(cmyk2rgb(args));
  953. }
  954. function cmyk2hwb(args) {
  955. return rgb2hwb(cmyk2rgb(args));
  956. }
  957. function cmyk2keyword(args) {
  958. return rgb2keyword(cmyk2rgb(args));
  959. }
  960. function xyz2rgb(xyz) {
  961. var x = xyz[0] / 100,
  962. y = xyz[1] / 100,
  963. z = xyz[2] / 100,
  964. r, g, b;
  965. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  966. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  967. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  968. // assume sRGB
  969. r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  970. : r = (r * 12.92);
  971. g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  972. : g = (g * 12.92);
  973. b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  974. : b = (b * 12.92);
  975. r = Math.min(Math.max(0, r), 1);
  976. g = Math.min(Math.max(0, g), 1);
  977. b = Math.min(Math.max(0, b), 1);
  978. return [r * 255, g * 255, b * 255];
  979. }
  980. function xyz2lab(xyz) {
  981. var x = xyz[0],
  982. y = xyz[1],
  983. z = xyz[2],
  984. l, a, b;
  985. x /= 95.047;
  986. y /= 100;
  987. z /= 108.883;
  988. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  989. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  990. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  991. l = (116 * y) - 16;
  992. a = 500 * (x - y);
  993. b = 200 * (y - z);
  994. return [l, a, b];
  995. }
  996. function xyz2lch(args) {
  997. return lab2lch(xyz2lab(args));
  998. }
  999. function lab2xyz(lab) {
  1000. var l = lab[0],
  1001. a = lab[1],
  1002. b = lab[2],
  1003. x, y, z, y2;
  1004. if (l <= 8) {
  1005. y = (l * 100) / 903.3;
  1006. y2 = (7.787 * (y / 100)) + (16 / 116);
  1007. } else {
  1008. y = 100 * Math.pow((l + 16) / 116, 3);
  1009. y2 = Math.pow(y / 100, 1/3);
  1010. }
  1011. x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
  1012. z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
  1013. return [x, y, z];
  1014. }
  1015. function lab2lch(lab) {
  1016. var l = lab[0],
  1017. a = lab[1],
  1018. b = lab[2],
  1019. hr, h, c;
  1020. hr = Math.atan2(b, a);
  1021. h = hr * 360 / 2 / Math.PI;
  1022. if (h < 0) {
  1023. h += 360;
  1024. }
  1025. c = Math.sqrt(a * a + b * b);
  1026. return [l, c, h];
  1027. }
  1028. function lab2rgb(args) {
  1029. return xyz2rgb(lab2xyz(args));
  1030. }
  1031. function lch2lab(lch) {
  1032. var l = lch[0],
  1033. c = lch[1],
  1034. h = lch[2],
  1035. a, b, hr;
  1036. hr = h / 360 * 2 * Math.PI;
  1037. a = c * Math.cos(hr);
  1038. b = c * Math.sin(hr);
  1039. return [l, a, b];
  1040. }
  1041. function lch2xyz(args) {
  1042. return lab2xyz(lch2lab(args));
  1043. }
  1044. function lch2rgb(args) {
  1045. return lab2rgb(lch2lab(args));
  1046. }
  1047. function keyword2rgb(keyword) {
  1048. return cssKeywords[keyword];
  1049. }
  1050. function keyword2hsl(args) {
  1051. return rgb2hsl(keyword2rgb(args));
  1052. }
  1053. function keyword2hsv(args) {
  1054. return rgb2hsv(keyword2rgb(args));
  1055. }
  1056. function keyword2hwb(args) {
  1057. return rgb2hwb(keyword2rgb(args));
  1058. }
  1059. function keyword2cmyk(args) {
  1060. return rgb2cmyk(keyword2rgb(args));
  1061. }
  1062. function keyword2lab(args) {
  1063. return rgb2lab(keyword2rgb(args));
  1064. }
  1065. function keyword2xyz(args) {
  1066. return rgb2xyz(keyword2rgb(args));
  1067. }
  1068. var cssKeywords = {
  1069. aliceblue: [240,248,255],
  1070. antiquewhite: [250,235,215],
  1071. aqua: [0,255,255],
  1072. aquamarine: [127,255,212],
  1073. azure: [240,255,255],
  1074. beige: [245,245,220],
  1075. bisque: [255,228,196],
  1076. black: [0,0,0],
  1077. blanchedalmond: [255,235,205],
  1078. blue: [0,0,255],
  1079. blueviolet: [138,43,226],
  1080. brown: [165,42,42],
  1081. burlywood: [222,184,135],
  1082. cadetblue: [95,158,160],
  1083. chartreuse: [127,255,0],
  1084. chocolate: [210,105,30],
  1085. coral: [255,127,80],
  1086. cornflowerblue: [100,149,237],
  1087. cornsilk: [255,248,220],
  1088. crimson: [220,20,60],
  1089. cyan: [0,255,255],
  1090. darkblue: [0,0,139],
  1091. darkcyan: [0,139,139],
  1092. darkgoldenrod: [184,134,11],
  1093. darkgray: [169,169,169],
  1094. darkgreen: [0,100,0],
  1095. darkgrey: [169,169,169],
  1096. darkkhaki: [189,183,107],
  1097. darkmagenta: [139,0,139],
  1098. darkolivegreen: [85,107,47],
  1099. darkorange: [255,140,0],
  1100. darkorchid: [153,50,204],
  1101. darkred: [139,0,0],
  1102. darksalmon: [233,150,122],
  1103. darkseagreen: [143,188,143],
  1104. darkslateblue: [72,61,139],
  1105. darkslategray: [47,79,79],
  1106. darkslategrey: [47,79,79],
  1107. darkturquoise: [0,206,209],
  1108. darkviolet: [148,0,211],
  1109. deeppink: [255,20,147],
  1110. deepskyblue: [0,191,255],
  1111. dimgray: [105,105,105],
  1112. dimgrey: [105,105,105],
  1113. dodgerblue: [30,144,255],
  1114. firebrick: [178,34,34],
  1115. floralwhite: [255,250,240],
  1116. forestgreen: [34,139,34],
  1117. fuchsia: [255,0,255],
  1118. gainsboro: [220,220,220],
  1119. ghostwhite: [248,248,255],
  1120. gold: [255,215,0],
  1121. goldenrod: [218,165,32],
  1122. gray: [128,128,128],
  1123. green: [0,128,0],
  1124. greenyellow: [173,255,47],
  1125. grey: [128,128,128],
  1126. honeydew: [240,255,240],
  1127. hotpink: [255,105,180],
  1128. indianred: [205,92,92],
  1129. indigo: [75,0,130],
  1130. ivory: [255,255,240],
  1131. khaki: [240,230,140],
  1132. lavender: [230,230,250],
  1133. lavenderblush: [255,240,245],
  1134. lawngreen: [124,252,0],
  1135. lemonchiffon: [255,250,205],
  1136. lightblue: [173,216,230],
  1137. lightcoral: [240,128,128],
  1138. lightcyan: [224,255,255],
  1139. lightgoldenrodyellow: [250,250,210],
  1140. lightgray: [211,211,211],
  1141. lightgreen: [144,238,144],
  1142. lightgrey: [211,211,211],
  1143. lightpink: [255,182,193],
  1144. lightsalmon: [255,160,122],
  1145. lightseagreen: [32,178,170],
  1146. lightskyblue: [135,206,250],
  1147. lightslategray: [119,136,153],
  1148. lightslategrey: [119,136,153],
  1149. lightsteelblue: [176,196,222],
  1150. lightyellow: [255,255,224],
  1151. lime: [0,255,0],
  1152. limegreen: [50,205,50],
  1153. linen: [250,240,230],
  1154. magenta: [255,0,255],
  1155. maroon: [128,0,0],
  1156. mediumaquamarine: [102,205,170],
  1157. mediumblue: [0,0,205],
  1158. mediumorchid: [186,85,211],
  1159. mediumpurple: [147,112,219],
  1160. mediumseagreen: [60,179,113],
  1161. mediumslateblue: [123,104,238],
  1162. mediumspringgreen: [0,250,154],
  1163. mediumturquoise: [72,209,204],
  1164. mediumvioletred: [199,21,133],
  1165. midnightblue: [25,25,112],
  1166. mintcream: [245,255,250],
  1167. mistyrose: [255,228,225],
  1168. moccasin: [255,228,181],
  1169. navajowhite: [255,222,173],
  1170. navy: [0,0,128],
  1171. oldlace: [253,245,230],
  1172. olive: [128,128,0],
  1173. olivedrab: [107,142,35],
  1174. orange: [255,165,0],
  1175. orangered: [255,69,0],
  1176. orchid: [218,112,214],
  1177. palegoldenrod: [238,232,170],
  1178. palegreen: [152,251,152],
  1179. paleturquoise: [175,238,238],
  1180. palevioletred: [219,112,147],
  1181. papayawhip: [255,239,213],
  1182. peachpuff: [255,218,185],
  1183. peru: [205,133,63],
  1184. pink: [255,192,203],
  1185. plum: [221,160,221],
  1186. powderblue: [176,224,230],
  1187. purple: [128,0,128],
  1188. rebeccapurple: [102, 51, 153],
  1189. red: [255,0,0],
  1190. rosybrown: [188,143,143],
  1191. royalblue: [65,105,225],
  1192. saddlebrown: [139,69,19],
  1193. salmon: [250,128,114],
  1194. sandybrown: [244,164,96],
  1195. seagreen: [46,139,87],
  1196. seashell: [255,245,238],
  1197. sienna: [160,82,45],
  1198. silver: [192,192,192],
  1199. skyblue: [135,206,235],
  1200. slateblue: [106,90,205],
  1201. slategray: [112,128,144],
  1202. slategrey: [112,128,144],
  1203. snow: [255,250,250],
  1204. springgreen: [0,255,127],
  1205. steelblue: [70,130,180],
  1206. tan: [210,180,140],
  1207. teal: [0,128,128],
  1208. thistle: [216,191,216],
  1209. tomato: [255,99,71],
  1210. turquoise: [64,224,208],
  1211. violet: [238,130,238],
  1212. wheat: [245,222,179],
  1213. white: [255,255,255],
  1214. whitesmoke: [245,245,245],
  1215. yellow: [255,255,0],
  1216. yellowgreen: [154,205,50]
  1217. };
  1218. var reverseKeywords = {};
  1219. for (var key in cssKeywords) {
  1220. reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
  1221. }
  1222. },{}],5:[function(require,module,exports){
  1223. var conversions = require(4);
  1224. var convert = function() {
  1225. return new Converter();
  1226. }
  1227. for (var func in conversions) {
  1228. // export Raw versions
  1229. convert[func + "Raw"] = (function(func) {
  1230. // accept array or plain args
  1231. return function(arg) {
  1232. if (typeof arg == "number")
  1233. arg = Array.prototype.slice.call(arguments);
  1234. return conversions[func](arg);
  1235. }
  1236. })(func);
  1237. var pair = /(\w+)2(\w+)/.exec(func),
  1238. from = pair[1],
  1239. to = pair[2];
  1240. // export rgb2hsl and ["rgb"]["hsl"]
  1241. convert[from] = convert[from] || {};
  1242. convert[from][to] = convert[func] = (function(func) {
  1243. return function(arg) {
  1244. if (typeof arg == "number")
  1245. arg = Array.prototype.slice.call(arguments);
  1246. var val = conversions[func](arg);
  1247. if (typeof val == "string" || val === undefined)
  1248. return val; // keyword
  1249. for (var i = 0; i < val.length; i++)
  1250. val[i] = Math.round(val[i]);
  1251. return val;
  1252. }
  1253. })(func);
  1254. }
  1255. /* Converter does lazy conversion and caching */
  1256. var Converter = function() {
  1257. this.convs = {};
  1258. };
  1259. /* Either get the values for a space or
  1260. set the values for a space, depending on args */
  1261. Converter.prototype.routeSpace = function(space, args) {
  1262. var values = args[0];
  1263. if (values === undefined) {
  1264. // color.rgb()
  1265. return this.getValues(space);
  1266. }
  1267. // color.rgb(10, 10, 10)
  1268. if (typeof values == "number") {
  1269. values = Array.prototype.slice.call(args);
  1270. }
  1271. return this.setValues(space, values);
  1272. };
  1273. /* Set the values for a space, invalidating cache */
  1274. Converter.prototype.setValues = function(space, values) {
  1275. this.space = space;
  1276. this.convs = {};
  1277. this.convs[space] = values;
  1278. return this;
  1279. };
  1280. /* Get the values for a space. If there's already
  1281. a conversion for the space, fetch it, otherwise
  1282. compute it */
  1283. Converter.prototype.getValues = function(space) {
  1284. var vals = this.convs[space];
  1285. if (!vals) {
  1286. var fspace = this.space,
  1287. from = this.convs[fspace];
  1288. vals = convert[fspace][space](from);
  1289. this.convs[space] = vals;
  1290. }
  1291. return vals;
  1292. };
  1293. ["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
  1294. Converter.prototype[space] = function(vals) {
  1295. return this.routeSpace(space, arguments);
  1296. }
  1297. });
  1298. module.exports = convert;
  1299. },{"4":4}],6:[function(require,module,exports){
  1300. module.exports = {
  1301. "aliceblue": [240, 248, 255],
  1302. "antiquewhite": [250, 235, 215],
  1303. "aqua": [0, 255, 255],
  1304. "aquamarine": [127, 255, 212],
  1305. "azure": [240, 255, 255],
  1306. "beige": [245, 245, 220],
  1307. "bisque": [255, 228, 196],
  1308. "black": [0, 0, 0],
  1309. "blanchedalmond": [255, 235, 205],
  1310. "blue": [0, 0, 255],
  1311. "blueviolet": [138, 43, 226],
  1312. "brown": [165, 42, 42],
  1313. "burlywood": [222, 184, 135],
  1314. "cadetblue": [95, 158, 160],
  1315. "chartreuse": [127, 255, 0],
  1316. "chocolate": [210, 105, 30],
  1317. "coral": [255, 127, 80],
  1318. "cornflowerblue": [100, 149, 237],
  1319. "cornsilk": [255, 248, 220],
  1320. "crimson": [220, 20, 60],
  1321. "cyan": [0, 255, 255],
  1322. "darkblue": [0, 0, 139],
  1323. "darkcyan": [0, 139, 139],
  1324. "darkgoldenrod": [184, 134, 11],
  1325. "darkgray": [169, 169, 169],
  1326. "darkgreen": [0, 100, 0],
  1327. "darkgrey": [169, 169, 169],
  1328. "darkkhaki": [189, 183, 107],
  1329. "darkmagenta": [139, 0, 139],
  1330. "darkolivegreen": [85, 107, 47],
  1331. "darkorange": [255, 140, 0],
  1332. "darkorchid": [153, 50, 204],
  1333. "darkred": [139, 0, 0],
  1334. "darksalmon": [233, 150, 122],
  1335. "darkseagreen": [143, 188, 143],
  1336. "darkslateblue": [72, 61, 139],
  1337. "darkslategray": [47, 79, 79],
  1338. "darkslategrey": [47, 79, 79],
  1339. "darkturquoise": [0, 206, 209],
  1340. "darkviolet": [148, 0, 211],
  1341. "deeppink": [255, 20, 147],
  1342. "deepskyblue": [0, 191, 255],
  1343. "dimgray": [105, 105, 105],
  1344. "dimgrey": [105, 105, 105],
  1345. "dodgerblue": [30, 144, 255],
  1346. "firebrick": [178, 34, 34],
  1347. "floralwhite": [255, 250, 240],
  1348. "forestgreen": [34, 139, 34],
  1349. "fuchsia": [255, 0, 255],
  1350. "gainsboro": [220, 220, 220],
  1351. "ghostwhite": [248, 248, 255],
  1352. "gold": [255, 215, 0],
  1353. "goldenrod": [218, 165, 32],
  1354. "gray": [128, 128, 128],
  1355. "green": [0, 128, 0],
  1356. "greenyellow": [173, 255, 47],
  1357. "grey": [128, 128, 128],
  1358. "honeydew": [240, 255, 240],
  1359. "hotpink": [255, 105, 180],
  1360. "indianred": [205, 92, 92],
  1361. "indigo": [75, 0, 130],
  1362. "ivory": [255, 255, 240],
  1363. "khaki": [240, 230, 140],
  1364. "lavender": [230, 230, 250],
  1365. "lavenderblush": [255, 240, 245],
  1366. "lawngreen": [124, 252, 0],
  1367. "lemonchiffon": [255, 250, 205],
  1368. "lightblue": [173, 216, 230],
  1369. "lightcoral": [240, 128, 128],
  1370. "lightcyan": [224, 255, 255],
  1371. "lightgoldenrodyellow": [250, 250, 210],
  1372. "lightgray": [211, 211, 211],
  1373. "lightgreen": [144, 238, 144],
  1374. "lightgrey": [211, 211, 211],
  1375. "lightpink": [255, 182, 193],
  1376. "lightsalmon": [255, 160, 122],
  1377. "lightseagreen": [32, 178, 170],
  1378. "lightskyblue": [135, 206, 250],
  1379. "lightslategray": [119, 136, 153],
  1380. "lightslategrey": [119, 136, 153],
  1381. "lightsteelblue": [176, 196, 222],
  1382. "lightyellow": [255, 255, 224],
  1383. "lime": [0, 255, 0],
  1384. "limegreen": [50, 205, 50],
  1385. "linen": [250, 240, 230],
  1386. "magenta": [255, 0, 255],
  1387. "maroon": [128, 0, 0],
  1388. "mediumaquamarine": [102, 205, 170],
  1389. "mediumblue": [0, 0, 205],
  1390. "mediumorchid": [186, 85, 211],
  1391. "mediumpurple": [147, 112, 219],
  1392. "mediumseagreen": [60, 179, 113],
  1393. "mediumslateblue": [123, 104, 238],
  1394. "mediumspringgreen": [0, 250, 154],
  1395. "mediumturquoise": [72, 209, 204],
  1396. "mediumvioletred": [199, 21, 133],
  1397. "midnightblue": [25, 25, 112],
  1398. "mintcream": [245, 255, 250],
  1399. "mistyrose": [255, 228, 225],
  1400. "moccasin": [255, 228, 181],
  1401. "navajowhite": [255, 222, 173],
  1402. "navy": [0, 0, 128],
  1403. "oldlace": [253, 245, 230],
  1404. "olive": [128, 128, 0],
  1405. "olivedrab": [107, 142, 35],
  1406. "orange": [255, 165, 0],
  1407. "orangered": [255, 69, 0],
  1408. "orchid": [218, 112, 214],
  1409. "palegoldenrod": [238, 232, 170],
  1410. "palegreen": [152, 251, 152],
  1411. "paleturquoise": [175, 238, 238],
  1412. "palevioletred": [219, 112, 147],
  1413. "papayawhip": [255, 239, 213],
  1414. "peachpuff": [255, 218, 185],
  1415. "peru": [205, 133, 63],
  1416. "pink": [255, 192, 203],
  1417. "plum": [221, 160, 221],
  1418. "powderblue": [176, 224, 230],
  1419. "purple": [128, 0, 128],
  1420. "rebeccapurple": [102, 51, 153],
  1421. "red": [255, 0, 0],
  1422. "rosybrown": [188, 143, 143],
  1423. "royalblue": [65, 105, 225],
  1424. "saddlebrown": [139, 69, 19],
  1425. "salmon": [250, 128, 114],
  1426. "sandybrown": [244, 164, 96],
  1427. "seagreen": [46, 139, 87],
  1428. "seashell": [255, 245, 238],
  1429. "sienna": [160, 82, 45],
  1430. "silver": [192, 192, 192],
  1431. "skyblue": [135, 206, 235],
  1432. "slateblue": [106, 90, 205],
  1433. "slategray": [112, 128, 144],
  1434. "slategrey": [112, 128, 144],
  1435. "snow": [255, 250, 250],
  1436. "springgreen": [0, 255, 127],
  1437. "steelblue": [70, 130, 180],
  1438. "tan": [210, 180, 140],
  1439. "teal": [0, 128, 128],
  1440. "thistle": [216, 191, 216],
  1441. "tomato": [255, 99, 71],
  1442. "turquoise": [64, 224, 208],
  1443. "violet": [238, 130, 238],
  1444. "wheat": [245, 222, 179],
  1445. "white": [255, 255, 255],
  1446. "whitesmoke": [245, 245, 245],
  1447. "yellow": [255, 255, 0],
  1448. "yellowgreen": [154, 205, 50]
  1449. };
  1450. },{}],7:[function(require,module,exports){
  1451. /**
  1452. * @namespace Chart
  1453. */
  1454. var Chart = require(27)();
  1455. require(26)(Chart);
  1456. require(22)(Chart);
  1457. require(25)(Chart);
  1458. require(21)(Chart);
  1459. require(23)(Chart);
  1460. require(24)(Chart);
  1461. require(28)(Chart);
  1462. require(32)(Chart);
  1463. require(30)(Chart);
  1464. require(31)(Chart);
  1465. require(33)(Chart);
  1466. require(29)(Chart);
  1467. require(34)(Chart);
  1468. require(35)(Chart);
  1469. require(36)(Chart);
  1470. require(37)(Chart);
  1471. require(38)(Chart);
  1472. require(41)(Chart);
  1473. require(39)(Chart);
  1474. require(40)(Chart);
  1475. require(42)(Chart);
  1476. require(43)(Chart);
  1477. require(44)(Chart);
  1478. // Controllers must be loaded after elements
  1479. // See Chart.core.datasetController.dataElementType
  1480. require(15)(Chart);
  1481. require(16)(Chart);
  1482. require(17)(Chart);
  1483. require(18)(Chart);
  1484. require(19)(Chart);
  1485. require(20)(Chart);
  1486. require(8)(Chart);
  1487. require(9)(Chart);
  1488. require(10)(Chart);
  1489. require(11)(Chart);
  1490. require(12)(Chart);
  1491. require(13)(Chart);
  1492. require(14)(Chart);
  1493. window.Chart = module.exports = Chart;
  1494. },{"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){
  1495. "use strict";
  1496. module.exports = function(Chart) {
  1497. Chart.Bar = function(context, config) {
  1498. config.type = 'bar';
  1499. return new Chart(context, config);
  1500. };
  1501. };
  1502. },{}],9:[function(require,module,exports){
  1503. "use strict";
  1504. module.exports = function(Chart) {
  1505. Chart.Bubble = function(context, config) {
  1506. config.type = 'bubble';
  1507. return new Chart(context, config);
  1508. };
  1509. };
  1510. },{}],10:[function(require,module,exports){
  1511. "use strict";
  1512. module.exports = function(Chart) {
  1513. Chart.Doughnut = function(context, config) {
  1514. config.type = 'doughnut';
  1515. return new Chart(context, config);
  1516. };
  1517. };
  1518. },{}],11:[function(require,module,exports){
  1519. "use strict";
  1520. module.exports = function(Chart) {
  1521. Chart.Line = function(context, config) {
  1522. config.type = 'line';
  1523. return new Chart(context, config);
  1524. };
  1525. };
  1526. },{}],12:[function(require,module,exports){
  1527. "use strict";
  1528. module.exports = function(Chart) {
  1529. Chart.PolarArea = function(context, config) {
  1530. config.type = 'polarArea';
  1531. return new Chart(context, config);
  1532. };
  1533. };
  1534. },{}],13:[function(require,module,exports){
  1535. "use strict";
  1536. module.exports = function(Chart) {
  1537. Chart.Radar = function(context, config) {
  1538. config.options = Chart.helpers.configMerge({ aspectRatio: 1 }, config.options);
  1539. config.type = 'radar';
  1540. return new Chart(context, config);
  1541. };
  1542. };
  1543. },{}],14:[function(require,module,exports){
  1544. "use strict";
  1545. module.exports = function(Chart) {
  1546. var defaultConfig = {
  1547. hover: {
  1548. mode: 'single'
  1549. },
  1550. scales: {
  1551. xAxes: [{
  1552. type: "linear", // scatter should not use a category axis
  1553. position: "bottom",
  1554. id: "x-axis-1" // need an ID so datasets can reference the scale
  1555. }],
  1556. yAxes: [{
  1557. type: "linear",
  1558. position: "left",
  1559. id: "y-axis-1"
  1560. }]
  1561. },
  1562. tooltips: {
  1563. callbacks: {
  1564. title: function() {
  1565. // Title doesn't make sense for scatter since we format the data as a point
  1566. return '';
  1567. },
  1568. label: function(tooltipItem) {
  1569. return '(' + tooltipItem.xLabel + ', ' + tooltipItem.yLabel + ')';
  1570. }
  1571. }
  1572. }
  1573. };
  1574. // Register the default config for this type
  1575. Chart.defaults.scatter = defaultConfig;
  1576. // Scatter charts use line controllers
  1577. Chart.controllers.scatter = Chart.controllers.line;
  1578. Chart.Scatter = function(context, config) {
  1579. config.type = 'scatter';
  1580. return new Chart(context, config);
  1581. };
  1582. };
  1583. },{}],15:[function(require,module,exports){
  1584. "use strict";
  1585. module.exports = function(Chart) {
  1586. var helpers = Chart.helpers;
  1587. Chart.defaults.bar = {
  1588. hover: {
  1589. mode: "label"
  1590. },
  1591. scales: {
  1592. xAxes: [{
  1593. type: "category",
  1594. // Specific to Bar Controller
  1595. categoryPercentage: 0.8,
  1596. barPercentage: 0.9,
  1597. // grid line settings
  1598. gridLines: {
  1599. offsetGridLines: true
  1600. }
  1601. }],
  1602. yAxes: [{
  1603. type: "linear"
  1604. }]
  1605. }
  1606. };
  1607. Chart.controllers.bar = Chart.DatasetController.extend({
  1608. dataElementType: Chart.elements.Rectangle,
  1609. initialize: function(chart, datasetIndex) {
  1610. Chart.DatasetController.prototype.initialize.call(this, chart, datasetIndex);
  1611. // Use this to indicate that this is a bar dataset.
  1612. this.getMeta().bar = true;
  1613. },
  1614. // Get the number of datasets that display bars. We use this to correctly calculate the bar width
  1615. getBarCount: function() {
  1616. var me = this;
  1617. var barCount = 0;
  1618. helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
  1619. var meta = me.chart.getDatasetMeta(datasetIndex);
  1620. if (meta.bar && me.chart.isDatasetVisible(datasetIndex)) {
  1621. ++barCount;
  1622. }
  1623. }, me);
  1624. return barCount;
  1625. },
  1626. update: function(reset) {
  1627. var me = this;
  1628. helpers.each(me.getMeta().data, function(rectangle, index) {
  1629. me.updateElement(rectangle, index, reset);
  1630. }, me);
  1631. },
  1632. updateElement: function(rectangle, index, reset) {
  1633. var me = this;
  1634. var meta = me.getMeta();
  1635. var xScale = me.getScaleForId(meta.xAxisID);
  1636. var yScale = me.getScaleForId(meta.yAxisID);
  1637. var scaleBase = yScale.getBasePixel();
  1638. var rectangleElementOptions = me.chart.options.elements.rectangle;
  1639. var custom = rectangle.custom || {};
  1640. var dataset = me.getDataset();
  1641. helpers.extend(rectangle, {
  1642. // Utility
  1643. _xScale: xScale,
  1644. _yScale: yScale,
  1645. _datasetIndex: me.index,
  1646. _index: index,
  1647. // Desired view properties
  1648. _model: {
  1649. x: me.calculateBarX(index, me.index),
  1650. y: reset ? scaleBase : me.calculateBarY(index, me.index),
  1651. // Tooltip
  1652. label: me.chart.data.labels[index],
  1653. datasetLabel: dataset.label,
  1654. // Appearance
  1655. base: reset ? scaleBase : me.calculateBarBase(me.index, index),
  1656. width: me.calculateBarWidth(index),
  1657. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor),
  1658. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
  1659. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
  1660. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth)
  1661. }
  1662. });
  1663. rectangle.pivot();
  1664. },
  1665. calculateBarBase: function(datasetIndex, index) {
  1666. var me = this;
  1667. var meta = me.getMeta();
  1668. var yScale = me.getScaleForId(meta.yAxisID);
  1669. var base = 0;
  1670. if (yScale.options.stacked) {
  1671. var chart = me.chart;
  1672. var datasets = chart.data.datasets;
  1673. var value = Number(datasets[datasetIndex].data[index]);
  1674. for (var i = 0; i < datasetIndex; i++) {
  1675. var currentDs = datasets[i];
  1676. var currentDsMeta = chart.getDatasetMeta(i);
  1677. if (currentDsMeta.bar && currentDsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  1678. var currentVal = Number(currentDs.data[index]);
  1679. base += value < 0 ? Math.min(currentVal, 0) : Math.max(currentVal, 0);
  1680. }
  1681. }
  1682. return yScale.getPixelForValue(base);
  1683. }
  1684. return yScale.getBasePixel();
  1685. },
  1686. getRuler: function(index) {
  1687. var me = this;
  1688. var meta = me.getMeta();
  1689. var xScale = me.getScaleForId(meta.xAxisID);
  1690. var datasetCount = me.getBarCount();
  1691. var tickWidth;
  1692. if (xScale.options.type === 'category') {
  1693. tickWidth = xScale.getPixelForTick(index + 1) - xScale.getPixelForTick(index);
  1694. } else {
  1695. // Average width
  1696. tickWidth = xScale.width / xScale.ticks.length;
  1697. }
  1698. var categoryWidth = tickWidth * xScale.options.categoryPercentage;
  1699. var categorySpacing = (tickWidth - (tickWidth * xScale.options.categoryPercentage)) / 2;
  1700. var fullBarWidth = categoryWidth / datasetCount;
  1701. if (xScale.ticks.length !== me.chart.data.labels.length) {
  1702. var perc = xScale.ticks.length / me.chart.data.labels.length;
  1703. fullBarWidth = fullBarWidth * perc;
  1704. }
  1705. var barWidth = fullBarWidth * xScale.options.barPercentage;
  1706. var barSpacing = fullBarWidth - (fullBarWidth * xScale.options.barPercentage);
  1707. return {
  1708. datasetCount: datasetCount,
  1709. tickWidth: tickWidth,
  1710. categoryWidth: categoryWidth,
  1711. categorySpacing: categorySpacing,
  1712. fullBarWidth: fullBarWidth,
  1713. barWidth: barWidth,
  1714. barSpacing: barSpacing
  1715. };
  1716. },
  1717. calculateBarWidth: function(index) {
  1718. var xScale = this.getScaleForId(this.getMeta().xAxisID);
  1719. if (xScale.options.barThickness) {
  1720. return xScale.options.barThickness;
  1721. }
  1722. var ruler = this.getRuler(index);
  1723. return xScale.options.stacked ? ruler.categoryWidth : ruler.barWidth;
  1724. },
  1725. // Get bar index from the given dataset index accounting for the fact that not all bars are visible
  1726. getBarIndex: function(datasetIndex) {
  1727. var barIndex = 0;
  1728. var meta, j;
  1729. for (j = 0; j < datasetIndex; ++j) {
  1730. meta = this.chart.getDatasetMeta(j);
  1731. if (meta.bar && this.chart.isDatasetVisible(j)) {
  1732. ++barIndex;
  1733. }
  1734. }
  1735. return barIndex;
  1736. },
  1737. calculateBarX: function(index, datasetIndex) {
  1738. var me = this;
  1739. var meta = me.getMeta();
  1740. var xScale = me.getScaleForId(meta.xAxisID);
  1741. var barIndex = me.getBarIndex(datasetIndex);
  1742. var ruler = me.getRuler(index);
  1743. var leftTick = xScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
  1744. leftTick -= me.chart.isCombo ? (ruler.tickWidth / 2) : 0;
  1745. if (xScale.options.stacked) {
  1746. return leftTick + (ruler.categoryWidth / 2) + ruler.categorySpacing;
  1747. }
  1748. return leftTick +
  1749. (ruler.barWidth / 2) +
  1750. ruler.categorySpacing +
  1751. (ruler.barWidth * barIndex) +
  1752. (ruler.barSpacing / 2) +
  1753. (ruler.barSpacing * barIndex);
  1754. },
  1755. calculateBarY: function(index, datasetIndex) {
  1756. var me = this;
  1757. var meta = me.getMeta();
  1758. var yScale = me.getScaleForId(meta.yAxisID);
  1759. var value = Number(me.getDataset().data[index]);
  1760. if (yScale.options.stacked) {
  1761. var sumPos = 0,
  1762. sumNeg = 0;
  1763. for (var i = 0; i < datasetIndex; i++) {
  1764. var ds = me.chart.data.datasets[i];
  1765. var dsMeta = me.chart.getDatasetMeta(i);
  1766. if (dsMeta.bar && dsMeta.yAxisID === yScale.id && me.chart.isDatasetVisible(i)) {
  1767. var stackedVal = Number(ds.data[index]);
  1768. if (stackedVal < 0) {
  1769. sumNeg += stackedVal || 0;
  1770. } else {
  1771. sumPos += stackedVal || 0;
  1772. }
  1773. }
  1774. }
  1775. if (value < 0) {
  1776. return yScale.getPixelForValue(sumNeg + value);
  1777. } else {
  1778. return yScale.getPixelForValue(sumPos + value);
  1779. }
  1780. }
  1781. return yScale.getPixelForValue(value);
  1782. },
  1783. draw: function(ease) {
  1784. var me = this;
  1785. var easingDecimal = ease || 1;
  1786. helpers.each(me.getMeta().data, function(rectangle, index) {
  1787. var d = me.getDataset().data[index];
  1788. if (d !== null && d !== undefined && !isNaN(d)) {
  1789. rectangle.transition(easingDecimal).draw();
  1790. }
  1791. }, me);
  1792. },
  1793. setHoverStyle: function(rectangle) {
  1794. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  1795. var index = rectangle._index;
  1796. var custom = rectangle.custom || {};
  1797. var model = rectangle._model;
  1798. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  1799. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  1800. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  1801. },
  1802. removeHoverStyle: function(rectangle) {
  1803. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  1804. var index = rectangle._index;
  1805. var custom = rectangle.custom || {};
  1806. var model = rectangle._model;
  1807. var rectangleElementOptions = this.chart.options.elements.rectangle;
  1808. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor);
  1809. model.borderColor = custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor);
  1810. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth);
  1811. }
  1812. });
  1813. // including horizontalBar in the bar file, instead of a file of its own
  1814. // it extends bar (like pie extends doughnut)
  1815. Chart.defaults.horizontalBar = {
  1816. hover: {
  1817. mode: "label"
  1818. },
  1819. scales: {
  1820. xAxes: [{
  1821. type: "linear",
  1822. position: "bottom"
  1823. }],
  1824. yAxes: [{
  1825. position: "left",
  1826. type: "category",
  1827. // Specific to Horizontal Bar Controller
  1828. categoryPercentage: 0.8,
  1829. barPercentage: 0.9,
  1830. // grid line settings
  1831. gridLines: {
  1832. offsetGridLines: true
  1833. }
  1834. }]
  1835. },
  1836. elements: {
  1837. rectangle: {
  1838. borderSkipped: 'left'
  1839. }
  1840. },
  1841. tooltips: {
  1842. callbacks: {
  1843. title: function(tooltipItems, data) {
  1844. // Pick first xLabel for now
  1845. var title = '';
  1846. if (tooltipItems.length > 0) {
  1847. if (tooltipItems[0].yLabel) {
  1848. title = tooltipItems[0].yLabel;
  1849. } else if (data.labels.length > 0 && tooltipItems[0].index < data.labels.length) {
  1850. title = data.labels[tooltipItems[0].index];
  1851. }
  1852. }
  1853. return title;
  1854. },
  1855. label: function(tooltipItem, data) {
  1856. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  1857. return datasetLabel + ': ' + tooltipItem.xLabel;
  1858. }
  1859. }
  1860. }
  1861. };
  1862. Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
  1863. updateElement: function(rectangle, index, reset) {
  1864. var me = this;
  1865. var meta = me.getMeta();
  1866. var xScale = me.getScaleForId(meta.xAxisID);
  1867. var yScale = me.getScaleForId(meta.yAxisID);
  1868. var scaleBase = xScale.getBasePixel();
  1869. var custom = rectangle.custom || {};
  1870. var dataset = me.getDataset();
  1871. var rectangleElementOptions = me.chart.options.elements.rectangle;
  1872. helpers.extend(rectangle, {
  1873. // Utility
  1874. _xScale: xScale,
  1875. _yScale: yScale,
  1876. _datasetIndex: me.index,
  1877. _index: index,
  1878. // Desired view properties
  1879. _model: {
  1880. x: reset ? scaleBase : me.calculateBarX(index, me.index),
  1881. y: me.calculateBarY(index, me.index),
  1882. // Tooltip
  1883. label: me.chart.data.labels[index],
  1884. datasetLabel: dataset.label,
  1885. // Appearance
  1886. base: reset ? scaleBase : me.calculateBarBase(me.index, index),
  1887. height: me.calculateBarHeight(index),
  1888. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor),
  1889. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
  1890. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
  1891. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth)
  1892. },
  1893. draw: function () {
  1894. var ctx = this._chart.ctx;
  1895. var vm = this._view;
  1896. var halfHeight = vm.height / 2,
  1897. topY = vm.y - halfHeight,
  1898. bottomY = vm.y + halfHeight,
  1899. right = vm.base - (vm.base - vm.x),
  1900. halfStroke = vm.borderWidth / 2;
  1901. // Canvas doesn't allow us to stroke inside the width so we can
  1902. // adjust the sizes to fit if we're setting a stroke on the line
  1903. if (vm.borderWidth) {
  1904. topY += halfStroke;
  1905. bottomY -= halfStroke;
  1906. right += halfStroke;
  1907. }
  1908. ctx.beginPath();
  1909. ctx.fillStyle = vm.backgroundColor;
  1910. ctx.strokeStyle = vm.borderColor;
  1911. ctx.lineWidth = vm.borderWidth;
  1912. // Corner points, from bottom-left to bottom-right clockwise
  1913. // | 1 2 |
  1914. // | 0 3 |
  1915. var corners = [
  1916. [vm.base, bottomY],
  1917. [vm.base, topY],
  1918. [right, topY],
  1919. [right, bottomY]
  1920. ];
  1921. // Find first (starting) corner with fallback to 'bottom'
  1922. var borders = ['bottom', 'left', 'top', 'right'];
  1923. var startCorner = borders.indexOf(vm.borderSkipped, 0);
  1924. if (startCorner === -1) {
  1925. startCorner = 0;
  1926. }
  1927. function cornerAt(index) {
  1928. return corners[(startCorner + index) % 4];
  1929. }
  1930. // Draw rectangle from 'startCorner'
  1931. ctx.moveTo.apply(ctx, cornerAt(0));
  1932. for (var i = 1; i < 4; i++) {
  1933. ctx.lineTo.apply(ctx, cornerAt(i));
  1934. }
  1935. ctx.fill();
  1936. if (vm.borderWidth) {
  1937. ctx.stroke();
  1938. }
  1939. },
  1940. inRange: function (mouseX, mouseY) {
  1941. var vm = this._view;
  1942. var inRange = false;
  1943. if (vm) {
  1944. if (vm.x < vm.base) {
  1945. inRange = (mouseY >= vm.y - vm.height / 2 && mouseY <= vm.y + vm.height / 2) && (mouseX >= vm.x && mouseX <= vm.base);
  1946. } else {
  1947. inRange = (mouseY >= vm.y - vm.height / 2 && mouseY <= vm.y + vm.height / 2) && (mouseX >= vm.base && mouseX <= vm.x);
  1948. }
  1949. }
  1950. return inRange;
  1951. }
  1952. });
  1953. rectangle.pivot();
  1954. },
  1955. calculateBarBase: function (datasetIndex, index) {
  1956. var me = this;
  1957. var meta = me.getMeta();
  1958. var xScale = me.getScaleForId(meta.xAxisID);
  1959. var base = 0;
  1960. if (xScale.options.stacked) {
  1961. var chart = me.chart;
  1962. var datasets = chart.data.datasets;
  1963. var value = Number(datasets[datasetIndex].data[index]);
  1964. for (var i = 0; i < datasetIndex; i++) {
  1965. var currentDs = datasets[i];
  1966. var currentDsMeta = chart.getDatasetMeta(i);
  1967. if (currentDsMeta.bar && currentDsMeta.xAxisID === xScale.id && chart.isDatasetVisible(i)) {
  1968. var currentVal = Number(currentDs.data[index]);
  1969. base += value < 0 ? Math.min(currentVal, 0) : Math.max(currentVal, 0);
  1970. }
  1971. }
  1972. return xScale.getPixelForValue(base);
  1973. }
  1974. return xScale.getBasePixel();
  1975. },
  1976. getRuler: function (index) {
  1977. var me = this;
  1978. var meta = me.getMeta();
  1979. var yScale = me.getScaleForId(meta.yAxisID);
  1980. var datasetCount = me.getBarCount();
  1981. var tickHeight;
  1982. if (yScale.options.type === 'category') {
  1983. tickHeight = yScale.getPixelForTick(index + 1) - yScale.getPixelForTick(index);
  1984. } else {
  1985. // Average width
  1986. tickHeight = yScale.width / yScale.ticks.length;
  1987. }
  1988. var categoryHeight = tickHeight * yScale.options.categoryPercentage;
  1989. var categorySpacing = (tickHeight - (tickHeight * yScale.options.categoryPercentage)) / 2;
  1990. var fullBarHeight = categoryHeight / datasetCount;
  1991. if (yScale.ticks.length !== me.chart.data.labels.length) {
  1992. var perc = yScale.ticks.length / me.chart.data.labels.length;
  1993. fullBarHeight = fullBarHeight * perc;
  1994. }
  1995. var barHeight = fullBarHeight * yScale.options.barPercentage;
  1996. var barSpacing = fullBarHeight - (fullBarHeight * yScale.options.barPercentage);
  1997. return {
  1998. datasetCount: datasetCount,
  1999. tickHeight: tickHeight,
  2000. categoryHeight: categoryHeight,
  2001. categorySpacing: categorySpacing,
  2002. fullBarHeight: fullBarHeight,
  2003. barHeight: barHeight,
  2004. barSpacing: barSpacing
  2005. };
  2006. },
  2007. calculateBarHeight: function (index) {
  2008. var me = this;
  2009. var yScale = me.getScaleForId(me.getMeta().yAxisID);
  2010. if (yScale.options.barThickness) {
  2011. return yScale.options.barThickness;
  2012. }
  2013. var ruler = me.getRuler(index);
  2014. return yScale.options.stacked ? ruler.categoryHeight : ruler.barHeight;
  2015. },
  2016. calculateBarX: function (index, datasetIndex) {
  2017. var me = this;
  2018. var meta = me.getMeta();
  2019. var xScale = me.getScaleForId(meta.xAxisID);
  2020. var value = Number(me.getDataset().data[index]);
  2021. if (xScale.options.stacked) {
  2022. var sumPos = 0,
  2023. sumNeg = 0;
  2024. for (var i = 0; i < datasetIndex; i++) {
  2025. var ds = me.chart.data.datasets[i];
  2026. var dsMeta = me.chart.getDatasetMeta(i);
  2027. if (dsMeta.bar && dsMeta.xAxisID === xScale.id && me.chart.isDatasetVisible(i)) {
  2028. var stackedVal = Number(ds.data[index]);
  2029. if (stackedVal < 0) {
  2030. sumNeg += stackedVal || 0;
  2031. } else {
  2032. sumPos += stackedVal || 0;
  2033. }
  2034. }
  2035. }
  2036. if (value < 0) {
  2037. return xScale.getPixelForValue(sumNeg + value);
  2038. } else {
  2039. return xScale.getPixelForValue(sumPos + value);
  2040. }
  2041. }
  2042. return xScale.getPixelForValue(value);
  2043. },
  2044. calculateBarY: function (index, datasetIndex) {
  2045. var me = this;
  2046. var meta = me.getMeta();
  2047. var yScale = me.getScaleForId(meta.yAxisID);
  2048. var barIndex = me.getBarIndex(datasetIndex);
  2049. var ruler = me.getRuler(index);
  2050. var topTick = yScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
  2051. topTick -= me.chart.isCombo ? (ruler.tickHeight / 2) : 0;
  2052. if (yScale.options.stacked) {
  2053. return topTick + (ruler.categoryHeight / 2) + ruler.categorySpacing;
  2054. }
  2055. return topTick +
  2056. (ruler.barHeight / 2) +
  2057. ruler.categorySpacing +
  2058. (ruler.barHeight * barIndex) +
  2059. (ruler.barSpacing / 2) +
  2060. (ruler.barSpacing * barIndex);
  2061. }
  2062. });
  2063. };
  2064. },{}],16:[function(require,module,exports){
  2065. "use strict";
  2066. module.exports = function(Chart) {
  2067. var helpers = Chart.helpers;
  2068. Chart.defaults.bubble = {
  2069. hover: {
  2070. mode: "single"
  2071. },
  2072. scales: {
  2073. xAxes: [{
  2074. type: "linear", // bubble should probably use a linear scale by default
  2075. position: "bottom",
  2076. id: "x-axis-0" // need an ID so datasets can reference the scale
  2077. }],
  2078. yAxes: [{
  2079. type: "linear",
  2080. position: "left",
  2081. id: "y-axis-0"
  2082. }]
  2083. },
  2084. tooltips: {
  2085. callbacks: {
  2086. title: function() {
  2087. // Title doesn't make sense for scatter since we format the data as a point
  2088. return '';
  2089. },
  2090. label: function(tooltipItem, data) {
  2091. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  2092. var dataPoint = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  2093. return datasetLabel + ': (' + dataPoint.x + ', ' + dataPoint.y + ', ' + dataPoint.r + ')';
  2094. }
  2095. }
  2096. }
  2097. };
  2098. Chart.controllers.bubble = Chart.DatasetController.extend({
  2099. dataElementType: Chart.elements.Point,
  2100. update: function(reset) {
  2101. var me = this;
  2102. var meta = me.getMeta();
  2103. var points = meta.data;
  2104. // Update Points
  2105. helpers.each(points, function(point, index) {
  2106. me.updateElement(point, index, reset);
  2107. });
  2108. },
  2109. updateElement: function(point, index, reset) {
  2110. var me = this;
  2111. var meta = me.getMeta();
  2112. var xScale = me.getScaleForId(meta.xAxisID);
  2113. var yScale = me.getScaleForId(meta.yAxisID);
  2114. var custom = point.custom || {};
  2115. var dataset = me.getDataset();
  2116. var data = dataset.data[index];
  2117. var pointElementOptions = me.chart.options.elements.point;
  2118. var dsIndex = me.index;
  2119. helpers.extend(point, {
  2120. // Utility
  2121. _xScale: xScale,
  2122. _yScale: yScale,
  2123. _datasetIndex: dsIndex,
  2124. _index: index,
  2125. // Desired view properties
  2126. _model: {
  2127. x: reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex, me.chart.isCombo),
  2128. y: reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex),
  2129. // Appearance
  2130. radius: reset ? 0 : custom.radius ? custom.radius : me.getRadius(data),
  2131. // Tooltip
  2132. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.hitRadius, index, pointElementOptions.hitRadius)
  2133. }
  2134. });
  2135. // Trick to reset the styles of the point
  2136. Chart.DatasetController.prototype.removeHoverStyle.call(me, point, pointElementOptions);
  2137. var model = point._model;
  2138. model.skip = custom.skip ? custom.skip : (isNaN(model.x) || isNaN(model.y));
  2139. point.pivot();
  2140. },
  2141. getRadius: function(value) {
  2142. return value.r || this.chart.options.elements.point.radius;
  2143. },
  2144. setHoverStyle: function(point) {
  2145. var me = this;
  2146. Chart.DatasetController.prototype.setHoverStyle.call(me, point);
  2147. // Radius
  2148. var dataset = me.chart.data.datasets[point._datasetIndex];
  2149. var index = point._index;
  2150. var custom = point.custom || {};
  2151. var model = point._model;
  2152. model.radius = custom.hoverRadius ? custom.hoverRadius : (helpers.getValueAtIndexOrDefault(dataset.hoverRadius, index, me.chart.options.elements.point.hoverRadius)) + me.getRadius(dataset.data[index]);
  2153. },
  2154. removeHoverStyle: function(point) {
  2155. var me = this;
  2156. Chart.DatasetController.prototype.removeHoverStyle.call(me, point, me.chart.options.elements.point);
  2157. var dataVal = me.chart.data.datasets[point._datasetIndex].data[point._index];
  2158. var custom = point.custom || {};
  2159. var model = point._model;
  2160. model.radius = custom.radius ? custom.radius : me.getRadius(dataVal);
  2161. }
  2162. });
  2163. };
  2164. },{}],17:[function(require,module,exports){
  2165. "use strict";
  2166. module.exports = function(Chart) {
  2167. var helpers = Chart.helpers,
  2168. defaults = Chart.defaults;
  2169. defaults.doughnut = {
  2170. animation: {
  2171. //Boolean - Whether we animate the rotation of the Doughnut
  2172. animateRotate: true,
  2173. //Boolean - Whether we animate scaling the Doughnut from the centre
  2174. animateScale: false
  2175. },
  2176. aspectRatio: 1,
  2177. hover: {
  2178. mode: 'single'
  2179. },
  2180. legendCallback: function(chart) {
  2181. var text = [];
  2182. text.push('<ul class="' + chart.id + '-legend">');
  2183. var data = chart.data;
  2184. var datasets = data.datasets;
  2185. var labels = data.labels;
  2186. if (datasets.length) {
  2187. for (var i = 0; i < datasets[0].data.length; ++i) {
  2188. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2189. if (labels[i]) {
  2190. text.push(labels[i]);
  2191. }
  2192. text.push('</li>');
  2193. }
  2194. }
  2195. text.push('</ul>');
  2196. return text.join("");
  2197. },
  2198. legend: {
  2199. labels: {
  2200. generateLabels: function(chart) {
  2201. var data = chart.data;
  2202. if (data.labels.length && data.datasets.length) {
  2203. return data.labels.map(function(label, i) {
  2204. var meta = chart.getDatasetMeta(0);
  2205. var ds = data.datasets[0];
  2206. var arc = meta.data[i];
  2207. var custom = arc && arc.custom || {};
  2208. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2209. var arcOpts = chart.options.elements.arc;
  2210. var fill = custom.backgroundColor ? custom.backgroundColor : getValueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2211. var stroke = custom.borderColor ? custom.borderColor : getValueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2212. var bw = custom.borderWidth ? custom.borderWidth : getValueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2213. return {
  2214. text: label,
  2215. fillStyle: fill,
  2216. strokeStyle: stroke,
  2217. lineWidth: bw,
  2218. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2219. // Extra data used for toggling the correct item
  2220. index: i
  2221. };
  2222. });
  2223. } else {
  2224. return [];
  2225. }
  2226. }
  2227. },
  2228. onClick: function(e, legendItem) {
  2229. var index = legendItem.index;
  2230. var chart = this.chart;
  2231. var i, ilen, meta;
  2232. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2233. meta = chart.getDatasetMeta(i);
  2234. meta.data[index].hidden = !meta.data[index].hidden;
  2235. }
  2236. chart.update();
  2237. }
  2238. },
  2239. //The percentage of the chart that we cut out of the middle.
  2240. cutoutPercentage: 50,
  2241. //The rotation of the chart, where the first data arc begins.
  2242. rotation: Math.PI * -0.5,
  2243. //The total circumference of the chart.
  2244. circumference: Math.PI * 2.0,
  2245. // Need to override these to give a nice default
  2246. tooltips: {
  2247. callbacks: {
  2248. title: function() {
  2249. return '';
  2250. },
  2251. label: function(tooltipItem, data) {
  2252. return data.labels[tooltipItem.index] + ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  2253. }
  2254. }
  2255. }
  2256. };
  2257. defaults.pie = helpers.clone(defaults.doughnut);
  2258. helpers.extend(defaults.pie, {
  2259. cutoutPercentage: 0
  2260. });
  2261. Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
  2262. dataElementType: Chart.elements.Arc,
  2263. linkScales: helpers.noop,
  2264. // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
  2265. getRingIndex: function(datasetIndex) {
  2266. var ringIndex = 0;
  2267. for (var j = 0; j < datasetIndex; ++j) {
  2268. if (this.chart.isDatasetVisible(j)) {
  2269. ++ringIndex;
  2270. }
  2271. }
  2272. return ringIndex;
  2273. },
  2274. update: function(reset) {
  2275. var me = this;
  2276. var chart = me.chart,
  2277. chartArea = chart.chartArea,
  2278. opts = chart.options,
  2279. arcOpts = opts.elements.arc,
  2280. availableWidth = chartArea.right - chartArea.left - arcOpts.borderWidth,
  2281. availableHeight = chartArea.bottom - chartArea.top - arcOpts.borderWidth,
  2282. minSize = Math.min(availableWidth, availableHeight),
  2283. offset = {
  2284. x: 0,
  2285. y: 0
  2286. },
  2287. meta = me.getMeta(),
  2288. cutoutPercentage = opts.cutoutPercentage,
  2289. circumference = opts.circumference;
  2290. // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
  2291. if (circumference < Math.PI * 2.0) {
  2292. var startAngle = opts.rotation % (Math.PI * 2.0);
  2293. startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
  2294. var endAngle = startAngle + circumference;
  2295. var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
  2296. var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
  2297. var contains0 = (startAngle <= 0 && 0 <= endAngle) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
  2298. var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
  2299. var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
  2300. var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
  2301. var cutout = cutoutPercentage / 100.0;
  2302. 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))};
  2303. 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))};
  2304. var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
  2305. minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
  2306. offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
  2307. }
  2308. chart.borderWidth = me.getMaxBorderWidth(meta.data);
  2309. chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
  2310. chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 1, 0);
  2311. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2312. chart.offsetX = offset.x * chart.outerRadius;
  2313. chart.offsetY = offset.y * chart.outerRadius;
  2314. meta.total = me.calculateTotal();
  2315. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
  2316. me.innerRadius = me.outerRadius - chart.radiusLength;
  2317. helpers.each(meta.data, function(arc, index) {
  2318. me.updateElement(arc, index, reset);
  2319. });
  2320. },
  2321. updateElement: function(arc, index, reset) {
  2322. var me = this;
  2323. var chart = me.chart,
  2324. chartArea = chart.chartArea,
  2325. opts = chart.options,
  2326. animationOpts = opts.animation,
  2327. centerX = (chartArea.left + chartArea.right) / 2,
  2328. centerY = (chartArea.top + chartArea.bottom) / 2,
  2329. startAngle = opts.rotation, // non reset case handled later
  2330. endAngle = opts.rotation, // non reset case handled later
  2331. dataset = me.getDataset(),
  2332. circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI)),
  2333. innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius,
  2334. outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius,
  2335. valueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2336. helpers.extend(arc, {
  2337. // Utility
  2338. _datasetIndex: me.index,
  2339. _index: index,
  2340. // Desired view properties
  2341. _model: {
  2342. x: centerX + chart.offsetX,
  2343. y: centerY + chart.offsetY,
  2344. startAngle: startAngle,
  2345. endAngle: endAngle,
  2346. circumference: circumference,
  2347. outerRadius: outerRadius,
  2348. innerRadius: innerRadius,
  2349. label: valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index])
  2350. }
  2351. });
  2352. var model = arc._model;
  2353. // Resets the visual styles
  2354. this.removeHoverStyle(arc);
  2355. // Set correct angles if not resetting
  2356. if (!reset || !animationOpts.animateRotate) {
  2357. if (index === 0) {
  2358. model.startAngle = opts.rotation;
  2359. } else {
  2360. model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
  2361. }
  2362. model.endAngle = model.startAngle + model.circumference;
  2363. }
  2364. arc.pivot();
  2365. },
  2366. removeHoverStyle: function(arc) {
  2367. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  2368. },
  2369. calculateTotal: function() {
  2370. var dataset = this.getDataset();
  2371. var meta = this.getMeta();
  2372. var total = 0;
  2373. var value;
  2374. helpers.each(meta.data, function(element, index) {
  2375. value = dataset.data[index];
  2376. if (!isNaN(value) && !element.hidden) {
  2377. total += Math.abs(value);
  2378. }
  2379. });
  2380. /*if (total === 0) {
  2381. total = NaN;
  2382. }*/
  2383. return total;
  2384. },
  2385. calculateCircumference: function(value) {
  2386. var total = this.getMeta().total;
  2387. if (total > 0 && !isNaN(value)) {
  2388. return (Math.PI * 2.0) * (value / total);
  2389. } else {
  2390. return 0;
  2391. }
  2392. },
  2393. //gets the max border or hover width to properly scale pie charts
  2394. getMaxBorderWidth: function (elements) {
  2395. var max = 0,
  2396. index = this.index,
  2397. length = elements.length,
  2398. borderWidth,
  2399. hoverWidth;
  2400. for (var i = 0; i < length; i++) {
  2401. borderWidth = elements[i]._model ? elements[i]._model.borderWidth : 0;
  2402. hoverWidth = elements[i]._chart ? elements[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
  2403. max = borderWidth > max ? borderWidth : max;
  2404. max = hoverWidth > max ? hoverWidth : max;
  2405. }
  2406. return max;
  2407. }
  2408. });
  2409. };
  2410. },{}],18:[function(require,module,exports){
  2411. "use strict";
  2412. module.exports = function(Chart) {
  2413. var helpers = Chart.helpers;
  2414. Chart.defaults.line = {
  2415. showLines: true,
  2416. spanGaps: false,
  2417. hover: {
  2418. mode: "label"
  2419. },
  2420. scales: {
  2421. xAxes: [{
  2422. type: "category",
  2423. id: 'x-axis-0'
  2424. }],
  2425. yAxes: [{
  2426. type: "linear",
  2427. id: 'y-axis-0'
  2428. }]
  2429. }
  2430. };
  2431. function lineEnabled(dataset, options) {
  2432. return helpers.getValueOrDefault(dataset.showLine, options.showLines);
  2433. }
  2434. Chart.controllers.line = Chart.DatasetController.extend({
  2435. datasetElementType: Chart.elements.Line,
  2436. dataElementType: Chart.elements.Point,
  2437. addElementAndReset: function(index) {
  2438. var me = this;
  2439. var options = me.chart.options;
  2440. var meta = me.getMeta();
  2441. Chart.DatasetController.prototype.addElementAndReset.call(me, index);
  2442. // Make sure bezier control points are updated
  2443. if (lineEnabled(me.getDataset(), options) && meta.dataset._model.tension !== 0) {
  2444. me.updateBezierControlPoints();
  2445. }
  2446. },
  2447. update: function(reset) {
  2448. var me = this;
  2449. var meta = me.getMeta();
  2450. var line = meta.dataset;
  2451. var points = meta.data || [];
  2452. var options = me.chart.options;
  2453. var lineElementOptions = options.elements.line;
  2454. var scale = me.getScaleForId(meta.yAxisID);
  2455. var i, ilen, custom;
  2456. var dataset = me.getDataset();
  2457. var showLine = lineEnabled(dataset, options);
  2458. // Update Line
  2459. if (showLine) {
  2460. custom = line.custom || {};
  2461. // Compatibility: If the properties are defined with only the old name, use those values
  2462. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2463. dataset.lineTension = dataset.tension;
  2464. }
  2465. // Utility
  2466. line._scale = scale;
  2467. line._datasetIndex = me.index;
  2468. // Data
  2469. line._children = points;
  2470. // Model
  2471. line._model = {
  2472. // Appearance
  2473. // The default behavior of lines is to break at null values, according
  2474. // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
  2475. // This option gives linse the ability to span gaps
  2476. spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
  2477. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2478. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2479. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2480. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2481. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2482. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2483. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2484. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2485. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2486. steppedLine: custom.steppedLine ? custom.steppedLine : helpers.getValueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
  2487. cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.getValueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode),
  2488. // Scale
  2489. scaleTop: scale.top,
  2490. scaleBottom: scale.bottom,
  2491. scaleZero: scale.getBasePixel()
  2492. };
  2493. line.pivot();
  2494. }
  2495. // Update Points
  2496. for (i=0, ilen=points.length; i<ilen; ++i) {
  2497. me.updateElement(points[i], i, reset);
  2498. }
  2499. if (showLine && line._model.tension !== 0) {
  2500. me.updateBezierControlPoints();
  2501. }
  2502. // Now pivot the point for animation
  2503. for (i=0, ilen=points.length; i<ilen; ++i) {
  2504. points[i].pivot();
  2505. }
  2506. },
  2507. getPointBackgroundColor: function(point, index) {
  2508. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  2509. var dataset = this.getDataset();
  2510. var custom = point.custom || {};
  2511. if (custom.backgroundColor) {
  2512. backgroundColor = custom.backgroundColor;
  2513. } else if (dataset.pointBackgroundColor) {
  2514. backgroundColor = helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  2515. } else if (dataset.backgroundColor) {
  2516. backgroundColor = dataset.backgroundColor;
  2517. }
  2518. return backgroundColor;
  2519. },
  2520. getPointBorderColor: function(point, index) {
  2521. var borderColor = this.chart.options.elements.point.borderColor;
  2522. var dataset = this.getDataset();
  2523. var custom = point.custom || {};
  2524. if (custom.borderColor) {
  2525. borderColor = custom.borderColor;
  2526. } else if (dataset.pointBorderColor) {
  2527. borderColor = helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
  2528. } else if (dataset.borderColor) {
  2529. borderColor = dataset.borderColor;
  2530. }
  2531. return borderColor;
  2532. },
  2533. getPointBorderWidth: function(point, index) {
  2534. var borderWidth = this.chart.options.elements.point.borderWidth;
  2535. var dataset = this.getDataset();
  2536. var custom = point.custom || {};
  2537. if (custom.borderWidth) {
  2538. borderWidth = custom.borderWidth;
  2539. } else if (dataset.pointBorderWidth) {
  2540. borderWidth = helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  2541. } else if (dataset.borderWidth) {
  2542. borderWidth = dataset.borderWidth;
  2543. }
  2544. return borderWidth;
  2545. },
  2546. updateElement: function(point, index, reset) {
  2547. var me = this;
  2548. var meta = me.getMeta();
  2549. var custom = point.custom || {};
  2550. var dataset = me.getDataset();
  2551. var datasetIndex = me.index;
  2552. var value = dataset.data[index];
  2553. var yScale = me.getScaleForId(meta.yAxisID);
  2554. var xScale = me.getScaleForId(meta.xAxisID);
  2555. var pointOptions = me.chart.options.elements.point;
  2556. var x, y;
  2557. var labels = me.chart.data.labels || [];
  2558. var includeOffset = (labels.length === 1 || dataset.data.length === 1) || me.chart.isCombo;
  2559. // Compatibility: If the properties are defined with only the old name, use those values
  2560. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2561. dataset.pointRadius = dataset.radius;
  2562. }
  2563. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  2564. dataset.pointHitRadius = dataset.hitRadius;
  2565. }
  2566. x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex, includeOffset);
  2567. y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
  2568. // Utility
  2569. point._xScale = xScale;
  2570. point._yScale = yScale;
  2571. point._datasetIndex = datasetIndex;
  2572. point._index = index;
  2573. // Desired view properties
  2574. point._model = {
  2575. x: x,
  2576. y: y,
  2577. skip: custom.skip || isNaN(x) || isNaN(y),
  2578. // Appearance
  2579. radius: custom.radius || helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
  2580. pointStyle: custom.pointStyle || helpers.getValueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
  2581. backgroundColor: me.getPointBackgroundColor(point, index),
  2582. borderColor: me.getPointBorderColor(point, index),
  2583. borderWidth: me.getPointBorderWidth(point, index),
  2584. tension: meta.dataset._model ? meta.dataset._model.tension : 0,
  2585. steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
  2586. // Tooltip
  2587. hitRadius: custom.hitRadius || helpers.getValueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
  2588. };
  2589. },
  2590. calculatePointY: function(value, index, datasetIndex) {
  2591. var me = this;
  2592. var chart = me.chart;
  2593. var meta = me.getMeta();
  2594. var yScale = me.getScaleForId(meta.yAxisID);
  2595. var sumPos = 0;
  2596. var sumNeg = 0;
  2597. var i, ds, dsMeta;
  2598. if (yScale.options.stacked) {
  2599. for (i = 0; i < datasetIndex; i++) {
  2600. ds = chart.data.datasets[i];
  2601. dsMeta = chart.getDatasetMeta(i);
  2602. if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  2603. var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
  2604. if (stackedRightValue < 0) {
  2605. sumNeg += stackedRightValue || 0;
  2606. } else {
  2607. sumPos += stackedRightValue || 0;
  2608. }
  2609. }
  2610. }
  2611. var rightValue = Number(yScale.getRightValue(value));
  2612. if (rightValue < 0) {
  2613. return yScale.getPixelForValue(sumNeg + rightValue);
  2614. } else {
  2615. return yScale.getPixelForValue(sumPos + rightValue);
  2616. }
  2617. }
  2618. return yScale.getPixelForValue(value);
  2619. },
  2620. updateBezierControlPoints: function() {
  2621. var me = this;
  2622. var meta = me.getMeta();
  2623. var area = me.chart.chartArea;
  2624. var points = (meta.data || []);
  2625. var i, ilen, point, model, controlPoints;
  2626. // Only consider points that are drawn in case the spanGaps option is used
  2627. if (meta.dataset._model.spanGaps) {
  2628. points = points.filter(function(pt) {
  2629. return !pt._model.skip;
  2630. });
  2631. }
  2632. function capControlPoint(pt, min, max) {
  2633. return Math.max(Math.min(pt, max), min);
  2634. }
  2635. if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
  2636. helpers.splineCurveMonotone(points);
  2637. } else {
  2638. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2639. point = points[i];
  2640. model = point._model;
  2641. controlPoints = helpers.splineCurve(
  2642. helpers.previousItem(points, i)._model,
  2643. model,
  2644. helpers.nextItem(points, i)._model,
  2645. meta.dataset._model.tension
  2646. );
  2647. model.controlPointPreviousX = controlPoints.previous.x;
  2648. model.controlPointPreviousY = controlPoints.previous.y;
  2649. model.controlPointNextX = controlPoints.next.x;
  2650. model.controlPointNextY = controlPoints.next.y;
  2651. }
  2652. }
  2653. if (me.chart.options.elements.line.capBezierPoints) {
  2654. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2655. model = points[i]._model;
  2656. model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
  2657. model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
  2658. model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
  2659. model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
  2660. }
  2661. }
  2662. },
  2663. draw: function(ease) {
  2664. var me = this;
  2665. var meta = me.getMeta();
  2666. var points = meta.data || [];
  2667. var easingDecimal = ease || 1;
  2668. var i, ilen;
  2669. // Transition Point Locations
  2670. for (i=0, ilen=points.length; i<ilen; ++i) {
  2671. points[i].transition(easingDecimal);
  2672. }
  2673. // Transition and Draw the line
  2674. if (lineEnabled(me.getDataset(), me.chart.options)) {
  2675. meta.dataset.transition(easingDecimal).draw();
  2676. }
  2677. // Draw the points
  2678. for (i=0, ilen=points.length; i<ilen; ++i) {
  2679. points[i].draw();
  2680. }
  2681. },
  2682. setHoverStyle: function(point) {
  2683. // Point
  2684. var dataset = this.chart.data.datasets[point._datasetIndex];
  2685. var index = point._index;
  2686. var custom = point.custom || {};
  2687. var model = point._model;
  2688. model.radius = custom.hoverRadius || helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  2689. model.backgroundColor = custom.hoverBackgroundColor || helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  2690. model.borderColor = custom.hoverBorderColor || helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  2691. model.borderWidth = custom.hoverBorderWidth || helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  2692. },
  2693. removeHoverStyle: function(point) {
  2694. var me = this;
  2695. var dataset = me.chart.data.datasets[point._datasetIndex];
  2696. var index = point._index;
  2697. var custom = point.custom || {};
  2698. var model = point._model;
  2699. // Compatibility: If the properties are defined with only the old name, use those values
  2700. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2701. dataset.pointRadius = dataset.radius;
  2702. }
  2703. model.radius = custom.radius || helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, me.chart.options.elements.point.radius);
  2704. model.backgroundColor = me.getPointBackgroundColor(point, index);
  2705. model.borderColor = me.getPointBorderColor(point, index);
  2706. model.borderWidth = me.getPointBorderWidth(point, index);
  2707. }
  2708. });
  2709. };
  2710. },{}],19:[function(require,module,exports){
  2711. "use strict";
  2712. module.exports = function(Chart) {
  2713. var helpers = Chart.helpers;
  2714. Chart.defaults.polarArea = {
  2715. scale: {
  2716. type: "radialLinear",
  2717. lineArc: true, // so that lines are circular
  2718. ticks: {
  2719. beginAtZero: true
  2720. }
  2721. },
  2722. //Boolean - Whether to animate the rotation of the chart
  2723. animation: {
  2724. animateRotate: true,
  2725. animateScale: true
  2726. },
  2727. startAngle: -0.5 * Math.PI,
  2728. aspectRatio: 1,
  2729. legendCallback: function(chart) {
  2730. var text = [];
  2731. text.push('<ul class="' + chart.id + '-legend">');
  2732. var data = chart.data;
  2733. var datasets = data.datasets;
  2734. var labels = data.labels;
  2735. if (datasets.length) {
  2736. for (var i = 0; i < datasets[0].data.length; ++i) {
  2737. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '">');
  2738. if (labels[i]) {
  2739. text.push(labels[i]);
  2740. }
  2741. text.push('</span></li>');
  2742. }
  2743. }
  2744. text.push('</ul>');
  2745. return text.join("");
  2746. },
  2747. legend: {
  2748. labels: {
  2749. generateLabels: function(chart) {
  2750. var data = chart.data;
  2751. if (data.labels.length && data.datasets.length) {
  2752. return data.labels.map(function(label, i) {
  2753. var meta = chart.getDatasetMeta(0);
  2754. var ds = data.datasets[0];
  2755. var arc = meta.data[i];
  2756. var custom = arc.custom || {};
  2757. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2758. var arcOpts = chart.options.elements.arc;
  2759. var fill = custom.backgroundColor ? custom.backgroundColor : getValueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2760. var stroke = custom.borderColor ? custom.borderColor : getValueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2761. var bw = custom.borderWidth ? custom.borderWidth : getValueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2762. return {
  2763. text: label,
  2764. fillStyle: fill,
  2765. strokeStyle: stroke,
  2766. lineWidth: bw,
  2767. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2768. // Extra data used for toggling the correct item
  2769. index: i
  2770. };
  2771. });
  2772. } else {
  2773. return [];
  2774. }
  2775. }
  2776. },
  2777. onClick: function(e, legendItem) {
  2778. var index = legendItem.index;
  2779. var chart = this.chart;
  2780. var i, ilen, meta;
  2781. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2782. meta = chart.getDatasetMeta(i);
  2783. meta.data[index].hidden = !meta.data[index].hidden;
  2784. }
  2785. chart.update();
  2786. }
  2787. },
  2788. // Need to override these to give a nice default
  2789. tooltips: {
  2790. callbacks: {
  2791. title: function() {
  2792. return '';
  2793. },
  2794. label: function(tooltipItem, data) {
  2795. return data.labels[tooltipItem.index] + ': ' + tooltipItem.yLabel;
  2796. }
  2797. }
  2798. }
  2799. };
  2800. Chart.controllers.polarArea = Chart.DatasetController.extend({
  2801. dataElementType: Chart.elements.Arc,
  2802. linkScales: helpers.noop,
  2803. update: function(reset) {
  2804. var me = this;
  2805. var chart = me.chart;
  2806. var chartArea = chart.chartArea;
  2807. var meta = me.getMeta();
  2808. var opts = chart.options;
  2809. var arcOpts = opts.elements.arc;
  2810. var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
  2811. chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
  2812. chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
  2813. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2814. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
  2815. me.innerRadius = me.outerRadius - chart.radiusLength;
  2816. meta.count = me.countVisibleElements();
  2817. helpers.each(meta.data, function(arc, index) {
  2818. me.updateElement(arc, index, reset);
  2819. });
  2820. },
  2821. updateElement: function(arc, index, reset) {
  2822. var me = this;
  2823. var chart = me.chart;
  2824. var dataset = me.getDataset();
  2825. var opts = chart.options;
  2826. var animationOpts = opts.animation;
  2827. var scale = chart.scale;
  2828. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2829. var labels = chart.data.labels;
  2830. var circumference = me.calculateCircumference(dataset.data[index]);
  2831. var centerX = scale.xCenter;
  2832. var centerY = scale.yCenter;
  2833. // If there is NaN data before us, we need to calculate the starting angle correctly.
  2834. // We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
  2835. var visibleCount = 0;
  2836. var meta = me.getMeta();
  2837. for (var i = 0; i < index; ++i) {
  2838. if (!isNaN(dataset.data[i]) && !meta.data[i].hidden) {
  2839. ++visibleCount;
  2840. }
  2841. }
  2842. //var negHalfPI = -0.5 * Math.PI;
  2843. var datasetStartAngle = opts.startAngle;
  2844. var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2845. var startAngle = datasetStartAngle + (circumference * visibleCount);
  2846. var endAngle = startAngle + (arc.hidden ? 0 : circumference);
  2847. var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2848. helpers.extend(arc, {
  2849. // Utility
  2850. _datasetIndex: me.index,
  2851. _index: index,
  2852. _scale: scale,
  2853. // Desired view properties
  2854. _model: {
  2855. x: centerX,
  2856. y: centerY,
  2857. innerRadius: 0,
  2858. outerRadius: reset ? resetRadius : distance,
  2859. startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
  2860. endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
  2861. label: getValueAtIndexOrDefault(labels, index, labels[index])
  2862. }
  2863. });
  2864. // Apply border and fill style
  2865. me.removeHoverStyle(arc);
  2866. arc.pivot();
  2867. },
  2868. removeHoverStyle: function(arc) {
  2869. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  2870. },
  2871. countVisibleElements: function() {
  2872. var dataset = this.getDataset();
  2873. var meta = this.getMeta();
  2874. var count = 0;
  2875. helpers.each(meta.data, function(element, index) {
  2876. if (!isNaN(dataset.data[index]) && !element.hidden) {
  2877. count++;
  2878. }
  2879. });
  2880. return count;
  2881. },
  2882. calculateCircumference: function(value) {
  2883. var count = this.getMeta().count;
  2884. if (count > 0 && !isNaN(value)) {
  2885. return (2 * Math.PI) / count;
  2886. } else {
  2887. return 0;
  2888. }
  2889. }
  2890. });
  2891. };
  2892. },{}],20:[function(require,module,exports){
  2893. "use strict";
  2894. module.exports = function(Chart) {
  2895. var helpers = Chart.helpers;
  2896. Chart.defaults.radar = {
  2897. scale: {
  2898. type: "radialLinear"
  2899. },
  2900. elements: {
  2901. line: {
  2902. tension: 0 // no bezier in radar
  2903. }
  2904. }
  2905. };
  2906. Chart.controllers.radar = Chart.DatasetController.extend({
  2907. datasetElementType: Chart.elements.Line,
  2908. dataElementType: Chart.elements.Point,
  2909. linkScales: helpers.noop,
  2910. addElementAndReset: function(index) {
  2911. Chart.DatasetController.prototype.addElementAndReset.call(this, index);
  2912. // Make sure bezier control points are updated
  2913. this.updateBezierControlPoints();
  2914. },
  2915. update: function(reset) {
  2916. var me = this;
  2917. var meta = me.getMeta();
  2918. var line = meta.dataset;
  2919. var points = meta.data;
  2920. var custom = line.custom || {};
  2921. var dataset = me.getDataset();
  2922. var lineElementOptions = me.chart.options.elements.line;
  2923. var scale = me.chart.scale;
  2924. // Compatibility: If the properties are defined with only the old name, use those values
  2925. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2926. dataset.lineTension = dataset.tension;
  2927. }
  2928. helpers.extend(meta.dataset, {
  2929. // Utility
  2930. _datasetIndex: me.index,
  2931. // Data
  2932. _children: points,
  2933. _loop: true,
  2934. // Model
  2935. _model: {
  2936. // Appearance
  2937. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2938. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2939. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2940. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2941. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2942. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2943. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2944. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2945. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2946. // Scale
  2947. scaleTop: scale.top,
  2948. scaleBottom: scale.bottom,
  2949. scaleZero: scale.getBasePosition()
  2950. }
  2951. });
  2952. meta.dataset.pivot();
  2953. // Update Points
  2954. helpers.each(points, function(point, index) {
  2955. me.updateElement(point, index, reset);
  2956. }, me);
  2957. // Update bezier control points
  2958. me.updateBezierControlPoints();
  2959. },
  2960. updateElement: function(point, index, reset) {
  2961. var me = this;
  2962. var custom = point.custom || {};
  2963. var dataset = me.getDataset();
  2964. var scale = me.chart.scale;
  2965. var pointElementOptions = me.chart.options.elements.point;
  2966. var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
  2967. helpers.extend(point, {
  2968. // Utility
  2969. _datasetIndex: me.index,
  2970. _index: index,
  2971. _scale: scale,
  2972. // Desired view properties
  2973. _model: {
  2974. x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  2975. y: reset ? scale.yCenter : pointPosition.y,
  2976. // Appearance
  2977. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.tension, me.chart.options.elements.line.tension),
  2978. radius: custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
  2979. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
  2980. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
  2981. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
  2982. pointStyle: custom.pointStyle ? custom.pointStyle : helpers.getValueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
  2983. // Tooltip
  2984. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.hitRadius, index, pointElementOptions.hitRadius)
  2985. }
  2986. });
  2987. point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  2988. },
  2989. updateBezierControlPoints: function() {
  2990. var chartArea = this.chart.chartArea;
  2991. var meta = this.getMeta();
  2992. helpers.each(meta.data, function(point, index) {
  2993. var model = point._model;
  2994. var controlPoints = helpers.splineCurve(
  2995. helpers.previousItem(meta.data, index, true)._model,
  2996. model,
  2997. helpers.nextItem(meta.data, index, true)._model,
  2998. model.tension
  2999. );
  3000. // Prevent the bezier going outside of the bounds of the graph
  3001. model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, chartArea.right), chartArea.left);
  3002. model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, chartArea.bottom), chartArea.top);
  3003. model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, chartArea.right), chartArea.left);
  3004. model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, chartArea.bottom), chartArea.top);
  3005. // Now pivot the point for animation
  3006. point.pivot();
  3007. });
  3008. },
  3009. draw: function(ease) {
  3010. var meta = this.getMeta();
  3011. var easingDecimal = ease || 1;
  3012. // Transition Point Locations
  3013. helpers.each(meta.data, function(point) {
  3014. point.transition(easingDecimal);
  3015. });
  3016. // Transition and Draw the line
  3017. meta.dataset.transition(easingDecimal).draw();
  3018. // Draw the points
  3019. helpers.each(meta.data, function(point) {
  3020. point.draw();
  3021. });
  3022. },
  3023. setHoverStyle: function(point) {
  3024. // Point
  3025. var dataset = this.chart.data.datasets[point._datasetIndex];
  3026. var custom = point.custom || {};
  3027. var index = point._index;
  3028. var model = point._model;
  3029. model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  3030. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  3031. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  3032. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  3033. },
  3034. removeHoverStyle: function(point) {
  3035. var dataset = this.chart.data.datasets[point._datasetIndex];
  3036. var custom = point.custom || {};
  3037. var index = point._index;
  3038. var model = point._model;
  3039. var pointElementOptions = this.chart.options.elements.point;
  3040. model.radius = custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.radius, index, pointElementOptions.radius);
  3041. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor);
  3042. model.borderColor = custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor);
  3043. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth);
  3044. }
  3045. });
  3046. };
  3047. },{}],21:[function(require,module,exports){
  3048. /*global window: false */
  3049. "use strict";
  3050. module.exports = function(Chart) {
  3051. var helpers = Chart.helpers;
  3052. Chart.defaults.global.animation = {
  3053. duration: 1000,
  3054. easing: "easeOutQuart",
  3055. onProgress: helpers.noop,
  3056. onComplete: helpers.noop
  3057. };
  3058. Chart.Animation = Chart.Element.extend({
  3059. currentStep: null, // the current animation step
  3060. numSteps: 60, // default number of steps
  3061. easing: "", // the easing to use for this animation
  3062. render: null, // render function used by the animation service
  3063. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  3064. onAnimationComplete: null // user specified callback to fire when the animation finishes
  3065. });
  3066. Chart.animationService = {
  3067. frameDuration: 17,
  3068. animations: [],
  3069. dropFrames: 0,
  3070. request: null,
  3071. addAnimation: function(chartInstance, animationObject, duration, lazy) {
  3072. var me = this;
  3073. if (!lazy) {
  3074. chartInstance.animating = true;
  3075. }
  3076. for (var index = 0; index < me.animations.length; ++index) {
  3077. if (me.animations[index].chartInstance === chartInstance) {
  3078. // replacing an in progress animation
  3079. me.animations[index].animationObject = animationObject;
  3080. return;
  3081. }
  3082. }
  3083. me.animations.push({
  3084. chartInstance: chartInstance,
  3085. animationObject: animationObject
  3086. });
  3087. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  3088. if (me.animations.length === 1) {
  3089. me.requestAnimationFrame();
  3090. }
  3091. },
  3092. // Cancel the animation for a given chart instance
  3093. cancelAnimation: function(chartInstance) {
  3094. var index = helpers.findIndex(this.animations, function(animationWrapper) {
  3095. return animationWrapper.chartInstance === chartInstance;
  3096. });
  3097. if (index !== -1) {
  3098. this.animations.splice(index, 1);
  3099. chartInstance.animating = false;
  3100. }
  3101. },
  3102. requestAnimationFrame: function() {
  3103. var me = this;
  3104. if (me.request === null) {
  3105. // Skip animation frame requests until the active one is executed.
  3106. // This can happen when processing mouse events, e.g. 'mousemove'
  3107. // and 'mouseout' events will trigger multiple renders.
  3108. me.request = helpers.requestAnimFrame.call(window, function() {
  3109. me.request = null;
  3110. me.startDigest();
  3111. });
  3112. }
  3113. },
  3114. startDigest: function() {
  3115. var me = this;
  3116. var startTime = Date.now();
  3117. var framesToDrop = 0;
  3118. if (me.dropFrames > 1) {
  3119. framesToDrop = Math.floor(me.dropFrames);
  3120. me.dropFrames = me.dropFrames % 1;
  3121. }
  3122. var i = 0;
  3123. while (i < me.animations.length) {
  3124. if (me.animations[i].animationObject.currentStep === null) {
  3125. me.animations[i].animationObject.currentStep = 0;
  3126. }
  3127. me.animations[i].animationObject.currentStep += 1 + framesToDrop;
  3128. if (me.animations[i].animationObject.currentStep > me.animations[i].animationObject.numSteps) {
  3129. me.animations[i].animationObject.currentStep = me.animations[i].animationObject.numSteps;
  3130. }
  3131. me.animations[i].animationObject.render(me.animations[i].chartInstance, me.animations[i].animationObject);
  3132. if (me.animations[i].animationObject.onAnimationProgress && me.animations[i].animationObject.onAnimationProgress.call) {
  3133. me.animations[i].animationObject.onAnimationProgress.call(me.animations[i].chartInstance, me.animations[i]);
  3134. }
  3135. if (me.animations[i].animationObject.currentStep === me.animations[i].animationObject.numSteps) {
  3136. if (me.animations[i].animationObject.onAnimationComplete && me.animations[i].animationObject.onAnimationComplete.call) {
  3137. me.animations[i].animationObject.onAnimationComplete.call(me.animations[i].chartInstance, me.animations[i]);
  3138. }
  3139. // executed the last frame. Remove the animation.
  3140. me.animations[i].chartInstance.animating = false;
  3141. me.animations.splice(i, 1);
  3142. } else {
  3143. ++i;
  3144. }
  3145. }
  3146. var endTime = Date.now();
  3147. var dropFrames = (endTime - startTime) / me.frameDuration;
  3148. me.dropFrames += dropFrames;
  3149. // Do we have more stuff to animate?
  3150. if (me.animations.length > 0) {
  3151. me.requestAnimationFrame();
  3152. }
  3153. }
  3154. };
  3155. };
  3156. },{}],22:[function(require,module,exports){
  3157. "use strict";
  3158. module.exports = function(Chart) {
  3159. // Global Chart canvas helpers object for drawing items to canvas
  3160. var helpers = Chart.canvasHelpers = {};
  3161. helpers.drawPoint = function(ctx, pointStyle, radius, x, y) {
  3162. var type, edgeLength, xOffset, yOffset, height, size;
  3163. if (typeof pointStyle === 'object') {
  3164. type = pointStyle.toString();
  3165. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  3166. ctx.drawImage(pointStyle, x - pointStyle.width / 2, y - pointStyle.height / 2);
  3167. return;
  3168. }
  3169. }
  3170. if (isNaN(radius) || radius <= 0) {
  3171. return;
  3172. }
  3173. switch (pointStyle) {
  3174. // Default includes circle
  3175. default:
  3176. ctx.beginPath();
  3177. ctx.arc(x, y, radius, 0, Math.PI * 2);
  3178. ctx.closePath();
  3179. ctx.fill();
  3180. break;
  3181. case 'triangle':
  3182. ctx.beginPath();
  3183. edgeLength = 3 * radius / Math.sqrt(3);
  3184. height = edgeLength * Math.sqrt(3) / 2;
  3185. ctx.moveTo(x - edgeLength / 2, y + height / 3);
  3186. ctx.lineTo(x + edgeLength / 2, y + height / 3);
  3187. ctx.lineTo(x, y - 2 * height / 3);
  3188. ctx.closePath();
  3189. ctx.fill();
  3190. break;
  3191. case 'rect':
  3192. size = 1 / Math.SQRT2 * radius;
  3193. ctx.beginPath();
  3194. ctx.fillRect(x - size, y - size, 2 * size, 2 * size);
  3195. ctx.strokeRect(x - size, y - size, 2 * size, 2 * size);
  3196. break;
  3197. case 'rectRot':
  3198. size = 1 / Math.SQRT2 * radius;
  3199. ctx.beginPath();
  3200. ctx.moveTo(x - size, y);
  3201. ctx.lineTo(x, y + size);
  3202. ctx.lineTo(x + size, y);
  3203. ctx.lineTo(x, y - size);
  3204. ctx.closePath();
  3205. ctx.fill();
  3206. break;
  3207. case 'cross':
  3208. ctx.beginPath();
  3209. ctx.moveTo(x, y + radius);
  3210. ctx.lineTo(x, y - radius);
  3211. ctx.moveTo(x - radius, y);
  3212. ctx.lineTo(x + radius, y);
  3213. ctx.closePath();
  3214. break;
  3215. case 'crossRot':
  3216. ctx.beginPath();
  3217. xOffset = Math.cos(Math.PI / 4) * radius;
  3218. yOffset = Math.sin(Math.PI / 4) * radius;
  3219. ctx.moveTo(x - xOffset, y - yOffset);
  3220. ctx.lineTo(x + xOffset, y + yOffset);
  3221. ctx.moveTo(x - xOffset, y + yOffset);
  3222. ctx.lineTo(x + xOffset, y - yOffset);
  3223. ctx.closePath();
  3224. break;
  3225. case 'star':
  3226. ctx.beginPath();
  3227. ctx.moveTo(x, y + radius);
  3228. ctx.lineTo(x, y - radius);
  3229. ctx.moveTo(x - radius, y);
  3230. ctx.lineTo(x + radius, y);
  3231. xOffset = Math.cos(Math.PI / 4) * radius;
  3232. yOffset = Math.sin(Math.PI / 4) * radius;
  3233. ctx.moveTo(x - xOffset, y - yOffset);
  3234. ctx.lineTo(x + xOffset, y + yOffset);
  3235. ctx.moveTo(x - xOffset, y + yOffset);
  3236. ctx.lineTo(x + xOffset, y - yOffset);
  3237. ctx.closePath();
  3238. break;
  3239. case 'line':
  3240. ctx.beginPath();
  3241. ctx.moveTo(x - radius, y);
  3242. ctx.lineTo(x + radius, y);
  3243. ctx.closePath();
  3244. break;
  3245. case 'dash':
  3246. ctx.beginPath();
  3247. ctx.moveTo(x, y);
  3248. ctx.lineTo(x + radius, y);
  3249. ctx.closePath();
  3250. break;
  3251. }
  3252. ctx.stroke();
  3253. };
  3254. };
  3255. },{}],23:[function(require,module,exports){
  3256. "use strict";
  3257. module.exports = function(Chart) {
  3258. var helpers = Chart.helpers;
  3259. //Create a dictionary of chart types, to allow for extension of existing types
  3260. Chart.types = {};
  3261. //Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  3262. //Destroy method on the chart will remove the instance of the chart from this reference.
  3263. Chart.instances = {};
  3264. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  3265. Chart.controllers = {};
  3266. /**
  3267. * @class Chart.Controller
  3268. * The main controller of a chart.
  3269. */
  3270. Chart.Controller = function(instance) {
  3271. this.chart = instance;
  3272. this.config = instance.config;
  3273. this.options = this.config.options = helpers.configMerge(Chart.defaults.global, Chart.defaults[this.config.type], this.config.options || {});
  3274. this.id = helpers.uid();
  3275. Object.defineProperty(this, 'data', {
  3276. get: function() {
  3277. return this.config.data;
  3278. }
  3279. });
  3280. //Add the chart instance to the global namespace
  3281. Chart.instances[this.id] = this;
  3282. if (this.options.responsive) {
  3283. // Silent resize before chart draws
  3284. this.resize(true);
  3285. }
  3286. this.initialize();
  3287. return this;
  3288. };
  3289. helpers.extend(Chart.Controller.prototype, /** @lends Chart.Controller */ {
  3290. initialize: function() {
  3291. var me = this;
  3292. // Before init plugin notification
  3293. Chart.plugins.notify('beforeInit', [me]);
  3294. me.bindEvents();
  3295. // Make sure controllers are built first so that each dataset is bound to an axis before the scales
  3296. // are built
  3297. me.ensureScalesHaveIDs();
  3298. me.buildOrUpdateControllers();
  3299. me.buildScales();
  3300. me.updateLayout();
  3301. me.resetElements();
  3302. me.initToolTip();
  3303. me.update();
  3304. // After init plugin notification
  3305. Chart.plugins.notify('afterInit', [me]);
  3306. return me;
  3307. },
  3308. clear: function() {
  3309. helpers.clear(this.chart);
  3310. return this;
  3311. },
  3312. stop: function() {
  3313. // Stops any current animation loop occuring
  3314. Chart.animationService.cancelAnimation(this);
  3315. return this;
  3316. },
  3317. resize: function resize(silent) {
  3318. var me = this;
  3319. var chart = me.chart;
  3320. var canvas = chart.canvas;
  3321. var newWidth = helpers.getMaximumWidth(canvas);
  3322. var aspectRatio = chart.aspectRatio;
  3323. var newHeight = (me.options.maintainAspectRatio && isNaN(aspectRatio) === false && isFinite(aspectRatio) && aspectRatio !== 0) ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas);
  3324. var sizeChanged = chart.width !== newWidth || chart.height !== newHeight;
  3325. if (!sizeChanged) {
  3326. return me;
  3327. }
  3328. canvas.width = chart.width = newWidth;
  3329. canvas.height = chart.height = newHeight;
  3330. helpers.retinaScale(chart);
  3331. // Notify any plugins about the resize
  3332. var newSize = { width: newWidth, height: newHeight };
  3333. Chart.plugins.notify('resize', [me, newSize]);
  3334. // Notify of resize
  3335. if (me.options.onResize) {
  3336. me.options.onResize(me, newSize);
  3337. }
  3338. if (!silent) {
  3339. me.stop();
  3340. me.update(me.options.responsiveAnimationDuration);
  3341. }
  3342. return me;
  3343. },
  3344. ensureScalesHaveIDs: function() {
  3345. var options = this.options;
  3346. var scalesOptions = options.scales || {};
  3347. var scaleOptions = options.scale;
  3348. helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
  3349. xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
  3350. });
  3351. helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
  3352. yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
  3353. });
  3354. if (scaleOptions) {
  3355. scaleOptions.id = scaleOptions.id || 'scale';
  3356. }
  3357. },
  3358. /**
  3359. * Builds a map of scale ID to scale object for future lookup.
  3360. */
  3361. buildScales: function() {
  3362. var me = this;
  3363. var options = me.options;
  3364. var scales = me.scales = {};
  3365. var items = [];
  3366. if (options.scales) {
  3367. items = items.concat(
  3368. (options.scales.xAxes || []).map(function(xAxisOptions) {
  3369. return { options: xAxisOptions, dtype: 'category' }; }),
  3370. (options.scales.yAxes || []).map(function(yAxisOptions) {
  3371. return { options: yAxisOptions, dtype: 'linear' }; }));
  3372. }
  3373. if (options.scale) {
  3374. items.push({ options: options.scale, dtype: 'radialLinear', isDefault: true });
  3375. }
  3376. helpers.each(items, function(item) {
  3377. var scaleOptions = item.options;
  3378. var scaleType = helpers.getValueOrDefault(scaleOptions.type, item.dtype);
  3379. var scaleClass = Chart.scaleService.getScaleConstructor(scaleType);
  3380. if (!scaleClass) {
  3381. return;
  3382. }
  3383. var scale = new scaleClass({
  3384. id: scaleOptions.id,
  3385. options: scaleOptions,
  3386. ctx: me.chart.ctx,
  3387. chart: me
  3388. });
  3389. scales[scale.id] = scale;
  3390. // TODO(SB): I think we should be able to remove this custom case (options.scale)
  3391. // and consider it as a regular scale part of the "scales"" map only! This would
  3392. // make the logic easier and remove some useless? custom code.
  3393. if (item.isDefault) {
  3394. me.scale = scale;
  3395. }
  3396. });
  3397. Chart.scaleService.addScalesToLayout(this);
  3398. },
  3399. updateLayout: function() {
  3400. Chart.layoutService.update(this, this.chart.width, this.chart.height);
  3401. },
  3402. buildOrUpdateControllers: function() {
  3403. var me = this;
  3404. var types = [];
  3405. var newControllers = [];
  3406. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3407. var meta = me.getDatasetMeta(datasetIndex);
  3408. if (!meta.type) {
  3409. meta.type = dataset.type || me.config.type;
  3410. }
  3411. types.push(meta.type);
  3412. if (meta.controller) {
  3413. meta.controller.updateIndex(datasetIndex);
  3414. } else {
  3415. meta.controller = new Chart.controllers[meta.type](me, datasetIndex);
  3416. newControllers.push(meta.controller);
  3417. }
  3418. }, me);
  3419. if (types.length > 1) {
  3420. for (var i = 1; i < types.length; i++) {
  3421. if (types[i] !== types[i - 1]) {
  3422. me.isCombo = true;
  3423. break;
  3424. }
  3425. }
  3426. }
  3427. return newControllers;
  3428. },
  3429. resetElements: function() {
  3430. var me = this;
  3431. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3432. me.getDatasetMeta(datasetIndex).controller.reset();
  3433. }, me);
  3434. },
  3435. update: function update(animationDuration, lazy) {
  3436. var me = this;
  3437. Chart.plugins.notify('beforeUpdate', [me]);
  3438. // In case the entire data object changed
  3439. me.tooltip._data = me.data;
  3440. // Make sure dataset controllers are updated and new controllers are reset
  3441. var newControllers = me.buildOrUpdateControllers();
  3442. // Make sure all dataset controllers have correct meta data counts
  3443. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3444. me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
  3445. }, me);
  3446. Chart.layoutService.update(me, me.chart.width, me.chart.height);
  3447. // Apply changes to the dataets that require the scales to have been calculated i.e BorderColor chages
  3448. Chart.plugins.notify('afterScaleUpdate', [me]);
  3449. // Can only reset the new controllers after the scales have been updated
  3450. helpers.each(newControllers, function(controller) {
  3451. controller.reset();
  3452. });
  3453. me.updateDatasets();
  3454. // Do this before render so that any plugins that need final scale updates can use it
  3455. Chart.plugins.notify('afterUpdate', [me]);
  3456. me.render(animationDuration, lazy);
  3457. },
  3458. /**
  3459. * @method beforeDatasetsUpdate
  3460. * @description Called before all datasets are updated. If a plugin returns false,
  3461. * the datasets update will be cancelled until another chart update is triggered.
  3462. * @param {Object} instance the chart instance being updated.
  3463. * @returns {Boolean} false to cancel the datasets update.
  3464. * @memberof Chart.PluginBase
  3465. * @since version 2.1.5
  3466. * @instance
  3467. */
  3468. /**
  3469. * @method afterDatasetsUpdate
  3470. * @description Called after all datasets have been updated. Note that this
  3471. * extension will not be called if the datasets update has been cancelled.
  3472. * @param {Object} instance the chart instance being updated.
  3473. * @memberof Chart.PluginBase
  3474. * @since version 2.1.5
  3475. * @instance
  3476. */
  3477. /**
  3478. * Updates all datasets unless a plugin returns false to the beforeDatasetsUpdate
  3479. * extension, in which case no datasets will be updated and the afterDatasetsUpdate
  3480. * notification will be skipped.
  3481. * @protected
  3482. * @instance
  3483. */
  3484. updateDatasets: function() {
  3485. var me = this;
  3486. var i, ilen;
  3487. if (Chart.plugins.notify('beforeDatasetsUpdate', [ me ])) {
  3488. for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3489. me.getDatasetMeta(i).controller.update();
  3490. }
  3491. Chart.plugins.notify('afterDatasetsUpdate', [ me ]);
  3492. }
  3493. },
  3494. render: function render(duration, lazy) {
  3495. var me = this;
  3496. Chart.plugins.notify('beforeRender', [me]);
  3497. var animationOptions = me.options.animation;
  3498. if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
  3499. var animation = new Chart.Animation();
  3500. animation.numSteps = (duration || animationOptions.duration) / 16.66; //60 fps
  3501. animation.easing = animationOptions.easing;
  3502. // render function
  3503. animation.render = function(chartInstance, animationObject) {
  3504. var easingFunction = helpers.easingEffects[animationObject.easing];
  3505. var stepDecimal = animationObject.currentStep / animationObject.numSteps;
  3506. var easeDecimal = easingFunction(stepDecimal);
  3507. chartInstance.draw(easeDecimal, stepDecimal, animationObject.currentStep);
  3508. };
  3509. // user events
  3510. animation.onAnimationProgress = animationOptions.onProgress;
  3511. animation.onAnimationComplete = animationOptions.onComplete;
  3512. Chart.animationService.addAnimation(me, animation, duration, lazy);
  3513. } else {
  3514. me.draw();
  3515. if (animationOptions && animationOptions.onComplete && animationOptions.onComplete.call) {
  3516. animationOptions.onComplete.call(me);
  3517. }
  3518. }
  3519. return me;
  3520. },
  3521. draw: function(ease) {
  3522. var me = this;
  3523. var easingDecimal = ease || 1;
  3524. me.clear();
  3525. Chart.plugins.notify('beforeDraw', [me, easingDecimal]);
  3526. // Draw all the scales
  3527. helpers.each(me.boxes, function(box) {
  3528. box.draw(me.chartArea);
  3529. }, me);
  3530. if (me.scale) {
  3531. me.scale.draw();
  3532. }
  3533. Chart.plugins.notify('beforeDatasetsDraw', [me, easingDecimal]);
  3534. // Draw each dataset via its respective controller (reversed to support proper line stacking)
  3535. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3536. if (me.isDatasetVisible(datasetIndex)) {
  3537. me.getDatasetMeta(datasetIndex).controller.draw(ease);
  3538. }
  3539. }, me, true);
  3540. Chart.plugins.notify('afterDatasetsDraw', [me, easingDecimal]);
  3541. // Finally draw the tooltip
  3542. me.tooltip.transition(easingDecimal).draw();
  3543. Chart.plugins.notify('afterDraw', [me, easingDecimal]);
  3544. },
  3545. // Get the single element that was clicked on
  3546. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  3547. getElementAtEvent: function(e) {
  3548. var me = this;
  3549. var eventPosition = helpers.getRelativePosition(e, me.chart);
  3550. var elementsArray = [];
  3551. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3552. if (me.isDatasetVisible(datasetIndex)) {
  3553. var meta = me.getDatasetMeta(datasetIndex);
  3554. helpers.each(meta.data, function(element) {
  3555. if (element.inRange(eventPosition.x, eventPosition.y)) {
  3556. elementsArray.push(element);
  3557. return elementsArray;
  3558. }
  3559. });
  3560. }
  3561. });
  3562. return elementsArray.slice(0, 1);
  3563. },
  3564. getElementsAtEvent: function(e) {
  3565. var me = this;
  3566. var eventPosition = helpers.getRelativePosition(e, me.chart);
  3567. var elementsArray = [];
  3568. var found = (function() {
  3569. if (me.data.datasets) {
  3570. for (var i = 0; i < me.data.datasets.length; i++) {
  3571. var meta = me.getDatasetMeta(i);
  3572. if (me.isDatasetVisible(i)) {
  3573. for (var j = 0; j < meta.data.length; j++) {
  3574. if (meta.data[j].inRange(eventPosition.x, eventPosition.y)) {
  3575. return meta.data[j];
  3576. }
  3577. }
  3578. }
  3579. }
  3580. }
  3581. }).call(me);
  3582. if (!found) {
  3583. return elementsArray;
  3584. }
  3585. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3586. if (me.isDatasetVisible(datasetIndex)) {
  3587. var meta = me.getDatasetMeta(datasetIndex),
  3588. element = meta.data[found._index];
  3589. if(element && !element._view.skip){
  3590. elementsArray.push(element);
  3591. }
  3592. }
  3593. }, me);
  3594. return elementsArray;
  3595. },
  3596. getElementsAtXAxis: function(e) {
  3597. var me = this;
  3598. var eventPosition = helpers.getRelativePosition(e, me.chart);
  3599. var elementsArray = [];
  3600. var found = (function() {
  3601. if (me.data.datasets) {
  3602. for (var i = 0; i < me.data.datasets.length; i++) {
  3603. var meta = me.getDatasetMeta(i);
  3604. if (me.isDatasetVisible(i)) {
  3605. for (var j = 0; j < meta.data.length; j++) {
  3606. if (meta.data[j].inLabelRange(eventPosition.x, eventPosition.y)) {
  3607. return meta.data[j];
  3608. }
  3609. }
  3610. }
  3611. }
  3612. }
  3613. }).call(me);
  3614. if (!found) {
  3615. return elementsArray;
  3616. }
  3617. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3618. if (me.isDatasetVisible(datasetIndex)) {
  3619. var meta = me.getDatasetMeta(datasetIndex);
  3620. var index = helpers.findIndex(meta.data, function (it) {
  3621. return found._model.x === it._model.x;
  3622. });
  3623. if(index !== -1 && !meta.data[index]._view.skip) {
  3624. elementsArray.push(meta.data[index]);
  3625. }
  3626. }
  3627. }, me);
  3628. return elementsArray;
  3629. },
  3630. getElementsAtEventForMode: function(e, mode) {
  3631. var me = this;
  3632. switch (mode) {
  3633. case 'single':
  3634. return me.getElementAtEvent(e);
  3635. case 'label':
  3636. return me.getElementsAtEvent(e);
  3637. case 'dataset':
  3638. return me.getDatasetAtEvent(e);
  3639. case 'x-axis':
  3640. return me.getElementsAtXAxis(e);
  3641. default:
  3642. return e;
  3643. }
  3644. },
  3645. getDatasetAtEvent: function(e) {
  3646. var elementsArray = this.getElementAtEvent(e);
  3647. if (elementsArray.length > 0) {
  3648. elementsArray = this.getDatasetMeta(elementsArray[0]._datasetIndex).data;
  3649. }
  3650. return elementsArray;
  3651. },
  3652. getDatasetMeta: function(datasetIndex) {
  3653. var me = this;
  3654. var dataset = me.data.datasets[datasetIndex];
  3655. if (!dataset._meta) {
  3656. dataset._meta = {};
  3657. }
  3658. var meta = dataset._meta[me.id];
  3659. if (!meta) {
  3660. meta = dataset._meta[me.id] = {
  3661. type: null,
  3662. data: [],
  3663. dataset: null,
  3664. controller: null,
  3665. hidden: null, // See isDatasetVisible() comment
  3666. xAxisID: null,
  3667. yAxisID: null
  3668. };
  3669. }
  3670. return meta;
  3671. },
  3672. getVisibleDatasetCount: function() {
  3673. var count = 0;
  3674. for (var i = 0, ilen = this.data.datasets.length; i<ilen; ++i) {
  3675. if (this.isDatasetVisible(i)) {
  3676. count++;
  3677. }
  3678. }
  3679. return count;
  3680. },
  3681. isDatasetVisible: function(datasetIndex) {
  3682. var meta = this.getDatasetMeta(datasetIndex);
  3683. // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
  3684. // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
  3685. return typeof meta.hidden === 'boolean'? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
  3686. },
  3687. generateLegend: function() {
  3688. return this.options.legendCallback(this);
  3689. },
  3690. destroy: function() {
  3691. var me = this;
  3692. me.stop();
  3693. me.clear();
  3694. helpers.unbindEvents(me, me.events);
  3695. helpers.removeResizeListener(me.chart.canvas.parentNode);
  3696. // Reset canvas height/width attributes
  3697. var canvas = me.chart.canvas;
  3698. canvas.width = me.chart.width;
  3699. canvas.height = me.chart.height;
  3700. // if we scaled the canvas in response to a devicePixelRatio !== 1, we need to undo that transform here
  3701. if (me.chart.originalDevicePixelRatio !== undefined) {
  3702. me.chart.ctx.scale(1 / me.chart.originalDevicePixelRatio, 1 / me.chart.originalDevicePixelRatio);
  3703. }
  3704. // Reset to the old style since it may have been changed by the device pixel ratio changes
  3705. canvas.style.width = me.chart.originalCanvasStyleWidth;
  3706. canvas.style.height = me.chart.originalCanvasStyleHeight;
  3707. Chart.plugins.notify('destroy', [me]);
  3708. delete Chart.instances[me.id];
  3709. },
  3710. toBase64Image: function() {
  3711. return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments);
  3712. },
  3713. initToolTip: function() {
  3714. var me = this;
  3715. me.tooltip = new Chart.Tooltip({
  3716. _chart: me.chart,
  3717. _chartInstance: me,
  3718. _data: me.data,
  3719. _options: me.options.tooltips
  3720. }, me);
  3721. },
  3722. bindEvents: function() {
  3723. var me = this;
  3724. helpers.bindEvents(me, me.options.events, function(evt) {
  3725. me.eventHandler(evt);
  3726. });
  3727. },
  3728. updateHoverStyle: function(elements, mode, enabled) {
  3729. var method = enabled? 'setHoverStyle' : 'removeHoverStyle';
  3730. var element, i, ilen;
  3731. switch (mode) {
  3732. case 'single':
  3733. elements = [ elements[0] ];
  3734. break;
  3735. case 'label':
  3736. case 'dataset':
  3737. case 'x-axis':
  3738. // elements = elements;
  3739. break;
  3740. default:
  3741. // unsupported mode
  3742. return;
  3743. }
  3744. for (i=0, ilen=elements.length; i<ilen; ++i) {
  3745. element = elements[i];
  3746. if (element) {
  3747. this.getDatasetMeta(element._datasetIndex).controller[method](element);
  3748. }
  3749. }
  3750. },
  3751. eventHandler: function eventHandler(e) {
  3752. var me = this;
  3753. var tooltip = me.tooltip;
  3754. var options = me.options || {};
  3755. var hoverOptions = options.hover;
  3756. var tooltipsOptions = options.tooltips;
  3757. me.lastActive = me.lastActive || [];
  3758. me.lastTooltipActive = me.lastTooltipActive || [];
  3759. // Find Active Elements for hover and tooltips
  3760. if (e.type === 'mouseout') {
  3761. me.active = [];
  3762. me.tooltipActive = [];
  3763. } else {
  3764. me.active = me.getElementsAtEventForMode(e, hoverOptions.mode);
  3765. me.tooltipActive = me.getElementsAtEventForMode(e, tooltipsOptions.mode);
  3766. }
  3767. // On Hover hook
  3768. if (hoverOptions.onHover) {
  3769. hoverOptions.onHover.call(me, me.active);
  3770. }
  3771. if (me.legend && me.legend.handleEvent) {
  3772. me.legend.handleEvent(e);
  3773. }
  3774. if (e.type === 'mouseup' || e.type === 'click') {
  3775. if (options.onClick) {
  3776. options.onClick.call(me, e, me.active);
  3777. }
  3778. }
  3779. // Remove styling for last active (even if it may still be active)
  3780. if (me.lastActive.length) {
  3781. me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
  3782. }
  3783. // Built in hover styling
  3784. if (me.active.length && hoverOptions.mode) {
  3785. me.updateHoverStyle(me.active, hoverOptions.mode, true);
  3786. }
  3787. // Built in Tooltips
  3788. if (tooltipsOptions.enabled || tooltipsOptions.custom) {
  3789. tooltip.initialize();
  3790. tooltip._active = me.tooltipActive;
  3791. tooltip.update(true);
  3792. }
  3793. // Hover animations
  3794. tooltip.pivot();
  3795. if (!me.animating) {
  3796. // If entering, leaving, or changing elements, animate the change via pivot
  3797. if (!helpers.arrayEquals(me.active, me.lastActive) ||
  3798. !helpers.arrayEquals(me.tooltipActive, me.lastTooltipActive)) {
  3799. me.stop();
  3800. if (tooltipsOptions.enabled || tooltipsOptions.custom) {
  3801. tooltip.update(true);
  3802. }
  3803. // We only need to render at this point. Updating will cause scales to be
  3804. // recomputed generating flicker & using more memory than necessary.
  3805. me.render(hoverOptions.animationDuration, true);
  3806. }
  3807. }
  3808. // Remember Last Actives
  3809. me.lastActive = me.active;
  3810. me.lastTooltipActive = me.tooltipActive;
  3811. return me;
  3812. }
  3813. });
  3814. };
  3815. },{}],24:[function(require,module,exports){
  3816. "use strict";
  3817. module.exports = function(Chart) {
  3818. var helpers = Chart.helpers;
  3819. var noop = helpers.noop;
  3820. // Base class for all dataset controllers (line, bar, etc)
  3821. Chart.DatasetController = function(chart, datasetIndex) {
  3822. this.initialize(chart, datasetIndex);
  3823. };
  3824. helpers.extend(Chart.DatasetController.prototype, {
  3825. /**
  3826. * Element type used to generate a meta dataset (e.g. Chart.element.Line).
  3827. * @type {Chart.core.element}
  3828. */
  3829. datasetElementType: null,
  3830. /**
  3831. * Element type used to generate a meta data (e.g. Chart.element.Point).
  3832. * @type {Chart.core.element}
  3833. */
  3834. dataElementType: null,
  3835. initialize: function(chart, datasetIndex) {
  3836. var me = this;
  3837. me.chart = chart;
  3838. me.index = datasetIndex;
  3839. me.linkScales();
  3840. me.addElements();
  3841. },
  3842. updateIndex: function(datasetIndex) {
  3843. this.index = datasetIndex;
  3844. },
  3845. linkScales: function() {
  3846. var me = this;
  3847. var meta = me.getMeta();
  3848. var dataset = me.getDataset();
  3849. if (meta.xAxisID === null) {
  3850. meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
  3851. }
  3852. if (meta.yAxisID === null) {
  3853. meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
  3854. }
  3855. },
  3856. getDataset: function() {
  3857. return this.chart.data.datasets[this.index];
  3858. },
  3859. getMeta: function() {
  3860. return this.chart.getDatasetMeta(this.index);
  3861. },
  3862. getScaleForId: function(scaleID) {
  3863. return this.chart.scales[scaleID];
  3864. },
  3865. reset: function() {
  3866. this.update(true);
  3867. },
  3868. createMetaDataset: function() {
  3869. var me = this;
  3870. var type = me.datasetElementType;
  3871. return type && new type({
  3872. _chart: me.chart.chart,
  3873. _datasetIndex: me.index
  3874. });
  3875. },
  3876. createMetaData: function(index) {
  3877. var me = this;
  3878. var type = me.dataElementType;
  3879. return type && new type({
  3880. _chart: me.chart.chart,
  3881. _datasetIndex: me.index,
  3882. _index: index
  3883. });
  3884. },
  3885. addElements: function() {
  3886. var me = this;
  3887. var meta = me.getMeta();
  3888. var data = me.getDataset().data || [];
  3889. var metaData = meta.data;
  3890. var i, ilen;
  3891. for (i=0, ilen=data.length; i<ilen; ++i) {
  3892. metaData[i] = metaData[i] || me.createMetaData(meta, i);
  3893. }
  3894. meta.dataset = meta.dataset || me.createMetaDataset();
  3895. },
  3896. addElementAndReset: function(index) {
  3897. var me = this;
  3898. var element = me.createMetaData(index);
  3899. me.getMeta().data.splice(index, 0, element);
  3900. me.updateElement(element, index, true);
  3901. },
  3902. buildOrUpdateElements: function() {
  3903. // Handle the number of data points changing
  3904. var meta = this.getMeta(),
  3905. md = meta.data,
  3906. numData = this.getDataset().data.length,
  3907. numMetaData = md.length;
  3908. // Make sure that we handle number of datapoints changing
  3909. if (numData < numMetaData) {
  3910. // Remove excess bars for data points that have been removed
  3911. md.splice(numData, numMetaData - numData);
  3912. } else if (numData > numMetaData) {
  3913. // Add new elements
  3914. for (var index = numMetaData; index < numData; ++index) {
  3915. this.addElementAndReset(index);
  3916. }
  3917. }
  3918. },
  3919. update: noop,
  3920. draw: function(ease) {
  3921. var easingDecimal = ease || 1;
  3922. helpers.each(this.getMeta().data, function(element) {
  3923. element.transition(easingDecimal).draw();
  3924. });
  3925. },
  3926. removeHoverStyle: function(element, elementOpts) {
  3927. var dataset = this.chart.data.datasets[element._datasetIndex],
  3928. index = element._index,
  3929. custom = element.custom || {},
  3930. valueOrDefault = helpers.getValueAtIndexOrDefault,
  3931. model = element._model;
  3932. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  3933. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  3934. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  3935. },
  3936. setHoverStyle: function(element) {
  3937. var dataset = this.chart.data.datasets[element._datasetIndex],
  3938. index = element._index,
  3939. custom = element.custom || {},
  3940. valueOrDefault = helpers.getValueAtIndexOrDefault,
  3941. getHoverColor = helpers.getHoverColor,
  3942. model = element._model;
  3943. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
  3944. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
  3945. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  3946. }
  3947. });
  3948. Chart.DatasetController.extend = helpers.inherits;
  3949. };
  3950. },{}],25:[function(require,module,exports){
  3951. "use strict";
  3952. module.exports = function(Chart) {
  3953. var helpers = Chart.helpers;
  3954. Chart.elements = {};
  3955. Chart.Element = function(configuration) {
  3956. helpers.extend(this, configuration);
  3957. this.initialize.apply(this, arguments);
  3958. };
  3959. helpers.extend(Chart.Element.prototype, {
  3960. initialize: function() {
  3961. this.hidden = false;
  3962. },
  3963. pivot: function() {
  3964. var me = this;
  3965. if (!me._view) {
  3966. me._view = helpers.clone(me._model);
  3967. }
  3968. me._start = helpers.clone(me._view);
  3969. return me;
  3970. },
  3971. transition: function(ease) {
  3972. var me = this;
  3973. if (!me._view) {
  3974. me._view = helpers.clone(me._model);
  3975. }
  3976. // No animation -> No Transition
  3977. if (ease === 1) {
  3978. me._view = me._model;
  3979. me._start = null;
  3980. return me;
  3981. }
  3982. if (!me._start) {
  3983. me.pivot();
  3984. }
  3985. helpers.each(me._model, function(value, key) {
  3986. if (key[0] === '_') {
  3987. // Only non-underscored properties
  3988. }
  3989. // Init if doesn't exist
  3990. else if (!me._view.hasOwnProperty(key)) {
  3991. if (typeof value === 'number' && !isNaN(me._view[key])) {
  3992. me._view[key] = value * ease;
  3993. } else {
  3994. me._view[key] = value;
  3995. }
  3996. }
  3997. // No unnecessary computations
  3998. else if (value === me._view[key]) {
  3999. // It's the same! Woohoo!
  4000. }
  4001. // Color transitions if possible
  4002. else if (typeof value === 'string') {
  4003. try {
  4004. var color = helpers.color(me._model[key]).mix(helpers.color(me._start[key]), ease);
  4005. me._view[key] = color.rgbString();
  4006. } catch (err) {
  4007. me._view[key] = value;
  4008. }
  4009. }
  4010. // Number transitions
  4011. else if (typeof value === 'number') {
  4012. var startVal = me._start[key] !== undefined && isNaN(me._start[key]) === false ? me._start[key] : 0;
  4013. me._view[key] = ((me._model[key] - startVal) * ease) + startVal;
  4014. }
  4015. // Everything else
  4016. else {
  4017. me._view[key] = value;
  4018. }
  4019. }, me);
  4020. return me;
  4021. },
  4022. tooltipPosition: function() {
  4023. return {
  4024. x: this._model.x,
  4025. y: this._model.y
  4026. };
  4027. },
  4028. hasValue: function() {
  4029. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  4030. }
  4031. });
  4032. Chart.Element.extend = helpers.inherits;
  4033. };
  4034. },{}],26:[function(require,module,exports){
  4035. /*global window: false */
  4036. /*global document: false */
  4037. "use strict";
  4038. var color = require(3);
  4039. module.exports = function(Chart) {
  4040. //Global Chart helpers object for utility methods and classes
  4041. var helpers = Chart.helpers = {};
  4042. //-- Basic js utility methods
  4043. helpers.each = function(loopable, callback, self, reverse) {
  4044. // Check to see if null or undefined firstly.
  4045. var i, len;
  4046. if (helpers.isArray(loopable)) {
  4047. len = loopable.length;
  4048. if (reverse) {
  4049. for (i = len - 1; i >= 0; i--) {
  4050. callback.call(self, loopable[i], i);
  4051. }
  4052. } else {
  4053. for (i = 0; i < len; i++) {
  4054. callback.call(self, loopable[i], i);
  4055. }
  4056. }
  4057. } else if (typeof loopable === 'object') {
  4058. var keys = Object.keys(loopable);
  4059. len = keys.length;
  4060. for (i = 0; i < len; i++) {
  4061. callback.call(self, loopable[keys[i]], keys[i]);
  4062. }
  4063. }
  4064. };
  4065. helpers.clone = function(obj) {
  4066. var objClone = {};
  4067. helpers.each(obj, function(value, key) {
  4068. if (helpers.isArray(value)) {
  4069. objClone[key] = value.slice(0);
  4070. } else if (typeof value === 'object' && value !== null) {
  4071. objClone[key] = helpers.clone(value);
  4072. } else {
  4073. objClone[key] = value;
  4074. }
  4075. });
  4076. return objClone;
  4077. };
  4078. helpers.extend = function(base) {
  4079. var setFn = function(value, key) { base[key] = value; };
  4080. for (var i = 1, ilen = arguments.length; i < ilen; i++) {
  4081. helpers.each(arguments[i], setFn);
  4082. }
  4083. return base;
  4084. };
  4085. // Need a special merge function to chart configs since they are now grouped
  4086. helpers.configMerge = function(_base) {
  4087. var base = helpers.clone(_base);
  4088. helpers.each(Array.prototype.slice.call(arguments, 1), function(extension) {
  4089. helpers.each(extension, function(value, key) {
  4090. if (key === 'scales') {
  4091. // Scale config merging is complex. Add out own function here for that
  4092. base[key] = helpers.scaleMerge(base.hasOwnProperty(key) ? base[key] : {}, value);
  4093. } else if (key === 'scale') {
  4094. // Used in polar area & radar charts since there is only one scale
  4095. base[key] = helpers.configMerge(base.hasOwnProperty(key) ? base[key] : {}, Chart.scaleService.getScaleDefaults(value.type), value);
  4096. } else if (base.hasOwnProperty(key) && helpers.isArray(base[key]) && helpers.isArray(value)) {
  4097. // In this case we have an array of objects replacing another array. Rather than doing a strict replace,
  4098. // merge. This allows easy scale option merging
  4099. var baseArray = base[key];
  4100. helpers.each(value, function(valueObj, index) {
  4101. if (index < baseArray.length) {
  4102. if (typeof baseArray[index] === 'object' && baseArray[index] !== null && typeof valueObj === 'object' && valueObj !== null) {
  4103. // Two objects are coming together. Do a merge of them.
  4104. baseArray[index] = helpers.configMerge(baseArray[index], valueObj);
  4105. } else {
  4106. // Just overwrite in this case since there is nothing to merge
  4107. baseArray[index] = valueObj;
  4108. }
  4109. } else {
  4110. baseArray.push(valueObj); // nothing to merge
  4111. }
  4112. });
  4113. } else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") {
  4114. // If we are overwriting an object with an object, do a merge of the properties.
  4115. base[key] = helpers.configMerge(base[key], value);
  4116. } else {
  4117. // can just overwrite the value in this case
  4118. base[key] = value;
  4119. }
  4120. });
  4121. });
  4122. return base;
  4123. };
  4124. helpers.scaleMerge = function(_base, extension) {
  4125. var base = helpers.clone(_base);
  4126. helpers.each(extension, function(value, key) {
  4127. if (key === 'xAxes' || key === 'yAxes') {
  4128. // These properties are arrays of items
  4129. if (base.hasOwnProperty(key)) {
  4130. helpers.each(value, function(valueObj, index) {
  4131. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  4132. var axisDefaults = Chart.scaleService.getScaleDefaults(axisType);
  4133. if (index >= base[key].length || !base[key][index].type) {
  4134. base[key].push(helpers.configMerge(axisDefaults, valueObj));
  4135. } else if (valueObj.type && valueObj.type !== base[key][index].type) {
  4136. // Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults
  4137. base[key][index] = helpers.configMerge(base[key][index], axisDefaults, valueObj);
  4138. } else {
  4139. // Type is the same
  4140. base[key][index] = helpers.configMerge(base[key][index], valueObj);
  4141. }
  4142. });
  4143. } else {
  4144. base[key] = [];
  4145. helpers.each(value, function(valueObj) {
  4146. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  4147. base[key].push(helpers.configMerge(Chart.scaleService.getScaleDefaults(axisType), valueObj));
  4148. });
  4149. }
  4150. } else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") {
  4151. // If we are overwriting an object with an object, do a merge of the properties.
  4152. base[key] = helpers.configMerge(base[key], value);
  4153. } else {
  4154. // can just overwrite the value in this case
  4155. base[key] = value;
  4156. }
  4157. });
  4158. return base;
  4159. };
  4160. helpers.getValueAtIndexOrDefault = function(value, index, defaultValue) {
  4161. if (value === undefined || value === null) {
  4162. return defaultValue;
  4163. }
  4164. if (helpers.isArray(value)) {
  4165. return index < value.length ? value[index] : defaultValue;
  4166. }
  4167. return value;
  4168. };
  4169. helpers.getValueOrDefault = function(value, defaultValue) {
  4170. return value === undefined ? defaultValue : value;
  4171. };
  4172. helpers.indexOf = Array.prototype.indexOf?
  4173. function(array, item) { return array.indexOf(item); } :
  4174. function(array, item) {
  4175. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4176. if (array[i] === item) {
  4177. return i;
  4178. }
  4179. }
  4180. return -1;
  4181. };
  4182. helpers.where = function(collection, filterCallback) {
  4183. if (helpers.isArray(collection) && Array.prototype.filter) {
  4184. return collection.filter(filterCallback);
  4185. } else {
  4186. var filtered = [];
  4187. helpers.each(collection, function(item) {
  4188. if (filterCallback(item)) {
  4189. filtered.push(item);
  4190. }
  4191. });
  4192. return filtered;
  4193. }
  4194. };
  4195. helpers.findIndex = Array.prototype.findIndex?
  4196. function(array, callback, scope) { return array.findIndex(callback, scope); } :
  4197. function(array, callback, scope) {
  4198. scope = scope === undefined? array : scope;
  4199. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4200. if (callback.call(scope, array[i], i, array)) {
  4201. return i;
  4202. }
  4203. }
  4204. return -1;
  4205. };
  4206. helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
  4207. // Default to start of the array
  4208. if (startIndex === undefined || startIndex === null) {
  4209. startIndex = -1;
  4210. }
  4211. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  4212. var currentItem = arrayToSearch[i];
  4213. if (filterCallback(currentItem)) {
  4214. return currentItem;
  4215. }
  4216. }
  4217. };
  4218. helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
  4219. // Default to end of the array
  4220. if (startIndex === undefined || startIndex === null) {
  4221. startIndex = arrayToSearch.length;
  4222. }
  4223. for (var i = startIndex - 1; i >= 0; i--) {
  4224. var currentItem = arrayToSearch[i];
  4225. if (filterCallback(currentItem)) {
  4226. return currentItem;
  4227. }
  4228. }
  4229. };
  4230. helpers.inherits = function(extensions) {
  4231. //Basic javascript inheritance based on the model created in Backbone.js
  4232. var parent = this;
  4233. var ChartElement = (extensions && extensions.hasOwnProperty("constructor")) ? extensions.constructor : function() {
  4234. return parent.apply(this, arguments);
  4235. };
  4236. var Surrogate = function() {
  4237. this.constructor = ChartElement;
  4238. };
  4239. Surrogate.prototype = parent.prototype;
  4240. ChartElement.prototype = new Surrogate();
  4241. ChartElement.extend = helpers.inherits;
  4242. if (extensions) {
  4243. helpers.extend(ChartElement.prototype, extensions);
  4244. }
  4245. ChartElement.__super__ = parent.prototype;
  4246. return ChartElement;
  4247. };
  4248. helpers.noop = function() {};
  4249. helpers.uid = (function() {
  4250. var id = 0;
  4251. return function() {
  4252. return id++;
  4253. };
  4254. }());
  4255. //-- Math methods
  4256. helpers.isNumber = function(n) {
  4257. return !isNaN(parseFloat(n)) && isFinite(n);
  4258. };
  4259. helpers.almostEquals = function(x, y, epsilon) {
  4260. return Math.abs(x - y) < epsilon;
  4261. };
  4262. helpers.max = function(array) {
  4263. return array.reduce(function(max, value) {
  4264. if (!isNaN(value)) {
  4265. return Math.max(max, value);
  4266. } else {
  4267. return max;
  4268. }
  4269. }, Number.NEGATIVE_INFINITY);
  4270. };
  4271. helpers.min = function(array) {
  4272. return array.reduce(function(min, value) {
  4273. if (!isNaN(value)) {
  4274. return Math.min(min, value);
  4275. } else {
  4276. return min;
  4277. }
  4278. }, Number.POSITIVE_INFINITY);
  4279. };
  4280. helpers.sign = Math.sign?
  4281. function(x) { return Math.sign(x); } :
  4282. function(x) {
  4283. x = +x; // convert to a number
  4284. if (x === 0 || isNaN(x)) {
  4285. return x;
  4286. }
  4287. return x > 0 ? 1 : -1;
  4288. };
  4289. helpers.log10 = Math.log10?
  4290. function(x) { return Math.log10(x); } :
  4291. function(x) {
  4292. return Math.log(x) / Math.LN10;
  4293. };
  4294. helpers.toRadians = function(degrees) {
  4295. return degrees * (Math.PI / 180);
  4296. };
  4297. helpers.toDegrees = function(radians) {
  4298. return radians * (180 / Math.PI);
  4299. };
  4300. // Gets the angle from vertical upright to the point about a centre.
  4301. helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
  4302. var distanceFromXCenter = anglePoint.x - centrePoint.x,
  4303. distanceFromYCenter = anglePoint.y - centrePoint.y,
  4304. radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  4305. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  4306. if (angle < (-0.5 * Math.PI)) {
  4307. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  4308. }
  4309. return {
  4310. angle: angle,
  4311. distance: radialDistanceFromCenter
  4312. };
  4313. };
  4314. helpers.aliasPixel = function(pixelWidth) {
  4315. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  4316. };
  4317. helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
  4318. //Props to Rob Spencer at scaled innovation for his post on splining between points
  4319. //http://scaledinnovation.com/analytics/splines/aboutSplines.html
  4320. // This function must also respect "skipped" points
  4321. var previous = firstPoint.skip ? middlePoint : firstPoint,
  4322. current = middlePoint,
  4323. next = afterPoint.skip ? middlePoint : afterPoint;
  4324. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  4325. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  4326. var s01 = d01 / (d01 + d12);
  4327. var s12 = d12 / (d01 + d12);
  4328. // If all points are the same, s01 & s02 will be inf
  4329. s01 = isNaN(s01) ? 0 : s01;
  4330. s12 = isNaN(s12) ? 0 : s12;
  4331. var fa = t * s01; // scaling factor for triangle Ta
  4332. var fb = t * s12;
  4333. return {
  4334. previous: {
  4335. x: current.x - fa * (next.x - previous.x),
  4336. y: current.y - fa * (next.y - previous.y)
  4337. },
  4338. next: {
  4339. x: current.x + fb * (next.x - previous.x),
  4340. y: current.y + fb * (next.y - previous.y)
  4341. }
  4342. };
  4343. };
  4344. helpers.EPSILON = Number.EPSILON || 1e-14;
  4345. helpers.splineCurveMonotone = function(points) {
  4346. // This function calculates Bézier control points in a similar way than |splineCurve|,
  4347. // but preserves monotonicity of the provided data and ensures no local extremums are added
  4348. // between the dataset discrete points due to the interpolation.
  4349. // See : https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
  4350. var pointsWithTangents = (points || []).map(function(point) {
  4351. return {
  4352. model: point._model,
  4353. deltaK: 0,
  4354. mK: 0
  4355. };
  4356. });
  4357. // Calculate slopes (deltaK) and initialize tangents (mK)
  4358. var pointsLen = pointsWithTangents.length;
  4359. var i, pointBefore, pointCurrent, pointAfter;
  4360. for (i = 0; i < pointsLen; ++i) {
  4361. pointCurrent = pointsWithTangents[i];
  4362. if (pointCurrent.model.skip) {
  4363. continue;
  4364. }
  4365. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4366. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4367. if (pointAfter && !pointAfter.model.skip) {
  4368. pointCurrent.deltaK = (pointAfter.model.y - pointCurrent.model.y) / (pointAfter.model.x - pointCurrent.model.x);
  4369. }
  4370. if (!pointBefore || pointBefore.model.skip) {
  4371. pointCurrent.mK = pointCurrent.deltaK;
  4372. } else if (!pointAfter || pointAfter.model.skip) {
  4373. pointCurrent.mK = pointBefore.deltaK;
  4374. } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
  4375. pointCurrent.mK = 0;
  4376. } else {
  4377. pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
  4378. }
  4379. }
  4380. // Adjust tangents to ensure monotonic properties
  4381. var alphaK, betaK, tauK, squaredMagnitude;
  4382. for (i = 0; i < pointsLen - 1; ++i) {
  4383. pointCurrent = pointsWithTangents[i];
  4384. pointAfter = pointsWithTangents[i + 1];
  4385. if (pointCurrent.model.skip || pointAfter.model.skip) {
  4386. continue;
  4387. }
  4388. if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
  4389. pointCurrent.mK = pointAfter.mK = 0;
  4390. continue;
  4391. }
  4392. alphaK = pointCurrent.mK / pointCurrent.deltaK;
  4393. betaK = pointAfter.mK / pointCurrent.deltaK;
  4394. squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
  4395. if (squaredMagnitude <= 9) {
  4396. continue;
  4397. }
  4398. tauK = 3 / Math.sqrt(squaredMagnitude);
  4399. pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
  4400. pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
  4401. }
  4402. // Compute control points
  4403. var deltaX;
  4404. for (i = 0; i < pointsLen; ++i) {
  4405. pointCurrent = pointsWithTangents[i];
  4406. if (pointCurrent.model.skip) {
  4407. continue;
  4408. }
  4409. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4410. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4411. if (pointBefore && !pointBefore.model.skip) {
  4412. deltaX = (pointCurrent.model.x - pointBefore.model.x) / 3;
  4413. pointCurrent.model.controlPointPreviousX = pointCurrent.model.x - deltaX;
  4414. pointCurrent.model.controlPointPreviousY = pointCurrent.model.y - deltaX * pointCurrent.mK;
  4415. }
  4416. if (pointAfter && !pointAfter.model.skip) {
  4417. deltaX = (pointAfter.model.x - pointCurrent.model.x) / 3;
  4418. pointCurrent.model.controlPointNextX = pointCurrent.model.x + deltaX;
  4419. pointCurrent.model.controlPointNextY = pointCurrent.model.y + deltaX * pointCurrent.mK;
  4420. }
  4421. }
  4422. };
  4423. helpers.nextItem = function(collection, index, loop) {
  4424. if (loop) {
  4425. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  4426. }
  4427. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  4428. };
  4429. helpers.previousItem = function(collection, index, loop) {
  4430. if (loop) {
  4431. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  4432. }
  4433. return index <= 0 ? collection[0] : collection[index - 1];
  4434. };
  4435. // Implementation of the nice number algorithm used in determining where axis labels will go
  4436. helpers.niceNum = function(range, round) {
  4437. var exponent = Math.floor(helpers.log10(range));
  4438. var fraction = range / Math.pow(10, exponent);
  4439. var niceFraction;
  4440. if (round) {
  4441. if (fraction < 1.5) {
  4442. niceFraction = 1;
  4443. } else if (fraction < 3) {
  4444. niceFraction = 2;
  4445. } else if (fraction < 7) {
  4446. niceFraction = 5;
  4447. } else {
  4448. niceFraction = 10;
  4449. }
  4450. } else {
  4451. if (fraction <= 1.0) {
  4452. niceFraction = 1;
  4453. } else if (fraction <= 2) {
  4454. niceFraction = 2;
  4455. } else if (fraction <= 5) {
  4456. niceFraction = 5;
  4457. } else {
  4458. niceFraction = 10;
  4459. }
  4460. }
  4461. return niceFraction * Math.pow(10, exponent);
  4462. };
  4463. //Easing functions adapted from Robert Penner's easing equations
  4464. //http://www.robertpenner.com/easing/
  4465. var easingEffects = helpers.easingEffects = {
  4466. linear: function(t) {
  4467. return t;
  4468. },
  4469. easeInQuad: function(t) {
  4470. return t * t;
  4471. },
  4472. easeOutQuad: function(t) {
  4473. return -1 * t * (t - 2);
  4474. },
  4475. easeInOutQuad: function(t) {
  4476. if ((t /= 1 / 2) < 1) {
  4477. return 1 / 2 * t * t;
  4478. }
  4479. return -1 / 2 * ((--t) * (t - 2) - 1);
  4480. },
  4481. easeInCubic: function(t) {
  4482. return t * t * t;
  4483. },
  4484. easeOutCubic: function(t) {
  4485. return 1 * ((t = t / 1 - 1) * t * t + 1);
  4486. },
  4487. easeInOutCubic: function(t) {
  4488. if ((t /= 1 / 2) < 1) {
  4489. return 1 / 2 * t * t * t;
  4490. }
  4491. return 1 / 2 * ((t -= 2) * t * t + 2);
  4492. },
  4493. easeInQuart: function(t) {
  4494. return t * t * t * t;
  4495. },
  4496. easeOutQuart: function(t) {
  4497. return -1 * ((t = t / 1 - 1) * t * t * t - 1);
  4498. },
  4499. easeInOutQuart: function(t) {
  4500. if ((t /= 1 / 2) < 1) {
  4501. return 1 / 2 * t * t * t * t;
  4502. }
  4503. return -1 / 2 * ((t -= 2) * t * t * t - 2);
  4504. },
  4505. easeInQuint: function(t) {
  4506. return 1 * (t /= 1) * t * t * t * t;
  4507. },
  4508. easeOutQuint: function(t) {
  4509. return 1 * ((t = t / 1 - 1) * t * t * t * t + 1);
  4510. },
  4511. easeInOutQuint: function(t) {
  4512. if ((t /= 1 / 2) < 1) {
  4513. return 1 / 2 * t * t * t * t * t;
  4514. }
  4515. return 1 / 2 * ((t -= 2) * t * t * t * t + 2);
  4516. },
  4517. easeInSine: function(t) {
  4518. return -1 * Math.cos(t / 1 * (Math.PI / 2)) + 1;
  4519. },
  4520. easeOutSine: function(t) {
  4521. return 1 * Math.sin(t / 1 * (Math.PI / 2));
  4522. },
  4523. easeInOutSine: function(t) {
  4524. return -1 / 2 * (Math.cos(Math.PI * t / 1) - 1);
  4525. },
  4526. easeInExpo: function(t) {
  4527. return (t === 0) ? 1 : 1 * Math.pow(2, 10 * (t / 1 - 1));
  4528. },
  4529. easeOutExpo: function(t) {
  4530. return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1);
  4531. },
  4532. easeInOutExpo: function(t) {
  4533. if (t === 0) {
  4534. return 0;
  4535. }
  4536. if (t === 1) {
  4537. return 1;
  4538. }
  4539. if ((t /= 1 / 2) < 1) {
  4540. return 1 / 2 * Math.pow(2, 10 * (t - 1));
  4541. }
  4542. return 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
  4543. },
  4544. easeInCirc: function(t) {
  4545. if (t >= 1) {
  4546. return t;
  4547. }
  4548. return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1);
  4549. },
  4550. easeOutCirc: function(t) {
  4551. return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t);
  4552. },
  4553. easeInOutCirc: function(t) {
  4554. if ((t /= 1 / 2) < 1) {
  4555. return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
  4556. }
  4557. return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  4558. },
  4559. easeInElastic: function(t) {
  4560. var s = 1.70158;
  4561. var p = 0;
  4562. var a = 1;
  4563. if (t === 0) {
  4564. return 0;
  4565. }
  4566. if ((t /= 1) === 1) {
  4567. return 1;
  4568. }
  4569. if (!p) {
  4570. p = 1 * 0.3;
  4571. }
  4572. if (a < Math.abs(1)) {
  4573. a = 1;
  4574. s = p / 4;
  4575. } else {
  4576. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4577. }
  4578. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  4579. },
  4580. easeOutElastic: function(t) {
  4581. var s = 1.70158;
  4582. var p = 0;
  4583. var a = 1;
  4584. if (t === 0) {
  4585. return 0;
  4586. }
  4587. if ((t /= 1) === 1) {
  4588. return 1;
  4589. }
  4590. if (!p) {
  4591. p = 1 * 0.3;
  4592. }
  4593. if (a < Math.abs(1)) {
  4594. a = 1;
  4595. s = p / 4;
  4596. } else {
  4597. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4598. }
  4599. return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1;
  4600. },
  4601. easeInOutElastic: function(t) {
  4602. var s = 1.70158;
  4603. var p = 0;
  4604. var a = 1;
  4605. if (t === 0) {
  4606. return 0;
  4607. }
  4608. if ((t /= 1 / 2) === 2) {
  4609. return 1;
  4610. }
  4611. if (!p) {
  4612. p = 1 * (0.3 * 1.5);
  4613. }
  4614. if (a < Math.abs(1)) {
  4615. a = 1;
  4616. s = p / 4;
  4617. } else {
  4618. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4619. }
  4620. if (t < 1) {
  4621. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  4622. }
  4623. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1;
  4624. },
  4625. easeInBack: function(t) {
  4626. var s = 1.70158;
  4627. return 1 * (t /= 1) * t * ((s + 1) * t - s);
  4628. },
  4629. easeOutBack: function(t) {
  4630. var s = 1.70158;
  4631. return 1 * ((t = t / 1 - 1) * t * ((s + 1) * t + s) + 1);
  4632. },
  4633. easeInOutBack: function(t) {
  4634. var s = 1.70158;
  4635. if ((t /= 1 / 2) < 1) {
  4636. return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
  4637. }
  4638. return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  4639. },
  4640. easeInBounce: function(t) {
  4641. return 1 - easingEffects.easeOutBounce(1 - t);
  4642. },
  4643. easeOutBounce: function(t) {
  4644. if ((t /= 1) < (1 / 2.75)) {
  4645. return 1 * (7.5625 * t * t);
  4646. } else if (t < (2 / 2.75)) {
  4647. return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
  4648. } else if (t < (2.5 / 2.75)) {
  4649. return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
  4650. } else {
  4651. return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
  4652. }
  4653. },
  4654. easeInOutBounce: function(t) {
  4655. if (t < 1 / 2) {
  4656. return easingEffects.easeInBounce(t * 2) * 0.5;
  4657. }
  4658. return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
  4659. }
  4660. };
  4661. //Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  4662. helpers.requestAnimFrame = (function() {
  4663. return window.requestAnimationFrame ||
  4664. window.webkitRequestAnimationFrame ||
  4665. window.mozRequestAnimationFrame ||
  4666. window.oRequestAnimationFrame ||
  4667. window.msRequestAnimationFrame ||
  4668. function(callback) {
  4669. return window.setTimeout(callback, 1000 / 60);
  4670. };
  4671. }());
  4672. helpers.cancelAnimFrame = (function() {
  4673. return window.cancelAnimationFrame ||
  4674. window.webkitCancelAnimationFrame ||
  4675. window.mozCancelAnimationFrame ||
  4676. window.oCancelAnimationFrame ||
  4677. window.msCancelAnimationFrame ||
  4678. function(callback) {
  4679. return window.clearTimeout(callback, 1000 / 60);
  4680. };
  4681. }());
  4682. //-- DOM methods
  4683. helpers.getRelativePosition = function(evt, chart) {
  4684. var mouseX, mouseY;
  4685. var e = evt.originalEvent || evt,
  4686. canvas = evt.currentTarget || evt.srcElement,
  4687. boundingRect = canvas.getBoundingClientRect();
  4688. var touches = e.touches;
  4689. if (touches && touches.length > 0) {
  4690. mouseX = touches[0].clientX;
  4691. mouseY = touches[0].clientY;
  4692. } else {
  4693. mouseX = e.clientX;
  4694. mouseY = e.clientY;
  4695. }
  4696. // Scale mouse coordinates into canvas coordinates
  4697. // by following the pattern laid out by 'jerryj' in the comments of
  4698. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  4699. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  4700. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  4701. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  4702. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  4703. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  4704. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  4705. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  4706. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  4707. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  4708. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  4709. return {
  4710. x: mouseX,
  4711. y: mouseY
  4712. };
  4713. };
  4714. helpers.addEvent = function(node, eventType, method) {
  4715. if (node.addEventListener) {
  4716. node.addEventListener(eventType, method);
  4717. } else if (node.attachEvent) {
  4718. node.attachEvent("on" + eventType, method);
  4719. } else {
  4720. node["on" + eventType] = method;
  4721. }
  4722. };
  4723. helpers.removeEvent = function(node, eventType, handler) {
  4724. if (node.removeEventListener) {
  4725. node.removeEventListener(eventType, handler, false);
  4726. } else if (node.detachEvent) {
  4727. node.detachEvent("on" + eventType, handler);
  4728. } else {
  4729. node["on" + eventType] = helpers.noop;
  4730. }
  4731. };
  4732. helpers.bindEvents = function(chartInstance, arrayOfEvents, handler) {
  4733. // Create the events object if it's not already present
  4734. var events = chartInstance.events = chartInstance.events || {};
  4735. helpers.each(arrayOfEvents, function(eventName) {
  4736. events[eventName] = function() {
  4737. handler.apply(chartInstance, arguments);
  4738. };
  4739. helpers.addEvent(chartInstance.chart.canvas, eventName, events[eventName]);
  4740. });
  4741. };
  4742. helpers.unbindEvents = function(chartInstance, arrayOfEvents) {
  4743. var canvas = chartInstance.chart.canvas;
  4744. helpers.each(arrayOfEvents, function(handler, eventName) {
  4745. helpers.removeEvent(canvas, eventName, handler);
  4746. });
  4747. };
  4748. // Private helper function to convert max-width/max-height values that may be percentages into a number
  4749. function parseMaxStyle(styleValue, node, parentProperty) {
  4750. var valueInPixels;
  4751. if (typeof(styleValue) === 'string') {
  4752. valueInPixels = parseInt(styleValue, 10);
  4753. if (styleValue.indexOf('%') !== -1) {
  4754. // percentage * size in dimension
  4755. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  4756. }
  4757. } else {
  4758. valueInPixels = styleValue;
  4759. }
  4760. return valueInPixels;
  4761. }
  4762. /**
  4763. * Returns if the given value contains an effective constraint.
  4764. * @private
  4765. */
  4766. function isConstrainedValue(value) {
  4767. return value !== undefined && value !== null && value !== 'none';
  4768. }
  4769. // Private helper to get a constraint dimension
  4770. // @param domNode : the node to check the constraint on
  4771. // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
  4772. // @param percentageProperty : property of parent to use when calculating width as a percentage
  4773. // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
  4774. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  4775. var view = document.defaultView;
  4776. var parentNode = domNode.parentNode;
  4777. var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
  4778. var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
  4779. var hasCNode = isConstrainedValue(constrainedNode);
  4780. var hasCContainer = isConstrainedValue(constrainedContainer);
  4781. var infinity = Number.POSITIVE_INFINITY;
  4782. if (hasCNode || hasCContainer) {
  4783. return Math.min(
  4784. hasCNode? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
  4785. hasCContainer? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
  4786. }
  4787. return 'none';
  4788. }
  4789. // returns Number or undefined if no constraint
  4790. helpers.getConstraintWidth = function(domNode) {
  4791. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  4792. };
  4793. // returns Number or undefined if no constraint
  4794. helpers.getConstraintHeight = function(domNode) {
  4795. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  4796. };
  4797. helpers.getMaximumWidth = function(domNode) {
  4798. var container = domNode.parentNode;
  4799. var paddingLeft = parseInt(helpers.getStyle(container, 'padding-left'), 10);
  4800. var paddingRight = parseInt(helpers.getStyle(container, 'padding-right'), 10);
  4801. var w = container.clientWidth - paddingLeft - paddingRight;
  4802. var cw = helpers.getConstraintWidth(domNode);
  4803. return isNaN(cw)? w : Math.min(w, cw);
  4804. };
  4805. helpers.getMaximumHeight = function(domNode) {
  4806. var container = domNode.parentNode;
  4807. var paddingTop = parseInt(helpers.getStyle(container, 'padding-top'), 10);
  4808. var paddingBottom = parseInt(helpers.getStyle(container, 'padding-bottom'), 10);
  4809. var h = container.clientHeight - paddingTop - paddingBottom;
  4810. var ch = helpers.getConstraintHeight(domNode);
  4811. return isNaN(ch)? h : Math.min(h, ch);
  4812. };
  4813. helpers.getStyle = function(el, property) {
  4814. return el.currentStyle ?
  4815. el.currentStyle[property] :
  4816. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  4817. };
  4818. helpers.retinaScale = function(chart) {
  4819. var ctx = chart.ctx;
  4820. var canvas = chart.canvas;
  4821. var width = canvas.width;
  4822. var height = canvas.height;
  4823. var pixelRatio = chart.currentDevicePixelRatio = window.devicePixelRatio || 1;
  4824. if (pixelRatio !== 1) {
  4825. canvas.height = height * pixelRatio;
  4826. canvas.width = width * pixelRatio;
  4827. ctx.scale(pixelRatio, pixelRatio);
  4828. // Store the device pixel ratio so that we can go backwards in `destroy`.
  4829. // The devicePixelRatio changes with zoom, so there are no guarantees that it is the same
  4830. // when destroy is called
  4831. chart.originalDevicePixelRatio = chart.originalDevicePixelRatio || pixelRatio;
  4832. }
  4833. canvas.style.width = width + 'px';
  4834. canvas.style.height = height + 'px';
  4835. };
  4836. //-- Canvas methods
  4837. helpers.clear = function(chart) {
  4838. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  4839. };
  4840. helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
  4841. return fontStyle + " " + pixelSize + "px " + fontFamily;
  4842. };
  4843. helpers.longestText = function(ctx, font, arrayOfThings, cache) {
  4844. cache = cache || {};
  4845. var data = cache.data = cache.data || {};
  4846. var gc = cache.garbageCollect = cache.garbageCollect || [];
  4847. if (cache.font !== font) {
  4848. data = cache.data = {};
  4849. gc = cache.garbageCollect = [];
  4850. cache.font = font;
  4851. }
  4852. ctx.font = font;
  4853. var longest = 0;
  4854. helpers.each(arrayOfThings, function(thing) {
  4855. // Undefined strings and arrays should not be measured
  4856. if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
  4857. longest = helpers.measureText(ctx, data, gc, longest, thing);
  4858. } else if (helpers.isArray(thing)) {
  4859. // if it is an array lets measure each element
  4860. // to do maybe simplify this function a bit so we can do this more recursively?
  4861. helpers.each(thing, function(nestedThing) {
  4862. // Undefined strings and arrays should not be measured
  4863. if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
  4864. longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
  4865. }
  4866. });
  4867. }
  4868. });
  4869. var gcLen = gc.length / 2;
  4870. if (gcLen > arrayOfThings.length) {
  4871. for (var i = 0; i < gcLen; i++) {
  4872. delete data[gc[i]];
  4873. }
  4874. gc.splice(0, gcLen);
  4875. }
  4876. return longest;
  4877. };
  4878. helpers.measureText = function (ctx, data, gc, longest, string) {
  4879. var textWidth = data[string];
  4880. if (!textWidth) {
  4881. textWidth = data[string] = ctx.measureText(string).width;
  4882. gc.push(string);
  4883. }
  4884. if (textWidth > longest) {
  4885. longest = textWidth;
  4886. }
  4887. return longest;
  4888. };
  4889. helpers.numberOfLabelLines = function(arrayOfThings) {
  4890. var numberOfLines = 1;
  4891. helpers.each(arrayOfThings, function(thing) {
  4892. if (helpers.isArray(thing)) {
  4893. if (thing.length > numberOfLines) {
  4894. numberOfLines = thing.length;
  4895. }
  4896. }
  4897. });
  4898. return numberOfLines;
  4899. };
  4900. helpers.drawRoundedRectangle = function(ctx, x, y, width, height, radius) {
  4901. ctx.beginPath();
  4902. ctx.moveTo(x + radius, y);
  4903. ctx.lineTo(x + width - radius, y);
  4904. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  4905. ctx.lineTo(x + width, y + height - radius);
  4906. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  4907. ctx.lineTo(x + radius, y + height);
  4908. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  4909. ctx.lineTo(x, y + radius);
  4910. ctx.quadraticCurveTo(x, y, x + radius, y);
  4911. ctx.closePath();
  4912. };
  4913. helpers.color = function(c) {
  4914. if (!color) {
  4915. console.log('Color.js not found!');
  4916. return c;
  4917. }
  4918. /* global CanvasGradient */
  4919. if (c instanceof CanvasGradient) {
  4920. return color(Chart.defaults.global.defaultColor);
  4921. }
  4922. return color(c);
  4923. };
  4924. helpers.addResizeListener = function(node, callback) {
  4925. // Hide an iframe before the node
  4926. var hiddenIframe = document.createElement('iframe');
  4927. var hiddenIframeClass = 'chartjs-hidden-iframe';
  4928. if (hiddenIframe.classlist) {
  4929. // can use classlist
  4930. hiddenIframe.classlist.add(hiddenIframeClass);
  4931. } else {
  4932. hiddenIframe.setAttribute('class', hiddenIframeClass);
  4933. }
  4934. // Set the style
  4935. hiddenIframe.tabIndex = -1;
  4936. var style = hiddenIframe.style;
  4937. style.width = '100%';
  4938. style.display = 'block';
  4939. style.border = 0;
  4940. style.height = 0;
  4941. style.margin = 0;
  4942. style.position = 'absolute';
  4943. style.left = 0;
  4944. style.right = 0;
  4945. style.top = 0;
  4946. style.bottom = 0;
  4947. // Insert the iframe so that contentWindow is available
  4948. node.insertBefore(hiddenIframe, node.firstChild);
  4949. (hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
  4950. if (callback) {
  4951. return callback();
  4952. }
  4953. };
  4954. };
  4955. helpers.removeResizeListener = function(node) {
  4956. var hiddenIframe = node.querySelector('.chartjs-hidden-iframe');
  4957. // Remove the resize detect iframe
  4958. if (hiddenIframe) {
  4959. hiddenIframe.parentNode.removeChild(hiddenIframe);
  4960. }
  4961. };
  4962. helpers.isArray = Array.isArray?
  4963. function(obj) { return Array.isArray(obj); } :
  4964. function(obj) {
  4965. return Object.prototype.toString.call(obj) === '[object Array]';
  4966. };
  4967. //! @see http://stackoverflow.com/a/14853974
  4968. helpers.arrayEquals = function(a0, a1) {
  4969. var i, ilen, v0, v1;
  4970. if (!a0 || !a1 || a0.length !== a1.length) {
  4971. return false;
  4972. }
  4973. for (i = 0, ilen=a0.length; i < ilen; ++i) {
  4974. v0 = a0[i];
  4975. v1 = a1[i];
  4976. if (v0 instanceof Array && v1 instanceof Array) {
  4977. if (!helpers.arrayEquals(v0, v1)) {
  4978. return false;
  4979. }
  4980. } else if (v0 !== v1) {
  4981. // NOTE: two different object instances will never be equal: {x:20} != {x:20}
  4982. return false;
  4983. }
  4984. }
  4985. return true;
  4986. };
  4987. helpers.callCallback = function(fn, args, _tArg) {
  4988. if (fn && typeof fn.call === 'function') {
  4989. fn.apply(_tArg, args);
  4990. }
  4991. };
  4992. helpers.getHoverColor = function(color) {
  4993. /* global CanvasPattern */
  4994. return (color instanceof CanvasPattern) ?
  4995. color :
  4996. helpers.color(color).saturate(0.5).darken(0.1).rgbString();
  4997. };
  4998. };
  4999. },{"3":3}],27:[function(require,module,exports){
  5000. "use strict";
  5001. module.exports = function() {
  5002. //Occupy the global variable of Chart, and create a simple base class
  5003. var Chart = function(context, config) {
  5004. var me = this;
  5005. var helpers = Chart.helpers;
  5006. me.config = config || {
  5007. data: {
  5008. datasets: []
  5009. }
  5010. };
  5011. // Support a jQuery'd canvas element
  5012. if (context.length && context[0].getContext) {
  5013. context = context[0];
  5014. }
  5015. // Support a canvas domnode
  5016. if (context.getContext) {
  5017. context = context.getContext("2d");
  5018. }
  5019. me.ctx = context;
  5020. me.canvas = context.canvas;
  5021. context.canvas.style.display = context.canvas.style.display || 'block';
  5022. // Figure out what the size of the chart will be.
  5023. // If the canvas has a specified width and height, we use those else
  5024. // we look to see if the canvas node has a CSS width and height.
  5025. // If there is still no height, fill the parent container
  5026. me.width = context.canvas.width || parseInt(helpers.getStyle(context.canvas, 'width'), 10) || helpers.getMaximumWidth(context.canvas);
  5027. me.height = context.canvas.height || parseInt(helpers.getStyle(context.canvas, 'height'), 10) || helpers.getMaximumHeight(context.canvas);
  5028. me.aspectRatio = me.width / me.height;
  5029. if (isNaN(me.aspectRatio) || isFinite(me.aspectRatio) === false) {
  5030. // If the canvas has no size, try and figure out what the aspect ratio will be.
  5031. // Some charts prefer square canvases (pie, radar, etc). If that is specified, use that
  5032. // else use the canvas default ratio of 2
  5033. me.aspectRatio = config.aspectRatio !== undefined ? config.aspectRatio : 2;
  5034. }
  5035. // Store the original style of the element so we can set it back
  5036. me.originalCanvasStyleWidth = context.canvas.style.width;
  5037. me.originalCanvasStyleHeight = context.canvas.style.height;
  5038. // High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale.
  5039. helpers.retinaScale(me);
  5040. me.controller = new Chart.Controller(me);
  5041. // Always bind this so that if the responsive state changes we still work
  5042. helpers.addResizeListener(context.canvas.parentNode, function() {
  5043. if (me.controller && me.controller.config.options.responsive) {
  5044. me.controller.resize();
  5045. }
  5046. });
  5047. return me.controller ? me.controller : me;
  5048. };
  5049. //Globally expose the defaults to allow for user updating/changing
  5050. Chart.defaults = {
  5051. global: {
  5052. responsive: true,
  5053. responsiveAnimationDuration: 0,
  5054. maintainAspectRatio: true,
  5055. events: ["mousemove", "mouseout", "click", "touchstart", "touchmove"],
  5056. hover: {
  5057. onHover: null,
  5058. mode: 'single',
  5059. animationDuration: 400
  5060. },
  5061. onClick: null,
  5062. defaultColor: 'rgba(0,0,0,0.1)',
  5063. defaultFontColor: '#666',
  5064. defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  5065. defaultFontSize: 12,
  5066. defaultFontStyle: 'normal',
  5067. showLines: true,
  5068. // Element defaults defined in element extensions
  5069. elements: {},
  5070. // Legend callback string
  5071. legendCallback: function(chart) {
  5072. var text = [];
  5073. text.push('<ul class="' + chart.id + '-legend">');
  5074. for (var i = 0; i < chart.data.datasets.length; i++) {
  5075. text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
  5076. if (chart.data.datasets[i].label) {
  5077. text.push(chart.data.datasets[i].label);
  5078. }
  5079. text.push('</li>');
  5080. }
  5081. text.push('</ul>');
  5082. return text.join("");
  5083. }
  5084. }
  5085. };
  5086. Chart.Chart = Chart;
  5087. return Chart;
  5088. };
  5089. },{}],28:[function(require,module,exports){
  5090. "use strict";
  5091. module.exports = function(Chart) {
  5092. var helpers = Chart.helpers;
  5093. // The layout service is very self explanatory. It's responsible for the layout within a chart.
  5094. // Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
  5095. // It is this service's responsibility of carrying out that layout.
  5096. Chart.layoutService = {
  5097. defaults: {},
  5098. // Register a box to a chartInstance. A box is simply a reference to an object that requires layout. eg. Scales, Legend, Plugins.
  5099. addBox: function(chartInstance, box) {
  5100. if (!chartInstance.boxes) {
  5101. chartInstance.boxes = [];
  5102. }
  5103. chartInstance.boxes.push(box);
  5104. },
  5105. removeBox: function(chartInstance, box) {
  5106. if (!chartInstance.boxes) {
  5107. return;
  5108. }
  5109. chartInstance.boxes.splice(chartInstance.boxes.indexOf(box), 1);
  5110. },
  5111. // The most important function
  5112. update: function(chartInstance, width, height) {
  5113. if (!chartInstance) {
  5114. return;
  5115. }
  5116. var xPadding = 0;
  5117. var yPadding = 0;
  5118. var leftBoxes = helpers.where(chartInstance.boxes, function(box) {
  5119. return box.options.position === "left";
  5120. });
  5121. var rightBoxes = helpers.where(chartInstance.boxes, function(box) {
  5122. return box.options.position === "right";
  5123. });
  5124. var topBoxes = helpers.where(chartInstance.boxes, function(box) {
  5125. return box.options.position === "top";
  5126. });
  5127. var bottomBoxes = helpers.where(chartInstance.boxes, function(box) {
  5128. return box.options.position === "bottom";
  5129. });
  5130. // Boxes that overlay the chartarea such as the radialLinear scale
  5131. var chartAreaBoxes = helpers.where(chartInstance.boxes, function(box) {
  5132. return box.options.position === "chartArea";
  5133. });
  5134. // Ensure that full width boxes are at the very top / bottom
  5135. topBoxes.sort(function(a, b) {
  5136. return (b.options.fullWidth ? 1 : 0) - (a.options.fullWidth ? 1 : 0);
  5137. });
  5138. bottomBoxes.sort(function(a, b) {
  5139. return (a.options.fullWidth ? 1 : 0) - (b.options.fullWidth ? 1 : 0);
  5140. });
  5141. // Essentially we now have any number of boxes on each of the 4 sides.
  5142. // Our canvas looks like the following.
  5143. // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
  5144. // B1 is the bottom axis
  5145. // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
  5146. // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
  5147. // an error will be thrown.
  5148. //
  5149. // |----------------------------------------------------|
  5150. // | T1 (Full Width) |
  5151. // |----------------------------------------------------|
  5152. // | | | T2 | |
  5153. // | |----|-------------------------------------|----|
  5154. // | | | C1 | | C2 | |
  5155. // | | |----| |----| |
  5156. // | | | | |
  5157. // | L1 | L2 | ChartArea (C0) | R1 |
  5158. // | | | | |
  5159. // | | |----| |----| |
  5160. // | | | C3 | | C4 | |
  5161. // | |----|-------------------------------------|----|
  5162. // | | | B1 | |
  5163. // |----------------------------------------------------|
  5164. // | B2 (Full Width) |
  5165. // |----------------------------------------------------|
  5166. //
  5167. // What we do to find the best sizing, we do the following
  5168. // 1. Determine the minimum size of the chart area.
  5169. // 2. Split the remaining width equally between each vertical axis
  5170. // 3. Split the remaining height equally between each horizontal axis
  5171. // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
  5172. // 5. Adjust the sizes of each axis based on it's minimum reported size.
  5173. // 6. Refit each axis
  5174. // 7. Position each axis in the final location
  5175. // 8. Tell the chart the final location of the chart area
  5176. // 9. Tell any axes that overlay the chart area the positions of the chart area
  5177. // Step 1
  5178. var chartWidth = width - (2 * xPadding);
  5179. var chartHeight = height - (2 * yPadding);
  5180. var chartAreaWidth = chartWidth / 2; // min 50%
  5181. var chartAreaHeight = chartHeight / 2; // min 50%
  5182. // Step 2
  5183. var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
  5184. // Step 3
  5185. var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
  5186. // Step 4
  5187. var maxChartAreaWidth = chartWidth;
  5188. var maxChartAreaHeight = chartHeight;
  5189. var minBoxSizes = [];
  5190. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  5191. function getMinimumBoxSize(box) {
  5192. var minSize;
  5193. var isHorizontal = box.isHorizontal();
  5194. if (isHorizontal) {
  5195. minSize = box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  5196. maxChartAreaHeight -= minSize.height;
  5197. } else {
  5198. minSize = box.update(verticalBoxWidth, chartAreaHeight);
  5199. maxChartAreaWidth -= minSize.width;
  5200. }
  5201. minBoxSizes.push({
  5202. horizontal: isHorizontal,
  5203. minSize: minSize,
  5204. box: box
  5205. });
  5206. }
  5207. // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
  5208. // be if the axes are drawn at their minimum sizes.
  5209. // Steps 5 & 6
  5210. var totalLeftBoxesWidth = xPadding;
  5211. var totalRightBoxesWidth = xPadding;
  5212. var totalTopBoxesHeight = yPadding;
  5213. var totalBottomBoxesHeight = yPadding;
  5214. // Update, and calculate the left and right margins for the horizontal boxes
  5215. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  5216. helpers.each(leftBoxes, function(box) {
  5217. totalLeftBoxesWidth += box.width;
  5218. });
  5219. helpers.each(rightBoxes, function(box) {
  5220. totalRightBoxesWidth += box.width;
  5221. });
  5222. // Set the Left and Right margins for the horizontal boxes
  5223. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  5224. // Function to fit a box
  5225. function fitBox(box) {
  5226. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
  5227. return minBoxSize.box === box;
  5228. });
  5229. if (minBoxSize) {
  5230. if (box.isHorizontal()) {
  5231. var scaleMargin = {
  5232. left: totalLeftBoxesWidth,
  5233. right: totalRightBoxesWidth,
  5234. top: 0,
  5235. bottom: 0
  5236. };
  5237. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  5238. // on the margin. Sometimes they need to increase in size slightly
  5239. box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  5240. } else {
  5241. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  5242. }
  5243. }
  5244. }
  5245. // Figure out how much margin is on the top and bottom of the vertical boxes
  5246. helpers.each(topBoxes, function(box) {
  5247. totalTopBoxesHeight += box.height;
  5248. });
  5249. helpers.each(bottomBoxes, function(box) {
  5250. totalBottomBoxesHeight += box.height;
  5251. });
  5252. // Let the left layout know the final margin
  5253. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  5254. function finalFitVerticalBox(box) {
  5255. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
  5256. return minBoxSize.box === box;
  5257. });
  5258. var scaleMargin = {
  5259. left: 0,
  5260. right: 0,
  5261. top: totalTopBoxesHeight,
  5262. bottom: totalBottomBoxesHeight
  5263. };
  5264. if (minBoxSize) {
  5265. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  5266. }
  5267. }
  5268. // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
  5269. totalLeftBoxesWidth = xPadding;
  5270. totalRightBoxesWidth = xPadding;
  5271. totalTopBoxesHeight = yPadding;
  5272. totalBottomBoxesHeight = yPadding;
  5273. helpers.each(leftBoxes, function(box) {
  5274. totalLeftBoxesWidth += box.width;
  5275. });
  5276. helpers.each(rightBoxes, function(box) {
  5277. totalRightBoxesWidth += box.width;
  5278. });
  5279. helpers.each(topBoxes, function(box) {
  5280. totalTopBoxesHeight += box.height;
  5281. });
  5282. helpers.each(bottomBoxes, function(box) {
  5283. totalBottomBoxesHeight += box.height;
  5284. });
  5285. // Figure out if our chart area changed. This would occur if the dataset layout label rotation
  5286. // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
  5287. // without calling `fit` again
  5288. var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
  5289. var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
  5290. if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
  5291. helpers.each(leftBoxes, function(box) {
  5292. box.height = newMaxChartAreaHeight;
  5293. });
  5294. helpers.each(rightBoxes, function(box) {
  5295. box.height = newMaxChartAreaHeight;
  5296. });
  5297. helpers.each(topBoxes, function(box) {
  5298. if (!box.options.fullWidth) {
  5299. box.width = newMaxChartAreaWidth;
  5300. }
  5301. });
  5302. helpers.each(bottomBoxes, function(box) {
  5303. if (!box.options.fullWidth) {
  5304. box.width = newMaxChartAreaWidth;
  5305. }
  5306. });
  5307. maxChartAreaHeight = newMaxChartAreaHeight;
  5308. maxChartAreaWidth = newMaxChartAreaWidth;
  5309. }
  5310. // Step 7 - Position the boxes
  5311. var left = xPadding;
  5312. var top = yPadding;
  5313. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  5314. // Account for chart width and height
  5315. left += maxChartAreaWidth;
  5316. top += maxChartAreaHeight;
  5317. helpers.each(rightBoxes, placeBox);
  5318. helpers.each(bottomBoxes, placeBox);
  5319. function placeBox(box) {
  5320. if (box.isHorizontal()) {
  5321. box.left = box.options.fullWidth ? xPadding : totalLeftBoxesWidth;
  5322. box.right = box.options.fullWidth ? width - xPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  5323. box.top = top;
  5324. box.bottom = top + box.height;
  5325. // Move to next point
  5326. top = box.bottom;
  5327. } else {
  5328. box.left = left;
  5329. box.right = left + box.width;
  5330. box.top = totalTopBoxesHeight;
  5331. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  5332. // Move to next point
  5333. left = box.right;
  5334. }
  5335. }
  5336. // Step 8
  5337. chartInstance.chartArea = {
  5338. left: totalLeftBoxesWidth,
  5339. top: totalTopBoxesHeight,
  5340. right: totalLeftBoxesWidth + maxChartAreaWidth,
  5341. bottom: totalTopBoxesHeight + maxChartAreaHeight
  5342. };
  5343. // Step 9
  5344. helpers.each(chartAreaBoxes, function(box) {
  5345. box.left = chartInstance.chartArea.left;
  5346. box.top = chartInstance.chartArea.top;
  5347. box.right = chartInstance.chartArea.right;
  5348. box.bottom = chartInstance.chartArea.bottom;
  5349. box.update(maxChartAreaWidth, maxChartAreaHeight);
  5350. });
  5351. }
  5352. };
  5353. };
  5354. },{}],29:[function(require,module,exports){
  5355. "use strict";
  5356. module.exports = function(Chart) {
  5357. var helpers = Chart.helpers;
  5358. var noop = helpers.noop;
  5359. Chart.defaults.global.legend = {
  5360. display: true,
  5361. position: 'top',
  5362. fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
  5363. reverse: false,
  5364. // a callback that will handle
  5365. onClick: function(e, legendItem) {
  5366. var index = legendItem.datasetIndex;
  5367. var ci = this.chart;
  5368. var meta = ci.getDatasetMeta(index);
  5369. // See controller.isDatasetVisible comment
  5370. meta.hidden = meta.hidden === null? !ci.data.datasets[index].hidden : null;
  5371. // We hid a dataset ... rerender the chart
  5372. ci.update();
  5373. },
  5374. onHover: null,
  5375. labels: {
  5376. boxWidth: 40,
  5377. padding: 10,
  5378. // Generates labels shown in the legend
  5379. // Valid properties to return:
  5380. // text : text to display
  5381. // fillStyle : fill of coloured box
  5382. // strokeStyle: stroke of coloured box
  5383. // hidden : if this legend item refers to a hidden item
  5384. // lineCap : cap style for line
  5385. // lineDash
  5386. // lineDashOffset :
  5387. // lineJoin :
  5388. // lineWidth :
  5389. generateLabels: function(chart) {
  5390. var data = chart.data;
  5391. return helpers.isArray(data.datasets) ? data.datasets.map(function(dataset, i) {
  5392. return {
  5393. text: dataset.label,
  5394. fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
  5395. hidden: !chart.isDatasetVisible(i),
  5396. lineCap: dataset.borderCapStyle,
  5397. lineDash: dataset.borderDash,
  5398. lineDashOffset: dataset.borderDashOffset,
  5399. lineJoin: dataset.borderJoinStyle,
  5400. lineWidth: dataset.borderWidth,
  5401. strokeStyle: dataset.borderColor,
  5402. pointStyle: dataset.pointStyle,
  5403. // Below is extra data used for toggling the datasets
  5404. datasetIndex: i
  5405. };
  5406. }, this) : [];
  5407. }
  5408. }
  5409. };
  5410. Chart.Legend = Chart.Element.extend({
  5411. initialize: function(config) {
  5412. helpers.extend(this, config);
  5413. // Contains hit boxes for each dataset (in dataset order)
  5414. this.legendHitBoxes = [];
  5415. // Are we in doughnut mode which has a different data type
  5416. this.doughnutMode = false;
  5417. },
  5418. // These methods are ordered by lifecyle. Utilities then follow.
  5419. // Any function defined here is inherited by all legend types.
  5420. // Any function can be extended by the legend type
  5421. beforeUpdate: noop,
  5422. update: function(maxWidth, maxHeight, margins) {
  5423. var me = this;
  5424. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  5425. me.beforeUpdate();
  5426. // Absorb the master measurements
  5427. me.maxWidth = maxWidth;
  5428. me.maxHeight = maxHeight;
  5429. me.margins = margins;
  5430. // Dimensions
  5431. me.beforeSetDimensions();
  5432. me.setDimensions();
  5433. me.afterSetDimensions();
  5434. // Labels
  5435. me.beforeBuildLabels();
  5436. me.buildLabels();
  5437. me.afterBuildLabels();
  5438. // Fit
  5439. me.beforeFit();
  5440. me.fit();
  5441. me.afterFit();
  5442. //
  5443. me.afterUpdate();
  5444. return me.minSize;
  5445. },
  5446. afterUpdate: noop,
  5447. //
  5448. beforeSetDimensions: noop,
  5449. setDimensions: function() {
  5450. var me = this;
  5451. // Set the unconstrained dimension before label rotation
  5452. if (me.isHorizontal()) {
  5453. // Reset position before calculating rotation
  5454. me.width = me.maxWidth;
  5455. me.left = 0;
  5456. me.right = me.width;
  5457. } else {
  5458. me.height = me.maxHeight;
  5459. // Reset position before calculating rotation
  5460. me.top = 0;
  5461. me.bottom = me.height;
  5462. }
  5463. // Reset padding
  5464. me.paddingLeft = 0;
  5465. me.paddingTop = 0;
  5466. me.paddingRight = 0;
  5467. me.paddingBottom = 0;
  5468. // Reset minSize
  5469. me.minSize = {
  5470. width: 0,
  5471. height: 0
  5472. };
  5473. },
  5474. afterSetDimensions: noop,
  5475. //
  5476. beforeBuildLabels: noop,
  5477. buildLabels: function() {
  5478. var me = this;
  5479. me.legendItems = me.options.labels.generateLabels.call(me, me.chart);
  5480. if(me.options.reverse){
  5481. me.legendItems.reverse();
  5482. }
  5483. },
  5484. afterBuildLabels: noop,
  5485. //
  5486. beforeFit: noop,
  5487. fit: function() {
  5488. var me = this;
  5489. var opts = me.options;
  5490. var labelOpts = opts.labels;
  5491. var display = opts.display;
  5492. var ctx = me.ctx;
  5493. var globalDefault = Chart.defaults.global,
  5494. itemOrDefault = helpers.getValueOrDefault,
  5495. fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize),
  5496. fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle),
  5497. fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily),
  5498. labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  5499. // Reset hit boxes
  5500. var hitboxes = me.legendHitBoxes = [];
  5501. var minSize = me.minSize;
  5502. var isHorizontal = me.isHorizontal();
  5503. if (isHorizontal) {
  5504. minSize.width = me.maxWidth; // fill all the width
  5505. minSize.height = display ? 10 : 0;
  5506. } else {
  5507. minSize.width = display ? 10 : 0;
  5508. minSize.height = me.maxHeight; // fill all the height
  5509. }
  5510. // Increase sizes here
  5511. if (display) {
  5512. ctx.font = labelFont;
  5513. if (isHorizontal) {
  5514. // Labels
  5515. // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
  5516. var lineWidths = me.lineWidths = [0];
  5517. var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0;
  5518. ctx.textAlign = "left";
  5519. ctx.textBaseline = 'top';
  5520. helpers.each(me.legendItems, function(legendItem, i) {
  5521. var boxWidth = labelOpts.usePointStyle ?
  5522. fontSize * Math.sqrt(2) :
  5523. labelOpts.boxWidth;
  5524. var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  5525. if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= me.width) {
  5526. totalHeight += fontSize + (labelOpts.padding);
  5527. lineWidths[lineWidths.length] = me.left;
  5528. }
  5529. // Store the hitbox width and height here. Final position will be updated in `draw`
  5530. hitboxes[i] = {
  5531. left: 0,
  5532. top: 0,
  5533. width: width,
  5534. height: fontSize
  5535. };
  5536. lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
  5537. });
  5538. minSize.height += totalHeight;
  5539. } else {
  5540. var vPadding = labelOpts.padding;
  5541. var columnWidths = me.columnWidths = [];
  5542. var totalWidth = labelOpts.padding;
  5543. var currentColWidth = 0;
  5544. var currentColHeight = 0;
  5545. var itemHeight = fontSize + vPadding;
  5546. helpers.each(me.legendItems, function(legendItem, i) {
  5547. // If usePointStyle is set, multiple boxWidth by 2 since it represents
  5548. // the radius and not truly the width
  5549. var boxWidth = labelOpts.usePointStyle ? 2 * labelOpts.boxWidth : labelOpts.boxWidth;
  5550. var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  5551. // If too tall, go to new column
  5552. if (currentColHeight + itemHeight > minSize.height) {
  5553. totalWidth += currentColWidth + labelOpts.padding;
  5554. columnWidths.push(currentColWidth); // previous column width
  5555. currentColWidth = 0;
  5556. currentColHeight = 0;
  5557. }
  5558. // Get max width
  5559. currentColWidth = Math.max(currentColWidth, itemWidth);
  5560. currentColHeight += itemHeight;
  5561. // Store the hitbox width and height here. Final position will be updated in `draw`
  5562. hitboxes[i] = {
  5563. left: 0,
  5564. top: 0,
  5565. width: itemWidth,
  5566. height: fontSize
  5567. };
  5568. });
  5569. totalWidth += currentColWidth;
  5570. columnWidths.push(currentColWidth);
  5571. minSize.width += totalWidth;
  5572. }
  5573. }
  5574. me.width = minSize.width;
  5575. me.height = minSize.height;
  5576. },
  5577. afterFit: noop,
  5578. // Shared Methods
  5579. isHorizontal: function() {
  5580. return this.options.position === "top" || this.options.position === "bottom";
  5581. },
  5582. // Actualy draw the legend on the canvas
  5583. draw: function() {
  5584. var me = this;
  5585. var opts = me.options;
  5586. var labelOpts = opts.labels;
  5587. var globalDefault = Chart.defaults.global,
  5588. lineDefault = globalDefault.elements.line,
  5589. legendWidth = me.width,
  5590. lineWidths = me.lineWidths;
  5591. if (opts.display) {
  5592. var ctx = me.ctx,
  5593. cursor,
  5594. itemOrDefault = helpers.getValueOrDefault,
  5595. fontColor = itemOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor),
  5596. fontSize = itemOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize),
  5597. fontStyle = itemOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle),
  5598. fontFamily = itemOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily),
  5599. labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  5600. // Canvas setup
  5601. ctx.textAlign = "left";
  5602. ctx.textBaseline = 'top';
  5603. ctx.lineWidth = 0.5;
  5604. ctx.strokeStyle = fontColor; // for strikethrough effect
  5605. ctx.fillStyle = fontColor; // render in correct colour
  5606. ctx.font = labelFont;
  5607. var boxWidth = labelOpts.boxWidth,
  5608. hitboxes = me.legendHitBoxes;
  5609. // current position
  5610. var drawLegendBox = function(x, y, legendItem) {
  5611. if (isNaN(boxWidth) || boxWidth <= 0) {
  5612. return;
  5613. }
  5614. // Set the ctx for the box
  5615. ctx.save();
  5616. ctx.fillStyle = itemOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
  5617. ctx.lineCap = itemOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
  5618. ctx.lineDashOffset = itemOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
  5619. ctx.lineJoin = itemOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
  5620. ctx.lineWidth = itemOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
  5621. ctx.strokeStyle = itemOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
  5622. var isLineWidthZero = (itemOrDefault(legendItem.lineWidth, lineDefault.borderWidth) === 0);
  5623. if (ctx.setLineDash) {
  5624. // IE 9 and 10 do not support line dash
  5625. ctx.setLineDash(itemOrDefault(legendItem.lineDash, lineDefault.borderDash));
  5626. }
  5627. if (opts.labels && opts.labels.usePointStyle) {
  5628. // Recalulate x and y for drawPoint() because its expecting
  5629. // x and y to be center of figure (instead of top left)
  5630. var radius = fontSize * Math.SQRT2 / 2;
  5631. var offSet = radius / Math.SQRT2;
  5632. var centerX = x + offSet;
  5633. var centerY = y + offSet;
  5634. // Draw pointStyle as legend symbol
  5635. Chart.canvasHelpers.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
  5636. } else {
  5637. // Draw box as legend symbol
  5638. if (!isLineWidthZero) {
  5639. ctx.strokeRect(x, y, boxWidth, fontSize);
  5640. }
  5641. ctx.fillRect(x, y, boxWidth, fontSize);
  5642. }
  5643. ctx.restore();
  5644. };
  5645. var fillText = function(x, y, legendItem, textWidth) {
  5646. ctx.fillText(legendItem.text, boxWidth + (fontSize / 2) + x, y);
  5647. if (legendItem.hidden) {
  5648. // Strikethrough the text if hidden
  5649. ctx.beginPath();
  5650. ctx.lineWidth = 2;
  5651. ctx.moveTo(boxWidth + (fontSize / 2) + x, y + (fontSize / 2));
  5652. ctx.lineTo(boxWidth + (fontSize / 2) + x + textWidth, y + (fontSize / 2));
  5653. ctx.stroke();
  5654. }
  5655. };
  5656. // Horizontal
  5657. var isHorizontal = me.isHorizontal();
  5658. if (isHorizontal) {
  5659. cursor = {
  5660. x: me.left + ((legendWidth - lineWidths[0]) / 2),
  5661. y: me.top + labelOpts.padding,
  5662. line: 0
  5663. };
  5664. } else {
  5665. cursor = {
  5666. x: me.left + labelOpts.padding,
  5667. y: me.top + labelOpts.padding,
  5668. line: 0
  5669. };
  5670. }
  5671. var itemHeight = fontSize + labelOpts.padding;
  5672. helpers.each(me.legendItems, function(legendItem, i) {
  5673. var textWidth = ctx.measureText(legendItem.text).width,
  5674. width = labelOpts.usePointStyle ?
  5675. fontSize + (fontSize / 2) + textWidth :
  5676. boxWidth + (fontSize / 2) + textWidth,
  5677. x = cursor.x,
  5678. y = cursor.y;
  5679. if (isHorizontal) {
  5680. if (x + width >= legendWidth) {
  5681. y = cursor.y += itemHeight;
  5682. cursor.line++;
  5683. x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
  5684. }
  5685. } else {
  5686. if (y + itemHeight > me.bottom) {
  5687. x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
  5688. y = cursor.y = me.top;
  5689. cursor.line++;
  5690. }
  5691. }
  5692. drawLegendBox(x, y, legendItem);
  5693. hitboxes[i].left = x;
  5694. hitboxes[i].top = y;
  5695. // Fill the actual label
  5696. fillText(x, y, legendItem, textWidth);
  5697. if (isHorizontal) {
  5698. cursor.x += width + (labelOpts.padding);
  5699. } else {
  5700. cursor.y += itemHeight;
  5701. }
  5702. });
  5703. }
  5704. },
  5705. // Handle an event
  5706. handleEvent: function(e) {
  5707. var me = this;
  5708. var opts = me.options;
  5709. var type = e.type === 'mouseup' ? 'click' : e.type;
  5710. if (type === 'mousemove') {
  5711. if (!opts.onHover) {
  5712. return;
  5713. }
  5714. } else if (type === 'click') {
  5715. if (!opts.onClick) {
  5716. return;
  5717. }
  5718. } else {
  5719. return;
  5720. }
  5721. var position = helpers.getRelativePosition(e, me.chart.chart),
  5722. x = position.x,
  5723. y = position.y;
  5724. if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
  5725. // See if we are touching one of the dataset boxes
  5726. var lh = me.legendHitBoxes;
  5727. for (var i = 0; i < lh.length; ++i) {
  5728. var hitBox = lh[i];
  5729. if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
  5730. // Touching an element
  5731. if (type === 'click') {
  5732. opts.onClick.call(me, e, me.legendItems[i]);
  5733. break;
  5734. } else if (type === 'mousemove') {
  5735. opts.onHover.call(me, e, me.legendItems[i]);
  5736. break;
  5737. }
  5738. }
  5739. }
  5740. }
  5741. }
  5742. });
  5743. // Register the legend plugin
  5744. Chart.plugins.register({
  5745. beforeInit: function(chartInstance) {
  5746. var opts = chartInstance.options;
  5747. var legendOpts = opts.legend;
  5748. if (legendOpts) {
  5749. chartInstance.legend = new Chart.Legend({
  5750. ctx: chartInstance.chart.ctx,
  5751. options: legendOpts,
  5752. chart: chartInstance
  5753. });
  5754. Chart.layoutService.addBox(chartInstance, chartInstance.legend);
  5755. }
  5756. }
  5757. });
  5758. };
  5759. },{}],30:[function(require,module,exports){
  5760. "use strict";
  5761. module.exports = function(Chart) {
  5762. var noop = Chart.helpers.noop;
  5763. /**
  5764. * The plugin service singleton
  5765. * @namespace Chart.plugins
  5766. * @since 2.1.0
  5767. */
  5768. Chart.plugins = {
  5769. _plugins: [],
  5770. /**
  5771. * Registers the given plugin(s) if not already registered.
  5772. * @param {Array|Object} plugins plugin instance(s).
  5773. */
  5774. register: function(plugins) {
  5775. var p = this._plugins;
  5776. ([]).concat(plugins).forEach(function(plugin) {
  5777. if (p.indexOf(plugin) === -1) {
  5778. p.push(plugin);
  5779. }
  5780. });
  5781. },
  5782. /**
  5783. * Unregisters the given plugin(s) only if registered.
  5784. * @param {Array|Object} plugins plugin instance(s).
  5785. */
  5786. unregister: function(plugins) {
  5787. var p = this._plugins;
  5788. ([]).concat(plugins).forEach(function(plugin) {
  5789. var idx = p.indexOf(plugin);
  5790. if (idx !== -1) {
  5791. p.splice(idx, 1);
  5792. }
  5793. });
  5794. },
  5795. /**
  5796. * Remove all registered p^lugins.
  5797. * @since 2.1.5
  5798. */
  5799. clear: function() {
  5800. this._plugins = [];
  5801. },
  5802. /**
  5803. * Returns the number of registered plugins?
  5804. * @returns {Number}
  5805. * @since 2.1.5
  5806. */
  5807. count: function() {
  5808. return this._plugins.length;
  5809. },
  5810. /**
  5811. * Returns all registered plugin intances.
  5812. * @returns {Array} array of plugin objects.
  5813. * @since 2.1.5
  5814. */
  5815. getAll: function() {
  5816. return this._plugins;
  5817. },
  5818. /**
  5819. * Calls registered plugins on the specified extension, with the given args. This
  5820. * method immediately returns as soon as a plugin explicitly returns false. The
  5821. * returned value can be used, for instance, to interrupt the current action.
  5822. * @param {String} extension the name of the plugin method to call (e.g. 'beforeUpdate').
  5823. * @param {Array} [args] extra arguments to apply to the extension call.
  5824. * @returns {Boolean} false if any of the plugins return false, else returns true.
  5825. */
  5826. notify: function(extension, args) {
  5827. var plugins = this._plugins;
  5828. var ilen = plugins.length;
  5829. var i, plugin;
  5830. for (i=0; i<ilen; ++i) {
  5831. plugin = plugins[i];
  5832. if (typeof plugin[extension] === 'function') {
  5833. if (plugin[extension].apply(plugin, args || []) === false) {
  5834. return false;
  5835. }
  5836. }
  5837. }
  5838. return true;
  5839. }
  5840. };
  5841. /**
  5842. * Plugin extension methods.
  5843. * @interface Chart.PluginBase
  5844. * @since 2.1.0
  5845. */
  5846. Chart.PluginBase = Chart.Element.extend({
  5847. // Called at start of chart init
  5848. beforeInit: noop,
  5849. // Called at end of chart init
  5850. afterInit: noop,
  5851. // Called at start of update
  5852. beforeUpdate: noop,
  5853. // Called at end of update
  5854. afterUpdate: noop,
  5855. // Called at start of draw
  5856. beforeDraw: noop,
  5857. // Called at end of draw
  5858. afterDraw: noop,
  5859. // Called during destroy
  5860. destroy: noop
  5861. });
  5862. /**
  5863. * Provided for backward compatibility, use Chart.plugins instead
  5864. * @namespace Chart.pluginService
  5865. * @deprecated since version 2.1.5
  5866. * @todo remove me at version 3
  5867. */
  5868. Chart.pluginService = Chart.plugins;
  5869. };
  5870. },{}],31:[function(require,module,exports){
  5871. "use strict";
  5872. module.exports = function(Chart) {
  5873. var helpers = Chart.helpers;
  5874. Chart.defaults.scale = {
  5875. display: true,
  5876. position: "left",
  5877. // grid line settings
  5878. gridLines: {
  5879. display: true,
  5880. color: "rgba(0, 0, 0, 0.1)",
  5881. lineWidth: 1,
  5882. drawBorder: true,
  5883. drawOnChartArea: true,
  5884. drawTicks: true,
  5885. tickMarkLength: 10,
  5886. zeroLineWidth: 1,
  5887. zeroLineColor: "rgba(0,0,0,0.25)",
  5888. offsetGridLines: false,
  5889. borderDash: [],
  5890. borderDashOffset: 0.0
  5891. },
  5892. // scale label
  5893. scaleLabel: {
  5894. // actual label
  5895. labelString: '',
  5896. // display property
  5897. display: false
  5898. },
  5899. // label settings
  5900. ticks: {
  5901. beginAtZero: false,
  5902. minRotation: 0,
  5903. maxRotation: 50,
  5904. mirror: false,
  5905. padding: 10,
  5906. reverse: false,
  5907. display: true,
  5908. autoSkip: true,
  5909. autoSkipPadding: 0,
  5910. labelOffset: 0,
  5911. // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
  5912. callback: function(value) {
  5913. return helpers.isArray(value) ? value : '' + value;
  5914. }
  5915. }
  5916. };
  5917. Chart.Scale = Chart.Element.extend({
  5918. // These methods are ordered by lifecyle. Utilities then follow.
  5919. // Any function defined here is inherited by all scale types.
  5920. // Any function can be extended by the scale type
  5921. beforeUpdate: function() {
  5922. helpers.callCallback(this.options.beforeUpdate, [this]);
  5923. },
  5924. update: function(maxWidth, maxHeight, margins) {
  5925. var me = this;
  5926. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  5927. me.beforeUpdate();
  5928. // Absorb the master measurements
  5929. me.maxWidth = maxWidth;
  5930. me.maxHeight = maxHeight;
  5931. me.margins = helpers.extend({
  5932. left: 0,
  5933. right: 0,
  5934. top: 0,
  5935. bottom: 0
  5936. }, margins);
  5937. // Dimensions
  5938. me.beforeSetDimensions();
  5939. me.setDimensions();
  5940. me.afterSetDimensions();
  5941. // Data min/max
  5942. me.beforeDataLimits();
  5943. me.determineDataLimits();
  5944. me.afterDataLimits();
  5945. // Ticks
  5946. me.beforeBuildTicks();
  5947. me.buildTicks();
  5948. me.afterBuildTicks();
  5949. me.beforeTickToLabelConversion();
  5950. me.convertTicksToLabels();
  5951. me.afterTickToLabelConversion();
  5952. // Tick Rotation
  5953. me.beforeCalculateTickRotation();
  5954. me.calculateTickRotation();
  5955. me.afterCalculateTickRotation();
  5956. // Fit
  5957. me.beforeFit();
  5958. me.fit();
  5959. me.afterFit();
  5960. //
  5961. me.afterUpdate();
  5962. return me.minSize;
  5963. },
  5964. afterUpdate: function() {
  5965. helpers.callCallback(this.options.afterUpdate, [this]);
  5966. },
  5967. //
  5968. beforeSetDimensions: function() {
  5969. helpers.callCallback(this.options.beforeSetDimensions, [this]);
  5970. },
  5971. setDimensions: function() {
  5972. var me = this;
  5973. // Set the unconstrained dimension before label rotation
  5974. if (me.isHorizontal()) {
  5975. // Reset position before calculating rotation
  5976. me.width = me.maxWidth;
  5977. me.left = 0;
  5978. me.right = me.width;
  5979. } else {
  5980. me.height = me.maxHeight;
  5981. // Reset position before calculating rotation
  5982. me.top = 0;
  5983. me.bottom = me.height;
  5984. }
  5985. // Reset padding
  5986. me.paddingLeft = 0;
  5987. me.paddingTop = 0;
  5988. me.paddingRight = 0;
  5989. me.paddingBottom = 0;
  5990. },
  5991. afterSetDimensions: function() {
  5992. helpers.callCallback(this.options.afterSetDimensions, [this]);
  5993. },
  5994. // Data limits
  5995. beforeDataLimits: function() {
  5996. helpers.callCallback(this.options.beforeDataLimits, [this]);
  5997. },
  5998. determineDataLimits: helpers.noop,
  5999. afterDataLimits: function() {
  6000. helpers.callCallback(this.options.afterDataLimits, [this]);
  6001. },
  6002. //
  6003. beforeBuildTicks: function() {
  6004. helpers.callCallback(this.options.beforeBuildTicks, [this]);
  6005. },
  6006. buildTicks: helpers.noop,
  6007. afterBuildTicks: function() {
  6008. helpers.callCallback(this.options.afterBuildTicks, [this]);
  6009. },
  6010. beforeTickToLabelConversion: function() {
  6011. helpers.callCallback(this.options.beforeTickToLabelConversion, [this]);
  6012. },
  6013. convertTicksToLabels: function() {
  6014. var me = this;
  6015. // Convert ticks to strings
  6016. me.ticks = me.ticks.map(function(numericalTick, index, ticks) {
  6017. if (me.options.ticks.userCallback) {
  6018. return me.options.ticks.userCallback(numericalTick, index, ticks);
  6019. }
  6020. return me.options.ticks.callback(numericalTick, index, ticks);
  6021. },
  6022. me);
  6023. },
  6024. afterTickToLabelConversion: function() {
  6025. helpers.callCallback(this.options.afterTickToLabelConversion, [this]);
  6026. },
  6027. //
  6028. beforeCalculateTickRotation: function() {
  6029. helpers.callCallback(this.options.beforeCalculateTickRotation, [this]);
  6030. },
  6031. calculateTickRotation: function() {
  6032. var me = this;
  6033. var context = me.ctx;
  6034. var globalDefaults = Chart.defaults.global;
  6035. var optionTicks = me.options.ticks;
  6036. //Get the width of each grid by calculating the difference
  6037. //between x offsets between 0 and 1.
  6038. var tickFontSize = helpers.getValueOrDefault(optionTicks.fontSize, globalDefaults.defaultFontSize);
  6039. var tickFontStyle = helpers.getValueOrDefault(optionTicks.fontStyle, globalDefaults.defaultFontStyle);
  6040. var tickFontFamily = helpers.getValueOrDefault(optionTicks.fontFamily, globalDefaults.defaultFontFamily);
  6041. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  6042. context.font = tickLabelFont;
  6043. var firstWidth = context.measureText(me.ticks[0]).width;
  6044. var lastWidth = context.measureText(me.ticks[me.ticks.length - 1]).width;
  6045. var firstRotated;
  6046. me.labelRotation = optionTicks.minRotation || 0;
  6047. me.paddingRight = 0;
  6048. me.paddingLeft = 0;
  6049. if (me.options.display) {
  6050. if (me.isHorizontal()) {
  6051. me.paddingRight = lastWidth / 2 + 3;
  6052. me.paddingLeft = firstWidth / 2 + 3;
  6053. if (!me.longestTextCache) {
  6054. me.longestTextCache = {};
  6055. }
  6056. var originalLabelWidth = helpers.longestText(context, tickLabelFont, me.ticks, me.longestTextCache);
  6057. var labelWidth = originalLabelWidth;
  6058. var cosRotation;
  6059. var sinRotation;
  6060. // Allow 3 pixels x2 padding either side for label readability
  6061. // only the index matters for a dataset scale, but we want a consistent interface between scales
  6062. var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
  6063. //Max label rotation can be set or default to 90 - also act as a loop counter
  6064. while (labelWidth > tickWidth && me.labelRotation < optionTicks.maxRotation) {
  6065. cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
  6066. sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
  6067. firstRotated = cosRotation * firstWidth;
  6068. // We're right aligning the text now.
  6069. if (firstRotated + tickFontSize / 2 > me.yLabelWidth) {
  6070. me.paddingLeft = firstRotated + tickFontSize / 2;
  6071. }
  6072. me.paddingRight = tickFontSize / 2;
  6073. if (sinRotation * originalLabelWidth > me.maxHeight) {
  6074. // go back one step
  6075. me.labelRotation--;
  6076. break;
  6077. }
  6078. me.labelRotation++;
  6079. labelWidth = cosRotation * originalLabelWidth;
  6080. }
  6081. }
  6082. }
  6083. if (me.margins) {
  6084. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  6085. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  6086. }
  6087. },
  6088. afterCalculateTickRotation: function() {
  6089. helpers.callCallback(this.options.afterCalculateTickRotation, [this]);
  6090. },
  6091. //
  6092. beforeFit: function() {
  6093. helpers.callCallback(this.options.beforeFit, [this]);
  6094. },
  6095. fit: function() {
  6096. var me = this;
  6097. // Reset
  6098. var minSize = me.minSize = {
  6099. width: 0,
  6100. height: 0
  6101. };
  6102. var opts = me.options;
  6103. var globalDefaults = Chart.defaults.global;
  6104. var tickOpts = opts.ticks;
  6105. var scaleLabelOpts = opts.scaleLabel;
  6106. var gridLineOpts = opts.gridLines;
  6107. var display = opts.display;
  6108. var isHorizontal = me.isHorizontal();
  6109. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  6110. var tickFontStyle = helpers.getValueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  6111. var tickFontFamily = helpers.getValueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  6112. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  6113. var scaleLabelFontSize = helpers.getValueOrDefault(scaleLabelOpts.fontSize, globalDefaults.defaultFontSize);
  6114. var tickMarkLength = opts.gridLines.tickMarkLength;
  6115. // Width
  6116. if (isHorizontal) {
  6117. // subtract the margins to line up with the chartArea if we are a full width scale
  6118. minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
  6119. } else {
  6120. minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6121. }
  6122. // height
  6123. if (isHorizontal) {
  6124. minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6125. } else {
  6126. minSize.height = me.maxHeight; // fill all the height
  6127. }
  6128. // Are we showing a title for the scale?
  6129. if (scaleLabelOpts.display && display) {
  6130. if (isHorizontal) {
  6131. minSize.height += (scaleLabelFontSize * 1.5);
  6132. } else {
  6133. minSize.width += (scaleLabelFontSize * 1.5);
  6134. }
  6135. }
  6136. if (tickOpts.display && display) {
  6137. // Don't bother fitting the ticks if we are not showing them
  6138. if (!me.longestTextCache) {
  6139. me.longestTextCache = {};
  6140. }
  6141. var largestTextWidth = helpers.longestText(me.ctx, tickLabelFont, me.ticks, me.longestTextCache);
  6142. var tallestLabelHeightInLines = helpers.numberOfLabelLines(me.ticks);
  6143. var lineSpace = tickFontSize * 0.5;
  6144. if (isHorizontal) {
  6145. // A horizontal axis is more constrained by the height.
  6146. me.longestLabelWidth = largestTextWidth;
  6147. // TODO - improve this calculation
  6148. var labelHeight = (Math.sin(helpers.toRadians(me.labelRotation)) * me.longestLabelWidth) + (tickFontSize * tallestLabelHeightInLines) + (lineSpace * tallestLabelHeightInLines);
  6149. minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight);
  6150. me.ctx.font = tickLabelFont;
  6151. var firstLabelWidth = me.ctx.measureText(me.ticks[0]).width;
  6152. var lastLabelWidth = me.ctx.measureText(me.ticks[me.ticks.length - 1]).width;
  6153. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
  6154. // by the font height
  6155. var cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
  6156. var sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
  6157. me.paddingLeft = me.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  6158. me.paddingRight = me.labelRotation !== 0 ? (sinRotation * (tickFontSize / 2)) + 3 : lastLabelWidth / 2 + 3; // when rotated
  6159. } else {
  6160. // A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first
  6161. var maxLabelWidth = me.maxWidth - minSize.width;
  6162. // Account for padding
  6163. var mirror = tickOpts.mirror;
  6164. if (!mirror) {
  6165. largestTextWidth += me.options.ticks.padding;
  6166. } else {
  6167. // If mirrored text is on the inside so don't expand
  6168. largestTextWidth = 0;
  6169. }
  6170. if (largestTextWidth < maxLabelWidth) {
  6171. // We don't need all the room
  6172. minSize.width += largestTextWidth;
  6173. } else {
  6174. // Expand to max size
  6175. minSize.width = me.maxWidth;
  6176. }
  6177. me.paddingTop = tickFontSize / 2;
  6178. me.paddingBottom = tickFontSize / 2;
  6179. }
  6180. }
  6181. if (me.margins) {
  6182. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  6183. me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
  6184. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  6185. me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
  6186. }
  6187. me.width = minSize.width;
  6188. me.height = minSize.height;
  6189. },
  6190. afterFit: function() {
  6191. helpers.callCallback(this.options.afterFit, [this]);
  6192. },
  6193. // Shared Methods
  6194. isHorizontal: function() {
  6195. return this.options.position === "top" || this.options.position === "bottom";
  6196. },
  6197. isFullWidth: function() {
  6198. return (this.options.fullWidth);
  6199. },
  6200. // 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
  6201. getRightValue: function(rawValue) {
  6202. // Null and undefined values first
  6203. if (rawValue === null || typeof(rawValue) === 'undefined') {
  6204. return NaN;
  6205. }
  6206. // isNaN(object) returns true, so make sure NaN is checking for a number
  6207. if (typeof(rawValue) === 'number' && isNaN(rawValue)) {
  6208. return NaN;
  6209. }
  6210. // If it is in fact an object, dive in one more level
  6211. if (typeof(rawValue) === "object") {
  6212. if ((rawValue instanceof Date) || (rawValue.isValid)) {
  6213. return rawValue;
  6214. } else {
  6215. return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
  6216. }
  6217. }
  6218. // Value is good, return it
  6219. return rawValue;
  6220. },
  6221. // Used to get the value to display in the tooltip for the data at the given index
  6222. // function getLabelForIndex(index, datasetIndex)
  6223. getLabelForIndex: helpers.noop,
  6224. // Used to get data value locations. Value can either be an index or a numerical value
  6225. getPixelForValue: helpers.noop,
  6226. // Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  6227. getValueForPixel: helpers.noop,
  6228. // Used for tick location, should
  6229. getPixelForTick: function(index, includeOffset) {
  6230. var me = this;
  6231. if (me.isHorizontal()) {
  6232. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6233. var tickWidth = innerWidth / Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  6234. var pixel = (tickWidth * index) + me.paddingLeft;
  6235. if (includeOffset) {
  6236. pixel += tickWidth / 2;
  6237. }
  6238. var finalVal = me.left + Math.round(pixel);
  6239. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6240. return finalVal;
  6241. } else {
  6242. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  6243. return me.top + (index * (innerHeight / (me.ticks.length - 1)));
  6244. }
  6245. },
  6246. // Utility for getting the pixel location of a percentage of scale
  6247. getPixelForDecimal: function(decimal /*, includeOffset*/ ) {
  6248. var me = this;
  6249. if (me.isHorizontal()) {
  6250. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6251. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  6252. var finalVal = me.left + Math.round(valueOffset);
  6253. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6254. return finalVal;
  6255. } else {
  6256. return me.top + (decimal * me.height);
  6257. }
  6258. },
  6259. getBasePixel: function() {
  6260. var me = this;
  6261. var min = me.min;
  6262. var max = me.max;
  6263. return me.getPixelForValue(
  6264. me.beginAtZero? 0:
  6265. min < 0 && max < 0? max :
  6266. min > 0 && max > 0? min :
  6267. 0);
  6268. },
  6269. // Actualy draw the scale on the canvas
  6270. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  6271. draw: function(chartArea) {
  6272. var me = this;
  6273. var options = me.options;
  6274. if (!options.display) {
  6275. return;
  6276. }
  6277. var context = me.ctx;
  6278. var globalDefaults = Chart.defaults.global;
  6279. var optionTicks = options.ticks;
  6280. var gridLines = options.gridLines;
  6281. var scaleLabel = options.scaleLabel;
  6282. var isRotated = me.labelRotation !== 0;
  6283. var skipRatio;
  6284. var useAutoskipper = optionTicks.autoSkip;
  6285. var isHorizontal = me.isHorizontal();
  6286. // figure out the maximum number of gridlines to show
  6287. var maxTicks;
  6288. if (optionTicks.maxTicksLimit) {
  6289. maxTicks = optionTicks.maxTicksLimit;
  6290. }
  6291. var tickFontColor = helpers.getValueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
  6292. var tickFontSize = helpers.getValueOrDefault(optionTicks.fontSize, globalDefaults.defaultFontSize);
  6293. var tickFontStyle = helpers.getValueOrDefault(optionTicks.fontStyle, globalDefaults.defaultFontStyle);
  6294. var tickFontFamily = helpers.getValueOrDefault(optionTicks.fontFamily, globalDefaults.defaultFontFamily);
  6295. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  6296. var tl = gridLines.tickMarkLength;
  6297. var borderDash = helpers.getValueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
  6298. var borderDashOffset = helpers.getValueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
  6299. var scaleLabelFontColor = helpers.getValueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
  6300. var scaleLabelFontSize = helpers.getValueOrDefault(scaleLabel.fontSize, globalDefaults.defaultFontSize);
  6301. var scaleLabelFontStyle = helpers.getValueOrDefault(scaleLabel.fontStyle, globalDefaults.defaultFontStyle);
  6302. var scaleLabelFontFamily = helpers.getValueOrDefault(scaleLabel.fontFamily, globalDefaults.defaultFontFamily);
  6303. var scaleLabelFont = helpers.fontString(scaleLabelFontSize, scaleLabelFontStyle, scaleLabelFontFamily);
  6304. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6305. var cosRotation = Math.cos(labelRotationRadians);
  6306. var longestRotatedLabel = me.longestLabelWidth * cosRotation;
  6307. // Make sure we draw text in the correct color and font
  6308. context.fillStyle = tickFontColor;
  6309. var itemsToDraw = [];
  6310. if (isHorizontal) {
  6311. skipRatio = false;
  6312. // Only calculate the skip ratio with the half width of longestRotateLabel if we got an actual rotation
  6313. // See #2584
  6314. if (isRotated) {
  6315. longestRotatedLabel /= 2;
  6316. }
  6317. if ((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length > (me.width - (me.paddingLeft + me.paddingRight))) {
  6318. skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length) / (me.width - (me.paddingLeft + me.paddingRight)));
  6319. }
  6320. // if they defined a max number of optionTicks,
  6321. // increase skipRatio until that number is met
  6322. if (maxTicks && me.ticks.length > maxTicks) {
  6323. while (!skipRatio || me.ticks.length / (skipRatio || 1) > maxTicks) {
  6324. if (!skipRatio) {
  6325. skipRatio = 1;
  6326. }
  6327. skipRatio += 1;
  6328. }
  6329. }
  6330. if (!useAutoskipper) {
  6331. skipRatio = false;
  6332. }
  6333. }
  6334. var xTickStart = options.position === "right" ? me.left : me.right - tl;
  6335. var xTickEnd = options.position === "right" ? me.left + tl : me.right;
  6336. var yTickStart = options.position === "bottom" ? me.top : me.bottom - tl;
  6337. var yTickEnd = options.position === "bottom" ? me.top + tl : me.bottom;
  6338. helpers.each(me.ticks, function(label, index) {
  6339. // If the callback returned a null or undefined value, do not draw this line
  6340. if (label === undefined || label === null) {
  6341. return;
  6342. }
  6343. var isLastTick = me.ticks.length === index + 1;
  6344. // Since we always show the last tick,we need may need to hide the last shown one before
  6345. var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= me.ticks.length);
  6346. if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
  6347. return;
  6348. }
  6349. var lineWidth, lineColor;
  6350. if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
  6351. // Draw the first index specially
  6352. lineWidth = gridLines.zeroLineWidth;
  6353. lineColor = gridLines.zeroLineColor;
  6354. } else {
  6355. lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index);
  6356. lineColor = helpers.getValueAtIndexOrDefault(gridLines.color, index);
  6357. }
  6358. // Common properties
  6359. var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
  6360. var textAlign, textBaseline = 'middle';
  6361. if (isHorizontal) {
  6362. if (!isRotated) {
  6363. textBaseline = options.position === 'top' ? 'bottom' : 'top';
  6364. }
  6365. textAlign = isRotated ? 'right' : 'center';
  6366. var xLineValue = me.getPixelForTick(index) + helpers.aliasPixel(lineWidth); // xvalues for grid lines
  6367. labelX = me.getPixelForTick(index, gridLines.offsetGridLines) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
  6368. labelY = (isRotated) ? me.top + 12 : options.position === 'top' ? me.bottom - tl : me.top + tl;
  6369. tx1 = tx2 = x1 = x2 = xLineValue;
  6370. ty1 = yTickStart;
  6371. ty2 = yTickEnd;
  6372. y1 = chartArea.top;
  6373. y2 = chartArea.bottom;
  6374. } else {
  6375. if (options.position === 'left') {
  6376. if (optionTicks.mirror) {
  6377. labelX = me.right + optionTicks.padding;
  6378. textAlign = 'left';
  6379. } else {
  6380. labelX = me.right - optionTicks.padding;
  6381. textAlign = 'right';
  6382. }
  6383. } else {
  6384. // right side
  6385. if (optionTicks.mirror) {
  6386. labelX = me.left - optionTicks.padding;
  6387. textAlign = 'right';
  6388. } else {
  6389. labelX = me.left + optionTicks.padding;
  6390. textAlign = 'left';
  6391. }
  6392. }
  6393. var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
  6394. yLineValue += helpers.aliasPixel(lineWidth);
  6395. labelY = me.getPixelForTick(index, gridLines.offsetGridLines);
  6396. tx1 = xTickStart;
  6397. tx2 = xTickEnd;
  6398. x1 = chartArea.left;
  6399. x2 = chartArea.right;
  6400. ty1 = ty2 = y1 = y2 = yLineValue;
  6401. }
  6402. itemsToDraw.push({
  6403. tx1: tx1,
  6404. ty1: ty1,
  6405. tx2: tx2,
  6406. ty2: ty2,
  6407. x1: x1,
  6408. y1: y1,
  6409. x2: x2,
  6410. y2: y2,
  6411. labelX: labelX,
  6412. labelY: labelY,
  6413. glWidth: lineWidth,
  6414. glColor: lineColor,
  6415. glBorderDash: borderDash,
  6416. glBorderDashOffset: borderDashOffset,
  6417. rotation: -1 * labelRotationRadians,
  6418. label: label,
  6419. textBaseline: textBaseline,
  6420. textAlign: textAlign
  6421. });
  6422. });
  6423. // Draw all of the tick labels, tick marks, and grid lines at the correct places
  6424. helpers.each(itemsToDraw, function(itemToDraw) {
  6425. if (gridLines.display) {
  6426. context.save();
  6427. context.lineWidth = itemToDraw.glWidth;
  6428. context.strokeStyle = itemToDraw.glColor;
  6429. if (context.setLineDash) {
  6430. context.setLineDash(itemToDraw.glBorderDash);
  6431. context.lineDashOffset = itemToDraw.glBorderDashOffset;
  6432. }
  6433. context.beginPath();
  6434. if (gridLines.drawTicks) {
  6435. context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
  6436. context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
  6437. }
  6438. if (gridLines.drawOnChartArea) {
  6439. context.moveTo(itemToDraw.x1, itemToDraw.y1);
  6440. context.lineTo(itemToDraw.x2, itemToDraw.y2);
  6441. }
  6442. context.stroke();
  6443. context.restore();
  6444. }
  6445. if (optionTicks.display) {
  6446. context.save();
  6447. context.translate(itemToDraw.labelX, itemToDraw.labelY);
  6448. context.rotate(itemToDraw.rotation);
  6449. context.font = tickLabelFont;
  6450. context.textBaseline = itemToDraw.textBaseline;
  6451. context.textAlign = itemToDraw.textAlign;
  6452. var label = itemToDraw.label;
  6453. if (helpers.isArray(label)) {
  6454. for (var i = 0, y = -(label.length - 1)*tickFontSize*0.75; i < label.length; ++i) {
  6455. // We just make sure the multiline element is a string here..
  6456. context.fillText('' + label[i], 0, y);
  6457. // apply same lineSpacing as calculated @ L#320
  6458. y += (tickFontSize * 1.5);
  6459. }
  6460. } else {
  6461. context.fillText(label, 0, 0);
  6462. }
  6463. context.restore();
  6464. }
  6465. });
  6466. if (scaleLabel.display) {
  6467. // Draw the scale label
  6468. var scaleLabelX;
  6469. var scaleLabelY;
  6470. var rotation = 0;
  6471. if (isHorizontal) {
  6472. scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
  6473. scaleLabelY = options.position === 'bottom' ? me.bottom - (scaleLabelFontSize / 2) : me.top + (scaleLabelFontSize / 2);
  6474. } else {
  6475. var isLeft = options.position === 'left';
  6476. scaleLabelX = isLeft ? me.left + (scaleLabelFontSize / 2) : me.right - (scaleLabelFontSize / 2);
  6477. scaleLabelY = me.top + ((me.bottom - me.top) / 2);
  6478. rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
  6479. }
  6480. context.save();
  6481. context.translate(scaleLabelX, scaleLabelY);
  6482. context.rotate(rotation);
  6483. context.textAlign = 'center';
  6484. context.textBaseline = 'middle';
  6485. context.fillStyle = scaleLabelFontColor; // render in correct colour
  6486. context.font = scaleLabelFont;
  6487. context.fillText(scaleLabel.labelString, 0, 0);
  6488. context.restore();
  6489. }
  6490. if (gridLines.drawBorder) {
  6491. // Draw the line at the edge of the axis
  6492. context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, 0);
  6493. context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, 0);
  6494. var x1 = me.left,
  6495. x2 = me.right,
  6496. y1 = me.top,
  6497. y2 = me.bottom;
  6498. var aliasPixel = helpers.aliasPixel(context.lineWidth);
  6499. if (isHorizontal) {
  6500. y1 = y2 = options.position === 'top' ? me.bottom : me.top;
  6501. y1 += aliasPixel;
  6502. y2 += aliasPixel;
  6503. } else {
  6504. x1 = x2 = options.position === 'left' ? me.right : me.left;
  6505. x1 += aliasPixel;
  6506. x2 += aliasPixel;
  6507. }
  6508. context.beginPath();
  6509. context.moveTo(x1, y1);
  6510. context.lineTo(x2, y2);
  6511. context.stroke();
  6512. }
  6513. }
  6514. });
  6515. };
  6516. },{}],32:[function(require,module,exports){
  6517. "use strict";
  6518. module.exports = function(Chart) {
  6519. var helpers = Chart.helpers;
  6520. Chart.scaleService = {
  6521. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  6522. // use the new chart options to grab the correct scale
  6523. constructors: {},
  6524. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  6525. // old browsers
  6526. // Scale config defaults
  6527. defaults: {},
  6528. registerScaleType: function(type, scaleConstructor, defaults) {
  6529. this.constructors[type] = scaleConstructor;
  6530. this.defaults[type] = helpers.clone(defaults);
  6531. },
  6532. getScaleConstructor: function(type) {
  6533. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  6534. },
  6535. getScaleDefaults: function(type) {
  6536. // Return the scale defaults merged with the global settings so that we always use the latest ones
  6537. return this.defaults.hasOwnProperty(type) ? helpers.scaleMerge(Chart.defaults.scale, this.defaults[type]) : {};
  6538. },
  6539. updateScaleDefaults: function(type, additions) {
  6540. var defaults = this.defaults;
  6541. if (defaults.hasOwnProperty(type)) {
  6542. defaults[type] = helpers.extend(defaults[type], additions);
  6543. }
  6544. },
  6545. addScalesToLayout: function(chartInstance) {
  6546. // Adds each scale to the chart.boxes array to be sized accordingly
  6547. helpers.each(chartInstance.scales, function(scale) {
  6548. Chart.layoutService.addBox(chartInstance, scale);
  6549. });
  6550. }
  6551. };
  6552. };
  6553. },{}],33:[function(require,module,exports){
  6554. "use strict";
  6555. module.exports = function(Chart) {
  6556. var helpers = Chart.helpers;
  6557. Chart.defaults.global.title = {
  6558. display: false,
  6559. position: 'top',
  6560. fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
  6561. fontStyle: 'bold',
  6562. padding: 10,
  6563. // actual title
  6564. text: ''
  6565. };
  6566. var noop = helpers.noop;
  6567. Chart.Title = Chart.Element.extend({
  6568. initialize: function(config) {
  6569. var me = this;
  6570. helpers.extend(me, config);
  6571. me.options = helpers.configMerge(Chart.defaults.global.title, config.options);
  6572. // Contains hit boxes for each dataset (in dataset order)
  6573. me.legendHitBoxes = [];
  6574. },
  6575. // These methods are ordered by lifecyle. Utilities then follow.
  6576. beforeUpdate: function () {
  6577. var chartOpts = this.chart.options;
  6578. if (chartOpts && chartOpts.title) {
  6579. this.options = helpers.configMerge(Chart.defaults.global.title, chartOpts.title);
  6580. }
  6581. },
  6582. update: function(maxWidth, maxHeight, margins) {
  6583. var me = this;
  6584. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  6585. me.beforeUpdate();
  6586. // Absorb the master measurements
  6587. me.maxWidth = maxWidth;
  6588. me.maxHeight = maxHeight;
  6589. me.margins = margins;
  6590. // Dimensions
  6591. me.beforeSetDimensions();
  6592. me.setDimensions();
  6593. me.afterSetDimensions();
  6594. // Labels
  6595. me.beforeBuildLabels();
  6596. me.buildLabels();
  6597. me.afterBuildLabels();
  6598. // Fit
  6599. me.beforeFit();
  6600. me.fit();
  6601. me.afterFit();
  6602. //
  6603. me.afterUpdate();
  6604. return me.minSize;
  6605. },
  6606. afterUpdate: noop,
  6607. //
  6608. beforeSetDimensions: noop,
  6609. setDimensions: function() {
  6610. var me = this;
  6611. // Set the unconstrained dimension before label rotation
  6612. if (me.isHorizontal()) {
  6613. // Reset position before calculating rotation
  6614. me.width = me.maxWidth;
  6615. me.left = 0;
  6616. me.right = me.width;
  6617. } else {
  6618. me.height = me.maxHeight;
  6619. // Reset position before calculating rotation
  6620. me.top = 0;
  6621. me.bottom = me.height;
  6622. }
  6623. // Reset padding
  6624. me.paddingLeft = 0;
  6625. me.paddingTop = 0;
  6626. me.paddingRight = 0;
  6627. me.paddingBottom = 0;
  6628. // Reset minSize
  6629. me.minSize = {
  6630. width: 0,
  6631. height: 0
  6632. };
  6633. },
  6634. afterSetDimensions: noop,
  6635. //
  6636. beforeBuildLabels: noop,
  6637. buildLabels: noop,
  6638. afterBuildLabels: noop,
  6639. //
  6640. beforeFit: noop,
  6641. fit: function() {
  6642. var me = this,
  6643. valueOrDefault = helpers.getValueOrDefault,
  6644. opts = me.options,
  6645. globalDefaults = Chart.defaults.global,
  6646. display = opts.display,
  6647. fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
  6648. minSize = me.minSize;
  6649. if (me.isHorizontal()) {
  6650. minSize.width = me.maxWidth; // fill all the width
  6651. minSize.height = display ? fontSize + (opts.padding * 2) : 0;
  6652. } else {
  6653. minSize.width = display ? fontSize + (opts.padding * 2) : 0;
  6654. minSize.height = me.maxHeight; // fill all the height
  6655. }
  6656. me.width = minSize.width;
  6657. me.height = minSize.height;
  6658. },
  6659. afterFit: noop,
  6660. // Shared Methods
  6661. isHorizontal: function() {
  6662. var pos = this.options.position;
  6663. return pos === "top" || pos === "bottom";
  6664. },
  6665. // Actualy draw the title block on the canvas
  6666. draw: function() {
  6667. var me = this,
  6668. ctx = me.ctx,
  6669. valueOrDefault = helpers.getValueOrDefault,
  6670. opts = me.options,
  6671. globalDefaults = Chart.defaults.global;
  6672. if (opts.display) {
  6673. var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
  6674. fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle),
  6675. fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily),
  6676. titleFont = helpers.fontString(fontSize, fontStyle, fontFamily),
  6677. rotation = 0,
  6678. titleX,
  6679. titleY,
  6680. top = me.top,
  6681. left = me.left,
  6682. bottom = me.bottom,
  6683. right = me.right;
  6684. ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
  6685. ctx.font = titleFont;
  6686. // Horizontal
  6687. if (me.isHorizontal()) {
  6688. titleX = left + ((right - left) / 2); // midpoint of the width
  6689. titleY = top + ((bottom - top) / 2); // midpoint of the height
  6690. } else {
  6691. titleX = opts.position === 'left' ? left + (fontSize / 2) : right - (fontSize / 2);
  6692. titleY = top + ((bottom - top) / 2);
  6693. rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
  6694. }
  6695. ctx.save();
  6696. ctx.translate(titleX, titleY);
  6697. ctx.rotate(rotation);
  6698. ctx.textAlign = 'center';
  6699. ctx.textBaseline = 'middle';
  6700. ctx.fillText(opts.text, 0, 0);
  6701. ctx.restore();
  6702. }
  6703. }
  6704. });
  6705. // Register the title plugin
  6706. Chart.plugins.register({
  6707. beforeInit: function(chartInstance) {
  6708. var opts = chartInstance.options;
  6709. var titleOpts = opts.title;
  6710. if (titleOpts) {
  6711. chartInstance.titleBlock = new Chart.Title({
  6712. ctx: chartInstance.chart.ctx,
  6713. options: titleOpts,
  6714. chart: chartInstance
  6715. });
  6716. Chart.layoutService.addBox(chartInstance, chartInstance.titleBlock);
  6717. }
  6718. }
  6719. });
  6720. };
  6721. },{}],34:[function(require,module,exports){
  6722. "use strict";
  6723. module.exports = function(Chart) {
  6724. var helpers = Chart.helpers;
  6725. Chart.defaults.global.tooltips = {
  6726. enabled: true,
  6727. custom: null,
  6728. mode: 'single',
  6729. backgroundColor: "rgba(0,0,0,0.8)",
  6730. titleFontStyle: "bold",
  6731. titleSpacing: 2,
  6732. titleMarginBottom: 6,
  6733. titleFontColor: "#fff",
  6734. titleAlign: "left",
  6735. bodySpacing: 2,
  6736. bodyFontColor: "#fff",
  6737. bodyAlign: "left",
  6738. footerFontStyle: "bold",
  6739. footerSpacing: 2,
  6740. footerMarginTop: 6,
  6741. footerFontColor: "#fff",
  6742. footerAlign: "left",
  6743. yPadding: 6,
  6744. xPadding: 6,
  6745. yAlign : 'center',
  6746. xAlign : 'center',
  6747. caretSize: 5,
  6748. cornerRadius: 6,
  6749. multiKeyBackground: '#fff',
  6750. callbacks: {
  6751. // Args are: (tooltipItems, data)
  6752. beforeTitle: helpers.noop,
  6753. title: function(tooltipItems, data) {
  6754. // Pick first xLabel for now
  6755. var title = '';
  6756. var labels = data.labels;
  6757. var labelCount = labels ? labels.length : 0;
  6758. if (tooltipItems.length > 0) {
  6759. var item = tooltipItems[0];
  6760. if (item.xLabel) {
  6761. title = item.xLabel;
  6762. } else if (labelCount > 0 && item.index < labelCount) {
  6763. title = labels[item.index];
  6764. }
  6765. }
  6766. return title;
  6767. },
  6768. afterTitle: helpers.noop,
  6769. // Args are: (tooltipItems, data)
  6770. beforeBody: helpers.noop,
  6771. // Args are: (tooltipItem, data)
  6772. beforeLabel: helpers.noop,
  6773. label: function(tooltipItem, data) {
  6774. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  6775. return datasetLabel + ': ' + tooltipItem.yLabel;
  6776. },
  6777. labelColor: function(tooltipItem, chartInstance) {
  6778. var meta = chartInstance.getDatasetMeta(tooltipItem.datasetIndex);
  6779. var activeElement = meta.data[tooltipItem.index];
  6780. var view = activeElement._view;
  6781. return {
  6782. borderColor: view.borderColor,
  6783. backgroundColor: view.backgroundColor
  6784. };
  6785. },
  6786. afterLabel: helpers.noop,
  6787. // Args are: (tooltipItems, data)
  6788. afterBody: helpers.noop,
  6789. // Args are: (tooltipItems, data)
  6790. beforeFooter: helpers.noop,
  6791. footer: helpers.noop,
  6792. afterFooter: helpers.noop
  6793. }
  6794. };
  6795. // Helper to push or concat based on if the 2nd parameter is an array or not
  6796. function pushOrConcat(base, toPush) {
  6797. if (toPush) {
  6798. if (helpers.isArray(toPush)) {
  6799. //base = base.concat(toPush);
  6800. Array.prototype.push.apply(base, toPush);
  6801. } else {
  6802. base.push(toPush);
  6803. }
  6804. }
  6805. return base;
  6806. }
  6807. function getAveragePosition(elements) {
  6808. if (!elements.length) {
  6809. return false;
  6810. }
  6811. var i, len;
  6812. var xPositions = [];
  6813. var yPositions = [];
  6814. for (i = 0, len = elements.length; i < len; ++i) {
  6815. var el = elements[i];
  6816. if (el && el.hasValue()){
  6817. var pos = el.tooltipPosition();
  6818. xPositions.push(pos.x);
  6819. yPositions.push(pos.y);
  6820. }
  6821. }
  6822. var x = 0,
  6823. y = 0;
  6824. for (i = 0; i < xPositions.length; ++i) {
  6825. if (xPositions[ i ]) {
  6826. x += xPositions[i];
  6827. y += yPositions[i];
  6828. }
  6829. }
  6830. return {
  6831. x: Math.round(x / xPositions.length),
  6832. y: Math.round(y / xPositions.length)
  6833. };
  6834. }
  6835. // Private helper to create a tooltip iteam model
  6836. // @param element : the chart element (point, arc, bar) to create the tooltip item for
  6837. // @return : new tooltip item
  6838. function createTooltipItem(element) {
  6839. var xScale = element._xScale;
  6840. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  6841. var index = element._index,
  6842. datasetIndex = element._datasetIndex;
  6843. return {
  6844. xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
  6845. yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
  6846. index: index,
  6847. datasetIndex: datasetIndex
  6848. };
  6849. }
  6850. Chart.Tooltip = Chart.Element.extend({
  6851. initialize: function() {
  6852. var me = this;
  6853. var globalDefaults = Chart.defaults.global;
  6854. var tooltipOpts = me._options;
  6855. var getValueOrDefault = helpers.getValueOrDefault;
  6856. helpers.extend(me, {
  6857. _model: {
  6858. // Positioning
  6859. xPadding: tooltipOpts.xPadding,
  6860. yPadding: tooltipOpts.yPadding,
  6861. xAlign : tooltipOpts.xAlign,
  6862. yAlign : tooltipOpts.yAlign,
  6863. // Body
  6864. bodyFontColor: tooltipOpts.bodyFontColor,
  6865. _bodyFontFamily: getValueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
  6866. _bodyFontStyle: getValueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
  6867. _bodyAlign: tooltipOpts.bodyAlign,
  6868. bodyFontSize: getValueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
  6869. bodySpacing: tooltipOpts.bodySpacing,
  6870. // Title
  6871. titleFontColor: tooltipOpts.titleFontColor,
  6872. _titleFontFamily: getValueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
  6873. _titleFontStyle: getValueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
  6874. titleFontSize: getValueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
  6875. _titleAlign: tooltipOpts.titleAlign,
  6876. titleSpacing: tooltipOpts.titleSpacing,
  6877. titleMarginBottom: tooltipOpts.titleMarginBottom,
  6878. // Footer
  6879. footerFontColor: tooltipOpts.footerFontColor,
  6880. _footerFontFamily: getValueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
  6881. _footerFontStyle: getValueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
  6882. footerFontSize: getValueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
  6883. _footerAlign: tooltipOpts.footerAlign,
  6884. footerSpacing: tooltipOpts.footerSpacing,
  6885. footerMarginTop: tooltipOpts.footerMarginTop,
  6886. // Appearance
  6887. caretSize: tooltipOpts.caretSize,
  6888. cornerRadius: tooltipOpts.cornerRadius,
  6889. backgroundColor: tooltipOpts.backgroundColor,
  6890. opacity: 0,
  6891. legendColorBackground: tooltipOpts.multiKeyBackground
  6892. }
  6893. });
  6894. },
  6895. // Get the title
  6896. // Args are: (tooltipItem, data)
  6897. getTitle: function() {
  6898. var me = this;
  6899. var opts = me._options;
  6900. var callbacks = opts.callbacks;
  6901. var beforeTitle = callbacks.beforeTitle.apply(me, arguments),
  6902. title = callbacks.title.apply(me, arguments),
  6903. afterTitle = callbacks.afterTitle.apply(me, arguments);
  6904. var lines = [];
  6905. lines = pushOrConcat(lines, beforeTitle);
  6906. lines = pushOrConcat(lines, title);
  6907. lines = pushOrConcat(lines, afterTitle);
  6908. return lines;
  6909. },
  6910. // Args are: (tooltipItem, data)
  6911. getBeforeBody: function() {
  6912. var lines = this._options.callbacks.beforeBody.apply(this, arguments);
  6913. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  6914. },
  6915. // Args are: (tooltipItem, data)
  6916. getBody: function(tooltipItems, data) {
  6917. var me = this;
  6918. var callbacks = me._options.callbacks;
  6919. var bodyItems = [];
  6920. helpers.each(tooltipItems, function(tooltipItem) {
  6921. var bodyItem = {
  6922. before: [],
  6923. lines: [],
  6924. after: []
  6925. };
  6926. pushOrConcat(bodyItem.before, callbacks.beforeLabel.call(me, tooltipItem, data));
  6927. pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
  6928. pushOrConcat(bodyItem.after, callbacks.afterLabel.call(me, tooltipItem, data));
  6929. bodyItems.push(bodyItem);
  6930. });
  6931. return bodyItems;
  6932. },
  6933. // Args are: (tooltipItem, data)
  6934. getAfterBody: function() {
  6935. var lines = this._options.callbacks.afterBody.apply(this, arguments);
  6936. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  6937. },
  6938. // Get the footer and beforeFooter and afterFooter lines
  6939. // Args are: (tooltipItem, data)
  6940. getFooter: function() {
  6941. var me = this;
  6942. var callbacks = me._options.callbacks;
  6943. var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
  6944. var footer = callbacks.footer.apply(me, arguments);
  6945. var afterFooter = callbacks.afterFooter.apply(me, arguments);
  6946. var lines = [];
  6947. lines = pushOrConcat(lines, beforeFooter);
  6948. lines = pushOrConcat(lines, footer);
  6949. lines = pushOrConcat(lines, afterFooter);
  6950. return lines;
  6951. },
  6952. update: function(changed) {
  6953. var me = this;
  6954. var opts = me._options;
  6955. var model = me._model;
  6956. var active = me._active;
  6957. var data = me._data;
  6958. var chartInstance = me._chartInstance;
  6959. var i, len;
  6960. if (active.length) {
  6961. model.opacity = 1;
  6962. var labelColors = [],
  6963. tooltipPosition = getAveragePosition(active);
  6964. var tooltipItems = [];
  6965. for (i = 0, len = active.length; i < len; ++i) {
  6966. tooltipItems.push(createTooltipItem(active[i]));
  6967. }
  6968. // If the user provided a sorting function, use it to modify the tooltip items
  6969. if (opts.itemSort) {
  6970. tooltipItems = tooltipItems.sort(function(a,b) {
  6971. return opts.itemSort(a,b, data);
  6972. });
  6973. }
  6974. // If there is more than one item, show color items
  6975. if (active.length > 1) {
  6976. helpers.each(tooltipItems, function(tooltipItem) {
  6977. labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, chartInstance));
  6978. });
  6979. }
  6980. // Build the Text Lines
  6981. helpers.extend(model, {
  6982. title: me.getTitle(tooltipItems, data),
  6983. beforeBody: me.getBeforeBody(tooltipItems, data),
  6984. body: me.getBody(tooltipItems, data),
  6985. afterBody: me.getAfterBody(tooltipItems, data),
  6986. footer: me.getFooter(tooltipItems, data),
  6987. x: Math.round(tooltipPosition.x),
  6988. y: Math.round(tooltipPosition.y),
  6989. caretPadding: helpers.getValueOrDefault(tooltipPosition.padding, 2),
  6990. labelColors: labelColors
  6991. });
  6992. // We need to determine alignment of
  6993. var tooltipSize = me.getTooltipSize(model);
  6994. me.determineAlignment(tooltipSize); // Smart Tooltip placement to stay on the canvas
  6995. helpers.extend(model, me.getBackgroundPoint(model, tooltipSize));
  6996. } else {
  6997. me._model.opacity = 0;
  6998. }
  6999. if (changed && opts.custom) {
  7000. opts.custom.call(me, model);
  7001. }
  7002. return me;
  7003. },
  7004. getTooltipSize: function(vm) {
  7005. var ctx = this._chart.ctx;
  7006. var size = {
  7007. height: vm.yPadding * 2, // Tooltip Padding
  7008. width: 0
  7009. };
  7010. // Count of all lines in the body
  7011. var body = vm.body;
  7012. var combinedBodyLength = body.reduce(function(count, bodyItem) {
  7013. return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
  7014. }, 0);
  7015. combinedBodyLength += vm.beforeBody.length + vm.afterBody.length;
  7016. var titleLineCount = vm.title.length;
  7017. var footerLineCount = vm.footer.length;
  7018. var titleFontSize = vm.titleFontSize,
  7019. bodyFontSize = vm.bodyFontSize,
  7020. footerFontSize = vm.footerFontSize;
  7021. size.height += titleLineCount * titleFontSize; // Title Lines
  7022. size.height += (titleLineCount - 1) * vm.titleSpacing; // Title Line Spacing
  7023. size.height += titleLineCount ? vm.titleMarginBottom : 0; // Title's bottom Margin
  7024. size.height += combinedBodyLength * bodyFontSize; // Body Lines
  7025. size.height += combinedBodyLength ? (combinedBodyLength - 1) * vm.bodySpacing : 0; // Body Line Spacing
  7026. size.height += footerLineCount ? vm.footerMarginTop : 0; // Footer Margin
  7027. size.height += footerLineCount * (footerFontSize); // Footer Lines
  7028. size.height += footerLineCount ? (footerLineCount - 1) * vm.footerSpacing : 0; // Footer Line Spacing
  7029. // Title width
  7030. var widthPadding = 0;
  7031. var maxLineWidth = function(line) {
  7032. size.width = Math.max(size.width, ctx.measureText(line).width + widthPadding);
  7033. };
  7034. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  7035. helpers.each(vm.title, maxLineWidth);
  7036. // Body width
  7037. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  7038. helpers.each(vm.beforeBody.concat(vm.afterBody), maxLineWidth);
  7039. // Body lines may include some extra width due to the color box
  7040. widthPadding = body.length > 1 ? (bodyFontSize + 2) : 0;
  7041. helpers.each(body, function(bodyItem) {
  7042. helpers.each(bodyItem.before, maxLineWidth);
  7043. helpers.each(bodyItem.lines, maxLineWidth);
  7044. helpers.each(bodyItem.after, maxLineWidth);
  7045. });
  7046. // Reset back to 0
  7047. widthPadding = 0;
  7048. // Footer width
  7049. ctx.font = helpers.fontString(footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  7050. helpers.each(vm.footer, maxLineWidth);
  7051. // Add padding
  7052. size.width += 2 * vm.xPadding;
  7053. return size;
  7054. },
  7055. determineAlignment: function(size) {
  7056. var me = this;
  7057. var model = me._model;
  7058. var chart = me._chart;
  7059. var chartArea = me._chartInstance.chartArea;
  7060. if (model.y < size.height) {
  7061. model.yAlign = 'top';
  7062. } else if (model.y > (chart.height - size.height)) {
  7063. model.yAlign = 'bottom';
  7064. }
  7065. var lf, rf; // functions to determine left, right alignment
  7066. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  7067. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  7068. var midX = (chartArea.left + chartArea.right) / 2;
  7069. var midY = (chartArea.top + chartArea.bottom) / 2;
  7070. if (model.yAlign === 'center') {
  7071. lf = function(x) {
  7072. return x <= midX;
  7073. };
  7074. rf = function(x) {
  7075. return x > midX;
  7076. };
  7077. } else {
  7078. lf = function(x) {
  7079. return x <= (size.width / 2);
  7080. };
  7081. rf = function(x) {
  7082. return x >= (chart.width - (size.width / 2));
  7083. };
  7084. }
  7085. olf = function(x) {
  7086. return x + size.width > chart.width;
  7087. };
  7088. orf = function(x) {
  7089. return x - size.width < 0;
  7090. };
  7091. yf = function(y) {
  7092. return y <= midY ? 'top' : 'bottom';
  7093. };
  7094. if (lf(model.x)) {
  7095. model.xAlign = 'left';
  7096. // Is tooltip too wide and goes over the right side of the chart.?
  7097. if (olf(model.x)) {
  7098. model.xAlign = 'center';
  7099. model.yAlign = yf(model.y);
  7100. }
  7101. } else if (rf(model.x)) {
  7102. model.xAlign = 'right';
  7103. // Is tooltip too wide and goes outside left edge of canvas?
  7104. if (orf(model.x)) {
  7105. model.xAlign = 'center';
  7106. model.yAlign = yf(model.y);
  7107. }
  7108. }
  7109. },
  7110. getBackgroundPoint: function(vm, size) {
  7111. // Background Position
  7112. var pt = {
  7113. x: vm.x,
  7114. y: vm.y
  7115. };
  7116. var caretSize = vm.caretSize,
  7117. caretPadding = vm.caretPadding,
  7118. cornerRadius = vm.cornerRadius,
  7119. xAlign = vm.xAlign,
  7120. yAlign = vm.yAlign,
  7121. paddingAndSize = caretSize + caretPadding,
  7122. radiusAndPadding = cornerRadius + caretPadding;
  7123. if (xAlign === 'right') {
  7124. pt.x -= size.width;
  7125. } else if (xAlign === 'center') {
  7126. pt.x -= (size.width / 2);
  7127. }
  7128. if (yAlign === 'top') {
  7129. pt.y += paddingAndSize;
  7130. } else if (yAlign === 'bottom') {
  7131. pt.y -= size.height + paddingAndSize;
  7132. } else {
  7133. pt.y -= (size.height / 2);
  7134. }
  7135. if (yAlign === 'center') {
  7136. if (xAlign === 'left') {
  7137. pt.x += paddingAndSize;
  7138. } else if (xAlign === 'right') {
  7139. pt.x -= paddingAndSize;
  7140. }
  7141. } else {
  7142. if (xAlign === 'left') {
  7143. pt.x -= radiusAndPadding;
  7144. } else if (xAlign === 'right') {
  7145. pt.x += radiusAndPadding;
  7146. }
  7147. }
  7148. return pt;
  7149. },
  7150. drawCaret: function(tooltipPoint, size, opacity) {
  7151. var vm = this._view;
  7152. var ctx = this._chart.ctx;
  7153. var x1, x2, x3;
  7154. var y1, y2, y3;
  7155. var caretSize = vm.caretSize;
  7156. var cornerRadius = vm.cornerRadius;
  7157. var xAlign = vm.xAlign,
  7158. yAlign = vm.yAlign;
  7159. var ptX = tooltipPoint.x,
  7160. ptY = tooltipPoint.y;
  7161. var width = size.width,
  7162. height = size.height;
  7163. if (yAlign === 'center') {
  7164. // Left or right side
  7165. if (xAlign === 'left') {
  7166. x1 = ptX;
  7167. x2 = x1 - caretSize;
  7168. x3 = x1;
  7169. } else {
  7170. x1 = ptX + width;
  7171. x2 = x1 + caretSize;
  7172. x3 = x1;
  7173. }
  7174. y2 = ptY + (height / 2);
  7175. y1 = y2 - caretSize;
  7176. y3 = y2 + caretSize;
  7177. } else {
  7178. if (xAlign === 'left') {
  7179. x1 = ptX + cornerRadius;
  7180. x2 = x1 + caretSize;
  7181. x3 = x2 + caretSize;
  7182. } else if (xAlign === 'right') {
  7183. x1 = ptX + width - cornerRadius;
  7184. x2 = x1 - caretSize;
  7185. x3 = x2 - caretSize;
  7186. } else {
  7187. x2 = ptX + (width / 2);
  7188. x1 = x2 - caretSize;
  7189. x3 = x2 + caretSize;
  7190. }
  7191. if (yAlign === 'top') {
  7192. y1 = ptY;
  7193. y2 = y1 - caretSize;
  7194. y3 = y1;
  7195. } else {
  7196. y1 = ptY + height;
  7197. y2 = y1 + caretSize;
  7198. y3 = y1;
  7199. }
  7200. }
  7201. var bgColor = helpers.color(vm.backgroundColor);
  7202. ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
  7203. ctx.beginPath();
  7204. ctx.moveTo(x1, y1);
  7205. ctx.lineTo(x2, y2);
  7206. ctx.lineTo(x3, y3);
  7207. ctx.closePath();
  7208. ctx.fill();
  7209. },
  7210. drawTitle: function(pt, vm, ctx, opacity) {
  7211. var title = vm.title;
  7212. if (title.length) {
  7213. ctx.textAlign = vm._titleAlign;
  7214. ctx.textBaseline = "top";
  7215. var titleFontSize = vm.titleFontSize,
  7216. titleSpacing = vm.titleSpacing;
  7217. var titleFontColor = helpers.color(vm.titleFontColor);
  7218. ctx.fillStyle = titleFontColor.alpha(opacity * titleFontColor.alpha()).rgbString();
  7219. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  7220. var i, len;
  7221. for (i = 0, len = title.length; i < len; ++i) {
  7222. ctx.fillText(title[i], pt.x, pt.y);
  7223. pt.y += titleFontSize + titleSpacing; // Line Height and spacing
  7224. if (i + 1 === title.length) {
  7225. pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
  7226. }
  7227. }
  7228. }
  7229. },
  7230. drawBody: function(pt, vm, ctx, opacity) {
  7231. var bodyFontSize = vm.bodyFontSize;
  7232. var bodySpacing = vm.bodySpacing;
  7233. var body = vm.body;
  7234. ctx.textAlign = vm._bodyAlign;
  7235. ctx.textBaseline = "top";
  7236. var bodyFontColor = helpers.color(vm.bodyFontColor);
  7237. var textColor = bodyFontColor.alpha(opacity * bodyFontColor.alpha()).rgbString();
  7238. ctx.fillStyle = textColor;
  7239. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  7240. // Before Body
  7241. var xLinePadding = 0;
  7242. var fillLineOfText = function(line) {
  7243. ctx.fillText(line, pt.x + xLinePadding, pt.y);
  7244. pt.y += bodyFontSize + bodySpacing;
  7245. };
  7246. // Before body lines
  7247. helpers.each(vm.beforeBody, fillLineOfText);
  7248. var drawColorBoxes = body.length > 1;
  7249. xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
  7250. // Draw body lines now
  7251. helpers.each(body, function(bodyItem, i) {
  7252. helpers.each(bodyItem.before, fillLineOfText);
  7253. helpers.each(bodyItem.lines, function(line) {
  7254. // Draw Legend-like boxes if needed
  7255. if (drawColorBoxes) {
  7256. // Fill a white rect so that colours merge nicely if the opacity is < 1
  7257. ctx.fillStyle = helpers.color(vm.legendColorBackground).alpha(opacity).rgbaString();
  7258. ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7259. // Border
  7260. ctx.strokeStyle = helpers.color(vm.labelColors[i].borderColor).alpha(opacity).rgbaString();
  7261. ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7262. // Inner square
  7263. ctx.fillStyle = helpers.color(vm.labelColors[i].backgroundColor).alpha(opacity).rgbaString();
  7264. ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
  7265. ctx.fillStyle = textColor;
  7266. }
  7267. fillLineOfText(line);
  7268. });
  7269. helpers.each(bodyItem.after, fillLineOfText);
  7270. });
  7271. // Reset back to 0 for after body
  7272. xLinePadding = 0;
  7273. // After body lines
  7274. helpers.each(vm.afterBody, fillLineOfText);
  7275. pt.y -= bodySpacing; // Remove last body spacing
  7276. },
  7277. drawFooter: function(pt, vm, ctx, opacity) {
  7278. var footer = vm.footer;
  7279. if (footer.length) {
  7280. pt.y += vm.footerMarginTop;
  7281. ctx.textAlign = vm._footerAlign;
  7282. ctx.textBaseline = "top";
  7283. var footerFontColor = helpers.color(vm.footerFontColor);
  7284. ctx.fillStyle = footerFontColor.alpha(opacity * footerFontColor.alpha()).rgbString();
  7285. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  7286. helpers.each(footer, function(line) {
  7287. ctx.fillText(line, pt.x, pt.y);
  7288. pt.y += vm.footerFontSize + vm.footerSpacing;
  7289. });
  7290. }
  7291. },
  7292. draw: function() {
  7293. var ctx = this._chart.ctx;
  7294. var vm = this._view;
  7295. if (vm.opacity === 0) {
  7296. return;
  7297. }
  7298. var tooltipSize = this.getTooltipSize(vm);
  7299. var pt = {
  7300. x: vm.x,
  7301. y: vm.y
  7302. };
  7303. // IE11/Edge does not like very small opacities, so snap to 0
  7304. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  7305. if (this._options.enabled) {
  7306. // Draw Background
  7307. var bgColor = helpers.color(vm.backgroundColor);
  7308. ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
  7309. helpers.drawRoundedRectangle(ctx, pt.x, pt.y, tooltipSize.width, tooltipSize.height, vm.cornerRadius);
  7310. ctx.fill();
  7311. // Draw Caret
  7312. this.drawCaret(pt, tooltipSize, opacity);
  7313. // Draw Title, Body, and Footer
  7314. pt.x += vm.xPadding;
  7315. pt.y += vm.yPadding;
  7316. // Titles
  7317. this.drawTitle(pt, vm, ctx, opacity);
  7318. // Body
  7319. this.drawBody(pt, vm, ctx, opacity);
  7320. // Footer
  7321. this.drawFooter(pt, vm, ctx, opacity);
  7322. }
  7323. }
  7324. });
  7325. };
  7326. },{}],35:[function(require,module,exports){
  7327. "use strict";
  7328. module.exports = function(Chart) {
  7329. var helpers = Chart.helpers,
  7330. globalOpts = Chart.defaults.global;
  7331. globalOpts.elements.arc = {
  7332. backgroundColor: globalOpts.defaultColor,
  7333. borderColor: "#fff",
  7334. borderWidth: 2
  7335. };
  7336. Chart.elements.Arc = Chart.Element.extend({
  7337. inLabelRange: function(mouseX) {
  7338. var vm = this._view;
  7339. if (vm) {
  7340. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  7341. } else {
  7342. return false;
  7343. }
  7344. },
  7345. inRange: function(chartX, chartY) {
  7346. var vm = this._view;
  7347. if (vm) {
  7348. var pointRelativePosition = helpers.getAngleFromPoint(vm, {
  7349. x: chartX,
  7350. y: chartY
  7351. }),
  7352. angle = pointRelativePosition.angle,
  7353. distance = pointRelativePosition.distance;
  7354. //Sanitise angle range
  7355. var startAngle = vm.startAngle;
  7356. var endAngle = vm.endAngle;
  7357. while (endAngle < startAngle) {
  7358. endAngle += 2.0 * Math.PI;
  7359. }
  7360. while (angle > endAngle) {
  7361. angle -= 2.0 * Math.PI;
  7362. }
  7363. while (angle < startAngle) {
  7364. angle += 2.0 * Math.PI;
  7365. }
  7366. //Check if within the range of the open/close angle
  7367. var betweenAngles = (angle >= startAngle && angle <= endAngle),
  7368. withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
  7369. return (betweenAngles && withinRadius);
  7370. } else {
  7371. return false;
  7372. }
  7373. },
  7374. tooltipPosition: function() {
  7375. var vm = this._view;
  7376. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2),
  7377. rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  7378. return {
  7379. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  7380. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  7381. };
  7382. },
  7383. draw: function() {
  7384. var ctx = this._chart.ctx,
  7385. vm = this._view,
  7386. sA = vm.startAngle,
  7387. eA = vm.endAngle;
  7388. ctx.beginPath();
  7389. ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
  7390. ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
  7391. ctx.closePath();
  7392. ctx.strokeStyle = vm.borderColor;
  7393. ctx.lineWidth = vm.borderWidth;
  7394. ctx.fillStyle = vm.backgroundColor;
  7395. ctx.fill();
  7396. ctx.lineJoin = 'bevel';
  7397. if (vm.borderWidth) {
  7398. ctx.stroke();
  7399. }
  7400. }
  7401. });
  7402. };
  7403. },{}],36:[function(require,module,exports){
  7404. "use strict";
  7405. module.exports = function(Chart) {
  7406. var helpers = Chart.helpers;
  7407. var globalDefaults = Chart.defaults.global;
  7408. Chart.defaults.global.elements.line = {
  7409. tension: 0.4,
  7410. backgroundColor: globalDefaults.defaultColor,
  7411. borderWidth: 3,
  7412. borderColor: globalDefaults.defaultColor,
  7413. borderCapStyle: 'butt',
  7414. borderDash: [],
  7415. borderDashOffset: 0.0,
  7416. borderJoinStyle: 'miter',
  7417. capBezierPoints: true,
  7418. fill: true // do we fill in the area between the line and its base axis
  7419. };
  7420. Chart.elements.Line = Chart.Element.extend({
  7421. draw: function() {
  7422. var me = this;
  7423. var vm = me._view;
  7424. var spanGaps = vm.spanGaps;
  7425. var scaleZero = vm.scaleZero;
  7426. var loop = me._loop;
  7427. var ctx = me._chart.ctx;
  7428. ctx.save();
  7429. // Helper function to draw a line to a point
  7430. function lineToPoint(previousPoint, point) {
  7431. var vm = point._view;
  7432. if (point._view.steppedLine === true) {
  7433. ctx.lineTo(point._view.x, previousPoint._view.y);
  7434. ctx.lineTo(point._view.x, point._view.y);
  7435. } else if (point._view.tension === 0) {
  7436. ctx.lineTo(vm.x, vm.y);
  7437. } else {
  7438. ctx.bezierCurveTo(
  7439. previousPoint._view.controlPointNextX,
  7440. previousPoint._view.controlPointNextY,
  7441. vm.controlPointPreviousX,
  7442. vm.controlPointPreviousY,
  7443. vm.x,
  7444. vm.y
  7445. );
  7446. }
  7447. }
  7448. var points = me._children.slice(); // clone array
  7449. var lastDrawnIndex = -1;
  7450. // If we are looping, adding the first point again
  7451. if (loop && points.length) {
  7452. points.push(points[0]);
  7453. }
  7454. var index, current, previous, currentVM;
  7455. // Fill Line
  7456. if (points.length && vm.fill) {
  7457. ctx.beginPath();
  7458. for (index = 0; index < points.length; ++index) {
  7459. current = points[index];
  7460. previous = helpers.previousItem(points, index);
  7461. currentVM = current._view;
  7462. // First point moves to it's starting position no matter what
  7463. if (index === 0) {
  7464. if (loop) {
  7465. ctx.moveTo(scaleZero.x, scaleZero.y);
  7466. } else {
  7467. ctx.moveTo(currentVM.x, scaleZero);
  7468. }
  7469. if (!currentVM.skip) {
  7470. lastDrawnIndex = index;
  7471. ctx.lineTo(currentVM.x, currentVM.y);
  7472. }
  7473. } else {
  7474. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  7475. if (currentVM.skip) {
  7476. // Only do this if this is the first point that is skipped
  7477. if (!spanGaps && lastDrawnIndex === (index - 1)) {
  7478. if (loop) {
  7479. ctx.lineTo(scaleZero.x, scaleZero.y);
  7480. } else {
  7481. ctx.lineTo(previous._view.x, scaleZero);
  7482. }
  7483. }
  7484. } else {
  7485. if (lastDrawnIndex !== (index - 1)) {
  7486. // 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.
  7487. // If the first data point is NaN, then there is no real gap to skip
  7488. if (spanGaps && lastDrawnIndex !== -1) {
  7489. // We are spanning the gap, so simple draw a line to this point
  7490. lineToPoint(previous, current);
  7491. } else {
  7492. if (loop) {
  7493. ctx.lineTo(currentVM.x, currentVM.y);
  7494. } else {
  7495. ctx.lineTo(currentVM.x, scaleZero);
  7496. ctx.lineTo(currentVM.x, currentVM.y);
  7497. }
  7498. }
  7499. } else {
  7500. // Line to next point
  7501. lineToPoint(previous, current);
  7502. }
  7503. lastDrawnIndex = index;
  7504. }
  7505. }
  7506. }
  7507. if (!loop && lastDrawnIndex !== -1) {
  7508. ctx.lineTo(points[lastDrawnIndex]._view.x, scaleZero);
  7509. }
  7510. ctx.fillStyle = vm.backgroundColor || globalDefaults.defaultColor;
  7511. ctx.closePath();
  7512. ctx.fill();
  7513. }
  7514. // Stroke Line Options
  7515. var globalOptionLineElements = globalDefaults.elements.line;
  7516. ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
  7517. // IE 9 and 10 do not support line dash
  7518. if (ctx.setLineDash) {
  7519. ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
  7520. }
  7521. ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
  7522. ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
  7523. ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
  7524. ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
  7525. // Stroke Line
  7526. ctx.beginPath();
  7527. lastDrawnIndex = -1;
  7528. for (index = 0; index < points.length; ++index) {
  7529. current = points[index];
  7530. previous = helpers.previousItem(points, index);
  7531. currentVM = current._view;
  7532. // First point moves to it's starting position no matter what
  7533. if (index === 0) {
  7534. if (!currentVM.skip) {
  7535. ctx.moveTo(currentVM.x, currentVM.y);
  7536. lastDrawnIndex = index;
  7537. }
  7538. } else {
  7539. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  7540. if (!currentVM.skip) {
  7541. if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
  7542. // There was a gap and this is the first point after the gap
  7543. ctx.moveTo(currentVM.x, currentVM.y);
  7544. } else {
  7545. // Line to next point
  7546. lineToPoint(previous, current);
  7547. }
  7548. lastDrawnIndex = index;
  7549. }
  7550. }
  7551. }
  7552. ctx.stroke();
  7553. ctx.restore();
  7554. }
  7555. });
  7556. };
  7557. },{}],37:[function(require,module,exports){
  7558. "use strict";
  7559. module.exports = function(Chart) {
  7560. var helpers = Chart.helpers,
  7561. globalOpts = Chart.defaults.global,
  7562. defaultColor = globalOpts.defaultColor;
  7563. globalOpts.elements.point = {
  7564. radius: 3,
  7565. pointStyle: 'circle',
  7566. backgroundColor: defaultColor,
  7567. borderWidth: 1,
  7568. borderColor: defaultColor,
  7569. // Hover
  7570. hitRadius: 1,
  7571. hoverRadius: 4,
  7572. hoverBorderWidth: 1
  7573. };
  7574. Chart.elements.Point = Chart.Element.extend({
  7575. inRange: function(mouseX, mouseY) {
  7576. var vm = this._view;
  7577. return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
  7578. },
  7579. inLabelRange: function(mouseX) {
  7580. var vm = this._view;
  7581. return vm ? (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hitRadius, 2)) : false;
  7582. },
  7583. tooltipPosition: function() {
  7584. var vm = this._view;
  7585. return {
  7586. x: vm.x,
  7587. y: vm.y,
  7588. padding: vm.radius + vm.borderWidth
  7589. };
  7590. },
  7591. draw: function() {
  7592. var vm = this._view;
  7593. var ctx = this._chart.ctx;
  7594. var pointStyle = vm.pointStyle;
  7595. var radius = vm.radius;
  7596. var x = vm.x;
  7597. var y = vm.y;
  7598. if (vm.skip) {
  7599. return;
  7600. }
  7601. ctx.strokeStyle = vm.borderColor || defaultColor;
  7602. ctx.lineWidth = helpers.getValueOrDefault(vm.borderWidth, globalOpts.elements.point.borderWidth);
  7603. ctx.fillStyle = vm.backgroundColor || defaultColor;
  7604. Chart.canvasHelpers.drawPoint(ctx, pointStyle, radius, x, y);
  7605. }
  7606. });
  7607. };
  7608. },{}],38:[function(require,module,exports){
  7609. "use strict";
  7610. module.exports = function(Chart) {
  7611. var globalOpts = Chart.defaults.global;
  7612. globalOpts.elements.rectangle = {
  7613. backgroundColor: globalOpts.defaultColor,
  7614. borderWidth: 0,
  7615. borderColor: globalOpts.defaultColor,
  7616. borderSkipped: 'bottom'
  7617. };
  7618. Chart.elements.Rectangle = Chart.Element.extend({
  7619. draw: function() {
  7620. var ctx = this._chart.ctx;
  7621. var vm = this._view;
  7622. var halfWidth = vm.width / 2,
  7623. leftX = vm.x - halfWidth,
  7624. rightX = vm.x + halfWidth,
  7625. top = vm.base - (vm.base - vm.y),
  7626. halfStroke = vm.borderWidth / 2;
  7627. // Canvas doesn't allow us to stroke inside the width so we can
  7628. // adjust the sizes to fit if we're setting a stroke on the line
  7629. if (vm.borderWidth) {
  7630. leftX += halfStroke;
  7631. rightX -= halfStroke;
  7632. top += halfStroke;
  7633. }
  7634. ctx.beginPath();
  7635. ctx.fillStyle = vm.backgroundColor;
  7636. ctx.strokeStyle = vm.borderColor;
  7637. ctx.lineWidth = vm.borderWidth;
  7638. // Corner points, from bottom-left to bottom-right clockwise
  7639. // | 1 2 |
  7640. // | 0 3 |
  7641. var corners = [
  7642. [leftX, vm.base],
  7643. [leftX, top],
  7644. [rightX, top],
  7645. [rightX, vm.base]
  7646. ];
  7647. // Find first (starting) corner with fallback to 'bottom'
  7648. var borders = ['bottom', 'left', 'top', 'right'];
  7649. var startCorner = borders.indexOf(vm.borderSkipped, 0);
  7650. if (startCorner === -1) {
  7651. startCorner = 0;
  7652. }
  7653. function cornerAt(index) {
  7654. return corners[(startCorner + index) % 4];
  7655. }
  7656. // Draw rectangle from 'startCorner'
  7657. ctx.moveTo.apply(ctx, cornerAt(0));
  7658. for (var i = 1; i < 4; i++) {
  7659. ctx.lineTo.apply(ctx, cornerAt(i));
  7660. }
  7661. ctx.fill();
  7662. if (vm.borderWidth) {
  7663. ctx.stroke();
  7664. }
  7665. },
  7666. height: function() {
  7667. var vm = this._view;
  7668. return vm.base - vm.y;
  7669. },
  7670. inRange: function(mouseX, mouseY) {
  7671. var vm = this._view;
  7672. return vm ?
  7673. (vm.y < vm.base ?
  7674. (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.y && mouseY <= vm.base) :
  7675. (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.base && mouseY <= vm.y)) :
  7676. false;
  7677. },
  7678. inLabelRange: function(mouseX) {
  7679. var vm = this._view;
  7680. return vm ? (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) : false;
  7681. },
  7682. tooltipPosition: function() {
  7683. var vm = this._view;
  7684. return {
  7685. x: vm.x,
  7686. y: vm.y
  7687. };
  7688. }
  7689. });
  7690. };
  7691. },{}],39:[function(require,module,exports){
  7692. "use strict";
  7693. module.exports = function(Chart) {
  7694. var helpers = Chart.helpers;
  7695. // Default config for a category scale
  7696. var defaultConfig = {
  7697. position: "bottom"
  7698. };
  7699. var DatasetScale = Chart.Scale.extend({
  7700. /**
  7701. * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use tose
  7702. * else fall back to data.labels
  7703. * @private
  7704. */
  7705. getLabels: function() {
  7706. var data = this.chart.data;
  7707. return (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
  7708. },
  7709. // Implement this so that
  7710. determineDataLimits: function() {
  7711. var me = this;
  7712. var labels = me.getLabels();
  7713. me.minIndex = 0;
  7714. me.maxIndex = labels.length - 1;
  7715. var findIndex;
  7716. if (me.options.ticks.min !== undefined) {
  7717. // user specified min value
  7718. findIndex = helpers.indexOf(labels, me.options.ticks.min);
  7719. me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
  7720. }
  7721. if (me.options.ticks.max !== undefined) {
  7722. // user specified max value
  7723. findIndex = helpers.indexOf(labels, me.options.ticks.max);
  7724. me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
  7725. }
  7726. me.min = labels[me.minIndex];
  7727. me.max = labels[me.maxIndex];
  7728. },
  7729. buildTicks: function() {
  7730. var me = this;
  7731. var labels = me.getLabels();
  7732. // If we are viewing some subset of labels, slice the original array
  7733. me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
  7734. },
  7735. getLabelForIndex: function(index, datasetIndex) {
  7736. var me = this;
  7737. var data = me.chart.data;
  7738. var isHorizontal = me.isHorizontal();
  7739. if ((data.xLabels && isHorizontal) || (data.yLabels && !isHorizontal)) {
  7740. return me.getRightValue(data.datasets[datasetIndex].data[index]);
  7741. } else {
  7742. return me.ticks[index];
  7743. }
  7744. },
  7745. // Used to get data value locations. Value can either be an index or a numerical value
  7746. getPixelForValue: function(value, index, datasetIndex, includeOffset) {
  7747. var me = this;
  7748. // 1 is added because we need the length but we have the indexes
  7749. var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  7750. if (value !== undefined && isNaN(index)) {
  7751. var labels = me.getLabels();
  7752. var idx = labels.indexOf(value);
  7753. index = idx !== -1 ? idx : index;
  7754. }
  7755. if (me.isHorizontal()) {
  7756. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  7757. var valueWidth = innerWidth / offsetAmt;
  7758. var widthOffset = (valueWidth * (index - me.minIndex)) + me.paddingLeft;
  7759. if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) {
  7760. widthOffset += (valueWidth / 2);
  7761. }
  7762. return me.left + Math.round(widthOffset);
  7763. } else {
  7764. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  7765. var valueHeight = innerHeight / offsetAmt;
  7766. var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop;
  7767. if (me.options.gridLines.offsetGridLines && includeOffset) {
  7768. heightOffset += (valueHeight / 2);
  7769. }
  7770. return me.top + Math.round(heightOffset);
  7771. }
  7772. },
  7773. getPixelForTick: function(index, includeOffset) {
  7774. return this.getPixelForValue(this.ticks[index], index + this.minIndex, null, includeOffset);
  7775. },
  7776. getValueForPixel: function(pixel) {
  7777. var me = this;
  7778. var value;
  7779. var offsetAmt = Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  7780. var horz = me.isHorizontal();
  7781. var innerDimension = horz ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
  7782. var valueDimension = innerDimension / offsetAmt;
  7783. pixel -= horz ? me.left : me.top;
  7784. if (me.options.gridLines.offsetGridLines) {
  7785. pixel -= (valueDimension / 2);
  7786. }
  7787. pixel -= horz ? me.paddingLeft : me.paddingTop;
  7788. if (pixel <= 0) {
  7789. value = 0;
  7790. } else {
  7791. value = Math.round(pixel / valueDimension);
  7792. }
  7793. return value;
  7794. },
  7795. getBasePixel: function() {
  7796. return this.bottom;
  7797. }
  7798. });
  7799. Chart.scaleService.registerScaleType("category", DatasetScale, defaultConfig);
  7800. };
  7801. },{}],40:[function(require,module,exports){
  7802. "use strict";
  7803. module.exports = function(Chart) {
  7804. var helpers = Chart.helpers;
  7805. var defaultConfig = {
  7806. position: "left",
  7807. ticks: {
  7808. callback: function(tickValue, index, ticks) {
  7809. // If we have lots of ticks, don't use the ones
  7810. var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
  7811. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  7812. if (Math.abs(delta) > 1) {
  7813. if (tickValue !== Math.floor(tickValue)) {
  7814. // not an integer
  7815. delta = tickValue - Math.floor(tickValue);
  7816. }
  7817. }
  7818. var logDelta = helpers.log10(Math.abs(delta));
  7819. var tickString = '';
  7820. if (tickValue !== 0) {
  7821. var numDecimal = -1 * Math.floor(logDelta);
  7822. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  7823. tickString = tickValue.toFixed(numDecimal);
  7824. } else {
  7825. tickString = '0'; // never show decimal places for 0
  7826. }
  7827. return tickString;
  7828. }
  7829. }
  7830. };
  7831. var LinearScale = Chart.LinearScaleBase.extend({
  7832. determineDataLimits: function() {
  7833. var me = this;
  7834. var opts = me.options;
  7835. var chart = me.chart;
  7836. var data = chart.data;
  7837. var datasets = data.datasets;
  7838. var isHorizontal = me.isHorizontal();
  7839. function IDMatches(meta) {
  7840. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  7841. }
  7842. // First Calculate the range
  7843. me.min = null;
  7844. me.max = null;
  7845. if (opts.stacked) {
  7846. var valuesPerType = {};
  7847. var hasPositiveValues = false;
  7848. var hasNegativeValues = false;
  7849. helpers.each(datasets, function(dataset, datasetIndex) {
  7850. var meta = chart.getDatasetMeta(datasetIndex);
  7851. if (valuesPerType[meta.type] === undefined) {
  7852. valuesPerType[meta.type] = {
  7853. positiveValues: [],
  7854. negativeValues: []
  7855. };
  7856. }
  7857. // Store these per type
  7858. var positiveValues = valuesPerType[meta.type].positiveValues;
  7859. var negativeValues = valuesPerType[meta.type].negativeValues;
  7860. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  7861. helpers.each(dataset.data, function(rawValue, index) {
  7862. var value = +me.getRightValue(rawValue);
  7863. if (isNaN(value) || meta.data[index].hidden) {
  7864. return;
  7865. }
  7866. positiveValues[index] = positiveValues[index] || 0;
  7867. negativeValues[index] = negativeValues[index] || 0;
  7868. if (opts.relativePoints) {
  7869. positiveValues[index] = 100;
  7870. } else {
  7871. if (value < 0) {
  7872. hasNegativeValues = true;
  7873. negativeValues[index] += value;
  7874. } else {
  7875. hasPositiveValues = true;
  7876. positiveValues[index] += value;
  7877. }
  7878. }
  7879. });
  7880. }
  7881. });
  7882. helpers.each(valuesPerType, function(valuesForType) {
  7883. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  7884. var minVal = helpers.min(values);
  7885. var maxVal = helpers.max(values);
  7886. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  7887. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  7888. });
  7889. } else {
  7890. helpers.each(datasets, function(dataset, datasetIndex) {
  7891. var meta = chart.getDatasetMeta(datasetIndex);
  7892. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  7893. helpers.each(dataset.data, function(rawValue, index) {
  7894. var value = +me.getRightValue(rawValue);
  7895. if (isNaN(value) || meta.data[index].hidden) {
  7896. return;
  7897. }
  7898. if (me.min === null) {
  7899. me.min = value;
  7900. } else if (value < me.min) {
  7901. me.min = value;
  7902. }
  7903. if (me.max === null) {
  7904. me.max = value;
  7905. } else if (value > me.max) {
  7906. me.max = value;
  7907. }
  7908. });
  7909. }
  7910. });
  7911. }
  7912. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  7913. this.handleTickRangeOptions();
  7914. },
  7915. getTickLimit: function() {
  7916. var maxTicks;
  7917. var me = this;
  7918. var tickOpts = me.options.ticks;
  7919. if (me.isHorizontal()) {
  7920. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
  7921. } else {
  7922. // The factor of 2 used to scale the font size has been experimentally determined.
  7923. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, Chart.defaults.global.defaultFontSize);
  7924. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
  7925. }
  7926. return maxTicks;
  7927. },
  7928. // Called after the ticks are built. We need
  7929. handleDirectionalChanges: function() {
  7930. if (!this.isHorizontal()) {
  7931. // We are in a vertical orientation. The top value is the highest. So reverse the array
  7932. this.ticks.reverse();
  7933. }
  7934. },
  7935. getLabelForIndex: function(index, datasetIndex) {
  7936. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  7937. },
  7938. // Utils
  7939. getPixelForValue: function(value) {
  7940. // This must be called after fit has been run so that
  7941. // this.left, this.top, this.right, and this.bottom have been defined
  7942. var me = this;
  7943. var paddingLeft = me.paddingLeft;
  7944. var paddingBottom = me.paddingBottom;
  7945. var start = me.start;
  7946. var rightValue = +me.getRightValue(value);
  7947. var pixel;
  7948. var innerDimension;
  7949. var range = me.end - start;
  7950. if (me.isHorizontal()) {
  7951. innerDimension = me.width - (paddingLeft + me.paddingRight);
  7952. pixel = me.left + (innerDimension / range * (rightValue - start));
  7953. return Math.round(pixel + paddingLeft);
  7954. } else {
  7955. innerDimension = me.height - (me.paddingTop + paddingBottom);
  7956. pixel = (me.bottom - paddingBottom) - (innerDimension / range * (rightValue - start));
  7957. return Math.round(pixel);
  7958. }
  7959. },
  7960. getValueForPixel: function(pixel) {
  7961. var me = this;
  7962. var isHorizontal = me.isHorizontal();
  7963. var paddingLeft = me.paddingLeft;
  7964. var paddingBottom = me.paddingBottom;
  7965. var innerDimension = isHorizontal ? me.width - (paddingLeft + me.paddingRight) : me.height - (me.paddingTop + paddingBottom);
  7966. var offset = (isHorizontal ? pixel - me.left - paddingLeft : me.bottom - paddingBottom - pixel) / innerDimension;
  7967. return me.start + ((me.end - me.start) * offset);
  7968. },
  7969. getPixelForTick: function(index) {
  7970. return this.getPixelForValue(this.ticksAsNumbers[index]);
  7971. }
  7972. });
  7973. Chart.scaleService.registerScaleType("linear", LinearScale, defaultConfig);
  7974. };
  7975. },{}],41:[function(require,module,exports){
  7976. "use strict";
  7977. module.exports = function(Chart) {
  7978. var helpers = Chart.helpers,
  7979. noop = helpers.noop;
  7980. Chart.LinearScaleBase = Chart.Scale.extend({
  7981. handleTickRangeOptions: function() {
  7982. var me = this;
  7983. var opts = me.options;
  7984. var tickOpts = opts.ticks;
  7985. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  7986. // do nothing since that would make the chart weird. If the user really wants a weird chart
  7987. // axis, they can manually override it
  7988. if (tickOpts.beginAtZero) {
  7989. var minSign = helpers.sign(me.min);
  7990. var maxSign = helpers.sign(me.max);
  7991. if (minSign < 0 && maxSign < 0) {
  7992. // move the top up to 0
  7993. me.max = 0;
  7994. } else if (minSign > 0 && maxSign > 0) {
  7995. // move the botttom down to 0
  7996. me.min = 0;
  7997. }
  7998. }
  7999. if (tickOpts.min !== undefined) {
  8000. me.min = tickOpts.min;
  8001. } else if (tickOpts.suggestedMin !== undefined) {
  8002. me.min = Math.min(me.min, tickOpts.suggestedMin);
  8003. }
  8004. if (tickOpts.max !== undefined) {
  8005. me.max = tickOpts.max;
  8006. } else if (tickOpts.suggestedMax !== undefined) {
  8007. me.max = Math.max(me.max, tickOpts.suggestedMax);
  8008. }
  8009. if (me.min === me.max) {
  8010. me.max++;
  8011. if (!tickOpts.beginAtZero) {
  8012. me.min--;
  8013. }
  8014. }
  8015. },
  8016. getTickLimit: noop,
  8017. handleDirectionalChanges: noop,
  8018. buildTicks: function() {
  8019. var me = this;
  8020. var opts = me.options;
  8021. var ticks = me.ticks = [];
  8022. var tickOpts = opts.ticks;
  8023. var getValueOrDefault = helpers.getValueOrDefault;
  8024. // Figure out what the max number of ticks we can support it is based on the size of
  8025. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  8026. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  8027. // the graph
  8028. var maxTicks = me.getTickLimit();
  8029. // Make sure we always have at least 2 ticks
  8030. maxTicks = Math.max(2, maxTicks);
  8031. // To get a "nice" value for the tick spacing, we will use the appropriately named
  8032. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  8033. // for details.
  8034. var spacing;
  8035. var fixedStepSizeSet = (tickOpts.fixedStepSize && tickOpts.fixedStepSize > 0) || (tickOpts.stepSize && tickOpts.stepSize > 0);
  8036. if (fixedStepSizeSet) {
  8037. spacing = getValueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize);
  8038. } else {
  8039. var niceRange = helpers.niceNum(me.max - me.min, false);
  8040. spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
  8041. }
  8042. var niceMin = Math.floor(me.min / spacing) * spacing;
  8043. var niceMax = Math.ceil(me.max / spacing) * spacing;
  8044. var numSpaces = (niceMax - niceMin) / spacing;
  8045. // If very close to our rounded value, use it.
  8046. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  8047. numSpaces = Math.round(numSpaces);
  8048. } else {
  8049. numSpaces = Math.ceil(numSpaces);
  8050. }
  8051. // Put the values into the ticks array
  8052. ticks.push(tickOpts.min !== undefined ? tickOpts.min : niceMin);
  8053. for (var j = 1; j < numSpaces; ++j) {
  8054. ticks.push(niceMin + (j * spacing));
  8055. }
  8056. ticks.push(tickOpts.max !== undefined ? tickOpts.max : niceMax);
  8057. me.handleDirectionalChanges();
  8058. // At this point, we need to update our max and min given the tick values since we have expanded the
  8059. // range of the scale
  8060. me.max = helpers.max(ticks);
  8061. me.min = helpers.min(ticks);
  8062. if (tickOpts.reverse) {
  8063. ticks.reverse();
  8064. me.start = me.max;
  8065. me.end = me.min;
  8066. } else {
  8067. me.start = me.min;
  8068. me.end = me.max;
  8069. }
  8070. },
  8071. convertTicksToLabels: function() {
  8072. var me = this;
  8073. me.ticksAsNumbers = me.ticks.slice();
  8074. me.zeroLineIndex = me.ticks.indexOf(0);
  8075. Chart.Scale.prototype.convertTicksToLabels.call(me);
  8076. }
  8077. });
  8078. };
  8079. },{}],42:[function(require,module,exports){
  8080. "use strict";
  8081. module.exports = function(Chart) {
  8082. var helpers = Chart.helpers;
  8083. var defaultConfig = {
  8084. position: "left",
  8085. // label settings
  8086. ticks: {
  8087. callback: function(value, index, arr) {
  8088. var remain = value / (Math.pow(10, Math.floor(helpers.log10(value))));
  8089. if (value === 0){
  8090. return '0';
  8091. } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === arr.length - 1) {
  8092. return value.toExponential();
  8093. } else {
  8094. return '';
  8095. }
  8096. }
  8097. }
  8098. };
  8099. var LogarithmicScale = Chart.Scale.extend({
  8100. determineDataLimits: function() {
  8101. var me = this;
  8102. var opts = me.options;
  8103. var tickOpts = opts.ticks;
  8104. var chart = me.chart;
  8105. var data = chart.data;
  8106. var datasets = data.datasets;
  8107. var getValueOrDefault = helpers.getValueOrDefault;
  8108. var isHorizontal = me.isHorizontal();
  8109. function IDMatches(meta) {
  8110. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  8111. }
  8112. // Calculate Range
  8113. me.min = null;
  8114. me.max = null;
  8115. me.minNotZero = null;
  8116. if (opts.stacked) {
  8117. var valuesPerType = {};
  8118. helpers.each(datasets, function(dataset, datasetIndex) {
  8119. var meta = chart.getDatasetMeta(datasetIndex);
  8120. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  8121. if (valuesPerType[meta.type] === undefined) {
  8122. valuesPerType[meta.type] = [];
  8123. }
  8124. helpers.each(dataset.data, function(rawValue, index) {
  8125. var values = valuesPerType[meta.type];
  8126. var value = +me.getRightValue(rawValue);
  8127. if (isNaN(value) || meta.data[index].hidden) {
  8128. return;
  8129. }
  8130. values[index] = values[index] || 0;
  8131. if (opts.relativePoints) {
  8132. values[index] = 100;
  8133. } else {
  8134. // Don't need to split positive and negative since the log scale can't handle a 0 crossing
  8135. values[index] += value;
  8136. }
  8137. });
  8138. }
  8139. });
  8140. helpers.each(valuesPerType, function(valuesForType) {
  8141. var minVal = helpers.min(valuesForType);
  8142. var maxVal = helpers.max(valuesForType);
  8143. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  8144. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  8145. });
  8146. } else {
  8147. helpers.each(datasets, function(dataset, datasetIndex) {
  8148. var meta = chart.getDatasetMeta(datasetIndex);
  8149. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  8150. helpers.each(dataset.data, function(rawValue, index) {
  8151. var value = +me.getRightValue(rawValue);
  8152. if (isNaN(value) || meta.data[index].hidden) {
  8153. return;
  8154. }
  8155. if (me.min === null) {
  8156. me.min = value;
  8157. } else if (value < me.min) {
  8158. me.min = value;
  8159. }
  8160. if (me.max === null) {
  8161. me.max = value;
  8162. } else if (value > me.max) {
  8163. me.max = value;
  8164. }
  8165. if(value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
  8166. me.minNotZero = value;
  8167. }
  8168. });
  8169. }
  8170. });
  8171. }
  8172. me.min = getValueOrDefault(tickOpts.min, me.min);
  8173. me.max = getValueOrDefault(tickOpts.max, me.max);
  8174. if (me.min === me.max) {
  8175. if (me.min !== 0 && me.min !== null) {
  8176. me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
  8177. me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
  8178. } else {
  8179. me.min = 1;
  8180. me.max = 10;
  8181. }
  8182. }
  8183. },
  8184. buildTicks: function() {
  8185. var me = this;
  8186. var opts = me.options;
  8187. var tickOpts = opts.ticks;
  8188. var getValueOrDefault = helpers.getValueOrDefault;
  8189. // Reset the ticks array. Later on, we will draw a grid line at these positions
  8190. // The array simply contains the numerical value of the spots where ticks will be
  8191. var ticks = me.ticks = [];
  8192. // Figure out what the max number of ticks we can support it is based on the size of
  8193. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  8194. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  8195. // the graph
  8196. var tickVal = getValueOrDefault(tickOpts.min, Math.pow(10, Math.floor(helpers.log10(me.min))));
  8197. while (tickVal < me.max) {
  8198. ticks.push(tickVal);
  8199. var exp;
  8200. var significand;
  8201. if(tickVal === 0){
  8202. exp = Math.floor(helpers.log10(me.minNotZero));
  8203. significand = Math.round(me.minNotZero / Math.pow(10, exp));
  8204. } else {
  8205. exp = Math.floor(helpers.log10(tickVal));
  8206. significand = Math.floor(tickVal / Math.pow(10, exp)) + 1;
  8207. }
  8208. if (significand === 10) {
  8209. significand = 1;
  8210. ++exp;
  8211. }
  8212. tickVal = significand * Math.pow(10, exp);
  8213. }
  8214. var lastTick = getValueOrDefault(tickOpts.max, tickVal);
  8215. ticks.push(lastTick);
  8216. if (!me.isHorizontal()) {
  8217. // We are in a vertical orientation. The top value is the highest. So reverse the array
  8218. ticks.reverse();
  8219. }
  8220. // At this point, we need to update our max and min given the tick values since we have expanded the
  8221. // range of the scale
  8222. me.max = helpers.max(ticks);
  8223. me.min = helpers.min(ticks);
  8224. if (tickOpts.reverse) {
  8225. ticks.reverse();
  8226. me.start = me.max;
  8227. me.end = me.min;
  8228. } else {
  8229. me.start = me.min;
  8230. me.end = me.max;
  8231. }
  8232. },
  8233. convertTicksToLabels: function() {
  8234. this.tickValues = this.ticks.slice();
  8235. Chart.Scale.prototype.convertTicksToLabels.call(this);
  8236. },
  8237. // Get the correct tooltip label
  8238. getLabelForIndex: function(index, datasetIndex) {
  8239. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  8240. },
  8241. getPixelForTick: function(index) {
  8242. return this.getPixelForValue(this.tickValues[index]);
  8243. },
  8244. getPixelForValue: function(value) {
  8245. var me = this;
  8246. var innerDimension;
  8247. var pixel;
  8248. var start = me.start;
  8249. var newVal = +me.getRightValue(value);
  8250. var range;
  8251. var paddingTop = me.paddingTop;
  8252. var paddingBottom = me.paddingBottom;
  8253. var paddingLeft = me.paddingLeft;
  8254. var opts = me.options;
  8255. var tickOpts = opts.ticks;
  8256. if (me.isHorizontal()) {
  8257. range = helpers.log10(me.end) - helpers.log10(start); // todo: if start === 0
  8258. if (newVal === 0) {
  8259. pixel = me.left + paddingLeft;
  8260. } else {
  8261. innerDimension = me.width - (paddingLeft + me.paddingRight);
  8262. pixel = me.left + (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
  8263. pixel += paddingLeft;
  8264. }
  8265. } else {
  8266. // Bottom - top since pixels increase downard on a screen
  8267. innerDimension = me.height - (paddingTop + paddingBottom);
  8268. if(start === 0 && !tickOpts.reverse){
  8269. range = helpers.log10(me.end) - helpers.log10(me.minNotZero);
  8270. if (newVal === start) {
  8271. pixel = me.bottom - paddingBottom;
  8272. } else if(newVal === me.minNotZero){
  8273. pixel = me.bottom - paddingBottom - innerDimension * 0.02;
  8274. } else {
  8275. pixel = me.bottom - paddingBottom - innerDimension * 0.02 - (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero)));
  8276. }
  8277. } else if (me.end === 0 && tickOpts.reverse){
  8278. range = helpers.log10(me.start) - helpers.log10(me.minNotZero);
  8279. if (newVal === me.end) {
  8280. pixel = me.top + paddingTop;
  8281. } else if(newVal === me.minNotZero){
  8282. pixel = me.top + paddingTop + innerDimension * 0.02;
  8283. } else {
  8284. pixel = me.top + paddingTop + innerDimension * 0.02 + (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero)));
  8285. }
  8286. } else {
  8287. range = helpers.log10(me.end) - helpers.log10(start);
  8288. innerDimension = me.height - (paddingTop + paddingBottom);
  8289. pixel = (me.bottom - paddingBottom) - (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
  8290. }
  8291. }
  8292. return pixel;
  8293. },
  8294. getValueForPixel: function(pixel) {
  8295. var me = this;
  8296. var range = helpers.log10(me.end) - helpers.log10(me.start);
  8297. var value, innerDimension;
  8298. if (me.isHorizontal()) {
  8299. innerDimension = me.width - (me.paddingLeft + me.paddingRight);
  8300. value = me.start * Math.pow(10, (pixel - me.left - me.paddingLeft) * range / innerDimension);
  8301. } else { // todo: if start === 0
  8302. innerDimension = me.height - (me.paddingTop + me.paddingBottom);
  8303. value = Math.pow(10, (me.bottom - me.paddingBottom - pixel) * range / innerDimension) / me.start;
  8304. }
  8305. return value;
  8306. }
  8307. });
  8308. Chart.scaleService.registerScaleType("logarithmic", LogarithmicScale, defaultConfig);
  8309. };
  8310. },{}],43:[function(require,module,exports){
  8311. "use strict";
  8312. module.exports = function(Chart) {
  8313. var helpers = Chart.helpers;
  8314. var globalDefaults = Chart.defaults.global;
  8315. var defaultConfig = {
  8316. display: true,
  8317. //Boolean - Whether to animate scaling the chart from the centre
  8318. animate: true,
  8319. lineArc: false,
  8320. position: "chartArea",
  8321. angleLines: {
  8322. display: true,
  8323. color: "rgba(0, 0, 0, 0.1)",
  8324. lineWidth: 1
  8325. },
  8326. // label settings
  8327. ticks: {
  8328. //Boolean - Show a backdrop to the scale label
  8329. showLabelBackdrop: true,
  8330. //String - The colour of the label backdrop
  8331. backdropColor: "rgba(255,255,255,0.75)",
  8332. //Number - The backdrop padding above & below the label in pixels
  8333. backdropPaddingY: 2,
  8334. //Number - The backdrop padding to the side of the label in pixels
  8335. backdropPaddingX: 2
  8336. },
  8337. pointLabels: {
  8338. //Number - Point label font size in pixels
  8339. fontSize: 10,
  8340. //Function - Used to convert point labels
  8341. callback: function(label) {
  8342. return label;
  8343. }
  8344. }
  8345. };
  8346. var LinearRadialScale = Chart.LinearScaleBase.extend({
  8347. getValueCount: function() {
  8348. return this.chart.data.labels.length;
  8349. },
  8350. setDimensions: function() {
  8351. var me = this;
  8352. var opts = me.options;
  8353. var tickOpts = opts.ticks;
  8354. // Set the unconstrained dimension before label rotation
  8355. me.width = me.maxWidth;
  8356. me.height = me.maxHeight;
  8357. me.xCenter = Math.round(me.width / 2);
  8358. me.yCenter = Math.round(me.height / 2);
  8359. var minSize = helpers.min([me.height, me.width]);
  8360. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  8361. me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
  8362. },
  8363. determineDataLimits: function() {
  8364. var me = this;
  8365. var chart = me.chart;
  8366. me.min = null;
  8367. me.max = null;
  8368. helpers.each(chart.data.datasets, function(dataset, datasetIndex) {
  8369. if (chart.isDatasetVisible(datasetIndex)) {
  8370. var meta = chart.getDatasetMeta(datasetIndex);
  8371. helpers.each(dataset.data, function(rawValue, index) {
  8372. var value = +me.getRightValue(rawValue);
  8373. if (isNaN(value) || meta.data[index].hidden) {
  8374. return;
  8375. }
  8376. if (me.min === null) {
  8377. me.min = value;
  8378. } else if (value < me.min) {
  8379. me.min = value;
  8380. }
  8381. if (me.max === null) {
  8382. me.max = value;
  8383. } else if (value > me.max) {
  8384. me.max = value;
  8385. }
  8386. });
  8387. }
  8388. });
  8389. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  8390. me.handleTickRangeOptions();
  8391. },
  8392. getTickLimit: function() {
  8393. var tickOpts = this.options.ticks;
  8394. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  8395. return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  8396. },
  8397. convertTicksToLabels: function() {
  8398. var me = this;
  8399. Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
  8400. // Point labels
  8401. me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
  8402. },
  8403. getLabelForIndex: function(index, datasetIndex) {
  8404. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  8405. },
  8406. fit: function() {
  8407. /*
  8408. * Right, this is really confusing and there is a lot of maths going on here
  8409. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  8410. *
  8411. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  8412. *
  8413. * Solution:
  8414. *
  8415. * We assume the radius of the polygon is half the size of the canvas at first
  8416. * at each index we check if the text overlaps.
  8417. *
  8418. * Where it does, we store that angle and that index.
  8419. *
  8420. * After finding the largest index and angle we calculate how much we need to remove
  8421. * from the shape radius to move the point inwards by that x.
  8422. *
  8423. * We average the left and right distances to get the maximum shape radius that can fit in the box
  8424. * along with labels.
  8425. *
  8426. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  8427. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  8428. *
  8429. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  8430. * and position it in the most space efficient manner
  8431. *
  8432. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  8433. */
  8434. var pointLabels = this.options.pointLabels;
  8435. var pointLabelFontSize = helpers.getValueOrDefault(pointLabels.fontSize, globalDefaults.defaultFontSize);
  8436. var pointLabeFontStyle = helpers.getValueOrDefault(pointLabels.fontStyle, globalDefaults.defaultFontStyle);
  8437. var pointLabeFontFamily = helpers.getValueOrDefault(pointLabels.fontFamily, globalDefaults.defaultFontFamily);
  8438. var pointLabeFont = helpers.fontString(pointLabelFontSize, pointLabeFontStyle, pointLabeFontFamily);
  8439. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  8440. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  8441. var largestPossibleRadius = helpers.min([(this.height / 2 - pointLabelFontSize - 5), this.width / 2]),
  8442. pointPosition,
  8443. i,
  8444. textWidth,
  8445. halfTextWidth,
  8446. furthestRight = this.width,
  8447. furthestRightIndex,
  8448. furthestRightAngle,
  8449. furthestLeft = 0,
  8450. furthestLeftIndex,
  8451. furthestLeftAngle,
  8452. xProtrusionLeft,
  8453. xProtrusionRight,
  8454. radiusReductionRight,
  8455. radiusReductionLeft;
  8456. this.ctx.font = pointLabeFont;
  8457. for (i = 0; i < this.getValueCount(); i++) {
  8458. // 5px to space the text slightly out - similar to what we do in the draw function.
  8459. pointPosition = this.getPointPosition(i, largestPossibleRadius);
  8460. textWidth = this.ctx.measureText(this.pointLabels[i] ? this.pointLabels[i] : '').width + 5;
  8461. // Add quarter circle to make degree 0 mean top of circle
  8462. var angleRadians = this.getIndexAngle(i) + (Math.PI / 2);
  8463. var angle = (angleRadians * 360 / (2 * Math.PI)) % 360;
  8464. if (angle === 0 || angle === 180) {
  8465. // At angle 0 and 180, we're at exactly the top/bottom
  8466. // of the radar chart, so text will be aligned centrally, so we'll half it and compare
  8467. // w/left and right text sizes
  8468. halfTextWidth = textWidth / 2;
  8469. if (pointPosition.x + halfTextWidth > furthestRight) {
  8470. furthestRight = pointPosition.x + halfTextWidth;
  8471. furthestRightIndex = i;
  8472. }
  8473. if (pointPosition.x - halfTextWidth < furthestLeft) {
  8474. furthestLeft = pointPosition.x - halfTextWidth;
  8475. furthestLeftIndex = i;
  8476. }
  8477. } else if (angle < 180) {
  8478. // Less than half the values means we'll left align the text
  8479. if (pointPosition.x + textWidth > furthestRight) {
  8480. furthestRight = pointPosition.x + textWidth;
  8481. furthestRightIndex = i;
  8482. }
  8483. } else {
  8484. // More than half the values means we'll right align the text
  8485. if (pointPosition.x - textWidth < furthestLeft) {
  8486. furthestLeft = pointPosition.x - textWidth;
  8487. furthestLeftIndex = i;
  8488. }
  8489. }
  8490. }
  8491. xProtrusionLeft = furthestLeft;
  8492. xProtrusionRight = Math.ceil(furthestRight - this.width);
  8493. furthestRightAngle = this.getIndexAngle(furthestRightIndex);
  8494. furthestLeftAngle = this.getIndexAngle(furthestLeftIndex);
  8495. radiusReductionRight = xProtrusionRight / Math.sin(furthestRightAngle + Math.PI / 2);
  8496. radiusReductionLeft = xProtrusionLeft / Math.sin(furthestLeftAngle + Math.PI / 2);
  8497. // Ensure we actually need to reduce the size of the chart
  8498. radiusReductionRight = (helpers.isNumber(radiusReductionRight)) ? radiusReductionRight : 0;
  8499. radiusReductionLeft = (helpers.isNumber(radiusReductionLeft)) ? radiusReductionLeft : 0;
  8500. this.drawingArea = Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2);
  8501. this.setCenterPoint(radiusReductionLeft, radiusReductionRight);
  8502. },
  8503. setCenterPoint: function(leftMovement, rightMovement) {
  8504. var me = this;
  8505. var maxRight = me.width - rightMovement - me.drawingArea,
  8506. maxLeft = leftMovement + me.drawingArea;
  8507. me.xCenter = Math.round(((maxLeft + maxRight) / 2) + me.left);
  8508. // Always vertically in the centre as the text height doesn't change
  8509. me.yCenter = Math.round((me.height / 2) + me.top);
  8510. },
  8511. getIndexAngle: function(index) {
  8512. var angleMultiplier = (Math.PI * 2) / this.getValueCount();
  8513. var startAngle = this.chart.options && this.chart.options.startAngle ?
  8514. this.chart.options.startAngle :
  8515. 0;
  8516. var startAngleRadians = startAngle * Math.PI * 2 / 360;
  8517. // Start from the top instead of right, so remove a quarter of the circle
  8518. return index * angleMultiplier - (Math.PI / 2) + startAngleRadians;
  8519. },
  8520. getDistanceFromCenterForValue: function(value) {
  8521. var me = this;
  8522. if (value === null) {
  8523. return 0; // null always in center
  8524. }
  8525. // Take into account half font size + the yPadding of the top value
  8526. var scalingFactor = me.drawingArea / (me.max - me.min);
  8527. if (me.options.reverse) {
  8528. return (me.max - value) * scalingFactor;
  8529. } else {
  8530. return (value - me.min) * scalingFactor;
  8531. }
  8532. },
  8533. getPointPosition: function(index, distanceFromCenter) {
  8534. var me = this;
  8535. var thisAngle = me.getIndexAngle(index);
  8536. return {
  8537. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
  8538. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
  8539. };
  8540. },
  8541. getPointPositionForValue: function(index, value) {
  8542. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  8543. },
  8544. getBasePosition: function() {
  8545. var me = this;
  8546. var min = me.min;
  8547. var max = me.max;
  8548. return me.getPointPositionForValue(0,
  8549. me.beginAtZero? 0:
  8550. min < 0 && max < 0? max :
  8551. min > 0 && max > 0? min :
  8552. 0);
  8553. },
  8554. draw: function() {
  8555. var me = this;
  8556. var opts = me.options;
  8557. var gridLineOpts = opts.gridLines;
  8558. var tickOpts = opts.ticks;
  8559. var angleLineOpts = opts.angleLines;
  8560. var pointLabelOpts = opts.pointLabels;
  8561. var getValueOrDefault = helpers.getValueOrDefault;
  8562. if (opts.display) {
  8563. var ctx = me.ctx;
  8564. // Tick Font
  8565. var tickFontSize = getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  8566. var tickFontStyle = getValueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  8567. var tickFontFamily = getValueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  8568. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  8569. helpers.each(me.ticks, function(label, index) {
  8570. // Don't draw a centre value (if it is minimum)
  8571. if (index > 0 || opts.reverse) {
  8572. var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
  8573. var yHeight = me.yCenter - yCenterOffset;
  8574. // Draw circular lines around the scale
  8575. if (gridLineOpts.display && index !== 0) {
  8576. ctx.strokeStyle = helpers.getValueAtIndexOrDefault(gridLineOpts.color, index - 1);
  8577. ctx.lineWidth = helpers.getValueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
  8578. if (opts.lineArc) {
  8579. // Draw circular arcs between the points
  8580. ctx.beginPath();
  8581. ctx.arc(me.xCenter, me.yCenter, yCenterOffset, 0, Math.PI * 2);
  8582. ctx.closePath();
  8583. ctx.stroke();
  8584. } else {
  8585. // Draw straight lines connecting each index
  8586. ctx.beginPath();
  8587. for (var i = 0; i < me.getValueCount(); i++) {
  8588. var pointPosition = me.getPointPosition(i, yCenterOffset);
  8589. if (i === 0) {
  8590. ctx.moveTo(pointPosition.x, pointPosition.y);
  8591. } else {
  8592. ctx.lineTo(pointPosition.x, pointPosition.y);
  8593. }
  8594. }
  8595. ctx.closePath();
  8596. ctx.stroke();
  8597. }
  8598. }
  8599. if (tickOpts.display) {
  8600. var tickFontColor = getValueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
  8601. ctx.font = tickLabelFont;
  8602. if (tickOpts.showLabelBackdrop) {
  8603. var labelWidth = ctx.measureText(label).width;
  8604. ctx.fillStyle = tickOpts.backdropColor;
  8605. ctx.fillRect(
  8606. me.xCenter - labelWidth / 2 - tickOpts.backdropPaddingX,
  8607. yHeight - tickFontSize / 2 - tickOpts.backdropPaddingY,
  8608. labelWidth + tickOpts.backdropPaddingX * 2,
  8609. tickFontSize + tickOpts.backdropPaddingY * 2
  8610. );
  8611. }
  8612. ctx.textAlign = 'center';
  8613. ctx.textBaseline = "middle";
  8614. ctx.fillStyle = tickFontColor;
  8615. ctx.fillText(label, me.xCenter, yHeight);
  8616. }
  8617. }
  8618. });
  8619. if (!opts.lineArc) {
  8620. ctx.lineWidth = angleLineOpts.lineWidth;
  8621. ctx.strokeStyle = angleLineOpts.color;
  8622. var outerDistance = me.getDistanceFromCenterForValue(opts.reverse ? me.min : me.max);
  8623. // Point Label Font
  8624. var pointLabelFontSize = getValueOrDefault(pointLabelOpts.fontSize, globalDefaults.defaultFontSize);
  8625. var pointLabeFontStyle = getValueOrDefault(pointLabelOpts.fontStyle, globalDefaults.defaultFontStyle);
  8626. var pointLabeFontFamily = getValueOrDefault(pointLabelOpts.fontFamily, globalDefaults.defaultFontFamily);
  8627. var pointLabeFont = helpers.fontString(pointLabelFontSize, pointLabeFontStyle, pointLabeFontFamily);
  8628. for (var i = me.getValueCount() - 1; i >= 0; i--) {
  8629. if (angleLineOpts.display) {
  8630. var outerPosition = me.getPointPosition(i, outerDistance);
  8631. ctx.beginPath();
  8632. ctx.moveTo(me.xCenter, me.yCenter);
  8633. ctx.lineTo(outerPosition.x, outerPosition.y);
  8634. ctx.stroke();
  8635. ctx.closePath();
  8636. }
  8637. // Extra 3px out for some label spacing
  8638. var pointLabelPosition = me.getPointPosition(i, outerDistance + 5);
  8639. // Keep this in loop since we may support array properties here
  8640. var pointLabelFontColor = getValueOrDefault(pointLabelOpts.fontColor, globalDefaults.defaultFontColor);
  8641. ctx.font = pointLabeFont;
  8642. ctx.fillStyle = pointLabelFontColor;
  8643. var pointLabels = me.pointLabels;
  8644. // Add quarter circle to make degree 0 mean top of circle
  8645. var angleRadians = this.getIndexAngle(i) + (Math.PI / 2);
  8646. var angle = (angleRadians * 360 / (2 * Math.PI)) % 360;
  8647. if (angle === 0 || angle === 180) {
  8648. ctx.textAlign = 'center';
  8649. } else if (angle < 180) {
  8650. ctx.textAlign = 'left';
  8651. } else {
  8652. ctx.textAlign = 'right';
  8653. }
  8654. // Set the correct text baseline based on outer positioning
  8655. if (angle === 90 || angle === 270) {
  8656. ctx.textBaseline = 'middle';
  8657. } else if (angle > 270 || angle < 90) {
  8658. ctx.textBaseline = 'bottom';
  8659. } else {
  8660. ctx.textBaseline = 'top';
  8661. }
  8662. ctx.fillText(pointLabels[i] ? pointLabels[i] : '', pointLabelPosition.x, pointLabelPosition.y);
  8663. }
  8664. }
  8665. }
  8666. }
  8667. });
  8668. Chart.scaleService.registerScaleType("radialLinear", LinearRadialScale, defaultConfig);
  8669. };
  8670. },{}],44:[function(require,module,exports){
  8671. /*global window: false */
  8672. "use strict";
  8673. var moment = require(1);
  8674. moment = typeof(moment) === 'function' ? moment : window.moment;
  8675. module.exports = function(Chart) {
  8676. var helpers = Chart.helpers;
  8677. var time = {
  8678. units: [{
  8679. name: 'millisecond',
  8680. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  8681. }, {
  8682. name: 'second',
  8683. steps: [1, 2, 5, 10, 30]
  8684. }, {
  8685. name: 'minute',
  8686. steps: [1, 2, 5, 10, 30]
  8687. }, {
  8688. name: 'hour',
  8689. steps: [1, 2, 3, 6, 12]
  8690. }, {
  8691. name: 'day',
  8692. steps: [1, 2, 5]
  8693. }, {
  8694. name: 'week',
  8695. maxStep: 4
  8696. }, {
  8697. name: 'month',
  8698. maxStep: 3
  8699. }, {
  8700. name: 'quarter',
  8701. maxStep: 4
  8702. }, {
  8703. name: 'year',
  8704. maxStep: false
  8705. }]
  8706. };
  8707. var defaultConfig = {
  8708. position: "bottom",
  8709. time: {
  8710. 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
  8711. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  8712. unit: false, // false == automatic or override with week, month, year, etc.
  8713. round: false, // none, or override with week, month, year, etc.
  8714. displayFormat: false, // DEPRECATED
  8715. isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
  8716. minUnit: 'millisecond',
  8717. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  8718. displayFormats: {
  8719. 'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  8720. 'second': 'h:mm:ss a', // 11:20:01 AM
  8721. 'minute': 'h:mm:ss a', // 11:20:01 AM
  8722. 'hour': 'MMM D, hA', // Sept 4, 5PM
  8723. 'day': 'll', // Sep 4 2015
  8724. 'week': 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  8725. 'month': 'MMM YYYY', // Sept 2015
  8726. 'quarter': '[Q]Q - YYYY', // Q3
  8727. 'year': 'YYYY' // 2015
  8728. }
  8729. },
  8730. ticks: {
  8731. autoSkip: false
  8732. }
  8733. };
  8734. var TimeScale = Chart.Scale.extend({
  8735. initialize: function() {
  8736. if (!moment) {
  8737. 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');
  8738. }
  8739. Chart.Scale.prototype.initialize.call(this);
  8740. },
  8741. getLabelMoment: function(datasetIndex, index) {
  8742. if (datasetIndex === null || index === null) {
  8743. return null;
  8744. }
  8745. if (typeof this.labelMoments[datasetIndex] !== 'undefined') {
  8746. return this.labelMoments[datasetIndex][index];
  8747. }
  8748. return null;
  8749. },
  8750. getMomentStartOf: function(tick) {
  8751. var me = this;
  8752. if (me.options.time.unit === 'week' && me.options.time.isoWeekday !== false) {
  8753. return tick.clone().startOf('isoWeek').isoWeekday(me.options.time.isoWeekday);
  8754. } else {
  8755. return tick.clone().startOf(me.tickUnit);
  8756. }
  8757. },
  8758. determineDataLimits: function() {
  8759. var me = this;
  8760. me.labelMoments = [];
  8761. // Only parse these once. If the dataset does not have data as x,y pairs, we will use
  8762. // these
  8763. var scaleLabelMoments = [];
  8764. if (me.chart.data.labels && me.chart.data.labels.length > 0) {
  8765. helpers.each(me.chart.data.labels, function(label) {
  8766. var labelMoment = me.parseTime(label);
  8767. if (labelMoment.isValid()) {
  8768. if (me.options.time.round) {
  8769. labelMoment.startOf(me.options.time.round);
  8770. }
  8771. scaleLabelMoments.push(labelMoment);
  8772. }
  8773. }, me);
  8774. me.firstTick = moment.min.call(me, scaleLabelMoments);
  8775. me.lastTick = moment.max.call(me, scaleLabelMoments);
  8776. } else {
  8777. me.firstTick = null;
  8778. me.lastTick = null;
  8779. }
  8780. helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
  8781. var momentsForDataset = [];
  8782. var datasetVisible = me.chart.isDatasetVisible(datasetIndex);
  8783. if (typeof dataset.data[0] === 'object' && dataset.data[0] !== null) {
  8784. helpers.each(dataset.data, function(value) {
  8785. var labelMoment = me.parseTime(me.getRightValue(value));
  8786. if (labelMoment.isValid()) {
  8787. if (me.options.time.round) {
  8788. labelMoment.startOf(me.options.time.round);
  8789. }
  8790. momentsForDataset.push(labelMoment);
  8791. if (datasetVisible) {
  8792. // May have gone outside the scale ranges, make sure we keep the first and last ticks updated
  8793. me.firstTick = me.firstTick !== null ? moment.min(me.firstTick, labelMoment) : labelMoment;
  8794. me.lastTick = me.lastTick !== null ? moment.max(me.lastTick, labelMoment) : labelMoment;
  8795. }
  8796. }
  8797. }, me);
  8798. } else {
  8799. // We have no labels. Use the ones from the scale
  8800. momentsForDataset = scaleLabelMoments;
  8801. }
  8802. me.labelMoments.push(momentsForDataset);
  8803. }, me);
  8804. // Set these after we've done all the data
  8805. if (me.options.time.min) {
  8806. me.firstTick = me.parseTime(me.options.time.min);
  8807. }
  8808. if (me.options.time.max) {
  8809. me.lastTick = me.parseTime(me.options.time.max);
  8810. }
  8811. // We will modify these, so clone for later
  8812. me.firstTick = (me.firstTick || moment()).clone();
  8813. me.lastTick = (me.lastTick || moment()).clone();
  8814. },
  8815. buildTicks: function() {
  8816. var me = this;
  8817. me.ctx.save();
  8818. var tickFontSize = helpers.getValueOrDefault(me.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  8819. var tickFontStyle = helpers.getValueOrDefault(me.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
  8820. var tickFontFamily = helpers.getValueOrDefault(me.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
  8821. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  8822. me.ctx.font = tickLabelFont;
  8823. me.ticks = [];
  8824. me.unitScale = 1; // How much we scale the unit by, ie 2 means 2x unit per step
  8825. me.scaleSizeInUnits = 0; // How large the scale is in the base unit (seconds, minutes, etc)
  8826. // Set unit override if applicable
  8827. if (me.options.time.unit) {
  8828. me.tickUnit = me.options.time.unit || 'day';
  8829. me.displayFormat = me.options.time.displayFormats[me.tickUnit];
  8830. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  8831. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, 1);
  8832. } else {
  8833. // Determine the smallest needed unit of the time
  8834. var innerWidth = me.isHorizontal() ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
  8835. // Crude approximation of what the label length might be
  8836. var tempFirstLabel = me.tickFormatFunction(me.firstTick, 0, []);
  8837. var tickLabelWidth = me.ctx.measureText(tempFirstLabel).width;
  8838. var cosRotation = Math.cos(helpers.toRadians(me.options.ticks.maxRotation));
  8839. var sinRotation = Math.sin(helpers.toRadians(me.options.ticks.maxRotation));
  8840. tickLabelWidth = (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  8841. var labelCapacity = innerWidth / (tickLabelWidth);
  8842. // Start as small as possible
  8843. me.tickUnit = me.options.time.minUnit;
  8844. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  8845. me.displayFormat = me.options.time.displayFormats[me.tickUnit];
  8846. var unitDefinitionIndex = 0;
  8847. var unitDefinition = time.units[unitDefinitionIndex];
  8848. // While we aren't ideal and we don't have units left
  8849. while (unitDefinitionIndex < time.units.length) {
  8850. // Can we scale this unit. If `false` we can scale infinitely
  8851. me.unitScale = 1;
  8852. if (helpers.isArray(unitDefinition.steps) && Math.ceil(me.scaleSizeInUnits / labelCapacity) < helpers.max(unitDefinition.steps)) {
  8853. // Use one of the prefedined steps
  8854. for (var idx = 0; idx < unitDefinition.steps.length; ++idx) {
  8855. if (unitDefinition.steps[idx] >= Math.ceil(me.scaleSizeInUnits / labelCapacity)) {
  8856. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, unitDefinition.steps[idx]);
  8857. break;
  8858. }
  8859. }
  8860. break;
  8861. } else if ((unitDefinition.maxStep === false) || (Math.ceil(me.scaleSizeInUnits / labelCapacity) < unitDefinition.maxStep)) {
  8862. // We have a max step. Scale this unit
  8863. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, Math.ceil(me.scaleSizeInUnits / labelCapacity));
  8864. break;
  8865. } else {
  8866. // Move to the next unit up
  8867. ++unitDefinitionIndex;
  8868. unitDefinition = time.units[unitDefinitionIndex];
  8869. me.tickUnit = unitDefinition.name;
  8870. var leadingUnitBuffer = me.firstTick.diff(me.getMomentStartOf(me.firstTick), me.tickUnit, true);
  8871. var trailingUnitBuffer = me.getMomentStartOf(me.lastTick.clone().add(1, me.tickUnit)).diff(me.lastTick, me.tickUnit, true);
  8872. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true) + leadingUnitBuffer + trailingUnitBuffer;
  8873. me.displayFormat = me.options.time.displayFormats[unitDefinition.name];
  8874. }
  8875. }
  8876. }
  8877. var roundedStart;
  8878. // Only round the first tick if we have no hard minimum
  8879. if (!me.options.time.min) {
  8880. me.firstTick = me.getMomentStartOf(me.firstTick);
  8881. roundedStart = me.firstTick;
  8882. } else {
  8883. roundedStart = me.getMomentStartOf(me.firstTick);
  8884. }
  8885. // Only round the last tick if we have no hard maximum
  8886. if (!me.options.time.max) {
  8887. var roundedEnd = me.getMomentStartOf(me.lastTick);
  8888. var delta = roundedEnd.diff(me.lastTick, me.tickUnit, true);
  8889. if (delta < 0) {
  8890. // Do not use end of because we need me to be in the next time unit
  8891. me.lastTick = me.getMomentStartOf(me.lastTick.add(1, me.tickUnit));
  8892. } else if (delta >= 0) {
  8893. me.lastTick = roundedEnd;
  8894. }
  8895. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  8896. }
  8897. // Tick displayFormat override
  8898. if (me.options.time.displayFormat) {
  8899. me.displayFormat = me.options.time.displayFormat;
  8900. }
  8901. // first tick. will have been rounded correctly if options.time.min is not specified
  8902. me.ticks.push(me.firstTick.clone());
  8903. // For every unit in between the first and last moment, create a moment and add it to the ticks tick
  8904. for (var i = 1; i <= me.scaleSizeInUnits; ++i) {
  8905. var newTick = roundedStart.clone().add(i, me.tickUnit);
  8906. // Are we greater than the max time
  8907. if (me.options.time.max && newTick.diff(me.lastTick, me.tickUnit, true) >= 0) {
  8908. break;
  8909. }
  8910. if (i % me.unitScale === 0) {
  8911. me.ticks.push(newTick);
  8912. }
  8913. }
  8914. // Always show the right tick
  8915. var diff = me.ticks[me.ticks.length - 1].diff(me.lastTick, me.tickUnit);
  8916. if (diff !== 0 || me.scaleSizeInUnits === 0) {
  8917. // 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
  8918. // but the last tick was not rounded.
  8919. if (me.options.time.max) {
  8920. me.ticks.push(me.lastTick.clone());
  8921. me.scaleSizeInUnits = me.lastTick.diff(me.ticks[0], me.tickUnit, true);
  8922. } else if (me.scaleSizeInUnits === 0) {
  8923. me.ticks.push(me.lastTick.clone());
  8924. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  8925. }
  8926. }
  8927. me.ctx.restore();
  8928. },
  8929. // Get tooltip label
  8930. getLabelForIndex: function(index, datasetIndex) {
  8931. var me = this;
  8932. var label = me.chart.data.labels && index < me.chart.data.labels.length ? me.chart.data.labels[index] : '';
  8933. if (typeof me.chart.data.datasets[datasetIndex].data[0] === 'object') {
  8934. label = me.getRightValue(me.chart.data.datasets[datasetIndex].data[index]);
  8935. }
  8936. // Format nicely
  8937. if (me.options.time.tooltipFormat) {
  8938. label = me.parseTime(label).format(me.options.time.tooltipFormat);
  8939. }
  8940. return label;
  8941. },
  8942. // Function to format an individual tick mark
  8943. tickFormatFunction: function(tick, index, ticks) {
  8944. var formattedTick = tick.format(this.displayFormat);
  8945. var tickOpts = this.options.ticks;
  8946. var callback = helpers.getValueOrDefault(tickOpts.callback, tickOpts.userCallback);
  8947. if (callback) {
  8948. return callback(formattedTick, index, ticks);
  8949. } else {
  8950. return formattedTick;
  8951. }
  8952. },
  8953. convertTicksToLabels: function() {
  8954. var me = this;
  8955. me.tickMoments = me.ticks;
  8956. me.ticks = me.ticks.map(me.tickFormatFunction, me);
  8957. },
  8958. getPixelForValue: function(value, index, datasetIndex) {
  8959. var me = this;
  8960. if (!value || !value.isValid) {
  8961. // not already a moment object
  8962. value = me.parseTime(me.getRightValue(value));
  8963. }
  8964. var labelMoment = value && value.isValid && value.isValid() ? value : me.getLabelMoment(datasetIndex, index);
  8965. if (labelMoment) {
  8966. var offset = labelMoment.diff(me.firstTick, me.tickUnit, true);
  8967. var decimal = offset !== 0 ? offset / me.scaleSizeInUnits : offset;
  8968. if (me.isHorizontal()) {
  8969. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  8970. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  8971. return me.left + Math.round(valueOffset);
  8972. } else {
  8973. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  8974. var heightOffset = (innerHeight * decimal) + me.paddingTop;
  8975. return me.top + Math.round(heightOffset);
  8976. }
  8977. }
  8978. },
  8979. getPixelForTick: function(index) {
  8980. return this.getPixelForValue(this.tickMoments[index], null, null);
  8981. },
  8982. getValueForPixel: function(pixel) {
  8983. var me = this;
  8984. var innerDimension = me.isHorizontal() ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
  8985. var offset = (pixel - (me.isHorizontal() ? me.left + me.paddingLeft : me.top + me.paddingTop)) / innerDimension;
  8986. offset *= me.scaleSizeInUnits;
  8987. return me.firstTick.clone().add(moment.duration(offset, me.tickUnit).asSeconds(), 'seconds');
  8988. },
  8989. parseTime: function(label) {
  8990. var me = this;
  8991. if (typeof me.options.time.parser === 'string') {
  8992. return moment(label, me.options.time.parser);
  8993. }
  8994. if (typeof me.options.time.parser === 'function') {
  8995. return me.options.time.parser(label);
  8996. }
  8997. // Date objects
  8998. if (typeof label.getMonth === 'function' || typeof label === 'number') {
  8999. return moment(label);
  9000. }
  9001. // Moment support
  9002. if (label.isValid && label.isValid()) {
  9003. return label;
  9004. }
  9005. // Custom parsing (return an instance of moment)
  9006. if (typeof me.options.time.format !== 'string' && me.options.time.format.call) {
  9007. 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");
  9008. return me.options.time.format(label);
  9009. }
  9010. // Moment format parsing
  9011. return moment(label, me.options.time.format);
  9012. }
  9013. });
  9014. Chart.scaleService.registerScaleType("time", TimeScale, defaultConfig);
  9015. };
  9016. },{"1":1}]},{},[7])(7)
  9017. });