Chart.js 306 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635
  1. /*!
  2. * Chart.js
  3. * http://chartjs.org/
  4. * Version: 2.3.0
  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. }
  1778. return yScale.getPixelForValue(sumPos + value);
  1779. }
  1780. return yScale.getPixelForValue(value);
  1781. },
  1782. draw: function(ease) {
  1783. var me = this;
  1784. var easingDecimal = ease || 1;
  1785. helpers.each(me.getMeta().data, function(rectangle, index) {
  1786. var d = me.getDataset().data[index];
  1787. if (d !== null && d !== undefined && !isNaN(d)) {
  1788. rectangle.transition(easingDecimal).draw();
  1789. }
  1790. }, me);
  1791. },
  1792. setHoverStyle: function(rectangle) {
  1793. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  1794. var index = rectangle._index;
  1795. var custom = rectangle.custom || {};
  1796. var model = rectangle._model;
  1797. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  1798. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  1799. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  1800. },
  1801. removeHoverStyle: function(rectangle) {
  1802. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  1803. var index = rectangle._index;
  1804. var custom = rectangle.custom || {};
  1805. var model = rectangle._model;
  1806. var rectangleElementOptions = this.chart.options.elements.rectangle;
  1807. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor);
  1808. model.borderColor = custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor);
  1809. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth);
  1810. }
  1811. });
  1812. // including horizontalBar in the bar file, instead of a file of its own
  1813. // it extends bar (like pie extends doughnut)
  1814. Chart.defaults.horizontalBar = {
  1815. hover: {
  1816. mode: 'label'
  1817. },
  1818. scales: {
  1819. xAxes: [{
  1820. type: 'linear',
  1821. position: 'bottom'
  1822. }],
  1823. yAxes: [{
  1824. position: 'left',
  1825. type: 'category',
  1826. // Specific to Horizontal Bar Controller
  1827. categoryPercentage: 0.8,
  1828. barPercentage: 0.9,
  1829. // grid line settings
  1830. gridLines: {
  1831. offsetGridLines: true
  1832. }
  1833. }]
  1834. },
  1835. elements: {
  1836. rectangle: {
  1837. borderSkipped: 'left'
  1838. }
  1839. },
  1840. tooltips: {
  1841. callbacks: {
  1842. title: function(tooltipItems, data) {
  1843. // Pick first xLabel for now
  1844. var title = '';
  1845. if (tooltipItems.length > 0) {
  1846. if (tooltipItems[0].yLabel) {
  1847. title = tooltipItems[0].yLabel;
  1848. } else if (data.labels.length > 0 && tooltipItems[0].index < data.labels.length) {
  1849. title = data.labels[tooltipItems[0].index];
  1850. }
  1851. }
  1852. return title;
  1853. },
  1854. label: function(tooltipItem, data) {
  1855. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  1856. return datasetLabel + ': ' + tooltipItem.xLabel;
  1857. }
  1858. }
  1859. }
  1860. };
  1861. Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
  1862. updateElement: function(rectangle, index, reset) {
  1863. var me = this;
  1864. var meta = me.getMeta();
  1865. var xScale = me.getScaleForId(meta.xAxisID);
  1866. var yScale = me.getScaleForId(meta.yAxisID);
  1867. var scaleBase = xScale.getBasePixel();
  1868. var custom = rectangle.custom || {};
  1869. var dataset = me.getDataset();
  1870. var rectangleElementOptions = me.chart.options.elements.rectangle;
  1871. helpers.extend(rectangle, {
  1872. // Utility
  1873. _xScale: xScale,
  1874. _yScale: yScale,
  1875. _datasetIndex: me.index,
  1876. _index: index,
  1877. // Desired view properties
  1878. _model: {
  1879. x: reset ? scaleBase : me.calculateBarX(index, me.index),
  1880. y: me.calculateBarY(index, me.index),
  1881. // Tooltip
  1882. label: me.chart.data.labels[index],
  1883. datasetLabel: dataset.label,
  1884. // Appearance
  1885. base: reset ? scaleBase : me.calculateBarBase(me.index, index),
  1886. height: me.calculateBarHeight(index),
  1887. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor),
  1888. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
  1889. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
  1890. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth)
  1891. },
  1892. draw: function() {
  1893. var ctx = this._chart.ctx;
  1894. var vm = this._view;
  1895. var halfHeight = vm.height / 2,
  1896. topY = vm.y - halfHeight,
  1897. bottomY = vm.y + halfHeight,
  1898. right = vm.base - (vm.base - vm.x),
  1899. halfStroke = vm.borderWidth / 2;
  1900. // Canvas doesn't allow us to stroke inside the width so we can
  1901. // adjust the sizes to fit if we're setting a stroke on the line
  1902. if (vm.borderWidth) {
  1903. topY += halfStroke;
  1904. bottomY -= halfStroke;
  1905. right += halfStroke;
  1906. }
  1907. ctx.beginPath();
  1908. ctx.fillStyle = vm.backgroundColor;
  1909. ctx.strokeStyle = vm.borderColor;
  1910. ctx.lineWidth = vm.borderWidth;
  1911. // Corner points, from bottom-left to bottom-right clockwise
  1912. // | 1 2 |
  1913. // | 0 3 |
  1914. var corners = [
  1915. [vm.base, bottomY],
  1916. [vm.base, topY],
  1917. [right, topY],
  1918. [right, bottomY]
  1919. ];
  1920. // Find first (starting) corner with fallback to 'bottom'
  1921. var borders = ['bottom', 'left', 'top', 'right'];
  1922. var startCorner = borders.indexOf(vm.borderSkipped, 0);
  1923. if (startCorner === -1) {
  1924. startCorner = 0;
  1925. }
  1926. function cornerAt(cornerIndex) {
  1927. return corners[(startCorner + cornerIndex) % 4];
  1928. }
  1929. // Draw rectangle from 'startCorner'
  1930. ctx.moveTo.apply(ctx, cornerAt(0));
  1931. for (var i = 1; i < 4; i++) {
  1932. ctx.lineTo.apply(ctx, cornerAt(i));
  1933. }
  1934. ctx.fill();
  1935. if (vm.borderWidth) {
  1936. ctx.stroke();
  1937. }
  1938. },
  1939. inRange: function(mouseX, mouseY) {
  1940. var vm = this._view;
  1941. var inRange = false;
  1942. if (vm) {
  1943. if (vm.x < vm.base) {
  1944. inRange = (mouseY >= vm.y - vm.height / 2 && mouseY <= vm.y + vm.height / 2) && (mouseX >= vm.x && mouseX <= vm.base);
  1945. } else {
  1946. inRange = (mouseY >= vm.y - vm.height / 2 && mouseY <= vm.y + vm.height / 2) && (mouseX >= vm.base && mouseX <= vm.x);
  1947. }
  1948. }
  1949. return inRange;
  1950. }
  1951. });
  1952. rectangle.pivot();
  1953. },
  1954. calculateBarBase: function(datasetIndex, index) {
  1955. var me = this;
  1956. var meta = me.getMeta();
  1957. var xScale = me.getScaleForId(meta.xAxisID);
  1958. var base = 0;
  1959. if (xScale.options.stacked) {
  1960. var chart = me.chart;
  1961. var datasets = chart.data.datasets;
  1962. var value = Number(datasets[datasetIndex].data[index]);
  1963. for (var i = 0; i < datasetIndex; i++) {
  1964. var currentDs = datasets[i];
  1965. var currentDsMeta = chart.getDatasetMeta(i);
  1966. if (currentDsMeta.bar && currentDsMeta.xAxisID === xScale.id && chart.isDatasetVisible(i)) {
  1967. var currentVal = Number(currentDs.data[index]);
  1968. base += value < 0 ? Math.min(currentVal, 0) : Math.max(currentVal, 0);
  1969. }
  1970. }
  1971. return xScale.getPixelForValue(base);
  1972. }
  1973. return xScale.getBasePixel();
  1974. },
  1975. getRuler: function(index) {
  1976. var me = this;
  1977. var meta = me.getMeta();
  1978. var yScale = me.getScaleForId(meta.yAxisID);
  1979. var datasetCount = me.getBarCount();
  1980. var tickHeight;
  1981. if (yScale.options.type === 'category') {
  1982. tickHeight = yScale.getPixelForTick(index + 1) - yScale.getPixelForTick(index);
  1983. } else {
  1984. // Average width
  1985. tickHeight = yScale.width / yScale.ticks.length;
  1986. }
  1987. var categoryHeight = tickHeight * yScale.options.categoryPercentage;
  1988. var categorySpacing = (tickHeight - (tickHeight * yScale.options.categoryPercentage)) / 2;
  1989. var fullBarHeight = categoryHeight / datasetCount;
  1990. if (yScale.ticks.length !== me.chart.data.labels.length) {
  1991. var perc = yScale.ticks.length / me.chart.data.labels.length;
  1992. fullBarHeight = fullBarHeight * perc;
  1993. }
  1994. var barHeight = fullBarHeight * yScale.options.barPercentage;
  1995. var barSpacing = fullBarHeight - (fullBarHeight * yScale.options.barPercentage);
  1996. return {
  1997. datasetCount: datasetCount,
  1998. tickHeight: tickHeight,
  1999. categoryHeight: categoryHeight,
  2000. categorySpacing: categorySpacing,
  2001. fullBarHeight: fullBarHeight,
  2002. barHeight: barHeight,
  2003. barSpacing: barSpacing
  2004. };
  2005. },
  2006. calculateBarHeight: function(index) {
  2007. var me = this;
  2008. var yScale = me.getScaleForId(me.getMeta().yAxisID);
  2009. if (yScale.options.barThickness) {
  2010. return yScale.options.barThickness;
  2011. }
  2012. var ruler = me.getRuler(index);
  2013. return yScale.options.stacked ? ruler.categoryHeight : ruler.barHeight;
  2014. },
  2015. calculateBarX: function(index, datasetIndex) {
  2016. var me = this;
  2017. var meta = me.getMeta();
  2018. var xScale = me.getScaleForId(meta.xAxisID);
  2019. var value = Number(me.getDataset().data[index]);
  2020. if (xScale.options.stacked) {
  2021. var sumPos = 0,
  2022. sumNeg = 0;
  2023. for (var i = 0; i < datasetIndex; i++) {
  2024. var ds = me.chart.data.datasets[i];
  2025. var dsMeta = me.chart.getDatasetMeta(i);
  2026. if (dsMeta.bar && dsMeta.xAxisID === xScale.id && me.chart.isDatasetVisible(i)) {
  2027. var stackedVal = Number(ds.data[index]);
  2028. if (stackedVal < 0) {
  2029. sumNeg += stackedVal || 0;
  2030. } else {
  2031. sumPos += stackedVal || 0;
  2032. }
  2033. }
  2034. }
  2035. if (value < 0) {
  2036. return xScale.getPixelForValue(sumNeg + value);
  2037. }
  2038. return xScale.getPixelForValue(sumPos + value);
  2039. }
  2040. return xScale.getPixelForValue(value);
  2041. },
  2042. calculateBarY: function(index, datasetIndex) {
  2043. var me = this;
  2044. var meta = me.getMeta();
  2045. var yScale = me.getScaleForId(meta.yAxisID);
  2046. var barIndex = me.getBarIndex(datasetIndex);
  2047. var ruler = me.getRuler(index);
  2048. var topTick = yScale.getPixelForValue(null, index, datasetIndex, me.chart.isCombo);
  2049. topTick -= me.chart.isCombo ? (ruler.tickHeight / 2) : 0;
  2050. if (yScale.options.stacked) {
  2051. return topTick + (ruler.categoryHeight / 2) + ruler.categorySpacing;
  2052. }
  2053. return topTick +
  2054. (ruler.barHeight / 2) +
  2055. ruler.categorySpacing +
  2056. (ruler.barHeight * barIndex) +
  2057. (ruler.barSpacing / 2) +
  2058. (ruler.barSpacing * barIndex);
  2059. }
  2060. });
  2061. };
  2062. },{}],16:[function(require,module,exports){
  2063. 'use strict';
  2064. module.exports = function(Chart) {
  2065. var helpers = Chart.helpers;
  2066. Chart.defaults.bubble = {
  2067. hover: {
  2068. mode: 'single'
  2069. },
  2070. scales: {
  2071. xAxes: [{
  2072. type: 'linear', // bubble should probably use a linear scale by default
  2073. position: 'bottom',
  2074. id: 'x-axis-0' // need an ID so datasets can reference the scale
  2075. }],
  2076. yAxes: [{
  2077. type: 'linear',
  2078. position: 'left',
  2079. id: 'y-axis-0'
  2080. }]
  2081. },
  2082. tooltips: {
  2083. callbacks: {
  2084. title: function() {
  2085. // Title doesn't make sense for scatter since we format the data as a point
  2086. return '';
  2087. },
  2088. label: function(tooltipItem, data) {
  2089. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  2090. var dataPoint = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  2091. return datasetLabel + ': (' + dataPoint.x + ', ' + dataPoint.y + ', ' + dataPoint.r + ')';
  2092. }
  2093. }
  2094. }
  2095. };
  2096. Chart.controllers.bubble = Chart.DatasetController.extend({
  2097. dataElementType: Chart.elements.Point,
  2098. update: function(reset) {
  2099. var me = this;
  2100. var meta = me.getMeta();
  2101. var points = meta.data;
  2102. // Update Points
  2103. helpers.each(points, function(point, index) {
  2104. me.updateElement(point, index, reset);
  2105. });
  2106. },
  2107. updateElement: function(point, index, reset) {
  2108. var me = this;
  2109. var meta = me.getMeta();
  2110. var xScale = me.getScaleForId(meta.xAxisID);
  2111. var yScale = me.getScaleForId(meta.yAxisID);
  2112. var custom = point.custom || {};
  2113. var dataset = me.getDataset();
  2114. var data = dataset.data[index];
  2115. var pointElementOptions = me.chart.options.elements.point;
  2116. var dsIndex = me.index;
  2117. helpers.extend(point, {
  2118. // Utility
  2119. _xScale: xScale,
  2120. _yScale: yScale,
  2121. _datasetIndex: dsIndex,
  2122. _index: index,
  2123. // Desired view properties
  2124. _model: {
  2125. x: reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex, me.chart.isCombo),
  2126. y: reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex),
  2127. // Appearance
  2128. radius: reset ? 0 : custom.radius ? custom.radius : me.getRadius(data),
  2129. // Tooltip
  2130. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.hitRadius, index, pointElementOptions.hitRadius)
  2131. }
  2132. });
  2133. // Trick to reset the styles of the point
  2134. Chart.DatasetController.prototype.removeHoverStyle.call(me, point, pointElementOptions);
  2135. var model = point._model;
  2136. model.skip = custom.skip ? custom.skip : (isNaN(model.x) || isNaN(model.y));
  2137. point.pivot();
  2138. },
  2139. getRadius: function(value) {
  2140. return value.r || this.chart.options.elements.point.radius;
  2141. },
  2142. setHoverStyle: function(point) {
  2143. var me = this;
  2144. Chart.DatasetController.prototype.setHoverStyle.call(me, point);
  2145. // Radius
  2146. var dataset = me.chart.data.datasets[point._datasetIndex];
  2147. var index = point._index;
  2148. var custom = point.custom || {};
  2149. var model = point._model;
  2150. model.radius = custom.hoverRadius ? custom.hoverRadius : (helpers.getValueAtIndexOrDefault(dataset.hoverRadius, index, me.chart.options.elements.point.hoverRadius)) + me.getRadius(dataset.data[index]);
  2151. },
  2152. removeHoverStyle: function(point) {
  2153. var me = this;
  2154. Chart.DatasetController.prototype.removeHoverStyle.call(me, point, me.chart.options.elements.point);
  2155. var dataVal = me.chart.data.datasets[point._datasetIndex].data[point._index];
  2156. var custom = point.custom || {};
  2157. var model = point._model;
  2158. model.radius = custom.radius ? custom.radius : me.getRadius(dataVal);
  2159. }
  2160. });
  2161. };
  2162. },{}],17:[function(require,module,exports){
  2163. 'use strict';
  2164. module.exports = function(Chart) {
  2165. var helpers = Chart.helpers,
  2166. defaults = Chart.defaults;
  2167. defaults.doughnut = {
  2168. animation: {
  2169. // Boolean - Whether we animate the rotation of the Doughnut
  2170. animateRotate: true,
  2171. // Boolean - Whether we animate scaling the Doughnut from the centre
  2172. animateScale: false
  2173. },
  2174. aspectRatio: 1,
  2175. hover: {
  2176. mode: 'single'
  2177. },
  2178. legendCallback: function(chart) {
  2179. var text = [];
  2180. text.push('<ul class="' + chart.id + '-legend">');
  2181. var data = chart.data;
  2182. var datasets = data.datasets;
  2183. var labels = data.labels;
  2184. if (datasets.length) {
  2185. for (var i = 0; i < datasets[0].data.length; ++i) {
  2186. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2187. if (labels[i]) {
  2188. text.push(labels[i]);
  2189. }
  2190. text.push('</li>');
  2191. }
  2192. }
  2193. text.push('</ul>');
  2194. return text.join('');
  2195. },
  2196. legend: {
  2197. labels: {
  2198. generateLabels: function(chart) {
  2199. var data = chart.data;
  2200. if (data.labels.length && data.datasets.length) {
  2201. return data.labels.map(function(label, i) {
  2202. var meta = chart.getDatasetMeta(0);
  2203. var ds = data.datasets[0];
  2204. var arc = meta.data[i];
  2205. var custom = arc && arc.custom || {};
  2206. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2207. var arcOpts = chart.options.elements.arc;
  2208. var fill = custom.backgroundColor ? custom.backgroundColor : getValueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2209. var stroke = custom.borderColor ? custom.borderColor : getValueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2210. var bw = custom.borderWidth ? custom.borderWidth : getValueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2211. return {
  2212. text: label,
  2213. fillStyle: fill,
  2214. strokeStyle: stroke,
  2215. lineWidth: bw,
  2216. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2217. // Extra data used for toggling the correct item
  2218. index: i
  2219. };
  2220. });
  2221. }
  2222. return [];
  2223. }
  2224. },
  2225. onClick: function(e, legendItem) {
  2226. var index = legendItem.index;
  2227. var chart = this.chart;
  2228. var i, ilen, meta;
  2229. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2230. meta = chart.getDatasetMeta(i);
  2231. // toggle visibility of index if exists
  2232. if (meta.data[index]) {
  2233. meta.data[index].hidden = !meta.data[index].hidden;
  2234. }
  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. }
  2390. return 0;
  2391. },
  2392. // gets the max border or hover width to properly scale pie charts
  2393. getMaxBorderWidth: function(elements) {
  2394. var max = 0,
  2395. index = this.index,
  2396. length = elements.length,
  2397. borderWidth,
  2398. hoverWidth;
  2399. for (var i = 0; i < length; i++) {
  2400. borderWidth = elements[i]._model ? elements[i]._model.borderWidth : 0;
  2401. hoverWidth = elements[i]._chart ? elements[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
  2402. max = borderWidth > max ? borderWidth : max;
  2403. max = hoverWidth > max ? hoverWidth : max;
  2404. }
  2405. return max;
  2406. }
  2407. });
  2408. };
  2409. },{}],18:[function(require,module,exports){
  2410. 'use strict';
  2411. module.exports = function(Chart) {
  2412. var helpers = Chart.helpers;
  2413. Chart.defaults.line = {
  2414. showLines: true,
  2415. spanGaps: false,
  2416. hover: {
  2417. mode: 'label'
  2418. },
  2419. scales: {
  2420. xAxes: [{
  2421. type: 'category',
  2422. id: 'x-axis-0'
  2423. }],
  2424. yAxes: [{
  2425. type: 'linear',
  2426. id: 'y-axis-0'
  2427. }]
  2428. }
  2429. };
  2430. function lineEnabled(dataset, options) {
  2431. return helpers.getValueOrDefault(dataset.showLine, options.showLines);
  2432. }
  2433. Chart.controllers.line = Chart.DatasetController.extend({
  2434. datasetElementType: Chart.elements.Line,
  2435. dataElementType: Chart.elements.Point,
  2436. addElementAndReset: function(index) {
  2437. var me = this;
  2438. var options = me.chart.options;
  2439. var meta = me.getMeta();
  2440. Chart.DatasetController.prototype.addElementAndReset.call(me, index);
  2441. // Make sure bezier control points are updated
  2442. if (lineEnabled(me.getDataset(), options) && meta.dataset._model.tension !== 0) {
  2443. me.updateBezierControlPoints();
  2444. }
  2445. },
  2446. update: function(reset) {
  2447. var me = this;
  2448. var meta = me.getMeta();
  2449. var line = meta.dataset;
  2450. var points = meta.data || [];
  2451. var options = me.chart.options;
  2452. var lineElementOptions = options.elements.line;
  2453. var scale = me.getScaleForId(meta.yAxisID);
  2454. var i, ilen, custom;
  2455. var dataset = me.getDataset();
  2456. var showLine = lineEnabled(dataset, options);
  2457. // Update Line
  2458. if (showLine) {
  2459. custom = line.custom || {};
  2460. // Compatibility: If the properties are defined with only the old name, use those values
  2461. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2462. dataset.lineTension = dataset.tension;
  2463. }
  2464. // Utility
  2465. line._scale = scale;
  2466. line._datasetIndex = me.index;
  2467. // Data
  2468. line._children = points;
  2469. // Model
  2470. line._model = {
  2471. // Appearance
  2472. // The default behavior of lines is to break at null values, according
  2473. // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
  2474. // This option gives linse the ability to span gaps
  2475. spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
  2476. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2477. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2478. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2479. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2480. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2481. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2482. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2483. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2484. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2485. steppedLine: custom.steppedLine ? custom.steppedLine : helpers.getValueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
  2486. cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.getValueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode),
  2487. // Scale
  2488. scaleTop: scale.top,
  2489. scaleBottom: scale.bottom,
  2490. scaleZero: scale.getBasePixel()
  2491. };
  2492. line.pivot();
  2493. }
  2494. // Update Points
  2495. for (i=0, ilen=points.length; i<ilen; ++i) {
  2496. me.updateElement(points[i], i, reset);
  2497. }
  2498. if (showLine && line._model.tension !== 0) {
  2499. me.updateBezierControlPoints();
  2500. }
  2501. // Now pivot the point for animation
  2502. for (i=0, ilen=points.length; i<ilen; ++i) {
  2503. points[i].pivot();
  2504. }
  2505. },
  2506. getPointBackgroundColor: function(point, index) {
  2507. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  2508. var dataset = this.getDataset();
  2509. var custom = point.custom || {};
  2510. if (custom.backgroundColor) {
  2511. backgroundColor = custom.backgroundColor;
  2512. } else if (dataset.pointBackgroundColor) {
  2513. backgroundColor = helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  2514. } else if (dataset.backgroundColor) {
  2515. backgroundColor = dataset.backgroundColor;
  2516. }
  2517. return backgroundColor;
  2518. },
  2519. getPointBorderColor: function(point, index) {
  2520. var borderColor = this.chart.options.elements.point.borderColor;
  2521. var dataset = this.getDataset();
  2522. var custom = point.custom || {};
  2523. if (custom.borderColor) {
  2524. borderColor = custom.borderColor;
  2525. } else if (dataset.pointBorderColor) {
  2526. borderColor = helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
  2527. } else if (dataset.borderColor) {
  2528. borderColor = dataset.borderColor;
  2529. }
  2530. return borderColor;
  2531. },
  2532. getPointBorderWidth: function(point, index) {
  2533. var borderWidth = this.chart.options.elements.point.borderWidth;
  2534. var dataset = this.getDataset();
  2535. var custom = point.custom || {};
  2536. if (custom.borderWidth) {
  2537. borderWidth = custom.borderWidth;
  2538. } else if (dataset.pointBorderWidth) {
  2539. borderWidth = helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  2540. } else if (dataset.borderWidth) {
  2541. borderWidth = dataset.borderWidth;
  2542. }
  2543. return borderWidth;
  2544. },
  2545. updateElement: function(point, index, reset) {
  2546. var me = this;
  2547. var meta = me.getMeta();
  2548. var custom = point.custom || {};
  2549. var dataset = me.getDataset();
  2550. var datasetIndex = me.index;
  2551. var value = dataset.data[index];
  2552. var yScale = me.getScaleForId(meta.yAxisID);
  2553. var xScale = me.getScaleForId(meta.xAxisID);
  2554. var pointOptions = me.chart.options.elements.point;
  2555. var x, y;
  2556. var labels = me.chart.data.labels || [];
  2557. var includeOffset = (labels.length === 1 || dataset.data.length === 1) || me.chart.isCombo;
  2558. // Compatibility: If the properties are defined with only the old name, use those values
  2559. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2560. dataset.pointRadius = dataset.radius;
  2561. }
  2562. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  2563. dataset.pointHitRadius = dataset.hitRadius;
  2564. }
  2565. x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex, includeOffset);
  2566. y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
  2567. // Utility
  2568. point._xScale = xScale;
  2569. point._yScale = yScale;
  2570. point._datasetIndex = datasetIndex;
  2571. point._index = index;
  2572. // Desired view properties
  2573. point._model = {
  2574. x: x,
  2575. y: y,
  2576. skip: custom.skip || isNaN(x) || isNaN(y),
  2577. // Appearance
  2578. radius: custom.radius || helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
  2579. pointStyle: custom.pointStyle || helpers.getValueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
  2580. backgroundColor: me.getPointBackgroundColor(point, index),
  2581. borderColor: me.getPointBorderColor(point, index),
  2582. borderWidth: me.getPointBorderWidth(point, index),
  2583. tension: meta.dataset._model ? meta.dataset._model.tension : 0,
  2584. steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
  2585. // Tooltip
  2586. hitRadius: custom.hitRadius || helpers.getValueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
  2587. };
  2588. },
  2589. calculatePointY: function(value, index, datasetIndex) {
  2590. var me = this;
  2591. var chart = me.chart;
  2592. var meta = me.getMeta();
  2593. var yScale = me.getScaleForId(meta.yAxisID);
  2594. var sumPos = 0;
  2595. var sumNeg = 0;
  2596. var i, ds, dsMeta;
  2597. if (yScale.options.stacked) {
  2598. for (i = 0; i < datasetIndex; i++) {
  2599. ds = chart.data.datasets[i];
  2600. dsMeta = chart.getDatasetMeta(i);
  2601. if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  2602. var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
  2603. if (stackedRightValue < 0) {
  2604. sumNeg += stackedRightValue || 0;
  2605. } else {
  2606. sumPos += stackedRightValue || 0;
  2607. }
  2608. }
  2609. }
  2610. var rightValue = Number(yScale.getRightValue(value));
  2611. if (rightValue < 0) {
  2612. return yScale.getPixelForValue(sumNeg + rightValue);
  2613. }
  2614. return yScale.getPixelForValue(sumPos + rightValue);
  2615. }
  2616. return yScale.getPixelForValue(value);
  2617. },
  2618. updateBezierControlPoints: function() {
  2619. var me = this;
  2620. var meta = me.getMeta();
  2621. var area = me.chart.chartArea;
  2622. var points = (meta.data || []);
  2623. var i, ilen, point, model, controlPoints;
  2624. // Only consider points that are drawn in case the spanGaps option is used
  2625. if (meta.dataset._model.spanGaps) {
  2626. points = points.filter(function(pt) {
  2627. return !pt._model.skip;
  2628. });
  2629. }
  2630. function capControlPoint(pt, min, max) {
  2631. return Math.max(Math.min(pt, max), min);
  2632. }
  2633. if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
  2634. helpers.splineCurveMonotone(points);
  2635. } else {
  2636. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2637. point = points[i];
  2638. model = point._model;
  2639. controlPoints = helpers.splineCurve(
  2640. helpers.previousItem(points, i)._model,
  2641. model,
  2642. helpers.nextItem(points, i)._model,
  2643. meta.dataset._model.tension
  2644. );
  2645. model.controlPointPreviousX = controlPoints.previous.x;
  2646. model.controlPointPreviousY = controlPoints.previous.y;
  2647. model.controlPointNextX = controlPoints.next.x;
  2648. model.controlPointNextY = controlPoints.next.y;
  2649. }
  2650. }
  2651. if (me.chart.options.elements.line.capBezierPoints) {
  2652. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2653. model = points[i]._model;
  2654. model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
  2655. model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
  2656. model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
  2657. model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
  2658. }
  2659. }
  2660. },
  2661. draw: function(ease) {
  2662. var me = this;
  2663. var meta = me.getMeta();
  2664. var points = meta.data || [];
  2665. var easingDecimal = ease || 1;
  2666. var i, ilen;
  2667. // Transition Point Locations
  2668. for (i=0, ilen=points.length; i<ilen; ++i) {
  2669. points[i].transition(easingDecimal);
  2670. }
  2671. // Transition and Draw the line
  2672. if (lineEnabled(me.getDataset(), me.chart.options)) {
  2673. meta.dataset.transition(easingDecimal).draw();
  2674. }
  2675. // Draw the points
  2676. for (i=0, ilen=points.length; i<ilen; ++i) {
  2677. points[i].draw();
  2678. }
  2679. },
  2680. setHoverStyle: function(point) {
  2681. // Point
  2682. var dataset = this.chart.data.datasets[point._datasetIndex];
  2683. var index = point._index;
  2684. var custom = point.custom || {};
  2685. var model = point._model;
  2686. model.radius = custom.hoverRadius || helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  2687. model.backgroundColor = custom.hoverBackgroundColor || helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  2688. model.borderColor = custom.hoverBorderColor || helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  2689. model.borderWidth = custom.hoverBorderWidth || helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  2690. },
  2691. removeHoverStyle: function(point) {
  2692. var me = this;
  2693. var dataset = me.chart.data.datasets[point._datasetIndex];
  2694. var index = point._index;
  2695. var custom = point.custom || {};
  2696. var model = point._model;
  2697. // Compatibility: If the properties are defined with only the old name, use those values
  2698. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2699. dataset.pointRadius = dataset.radius;
  2700. }
  2701. model.radius = custom.radius || helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, me.chart.options.elements.point.radius);
  2702. model.backgroundColor = me.getPointBackgroundColor(point, index);
  2703. model.borderColor = me.getPointBorderColor(point, index);
  2704. model.borderWidth = me.getPointBorderWidth(point, index);
  2705. }
  2706. });
  2707. };
  2708. },{}],19:[function(require,module,exports){
  2709. 'use strict';
  2710. module.exports = function(Chart) {
  2711. var helpers = Chart.helpers;
  2712. Chart.defaults.polarArea = {
  2713. scale: {
  2714. type: 'radialLinear',
  2715. lineArc: true, // so that lines are circular
  2716. ticks: {
  2717. beginAtZero: true
  2718. }
  2719. },
  2720. // Boolean - Whether to animate the rotation of the chart
  2721. animation: {
  2722. animateRotate: true,
  2723. animateScale: true
  2724. },
  2725. startAngle: -0.5 * Math.PI,
  2726. aspectRatio: 1,
  2727. legendCallback: function(chart) {
  2728. var text = [];
  2729. text.push('<ul class="' + chart.id + '-legend">');
  2730. var data = chart.data;
  2731. var datasets = data.datasets;
  2732. var labels = data.labels;
  2733. if (datasets.length) {
  2734. for (var i = 0; i < datasets[0].data.length; ++i) {
  2735. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '">');
  2736. if (labels[i]) {
  2737. text.push(labels[i]);
  2738. }
  2739. text.push('</span></li>');
  2740. }
  2741. }
  2742. text.push('</ul>');
  2743. return text.join('');
  2744. },
  2745. legend: {
  2746. labels: {
  2747. generateLabels: function(chart) {
  2748. var data = chart.data;
  2749. if (data.labels.length && data.datasets.length) {
  2750. return data.labels.map(function(label, i) {
  2751. var meta = chart.getDatasetMeta(0);
  2752. var ds = data.datasets[0];
  2753. var arc = meta.data[i];
  2754. var custom = arc.custom || {};
  2755. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2756. var arcOpts = chart.options.elements.arc;
  2757. var fill = custom.backgroundColor ? custom.backgroundColor : getValueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2758. var stroke = custom.borderColor ? custom.borderColor : getValueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2759. var bw = custom.borderWidth ? custom.borderWidth : getValueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2760. return {
  2761. text: label,
  2762. fillStyle: fill,
  2763. strokeStyle: stroke,
  2764. lineWidth: bw,
  2765. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2766. // Extra data used for toggling the correct item
  2767. index: i
  2768. };
  2769. });
  2770. }
  2771. return [];
  2772. }
  2773. },
  2774. onClick: function(e, legendItem) {
  2775. var index = legendItem.index;
  2776. var chart = this.chart;
  2777. var i, ilen, meta;
  2778. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2779. meta = chart.getDatasetMeta(i);
  2780. meta.data[index].hidden = !meta.data[index].hidden;
  2781. }
  2782. chart.update();
  2783. }
  2784. },
  2785. // Need to override these to give a nice default
  2786. tooltips: {
  2787. callbacks: {
  2788. title: function() {
  2789. return '';
  2790. },
  2791. label: function(tooltipItem, data) {
  2792. return data.labels[tooltipItem.index] + ': ' + tooltipItem.yLabel;
  2793. }
  2794. }
  2795. }
  2796. };
  2797. Chart.controllers.polarArea = Chart.DatasetController.extend({
  2798. dataElementType: Chart.elements.Arc,
  2799. linkScales: helpers.noop,
  2800. update: function(reset) {
  2801. var me = this;
  2802. var chart = me.chart;
  2803. var chartArea = chart.chartArea;
  2804. var meta = me.getMeta();
  2805. var opts = chart.options;
  2806. var arcOpts = opts.elements.arc;
  2807. var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
  2808. chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
  2809. chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
  2810. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2811. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
  2812. me.innerRadius = me.outerRadius - chart.radiusLength;
  2813. meta.count = me.countVisibleElements();
  2814. helpers.each(meta.data, function(arc, index) {
  2815. me.updateElement(arc, index, reset);
  2816. });
  2817. },
  2818. updateElement: function(arc, index, reset) {
  2819. var me = this;
  2820. var chart = me.chart;
  2821. var dataset = me.getDataset();
  2822. var opts = chart.options;
  2823. var animationOpts = opts.animation;
  2824. var scale = chart.scale;
  2825. var getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault;
  2826. var labels = chart.data.labels;
  2827. var circumference = me.calculateCircumference(dataset.data[index]);
  2828. var centerX = scale.xCenter;
  2829. var centerY = scale.yCenter;
  2830. // If there is NaN data before us, we need to calculate the starting angle correctly.
  2831. // We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
  2832. var visibleCount = 0;
  2833. var meta = me.getMeta();
  2834. for (var i = 0; i < index; ++i) {
  2835. if (!isNaN(dataset.data[i]) && !meta.data[i].hidden) {
  2836. ++visibleCount;
  2837. }
  2838. }
  2839. // var negHalfPI = -0.5 * Math.PI;
  2840. var datasetStartAngle = opts.startAngle;
  2841. var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2842. var startAngle = datasetStartAngle + (circumference * visibleCount);
  2843. var endAngle = startAngle + (arc.hidden ? 0 : circumference);
  2844. var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2845. helpers.extend(arc, {
  2846. // Utility
  2847. _datasetIndex: me.index,
  2848. _index: index,
  2849. _scale: scale,
  2850. // Desired view properties
  2851. _model: {
  2852. x: centerX,
  2853. y: centerY,
  2854. innerRadius: 0,
  2855. outerRadius: reset ? resetRadius : distance,
  2856. startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
  2857. endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
  2858. label: getValueAtIndexOrDefault(labels, index, labels[index])
  2859. }
  2860. });
  2861. // Apply border and fill style
  2862. me.removeHoverStyle(arc);
  2863. arc.pivot();
  2864. },
  2865. removeHoverStyle: function(arc) {
  2866. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  2867. },
  2868. countVisibleElements: function() {
  2869. var dataset = this.getDataset();
  2870. var meta = this.getMeta();
  2871. var count = 0;
  2872. helpers.each(meta.data, function(element, index) {
  2873. if (!isNaN(dataset.data[index]) && !element.hidden) {
  2874. count++;
  2875. }
  2876. });
  2877. return count;
  2878. },
  2879. calculateCircumference: function(value) {
  2880. var count = this.getMeta().count;
  2881. if (count > 0 && !isNaN(value)) {
  2882. return (2 * Math.PI) / count;
  2883. }
  2884. return 0;
  2885. }
  2886. });
  2887. };
  2888. },{}],20:[function(require,module,exports){
  2889. 'use strict';
  2890. module.exports = function(Chart) {
  2891. var helpers = Chart.helpers;
  2892. Chart.defaults.radar = {
  2893. scale: {
  2894. type: 'radialLinear'
  2895. },
  2896. elements: {
  2897. line: {
  2898. tension: 0 // no bezier in radar
  2899. }
  2900. }
  2901. };
  2902. Chart.controllers.radar = Chart.DatasetController.extend({
  2903. datasetElementType: Chart.elements.Line,
  2904. dataElementType: Chart.elements.Point,
  2905. linkScales: helpers.noop,
  2906. addElementAndReset: function(index) {
  2907. Chart.DatasetController.prototype.addElementAndReset.call(this, index);
  2908. // Make sure bezier control points are updated
  2909. this.updateBezierControlPoints();
  2910. },
  2911. update: function(reset) {
  2912. var me = this;
  2913. var meta = me.getMeta();
  2914. var line = meta.dataset;
  2915. var points = meta.data;
  2916. var custom = line.custom || {};
  2917. var dataset = me.getDataset();
  2918. var lineElementOptions = me.chart.options.elements.line;
  2919. var scale = me.chart.scale;
  2920. // Compatibility: If the properties are defined with only the old name, use those values
  2921. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2922. dataset.lineTension = dataset.tension;
  2923. }
  2924. helpers.extend(meta.dataset, {
  2925. // Utility
  2926. _datasetIndex: me.index,
  2927. // Data
  2928. _children: points,
  2929. _loop: true,
  2930. // Model
  2931. _model: {
  2932. // Appearance
  2933. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2934. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2935. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2936. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2937. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2938. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2939. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2940. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2941. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2942. // Scale
  2943. scaleTop: scale.top,
  2944. scaleBottom: scale.bottom,
  2945. scaleZero: scale.getBasePosition()
  2946. }
  2947. });
  2948. meta.dataset.pivot();
  2949. // Update Points
  2950. helpers.each(points, function(point, index) {
  2951. me.updateElement(point, index, reset);
  2952. }, me);
  2953. // Update bezier control points
  2954. me.updateBezierControlPoints();
  2955. },
  2956. updateElement: function(point, index, reset) {
  2957. var me = this;
  2958. var custom = point.custom || {};
  2959. var dataset = me.getDataset();
  2960. var scale = me.chart.scale;
  2961. var pointElementOptions = me.chart.options.elements.point;
  2962. var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
  2963. helpers.extend(point, {
  2964. // Utility
  2965. _datasetIndex: me.index,
  2966. _index: index,
  2967. _scale: scale,
  2968. // Desired view properties
  2969. _model: {
  2970. x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  2971. y: reset ? scale.yCenter : pointPosition.y,
  2972. // Appearance
  2973. tension: custom.tension ? custom.tension : helpers.getValueOrDefault(dataset.tension, me.chart.options.elements.line.tension),
  2974. radius: custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
  2975. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
  2976. borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
  2977. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
  2978. pointStyle: custom.pointStyle ? custom.pointStyle : helpers.getValueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
  2979. // Tooltip
  2980. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.getValueAtIndexOrDefault(dataset.hitRadius, index, pointElementOptions.hitRadius)
  2981. }
  2982. });
  2983. point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  2984. },
  2985. updateBezierControlPoints: function() {
  2986. var chartArea = this.chart.chartArea;
  2987. var meta = this.getMeta();
  2988. helpers.each(meta.data, function(point, index) {
  2989. var model = point._model;
  2990. var controlPoints = helpers.splineCurve(
  2991. helpers.previousItem(meta.data, index, true)._model,
  2992. model,
  2993. helpers.nextItem(meta.data, index, true)._model,
  2994. model.tension
  2995. );
  2996. // Prevent the bezier going outside of the bounds of the graph
  2997. model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, chartArea.right), chartArea.left);
  2998. model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, chartArea.bottom), chartArea.top);
  2999. model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, chartArea.right), chartArea.left);
  3000. model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, chartArea.bottom), chartArea.top);
  3001. // Now pivot the point for animation
  3002. point.pivot();
  3003. });
  3004. },
  3005. draw: function(ease) {
  3006. var meta = this.getMeta();
  3007. var easingDecimal = ease || 1;
  3008. // Transition Point Locations
  3009. helpers.each(meta.data, function(point) {
  3010. point.transition(easingDecimal);
  3011. });
  3012. // Transition and Draw the line
  3013. meta.dataset.transition(easingDecimal).draw();
  3014. // Draw the points
  3015. helpers.each(meta.data, function(point) {
  3016. point.draw();
  3017. });
  3018. },
  3019. setHoverStyle: function(point) {
  3020. // Point
  3021. var dataset = this.chart.data.datasets[point._datasetIndex];
  3022. var custom = point.custom || {};
  3023. var index = point._index;
  3024. var model = point._model;
  3025. model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  3026. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  3027. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  3028. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  3029. },
  3030. removeHoverStyle: function(point) {
  3031. var dataset = this.chart.data.datasets[point._datasetIndex];
  3032. var custom = point.custom || {};
  3033. var index = point._index;
  3034. var model = point._model;
  3035. var pointElementOptions = this.chart.options.elements.point;
  3036. model.radius = custom.radius ? custom.radius : helpers.getValueAtIndexOrDefault(dataset.radius, index, pointElementOptions.radius);
  3037. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor);
  3038. model.borderColor = custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor);
  3039. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth);
  3040. }
  3041. });
  3042. };
  3043. },{}],21:[function(require,module,exports){
  3044. /* global window: false */
  3045. 'use strict';
  3046. module.exports = function(Chart) {
  3047. var helpers = Chart.helpers;
  3048. Chart.defaults.global.animation = {
  3049. duration: 1000,
  3050. easing: 'easeOutQuart',
  3051. onProgress: helpers.noop,
  3052. onComplete: helpers.noop
  3053. };
  3054. Chart.Animation = Chart.Element.extend({
  3055. currentStep: null, // the current animation step
  3056. numSteps: 60, // default number of steps
  3057. easing: '', // the easing to use for this animation
  3058. render: null, // render function used by the animation service
  3059. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  3060. onAnimationComplete: null // user specified callback to fire when the animation finishes
  3061. });
  3062. Chart.animationService = {
  3063. frameDuration: 17,
  3064. animations: [],
  3065. dropFrames: 0,
  3066. request: null,
  3067. addAnimation: function(chartInstance, animationObject, duration, lazy) {
  3068. var me = this;
  3069. if (!lazy) {
  3070. chartInstance.animating = true;
  3071. }
  3072. for (var index = 0; index < me.animations.length; ++index) {
  3073. if (me.animations[index].chartInstance === chartInstance) {
  3074. // replacing an in progress animation
  3075. me.animations[index].animationObject = animationObject;
  3076. return;
  3077. }
  3078. }
  3079. me.animations.push({
  3080. chartInstance: chartInstance,
  3081. animationObject: animationObject
  3082. });
  3083. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  3084. if (me.animations.length === 1) {
  3085. me.requestAnimationFrame();
  3086. }
  3087. },
  3088. // Cancel the animation for a given chart instance
  3089. cancelAnimation: function(chartInstance) {
  3090. var index = helpers.findIndex(this.animations, function(animationWrapper) {
  3091. return animationWrapper.chartInstance === chartInstance;
  3092. });
  3093. if (index !== -1) {
  3094. this.animations.splice(index, 1);
  3095. chartInstance.animating = false;
  3096. }
  3097. },
  3098. requestAnimationFrame: function() {
  3099. var me = this;
  3100. if (me.request === null) {
  3101. // Skip animation frame requests until the active one is executed.
  3102. // This can happen when processing mouse events, e.g. 'mousemove'
  3103. // and 'mouseout' events will trigger multiple renders.
  3104. me.request = helpers.requestAnimFrame.call(window, function() {
  3105. me.request = null;
  3106. me.startDigest();
  3107. });
  3108. }
  3109. },
  3110. startDigest: function() {
  3111. var me = this;
  3112. var startTime = Date.now();
  3113. var framesToDrop = 0;
  3114. if (me.dropFrames > 1) {
  3115. framesToDrop = Math.floor(me.dropFrames);
  3116. me.dropFrames = me.dropFrames % 1;
  3117. }
  3118. var i = 0;
  3119. while (i < me.animations.length) {
  3120. if (me.animations[i].animationObject.currentStep === null) {
  3121. me.animations[i].animationObject.currentStep = 0;
  3122. }
  3123. me.animations[i].animationObject.currentStep += 1 + framesToDrop;
  3124. if (me.animations[i].animationObject.currentStep > me.animations[i].animationObject.numSteps) {
  3125. me.animations[i].animationObject.currentStep = me.animations[i].animationObject.numSteps;
  3126. }
  3127. me.animations[i].animationObject.render(me.animations[i].chartInstance, me.animations[i].animationObject);
  3128. if (me.animations[i].animationObject.onAnimationProgress && me.animations[i].animationObject.onAnimationProgress.call) {
  3129. me.animations[i].animationObject.onAnimationProgress.call(me.animations[i].chartInstance, me.animations[i]);
  3130. }
  3131. if (me.animations[i].animationObject.currentStep === me.animations[i].animationObject.numSteps) {
  3132. if (me.animations[i].animationObject.onAnimationComplete && me.animations[i].animationObject.onAnimationComplete.call) {
  3133. me.animations[i].animationObject.onAnimationComplete.call(me.animations[i].chartInstance, me.animations[i]);
  3134. }
  3135. // executed the last frame. Remove the animation.
  3136. me.animations[i].chartInstance.animating = false;
  3137. me.animations.splice(i, 1);
  3138. } else {
  3139. ++i;
  3140. }
  3141. }
  3142. var endTime = Date.now();
  3143. var dropFrames = (endTime - startTime) / me.frameDuration;
  3144. me.dropFrames += dropFrames;
  3145. // Do we have more stuff to animate?
  3146. if (me.animations.length > 0) {
  3147. me.requestAnimationFrame();
  3148. }
  3149. }
  3150. };
  3151. };
  3152. },{}],22:[function(require,module,exports){
  3153. 'use strict';
  3154. module.exports = function(Chart) {
  3155. // Global Chart canvas helpers object for drawing items to canvas
  3156. var helpers = Chart.canvasHelpers = {};
  3157. helpers.drawPoint = function(ctx, pointStyle, radius, x, y) {
  3158. var type, edgeLength, xOffset, yOffset, height, size;
  3159. if (typeof pointStyle === 'object') {
  3160. type = pointStyle.toString();
  3161. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  3162. ctx.drawImage(pointStyle, x - pointStyle.width / 2, y - pointStyle.height / 2);
  3163. return;
  3164. }
  3165. }
  3166. if (isNaN(radius) || radius <= 0) {
  3167. return;
  3168. }
  3169. switch (pointStyle) {
  3170. // Default includes circle
  3171. default:
  3172. ctx.beginPath();
  3173. ctx.arc(x, y, radius, 0, Math.PI * 2);
  3174. ctx.closePath();
  3175. ctx.fill();
  3176. break;
  3177. case 'triangle':
  3178. ctx.beginPath();
  3179. edgeLength = 3 * radius / Math.sqrt(3);
  3180. height = edgeLength * Math.sqrt(3) / 2;
  3181. ctx.moveTo(x - edgeLength / 2, y + height / 3);
  3182. ctx.lineTo(x + edgeLength / 2, y + height / 3);
  3183. ctx.lineTo(x, y - 2 * height / 3);
  3184. ctx.closePath();
  3185. ctx.fill();
  3186. break;
  3187. case 'rect':
  3188. size = 1 / Math.SQRT2 * radius;
  3189. ctx.beginPath();
  3190. ctx.fillRect(x - size, y - size, 2 * size, 2 * size);
  3191. ctx.strokeRect(x - size, y - size, 2 * size, 2 * size);
  3192. break;
  3193. case 'rectRot':
  3194. size = 1 / Math.SQRT2 * radius;
  3195. ctx.beginPath();
  3196. ctx.moveTo(x - size, y);
  3197. ctx.lineTo(x, y + size);
  3198. ctx.lineTo(x + size, y);
  3199. ctx.lineTo(x, y - size);
  3200. ctx.closePath();
  3201. ctx.fill();
  3202. break;
  3203. case 'cross':
  3204. ctx.beginPath();
  3205. ctx.moveTo(x, y + radius);
  3206. ctx.lineTo(x, y - radius);
  3207. ctx.moveTo(x - radius, y);
  3208. ctx.lineTo(x + radius, y);
  3209. ctx.closePath();
  3210. break;
  3211. case 'crossRot':
  3212. ctx.beginPath();
  3213. xOffset = Math.cos(Math.PI / 4) * radius;
  3214. yOffset = Math.sin(Math.PI / 4) * radius;
  3215. ctx.moveTo(x - xOffset, y - yOffset);
  3216. ctx.lineTo(x + xOffset, y + yOffset);
  3217. ctx.moveTo(x - xOffset, y + yOffset);
  3218. ctx.lineTo(x + xOffset, y - yOffset);
  3219. ctx.closePath();
  3220. break;
  3221. case 'star':
  3222. ctx.beginPath();
  3223. ctx.moveTo(x, y + radius);
  3224. ctx.lineTo(x, y - radius);
  3225. ctx.moveTo(x - radius, y);
  3226. ctx.lineTo(x + radius, y);
  3227. xOffset = Math.cos(Math.PI / 4) * radius;
  3228. yOffset = Math.sin(Math.PI / 4) * radius;
  3229. ctx.moveTo(x - xOffset, y - yOffset);
  3230. ctx.lineTo(x + xOffset, y + yOffset);
  3231. ctx.moveTo(x - xOffset, y + yOffset);
  3232. ctx.lineTo(x + xOffset, y - yOffset);
  3233. ctx.closePath();
  3234. break;
  3235. case 'line':
  3236. ctx.beginPath();
  3237. ctx.moveTo(x - radius, y);
  3238. ctx.lineTo(x + radius, y);
  3239. ctx.closePath();
  3240. break;
  3241. case 'dash':
  3242. ctx.beginPath();
  3243. ctx.moveTo(x, y);
  3244. ctx.lineTo(x + radius, y);
  3245. ctx.closePath();
  3246. break;
  3247. }
  3248. ctx.stroke();
  3249. };
  3250. };
  3251. },{}],23:[function(require,module,exports){
  3252. 'use strict';
  3253. module.exports = function(Chart) {
  3254. var helpers = Chart.helpers;
  3255. // Create a dictionary of chart types, to allow for extension of existing types
  3256. Chart.types = {};
  3257. // Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  3258. // Destroy method on the chart will remove the instance of the chart from this reference.
  3259. Chart.instances = {};
  3260. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  3261. Chart.controllers = {};
  3262. /**
  3263. * @class Chart.Controller
  3264. * The main controller of a chart.
  3265. */
  3266. Chart.Controller = function(instance) {
  3267. this.chart = instance;
  3268. this.config = instance.config;
  3269. this.options = this.config.options = helpers.configMerge(Chart.defaults.global, Chart.defaults[this.config.type], this.config.options || {});
  3270. this.id = helpers.uid();
  3271. Object.defineProperty(this, 'data', {
  3272. get: function() {
  3273. return this.config.data;
  3274. }
  3275. });
  3276. // Add the chart instance to the global namespace
  3277. Chart.instances[this.id] = this;
  3278. if (this.options.responsive) {
  3279. // Silent resize before chart draws
  3280. this.resize(true);
  3281. }
  3282. this.initialize();
  3283. return this;
  3284. };
  3285. helpers.extend(Chart.Controller.prototype, /** @lends Chart.Controller */ {
  3286. initialize: function() {
  3287. var me = this;
  3288. // Before init plugin notification
  3289. Chart.plugins.notify('beforeInit', [me]);
  3290. me.bindEvents();
  3291. // Make sure controllers are built first so that each dataset is bound to an axis before the scales
  3292. // are built
  3293. me.ensureScalesHaveIDs();
  3294. me.buildOrUpdateControllers();
  3295. me.buildScales();
  3296. me.updateLayout();
  3297. me.resetElements();
  3298. me.initToolTip();
  3299. me.update();
  3300. // After init plugin notification
  3301. Chart.plugins.notify('afterInit', [me]);
  3302. return me;
  3303. },
  3304. clear: function() {
  3305. helpers.clear(this.chart);
  3306. return this;
  3307. },
  3308. stop: function() {
  3309. // Stops any current animation loop occuring
  3310. Chart.animationService.cancelAnimation(this);
  3311. return this;
  3312. },
  3313. resize: function(silent) {
  3314. var me = this;
  3315. var chart = me.chart;
  3316. var canvas = chart.canvas;
  3317. var newWidth = helpers.getMaximumWidth(canvas);
  3318. var aspectRatio = chart.aspectRatio;
  3319. var newHeight = (me.options.maintainAspectRatio && isNaN(aspectRatio) === false && isFinite(aspectRatio) && aspectRatio !== 0) ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas);
  3320. var sizeChanged = chart.width !== newWidth || chart.height !== newHeight;
  3321. if (!sizeChanged) {
  3322. return me;
  3323. }
  3324. canvas.width = chart.width = newWidth;
  3325. canvas.height = chart.height = newHeight;
  3326. helpers.retinaScale(chart);
  3327. // Notify any plugins about the resize
  3328. var newSize = {width: newWidth, height: newHeight};
  3329. Chart.plugins.notify('resize', [me, newSize]);
  3330. // Notify of resize
  3331. if (me.options.onResize) {
  3332. me.options.onResize(me, newSize);
  3333. }
  3334. if (!silent) {
  3335. me.stop();
  3336. me.update(me.options.responsiveAnimationDuration);
  3337. }
  3338. return me;
  3339. },
  3340. ensureScalesHaveIDs: function() {
  3341. var options = this.options;
  3342. var scalesOptions = options.scales || {};
  3343. var scaleOptions = options.scale;
  3344. helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
  3345. xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
  3346. });
  3347. helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
  3348. yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
  3349. });
  3350. if (scaleOptions) {
  3351. scaleOptions.id = scaleOptions.id || 'scale';
  3352. }
  3353. },
  3354. /**
  3355. * Builds a map of scale ID to scale object for future lookup.
  3356. */
  3357. buildScales: function() {
  3358. var me = this;
  3359. var options = me.options;
  3360. var scales = me.scales = {};
  3361. var items = [];
  3362. if (options.scales) {
  3363. items = items.concat(
  3364. (options.scales.xAxes || []).map(function(xAxisOptions) {
  3365. return {options: xAxisOptions, dtype: 'category'};
  3366. }),
  3367. (options.scales.yAxes || []).map(function(yAxisOptions) {
  3368. return {options: yAxisOptions, dtype: 'linear'};
  3369. })
  3370. );
  3371. }
  3372. if (options.scale) {
  3373. items.push({options: options.scale, dtype: 'radialLinear', isDefault: true});
  3374. }
  3375. helpers.each(items, function(item) {
  3376. var scaleOptions = item.options;
  3377. var scaleType = helpers.getValueOrDefault(scaleOptions.type, item.dtype);
  3378. var scaleClass = Chart.scaleService.getScaleConstructor(scaleType);
  3379. if (!scaleClass) {
  3380. return;
  3381. }
  3382. var scale = new scaleClass({
  3383. id: scaleOptions.id,
  3384. options: scaleOptions,
  3385. ctx: me.chart.ctx,
  3386. chart: me
  3387. });
  3388. scales[scale.id] = scale;
  3389. // TODO(SB): I think we should be able to remove this custom case (options.scale)
  3390. // and consider it as a regular scale part of the "scales"" map only! This would
  3391. // make the logic easier and remove some useless? custom code.
  3392. if (item.isDefault) {
  3393. me.scale = scale;
  3394. }
  3395. });
  3396. Chart.scaleService.addScalesToLayout(this);
  3397. },
  3398. updateLayout: function() {
  3399. Chart.layoutService.update(this, this.chart.width, this.chart.height);
  3400. },
  3401. buildOrUpdateControllers: function() {
  3402. var me = this;
  3403. var types = [];
  3404. var newControllers = [];
  3405. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3406. var meta = me.getDatasetMeta(datasetIndex);
  3407. if (!meta.type) {
  3408. meta.type = dataset.type || me.config.type;
  3409. }
  3410. types.push(meta.type);
  3411. if (meta.controller) {
  3412. meta.controller.updateIndex(datasetIndex);
  3413. } else {
  3414. meta.controller = new Chart.controllers[meta.type](me, datasetIndex);
  3415. newControllers.push(meta.controller);
  3416. }
  3417. }, me);
  3418. if (types.length > 1) {
  3419. for (var i = 1; i < types.length; i++) {
  3420. if (types[i] !== types[i - 1]) {
  3421. me.isCombo = true;
  3422. break;
  3423. }
  3424. }
  3425. }
  3426. return newControllers;
  3427. },
  3428. resetElements: function() {
  3429. var me = this;
  3430. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3431. me.getDatasetMeta(datasetIndex).controller.reset();
  3432. }, me);
  3433. },
  3434. update: function(animationDuration, lazy) {
  3435. var me = this;
  3436. Chart.plugins.notify('beforeUpdate', [me]);
  3437. // In case the entire data object changed
  3438. me.tooltip._data = me.data;
  3439. // Make sure dataset controllers are updated and new controllers are reset
  3440. var newControllers = me.buildOrUpdateControllers();
  3441. // Make sure all dataset controllers have correct meta data counts
  3442. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3443. me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
  3444. }, me);
  3445. Chart.layoutService.update(me, me.chart.width, me.chart.height);
  3446. // Apply changes to the dataets that require the scales to have been calculated i.e BorderColor chages
  3447. Chart.plugins.notify('afterScaleUpdate', [me]);
  3448. // Can only reset the new controllers after the scales have been updated
  3449. helpers.each(newControllers, function(controller) {
  3450. controller.reset();
  3451. });
  3452. me.updateDatasets();
  3453. // Do this before render so that any plugins that need final scale updates can use it
  3454. Chart.plugins.notify('afterUpdate', [me]);
  3455. me.render(animationDuration, lazy);
  3456. },
  3457. /**
  3458. * @method beforeDatasetsUpdate
  3459. * @description Called before all datasets are updated. If a plugin returns false,
  3460. * the datasets update will be cancelled until another chart update is triggered.
  3461. * @param {Object} instance the chart instance being updated.
  3462. * @returns {Boolean} false to cancel the datasets update.
  3463. * @memberof Chart.PluginBase
  3464. * @since version 2.1.5
  3465. * @instance
  3466. */
  3467. /**
  3468. * @method afterDatasetsUpdate
  3469. * @description Called after all datasets have been updated. Note that this
  3470. * extension will not be called if the datasets update has been cancelled.
  3471. * @param {Object} instance the chart instance being updated.
  3472. * @memberof Chart.PluginBase
  3473. * @since version 2.1.5
  3474. * @instance
  3475. */
  3476. /**
  3477. * Updates all datasets unless a plugin returns false to the beforeDatasetsUpdate
  3478. * extension, in which case no datasets will be updated and the afterDatasetsUpdate
  3479. * notification will be skipped.
  3480. * @protected
  3481. * @instance
  3482. */
  3483. updateDatasets: function() {
  3484. var me = this;
  3485. var i, ilen;
  3486. if (Chart.plugins.notify('beforeDatasetsUpdate', [me])) {
  3487. for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3488. me.getDatasetMeta(i).controller.update();
  3489. }
  3490. Chart.plugins.notify('afterDatasetsUpdate', [me]);
  3491. }
  3492. },
  3493. render: function(duration, lazy) {
  3494. var me = this;
  3495. Chart.plugins.notify('beforeRender', [me]);
  3496. var animationOptions = me.options.animation;
  3497. if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
  3498. var animation = new Chart.Animation();
  3499. animation.numSteps = (duration || animationOptions.duration) / 16.66; // 60 fps
  3500. animation.easing = animationOptions.easing;
  3501. // render function
  3502. animation.render = function(chartInstance, animationObject) {
  3503. var easingFunction = helpers.easingEffects[animationObject.easing];
  3504. var stepDecimal = animationObject.currentStep / animationObject.numSteps;
  3505. var easeDecimal = easingFunction(stepDecimal);
  3506. chartInstance.draw(easeDecimal, stepDecimal, animationObject.currentStep);
  3507. };
  3508. // user events
  3509. animation.onAnimationProgress = animationOptions.onProgress;
  3510. animation.onAnimationComplete = animationOptions.onComplete;
  3511. Chart.animationService.addAnimation(me, animation, duration, lazy);
  3512. } else {
  3513. me.draw();
  3514. if (animationOptions && animationOptions.onComplete && animationOptions.onComplete.call) {
  3515. animationOptions.onComplete.call(me);
  3516. }
  3517. }
  3518. return me;
  3519. },
  3520. draw: function(ease) {
  3521. var me = this;
  3522. var easingDecimal = ease || 1;
  3523. me.clear();
  3524. Chart.plugins.notify('beforeDraw', [me, easingDecimal]);
  3525. // Draw all the scales
  3526. helpers.each(me.boxes, function(box) {
  3527. box.draw(me.chartArea);
  3528. }, me);
  3529. if (me.scale) {
  3530. me.scale.draw();
  3531. }
  3532. Chart.plugins.notify('beforeDatasetsDraw', [me, easingDecimal]);
  3533. // Draw each dataset via its respective controller (reversed to support proper line stacking)
  3534. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3535. if (me.isDatasetVisible(datasetIndex)) {
  3536. me.getDatasetMeta(datasetIndex).controller.draw(ease);
  3537. }
  3538. }, me, true);
  3539. Chart.plugins.notify('afterDatasetsDraw', [me, easingDecimal]);
  3540. // Finally draw the tooltip
  3541. me.tooltip.transition(easingDecimal).draw();
  3542. Chart.plugins.notify('afterDraw', [me, easingDecimal]);
  3543. },
  3544. // Get the single element that was clicked on
  3545. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  3546. getElementAtEvent: function(e) {
  3547. var me = this;
  3548. var eventPosition = helpers.getRelativePosition(e, me.chart);
  3549. var elementsArray = [];
  3550. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3551. if (me.isDatasetVisible(datasetIndex)) {
  3552. var meta = me.getDatasetMeta(datasetIndex);
  3553. helpers.each(meta.data, function(element) {
  3554. if (element.inRange(eventPosition.x, eventPosition.y)) {
  3555. elementsArray.push(element);
  3556. return elementsArray;
  3557. }
  3558. });
  3559. }
  3560. });
  3561. return elementsArray.slice(0, 1);
  3562. },
  3563. getElementsAtEvent: function(e) {
  3564. var me = this;
  3565. var eventPosition = helpers.getRelativePosition(e, me.chart);
  3566. var elementsArray = [];
  3567. var found = function() {
  3568. if (me.data.datasets) {
  3569. for (var i = 0; i < me.data.datasets.length; i++) {
  3570. var meta = me.getDatasetMeta(i);
  3571. if (me.isDatasetVisible(i)) {
  3572. for (var j = 0; j < meta.data.length; j++) {
  3573. if (meta.data[j].inRange(eventPosition.x, eventPosition.y)) {
  3574. return meta.data[j];
  3575. }
  3576. }
  3577. }
  3578. }
  3579. }
  3580. }.call(me);
  3581. if (!found) {
  3582. return elementsArray;
  3583. }
  3584. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3585. if (me.isDatasetVisible(datasetIndex)) {
  3586. var meta = me.getDatasetMeta(datasetIndex),
  3587. element = meta.data[found._index];
  3588. if (element && !element._view.skip) {
  3589. elementsArray.push(element);
  3590. }
  3591. }
  3592. }, me);
  3593. return elementsArray;
  3594. },
  3595. getElementsAtXAxis: function(e) {
  3596. var me = this;
  3597. var eventPosition = helpers.getRelativePosition(e, me.chart);
  3598. var elementsArray = [];
  3599. var found = function() {
  3600. if (me.data.datasets) {
  3601. for (var i = 0; i < me.data.datasets.length; i++) {
  3602. var meta = me.getDatasetMeta(i);
  3603. if (me.isDatasetVisible(i)) {
  3604. for (var j = 0; j < meta.data.length; j++) {
  3605. if (meta.data[j].inLabelRange(eventPosition.x, eventPosition.y)) {
  3606. return meta.data[j];
  3607. }
  3608. }
  3609. }
  3610. }
  3611. }
  3612. }.call(me);
  3613. if (!found) {
  3614. return elementsArray;
  3615. }
  3616. helpers.each(me.data.datasets, function(dataset, datasetIndex) {
  3617. if (me.isDatasetVisible(datasetIndex)) {
  3618. var meta = me.getDatasetMeta(datasetIndex);
  3619. var index = helpers.findIndex(meta.data, function(it) {
  3620. return found._model.x === it._model.x;
  3621. });
  3622. if (index !== -1 && !meta.data[index]._view.skip) {
  3623. elementsArray.push(meta.data[index]);
  3624. }
  3625. }
  3626. }, me);
  3627. return elementsArray;
  3628. },
  3629. getElementsAtEventForMode: function(e, mode) {
  3630. var me = this;
  3631. switch (mode) {
  3632. case 'single':
  3633. return me.getElementAtEvent(e);
  3634. case 'label':
  3635. return me.getElementsAtEvent(e);
  3636. case 'dataset':
  3637. return me.getDatasetAtEvent(e);
  3638. case 'x-axis':
  3639. return me.getElementsAtXAxis(e);
  3640. default:
  3641. return e;
  3642. }
  3643. },
  3644. getDatasetAtEvent: function(e) {
  3645. var elementsArray = this.getElementAtEvent(e);
  3646. if (elementsArray.length > 0) {
  3647. elementsArray = this.getDatasetMeta(elementsArray[0]._datasetIndex).data;
  3648. }
  3649. return elementsArray;
  3650. },
  3651. getDatasetMeta: function(datasetIndex) {
  3652. var me = this;
  3653. var dataset = me.data.datasets[datasetIndex];
  3654. if (!dataset._meta) {
  3655. dataset._meta = {};
  3656. }
  3657. var meta = dataset._meta[me.id];
  3658. if (!meta) {
  3659. meta = dataset._meta[me.id] = {
  3660. type: null,
  3661. data: [],
  3662. dataset: null,
  3663. controller: null,
  3664. hidden: null, // See isDatasetVisible() comment
  3665. xAxisID: null,
  3666. yAxisID: null
  3667. };
  3668. }
  3669. return meta;
  3670. },
  3671. getVisibleDatasetCount: function() {
  3672. var count = 0;
  3673. for (var i = 0, ilen = this.data.datasets.length; i<ilen; ++i) {
  3674. if (this.isDatasetVisible(i)) {
  3675. count++;
  3676. }
  3677. }
  3678. return count;
  3679. },
  3680. isDatasetVisible: function(datasetIndex) {
  3681. var meta = this.getDatasetMeta(datasetIndex);
  3682. // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
  3683. // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
  3684. return typeof meta.hidden === 'boolean'? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
  3685. },
  3686. generateLegend: function() {
  3687. return this.options.legendCallback(this);
  3688. },
  3689. destroy: function() {
  3690. var me = this;
  3691. me.stop();
  3692. me.clear();
  3693. helpers.unbindEvents(me, me.events);
  3694. helpers.removeResizeListener(me.chart.canvas.parentNode);
  3695. // Reset canvas height/width attributes
  3696. var canvas = me.chart.canvas;
  3697. canvas.width = me.chart.width;
  3698. canvas.height = me.chart.height;
  3699. // if we scaled the canvas in response to a devicePixelRatio !== 1, we need to undo that transform here
  3700. if (me.chart.originalDevicePixelRatio !== undefined) {
  3701. me.chart.ctx.scale(1 / me.chart.originalDevicePixelRatio, 1 / me.chart.originalDevicePixelRatio);
  3702. }
  3703. // Reset to the old style since it may have been changed by the device pixel ratio changes
  3704. canvas.style.width = me.chart.originalCanvasStyleWidth;
  3705. canvas.style.height = me.chart.originalCanvasStyleHeight;
  3706. Chart.plugins.notify('destroy', [me]);
  3707. delete Chart.instances[me.id];
  3708. },
  3709. toBase64Image: function() {
  3710. return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments);
  3711. },
  3712. initToolTip: function() {
  3713. var me = this;
  3714. me.tooltip = new Chart.Tooltip({
  3715. _chart: me.chart,
  3716. _chartInstance: me,
  3717. _data: me.data,
  3718. _options: me.options.tooltips
  3719. }, me);
  3720. },
  3721. bindEvents: function() {
  3722. var me = this;
  3723. helpers.bindEvents(me, me.options.events, function(evt) {
  3724. me.eventHandler(evt);
  3725. });
  3726. },
  3727. updateHoverStyle: function(elements, mode, enabled) {
  3728. var method = enabled? 'setHoverStyle' : 'removeHoverStyle';
  3729. var element, i, ilen;
  3730. switch (mode) {
  3731. case 'single':
  3732. elements = [elements[0]];
  3733. break;
  3734. case 'label':
  3735. case 'dataset':
  3736. case 'x-axis':
  3737. // elements = elements;
  3738. break;
  3739. default:
  3740. // unsupported mode
  3741. return;
  3742. }
  3743. for (i=0, ilen=elements.length; i<ilen; ++i) {
  3744. element = elements[i];
  3745. if (element) {
  3746. this.getDatasetMeta(element._datasetIndex).controller[method](element);
  3747. }
  3748. }
  3749. },
  3750. eventHandler: function(e) {
  3751. var me = this;
  3752. var tooltip = me.tooltip;
  3753. var options = me.options || {};
  3754. var hoverOptions = options.hover;
  3755. var tooltipsOptions = options.tooltips;
  3756. me.lastActive = me.lastActive || [];
  3757. me.lastTooltipActive = me.lastTooltipActive || [];
  3758. // Find Active Elements for hover and tooltips
  3759. if (e.type === 'mouseout') {
  3760. me.active = [];
  3761. me.tooltipActive = [];
  3762. } else {
  3763. me.active = me.getElementsAtEventForMode(e, hoverOptions.mode);
  3764. me.tooltipActive = me.getElementsAtEventForMode(e, tooltipsOptions.mode);
  3765. }
  3766. // On Hover hook
  3767. if (hoverOptions.onHover) {
  3768. hoverOptions.onHover.call(me, me.active);
  3769. }
  3770. if (me.legend && me.legend.handleEvent) {
  3771. me.legend.handleEvent(e);
  3772. }
  3773. if (e.type === 'mouseup' || e.type === 'click') {
  3774. if (options.onClick) {
  3775. options.onClick.call(me, e, me.active);
  3776. }
  3777. }
  3778. // Remove styling for last active (even if it may still be active)
  3779. if (me.lastActive.length) {
  3780. me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
  3781. }
  3782. // Built in hover styling
  3783. if (me.active.length && hoverOptions.mode) {
  3784. me.updateHoverStyle(me.active, hoverOptions.mode, true);
  3785. }
  3786. // Built in Tooltips
  3787. if (tooltipsOptions.enabled || tooltipsOptions.custom) {
  3788. tooltip.initialize();
  3789. tooltip._active = me.tooltipActive;
  3790. tooltip.update(true);
  3791. }
  3792. // Hover animations
  3793. tooltip.pivot();
  3794. if (!me.animating) {
  3795. // If entering, leaving, or changing elements, animate the change via pivot
  3796. if (!helpers.arrayEquals(me.active, me.lastActive) ||
  3797. !helpers.arrayEquals(me.tooltipActive, me.lastTooltipActive)) {
  3798. me.stop();
  3799. if (tooltipsOptions.enabled || tooltipsOptions.custom) {
  3800. tooltip.update(true);
  3801. }
  3802. // We only need to render at this point. Updating will cause scales to be
  3803. // recomputed generating flicker & using more memory than necessary.
  3804. me.render(hoverOptions.animationDuration, true);
  3805. }
  3806. }
  3807. // Remember Last Actives
  3808. me.lastActive = me.active;
  3809. me.lastTooltipActive = me.tooltipActive;
  3810. return me;
  3811. }
  3812. });
  3813. };
  3814. },{}],24:[function(require,module,exports){
  3815. 'use strict';
  3816. module.exports = function(Chart) {
  3817. var helpers = Chart.helpers;
  3818. var noop = helpers.noop;
  3819. // Base class for all dataset controllers (line, bar, etc)
  3820. Chart.DatasetController = function(chart, datasetIndex) {
  3821. this.initialize(chart, datasetIndex);
  3822. };
  3823. helpers.extend(Chart.DatasetController.prototype, {
  3824. /**
  3825. * Element type used to generate a meta dataset (e.g. Chart.element.Line).
  3826. * @type {Chart.core.element}
  3827. */
  3828. datasetElementType: null,
  3829. /**
  3830. * Element type used to generate a meta data (e.g. Chart.element.Point).
  3831. * @type {Chart.core.element}
  3832. */
  3833. dataElementType: null,
  3834. initialize: function(chart, datasetIndex) {
  3835. var me = this;
  3836. me.chart = chart;
  3837. me.index = datasetIndex;
  3838. me.linkScales();
  3839. me.addElements();
  3840. },
  3841. updateIndex: function(datasetIndex) {
  3842. this.index = datasetIndex;
  3843. },
  3844. linkScales: function() {
  3845. var me = this;
  3846. var meta = me.getMeta();
  3847. var dataset = me.getDataset();
  3848. if (meta.xAxisID === null) {
  3849. meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
  3850. }
  3851. if (meta.yAxisID === null) {
  3852. meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
  3853. }
  3854. },
  3855. getDataset: function() {
  3856. return this.chart.data.datasets[this.index];
  3857. },
  3858. getMeta: function() {
  3859. return this.chart.getDatasetMeta(this.index);
  3860. },
  3861. getScaleForId: function(scaleID) {
  3862. return this.chart.scales[scaleID];
  3863. },
  3864. reset: function() {
  3865. this.update(true);
  3866. },
  3867. createMetaDataset: function() {
  3868. var me = this;
  3869. var type = me.datasetElementType;
  3870. return type && new type({
  3871. _chart: me.chart.chart,
  3872. _datasetIndex: me.index
  3873. });
  3874. },
  3875. createMetaData: function(index) {
  3876. var me = this;
  3877. var type = me.dataElementType;
  3878. return type && new type({
  3879. _chart: me.chart.chart,
  3880. _datasetIndex: me.index,
  3881. _index: index
  3882. });
  3883. },
  3884. addElements: function() {
  3885. var me = this;
  3886. var meta = me.getMeta();
  3887. var data = me.getDataset().data || [];
  3888. var metaData = meta.data;
  3889. var i, ilen;
  3890. for (i=0, ilen=data.length; i<ilen; ++i) {
  3891. metaData[i] = metaData[i] || me.createMetaData(meta, i);
  3892. }
  3893. meta.dataset = meta.dataset || me.createMetaDataset();
  3894. },
  3895. addElementAndReset: function(index) {
  3896. var me = this;
  3897. var element = me.createMetaData(index);
  3898. me.getMeta().data.splice(index, 0, element);
  3899. me.updateElement(element, index, true);
  3900. },
  3901. buildOrUpdateElements: function() {
  3902. // Handle the number of data points changing
  3903. var meta = this.getMeta(),
  3904. md = meta.data,
  3905. numData = this.getDataset().data.length,
  3906. numMetaData = md.length;
  3907. // Make sure that we handle number of datapoints changing
  3908. if (numData < numMetaData) {
  3909. // Remove excess bars for data points that have been removed
  3910. md.splice(numData, numMetaData - numData);
  3911. } else if (numData > numMetaData) {
  3912. // Add new elements
  3913. for (var index = numMetaData; index < numData; ++index) {
  3914. this.addElementAndReset(index);
  3915. }
  3916. }
  3917. },
  3918. update: noop,
  3919. draw: function(ease) {
  3920. var easingDecimal = ease || 1;
  3921. helpers.each(this.getMeta().data, function(element) {
  3922. element.transition(easingDecimal).draw();
  3923. });
  3924. },
  3925. removeHoverStyle: function(element, elementOpts) {
  3926. var dataset = this.chart.data.datasets[element._datasetIndex],
  3927. index = element._index,
  3928. custom = element.custom || {},
  3929. valueOrDefault = helpers.getValueAtIndexOrDefault,
  3930. model = element._model;
  3931. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  3932. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  3933. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  3934. },
  3935. setHoverStyle: function(element) {
  3936. var dataset = this.chart.data.datasets[element._datasetIndex],
  3937. index = element._index,
  3938. custom = element.custom || {},
  3939. valueOrDefault = helpers.getValueAtIndexOrDefault,
  3940. getHoverColor = helpers.getHoverColor,
  3941. model = element._model;
  3942. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
  3943. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
  3944. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  3945. }
  3946. });
  3947. Chart.DatasetController.extend = helpers.inherits;
  3948. };
  3949. },{}],25:[function(require,module,exports){
  3950. 'use strict';
  3951. module.exports = function(Chart) {
  3952. var helpers = Chart.helpers;
  3953. Chart.elements = {};
  3954. Chart.Element = function(configuration) {
  3955. helpers.extend(this, configuration);
  3956. this.initialize.apply(this, arguments);
  3957. };
  3958. helpers.extend(Chart.Element.prototype, {
  3959. initialize: function() {
  3960. this.hidden = false;
  3961. },
  3962. pivot: function() {
  3963. var me = this;
  3964. if (!me._view) {
  3965. me._view = helpers.clone(me._model);
  3966. }
  3967. me._start = helpers.clone(me._view);
  3968. return me;
  3969. },
  3970. transition: function(ease) {
  3971. var me = this;
  3972. if (!me._view) {
  3973. me._view = helpers.clone(me._model);
  3974. }
  3975. // No animation -> No Transition
  3976. if (ease === 1) {
  3977. me._view = me._model;
  3978. me._start = null;
  3979. return me;
  3980. }
  3981. if (!me._start) {
  3982. me.pivot();
  3983. }
  3984. helpers.each(me._model, function(value, key) {
  3985. if (key[0] === '_') {
  3986. // Only non-underscored properties
  3987. // Init if doesn't exist
  3988. } else if (!me._view.hasOwnProperty(key)) {
  3989. if (typeof value === 'number' && !isNaN(me._view[key])) {
  3990. me._view[key] = value * ease;
  3991. } else {
  3992. me._view[key] = value;
  3993. }
  3994. // No unnecessary computations
  3995. } else if (value === me._view[key]) {
  3996. // It's the same! Woohoo!
  3997. // Color transitions if possible
  3998. } else if (typeof value === 'string') {
  3999. try {
  4000. var color = helpers.color(me._model[key]).mix(helpers.color(me._start[key]), ease);
  4001. me._view[key] = color.rgbString();
  4002. } catch (err) {
  4003. me._view[key] = value;
  4004. }
  4005. // Number transitions
  4006. } else if (typeof value === 'number') {
  4007. var startVal = me._start[key] !== undefined && isNaN(me._start[key]) === false ? me._start[key] : 0;
  4008. me._view[key] = ((me._model[key] - startVal) * ease) + startVal;
  4009. // Everything else
  4010. } else {
  4011. me._view[key] = value;
  4012. }
  4013. }, me);
  4014. return me;
  4015. },
  4016. tooltipPosition: function() {
  4017. return {
  4018. x: this._model.x,
  4019. y: this._model.y
  4020. };
  4021. },
  4022. hasValue: function() {
  4023. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  4024. }
  4025. });
  4026. Chart.Element.extend = helpers.inherits;
  4027. };
  4028. },{}],26:[function(require,module,exports){
  4029. /* global window: false */
  4030. /* global document: false */
  4031. 'use strict';
  4032. var color = require(3);
  4033. module.exports = function(Chart) {
  4034. // Global Chart helpers object for utility methods and classes
  4035. var helpers = Chart.helpers = {};
  4036. // -- Basic js utility methods
  4037. helpers.each = function(loopable, callback, self, reverse) {
  4038. // Check to see if null or undefined firstly.
  4039. var i, len;
  4040. if (helpers.isArray(loopable)) {
  4041. len = loopable.length;
  4042. if (reverse) {
  4043. for (i = len - 1; i >= 0; i--) {
  4044. callback.call(self, loopable[i], i);
  4045. }
  4046. } else {
  4047. for (i = 0; i < len; i++) {
  4048. callback.call(self, loopable[i], i);
  4049. }
  4050. }
  4051. } else if (typeof loopable === 'object') {
  4052. var keys = Object.keys(loopable);
  4053. len = keys.length;
  4054. for (i = 0; i < len; i++) {
  4055. callback.call(self, loopable[keys[i]], keys[i]);
  4056. }
  4057. }
  4058. };
  4059. helpers.clone = function(obj) {
  4060. var objClone = {};
  4061. helpers.each(obj, function(value, key) {
  4062. if (helpers.isArray(value)) {
  4063. objClone[key] = value.slice(0);
  4064. } else if (typeof value === 'object' && value !== null) {
  4065. objClone[key] = helpers.clone(value);
  4066. } else {
  4067. objClone[key] = value;
  4068. }
  4069. });
  4070. return objClone;
  4071. };
  4072. helpers.extend = function(base) {
  4073. var setFn = function(value, key) {
  4074. base[key] = value;
  4075. };
  4076. for (var i = 1, ilen = arguments.length; i < ilen; i++) {
  4077. helpers.each(arguments[i], setFn);
  4078. }
  4079. return base;
  4080. };
  4081. // Need a special merge function to chart configs since they are now grouped
  4082. helpers.configMerge = function(_base) {
  4083. var base = helpers.clone(_base);
  4084. helpers.each(Array.prototype.slice.call(arguments, 1), function(extension) {
  4085. helpers.each(extension, function(value, key) {
  4086. if (key === 'scales') {
  4087. // Scale config merging is complex. Add out own function here for that
  4088. base[key] = helpers.scaleMerge(base.hasOwnProperty(key) ? base[key] : {}, value);
  4089. } else if (key === 'scale') {
  4090. // Used in polar area & radar charts since there is only one scale
  4091. base[key] = helpers.configMerge(base.hasOwnProperty(key) ? base[key] : {}, Chart.scaleService.getScaleDefaults(value.type), value);
  4092. } else if (base.hasOwnProperty(key) && helpers.isArray(base[key]) && helpers.isArray(value)) {
  4093. // In this case we have an array of objects replacing another array. Rather than doing a strict replace,
  4094. // merge. This allows easy scale option merging
  4095. var baseArray = base[key];
  4096. helpers.each(value, function(valueObj, index) {
  4097. if (index < baseArray.length) {
  4098. if (typeof baseArray[index] === 'object' && baseArray[index] !== null && typeof valueObj === 'object' && valueObj !== null) {
  4099. // Two objects are coming together. Do a merge of them.
  4100. baseArray[index] = helpers.configMerge(baseArray[index], valueObj);
  4101. } else {
  4102. // Just overwrite in this case since there is nothing to merge
  4103. baseArray[index] = valueObj;
  4104. }
  4105. } else {
  4106. baseArray.push(valueObj); // nothing to merge
  4107. }
  4108. });
  4109. } else if (base.hasOwnProperty(key) && typeof base[key] === 'object' && base[key] !== null && typeof value === 'object') {
  4110. // If we are overwriting an object with an object, do a merge of the properties.
  4111. base[key] = helpers.configMerge(base[key], value);
  4112. } else {
  4113. // can just overwrite the value in this case
  4114. base[key] = value;
  4115. }
  4116. });
  4117. });
  4118. return base;
  4119. };
  4120. helpers.scaleMerge = function(_base, extension) {
  4121. var base = helpers.clone(_base);
  4122. helpers.each(extension, function(value, key) {
  4123. if (key === 'xAxes' || key === 'yAxes') {
  4124. // These properties are arrays of items
  4125. if (base.hasOwnProperty(key)) {
  4126. helpers.each(value, function(valueObj, index) {
  4127. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  4128. var axisDefaults = Chart.scaleService.getScaleDefaults(axisType);
  4129. if (index >= base[key].length || !base[key][index].type) {
  4130. base[key].push(helpers.configMerge(axisDefaults, valueObj));
  4131. } else if (valueObj.type && valueObj.type !== base[key][index].type) {
  4132. // Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults
  4133. base[key][index] = helpers.configMerge(base[key][index], axisDefaults, valueObj);
  4134. } else {
  4135. // Type is the same
  4136. base[key][index] = helpers.configMerge(base[key][index], valueObj);
  4137. }
  4138. });
  4139. } else {
  4140. base[key] = [];
  4141. helpers.each(value, function(valueObj) {
  4142. var axisType = helpers.getValueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
  4143. base[key].push(helpers.configMerge(Chart.scaleService.getScaleDefaults(axisType), valueObj));
  4144. });
  4145. }
  4146. } else if (base.hasOwnProperty(key) && typeof base[key] === 'object' && base[key] !== null && typeof value === 'object') {
  4147. // If we are overwriting an object with an object, do a merge of the properties.
  4148. base[key] = helpers.configMerge(base[key], value);
  4149. } else {
  4150. // can just overwrite the value in this case
  4151. base[key] = value;
  4152. }
  4153. });
  4154. return base;
  4155. };
  4156. helpers.getValueAtIndexOrDefault = function(value, index, defaultValue) {
  4157. if (value === undefined || value === null) {
  4158. return defaultValue;
  4159. }
  4160. if (helpers.isArray(value)) {
  4161. return index < value.length ? value[index] : defaultValue;
  4162. }
  4163. return value;
  4164. };
  4165. helpers.getValueOrDefault = function(value, defaultValue) {
  4166. return value === undefined ? defaultValue : value;
  4167. };
  4168. helpers.indexOf = Array.prototype.indexOf?
  4169. function(array, item) {
  4170. return array.indexOf(item);
  4171. }:
  4172. function(array, item) {
  4173. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4174. if (array[i] === item) {
  4175. return i;
  4176. }
  4177. }
  4178. return -1;
  4179. };
  4180. helpers.where = function(collection, filterCallback) {
  4181. if (helpers.isArray(collection) && Array.prototype.filter) {
  4182. return collection.filter(filterCallback);
  4183. }
  4184. var filtered = [];
  4185. helpers.each(collection, function(item) {
  4186. if (filterCallback(item)) {
  4187. filtered.push(item);
  4188. }
  4189. });
  4190. return filtered;
  4191. };
  4192. helpers.findIndex = Array.prototype.findIndex?
  4193. function(array, callback, scope) {
  4194. return array.findIndex(callback, scope);
  4195. } :
  4196. function(array, callback, scope) {
  4197. scope = scope === undefined? array : scope;
  4198. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4199. if (callback.call(scope, array[i], i, array)) {
  4200. return i;
  4201. }
  4202. }
  4203. return -1;
  4204. };
  4205. helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
  4206. // Default to start of the array
  4207. if (startIndex === undefined || startIndex === null) {
  4208. startIndex = -1;
  4209. }
  4210. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  4211. var currentItem = arrayToSearch[i];
  4212. if (filterCallback(currentItem)) {
  4213. return currentItem;
  4214. }
  4215. }
  4216. };
  4217. helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
  4218. // Default to end of the array
  4219. if (startIndex === undefined || startIndex === null) {
  4220. startIndex = arrayToSearch.length;
  4221. }
  4222. for (var i = startIndex - 1; i >= 0; i--) {
  4223. var currentItem = arrayToSearch[i];
  4224. if (filterCallback(currentItem)) {
  4225. return currentItem;
  4226. }
  4227. }
  4228. };
  4229. helpers.inherits = function(extensions) {
  4230. // Basic javascript inheritance based on the model created in Backbone.js
  4231. var me = this;
  4232. var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
  4233. return me.apply(this, arguments);
  4234. };
  4235. var Surrogate = function() {
  4236. this.constructor = ChartElement;
  4237. };
  4238. Surrogate.prototype = me.prototype;
  4239. ChartElement.prototype = new Surrogate();
  4240. ChartElement.extend = helpers.inherits;
  4241. if (extensions) {
  4242. helpers.extend(ChartElement.prototype, extensions);
  4243. }
  4244. ChartElement.__super__ = me.prototype;
  4245. return ChartElement;
  4246. };
  4247. helpers.noop = function() {};
  4248. helpers.uid = (function() {
  4249. var id = 0;
  4250. return function() {
  4251. return id++;
  4252. };
  4253. }());
  4254. // -- Math methods
  4255. helpers.isNumber = function(n) {
  4256. return !isNaN(parseFloat(n)) && isFinite(n);
  4257. };
  4258. helpers.almostEquals = function(x, y, epsilon) {
  4259. return Math.abs(x - y) < epsilon;
  4260. };
  4261. helpers.max = function(array) {
  4262. return array.reduce(function(max, value) {
  4263. if (!isNaN(value)) {
  4264. return Math.max(max, value);
  4265. }
  4266. return max;
  4267. }, Number.NEGATIVE_INFINITY);
  4268. };
  4269. helpers.min = function(array) {
  4270. return array.reduce(function(min, value) {
  4271. if (!isNaN(value)) {
  4272. return Math.min(min, value);
  4273. }
  4274. return min;
  4275. }, Number.POSITIVE_INFINITY);
  4276. };
  4277. helpers.sign = Math.sign?
  4278. function(x) {
  4279. return Math.sign(x);
  4280. } :
  4281. function(x) {
  4282. x = +x; // convert to a number
  4283. if (x === 0 || isNaN(x)) {
  4284. return x;
  4285. }
  4286. return x > 0 ? 1 : -1;
  4287. };
  4288. helpers.log10 = Math.log10?
  4289. function(x) {
  4290. return Math.log10(x);
  4291. } :
  4292. function(x) {
  4293. return Math.log(x) / Math.LN10;
  4294. };
  4295. helpers.toRadians = function(degrees) {
  4296. return degrees * (Math.PI / 180);
  4297. };
  4298. helpers.toDegrees = function(radians) {
  4299. return radians * (180 / Math.PI);
  4300. };
  4301. // Gets the angle from vertical upright to the point about a centre.
  4302. helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
  4303. var distanceFromXCenter = anglePoint.x - centrePoint.x,
  4304. distanceFromYCenter = anglePoint.y - centrePoint.y,
  4305. radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  4306. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  4307. if (angle < (-0.5 * Math.PI)) {
  4308. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  4309. }
  4310. return {
  4311. angle: angle,
  4312. distance: radialDistanceFromCenter
  4313. };
  4314. };
  4315. helpers.aliasPixel = function(pixelWidth) {
  4316. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  4317. };
  4318. helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
  4319. // Props to Rob Spencer at scaled innovation for his post on splining between points
  4320. // http://scaledinnovation.com/analytics/splines/aboutSplines.html
  4321. // This function must also respect "skipped" points
  4322. var previous = firstPoint.skip ? middlePoint : firstPoint,
  4323. current = middlePoint,
  4324. next = afterPoint.skip ? middlePoint : afterPoint;
  4325. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  4326. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  4327. var s01 = d01 / (d01 + d12);
  4328. var s12 = d12 / (d01 + d12);
  4329. // If all points are the same, s01 & s02 will be inf
  4330. s01 = isNaN(s01) ? 0 : s01;
  4331. s12 = isNaN(s12) ? 0 : s12;
  4332. var fa = t * s01; // scaling factor for triangle Ta
  4333. var fb = t * s12;
  4334. return {
  4335. previous: {
  4336. x: current.x - fa * (next.x - previous.x),
  4337. y: current.y - fa * (next.y - previous.y)
  4338. },
  4339. next: {
  4340. x: current.x + fb * (next.x - previous.x),
  4341. y: current.y + fb * (next.y - previous.y)
  4342. }
  4343. };
  4344. };
  4345. helpers.EPSILON = Number.EPSILON || 1e-14;
  4346. helpers.splineCurveMonotone = function(points) {
  4347. // This function calculates Bézier control points in a similar way than |splineCurve|,
  4348. // but preserves monotonicity of the provided data and ensures no local extremums are added
  4349. // between the dataset discrete points due to the interpolation.
  4350. // See : https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
  4351. var pointsWithTangents = (points || []).map(function(point) {
  4352. return {
  4353. model: point._model,
  4354. deltaK: 0,
  4355. mK: 0
  4356. };
  4357. });
  4358. // Calculate slopes (deltaK) and initialize tangents (mK)
  4359. var pointsLen = pointsWithTangents.length;
  4360. var i, pointBefore, pointCurrent, pointAfter;
  4361. for (i = 0; i < pointsLen; ++i) {
  4362. pointCurrent = pointsWithTangents[i];
  4363. if (pointCurrent.model.skip) {
  4364. continue;
  4365. }
  4366. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4367. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4368. if (pointAfter && !pointAfter.model.skip) {
  4369. pointCurrent.deltaK = (pointAfter.model.y - pointCurrent.model.y) / (pointAfter.model.x - pointCurrent.model.x);
  4370. }
  4371. if (!pointBefore || pointBefore.model.skip) {
  4372. pointCurrent.mK = pointCurrent.deltaK;
  4373. } else if (!pointAfter || pointAfter.model.skip) {
  4374. pointCurrent.mK = pointBefore.deltaK;
  4375. } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
  4376. pointCurrent.mK = 0;
  4377. } else {
  4378. pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
  4379. }
  4380. }
  4381. // Adjust tangents to ensure monotonic properties
  4382. var alphaK, betaK, tauK, squaredMagnitude;
  4383. for (i = 0; i < pointsLen - 1; ++i) {
  4384. pointCurrent = pointsWithTangents[i];
  4385. pointAfter = pointsWithTangents[i + 1];
  4386. if (pointCurrent.model.skip || pointAfter.model.skip) {
  4387. continue;
  4388. }
  4389. if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
  4390. pointCurrent.mK = pointAfter.mK = 0;
  4391. continue;
  4392. }
  4393. alphaK = pointCurrent.mK / pointCurrent.deltaK;
  4394. betaK = pointAfter.mK / pointCurrent.deltaK;
  4395. squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
  4396. if (squaredMagnitude <= 9) {
  4397. continue;
  4398. }
  4399. tauK = 3 / Math.sqrt(squaredMagnitude);
  4400. pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
  4401. pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
  4402. }
  4403. // Compute control points
  4404. var deltaX;
  4405. for (i = 0; i < pointsLen; ++i) {
  4406. pointCurrent = pointsWithTangents[i];
  4407. if (pointCurrent.model.skip) {
  4408. continue;
  4409. }
  4410. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4411. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4412. if (pointBefore && !pointBefore.model.skip) {
  4413. deltaX = (pointCurrent.model.x - pointBefore.model.x) / 3;
  4414. pointCurrent.model.controlPointPreviousX = pointCurrent.model.x - deltaX;
  4415. pointCurrent.model.controlPointPreviousY = pointCurrent.model.y - deltaX * pointCurrent.mK;
  4416. }
  4417. if (pointAfter && !pointAfter.model.skip) {
  4418. deltaX = (pointAfter.model.x - pointCurrent.model.x) / 3;
  4419. pointCurrent.model.controlPointNextX = pointCurrent.model.x + deltaX;
  4420. pointCurrent.model.controlPointNextY = pointCurrent.model.y + deltaX * pointCurrent.mK;
  4421. }
  4422. }
  4423. };
  4424. helpers.nextItem = function(collection, index, loop) {
  4425. if (loop) {
  4426. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  4427. }
  4428. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  4429. };
  4430. helpers.previousItem = function(collection, index, loop) {
  4431. if (loop) {
  4432. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  4433. }
  4434. return index <= 0 ? collection[0] : collection[index - 1];
  4435. };
  4436. // Implementation of the nice number algorithm used in determining where axis labels will go
  4437. helpers.niceNum = function(range, round) {
  4438. var exponent = Math.floor(helpers.log10(range));
  4439. var fraction = range / Math.pow(10, exponent);
  4440. var niceFraction;
  4441. if (round) {
  4442. if (fraction < 1.5) {
  4443. niceFraction = 1;
  4444. } else if (fraction < 3) {
  4445. niceFraction = 2;
  4446. } else if (fraction < 7) {
  4447. niceFraction = 5;
  4448. } else {
  4449. niceFraction = 10;
  4450. }
  4451. } else 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. return niceFraction * Math.pow(10, exponent);
  4461. };
  4462. // Easing functions adapted from Robert Penner's easing equations
  4463. // http://www.robertpenner.com/easing/
  4464. var easingEffects = helpers.easingEffects = {
  4465. linear: function(t) {
  4466. return t;
  4467. },
  4468. easeInQuad: function(t) {
  4469. return t * t;
  4470. },
  4471. easeOutQuad: function(t) {
  4472. return -1 * t * (t - 2);
  4473. },
  4474. easeInOutQuad: function(t) {
  4475. if ((t /= 1 / 2) < 1) {
  4476. return 1 / 2 * t * t;
  4477. }
  4478. return -1 / 2 * ((--t) * (t - 2) - 1);
  4479. },
  4480. easeInCubic: function(t) {
  4481. return t * t * t;
  4482. },
  4483. easeOutCubic: function(t) {
  4484. return 1 * ((t = t / 1 - 1) * t * t + 1);
  4485. },
  4486. easeInOutCubic: function(t) {
  4487. if ((t /= 1 / 2) < 1) {
  4488. return 1 / 2 * t * t * t;
  4489. }
  4490. return 1 / 2 * ((t -= 2) * t * t + 2);
  4491. },
  4492. easeInQuart: function(t) {
  4493. return t * t * t * t;
  4494. },
  4495. easeOutQuart: function(t) {
  4496. return -1 * ((t = t / 1 - 1) * t * t * t - 1);
  4497. },
  4498. easeInOutQuart: function(t) {
  4499. if ((t /= 1 / 2) < 1) {
  4500. return 1 / 2 * t * t * t * t;
  4501. }
  4502. return -1 / 2 * ((t -= 2) * t * t * t - 2);
  4503. },
  4504. easeInQuint: function(t) {
  4505. return 1 * (t /= 1) * t * t * t * t;
  4506. },
  4507. easeOutQuint: function(t) {
  4508. return 1 * ((t = t / 1 - 1) * t * t * t * t + 1);
  4509. },
  4510. easeInOutQuint: function(t) {
  4511. if ((t /= 1 / 2) < 1) {
  4512. return 1 / 2 * t * t * t * t * t;
  4513. }
  4514. return 1 / 2 * ((t -= 2) * t * t * t * t + 2);
  4515. },
  4516. easeInSine: function(t) {
  4517. return -1 * Math.cos(t / 1 * (Math.PI / 2)) + 1;
  4518. },
  4519. easeOutSine: function(t) {
  4520. return 1 * Math.sin(t / 1 * (Math.PI / 2));
  4521. },
  4522. easeInOutSine: function(t) {
  4523. return -1 / 2 * (Math.cos(Math.PI * t / 1) - 1);
  4524. },
  4525. easeInExpo: function(t) {
  4526. return (t === 0) ? 1 : 1 * Math.pow(2, 10 * (t / 1 - 1));
  4527. },
  4528. easeOutExpo: function(t) {
  4529. return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1);
  4530. },
  4531. easeInOutExpo: function(t) {
  4532. if (t === 0) {
  4533. return 0;
  4534. }
  4535. if (t === 1) {
  4536. return 1;
  4537. }
  4538. if ((t /= 1 / 2) < 1) {
  4539. return 1 / 2 * Math.pow(2, 10 * (t - 1));
  4540. }
  4541. return 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
  4542. },
  4543. easeInCirc: function(t) {
  4544. if (t >= 1) {
  4545. return t;
  4546. }
  4547. return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1);
  4548. },
  4549. easeOutCirc: function(t) {
  4550. return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t);
  4551. },
  4552. easeInOutCirc: function(t) {
  4553. if ((t /= 1 / 2) < 1) {
  4554. return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
  4555. }
  4556. return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  4557. },
  4558. easeInElastic: function(t) {
  4559. var s = 1.70158;
  4560. var p = 0;
  4561. var a = 1;
  4562. if (t === 0) {
  4563. return 0;
  4564. }
  4565. if ((t /= 1) === 1) {
  4566. return 1;
  4567. }
  4568. if (!p) {
  4569. p = 1 * 0.3;
  4570. }
  4571. if (a < Math.abs(1)) {
  4572. a = 1;
  4573. s = p / 4;
  4574. } else {
  4575. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4576. }
  4577. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  4578. },
  4579. easeOutElastic: function(t) {
  4580. var s = 1.70158;
  4581. var p = 0;
  4582. var a = 1;
  4583. if (t === 0) {
  4584. return 0;
  4585. }
  4586. if ((t /= 1) === 1) {
  4587. return 1;
  4588. }
  4589. if (!p) {
  4590. p = 1 * 0.3;
  4591. }
  4592. if (a < Math.abs(1)) {
  4593. a = 1;
  4594. s = p / 4;
  4595. } else {
  4596. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4597. }
  4598. return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1;
  4599. },
  4600. easeInOutElastic: function(t) {
  4601. var s = 1.70158;
  4602. var p = 0;
  4603. var a = 1;
  4604. if (t === 0) {
  4605. return 0;
  4606. }
  4607. if ((t /= 1 / 2) === 2) {
  4608. return 1;
  4609. }
  4610. if (!p) {
  4611. p = 1 * (0.3 * 1.5);
  4612. }
  4613. if (a < Math.abs(1)) {
  4614. a = 1;
  4615. s = p / 4;
  4616. } else {
  4617. s = p / (2 * Math.PI) * Math.asin(1 / a);
  4618. }
  4619. if (t < 1) {
  4620. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
  4621. }
  4622. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1;
  4623. },
  4624. easeInBack: function(t) {
  4625. var s = 1.70158;
  4626. return 1 * (t /= 1) * t * ((s + 1) * t - s);
  4627. },
  4628. easeOutBack: function(t) {
  4629. var s = 1.70158;
  4630. return 1 * ((t = t / 1 - 1) * t * ((s + 1) * t + s) + 1);
  4631. },
  4632. easeInOutBack: function(t) {
  4633. var s = 1.70158;
  4634. if ((t /= 1 / 2) < 1) {
  4635. return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
  4636. }
  4637. return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  4638. },
  4639. easeInBounce: function(t) {
  4640. return 1 - easingEffects.easeOutBounce(1 - t);
  4641. },
  4642. easeOutBounce: function(t) {
  4643. if ((t /= 1) < (1 / 2.75)) {
  4644. return 1 * (7.5625 * t * t);
  4645. } else if (t < (2 / 2.75)) {
  4646. return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
  4647. } else if (t < (2.5 / 2.75)) {
  4648. return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
  4649. }
  4650. return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
  4651. },
  4652. easeInOutBounce: function(t) {
  4653. if (t < 1 / 2) {
  4654. return easingEffects.easeInBounce(t * 2) * 0.5;
  4655. }
  4656. return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
  4657. }
  4658. };
  4659. // Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  4660. helpers.requestAnimFrame = (function() {
  4661. return window.requestAnimationFrame ||
  4662. window.webkitRequestAnimationFrame ||
  4663. window.mozRequestAnimationFrame ||
  4664. window.oRequestAnimationFrame ||
  4665. window.msRequestAnimationFrame ||
  4666. function(callback) {
  4667. return window.setTimeout(callback, 1000 / 60);
  4668. };
  4669. }());
  4670. helpers.cancelAnimFrame = (function() {
  4671. return window.cancelAnimationFrame ||
  4672. window.webkitCancelAnimationFrame ||
  4673. window.mozCancelAnimationFrame ||
  4674. window.oCancelAnimationFrame ||
  4675. window.msCancelAnimationFrame ||
  4676. function(callback) {
  4677. return window.clearTimeout(callback, 1000 / 60);
  4678. };
  4679. }());
  4680. // -- DOM methods
  4681. helpers.getRelativePosition = function(evt, chart) {
  4682. var mouseX, mouseY;
  4683. var e = evt.originalEvent || evt,
  4684. canvas = evt.currentTarget || evt.srcElement,
  4685. boundingRect = canvas.getBoundingClientRect();
  4686. var touches = e.touches;
  4687. if (touches && touches.length > 0) {
  4688. mouseX = touches[0].clientX;
  4689. mouseY = touches[0].clientY;
  4690. } else {
  4691. mouseX = e.clientX;
  4692. mouseY = e.clientY;
  4693. }
  4694. // Scale mouse coordinates into canvas coordinates
  4695. // by following the pattern laid out by 'jerryj' in the comments of
  4696. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  4697. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  4698. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  4699. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  4700. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  4701. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  4702. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  4703. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  4704. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  4705. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  4706. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  4707. return {
  4708. x: mouseX,
  4709. y: mouseY
  4710. };
  4711. };
  4712. helpers.addEvent = function(node, eventType, method) {
  4713. if (node.addEventListener) {
  4714. node.addEventListener(eventType, method);
  4715. } else if (node.attachEvent) {
  4716. node.attachEvent('on' + eventType, method);
  4717. } else {
  4718. node['on' + eventType] = method;
  4719. }
  4720. };
  4721. helpers.removeEvent = function(node, eventType, handler) {
  4722. if (node.removeEventListener) {
  4723. node.removeEventListener(eventType, handler, false);
  4724. } else if (node.detachEvent) {
  4725. node.detachEvent('on' + eventType, handler);
  4726. } else {
  4727. node['on' + eventType] = helpers.noop;
  4728. }
  4729. };
  4730. helpers.bindEvents = function(chartInstance, arrayOfEvents, handler) {
  4731. // Create the events object if it's not already present
  4732. var events = chartInstance.events = chartInstance.events || {};
  4733. helpers.each(arrayOfEvents, function(eventName) {
  4734. events[eventName] = function() {
  4735. handler.apply(chartInstance, arguments);
  4736. };
  4737. helpers.addEvent(chartInstance.chart.canvas, eventName, events[eventName]);
  4738. });
  4739. };
  4740. helpers.unbindEvents = function(chartInstance, arrayOfEvents) {
  4741. var canvas = chartInstance.chart.canvas;
  4742. helpers.each(arrayOfEvents, function(handler, eventName) {
  4743. helpers.removeEvent(canvas, eventName, handler);
  4744. });
  4745. };
  4746. // Private helper function to convert max-width/max-height values that may be percentages into a number
  4747. function parseMaxStyle(styleValue, node, parentProperty) {
  4748. var valueInPixels;
  4749. if (typeof(styleValue) === 'string') {
  4750. valueInPixels = parseInt(styleValue, 10);
  4751. if (styleValue.indexOf('%') !== -1) {
  4752. // percentage * size in dimension
  4753. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  4754. }
  4755. } else {
  4756. valueInPixels = styleValue;
  4757. }
  4758. return valueInPixels;
  4759. }
  4760. /**
  4761. * Returns if the given value contains an effective constraint.
  4762. * @private
  4763. */
  4764. function isConstrainedValue(value) {
  4765. return value !== undefined && value !== null && value !== 'none';
  4766. }
  4767. // Private helper to get a constraint dimension
  4768. // @param domNode : the node to check the constraint on
  4769. // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
  4770. // @param percentageProperty : property of parent to use when calculating width as a percentage
  4771. // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
  4772. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  4773. var view = document.defaultView;
  4774. var parentNode = domNode.parentNode;
  4775. var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
  4776. var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
  4777. var hasCNode = isConstrainedValue(constrainedNode);
  4778. var hasCContainer = isConstrainedValue(constrainedContainer);
  4779. var infinity = Number.POSITIVE_INFINITY;
  4780. if (hasCNode || hasCContainer) {
  4781. return Math.min(
  4782. hasCNode? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
  4783. hasCContainer? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
  4784. }
  4785. return 'none';
  4786. }
  4787. // returns Number or undefined if no constraint
  4788. helpers.getConstraintWidth = function(domNode) {
  4789. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  4790. };
  4791. // returns Number or undefined if no constraint
  4792. helpers.getConstraintHeight = function(domNode) {
  4793. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  4794. };
  4795. helpers.getMaximumWidth = function(domNode) {
  4796. var container = domNode.parentNode;
  4797. var paddingLeft = parseInt(helpers.getStyle(container, 'padding-left'), 10);
  4798. var paddingRight = parseInt(helpers.getStyle(container, 'padding-right'), 10);
  4799. var w = container.clientWidth - paddingLeft - paddingRight;
  4800. var cw = helpers.getConstraintWidth(domNode);
  4801. return isNaN(cw)? w : Math.min(w, cw);
  4802. };
  4803. helpers.getMaximumHeight = function(domNode) {
  4804. var container = domNode.parentNode;
  4805. var paddingTop = parseInt(helpers.getStyle(container, 'padding-top'), 10);
  4806. var paddingBottom = parseInt(helpers.getStyle(container, 'padding-bottom'), 10);
  4807. var h = container.clientHeight - paddingTop - paddingBottom;
  4808. var ch = helpers.getConstraintHeight(domNode);
  4809. return isNaN(ch)? h : Math.min(h, ch);
  4810. };
  4811. helpers.getStyle = function(el, property) {
  4812. return el.currentStyle ?
  4813. el.currentStyle[property] :
  4814. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  4815. };
  4816. helpers.retinaScale = function(chart) {
  4817. var ctx = chart.ctx;
  4818. var canvas = chart.canvas;
  4819. var width = canvas.width;
  4820. var height = canvas.height;
  4821. var pixelRatio = chart.currentDevicePixelRatio = window.devicePixelRatio || 1;
  4822. if (pixelRatio !== 1) {
  4823. canvas.height = height * pixelRatio;
  4824. canvas.width = width * pixelRatio;
  4825. ctx.scale(pixelRatio, pixelRatio);
  4826. // Store the device pixel ratio so that we can go backwards in `destroy`.
  4827. // The devicePixelRatio changes with zoom, so there are no guarantees that it is the same
  4828. // when destroy is called
  4829. chart.originalDevicePixelRatio = chart.originalDevicePixelRatio || pixelRatio;
  4830. }
  4831. canvas.style.width = width + 'px';
  4832. canvas.style.height = height + 'px';
  4833. };
  4834. // -- Canvas methods
  4835. helpers.clear = function(chart) {
  4836. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  4837. };
  4838. helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
  4839. return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
  4840. };
  4841. helpers.longestText = function(ctx, font, arrayOfThings, cache) {
  4842. cache = cache || {};
  4843. var data = cache.data = cache.data || {};
  4844. var gc = cache.garbageCollect = cache.garbageCollect || [];
  4845. if (cache.font !== font) {
  4846. data = cache.data = {};
  4847. gc = cache.garbageCollect = [];
  4848. cache.font = font;
  4849. }
  4850. ctx.font = font;
  4851. var longest = 0;
  4852. helpers.each(arrayOfThings, function(thing) {
  4853. // Undefined strings and arrays should not be measured
  4854. if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
  4855. longest = helpers.measureText(ctx, data, gc, longest, thing);
  4856. } else if (helpers.isArray(thing)) {
  4857. // if it is an array lets measure each element
  4858. // to do maybe simplify this function a bit so we can do this more recursively?
  4859. helpers.each(thing, function(nestedThing) {
  4860. // Undefined strings and arrays should not be measured
  4861. if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
  4862. longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
  4863. }
  4864. });
  4865. }
  4866. });
  4867. var gcLen = gc.length / 2;
  4868. if (gcLen > arrayOfThings.length) {
  4869. for (var i = 0; i < gcLen; i++) {
  4870. delete data[gc[i]];
  4871. }
  4872. gc.splice(0, gcLen);
  4873. }
  4874. return longest;
  4875. };
  4876. helpers.measureText = function(ctx, data, gc, longest, string) {
  4877. var textWidth = data[string];
  4878. if (!textWidth) {
  4879. textWidth = data[string] = ctx.measureText(string).width;
  4880. gc.push(string);
  4881. }
  4882. if (textWidth > longest) {
  4883. longest = textWidth;
  4884. }
  4885. return longest;
  4886. };
  4887. helpers.numberOfLabelLines = function(arrayOfThings) {
  4888. var numberOfLines = 1;
  4889. helpers.each(arrayOfThings, function(thing) {
  4890. if (helpers.isArray(thing)) {
  4891. if (thing.length > numberOfLines) {
  4892. numberOfLines = thing.length;
  4893. }
  4894. }
  4895. });
  4896. return numberOfLines;
  4897. };
  4898. helpers.drawRoundedRectangle = function(ctx, x, y, width, height, radius) {
  4899. ctx.beginPath();
  4900. ctx.moveTo(x + radius, y);
  4901. ctx.lineTo(x + width - radius, y);
  4902. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  4903. ctx.lineTo(x + width, y + height - radius);
  4904. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  4905. ctx.lineTo(x + radius, y + height);
  4906. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  4907. ctx.lineTo(x, y + radius);
  4908. ctx.quadraticCurveTo(x, y, x + radius, y);
  4909. ctx.closePath();
  4910. };
  4911. helpers.color = function(c) {
  4912. if (!color) {
  4913. console.error('Color.js not found!');
  4914. return c;
  4915. }
  4916. /* global CanvasGradient */
  4917. if (c instanceof CanvasGradient) {
  4918. return color(Chart.defaults.global.defaultColor);
  4919. }
  4920. return color(c);
  4921. };
  4922. helpers.addResizeListener = function(node, callback) {
  4923. // Hide an iframe before the node
  4924. var hiddenIframe = document.createElement('iframe');
  4925. var hiddenIframeClass = 'chartjs-hidden-iframe';
  4926. if (hiddenIframe.classlist) {
  4927. // can use classlist
  4928. hiddenIframe.classlist.add(hiddenIframeClass);
  4929. } else {
  4930. hiddenIframe.setAttribute('class', hiddenIframeClass);
  4931. }
  4932. // Set the style
  4933. hiddenIframe.tabIndex = -1;
  4934. var style = hiddenIframe.style;
  4935. style.width = '100%';
  4936. style.display = 'block';
  4937. style.border = 0;
  4938. style.height = 0;
  4939. style.margin = 0;
  4940. style.position = 'absolute';
  4941. style.left = 0;
  4942. style.right = 0;
  4943. style.top = 0;
  4944. style.bottom = 0;
  4945. // Insert the iframe so that contentWindow is available
  4946. node.insertBefore(hiddenIframe, node.firstChild);
  4947. (hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
  4948. if (callback) {
  4949. return callback();
  4950. }
  4951. };
  4952. };
  4953. helpers.removeResizeListener = function(node) {
  4954. var hiddenIframe = node.querySelector('.chartjs-hidden-iframe');
  4955. // Remove the resize detect iframe
  4956. if (hiddenIframe) {
  4957. hiddenIframe.parentNode.removeChild(hiddenIframe);
  4958. }
  4959. };
  4960. helpers.isArray = Array.isArray?
  4961. function(obj) {
  4962. return Array.isArray(obj);
  4963. } :
  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(colorValue) {
  4993. /* global CanvasPattern */
  4994. return (colorValue instanceof CanvasPattern) ?
  4995. colorValue :
  4996. helpers.color(colorValue).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. function getMinimumBoxSize(box) {
  5191. var minSize;
  5192. var isHorizontal = box.isHorizontal();
  5193. if (isHorizontal) {
  5194. minSize = box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  5195. maxChartAreaHeight -= minSize.height;
  5196. } else {
  5197. minSize = box.update(verticalBoxWidth, chartAreaHeight);
  5198. maxChartAreaWidth -= minSize.width;
  5199. }
  5200. minBoxSizes.push({
  5201. horizontal: isHorizontal,
  5202. minSize: minSize,
  5203. box: box
  5204. });
  5205. }
  5206. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  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. // Function to fit a box
  5215. function fitBox(box) {
  5216. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) {
  5217. return minBox.box === box;
  5218. });
  5219. if (minBoxSize) {
  5220. if (box.isHorizontal()) {
  5221. var scaleMargin = {
  5222. left: totalLeftBoxesWidth,
  5223. right: totalRightBoxesWidth,
  5224. top: 0,
  5225. bottom: 0
  5226. };
  5227. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  5228. // on the margin. Sometimes they need to increase in size slightly
  5229. box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  5230. } else {
  5231. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  5232. }
  5233. }
  5234. }
  5235. // Update, and calculate the left and right margins for the horizontal boxes
  5236. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  5237. helpers.each(leftBoxes, function(box) {
  5238. totalLeftBoxesWidth += box.width;
  5239. });
  5240. helpers.each(rightBoxes, function(box) {
  5241. totalRightBoxesWidth += box.width;
  5242. });
  5243. // Set the Left and Right margins for the horizontal boxes
  5244. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  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. function finalFitVerticalBox(box) {
  5253. var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) {
  5254. return minSize.box === box;
  5255. });
  5256. var scaleMargin = {
  5257. left: 0,
  5258. right: 0,
  5259. top: totalTopBoxesHeight,
  5260. bottom: totalBottomBoxesHeight
  5261. };
  5262. if (minBoxSize) {
  5263. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  5264. }
  5265. }
  5266. // Let the left layout know the final margin
  5267. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  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. function placeBox(box) {
  5314. if (box.isHorizontal()) {
  5315. box.left = box.options.fullWidth ? xPadding : totalLeftBoxesWidth;
  5316. box.right = box.options.fullWidth ? width - xPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  5317. box.top = top;
  5318. box.bottom = top + box.height;
  5319. // Move to next point
  5320. top = box.bottom;
  5321. } else {
  5322. box.left = left;
  5323. box.right = left + box.width;
  5324. box.top = totalTopBoxesHeight;
  5325. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  5326. // Move to next point
  5327. left = box.right;
  5328. }
  5329. }
  5330. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  5331. // Account for chart width and height
  5332. left += maxChartAreaWidth;
  5333. top += maxChartAreaHeight;
  5334. helpers.each(rightBoxes, placeBox);
  5335. helpers.each(bottomBoxes, placeBox);
  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 if (y + itemHeight > me.bottom) {
  5686. x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
  5687. y = cursor.y = me.top;
  5688. cursor.line++;
  5689. }
  5690. drawLegendBox(x, y, legendItem);
  5691. hitboxes[i].left = x;
  5692. hitboxes[i].top = y;
  5693. // Fill the actual label
  5694. fillText(x, y, legendItem, textWidth);
  5695. if (isHorizontal) {
  5696. cursor.x += width + (labelOpts.padding);
  5697. } else {
  5698. cursor.y += itemHeight;
  5699. }
  5700. });
  5701. }
  5702. },
  5703. // Handle an event
  5704. handleEvent: function(e) {
  5705. var me = this;
  5706. var opts = me.options;
  5707. var type = e.type === 'mouseup' ? 'click' : e.type;
  5708. if (type === 'mousemove') {
  5709. if (!opts.onHover) {
  5710. return;
  5711. }
  5712. } else if (type === 'click') {
  5713. if (!opts.onClick) {
  5714. return;
  5715. }
  5716. } else {
  5717. return;
  5718. }
  5719. var position = helpers.getRelativePosition(e, me.chart.chart),
  5720. x = position.x,
  5721. y = position.y;
  5722. if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
  5723. // See if we are touching one of the dataset boxes
  5724. var lh = me.legendHitBoxes;
  5725. for (var i = 0; i < lh.length; ++i) {
  5726. var hitBox = lh[i];
  5727. if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
  5728. // Touching an element
  5729. if (type === 'click') {
  5730. opts.onClick.call(me, e, me.legendItems[i]);
  5731. break;
  5732. } else if (type === 'mousemove') {
  5733. opts.onHover.call(me, e, me.legendItems[i]);
  5734. break;
  5735. }
  5736. }
  5737. }
  5738. }
  5739. }
  5740. });
  5741. // Register the legend plugin
  5742. Chart.plugins.register({
  5743. beforeInit: function(chartInstance) {
  5744. var opts = chartInstance.options;
  5745. var legendOpts = opts.legend;
  5746. if (legendOpts) {
  5747. chartInstance.legend = new Chart.Legend({
  5748. ctx: chartInstance.chart.ctx,
  5749. options: legendOpts,
  5750. chart: chartInstance
  5751. });
  5752. Chart.layoutService.addBox(chartInstance, chartInstance.legend);
  5753. }
  5754. }
  5755. });
  5756. };
  5757. },{}],30:[function(require,module,exports){
  5758. 'use strict';
  5759. module.exports = function(Chart) {
  5760. var noop = Chart.helpers.noop;
  5761. /**
  5762. * The plugin service singleton
  5763. * @namespace Chart.plugins
  5764. * @since 2.1.0
  5765. */
  5766. Chart.plugins = {
  5767. _plugins: [],
  5768. /**
  5769. * Registers the given plugin(s) if not already registered.
  5770. * @param {Array|Object} plugins plugin instance(s).
  5771. */
  5772. register: function(plugins) {
  5773. var p = this._plugins;
  5774. ([]).concat(plugins).forEach(function(plugin) {
  5775. if (p.indexOf(plugin) === -1) {
  5776. p.push(plugin);
  5777. }
  5778. });
  5779. },
  5780. /**
  5781. * Unregisters the given plugin(s) only if registered.
  5782. * @param {Array|Object} plugins plugin instance(s).
  5783. */
  5784. unregister: function(plugins) {
  5785. var p = this._plugins;
  5786. ([]).concat(plugins).forEach(function(plugin) {
  5787. var idx = p.indexOf(plugin);
  5788. if (idx !== -1) {
  5789. p.splice(idx, 1);
  5790. }
  5791. });
  5792. },
  5793. /**
  5794. * Remove all registered p^lugins.
  5795. * @since 2.1.5
  5796. */
  5797. clear: function() {
  5798. this._plugins = [];
  5799. },
  5800. /**
  5801. * Returns the number of registered plugins?
  5802. * @returns {Number}
  5803. * @since 2.1.5
  5804. */
  5805. count: function() {
  5806. return this._plugins.length;
  5807. },
  5808. /**
  5809. * Returns all registered plugin intances.
  5810. * @returns {Array} array of plugin objects.
  5811. * @since 2.1.5
  5812. */
  5813. getAll: function() {
  5814. return this._plugins;
  5815. },
  5816. /**
  5817. * Calls registered plugins on the specified extension, with the given args. This
  5818. * method immediately returns as soon as a plugin explicitly returns false. The
  5819. * returned value can be used, for instance, to interrupt the current action.
  5820. * @param {String} extension the name of the plugin method to call (e.g. 'beforeUpdate').
  5821. * @param {Array} [args] extra arguments to apply to the extension call.
  5822. * @returns {Boolean} false if any of the plugins return false, else returns true.
  5823. */
  5824. notify: function(extension, args) {
  5825. var plugins = this._plugins;
  5826. var ilen = plugins.length;
  5827. var i, plugin;
  5828. for (i=0; i<ilen; ++i) {
  5829. plugin = plugins[i];
  5830. if (typeof plugin[extension] === 'function') {
  5831. if (plugin[extension].apply(plugin, args || []) === false) {
  5832. return false;
  5833. }
  5834. }
  5835. }
  5836. return true;
  5837. }
  5838. };
  5839. /**
  5840. * Plugin extension methods.
  5841. * @interface Chart.PluginBase
  5842. * @since 2.1.0
  5843. */
  5844. Chart.PluginBase = Chart.Element.extend({
  5845. // Called at start of chart init
  5846. beforeInit: noop,
  5847. // Called at end of chart init
  5848. afterInit: noop,
  5849. // Called at start of update
  5850. beforeUpdate: noop,
  5851. // Called at end of update
  5852. afterUpdate: noop,
  5853. // Called at start of draw
  5854. beforeDraw: noop,
  5855. // Called at end of draw
  5856. afterDraw: noop,
  5857. // Called during destroy
  5858. destroy: noop
  5859. });
  5860. /**
  5861. * Provided for backward compatibility, use Chart.plugins instead
  5862. * @namespace Chart.pluginService
  5863. * @deprecated since version 2.1.5
  5864. * @todo remove me at version 3
  5865. */
  5866. Chart.pluginService = Chart.plugins;
  5867. };
  5868. },{}],31:[function(require,module,exports){
  5869. 'use strict';
  5870. module.exports = function(Chart) {
  5871. var helpers = Chart.helpers;
  5872. Chart.defaults.scale = {
  5873. display: true,
  5874. position: 'left',
  5875. // grid line settings
  5876. gridLines: {
  5877. display: true,
  5878. color: 'rgba(0, 0, 0, 0.1)',
  5879. lineWidth: 1,
  5880. drawBorder: true,
  5881. drawOnChartArea: true,
  5882. drawTicks: true,
  5883. tickMarkLength: 10,
  5884. zeroLineWidth: 1,
  5885. zeroLineColor: 'rgba(0,0,0,0.25)',
  5886. offsetGridLines: false,
  5887. borderDash: [],
  5888. borderDashOffset: 0.0
  5889. },
  5890. // scale label
  5891. scaleLabel: {
  5892. // actual label
  5893. labelString: '',
  5894. // display property
  5895. display: false
  5896. },
  5897. // label settings
  5898. ticks: {
  5899. beginAtZero: false,
  5900. minRotation: 0,
  5901. maxRotation: 50,
  5902. mirror: false,
  5903. padding: 10,
  5904. reverse: false,
  5905. display: true,
  5906. autoSkip: true,
  5907. autoSkipPadding: 0,
  5908. labelOffset: 0,
  5909. // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
  5910. callback: function(value) {
  5911. return helpers.isArray(value) ? value : '' + value;
  5912. }
  5913. }
  5914. };
  5915. Chart.Scale = Chart.Element.extend({
  5916. // These methods are ordered by lifecyle. Utilities then follow.
  5917. // Any function defined here is inherited by all scale types.
  5918. // Any function can be extended by the scale type
  5919. beforeUpdate: function() {
  5920. helpers.callCallback(this.options.beforeUpdate, [this]);
  5921. },
  5922. update: function(maxWidth, maxHeight, margins) {
  5923. var me = this;
  5924. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  5925. me.beforeUpdate();
  5926. // Absorb the master measurements
  5927. me.maxWidth = maxWidth;
  5928. me.maxHeight = maxHeight;
  5929. me.margins = helpers.extend({
  5930. left: 0,
  5931. right: 0,
  5932. top: 0,
  5933. bottom: 0
  5934. }, margins);
  5935. // Dimensions
  5936. me.beforeSetDimensions();
  5937. me.setDimensions();
  5938. me.afterSetDimensions();
  5939. // Data min/max
  5940. me.beforeDataLimits();
  5941. me.determineDataLimits();
  5942. me.afterDataLimits();
  5943. // Ticks
  5944. me.beforeBuildTicks();
  5945. me.buildTicks();
  5946. me.afterBuildTicks();
  5947. me.beforeTickToLabelConversion();
  5948. me.convertTicksToLabels();
  5949. me.afterTickToLabelConversion();
  5950. // Tick Rotation
  5951. me.beforeCalculateTickRotation();
  5952. me.calculateTickRotation();
  5953. me.afterCalculateTickRotation();
  5954. // Fit
  5955. me.beforeFit();
  5956. me.fit();
  5957. me.afterFit();
  5958. //
  5959. me.afterUpdate();
  5960. return me.minSize;
  5961. },
  5962. afterUpdate: function() {
  5963. helpers.callCallback(this.options.afterUpdate, [this]);
  5964. },
  5965. //
  5966. beforeSetDimensions: function() {
  5967. helpers.callCallback(this.options.beforeSetDimensions, [this]);
  5968. },
  5969. setDimensions: function() {
  5970. var me = this;
  5971. // Set the unconstrained dimension before label rotation
  5972. if (me.isHorizontal()) {
  5973. // Reset position before calculating rotation
  5974. me.width = me.maxWidth;
  5975. me.left = 0;
  5976. me.right = me.width;
  5977. } else {
  5978. me.height = me.maxHeight;
  5979. // Reset position before calculating rotation
  5980. me.top = 0;
  5981. me.bottom = me.height;
  5982. }
  5983. // Reset padding
  5984. me.paddingLeft = 0;
  5985. me.paddingTop = 0;
  5986. me.paddingRight = 0;
  5987. me.paddingBottom = 0;
  5988. },
  5989. afterSetDimensions: function() {
  5990. helpers.callCallback(this.options.afterSetDimensions, [this]);
  5991. },
  5992. // Data limits
  5993. beforeDataLimits: function() {
  5994. helpers.callCallback(this.options.beforeDataLimits, [this]);
  5995. },
  5996. determineDataLimits: helpers.noop,
  5997. afterDataLimits: function() {
  5998. helpers.callCallback(this.options.afterDataLimits, [this]);
  5999. },
  6000. //
  6001. beforeBuildTicks: function() {
  6002. helpers.callCallback(this.options.beforeBuildTicks, [this]);
  6003. },
  6004. buildTicks: helpers.noop,
  6005. afterBuildTicks: function() {
  6006. helpers.callCallback(this.options.afterBuildTicks, [this]);
  6007. },
  6008. beforeTickToLabelConversion: function() {
  6009. helpers.callCallback(this.options.beforeTickToLabelConversion, [this]);
  6010. },
  6011. convertTicksToLabels: function() {
  6012. var me = this;
  6013. // Convert ticks to strings
  6014. me.ticks = me.ticks.map(function(numericalTick, index, ticks) {
  6015. if (me.options.ticks.userCallback) {
  6016. return me.options.ticks.userCallback(numericalTick, index, ticks);
  6017. }
  6018. return me.options.ticks.callback(numericalTick, index, ticks);
  6019. },
  6020. me);
  6021. },
  6022. afterTickToLabelConversion: function() {
  6023. helpers.callCallback(this.options.afterTickToLabelConversion, [this]);
  6024. },
  6025. //
  6026. beforeCalculateTickRotation: function() {
  6027. helpers.callCallback(this.options.beforeCalculateTickRotation, [this]);
  6028. },
  6029. calculateTickRotation: function() {
  6030. var me = this;
  6031. var context = me.ctx;
  6032. var globalDefaults = Chart.defaults.global;
  6033. var optionTicks = me.options.ticks;
  6034. // Get the width of each grid by calculating the difference
  6035. // between x offsets between 0 and 1.
  6036. var tickFontSize = helpers.getValueOrDefault(optionTicks.fontSize, globalDefaults.defaultFontSize);
  6037. var tickFontStyle = helpers.getValueOrDefault(optionTicks.fontStyle, globalDefaults.defaultFontStyle);
  6038. var tickFontFamily = helpers.getValueOrDefault(optionTicks.fontFamily, globalDefaults.defaultFontFamily);
  6039. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  6040. context.font = tickLabelFont;
  6041. var firstWidth = context.measureText(me.ticks[0]).width;
  6042. var lastWidth = context.measureText(me.ticks[me.ticks.length - 1]).width;
  6043. var firstRotated;
  6044. me.labelRotation = optionTicks.minRotation || 0;
  6045. me.paddingRight = 0;
  6046. me.paddingLeft = 0;
  6047. if (me.options.display) {
  6048. if (me.isHorizontal()) {
  6049. me.paddingRight = lastWidth / 2 + 3;
  6050. me.paddingLeft = firstWidth / 2 + 3;
  6051. if (!me.longestTextCache) {
  6052. me.longestTextCache = {};
  6053. }
  6054. var originalLabelWidth = helpers.longestText(context, tickLabelFont, me.ticks, me.longestTextCache);
  6055. var labelWidth = originalLabelWidth;
  6056. var cosRotation;
  6057. var sinRotation;
  6058. // Allow 3 pixels x2 padding either side for label readability
  6059. // only the index matters for a dataset scale, but we want a consistent interface between scales
  6060. var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
  6061. // Max label rotation can be set or default to 90 - also act as a loop counter
  6062. while (labelWidth > tickWidth && me.labelRotation < optionTicks.maxRotation) {
  6063. cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
  6064. sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
  6065. firstRotated = cosRotation * firstWidth;
  6066. // We're right aligning the text now.
  6067. if (firstRotated + tickFontSize / 2 > me.yLabelWidth) {
  6068. me.paddingLeft = firstRotated + tickFontSize / 2;
  6069. }
  6070. me.paddingRight = tickFontSize / 2;
  6071. if (sinRotation * originalLabelWidth > me.maxHeight) {
  6072. // go back one step
  6073. me.labelRotation--;
  6074. break;
  6075. }
  6076. me.labelRotation++;
  6077. labelWidth = cosRotation * originalLabelWidth;
  6078. }
  6079. }
  6080. }
  6081. if (me.margins) {
  6082. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  6083. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  6084. }
  6085. },
  6086. afterCalculateTickRotation: function() {
  6087. helpers.callCallback(this.options.afterCalculateTickRotation, [this]);
  6088. },
  6089. //
  6090. beforeFit: function() {
  6091. helpers.callCallback(this.options.beforeFit, [this]);
  6092. },
  6093. fit: function() {
  6094. var me = this;
  6095. // Reset
  6096. var minSize = me.minSize = {
  6097. width: 0,
  6098. height: 0
  6099. };
  6100. var opts = me.options;
  6101. var globalDefaults = Chart.defaults.global;
  6102. var tickOpts = opts.ticks;
  6103. var scaleLabelOpts = opts.scaleLabel;
  6104. var gridLineOpts = opts.gridLines;
  6105. var display = opts.display;
  6106. var isHorizontal = me.isHorizontal();
  6107. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  6108. var tickFontStyle = helpers.getValueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  6109. var tickFontFamily = helpers.getValueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  6110. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  6111. var scaleLabelFontSize = helpers.getValueOrDefault(scaleLabelOpts.fontSize, globalDefaults.defaultFontSize);
  6112. var tickMarkLength = opts.gridLines.tickMarkLength;
  6113. // Width
  6114. if (isHorizontal) {
  6115. // subtract the margins to line up with the chartArea if we are a full width scale
  6116. minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
  6117. } else {
  6118. minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6119. }
  6120. // height
  6121. if (isHorizontal) {
  6122. minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6123. } else {
  6124. minSize.height = me.maxHeight; // fill all the height
  6125. }
  6126. // Are we showing a title for the scale?
  6127. if (scaleLabelOpts.display && display) {
  6128. if (isHorizontal) {
  6129. minSize.height += (scaleLabelFontSize * 1.5);
  6130. } else {
  6131. minSize.width += (scaleLabelFontSize * 1.5);
  6132. }
  6133. }
  6134. if (tickOpts.display && display) {
  6135. // Don't bother fitting the ticks if we are not showing them
  6136. if (!me.longestTextCache) {
  6137. me.longestTextCache = {};
  6138. }
  6139. var largestTextWidth = helpers.longestText(me.ctx, tickLabelFont, me.ticks, me.longestTextCache);
  6140. var tallestLabelHeightInLines = helpers.numberOfLabelLines(me.ticks);
  6141. var lineSpace = tickFontSize * 0.5;
  6142. if (isHorizontal) {
  6143. // A horizontal axis is more constrained by the height.
  6144. me.longestLabelWidth = largestTextWidth;
  6145. // TODO - improve this calculation
  6146. var labelHeight = (Math.sin(helpers.toRadians(me.labelRotation)) * me.longestLabelWidth) + (tickFontSize * tallestLabelHeightInLines) + (lineSpace * tallestLabelHeightInLines);
  6147. minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight);
  6148. me.ctx.font = tickLabelFont;
  6149. var firstLabelWidth = me.ctx.measureText(me.ticks[0]).width;
  6150. var lastLabelWidth = me.ctx.measureText(me.ticks[me.ticks.length - 1]).width;
  6151. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
  6152. // by the font height
  6153. var cosRotation = Math.cos(helpers.toRadians(me.labelRotation));
  6154. var sinRotation = Math.sin(helpers.toRadians(me.labelRotation));
  6155. me.paddingLeft = me.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  6156. me.paddingRight = me.labelRotation !== 0 ? (sinRotation * (tickFontSize / 2)) + 3 : lastLabelWidth / 2 + 3; // when rotated
  6157. } else {
  6158. // A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first
  6159. var maxLabelWidth = me.maxWidth - minSize.width;
  6160. // Account for padding
  6161. var mirror = tickOpts.mirror;
  6162. if (!mirror) {
  6163. largestTextWidth += me.options.ticks.padding;
  6164. } else {
  6165. // If mirrored text is on the inside so don't expand
  6166. largestTextWidth = 0;
  6167. }
  6168. if (largestTextWidth < maxLabelWidth) {
  6169. // We don't need all the room
  6170. minSize.width += largestTextWidth;
  6171. } else {
  6172. // Expand to max size
  6173. minSize.width = me.maxWidth;
  6174. }
  6175. me.paddingTop = tickFontSize / 2;
  6176. me.paddingBottom = tickFontSize / 2;
  6177. }
  6178. }
  6179. if (me.margins) {
  6180. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  6181. me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
  6182. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  6183. me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
  6184. }
  6185. me.width = minSize.width;
  6186. me.height = minSize.height;
  6187. },
  6188. afterFit: function() {
  6189. helpers.callCallback(this.options.afterFit, [this]);
  6190. },
  6191. // Shared Methods
  6192. isHorizontal: function() {
  6193. return this.options.position === 'top' || this.options.position === 'bottom';
  6194. },
  6195. isFullWidth: function() {
  6196. return (this.options.fullWidth);
  6197. },
  6198. // 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
  6199. getRightValue: function(rawValue) {
  6200. // Null and undefined values first
  6201. if (rawValue === null || typeof(rawValue) === 'undefined') {
  6202. return NaN;
  6203. }
  6204. // isNaN(object) returns true, so make sure NaN is checking for a number
  6205. if (typeof(rawValue) === 'number' && isNaN(rawValue)) {
  6206. return NaN;
  6207. }
  6208. // If it is in fact an object, dive in one more level
  6209. if (typeof(rawValue) === 'object') {
  6210. if ((rawValue instanceof Date) || (rawValue.isValid)) {
  6211. return rawValue;
  6212. }
  6213. return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
  6214. }
  6215. // Value is good, return it
  6216. return rawValue;
  6217. },
  6218. // Used to get the value to display in the tooltip for the data at the given index
  6219. // function getLabelForIndex(index, datasetIndex)
  6220. getLabelForIndex: helpers.noop,
  6221. // Used to get data value locations. Value can either be an index or a numerical value
  6222. getPixelForValue: helpers.noop,
  6223. // Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  6224. getValueForPixel: helpers.noop,
  6225. // Used for tick location, should
  6226. getPixelForTick: function(index, includeOffset) {
  6227. var me = this;
  6228. if (me.isHorizontal()) {
  6229. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6230. var tickWidth = innerWidth / Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  6231. var pixel = (tickWidth * index) + me.paddingLeft;
  6232. if (includeOffset) {
  6233. pixel += tickWidth / 2;
  6234. }
  6235. var finalVal = me.left + Math.round(pixel);
  6236. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6237. return finalVal;
  6238. }
  6239. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  6240. return me.top + (index * (innerHeight / (me.ticks.length - 1)));
  6241. },
  6242. // Utility for getting the pixel location of a percentage of scale
  6243. getPixelForDecimal: function(decimal /* , includeOffset*/) {
  6244. var me = this;
  6245. if (me.isHorizontal()) {
  6246. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6247. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  6248. var finalVal = me.left + Math.round(valueOffset);
  6249. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6250. return finalVal;
  6251. }
  6252. return me.top + (decimal * me.height);
  6253. },
  6254. getBasePixel: function() {
  6255. var me = this;
  6256. var min = me.min;
  6257. var max = me.max;
  6258. return me.getPixelForValue(
  6259. me.beginAtZero? 0:
  6260. min < 0 && max < 0? max :
  6261. min > 0 && max > 0? min :
  6262. 0);
  6263. },
  6264. // Actualy draw the scale on the canvas
  6265. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  6266. draw: function(chartArea) {
  6267. var me = this;
  6268. var options = me.options;
  6269. if (!options.display) {
  6270. return;
  6271. }
  6272. var context = me.ctx;
  6273. var globalDefaults = Chart.defaults.global;
  6274. var optionTicks = options.ticks;
  6275. var gridLines = options.gridLines;
  6276. var scaleLabel = options.scaleLabel;
  6277. var isRotated = me.labelRotation !== 0;
  6278. var skipRatio;
  6279. var useAutoskipper = optionTicks.autoSkip;
  6280. var isHorizontal = me.isHorizontal();
  6281. // figure out the maximum number of gridlines to show
  6282. var maxTicks;
  6283. if (optionTicks.maxTicksLimit) {
  6284. maxTicks = optionTicks.maxTicksLimit;
  6285. }
  6286. var tickFontColor = helpers.getValueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
  6287. var tickFontSize = helpers.getValueOrDefault(optionTicks.fontSize, globalDefaults.defaultFontSize);
  6288. var tickFontStyle = helpers.getValueOrDefault(optionTicks.fontStyle, globalDefaults.defaultFontStyle);
  6289. var tickFontFamily = helpers.getValueOrDefault(optionTicks.fontFamily, globalDefaults.defaultFontFamily);
  6290. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  6291. var tl = gridLines.tickMarkLength;
  6292. var borderDash = helpers.getValueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
  6293. var borderDashOffset = helpers.getValueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
  6294. var scaleLabelFontColor = helpers.getValueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
  6295. var scaleLabelFontSize = helpers.getValueOrDefault(scaleLabel.fontSize, globalDefaults.defaultFontSize);
  6296. var scaleLabelFontStyle = helpers.getValueOrDefault(scaleLabel.fontStyle, globalDefaults.defaultFontStyle);
  6297. var scaleLabelFontFamily = helpers.getValueOrDefault(scaleLabel.fontFamily, globalDefaults.defaultFontFamily);
  6298. var scaleLabelFont = helpers.fontString(scaleLabelFontSize, scaleLabelFontStyle, scaleLabelFontFamily);
  6299. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6300. var cosRotation = Math.cos(labelRotationRadians);
  6301. var longestRotatedLabel = me.longestLabelWidth * cosRotation;
  6302. // Make sure we draw text in the correct color and font
  6303. context.fillStyle = tickFontColor;
  6304. var itemsToDraw = [];
  6305. if (isHorizontal) {
  6306. skipRatio = false;
  6307. // Only calculate the skip ratio with the half width of longestRotateLabel if we got an actual rotation
  6308. // See #2584
  6309. if (isRotated) {
  6310. longestRotatedLabel /= 2;
  6311. }
  6312. if ((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length > (me.width - (me.paddingLeft + me.paddingRight))) {
  6313. skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * me.ticks.length) / (me.width - (me.paddingLeft + me.paddingRight)));
  6314. }
  6315. // if they defined a max number of optionTicks,
  6316. // increase skipRatio until that number is met
  6317. if (maxTicks && me.ticks.length > maxTicks) {
  6318. while (!skipRatio || me.ticks.length / (skipRatio || 1) > maxTicks) {
  6319. if (!skipRatio) {
  6320. skipRatio = 1;
  6321. }
  6322. skipRatio += 1;
  6323. }
  6324. }
  6325. if (!useAutoskipper) {
  6326. skipRatio = false;
  6327. }
  6328. }
  6329. var xTickStart = options.position === 'right' ? me.left : me.right - tl;
  6330. var xTickEnd = options.position === 'right' ? me.left + tl : me.right;
  6331. var yTickStart = options.position === 'bottom' ? me.top : me.bottom - tl;
  6332. var yTickEnd = options.position === 'bottom' ? me.top + tl : me.bottom;
  6333. helpers.each(me.ticks, function(label, index) {
  6334. // If the callback returned a null or undefined value, do not draw this line
  6335. if (label === undefined || label === null) {
  6336. return;
  6337. }
  6338. var isLastTick = me.ticks.length === index + 1;
  6339. // Since we always show the last tick,we need may need to hide the last shown one before
  6340. var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio >= me.ticks.length);
  6341. if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
  6342. return;
  6343. }
  6344. var lineWidth, lineColor;
  6345. if (index === (typeof me.zeroLineIndex !== 'undefined' ? me.zeroLineIndex : 0)) {
  6346. // Draw the first index specially
  6347. lineWidth = gridLines.zeroLineWidth;
  6348. lineColor = gridLines.zeroLineColor;
  6349. } else {
  6350. lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index);
  6351. lineColor = helpers.getValueAtIndexOrDefault(gridLines.color, index);
  6352. }
  6353. // Common properties
  6354. var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
  6355. var textAlign = 'middle';
  6356. var textBaseline = 'middle';
  6357. if (isHorizontal) {
  6358. if (!isRotated) {
  6359. textBaseline = options.position === 'top' ? 'bottom' : 'top';
  6360. }
  6361. textAlign = isRotated ? 'right' : 'center';
  6362. var xLineValue = me.getPixelForTick(index) + helpers.aliasPixel(lineWidth); // xvalues for grid lines
  6363. labelX = me.getPixelForTick(index, gridLines.offsetGridLines) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
  6364. labelY = (isRotated) ? me.top + 12 : options.position === 'top' ? me.bottom - tl : me.top + tl;
  6365. tx1 = tx2 = x1 = x2 = xLineValue;
  6366. ty1 = yTickStart;
  6367. ty2 = yTickEnd;
  6368. y1 = chartArea.top;
  6369. y2 = chartArea.bottom;
  6370. } else {
  6371. if (options.position === 'left') {
  6372. if (optionTicks.mirror) {
  6373. labelX = me.right + optionTicks.padding;
  6374. textAlign = 'left';
  6375. } else {
  6376. labelX = me.right - optionTicks.padding;
  6377. textAlign = 'right';
  6378. }
  6379. // right side
  6380. } else if (optionTicks.mirror) {
  6381. labelX = me.left - optionTicks.padding;
  6382. textAlign = 'right';
  6383. } else {
  6384. labelX = me.left + optionTicks.padding;
  6385. textAlign = 'left';
  6386. }
  6387. var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
  6388. yLineValue += helpers.aliasPixel(lineWidth);
  6389. labelY = me.getPixelForTick(index, gridLines.offsetGridLines);
  6390. tx1 = xTickStart;
  6391. tx2 = xTickEnd;
  6392. x1 = chartArea.left;
  6393. x2 = chartArea.right;
  6394. ty1 = ty2 = y1 = y2 = yLineValue;
  6395. }
  6396. itemsToDraw.push({
  6397. tx1: tx1,
  6398. ty1: ty1,
  6399. tx2: tx2,
  6400. ty2: ty2,
  6401. x1: x1,
  6402. y1: y1,
  6403. x2: x2,
  6404. y2: y2,
  6405. labelX: labelX,
  6406. labelY: labelY,
  6407. glWidth: lineWidth,
  6408. glColor: lineColor,
  6409. glBorderDash: borderDash,
  6410. glBorderDashOffset: borderDashOffset,
  6411. rotation: -1 * labelRotationRadians,
  6412. label: label,
  6413. textBaseline: textBaseline,
  6414. textAlign: textAlign
  6415. });
  6416. });
  6417. // Draw all of the tick labels, tick marks, and grid lines at the correct places
  6418. helpers.each(itemsToDraw, function(itemToDraw) {
  6419. if (gridLines.display) {
  6420. context.save();
  6421. context.lineWidth = itemToDraw.glWidth;
  6422. context.strokeStyle = itemToDraw.glColor;
  6423. if (context.setLineDash) {
  6424. context.setLineDash(itemToDraw.glBorderDash);
  6425. context.lineDashOffset = itemToDraw.glBorderDashOffset;
  6426. }
  6427. context.beginPath();
  6428. if (gridLines.drawTicks) {
  6429. context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
  6430. context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
  6431. }
  6432. if (gridLines.drawOnChartArea) {
  6433. context.moveTo(itemToDraw.x1, itemToDraw.y1);
  6434. context.lineTo(itemToDraw.x2, itemToDraw.y2);
  6435. }
  6436. context.stroke();
  6437. context.restore();
  6438. }
  6439. if (optionTicks.display) {
  6440. context.save();
  6441. context.translate(itemToDraw.labelX, itemToDraw.labelY);
  6442. context.rotate(itemToDraw.rotation);
  6443. context.font = tickLabelFont;
  6444. context.textBaseline = itemToDraw.textBaseline;
  6445. context.textAlign = itemToDraw.textAlign;
  6446. var label = itemToDraw.label;
  6447. if (helpers.isArray(label)) {
  6448. for (var i = 0, y = -(label.length - 1)*tickFontSize*0.75; i < label.length; ++i) {
  6449. // We just make sure the multiline element is a string here..
  6450. context.fillText('' + label[i], 0, y);
  6451. // apply same lineSpacing as calculated @ L#320
  6452. y += (tickFontSize * 1.5);
  6453. }
  6454. } else {
  6455. context.fillText(label, 0, 0);
  6456. }
  6457. context.restore();
  6458. }
  6459. });
  6460. if (scaleLabel.display) {
  6461. // Draw the scale label
  6462. var scaleLabelX;
  6463. var scaleLabelY;
  6464. var rotation = 0;
  6465. if (isHorizontal) {
  6466. scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
  6467. scaleLabelY = options.position === 'bottom' ? me.bottom - (scaleLabelFontSize / 2) : me.top + (scaleLabelFontSize / 2);
  6468. } else {
  6469. var isLeft = options.position === 'left';
  6470. scaleLabelX = isLeft ? me.left + (scaleLabelFontSize / 2) : me.right - (scaleLabelFontSize / 2);
  6471. scaleLabelY = me.top + ((me.bottom - me.top) / 2);
  6472. rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
  6473. }
  6474. context.save();
  6475. context.translate(scaleLabelX, scaleLabelY);
  6476. context.rotate(rotation);
  6477. context.textAlign = 'center';
  6478. context.textBaseline = 'middle';
  6479. context.fillStyle = scaleLabelFontColor; // render in correct colour
  6480. context.font = scaleLabelFont;
  6481. context.fillText(scaleLabel.labelString, 0, 0);
  6482. context.restore();
  6483. }
  6484. if (gridLines.drawBorder) {
  6485. // Draw the line at the edge of the axis
  6486. context.lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, 0);
  6487. context.strokeStyle = helpers.getValueAtIndexOrDefault(gridLines.color, 0);
  6488. var x1 = me.left,
  6489. x2 = me.right,
  6490. y1 = me.top,
  6491. y2 = me.bottom;
  6492. var aliasPixel = helpers.aliasPixel(context.lineWidth);
  6493. if (isHorizontal) {
  6494. y1 = y2 = options.position === 'top' ? me.bottom : me.top;
  6495. y1 += aliasPixel;
  6496. y2 += aliasPixel;
  6497. } else {
  6498. x1 = x2 = options.position === 'left' ? me.right : me.left;
  6499. x1 += aliasPixel;
  6500. x2 += aliasPixel;
  6501. }
  6502. context.beginPath();
  6503. context.moveTo(x1, y1);
  6504. context.lineTo(x2, y2);
  6505. context.stroke();
  6506. }
  6507. }
  6508. });
  6509. };
  6510. },{}],32:[function(require,module,exports){
  6511. 'use strict';
  6512. module.exports = function(Chart) {
  6513. var helpers = Chart.helpers;
  6514. Chart.scaleService = {
  6515. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  6516. // use the new chart options to grab the correct scale
  6517. constructors: {},
  6518. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  6519. // old browsers
  6520. // Scale config defaults
  6521. defaults: {},
  6522. registerScaleType: function(type, scaleConstructor, defaults) {
  6523. this.constructors[type] = scaleConstructor;
  6524. this.defaults[type] = helpers.clone(defaults);
  6525. },
  6526. getScaleConstructor: function(type) {
  6527. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  6528. },
  6529. getScaleDefaults: function(type) {
  6530. // Return the scale defaults merged with the global settings so that we always use the latest ones
  6531. return this.defaults.hasOwnProperty(type) ? helpers.scaleMerge(Chart.defaults.scale, this.defaults[type]) : {};
  6532. },
  6533. updateScaleDefaults: function(type, additions) {
  6534. var defaults = this.defaults;
  6535. if (defaults.hasOwnProperty(type)) {
  6536. defaults[type] = helpers.extend(defaults[type], additions);
  6537. }
  6538. },
  6539. addScalesToLayout: function(chartInstance) {
  6540. // Adds each scale to the chart.boxes array to be sized accordingly
  6541. helpers.each(chartInstance.scales, function(scale) {
  6542. Chart.layoutService.addBox(chartInstance, scale);
  6543. });
  6544. }
  6545. };
  6546. };
  6547. },{}],33:[function(require,module,exports){
  6548. 'use strict';
  6549. module.exports = function(Chart) {
  6550. var helpers = Chart.helpers;
  6551. Chart.defaults.global.title = {
  6552. display: false,
  6553. position: 'top',
  6554. fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
  6555. fontStyle: 'bold',
  6556. padding: 10,
  6557. // actual title
  6558. text: ''
  6559. };
  6560. var noop = helpers.noop;
  6561. Chart.Title = Chart.Element.extend({
  6562. initialize: function(config) {
  6563. var me = this;
  6564. helpers.extend(me, config);
  6565. me.options = helpers.configMerge(Chart.defaults.global.title, config.options);
  6566. // Contains hit boxes for each dataset (in dataset order)
  6567. me.legendHitBoxes = [];
  6568. },
  6569. // These methods are ordered by lifecyle. Utilities then follow.
  6570. beforeUpdate: function() {
  6571. var chartOpts = this.chart.options;
  6572. if (chartOpts && chartOpts.title) {
  6573. this.options = helpers.configMerge(Chart.defaults.global.title, chartOpts.title);
  6574. }
  6575. },
  6576. update: function(maxWidth, maxHeight, margins) {
  6577. var me = this;
  6578. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  6579. me.beforeUpdate();
  6580. // Absorb the master measurements
  6581. me.maxWidth = maxWidth;
  6582. me.maxHeight = maxHeight;
  6583. me.margins = margins;
  6584. // Dimensions
  6585. me.beforeSetDimensions();
  6586. me.setDimensions();
  6587. me.afterSetDimensions();
  6588. // Labels
  6589. me.beforeBuildLabels();
  6590. me.buildLabels();
  6591. me.afterBuildLabels();
  6592. // Fit
  6593. me.beforeFit();
  6594. me.fit();
  6595. me.afterFit();
  6596. //
  6597. me.afterUpdate();
  6598. return me.minSize;
  6599. },
  6600. afterUpdate: noop,
  6601. //
  6602. beforeSetDimensions: noop,
  6603. setDimensions: function() {
  6604. var me = this;
  6605. // Set the unconstrained dimension before label rotation
  6606. if (me.isHorizontal()) {
  6607. // Reset position before calculating rotation
  6608. me.width = me.maxWidth;
  6609. me.left = 0;
  6610. me.right = me.width;
  6611. } else {
  6612. me.height = me.maxHeight;
  6613. // Reset position before calculating rotation
  6614. me.top = 0;
  6615. me.bottom = me.height;
  6616. }
  6617. // Reset padding
  6618. me.paddingLeft = 0;
  6619. me.paddingTop = 0;
  6620. me.paddingRight = 0;
  6621. me.paddingBottom = 0;
  6622. // Reset minSize
  6623. me.minSize = {
  6624. width: 0,
  6625. height: 0
  6626. };
  6627. },
  6628. afterSetDimensions: noop,
  6629. //
  6630. beforeBuildLabels: noop,
  6631. buildLabels: noop,
  6632. afterBuildLabels: noop,
  6633. //
  6634. beforeFit: noop,
  6635. fit: function() {
  6636. var me = this,
  6637. valueOrDefault = helpers.getValueOrDefault,
  6638. opts = me.options,
  6639. globalDefaults = Chart.defaults.global,
  6640. display = opts.display,
  6641. fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
  6642. minSize = me.minSize;
  6643. if (me.isHorizontal()) {
  6644. minSize.width = me.maxWidth; // fill all the width
  6645. minSize.height = display ? fontSize + (opts.padding * 2) : 0;
  6646. } else {
  6647. minSize.width = display ? fontSize + (opts.padding * 2) : 0;
  6648. minSize.height = me.maxHeight; // fill all the height
  6649. }
  6650. me.width = minSize.width;
  6651. me.height = minSize.height;
  6652. },
  6653. afterFit: noop,
  6654. // Shared Methods
  6655. isHorizontal: function() {
  6656. var pos = this.options.position;
  6657. return pos === 'top' || pos === 'bottom';
  6658. },
  6659. // Actualy draw the title block on the canvas
  6660. draw: function() {
  6661. var me = this,
  6662. ctx = me.ctx,
  6663. valueOrDefault = helpers.getValueOrDefault,
  6664. opts = me.options,
  6665. globalDefaults = Chart.defaults.global;
  6666. if (opts.display) {
  6667. var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize),
  6668. fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle),
  6669. fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily),
  6670. titleFont = helpers.fontString(fontSize, fontStyle, fontFamily),
  6671. rotation = 0,
  6672. titleX,
  6673. titleY,
  6674. top = me.top,
  6675. left = me.left,
  6676. bottom = me.bottom,
  6677. right = me.right;
  6678. ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
  6679. ctx.font = titleFont;
  6680. // Horizontal
  6681. if (me.isHorizontal()) {
  6682. titleX = left + ((right - left) / 2); // midpoint of the width
  6683. titleY = top + ((bottom - top) / 2); // midpoint of the height
  6684. } else {
  6685. titleX = opts.position === 'left' ? left + (fontSize / 2) : right - (fontSize / 2);
  6686. titleY = top + ((bottom - top) / 2);
  6687. rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
  6688. }
  6689. ctx.save();
  6690. ctx.translate(titleX, titleY);
  6691. ctx.rotate(rotation);
  6692. ctx.textAlign = 'center';
  6693. ctx.textBaseline = 'middle';
  6694. ctx.fillText(opts.text, 0, 0);
  6695. ctx.restore();
  6696. }
  6697. }
  6698. });
  6699. // Register the title plugin
  6700. Chart.plugins.register({
  6701. beforeInit: function(chartInstance) {
  6702. var opts = chartInstance.options;
  6703. var titleOpts = opts.title;
  6704. if (titleOpts) {
  6705. chartInstance.titleBlock = new Chart.Title({
  6706. ctx: chartInstance.chart.ctx,
  6707. options: titleOpts,
  6708. chart: chartInstance
  6709. });
  6710. Chart.layoutService.addBox(chartInstance, chartInstance.titleBlock);
  6711. }
  6712. }
  6713. });
  6714. };
  6715. },{}],34:[function(require,module,exports){
  6716. 'use strict';
  6717. module.exports = function(Chart) {
  6718. var helpers = Chart.helpers;
  6719. Chart.defaults.global.tooltips = {
  6720. enabled: true,
  6721. custom: null,
  6722. mode: 'single',
  6723. backgroundColor: 'rgba(0,0,0,0.8)',
  6724. titleFontStyle: 'bold',
  6725. titleSpacing: 2,
  6726. titleMarginBottom: 6,
  6727. titleFontColor: '#fff',
  6728. titleAlign: 'left',
  6729. bodySpacing: 2,
  6730. bodyFontColor: '#fff',
  6731. bodyAlign: 'left',
  6732. footerFontStyle: 'bold',
  6733. footerSpacing: 2,
  6734. footerMarginTop: 6,
  6735. footerFontColor: '#fff',
  6736. footerAlign: 'left',
  6737. yPadding: 6,
  6738. xPadding: 6,
  6739. yAlign: 'center',
  6740. xAlign: 'center',
  6741. caretSize: 5,
  6742. cornerRadius: 6,
  6743. multiKeyBackground: '#fff',
  6744. callbacks: {
  6745. // Args are: (tooltipItems, data)
  6746. beforeTitle: helpers.noop,
  6747. title: function(tooltipItems, data) {
  6748. // Pick first xLabel for now
  6749. var title = '';
  6750. var labels = data.labels;
  6751. var labelCount = labels ? labels.length : 0;
  6752. if (tooltipItems.length > 0) {
  6753. var item = tooltipItems[0];
  6754. if (item.xLabel) {
  6755. title = item.xLabel;
  6756. } else if (labelCount > 0 && item.index < labelCount) {
  6757. title = labels[item.index];
  6758. }
  6759. }
  6760. return title;
  6761. },
  6762. afterTitle: helpers.noop,
  6763. // Args are: (tooltipItems, data)
  6764. beforeBody: helpers.noop,
  6765. // Args are: (tooltipItem, data)
  6766. beforeLabel: helpers.noop,
  6767. label: function(tooltipItem, data) {
  6768. var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
  6769. return datasetLabel + ': ' + tooltipItem.yLabel;
  6770. },
  6771. labelColor: function(tooltipItem, chartInstance) {
  6772. var meta = chartInstance.getDatasetMeta(tooltipItem.datasetIndex);
  6773. var activeElement = meta.data[tooltipItem.index];
  6774. var view = activeElement._view;
  6775. return {
  6776. borderColor: view.borderColor,
  6777. backgroundColor: view.backgroundColor
  6778. };
  6779. },
  6780. afterLabel: helpers.noop,
  6781. // Args are: (tooltipItems, data)
  6782. afterBody: helpers.noop,
  6783. // Args are: (tooltipItems, data)
  6784. beforeFooter: helpers.noop,
  6785. footer: helpers.noop,
  6786. afterFooter: helpers.noop
  6787. }
  6788. };
  6789. // Helper to push or concat based on if the 2nd parameter is an array or not
  6790. function pushOrConcat(base, toPush) {
  6791. if (toPush) {
  6792. if (helpers.isArray(toPush)) {
  6793. // base = base.concat(toPush);
  6794. Array.prototype.push.apply(base, toPush);
  6795. } else {
  6796. base.push(toPush);
  6797. }
  6798. }
  6799. return base;
  6800. }
  6801. function getAveragePosition(elements) {
  6802. if (!elements.length) {
  6803. return false;
  6804. }
  6805. var i, len;
  6806. var xPositions = [];
  6807. var yPositions = [];
  6808. for (i = 0, len = elements.length; i < len; ++i) {
  6809. var el = elements[i];
  6810. if (el && el.hasValue()) {
  6811. var pos = el.tooltipPosition();
  6812. xPositions.push(pos.x);
  6813. yPositions.push(pos.y);
  6814. }
  6815. }
  6816. var x = 0,
  6817. y = 0;
  6818. for (i = 0; i < xPositions.length; ++i) {
  6819. if (xPositions[i]) {
  6820. x += xPositions[i];
  6821. y += yPositions[i];
  6822. }
  6823. }
  6824. return {
  6825. x: Math.round(x / xPositions.length),
  6826. y: Math.round(y / xPositions.length)
  6827. };
  6828. }
  6829. // Private helper to create a tooltip iteam model
  6830. // @param element : the chart element (point, arc, bar) to create the tooltip item for
  6831. // @return : new tooltip item
  6832. function createTooltipItem(element) {
  6833. var xScale = element._xScale;
  6834. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  6835. var index = element._index,
  6836. datasetIndex = element._datasetIndex;
  6837. return {
  6838. xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
  6839. yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
  6840. index: index,
  6841. datasetIndex: datasetIndex
  6842. };
  6843. }
  6844. Chart.Tooltip = Chart.Element.extend({
  6845. initialize: function() {
  6846. var me = this;
  6847. var globalDefaults = Chart.defaults.global;
  6848. var tooltipOpts = me._options;
  6849. var getValueOrDefault = helpers.getValueOrDefault;
  6850. helpers.extend(me, {
  6851. _model: {
  6852. // Positioning
  6853. xPadding: tooltipOpts.xPadding,
  6854. yPadding: tooltipOpts.yPadding,
  6855. xAlign: tooltipOpts.xAlign,
  6856. yAlign: tooltipOpts.yAlign,
  6857. // Body
  6858. bodyFontColor: tooltipOpts.bodyFontColor,
  6859. _bodyFontFamily: getValueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
  6860. _bodyFontStyle: getValueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
  6861. _bodyAlign: tooltipOpts.bodyAlign,
  6862. bodyFontSize: getValueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
  6863. bodySpacing: tooltipOpts.bodySpacing,
  6864. // Title
  6865. titleFontColor: tooltipOpts.titleFontColor,
  6866. _titleFontFamily: getValueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
  6867. _titleFontStyle: getValueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
  6868. titleFontSize: getValueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
  6869. _titleAlign: tooltipOpts.titleAlign,
  6870. titleSpacing: tooltipOpts.titleSpacing,
  6871. titleMarginBottom: tooltipOpts.titleMarginBottom,
  6872. // Footer
  6873. footerFontColor: tooltipOpts.footerFontColor,
  6874. _footerFontFamily: getValueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
  6875. _footerFontStyle: getValueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
  6876. footerFontSize: getValueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
  6877. _footerAlign: tooltipOpts.footerAlign,
  6878. footerSpacing: tooltipOpts.footerSpacing,
  6879. footerMarginTop: tooltipOpts.footerMarginTop,
  6880. // Appearance
  6881. caretSize: tooltipOpts.caretSize,
  6882. cornerRadius: tooltipOpts.cornerRadius,
  6883. backgroundColor: tooltipOpts.backgroundColor,
  6884. opacity: 0,
  6885. legendColorBackground: tooltipOpts.multiKeyBackground
  6886. }
  6887. });
  6888. },
  6889. // Get the title
  6890. // Args are: (tooltipItem, data)
  6891. getTitle: function() {
  6892. var me = this;
  6893. var opts = me._options;
  6894. var callbacks = opts.callbacks;
  6895. var beforeTitle = callbacks.beforeTitle.apply(me, arguments),
  6896. title = callbacks.title.apply(me, arguments),
  6897. afterTitle = callbacks.afterTitle.apply(me, arguments);
  6898. var lines = [];
  6899. lines = pushOrConcat(lines, beforeTitle);
  6900. lines = pushOrConcat(lines, title);
  6901. lines = pushOrConcat(lines, afterTitle);
  6902. return lines;
  6903. },
  6904. // Args are: (tooltipItem, data)
  6905. getBeforeBody: function() {
  6906. var lines = this._options.callbacks.beforeBody.apply(this, arguments);
  6907. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  6908. },
  6909. // Args are: (tooltipItem, data)
  6910. getBody: function(tooltipItems, data) {
  6911. var me = this;
  6912. var callbacks = me._options.callbacks;
  6913. var bodyItems = [];
  6914. helpers.each(tooltipItems, function(tooltipItem) {
  6915. var bodyItem = {
  6916. before: [],
  6917. lines: [],
  6918. after: []
  6919. };
  6920. pushOrConcat(bodyItem.before, callbacks.beforeLabel.call(me, tooltipItem, data));
  6921. pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
  6922. pushOrConcat(bodyItem.after, callbacks.afterLabel.call(me, tooltipItem, data));
  6923. bodyItems.push(bodyItem);
  6924. });
  6925. return bodyItems;
  6926. },
  6927. // Args are: (tooltipItem, data)
  6928. getAfterBody: function() {
  6929. var lines = this._options.callbacks.afterBody.apply(this, arguments);
  6930. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  6931. },
  6932. // Get the footer and beforeFooter and afterFooter lines
  6933. // Args are: (tooltipItem, data)
  6934. getFooter: function() {
  6935. var me = this;
  6936. var callbacks = me._options.callbacks;
  6937. var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
  6938. var footer = callbacks.footer.apply(me, arguments);
  6939. var afterFooter = callbacks.afterFooter.apply(me, arguments);
  6940. var lines = [];
  6941. lines = pushOrConcat(lines, beforeFooter);
  6942. lines = pushOrConcat(lines, footer);
  6943. lines = pushOrConcat(lines, afterFooter);
  6944. return lines;
  6945. },
  6946. update: function(changed) {
  6947. var me = this;
  6948. var opts = me._options;
  6949. var model = me._model;
  6950. var active = me._active;
  6951. var data = me._data;
  6952. var chartInstance = me._chartInstance;
  6953. var i, len;
  6954. if (active.length) {
  6955. model.opacity = 1;
  6956. var labelColors = [],
  6957. tooltipPosition = getAveragePosition(active);
  6958. var tooltipItems = [];
  6959. for (i = 0, len = active.length; i < len; ++i) {
  6960. tooltipItems.push(createTooltipItem(active[i]));
  6961. }
  6962. // If the user provided a sorting function, use it to modify the tooltip items
  6963. if (opts.itemSort) {
  6964. tooltipItems = tooltipItems.sort(function(a, b) {
  6965. return opts.itemSort(a, b, data);
  6966. });
  6967. }
  6968. // If there is more than one item, show color items
  6969. if (active.length > 1) {
  6970. helpers.each(tooltipItems, function(tooltipItem) {
  6971. labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, chartInstance));
  6972. });
  6973. }
  6974. // Build the Text Lines
  6975. helpers.extend(model, {
  6976. title: me.getTitle(tooltipItems, data),
  6977. beforeBody: me.getBeforeBody(tooltipItems, data),
  6978. body: me.getBody(tooltipItems, data),
  6979. afterBody: me.getAfterBody(tooltipItems, data),
  6980. footer: me.getFooter(tooltipItems, data),
  6981. x: Math.round(tooltipPosition.x),
  6982. y: Math.round(tooltipPosition.y),
  6983. caretPadding: helpers.getValueOrDefault(tooltipPosition.padding, 2),
  6984. labelColors: labelColors
  6985. });
  6986. // We need to determine alignment of
  6987. var tooltipSize = me.getTooltipSize(model);
  6988. me.determineAlignment(tooltipSize); // Smart Tooltip placement to stay on the canvas
  6989. helpers.extend(model, me.getBackgroundPoint(model, tooltipSize));
  6990. } else {
  6991. me._model.opacity = 0;
  6992. }
  6993. if (changed && opts.custom) {
  6994. opts.custom.call(me, model);
  6995. }
  6996. return me;
  6997. },
  6998. getTooltipSize: function(vm) {
  6999. var ctx = this._chart.ctx;
  7000. var size = {
  7001. height: vm.yPadding * 2, // Tooltip Padding
  7002. width: 0
  7003. };
  7004. // Count of all lines in the body
  7005. var body = vm.body;
  7006. var combinedBodyLength = body.reduce(function(count, bodyItem) {
  7007. return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
  7008. }, 0);
  7009. combinedBodyLength += vm.beforeBody.length + vm.afterBody.length;
  7010. var titleLineCount = vm.title.length;
  7011. var footerLineCount = vm.footer.length;
  7012. var titleFontSize = vm.titleFontSize,
  7013. bodyFontSize = vm.bodyFontSize,
  7014. footerFontSize = vm.footerFontSize;
  7015. size.height += titleLineCount * titleFontSize; // Title Lines
  7016. size.height += (titleLineCount - 1) * vm.titleSpacing; // Title Line Spacing
  7017. size.height += titleLineCount ? vm.titleMarginBottom : 0; // Title's bottom Margin
  7018. size.height += combinedBodyLength * bodyFontSize; // Body Lines
  7019. size.height += combinedBodyLength ? (combinedBodyLength - 1) * vm.bodySpacing : 0; // Body Line Spacing
  7020. size.height += footerLineCount ? vm.footerMarginTop : 0; // Footer Margin
  7021. size.height += footerLineCount * (footerFontSize); // Footer Lines
  7022. size.height += footerLineCount ? (footerLineCount - 1) * vm.footerSpacing : 0; // Footer Line Spacing
  7023. // Title width
  7024. var widthPadding = 0;
  7025. var maxLineWidth = function(line) {
  7026. size.width = Math.max(size.width, ctx.measureText(line).width + widthPadding);
  7027. };
  7028. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  7029. helpers.each(vm.title, maxLineWidth);
  7030. // Body width
  7031. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  7032. helpers.each(vm.beforeBody.concat(vm.afterBody), maxLineWidth);
  7033. // Body lines may include some extra width due to the color box
  7034. widthPadding = body.length > 1 ? (bodyFontSize + 2) : 0;
  7035. helpers.each(body, function(bodyItem) {
  7036. helpers.each(bodyItem.before, maxLineWidth);
  7037. helpers.each(bodyItem.lines, maxLineWidth);
  7038. helpers.each(bodyItem.after, maxLineWidth);
  7039. });
  7040. // Reset back to 0
  7041. widthPadding = 0;
  7042. // Footer width
  7043. ctx.font = helpers.fontString(footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  7044. helpers.each(vm.footer, maxLineWidth);
  7045. // Add padding
  7046. size.width += 2 * vm.xPadding;
  7047. return size;
  7048. },
  7049. determineAlignment: function(size) {
  7050. var me = this;
  7051. var model = me._model;
  7052. var chart = me._chart;
  7053. var chartArea = me._chartInstance.chartArea;
  7054. if (model.y < size.height) {
  7055. model.yAlign = 'top';
  7056. } else if (model.y > (chart.height - size.height)) {
  7057. model.yAlign = 'bottom';
  7058. }
  7059. var lf, rf; // functions to determine left, right alignment
  7060. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  7061. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  7062. var midX = (chartArea.left + chartArea.right) / 2;
  7063. var midY = (chartArea.top + chartArea.bottom) / 2;
  7064. if (model.yAlign === 'center') {
  7065. lf = function(x) {
  7066. return x <= midX;
  7067. };
  7068. rf = function(x) {
  7069. return x > midX;
  7070. };
  7071. } else {
  7072. lf = function(x) {
  7073. return x <= (size.width / 2);
  7074. };
  7075. rf = function(x) {
  7076. return x >= (chart.width - (size.width / 2));
  7077. };
  7078. }
  7079. olf = function(x) {
  7080. return x + size.width > chart.width;
  7081. };
  7082. orf = function(x) {
  7083. return x - size.width < 0;
  7084. };
  7085. yf = function(y) {
  7086. return y <= midY ? 'top' : 'bottom';
  7087. };
  7088. if (lf(model.x)) {
  7089. model.xAlign = 'left';
  7090. // Is tooltip too wide and goes over the right side of the chart.?
  7091. if (olf(model.x)) {
  7092. model.xAlign = 'center';
  7093. model.yAlign = yf(model.y);
  7094. }
  7095. } else if (rf(model.x)) {
  7096. model.xAlign = 'right';
  7097. // Is tooltip too wide and goes outside left edge of canvas?
  7098. if (orf(model.x)) {
  7099. model.xAlign = 'center';
  7100. model.yAlign = yf(model.y);
  7101. }
  7102. }
  7103. },
  7104. getBackgroundPoint: function(vm, size) {
  7105. // Background Position
  7106. var pt = {
  7107. x: vm.x,
  7108. y: vm.y
  7109. };
  7110. var caretSize = vm.caretSize,
  7111. caretPadding = vm.caretPadding,
  7112. cornerRadius = vm.cornerRadius,
  7113. xAlign = vm.xAlign,
  7114. yAlign = vm.yAlign,
  7115. paddingAndSize = caretSize + caretPadding,
  7116. radiusAndPadding = cornerRadius + caretPadding;
  7117. if (xAlign === 'right') {
  7118. pt.x -= size.width;
  7119. } else if (xAlign === 'center') {
  7120. pt.x -= (size.width / 2);
  7121. }
  7122. if (yAlign === 'top') {
  7123. pt.y += paddingAndSize;
  7124. } else if (yAlign === 'bottom') {
  7125. pt.y -= size.height + paddingAndSize;
  7126. } else {
  7127. pt.y -= (size.height / 2);
  7128. }
  7129. if (yAlign === 'center') {
  7130. if (xAlign === 'left') {
  7131. pt.x += paddingAndSize;
  7132. } else if (xAlign === 'right') {
  7133. pt.x -= paddingAndSize;
  7134. }
  7135. } else if (xAlign === 'left') {
  7136. pt.x -= radiusAndPadding;
  7137. } else if (xAlign === 'right') {
  7138. pt.x += radiusAndPadding;
  7139. }
  7140. return pt;
  7141. },
  7142. drawCaret: function(tooltipPoint, size, opacity) {
  7143. var vm = this._view;
  7144. var ctx = this._chart.ctx;
  7145. var x1, x2, x3;
  7146. var y1, y2, y3;
  7147. var caretSize = vm.caretSize;
  7148. var cornerRadius = vm.cornerRadius;
  7149. var xAlign = vm.xAlign,
  7150. yAlign = vm.yAlign;
  7151. var ptX = tooltipPoint.x,
  7152. ptY = tooltipPoint.y;
  7153. var width = size.width,
  7154. height = size.height;
  7155. if (yAlign === 'center') {
  7156. // Left or right side
  7157. if (xAlign === 'left') {
  7158. x1 = ptX;
  7159. x2 = x1 - caretSize;
  7160. x3 = x1;
  7161. } else {
  7162. x1 = ptX + width;
  7163. x2 = x1 + caretSize;
  7164. x3 = x1;
  7165. }
  7166. y2 = ptY + (height / 2);
  7167. y1 = y2 - caretSize;
  7168. y3 = y2 + caretSize;
  7169. } else {
  7170. if (xAlign === 'left') {
  7171. x1 = ptX + cornerRadius;
  7172. x2 = x1 + caretSize;
  7173. x3 = x2 + caretSize;
  7174. } else if (xAlign === 'right') {
  7175. x1 = ptX + width - cornerRadius;
  7176. x2 = x1 - caretSize;
  7177. x3 = x2 - caretSize;
  7178. } else {
  7179. x2 = ptX + (width / 2);
  7180. x1 = x2 - caretSize;
  7181. x3 = x2 + caretSize;
  7182. }
  7183. if (yAlign === 'top') {
  7184. y1 = ptY;
  7185. y2 = y1 - caretSize;
  7186. y3 = y1;
  7187. } else {
  7188. y1 = ptY + height;
  7189. y2 = y1 + caretSize;
  7190. y3 = y1;
  7191. }
  7192. }
  7193. var bgColor = helpers.color(vm.backgroundColor);
  7194. ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
  7195. ctx.beginPath();
  7196. ctx.moveTo(x1, y1);
  7197. ctx.lineTo(x2, y2);
  7198. ctx.lineTo(x3, y3);
  7199. ctx.closePath();
  7200. ctx.fill();
  7201. },
  7202. drawTitle: function(pt, vm, ctx, opacity) {
  7203. var title = vm.title;
  7204. if (title.length) {
  7205. ctx.textAlign = vm._titleAlign;
  7206. ctx.textBaseline = 'top';
  7207. var titleFontSize = vm.titleFontSize,
  7208. titleSpacing = vm.titleSpacing;
  7209. var titleFontColor = helpers.color(vm.titleFontColor);
  7210. ctx.fillStyle = titleFontColor.alpha(opacity * titleFontColor.alpha()).rgbString();
  7211. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  7212. var i, len;
  7213. for (i = 0, len = title.length; i < len; ++i) {
  7214. ctx.fillText(title[i], pt.x, pt.y);
  7215. pt.y += titleFontSize + titleSpacing; // Line Height and spacing
  7216. if (i + 1 === title.length) {
  7217. pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
  7218. }
  7219. }
  7220. }
  7221. },
  7222. drawBody: function(pt, vm, ctx, opacity) {
  7223. var bodyFontSize = vm.bodyFontSize;
  7224. var bodySpacing = vm.bodySpacing;
  7225. var body = vm.body;
  7226. ctx.textAlign = vm._bodyAlign;
  7227. ctx.textBaseline = 'top';
  7228. var bodyFontColor = helpers.color(vm.bodyFontColor);
  7229. var textColor = bodyFontColor.alpha(opacity * bodyFontColor.alpha()).rgbString();
  7230. ctx.fillStyle = textColor;
  7231. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  7232. // Before Body
  7233. var xLinePadding = 0;
  7234. var fillLineOfText = function(line) {
  7235. ctx.fillText(line, pt.x + xLinePadding, pt.y);
  7236. pt.y += bodyFontSize + bodySpacing;
  7237. };
  7238. // Before body lines
  7239. helpers.each(vm.beforeBody, fillLineOfText);
  7240. var drawColorBoxes = body.length > 1;
  7241. xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
  7242. // Draw body lines now
  7243. helpers.each(body, function(bodyItem, i) {
  7244. helpers.each(bodyItem.before, fillLineOfText);
  7245. helpers.each(bodyItem.lines, function(line) {
  7246. // Draw Legend-like boxes if needed
  7247. if (drawColorBoxes) {
  7248. // Fill a white rect so that colours merge nicely if the opacity is < 1
  7249. ctx.fillStyle = helpers.color(vm.legendColorBackground).alpha(opacity).rgbaString();
  7250. ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7251. // Border
  7252. ctx.strokeStyle = helpers.color(vm.labelColors[i].borderColor).alpha(opacity).rgbaString();
  7253. ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7254. // Inner square
  7255. ctx.fillStyle = helpers.color(vm.labelColors[i].backgroundColor).alpha(opacity).rgbaString();
  7256. ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
  7257. ctx.fillStyle = textColor;
  7258. }
  7259. fillLineOfText(line);
  7260. });
  7261. helpers.each(bodyItem.after, fillLineOfText);
  7262. });
  7263. // Reset back to 0 for after body
  7264. xLinePadding = 0;
  7265. // After body lines
  7266. helpers.each(vm.afterBody, fillLineOfText);
  7267. pt.y -= bodySpacing; // Remove last body spacing
  7268. },
  7269. drawFooter: function(pt, vm, ctx, opacity) {
  7270. var footer = vm.footer;
  7271. if (footer.length) {
  7272. pt.y += vm.footerMarginTop;
  7273. ctx.textAlign = vm._footerAlign;
  7274. ctx.textBaseline = 'top';
  7275. var footerFontColor = helpers.color(vm.footerFontColor);
  7276. ctx.fillStyle = footerFontColor.alpha(opacity * footerFontColor.alpha()).rgbString();
  7277. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  7278. helpers.each(footer, function(line) {
  7279. ctx.fillText(line, pt.x, pt.y);
  7280. pt.y += vm.footerFontSize + vm.footerSpacing;
  7281. });
  7282. }
  7283. },
  7284. draw: function() {
  7285. var ctx = this._chart.ctx;
  7286. var vm = this._view;
  7287. if (vm.opacity === 0) {
  7288. return;
  7289. }
  7290. var tooltipSize = this.getTooltipSize(vm);
  7291. var pt = {
  7292. x: vm.x,
  7293. y: vm.y
  7294. };
  7295. // IE11/Edge does not like very small opacities, so snap to 0
  7296. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  7297. if (this._options.enabled) {
  7298. // Draw Background
  7299. var bgColor = helpers.color(vm.backgroundColor);
  7300. ctx.fillStyle = bgColor.alpha(opacity * bgColor.alpha()).rgbString();
  7301. helpers.drawRoundedRectangle(ctx, pt.x, pt.y, tooltipSize.width, tooltipSize.height, vm.cornerRadius);
  7302. ctx.fill();
  7303. // Draw Caret
  7304. this.drawCaret(pt, tooltipSize, opacity);
  7305. // Draw Title, Body, and Footer
  7306. pt.x += vm.xPadding;
  7307. pt.y += vm.yPadding;
  7308. // Titles
  7309. this.drawTitle(pt, vm, ctx, opacity);
  7310. // Body
  7311. this.drawBody(pt, vm, ctx, opacity);
  7312. // Footer
  7313. this.drawFooter(pt, vm, ctx, opacity);
  7314. }
  7315. }
  7316. });
  7317. };
  7318. },{}],35:[function(require,module,exports){
  7319. 'use strict';
  7320. module.exports = function(Chart) {
  7321. var helpers = Chart.helpers,
  7322. globalOpts = Chart.defaults.global;
  7323. globalOpts.elements.arc = {
  7324. backgroundColor: globalOpts.defaultColor,
  7325. borderColor: '#fff',
  7326. borderWidth: 2
  7327. };
  7328. Chart.elements.Arc = Chart.Element.extend({
  7329. inLabelRange: function(mouseX) {
  7330. var vm = this._view;
  7331. if (vm) {
  7332. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  7333. }
  7334. return false;
  7335. },
  7336. inRange: function(chartX, chartY) {
  7337. var vm = this._view;
  7338. if (vm) {
  7339. var pointRelativePosition = helpers.getAngleFromPoint(vm, {
  7340. x: chartX,
  7341. y: chartY
  7342. }),
  7343. angle = pointRelativePosition.angle,
  7344. distance = pointRelativePosition.distance;
  7345. // Sanitise angle range
  7346. var startAngle = vm.startAngle;
  7347. var endAngle = vm.endAngle;
  7348. while (endAngle < startAngle) {
  7349. endAngle += 2.0 * Math.PI;
  7350. }
  7351. while (angle > endAngle) {
  7352. angle -= 2.0 * Math.PI;
  7353. }
  7354. while (angle < startAngle) {
  7355. angle += 2.0 * Math.PI;
  7356. }
  7357. // Check if within the range of the open/close angle
  7358. var betweenAngles = (angle >= startAngle && angle <= endAngle),
  7359. withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
  7360. return (betweenAngles && withinRadius);
  7361. }
  7362. return false;
  7363. },
  7364. tooltipPosition: function() {
  7365. var vm = this._view;
  7366. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2),
  7367. rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  7368. return {
  7369. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  7370. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  7371. };
  7372. },
  7373. draw: function() {
  7374. var ctx = this._chart.ctx,
  7375. vm = this._view,
  7376. sA = vm.startAngle,
  7377. eA = vm.endAngle;
  7378. ctx.beginPath();
  7379. ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
  7380. ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
  7381. ctx.closePath();
  7382. ctx.strokeStyle = vm.borderColor;
  7383. ctx.lineWidth = vm.borderWidth;
  7384. ctx.fillStyle = vm.backgroundColor;
  7385. ctx.fill();
  7386. ctx.lineJoin = 'bevel';
  7387. if (vm.borderWidth) {
  7388. ctx.stroke();
  7389. }
  7390. }
  7391. });
  7392. };
  7393. },{}],36:[function(require,module,exports){
  7394. 'use strict';
  7395. module.exports = function(Chart) {
  7396. var helpers = Chart.helpers;
  7397. var globalDefaults = Chart.defaults.global;
  7398. Chart.defaults.global.elements.line = {
  7399. tension: 0.4,
  7400. backgroundColor: globalDefaults.defaultColor,
  7401. borderWidth: 3,
  7402. borderColor: globalDefaults.defaultColor,
  7403. borderCapStyle: 'butt',
  7404. borderDash: [],
  7405. borderDashOffset: 0.0,
  7406. borderJoinStyle: 'miter',
  7407. capBezierPoints: true,
  7408. fill: true // do we fill in the area between the line and its base axis
  7409. };
  7410. Chart.elements.Line = Chart.Element.extend({
  7411. draw: function() {
  7412. var me = this;
  7413. var vm = me._view;
  7414. var spanGaps = vm.spanGaps;
  7415. var scaleZero = vm.scaleZero;
  7416. var loop = me._loop;
  7417. var ctx = me._chart.ctx;
  7418. ctx.save();
  7419. // Helper function to draw a line to a point
  7420. function lineToPoint(previousPoint, point) {
  7421. var pointVM = point._view;
  7422. if (point._view.steppedLine === true) {
  7423. ctx.lineTo(pointVM.x, previousPoint._view.y);
  7424. ctx.lineTo(pointVM.x, pointVM.y);
  7425. } else if (point._view.tension === 0) {
  7426. ctx.lineTo(pointVM.x, pointVM.y);
  7427. } else {
  7428. ctx.bezierCurveTo(
  7429. previousPoint._view.controlPointNextX,
  7430. previousPoint._view.controlPointNextY,
  7431. pointVM.controlPointPreviousX,
  7432. pointVM.controlPointPreviousY,
  7433. pointVM.x,
  7434. pointVM.y
  7435. );
  7436. }
  7437. }
  7438. var points = me._children.slice(); // clone array
  7439. var lastDrawnIndex = -1;
  7440. // If we are looping, adding the first point again
  7441. if (loop && points.length) {
  7442. points.push(points[0]);
  7443. }
  7444. var index, current, previous, currentVM;
  7445. // Fill Line
  7446. if (points.length && vm.fill) {
  7447. ctx.beginPath();
  7448. for (index = 0; index < points.length; ++index) {
  7449. current = points[index];
  7450. previous = helpers.previousItem(points, index);
  7451. currentVM = current._view;
  7452. // First point moves to it's starting position no matter what
  7453. if (index === 0) {
  7454. if (loop) {
  7455. ctx.moveTo(scaleZero.x, scaleZero.y);
  7456. } else {
  7457. ctx.moveTo(currentVM.x, scaleZero);
  7458. }
  7459. if (!currentVM.skip) {
  7460. lastDrawnIndex = index;
  7461. ctx.lineTo(currentVM.x, currentVM.y);
  7462. }
  7463. } else {
  7464. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  7465. if (currentVM.skip) {
  7466. // Only do this if this is the first point that is skipped
  7467. if (!spanGaps && lastDrawnIndex === (index - 1)) {
  7468. if (loop) {
  7469. ctx.lineTo(scaleZero.x, scaleZero.y);
  7470. } else {
  7471. ctx.lineTo(previous._view.x, scaleZero);
  7472. }
  7473. }
  7474. } else {
  7475. if (lastDrawnIndex !== (index - 1)) {
  7476. // 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.
  7477. // If the first data point is NaN, then there is no real gap to skip
  7478. if (spanGaps && lastDrawnIndex !== -1) {
  7479. // We are spanning the gap, so simple draw a line to this point
  7480. lineToPoint(previous, current);
  7481. } else if (loop) {
  7482. ctx.lineTo(currentVM.x, currentVM.y);
  7483. } else {
  7484. ctx.lineTo(currentVM.x, scaleZero);
  7485. ctx.lineTo(currentVM.x, currentVM.y);
  7486. }
  7487. } else {
  7488. // Line to next point
  7489. lineToPoint(previous, current);
  7490. }
  7491. lastDrawnIndex = index;
  7492. }
  7493. }
  7494. }
  7495. if (!loop && lastDrawnIndex !== -1) {
  7496. ctx.lineTo(points[lastDrawnIndex]._view.x, scaleZero);
  7497. }
  7498. ctx.fillStyle = vm.backgroundColor || globalDefaults.defaultColor;
  7499. ctx.closePath();
  7500. ctx.fill();
  7501. }
  7502. // Stroke Line Options
  7503. var globalOptionLineElements = globalDefaults.elements.line;
  7504. ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
  7505. // IE 9 and 10 do not support line dash
  7506. if (ctx.setLineDash) {
  7507. ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
  7508. }
  7509. ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
  7510. ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
  7511. ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
  7512. ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
  7513. // Stroke Line
  7514. ctx.beginPath();
  7515. lastDrawnIndex = -1;
  7516. for (index = 0; index < points.length; ++index) {
  7517. current = points[index];
  7518. previous = helpers.previousItem(points, index);
  7519. currentVM = current._view;
  7520. // First point moves to it's starting position no matter what
  7521. if (index === 0) {
  7522. if (!currentVM.skip) {
  7523. ctx.moveTo(currentVM.x, currentVM.y);
  7524. lastDrawnIndex = index;
  7525. }
  7526. } else {
  7527. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  7528. if (!currentVM.skip) {
  7529. if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
  7530. // There was a gap and this is the first point after the gap
  7531. ctx.moveTo(currentVM.x, currentVM.y);
  7532. } else {
  7533. // Line to next point
  7534. lineToPoint(previous, current);
  7535. }
  7536. lastDrawnIndex = index;
  7537. }
  7538. }
  7539. }
  7540. ctx.stroke();
  7541. ctx.restore();
  7542. }
  7543. });
  7544. };
  7545. },{}],37:[function(require,module,exports){
  7546. 'use strict';
  7547. module.exports = function(Chart) {
  7548. var helpers = Chart.helpers,
  7549. globalOpts = Chart.defaults.global,
  7550. defaultColor = globalOpts.defaultColor;
  7551. globalOpts.elements.point = {
  7552. radius: 3,
  7553. pointStyle: 'circle',
  7554. backgroundColor: defaultColor,
  7555. borderWidth: 1,
  7556. borderColor: defaultColor,
  7557. // Hover
  7558. hitRadius: 1,
  7559. hoverRadius: 4,
  7560. hoverBorderWidth: 1
  7561. };
  7562. Chart.elements.Point = Chart.Element.extend({
  7563. inRange: function(mouseX, mouseY) {
  7564. var vm = this._view;
  7565. return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
  7566. },
  7567. inLabelRange: function(mouseX) {
  7568. var vm = this._view;
  7569. return vm ? (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hitRadius, 2)) : false;
  7570. },
  7571. tooltipPosition: function() {
  7572. var vm = this._view;
  7573. return {
  7574. x: vm.x,
  7575. y: vm.y,
  7576. padding: vm.radius + vm.borderWidth
  7577. };
  7578. },
  7579. draw: function() {
  7580. var vm = this._view;
  7581. var ctx = this._chart.ctx;
  7582. var pointStyle = vm.pointStyle;
  7583. var radius = vm.radius;
  7584. var x = vm.x;
  7585. var y = vm.y;
  7586. if (vm.skip) {
  7587. return;
  7588. }
  7589. ctx.strokeStyle = vm.borderColor || defaultColor;
  7590. ctx.lineWidth = helpers.getValueOrDefault(vm.borderWidth, globalOpts.elements.point.borderWidth);
  7591. ctx.fillStyle = vm.backgroundColor || defaultColor;
  7592. Chart.canvasHelpers.drawPoint(ctx, pointStyle, radius, x, y);
  7593. }
  7594. });
  7595. };
  7596. },{}],38:[function(require,module,exports){
  7597. 'use strict';
  7598. module.exports = function(Chart) {
  7599. var globalOpts = Chart.defaults.global;
  7600. globalOpts.elements.rectangle = {
  7601. backgroundColor: globalOpts.defaultColor,
  7602. borderWidth: 0,
  7603. borderColor: globalOpts.defaultColor,
  7604. borderSkipped: 'bottom'
  7605. };
  7606. Chart.elements.Rectangle = Chart.Element.extend({
  7607. draw: function() {
  7608. var ctx = this._chart.ctx;
  7609. var vm = this._view;
  7610. var halfWidth = vm.width / 2,
  7611. leftX = vm.x - halfWidth,
  7612. rightX = vm.x + halfWidth,
  7613. top = vm.base - (vm.base - vm.y),
  7614. halfStroke = vm.borderWidth / 2;
  7615. // Canvas doesn't allow us to stroke inside the width so we can
  7616. // adjust the sizes to fit if we're setting a stroke on the line
  7617. if (vm.borderWidth) {
  7618. leftX += halfStroke;
  7619. rightX -= halfStroke;
  7620. top += halfStroke;
  7621. }
  7622. ctx.beginPath();
  7623. ctx.fillStyle = vm.backgroundColor;
  7624. ctx.strokeStyle = vm.borderColor;
  7625. ctx.lineWidth = vm.borderWidth;
  7626. // Corner points, from bottom-left to bottom-right clockwise
  7627. // | 1 2 |
  7628. // | 0 3 |
  7629. var corners = [
  7630. [leftX, vm.base],
  7631. [leftX, top],
  7632. [rightX, top],
  7633. [rightX, vm.base]
  7634. ];
  7635. // Find first (starting) corner with fallback to 'bottom'
  7636. var borders = ['bottom', 'left', 'top', 'right'];
  7637. var startCorner = borders.indexOf(vm.borderSkipped, 0);
  7638. if (startCorner === -1) {
  7639. startCorner = 0;
  7640. }
  7641. function cornerAt(index) {
  7642. return corners[(startCorner + index) % 4];
  7643. }
  7644. // Draw rectangle from 'startCorner'
  7645. ctx.moveTo.apply(ctx, cornerAt(0));
  7646. for (var i = 1; i < 4; i++) {
  7647. ctx.lineTo.apply(ctx, cornerAt(i));
  7648. }
  7649. ctx.fill();
  7650. if (vm.borderWidth) {
  7651. ctx.stroke();
  7652. }
  7653. },
  7654. height: function() {
  7655. var vm = this._view;
  7656. return vm.base - vm.y;
  7657. },
  7658. inRange: function(mouseX, mouseY) {
  7659. var vm = this._view;
  7660. return vm ?
  7661. (vm.y < vm.base ?
  7662. (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.y && mouseY <= vm.base) :
  7663. (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.base && mouseY <= vm.y)) :
  7664. false;
  7665. },
  7666. inLabelRange: function(mouseX) {
  7667. var vm = this._view;
  7668. return vm ? (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) : false;
  7669. },
  7670. tooltipPosition: function() {
  7671. var vm = this._view;
  7672. return {
  7673. x: vm.x,
  7674. y: vm.y
  7675. };
  7676. }
  7677. });
  7678. };
  7679. },{}],39:[function(require,module,exports){
  7680. 'use strict';
  7681. module.exports = function(Chart) {
  7682. var helpers = Chart.helpers;
  7683. // Default config for a category scale
  7684. var defaultConfig = {
  7685. position: 'bottom'
  7686. };
  7687. var DatasetScale = Chart.Scale.extend({
  7688. /**
  7689. * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use tose
  7690. * else fall back to data.labels
  7691. * @private
  7692. */
  7693. getLabels: function() {
  7694. var data = this.chart.data;
  7695. return (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
  7696. },
  7697. // Implement this so that
  7698. determineDataLimits: function() {
  7699. var me = this;
  7700. var labels = me.getLabels();
  7701. me.minIndex = 0;
  7702. me.maxIndex = labels.length - 1;
  7703. var findIndex;
  7704. if (me.options.ticks.min !== undefined) {
  7705. // user specified min value
  7706. findIndex = helpers.indexOf(labels, me.options.ticks.min);
  7707. me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
  7708. }
  7709. if (me.options.ticks.max !== undefined) {
  7710. // user specified max value
  7711. findIndex = helpers.indexOf(labels, me.options.ticks.max);
  7712. me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
  7713. }
  7714. me.min = labels[me.minIndex];
  7715. me.max = labels[me.maxIndex];
  7716. },
  7717. buildTicks: function() {
  7718. var me = this;
  7719. var labels = me.getLabels();
  7720. // If we are viewing some subset of labels, slice the original array
  7721. me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
  7722. },
  7723. getLabelForIndex: function(index, datasetIndex) {
  7724. var me = this;
  7725. var data = me.chart.data;
  7726. var isHorizontal = me.isHorizontal();
  7727. if ((data.xLabels && isHorizontal) || (data.yLabels && !isHorizontal)) {
  7728. return me.getRightValue(data.datasets[datasetIndex].data[index]);
  7729. }
  7730. return me.ticks[index];
  7731. },
  7732. // Used to get data value locations. Value can either be an index or a numerical value
  7733. getPixelForValue: function(value, index, datasetIndex, includeOffset) {
  7734. var me = this;
  7735. // 1 is added because we need the length but we have the indexes
  7736. var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  7737. if (value !== undefined && isNaN(index)) {
  7738. var labels = me.getLabels();
  7739. var idx = labels.indexOf(value);
  7740. index = idx !== -1 ? idx : index;
  7741. }
  7742. if (me.isHorizontal()) {
  7743. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  7744. var valueWidth = innerWidth / offsetAmt;
  7745. var widthOffset = (valueWidth * (index - me.minIndex)) + me.paddingLeft;
  7746. if (me.options.gridLines.offsetGridLines && includeOffset || me.maxIndex === me.minIndex && includeOffset) {
  7747. widthOffset += (valueWidth / 2);
  7748. }
  7749. return me.left + Math.round(widthOffset);
  7750. }
  7751. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  7752. var valueHeight = innerHeight / offsetAmt;
  7753. var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop;
  7754. if (me.options.gridLines.offsetGridLines && includeOffset) {
  7755. heightOffset += (valueHeight / 2);
  7756. }
  7757. return me.top + Math.round(heightOffset);
  7758. },
  7759. getPixelForTick: function(index, includeOffset) {
  7760. return this.getPixelForValue(this.ticks[index], index + this.minIndex, null, includeOffset);
  7761. },
  7762. getValueForPixel: function(pixel) {
  7763. var me = this;
  7764. var value;
  7765. var offsetAmt = Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
  7766. var horz = me.isHorizontal();
  7767. var innerDimension = horz ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
  7768. var valueDimension = innerDimension / offsetAmt;
  7769. pixel -= horz ? me.left : me.top;
  7770. if (me.options.gridLines.offsetGridLines) {
  7771. pixel -= (valueDimension / 2);
  7772. }
  7773. pixel -= horz ? me.paddingLeft : me.paddingTop;
  7774. if (pixel <= 0) {
  7775. value = 0;
  7776. } else {
  7777. value = Math.round(pixel / valueDimension);
  7778. }
  7779. return value;
  7780. },
  7781. getBasePixel: function() {
  7782. return this.bottom;
  7783. }
  7784. });
  7785. Chart.scaleService.registerScaleType('category', DatasetScale, defaultConfig);
  7786. };
  7787. },{}],40:[function(require,module,exports){
  7788. 'use strict';
  7789. module.exports = function(Chart) {
  7790. var helpers = Chart.helpers;
  7791. var defaultConfig = {
  7792. position: 'left',
  7793. ticks: {
  7794. callback: function(tickValue, index, ticks) {
  7795. // If we have lots of ticks, don't use the ones
  7796. var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
  7797. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  7798. if (Math.abs(delta) > 1) {
  7799. if (tickValue !== Math.floor(tickValue)) {
  7800. // not an integer
  7801. delta = tickValue - Math.floor(tickValue);
  7802. }
  7803. }
  7804. var logDelta = helpers.log10(Math.abs(delta));
  7805. var tickString = '';
  7806. if (tickValue !== 0) {
  7807. var numDecimal = -1 * Math.floor(logDelta);
  7808. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  7809. tickString = tickValue.toFixed(numDecimal);
  7810. } else {
  7811. tickString = '0'; // never show decimal places for 0
  7812. }
  7813. return tickString;
  7814. }
  7815. }
  7816. };
  7817. var LinearScale = Chart.LinearScaleBase.extend({
  7818. determineDataLimits: function() {
  7819. var me = this;
  7820. var opts = me.options;
  7821. var chart = me.chart;
  7822. var data = chart.data;
  7823. var datasets = data.datasets;
  7824. var isHorizontal = me.isHorizontal();
  7825. function IDMatches(meta) {
  7826. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  7827. }
  7828. // First Calculate the range
  7829. me.min = null;
  7830. me.max = null;
  7831. if (opts.stacked) {
  7832. var valuesPerType = {};
  7833. helpers.each(datasets, function(dataset, datasetIndex) {
  7834. var meta = chart.getDatasetMeta(datasetIndex);
  7835. if (valuesPerType[meta.type] === undefined) {
  7836. valuesPerType[meta.type] = {
  7837. positiveValues: [],
  7838. negativeValues: []
  7839. };
  7840. }
  7841. // Store these per type
  7842. var positiveValues = valuesPerType[meta.type].positiveValues;
  7843. var negativeValues = valuesPerType[meta.type].negativeValues;
  7844. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  7845. helpers.each(dataset.data, function(rawValue, index) {
  7846. var value = +me.getRightValue(rawValue);
  7847. if (isNaN(value) || meta.data[index].hidden) {
  7848. return;
  7849. }
  7850. positiveValues[index] = positiveValues[index] || 0;
  7851. negativeValues[index] = negativeValues[index] || 0;
  7852. if (opts.relativePoints) {
  7853. positiveValues[index] = 100;
  7854. } else if (value < 0) {
  7855. negativeValues[index] += value;
  7856. } else {
  7857. positiveValues[index] += value;
  7858. }
  7859. });
  7860. }
  7861. });
  7862. helpers.each(valuesPerType, function(valuesForType) {
  7863. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  7864. var minVal = helpers.min(values);
  7865. var maxVal = helpers.max(values);
  7866. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  7867. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  7868. });
  7869. } else {
  7870. helpers.each(datasets, function(dataset, datasetIndex) {
  7871. var meta = chart.getDatasetMeta(datasetIndex);
  7872. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  7873. helpers.each(dataset.data, function(rawValue, index) {
  7874. var value = +me.getRightValue(rawValue);
  7875. if (isNaN(value) || meta.data[index].hidden) {
  7876. return;
  7877. }
  7878. if (me.min === null) {
  7879. me.min = value;
  7880. } else if (value < me.min) {
  7881. me.min = value;
  7882. }
  7883. if (me.max === null) {
  7884. me.max = value;
  7885. } else if (value > me.max) {
  7886. me.max = value;
  7887. }
  7888. });
  7889. }
  7890. });
  7891. }
  7892. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  7893. this.handleTickRangeOptions();
  7894. },
  7895. getTickLimit: function() {
  7896. var maxTicks;
  7897. var me = this;
  7898. var tickOpts = me.options.ticks;
  7899. if (me.isHorizontal()) {
  7900. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
  7901. } else {
  7902. // The factor of 2 used to scale the font size has been experimentally determined.
  7903. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, Chart.defaults.global.defaultFontSize);
  7904. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
  7905. }
  7906. return maxTicks;
  7907. },
  7908. // Called after the ticks are built. We need
  7909. handleDirectionalChanges: function() {
  7910. if (!this.isHorizontal()) {
  7911. // We are in a vertical orientation. The top value is the highest. So reverse the array
  7912. this.ticks.reverse();
  7913. }
  7914. },
  7915. getLabelForIndex: function(index, datasetIndex) {
  7916. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  7917. },
  7918. // Utils
  7919. getPixelForValue: function(value) {
  7920. // This must be called after fit has been run so that
  7921. // this.left, this.top, this.right, and this.bottom have been defined
  7922. var me = this;
  7923. var paddingLeft = me.paddingLeft;
  7924. var paddingBottom = me.paddingBottom;
  7925. var start = me.start;
  7926. var rightValue = +me.getRightValue(value);
  7927. var pixel;
  7928. var innerDimension;
  7929. var range = me.end - start;
  7930. if (me.isHorizontal()) {
  7931. innerDimension = me.width - (paddingLeft + me.paddingRight);
  7932. pixel = me.left + (innerDimension / range * (rightValue - start));
  7933. return Math.round(pixel + paddingLeft);
  7934. }
  7935. innerDimension = me.height - (me.paddingTop + paddingBottom);
  7936. pixel = (me.bottom - paddingBottom) - (innerDimension / range * (rightValue - start));
  7937. return Math.round(pixel);
  7938. },
  7939. getValueForPixel: function(pixel) {
  7940. var me = this;
  7941. var isHorizontal = me.isHorizontal();
  7942. var paddingLeft = me.paddingLeft;
  7943. var paddingBottom = me.paddingBottom;
  7944. var innerDimension = isHorizontal ? me.width - (paddingLeft + me.paddingRight) : me.height - (me.paddingTop + paddingBottom);
  7945. var offset = (isHorizontal ? pixel - me.left - paddingLeft : me.bottom - paddingBottom - pixel) / innerDimension;
  7946. return me.start + ((me.end - me.start) * offset);
  7947. },
  7948. getPixelForTick: function(index) {
  7949. return this.getPixelForValue(this.ticksAsNumbers[index]);
  7950. }
  7951. });
  7952. Chart.scaleService.registerScaleType('linear', LinearScale, defaultConfig);
  7953. };
  7954. },{}],41:[function(require,module,exports){
  7955. 'use strict';
  7956. module.exports = function(Chart) {
  7957. var helpers = Chart.helpers,
  7958. noop = helpers.noop;
  7959. Chart.LinearScaleBase = Chart.Scale.extend({
  7960. handleTickRangeOptions: function() {
  7961. var me = this;
  7962. var opts = me.options;
  7963. var tickOpts = opts.ticks;
  7964. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  7965. // do nothing since that would make the chart weird. If the user really wants a weird chart
  7966. // axis, they can manually override it
  7967. if (tickOpts.beginAtZero) {
  7968. var minSign = helpers.sign(me.min);
  7969. var maxSign = helpers.sign(me.max);
  7970. if (minSign < 0 && maxSign < 0) {
  7971. // move the top up to 0
  7972. me.max = 0;
  7973. } else if (minSign > 0 && maxSign > 0) {
  7974. // move the botttom down to 0
  7975. me.min = 0;
  7976. }
  7977. }
  7978. if (tickOpts.min !== undefined) {
  7979. me.min = tickOpts.min;
  7980. } else if (tickOpts.suggestedMin !== undefined) {
  7981. me.min = Math.min(me.min, tickOpts.suggestedMin);
  7982. }
  7983. if (tickOpts.max !== undefined) {
  7984. me.max = tickOpts.max;
  7985. } else if (tickOpts.suggestedMax !== undefined) {
  7986. me.max = Math.max(me.max, tickOpts.suggestedMax);
  7987. }
  7988. if (me.min === me.max) {
  7989. me.max++;
  7990. if (!tickOpts.beginAtZero) {
  7991. me.min--;
  7992. }
  7993. }
  7994. },
  7995. getTickLimit: noop,
  7996. handleDirectionalChanges: noop,
  7997. buildTicks: function() {
  7998. var me = this;
  7999. var opts = me.options;
  8000. var ticks = me.ticks = [];
  8001. var tickOpts = opts.ticks;
  8002. var getValueOrDefault = helpers.getValueOrDefault;
  8003. // Figure out what the max number of ticks we can support it is based on the size of
  8004. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  8005. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  8006. // the graph
  8007. var maxTicks = me.getTickLimit();
  8008. // Make sure we always have at least 2 ticks
  8009. maxTicks = Math.max(2, maxTicks);
  8010. // To get a "nice" value for the tick spacing, we will use the appropriately named
  8011. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  8012. // for details.
  8013. var spacing;
  8014. var fixedStepSizeSet = (tickOpts.fixedStepSize && tickOpts.fixedStepSize > 0) || (tickOpts.stepSize && tickOpts.stepSize > 0);
  8015. if (fixedStepSizeSet) {
  8016. spacing = getValueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize);
  8017. } else {
  8018. var niceRange = helpers.niceNum(me.max - me.min, false);
  8019. spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
  8020. }
  8021. var niceMin = Math.floor(me.min / spacing) * spacing;
  8022. var niceMax = Math.ceil(me.max / spacing) * spacing;
  8023. var numSpaces = (niceMax - niceMin) / spacing;
  8024. // If very close to our rounded value, use it.
  8025. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  8026. numSpaces = Math.round(numSpaces);
  8027. } else {
  8028. numSpaces = Math.ceil(numSpaces);
  8029. }
  8030. // Put the values into the ticks array
  8031. ticks.push(tickOpts.min !== undefined ? tickOpts.min : niceMin);
  8032. for (var j = 1; j < numSpaces; ++j) {
  8033. ticks.push(niceMin + (j * spacing));
  8034. }
  8035. ticks.push(tickOpts.max !== undefined ? tickOpts.max : niceMax);
  8036. me.handleDirectionalChanges();
  8037. // At this point, we need to update our max and min given the tick values since we have expanded the
  8038. // range of the scale
  8039. me.max = helpers.max(ticks);
  8040. me.min = helpers.min(ticks);
  8041. if (tickOpts.reverse) {
  8042. ticks.reverse();
  8043. me.start = me.max;
  8044. me.end = me.min;
  8045. } else {
  8046. me.start = me.min;
  8047. me.end = me.max;
  8048. }
  8049. },
  8050. convertTicksToLabels: function() {
  8051. var me = this;
  8052. me.ticksAsNumbers = me.ticks.slice();
  8053. me.zeroLineIndex = me.ticks.indexOf(0);
  8054. Chart.Scale.prototype.convertTicksToLabels.call(me);
  8055. }
  8056. });
  8057. };
  8058. },{}],42:[function(require,module,exports){
  8059. 'use strict';
  8060. module.exports = function(Chart) {
  8061. var helpers = Chart.helpers;
  8062. var defaultConfig = {
  8063. position: 'left',
  8064. // label settings
  8065. ticks: {
  8066. callback: function(value, index, arr) {
  8067. var remain = value / (Math.pow(10, Math.floor(helpers.log10(value))));
  8068. if (value === 0) {
  8069. return '0';
  8070. } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === arr.length - 1) {
  8071. return value.toExponential();
  8072. }
  8073. return '';
  8074. }
  8075. }
  8076. };
  8077. var LogarithmicScale = Chart.Scale.extend({
  8078. determineDataLimits: function() {
  8079. var me = this;
  8080. var opts = me.options;
  8081. var tickOpts = opts.ticks;
  8082. var chart = me.chart;
  8083. var data = chart.data;
  8084. var datasets = data.datasets;
  8085. var getValueOrDefault = helpers.getValueOrDefault;
  8086. var isHorizontal = me.isHorizontal();
  8087. function IDMatches(meta) {
  8088. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  8089. }
  8090. // Calculate Range
  8091. me.min = null;
  8092. me.max = null;
  8093. me.minNotZero = null;
  8094. if (opts.stacked) {
  8095. var valuesPerType = {};
  8096. helpers.each(datasets, function(dataset, datasetIndex) {
  8097. var meta = chart.getDatasetMeta(datasetIndex);
  8098. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  8099. if (valuesPerType[meta.type] === undefined) {
  8100. valuesPerType[meta.type] = [];
  8101. }
  8102. helpers.each(dataset.data, function(rawValue, index) {
  8103. var values = valuesPerType[meta.type];
  8104. var value = +me.getRightValue(rawValue);
  8105. if (isNaN(value) || meta.data[index].hidden) {
  8106. return;
  8107. }
  8108. values[index] = values[index] || 0;
  8109. if (opts.relativePoints) {
  8110. values[index] = 100;
  8111. } else {
  8112. // Don't need to split positive and negative since the log scale can't handle a 0 crossing
  8113. values[index] += value;
  8114. }
  8115. });
  8116. }
  8117. });
  8118. helpers.each(valuesPerType, function(valuesForType) {
  8119. var minVal = helpers.min(valuesForType);
  8120. var maxVal = helpers.max(valuesForType);
  8121. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  8122. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  8123. });
  8124. } else {
  8125. helpers.each(datasets, function(dataset, datasetIndex) {
  8126. var meta = chart.getDatasetMeta(datasetIndex);
  8127. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  8128. helpers.each(dataset.data, function(rawValue, index) {
  8129. var value = +me.getRightValue(rawValue);
  8130. if (isNaN(value) || meta.data[index].hidden) {
  8131. return;
  8132. }
  8133. if (me.min === null) {
  8134. me.min = value;
  8135. } else if (value < me.min) {
  8136. me.min = value;
  8137. }
  8138. if (me.max === null) {
  8139. me.max = value;
  8140. } else if (value > me.max) {
  8141. me.max = value;
  8142. }
  8143. if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
  8144. me.minNotZero = value;
  8145. }
  8146. });
  8147. }
  8148. });
  8149. }
  8150. me.min = getValueOrDefault(tickOpts.min, me.min);
  8151. me.max = getValueOrDefault(tickOpts.max, me.max);
  8152. if (me.min === me.max) {
  8153. if (me.min !== 0 && me.min !== null) {
  8154. me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
  8155. me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
  8156. } else {
  8157. me.min = 1;
  8158. me.max = 10;
  8159. }
  8160. }
  8161. },
  8162. buildTicks: function() {
  8163. var me = this;
  8164. var opts = me.options;
  8165. var tickOpts = opts.ticks;
  8166. var getValueOrDefault = helpers.getValueOrDefault;
  8167. // Reset the ticks array. Later on, we will draw a grid line at these positions
  8168. // The array simply contains the numerical value of the spots where ticks will be
  8169. var ticks = me.ticks = [];
  8170. // Figure out what the max number of ticks we can support it is based on the size of
  8171. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  8172. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  8173. // the graph
  8174. var tickVal = getValueOrDefault(tickOpts.min, Math.pow(10, Math.floor(helpers.log10(me.min))));
  8175. while (tickVal < me.max) {
  8176. ticks.push(tickVal);
  8177. var exp;
  8178. var significand;
  8179. if (tickVal === 0) {
  8180. exp = Math.floor(helpers.log10(me.minNotZero));
  8181. significand = Math.round(me.minNotZero / Math.pow(10, exp));
  8182. } else {
  8183. exp = Math.floor(helpers.log10(tickVal));
  8184. significand = Math.floor(tickVal / Math.pow(10, exp)) + 1;
  8185. }
  8186. if (significand === 10) {
  8187. significand = 1;
  8188. ++exp;
  8189. }
  8190. tickVal = significand * Math.pow(10, exp);
  8191. }
  8192. var lastTick = getValueOrDefault(tickOpts.max, tickVal);
  8193. ticks.push(lastTick);
  8194. if (!me.isHorizontal()) {
  8195. // We are in a vertical orientation. The top value is the highest. So reverse the array
  8196. ticks.reverse();
  8197. }
  8198. // At this point, we need to update our max and min given the tick values since we have expanded the
  8199. // range of the scale
  8200. me.max = helpers.max(ticks);
  8201. me.min = helpers.min(ticks);
  8202. if (tickOpts.reverse) {
  8203. ticks.reverse();
  8204. me.start = me.max;
  8205. me.end = me.min;
  8206. } else {
  8207. me.start = me.min;
  8208. me.end = me.max;
  8209. }
  8210. },
  8211. convertTicksToLabels: function() {
  8212. this.tickValues = this.ticks.slice();
  8213. Chart.Scale.prototype.convertTicksToLabels.call(this);
  8214. },
  8215. // Get the correct tooltip label
  8216. getLabelForIndex: function(index, datasetIndex) {
  8217. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  8218. },
  8219. getPixelForTick: function(index) {
  8220. return this.getPixelForValue(this.tickValues[index]);
  8221. },
  8222. getPixelForValue: function(value) {
  8223. var me = this;
  8224. var innerDimension;
  8225. var pixel;
  8226. var start = me.start;
  8227. var newVal = +me.getRightValue(value);
  8228. var range;
  8229. var paddingTop = me.paddingTop;
  8230. var paddingBottom = me.paddingBottom;
  8231. var paddingLeft = me.paddingLeft;
  8232. var opts = me.options;
  8233. var tickOpts = opts.ticks;
  8234. if (me.isHorizontal()) {
  8235. range = helpers.log10(me.end) - helpers.log10(start); // todo: if start === 0
  8236. if (newVal === 0) {
  8237. pixel = me.left + paddingLeft;
  8238. } else {
  8239. innerDimension = me.width - (paddingLeft + me.paddingRight);
  8240. pixel = me.left + (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
  8241. pixel += paddingLeft;
  8242. }
  8243. } else {
  8244. // Bottom - top since pixels increase downard on a screen
  8245. innerDimension = me.height - (paddingTop + paddingBottom);
  8246. if (start === 0 && !tickOpts.reverse) {
  8247. range = helpers.log10(me.end) - helpers.log10(me.minNotZero);
  8248. if (newVal === start) {
  8249. pixel = me.bottom - paddingBottom;
  8250. } else if (newVal === me.minNotZero) {
  8251. pixel = me.bottom - paddingBottom - innerDimension * 0.02;
  8252. } else {
  8253. pixel = me.bottom - paddingBottom - innerDimension * 0.02 - (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero)));
  8254. }
  8255. } else if (me.end === 0 && tickOpts.reverse) {
  8256. range = helpers.log10(me.start) - helpers.log10(me.minNotZero);
  8257. if (newVal === me.end) {
  8258. pixel = me.top + paddingTop;
  8259. } else if (newVal === me.minNotZero) {
  8260. pixel = me.top + paddingTop + innerDimension * 0.02;
  8261. } else {
  8262. pixel = me.top + paddingTop + innerDimension * 0.02 + (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero)));
  8263. }
  8264. } else {
  8265. range = helpers.log10(me.end) - helpers.log10(start);
  8266. innerDimension = me.height - (paddingTop + paddingBottom);
  8267. pixel = (me.bottom - paddingBottom) - (innerDimension / range * (helpers.log10(newVal) - helpers.log10(start)));
  8268. }
  8269. }
  8270. return pixel;
  8271. },
  8272. getValueForPixel: function(pixel) {
  8273. var me = this;
  8274. var range = helpers.log10(me.end) - helpers.log10(me.start);
  8275. var value, innerDimension;
  8276. if (me.isHorizontal()) {
  8277. innerDimension = me.width - (me.paddingLeft + me.paddingRight);
  8278. value = me.start * Math.pow(10, (pixel - me.left - me.paddingLeft) * range / innerDimension);
  8279. } else { // todo: if start === 0
  8280. innerDimension = me.height - (me.paddingTop + me.paddingBottom);
  8281. value = Math.pow(10, (me.bottom - me.paddingBottom - pixel) * range / innerDimension) / me.start;
  8282. }
  8283. return value;
  8284. }
  8285. });
  8286. Chart.scaleService.registerScaleType('logarithmic', LogarithmicScale, defaultConfig);
  8287. };
  8288. },{}],43:[function(require,module,exports){
  8289. 'use strict';
  8290. module.exports = function(Chart) {
  8291. var helpers = Chart.helpers;
  8292. var globalDefaults = Chart.defaults.global;
  8293. var defaultConfig = {
  8294. display: true,
  8295. // Boolean - Whether to animate scaling the chart from the centre
  8296. animate: true,
  8297. lineArc: false,
  8298. position: 'chartArea',
  8299. angleLines: {
  8300. display: true,
  8301. color: 'rgba(0, 0, 0, 0.1)',
  8302. lineWidth: 1
  8303. },
  8304. // label settings
  8305. ticks: {
  8306. // Boolean - Show a backdrop to the scale label
  8307. showLabelBackdrop: true,
  8308. // String - The colour of the label backdrop
  8309. backdropColor: 'rgba(255,255,255,0.75)',
  8310. // Number - The backdrop padding above & below the label in pixels
  8311. backdropPaddingY: 2,
  8312. // Number - The backdrop padding to the side of the label in pixels
  8313. backdropPaddingX: 2
  8314. },
  8315. pointLabels: {
  8316. // Number - Point label font size in pixels
  8317. fontSize: 10,
  8318. // Function - Used to convert point labels
  8319. callback: function(label) {
  8320. return label;
  8321. }
  8322. }
  8323. };
  8324. var LinearRadialScale = Chart.LinearScaleBase.extend({
  8325. getValueCount: function() {
  8326. return this.chart.data.labels.length;
  8327. },
  8328. setDimensions: function() {
  8329. var me = this;
  8330. var opts = me.options;
  8331. var tickOpts = opts.ticks;
  8332. // Set the unconstrained dimension before label rotation
  8333. me.width = me.maxWidth;
  8334. me.height = me.maxHeight;
  8335. me.xCenter = Math.round(me.width / 2);
  8336. me.yCenter = Math.round(me.height / 2);
  8337. var minSize = helpers.min([me.height, me.width]);
  8338. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  8339. me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
  8340. },
  8341. determineDataLimits: function() {
  8342. var me = this;
  8343. var chart = me.chart;
  8344. me.min = null;
  8345. me.max = null;
  8346. helpers.each(chart.data.datasets, function(dataset, datasetIndex) {
  8347. if (chart.isDatasetVisible(datasetIndex)) {
  8348. var meta = chart.getDatasetMeta(datasetIndex);
  8349. helpers.each(dataset.data, function(rawValue, index) {
  8350. var value = +me.getRightValue(rawValue);
  8351. if (isNaN(value) || meta.data[index].hidden) {
  8352. return;
  8353. }
  8354. if (me.min === null) {
  8355. me.min = value;
  8356. } else if (value < me.min) {
  8357. me.min = value;
  8358. }
  8359. if (me.max === null) {
  8360. me.max = value;
  8361. } else if (value > me.max) {
  8362. me.max = value;
  8363. }
  8364. });
  8365. }
  8366. });
  8367. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  8368. me.handleTickRangeOptions();
  8369. },
  8370. getTickLimit: function() {
  8371. var tickOpts = this.options.ticks;
  8372. var tickFontSize = helpers.getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  8373. return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  8374. },
  8375. convertTicksToLabels: function() {
  8376. var me = this;
  8377. Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
  8378. // Point labels
  8379. me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
  8380. },
  8381. getLabelForIndex: function(index, datasetIndex) {
  8382. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  8383. },
  8384. fit: function() {
  8385. /*
  8386. * Right, this is really confusing and there is a lot of maths going on here
  8387. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  8388. *
  8389. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  8390. *
  8391. * Solution:
  8392. *
  8393. * We assume the radius of the polygon is half the size of the canvas at first
  8394. * at each index we check if the text overlaps.
  8395. *
  8396. * Where it does, we store that angle and that index.
  8397. *
  8398. * After finding the largest index and angle we calculate how much we need to remove
  8399. * from the shape radius to move the point inwards by that x.
  8400. *
  8401. * We average the left and right distances to get the maximum shape radius that can fit in the box
  8402. * along with labels.
  8403. *
  8404. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  8405. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  8406. *
  8407. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  8408. * and position it in the most space efficient manner
  8409. *
  8410. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  8411. */
  8412. var pointLabels = this.options.pointLabels;
  8413. var pointLabelFontSize = helpers.getValueOrDefault(pointLabels.fontSize, globalDefaults.defaultFontSize);
  8414. var pointLabeFontStyle = helpers.getValueOrDefault(pointLabels.fontStyle, globalDefaults.defaultFontStyle);
  8415. var pointLabeFontFamily = helpers.getValueOrDefault(pointLabels.fontFamily, globalDefaults.defaultFontFamily);
  8416. var pointLabeFont = helpers.fontString(pointLabelFontSize, pointLabeFontStyle, pointLabeFontFamily);
  8417. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  8418. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  8419. var largestPossibleRadius = helpers.min([(this.height / 2 - pointLabelFontSize - 5), this.width / 2]),
  8420. pointPosition,
  8421. i,
  8422. textWidth,
  8423. halfTextWidth,
  8424. furthestRight = this.width,
  8425. furthestRightIndex,
  8426. furthestRightAngle,
  8427. furthestLeft = 0,
  8428. furthestLeftIndex,
  8429. furthestLeftAngle,
  8430. xProtrusionLeft,
  8431. xProtrusionRight,
  8432. radiusReductionRight,
  8433. radiusReductionLeft;
  8434. this.ctx.font = pointLabeFont;
  8435. for (i = 0; i < this.getValueCount(); i++) {
  8436. // 5px to space the text slightly out - similar to what we do in the draw function.
  8437. pointPosition = this.getPointPosition(i, largestPossibleRadius);
  8438. textWidth = this.ctx.measureText(this.pointLabels[i] ? this.pointLabels[i] : '').width + 5;
  8439. // Add quarter circle to make degree 0 mean top of circle
  8440. var angleRadians = this.getIndexAngle(i) + (Math.PI / 2);
  8441. var angle = (angleRadians * 360 / (2 * Math.PI)) % 360;
  8442. if (angle === 0 || angle === 180) {
  8443. // At angle 0 and 180, we're at exactly the top/bottom
  8444. // of the radar chart, so text will be aligned centrally, so we'll half it and compare
  8445. // w/left and right text sizes
  8446. halfTextWidth = textWidth / 2;
  8447. if (pointPosition.x + halfTextWidth > furthestRight) {
  8448. furthestRight = pointPosition.x + halfTextWidth;
  8449. furthestRightIndex = i;
  8450. }
  8451. if (pointPosition.x - halfTextWidth < furthestLeft) {
  8452. furthestLeft = pointPosition.x - halfTextWidth;
  8453. furthestLeftIndex = i;
  8454. }
  8455. } else if (angle < 180) {
  8456. // Less than half the values means we'll left align the text
  8457. if (pointPosition.x + textWidth > furthestRight) {
  8458. furthestRight = pointPosition.x + textWidth;
  8459. furthestRightIndex = i;
  8460. }
  8461. // More than half the values means we'll right align the text
  8462. } else if (pointPosition.x - textWidth < furthestLeft) {
  8463. furthestLeft = pointPosition.x - textWidth;
  8464. furthestLeftIndex = i;
  8465. }
  8466. }
  8467. xProtrusionLeft = furthestLeft;
  8468. xProtrusionRight = Math.ceil(furthestRight - this.width);
  8469. furthestRightAngle = this.getIndexAngle(furthestRightIndex);
  8470. furthestLeftAngle = this.getIndexAngle(furthestLeftIndex);
  8471. radiusReductionRight = xProtrusionRight / Math.sin(furthestRightAngle + Math.PI / 2);
  8472. radiusReductionLeft = xProtrusionLeft / Math.sin(furthestLeftAngle + Math.PI / 2);
  8473. // Ensure we actually need to reduce the size of the chart
  8474. radiusReductionRight = (helpers.isNumber(radiusReductionRight)) ? radiusReductionRight : 0;
  8475. radiusReductionLeft = (helpers.isNumber(radiusReductionLeft)) ? radiusReductionLeft : 0;
  8476. this.drawingArea = Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2);
  8477. this.setCenterPoint(radiusReductionLeft, radiusReductionRight);
  8478. },
  8479. setCenterPoint: function(leftMovement, rightMovement) {
  8480. var me = this;
  8481. var maxRight = me.width - rightMovement - me.drawingArea,
  8482. maxLeft = leftMovement + me.drawingArea;
  8483. me.xCenter = Math.round(((maxLeft + maxRight) / 2) + me.left);
  8484. // Always vertically in the centre as the text height doesn't change
  8485. me.yCenter = Math.round((me.height / 2) + me.top);
  8486. },
  8487. getIndexAngle: function(index) {
  8488. var angleMultiplier = (Math.PI * 2) / this.getValueCount();
  8489. var startAngle = this.chart.options && this.chart.options.startAngle ?
  8490. this.chart.options.startAngle :
  8491. 0;
  8492. var startAngleRadians = startAngle * Math.PI * 2 / 360;
  8493. // Start from the top instead of right, so remove a quarter of the circle
  8494. return index * angleMultiplier - (Math.PI / 2) + startAngleRadians;
  8495. },
  8496. getDistanceFromCenterForValue: function(value) {
  8497. var me = this;
  8498. if (value === null) {
  8499. return 0; // null always in center
  8500. }
  8501. // Take into account half font size + the yPadding of the top value
  8502. var scalingFactor = me.drawingArea / (me.max - me.min);
  8503. if (me.options.reverse) {
  8504. return (me.max - value) * scalingFactor;
  8505. }
  8506. return (value - me.min) * scalingFactor;
  8507. },
  8508. getPointPosition: function(index, distanceFromCenter) {
  8509. var me = this;
  8510. var thisAngle = me.getIndexAngle(index);
  8511. return {
  8512. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
  8513. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
  8514. };
  8515. },
  8516. getPointPositionForValue: function(index, value) {
  8517. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  8518. },
  8519. getBasePosition: function() {
  8520. var me = this;
  8521. var min = me.min;
  8522. var max = me.max;
  8523. return me.getPointPositionForValue(0,
  8524. me.beginAtZero? 0:
  8525. min < 0 && max < 0? max :
  8526. min > 0 && max > 0? min :
  8527. 0);
  8528. },
  8529. draw: function() {
  8530. var me = this;
  8531. var opts = me.options;
  8532. var gridLineOpts = opts.gridLines;
  8533. var tickOpts = opts.ticks;
  8534. var angleLineOpts = opts.angleLines;
  8535. var pointLabelOpts = opts.pointLabels;
  8536. var getValueOrDefault = helpers.getValueOrDefault;
  8537. if (opts.display) {
  8538. var ctx = me.ctx;
  8539. // Tick Font
  8540. var tickFontSize = getValueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  8541. var tickFontStyle = getValueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  8542. var tickFontFamily = getValueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  8543. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  8544. helpers.each(me.ticks, function(label, index) {
  8545. // Don't draw a centre value (if it is minimum)
  8546. if (index > 0 || opts.reverse) {
  8547. var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
  8548. var yHeight = me.yCenter - yCenterOffset;
  8549. // Draw circular lines around the scale
  8550. if (gridLineOpts.display && index !== 0) {
  8551. ctx.strokeStyle = helpers.getValueAtIndexOrDefault(gridLineOpts.color, index - 1);
  8552. ctx.lineWidth = helpers.getValueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
  8553. if (opts.lineArc) {
  8554. // Draw circular arcs between the points
  8555. ctx.beginPath();
  8556. ctx.arc(me.xCenter, me.yCenter, yCenterOffset, 0, Math.PI * 2);
  8557. ctx.closePath();
  8558. ctx.stroke();
  8559. } else {
  8560. // Draw straight lines connecting each index
  8561. ctx.beginPath();
  8562. for (var i = 0; i < me.getValueCount(); i++) {
  8563. var pointPosition = me.getPointPosition(i, yCenterOffset);
  8564. if (i === 0) {
  8565. ctx.moveTo(pointPosition.x, pointPosition.y);
  8566. } else {
  8567. ctx.lineTo(pointPosition.x, pointPosition.y);
  8568. }
  8569. }
  8570. ctx.closePath();
  8571. ctx.stroke();
  8572. }
  8573. }
  8574. if (tickOpts.display) {
  8575. var tickFontColor = getValueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
  8576. ctx.font = tickLabelFont;
  8577. if (tickOpts.showLabelBackdrop) {
  8578. var labelWidth = ctx.measureText(label).width;
  8579. ctx.fillStyle = tickOpts.backdropColor;
  8580. ctx.fillRect(
  8581. me.xCenter - labelWidth / 2 - tickOpts.backdropPaddingX,
  8582. yHeight - tickFontSize / 2 - tickOpts.backdropPaddingY,
  8583. labelWidth + tickOpts.backdropPaddingX * 2,
  8584. tickFontSize + tickOpts.backdropPaddingY * 2
  8585. );
  8586. }
  8587. ctx.textAlign = 'center';
  8588. ctx.textBaseline = 'middle';
  8589. ctx.fillStyle = tickFontColor;
  8590. ctx.fillText(label, me.xCenter, yHeight);
  8591. }
  8592. }
  8593. });
  8594. if (!opts.lineArc) {
  8595. ctx.lineWidth = angleLineOpts.lineWidth;
  8596. ctx.strokeStyle = angleLineOpts.color;
  8597. var outerDistance = me.getDistanceFromCenterForValue(opts.reverse ? me.min : me.max);
  8598. // Point Label Font
  8599. var pointLabelFontSize = getValueOrDefault(pointLabelOpts.fontSize, globalDefaults.defaultFontSize);
  8600. var pointLabeFontStyle = getValueOrDefault(pointLabelOpts.fontStyle, globalDefaults.defaultFontStyle);
  8601. var pointLabeFontFamily = getValueOrDefault(pointLabelOpts.fontFamily, globalDefaults.defaultFontFamily);
  8602. var pointLabeFont = helpers.fontString(pointLabelFontSize, pointLabeFontStyle, pointLabeFontFamily);
  8603. for (var i = me.getValueCount() - 1; i >= 0; i--) {
  8604. if (angleLineOpts.display) {
  8605. var outerPosition = me.getPointPosition(i, outerDistance);
  8606. ctx.beginPath();
  8607. ctx.moveTo(me.xCenter, me.yCenter);
  8608. ctx.lineTo(outerPosition.x, outerPosition.y);
  8609. ctx.stroke();
  8610. ctx.closePath();
  8611. }
  8612. // Extra 3px out for some label spacing
  8613. var pointLabelPosition = me.getPointPosition(i, outerDistance + 5);
  8614. // Keep this in loop since we may support array properties here
  8615. var pointLabelFontColor = getValueOrDefault(pointLabelOpts.fontColor, globalDefaults.defaultFontColor);
  8616. ctx.font = pointLabeFont;
  8617. ctx.fillStyle = pointLabelFontColor;
  8618. var pointLabels = me.pointLabels;
  8619. // Add quarter circle to make degree 0 mean top of circle
  8620. var angleRadians = this.getIndexAngle(i) + (Math.PI / 2);
  8621. var angle = (angleRadians * 360 / (2 * Math.PI)) % 360;
  8622. if (angle === 0 || angle === 180) {
  8623. ctx.textAlign = 'center';
  8624. } else if (angle < 180) {
  8625. ctx.textAlign = 'left';
  8626. } else {
  8627. ctx.textAlign = 'right';
  8628. }
  8629. // Set the correct text baseline based on outer positioning
  8630. if (angle === 90 || angle === 270) {
  8631. ctx.textBaseline = 'middle';
  8632. } else if (angle > 270 || angle < 90) {
  8633. ctx.textBaseline = 'bottom';
  8634. } else {
  8635. ctx.textBaseline = 'top';
  8636. }
  8637. ctx.fillText(pointLabels[i] ? pointLabels[i] : '', pointLabelPosition.x, pointLabelPosition.y);
  8638. }
  8639. }
  8640. }
  8641. }
  8642. });
  8643. Chart.scaleService.registerScaleType('radialLinear', LinearRadialScale, defaultConfig);
  8644. };
  8645. },{}],44:[function(require,module,exports){
  8646. /* global window: false */
  8647. 'use strict';
  8648. var moment = require(1);
  8649. moment = typeof(moment) === 'function' ? moment : window.moment;
  8650. module.exports = function(Chart) {
  8651. var helpers = Chart.helpers;
  8652. var time = {
  8653. units: [{
  8654. name: 'millisecond',
  8655. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  8656. }, {
  8657. name: 'second',
  8658. steps: [1, 2, 5, 10, 30]
  8659. }, {
  8660. name: 'minute',
  8661. steps: [1, 2, 5, 10, 30]
  8662. }, {
  8663. name: 'hour',
  8664. steps: [1, 2, 3, 6, 12]
  8665. }, {
  8666. name: 'day',
  8667. steps: [1, 2, 5]
  8668. }, {
  8669. name: 'week',
  8670. maxStep: 4
  8671. }, {
  8672. name: 'month',
  8673. maxStep: 3
  8674. }, {
  8675. name: 'quarter',
  8676. maxStep: 4
  8677. }, {
  8678. name: 'year',
  8679. maxStep: false
  8680. }]
  8681. };
  8682. var defaultConfig = {
  8683. position: 'bottom',
  8684. time: {
  8685. 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
  8686. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  8687. unit: false, // false == automatic or override with week, month, year, etc.
  8688. round: false, // none, or override with week, month, year, etc.
  8689. displayFormat: false, // DEPRECATED
  8690. isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
  8691. minUnit: 'millisecond',
  8692. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  8693. displayFormats: {
  8694. millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  8695. second: 'h:mm:ss a', // 11:20:01 AM
  8696. minute: 'h:mm:ss a', // 11:20:01 AM
  8697. hour: 'MMM D, hA', // Sept 4, 5PM
  8698. day: 'll', // Sep 4 2015
  8699. week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  8700. month: 'MMM YYYY', // Sept 2015
  8701. quarter: '[Q]Q - YYYY', // Q3
  8702. year: 'YYYY' // 2015
  8703. }
  8704. },
  8705. ticks: {
  8706. autoSkip: false
  8707. }
  8708. };
  8709. var TimeScale = Chart.Scale.extend({
  8710. initialize: function() {
  8711. if (!moment) {
  8712. 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');
  8713. }
  8714. Chart.Scale.prototype.initialize.call(this);
  8715. },
  8716. getLabelMoment: function(datasetIndex, index) {
  8717. if (datasetIndex === null || index === null) {
  8718. return null;
  8719. }
  8720. if (typeof this.labelMoments[datasetIndex] !== 'undefined') {
  8721. return this.labelMoments[datasetIndex][index];
  8722. }
  8723. return null;
  8724. },
  8725. getLabelDiff: function(datasetIndex, index) {
  8726. var me = this;
  8727. if (datasetIndex === null || index === null) {
  8728. return null;
  8729. }
  8730. if (me.labelDiffs === undefined) {
  8731. me.buildLabelDiffs();
  8732. }
  8733. if (typeof me.labelDiffs[datasetIndex] !== 'undefined') {
  8734. return me.labelDiffs[datasetIndex][index];
  8735. }
  8736. return null;
  8737. },
  8738. getMomentStartOf: function(tick) {
  8739. var me = this;
  8740. if (me.options.time.unit === 'week' && me.options.time.isoWeekday !== false) {
  8741. return tick.clone().startOf('isoWeek').isoWeekday(me.options.time.isoWeekday);
  8742. }
  8743. return tick.clone().startOf(me.tickUnit);
  8744. },
  8745. determineDataLimits: function() {
  8746. var me = this;
  8747. me.labelMoments = [];
  8748. // Only parse these once. If the dataset does not have data as x,y pairs, we will use
  8749. // these
  8750. var scaleLabelMoments = [];
  8751. if (me.chart.data.labels && me.chart.data.labels.length > 0) {
  8752. helpers.each(me.chart.data.labels, function(label) {
  8753. var labelMoment = me.parseTime(label);
  8754. if (labelMoment.isValid()) {
  8755. if (me.options.time.round) {
  8756. labelMoment.startOf(me.options.time.round);
  8757. }
  8758. scaleLabelMoments.push(labelMoment);
  8759. }
  8760. }, me);
  8761. me.firstTick = moment.min.call(me, scaleLabelMoments);
  8762. me.lastTick = moment.max.call(me, scaleLabelMoments);
  8763. } else {
  8764. me.firstTick = null;
  8765. me.lastTick = null;
  8766. }
  8767. helpers.each(me.chart.data.datasets, function(dataset, datasetIndex) {
  8768. var momentsForDataset = [];
  8769. var datasetVisible = me.chart.isDatasetVisible(datasetIndex);
  8770. if (typeof dataset.data[0] === 'object' && dataset.data[0] !== null) {
  8771. helpers.each(dataset.data, function(value) {
  8772. var labelMoment = me.parseTime(me.getRightValue(value));
  8773. if (labelMoment.isValid()) {
  8774. if (me.options.time.round) {
  8775. labelMoment.startOf(me.options.time.round);
  8776. }
  8777. momentsForDataset.push(labelMoment);
  8778. if (datasetVisible) {
  8779. // May have gone outside the scale ranges, make sure we keep the first and last ticks updated
  8780. me.firstTick = me.firstTick !== null ? moment.min(me.firstTick, labelMoment) : labelMoment;
  8781. me.lastTick = me.lastTick !== null ? moment.max(me.lastTick, labelMoment) : labelMoment;
  8782. }
  8783. }
  8784. }, me);
  8785. } else {
  8786. // We have no labels. Use the ones from the scale
  8787. momentsForDataset = scaleLabelMoments;
  8788. }
  8789. me.labelMoments.push(momentsForDataset);
  8790. }, me);
  8791. // Set these after we've done all the data
  8792. if (me.options.time.min) {
  8793. me.firstTick = me.parseTime(me.options.time.min);
  8794. }
  8795. if (me.options.time.max) {
  8796. me.lastTick = me.parseTime(me.options.time.max);
  8797. }
  8798. // We will modify these, so clone for later
  8799. me.firstTick = (me.firstTick || moment()).clone();
  8800. me.lastTick = (me.lastTick || moment()).clone();
  8801. },
  8802. buildLabelDiffs: function() {
  8803. var me = this;
  8804. me.labelDiffs = [];
  8805. var scaleLabelDiffs = [];
  8806. // Parse common labels once
  8807. if (me.chart.data.labels && me.chart.data.labels.length > 0) {
  8808. helpers.each(me.chart.data.labels, function(label) {
  8809. var labelMoment = me.parseTime(label);
  8810. if (labelMoment.isValid()) {
  8811. if (me.options.time.round) {
  8812. labelMoment.startOf(me.options.time.round);
  8813. }
  8814. scaleLabelDiffs.push(labelMoment.diff(me.firstTick, me.tickUnit, true));
  8815. }
  8816. }, me);
  8817. }
  8818. helpers.each(me.chart.data.datasets, function(dataset) {
  8819. var diffsForDataset = [];
  8820. if (typeof dataset.data[0] === 'object' && dataset.data[0] !== null) {
  8821. helpers.each(dataset.data, function(value) {
  8822. var labelMoment = me.parseTime(me.getRightValue(value));
  8823. if (labelMoment.isValid()) {
  8824. if (me.options.time.round) {
  8825. labelMoment.startOf(me.options.time.round);
  8826. }
  8827. diffsForDataset.push(labelMoment.diff(me.firstTick, me.tickUnit, true));
  8828. }
  8829. }, me);
  8830. } else {
  8831. // We have no labels. Use common ones
  8832. diffsForDataset = scaleLabelDiffs;
  8833. }
  8834. me.labelDiffs.push(diffsForDataset);
  8835. }, me);
  8836. },
  8837. buildTicks: function() {
  8838. var me = this;
  8839. me.ctx.save();
  8840. var tickFontSize = helpers.getValueOrDefault(me.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
  8841. var tickFontStyle = helpers.getValueOrDefault(me.options.ticks.fontStyle, Chart.defaults.global.defaultFontStyle);
  8842. var tickFontFamily = helpers.getValueOrDefault(me.options.ticks.fontFamily, Chart.defaults.global.defaultFontFamily);
  8843. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  8844. me.ctx.font = tickLabelFont;
  8845. me.ticks = [];
  8846. me.unitScale = 1; // How much we scale the unit by, ie 2 means 2x unit per step
  8847. me.scaleSizeInUnits = 0; // How large the scale is in the base unit (seconds, minutes, etc)
  8848. // Set unit override if applicable
  8849. if (me.options.time.unit) {
  8850. me.tickUnit = me.options.time.unit || 'day';
  8851. me.displayFormat = me.options.time.displayFormats[me.tickUnit];
  8852. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  8853. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, 1);
  8854. } else {
  8855. // Determine the smallest needed unit of the time
  8856. var innerWidth = me.isHorizontal() ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
  8857. // Crude approximation of what the label length might be
  8858. var tempFirstLabel = me.tickFormatFunction(me.firstTick, 0, []);
  8859. var tickLabelWidth = me.ctx.measureText(tempFirstLabel).width;
  8860. var cosRotation = Math.cos(helpers.toRadians(me.options.ticks.maxRotation));
  8861. var sinRotation = Math.sin(helpers.toRadians(me.options.ticks.maxRotation));
  8862. tickLabelWidth = (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  8863. var labelCapacity = innerWidth / (tickLabelWidth);
  8864. // Start as small as possible
  8865. me.tickUnit = me.options.time.minUnit;
  8866. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  8867. me.displayFormat = me.options.time.displayFormats[me.tickUnit];
  8868. var unitDefinitionIndex = 0;
  8869. var unitDefinition = time.units[unitDefinitionIndex];
  8870. // While we aren't ideal and we don't have units left
  8871. while (unitDefinitionIndex < time.units.length) {
  8872. // Can we scale this unit. If `false` we can scale infinitely
  8873. me.unitScale = 1;
  8874. if (helpers.isArray(unitDefinition.steps) && Math.ceil(me.scaleSizeInUnits / labelCapacity) < helpers.max(unitDefinition.steps)) {
  8875. // Use one of the prefedined steps
  8876. for (var idx = 0; idx < unitDefinition.steps.length; ++idx) {
  8877. if (unitDefinition.steps[idx] >= Math.ceil(me.scaleSizeInUnits / labelCapacity)) {
  8878. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, unitDefinition.steps[idx]);
  8879. break;
  8880. }
  8881. }
  8882. break;
  8883. } else if ((unitDefinition.maxStep === false) || (Math.ceil(me.scaleSizeInUnits / labelCapacity) < unitDefinition.maxStep)) {
  8884. // We have a max step. Scale this unit
  8885. me.unitScale = helpers.getValueOrDefault(me.options.time.unitStepSize, Math.ceil(me.scaleSizeInUnits / labelCapacity));
  8886. break;
  8887. } else {
  8888. // Move to the next unit up
  8889. ++unitDefinitionIndex;
  8890. unitDefinition = time.units[unitDefinitionIndex];
  8891. me.tickUnit = unitDefinition.name;
  8892. var leadingUnitBuffer = me.firstTick.diff(me.getMomentStartOf(me.firstTick), me.tickUnit, true);
  8893. var trailingUnitBuffer = me.getMomentStartOf(me.lastTick.clone().add(1, me.tickUnit)).diff(me.lastTick, me.tickUnit, true);
  8894. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true) + leadingUnitBuffer + trailingUnitBuffer;
  8895. me.displayFormat = me.options.time.displayFormats[unitDefinition.name];
  8896. }
  8897. }
  8898. }
  8899. var roundedStart;
  8900. // Only round the first tick if we have no hard minimum
  8901. if (!me.options.time.min) {
  8902. me.firstTick = me.getMomentStartOf(me.firstTick);
  8903. roundedStart = me.firstTick;
  8904. } else {
  8905. roundedStart = me.getMomentStartOf(me.firstTick);
  8906. }
  8907. // Only round the last tick if we have no hard maximum
  8908. if (!me.options.time.max) {
  8909. var roundedEnd = me.getMomentStartOf(me.lastTick);
  8910. var delta = roundedEnd.diff(me.lastTick, me.tickUnit, true);
  8911. if (delta < 0) {
  8912. // Do not use end of because we need me to be in the next time unit
  8913. me.lastTick = me.getMomentStartOf(me.lastTick.add(1, me.tickUnit));
  8914. } else if (delta >= 0) {
  8915. me.lastTick = roundedEnd;
  8916. }
  8917. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  8918. }
  8919. // Tick displayFormat override
  8920. if (me.options.time.displayFormat) {
  8921. me.displayFormat = me.options.time.displayFormat;
  8922. }
  8923. // first tick. will have been rounded correctly if options.time.min is not specified
  8924. me.ticks.push(me.firstTick.clone());
  8925. // For every unit in between the first and last moment, create a moment and add it to the ticks tick
  8926. for (var i = 1; i <= me.scaleSizeInUnits; ++i) {
  8927. var newTick = roundedStart.clone().add(i, me.tickUnit);
  8928. // Are we greater than the max time
  8929. if (me.options.time.max && newTick.diff(me.lastTick, me.tickUnit, true) >= 0) {
  8930. break;
  8931. }
  8932. if (i % me.unitScale === 0) {
  8933. me.ticks.push(newTick);
  8934. }
  8935. }
  8936. // Always show the right tick
  8937. var diff = me.ticks[me.ticks.length - 1].diff(me.lastTick, me.tickUnit);
  8938. if (diff !== 0 || me.scaleSizeInUnits === 0) {
  8939. // 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
  8940. // but the last tick was not rounded.
  8941. if (me.options.time.max) {
  8942. me.ticks.push(me.lastTick.clone());
  8943. me.scaleSizeInUnits = me.lastTick.diff(me.ticks[0], me.tickUnit, true);
  8944. } else {
  8945. me.ticks.push(me.lastTick.clone());
  8946. me.scaleSizeInUnits = me.lastTick.diff(me.firstTick, me.tickUnit, true);
  8947. }
  8948. }
  8949. me.ctx.restore();
  8950. // Invalidate label diffs cache
  8951. me.labelDiffs = undefined;
  8952. },
  8953. // Get tooltip label
  8954. getLabelForIndex: function(index, datasetIndex) {
  8955. var me = this;
  8956. var label = me.chart.data.labels && index < me.chart.data.labels.length ? me.chart.data.labels[index] : '';
  8957. if (typeof me.chart.data.datasets[datasetIndex].data[0] === 'object') {
  8958. label = me.getRightValue(me.chart.data.datasets[datasetIndex].data[index]);
  8959. }
  8960. // Format nicely
  8961. if (me.options.time.tooltipFormat) {
  8962. label = me.parseTime(label).format(me.options.time.tooltipFormat);
  8963. }
  8964. return label;
  8965. },
  8966. // Function to format an individual tick mark
  8967. tickFormatFunction: function(tick, index, ticks) {
  8968. var formattedTick = tick.format(this.displayFormat);
  8969. var tickOpts = this.options.ticks;
  8970. var callback = helpers.getValueOrDefault(tickOpts.callback, tickOpts.userCallback);
  8971. if (callback) {
  8972. return callback(formattedTick, index, ticks);
  8973. }
  8974. return formattedTick;
  8975. },
  8976. convertTicksToLabels: function() {
  8977. var me = this;
  8978. me.tickMoments = me.ticks;
  8979. me.ticks = me.ticks.map(me.tickFormatFunction, me);
  8980. },
  8981. getPixelForValue: function(value, index, datasetIndex) {
  8982. var me = this;
  8983. var offset = null;
  8984. if (index !== undefined && datasetIndex !== undefined) {
  8985. offset = me.getLabelDiff(datasetIndex, index);
  8986. }
  8987. if (offset === null) {
  8988. if (!value || !value.isValid) {
  8989. // not already a moment object
  8990. value = me.parseTime(me.getRightValue(value));
  8991. }
  8992. if (value && value.isValid && value.isValid()) {
  8993. offset = value.diff(me.firstTick, me.tickUnit, true);
  8994. }
  8995. }
  8996. if (offset !== null) {
  8997. var decimal = offset !== 0 ? offset / me.scaleSizeInUnits : offset;
  8998. if (me.isHorizontal()) {
  8999. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  9000. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  9001. return me.left + Math.round(valueOffset);
  9002. }
  9003. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  9004. var heightOffset = (innerHeight * decimal) + me.paddingTop;
  9005. return me.top + Math.round(heightOffset);
  9006. }
  9007. },
  9008. getPixelForTick: function(index) {
  9009. return this.getPixelForValue(this.tickMoments[index], null, null);
  9010. },
  9011. getValueForPixel: function(pixel) {
  9012. var me = this;
  9013. var innerDimension = me.isHorizontal() ? me.width - (me.paddingLeft + me.paddingRight) : me.height - (me.paddingTop + me.paddingBottom);
  9014. var offset = (pixel - (me.isHorizontal() ? me.left + me.paddingLeft : me.top + me.paddingTop)) / innerDimension;
  9015. offset *= me.scaleSizeInUnits;
  9016. return me.firstTick.clone().add(moment.duration(offset, me.tickUnit).asSeconds(), 'seconds');
  9017. },
  9018. parseTime: function(label) {
  9019. var me = this;
  9020. if (typeof me.options.time.parser === 'string') {
  9021. return moment(label, me.options.time.parser);
  9022. }
  9023. if (typeof me.options.time.parser === 'function') {
  9024. return me.options.time.parser(label);
  9025. }
  9026. // Date objects
  9027. if (typeof label.getMonth === 'function' || typeof label === 'number') {
  9028. return moment(label);
  9029. }
  9030. // Moment support
  9031. if (label.isValid && label.isValid()) {
  9032. return label;
  9033. }
  9034. // Custom parsing (return an instance of moment)
  9035. if (typeof me.options.time.format !== 'string' && me.options.time.format.call) {
  9036. 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');
  9037. return me.options.time.format(label);
  9038. }
  9039. // Moment format parsing
  9040. return moment(label, me.options.time.format);
  9041. }
  9042. });
  9043. Chart.scaleService.registerScaleType('time', TimeScale, defaultConfig);
  9044. };
  9045. },{"1":1}]},{},[7])(7)
  9046. });