Chart.js 493 KB

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