chart.js 307 KB

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