chart.min.js 672 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448
  1. /*!
  2. * Chart.js
  3. * http://chartjs.org/
  4. * Version: 2.7.2
  5. *
  6. * Copyright 2018 Chart.js Contributors
  7. * Released under the MIT license
  8. * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md
  9. */
  10. (function (f) {
  11. if (typeof exports === "object" && typeof module !== "undefined") {
  12. module.exports = f()
  13. } else if (typeof define === "function" && define.amd) {
  14. define([], f)
  15. } else {
  16. var g;
  17. if (typeof window !== "undefined") {
  18. g = window
  19. } else if (typeof global !== "undefined") {
  20. g = global
  21. } else if (typeof self !== "undefined") {
  22. g = self
  23. } else {
  24. g = this
  25. }
  26. g.Chart = f()
  27. }
  28. })(function () {
  29. var define, module, exports;
  30. return (function () {
  31. function e(t, n, r) {
  32. function s(o, u) {
  33. if (!n[o]) {
  34. if (!t[o]) {
  35. var a = typeof require == "function" && require;
  36. if (!u && a)
  37. return a(o, !0);
  38. if (i)
  39. return i(o, !0);
  40. var f = new Error("Cannot find module '" + o + "'");
  41. throw f.code = "MODULE_NOT_FOUND", f
  42. }
  43. var l = n[o] = {exports: {}};
  44. t[o][0].call(l.exports, function (e) {
  45. var n = t[o][1][e];
  46. return s(n ? n : e)
  47. }, l, l.exports, e, t, n, r)
  48. }
  49. return n[o].exports
  50. }
  51. var i = typeof require == "function" && require;
  52. for (var o = 0; o < r.length; o++)
  53. s(r[o]);
  54. return s
  55. }
  56. return e
  57. })()({1: [function (require, module, exports) {
  58. }, {}], 2: [function (require, module, exports) {
  59. /* MIT license */
  60. var colorNames = require(6);
  61. module.exports = {
  62. getRgba: getRgba,
  63. getHsla: getHsla,
  64. getRgb: getRgb,
  65. getHsl: getHsl,
  66. getHwb: getHwb,
  67. getAlpha: getAlpha,
  68. hexString: hexString,
  69. rgbString: rgbString,
  70. rgbaString: rgbaString,
  71. percentString: percentString,
  72. percentaString: percentaString,
  73. hslString: hslString,
  74. hslaString: hslaString,
  75. hwbString: hwbString,
  76. keyword: keyword
  77. }
  78. function getRgba(string) {
  79. if (!string) {
  80. return;
  81. }
  82. var abbr = /^#([a-fA-F0-9]{3})$/i,
  83. hex = /^#([a-fA-F0-9]{6})$/i,
  84. rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  85. per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/i,
  86. keyword = /(\w+)/;
  87. var rgb = [0, 0, 0],
  88. a = 1,
  89. match = string.match(abbr);
  90. if (match) {
  91. match = match[1];
  92. for (var i = 0; i < rgb.length; i++) {
  93. rgb[i] = parseInt(match[i] + match[i], 16);
  94. }
  95. } else if (match = string.match(hex)) {
  96. match = match[1];
  97. for (var i = 0; i < rgb.length; i++) {
  98. rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
  99. }
  100. } else if (match = string.match(rgba)) {
  101. for (var i = 0; i < rgb.length; i++) {
  102. rgb[i] = parseInt(match[i + 1]);
  103. }
  104. a = parseFloat(match[4]);
  105. } else if (match = string.match(per)) {
  106. for (var i = 0; i < rgb.length; i++) {
  107. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  108. }
  109. a = parseFloat(match[4]);
  110. } else if (match = string.match(keyword)) {
  111. if (match[1] == "transparent") {
  112. return [0, 0, 0, 0];
  113. }
  114. rgb = colorNames[match[1]];
  115. if (!rgb) {
  116. return;
  117. }
  118. }
  119. for (var i = 0; i < rgb.length; i++) {
  120. rgb[i] = scale(rgb[i], 0, 255);
  121. }
  122. if (!a && a != 0) {
  123. a = 1;
  124. } else {
  125. a = scale(a, 0, 1);
  126. }
  127. rgb[3] = a;
  128. return rgb;
  129. }
  130. function getHsla(string) {
  131. if (!string) {
  132. return;
  133. }
  134. var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  135. var match = string.match(hsl);
  136. if (match) {
  137. var alpha = parseFloat(match[4]);
  138. var h = scale(parseInt(match[1]), 0, 360),
  139. s = scale(parseFloat(match[2]), 0, 100),
  140. l = scale(parseFloat(match[3]), 0, 100),
  141. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  142. return [h, s, l, a];
  143. }
  144. }
  145. function getHwb(string) {
  146. if (!string) {
  147. return;
  148. }
  149. var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  150. var match = string.match(hwb);
  151. if (match) {
  152. var alpha = parseFloat(match[4]);
  153. var h = scale(parseInt(match[1]), 0, 360),
  154. w = scale(parseFloat(match[2]), 0, 100),
  155. b = scale(parseFloat(match[3]), 0, 100),
  156. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  157. return [h, w, b, a];
  158. }
  159. }
  160. function getRgb(string) {
  161. var rgba = getRgba(string);
  162. return rgba && rgba.slice(0, 3);
  163. }
  164. function getHsl(string) {
  165. var hsla = getHsla(string);
  166. return hsla && hsla.slice(0, 3);
  167. }
  168. function getAlpha(string) {
  169. var vals = getRgba(string);
  170. if (vals) {
  171. return vals[3];
  172. } else if (vals = getHsla(string)) {
  173. return vals[3];
  174. } else if (vals = getHwb(string)) {
  175. return vals[3];
  176. }
  177. }
  178. // generators
  179. function hexString(rgb) {
  180. return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
  181. + hexDouble(rgb[2]);
  182. }
  183. function rgbString(rgba, alpha) {
  184. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  185. return rgbaString(rgba, alpha);
  186. }
  187. return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
  188. }
  189. function rgbaString(rgba, alpha) {
  190. if (alpha === undefined) {
  191. alpha = (rgba[3] !== undefined ? rgba[3] : 1);
  192. }
  193. return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
  194. + ", " + alpha + ")";
  195. }
  196. function percentString(rgba, alpha) {
  197. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  198. return percentaString(rgba, alpha);
  199. }
  200. var r = Math.round(rgba[0] / 255 * 100),
  201. g = Math.round(rgba[1] / 255 * 100),
  202. b = Math.round(rgba[2] / 255 * 100);
  203. return "rgb(" + r + "%, " + g + "%, " + b + "%)";
  204. }
  205. function percentaString(rgba, alpha) {
  206. var r = Math.round(rgba[0] / 255 * 100),
  207. g = Math.round(rgba[1] / 255 * 100),
  208. b = Math.round(rgba[2] / 255 * 100);
  209. return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
  210. }
  211. function hslString(hsla, alpha) {
  212. if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
  213. return hslaString(hsla, alpha);
  214. }
  215. return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
  216. }
  217. function hslaString(hsla, alpha) {
  218. if (alpha === undefined) {
  219. alpha = (hsla[3] !== undefined ? hsla[3] : 1);
  220. }
  221. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
  222. + alpha + ")";
  223. }
  224. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  225. // (hwb have alpha optional & 1 is default value)
  226. function hwbString(hwb, alpha) {
  227. if (alpha === undefined) {
  228. alpha = (hwb[3] !== undefined ? hwb[3] : 1);
  229. }
  230. return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
  231. + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
  232. }
  233. function keyword(rgb) {
  234. return reverseNames[rgb.slice(0, 3)];
  235. }
  236. // helpers
  237. function scale(num, min, max) {
  238. return Math.min(Math.max(min, num), max);
  239. }
  240. function hexDouble(num) {
  241. var str = num.toString(16).toUpperCase();
  242. return (str.length < 2) ? "0" + str : str;
  243. }
  244. //create a list of reverse color names
  245. var reverseNames = {};
  246. for (var name in colorNames) {
  247. reverseNames[colorNames[name]] = name;
  248. }
  249. }, {"6": 6}], 3: [function (require, module, exports) {
  250. /* MIT license */
  251. var convert = require(5);
  252. var string = require(2);
  253. var Color = function (obj) {
  254. if (obj instanceof Color) {
  255. return obj;
  256. }
  257. if (!(this instanceof Color)) {
  258. return new Color(obj);
  259. }
  260. this.valid = false;
  261. this.values = {
  262. rgb: [0, 0, 0],
  263. hsl: [0, 0, 0],
  264. hsv: [0, 0, 0],
  265. hwb: [0, 0, 0],
  266. cmyk: [0, 0, 0, 0],
  267. alpha: 1
  268. };
  269. // parse Color() argument
  270. var vals;
  271. if (typeof obj === 'string') {
  272. vals = string.getRgba(obj);
  273. if (vals) {
  274. this.setValues('rgb', vals);
  275. } else if (vals = string.getHsla(obj)) {
  276. this.setValues('hsl', vals);
  277. } else if (vals = string.getHwb(obj)) {
  278. this.setValues('hwb', vals);
  279. }
  280. } else if (typeof obj === 'object') {
  281. vals = obj;
  282. if (vals.r !== undefined || vals.red !== undefined) {
  283. this.setValues('rgb', vals);
  284. } else if (vals.l !== undefined || vals.lightness !== undefined) {
  285. this.setValues('hsl', vals);
  286. } else if (vals.v !== undefined || vals.value !== undefined) {
  287. this.setValues('hsv', vals);
  288. } else if (vals.w !== undefined || vals.whiteness !== undefined) {
  289. this.setValues('hwb', vals);
  290. } else if (vals.c !== undefined || vals.cyan !== undefined) {
  291. this.setValues('cmyk', vals);
  292. }
  293. }
  294. };
  295. Color.prototype = {
  296. isValid: function () {
  297. return this.valid;
  298. },
  299. rgb: function () {
  300. return this.setSpace('rgb', arguments);
  301. },
  302. hsl: function () {
  303. return this.setSpace('hsl', arguments);
  304. },
  305. hsv: function () {
  306. return this.setSpace('hsv', arguments);
  307. },
  308. hwb: function () {
  309. return this.setSpace('hwb', arguments);
  310. },
  311. cmyk: function () {
  312. return this.setSpace('cmyk', arguments);
  313. },
  314. rgbArray: function () {
  315. return this.values.rgb;
  316. },
  317. hslArray: function () {
  318. return this.values.hsl;
  319. },
  320. hsvArray: function () {
  321. return this.values.hsv;
  322. },
  323. hwbArray: function () {
  324. var values = this.values;
  325. if (values.alpha !== 1) {
  326. return values.hwb.concat([values.alpha]);
  327. }
  328. return values.hwb;
  329. },
  330. cmykArray: function () {
  331. return this.values.cmyk;
  332. },
  333. rgbaArray: function () {
  334. var values = this.values;
  335. return values.rgb.concat([values.alpha]);
  336. },
  337. hslaArray: function () {
  338. var values = this.values;
  339. return values.hsl.concat([values.alpha]);
  340. },
  341. alpha: function (val) {
  342. if (val === undefined) {
  343. return this.values.alpha;
  344. }
  345. this.setValues('alpha', val);
  346. return this;
  347. },
  348. red: function (val) {
  349. return this.setChannel('rgb', 0, val);
  350. },
  351. green: function (val) {
  352. return this.setChannel('rgb', 1, val);
  353. },
  354. blue: function (val) {
  355. return this.setChannel('rgb', 2, val);
  356. },
  357. hue: function (val) {
  358. if (val) {
  359. val %= 360;
  360. val = val < 0 ? 360 + val : val;
  361. }
  362. return this.setChannel('hsl', 0, val);
  363. },
  364. saturation: function (val) {
  365. return this.setChannel('hsl', 1, val);
  366. },
  367. lightness: function (val) {
  368. return this.setChannel('hsl', 2, val);
  369. },
  370. saturationv: function (val) {
  371. return this.setChannel('hsv', 1, val);
  372. },
  373. whiteness: function (val) {
  374. return this.setChannel('hwb', 1, val);
  375. },
  376. blackness: function (val) {
  377. return this.setChannel('hwb', 2, val);
  378. },
  379. value: function (val) {
  380. return this.setChannel('hsv', 2, val);
  381. },
  382. cyan: function (val) {
  383. return this.setChannel('cmyk', 0, val);
  384. },
  385. magenta: function (val) {
  386. return this.setChannel('cmyk', 1, val);
  387. },
  388. yellow: function (val) {
  389. return this.setChannel('cmyk', 2, val);
  390. },
  391. black: function (val) {
  392. return this.setChannel('cmyk', 3, val);
  393. },
  394. hexString: function () {
  395. return string.hexString(this.values.rgb);
  396. },
  397. rgbString: function () {
  398. return string.rgbString(this.values.rgb, this.values.alpha);
  399. },
  400. rgbaString: function () {
  401. return string.rgbaString(this.values.rgb, this.values.alpha);
  402. },
  403. percentString: function () {
  404. return string.percentString(this.values.rgb, this.values.alpha);
  405. },
  406. hslString: function () {
  407. return string.hslString(this.values.hsl, this.values.alpha);
  408. },
  409. hslaString: function () {
  410. return string.hslaString(this.values.hsl, this.values.alpha);
  411. },
  412. hwbString: function () {
  413. return string.hwbString(this.values.hwb, this.values.alpha);
  414. },
  415. keyword: function () {
  416. return string.keyword(this.values.rgb, this.values.alpha);
  417. },
  418. rgbNumber: function () {
  419. var rgb = this.values.rgb;
  420. return (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
  421. },
  422. luminosity: function () {
  423. // http://www.w3.org/TR/WCAG20/#relativeluminancedef
  424. var rgb = this.values.rgb;
  425. var lum = [];
  426. for (var i = 0; i < rgb.length; i++) {
  427. var chan = rgb[i] / 255;
  428. lum[i] = (chan <= 0.03928) ? chan / 12.92 : Math.pow(((chan + 0.055) / 1.055), 2.4);
  429. }
  430. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  431. },
  432. contrast: function (color2) {
  433. // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  434. var lum1 = this.luminosity();
  435. var lum2 = color2.luminosity();
  436. if (lum1 > lum2) {
  437. return (lum1 + 0.05) / (lum2 + 0.05);
  438. }
  439. return (lum2 + 0.05) / (lum1 + 0.05);
  440. },
  441. level: function (color2) {
  442. var contrastRatio = this.contrast(color2);
  443. if (contrastRatio >= 7.1) {
  444. return 'AAA';
  445. }
  446. return (contrastRatio >= 4.5) ? 'AA' : '';
  447. },
  448. dark: function () {
  449. // YIQ equation from http://24ways.org/2010/calculating-color-contrast
  450. var rgb = this.values.rgb;
  451. var yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
  452. return yiq < 128;
  453. },
  454. light: function () {
  455. return !this.dark();
  456. },
  457. negate: function () {
  458. var rgb = [];
  459. for (var i = 0; i < 3; i++) {
  460. rgb[i] = 255 - this.values.rgb[i];
  461. }
  462. this.setValues('rgb', rgb);
  463. return this;
  464. },
  465. lighten: function (ratio) {
  466. var hsl = this.values.hsl;
  467. hsl[2] += hsl[2] * ratio;
  468. this.setValues('hsl', hsl);
  469. return this;
  470. },
  471. darken: function (ratio) {
  472. var hsl = this.values.hsl;
  473. hsl[2] -= hsl[2] * ratio;
  474. this.setValues('hsl', hsl);
  475. return this;
  476. },
  477. saturate: function (ratio) {
  478. var hsl = this.values.hsl;
  479. hsl[1] += hsl[1] * ratio;
  480. this.setValues('hsl', hsl);
  481. return this;
  482. },
  483. desaturate: function (ratio) {
  484. var hsl = this.values.hsl;
  485. hsl[1] -= hsl[1] * ratio;
  486. this.setValues('hsl', hsl);
  487. return this;
  488. },
  489. whiten: function (ratio) {
  490. var hwb = this.values.hwb;
  491. hwb[1] += hwb[1] * ratio;
  492. this.setValues('hwb', hwb);
  493. return this;
  494. },
  495. blacken: function (ratio) {
  496. var hwb = this.values.hwb;
  497. hwb[2] += hwb[2] * ratio;
  498. this.setValues('hwb', hwb);
  499. return this;
  500. },
  501. greyscale: function () {
  502. var rgb = this.values.rgb;
  503. // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
  504. var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  505. this.setValues('rgb', [val, val, val]);
  506. return this;
  507. },
  508. clearer: function (ratio) {
  509. var alpha = this.values.alpha;
  510. this.setValues('alpha', alpha - (alpha * ratio));
  511. return this;
  512. },
  513. opaquer: function (ratio) {
  514. var alpha = this.values.alpha;
  515. this.setValues('alpha', alpha + (alpha * ratio));
  516. return this;
  517. },
  518. rotate: function (degrees) {
  519. var hsl = this.values.hsl;
  520. var hue = (hsl[0] + degrees) % 360;
  521. hsl[0] = hue < 0 ? 360 + hue : hue;
  522. this.setValues('hsl', hsl);
  523. return this;
  524. },
  525. /**
  526. * Ported from sass implementation in C
  527. * https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
  528. */
  529. mix: function (mixinColor, weight) {
  530. var color1 = this;
  531. var color2 = mixinColor;
  532. var p = weight === undefined ? 0.5 : weight;
  533. var w = 2 * p - 1;
  534. var a = color1.alpha() - color2.alpha();
  535. var w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  536. var w2 = 1 - w1;
  537. return this
  538. .rgb(
  539. w1 * color1.red() + w2 * color2.red(),
  540. w1 * color1.green() + w2 * color2.green(),
  541. w1 * color1.blue() + w2 * color2.blue()
  542. )
  543. .alpha(color1.alpha() * p + color2.alpha() * (1 - p));
  544. },
  545. toJSON: function () {
  546. return this.rgb();
  547. },
  548. clone: function () {
  549. // NOTE(SB): using node-clone creates a dependency to Buffer when using browserify,
  550. // making the final build way to big to embed in Chart.js. So let's do it manually,
  551. // assuming that values to clone are 1 dimension arrays containing only numbers,
  552. // except 'alpha' which is a number.
  553. var result = new Color();
  554. var source = this.values;
  555. var target = result.values;
  556. var value, type;
  557. for (var prop in source) {
  558. if (source.hasOwnProperty(prop)) {
  559. value = source[prop];
  560. type = ({}).toString.call(value);
  561. if (type === '[object Array]') {
  562. target[prop] = value.slice(0);
  563. } else if (type === '[object Number]') {
  564. target[prop] = value;
  565. } else {
  566. console.error('unexpected color value:', value);
  567. }
  568. }
  569. }
  570. return result;
  571. }
  572. };
  573. Color.prototype.spaces = {
  574. rgb: ['red', 'green', 'blue'],
  575. hsl: ['hue', 'saturation', 'lightness'],
  576. hsv: ['hue', 'saturation', 'value'],
  577. hwb: ['hue', 'whiteness', 'blackness'],
  578. cmyk: ['cyan', 'magenta', 'yellow', 'black']
  579. };
  580. Color.prototype.maxes = {
  581. rgb: [255, 255, 255],
  582. hsl: [360, 100, 100],
  583. hsv: [360, 100, 100],
  584. hwb: [360, 100, 100],
  585. cmyk: [100, 100, 100, 100]
  586. };
  587. Color.prototype.getValues = function (space) {
  588. var values = this.values;
  589. var vals = {};
  590. for (var i = 0; i < space.length; i++) {
  591. vals[space.charAt(i)] = values[space][i];
  592. }
  593. if (values.alpha !== 1) {
  594. vals.a = values.alpha;
  595. }
  596. // {r: 255, g: 255, b: 255, a: 0.4}
  597. return vals;
  598. };
  599. Color.prototype.setValues = function (space, vals) {
  600. var values = this.values;
  601. var spaces = this.spaces;
  602. var maxes = this.maxes;
  603. var alpha = 1;
  604. var i;
  605. this.valid = true;
  606. if (space === 'alpha') {
  607. alpha = vals;
  608. } else if (vals.length) {
  609. // [10, 10, 10]
  610. values[space] = vals.slice(0, space.length);
  611. alpha = vals[space.length];
  612. } else if (vals[space.charAt(0)] !== undefined) {
  613. // {r: 10, g: 10, b: 10}
  614. for (i = 0; i < space.length; i++) {
  615. values[space][i] = vals[space.charAt(i)];
  616. }
  617. alpha = vals.a;
  618. } else if (vals[spaces[space][0]] !== undefined) {
  619. // {red: 10, green: 10, blue: 10}
  620. var chans = spaces[space];
  621. for (i = 0; i < space.length; i++) {
  622. values[space][i] = vals[chans[i]];
  623. }
  624. alpha = vals.alpha;
  625. }
  626. values.alpha = Math.max(0, Math.min(1, (alpha === undefined ? values.alpha : alpha)));
  627. if (space === 'alpha') {
  628. return false;
  629. }
  630. var capped;
  631. // cap values of the space prior converting all values
  632. for (i = 0; i < space.length; i++) {
  633. capped = Math.max(0, Math.min(maxes[space][i], values[space][i]));
  634. values[space][i] = Math.round(capped);
  635. }
  636. // convert to all the other color spaces
  637. for (var sname in spaces) {
  638. if (sname !== space) {
  639. values[sname] = convert[space][sname](values[space]);
  640. }
  641. }
  642. return true;
  643. };
  644. Color.prototype.setSpace = function (space, args) {
  645. var vals = args[0];
  646. if (vals === undefined) {
  647. // color.rgb()
  648. return this.getValues(space);
  649. }
  650. // color.rgb(10, 10, 10)
  651. if (typeof vals === 'number') {
  652. vals = Array.prototype.slice.call(args);
  653. }
  654. this.setValues(space, vals);
  655. return this;
  656. };
  657. Color.prototype.setChannel = function (space, index, val) {
  658. var svalues = this.values[space];
  659. if (val === undefined) {
  660. // color.red()
  661. return svalues[index];
  662. } else if (val === svalues[index]) {
  663. // color.red(color.red())
  664. return this;
  665. }
  666. // color.red(100)
  667. svalues[index] = val;
  668. this.setValues(space, svalues);
  669. return this;
  670. };
  671. if (typeof window !== 'undefined') {
  672. window.Color = Color;
  673. }
  674. module.exports = Color;
  675. }, {"2": 2, "5": 5}], 4: [function (require, module, exports) {
  676. /* MIT license */
  677. module.exports = {
  678. rgb2hsl: rgb2hsl,
  679. rgb2hsv: rgb2hsv,
  680. rgb2hwb: rgb2hwb,
  681. rgb2cmyk: rgb2cmyk,
  682. rgb2keyword: rgb2keyword,
  683. rgb2xyz: rgb2xyz,
  684. rgb2lab: rgb2lab,
  685. rgb2lch: rgb2lch,
  686. hsl2rgb: hsl2rgb,
  687. hsl2hsv: hsl2hsv,
  688. hsl2hwb: hsl2hwb,
  689. hsl2cmyk: hsl2cmyk,
  690. hsl2keyword: hsl2keyword,
  691. hsv2rgb: hsv2rgb,
  692. hsv2hsl: hsv2hsl,
  693. hsv2hwb: hsv2hwb,
  694. hsv2cmyk: hsv2cmyk,
  695. hsv2keyword: hsv2keyword,
  696. hwb2rgb: hwb2rgb,
  697. hwb2hsl: hwb2hsl,
  698. hwb2hsv: hwb2hsv,
  699. hwb2cmyk: hwb2cmyk,
  700. hwb2keyword: hwb2keyword,
  701. cmyk2rgb: cmyk2rgb,
  702. cmyk2hsl: cmyk2hsl,
  703. cmyk2hsv: cmyk2hsv,
  704. cmyk2hwb: cmyk2hwb,
  705. cmyk2keyword: cmyk2keyword,
  706. keyword2rgb: keyword2rgb,
  707. keyword2hsl: keyword2hsl,
  708. keyword2hsv: keyword2hsv,
  709. keyword2hwb: keyword2hwb,
  710. keyword2cmyk: keyword2cmyk,
  711. keyword2lab: keyword2lab,
  712. keyword2xyz: keyword2xyz,
  713. xyz2rgb: xyz2rgb,
  714. xyz2lab: xyz2lab,
  715. xyz2lch: xyz2lch,
  716. lab2xyz: lab2xyz,
  717. lab2rgb: lab2rgb,
  718. lab2lch: lab2lch,
  719. lch2lab: lch2lab,
  720. lch2xyz: lch2xyz,
  721. lch2rgb: lch2rgb
  722. }
  723. function rgb2hsl(rgb) {
  724. var r = rgb[0] / 255,
  725. g = rgb[1] / 255,
  726. b = rgb[2] / 255,
  727. min = Math.min(r, g, b),
  728. max = Math.max(r, g, b),
  729. delta = max - min,
  730. h, s, l;
  731. if (max == min)
  732. h = 0;
  733. else if (r == max)
  734. h = (g - b) / delta;
  735. else if (g == max)
  736. h = 2 + (b - r) / delta;
  737. else if (b == max)
  738. h = 4 + (r - g) / delta;
  739. h = Math.min(h * 60, 360);
  740. if (h < 0)
  741. h += 360;
  742. l = (min + max) / 2;
  743. if (max == min)
  744. s = 0;
  745. else if (l <= 0.5)
  746. s = delta / (max + min);
  747. else
  748. s = delta / (2 - max - min);
  749. return [h, s * 100, l * 100];
  750. }
  751. function rgb2hsv(rgb) {
  752. var r = rgb[0],
  753. g = rgb[1],
  754. b = rgb[2],
  755. min = Math.min(r, g, b),
  756. max = Math.max(r, g, b),
  757. delta = max - min,
  758. h, s, v;
  759. if (max == 0)
  760. s = 0;
  761. else
  762. s = (delta / max * 1000) / 10;
  763. if (max == min)
  764. h = 0;
  765. else if (r == max)
  766. h = (g - b) / delta;
  767. else if (g == max)
  768. h = 2 + (b - r) / delta;
  769. else if (b == max)
  770. h = 4 + (r - g) / delta;
  771. h = Math.min(h * 60, 360);
  772. if (h < 0)
  773. h += 360;
  774. v = ((max / 255) * 1000) / 10;
  775. return [h, s, v];
  776. }
  777. function rgb2hwb(rgb) {
  778. var r = rgb[0],
  779. g = rgb[1],
  780. b = rgb[2],
  781. h = rgb2hsl(rgb)[0],
  782. w = 1 / 255 * Math.min(r, Math.min(g, b)),
  783. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  784. return [h, w * 100, b * 100];
  785. }
  786. function rgb2cmyk(rgb) {
  787. var r = rgb[0] / 255,
  788. g = rgb[1] / 255,
  789. b = rgb[2] / 255,
  790. c, m, y, k;
  791. k = Math.min(1 - r, 1 - g, 1 - b);
  792. c = (1 - r - k) / (1 - k) || 0;
  793. m = (1 - g - k) / (1 - k) || 0;
  794. y = (1 - b - k) / (1 - k) || 0;
  795. return [c * 100, m * 100, y * 100, k * 100];
  796. }
  797. function rgb2keyword(rgb) {
  798. return reverseKeywords[JSON.stringify(rgb)];
  799. }
  800. function rgb2xyz(rgb) {
  801. var r = rgb[0] / 255,
  802. g = rgb[1] / 255,
  803. b = rgb[2] / 255;
  804. // assume sRGB
  805. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  806. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  807. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  808. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  809. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  810. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  811. return [x * 100, y * 100, z * 100];
  812. }
  813. function rgb2lab(rgb) {
  814. var xyz = rgb2xyz(rgb),
  815. x = xyz[0],
  816. y = xyz[1],
  817. z = xyz[2],
  818. l, a, b;
  819. x /= 95.047;
  820. y /= 100;
  821. z /= 108.883;
  822. x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);
  823. y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);
  824. z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);
  825. l = (116 * y) - 16;
  826. a = 500 * (x - y);
  827. b = 200 * (y - z);
  828. return [l, a, b];
  829. }
  830. function rgb2lch(args) {
  831. return lab2lch(rgb2lab(args));
  832. }
  833. function hsl2rgb(hsl) {
  834. var h = hsl[0] / 360,
  835. s = hsl[1] / 100,
  836. l = hsl[2] / 100,
  837. t1, t2, t3, rgb, val;
  838. if (s == 0) {
  839. val = l * 255;
  840. return [val, val, val];
  841. }
  842. if (l < 0.5)
  843. t2 = l * (1 + s);
  844. else
  845. t2 = l + s - l * s;
  846. t1 = 2 * l - t2;
  847. rgb = [0, 0, 0];
  848. for (var i = 0; i < 3; i++) {
  849. t3 = h + 1 / 3 * -(i - 1);
  850. t3 < 0 && t3++;
  851. t3 > 1 && t3--;
  852. if (6 * t3 < 1)
  853. val = t1 + (t2 - t1) * 6 * t3;
  854. else if (2 * t3 < 1)
  855. val = t2;
  856. else if (3 * t3 < 2)
  857. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  858. else
  859. val = t1;
  860. rgb[i] = val * 255;
  861. }
  862. return rgb;
  863. }
  864. function hsl2hsv(hsl) {
  865. var h = hsl[0],
  866. s = hsl[1] / 100,
  867. l = hsl[2] / 100,
  868. sv, v;
  869. if (l === 0) {
  870. // no need to do calc on black
  871. // also avoids divide by 0 error
  872. return [0, 0, 0];
  873. }
  874. l *= 2;
  875. s *= (l <= 1) ? l : 2 - l;
  876. v = (l + s) / 2;
  877. sv = (2 * s) / (l + s);
  878. return [h, sv * 100, v * 100];
  879. }
  880. function hsl2hwb(args) {
  881. return rgb2hwb(hsl2rgb(args));
  882. }
  883. function hsl2cmyk(args) {
  884. return rgb2cmyk(hsl2rgb(args));
  885. }
  886. function hsl2keyword(args) {
  887. return rgb2keyword(hsl2rgb(args));
  888. }
  889. function hsv2rgb(hsv) {
  890. var h = hsv[0] / 60,
  891. s = hsv[1] / 100,
  892. v = hsv[2] / 100,
  893. hi = Math.floor(h) % 6;
  894. var f = h - Math.floor(h),
  895. p = 255 * v * (1 - s),
  896. q = 255 * v * (1 - (s * f)),
  897. t = 255 * v * (1 - (s * (1 - f))),
  898. v = 255 * v;
  899. switch (hi) {
  900. case 0:
  901. return [v, t, p];
  902. case 1:
  903. return [q, v, p];
  904. case 2:
  905. return [p, v, t];
  906. case 3:
  907. return [p, q, v];
  908. case 4:
  909. return [t, p, v];
  910. case 5:
  911. return [v, p, q];
  912. }
  913. }
  914. function hsv2hsl(hsv) {
  915. var h = hsv[0],
  916. s = hsv[1] / 100,
  917. v = hsv[2] / 100,
  918. sl, l;
  919. l = (2 - s) * v;
  920. sl = s * v;
  921. sl /= (l <= 1) ? l : 2 - l;
  922. sl = sl || 0;
  923. l /= 2;
  924. return [h, sl * 100, l * 100];
  925. }
  926. function hsv2hwb(args) {
  927. return rgb2hwb(hsv2rgb(args))
  928. }
  929. function hsv2cmyk(args) {
  930. return rgb2cmyk(hsv2rgb(args));
  931. }
  932. function hsv2keyword(args) {
  933. return rgb2keyword(hsv2rgb(args));
  934. }
  935. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  936. function hwb2rgb(hwb) {
  937. var h = hwb[0] / 360,
  938. wh = hwb[1] / 100,
  939. bl = hwb[2] / 100,
  940. ratio = wh + bl,
  941. i, v, f, n;
  942. // wh + bl cant be > 1
  943. if (ratio > 1) {
  944. wh /= ratio;
  945. bl /= ratio;
  946. }
  947. i = Math.floor(6 * h);
  948. v = 1 - bl;
  949. f = 6 * h - i;
  950. if ((i & 0x01) != 0) {
  951. f = 1 - f;
  952. }
  953. n = wh + f * (v - wh); // linear interpolation
  954. switch (i) {
  955. default:
  956. case 6:
  957. case 0:
  958. r = v;
  959. g = n;
  960. b = wh;
  961. break;
  962. case 1:
  963. r = n;
  964. g = v;
  965. b = wh;
  966. break;
  967. case 2:
  968. r = wh;
  969. g = v;
  970. b = n;
  971. break;
  972. case 3:
  973. r = wh;
  974. g = n;
  975. b = v;
  976. break;
  977. case 4:
  978. r = n;
  979. g = wh;
  980. b = v;
  981. break;
  982. case 5:
  983. r = v;
  984. g = wh;
  985. b = n;
  986. break;
  987. }
  988. return [r * 255, g * 255, b * 255];
  989. }
  990. function hwb2hsl(args) {
  991. return rgb2hsl(hwb2rgb(args));
  992. }
  993. function hwb2hsv(args) {
  994. return rgb2hsv(hwb2rgb(args));
  995. }
  996. function hwb2cmyk(args) {
  997. return rgb2cmyk(hwb2rgb(args));
  998. }
  999. function hwb2keyword(args) {
  1000. return rgb2keyword(hwb2rgb(args));
  1001. }
  1002. function cmyk2rgb(cmyk) {
  1003. var c = cmyk[0] / 100,
  1004. m = cmyk[1] / 100,
  1005. y = cmyk[2] / 100,
  1006. k = cmyk[3] / 100,
  1007. r, g, b;
  1008. r = 1 - Math.min(1, c * (1 - k) + k);
  1009. g = 1 - Math.min(1, m * (1 - k) + k);
  1010. b = 1 - Math.min(1, y * (1 - k) + k);
  1011. return [r * 255, g * 255, b * 255];
  1012. }
  1013. function cmyk2hsl(args) {
  1014. return rgb2hsl(cmyk2rgb(args));
  1015. }
  1016. function cmyk2hsv(args) {
  1017. return rgb2hsv(cmyk2rgb(args));
  1018. }
  1019. function cmyk2hwb(args) {
  1020. return rgb2hwb(cmyk2rgb(args));
  1021. }
  1022. function cmyk2keyword(args) {
  1023. return rgb2keyword(cmyk2rgb(args));
  1024. }
  1025. function xyz2rgb(xyz) {
  1026. var x = xyz[0] / 100,
  1027. y = xyz[1] / 100,
  1028. z = xyz[2] / 100,
  1029. r, g, b;
  1030. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  1031. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  1032. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  1033. // assume sRGB
  1034. r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  1035. : r = (r * 12.92);
  1036. g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  1037. : g = (g * 12.92);
  1038. b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  1039. : b = (b * 12.92);
  1040. r = Math.min(Math.max(0, r), 1);
  1041. g = Math.min(Math.max(0, g), 1);
  1042. b = Math.min(Math.max(0, b), 1);
  1043. return [r * 255, g * 255, b * 255];
  1044. }
  1045. function xyz2lab(xyz) {
  1046. var x = xyz[0],
  1047. y = xyz[1],
  1048. z = xyz[2],
  1049. l, a, b;
  1050. x /= 95.047;
  1051. y /= 100;
  1052. z /= 108.883;
  1053. x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);
  1054. y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);
  1055. z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);
  1056. l = (116 * y) - 16;
  1057. a = 500 * (x - y);
  1058. b = 200 * (y - z);
  1059. return [l, a, b];
  1060. }
  1061. function xyz2lch(args) {
  1062. return lab2lch(xyz2lab(args));
  1063. }
  1064. function lab2xyz(lab) {
  1065. var l = lab[0],
  1066. a = lab[1],
  1067. b = lab[2],
  1068. x, y, z, y2;
  1069. if (l <= 8) {
  1070. y = (l * 100) / 903.3;
  1071. y2 = (7.787 * (y / 100)) + (16 / 116);
  1072. } else {
  1073. y = 100 * Math.pow((l + 16) / 116, 3);
  1074. y2 = Math.pow(y / 100, 1 / 3);
  1075. }
  1076. x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
  1077. z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
  1078. return [x, y, z];
  1079. }
  1080. function lab2lch(lab) {
  1081. var l = lab[0],
  1082. a = lab[1],
  1083. b = lab[2],
  1084. hr, h, c;
  1085. hr = Math.atan2(b, a);
  1086. h = hr * 360 / 2 / Math.PI;
  1087. if (h < 0) {
  1088. h += 360;
  1089. }
  1090. c = Math.sqrt(a * a + b * b);
  1091. return [l, c, h];
  1092. }
  1093. function lab2rgb(args) {
  1094. return xyz2rgb(lab2xyz(args));
  1095. }
  1096. function lch2lab(lch) {
  1097. var l = lch[0],
  1098. c = lch[1],
  1099. h = lch[2],
  1100. a, b, hr;
  1101. hr = h / 360 * 2 * Math.PI;
  1102. a = c * Math.cos(hr);
  1103. b = c * Math.sin(hr);
  1104. return [l, a, b];
  1105. }
  1106. function lch2xyz(args) {
  1107. return lab2xyz(lch2lab(args));
  1108. }
  1109. function lch2rgb(args) {
  1110. return lab2rgb(lch2lab(args));
  1111. }
  1112. function keyword2rgb(keyword) {
  1113. return cssKeywords[keyword];
  1114. }
  1115. function keyword2hsl(args) {
  1116. return rgb2hsl(keyword2rgb(args));
  1117. }
  1118. function keyword2hsv(args) {
  1119. return rgb2hsv(keyword2rgb(args));
  1120. }
  1121. function keyword2hwb(args) {
  1122. return rgb2hwb(keyword2rgb(args));
  1123. }
  1124. function keyword2cmyk(args) {
  1125. return rgb2cmyk(keyword2rgb(args));
  1126. }
  1127. function keyword2lab(args) {
  1128. return rgb2lab(keyword2rgb(args));
  1129. }
  1130. function keyword2xyz(args) {
  1131. return rgb2xyz(keyword2rgb(args));
  1132. }
  1133. var cssKeywords = {
  1134. aliceblue: [240, 248, 255],
  1135. antiquewhite: [250, 235, 215],
  1136. aqua: [0, 255, 255],
  1137. aquamarine: [127, 255, 212],
  1138. azure: [240, 255, 255],
  1139. beige: [245, 245, 220],
  1140. bisque: [255, 228, 196],
  1141. black: [0, 0, 0],
  1142. blanchedalmond: [255, 235, 205],
  1143. blue: [0, 0, 255],
  1144. blueviolet: [138, 43, 226],
  1145. brown: [165, 42, 42],
  1146. burlywood: [222, 184, 135],
  1147. cadetblue: [95, 158, 160],
  1148. chartreuse: [127, 255, 0],
  1149. chocolate: [210, 105, 30],
  1150. coral: [255, 127, 80],
  1151. cornflowerblue: [100, 149, 237],
  1152. cornsilk: [255, 248, 220],
  1153. crimson: [220, 20, 60],
  1154. cyan: [0, 255, 255],
  1155. darkblue: [0, 0, 139],
  1156. darkcyan: [0, 139, 139],
  1157. darkgoldenrod: [184, 134, 11],
  1158. darkgray: [169, 169, 169],
  1159. darkgreen: [0, 100, 0],
  1160. darkgrey: [169, 169, 169],
  1161. darkkhaki: [189, 183, 107],
  1162. darkmagenta: [139, 0, 139],
  1163. darkolivegreen: [85, 107, 47],
  1164. darkorange: [255, 140, 0],
  1165. darkorchid: [153, 50, 204],
  1166. darkred: [139, 0, 0],
  1167. darksalmon: [233, 150, 122],
  1168. darkseagreen: [143, 188, 143],
  1169. darkslateblue: [72, 61, 139],
  1170. darkslategray: [47, 79, 79],
  1171. darkslategrey: [47, 79, 79],
  1172. darkturquoise: [0, 206, 209],
  1173. darkviolet: [148, 0, 211],
  1174. deeppink: [255, 20, 147],
  1175. deepskyblue: [0, 191, 255],
  1176. dimgray: [105, 105, 105],
  1177. dimgrey: [105, 105, 105],
  1178. dodgerblue: [30, 144, 255],
  1179. firebrick: [178, 34, 34],
  1180. floralwhite: [255, 250, 240],
  1181. forestgreen: [34, 139, 34],
  1182. fuchsia: [255, 0, 255],
  1183. gainsboro: [220, 220, 220],
  1184. ghostwhite: [248, 248, 255],
  1185. gold: [255, 215, 0],
  1186. goldenrod: [218, 165, 32],
  1187. gray: [128, 128, 128],
  1188. green: [0, 128, 0],
  1189. greenyellow: [173, 255, 47],
  1190. grey: [128, 128, 128],
  1191. honeydew: [240, 255, 240],
  1192. hotpink: [255, 105, 180],
  1193. indianred: [205, 92, 92],
  1194. indigo: [75, 0, 130],
  1195. ivory: [255, 255, 240],
  1196. khaki: [240, 230, 140],
  1197. lavender: [230, 230, 250],
  1198. lavenderblush: [255, 240, 245],
  1199. lawngreen: [124, 252, 0],
  1200. lemonchiffon: [255, 250, 205],
  1201. lightblue: [173, 216, 230],
  1202. lightcoral: [240, 128, 128],
  1203. lightcyan: [224, 255, 255],
  1204. lightgoldenrodyellow: [250, 250, 210],
  1205. lightgray: [211, 211, 211],
  1206. lightgreen: [144, 238, 144],
  1207. lightgrey: [211, 211, 211],
  1208. lightpink: [255, 182, 193],
  1209. lightsalmon: [255, 160, 122],
  1210. lightseagreen: [32, 178, 170],
  1211. lightskyblue: [135, 206, 250],
  1212. lightslategray: [119, 136, 153],
  1213. lightslategrey: [119, 136, 153],
  1214. lightsteelblue: [176, 196, 222],
  1215. lightyellow: [255, 255, 224],
  1216. lime: [0, 255, 0],
  1217. limegreen: [50, 205, 50],
  1218. linen: [250, 240, 230],
  1219. magenta: [255, 0, 255],
  1220. maroon: [128, 0, 0],
  1221. mediumaquamarine: [102, 205, 170],
  1222. mediumblue: [0, 0, 205],
  1223. mediumorchid: [186, 85, 211],
  1224. mediumpurple: [147, 112, 219],
  1225. mediumseagreen: [60, 179, 113],
  1226. mediumslateblue: [123, 104, 238],
  1227. mediumspringgreen: [0, 250, 154],
  1228. mediumturquoise: [72, 209, 204],
  1229. mediumvioletred: [199, 21, 133],
  1230. midnightblue: [25, 25, 112],
  1231. mintcream: [245, 255, 250],
  1232. mistyrose: [255, 228, 225],
  1233. moccasin: [255, 228, 181],
  1234. navajowhite: [255, 222, 173],
  1235. navy: [0, 0, 128],
  1236. oldlace: [253, 245, 230],
  1237. olive: [128, 128, 0],
  1238. olivedrab: [107, 142, 35],
  1239. orange: [255, 165, 0],
  1240. orangered: [255, 69, 0],
  1241. orchid: [218, 112, 214],
  1242. palegoldenrod: [238, 232, 170],
  1243. palegreen: [152, 251, 152],
  1244. paleturquoise: [175, 238, 238],
  1245. palevioletred: [219, 112, 147],
  1246. papayawhip: [255, 239, 213],
  1247. peachpuff: [255, 218, 185],
  1248. peru: [205, 133, 63],
  1249. pink: [255, 192, 203],
  1250. plum: [221, 160, 221],
  1251. powderblue: [176, 224, 230],
  1252. purple: [128, 0, 128],
  1253. rebeccapurple: [102, 51, 153],
  1254. red: [255, 0, 0],
  1255. rosybrown: [188, 143, 143],
  1256. royalblue: [65, 105, 225],
  1257. saddlebrown: [139, 69, 19],
  1258. salmon: [250, 128, 114],
  1259. sandybrown: [244, 164, 96],
  1260. seagreen: [46, 139, 87],
  1261. seashell: [255, 245, 238],
  1262. sienna: [160, 82, 45],
  1263. silver: [192, 192, 192],
  1264. skyblue: [135, 206, 235],
  1265. slateblue: [106, 90, 205],
  1266. slategray: [112, 128, 144],
  1267. slategrey: [112, 128, 144],
  1268. snow: [255, 250, 250],
  1269. springgreen: [0, 255, 127],
  1270. steelblue: [70, 130, 180],
  1271. tan: [210, 180, 140],
  1272. teal: [0, 128, 128],
  1273. thistle: [216, 191, 216],
  1274. tomato: [255, 99, 71],
  1275. turquoise: [64, 224, 208],
  1276. violet: [238, 130, 238],
  1277. wheat: [245, 222, 179],
  1278. white: [255, 255, 255],
  1279. whitesmoke: [245, 245, 245],
  1280. yellow: [255, 255, 0],
  1281. yellowgreen: [154, 205, 50]
  1282. };
  1283. var reverseKeywords = {};
  1284. for (var key in cssKeywords) {
  1285. reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
  1286. }
  1287. }, {}], 5: [function (require, module, exports) {
  1288. var conversions = require(4);
  1289. var convert = function () {
  1290. return new Converter();
  1291. }
  1292. for (var func in conversions) {
  1293. // export Raw versions
  1294. convert[func + "Raw"] = (function (func) {
  1295. // accept array or plain args
  1296. return function (arg) {
  1297. if (typeof arg == "number")
  1298. arg = Array.prototype.slice.call(arguments);
  1299. return conversions[func](arg);
  1300. }
  1301. })(func);
  1302. var pair = /(\w+)2(\w+)/.exec(func),
  1303. from = pair[1],
  1304. to = pair[2];
  1305. // export rgb2hsl and ["rgb"]["hsl"]
  1306. convert[from] = convert[from] || {};
  1307. convert[from][to] = convert[func] = (function (func) {
  1308. return function (arg) {
  1309. if (typeof arg == "number")
  1310. arg = Array.prototype.slice.call(arguments);
  1311. var val = conversions[func](arg);
  1312. if (typeof val == "string" || val === undefined)
  1313. return val; // keyword
  1314. for (var i = 0; i < val.length; i++)
  1315. val[i] = Math.round(val[i]);
  1316. return val;
  1317. }
  1318. })(func);
  1319. }
  1320. /* Converter does lazy conversion and caching */
  1321. var Converter = function () {
  1322. this.convs = {};
  1323. };
  1324. /* Either get the values for a space or
  1325. set the values for a space, depending on args */
  1326. Converter.prototype.routeSpace = function (space, args) {
  1327. var values = args[0];
  1328. if (values === undefined) {
  1329. // color.rgb()
  1330. return this.getValues(space);
  1331. }
  1332. // color.rgb(10, 10, 10)
  1333. if (typeof values == "number") {
  1334. values = Array.prototype.slice.call(args);
  1335. }
  1336. return this.setValues(space, values);
  1337. };
  1338. /* Set the values for a space, invalidating cache */
  1339. Converter.prototype.setValues = function (space, values) {
  1340. this.space = space;
  1341. this.convs = {};
  1342. this.convs[space] = values;
  1343. return this;
  1344. };
  1345. /* Get the values for a space. If there's already
  1346. a conversion for the space, fetch it, otherwise
  1347. compute it */
  1348. Converter.prototype.getValues = function (space) {
  1349. var vals = this.convs[space];
  1350. if (!vals) {
  1351. var fspace = this.space,
  1352. from = this.convs[fspace];
  1353. vals = convert[fspace][space](from);
  1354. this.convs[space] = vals;
  1355. }
  1356. return vals;
  1357. };
  1358. ["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function (space) {
  1359. Converter.prototype[space] = function (vals) {
  1360. return this.routeSpace(space, arguments);
  1361. }
  1362. });
  1363. module.exports = convert;
  1364. }, {"4": 4}], 6: [function (require, module, exports) {
  1365. 'use strict'
  1366. module.exports = {
  1367. "aliceblue": [240, 248, 255],
  1368. "antiquewhite": [250, 235, 215],
  1369. "aqua": [0, 255, 255],
  1370. "aquamarine": [127, 255, 212],
  1371. "azure": [240, 255, 255],
  1372. "beige": [245, 245, 220],
  1373. "bisque": [255, 228, 196],
  1374. "black": [0, 0, 0],
  1375. "blanchedalmond": [255, 235, 205],
  1376. "blue": [0, 0, 255],
  1377. "blueviolet": [138, 43, 226],
  1378. "brown": [165, 42, 42],
  1379. "burlywood": [222, 184, 135],
  1380. "cadetblue": [95, 158, 160],
  1381. "chartreuse": [127, 255, 0],
  1382. "chocolate": [210, 105, 30],
  1383. "coral": [255, 127, 80],
  1384. "cornflowerblue": [100, 149, 237],
  1385. "cornsilk": [255, 248, 220],
  1386. "crimson": [220, 20, 60],
  1387. "cyan": [0, 255, 255],
  1388. "darkblue": [0, 0, 139],
  1389. "darkcyan": [0, 139, 139],
  1390. "darkgoldenrod": [184, 134, 11],
  1391. "darkgray": [169, 169, 169],
  1392. "darkgreen": [0, 100, 0],
  1393. "darkgrey": [169, 169, 169],
  1394. "darkkhaki": [189, 183, 107],
  1395. "darkmagenta": [139, 0, 139],
  1396. "darkolivegreen": [85, 107, 47],
  1397. "darkorange": [255, 140, 0],
  1398. "darkorchid": [153, 50, 204],
  1399. "darkred": [139, 0, 0],
  1400. "darksalmon": [233, 150, 122],
  1401. "darkseagreen": [143, 188, 143],
  1402. "darkslateblue": [72, 61, 139],
  1403. "darkslategray": [47, 79, 79],
  1404. "darkslategrey": [47, 79, 79],
  1405. "darkturquoise": [0, 206, 209],
  1406. "darkviolet": [148, 0, 211],
  1407. "deeppink": [255, 20, 147],
  1408. "deepskyblue": [0, 191, 255],
  1409. "dimgray": [105, 105, 105],
  1410. "dimgrey": [105, 105, 105],
  1411. "dodgerblue": [30, 144, 255],
  1412. "firebrick": [178, 34, 34],
  1413. "floralwhite": [255, 250, 240],
  1414. "forestgreen": [34, 139, 34],
  1415. "fuchsia": [255, 0, 255],
  1416. "gainsboro": [220, 220, 220],
  1417. "ghostwhite": [248, 248, 255],
  1418. "gold": [255, 215, 0],
  1419. "goldenrod": [218, 165, 32],
  1420. "gray": [128, 128, 128],
  1421. "green": [0, 128, 0],
  1422. "greenyellow": [173, 255, 47],
  1423. "grey": [128, 128, 128],
  1424. "honeydew": [240, 255, 240],
  1425. "hotpink": [255, 105, 180],
  1426. "indianred": [205, 92, 92],
  1427. "indigo": [75, 0, 130],
  1428. "ivory": [255, 255, 240],
  1429. "khaki": [240, 230, 140],
  1430. "lavender": [230, 230, 250],
  1431. "lavenderblush": [255, 240, 245],
  1432. "lawngreen": [124, 252, 0],
  1433. "lemonchiffon": [255, 250, 205],
  1434. "lightblue": [173, 216, 230],
  1435. "lightcoral": [240, 128, 128],
  1436. "lightcyan": [224, 255, 255],
  1437. "lightgoldenrodyellow": [250, 250, 210],
  1438. "lightgray": [211, 211, 211],
  1439. "lightgreen": [144, 238, 144],
  1440. "lightgrey": [211, 211, 211],
  1441. "lightpink": [255, 182, 193],
  1442. "lightsalmon": [255, 160, 122],
  1443. "lightseagreen": [32, 178, 170],
  1444. "lightskyblue": [135, 206, 250],
  1445. "lightslategray": [119, 136, 153],
  1446. "lightslategrey": [119, 136, 153],
  1447. "lightsteelblue": [176, 196, 222],
  1448. "lightyellow": [255, 255, 224],
  1449. "lime": [0, 255, 0],
  1450. "limegreen": [50, 205, 50],
  1451. "linen": [250, 240, 230],
  1452. "magenta": [255, 0, 255],
  1453. "maroon": [128, 0, 0],
  1454. "mediumaquamarine": [102, 205, 170],
  1455. "mediumblue": [0, 0, 205],
  1456. "mediumorchid": [186, 85, 211],
  1457. "mediumpurple": [147, 112, 219],
  1458. "mediumseagreen": [60, 179, 113],
  1459. "mediumslateblue": [123, 104, 238],
  1460. "mediumspringgreen": [0, 250, 154],
  1461. "mediumturquoise": [72, 209, 204],
  1462. "mediumvioletred": [199, 21, 133],
  1463. "midnightblue": [25, 25, 112],
  1464. "mintcream": [245, 255, 250],
  1465. "mistyrose": [255, 228, 225],
  1466. "moccasin": [255, 228, 181],
  1467. "navajowhite": [255, 222, 173],
  1468. "navy": [0, 0, 128],
  1469. "oldlace": [253, 245, 230],
  1470. "olive": [128, 128, 0],
  1471. "olivedrab": [107, 142, 35],
  1472. "orange": [255, 165, 0],
  1473. "orangered": [255, 69, 0],
  1474. "orchid": [218, 112, 214],
  1475. "palegoldenrod": [238, 232, 170],
  1476. "palegreen": [152, 251, 152],
  1477. "paleturquoise": [175, 238, 238],
  1478. "palevioletred": [219, 112, 147],
  1479. "papayawhip": [255, 239, 213],
  1480. "peachpuff": [255, 218, 185],
  1481. "peru": [205, 133, 63],
  1482. "pink": [255, 192, 203],
  1483. "plum": [221, 160, 221],
  1484. "powderblue": [176, 224, 230],
  1485. "purple": [128, 0, 128],
  1486. "rebeccapurple": [102, 51, 153],
  1487. "red": [255, 0, 0],
  1488. "rosybrown": [188, 143, 143],
  1489. "royalblue": [65, 105, 225],
  1490. "saddlebrown": [139, 69, 19],
  1491. "salmon": [250, 128, 114],
  1492. "sandybrown": [244, 164, 96],
  1493. "seagreen": [46, 139, 87],
  1494. "seashell": [255, 245, 238],
  1495. "sienna": [160, 82, 45],
  1496. "silver": [192, 192, 192],
  1497. "skyblue": [135, 206, 235],
  1498. "slateblue": [106, 90, 205],
  1499. "slategray": [112, 128, 144],
  1500. "slategrey": [112, 128, 144],
  1501. "snow": [255, 250, 250],
  1502. "springgreen": [0, 255, 127],
  1503. "steelblue": [70, 130, 180],
  1504. "tan": [210, 180, 140],
  1505. "teal": [0, 128, 128],
  1506. "thistle": [216, 191, 216],
  1507. "tomato": [255, 99, 71],
  1508. "turquoise": [64, 224, 208],
  1509. "violet": [238, 130, 238],
  1510. "wheat": [245, 222, 179],
  1511. "white": [255, 255, 255],
  1512. "whitesmoke": [245, 245, 245],
  1513. "yellow": [255, 255, 0],
  1514. "yellowgreen": [154, 205, 50]
  1515. };
  1516. }, {}], 7: [function (require, module, exports) {
  1517. /**
  1518. * @namespace Chart
  1519. */
  1520. var Chart = require(29)();
  1521. Chart.helpers = require(45);
  1522. // @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
  1523. require(27)(Chart);
  1524. Chart.defaults = require(25);
  1525. Chart.Element = require(26);
  1526. Chart.elements = require(40);
  1527. Chart.Interaction = require(28);
  1528. Chart.layouts = require(30);
  1529. Chart.platform = require(48);
  1530. Chart.plugins = require(31);
  1531. Chart.Ticks = require(34);
  1532. require(22)(Chart);
  1533. require(23)(Chart);
  1534. require(24)(Chart);
  1535. require(33)(Chart);
  1536. require(32)(Chart);
  1537. require(35)(Chart);
  1538. require(55)(Chart);
  1539. require(53)(Chart);
  1540. require(54)(Chart);
  1541. require(56)(Chart);
  1542. require(57)(Chart);
  1543. require(58)(Chart);
  1544. // Controllers must be loaded after elements
  1545. // See Chart.core.datasetController.dataElementType
  1546. require(15)(Chart);
  1547. require(16)(Chart);
  1548. require(17)(Chart);
  1549. require(18)(Chart);
  1550. require(19)(Chart);
  1551. require(20)(Chart);
  1552. require(21)(Chart);
  1553. require(8)(Chart);
  1554. require(9)(Chart);
  1555. require(10)(Chart);
  1556. require(11)(Chart);
  1557. require(12)(Chart);
  1558. require(13)(Chart);
  1559. require(14)(Chart);
  1560. // Loading built-it plugins
  1561. var plugins = require(49);
  1562. for (var k in plugins) {
  1563. if (plugins.hasOwnProperty(k)) {
  1564. Chart.plugins.register(plugins[k]);
  1565. }
  1566. }
  1567. Chart.platform.initialize();
  1568. module.exports = Chart;
  1569. if (typeof window !== 'undefined') {
  1570. window.Chart = Chart;
  1571. }
  1572. // DEPRECATIONS
  1573. /**
  1574. * Provided for backward compatibility, not available anymore
  1575. * @namespace Chart.Legend
  1576. * @deprecated since version 2.1.5
  1577. * @todo remove at version 3
  1578. * @private
  1579. */
  1580. Chart.Legend = plugins.legend._element;
  1581. /**
  1582. * Provided for backward compatibility, not available anymore
  1583. * @namespace Chart.Title
  1584. * @deprecated since version 2.1.5
  1585. * @todo remove at version 3
  1586. * @private
  1587. */
  1588. Chart.Title = plugins.title._element;
  1589. /**
  1590. * Provided for backward compatibility, use Chart.plugins instead
  1591. * @namespace Chart.pluginService
  1592. * @deprecated since version 2.1.5
  1593. * @todo remove at version 3
  1594. * @private
  1595. */
  1596. Chart.pluginService = Chart.plugins;
  1597. /**
  1598. * Provided for backward compatibility, inheriting from Chart.PlugingBase has no
  1599. * effect, instead simply create/register plugins via plain JavaScript objects.
  1600. * @interface Chart.PluginBase
  1601. * @deprecated since version 2.5.0
  1602. * @todo remove at version 3
  1603. * @private
  1604. */
  1605. Chart.PluginBase = Chart.Element.extend({});
  1606. /**
  1607. * Provided for backward compatibility, use Chart.helpers.canvas instead.
  1608. * @namespace Chart.canvasHelpers
  1609. * @deprecated since version 2.6.0
  1610. * @todo remove at version 3
  1611. * @private
  1612. */
  1613. Chart.canvasHelpers = Chart.helpers.canvas;
  1614. /**
  1615. * Provided for backward compatibility, use Chart.layouts instead.
  1616. * @namespace Chart.layoutService
  1617. * @deprecated since version 2.8.0
  1618. * @todo remove at version 3
  1619. * @private
  1620. */
  1621. Chart.layoutService = Chart.layouts;
  1622. }, {"10": 10, "11": 11, "12": 12, "13": 13, "14": 14, "15": 15, "16": 16, "17": 17, "18": 18, "19": 19, "20": 20, "21": 21, "22": 22, "23": 23, "24": 24, "25": 25, "26": 26, "27": 27, "28": 28, "29": 29, "30": 30, "31": 31, "32": 32, "33": 33, "34": 34, "35": 35, "40": 40, "45": 45, "48": 48, "49": 49, "53": 53, "54": 54, "55": 55, "56": 56, "57": 57, "58": 58, "8": 8, "9": 9}], 8: [function (require, module, exports) {
  1623. 'use strict';
  1624. module.exports = function (Chart) {
  1625. Chart.Bar = function (context, config) {
  1626. config.type = 'bar';
  1627. return new Chart(context, config);
  1628. };
  1629. };
  1630. }, {}], 9: [function (require, module, exports) {
  1631. 'use strict';
  1632. module.exports = function (Chart) {
  1633. Chart.Bubble = function (context, config) {
  1634. config.type = 'bubble';
  1635. return new Chart(context, config);
  1636. };
  1637. };
  1638. }, {}], 10: [function (require, module, exports) {
  1639. 'use strict';
  1640. module.exports = function (Chart) {
  1641. Chart.Doughnut = function (context, config) {
  1642. config.type = 'doughnut';
  1643. return new Chart(context, config);
  1644. };
  1645. };
  1646. }, {}], 11: [function (require, module, exports) {
  1647. 'use strict';
  1648. module.exports = function (Chart) {
  1649. Chart.Line = function (context, config) {
  1650. config.type = 'line';
  1651. return new Chart(context, config);
  1652. };
  1653. };
  1654. }, {}], 12: [function (require, module, exports) {
  1655. 'use strict';
  1656. module.exports = function (Chart) {
  1657. Chart.PolarArea = function (context, config) {
  1658. config.type = 'polarArea';
  1659. return new Chart(context, config);
  1660. };
  1661. };
  1662. }, {}], 13: [function (require, module, exports) {
  1663. 'use strict';
  1664. module.exports = function (Chart) {
  1665. Chart.Radar = function (context, config) {
  1666. config.type = 'radar';
  1667. return new Chart(context, config);
  1668. };
  1669. };
  1670. }, {}], 14: [function (require, module, exports) {
  1671. 'use strict';
  1672. module.exports = function (Chart) {
  1673. Chart.Scatter = function (context, config) {
  1674. config.type = 'scatter';
  1675. return new Chart(context, config);
  1676. };
  1677. };
  1678. }, {}], 15: [function (require, module, exports) {
  1679. 'use strict';
  1680. var defaults = require(25);
  1681. var elements = require(40);
  1682. var helpers = require(45);
  1683. defaults._set('bar', {
  1684. hover: {
  1685. mode: 'label'
  1686. },
  1687. scales: {
  1688. xAxes: [{
  1689. type: 'category',
  1690. // Specific to Bar Controller
  1691. categoryPercentage: 0.8,
  1692. barPercentage: 0.9,
  1693. // offset settings
  1694. offset: true,
  1695. // grid line settings
  1696. gridLines: {
  1697. offsetGridLines: true
  1698. }
  1699. }],
  1700. yAxes: [{
  1701. type: 'linear'
  1702. }]
  1703. }
  1704. });
  1705. defaults._set('horizontalBar', {
  1706. hover: {
  1707. mode: 'index',
  1708. axis: 'y'
  1709. },
  1710. scales: {
  1711. xAxes: [{
  1712. type: 'linear',
  1713. position: 'bottom'
  1714. }],
  1715. yAxes: [{
  1716. position: 'left',
  1717. type: 'category',
  1718. // Specific to Horizontal Bar Controller
  1719. categoryPercentage: 0.8,
  1720. barPercentage: 0.9,
  1721. // offset settings
  1722. offset: true,
  1723. // grid line settings
  1724. gridLines: {
  1725. offsetGridLines: true
  1726. }
  1727. }]
  1728. },
  1729. elements: {
  1730. rectangle: {
  1731. borderSkipped: 'left'
  1732. }
  1733. },
  1734. tooltips: {
  1735. callbacks: {
  1736. title: function (item, data) {
  1737. // Pick first xLabel for now
  1738. var title = '';
  1739. if (item.length > 0) {
  1740. if (item[0].yLabel) {
  1741. title = item[0].yLabel;
  1742. } else if (data.labels.length > 0 && item[0].index < data.labels.length) {
  1743. title = data.labels[item[0].index];
  1744. }
  1745. }
  1746. return title;
  1747. },
  1748. label: function (item, data) {
  1749. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  1750. return datasetLabel + ': ' + item.xLabel;
  1751. }
  1752. },
  1753. mode: 'index',
  1754. axis: 'y'
  1755. }
  1756. });
  1757. /**
  1758. * Computes the "optimal" sample size to maintain bars equally sized while preventing overlap.
  1759. * @private
  1760. */
  1761. function computeMinSampleSize(scale, pixels) {
  1762. var min = scale.isHorizontal() ? scale.width : scale.height;
  1763. var ticks = scale.getTicks();
  1764. var prev, curr, i, ilen;
  1765. for (i = 1, ilen = pixels.length; i < ilen; ++i) {
  1766. min = Math.min(min, pixels[i] - pixels[i - 1]);
  1767. }
  1768. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  1769. curr = scale.getPixelForTick(i);
  1770. min = i > 0 ? Math.min(min, curr - prev) : min;
  1771. prev = curr;
  1772. }
  1773. return min;
  1774. }
  1775. /**
  1776. * Computes an "ideal" category based on the absolute bar thickness or, if undefined or null,
  1777. * uses the smallest interval (see computeMinSampleSize) that prevents bar overlapping. This
  1778. * mode currently always generates bars equally sized (until we introduce scriptable options?).
  1779. * @private
  1780. */
  1781. function computeFitCategoryTraits(index, ruler, options) {
  1782. var thickness = options.barThickness;
  1783. var count = ruler.stackCount;
  1784. var curr = ruler.pixels[index];
  1785. var size, ratio;
  1786. if (helpers.isNullOrUndef(thickness)) {
  1787. size = ruler.min * options.categoryPercentage;
  1788. ratio = options.barPercentage;
  1789. } else {
  1790. // When bar thickness is enforced, category and bar percentages are ignored.
  1791. // Note(SB): we could add support for relative bar thickness (e.g. barThickness: '50%')
  1792. // and deprecate barPercentage since this value is ignored when thickness is absolute.
  1793. size = thickness * count;
  1794. ratio = 1;
  1795. }
  1796. return {
  1797. chunk: size / count,
  1798. ratio: ratio,
  1799. start: curr - (size / 2)
  1800. };
  1801. }
  1802. /**
  1803. * Computes an "optimal" category that globally arranges bars side by side (no gap when
  1804. * percentage options are 1), based on the previous and following categories. This mode
  1805. * generates bars with different widths when data are not evenly spaced.
  1806. * @private
  1807. */
  1808. function computeFlexCategoryTraits(index, ruler, options) {
  1809. var pixels = ruler.pixels;
  1810. var curr = pixels[index];
  1811. var prev = index > 0 ? pixels[index - 1] : null;
  1812. var next = index < pixels.length - 1 ? pixels[index + 1] : null;
  1813. var percent = options.categoryPercentage;
  1814. var start, size;
  1815. if (prev === null) {
  1816. // first data: its size is double based on the next point or,
  1817. // if it's also the last data, we use the scale end extremity.
  1818. prev = curr - (next === null ? ruler.end - curr : next - curr);
  1819. }
  1820. if (next === null) {
  1821. // last data: its size is also double based on the previous point.
  1822. next = curr + curr - prev;
  1823. }
  1824. start = curr - ((curr - prev) / 2) * percent;
  1825. size = ((next - prev) / 2) * percent;
  1826. return {
  1827. chunk: size / ruler.stackCount,
  1828. ratio: options.barPercentage,
  1829. start: start
  1830. };
  1831. }
  1832. module.exports = function (Chart) {
  1833. Chart.controllers.bar = Chart.DatasetController.extend({
  1834. dataElementType: elements.Rectangle,
  1835. initialize: function () {
  1836. var me = this;
  1837. var meta;
  1838. Chart.DatasetController.prototype.initialize.apply(me, arguments);
  1839. meta = me.getMeta();
  1840. meta.stack = me.getDataset().stack;
  1841. meta.bar = true;
  1842. },
  1843. update: function (reset) {
  1844. var me = this;
  1845. var rects = me.getMeta().data;
  1846. var i, ilen;
  1847. me._ruler = me.getRuler();
  1848. for (i = 0, ilen = rects.length; i < ilen; ++i) {
  1849. me.updateElement(rects[i], i, reset);
  1850. }
  1851. },
  1852. updateElement: function (rectangle, index, reset) {
  1853. var me = this;
  1854. var chart = me.chart;
  1855. var meta = me.getMeta();
  1856. var dataset = me.getDataset();
  1857. var custom = rectangle.custom || {};
  1858. var rectangleOptions = chart.options.elements.rectangle;
  1859. rectangle._xScale = me.getScaleForId(meta.xAxisID);
  1860. rectangle._yScale = me.getScaleForId(meta.yAxisID);
  1861. rectangle._datasetIndex = me.index;
  1862. rectangle._index = index;
  1863. rectangle._model = {
  1864. datasetLabel: dataset.label,
  1865. label: chart.data.labels[index],
  1866. borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleOptions.borderSkipped,
  1867. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleOptions.backgroundColor),
  1868. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleOptions.borderColor),
  1869. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleOptions.borderWidth)
  1870. };
  1871. me.updateElementGeometry(rectangle, index, reset);
  1872. rectangle.pivot();
  1873. },
  1874. /**
  1875. * @private
  1876. */
  1877. updateElementGeometry: function (rectangle, index, reset) {
  1878. var me = this;
  1879. var model = rectangle._model;
  1880. var vscale = me.getValueScale();
  1881. var base = vscale.getBasePixel();
  1882. var horizontal = vscale.isHorizontal();
  1883. var ruler = me._ruler || me.getRuler();
  1884. var vpixels = me.calculateBarValuePixels(me.index, index);
  1885. var ipixels = me.calculateBarIndexPixels(me.index, index, ruler);
  1886. model.horizontal = horizontal;
  1887. model.base = reset ? base : vpixels.base;
  1888. model.x = horizontal ? reset ? base : vpixels.head : ipixels.center;
  1889. model.y = horizontal ? ipixels.center : reset ? base : vpixels.head;
  1890. model.height = horizontal ? ipixels.size : undefined;
  1891. model.width = horizontal ? undefined : ipixels.size;
  1892. },
  1893. /**
  1894. * @private
  1895. */
  1896. getValueScaleId: function () {
  1897. return this.getMeta().yAxisID;
  1898. },
  1899. /**
  1900. * @private
  1901. */
  1902. getIndexScaleId: function () {
  1903. return this.getMeta().xAxisID;
  1904. },
  1905. /**
  1906. * @private
  1907. */
  1908. getValueScale: function () {
  1909. return this.getScaleForId(this.getValueScaleId());
  1910. },
  1911. /**
  1912. * @private
  1913. */
  1914. getIndexScale: function () {
  1915. return this.getScaleForId(this.getIndexScaleId());
  1916. },
  1917. /**
  1918. * Returns the stacks based on groups and bar visibility.
  1919. * @param {Number} [last] - The dataset index
  1920. * @returns {Array} The stack list
  1921. * @private
  1922. */
  1923. _getStacks: function (last) {
  1924. var me = this;
  1925. var chart = me.chart;
  1926. var scale = me.getIndexScale();
  1927. var stacked = scale.options.stacked;
  1928. var ilen = last === undefined ? chart.data.datasets.length : last + 1;
  1929. var stacks = [];
  1930. var i, meta;
  1931. for (i = 0; i < ilen; ++i) {
  1932. meta = chart.getDatasetMeta(i);
  1933. if (meta.bar && chart.isDatasetVisible(i) &&
  1934. (stacked === false ||
  1935. (stacked === true && stacks.indexOf(meta.stack) === -1) ||
  1936. (stacked === undefined && (meta.stack === undefined || stacks.indexOf(meta.stack) === -1)))) {
  1937. stacks.push(meta.stack);
  1938. }
  1939. }
  1940. return stacks;
  1941. },
  1942. /**
  1943. * Returns the effective number of stacks based on groups and bar visibility.
  1944. * @private
  1945. */
  1946. getStackCount: function () {
  1947. return this._getStacks().length;
  1948. },
  1949. /**
  1950. * Returns the stack index for the given dataset based on groups and bar visibility.
  1951. * @param {Number} [datasetIndex] - The dataset index
  1952. * @param {String} [name] - The stack name to find
  1953. * @returns {Number} The stack index
  1954. * @private
  1955. */
  1956. getStackIndex: function (datasetIndex, name) {
  1957. var stacks = this._getStacks(datasetIndex);
  1958. var index = (name !== undefined)
  1959. ? stacks.indexOf(name)
  1960. : -1; // indexOf returns -1 if element is not present
  1961. return (index === -1)
  1962. ? stacks.length - 1
  1963. : index;
  1964. },
  1965. /**
  1966. * @private
  1967. */
  1968. getRuler: function () {
  1969. var me = this;
  1970. var scale = me.getIndexScale();
  1971. var stackCount = me.getStackCount();
  1972. var datasetIndex = me.index;
  1973. var isHorizontal = scale.isHorizontal();
  1974. var start = isHorizontal ? scale.left : scale.top;
  1975. var end = start + (isHorizontal ? scale.width : scale.height);
  1976. var pixels = [];
  1977. var i, ilen, min;
  1978. for (i = 0, ilen = me.getMeta().data.length; i < ilen; ++i) {
  1979. pixels.push(scale.getPixelForValue(null, i, datasetIndex));
  1980. }
  1981. min = helpers.isNullOrUndef(scale.options.barThickness)
  1982. ? computeMinSampleSize(scale, pixels)
  1983. : -1;
  1984. return {
  1985. min: min,
  1986. pixels: pixels,
  1987. start: start,
  1988. end: end,
  1989. stackCount: stackCount,
  1990. scale: scale
  1991. };
  1992. },
  1993. /**
  1994. * Note: pixel values are not clamped to the scale area.
  1995. * @private
  1996. */
  1997. calculateBarValuePixels: function (datasetIndex, index) {
  1998. var me = this;
  1999. var chart = me.chart;
  2000. var meta = me.getMeta();
  2001. var scale = me.getValueScale();
  2002. var datasets = chart.data.datasets;
  2003. var value = scale.getRightValue(datasets[datasetIndex].data[index]);
  2004. var stacked = scale.options.stacked;
  2005. var stack = meta.stack;
  2006. var start = 0;
  2007. var i, imeta, ivalue, base, head, size;
  2008. if (stacked || (stacked === undefined && stack !== undefined)) {
  2009. for (i = 0; i < datasetIndex; ++i) {
  2010. imeta = chart.getDatasetMeta(i);
  2011. if (imeta.bar &&
  2012. imeta.stack === stack &&
  2013. imeta.controller.getValueScaleId() === scale.id &&
  2014. chart.isDatasetVisible(i)) {
  2015. ivalue = scale.getRightValue(datasets[i].data[index]);
  2016. if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) {
  2017. start += ivalue;
  2018. }
  2019. }
  2020. }
  2021. }
  2022. base = scale.getPixelForValue(start);
  2023. head = scale.getPixelForValue(start + value);
  2024. size = (head - base) / 2;
  2025. return {
  2026. size: size,
  2027. base: base,
  2028. head: head,
  2029. center: head + size / 2
  2030. };
  2031. },
  2032. /**
  2033. * @private
  2034. */
  2035. calculateBarIndexPixels: function (datasetIndex, index, ruler) {
  2036. var me = this;
  2037. var options = ruler.scale.options;
  2038. var range = options.barThickness === 'flex'
  2039. ? computeFlexCategoryTraits(index, ruler, options)
  2040. : computeFitCategoryTraits(index, ruler, options);
  2041. var stackIndex = me.getStackIndex(datasetIndex, me.getMeta().stack);
  2042. var center = range.start + (range.chunk * stackIndex) + (range.chunk / 2);
  2043. var size = Math.min(
  2044. helpers.valueOrDefault(options.maxBarThickness, Infinity),
  2045. range.chunk * range.ratio);
  2046. return {
  2047. base: center - size / 2,
  2048. head: center + size / 2,
  2049. center: center,
  2050. size: size
  2051. };
  2052. },
  2053. draw: function () {
  2054. var me = this;
  2055. var chart = me.chart;
  2056. var scale = me.getValueScale();
  2057. var rects = me.getMeta().data;
  2058. var dataset = me.getDataset();
  2059. var ilen = rects.length;
  2060. var i = 0;
  2061. helpers.canvas.clipArea(chart.ctx, chart.chartArea);
  2062. for (; i < ilen; ++i) {
  2063. if (!isNaN(scale.getRightValue(dataset.data[i]))) {
  2064. rects[i].draw();
  2065. }
  2066. }
  2067. helpers.canvas.unclipArea(chart.ctx);
  2068. },
  2069. setHoverStyle: function (rectangle) {
  2070. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  2071. var index = rectangle._index;
  2072. var custom = rectangle.custom || {};
  2073. var model = rectangle._model;
  2074. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  2075. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  2076. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  2077. },
  2078. removeHoverStyle: function (rectangle) {
  2079. var dataset = this.chart.data.datasets[rectangle._datasetIndex];
  2080. var index = rectangle._index;
  2081. var custom = rectangle.custom || {};
  2082. var model = rectangle._model;
  2083. var rectangleElementOptions = this.chart.options.elements.rectangle;
  2084. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleElementOptions.backgroundColor);
  2085. model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor);
  2086. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth);
  2087. }
  2088. });
  2089. Chart.controllers.horizontalBar = Chart.controllers.bar.extend({
  2090. /**
  2091. * @private
  2092. */
  2093. getValueScaleId: function () {
  2094. return this.getMeta().xAxisID;
  2095. },
  2096. /**
  2097. * @private
  2098. */
  2099. getIndexScaleId: function () {
  2100. return this.getMeta().yAxisID;
  2101. }
  2102. });
  2103. };
  2104. }, {"25": 25, "40": 40, "45": 45}], 16: [function (require, module, exports) {
  2105. 'use strict';
  2106. var defaults = require(25);
  2107. var elements = require(40);
  2108. var helpers = require(45);
  2109. defaults._set('bubble', {
  2110. hover: {
  2111. mode: 'single'
  2112. },
  2113. scales: {
  2114. xAxes: [{
  2115. type: 'linear', // bubble should probably use a linear scale by default
  2116. position: 'bottom',
  2117. id: 'x-axis-0' // need an ID so datasets can reference the scale
  2118. }],
  2119. yAxes: [{
  2120. type: 'linear',
  2121. position: 'left',
  2122. id: 'y-axis-0'
  2123. }]
  2124. },
  2125. tooltips: {
  2126. callbacks: {
  2127. title: function () {
  2128. // Title doesn't make sense for scatter since we format the data as a point
  2129. return '';
  2130. },
  2131. label: function (item, data) {
  2132. var datasetLabel = data.datasets[item.datasetIndex].label || '';
  2133. var dataPoint = data.datasets[item.datasetIndex].data[item.index];
  2134. return datasetLabel + ': (' + item.xLabel + ', ' + item.yLabel + ', ' + dataPoint.r + ')';
  2135. }
  2136. }
  2137. }
  2138. });
  2139. module.exports = function (Chart) {
  2140. Chart.controllers.bubble = Chart.DatasetController.extend({
  2141. /**
  2142. * @protected
  2143. */
  2144. dataElementType: elements.Point,
  2145. /**
  2146. * @protected
  2147. */
  2148. update: function (reset) {
  2149. var me = this;
  2150. var meta = me.getMeta();
  2151. var points = meta.data;
  2152. // Update Points
  2153. helpers.each(points, function (point, index) {
  2154. me.updateElement(point, index, reset);
  2155. });
  2156. },
  2157. /**
  2158. * @protected
  2159. */
  2160. updateElement: function (point, index, reset) {
  2161. var me = this;
  2162. var meta = me.getMeta();
  2163. var custom = point.custom || {};
  2164. var xScale = me.getScaleForId(meta.xAxisID);
  2165. var yScale = me.getScaleForId(meta.yAxisID);
  2166. var options = me._resolveElementOptions(point, index);
  2167. var data = me.getDataset().data[index];
  2168. var dsIndex = me.index;
  2169. var x = reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(typeof data === 'object' ? data : NaN, index, dsIndex);
  2170. var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(data, index, dsIndex);
  2171. point._xScale = xScale;
  2172. point._yScale = yScale;
  2173. point._options = options;
  2174. point._datasetIndex = dsIndex;
  2175. point._index = index;
  2176. point._model = {
  2177. backgroundColor: options.backgroundColor,
  2178. borderColor: options.borderColor,
  2179. borderWidth: options.borderWidth,
  2180. hitRadius: options.hitRadius,
  2181. pointStyle: options.pointStyle,
  2182. radius: reset ? 0 : options.radius,
  2183. skip: custom.skip || isNaN(x) || isNaN(y),
  2184. x: x,
  2185. y: y,
  2186. };
  2187. point.pivot();
  2188. },
  2189. /**
  2190. * @protected
  2191. */
  2192. setHoverStyle: function (point) {
  2193. var model = point._model;
  2194. var options = point._options;
  2195. model.backgroundColor = helpers.valueOrDefault(options.hoverBackgroundColor, helpers.getHoverColor(options.backgroundColor));
  2196. model.borderColor = helpers.valueOrDefault(options.hoverBorderColor, helpers.getHoverColor(options.borderColor));
  2197. model.borderWidth = helpers.valueOrDefault(options.hoverBorderWidth, options.borderWidth);
  2198. model.radius = options.radius + options.hoverRadius;
  2199. },
  2200. /**
  2201. * @protected
  2202. */
  2203. removeHoverStyle: function (point) {
  2204. var model = point._model;
  2205. var options = point._options;
  2206. model.backgroundColor = options.backgroundColor;
  2207. model.borderColor = options.borderColor;
  2208. model.borderWidth = options.borderWidth;
  2209. model.radius = options.radius;
  2210. },
  2211. /**
  2212. * @private
  2213. */
  2214. _resolveElementOptions: function (point, index) {
  2215. var me = this;
  2216. var chart = me.chart;
  2217. var datasets = chart.data.datasets;
  2218. var dataset = datasets[me.index];
  2219. var custom = point.custom || {};
  2220. var options = chart.options.elements.point;
  2221. var resolve = helpers.options.resolve;
  2222. var data = dataset.data[index];
  2223. var values = {};
  2224. var i, ilen, key;
  2225. // Scriptable options
  2226. var context = {
  2227. chart: chart,
  2228. dataIndex: index,
  2229. dataset: dataset,
  2230. datasetIndex: me.index
  2231. };
  2232. var keys = [
  2233. 'backgroundColor',
  2234. 'borderColor',
  2235. 'borderWidth',
  2236. 'hoverBackgroundColor',
  2237. 'hoverBorderColor',
  2238. 'hoverBorderWidth',
  2239. 'hoverRadius',
  2240. 'hitRadius',
  2241. 'pointStyle'
  2242. ];
  2243. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  2244. key = keys[i];
  2245. values[key] = resolve([
  2246. custom[key],
  2247. dataset[key],
  2248. options[key]
  2249. ], context, index);
  2250. }
  2251. // Custom radius resolution
  2252. values.radius = resolve([
  2253. custom.radius,
  2254. data ? data.r : undefined,
  2255. dataset.radius,
  2256. options.radius
  2257. ], context, index);
  2258. return values;
  2259. }
  2260. });
  2261. };
  2262. }, {"25": 25, "40": 40, "45": 45}], 17: [function (require, module, exports) {
  2263. 'use strict';
  2264. var defaults = require(25);
  2265. var elements = require(40);
  2266. var helpers = require(45);
  2267. defaults._set('doughnut', {
  2268. animation: {
  2269. // Boolean - Whether we animate the rotation of the Doughnut
  2270. animateRotate: true,
  2271. // Boolean - Whether we animate scaling the Doughnut from the centre
  2272. animateScale: false
  2273. },
  2274. hover: {
  2275. mode: 'single'
  2276. },
  2277. legendCallback: function (chart) {
  2278. var text = [];
  2279. text.push('<ul class="' + chart.id + '-legend">');
  2280. var data = chart.data;
  2281. var datasets = data.datasets;
  2282. var labels = data.labels;
  2283. if (datasets.length) {
  2284. for (var i = 0; i < datasets[0].data.length; ++i) {
  2285. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2286. if (labels[i]) {
  2287. text.push(labels[i]);
  2288. }
  2289. text.push('</li>');
  2290. }
  2291. }
  2292. text.push('</ul>');
  2293. return text.join('');
  2294. },
  2295. legend: {
  2296. labels: {
  2297. generateLabels: function (chart) {
  2298. var data = chart.data;
  2299. if (data.labels.length && data.datasets.length) {
  2300. return data.labels.map(function (label, i) {
  2301. var meta = chart.getDatasetMeta(0);
  2302. var ds = data.datasets[0];
  2303. var arc = meta.data[i];
  2304. var custom = arc && arc.custom || {};
  2305. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2306. var arcOpts = chart.options.elements.arc;
  2307. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2308. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2309. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2310. return {
  2311. text: label,
  2312. fillStyle: fill,
  2313. strokeStyle: stroke,
  2314. lineWidth: bw,
  2315. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2316. // Extra data used for toggling the correct item
  2317. index: i
  2318. };
  2319. });
  2320. }
  2321. return [];
  2322. }
  2323. },
  2324. onClick: function (e, legendItem) {
  2325. var index = legendItem.index;
  2326. var chart = this.chart;
  2327. var i, ilen, meta;
  2328. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2329. meta = chart.getDatasetMeta(i);
  2330. // toggle visibility of index if exists
  2331. if (meta.data[index]) {
  2332. meta.data[index].hidden = !meta.data[index].hidden;
  2333. }
  2334. }
  2335. chart.update();
  2336. }
  2337. },
  2338. // The percentage of the chart that we cut out of the middle.
  2339. cutoutPercentage: 50,
  2340. // The rotation of the chart, where the first data arc begins.
  2341. rotation: Math.PI * -0.5,
  2342. // The total circumference of the chart.
  2343. circumference: Math.PI * 2.0,
  2344. // Need to override these to give a nice default
  2345. tooltips: {
  2346. callbacks: {
  2347. title: function () {
  2348. return '';
  2349. },
  2350. label: function (tooltipItem, data) {
  2351. var dataLabel = data.labels[tooltipItem.index];
  2352. var value = ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
  2353. if (helpers.isArray(dataLabel)) {
  2354. // show value on first line of multiline label
  2355. // need to clone because we are changing the value
  2356. dataLabel = dataLabel.slice();
  2357. dataLabel[0] += value;
  2358. } else {
  2359. dataLabel += value;
  2360. }
  2361. return dataLabel;
  2362. }
  2363. }
  2364. }
  2365. });
  2366. defaults._set('pie', helpers.clone(defaults.doughnut));
  2367. defaults._set('pie', {
  2368. cutoutPercentage: 0
  2369. });
  2370. module.exports = function (Chart) {
  2371. Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
  2372. dataElementType: elements.Arc,
  2373. linkScales: helpers.noop,
  2374. // Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
  2375. getRingIndex: function (datasetIndex) {
  2376. var ringIndex = 0;
  2377. for (var j = 0; j < datasetIndex; ++j) {
  2378. if (this.chart.isDatasetVisible(j)) {
  2379. ++ringIndex;
  2380. }
  2381. }
  2382. return ringIndex;
  2383. },
  2384. update: function (reset) {
  2385. var me = this;
  2386. var chart = me.chart;
  2387. var chartArea = chart.chartArea;
  2388. var opts = chart.options;
  2389. var arcOpts = opts.elements.arc;
  2390. var availableWidth = chartArea.right - chartArea.left - arcOpts.borderWidth;
  2391. var availableHeight = chartArea.bottom - chartArea.top - arcOpts.borderWidth;
  2392. var minSize = Math.min(availableWidth, availableHeight);
  2393. var offset = {x: 0, y: 0};
  2394. var meta = me.getMeta();
  2395. var cutoutPercentage = opts.cutoutPercentage;
  2396. var circumference = opts.circumference;
  2397. // If the chart's circumference isn't a full circle, calculate minSize as a ratio of the width/height of the arc
  2398. if (circumference < Math.PI * 2.0) {
  2399. var startAngle = opts.rotation % (Math.PI * 2.0);
  2400. startAngle += Math.PI * 2.0 * (startAngle >= Math.PI ? -1 : startAngle < -Math.PI ? 1 : 0);
  2401. var endAngle = startAngle + circumference;
  2402. var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
  2403. var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
  2404. var contains0 = (startAngle <= 0 && endAngle >= 0) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
  2405. var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
  2406. var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
  2407. var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle);
  2408. var cutout = cutoutPercentage / 100.0;
  2409. 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))};
  2410. 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))};
  2411. var size = {width: (max.x - min.x) * 0.5, height: (max.y - min.y) * 0.5};
  2412. minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
  2413. offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
  2414. }
  2415. chart.borderWidth = me.getMaxBorderWidth(meta.data);
  2416. chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
  2417. chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 0, 0);
  2418. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2419. chart.offsetX = offset.x * chart.outerRadius;
  2420. chart.offsetY = offset.y * chart.outerRadius;
  2421. meta.total = me.calculateTotal();
  2422. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.getRingIndex(me.index));
  2423. me.innerRadius = Math.max(me.outerRadius - chart.radiusLength, 0);
  2424. helpers.each(meta.data, function (arc, index) {
  2425. me.updateElement(arc, index, reset);
  2426. });
  2427. },
  2428. updateElement: function (arc, index, reset) {
  2429. var me = this;
  2430. var chart = me.chart;
  2431. var chartArea = chart.chartArea;
  2432. var opts = chart.options;
  2433. var animationOpts = opts.animation;
  2434. var centerX = (chartArea.left + chartArea.right) / 2;
  2435. var centerY = (chartArea.top + chartArea.bottom) / 2;
  2436. var startAngle = opts.rotation; // non reset case handled later
  2437. var endAngle = opts.rotation; // non reset case handled later
  2438. var dataset = me.getDataset();
  2439. var circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(dataset.data[index]) * (opts.circumference / (2.0 * Math.PI));
  2440. var innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius;
  2441. var outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius;
  2442. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2443. helpers.extend(arc, {
  2444. // Utility
  2445. _datasetIndex: me.index,
  2446. _index: index,
  2447. // Desired view properties
  2448. _model: {
  2449. x: centerX + chart.offsetX,
  2450. y: centerY + chart.offsetY,
  2451. startAngle: startAngle,
  2452. endAngle: endAngle,
  2453. circumference: circumference,
  2454. outerRadius: outerRadius,
  2455. innerRadius: innerRadius,
  2456. label: valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index])
  2457. }
  2458. });
  2459. var model = arc._model;
  2460. // Resets the visual styles
  2461. this.removeHoverStyle(arc);
  2462. // Set correct angles if not resetting
  2463. if (!reset || !animationOpts.animateRotate) {
  2464. if (index === 0) {
  2465. model.startAngle = opts.rotation;
  2466. } else {
  2467. model.startAngle = me.getMeta().data[index - 1]._model.endAngle;
  2468. }
  2469. model.endAngle = model.startAngle + model.circumference;
  2470. }
  2471. arc.pivot();
  2472. },
  2473. removeHoverStyle: function (arc) {
  2474. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  2475. },
  2476. calculateTotal: function () {
  2477. var dataset = this.getDataset();
  2478. var meta = this.getMeta();
  2479. var total = 0;
  2480. var value;
  2481. helpers.each(meta.data, function (element, index) {
  2482. value = dataset.data[index];
  2483. if (!isNaN(value) && !element.hidden) {
  2484. total += Math.abs(value);
  2485. }
  2486. });
  2487. /* if (total === 0) {
  2488. total = NaN;
  2489. }*/
  2490. return total;
  2491. },
  2492. calculateCircumference: function (value) {
  2493. var total = this.getMeta().total;
  2494. if (total > 0 && !isNaN(value)) {
  2495. return (Math.PI * 2.0) * (Math.abs(value) / total);
  2496. }
  2497. return 0;
  2498. },
  2499. // gets the max border or hover width to properly scale pie charts
  2500. getMaxBorderWidth: function (arcs) {
  2501. var max = 0;
  2502. var index = this.index;
  2503. var length = arcs.length;
  2504. var borderWidth;
  2505. var hoverWidth;
  2506. for (var i = 0; i < length; i++) {
  2507. borderWidth = arcs[i]._model ? arcs[i]._model.borderWidth : 0;
  2508. hoverWidth = arcs[i]._chart ? arcs[i]._chart.config.data.datasets[index].hoverBorderWidth : 0;
  2509. max = borderWidth > max ? borderWidth : max;
  2510. max = hoverWidth > max ? hoverWidth : max;
  2511. }
  2512. return max;
  2513. }
  2514. });
  2515. };
  2516. }, {"25": 25, "40": 40, "45": 45}], 18: [function (require, module, exports) {
  2517. 'use strict';
  2518. var defaults = require(25);
  2519. var elements = require(40);
  2520. var helpers = require(45);
  2521. defaults._set('line', {
  2522. showLines: true,
  2523. spanGaps: false,
  2524. hover: {
  2525. mode: 'label'
  2526. },
  2527. scales: {
  2528. xAxes: [{
  2529. type: 'category',
  2530. id: 'x-axis-0'
  2531. }],
  2532. yAxes: [{
  2533. type: 'linear',
  2534. id: 'y-axis-0'
  2535. }]
  2536. }
  2537. });
  2538. module.exports = function (Chart) {
  2539. function lineEnabled(dataset, options) {
  2540. return helpers.valueOrDefault(dataset.showLine, options.showLines);
  2541. }
  2542. Chart.controllers.line = Chart.DatasetController.extend({
  2543. datasetElementType: elements.Line,
  2544. dataElementType: elements.Point,
  2545. update: function (reset) {
  2546. var me = this;
  2547. var meta = me.getMeta();
  2548. var line = meta.dataset;
  2549. var points = meta.data || [];
  2550. var options = me.chart.options;
  2551. var lineElementOptions = options.elements.line;
  2552. var scale = me.getScaleForId(meta.yAxisID);
  2553. var i, ilen, custom;
  2554. var dataset = me.getDataset();
  2555. var showLine = lineEnabled(dataset, options);
  2556. // Update Line
  2557. if (showLine) {
  2558. custom = line.custom || {};
  2559. // Compatibility: If the properties are defined with only the old name, use those values
  2560. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  2561. dataset.lineTension = dataset.tension;
  2562. }
  2563. // Utility
  2564. line._scale = scale;
  2565. line._datasetIndex = me.index;
  2566. // Data
  2567. line._children = points;
  2568. // Model
  2569. line._model = {
  2570. // Appearance
  2571. // The default behavior of lines is to break at null values, according
  2572. // to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
  2573. // This option gives lines the ability to span gaps
  2574. spanGaps: dataset.spanGaps ? dataset.spanGaps : options.spanGaps,
  2575. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  2576. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  2577. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  2578. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  2579. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  2580. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  2581. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  2582. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  2583. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  2584. steppedLine: custom.steppedLine ? custom.steppedLine : helpers.valueOrDefault(dataset.steppedLine, lineElementOptions.stepped),
  2585. cubicInterpolationMode: custom.cubicInterpolationMode ? custom.cubicInterpolationMode : helpers.valueOrDefault(dataset.cubicInterpolationMode, lineElementOptions.cubicInterpolationMode),
  2586. };
  2587. line.pivot();
  2588. }
  2589. // Update Points
  2590. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2591. me.updateElement(points[i], i, reset);
  2592. }
  2593. if (showLine && line._model.tension !== 0) {
  2594. me.updateBezierControlPoints();
  2595. }
  2596. // Now pivot the point for animation
  2597. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2598. points[i].pivot();
  2599. }
  2600. },
  2601. getPointBackgroundColor: function (point, index) {
  2602. var backgroundColor = this.chart.options.elements.point.backgroundColor;
  2603. var dataset = this.getDataset();
  2604. var custom = point.custom || {};
  2605. if (custom.backgroundColor) {
  2606. backgroundColor = custom.backgroundColor;
  2607. } else if (dataset.pointBackgroundColor) {
  2608. backgroundColor = helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
  2609. } else if (dataset.backgroundColor) {
  2610. backgroundColor = dataset.backgroundColor;
  2611. }
  2612. return backgroundColor;
  2613. },
  2614. getPointBorderColor: function (point, index) {
  2615. var borderColor = this.chart.options.elements.point.borderColor;
  2616. var dataset = this.getDataset();
  2617. var custom = point.custom || {};
  2618. if (custom.borderColor) {
  2619. borderColor = custom.borderColor;
  2620. } else if (dataset.pointBorderColor) {
  2621. borderColor = helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, borderColor);
  2622. } else if (dataset.borderColor) {
  2623. borderColor = dataset.borderColor;
  2624. }
  2625. return borderColor;
  2626. },
  2627. getPointBorderWidth: function (point, index) {
  2628. var borderWidth = this.chart.options.elements.point.borderWidth;
  2629. var dataset = this.getDataset();
  2630. var custom = point.custom || {};
  2631. if (!isNaN(custom.borderWidth)) {
  2632. borderWidth = custom.borderWidth;
  2633. } else if (!isNaN(dataset.pointBorderWidth) || helpers.isArray(dataset.pointBorderWidth)) {
  2634. borderWidth = helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
  2635. } else if (!isNaN(dataset.borderWidth)) {
  2636. borderWidth = dataset.borderWidth;
  2637. }
  2638. return borderWidth;
  2639. },
  2640. updateElement: function (point, index, reset) {
  2641. var me = this;
  2642. var meta = me.getMeta();
  2643. var custom = point.custom || {};
  2644. var dataset = me.getDataset();
  2645. var datasetIndex = me.index;
  2646. var value = dataset.data[index];
  2647. var yScale = me.getScaleForId(meta.yAxisID);
  2648. var xScale = me.getScaleForId(meta.xAxisID);
  2649. var pointOptions = me.chart.options.elements.point;
  2650. var x, y;
  2651. // Compatibility: If the properties are defined with only the old name, use those values
  2652. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2653. dataset.pointRadius = dataset.radius;
  2654. }
  2655. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  2656. dataset.pointHitRadius = dataset.hitRadius;
  2657. }
  2658. x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex);
  2659. y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
  2660. // Utility
  2661. point._xScale = xScale;
  2662. point._yScale = yScale;
  2663. point._datasetIndex = datasetIndex;
  2664. point._index = index;
  2665. // Desired view properties
  2666. point._model = {
  2667. x: x,
  2668. y: y,
  2669. skip: custom.skip || isNaN(x) || isNaN(y),
  2670. // Appearance
  2671. radius: custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointOptions.radius),
  2672. pointStyle: custom.pointStyle || helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointOptions.pointStyle),
  2673. backgroundColor: me.getPointBackgroundColor(point, index),
  2674. borderColor: me.getPointBorderColor(point, index),
  2675. borderWidth: me.getPointBorderWidth(point, index),
  2676. tension: meta.dataset._model ? meta.dataset._model.tension : 0,
  2677. steppedLine: meta.dataset._model ? meta.dataset._model.steppedLine : false,
  2678. // Tooltip
  2679. hitRadius: custom.hitRadius || helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointOptions.hitRadius)
  2680. };
  2681. },
  2682. calculatePointY: function (value, index, datasetIndex) {
  2683. var me = this;
  2684. var chart = me.chart;
  2685. var meta = me.getMeta();
  2686. var yScale = me.getScaleForId(meta.yAxisID);
  2687. var sumPos = 0;
  2688. var sumNeg = 0;
  2689. var i, ds, dsMeta;
  2690. if (yScale.options.stacked) {
  2691. for (i = 0; i < datasetIndex; i++) {
  2692. ds = chart.data.datasets[i];
  2693. dsMeta = chart.getDatasetMeta(i);
  2694. if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
  2695. var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
  2696. if (stackedRightValue < 0) {
  2697. sumNeg += stackedRightValue || 0;
  2698. } else {
  2699. sumPos += stackedRightValue || 0;
  2700. }
  2701. }
  2702. }
  2703. var rightValue = Number(yScale.getRightValue(value));
  2704. if (rightValue < 0) {
  2705. return yScale.getPixelForValue(sumNeg + rightValue);
  2706. }
  2707. return yScale.getPixelForValue(sumPos + rightValue);
  2708. }
  2709. return yScale.getPixelForValue(value);
  2710. },
  2711. updateBezierControlPoints: function () {
  2712. var me = this;
  2713. var meta = me.getMeta();
  2714. var area = me.chart.chartArea;
  2715. var points = (meta.data || []);
  2716. var i, ilen, point, model, controlPoints;
  2717. // Only consider points that are drawn in case the spanGaps option is used
  2718. if (meta.dataset._model.spanGaps) {
  2719. points = points.filter(function (pt) {
  2720. return !pt._model.skip;
  2721. });
  2722. }
  2723. function capControlPoint(pt, min, max) {
  2724. return Math.max(Math.min(pt, max), min);
  2725. }
  2726. if (meta.dataset._model.cubicInterpolationMode === 'monotone') {
  2727. helpers.splineCurveMonotone(points);
  2728. } else {
  2729. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2730. point = points[i];
  2731. model = point._model;
  2732. controlPoints = helpers.splineCurve(
  2733. helpers.previousItem(points, i)._model,
  2734. model,
  2735. helpers.nextItem(points, i)._model,
  2736. meta.dataset._model.tension
  2737. );
  2738. model.controlPointPreviousX = controlPoints.previous.x;
  2739. model.controlPointPreviousY = controlPoints.previous.y;
  2740. model.controlPointNextX = controlPoints.next.x;
  2741. model.controlPointNextY = controlPoints.next.y;
  2742. }
  2743. }
  2744. if (me.chart.options.elements.line.capBezierPoints) {
  2745. for (i = 0, ilen = points.length; i < ilen; ++i) {
  2746. model = points[i]._model;
  2747. model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
  2748. model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
  2749. model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
  2750. model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
  2751. }
  2752. }
  2753. },
  2754. draw: function () {
  2755. var me = this;
  2756. var chart = me.chart;
  2757. var meta = me.getMeta();
  2758. var points = meta.data || [];
  2759. var area = chart.chartArea;
  2760. var ilen = points.length;
  2761. var i = 0;
  2762. helpers.canvas.clipArea(chart.ctx, area);
  2763. if (lineEnabled(me.getDataset(), chart.options)) {
  2764. meta.dataset.draw();
  2765. }
  2766. helpers.canvas.unclipArea(chart.ctx);
  2767. // Draw the points
  2768. for (; i < ilen; ++i) {
  2769. points[i].draw(area);
  2770. }
  2771. },
  2772. setHoverStyle: function (point) {
  2773. // Point
  2774. var dataset = this.chart.data.datasets[point._datasetIndex];
  2775. var index = point._index;
  2776. var custom = point.custom || {};
  2777. var model = point._model;
  2778. model.radius = custom.hoverRadius || helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  2779. model.backgroundColor = custom.hoverBackgroundColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  2780. model.borderColor = custom.hoverBorderColor || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  2781. model.borderWidth = custom.hoverBorderWidth || helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  2782. },
  2783. removeHoverStyle: function (point) {
  2784. var me = this;
  2785. var dataset = me.chart.data.datasets[point._datasetIndex];
  2786. var index = point._index;
  2787. var custom = point.custom || {};
  2788. var model = point._model;
  2789. // Compatibility: If the properties are defined with only the old name, use those values
  2790. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  2791. dataset.pointRadius = dataset.radius;
  2792. }
  2793. model.radius = custom.radius || helpers.valueAtIndexOrDefault(dataset.pointRadius, index, me.chart.options.elements.point.radius);
  2794. model.backgroundColor = me.getPointBackgroundColor(point, index);
  2795. model.borderColor = me.getPointBorderColor(point, index);
  2796. model.borderWidth = me.getPointBorderWidth(point, index);
  2797. }
  2798. });
  2799. };
  2800. }, {"25": 25, "40": 40, "45": 45}], 19: [function (require, module, exports) {
  2801. 'use strict';
  2802. var defaults = require(25);
  2803. var elements = require(40);
  2804. var helpers = require(45);
  2805. defaults._set('polarArea', {
  2806. scale: {
  2807. type: 'radialLinear',
  2808. angleLines: {
  2809. display: false
  2810. },
  2811. gridLines: {
  2812. circular: true
  2813. },
  2814. pointLabels: {
  2815. display: false
  2816. },
  2817. ticks: {
  2818. beginAtZero: true
  2819. }
  2820. },
  2821. // Boolean - Whether to animate the rotation of the chart
  2822. animation: {
  2823. animateRotate: true,
  2824. animateScale: true
  2825. },
  2826. startAngle: -0.5 * Math.PI,
  2827. legendCallback: function (chart) {
  2828. var text = [];
  2829. text.push('<ul class="' + chart.id + '-legend">');
  2830. var data = chart.data;
  2831. var datasets = data.datasets;
  2832. var labels = data.labels;
  2833. if (datasets.length) {
  2834. for (var i = 0; i < datasets[0].data.length; ++i) {
  2835. text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>');
  2836. if (labels[i]) {
  2837. text.push(labels[i]);
  2838. }
  2839. text.push('</li>');
  2840. }
  2841. }
  2842. text.push('</ul>');
  2843. return text.join('');
  2844. },
  2845. legend: {
  2846. labels: {
  2847. generateLabels: function (chart) {
  2848. var data = chart.data;
  2849. if (data.labels.length && data.datasets.length) {
  2850. return data.labels.map(function (label, i) {
  2851. var meta = chart.getDatasetMeta(0);
  2852. var ds = data.datasets[0];
  2853. var arc = meta.data[i];
  2854. var custom = arc.custom || {};
  2855. var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  2856. var arcOpts = chart.options.elements.arc;
  2857. var fill = custom.backgroundColor ? custom.backgroundColor : valueAtIndexOrDefault(ds.backgroundColor, i, arcOpts.backgroundColor);
  2858. var stroke = custom.borderColor ? custom.borderColor : valueAtIndexOrDefault(ds.borderColor, i, arcOpts.borderColor);
  2859. var bw = custom.borderWidth ? custom.borderWidth : valueAtIndexOrDefault(ds.borderWidth, i, arcOpts.borderWidth);
  2860. return {
  2861. text: label,
  2862. fillStyle: fill,
  2863. strokeStyle: stroke,
  2864. lineWidth: bw,
  2865. hidden: isNaN(ds.data[i]) || meta.data[i].hidden,
  2866. // Extra data used for toggling the correct item
  2867. index: i
  2868. };
  2869. });
  2870. }
  2871. return [];
  2872. }
  2873. },
  2874. onClick: function (e, legendItem) {
  2875. var index = legendItem.index;
  2876. var chart = this.chart;
  2877. var i, ilen, meta;
  2878. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  2879. meta = chart.getDatasetMeta(i);
  2880. meta.data[index].hidden = !meta.data[index].hidden;
  2881. }
  2882. chart.update();
  2883. }
  2884. },
  2885. // Need to override these to give a nice default
  2886. tooltips: {
  2887. callbacks: {
  2888. title: function () {
  2889. return '';
  2890. },
  2891. label: function (item, data) {
  2892. return data.labels[item.index] + ': ' + item.yLabel;
  2893. }
  2894. }
  2895. }
  2896. });
  2897. module.exports = function (Chart) {
  2898. Chart.controllers.polarArea = Chart.DatasetController.extend({
  2899. dataElementType: elements.Arc,
  2900. linkScales: helpers.noop,
  2901. update: function (reset) {
  2902. var me = this;
  2903. var chart = me.chart;
  2904. var chartArea = chart.chartArea;
  2905. var meta = me.getMeta();
  2906. var opts = chart.options;
  2907. var arcOpts = opts.elements.arc;
  2908. var minSize = Math.min(chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
  2909. chart.outerRadius = Math.max((minSize - arcOpts.borderWidth / 2) / 2, 0);
  2910. chart.innerRadius = Math.max(opts.cutoutPercentage ? (chart.outerRadius / 100) * (opts.cutoutPercentage) : 1, 0);
  2911. chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
  2912. me.outerRadius = chart.outerRadius - (chart.radiusLength * me.index);
  2913. me.innerRadius = me.outerRadius - chart.radiusLength;
  2914. meta.count = me.countVisibleElements();
  2915. helpers.each(meta.data, function (arc, index) {
  2916. me.updateElement(arc, index, reset);
  2917. });
  2918. },
  2919. updateElement: function (arc, index, reset) {
  2920. var me = this;
  2921. var chart = me.chart;
  2922. var dataset = me.getDataset();
  2923. var opts = chart.options;
  2924. var animationOpts = opts.animation;
  2925. var scale = chart.scale;
  2926. var labels = chart.data.labels;
  2927. var circumference = me.calculateCircumference(dataset.data[index]);
  2928. var centerX = scale.xCenter;
  2929. var centerY = scale.yCenter;
  2930. // If there is NaN data before us, we need to calculate the starting angle correctly.
  2931. // We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
  2932. var visibleCount = 0;
  2933. var meta = me.getMeta();
  2934. for (var i = 0; i < index; ++i) {
  2935. if (!isNaN(dataset.data[i]) && !meta.data[i].hidden) {
  2936. ++visibleCount;
  2937. }
  2938. }
  2939. // var negHalfPI = -0.5 * Math.PI;
  2940. var datasetStartAngle = opts.startAngle;
  2941. var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2942. var startAngle = datasetStartAngle + (circumference * visibleCount);
  2943. var endAngle = startAngle + (arc.hidden ? 0 : circumference);
  2944. var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
  2945. helpers.extend(arc, {
  2946. // Utility
  2947. _datasetIndex: me.index,
  2948. _index: index,
  2949. _scale: scale,
  2950. // Desired view properties
  2951. _model: {
  2952. x: centerX,
  2953. y: centerY,
  2954. innerRadius: 0,
  2955. outerRadius: reset ? resetRadius : distance,
  2956. startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle,
  2957. endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle,
  2958. label: helpers.valueAtIndexOrDefault(labels, index, labels[index])
  2959. }
  2960. });
  2961. // Apply border and fill style
  2962. me.removeHoverStyle(arc);
  2963. arc.pivot();
  2964. },
  2965. removeHoverStyle: function (arc) {
  2966. Chart.DatasetController.prototype.removeHoverStyle.call(this, arc, this.chart.options.elements.arc);
  2967. },
  2968. countVisibleElements: function () {
  2969. var dataset = this.getDataset();
  2970. var meta = this.getMeta();
  2971. var count = 0;
  2972. helpers.each(meta.data, function (element, index) {
  2973. if (!isNaN(dataset.data[index]) && !element.hidden) {
  2974. count++;
  2975. }
  2976. });
  2977. return count;
  2978. },
  2979. calculateCircumference: function (value) {
  2980. var count = this.getMeta().count;
  2981. if (count > 0 && !isNaN(value)) {
  2982. return (2 * Math.PI) / count;
  2983. }
  2984. return 0;
  2985. }
  2986. });
  2987. };
  2988. }, {"25": 25, "40": 40, "45": 45}], 20: [function (require, module, exports) {
  2989. 'use strict';
  2990. var defaults = require(25);
  2991. var elements = require(40);
  2992. var helpers = require(45);
  2993. defaults._set('radar', {
  2994. scale: {
  2995. type: 'radialLinear'
  2996. },
  2997. elements: {
  2998. line: {
  2999. tension: 0 // no bezier in radar
  3000. }
  3001. }
  3002. });
  3003. module.exports = function (Chart) {
  3004. Chart.controllers.radar = Chart.DatasetController.extend({
  3005. datasetElementType: elements.Line,
  3006. dataElementType: elements.Point,
  3007. linkScales: helpers.noop,
  3008. update: function (reset) {
  3009. var me = this;
  3010. var meta = me.getMeta();
  3011. var line = meta.dataset;
  3012. var points = meta.data;
  3013. var custom = line.custom || {};
  3014. var dataset = me.getDataset();
  3015. var lineElementOptions = me.chart.options.elements.line;
  3016. var scale = me.chart.scale;
  3017. // Compatibility: If the properties are defined with only the old name, use those values
  3018. if ((dataset.tension !== undefined) && (dataset.lineTension === undefined)) {
  3019. dataset.lineTension = dataset.tension;
  3020. }
  3021. helpers.extend(meta.dataset, {
  3022. // Utility
  3023. _datasetIndex: me.index,
  3024. _scale: scale,
  3025. // Data
  3026. _children: points,
  3027. _loop: true,
  3028. // Model
  3029. _model: {
  3030. // Appearance
  3031. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, lineElementOptions.tension),
  3032. backgroundColor: custom.backgroundColor ? custom.backgroundColor : (dataset.backgroundColor || lineElementOptions.backgroundColor),
  3033. borderWidth: custom.borderWidth ? custom.borderWidth : (dataset.borderWidth || lineElementOptions.borderWidth),
  3034. borderColor: custom.borderColor ? custom.borderColor : (dataset.borderColor || lineElementOptions.borderColor),
  3035. fill: custom.fill ? custom.fill : (dataset.fill !== undefined ? dataset.fill : lineElementOptions.fill),
  3036. borderCapStyle: custom.borderCapStyle ? custom.borderCapStyle : (dataset.borderCapStyle || lineElementOptions.borderCapStyle),
  3037. borderDash: custom.borderDash ? custom.borderDash : (dataset.borderDash || lineElementOptions.borderDash),
  3038. borderDashOffset: custom.borderDashOffset ? custom.borderDashOffset : (dataset.borderDashOffset || lineElementOptions.borderDashOffset),
  3039. borderJoinStyle: custom.borderJoinStyle ? custom.borderJoinStyle : (dataset.borderJoinStyle || lineElementOptions.borderJoinStyle),
  3040. }
  3041. });
  3042. meta.dataset.pivot();
  3043. // Update Points
  3044. helpers.each(points, function (point, index) {
  3045. me.updateElement(point, index, reset);
  3046. }, me);
  3047. // Update bezier control points
  3048. me.updateBezierControlPoints();
  3049. },
  3050. updateElement: function (point, index, reset) {
  3051. var me = this;
  3052. var custom = point.custom || {};
  3053. var dataset = me.getDataset();
  3054. var scale = me.chart.scale;
  3055. var pointElementOptions = me.chart.options.elements.point;
  3056. var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
  3057. // Compatibility: If the properties are defined with only the old name, use those values
  3058. if ((dataset.radius !== undefined) && (dataset.pointRadius === undefined)) {
  3059. dataset.pointRadius = dataset.radius;
  3060. }
  3061. if ((dataset.hitRadius !== undefined) && (dataset.pointHitRadius === undefined)) {
  3062. dataset.pointHitRadius = dataset.hitRadius;
  3063. }
  3064. helpers.extend(point, {
  3065. // Utility
  3066. _datasetIndex: me.index,
  3067. _index: index,
  3068. _scale: scale,
  3069. // Desired view properties
  3070. _model: {
  3071. x: reset ? scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
  3072. y: reset ? scale.yCenter : pointPosition.y,
  3073. // Appearance
  3074. tension: custom.tension ? custom.tension : helpers.valueOrDefault(dataset.lineTension, me.chart.options.elements.line.tension),
  3075. radius: custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius),
  3076. backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor),
  3077. borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor),
  3078. borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth),
  3079. pointStyle: custom.pointStyle ? custom.pointStyle : helpers.valueAtIndexOrDefault(dataset.pointStyle, index, pointElementOptions.pointStyle),
  3080. // Tooltip
  3081. hitRadius: custom.hitRadius ? custom.hitRadius : helpers.valueAtIndexOrDefault(dataset.pointHitRadius, index, pointElementOptions.hitRadius)
  3082. }
  3083. });
  3084. point._model.skip = custom.skip ? custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
  3085. },
  3086. updateBezierControlPoints: function () {
  3087. var chartArea = this.chart.chartArea;
  3088. var meta = this.getMeta();
  3089. helpers.each(meta.data, function (point, index) {
  3090. var model = point._model;
  3091. var controlPoints = helpers.splineCurve(
  3092. helpers.previousItem(meta.data, index, true)._model,
  3093. model,
  3094. helpers.nextItem(meta.data, index, true)._model,
  3095. model.tension
  3096. );
  3097. // Prevent the bezier going outside of the bounds of the graph
  3098. model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, chartArea.right), chartArea.left);
  3099. model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, chartArea.bottom), chartArea.top);
  3100. model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, chartArea.right), chartArea.left);
  3101. model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, chartArea.bottom), chartArea.top);
  3102. // Now pivot the point for animation
  3103. point.pivot();
  3104. });
  3105. },
  3106. setHoverStyle: function (point) {
  3107. // Point
  3108. var dataset = this.chart.data.datasets[point._datasetIndex];
  3109. var custom = point.custom || {};
  3110. var index = point._index;
  3111. var model = point._model;
  3112. model.radius = custom.hoverRadius ? custom.hoverRadius : helpers.valueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
  3113. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.getHoverColor(model.backgroundColor));
  3114. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.getHoverColor(model.borderColor));
  3115. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : helpers.valueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, model.borderWidth);
  3116. },
  3117. removeHoverStyle: function (point) {
  3118. var dataset = this.chart.data.datasets[point._datasetIndex];
  3119. var custom = point.custom || {};
  3120. var index = point._index;
  3121. var model = point._model;
  3122. var pointElementOptions = this.chart.options.elements.point;
  3123. model.radius = custom.radius ? custom.radius : helpers.valueAtIndexOrDefault(dataset.pointRadius, index, pointElementOptions.radius);
  3124. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.pointBackgroundColor, index, pointElementOptions.backgroundColor);
  3125. model.borderColor = custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.pointBorderColor, index, pointElementOptions.borderColor);
  3126. model.borderWidth = custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, pointElementOptions.borderWidth);
  3127. }
  3128. });
  3129. };
  3130. }, {"25": 25, "40": 40, "45": 45}], 21: [function (require, module, exports) {
  3131. 'use strict';
  3132. var defaults = require(25);
  3133. defaults._set('scatter', {
  3134. hover: {
  3135. mode: 'single'
  3136. },
  3137. scales: {
  3138. xAxes: [{
  3139. id: 'x-axis-1', // need an ID so datasets can reference the scale
  3140. type: 'linear', // scatter should not use a category axis
  3141. position: 'bottom'
  3142. }],
  3143. yAxes: [{
  3144. id: 'y-axis-1',
  3145. type: 'linear',
  3146. position: 'left'
  3147. }]
  3148. },
  3149. showLines: false,
  3150. tooltips: {
  3151. callbacks: {
  3152. title: function () {
  3153. return ''; // doesn't make sense for scatter since data are formatted as a point
  3154. },
  3155. label: function (item) {
  3156. return '(' + item.xLabel + ', ' + item.yLabel + ')';
  3157. }
  3158. }
  3159. }
  3160. });
  3161. module.exports = function (Chart) {
  3162. // Scatter charts use line controllers
  3163. Chart.controllers.scatter = Chart.controllers.line;
  3164. };
  3165. }, {"25": 25}], 22: [function (require, module, exports) {
  3166. /* global window: false */
  3167. 'use strict';
  3168. var defaults = require(25);
  3169. var Element = require(26);
  3170. var helpers = require(45);
  3171. defaults._set('global', {
  3172. animation: {
  3173. duration: 1000,
  3174. easing: 'easeOutQuart',
  3175. onProgress: helpers.noop,
  3176. onComplete: helpers.noop
  3177. }
  3178. });
  3179. module.exports = function (Chart) {
  3180. Chart.Animation = Element.extend({
  3181. chart: null, // the animation associated chart instance
  3182. currentStep: 0, // the current animation step
  3183. numSteps: 60, // default number of steps
  3184. easing: '', // the easing to use for this animation
  3185. render: null, // render function used by the animation service
  3186. onAnimationProgress: null, // user specified callback to fire on each step of the animation
  3187. onAnimationComplete: null, // user specified callback to fire when the animation finishes
  3188. });
  3189. Chart.animationService = {
  3190. frameDuration: 17,
  3191. animations: [],
  3192. dropFrames: 0,
  3193. request: null,
  3194. /**
  3195. * @param {Chart} chart - The chart to animate.
  3196. * @param {Chart.Animation} animation - The animation that we will animate.
  3197. * @param {Number} duration - The animation duration in ms.
  3198. * @param {Boolean} lazy - if true, the chart is not marked as animating to enable more responsive interactions
  3199. */
  3200. addAnimation: function (chart, animation, duration, lazy) {
  3201. var animations = this.animations;
  3202. var i, ilen;
  3203. animation.chart = chart;
  3204. if (!lazy) {
  3205. chart.animating = true;
  3206. }
  3207. for (i = 0, ilen = animations.length; i < ilen; ++i) {
  3208. if (animations[i].chart === chart) {
  3209. animations[i] = animation;
  3210. return;
  3211. }
  3212. }
  3213. animations.push(animation);
  3214. // If there are no animations queued, manually kickstart a digest, for lack of a better word
  3215. if (animations.length === 1) {
  3216. this.requestAnimationFrame();
  3217. }
  3218. },
  3219. cancelAnimation: function (chart) {
  3220. var index = helpers.findIndex(this.animations, function (animation) {
  3221. return animation.chart === chart;
  3222. });
  3223. if (index !== -1) {
  3224. this.animations.splice(index, 1);
  3225. chart.animating = false;
  3226. }
  3227. },
  3228. requestAnimationFrame: function () {
  3229. var me = this;
  3230. if (me.request === null) {
  3231. // Skip animation frame requests until the active one is executed.
  3232. // This can happen when processing mouse events, e.g. 'mousemove'
  3233. // and 'mouseout' events will trigger multiple renders.
  3234. me.request = helpers.requestAnimFrame.call(window, function () {
  3235. me.request = null;
  3236. me.startDigest();
  3237. });
  3238. }
  3239. },
  3240. /**
  3241. * @private
  3242. */
  3243. startDigest: function () {
  3244. var me = this;
  3245. var startTime = Date.now();
  3246. var framesToDrop = 0;
  3247. if (me.dropFrames > 1) {
  3248. framesToDrop = Math.floor(me.dropFrames);
  3249. me.dropFrames = me.dropFrames % 1;
  3250. }
  3251. me.advance(1 + framesToDrop);
  3252. var endTime = Date.now();
  3253. me.dropFrames += (endTime - startTime) / me.frameDuration;
  3254. // Do we have more stuff to animate?
  3255. if (me.animations.length > 0) {
  3256. me.requestAnimationFrame();
  3257. }
  3258. },
  3259. /**
  3260. * @private
  3261. */
  3262. advance: function (count) {
  3263. var animations = this.animations;
  3264. var animation, chart;
  3265. var i = 0;
  3266. while (i < animations.length) {
  3267. animation = animations[i];
  3268. chart = animation.chart;
  3269. animation.currentStep = (animation.currentStep || 0) + count;
  3270. animation.currentStep = Math.min(animation.currentStep, animation.numSteps);
  3271. helpers.callback(animation.render, [chart, animation], chart);
  3272. helpers.callback(animation.onAnimationProgress, [animation], chart);
  3273. if (animation.currentStep >= animation.numSteps) {
  3274. helpers.callback(animation.onAnimationComplete, [animation], chart);
  3275. chart.animating = false;
  3276. animations.splice(i, 1);
  3277. } else {
  3278. ++i;
  3279. }
  3280. }
  3281. }
  3282. };
  3283. /**
  3284. * Provided for backward compatibility, use Chart.Animation instead
  3285. * @prop Chart.Animation#animationObject
  3286. * @deprecated since version 2.6.0
  3287. * @todo remove at version 3
  3288. */
  3289. Object.defineProperty(Chart.Animation.prototype, 'animationObject', {
  3290. get: function () {
  3291. return this;
  3292. }
  3293. });
  3294. /**
  3295. * Provided for backward compatibility, use Chart.Animation#chart instead
  3296. * @prop Chart.Animation#chartInstance
  3297. * @deprecated since version 2.6.0
  3298. * @todo remove at version 3
  3299. */
  3300. Object.defineProperty(Chart.Animation.prototype, 'chartInstance', {
  3301. get: function () {
  3302. return this.chart;
  3303. },
  3304. set: function (value) {
  3305. this.chart = value;
  3306. }
  3307. });
  3308. };
  3309. }, {"25": 25, "26": 26, "45": 45}], 23: [function (require, module, exports) {
  3310. 'use strict';
  3311. var defaults = require(25);
  3312. var helpers = require(45);
  3313. var Interaction = require(28);
  3314. var layouts = require(30);
  3315. var platform = require(48);
  3316. var plugins = require(31);
  3317. module.exports = function (Chart) {
  3318. // Create a dictionary of chart types, to allow for extension of existing types
  3319. Chart.types = {};
  3320. // Store a reference to each instance - allowing us to globally resize chart instances on window resize.
  3321. // Destroy method on the chart will remove the instance of the chart from this reference.
  3322. Chart.instances = {};
  3323. // Controllers available for dataset visualization eg. bar, line, slice, etc.
  3324. Chart.controllers = {};
  3325. /**
  3326. * Initializes the given config with global and chart default values.
  3327. */
  3328. function initConfig(config) {
  3329. config = config || {};
  3330. // Do NOT use configMerge() for the data object because this method merges arrays
  3331. // and so would change references to labels and datasets, preventing data updates.
  3332. var data = config.data = config.data || {};
  3333. data.datasets = data.datasets || [];
  3334. data.labels = data.labels || [];
  3335. config.options = helpers.configMerge(
  3336. defaults.global,
  3337. defaults[config.type],
  3338. config.options || {});
  3339. return config;
  3340. }
  3341. /**
  3342. * Updates the config of the chart
  3343. * @param chart {Chart} chart to update the options for
  3344. */
  3345. function updateConfig(chart) {
  3346. var newOptions = chart.options;
  3347. helpers.each(chart.scales, function (scale) {
  3348. layouts.removeBox(chart, scale);
  3349. });
  3350. newOptions = helpers.configMerge(
  3351. Chart.defaults.global,
  3352. Chart.defaults[chart.config.type],
  3353. newOptions);
  3354. chart.options = chart.config.options = newOptions;
  3355. chart.ensureScalesHaveIDs();
  3356. chart.buildOrUpdateScales();
  3357. // Tooltip
  3358. chart.tooltip._options = newOptions.tooltips;
  3359. chart.tooltip.initialize();
  3360. }
  3361. function positionIsHorizontal(position) {
  3362. return position === 'top' || position === 'bottom';
  3363. }
  3364. helpers.extend(Chart.prototype, /** @lends Chart */ {
  3365. /**
  3366. * @private
  3367. */
  3368. construct: function (item, config) {
  3369. var me = this;
  3370. config = initConfig(config);
  3371. var context = platform.acquireContext(item, config);
  3372. var canvas = context && context.canvas;
  3373. var height = canvas && canvas.height;
  3374. var width = canvas && canvas.width;
  3375. me.id = helpers.uid();
  3376. me.ctx = context;
  3377. me.canvas = canvas;
  3378. me.config = config;
  3379. me.width = width;
  3380. me.height = height;
  3381. me.aspectRatio = height ? width / height : null;
  3382. me.options = config.options;
  3383. me._bufferedRender = false;
  3384. /**
  3385. * Provided for backward compatibility, Chart and Chart.Controller have been merged,
  3386. * the "instance" still need to be defined since it might be called from plugins.
  3387. * @prop Chart#chart
  3388. * @deprecated since version 2.6.0
  3389. * @todo remove at version 3
  3390. * @private
  3391. */
  3392. me.chart = me;
  3393. me.controller = me; // chart.chart.controller #inception
  3394. // Add the chart instance to the global namespace
  3395. Chart.instances[me.id] = me;
  3396. // Define alias to the config data: `chart.data === chart.config.data`
  3397. Object.defineProperty(me, 'data', {
  3398. get: function () {
  3399. return me.config.data;
  3400. },
  3401. set: function (value) {
  3402. me.config.data = value;
  3403. }
  3404. });
  3405. if (!context || !canvas) {
  3406. // The given item is not a compatible context2d element, let's return before finalizing
  3407. // the chart initialization but after setting basic chart / controller properties that
  3408. // can help to figure out that the chart is not valid (e.g chart.canvas !== null);
  3409. // https://github.com/chartjs/Chart.js/issues/2807
  3410. console.error("Failed to create chart: can't acquire context from the given item");
  3411. return;
  3412. }
  3413. me.initialize();
  3414. me.update();
  3415. },
  3416. /**
  3417. * @private
  3418. */
  3419. initialize: function () {
  3420. var me = this;
  3421. // Before init plugin notification
  3422. plugins.notify(me, 'beforeInit');
  3423. helpers.retinaScale(me, me.options.devicePixelRatio);
  3424. me.bindEvents();
  3425. if (me.options.responsive) {
  3426. // Initial resize before chart draws (must be silent to preserve initial animations).
  3427. me.resize(true);
  3428. }
  3429. // Make sure scales have IDs and are built before we build any controllers.
  3430. me.ensureScalesHaveIDs();
  3431. me.buildOrUpdateScales();
  3432. me.initToolTip();
  3433. // After init plugin notification
  3434. plugins.notify(me, 'afterInit');
  3435. return me;
  3436. },
  3437. clear: function () {
  3438. helpers.canvas.clear(this);
  3439. return this;
  3440. },
  3441. stop: function () {
  3442. // Stops any current animation loop occurring
  3443. Chart.animationService.cancelAnimation(this);
  3444. return this;
  3445. },
  3446. resize: function (silent) {
  3447. var me = this;
  3448. var options = me.options;
  3449. var canvas = me.canvas;
  3450. var aspectRatio = (options.maintainAspectRatio && me.aspectRatio) || null;
  3451. // the canvas render width and height will be casted to integers so make sure that
  3452. // the canvas display style uses the same integer values to avoid blurring effect.
  3453. // Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collased
  3454. var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
  3455. var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas)));
  3456. if (me.width === newWidth && me.height === newHeight) {
  3457. return;
  3458. }
  3459. canvas.width = me.width = newWidth;
  3460. canvas.height = me.height = newHeight;
  3461. canvas.style.width = newWidth + 'px';
  3462. canvas.style.height = newHeight + 'px';
  3463. helpers.retinaScale(me, options.devicePixelRatio);
  3464. if (!silent) {
  3465. // Notify any plugins about the resize
  3466. var newSize = {width: newWidth, height: newHeight};
  3467. plugins.notify(me, 'resize', [newSize]);
  3468. // Notify of resize
  3469. if (me.options.onResize) {
  3470. me.options.onResize(me, newSize);
  3471. }
  3472. me.stop();
  3473. me.update(me.options.responsiveAnimationDuration);
  3474. }
  3475. },
  3476. ensureScalesHaveIDs: function () {
  3477. var options = this.options;
  3478. var scalesOptions = options.scales || {};
  3479. var scaleOptions = options.scale;
  3480. helpers.each(scalesOptions.xAxes, function (xAxisOptions, index) {
  3481. xAxisOptions.id = xAxisOptions.id || ('x-axis-' + index);
  3482. });
  3483. helpers.each(scalesOptions.yAxes, function (yAxisOptions, index) {
  3484. yAxisOptions.id = yAxisOptions.id || ('y-axis-' + index);
  3485. });
  3486. if (scaleOptions) {
  3487. scaleOptions.id = scaleOptions.id || 'scale';
  3488. }
  3489. },
  3490. /**
  3491. * Builds a map of scale ID to scale object for future lookup.
  3492. */
  3493. buildOrUpdateScales: function () {
  3494. var me = this;
  3495. var options = me.options;
  3496. var scales = me.scales || {};
  3497. var items = [];
  3498. var updated = Object.keys(scales).reduce(function (obj, id) {
  3499. obj[id] = false;
  3500. return obj;
  3501. }, {});
  3502. if (options.scales) {
  3503. items = items.concat(
  3504. (options.scales.xAxes || []).map(function (xAxisOptions) {
  3505. return {options: xAxisOptions, dtype: 'category', dposition: 'bottom'};
  3506. }),
  3507. (options.scales.yAxes || []).map(function (yAxisOptions) {
  3508. return {options: yAxisOptions, dtype: 'linear', dposition: 'left'};
  3509. })
  3510. );
  3511. }
  3512. if (options.scale) {
  3513. items.push({
  3514. options: options.scale,
  3515. dtype: 'radialLinear',
  3516. isDefault: true,
  3517. dposition: 'chartArea'
  3518. });
  3519. }
  3520. helpers.each(items, function (item) {
  3521. var scaleOptions = item.options;
  3522. var id = scaleOptions.id;
  3523. var scaleType = helpers.valueOrDefault(scaleOptions.type, item.dtype);
  3524. if (positionIsHorizontal(scaleOptions.position) !== positionIsHorizontal(item.dposition)) {
  3525. scaleOptions.position = item.dposition;
  3526. }
  3527. updated[id] = true;
  3528. var scale = null;
  3529. if (id in scales && scales[id].type === scaleType) {
  3530. scale = scales[id];
  3531. scale.options = scaleOptions;
  3532. scale.ctx = me.ctx;
  3533. scale.chart = me;
  3534. } else {
  3535. var scaleClass = Chart.scaleService.getScaleConstructor(scaleType);
  3536. if (!scaleClass) {
  3537. return;
  3538. }
  3539. scale = new scaleClass({
  3540. id: id,
  3541. type: scaleType,
  3542. options: scaleOptions,
  3543. ctx: me.ctx,
  3544. chart: me
  3545. });
  3546. scales[scale.id] = scale;
  3547. }
  3548. scale.mergeTicksOptions();
  3549. // TODO(SB): I think we should be able to remove this custom case (options.scale)
  3550. // and consider it as a regular scale part of the "scales"" map only! This would
  3551. // make the logic easier and remove some useless? custom code.
  3552. if (item.isDefault) {
  3553. me.scale = scale;
  3554. }
  3555. });
  3556. // clear up discarded scales
  3557. helpers.each(updated, function (hasUpdated, id) {
  3558. if (!hasUpdated) {
  3559. delete scales[id];
  3560. }
  3561. });
  3562. me.scales = scales;
  3563. Chart.scaleService.addScalesToLayout(this);
  3564. },
  3565. buildOrUpdateControllers: function () {
  3566. var me = this;
  3567. var types = [];
  3568. var newControllers = [];
  3569. helpers.each(me.data.datasets, function (dataset, datasetIndex) {
  3570. var meta = me.getDatasetMeta(datasetIndex);
  3571. var type = dataset.type || me.config.type;
  3572. if (meta.type && meta.type !== type) {
  3573. me.destroyDatasetMeta(datasetIndex);
  3574. meta = me.getDatasetMeta(datasetIndex);
  3575. }
  3576. meta.type = type;
  3577. types.push(meta.type);
  3578. if (meta.controller) {
  3579. meta.controller.updateIndex(datasetIndex);
  3580. meta.controller.linkScales();
  3581. } else {
  3582. var ControllerClass = Chart.controllers[meta.type];
  3583. if (ControllerClass === undefined) {
  3584. throw new Error('"' + meta.type + '" is not a chart type.');
  3585. }
  3586. meta.controller = new ControllerClass(me, datasetIndex);
  3587. newControllers.push(meta.controller);
  3588. }
  3589. }, me);
  3590. return newControllers;
  3591. },
  3592. /**
  3593. * Reset the elements of all datasets
  3594. * @private
  3595. */
  3596. resetElements: function () {
  3597. var me = this;
  3598. helpers.each(me.data.datasets, function (dataset, datasetIndex) {
  3599. me.getDatasetMeta(datasetIndex).controller.reset();
  3600. }, me);
  3601. },
  3602. /**
  3603. * Resets the chart back to it's state before the initial animation
  3604. */
  3605. reset: function () {
  3606. this.resetElements();
  3607. this.tooltip.initialize();
  3608. },
  3609. update: function (config) {
  3610. var me = this;
  3611. if (!config || typeof config !== 'object') {
  3612. // backwards compatibility
  3613. config = {
  3614. duration: config,
  3615. lazy: arguments[1]
  3616. };
  3617. }
  3618. updateConfig(me);
  3619. // plugins options references might have change, let's invalidate the cache
  3620. // https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  3621. plugins._invalidate(me);
  3622. if (plugins.notify(me, 'beforeUpdate') === false) {
  3623. return;
  3624. }
  3625. // In case the entire data object changed
  3626. me.tooltip._data = me.data;
  3627. // Make sure dataset controllers are updated and new controllers are reset
  3628. var newControllers = me.buildOrUpdateControllers();
  3629. // Make sure all dataset controllers have correct meta data counts
  3630. helpers.each(me.data.datasets, function (dataset, datasetIndex) {
  3631. me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
  3632. }, me);
  3633. me.updateLayout();
  3634. // Can only reset the new controllers after the scales have been updated
  3635. if (me.options.animation && me.options.animation.duration) {
  3636. helpers.each(newControllers, function (controller) {
  3637. controller.reset();
  3638. });
  3639. }
  3640. me.updateDatasets();
  3641. // Need to reset tooltip in case it is displayed with elements that are removed
  3642. // after update.
  3643. me.tooltip.initialize();
  3644. // Last active contains items that were previously in the tooltip.
  3645. // When we reset the tooltip, we need to clear it
  3646. me.lastActive = [];
  3647. // Do this before render so that any plugins that need final scale updates can use it
  3648. plugins.notify(me, 'afterUpdate');
  3649. if (me._bufferedRender) {
  3650. me._bufferedRequest = {
  3651. duration: config.duration,
  3652. easing: config.easing,
  3653. lazy: config.lazy
  3654. };
  3655. } else {
  3656. me.render(config);
  3657. }
  3658. },
  3659. /**
  3660. * Updates the chart layout unless a plugin returns `false` to the `beforeLayout`
  3661. * hook, in which case, plugins will not be called on `afterLayout`.
  3662. * @private
  3663. */
  3664. updateLayout: function () {
  3665. var me = this;
  3666. if (plugins.notify(me, 'beforeLayout') === false) {
  3667. return;
  3668. }
  3669. layouts.update(this, this.width, this.height);
  3670. /**
  3671. * Provided for backward compatibility, use `afterLayout` instead.
  3672. * @method IPlugin#afterScaleUpdate
  3673. * @deprecated since version 2.5.0
  3674. * @todo remove at version 3
  3675. * @private
  3676. */
  3677. plugins.notify(me, 'afterScaleUpdate');
  3678. plugins.notify(me, 'afterLayout');
  3679. },
  3680. /**
  3681. * Updates all datasets unless a plugin returns `false` to the `beforeDatasetsUpdate`
  3682. * hook, in which case, plugins will not be called on `afterDatasetsUpdate`.
  3683. * @private
  3684. */
  3685. updateDatasets: function () {
  3686. var me = this;
  3687. if (plugins.notify(me, 'beforeDatasetsUpdate') === false) {
  3688. return;
  3689. }
  3690. for (var i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3691. me.updateDataset(i);
  3692. }
  3693. plugins.notify(me, 'afterDatasetsUpdate');
  3694. },
  3695. /**
  3696. * Updates dataset at index unless a plugin returns `false` to the `beforeDatasetUpdate`
  3697. * hook, in which case, plugins will not be called on `afterDatasetUpdate`.
  3698. * @private
  3699. */
  3700. updateDataset: function (index) {
  3701. var me = this;
  3702. var meta = me.getDatasetMeta(index);
  3703. var args = {
  3704. meta: meta,
  3705. index: index
  3706. };
  3707. if (plugins.notify(me, 'beforeDatasetUpdate', [args]) === false) {
  3708. return;
  3709. }
  3710. meta.controller.update();
  3711. plugins.notify(me, 'afterDatasetUpdate', [args]);
  3712. },
  3713. render: function (config) {
  3714. var me = this;
  3715. if (!config || typeof config !== 'object') {
  3716. // backwards compatibility
  3717. config = {
  3718. duration: config,
  3719. lazy: arguments[1]
  3720. };
  3721. }
  3722. var duration = config.duration;
  3723. var lazy = config.lazy;
  3724. if (plugins.notify(me, 'beforeRender') === false) {
  3725. return;
  3726. }
  3727. var animationOptions = me.options.animation;
  3728. var onComplete = function (animation) {
  3729. plugins.notify(me, 'afterRender');
  3730. helpers.callback(animationOptions && animationOptions.onComplete, [animation], me);
  3731. };
  3732. if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
  3733. var animation = new Chart.Animation({
  3734. numSteps: (duration || animationOptions.duration) / 16.66, // 60 fps
  3735. easing: config.easing || animationOptions.easing,
  3736. render: function (chart, animationObject) {
  3737. var easingFunction = helpers.easing.effects[animationObject.easing];
  3738. var currentStep = animationObject.currentStep;
  3739. var stepDecimal = currentStep / animationObject.numSteps;
  3740. chart.draw(easingFunction(stepDecimal), stepDecimal, currentStep);
  3741. },
  3742. onAnimationProgress: animationOptions.onProgress,
  3743. onAnimationComplete: onComplete
  3744. });
  3745. Chart.animationService.addAnimation(me, animation, duration, lazy);
  3746. } else {
  3747. me.draw();
  3748. // See https://github.com/chartjs/Chart.js/issues/3781
  3749. onComplete(new Chart.Animation({numSteps: 0, chart: me}));
  3750. }
  3751. return me;
  3752. },
  3753. draw: function (easingValue) {
  3754. var me = this;
  3755. me.clear();
  3756. if (helpers.isNullOrUndef(easingValue)) {
  3757. easingValue = 1;
  3758. }
  3759. me.transition(easingValue);
  3760. if (plugins.notify(me, 'beforeDraw', [easingValue]) === false) {
  3761. return;
  3762. }
  3763. // Draw all the scales
  3764. helpers.each(me.boxes, function (box) {
  3765. box.draw(me.chartArea);
  3766. }, me);
  3767. if (me.scale) {
  3768. me.scale.draw();
  3769. }
  3770. me.drawDatasets(easingValue);
  3771. me._drawTooltip(easingValue);
  3772. plugins.notify(me, 'afterDraw', [easingValue]);
  3773. },
  3774. /**
  3775. * @private
  3776. */
  3777. transition: function (easingValue) {
  3778. var me = this;
  3779. for (var i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
  3780. if (me.isDatasetVisible(i)) {
  3781. me.getDatasetMeta(i).controller.transition(easingValue);
  3782. }
  3783. }
  3784. me.tooltip.transition(easingValue);
  3785. },
  3786. /**
  3787. * Draws all datasets unless a plugin returns `false` to the `beforeDatasetsDraw`
  3788. * hook, in which case, plugins will not be called on `afterDatasetsDraw`.
  3789. * @private
  3790. */
  3791. drawDatasets: function (easingValue) {
  3792. var me = this;
  3793. if (plugins.notify(me, 'beforeDatasetsDraw', [easingValue]) === false) {
  3794. return;
  3795. }
  3796. // Draw datasets reversed to support proper line stacking
  3797. for (var i = (me.data.datasets || []).length - 1; i >= 0; --i) {
  3798. if (me.isDatasetVisible(i)) {
  3799. me.drawDataset(i, easingValue);
  3800. }
  3801. }
  3802. plugins.notify(me, 'afterDatasetsDraw', [easingValue]);
  3803. },
  3804. /**
  3805. * Draws dataset at index unless a plugin returns `false` to the `beforeDatasetDraw`
  3806. * hook, in which case, plugins will not be called on `afterDatasetDraw`.
  3807. * @private
  3808. */
  3809. drawDataset: function (index, easingValue) {
  3810. var me = this;
  3811. var meta = me.getDatasetMeta(index);
  3812. var args = {
  3813. meta: meta,
  3814. index: index,
  3815. easingValue: easingValue
  3816. };
  3817. if (plugins.notify(me, 'beforeDatasetDraw', [args]) === false) {
  3818. return;
  3819. }
  3820. meta.controller.draw(easingValue);
  3821. plugins.notify(me, 'afterDatasetDraw', [args]);
  3822. },
  3823. /**
  3824. * Draws tooltip unless a plugin returns `false` to the `beforeTooltipDraw`
  3825. * hook, in which case, plugins will not be called on `afterTooltipDraw`.
  3826. * @private
  3827. */
  3828. _drawTooltip: function (easingValue) {
  3829. var me = this;
  3830. var tooltip = me.tooltip;
  3831. var args = {
  3832. tooltip: tooltip,
  3833. easingValue: easingValue
  3834. };
  3835. if (plugins.notify(me, 'beforeTooltipDraw', [args]) === false) {
  3836. return;
  3837. }
  3838. tooltip.draw();
  3839. plugins.notify(me, 'afterTooltipDraw', [args]);
  3840. },
  3841. // Get the single element that was clicked on
  3842. // @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
  3843. getElementAtEvent: function (e) {
  3844. return Interaction.modes.single(this, e);
  3845. },
  3846. getElementsAtEvent: function (e) {
  3847. return Interaction.modes.label(this, e, {intersect: true});
  3848. },
  3849. getElementsAtXAxis: function (e) {
  3850. return Interaction.modes['x-axis'](this, e, {intersect: true});
  3851. },
  3852. getElementsAtEventForMode: function (e, mode, options) {
  3853. var method = Interaction.modes[mode];
  3854. if (typeof method === 'function') {
  3855. return method(this, e, options);
  3856. }
  3857. return [];
  3858. },
  3859. getDatasetAtEvent: function (e) {
  3860. return Interaction.modes.dataset(this, e, {intersect: true});
  3861. },
  3862. getDatasetMeta: function (datasetIndex) {
  3863. var me = this;
  3864. var dataset = me.data.datasets[datasetIndex];
  3865. if (!dataset._meta) {
  3866. dataset._meta = {};
  3867. }
  3868. var meta = dataset._meta[me.id];
  3869. if (!meta) {
  3870. meta = dataset._meta[me.id] = {
  3871. type: null,
  3872. data: [],
  3873. dataset: null,
  3874. controller: null,
  3875. hidden: null, // See isDatasetVisible() comment
  3876. xAxisID: null,
  3877. yAxisID: null
  3878. };
  3879. }
  3880. return meta;
  3881. },
  3882. getVisibleDatasetCount: function () {
  3883. var count = 0;
  3884. for (var i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
  3885. if (this.isDatasetVisible(i)) {
  3886. count++;
  3887. }
  3888. }
  3889. return count;
  3890. },
  3891. isDatasetVisible: function (datasetIndex) {
  3892. var meta = this.getDatasetMeta(datasetIndex);
  3893. // meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
  3894. // the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
  3895. return typeof meta.hidden === 'boolean' ? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
  3896. },
  3897. generateLegend: function () {
  3898. return this.options.legendCallback(this);
  3899. },
  3900. /**
  3901. * @private
  3902. */
  3903. destroyDatasetMeta: function (datasetIndex) {
  3904. var id = this.id;
  3905. var dataset = this.data.datasets[datasetIndex];
  3906. var meta = dataset._meta && dataset._meta[id];
  3907. if (meta) {
  3908. meta.controller.destroy();
  3909. delete dataset._meta[id];
  3910. }
  3911. },
  3912. destroy: function () {
  3913. var me = this;
  3914. var canvas = me.canvas;
  3915. var i, ilen;
  3916. me.stop();
  3917. // dataset controllers need to cleanup associated data
  3918. for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
  3919. me.destroyDatasetMeta(i);
  3920. }
  3921. if (canvas) {
  3922. me.unbindEvents();
  3923. helpers.canvas.clear(me);
  3924. platform.releaseContext(me.ctx);
  3925. me.canvas = null;
  3926. me.ctx = null;
  3927. }
  3928. plugins.notify(me, 'destroy');
  3929. delete Chart.instances[me.id];
  3930. },
  3931. toBase64Image: function () {
  3932. return this.canvas.toDataURL.apply(this.canvas, arguments);
  3933. },
  3934. initToolTip: function () {
  3935. var me = this;
  3936. me.tooltip = new Chart.Tooltip({
  3937. _chart: me,
  3938. _chartInstance: me, // deprecated, backward compatibility
  3939. _data: me.data,
  3940. _options: me.options.tooltips
  3941. }, me);
  3942. },
  3943. /**
  3944. * @private
  3945. */
  3946. bindEvents: function () {
  3947. var me = this;
  3948. var listeners = me._listeners = {};
  3949. var listener = function () {
  3950. me.eventHandler.apply(me, arguments);
  3951. };
  3952. helpers.each(me.options.events, function (type) {
  3953. platform.addEventListener(me, type, listener);
  3954. listeners[type] = listener;
  3955. });
  3956. // Elements used to detect size change should not be injected for non responsive charts.
  3957. // See https://github.com/chartjs/Chart.js/issues/2210
  3958. if (me.options.responsive) {
  3959. listener = function () {
  3960. me.resize();
  3961. };
  3962. platform.addEventListener(me, 'resize', listener);
  3963. listeners.resize = listener;
  3964. }
  3965. },
  3966. /**
  3967. * @private
  3968. */
  3969. unbindEvents: function () {
  3970. var me = this;
  3971. var listeners = me._listeners;
  3972. if (!listeners) {
  3973. return;
  3974. }
  3975. delete me._listeners;
  3976. helpers.each(listeners, function (listener, type) {
  3977. platform.removeEventListener(me, type, listener);
  3978. });
  3979. },
  3980. updateHoverStyle: function (elements, mode, enabled) {
  3981. var method = enabled ? 'setHoverStyle' : 'removeHoverStyle';
  3982. var element, i, ilen;
  3983. for (i = 0, ilen = elements.length; i < ilen; ++i) {
  3984. element = elements[i];
  3985. if (element) {
  3986. this.getDatasetMeta(element._datasetIndex).controller[method](element);
  3987. }
  3988. }
  3989. },
  3990. /**
  3991. * @private
  3992. */
  3993. eventHandler: function (e) {
  3994. var me = this;
  3995. var tooltip = me.tooltip;
  3996. if (plugins.notify(me, 'beforeEvent', [e]) === false) {
  3997. return;
  3998. }
  3999. // Buffer any update calls so that renders do not occur
  4000. me._bufferedRender = true;
  4001. me._bufferedRequest = null;
  4002. var changed = me.handleEvent(e);
  4003. // for smooth tooltip animations issue #4989
  4004. // the tooltip should be the source of change
  4005. // Animation check workaround:
  4006. // tooltip._start will be null when tooltip isn't animating
  4007. if (tooltip) {
  4008. changed = tooltip._start
  4009. ? tooltip.handleEvent(e)
  4010. : changed | tooltip.handleEvent(e);
  4011. }
  4012. plugins.notify(me, 'afterEvent', [e]);
  4013. var bufferedRequest = me._bufferedRequest;
  4014. if (bufferedRequest) {
  4015. // If we have an update that was triggered, we need to do a normal render
  4016. me.render(bufferedRequest);
  4017. } else if (changed && !me.animating) {
  4018. // If entering, leaving, or changing elements, animate the change via pivot
  4019. me.stop();
  4020. // We only need to render at this point. Updating will cause scales to be
  4021. // recomputed generating flicker & using more memory than necessary.
  4022. me.render(me.options.hover.animationDuration, true);
  4023. }
  4024. me._bufferedRender = false;
  4025. me._bufferedRequest = null;
  4026. return me;
  4027. },
  4028. /**
  4029. * Handle an event
  4030. * @private
  4031. * @param {IEvent} event the event to handle
  4032. * @return {Boolean} true if the chart needs to re-render
  4033. */
  4034. handleEvent: function (e) {
  4035. var me = this;
  4036. var options = me.options || {};
  4037. var hoverOptions = options.hover;
  4038. var changed = false;
  4039. me.lastActive = me.lastActive || [];
  4040. // Find Active Elements for hover and tooltips
  4041. if (e.type === 'mouseout') {
  4042. me.active = [];
  4043. } else {
  4044. me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions);
  4045. }
  4046. // Invoke onHover hook
  4047. // Need to call with native event here to not break backwards compatibility
  4048. helpers.callback(options.onHover || options.hover.onHover, [e.native, me.active], me);
  4049. if (e.type === 'mouseup' || e.type === 'click') {
  4050. if (options.onClick) {
  4051. // Use e.native here for backwards compatibility
  4052. options.onClick.call(me, e.native, me.active);
  4053. }
  4054. }
  4055. // Remove styling for last active (even if it may still be active)
  4056. if (me.lastActive.length) {
  4057. me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
  4058. }
  4059. // Built in hover styling
  4060. if (me.active.length && hoverOptions.mode) {
  4061. me.updateHoverStyle(me.active, hoverOptions.mode, true);
  4062. }
  4063. changed = !helpers.arrayEquals(me.active, me.lastActive);
  4064. // Remember Last Actives
  4065. me.lastActive = me.active;
  4066. return changed;
  4067. }
  4068. });
  4069. /**
  4070. * Provided for backward compatibility, use Chart instead.
  4071. * @class Chart.Controller
  4072. * @deprecated since version 2.6.0
  4073. * @todo remove at version 3
  4074. * @private
  4075. */
  4076. Chart.Controller = Chart;
  4077. };
  4078. }, {"25": 25, "28": 28, "30": 30, "31": 31, "45": 45, "48": 48}], 24: [function (require, module, exports) {
  4079. 'use strict';
  4080. var helpers = require(45);
  4081. module.exports = function (Chart) {
  4082. var arrayEvents = ['push', 'pop', 'shift', 'splice', 'unshift'];
  4083. /**
  4084. * Hooks the array methods that add or remove values ('push', pop', 'shift', 'splice',
  4085. * 'unshift') and notify the listener AFTER the array has been altered. Listeners are
  4086. * called on the 'onData*' callbacks (e.g. onDataPush, etc.) with same arguments.
  4087. */
  4088. function listenArrayEvents(array, listener) {
  4089. if (array._chartjs) {
  4090. array._chartjs.listeners.push(listener);
  4091. return;
  4092. }
  4093. Object.defineProperty(array, '_chartjs', {
  4094. configurable: true,
  4095. enumerable: false,
  4096. value: {
  4097. listeners: [listener]
  4098. }
  4099. });
  4100. arrayEvents.forEach(function (key) {
  4101. var method = 'onData' + key.charAt(0).toUpperCase() + key.slice(1);
  4102. var base = array[key];
  4103. Object.defineProperty(array, key, {
  4104. configurable: true,
  4105. enumerable: false,
  4106. value: function () {
  4107. var args = Array.prototype.slice.call(arguments);
  4108. var res = base.apply(this, args);
  4109. helpers.each(array._chartjs.listeners, function (object) {
  4110. if (typeof object[method] === 'function') {
  4111. object[method].apply(object, args);
  4112. }
  4113. });
  4114. return res;
  4115. }
  4116. });
  4117. });
  4118. }
  4119. /**
  4120. * Removes the given array event listener and cleanup extra attached properties (such as
  4121. * the _chartjs stub and overridden methods) if array doesn't have any more listeners.
  4122. */
  4123. function unlistenArrayEvents(array, listener) {
  4124. var stub = array._chartjs;
  4125. if (!stub) {
  4126. return;
  4127. }
  4128. var listeners = stub.listeners;
  4129. var index = listeners.indexOf(listener);
  4130. if (index !== -1) {
  4131. listeners.splice(index, 1);
  4132. }
  4133. if (listeners.length > 0) {
  4134. return;
  4135. }
  4136. arrayEvents.forEach(function (key) {
  4137. delete array[key];
  4138. });
  4139. delete array._chartjs;
  4140. }
  4141. // Base class for all dataset controllers (line, bar, etc)
  4142. Chart.DatasetController = function (chart, datasetIndex) {
  4143. this.initialize(chart, datasetIndex);
  4144. };
  4145. helpers.extend(Chart.DatasetController.prototype, {
  4146. /**
  4147. * Element type used to generate a meta dataset (e.g. Chart.element.Line).
  4148. * @type {Chart.core.element}
  4149. */
  4150. datasetElementType: null,
  4151. /**
  4152. * Element type used to generate a meta data (e.g. Chart.element.Point).
  4153. * @type {Chart.core.element}
  4154. */
  4155. dataElementType: null,
  4156. initialize: function (chart, datasetIndex) {
  4157. var me = this;
  4158. me.chart = chart;
  4159. me.index = datasetIndex;
  4160. me.linkScales();
  4161. me.addElements();
  4162. },
  4163. updateIndex: function (datasetIndex) {
  4164. this.index = datasetIndex;
  4165. },
  4166. linkScales: function () {
  4167. var me = this;
  4168. var meta = me.getMeta();
  4169. var dataset = me.getDataset();
  4170. if (meta.xAxisID === null || !(meta.xAxisID in me.chart.scales)) {
  4171. meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
  4172. }
  4173. if (meta.yAxisID === null || !(meta.yAxisID in me.chart.scales)) {
  4174. meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
  4175. }
  4176. },
  4177. getDataset: function () {
  4178. return this.chart.data.datasets[this.index];
  4179. },
  4180. getMeta: function () {
  4181. return this.chart.getDatasetMeta(this.index);
  4182. },
  4183. getScaleForId: function (scaleID) {
  4184. return this.chart.scales[scaleID];
  4185. },
  4186. reset: function () {
  4187. this.update(true);
  4188. },
  4189. /**
  4190. * @private
  4191. */
  4192. destroy: function () {
  4193. if (this._data) {
  4194. unlistenArrayEvents(this._data, this);
  4195. }
  4196. },
  4197. createMetaDataset: function () {
  4198. var me = this;
  4199. var type = me.datasetElementType;
  4200. return type && new type({
  4201. _chart: me.chart,
  4202. _datasetIndex: me.index
  4203. });
  4204. },
  4205. createMetaData: function (index) {
  4206. var me = this;
  4207. var type = me.dataElementType;
  4208. return type && new type({
  4209. _chart: me.chart,
  4210. _datasetIndex: me.index,
  4211. _index: index
  4212. });
  4213. },
  4214. addElements: function () {
  4215. var me = this;
  4216. var meta = me.getMeta();
  4217. var data = me.getDataset().data || [];
  4218. var metaData = meta.data;
  4219. var i, ilen;
  4220. for (i = 0, ilen = data.length; i < ilen; ++i) {
  4221. metaData[i] = metaData[i] || me.createMetaData(i);
  4222. }
  4223. meta.dataset = meta.dataset || me.createMetaDataset();
  4224. },
  4225. addElementAndReset: function (index) {
  4226. var element = this.createMetaData(index);
  4227. this.getMeta().data.splice(index, 0, element);
  4228. this.updateElement(element, index, true);
  4229. },
  4230. buildOrUpdateElements: function () {
  4231. var me = this;
  4232. var dataset = me.getDataset();
  4233. var data = dataset.data || (dataset.data = []);
  4234. // In order to correctly handle data addition/deletion animation (an thus simulate
  4235. // real-time charts), we need to monitor these data modifications and synchronize
  4236. // the internal meta data accordingly.
  4237. if (me._data !== data) {
  4238. if (me._data) {
  4239. // This case happens when the user replaced the data array instance.
  4240. unlistenArrayEvents(me._data, me);
  4241. }
  4242. listenArrayEvents(data, me);
  4243. me._data = data;
  4244. }
  4245. // Re-sync meta data in case the user replaced the data array or if we missed
  4246. // any updates and so make sure that we handle number of datapoints changing.
  4247. me.resyncElements();
  4248. },
  4249. update: helpers.noop,
  4250. transition: function (easingValue) {
  4251. var meta = this.getMeta();
  4252. var elements = meta.data || [];
  4253. var ilen = elements.length;
  4254. var i = 0;
  4255. for (; i < ilen; ++i) {
  4256. elements[i].transition(easingValue);
  4257. }
  4258. if (meta.dataset) {
  4259. meta.dataset.transition(easingValue);
  4260. }
  4261. },
  4262. draw: function () {
  4263. var meta = this.getMeta();
  4264. var elements = meta.data || [];
  4265. var ilen = elements.length;
  4266. var i = 0;
  4267. if (meta.dataset) {
  4268. meta.dataset.draw();
  4269. }
  4270. for (; i < ilen; ++i) {
  4271. elements[i].draw();
  4272. }
  4273. },
  4274. removeHoverStyle: function (element, elementOpts) {
  4275. var dataset = this.chart.data.datasets[element._datasetIndex];
  4276. var index = element._index;
  4277. var custom = element.custom || {};
  4278. var valueOrDefault = helpers.valueAtIndexOrDefault;
  4279. var model = element._model;
  4280. model.backgroundColor = custom.backgroundColor ? custom.backgroundColor : valueOrDefault(dataset.backgroundColor, index, elementOpts.backgroundColor);
  4281. model.borderColor = custom.borderColor ? custom.borderColor : valueOrDefault(dataset.borderColor, index, elementOpts.borderColor);
  4282. model.borderWidth = custom.borderWidth ? custom.borderWidth : valueOrDefault(dataset.borderWidth, index, elementOpts.borderWidth);
  4283. },
  4284. setHoverStyle: function (element) {
  4285. var dataset = this.chart.data.datasets[element._datasetIndex];
  4286. var index = element._index;
  4287. var custom = element.custom || {};
  4288. var valueOrDefault = helpers.valueAtIndexOrDefault;
  4289. var getHoverColor = helpers.getHoverColor;
  4290. var model = element._model;
  4291. model.backgroundColor = custom.hoverBackgroundColor ? custom.hoverBackgroundColor : valueOrDefault(dataset.hoverBackgroundColor, index, getHoverColor(model.backgroundColor));
  4292. model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
  4293. model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
  4294. },
  4295. /**
  4296. * @private
  4297. */
  4298. resyncElements: function () {
  4299. var me = this;
  4300. var meta = me.getMeta();
  4301. var data = me.getDataset().data;
  4302. var numMeta = meta.data.length;
  4303. var numData = data.length;
  4304. if (numData < numMeta) {
  4305. meta.data.splice(numData, numMeta - numData);
  4306. } else if (numData > numMeta) {
  4307. me.insertElements(numMeta, numData - numMeta);
  4308. }
  4309. },
  4310. /**
  4311. * @private
  4312. */
  4313. insertElements: function (start, count) {
  4314. for (var i = 0; i < count; ++i) {
  4315. this.addElementAndReset(start + i);
  4316. }
  4317. },
  4318. /**
  4319. * @private
  4320. */
  4321. onDataPush: function () {
  4322. this.insertElements(this.getDataset().data.length - 1, arguments.length);
  4323. },
  4324. /**
  4325. * @private
  4326. */
  4327. onDataPop: function () {
  4328. this.getMeta().data.pop();
  4329. },
  4330. /**
  4331. * @private
  4332. */
  4333. onDataShift: function () {
  4334. this.getMeta().data.shift();
  4335. },
  4336. /**
  4337. * @private
  4338. */
  4339. onDataSplice: function (start, count) {
  4340. this.getMeta().data.splice(start, count);
  4341. this.insertElements(start, arguments.length - 2);
  4342. },
  4343. /**
  4344. * @private
  4345. */
  4346. onDataUnshift: function () {
  4347. this.insertElements(0, arguments.length);
  4348. }
  4349. });
  4350. Chart.DatasetController.extend = helpers.inherits;
  4351. };
  4352. }, {"45": 45}], 25: [function (require, module, exports) {
  4353. 'use strict';
  4354. var helpers = require(45);
  4355. module.exports = {
  4356. /**
  4357. * @private
  4358. */
  4359. _set: function (scope, values) {
  4360. return helpers.merge(this[scope] || (this[scope] = {}), values);
  4361. }
  4362. };
  4363. }, {"45": 45}], 26: [function (require, module, exports) {
  4364. 'use strict';
  4365. var color = require(3);
  4366. var helpers = require(45);
  4367. function interpolate(start, view, model, ease) {
  4368. var keys = Object.keys(model);
  4369. var i, ilen, key, actual, origin, target, type, c0, c1;
  4370. for (i = 0, ilen = keys.length; i < ilen; ++i) {
  4371. key = keys[i];
  4372. target = model[key];
  4373. // if a value is added to the model after pivot() has been called, the view
  4374. // doesn't contain it, so let's initialize the view to the target value.
  4375. if (!view.hasOwnProperty(key)) {
  4376. view[key] = target;
  4377. }
  4378. actual = view[key];
  4379. if (actual === target || key[0] === '_') {
  4380. continue;
  4381. }
  4382. if (!start.hasOwnProperty(key)) {
  4383. start[key] = actual;
  4384. }
  4385. origin = start[key];
  4386. type = typeof target;
  4387. if (type === typeof origin) {
  4388. if (type === 'string') {
  4389. c0 = color(origin);
  4390. if (c0.valid) {
  4391. c1 = color(target);
  4392. if (c1.valid) {
  4393. view[key] = c1.mix(c0, ease).rgbString();
  4394. continue;
  4395. }
  4396. }
  4397. } else if (type === 'number' && isFinite(origin) && isFinite(target)) {
  4398. view[key] = origin + (target - origin) * ease;
  4399. continue;
  4400. }
  4401. }
  4402. view[key] = target;
  4403. }
  4404. }
  4405. var Element = function (configuration) {
  4406. helpers.extend(this, configuration);
  4407. this.initialize.apply(this, arguments);
  4408. };
  4409. helpers.extend(Element.prototype, {
  4410. initialize: function () {
  4411. this.hidden = false;
  4412. },
  4413. pivot: function () {
  4414. var me = this;
  4415. if (!me._view) {
  4416. me._view = helpers.clone(me._model);
  4417. }
  4418. me._start = {};
  4419. return me;
  4420. },
  4421. transition: function (ease) {
  4422. var me = this;
  4423. var model = me._model;
  4424. var start = me._start;
  4425. var view = me._view;
  4426. // No animation -> No Transition
  4427. if (!model || ease === 1) {
  4428. me._view = model;
  4429. me._start = null;
  4430. return me;
  4431. }
  4432. if (!view) {
  4433. view = me._view = {};
  4434. }
  4435. if (!start) {
  4436. start = me._start = {};
  4437. }
  4438. interpolate(start, view, model, ease);
  4439. return me;
  4440. },
  4441. tooltipPosition: function () {
  4442. return {
  4443. x: this._model.x,
  4444. y: this._model.y
  4445. };
  4446. },
  4447. hasValue: function () {
  4448. return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
  4449. }
  4450. });
  4451. Element.extend = helpers.inherits;
  4452. module.exports = Element;
  4453. }, {"3": 3, "45": 45}], 27: [function (require, module, exports) {
  4454. /* global window: false */
  4455. /* global document: false */
  4456. 'use strict';
  4457. var color = require(3);
  4458. var defaults = require(25);
  4459. var helpers = require(45);
  4460. module.exports = function (Chart) {
  4461. // -- Basic js utility methods
  4462. helpers.configMerge = function (/* objects ... */) {
  4463. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  4464. merger: function (key, target, source, options) {
  4465. var tval = target[key] || {};
  4466. var sval = source[key];
  4467. if (key === 'scales') {
  4468. // scale config merging is complex. Add our own function here for that
  4469. target[key] = helpers.scaleMerge(tval, sval);
  4470. } else if (key === 'scale') {
  4471. // used in polar area & radar charts since there is only one scale
  4472. target[key] = helpers.merge(tval, [Chart.scaleService.getScaleDefaults(sval.type), sval]);
  4473. } else {
  4474. helpers._merger(key, target, source, options);
  4475. }
  4476. }
  4477. });
  4478. };
  4479. helpers.scaleMerge = function (/* objects ... */) {
  4480. return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
  4481. merger: function (key, target, source, options) {
  4482. if (key === 'xAxes' || key === 'yAxes') {
  4483. var slen = source[key].length;
  4484. var i, type, scale;
  4485. if (!target[key]) {
  4486. target[key] = [];
  4487. }
  4488. for (i = 0; i < slen; ++i) {
  4489. scale = source[key][i];
  4490. type = helpers.valueOrDefault(scale.type, key === 'xAxes' ? 'category' : 'linear');
  4491. if (i >= target[key].length) {
  4492. target[key].push({});
  4493. }
  4494. if (!target[key][i].type || (scale.type && scale.type !== target[key][i].type)) {
  4495. // new/untyped scale or type changed: let's apply the new defaults
  4496. // then merge source scale to correctly overwrite the defaults.
  4497. helpers.merge(target[key][i], [Chart.scaleService.getScaleDefaults(type), scale]);
  4498. } else {
  4499. // scales type are the same
  4500. helpers.merge(target[key][i], scale);
  4501. }
  4502. }
  4503. } else {
  4504. helpers._merger(key, target, source, options);
  4505. }
  4506. }
  4507. });
  4508. };
  4509. helpers.where = function (collection, filterCallback) {
  4510. if (helpers.isArray(collection) && Array.prototype.filter) {
  4511. return collection.filter(filterCallback);
  4512. }
  4513. var filtered = [];
  4514. helpers.each(collection, function (item) {
  4515. if (filterCallback(item)) {
  4516. filtered.push(item);
  4517. }
  4518. });
  4519. return filtered;
  4520. };
  4521. helpers.findIndex = Array.prototype.findIndex ?
  4522. function (array, callback, scope) {
  4523. return array.findIndex(callback, scope);
  4524. } :
  4525. function (array, callback, scope) {
  4526. scope = scope === undefined ? array : scope;
  4527. for (var i = 0, ilen = array.length; i < ilen; ++i) {
  4528. if (callback.call(scope, array[i], i, array)) {
  4529. return i;
  4530. }
  4531. }
  4532. return -1;
  4533. };
  4534. helpers.findNextWhere = function (arrayToSearch, filterCallback, startIndex) {
  4535. // Default to start of the array
  4536. if (helpers.isNullOrUndef(startIndex)) {
  4537. startIndex = -1;
  4538. }
  4539. for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
  4540. var currentItem = arrayToSearch[i];
  4541. if (filterCallback(currentItem)) {
  4542. return currentItem;
  4543. }
  4544. }
  4545. };
  4546. helpers.findPreviousWhere = function (arrayToSearch, filterCallback, startIndex) {
  4547. // Default to end of the array
  4548. if (helpers.isNullOrUndef(startIndex)) {
  4549. startIndex = arrayToSearch.length;
  4550. }
  4551. for (var i = startIndex - 1; i >= 0; i--) {
  4552. var currentItem = arrayToSearch[i];
  4553. if (filterCallback(currentItem)) {
  4554. return currentItem;
  4555. }
  4556. }
  4557. };
  4558. // -- Math methods
  4559. helpers.isNumber = function (n) {
  4560. return !isNaN(parseFloat(n)) && isFinite(n);
  4561. };
  4562. helpers.almostEquals = function (x, y, epsilon) {
  4563. return Math.abs(x - y) < epsilon;
  4564. };
  4565. helpers.almostWhole = function (x, epsilon) {
  4566. var rounded = Math.round(x);
  4567. return (((rounded - epsilon) < x) && ((rounded + epsilon) > x));
  4568. };
  4569. helpers.max = function (array) {
  4570. return array.reduce(function (max, value) {
  4571. if (!isNaN(value)) {
  4572. return Math.max(max, value);
  4573. }
  4574. return max;
  4575. }, Number.NEGATIVE_INFINITY);
  4576. };
  4577. helpers.min = function (array) {
  4578. return array.reduce(function (min, value) {
  4579. if (!isNaN(value)) {
  4580. return Math.min(min, value);
  4581. }
  4582. return min;
  4583. }, Number.POSITIVE_INFINITY);
  4584. };
  4585. helpers.sign = Math.sign ?
  4586. function (x) {
  4587. return Math.sign(x);
  4588. } :
  4589. function (x) {
  4590. x = +x; // convert to a number
  4591. if (x === 0 || isNaN(x)) {
  4592. return x;
  4593. }
  4594. return x > 0 ? 1 : -1;
  4595. };
  4596. helpers.log10 = Math.log10 ?
  4597. function (x) {
  4598. return Math.log10(x);
  4599. } :
  4600. function (x) {
  4601. var exponent = Math.log(x) * Math.LOG10E; // Math.LOG10E = 1 / Math.LN10.
  4602. // Check for whole powers of 10,
  4603. // which due to floating point rounding error should be corrected.
  4604. var powerOf10 = Math.round(exponent);
  4605. var isPowerOf10 = x === Math.pow(10, powerOf10);
  4606. return isPowerOf10 ? powerOf10 : exponent;
  4607. };
  4608. helpers.toRadians = function (degrees) {
  4609. return degrees * (Math.PI / 180);
  4610. };
  4611. helpers.toDegrees = function (radians) {
  4612. return radians * (180 / Math.PI);
  4613. };
  4614. // Gets the angle from vertical upright to the point about a centre.
  4615. helpers.getAngleFromPoint = function (centrePoint, anglePoint) {
  4616. var distanceFromXCenter = anglePoint.x - centrePoint.x;
  4617. var distanceFromYCenter = anglePoint.y - centrePoint.y;
  4618. var radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
  4619. var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
  4620. if (angle < (-0.5 * Math.PI)) {
  4621. angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
  4622. }
  4623. return {
  4624. angle: angle,
  4625. distance: radialDistanceFromCenter
  4626. };
  4627. };
  4628. helpers.distanceBetweenPoints = function (pt1, pt2) {
  4629. return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
  4630. };
  4631. helpers.aliasPixel = function (pixelWidth) {
  4632. return (pixelWidth % 2 === 0) ? 0 : 0.5;
  4633. };
  4634. helpers.splineCurve = function (firstPoint, middlePoint, afterPoint, t) {
  4635. // Props to Rob Spencer at scaled innovation for his post on splining between points
  4636. // http://scaledinnovation.com/analytics/splines/aboutSplines.html
  4637. // This function must also respect "skipped" points
  4638. var previous = firstPoint.skip ? middlePoint : firstPoint;
  4639. var current = middlePoint;
  4640. var next = afterPoint.skip ? middlePoint : afterPoint;
  4641. var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
  4642. var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
  4643. var s01 = d01 / (d01 + d12);
  4644. var s12 = d12 / (d01 + d12);
  4645. // If all points are the same, s01 & s02 will be inf
  4646. s01 = isNaN(s01) ? 0 : s01;
  4647. s12 = isNaN(s12) ? 0 : s12;
  4648. var fa = t * s01; // scaling factor for triangle Ta
  4649. var fb = t * s12;
  4650. return {
  4651. previous: {
  4652. x: current.x - fa * (next.x - previous.x),
  4653. y: current.y - fa * (next.y - previous.y)
  4654. },
  4655. next: {
  4656. x: current.x + fb * (next.x - previous.x),
  4657. y: current.y + fb * (next.y - previous.y)
  4658. }
  4659. };
  4660. };
  4661. helpers.EPSILON = Number.EPSILON || 1e-14;
  4662. helpers.splineCurveMonotone = function (points) {
  4663. // This function calculates Bézier control points in a similar way than |splineCurve|,
  4664. // but preserves monotonicity of the provided data and ensures no local extremums are added
  4665. // between the dataset discrete points due to the interpolation.
  4666. // See : https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
  4667. var pointsWithTangents = (points || []).map(function (point) {
  4668. return {
  4669. model: point._model,
  4670. deltaK: 0,
  4671. mK: 0
  4672. };
  4673. });
  4674. // Calculate slopes (deltaK) and initialize tangents (mK)
  4675. var pointsLen = pointsWithTangents.length;
  4676. var i, pointBefore, pointCurrent, pointAfter;
  4677. for (i = 0; i < pointsLen; ++i) {
  4678. pointCurrent = pointsWithTangents[i];
  4679. if (pointCurrent.model.skip) {
  4680. continue;
  4681. }
  4682. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4683. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4684. if (pointAfter && !pointAfter.model.skip) {
  4685. var slopeDeltaX = (pointAfter.model.x - pointCurrent.model.x);
  4686. // In the case of two points that appear at the same x pixel, slopeDeltaX is 0
  4687. pointCurrent.deltaK = slopeDeltaX !== 0 ? (pointAfter.model.y - pointCurrent.model.y) / slopeDeltaX : 0;
  4688. }
  4689. if (!pointBefore || pointBefore.model.skip) {
  4690. pointCurrent.mK = pointCurrent.deltaK;
  4691. } else if (!pointAfter || pointAfter.model.skip) {
  4692. pointCurrent.mK = pointBefore.deltaK;
  4693. } else if (this.sign(pointBefore.deltaK) !== this.sign(pointCurrent.deltaK)) {
  4694. pointCurrent.mK = 0;
  4695. } else {
  4696. pointCurrent.mK = (pointBefore.deltaK + pointCurrent.deltaK) / 2;
  4697. }
  4698. }
  4699. // Adjust tangents to ensure monotonic properties
  4700. var alphaK, betaK, tauK, squaredMagnitude;
  4701. for (i = 0; i < pointsLen - 1; ++i) {
  4702. pointCurrent = pointsWithTangents[i];
  4703. pointAfter = pointsWithTangents[i + 1];
  4704. if (pointCurrent.model.skip || pointAfter.model.skip) {
  4705. continue;
  4706. }
  4707. if (helpers.almostEquals(pointCurrent.deltaK, 0, this.EPSILON)) {
  4708. pointCurrent.mK = pointAfter.mK = 0;
  4709. continue;
  4710. }
  4711. alphaK = pointCurrent.mK / pointCurrent.deltaK;
  4712. betaK = pointAfter.mK / pointCurrent.deltaK;
  4713. squaredMagnitude = Math.pow(alphaK, 2) + Math.pow(betaK, 2);
  4714. if (squaredMagnitude <= 9) {
  4715. continue;
  4716. }
  4717. tauK = 3 / Math.sqrt(squaredMagnitude);
  4718. pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK;
  4719. pointAfter.mK = betaK * tauK * pointCurrent.deltaK;
  4720. }
  4721. // Compute control points
  4722. var deltaX;
  4723. for (i = 0; i < pointsLen; ++i) {
  4724. pointCurrent = pointsWithTangents[i];
  4725. if (pointCurrent.model.skip) {
  4726. continue;
  4727. }
  4728. pointBefore = i > 0 ? pointsWithTangents[i - 1] : null;
  4729. pointAfter = i < pointsLen - 1 ? pointsWithTangents[i + 1] : null;
  4730. if (pointBefore && !pointBefore.model.skip) {
  4731. deltaX = (pointCurrent.model.x - pointBefore.model.x) / 3;
  4732. pointCurrent.model.controlPointPreviousX = pointCurrent.model.x - deltaX;
  4733. pointCurrent.model.controlPointPreviousY = pointCurrent.model.y - deltaX * pointCurrent.mK;
  4734. }
  4735. if (pointAfter && !pointAfter.model.skip) {
  4736. deltaX = (pointAfter.model.x - pointCurrent.model.x) / 3;
  4737. pointCurrent.model.controlPointNextX = pointCurrent.model.x + deltaX;
  4738. pointCurrent.model.controlPointNextY = pointCurrent.model.y + deltaX * pointCurrent.mK;
  4739. }
  4740. }
  4741. };
  4742. helpers.nextItem = function (collection, index, loop) {
  4743. if (loop) {
  4744. return index >= collection.length - 1 ? collection[0] : collection[index + 1];
  4745. }
  4746. return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
  4747. };
  4748. helpers.previousItem = function (collection, index, loop) {
  4749. if (loop) {
  4750. return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
  4751. }
  4752. return index <= 0 ? collection[0] : collection[index - 1];
  4753. };
  4754. // Implementation of the nice number algorithm used in determining where axis labels will go
  4755. helpers.niceNum = function (range, round) {
  4756. var exponent = Math.floor(helpers.log10(range));
  4757. var fraction = range / Math.pow(10, exponent);
  4758. var niceFraction;
  4759. if (round) {
  4760. if (fraction < 1.5) {
  4761. niceFraction = 1;
  4762. } else if (fraction < 3) {
  4763. niceFraction = 2;
  4764. } else if (fraction < 7) {
  4765. niceFraction = 5;
  4766. } else {
  4767. niceFraction = 10;
  4768. }
  4769. } else if (fraction <= 1.0) {
  4770. niceFraction = 1;
  4771. } else if (fraction <= 2) {
  4772. niceFraction = 2;
  4773. } else if (fraction <= 5) {
  4774. niceFraction = 5;
  4775. } else {
  4776. niceFraction = 10;
  4777. }
  4778. return niceFraction * Math.pow(10, exponent);
  4779. };
  4780. // Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  4781. helpers.requestAnimFrame = (function () {
  4782. if (typeof window === 'undefined') {
  4783. return function (callback) {
  4784. callback();
  4785. };
  4786. }
  4787. return window.requestAnimationFrame ||
  4788. window.webkitRequestAnimationFrame ||
  4789. window.mozRequestAnimationFrame ||
  4790. window.oRequestAnimationFrame ||
  4791. window.msRequestAnimationFrame ||
  4792. function (callback) {
  4793. return window.setTimeout(callback, 1000 / 60);
  4794. };
  4795. }());
  4796. // -- DOM methods
  4797. helpers.getRelativePosition = function (evt, chart) {
  4798. var mouseX, mouseY;
  4799. var e = evt.originalEvent || evt;
  4800. var canvas = evt.currentTarget || evt.srcElement;
  4801. var boundingRect = canvas.getBoundingClientRect();
  4802. var touches = e.touches;
  4803. if (touches && touches.length > 0) {
  4804. mouseX = touches[0].clientX;
  4805. mouseY = touches[0].clientY;
  4806. } else {
  4807. mouseX = e.clientX;
  4808. mouseY = e.clientY;
  4809. }
  4810. // Scale mouse coordinates into canvas coordinates
  4811. // by following the pattern laid out by 'jerryj' in the comments of
  4812. // http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
  4813. var paddingLeft = parseFloat(helpers.getStyle(canvas, 'padding-left'));
  4814. var paddingTop = parseFloat(helpers.getStyle(canvas, 'padding-top'));
  4815. var paddingRight = parseFloat(helpers.getStyle(canvas, 'padding-right'));
  4816. var paddingBottom = parseFloat(helpers.getStyle(canvas, 'padding-bottom'));
  4817. var width = boundingRect.right - boundingRect.left - paddingLeft - paddingRight;
  4818. var height = boundingRect.bottom - boundingRect.top - paddingTop - paddingBottom;
  4819. // We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
  4820. // the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
  4821. mouseX = Math.round((mouseX - boundingRect.left - paddingLeft) / (width) * canvas.width / chart.currentDevicePixelRatio);
  4822. mouseY = Math.round((mouseY - boundingRect.top - paddingTop) / (height) * canvas.height / chart.currentDevicePixelRatio);
  4823. return {
  4824. x: mouseX,
  4825. y: mouseY
  4826. };
  4827. };
  4828. // Private helper function to convert max-width/max-height values that may be percentages into a number
  4829. function parseMaxStyle(styleValue, node, parentProperty) {
  4830. var valueInPixels;
  4831. if (typeof styleValue === 'string') {
  4832. valueInPixels = parseInt(styleValue, 10);
  4833. if (styleValue.indexOf('%') !== -1) {
  4834. // percentage * size in dimension
  4835. valueInPixels = valueInPixels / 100 * node.parentNode[parentProperty];
  4836. }
  4837. } else {
  4838. valueInPixels = styleValue;
  4839. }
  4840. return valueInPixels;
  4841. }
  4842. /**
  4843. * Returns if the given value contains an effective constraint.
  4844. * @private
  4845. */
  4846. function isConstrainedValue(value) {
  4847. return value !== undefined && value !== null && value !== 'none';
  4848. }
  4849. // Private helper to get a constraint dimension
  4850. // @param domNode : the node to check the constraint on
  4851. // @param maxStyle : the style that defines the maximum for the direction we are using (maxWidth / maxHeight)
  4852. // @param percentageProperty : property of parent to use when calculating width as a percentage
  4853. // @see http://www.nathanaeljones.com/blog/2013/reading-max-width-cross-browser
  4854. function getConstraintDimension(domNode, maxStyle, percentageProperty) {
  4855. var view = document.defaultView;
  4856. var parentNode = domNode.parentNode;
  4857. var constrainedNode = view.getComputedStyle(domNode)[maxStyle];
  4858. var constrainedContainer = view.getComputedStyle(parentNode)[maxStyle];
  4859. var hasCNode = isConstrainedValue(constrainedNode);
  4860. var hasCContainer = isConstrainedValue(constrainedContainer);
  4861. var infinity = Number.POSITIVE_INFINITY;
  4862. if (hasCNode || hasCContainer) {
  4863. return Math.min(
  4864. hasCNode ? parseMaxStyle(constrainedNode, domNode, percentageProperty) : infinity,
  4865. hasCContainer ? parseMaxStyle(constrainedContainer, parentNode, percentageProperty) : infinity);
  4866. }
  4867. return 'none';
  4868. }
  4869. // returns Number or undefined if no constraint
  4870. helpers.getConstraintWidth = function (domNode) {
  4871. return getConstraintDimension(domNode, 'max-width', 'clientWidth');
  4872. };
  4873. // returns Number or undefined if no constraint
  4874. helpers.getConstraintHeight = function (domNode) {
  4875. return getConstraintDimension(domNode, 'max-height', 'clientHeight');
  4876. };
  4877. helpers.getMaximumWidth = function (domNode) {
  4878. var container = domNode.parentNode;
  4879. if (!container) {
  4880. return domNode.clientWidth;
  4881. }
  4882. var paddingLeft = parseInt(helpers.getStyle(container, 'padding-left'), 10);
  4883. var paddingRight = parseInt(helpers.getStyle(container, 'padding-right'), 10);
  4884. var w = container.clientWidth - paddingLeft - paddingRight;
  4885. var cw = helpers.getConstraintWidth(domNode);
  4886. return isNaN(cw) ? w : Math.min(w, cw);
  4887. };
  4888. helpers.getMaximumHeight = function (domNode) {
  4889. var container = domNode.parentNode;
  4890. if (!container) {
  4891. return domNode.clientHeight;
  4892. }
  4893. var paddingTop = parseInt(helpers.getStyle(container, 'padding-top'), 10);
  4894. var paddingBottom = parseInt(helpers.getStyle(container, 'padding-bottom'), 10);
  4895. var h = container.clientHeight - paddingTop - paddingBottom;
  4896. var ch = helpers.getConstraintHeight(domNode);
  4897. return isNaN(ch) ? h : Math.min(h, ch);
  4898. };
  4899. helpers.getStyle = function (el, property) {
  4900. return el.currentStyle ?
  4901. el.currentStyle[property] :
  4902. document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  4903. };
  4904. helpers.retinaScale = function (chart, forceRatio) {
  4905. var pixelRatio = chart.currentDevicePixelRatio = forceRatio || window.devicePixelRatio || 1;
  4906. if (pixelRatio === 1) {
  4907. return;
  4908. }
  4909. var canvas = chart.canvas;
  4910. var height = chart.height;
  4911. var width = chart.width;
  4912. canvas.height = height * pixelRatio;
  4913. canvas.width = width * pixelRatio;
  4914. chart.ctx.scale(pixelRatio, pixelRatio);
  4915. // If no style has been set on the canvas, the render size is used as display size,
  4916. // making the chart visually bigger, so let's enforce it to the "correct" values.
  4917. // See https://github.com/chartjs/Chart.js/issues/3575
  4918. if (!canvas.style.height && !canvas.style.width) {
  4919. canvas.style.height = height + 'px';
  4920. canvas.style.width = width + 'px';
  4921. }
  4922. };
  4923. // -- Canvas methods
  4924. helpers.fontString = function (pixelSize, fontStyle, fontFamily) {
  4925. return fontStyle + ' ' + pixelSize + 'px ' + fontFamily;
  4926. };
  4927. helpers.longestText = function (ctx, font, arrayOfThings, cache) {
  4928. cache = cache || {};
  4929. var data = cache.data = cache.data || {};
  4930. var gc = cache.garbageCollect = cache.garbageCollect || [];
  4931. if (cache.font !== font) {
  4932. data = cache.data = {};
  4933. gc = cache.garbageCollect = [];
  4934. cache.font = font;
  4935. }
  4936. ctx.font = font;
  4937. var longest = 0;
  4938. helpers.each(arrayOfThings, function (thing) {
  4939. // Undefined strings and arrays should not be measured
  4940. if (thing !== undefined && thing !== null && helpers.isArray(thing) !== true) {
  4941. longest = helpers.measureText(ctx, data, gc, longest, thing);
  4942. } else if (helpers.isArray(thing)) {
  4943. // if it is an array lets measure each element
  4944. // to do maybe simplify this function a bit so we can do this more recursively?
  4945. helpers.each(thing, function (nestedThing) {
  4946. // Undefined strings and arrays should not be measured
  4947. if (nestedThing !== undefined && nestedThing !== null && !helpers.isArray(nestedThing)) {
  4948. longest = helpers.measureText(ctx, data, gc, longest, nestedThing);
  4949. }
  4950. });
  4951. }
  4952. });
  4953. var gcLen = gc.length / 2;
  4954. if (gcLen > arrayOfThings.length) {
  4955. for (var i = 0; i < gcLen; i++) {
  4956. delete data[gc[i]];
  4957. }
  4958. gc.splice(0, gcLen);
  4959. }
  4960. return longest;
  4961. };
  4962. helpers.measureText = function (ctx, data, gc, longest, string) {
  4963. var textWidth = data[string];
  4964. if (!textWidth) {
  4965. textWidth = data[string] = ctx.measureText(string).width;
  4966. gc.push(string);
  4967. }
  4968. if (textWidth > longest) {
  4969. longest = textWidth;
  4970. }
  4971. return longest;
  4972. };
  4973. helpers.numberOfLabelLines = function (arrayOfThings) {
  4974. var numberOfLines = 1;
  4975. helpers.each(arrayOfThings, function (thing) {
  4976. if (helpers.isArray(thing)) {
  4977. if (thing.length > numberOfLines) {
  4978. numberOfLines = thing.length;
  4979. }
  4980. }
  4981. });
  4982. return numberOfLines;
  4983. };
  4984. helpers.color = !color ?
  4985. function (value) {
  4986. console.error('Color.js not found!');
  4987. return value;
  4988. } :
  4989. function (value) {
  4990. /* global CanvasGradient */
  4991. if (value instanceof CanvasGradient) {
  4992. value = defaults.global.defaultColor;
  4993. }
  4994. return color(value);
  4995. };
  4996. helpers.getHoverColor = function (colorValue) {
  4997. /* global CanvasPattern */
  4998. return (colorValue instanceof CanvasPattern) ?
  4999. colorValue :
  5000. helpers.color(colorValue).saturate(0.5).darken(0.1).rgbString();
  5001. };
  5002. };
  5003. }, {"25": 25, "3": 3, "45": 45}], 28: [function (require, module, exports) {
  5004. 'use strict';
  5005. var helpers = require(45);
  5006. /**
  5007. * Helper function to get relative position for an event
  5008. * @param {Event|IEvent} event - The event to get the position for
  5009. * @param {Chart} chart - The chart
  5010. * @returns {Point} the event position
  5011. */
  5012. function getRelativePosition(e, chart) {
  5013. if (e.native) {
  5014. return {
  5015. x: e.x,
  5016. y: e.y
  5017. };
  5018. }
  5019. return helpers.getRelativePosition(e, chart);
  5020. }
  5021. /**
  5022. * Helper function to traverse all of the visible elements in the chart
  5023. * @param chart {chart} the chart
  5024. * @param handler {Function} the callback to execute for each visible item
  5025. */
  5026. function parseVisibleItems(chart, handler) {
  5027. var datasets = chart.data.datasets;
  5028. var meta, i, j, ilen, jlen;
  5029. for (i = 0, ilen = datasets.length; i < ilen; ++i) {
  5030. if (!chart.isDatasetVisible(i)) {
  5031. continue;
  5032. }
  5033. meta = chart.getDatasetMeta(i);
  5034. for (j = 0, jlen = meta.data.length; j < jlen; ++j) {
  5035. var element = meta.data[j];
  5036. if (!element._view.skip) {
  5037. handler(element);
  5038. }
  5039. }
  5040. }
  5041. }
  5042. /**
  5043. * Helper function to get the items that intersect the event position
  5044. * @param items {ChartElement[]} elements to filter
  5045. * @param position {Point} the point to be nearest to
  5046. * @return {ChartElement[]} the nearest items
  5047. */
  5048. function getIntersectItems(chart, position) {
  5049. var elements = [];
  5050. parseVisibleItems(chart, function (element) {
  5051. if (element.inRange(position.x, position.y)) {
  5052. elements.push(element);
  5053. }
  5054. });
  5055. return elements;
  5056. }
  5057. /**
  5058. * Helper function to get the items nearest to the event position considering all visible items in teh chart
  5059. * @param chart {Chart} the chart to look at elements from
  5060. * @param position {Point} the point to be nearest to
  5061. * @param intersect {Boolean} if true, only consider items that intersect the position
  5062. * @param distanceMetric {Function} function to provide the distance between points
  5063. * @return {ChartElement[]} the nearest items
  5064. */
  5065. function getNearestItems(chart, position, intersect, distanceMetric) {
  5066. var minDistance = Number.POSITIVE_INFINITY;
  5067. var nearestItems = [];
  5068. parseVisibleItems(chart, function (element) {
  5069. if (intersect && !element.inRange(position.x, position.y)) {
  5070. return;
  5071. }
  5072. var center = element.getCenterPoint();
  5073. var distance = distanceMetric(position, center);
  5074. if (distance < minDistance) {
  5075. nearestItems = [element];
  5076. minDistance = distance;
  5077. } else if (distance === minDistance) {
  5078. // Can have multiple items at the same distance in which case we sort by size
  5079. nearestItems.push(element);
  5080. }
  5081. });
  5082. return nearestItems;
  5083. }
  5084. /**
  5085. * Get a distance metric function for two points based on the
  5086. * axis mode setting
  5087. * @param {String} axis the axis mode. x|y|xy
  5088. */
  5089. function getDistanceMetricForAxis(axis) {
  5090. var useX = axis.indexOf('x') !== -1;
  5091. var useY = axis.indexOf('y') !== -1;
  5092. return function (pt1, pt2) {
  5093. var deltaX = useX ? Math.abs(pt1.x - pt2.x) : 0;
  5094. var deltaY = useY ? Math.abs(pt1.y - pt2.y) : 0;
  5095. return Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
  5096. };
  5097. }
  5098. function indexMode(chart, e, options) {
  5099. var position = getRelativePosition(e, chart);
  5100. // Default axis for index mode is 'x' to match old behaviour
  5101. options.axis = options.axis || 'x';
  5102. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5103. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  5104. var elements = [];
  5105. if (!items.length) {
  5106. return [];
  5107. }
  5108. chart.data.datasets.forEach(function (dataset, datasetIndex) {
  5109. if (chart.isDatasetVisible(datasetIndex)) {
  5110. var meta = chart.getDatasetMeta(datasetIndex);
  5111. var element = meta.data[items[0]._index];
  5112. // don't count items that are skipped (null data)
  5113. if (element && !element._view.skip) {
  5114. elements.push(element);
  5115. }
  5116. }
  5117. });
  5118. return elements;
  5119. }
  5120. /**
  5121. * @interface IInteractionOptions
  5122. */
  5123. /**
  5124. * If true, only consider items that intersect the point
  5125. * @name IInterfaceOptions#boolean
  5126. * @type Boolean
  5127. */
  5128. /**
  5129. * Contains interaction related functions
  5130. * @namespace Chart.Interaction
  5131. */
  5132. module.exports = {
  5133. // Helper function for different modes
  5134. modes: {
  5135. single: function (chart, e) {
  5136. var position = getRelativePosition(e, chart);
  5137. var elements = [];
  5138. parseVisibleItems(chart, function (element) {
  5139. if (element.inRange(position.x, position.y)) {
  5140. elements.push(element);
  5141. return elements;
  5142. }
  5143. });
  5144. return elements.slice(0, 1);
  5145. },
  5146. /**
  5147. * @function Chart.Interaction.modes.label
  5148. * @deprecated since version 2.4.0
  5149. * @todo remove at version 3
  5150. * @private
  5151. */
  5152. label: indexMode,
  5153. /**
  5154. * Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something
  5155. * If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item
  5156. * @function Chart.Interaction.modes.index
  5157. * @since v2.4.0
  5158. * @param chart {chart} the chart we are returning items from
  5159. * @param e {Event} the event we are find things at
  5160. * @param options {IInteractionOptions} options to use during interaction
  5161. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5162. */
  5163. index: indexMode,
  5164. /**
  5165. * Returns items in the same dataset. If the options.intersect parameter is true, we only return items if we intersect something
  5166. * If the options.intersect is false, we find the nearest item and return the items in that dataset
  5167. * @function Chart.Interaction.modes.dataset
  5168. * @param chart {chart} the chart we are returning items from
  5169. * @param e {Event} the event we are find things at
  5170. * @param options {IInteractionOptions} options to use during interaction
  5171. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5172. */
  5173. dataset: function (chart, e, options) {
  5174. var position = getRelativePosition(e, chart);
  5175. options.axis = options.axis || 'xy';
  5176. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5177. var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric);
  5178. if (items.length > 0) {
  5179. items = chart.getDatasetMeta(items[0]._datasetIndex).data;
  5180. }
  5181. return items;
  5182. },
  5183. /**
  5184. * @function Chart.Interaction.modes.x-axis
  5185. * @deprecated since version 2.4.0. Use index mode and intersect == true
  5186. * @todo remove at version 3
  5187. * @private
  5188. */
  5189. 'x-axis': function (chart, e) {
  5190. return indexMode(chart, e, {intersect: false});
  5191. },
  5192. /**
  5193. * Point mode returns all elements that hit test based on the event position
  5194. * of the event
  5195. * @function Chart.Interaction.modes.intersect
  5196. * @param chart {chart} the chart we are returning items from
  5197. * @param e {Event} the event we are find things at
  5198. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5199. */
  5200. point: function (chart, e) {
  5201. var position = getRelativePosition(e, chart);
  5202. return getIntersectItems(chart, position);
  5203. },
  5204. /**
  5205. * nearest mode returns the element closest to the point
  5206. * @function Chart.Interaction.modes.intersect
  5207. * @param chart {chart} the chart we are returning items from
  5208. * @param e {Event} the event we are find things at
  5209. * @param options {IInteractionOptions} options to use
  5210. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5211. */
  5212. nearest: function (chart, e, options) {
  5213. var position = getRelativePosition(e, chart);
  5214. options.axis = options.axis || 'xy';
  5215. var distanceMetric = getDistanceMetricForAxis(options.axis);
  5216. var nearestItems = getNearestItems(chart, position, options.intersect, distanceMetric);
  5217. // We have multiple items at the same distance from the event. Now sort by smallest
  5218. if (nearestItems.length > 1) {
  5219. nearestItems.sort(function (a, b) {
  5220. var sizeA = a.getArea();
  5221. var sizeB = b.getArea();
  5222. var ret = sizeA - sizeB;
  5223. if (ret === 0) {
  5224. // if equal sort by dataset index
  5225. ret = a._datasetIndex - b._datasetIndex;
  5226. }
  5227. return ret;
  5228. });
  5229. }
  5230. // Return only 1 item
  5231. return nearestItems.slice(0, 1);
  5232. },
  5233. /**
  5234. * x mode returns the elements that hit-test at the current x coordinate
  5235. * @function Chart.Interaction.modes.x
  5236. * @param chart {chart} the chart we are returning items from
  5237. * @param e {Event} the event we are find things at
  5238. * @param options {IInteractionOptions} options to use
  5239. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5240. */
  5241. x: function (chart, e, options) {
  5242. var position = getRelativePosition(e, chart);
  5243. var items = [];
  5244. var intersectsItem = false;
  5245. parseVisibleItems(chart, function (element) {
  5246. if (element.inXRange(position.x)) {
  5247. items.push(element);
  5248. }
  5249. if (element.inRange(position.x, position.y)) {
  5250. intersectsItem = true;
  5251. }
  5252. });
  5253. // If we want to trigger on an intersect and we don't have any items
  5254. // that intersect the position, return nothing
  5255. if (options.intersect && !intersectsItem) {
  5256. items = [];
  5257. }
  5258. return items;
  5259. },
  5260. /**
  5261. * y mode returns the elements that hit-test at the current y coordinate
  5262. * @function Chart.Interaction.modes.y
  5263. * @param chart {chart} the chart we are returning items from
  5264. * @param e {Event} the event we are find things at
  5265. * @param options {IInteractionOptions} options to use
  5266. * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned
  5267. */
  5268. y: function (chart, e, options) {
  5269. var position = getRelativePosition(e, chart);
  5270. var items = [];
  5271. var intersectsItem = false;
  5272. parseVisibleItems(chart, function (element) {
  5273. if (element.inYRange(position.y)) {
  5274. items.push(element);
  5275. }
  5276. if (element.inRange(position.x, position.y)) {
  5277. intersectsItem = true;
  5278. }
  5279. });
  5280. // If we want to trigger on an intersect and we don't have any items
  5281. // that intersect the position, return nothing
  5282. if (options.intersect && !intersectsItem) {
  5283. items = [];
  5284. }
  5285. return items;
  5286. }
  5287. }
  5288. };
  5289. }, {"45": 45}], 29: [function (require, module, exports) {
  5290. 'use strict';
  5291. var defaults = require(25);
  5292. defaults._set('global', {
  5293. responsive: true,
  5294. responsiveAnimationDuration: 0,
  5295. maintainAspectRatio: true,
  5296. events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
  5297. hover: {
  5298. onHover: null,
  5299. mode: 'nearest',
  5300. intersect: true,
  5301. animationDuration: 400
  5302. },
  5303. onClick: null,
  5304. defaultColor: 'rgba(0,0,0,0.1)',
  5305. defaultFontColor: '#666',
  5306. defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
  5307. defaultFontSize: 12,
  5308. defaultFontStyle: 'normal',
  5309. showLines: true,
  5310. // Element defaults defined in element extensions
  5311. elements: {},
  5312. // Layout options such as padding
  5313. layout: {
  5314. padding: {
  5315. top: 0,
  5316. right: 0,
  5317. bottom: 0,
  5318. left: 0
  5319. }
  5320. }
  5321. });
  5322. module.exports = function () {
  5323. // Occupy the global variable of Chart, and create a simple base class
  5324. var Chart = function (item, config) {
  5325. this.construct(item, config);
  5326. return this;
  5327. };
  5328. Chart.Chart = Chart;
  5329. return Chart;
  5330. };
  5331. }, {"25": 25}], 30: [function (require, module, exports) {
  5332. 'use strict';
  5333. var helpers = require(45);
  5334. function filterByPosition(array, position) {
  5335. return helpers.where(array, function (v) {
  5336. return v.position === position;
  5337. });
  5338. }
  5339. function sortByWeight(array, reverse) {
  5340. array.forEach(function (v, i) {
  5341. v._tmpIndex_ = i;
  5342. return v;
  5343. });
  5344. array.sort(function (a, b) {
  5345. var v0 = reverse ? b : a;
  5346. var v1 = reverse ? a : b;
  5347. return v0.weight === v1.weight ?
  5348. v0._tmpIndex_ - v1._tmpIndex_ :
  5349. v0.weight - v1.weight;
  5350. });
  5351. array.forEach(function (v) {
  5352. delete v._tmpIndex_;
  5353. });
  5354. }
  5355. /**
  5356. * @interface ILayoutItem
  5357. * @prop {String} position - The position of the item in the chart layout. Possible values are
  5358. * 'left', 'top', 'right', 'bottom', and 'chartArea'
  5359. * @prop {Number} weight - The weight used to sort the item. Higher weights are further away from the chart area
  5360. * @prop {Boolean} fullWidth - if true, and the item is horizontal, then push vertical boxes down
  5361. * @prop {Function} isHorizontal - returns true if the layout item is horizontal (ie. top or bottom)
  5362. * @prop {Function} update - Takes two parameters: width and height. Returns size of item
  5363. * @prop {Function} getPadding - Returns an object with padding on the edges
  5364. * @prop {Number} width - Width of item. Must be valid after update()
  5365. * @prop {Number} height - Height of item. Must be valid after update()
  5366. * @prop {Number} left - Left edge of the item. Set by layout system and cannot be used in update
  5367. * @prop {Number} top - Top edge of the item. Set by layout system and cannot be used in update
  5368. * @prop {Number} right - Right edge of the item. Set by layout system and cannot be used in update
  5369. * @prop {Number} bottom - Bottom edge of the item. Set by layout system and cannot be used in update
  5370. */
  5371. // The layout service is very self explanatory. It's responsible for the layout within a chart.
  5372. // Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
  5373. // It is this service's responsibility of carrying out that layout.
  5374. module.exports = {
  5375. defaults: {},
  5376. /**
  5377. * Register a box to a chart.
  5378. * A box is simply a reference to an object that requires layout. eg. Scales, Legend, Title.
  5379. * @param {Chart} chart - the chart to use
  5380. * @param {ILayoutItem} item - the item to add to be layed out
  5381. */
  5382. addBox: function (chart, item) {
  5383. if (!chart.boxes) {
  5384. chart.boxes = [];
  5385. }
  5386. // initialize item with default values
  5387. item.fullWidth = item.fullWidth || false;
  5388. item.position = item.position || 'top';
  5389. item.weight = item.weight || 0;
  5390. chart.boxes.push(item);
  5391. },
  5392. /**
  5393. * Remove a layoutItem from a chart
  5394. * @param {Chart} chart - the chart to remove the box from
  5395. * @param {Object} layoutItem - the item to remove from the layout
  5396. */
  5397. removeBox: function (chart, layoutItem) {
  5398. var index = chart.boxes ? chart.boxes.indexOf(layoutItem) : -1;
  5399. if (index !== -1) {
  5400. chart.boxes.splice(index, 1);
  5401. }
  5402. },
  5403. /**
  5404. * Sets (or updates) options on the given `item`.
  5405. * @param {Chart} chart - the chart in which the item lives (or will be added to)
  5406. * @param {Object} item - the item to configure with the given options
  5407. * @param {Object} options - the new item options.
  5408. */
  5409. configure: function (chart, item, options) {
  5410. var props = ['fullWidth', 'position', 'weight'];
  5411. var ilen = props.length;
  5412. var i = 0;
  5413. var prop;
  5414. for (; i < ilen; ++i) {
  5415. prop = props[i];
  5416. if (options.hasOwnProperty(prop)) {
  5417. item[prop] = options[prop];
  5418. }
  5419. }
  5420. },
  5421. /**
  5422. * Fits boxes of the given chart into the given size by having each box measure itself
  5423. * then running a fitting algorithm
  5424. * @param {Chart} chart - the chart
  5425. * @param {Number} width - the width to fit into
  5426. * @param {Number} height - the height to fit into
  5427. */
  5428. update: function (chart, width, height) {
  5429. if (!chart) {
  5430. return;
  5431. }
  5432. var layoutOptions = chart.options.layout || {};
  5433. var padding = helpers.options.toPadding(layoutOptions.padding);
  5434. var leftPadding = padding.left;
  5435. var rightPadding = padding.right;
  5436. var topPadding = padding.top;
  5437. var bottomPadding = padding.bottom;
  5438. var leftBoxes = filterByPosition(chart.boxes, 'left');
  5439. var rightBoxes = filterByPosition(chart.boxes, 'right');
  5440. var topBoxes = filterByPosition(chart.boxes, 'top');
  5441. var bottomBoxes = filterByPosition(chart.boxes, 'bottom');
  5442. var chartAreaBoxes = filterByPosition(chart.boxes, 'chartArea');
  5443. // Sort boxes by weight. A higher weight is further away from the chart area
  5444. sortByWeight(leftBoxes, true);
  5445. sortByWeight(rightBoxes, false);
  5446. sortByWeight(topBoxes, true);
  5447. sortByWeight(bottomBoxes, false);
  5448. // Essentially we now have any number of boxes on each of the 4 sides.
  5449. // Our canvas looks like the following.
  5450. // The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
  5451. // B1 is the bottom axis
  5452. // There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
  5453. // These locations are single-box locations only, when trying to register a chartArea location that is already taken,
  5454. // an error will be thrown.
  5455. //
  5456. // |----------------------------------------------------|
  5457. // | T1 (Full Width) |
  5458. // |----------------------------------------------------|
  5459. // | | | T2 | |
  5460. // | |----|-------------------------------------|----|
  5461. // | | | C1 | | C2 | |
  5462. // | | |----| |----| |
  5463. // | | | | |
  5464. // | L1 | L2 | ChartArea (C0) | R1 |
  5465. // | | | | |
  5466. // | | |----| |----| |
  5467. // | | | C3 | | C4 | |
  5468. // | |----|-------------------------------------|----|
  5469. // | | | B1 | |
  5470. // |----------------------------------------------------|
  5471. // | B2 (Full Width) |
  5472. // |----------------------------------------------------|
  5473. //
  5474. // What we do to find the best sizing, we do the following
  5475. // 1. Determine the minimum size of the chart area.
  5476. // 2. Split the remaining width equally between each vertical axis
  5477. // 3. Split the remaining height equally between each horizontal axis
  5478. // 4. Give each layout the maximum size it can be. The layout will return it's minimum size
  5479. // 5. Adjust the sizes of each axis based on it's minimum reported size.
  5480. // 6. Refit each axis
  5481. // 7. Position each axis in the final location
  5482. // 8. Tell the chart the final location of the chart area
  5483. // 9. Tell any axes that overlay the chart area the positions of the chart area
  5484. // Step 1
  5485. var chartWidth = width - leftPadding - rightPadding;
  5486. var chartHeight = height - topPadding - bottomPadding;
  5487. var chartAreaWidth = chartWidth / 2; // min 50%
  5488. var chartAreaHeight = chartHeight / 2; // min 50%
  5489. // Step 2
  5490. var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
  5491. // Step 3
  5492. var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
  5493. // Step 4
  5494. var maxChartAreaWidth = chartWidth;
  5495. var maxChartAreaHeight = chartHeight;
  5496. var minBoxSizes = [];
  5497. function getMinimumBoxSize(box) {
  5498. var minSize;
  5499. var isHorizontal = box.isHorizontal();
  5500. if (isHorizontal) {
  5501. minSize = box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
  5502. maxChartAreaHeight -= minSize.height;
  5503. } else {
  5504. minSize = box.update(verticalBoxWidth, maxChartAreaHeight);
  5505. maxChartAreaWidth -= minSize.width;
  5506. }
  5507. minBoxSizes.push({
  5508. horizontal: isHorizontal,
  5509. minSize: minSize,
  5510. box: box,
  5511. });
  5512. }
  5513. helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
  5514. // If a horizontal box has padding, we move the left boxes over to avoid ugly charts (see issue #2478)
  5515. var maxHorizontalLeftPadding = 0;
  5516. var maxHorizontalRightPadding = 0;
  5517. var maxVerticalTopPadding = 0;
  5518. var maxVerticalBottomPadding = 0;
  5519. helpers.each(topBoxes.concat(bottomBoxes), function (horizontalBox) {
  5520. if (horizontalBox.getPadding) {
  5521. var boxPadding = horizontalBox.getPadding();
  5522. maxHorizontalLeftPadding = Math.max(maxHorizontalLeftPadding, boxPadding.left);
  5523. maxHorizontalRightPadding = Math.max(maxHorizontalRightPadding, boxPadding.right);
  5524. }
  5525. });
  5526. helpers.each(leftBoxes.concat(rightBoxes), function (verticalBox) {
  5527. if (verticalBox.getPadding) {
  5528. var boxPadding = verticalBox.getPadding();
  5529. maxVerticalTopPadding = Math.max(maxVerticalTopPadding, boxPadding.top);
  5530. maxVerticalBottomPadding = Math.max(maxVerticalBottomPadding, boxPadding.bottom);
  5531. }
  5532. });
  5533. // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
  5534. // be if the axes are drawn at their minimum sizes.
  5535. // Steps 5 & 6
  5536. var totalLeftBoxesWidth = leftPadding;
  5537. var totalRightBoxesWidth = rightPadding;
  5538. var totalTopBoxesHeight = topPadding;
  5539. var totalBottomBoxesHeight = bottomPadding;
  5540. // Function to fit a box
  5541. function fitBox(box) {
  5542. var minBoxSize = helpers.findNextWhere(minBoxSizes, function (minBox) {
  5543. return minBox.box === box;
  5544. });
  5545. if (minBoxSize) {
  5546. if (box.isHorizontal()) {
  5547. var scaleMargin = {
  5548. left: Math.max(totalLeftBoxesWidth, maxHorizontalLeftPadding),
  5549. right: Math.max(totalRightBoxesWidth, maxHorizontalRightPadding),
  5550. top: 0,
  5551. bottom: 0
  5552. };
  5553. // Don't use min size here because of label rotation. When the labels are rotated, their rotation highly depends
  5554. // on the margin. Sometimes they need to increase in size slightly
  5555. box.update(box.fullWidth ? chartWidth : maxChartAreaWidth, chartHeight / 2, scaleMargin);
  5556. } else {
  5557. box.update(minBoxSize.minSize.width, maxChartAreaHeight);
  5558. }
  5559. }
  5560. }
  5561. // Update, and calculate the left and right margins for the horizontal boxes
  5562. helpers.each(leftBoxes.concat(rightBoxes), fitBox);
  5563. helpers.each(leftBoxes, function (box) {
  5564. totalLeftBoxesWidth += box.width;
  5565. });
  5566. helpers.each(rightBoxes, function (box) {
  5567. totalRightBoxesWidth += box.width;
  5568. });
  5569. // Set the Left and Right margins for the horizontal boxes
  5570. helpers.each(topBoxes.concat(bottomBoxes), fitBox);
  5571. // Figure out how much margin is on the top and bottom of the vertical boxes
  5572. helpers.each(topBoxes, function (box) {
  5573. totalTopBoxesHeight += box.height;
  5574. });
  5575. helpers.each(bottomBoxes, function (box) {
  5576. totalBottomBoxesHeight += box.height;
  5577. });
  5578. function finalFitVerticalBox(box) {
  5579. var minBoxSize = helpers.findNextWhere(minBoxSizes, function (minSize) {
  5580. return minSize.box === box;
  5581. });
  5582. var scaleMargin = {
  5583. left: 0,
  5584. right: 0,
  5585. top: totalTopBoxesHeight,
  5586. bottom: totalBottomBoxesHeight
  5587. };
  5588. if (minBoxSize) {
  5589. box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
  5590. }
  5591. }
  5592. // Let the left layout know the final margin
  5593. helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
  5594. // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
  5595. totalLeftBoxesWidth = leftPadding;
  5596. totalRightBoxesWidth = rightPadding;
  5597. totalTopBoxesHeight = topPadding;
  5598. totalBottomBoxesHeight = bottomPadding;
  5599. helpers.each(leftBoxes, function (box) {
  5600. totalLeftBoxesWidth += box.width;
  5601. });
  5602. helpers.each(rightBoxes, function (box) {
  5603. totalRightBoxesWidth += box.width;
  5604. });
  5605. helpers.each(topBoxes, function (box) {
  5606. totalTopBoxesHeight += box.height;
  5607. });
  5608. helpers.each(bottomBoxes, function (box) {
  5609. totalBottomBoxesHeight += box.height;
  5610. });
  5611. // We may be adding some padding to account for rotated x axis labels
  5612. var leftPaddingAddition = Math.max(maxHorizontalLeftPadding - totalLeftBoxesWidth, 0);
  5613. totalLeftBoxesWidth += leftPaddingAddition;
  5614. totalRightBoxesWidth += Math.max(maxHorizontalRightPadding - totalRightBoxesWidth, 0);
  5615. var topPaddingAddition = Math.max(maxVerticalTopPadding - totalTopBoxesHeight, 0);
  5616. totalTopBoxesHeight += topPaddingAddition;
  5617. totalBottomBoxesHeight += Math.max(maxVerticalBottomPadding - totalBottomBoxesHeight, 0);
  5618. // Figure out if our chart area changed. This would occur if the dataset layout label rotation
  5619. // changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
  5620. // without calling `fit` again
  5621. var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
  5622. var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
  5623. if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
  5624. helpers.each(leftBoxes, function (box) {
  5625. box.height = newMaxChartAreaHeight;
  5626. });
  5627. helpers.each(rightBoxes, function (box) {
  5628. box.height = newMaxChartAreaHeight;
  5629. });
  5630. helpers.each(topBoxes, function (box) {
  5631. if (!box.fullWidth) {
  5632. box.width = newMaxChartAreaWidth;
  5633. }
  5634. });
  5635. helpers.each(bottomBoxes, function (box) {
  5636. if (!box.fullWidth) {
  5637. box.width = newMaxChartAreaWidth;
  5638. }
  5639. });
  5640. maxChartAreaHeight = newMaxChartAreaHeight;
  5641. maxChartAreaWidth = newMaxChartAreaWidth;
  5642. }
  5643. // Step 7 - Position the boxes
  5644. var left = leftPadding + leftPaddingAddition;
  5645. var top = topPadding + topPaddingAddition;
  5646. function placeBox(box) {
  5647. if (box.isHorizontal()) {
  5648. box.left = box.fullWidth ? leftPadding : totalLeftBoxesWidth;
  5649. box.right = box.fullWidth ? width - rightPadding : totalLeftBoxesWidth + maxChartAreaWidth;
  5650. box.top = top;
  5651. box.bottom = top + box.height;
  5652. // Move to next point
  5653. top = box.bottom;
  5654. } else {
  5655. box.left = left;
  5656. box.right = left + box.width;
  5657. box.top = totalTopBoxesHeight;
  5658. box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
  5659. // Move to next point
  5660. left = box.right;
  5661. }
  5662. }
  5663. helpers.each(leftBoxes.concat(topBoxes), placeBox);
  5664. // Account for chart width and height
  5665. left += maxChartAreaWidth;
  5666. top += maxChartAreaHeight;
  5667. helpers.each(rightBoxes, placeBox);
  5668. helpers.each(bottomBoxes, placeBox);
  5669. // Step 8
  5670. chart.chartArea = {
  5671. left: totalLeftBoxesWidth,
  5672. top: totalTopBoxesHeight,
  5673. right: totalLeftBoxesWidth + maxChartAreaWidth,
  5674. bottom: totalTopBoxesHeight + maxChartAreaHeight
  5675. };
  5676. // Step 9
  5677. helpers.each(chartAreaBoxes, function (box) {
  5678. box.left = chart.chartArea.left;
  5679. box.top = chart.chartArea.top;
  5680. box.right = chart.chartArea.right;
  5681. box.bottom = chart.chartArea.bottom;
  5682. box.update(maxChartAreaWidth, maxChartAreaHeight);
  5683. });
  5684. }
  5685. };
  5686. }, {"45": 45}], 31: [function (require, module, exports) {
  5687. 'use strict';
  5688. var defaults = require(25);
  5689. var helpers = require(45);
  5690. defaults._set('global', {
  5691. plugins: {}
  5692. });
  5693. /**
  5694. * The plugin service singleton
  5695. * @namespace Chart.plugins
  5696. * @since 2.1.0
  5697. */
  5698. module.exports = {
  5699. /**
  5700. * Globally registered plugins.
  5701. * @private
  5702. */
  5703. _plugins: [],
  5704. /**
  5705. * This identifier is used to invalidate the descriptors cache attached to each chart
  5706. * when a global plugin is registered or unregistered. In this case, the cache ID is
  5707. * incremented and descriptors are regenerated during following API calls.
  5708. * @private
  5709. */
  5710. _cacheId: 0,
  5711. /**
  5712. * Registers the given plugin(s) if not already registered.
  5713. * @param {Array|Object} plugins plugin instance(s).
  5714. */
  5715. register: function (plugins) {
  5716. var p = this._plugins;
  5717. ([]).concat(plugins).forEach(function (plugin) {
  5718. if (p.indexOf(plugin) === -1) {
  5719. p.push(plugin);
  5720. }
  5721. });
  5722. this._cacheId++;
  5723. },
  5724. /**
  5725. * Unregisters the given plugin(s) only if registered.
  5726. * @param {Array|Object} plugins plugin instance(s).
  5727. */
  5728. unregister: function (plugins) {
  5729. var p = this._plugins;
  5730. ([]).concat(plugins).forEach(function (plugin) {
  5731. var idx = p.indexOf(plugin);
  5732. if (idx !== -1) {
  5733. p.splice(idx, 1);
  5734. }
  5735. });
  5736. this._cacheId++;
  5737. },
  5738. /**
  5739. * Remove all registered plugins.
  5740. * @since 2.1.5
  5741. */
  5742. clear: function () {
  5743. this._plugins = [];
  5744. this._cacheId++;
  5745. },
  5746. /**
  5747. * Returns the number of registered plugins?
  5748. * @returns {Number}
  5749. * @since 2.1.5
  5750. */
  5751. count: function () {
  5752. return this._plugins.length;
  5753. },
  5754. /**
  5755. * Returns all registered plugin instances.
  5756. * @returns {Array} array of plugin objects.
  5757. * @since 2.1.5
  5758. */
  5759. getAll: function () {
  5760. return this._plugins;
  5761. },
  5762. /**
  5763. * Calls enabled plugins for `chart` on the specified hook and with the given args.
  5764. * This method immediately returns as soon as a plugin explicitly returns false. The
  5765. * returned value can be used, for instance, to interrupt the current action.
  5766. * @param {Object} chart - The chart instance for which plugins should be called.
  5767. * @param {String} hook - The name of the plugin method to call (e.g. 'beforeUpdate').
  5768. * @param {Array} [args] - Extra arguments to apply to the hook call.
  5769. * @returns {Boolean} false if any of the plugins return false, else returns true.
  5770. */
  5771. notify: function (chart, hook, args) {
  5772. var descriptors = this.descriptors(chart);
  5773. var ilen = descriptors.length;
  5774. var i, descriptor, plugin, params, method;
  5775. for (i = 0; i < ilen; ++i) {
  5776. descriptor = descriptors[i];
  5777. plugin = descriptor.plugin;
  5778. method = plugin[hook];
  5779. if (typeof method === 'function') {
  5780. params = [chart].concat(args || []);
  5781. params.push(descriptor.options);
  5782. if (method.apply(plugin, params) === false) {
  5783. return false;
  5784. }
  5785. }
  5786. }
  5787. return true;
  5788. },
  5789. /**
  5790. * Returns descriptors of enabled plugins for the given chart.
  5791. * @returns {Array} [{ plugin, options }]
  5792. * @private
  5793. */
  5794. descriptors: function (chart) {
  5795. var cache = chart.$plugins || (chart.$plugins = {});
  5796. if (cache.id === this._cacheId) {
  5797. return cache.descriptors;
  5798. }
  5799. var plugins = [];
  5800. var descriptors = [];
  5801. var config = (chart && chart.config) || {};
  5802. var options = (config.options && config.options.plugins) || {};
  5803. this._plugins.concat(config.plugins || []).forEach(function (plugin) {
  5804. var idx = plugins.indexOf(plugin);
  5805. if (idx !== -1) {
  5806. return;
  5807. }
  5808. var id = plugin.id;
  5809. var opts = options[id];
  5810. if (opts === false) {
  5811. return;
  5812. }
  5813. if (opts === true) {
  5814. opts = helpers.clone(defaults.global.plugins[id]);
  5815. }
  5816. plugins.push(plugin);
  5817. descriptors.push({
  5818. plugin: plugin,
  5819. options: opts || {}
  5820. });
  5821. });
  5822. cache.descriptors = descriptors;
  5823. cache.id = this._cacheId;
  5824. return descriptors;
  5825. },
  5826. /**
  5827. * Invalidates cache for the given chart: descriptors hold a reference on plugin option,
  5828. * but in some cases, this reference can be changed by the user when updating options.
  5829. * https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
  5830. * @private
  5831. */
  5832. _invalidate: function (chart) {
  5833. delete chart.$plugins;
  5834. }
  5835. };
  5836. /**
  5837. * Plugin extension hooks.
  5838. * @interface IPlugin
  5839. * @since 2.1.0
  5840. */
  5841. /**
  5842. * @method IPlugin#beforeInit
  5843. * @desc Called before initializing `chart`.
  5844. * @param {Chart.Controller} chart - The chart instance.
  5845. * @param {Object} options - The plugin options.
  5846. */
  5847. /**
  5848. * @method IPlugin#afterInit
  5849. * @desc Called after `chart` has been initialized and before the first update.
  5850. * @param {Chart.Controller} chart - The chart instance.
  5851. * @param {Object} options - The plugin options.
  5852. */
  5853. /**
  5854. * @method IPlugin#beforeUpdate
  5855. * @desc Called before updating `chart`. If any plugin returns `false`, the update
  5856. * is cancelled (and thus subsequent render(s)) until another `update` is triggered.
  5857. * @param {Chart.Controller} chart - The chart instance.
  5858. * @param {Object} options - The plugin options.
  5859. * @returns {Boolean} `false` to cancel the chart update.
  5860. */
  5861. /**
  5862. * @method IPlugin#afterUpdate
  5863. * @desc Called after `chart` has been updated and before rendering. Note that this
  5864. * hook will not be called if the chart update has been previously cancelled.
  5865. * @param {Chart.Controller} chart - The chart instance.
  5866. * @param {Object} options - The plugin options.
  5867. */
  5868. /**
  5869. * @method IPlugin#beforeDatasetsUpdate
  5870. * @desc Called before updating the `chart` datasets. If any plugin returns `false`,
  5871. * the datasets update is cancelled until another `update` is triggered.
  5872. * @param {Chart.Controller} chart - The chart instance.
  5873. * @param {Object} options - The plugin options.
  5874. * @returns {Boolean} false to cancel the datasets update.
  5875. * @since version 2.1.5
  5876. */
  5877. /**
  5878. * @method IPlugin#afterDatasetsUpdate
  5879. * @desc Called after the `chart` datasets have been updated. Note that this hook
  5880. * will not be called if the datasets update has been previously cancelled.
  5881. * @param {Chart.Controller} chart - The chart instance.
  5882. * @param {Object} options - The plugin options.
  5883. * @since version 2.1.5
  5884. */
  5885. /**
  5886. * @method IPlugin#beforeDatasetUpdate
  5887. * @desc Called before updating the `chart` dataset at the given `args.index`. If any plugin
  5888. * returns `false`, the datasets update is cancelled until another `update` is triggered.
  5889. * @param {Chart} chart - The chart instance.
  5890. * @param {Object} args - The call arguments.
  5891. * @param {Number} args.index - The dataset index.
  5892. * @param {Object} args.meta - The dataset metadata.
  5893. * @param {Object} options - The plugin options.
  5894. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  5895. */
  5896. /**
  5897. * @method IPlugin#afterDatasetUpdate
  5898. * @desc Called after the `chart` datasets at the given `args.index` has been updated. Note
  5899. * that this hook will not be called if the datasets update has been previously cancelled.
  5900. * @param {Chart} chart - The chart instance.
  5901. * @param {Object} args - The call arguments.
  5902. * @param {Number} args.index - The dataset index.
  5903. * @param {Object} args.meta - The dataset metadata.
  5904. * @param {Object} options - The plugin options.
  5905. */
  5906. /**
  5907. * @method IPlugin#beforeLayout
  5908. * @desc Called before laying out `chart`. If any plugin returns `false`,
  5909. * the layout update is cancelled until another `update` is triggered.
  5910. * @param {Chart.Controller} chart - The chart instance.
  5911. * @param {Object} options - The plugin options.
  5912. * @returns {Boolean} `false` to cancel the chart layout.
  5913. */
  5914. /**
  5915. * @method IPlugin#afterLayout
  5916. * @desc Called after the `chart` has been layed out. Note that this hook will not
  5917. * be called if the layout update has been previously cancelled.
  5918. * @param {Chart.Controller} chart - The chart instance.
  5919. * @param {Object} options - The plugin options.
  5920. */
  5921. /**
  5922. * @method IPlugin#beforeRender
  5923. * @desc Called before rendering `chart`. If any plugin returns `false`,
  5924. * the rendering is cancelled until another `render` is triggered.
  5925. * @param {Chart.Controller} chart - The chart instance.
  5926. * @param {Object} options - The plugin options.
  5927. * @returns {Boolean} `false` to cancel the chart rendering.
  5928. */
  5929. /**
  5930. * @method IPlugin#afterRender
  5931. * @desc Called after the `chart` has been fully rendered (and animation completed). Note
  5932. * that this hook will not be called if the rendering has been previously cancelled.
  5933. * @param {Chart.Controller} chart - The chart instance.
  5934. * @param {Object} options - The plugin options.
  5935. */
  5936. /**
  5937. * @method IPlugin#beforeDraw
  5938. * @desc Called before drawing `chart` at every animation frame specified by the given
  5939. * easing value. If any plugin returns `false`, the frame drawing is cancelled until
  5940. * another `render` is triggered.
  5941. * @param {Chart.Controller} chart - The chart instance.
  5942. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5943. * @param {Object} options - The plugin options.
  5944. * @returns {Boolean} `false` to cancel the chart drawing.
  5945. */
  5946. /**
  5947. * @method IPlugin#afterDraw
  5948. * @desc Called after the `chart` has been drawn for the specific easing value. Note
  5949. * that this hook will not be called if the drawing has been previously cancelled.
  5950. * @param {Chart.Controller} chart - The chart instance.
  5951. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5952. * @param {Object} options - The plugin options.
  5953. */
  5954. /**
  5955. * @method IPlugin#beforeDatasetsDraw
  5956. * @desc Called before drawing the `chart` datasets. If any plugin returns `false`,
  5957. * the datasets drawing is cancelled until another `render` is triggered.
  5958. * @param {Chart.Controller} chart - The chart instance.
  5959. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5960. * @param {Object} options - The plugin options.
  5961. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  5962. */
  5963. /**
  5964. * @method IPlugin#afterDatasetsDraw
  5965. * @desc Called after the `chart` datasets have been drawn. Note that this hook
  5966. * will not be called if the datasets drawing has been previously cancelled.
  5967. * @param {Chart.Controller} chart - The chart instance.
  5968. * @param {Number} easingValue - The current animation value, between 0.0 and 1.0.
  5969. * @param {Object} options - The plugin options.
  5970. */
  5971. /**
  5972. * @method IPlugin#beforeDatasetDraw
  5973. * @desc Called before drawing the `chart` dataset at the given `args.index` (datasets
  5974. * are drawn in the reverse order). If any plugin returns `false`, the datasets drawing
  5975. * is cancelled until another `render` is triggered.
  5976. * @param {Chart} chart - The chart instance.
  5977. * @param {Object} args - The call arguments.
  5978. * @param {Number} args.index - The dataset index.
  5979. * @param {Object} args.meta - The dataset metadata.
  5980. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5981. * @param {Object} options - The plugin options.
  5982. * @returns {Boolean} `false` to cancel the chart datasets drawing.
  5983. */
  5984. /**
  5985. * @method IPlugin#afterDatasetDraw
  5986. * @desc Called after the `chart` datasets at the given `args.index` have been drawn
  5987. * (datasets are drawn in the reverse order). Note that this hook will not be called
  5988. * if the datasets drawing has been previously cancelled.
  5989. * @param {Chart} chart - The chart instance.
  5990. * @param {Object} args - The call arguments.
  5991. * @param {Number} args.index - The dataset index.
  5992. * @param {Object} args.meta - The dataset metadata.
  5993. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  5994. * @param {Object} options - The plugin options.
  5995. */
  5996. /**
  5997. * @method IPlugin#beforeTooltipDraw
  5998. * @desc Called before drawing the `tooltip`. If any plugin returns `false`,
  5999. * the tooltip drawing is cancelled until another `render` is triggered.
  6000. * @param {Chart} chart - The chart instance.
  6001. * @param {Object} args - The call arguments.
  6002. * @param {Object} args.tooltip - The tooltip.
  6003. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  6004. * @param {Object} options - The plugin options.
  6005. * @returns {Boolean} `false` to cancel the chart tooltip drawing.
  6006. */
  6007. /**
  6008. * @method IPlugin#afterTooltipDraw
  6009. * @desc Called after drawing the `tooltip`. Note that this hook will not
  6010. * be called if the tooltip drawing has been previously cancelled.
  6011. * @param {Chart} chart - The chart instance.
  6012. * @param {Object} args - The call arguments.
  6013. * @param {Object} args.tooltip - The tooltip.
  6014. * @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
  6015. * @param {Object} options - The plugin options.
  6016. */
  6017. /**
  6018. * @method IPlugin#beforeEvent
  6019. * @desc Called before processing the specified `event`. If any plugin returns `false`,
  6020. * the event will be discarded.
  6021. * @param {Chart.Controller} chart - The chart instance.
  6022. * @param {IEvent} event - The event object.
  6023. * @param {Object} options - The plugin options.
  6024. */
  6025. /**
  6026. * @method IPlugin#afterEvent
  6027. * @desc Called after the `event` has been consumed. Note that this hook
  6028. * will not be called if the `event` has been previously discarded.
  6029. * @param {Chart.Controller} chart - The chart instance.
  6030. * @param {IEvent} event - The event object.
  6031. * @param {Object} options - The plugin options.
  6032. */
  6033. /**
  6034. * @method IPlugin#resize
  6035. * @desc Called after the chart as been resized.
  6036. * @param {Chart.Controller} chart - The chart instance.
  6037. * @param {Number} size - The new canvas display size (eq. canvas.style width & height).
  6038. * @param {Object} options - The plugin options.
  6039. */
  6040. /**
  6041. * @method IPlugin#destroy
  6042. * @desc Called after the chart as been destroyed.
  6043. * @param {Chart.Controller} chart - The chart instance.
  6044. * @param {Object} options - The plugin options.
  6045. */
  6046. }, {"25": 25, "45": 45}], 32: [function (require, module, exports) {
  6047. 'use strict';
  6048. var defaults = require(25);
  6049. var Element = require(26);
  6050. var helpers = require(45);
  6051. var Ticks = require(34);
  6052. defaults._set('scale', {
  6053. display: true,
  6054. position: 'left',
  6055. offset: false,
  6056. // grid line settings
  6057. gridLines: {
  6058. display: true,
  6059. color: 'rgba(0, 0, 0, 0.1)',
  6060. lineWidth: 1,
  6061. drawBorder: true,
  6062. drawOnChartArea: true,
  6063. drawTicks: true,
  6064. tickMarkLength: 10,
  6065. zeroLineWidth: 1,
  6066. zeroLineColor: 'rgba(0,0,0,0.25)',
  6067. zeroLineBorderDash: [],
  6068. zeroLineBorderDashOffset: 0.0,
  6069. offsetGridLines: false,
  6070. borderDash: [],
  6071. borderDashOffset: 0.0
  6072. },
  6073. // scale label
  6074. scaleLabel: {
  6075. // display property
  6076. display: false,
  6077. // actual label
  6078. labelString: '',
  6079. // line height
  6080. lineHeight: 1.2,
  6081. // top/bottom padding
  6082. padding: {
  6083. top: 4,
  6084. bottom: 4
  6085. }
  6086. },
  6087. // label settings
  6088. ticks: {
  6089. beginAtZero: false,
  6090. minRotation: 0,
  6091. maxRotation: 50,
  6092. mirror: false,
  6093. padding: 0,
  6094. reverse: false,
  6095. display: true,
  6096. autoSkip: true,
  6097. autoSkipPadding: 0,
  6098. labelOffset: 0,
  6099. // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
  6100. callback: Ticks.formatters.values,
  6101. minor: {},
  6102. major: {}
  6103. }
  6104. });
  6105. function labelsFromTicks(ticks) {
  6106. var labels = [];
  6107. var i, ilen;
  6108. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  6109. labels.push(ticks[i].label);
  6110. }
  6111. return labels;
  6112. }
  6113. function getLineValue(scale, index, offsetGridLines) {
  6114. var lineValue = scale.getPixelForTick(index);
  6115. if (offsetGridLines) {
  6116. if (index === 0) {
  6117. lineValue -= (scale.getPixelForTick(1) - lineValue) / 2;
  6118. } else {
  6119. lineValue -= (lineValue - scale.getPixelForTick(index - 1)) / 2;
  6120. }
  6121. }
  6122. return lineValue;
  6123. }
  6124. module.exports = function (Chart) {
  6125. function computeTextSize(context, tick, font) {
  6126. return helpers.isArray(tick) ?
  6127. helpers.longestText(context, font, tick) :
  6128. context.measureText(tick).width;
  6129. }
  6130. function parseFontOptions(options) {
  6131. var valueOrDefault = helpers.valueOrDefault;
  6132. var globalDefaults = defaults.global;
  6133. var size = valueOrDefault(options.fontSize, globalDefaults.defaultFontSize);
  6134. var style = valueOrDefault(options.fontStyle, globalDefaults.defaultFontStyle);
  6135. var family = valueOrDefault(options.fontFamily, globalDefaults.defaultFontFamily);
  6136. return {
  6137. size: size,
  6138. style: style,
  6139. family: family,
  6140. font: helpers.fontString(size, style, family)
  6141. };
  6142. }
  6143. function parseLineHeight(options) {
  6144. return helpers.options.toLineHeight(
  6145. helpers.valueOrDefault(options.lineHeight, 1.2),
  6146. helpers.valueOrDefault(options.fontSize, defaults.global.defaultFontSize));
  6147. }
  6148. Chart.Scale = Element.extend({
  6149. /**
  6150. * Get the padding needed for the scale
  6151. * @method getPadding
  6152. * @private
  6153. * @returns {Padding} the necessary padding
  6154. */
  6155. getPadding: function () {
  6156. var me = this;
  6157. return {
  6158. left: me.paddingLeft || 0,
  6159. top: me.paddingTop || 0,
  6160. right: me.paddingRight || 0,
  6161. bottom: me.paddingBottom || 0
  6162. };
  6163. },
  6164. /**
  6165. * Returns the scale tick objects ({label, major})
  6166. * @since 2.7
  6167. */
  6168. getTicks: function () {
  6169. return this._ticks;
  6170. },
  6171. // These methods are ordered by lifecyle. Utilities then follow.
  6172. // Any function defined here is inherited by all scale types.
  6173. // Any function can be extended by the scale type
  6174. mergeTicksOptions: function () {
  6175. var ticks = this.options.ticks;
  6176. if (ticks.minor === false) {
  6177. ticks.minor = {
  6178. display: false
  6179. };
  6180. }
  6181. if (ticks.major === false) {
  6182. ticks.major = {
  6183. display: false
  6184. };
  6185. }
  6186. for (var key in ticks) {
  6187. if (key !== 'major' && key !== 'minor') {
  6188. if (typeof ticks.minor[key] === 'undefined') {
  6189. ticks.minor[key] = ticks[key];
  6190. }
  6191. if (typeof ticks.major[key] === 'undefined') {
  6192. ticks.major[key] = ticks[key];
  6193. }
  6194. }
  6195. }
  6196. },
  6197. beforeUpdate: function () {
  6198. helpers.callback(this.options.beforeUpdate, [this]);
  6199. },
  6200. update: function (maxWidth, maxHeight, margins) {
  6201. var me = this;
  6202. var i, ilen, labels, label, ticks, tick;
  6203. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  6204. me.beforeUpdate();
  6205. // Absorb the master measurements
  6206. me.maxWidth = maxWidth;
  6207. me.maxHeight = maxHeight;
  6208. me.margins = helpers.extend({
  6209. left: 0,
  6210. right: 0,
  6211. top: 0,
  6212. bottom: 0
  6213. }, margins);
  6214. me.longestTextCache = me.longestTextCache || {};
  6215. // Dimensions
  6216. me.beforeSetDimensions();
  6217. me.setDimensions();
  6218. me.afterSetDimensions();
  6219. // Data min/max
  6220. me.beforeDataLimits();
  6221. me.determineDataLimits();
  6222. me.afterDataLimits();
  6223. // Ticks - `this.ticks` is now DEPRECATED!
  6224. // Internal ticks are now stored as objects in the PRIVATE `this._ticks` member
  6225. // and must not be accessed directly from outside this class. `this.ticks` being
  6226. // around for long time and not marked as private, we can't change its structure
  6227. // without unexpected breaking changes. If you need to access the scale ticks,
  6228. // use scale.getTicks() instead.
  6229. me.beforeBuildTicks();
  6230. // New implementations should return an array of objects but for BACKWARD COMPAT,
  6231. // we still support no return (`this.ticks` internally set by calling this method).
  6232. ticks = me.buildTicks() || [];
  6233. me.afterBuildTicks();
  6234. me.beforeTickToLabelConversion();
  6235. // New implementations should return the formatted tick labels but for BACKWARD
  6236. // COMPAT, we still support no return (`this.ticks` internally changed by calling
  6237. // this method and supposed to contain only string values).
  6238. labels = me.convertTicksToLabels(ticks) || me.ticks;
  6239. me.afterTickToLabelConversion();
  6240. me.ticks = labels; // BACKWARD COMPATIBILITY
  6241. // IMPORTANT: from this point, we consider that `this.ticks` will NEVER change!
  6242. // BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
  6243. for (i = 0, ilen = labels.length; i < ilen; ++i) {
  6244. label = labels[i];
  6245. tick = ticks[i];
  6246. if (!tick) {
  6247. ticks.push(tick = {
  6248. label: label,
  6249. major: false
  6250. });
  6251. } else {
  6252. tick.label = label;
  6253. }
  6254. }
  6255. me._ticks = ticks;
  6256. // Tick Rotation
  6257. me.beforeCalculateTickRotation();
  6258. me.calculateTickRotation();
  6259. me.afterCalculateTickRotation();
  6260. // Fit
  6261. me.beforeFit();
  6262. me.fit();
  6263. me.afterFit();
  6264. //
  6265. me.afterUpdate();
  6266. return me.minSize;
  6267. },
  6268. afterUpdate: function () {
  6269. helpers.callback(this.options.afterUpdate, [this]);
  6270. },
  6271. //
  6272. beforeSetDimensions: function () {
  6273. helpers.callback(this.options.beforeSetDimensions, [this]);
  6274. },
  6275. setDimensions: function () {
  6276. var me = this;
  6277. // Set the unconstrained dimension before label rotation
  6278. if (me.isHorizontal()) {
  6279. // Reset position before calculating rotation
  6280. me.width = me.maxWidth;
  6281. me.left = 0;
  6282. me.right = me.width;
  6283. } else {
  6284. me.height = me.maxHeight;
  6285. // Reset position before calculating rotation
  6286. me.top = 0;
  6287. me.bottom = me.height;
  6288. }
  6289. // Reset padding
  6290. me.paddingLeft = 0;
  6291. me.paddingTop = 0;
  6292. me.paddingRight = 0;
  6293. me.paddingBottom = 0;
  6294. },
  6295. afterSetDimensions: function () {
  6296. helpers.callback(this.options.afterSetDimensions, [this]);
  6297. },
  6298. // Data limits
  6299. beforeDataLimits: function () {
  6300. helpers.callback(this.options.beforeDataLimits, [this]);
  6301. },
  6302. determineDataLimits: helpers.noop,
  6303. afterDataLimits: function () {
  6304. helpers.callback(this.options.afterDataLimits, [this]);
  6305. },
  6306. //
  6307. beforeBuildTicks: function () {
  6308. helpers.callback(this.options.beforeBuildTicks, [this]);
  6309. },
  6310. buildTicks: helpers.noop,
  6311. afterBuildTicks: function () {
  6312. helpers.callback(this.options.afterBuildTicks, [this]);
  6313. },
  6314. beforeTickToLabelConversion: function () {
  6315. helpers.callback(this.options.beforeTickToLabelConversion, [this]);
  6316. },
  6317. convertTicksToLabels: function () {
  6318. var me = this;
  6319. // Convert ticks to strings
  6320. var tickOpts = me.options.ticks;
  6321. me.ticks = me.ticks.map(tickOpts.userCallback || tickOpts.callback, this);
  6322. },
  6323. afterTickToLabelConversion: function () {
  6324. helpers.callback(this.options.afterTickToLabelConversion, [this]);
  6325. },
  6326. //
  6327. beforeCalculateTickRotation: function () {
  6328. helpers.callback(this.options.beforeCalculateTickRotation, [this]);
  6329. },
  6330. calculateTickRotation: function () {
  6331. var me = this;
  6332. var context = me.ctx;
  6333. var tickOpts = me.options.ticks;
  6334. var labels = labelsFromTicks(me._ticks);
  6335. // Get the width of each grid by calculating the difference
  6336. // between x offsets between 0 and 1.
  6337. var tickFont = parseFontOptions(tickOpts);
  6338. context.font = tickFont.font;
  6339. var labelRotation = tickOpts.minRotation || 0;
  6340. if (labels.length && me.options.display && me.isHorizontal()) {
  6341. var originalLabelWidth = helpers.longestText(context, tickFont.font, labels, me.longestTextCache);
  6342. var labelWidth = originalLabelWidth;
  6343. var cosRotation, sinRotation;
  6344. // Allow 3 pixels x2 padding either side for label readability
  6345. var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6;
  6346. // Max label rotation can be set or default to 90 - also act as a loop counter
  6347. while (labelWidth > tickWidth && labelRotation < tickOpts.maxRotation) {
  6348. var angleRadians = helpers.toRadians(labelRotation);
  6349. cosRotation = Math.cos(angleRadians);
  6350. sinRotation = Math.sin(angleRadians);
  6351. if (sinRotation * originalLabelWidth > me.maxHeight) {
  6352. // go back one step
  6353. labelRotation--;
  6354. break;
  6355. }
  6356. labelRotation++;
  6357. labelWidth = cosRotation * originalLabelWidth;
  6358. }
  6359. }
  6360. me.labelRotation = labelRotation;
  6361. },
  6362. afterCalculateTickRotation: function () {
  6363. helpers.callback(this.options.afterCalculateTickRotation, [this]);
  6364. },
  6365. //
  6366. beforeFit: function () {
  6367. helpers.callback(this.options.beforeFit, [this]);
  6368. },
  6369. fit: function () {
  6370. var me = this;
  6371. // Reset
  6372. var minSize = me.minSize = {
  6373. width: 0,
  6374. height: 0
  6375. };
  6376. var labels = labelsFromTicks(me._ticks);
  6377. var opts = me.options;
  6378. var tickOpts = opts.ticks;
  6379. var scaleLabelOpts = opts.scaleLabel;
  6380. var gridLineOpts = opts.gridLines;
  6381. var display = opts.display;
  6382. var isHorizontal = me.isHorizontal();
  6383. var tickFont = parseFontOptions(tickOpts);
  6384. var tickMarkLength = opts.gridLines.tickMarkLength;
  6385. // Width
  6386. if (isHorizontal) {
  6387. // subtract the margins to line up with the chartArea if we are a full width scale
  6388. minSize.width = me.isFullWidth() ? me.maxWidth - me.margins.left - me.margins.right : me.maxWidth;
  6389. } else {
  6390. minSize.width = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6391. }
  6392. // height
  6393. if (isHorizontal) {
  6394. minSize.height = display && gridLineOpts.drawTicks ? tickMarkLength : 0;
  6395. } else {
  6396. minSize.height = me.maxHeight; // fill all the height
  6397. }
  6398. // Are we showing a title for the scale?
  6399. if (scaleLabelOpts.display && display) {
  6400. var scaleLabelLineHeight = parseLineHeight(scaleLabelOpts);
  6401. var scaleLabelPadding = helpers.options.toPadding(scaleLabelOpts.padding);
  6402. var deltaHeight = scaleLabelLineHeight + scaleLabelPadding.height;
  6403. if (isHorizontal) {
  6404. minSize.height += deltaHeight;
  6405. } else {
  6406. minSize.width += deltaHeight;
  6407. }
  6408. }
  6409. // Don't bother fitting the ticks if we are not showing them
  6410. if (tickOpts.display && display) {
  6411. var largestTextWidth = helpers.longestText(me.ctx, tickFont.font, labels, me.longestTextCache);
  6412. var tallestLabelHeightInLines = helpers.numberOfLabelLines(labels);
  6413. var lineSpace = tickFont.size * 0.5;
  6414. var tickPadding = me.options.ticks.padding;
  6415. if (isHorizontal) {
  6416. // A horizontal axis is more constrained by the height.
  6417. me.longestLabelWidth = largestTextWidth;
  6418. var angleRadians = helpers.toRadians(me.labelRotation);
  6419. var cosRotation = Math.cos(angleRadians);
  6420. var sinRotation = Math.sin(angleRadians);
  6421. // TODO - improve this calculation
  6422. var labelHeight = (sinRotation * largestTextWidth)
  6423. + (tickFont.size * tallestLabelHeightInLines)
  6424. + (lineSpace * (tallestLabelHeightInLines - 1))
  6425. + lineSpace; // padding
  6426. minSize.height = Math.min(me.maxHeight, minSize.height + labelHeight + tickPadding);
  6427. me.ctx.font = tickFont.font;
  6428. var firstLabelWidth = computeTextSize(me.ctx, labels[0], tickFont.font);
  6429. var lastLabelWidth = computeTextSize(me.ctx, labels[labels.length - 1], tickFont.font);
  6430. // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned
  6431. // which means that the right padding is dominated by the font height
  6432. if (me.labelRotation !== 0) {
  6433. me.paddingLeft = opts.position === 'bottom' ? (cosRotation * firstLabelWidth) + 3 : (cosRotation * lineSpace) + 3; // add 3 px to move away from canvas edges
  6434. me.paddingRight = opts.position === 'bottom' ? (cosRotation * lineSpace) + 3 : (cosRotation * lastLabelWidth) + 3;
  6435. } else {
  6436. me.paddingLeft = firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
  6437. me.paddingRight = lastLabelWidth / 2 + 3;
  6438. }
  6439. } else {
  6440. // A vertical axis is more constrained by the width. Labels are the
  6441. // dominant factor here, so get that length first and account for padding
  6442. if (tickOpts.mirror) {
  6443. largestTextWidth = 0;
  6444. } else {
  6445. // use lineSpace for consistency with horizontal axis
  6446. // tickPadding is not implemented for horizontal
  6447. largestTextWidth += tickPadding + lineSpace;
  6448. }
  6449. minSize.width = Math.min(me.maxWidth, minSize.width + largestTextWidth);
  6450. me.paddingTop = tickFont.size / 2;
  6451. me.paddingBottom = tickFont.size / 2;
  6452. }
  6453. }
  6454. me.handleMargins();
  6455. me.width = minSize.width;
  6456. me.height = minSize.height;
  6457. },
  6458. /**
  6459. * Handle margins and padding interactions
  6460. * @private
  6461. */
  6462. handleMargins: function () {
  6463. var me = this;
  6464. if (me.margins) {
  6465. me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0);
  6466. me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0);
  6467. me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0);
  6468. me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0);
  6469. }
  6470. },
  6471. afterFit: function () {
  6472. helpers.callback(this.options.afterFit, [this]);
  6473. },
  6474. // Shared Methods
  6475. isHorizontal: function () {
  6476. return this.options.position === 'top' || this.options.position === 'bottom';
  6477. },
  6478. isFullWidth: function () {
  6479. return (this.options.fullWidth);
  6480. },
  6481. // 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
  6482. getRightValue: function (rawValue) {
  6483. // Null and undefined values first
  6484. if (helpers.isNullOrUndef(rawValue)) {
  6485. return NaN;
  6486. }
  6487. // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
  6488. if (typeof rawValue === 'number' && !isFinite(rawValue)) {
  6489. return NaN;
  6490. }
  6491. // If it is in fact an object, dive in one more level
  6492. if (rawValue) {
  6493. if (this.isHorizontal()) {
  6494. if (rawValue.x !== undefined) {
  6495. return this.getRightValue(rawValue.x);
  6496. }
  6497. } else if (rawValue.y !== undefined) {
  6498. return this.getRightValue(rawValue.y);
  6499. }
  6500. }
  6501. // Value is good, return it
  6502. return rawValue;
  6503. },
  6504. /**
  6505. * Used to get the value to display in the tooltip for the data at the given index
  6506. * @param index
  6507. * @param datasetIndex
  6508. */
  6509. getLabelForIndex: helpers.noop,
  6510. /**
  6511. * Returns the location of the given data point. Value can either be an index or a numerical value
  6512. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6513. * @param value
  6514. * @param index
  6515. * @param datasetIndex
  6516. */
  6517. getPixelForValue: helpers.noop,
  6518. /**
  6519. * Used to get the data value from a given pixel. This is the inverse of getPixelForValue
  6520. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6521. * @param pixel
  6522. */
  6523. getValueForPixel: helpers.noop,
  6524. /**
  6525. * Returns the location of the tick at the given index
  6526. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6527. */
  6528. getPixelForTick: function (index) {
  6529. var me = this;
  6530. var offset = me.options.offset;
  6531. if (me.isHorizontal()) {
  6532. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6533. var tickWidth = innerWidth / Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  6534. var pixel = (tickWidth * index) + me.paddingLeft;
  6535. if (offset) {
  6536. pixel += tickWidth / 2;
  6537. }
  6538. var finalVal = me.left + Math.round(pixel);
  6539. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6540. return finalVal;
  6541. }
  6542. var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
  6543. return me.top + (index * (innerHeight / (me._ticks.length - 1)));
  6544. },
  6545. /**
  6546. * Utility for getting the pixel location of a percentage of scale
  6547. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6548. */
  6549. getPixelForDecimal: function (decimal) {
  6550. var me = this;
  6551. if (me.isHorizontal()) {
  6552. var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
  6553. var valueOffset = (innerWidth * decimal) + me.paddingLeft;
  6554. var finalVal = me.left + Math.round(valueOffset);
  6555. finalVal += me.isFullWidth() ? me.margins.left : 0;
  6556. return finalVal;
  6557. }
  6558. return me.top + (decimal * me.height);
  6559. },
  6560. /**
  6561. * Returns the pixel for the minimum chart value
  6562. * The coordinate (0, 0) is at the upper-left corner of the canvas
  6563. */
  6564. getBasePixel: function () {
  6565. return this.getPixelForValue(this.getBaseValue());
  6566. },
  6567. getBaseValue: function () {
  6568. var me = this;
  6569. var min = me.min;
  6570. var max = me.max;
  6571. return me.beginAtZero ? 0 :
  6572. min < 0 && max < 0 ? max :
  6573. min > 0 && max > 0 ? min :
  6574. 0;
  6575. },
  6576. /**
  6577. * Returns a subset of ticks to be plotted to avoid overlapping labels.
  6578. * @private
  6579. */
  6580. _autoSkip: function (ticks) {
  6581. var skipRatio;
  6582. var me = this;
  6583. var isHorizontal = me.isHorizontal();
  6584. var optionTicks = me.options.ticks.minor;
  6585. var tickCount = ticks.length;
  6586. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6587. var cosRotation = Math.cos(labelRotationRadians);
  6588. var longestRotatedLabel = me.longestLabelWidth * cosRotation;
  6589. var result = [];
  6590. var i, tick, shouldSkip;
  6591. // figure out the maximum number of gridlines to show
  6592. var maxTicks;
  6593. if (optionTicks.maxTicksLimit) {
  6594. maxTicks = optionTicks.maxTicksLimit;
  6595. }
  6596. if (isHorizontal) {
  6597. skipRatio = false;
  6598. if ((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount > (me.width - (me.paddingLeft + me.paddingRight))) {
  6599. skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * tickCount) / (me.width - (me.paddingLeft + me.paddingRight)));
  6600. }
  6601. // if they defined a max number of optionTicks,
  6602. // increase skipRatio until that number is met
  6603. if (maxTicks && tickCount > maxTicks) {
  6604. skipRatio = Math.max(skipRatio, Math.floor(tickCount / maxTicks));
  6605. }
  6606. }
  6607. for (i = 0; i < tickCount; i++) {
  6608. tick = ticks[i];
  6609. // Since we always show the last tick,we need may need to hide the last shown one before
  6610. shouldSkip = (skipRatio > 1 && i % skipRatio > 0) || (i % skipRatio === 0 && i + skipRatio >= tickCount);
  6611. if (shouldSkip && i !== tickCount - 1) {
  6612. // leave tick in place but make sure it's not displayed (#4635)
  6613. delete tick.label;
  6614. }
  6615. result.push(tick);
  6616. }
  6617. return result;
  6618. },
  6619. // Actually draw the scale on the canvas
  6620. // @param {rectangle} chartArea : the area of the chart to draw full grid lines on
  6621. draw: function (chartArea) {
  6622. var me = this;
  6623. var options = me.options;
  6624. if (!options.display) {
  6625. return;
  6626. }
  6627. var context = me.ctx;
  6628. var globalDefaults = defaults.global;
  6629. var optionTicks = options.ticks.minor;
  6630. var optionMajorTicks = options.ticks.major || optionTicks;
  6631. var gridLines = options.gridLines;
  6632. var scaleLabel = options.scaleLabel;
  6633. var isRotated = me.labelRotation !== 0;
  6634. var isHorizontal = me.isHorizontal();
  6635. var ticks = optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks();
  6636. var tickFontColor = helpers.valueOrDefault(optionTicks.fontColor, globalDefaults.defaultFontColor);
  6637. var tickFont = parseFontOptions(optionTicks);
  6638. var majorTickFontColor = helpers.valueOrDefault(optionMajorTicks.fontColor, globalDefaults.defaultFontColor);
  6639. var majorTickFont = parseFontOptions(optionMajorTicks);
  6640. var tl = gridLines.drawTicks ? gridLines.tickMarkLength : 0;
  6641. var scaleLabelFontColor = helpers.valueOrDefault(scaleLabel.fontColor, globalDefaults.defaultFontColor);
  6642. var scaleLabelFont = parseFontOptions(scaleLabel);
  6643. var scaleLabelPadding = helpers.options.toPadding(scaleLabel.padding);
  6644. var labelRotationRadians = helpers.toRadians(me.labelRotation);
  6645. var itemsToDraw = [];
  6646. var axisWidth = me.options.gridLines.lineWidth;
  6647. var xTickStart = options.position === 'right' ? me.right : me.right - axisWidth - tl;
  6648. var xTickEnd = options.position === 'right' ? me.right + tl : me.right;
  6649. var yTickStart = options.position === 'bottom' ? me.top + axisWidth : me.bottom - tl - axisWidth;
  6650. var yTickEnd = options.position === 'bottom' ? me.top + axisWidth + tl : me.bottom + axisWidth;
  6651. helpers.each(ticks, function (tick, index) {
  6652. // autoskipper skipped this tick (#4635)
  6653. if (helpers.isNullOrUndef(tick.label)) {
  6654. return;
  6655. }
  6656. var label = tick.label;
  6657. var lineWidth, lineColor, borderDash, borderDashOffset;
  6658. if (index === me.zeroLineIndex && options.offset === gridLines.offsetGridLines) {
  6659. // Draw the first index specially
  6660. lineWidth = gridLines.zeroLineWidth;
  6661. lineColor = gridLines.zeroLineColor;
  6662. borderDash = gridLines.zeroLineBorderDash;
  6663. borderDashOffset = gridLines.zeroLineBorderDashOffset;
  6664. } else {
  6665. lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, index);
  6666. lineColor = helpers.valueAtIndexOrDefault(gridLines.color, index);
  6667. borderDash = helpers.valueOrDefault(gridLines.borderDash, globalDefaults.borderDash);
  6668. borderDashOffset = helpers.valueOrDefault(gridLines.borderDashOffset, globalDefaults.borderDashOffset);
  6669. }
  6670. // Common properties
  6671. var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
  6672. var textAlign = 'middle';
  6673. var textBaseline = 'middle';
  6674. var tickPadding = optionTicks.padding;
  6675. if (isHorizontal) {
  6676. var labelYOffset = tl + tickPadding;
  6677. if (options.position === 'bottom') {
  6678. // bottom
  6679. textBaseline = !isRotated ? 'top' : 'middle';
  6680. textAlign = !isRotated ? 'center' : 'right';
  6681. labelY = me.top + labelYOffset;
  6682. } else {
  6683. // top
  6684. textBaseline = !isRotated ? 'bottom' : 'middle';
  6685. textAlign = !isRotated ? 'center' : 'left';
  6686. labelY = me.bottom - labelYOffset;
  6687. }
  6688. var xLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  6689. if (xLineValue < me.left) {
  6690. lineColor = 'rgba(0,0,0,0)';
  6691. }
  6692. xLineValue += helpers.aliasPixel(lineWidth);
  6693. labelX = me.getPixelForTick(index) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option)
  6694. tx1 = tx2 = x1 = x2 = xLineValue;
  6695. ty1 = yTickStart;
  6696. ty2 = yTickEnd;
  6697. y1 = chartArea.top;
  6698. y2 = chartArea.bottom + axisWidth;
  6699. } else {
  6700. var isLeft = options.position === 'left';
  6701. var labelXOffset;
  6702. if (optionTicks.mirror) {
  6703. textAlign = isLeft ? 'left' : 'right';
  6704. labelXOffset = tickPadding;
  6705. } else {
  6706. textAlign = isLeft ? 'right' : 'left';
  6707. labelXOffset = tl + tickPadding;
  6708. }
  6709. labelX = isLeft ? me.right - labelXOffset : me.left + labelXOffset;
  6710. var yLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
  6711. if (yLineValue < me.top) {
  6712. lineColor = 'rgba(0,0,0,0)';
  6713. }
  6714. yLineValue += helpers.aliasPixel(lineWidth);
  6715. labelY = me.getPixelForTick(index) + optionTicks.labelOffset;
  6716. tx1 = xTickStart;
  6717. tx2 = xTickEnd;
  6718. x1 = chartArea.left;
  6719. x2 = chartArea.right + axisWidth;
  6720. ty1 = ty2 = y1 = y2 = yLineValue;
  6721. }
  6722. itemsToDraw.push({
  6723. tx1: tx1,
  6724. ty1: ty1,
  6725. tx2: tx2,
  6726. ty2: ty2,
  6727. x1: x1,
  6728. y1: y1,
  6729. x2: x2,
  6730. y2: y2,
  6731. labelX: labelX,
  6732. labelY: labelY,
  6733. glWidth: lineWidth,
  6734. glColor: lineColor,
  6735. glBorderDash: borderDash,
  6736. glBorderDashOffset: borderDashOffset,
  6737. rotation: -1 * labelRotationRadians,
  6738. label: label,
  6739. major: tick.major,
  6740. textBaseline: textBaseline,
  6741. textAlign: textAlign
  6742. });
  6743. });
  6744. // Draw all of the tick labels, tick marks, and grid lines at the correct places
  6745. helpers.each(itemsToDraw, function (itemToDraw) {
  6746. if (gridLines.display) {
  6747. context.save();
  6748. context.lineWidth = itemToDraw.glWidth;
  6749. context.strokeStyle = itemToDraw.glColor;
  6750. if (context.setLineDash) {
  6751. context.setLineDash(itemToDraw.glBorderDash);
  6752. context.lineDashOffset = itemToDraw.glBorderDashOffset;
  6753. }
  6754. context.beginPath();
  6755. if (gridLines.drawTicks) {
  6756. context.moveTo(itemToDraw.tx1, itemToDraw.ty1);
  6757. context.lineTo(itemToDraw.tx2, itemToDraw.ty2);
  6758. }
  6759. if (gridLines.drawOnChartArea) {
  6760. context.moveTo(itemToDraw.x1, itemToDraw.y1);
  6761. context.lineTo(itemToDraw.x2, itemToDraw.y2);
  6762. }
  6763. context.stroke();
  6764. context.restore();
  6765. }
  6766. if (optionTicks.display) {
  6767. // Make sure we draw text in the correct color and font
  6768. context.save();
  6769. context.translate(itemToDraw.labelX, itemToDraw.labelY);
  6770. context.rotate(itemToDraw.rotation);
  6771. context.font = itemToDraw.major ? majorTickFont.font : tickFont.font;
  6772. context.fillStyle = itemToDraw.major ? majorTickFontColor : tickFontColor;
  6773. context.textBaseline = itemToDraw.textBaseline;
  6774. context.textAlign = itemToDraw.textAlign;
  6775. var label = itemToDraw.label;
  6776. if (helpers.isArray(label)) {
  6777. var lineCount = label.length;
  6778. var lineHeight = tickFont.size * 1.5;
  6779. var y = me.isHorizontal() ? 0 : -lineHeight * (lineCount - 1) / 2;
  6780. for (var i = 0; i < lineCount; ++i) {
  6781. // We just make sure the multiline element is a string here..
  6782. context.fillText('' + label[i], 0, y);
  6783. // apply same lineSpacing as calculated @ L#320
  6784. y += lineHeight;
  6785. }
  6786. } else {
  6787. context.fillText(label, 0, 0);
  6788. }
  6789. context.restore();
  6790. }
  6791. });
  6792. if (scaleLabel.display) {
  6793. // Draw the scale label
  6794. var scaleLabelX;
  6795. var scaleLabelY;
  6796. var rotation = 0;
  6797. var halfLineHeight = parseLineHeight(scaleLabel) / 2;
  6798. if (isHorizontal) {
  6799. scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width
  6800. scaleLabelY = options.position === 'bottom'
  6801. ? me.bottom - halfLineHeight - scaleLabelPadding.bottom
  6802. : me.top + halfLineHeight + scaleLabelPadding.top;
  6803. } else {
  6804. var isLeft = options.position === 'left';
  6805. scaleLabelX = isLeft
  6806. ? me.left + halfLineHeight + scaleLabelPadding.top
  6807. : me.right - halfLineHeight - scaleLabelPadding.top;
  6808. scaleLabelY = me.top + ((me.bottom - me.top) / 2);
  6809. rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;
  6810. }
  6811. context.save();
  6812. context.translate(scaleLabelX, scaleLabelY);
  6813. context.rotate(rotation);
  6814. context.textAlign = 'center';
  6815. context.textBaseline = 'middle';
  6816. context.fillStyle = scaleLabelFontColor; // render in correct colour
  6817. context.font = scaleLabelFont.font;
  6818. context.fillText(scaleLabel.labelString, 0, 0);
  6819. context.restore();
  6820. }
  6821. if (gridLines.drawBorder) {
  6822. // Draw the line at the edge of the axis
  6823. context.lineWidth = helpers.valueAtIndexOrDefault(gridLines.lineWidth, 0);
  6824. context.strokeStyle = helpers.valueAtIndexOrDefault(gridLines.color, 0);
  6825. var x1 = me.left;
  6826. var x2 = me.right + axisWidth;
  6827. var y1 = me.top;
  6828. var y2 = me.bottom + axisWidth;
  6829. var aliasPixel = helpers.aliasPixel(context.lineWidth);
  6830. if (isHorizontal) {
  6831. y1 = y2 = options.position === 'top' ? me.bottom : me.top;
  6832. y1 += aliasPixel;
  6833. y2 += aliasPixel;
  6834. } else {
  6835. x1 = x2 = options.position === 'left' ? me.right : me.left;
  6836. x1 += aliasPixel;
  6837. x2 += aliasPixel;
  6838. }
  6839. context.beginPath();
  6840. context.moveTo(x1, y1);
  6841. context.lineTo(x2, y2);
  6842. context.stroke();
  6843. }
  6844. }
  6845. });
  6846. };
  6847. }, {"25": 25, "26": 26, "34": 34, "45": 45}], 33: [function (require, module, exports) {
  6848. 'use strict';
  6849. var defaults = require(25);
  6850. var helpers = require(45);
  6851. var layouts = require(30);
  6852. module.exports = function (Chart) {
  6853. Chart.scaleService = {
  6854. // Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
  6855. // use the new chart options to grab the correct scale
  6856. constructors: {},
  6857. // Use a registration function so that we can move to an ES6 map when we no longer need to support
  6858. // old browsers
  6859. // Scale config defaults
  6860. defaults: {},
  6861. registerScaleType: function (type, scaleConstructor, scaleDefaults) {
  6862. this.constructors[type] = scaleConstructor;
  6863. this.defaults[type] = helpers.clone(scaleDefaults);
  6864. },
  6865. getScaleConstructor: function (type) {
  6866. return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
  6867. },
  6868. getScaleDefaults: function (type) {
  6869. // Return the scale defaults merged with the global settings so that we always use the latest ones
  6870. return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [defaults.scale, this.defaults[type]]) : {};
  6871. },
  6872. updateScaleDefaults: function (type, additions) {
  6873. var me = this;
  6874. if (me.defaults.hasOwnProperty(type)) {
  6875. me.defaults[type] = helpers.extend(me.defaults[type], additions);
  6876. }
  6877. },
  6878. addScalesToLayout: function (chart) {
  6879. // Adds each scale to the chart.boxes array to be sized accordingly
  6880. helpers.each(chart.scales, function (scale) {
  6881. // Set ILayoutItem parameters for backwards compatibility
  6882. scale.fullWidth = scale.options.fullWidth;
  6883. scale.position = scale.options.position;
  6884. scale.weight = scale.options.weight;
  6885. layouts.addBox(chart, scale);
  6886. });
  6887. }
  6888. };
  6889. };
  6890. }, {"25": 25, "30": 30, "45": 45}], 34: [function (require, module, exports) {
  6891. 'use strict';
  6892. var helpers = require(45);
  6893. /**
  6894. * Namespace to hold static tick generation functions
  6895. * @namespace Chart.Ticks
  6896. */
  6897. module.exports = {
  6898. /**
  6899. * Namespace to hold formatters for different types of ticks
  6900. * @namespace Chart.Ticks.formatters
  6901. */
  6902. formatters: {
  6903. /**
  6904. * Formatter for value labels
  6905. * @method Chart.Ticks.formatters.values
  6906. * @param value the value to display
  6907. * @return {String|Array} the label to display
  6908. */
  6909. values: function (value) {
  6910. return helpers.isArray(value) ? value : '' + value;
  6911. },
  6912. /**
  6913. * Formatter for linear numeric ticks
  6914. * @method Chart.Ticks.formatters.linear
  6915. * @param tickValue {Number} the value to be formatted
  6916. * @param index {Number} the position of the tickValue parameter in the ticks array
  6917. * @param ticks {Array<Number>} the list of ticks being converted
  6918. * @return {String} string representation of the tickValue parameter
  6919. */
  6920. linear: function (tickValue, index, ticks) {
  6921. // If we have lots of ticks, don't use the ones
  6922. var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];
  6923. // If we have a number like 2.5 as the delta, figure out how many decimal places we need
  6924. if (Math.abs(delta) > 1) {
  6925. if (tickValue !== Math.floor(tickValue)) {
  6926. // not an integer
  6927. delta = tickValue - Math.floor(tickValue);
  6928. }
  6929. }
  6930. var logDelta = helpers.log10(Math.abs(delta));
  6931. var tickString = '';
  6932. if (tickValue !== 0) {
  6933. var numDecimal = -1 * Math.floor(logDelta);
  6934. numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
  6935. tickString = tickValue.toFixed(numDecimal);
  6936. } else {
  6937. tickString = '0'; // never show decimal places for 0
  6938. }
  6939. return tickString;
  6940. },
  6941. logarithmic: function (tickValue, index, ticks) {
  6942. var remain = tickValue / (Math.pow(10, Math.floor(helpers.log10(tickValue))));
  6943. if (tickValue === 0) {
  6944. return '0';
  6945. } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === ticks.length - 1) {
  6946. return tickValue.toExponential();
  6947. }
  6948. return '';
  6949. }
  6950. }
  6951. };
  6952. }, {"45": 45}], 35: [function (require, module, exports) {
  6953. 'use strict';
  6954. var defaults = require(25);
  6955. var Element = require(26);
  6956. var helpers = require(45);
  6957. defaults._set('global', {
  6958. tooltips: {
  6959. enabled: true,
  6960. custom: null,
  6961. mode: 'nearest',
  6962. position: 'average',
  6963. intersect: true,
  6964. backgroundColor: 'rgba(0,0,0,0.8)',
  6965. titleFontStyle: 'bold',
  6966. titleSpacing: 2,
  6967. titleMarginBottom: 6,
  6968. titleFontColor: '#fff',
  6969. titleAlign: 'left',
  6970. bodySpacing: 2,
  6971. bodyFontColor: '#fff',
  6972. bodyAlign: 'left',
  6973. footerFontStyle: 'bold',
  6974. footerSpacing: 2,
  6975. footerMarginTop: 6,
  6976. footerFontColor: '#fff',
  6977. footerAlign: 'left',
  6978. yPadding: 6,
  6979. xPadding: 6,
  6980. caretPadding: 2,
  6981. caretSize: 5,
  6982. cornerRadius: 6,
  6983. multiKeyBackground: '#fff',
  6984. displayColors: true,
  6985. borderColor: 'rgba(0,0,0,0)',
  6986. borderWidth: 0,
  6987. callbacks: {
  6988. // Args are: (tooltipItems, data)
  6989. beforeTitle: helpers.noop,
  6990. title: function (tooltipItems, data) {
  6991. // Pick first xLabel for now
  6992. var title = '';
  6993. var labels = data.labels;
  6994. var labelCount = labels ? labels.length : 0;
  6995. if (tooltipItems.length > 0) {
  6996. var item = tooltipItems[0];
  6997. if (item.xLabel) {
  6998. title = item.xLabel;
  6999. } else if (labelCount > 0 && item.index < labelCount) {
  7000. title = labels[item.index];
  7001. }
  7002. }
  7003. return title;
  7004. },
  7005. afterTitle: helpers.noop,
  7006. // Args are: (tooltipItems, data)
  7007. beforeBody: helpers.noop,
  7008. // Args are: (tooltipItem, data)
  7009. beforeLabel: helpers.noop,
  7010. label: function (tooltipItem, data) {
  7011. var label = data.datasets[tooltipItem.datasetIndex].label || '';
  7012. if (label) {
  7013. label += ': ';
  7014. }
  7015. label += tooltipItem.yLabel;
  7016. return label;
  7017. },
  7018. labelColor: function (tooltipItem, chart) {
  7019. var meta = chart.getDatasetMeta(tooltipItem.datasetIndex);
  7020. var activeElement = meta.data[tooltipItem.index];
  7021. var view = activeElement._view;
  7022. return {
  7023. borderColor: view.borderColor,
  7024. backgroundColor: view.backgroundColor
  7025. };
  7026. },
  7027. labelTextColor: function () {
  7028. return this._options.bodyFontColor;
  7029. },
  7030. afterLabel: helpers.noop,
  7031. // Args are: (tooltipItems, data)
  7032. afterBody: helpers.noop,
  7033. // Args are: (tooltipItems, data)
  7034. beforeFooter: helpers.noop,
  7035. footer: helpers.noop,
  7036. afterFooter: helpers.noop
  7037. }
  7038. }
  7039. });
  7040. module.exports = function (Chart) {
  7041. /**
  7042. * Helper method to merge the opacity into a color
  7043. */
  7044. function mergeOpacity(colorString, opacity) {
  7045. var color = helpers.color(colorString);
  7046. return color.alpha(opacity * color.alpha()).rgbaString();
  7047. }
  7048. // Helper to push or concat based on if the 2nd parameter is an array or not
  7049. function pushOrConcat(base, toPush) {
  7050. if (toPush) {
  7051. if (helpers.isArray(toPush)) {
  7052. // base = base.concat(toPush);
  7053. Array.prototype.push.apply(base, toPush);
  7054. } else {
  7055. base.push(toPush);
  7056. }
  7057. }
  7058. return base;
  7059. }
  7060. // Private helper to create a tooltip item model
  7061. // @param element : the chart element (point, arc, bar) to create the tooltip item for
  7062. // @return : new tooltip item
  7063. function createTooltipItem(element) {
  7064. var xScale = element._xScale;
  7065. var yScale = element._yScale || element._scale; // handle radar || polarArea charts
  7066. var index = element._index;
  7067. var datasetIndex = element._datasetIndex;
  7068. return {
  7069. xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
  7070. yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
  7071. index: index,
  7072. datasetIndex: datasetIndex,
  7073. x: element._model.x,
  7074. y: element._model.y
  7075. };
  7076. }
  7077. /**
  7078. * Helper to get the reset model for the tooltip
  7079. * @param tooltipOpts {Object} the tooltip options
  7080. */
  7081. function getBaseModel(tooltipOpts) {
  7082. var globalDefaults = defaults.global;
  7083. var valueOrDefault = helpers.valueOrDefault;
  7084. return {
  7085. // Positioning
  7086. xPadding: tooltipOpts.xPadding,
  7087. yPadding: tooltipOpts.yPadding,
  7088. xAlign: tooltipOpts.xAlign,
  7089. yAlign: tooltipOpts.yAlign,
  7090. // Body
  7091. bodyFontColor: tooltipOpts.bodyFontColor,
  7092. _bodyFontFamily: valueOrDefault(tooltipOpts.bodyFontFamily, globalDefaults.defaultFontFamily),
  7093. _bodyFontStyle: valueOrDefault(tooltipOpts.bodyFontStyle, globalDefaults.defaultFontStyle),
  7094. _bodyAlign: tooltipOpts.bodyAlign,
  7095. bodyFontSize: valueOrDefault(tooltipOpts.bodyFontSize, globalDefaults.defaultFontSize),
  7096. bodySpacing: tooltipOpts.bodySpacing,
  7097. // Title
  7098. titleFontColor: tooltipOpts.titleFontColor,
  7099. _titleFontFamily: valueOrDefault(tooltipOpts.titleFontFamily, globalDefaults.defaultFontFamily),
  7100. _titleFontStyle: valueOrDefault(tooltipOpts.titleFontStyle, globalDefaults.defaultFontStyle),
  7101. titleFontSize: valueOrDefault(tooltipOpts.titleFontSize, globalDefaults.defaultFontSize),
  7102. _titleAlign: tooltipOpts.titleAlign,
  7103. titleSpacing: tooltipOpts.titleSpacing,
  7104. titleMarginBottom: tooltipOpts.titleMarginBottom,
  7105. // Footer
  7106. footerFontColor: tooltipOpts.footerFontColor,
  7107. _footerFontFamily: valueOrDefault(tooltipOpts.footerFontFamily, globalDefaults.defaultFontFamily),
  7108. _footerFontStyle: valueOrDefault(tooltipOpts.footerFontStyle, globalDefaults.defaultFontStyle),
  7109. footerFontSize: valueOrDefault(tooltipOpts.footerFontSize, globalDefaults.defaultFontSize),
  7110. _footerAlign: tooltipOpts.footerAlign,
  7111. footerSpacing: tooltipOpts.footerSpacing,
  7112. footerMarginTop: tooltipOpts.footerMarginTop,
  7113. // Appearance
  7114. caretSize: tooltipOpts.caretSize,
  7115. cornerRadius: tooltipOpts.cornerRadius,
  7116. backgroundColor: tooltipOpts.backgroundColor,
  7117. opacity: 0,
  7118. legendColorBackground: tooltipOpts.multiKeyBackground,
  7119. displayColors: tooltipOpts.displayColors,
  7120. borderColor: tooltipOpts.borderColor,
  7121. borderWidth: tooltipOpts.borderWidth
  7122. };
  7123. }
  7124. /**
  7125. * Get the size of the tooltip
  7126. */
  7127. function getTooltipSize(tooltip, model) {
  7128. var ctx = tooltip._chart.ctx;
  7129. var height = model.yPadding * 2; // Tooltip Padding
  7130. var width = 0;
  7131. // Count of all lines in the body
  7132. var body = model.body;
  7133. var combinedBodyLength = body.reduce(function (count, bodyItem) {
  7134. return count + bodyItem.before.length + bodyItem.lines.length + bodyItem.after.length;
  7135. }, 0);
  7136. combinedBodyLength += model.beforeBody.length + model.afterBody.length;
  7137. var titleLineCount = model.title.length;
  7138. var footerLineCount = model.footer.length;
  7139. var titleFontSize = model.titleFontSize;
  7140. var bodyFontSize = model.bodyFontSize;
  7141. var footerFontSize = model.footerFontSize;
  7142. height += titleLineCount * titleFontSize; // Title Lines
  7143. height += titleLineCount ? (titleLineCount - 1) * model.titleSpacing : 0; // Title Line Spacing
  7144. height += titleLineCount ? model.titleMarginBottom : 0; // Title's bottom Margin
  7145. height += combinedBodyLength * bodyFontSize; // Body Lines
  7146. height += combinedBodyLength ? (combinedBodyLength - 1) * model.bodySpacing : 0; // Body Line Spacing
  7147. height += footerLineCount ? model.footerMarginTop : 0; // Footer Margin
  7148. height += footerLineCount * (footerFontSize); // Footer Lines
  7149. height += footerLineCount ? (footerLineCount - 1) * model.footerSpacing : 0; // Footer Line Spacing
  7150. // Title width
  7151. var widthPadding = 0;
  7152. var maxLineWidth = function (line) {
  7153. width = Math.max(width, ctx.measureText(line).width + widthPadding);
  7154. };
  7155. ctx.font = helpers.fontString(titleFontSize, model._titleFontStyle, model._titleFontFamily);
  7156. helpers.each(model.title, maxLineWidth);
  7157. // Body width
  7158. ctx.font = helpers.fontString(bodyFontSize, model._bodyFontStyle, model._bodyFontFamily);
  7159. helpers.each(model.beforeBody.concat(model.afterBody), maxLineWidth);
  7160. // Body lines may include some extra width due to the color box
  7161. widthPadding = model.displayColors ? (bodyFontSize + 2) : 0;
  7162. helpers.each(body, function (bodyItem) {
  7163. helpers.each(bodyItem.before, maxLineWidth);
  7164. helpers.each(bodyItem.lines, maxLineWidth);
  7165. helpers.each(bodyItem.after, maxLineWidth);
  7166. });
  7167. // Reset back to 0
  7168. widthPadding = 0;
  7169. // Footer width
  7170. ctx.font = helpers.fontString(footerFontSize, model._footerFontStyle, model._footerFontFamily);
  7171. helpers.each(model.footer, maxLineWidth);
  7172. // Add padding
  7173. width += 2 * model.xPadding;
  7174. return {
  7175. width: width,
  7176. height: height
  7177. };
  7178. }
  7179. /**
  7180. * Helper to get the alignment of a tooltip given the size
  7181. */
  7182. function determineAlignment(tooltip, size) {
  7183. var model = tooltip._model;
  7184. var chart = tooltip._chart;
  7185. var chartArea = tooltip._chart.chartArea;
  7186. var xAlign = 'center';
  7187. var yAlign = 'center';
  7188. if (model.y < size.height) {
  7189. yAlign = 'top';
  7190. } else if (model.y > (chart.height - size.height)) {
  7191. yAlign = 'bottom';
  7192. }
  7193. var lf, rf; // functions to determine left, right alignment
  7194. var olf, orf; // functions to determine if left/right alignment causes tooltip to go outside chart
  7195. var yf; // function to get the y alignment if the tooltip goes outside of the left or right edges
  7196. var midX = (chartArea.left + chartArea.right) / 2;
  7197. var midY = (chartArea.top + chartArea.bottom) / 2;
  7198. if (yAlign === 'center') {
  7199. lf = function (x) {
  7200. return x <= midX;
  7201. };
  7202. rf = function (x) {
  7203. return x > midX;
  7204. };
  7205. } else {
  7206. lf = function (x) {
  7207. return x <= (size.width / 2);
  7208. };
  7209. rf = function (x) {
  7210. return x >= (chart.width - (size.width / 2));
  7211. };
  7212. }
  7213. olf = function (x) {
  7214. return x + size.width + model.caretSize + model.caretPadding > chart.width;
  7215. };
  7216. orf = function (x) {
  7217. return x - size.width - model.caretSize - model.caretPadding < 0;
  7218. };
  7219. yf = function (y) {
  7220. return y <= midY ? 'top' : 'bottom';
  7221. };
  7222. if (lf(model.x)) {
  7223. xAlign = 'left';
  7224. // Is tooltip too wide and goes over the right side of the chart.?
  7225. if (olf(model.x)) {
  7226. xAlign = 'center';
  7227. yAlign = yf(model.y);
  7228. }
  7229. } else if (rf(model.x)) {
  7230. xAlign = 'right';
  7231. // Is tooltip too wide and goes outside left edge of canvas?
  7232. if (orf(model.x)) {
  7233. xAlign = 'center';
  7234. yAlign = yf(model.y);
  7235. }
  7236. }
  7237. var opts = tooltip._options;
  7238. return {
  7239. xAlign: opts.xAlign ? opts.xAlign : xAlign,
  7240. yAlign: opts.yAlign ? opts.yAlign : yAlign
  7241. };
  7242. }
  7243. /**
  7244. * @Helper to get the location a tooltip needs to be placed at given the initial position (via the vm) and the size and alignment
  7245. */
  7246. function getBackgroundPoint(vm, size, alignment, chart) {
  7247. // Background Position
  7248. var x = vm.x;
  7249. var y = vm.y;
  7250. var caretSize = vm.caretSize;
  7251. var caretPadding = vm.caretPadding;
  7252. var cornerRadius = vm.cornerRadius;
  7253. var xAlign = alignment.xAlign;
  7254. var yAlign = alignment.yAlign;
  7255. var paddingAndSize = caretSize + caretPadding;
  7256. var radiusAndPadding = cornerRadius + caretPadding;
  7257. if (xAlign === 'right') {
  7258. x -= size.width;
  7259. } else if (xAlign === 'center') {
  7260. x -= (size.width / 2);
  7261. if (x + size.width > chart.width) {
  7262. x = chart.width - size.width;
  7263. }
  7264. if (x < 0) {
  7265. x = 0;
  7266. }
  7267. }
  7268. if (yAlign === 'top') {
  7269. y += paddingAndSize;
  7270. } else if (yAlign === 'bottom') {
  7271. y -= size.height + paddingAndSize;
  7272. } else {
  7273. y -= (size.height / 2);
  7274. }
  7275. if (yAlign === 'center') {
  7276. if (xAlign === 'left') {
  7277. x += paddingAndSize;
  7278. } else if (xAlign === 'right') {
  7279. x -= paddingAndSize;
  7280. }
  7281. } else if (xAlign === 'left') {
  7282. x -= radiusAndPadding;
  7283. } else if (xAlign === 'right') {
  7284. x += radiusAndPadding;
  7285. }
  7286. return {
  7287. x: x,
  7288. y: y
  7289. };
  7290. }
  7291. Chart.Tooltip = Element.extend({
  7292. initialize: function () {
  7293. this._model = getBaseModel(this._options);
  7294. this._lastActive = [];
  7295. },
  7296. // Get the title
  7297. // Args are: (tooltipItem, data)
  7298. getTitle: function () {
  7299. var me = this;
  7300. var opts = me._options;
  7301. var callbacks = opts.callbacks;
  7302. var beforeTitle = callbacks.beforeTitle.apply(me, arguments);
  7303. var title = callbacks.title.apply(me, arguments);
  7304. var afterTitle = callbacks.afterTitle.apply(me, arguments);
  7305. var lines = [];
  7306. lines = pushOrConcat(lines, beforeTitle);
  7307. lines = pushOrConcat(lines, title);
  7308. lines = pushOrConcat(lines, afterTitle);
  7309. return lines;
  7310. },
  7311. // Args are: (tooltipItem, data)
  7312. getBeforeBody: function () {
  7313. var lines = this._options.callbacks.beforeBody.apply(this, arguments);
  7314. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  7315. },
  7316. // Args are: (tooltipItem, data)
  7317. getBody: function (tooltipItems, data) {
  7318. var me = this;
  7319. var callbacks = me._options.callbacks;
  7320. var bodyItems = [];
  7321. helpers.each(tooltipItems, function (tooltipItem) {
  7322. var bodyItem = {
  7323. before: [],
  7324. lines: [],
  7325. after: []
  7326. };
  7327. pushOrConcat(bodyItem.before, callbacks.beforeLabel.call(me, tooltipItem, data));
  7328. pushOrConcat(bodyItem.lines, callbacks.label.call(me, tooltipItem, data));
  7329. pushOrConcat(bodyItem.after, callbacks.afterLabel.call(me, tooltipItem, data));
  7330. bodyItems.push(bodyItem);
  7331. });
  7332. return bodyItems;
  7333. },
  7334. // Args are: (tooltipItem, data)
  7335. getAfterBody: function () {
  7336. var lines = this._options.callbacks.afterBody.apply(this, arguments);
  7337. return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
  7338. },
  7339. // Get the footer and beforeFooter and afterFooter lines
  7340. // Args are: (tooltipItem, data)
  7341. getFooter: function () {
  7342. var me = this;
  7343. var callbacks = me._options.callbacks;
  7344. var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
  7345. var footer = callbacks.footer.apply(me, arguments);
  7346. var afterFooter = callbacks.afterFooter.apply(me, arguments);
  7347. var lines = [];
  7348. lines = pushOrConcat(lines, beforeFooter);
  7349. lines = pushOrConcat(lines, footer);
  7350. lines = pushOrConcat(lines, afterFooter);
  7351. return lines;
  7352. },
  7353. update: function (changed) {
  7354. var me = this;
  7355. var opts = me._options;
  7356. // Need to regenerate the model because its faster than using extend and it is necessary due to the optimization in Chart.Element.transition
  7357. // that does _view = _model if ease === 1. This causes the 2nd tooltip update to set properties in both the view and model at the same time
  7358. // which breaks any animations.
  7359. var existingModel = me._model;
  7360. var model = me._model = getBaseModel(opts);
  7361. var active = me._active;
  7362. var data = me._data;
  7363. // In the case where active.length === 0 we need to keep these at existing values for good animations
  7364. var alignment = {
  7365. xAlign: existingModel.xAlign,
  7366. yAlign: existingModel.yAlign
  7367. };
  7368. var backgroundPoint = {
  7369. x: existingModel.x,
  7370. y: existingModel.y
  7371. };
  7372. var tooltipSize = {
  7373. width: existingModel.width,
  7374. height: existingModel.height
  7375. };
  7376. var tooltipPosition = {
  7377. x: existingModel.caretX,
  7378. y: existingModel.caretY
  7379. };
  7380. var i, len;
  7381. if (active.length) {
  7382. model.opacity = 1;
  7383. var labelColors = [];
  7384. var labelTextColors = [];
  7385. tooltipPosition = Chart.Tooltip.positioners[opts.position].call(me, active, me._eventPosition);
  7386. var tooltipItems = [];
  7387. for (i = 0, len = active.length; i < len; ++i) {
  7388. tooltipItems.push(createTooltipItem(active[i]));
  7389. }
  7390. // If the user provided a filter function, use it to modify the tooltip items
  7391. if (opts.filter) {
  7392. tooltipItems = tooltipItems.filter(function (a) {
  7393. return opts.filter(a, data);
  7394. });
  7395. }
  7396. // If the user provided a sorting function, use it to modify the tooltip items
  7397. if (opts.itemSort) {
  7398. tooltipItems = tooltipItems.sort(function (a, b) {
  7399. return opts.itemSort(a, b, data);
  7400. });
  7401. }
  7402. // Determine colors for boxes
  7403. helpers.each(tooltipItems, function (tooltipItem) {
  7404. labelColors.push(opts.callbacks.labelColor.call(me, tooltipItem, me._chart));
  7405. labelTextColors.push(opts.callbacks.labelTextColor.call(me, tooltipItem, me._chart));
  7406. });
  7407. // Build the Text Lines
  7408. model.title = me.getTitle(tooltipItems, data);
  7409. model.beforeBody = me.getBeforeBody(tooltipItems, data);
  7410. model.body = me.getBody(tooltipItems, data);
  7411. model.afterBody = me.getAfterBody(tooltipItems, data);
  7412. model.footer = me.getFooter(tooltipItems, data);
  7413. // Initial positioning and colors
  7414. model.x = Math.round(tooltipPosition.x);
  7415. model.y = Math.round(tooltipPosition.y);
  7416. model.caretPadding = opts.caretPadding;
  7417. model.labelColors = labelColors;
  7418. model.labelTextColors = labelTextColors;
  7419. // data points
  7420. model.dataPoints = tooltipItems;
  7421. // We need to determine alignment of the tooltip
  7422. tooltipSize = getTooltipSize(this, model);
  7423. alignment = determineAlignment(this, tooltipSize);
  7424. // Final Size and Position
  7425. backgroundPoint = getBackgroundPoint(model, tooltipSize, alignment, me._chart);
  7426. } else {
  7427. model.opacity = 0;
  7428. }
  7429. model.xAlign = alignment.xAlign;
  7430. model.yAlign = alignment.yAlign;
  7431. model.x = backgroundPoint.x;
  7432. model.y = backgroundPoint.y;
  7433. model.width = tooltipSize.width;
  7434. model.height = tooltipSize.height;
  7435. // Point where the caret on the tooltip points to
  7436. model.caretX = tooltipPosition.x;
  7437. model.caretY = tooltipPosition.y;
  7438. me._model = model;
  7439. if (changed && opts.custom) {
  7440. opts.custom.call(me, model);
  7441. }
  7442. return me;
  7443. },
  7444. drawCaret: function (tooltipPoint, size) {
  7445. var ctx = this._chart.ctx;
  7446. var vm = this._view;
  7447. var caretPosition = this.getCaretPosition(tooltipPoint, size, vm);
  7448. ctx.lineTo(caretPosition.x1, caretPosition.y1);
  7449. ctx.lineTo(caretPosition.x2, caretPosition.y2);
  7450. ctx.lineTo(caretPosition.x3, caretPosition.y3);
  7451. },
  7452. getCaretPosition: function (tooltipPoint, size, vm) {
  7453. var x1, x2, x3, y1, y2, y3;
  7454. var caretSize = vm.caretSize;
  7455. var cornerRadius = vm.cornerRadius;
  7456. var xAlign = vm.xAlign;
  7457. var yAlign = vm.yAlign;
  7458. var ptX = tooltipPoint.x;
  7459. var ptY = tooltipPoint.y;
  7460. var width = size.width;
  7461. var height = size.height;
  7462. if (yAlign === 'center') {
  7463. y2 = ptY + (height / 2);
  7464. if (xAlign === 'left') {
  7465. x1 = ptX;
  7466. x2 = x1 - caretSize;
  7467. x3 = x1;
  7468. y1 = y2 + caretSize;
  7469. y3 = y2 - caretSize;
  7470. } else {
  7471. x1 = ptX + width;
  7472. x2 = x1 + caretSize;
  7473. x3 = x1;
  7474. y1 = y2 - caretSize;
  7475. y3 = y2 + caretSize;
  7476. }
  7477. } else {
  7478. if (xAlign === 'left') {
  7479. x2 = ptX + cornerRadius + (caretSize);
  7480. x1 = x2 - caretSize;
  7481. x3 = x2 + caretSize;
  7482. } else if (xAlign === 'right') {
  7483. x2 = ptX + width - cornerRadius - caretSize;
  7484. x1 = x2 - caretSize;
  7485. x3 = x2 + caretSize;
  7486. } else {
  7487. x2 = vm.caretX;
  7488. x1 = x2 - caretSize;
  7489. x3 = x2 + caretSize;
  7490. }
  7491. if (yAlign === 'top') {
  7492. y1 = ptY;
  7493. y2 = y1 - caretSize;
  7494. y3 = y1;
  7495. } else {
  7496. y1 = ptY + height;
  7497. y2 = y1 + caretSize;
  7498. y3 = y1;
  7499. // invert drawing order
  7500. var tmp = x3;
  7501. x3 = x1;
  7502. x1 = tmp;
  7503. }
  7504. }
  7505. return {x1: x1, x2: x2, x3: x3, y1: y1, y2: y2, y3: y3};
  7506. },
  7507. drawTitle: function (pt, vm, ctx, opacity) {
  7508. var title = vm.title;
  7509. if (title.length) {
  7510. ctx.textAlign = vm._titleAlign;
  7511. ctx.textBaseline = 'top';
  7512. var titleFontSize = vm.titleFontSize;
  7513. var titleSpacing = vm.titleSpacing;
  7514. ctx.fillStyle = mergeOpacity(vm.titleFontColor, opacity);
  7515. ctx.font = helpers.fontString(titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
  7516. var i, len;
  7517. for (i = 0, len = title.length; i < len; ++i) {
  7518. ctx.fillText(title[i], pt.x, pt.y);
  7519. pt.y += titleFontSize + titleSpacing; // Line Height and spacing
  7520. if (i + 1 === title.length) {
  7521. pt.y += vm.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
  7522. }
  7523. }
  7524. }
  7525. },
  7526. drawBody: function (pt, vm, ctx, opacity) {
  7527. var bodyFontSize = vm.bodyFontSize;
  7528. var bodySpacing = vm.bodySpacing;
  7529. var body = vm.body;
  7530. ctx.textAlign = vm._bodyAlign;
  7531. ctx.textBaseline = 'top';
  7532. ctx.font = helpers.fontString(bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
  7533. // Before Body
  7534. var xLinePadding = 0;
  7535. var fillLineOfText = function (line) {
  7536. ctx.fillText(line, pt.x + xLinePadding, pt.y);
  7537. pt.y += bodyFontSize + bodySpacing;
  7538. };
  7539. // Before body lines
  7540. ctx.fillStyle = mergeOpacity(vm.bodyFontColor, opacity);
  7541. helpers.each(vm.beforeBody, fillLineOfText);
  7542. var drawColorBoxes = vm.displayColors;
  7543. xLinePadding = drawColorBoxes ? (bodyFontSize + 2) : 0;
  7544. // Draw body lines now
  7545. helpers.each(body, function (bodyItem, i) {
  7546. var textColor = mergeOpacity(vm.labelTextColors[i], opacity);
  7547. ctx.fillStyle = textColor;
  7548. helpers.each(bodyItem.before, fillLineOfText);
  7549. helpers.each(bodyItem.lines, function (line) {
  7550. // Draw Legend-like boxes if needed
  7551. if (drawColorBoxes) {
  7552. // Fill a white rect so that colours merge nicely if the opacity is < 1
  7553. ctx.fillStyle = mergeOpacity(vm.legendColorBackground, opacity);
  7554. ctx.fillRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7555. // Border
  7556. ctx.lineWidth = 1;
  7557. ctx.strokeStyle = mergeOpacity(vm.labelColors[i].borderColor, opacity);
  7558. ctx.strokeRect(pt.x, pt.y, bodyFontSize, bodyFontSize);
  7559. // Inner square
  7560. ctx.fillStyle = mergeOpacity(vm.labelColors[i].backgroundColor, opacity);
  7561. ctx.fillRect(pt.x + 1, pt.y + 1, bodyFontSize - 2, bodyFontSize - 2);
  7562. ctx.fillStyle = textColor;
  7563. }
  7564. fillLineOfText(line);
  7565. });
  7566. helpers.each(bodyItem.after, fillLineOfText);
  7567. });
  7568. // Reset back to 0 for after body
  7569. xLinePadding = 0;
  7570. // After body lines
  7571. helpers.each(vm.afterBody, fillLineOfText);
  7572. pt.y -= bodySpacing; // Remove last body spacing
  7573. },
  7574. drawFooter: function (pt, vm, ctx, opacity) {
  7575. var footer = vm.footer;
  7576. if (footer.length) {
  7577. pt.y += vm.footerMarginTop;
  7578. ctx.textAlign = vm._footerAlign;
  7579. ctx.textBaseline = 'top';
  7580. ctx.fillStyle = mergeOpacity(vm.footerFontColor, opacity);
  7581. ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
  7582. helpers.each(footer, function (line) {
  7583. ctx.fillText(line, pt.x, pt.y);
  7584. pt.y += vm.footerFontSize + vm.footerSpacing;
  7585. });
  7586. }
  7587. },
  7588. drawBackground: function (pt, vm, ctx, tooltipSize, opacity) {
  7589. ctx.fillStyle = mergeOpacity(vm.backgroundColor, opacity);
  7590. ctx.strokeStyle = mergeOpacity(vm.borderColor, opacity);
  7591. ctx.lineWidth = vm.borderWidth;
  7592. var xAlign = vm.xAlign;
  7593. var yAlign = vm.yAlign;
  7594. var x = pt.x;
  7595. var y = pt.y;
  7596. var width = tooltipSize.width;
  7597. var height = tooltipSize.height;
  7598. var radius = vm.cornerRadius;
  7599. ctx.beginPath();
  7600. ctx.moveTo(x + radius, y);
  7601. if (yAlign === 'top') {
  7602. this.drawCaret(pt, tooltipSize);
  7603. }
  7604. ctx.lineTo(x + width - radius, y);
  7605. ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  7606. if (yAlign === 'center' && xAlign === 'right') {
  7607. this.drawCaret(pt, tooltipSize);
  7608. }
  7609. ctx.lineTo(x + width, y + height - radius);
  7610. ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  7611. if (yAlign === 'bottom') {
  7612. this.drawCaret(pt, tooltipSize);
  7613. }
  7614. ctx.lineTo(x + radius, y + height);
  7615. ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  7616. if (yAlign === 'center' && xAlign === 'left') {
  7617. this.drawCaret(pt, tooltipSize);
  7618. }
  7619. ctx.lineTo(x, y + radius);
  7620. ctx.quadraticCurveTo(x, y, x + radius, y);
  7621. ctx.closePath();
  7622. ctx.fill();
  7623. if (vm.borderWidth > 0) {
  7624. ctx.stroke();
  7625. }
  7626. },
  7627. draw: function () {
  7628. var ctx = this._chart.ctx;
  7629. var vm = this._view;
  7630. if (vm.opacity === 0) {
  7631. return;
  7632. }
  7633. var tooltipSize = {
  7634. width: vm.width,
  7635. height: vm.height
  7636. };
  7637. var pt = {
  7638. x: vm.x,
  7639. y: vm.y
  7640. };
  7641. // IE11/Edge does not like very small opacities, so snap to 0
  7642. var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
  7643. // Truthy/falsey value for empty tooltip
  7644. var hasTooltipContent = vm.title.length || vm.beforeBody.length || vm.body.length || vm.afterBody.length || vm.footer.length;
  7645. if (this._options.enabled && hasTooltipContent) {
  7646. // Draw Background
  7647. this.drawBackground(pt, vm, ctx, tooltipSize, opacity);
  7648. // Draw Title, Body, and Footer
  7649. pt.x += vm.xPadding;
  7650. pt.y += vm.yPadding;
  7651. // Titles
  7652. this.drawTitle(pt, vm, ctx, opacity);
  7653. // Body
  7654. this.drawBody(pt, vm, ctx, opacity);
  7655. // Footer
  7656. this.drawFooter(pt, vm, ctx, opacity);
  7657. }
  7658. },
  7659. /**
  7660. * Handle an event
  7661. * @private
  7662. * @param {IEvent} event - The event to handle
  7663. * @returns {Boolean} true if the tooltip changed
  7664. */
  7665. handleEvent: function (e) {
  7666. var me = this;
  7667. var options = me._options;
  7668. var changed = false;
  7669. me._lastActive = me._lastActive || [];
  7670. // Find Active Elements for tooltips
  7671. if (e.type === 'mouseout') {
  7672. me._active = [];
  7673. } else {
  7674. me._active = me._chart.getElementsAtEventForMode(e, options.mode, options);
  7675. }
  7676. // Remember Last Actives
  7677. changed = !helpers.arrayEquals(me._active, me._lastActive);
  7678. // Only handle target event on tooltip change
  7679. if (changed) {
  7680. me._lastActive = me._active;
  7681. if (options.enabled || options.custom) {
  7682. me._eventPosition = {
  7683. x: e.x,
  7684. y: e.y
  7685. };
  7686. me.update(true);
  7687. me.pivot();
  7688. }
  7689. }
  7690. return changed;
  7691. }
  7692. });
  7693. /**
  7694. * @namespace Chart.Tooltip.positioners
  7695. */
  7696. Chart.Tooltip.positioners = {
  7697. /**
  7698. * Average mode places the tooltip at the average position of the elements shown
  7699. * @function Chart.Tooltip.positioners.average
  7700. * @param elements {ChartElement[]} the elements being displayed in the tooltip
  7701. * @returns {Point} tooltip position
  7702. */
  7703. average: function (elements) {
  7704. if (!elements.length) {
  7705. return false;
  7706. }
  7707. var i, len;
  7708. var x = 0;
  7709. var y = 0;
  7710. var count = 0;
  7711. for (i = 0, len = elements.length; i < len; ++i) {
  7712. var el = elements[i];
  7713. if (el && el.hasValue()) {
  7714. var pos = el.tooltipPosition();
  7715. x += pos.x;
  7716. y += pos.y;
  7717. ++count;
  7718. }
  7719. }
  7720. return {
  7721. x: Math.round(x / count),
  7722. y: Math.round(y / count)
  7723. };
  7724. },
  7725. /**
  7726. * Gets the tooltip position nearest of the item nearest to the event position
  7727. * @function Chart.Tooltip.positioners.nearest
  7728. * @param elements {Chart.Element[]} the tooltip elements
  7729. * @param eventPosition {Point} the position of the event in canvas coordinates
  7730. * @returns {Point} the tooltip position
  7731. */
  7732. nearest: function (elements, eventPosition) {
  7733. var x = eventPosition.x;
  7734. var y = eventPosition.y;
  7735. var minDistance = Number.POSITIVE_INFINITY;
  7736. var i, len, nearestElement;
  7737. for (i = 0, len = elements.length; i < len; ++i) {
  7738. var el = elements[i];
  7739. if (el && el.hasValue()) {
  7740. var center = el.getCenterPoint();
  7741. var d = helpers.distanceBetweenPoints(eventPosition, center);
  7742. if (d < minDistance) {
  7743. minDistance = d;
  7744. nearestElement = el;
  7745. }
  7746. }
  7747. }
  7748. if (nearestElement) {
  7749. var tp = nearestElement.tooltipPosition();
  7750. x = tp.x;
  7751. y = tp.y;
  7752. }
  7753. return {
  7754. x: x,
  7755. y: y
  7756. };
  7757. }
  7758. };
  7759. };
  7760. }, {"25": 25, "26": 26, "45": 45}], 36: [function (require, module, exports) {
  7761. 'use strict';
  7762. var defaults = require(25);
  7763. var Element = require(26);
  7764. var helpers = require(45);
  7765. defaults._set('global', {
  7766. elements: {
  7767. arc: {
  7768. backgroundColor: defaults.global.defaultColor,
  7769. borderColor: '#fff',
  7770. borderWidth: 2
  7771. }
  7772. }
  7773. });
  7774. module.exports = Element.extend({
  7775. inLabelRange: function (mouseX) {
  7776. var vm = this._view;
  7777. if (vm) {
  7778. return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
  7779. }
  7780. return false;
  7781. },
  7782. inRange: function (chartX, chartY) {
  7783. var vm = this._view;
  7784. if (vm) {
  7785. var pointRelativePosition = helpers.getAngleFromPoint(vm, {x: chartX, y: chartY});
  7786. var angle = pointRelativePosition.angle;
  7787. var distance = pointRelativePosition.distance;
  7788. // Sanitise angle range
  7789. var startAngle = vm.startAngle;
  7790. var endAngle = vm.endAngle;
  7791. while (endAngle < startAngle) {
  7792. endAngle += 2.0 * Math.PI;
  7793. }
  7794. while (angle > endAngle) {
  7795. angle -= 2.0 * Math.PI;
  7796. }
  7797. while (angle < startAngle) {
  7798. angle += 2.0 * Math.PI;
  7799. }
  7800. // Check if within the range of the open/close angle
  7801. var betweenAngles = (angle >= startAngle && angle <= endAngle);
  7802. var withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius);
  7803. return (betweenAngles && withinRadius);
  7804. }
  7805. return false;
  7806. },
  7807. getCenterPoint: function () {
  7808. var vm = this._view;
  7809. var halfAngle = (vm.startAngle + vm.endAngle) / 2;
  7810. var halfRadius = (vm.innerRadius + vm.outerRadius) / 2;
  7811. return {
  7812. x: vm.x + Math.cos(halfAngle) * halfRadius,
  7813. y: vm.y + Math.sin(halfAngle) * halfRadius
  7814. };
  7815. },
  7816. getArea: function () {
  7817. var vm = this._view;
  7818. return Math.PI * ((vm.endAngle - vm.startAngle) / (2 * Math.PI)) * (Math.pow(vm.outerRadius, 2) - Math.pow(vm.innerRadius, 2));
  7819. },
  7820. tooltipPosition: function () {
  7821. var vm = this._view;
  7822. var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2);
  7823. var rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
  7824. return {
  7825. x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
  7826. y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
  7827. };
  7828. },
  7829. draw: function () {
  7830. var ctx = this._chart.ctx;
  7831. var vm = this._view;
  7832. var sA = vm.startAngle;
  7833. var eA = vm.endAngle;
  7834. ctx.beginPath();
  7835. ctx.arc(vm.x, vm.y, vm.outerRadius, sA, eA);
  7836. ctx.arc(vm.x, vm.y, vm.innerRadius, eA, sA, true);
  7837. ctx.closePath();
  7838. ctx.strokeStyle = vm.borderColor;
  7839. ctx.lineWidth = vm.borderWidth;
  7840. ctx.fillStyle = vm.backgroundColor;
  7841. ctx.fill();
  7842. ctx.lineJoin = 'bevel';
  7843. if (vm.borderWidth) {
  7844. ctx.stroke();
  7845. }
  7846. }
  7847. });
  7848. }, {"25": 25, "26": 26, "45": 45}], 37: [function (require, module, exports) {
  7849. 'use strict';
  7850. var defaults = require(25);
  7851. var Element = require(26);
  7852. var helpers = require(45);
  7853. var globalDefaults = defaults.global;
  7854. defaults._set('global', {
  7855. elements: {
  7856. line: {
  7857. tension: 0.4,
  7858. backgroundColor: globalDefaults.defaultColor,
  7859. borderWidth: 3,
  7860. borderColor: globalDefaults.defaultColor,
  7861. borderCapStyle: 'butt',
  7862. borderDash: [],
  7863. borderDashOffset: 0.0,
  7864. borderJoinStyle: 'miter',
  7865. capBezierPoints: true,
  7866. fill: true, // do we fill in the area between the line and its base axis
  7867. }
  7868. }
  7869. });
  7870. module.exports = Element.extend({
  7871. draw: function () {
  7872. var me = this;
  7873. var vm = me._view;
  7874. var ctx = me._chart.ctx;
  7875. var spanGaps = vm.spanGaps;
  7876. var points = me._children.slice(); // clone array
  7877. var globalOptionLineElements = globalDefaults.elements.line;
  7878. var lastDrawnIndex = -1;
  7879. var index, current, previous, currentVM;
  7880. // If we are looping, adding the first point again
  7881. if (me._loop && points.length) {
  7882. points.push(points[0]);
  7883. }
  7884. ctx.save();
  7885. // Stroke Line Options
  7886. ctx.lineCap = vm.borderCapStyle || globalOptionLineElements.borderCapStyle;
  7887. // IE 9 and 10 do not support line dash
  7888. if (ctx.setLineDash) {
  7889. ctx.setLineDash(vm.borderDash || globalOptionLineElements.borderDash);
  7890. }
  7891. ctx.lineDashOffset = vm.borderDashOffset || globalOptionLineElements.borderDashOffset;
  7892. ctx.lineJoin = vm.borderJoinStyle || globalOptionLineElements.borderJoinStyle;
  7893. ctx.lineWidth = vm.borderWidth || globalOptionLineElements.borderWidth;
  7894. ctx.strokeStyle = vm.borderColor || globalDefaults.defaultColor;
  7895. // Stroke Line
  7896. ctx.beginPath();
  7897. lastDrawnIndex = -1;
  7898. for (index = 0; index < points.length; ++index) {
  7899. current = points[index];
  7900. previous = helpers.previousItem(points, index);
  7901. currentVM = current._view;
  7902. // First point moves to it's starting position no matter what
  7903. if (index === 0) {
  7904. if (!currentVM.skip) {
  7905. ctx.moveTo(currentVM.x, currentVM.y);
  7906. lastDrawnIndex = index;
  7907. }
  7908. } else {
  7909. previous = lastDrawnIndex === -1 ? previous : points[lastDrawnIndex];
  7910. if (!currentVM.skip) {
  7911. if ((lastDrawnIndex !== (index - 1) && !spanGaps) || lastDrawnIndex === -1) {
  7912. // There was a gap and this is the first point after the gap
  7913. ctx.moveTo(currentVM.x, currentVM.y);
  7914. } else {
  7915. // Line to next point
  7916. helpers.canvas.lineTo(ctx, previous._view, current._view);
  7917. }
  7918. lastDrawnIndex = index;
  7919. }
  7920. }
  7921. }
  7922. ctx.stroke();
  7923. ctx.restore();
  7924. }
  7925. });
  7926. }, {"25": 25, "26": 26, "45": 45}], 38: [function (require, module, exports) {
  7927. 'use strict';
  7928. var defaults = require(25);
  7929. var Element = require(26);
  7930. var helpers = require(45);
  7931. var defaultColor = defaults.global.defaultColor;
  7932. defaults._set('global', {
  7933. elements: {
  7934. point: {
  7935. radius: 3,
  7936. pointStyle: 'circle',
  7937. backgroundColor: defaultColor,
  7938. borderColor: defaultColor,
  7939. borderWidth: 1,
  7940. // Hover
  7941. hitRadius: 1,
  7942. hoverRadius: 4,
  7943. hoverBorderWidth: 1
  7944. }
  7945. }
  7946. });
  7947. function xRange(mouseX) {
  7948. var vm = this._view;
  7949. return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false;
  7950. }
  7951. function yRange(mouseY) {
  7952. var vm = this._view;
  7953. return vm ? (Math.abs(mouseY - vm.y) < vm.radius + vm.hitRadius) : false;
  7954. }
  7955. module.exports = Element.extend({
  7956. inRange: function (mouseX, mouseY) {
  7957. var vm = this._view;
  7958. return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false;
  7959. },
  7960. inLabelRange: xRange,
  7961. inXRange: xRange,
  7962. inYRange: yRange,
  7963. getCenterPoint: function () {
  7964. var vm = this._view;
  7965. return {
  7966. x: vm.x,
  7967. y: vm.y
  7968. };
  7969. },
  7970. getArea: function () {
  7971. return Math.PI * Math.pow(this._view.radius, 2);
  7972. },
  7973. tooltipPosition: function () {
  7974. var vm = this._view;
  7975. return {
  7976. x: vm.x,
  7977. y: vm.y,
  7978. padding: vm.radius + vm.borderWidth
  7979. };
  7980. },
  7981. draw: function (chartArea) {
  7982. var vm = this._view;
  7983. var model = this._model;
  7984. var ctx = this._chart.ctx;
  7985. var pointStyle = vm.pointStyle;
  7986. var radius = vm.radius;
  7987. var x = vm.x;
  7988. var y = vm.y;
  7989. var color = helpers.color;
  7990. var errMargin = 1.01; // 1.01 is margin for Accumulated error. (Especially Edge, IE.)
  7991. var ratio = 0;
  7992. if (vm.skip) {
  7993. return;
  7994. }
  7995. ctx.strokeStyle = vm.borderColor || defaultColor;
  7996. ctx.lineWidth = helpers.valueOrDefault(vm.borderWidth, defaults.global.elements.point.borderWidth);
  7997. ctx.fillStyle = vm.backgroundColor || defaultColor;
  7998. // Cliping for Points.
  7999. // going out from inner charArea?
  8000. if ((chartArea !== undefined) && ((model.x < chartArea.left) || (chartArea.right * errMargin < model.x) || (model.y < chartArea.top) || (chartArea.bottom * errMargin < model.y))) {
  8001. // Point fade out
  8002. if (model.x < chartArea.left) {
  8003. ratio = (x - model.x) / (chartArea.left - model.x);
  8004. } else if (chartArea.right * errMargin < model.x) {
  8005. ratio = (model.x - x) / (model.x - chartArea.right);
  8006. } else if (model.y < chartArea.top) {
  8007. ratio = (y - model.y) / (chartArea.top - model.y);
  8008. } else if (chartArea.bottom * errMargin < model.y) {
  8009. ratio = (model.y - y) / (model.y - chartArea.bottom);
  8010. }
  8011. ratio = Math.round(ratio * 100) / 100;
  8012. ctx.strokeStyle = color(ctx.strokeStyle).alpha(ratio).rgbString();
  8013. ctx.fillStyle = color(ctx.fillStyle).alpha(ratio).rgbString();
  8014. }
  8015. helpers.canvas.drawPoint(ctx, pointStyle, radius, x, y);
  8016. }
  8017. });
  8018. }, {"25": 25, "26": 26, "45": 45}], 39: [function (require, module, exports) {
  8019. 'use strict';
  8020. var defaults = require(25);
  8021. var Element = require(26);
  8022. defaults._set('global', {
  8023. elements: {
  8024. rectangle: {
  8025. backgroundColor: defaults.global.defaultColor,
  8026. borderColor: defaults.global.defaultColor,
  8027. borderSkipped: 'bottom',
  8028. borderWidth: 0
  8029. }
  8030. }
  8031. });
  8032. function isVertical(bar) {
  8033. return bar._view.width !== undefined;
  8034. }
  8035. /**
  8036. * Helper function to get the bounds of the bar regardless of the orientation
  8037. * @param bar {Chart.Element.Rectangle} the bar
  8038. * @return {Bounds} bounds of the bar
  8039. * @private
  8040. */
  8041. function getBarBounds(bar) {
  8042. var vm = bar._view;
  8043. var x1, x2, y1, y2;
  8044. if (isVertical(bar)) {
  8045. // vertical
  8046. var halfWidth = vm.width / 2;
  8047. x1 = vm.x - halfWidth;
  8048. x2 = vm.x + halfWidth;
  8049. y1 = Math.min(vm.y, vm.base);
  8050. y2 = Math.max(vm.y, vm.base);
  8051. } else {
  8052. // horizontal bar
  8053. var halfHeight = vm.height / 2;
  8054. x1 = Math.min(vm.x, vm.base);
  8055. x2 = Math.max(vm.x, vm.base);
  8056. y1 = vm.y - halfHeight;
  8057. y2 = vm.y + halfHeight;
  8058. }
  8059. return {
  8060. left: x1,
  8061. top: y1,
  8062. right: x2,
  8063. bottom: y2
  8064. };
  8065. }
  8066. module.exports = Element.extend({
  8067. draw: function () {
  8068. var ctx = this._chart.ctx;
  8069. var vm = this._view;
  8070. var left, right, top, bottom, signX, signY, borderSkipped;
  8071. var borderWidth = vm.borderWidth;
  8072. if (!vm.horizontal) {
  8073. // bar
  8074. left = vm.x - vm.width / 2;
  8075. right = vm.x + vm.width / 2;
  8076. top = vm.y;
  8077. bottom = vm.base;
  8078. signX = 1;
  8079. signY = bottom > top ? 1 : -1;
  8080. borderSkipped = vm.borderSkipped || 'bottom';
  8081. } else {
  8082. // horizontal bar
  8083. left = vm.base;
  8084. right = vm.x;
  8085. top = vm.y - vm.height / 2;
  8086. bottom = vm.y + vm.height / 2;
  8087. signX = right > left ? 1 : -1;
  8088. signY = 1;
  8089. borderSkipped = vm.borderSkipped || 'left';
  8090. }
  8091. // Canvas doesn't allow us to stroke inside the width so we can
  8092. // adjust the sizes to fit if we're setting a stroke on the line
  8093. if (borderWidth) {
  8094. // borderWidth shold be less than bar width and bar height.
  8095. var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom));
  8096. borderWidth = borderWidth > barSize ? barSize : borderWidth;
  8097. var halfStroke = borderWidth / 2;
  8098. // Adjust borderWidth when bar top position is near vm.base(zero).
  8099. var borderLeft = left + (borderSkipped !== 'left' ? halfStroke * signX : 0);
  8100. var borderRight = right + (borderSkipped !== 'right' ? -halfStroke * signX : 0);
  8101. var borderTop = top + (borderSkipped !== 'top' ? halfStroke * signY : 0);
  8102. var borderBottom = bottom + (borderSkipped !== 'bottom' ? -halfStroke * signY : 0);
  8103. // not become a vertical line?
  8104. if (borderLeft !== borderRight) {
  8105. top = borderTop;
  8106. bottom = borderBottom;
  8107. }
  8108. // not become a horizontal line?
  8109. if (borderTop !== borderBottom) {
  8110. left = borderLeft;
  8111. right = borderRight;
  8112. }
  8113. }
  8114. ctx.beginPath();
  8115. ctx.fillStyle = vm.backgroundColor;
  8116. ctx.strokeStyle = vm.borderColor;
  8117. ctx.lineWidth = borderWidth;
  8118. // Corner points, from bottom-left to bottom-right clockwise
  8119. // | 1 2 |
  8120. // | 0 3 |
  8121. var corners = [
  8122. [left, bottom],
  8123. [left, top],
  8124. [right, top],
  8125. [right, bottom]
  8126. ];
  8127. // Find first (starting) corner with fallback to 'bottom'
  8128. var borders = ['bottom', 'left', 'top', 'right'];
  8129. var startCorner = borders.indexOf(borderSkipped, 0);
  8130. if (startCorner === -1) {
  8131. startCorner = 0;
  8132. }
  8133. function cornerAt(index) {
  8134. return corners[(startCorner + index) % 4];
  8135. }
  8136. // Draw rectangle from 'startCorner'
  8137. var corner = cornerAt(0);
  8138. ctx.moveTo(corner[0], corner[1]);
  8139. for (var i = 1; i < 4; i++) {
  8140. corner = cornerAt(i);
  8141. ctx.lineTo(corner[0], corner[1]);
  8142. }
  8143. ctx.fill();
  8144. if (borderWidth) {
  8145. ctx.stroke();
  8146. }
  8147. },
  8148. height: function () {
  8149. var vm = this._view;
  8150. return vm.base - vm.y;
  8151. },
  8152. inRange: function (mouseX, mouseY) {
  8153. var inRange = false;
  8154. if (this._view) {
  8155. var bounds = getBarBounds(this);
  8156. inRange = mouseX >= bounds.left && mouseX <= bounds.right && mouseY >= bounds.top && mouseY <= bounds.bottom;
  8157. }
  8158. return inRange;
  8159. },
  8160. inLabelRange: function (mouseX, mouseY) {
  8161. var me = this;
  8162. if (!me._view) {
  8163. return false;
  8164. }
  8165. var inRange = false;
  8166. var bounds = getBarBounds(me);
  8167. if (isVertical(me)) {
  8168. inRange = mouseX >= bounds.left && mouseX <= bounds.right;
  8169. } else {
  8170. inRange = mouseY >= bounds.top && mouseY <= bounds.bottom;
  8171. }
  8172. return inRange;
  8173. },
  8174. inXRange: function (mouseX) {
  8175. var bounds = getBarBounds(this);
  8176. return mouseX >= bounds.left && mouseX <= bounds.right;
  8177. },
  8178. inYRange: function (mouseY) {
  8179. var bounds = getBarBounds(this);
  8180. return mouseY >= bounds.top && mouseY <= bounds.bottom;
  8181. },
  8182. getCenterPoint: function () {
  8183. var vm = this._view;
  8184. var x, y;
  8185. if (isVertical(this)) {
  8186. x = vm.x;
  8187. y = (vm.y + vm.base) / 2;
  8188. } else {
  8189. x = (vm.x + vm.base) / 2;
  8190. y = vm.y;
  8191. }
  8192. return {x: x, y: y};
  8193. },
  8194. getArea: function () {
  8195. var vm = this._view;
  8196. return vm.width * Math.abs(vm.y - vm.base);
  8197. },
  8198. tooltipPosition: function () {
  8199. var vm = this._view;
  8200. return {
  8201. x: vm.x,
  8202. y: vm.y
  8203. };
  8204. }
  8205. });
  8206. }, {"25": 25, "26": 26}], 40: [function (require, module, exports) {
  8207. 'use strict';
  8208. module.exports = {};
  8209. module.exports.Arc = require(36);
  8210. module.exports.Line = require(37);
  8211. module.exports.Point = require(38);
  8212. module.exports.Rectangle = require(39);
  8213. }, {"36": 36, "37": 37, "38": 38, "39": 39}], 41: [function (require, module, exports) {
  8214. 'use strict';
  8215. var helpers = require(42);
  8216. /**
  8217. * @namespace Chart.helpers.canvas
  8218. */
  8219. var exports = module.exports = {
  8220. /**
  8221. * Clears the entire canvas associated to the given `chart`.
  8222. * @param {Chart} chart - The chart for which to clear the canvas.
  8223. */
  8224. clear: function (chart) {
  8225. chart.ctx.clearRect(0, 0, chart.width, chart.height);
  8226. },
  8227. /**
  8228. * Creates a "path" for a rectangle with rounded corners at position (x, y) with a
  8229. * given size (width, height) and the same `radius` for all corners.
  8230. * @param {CanvasRenderingContext2D} ctx - The canvas 2D Context.
  8231. * @param {Number} x - The x axis of the coordinate for the rectangle starting point.
  8232. * @param {Number} y - The y axis of the coordinate for the rectangle starting point.
  8233. * @param {Number} width - The rectangle's width.
  8234. * @param {Number} height - The rectangle's height.
  8235. * @param {Number} radius - The rounded amount (in pixels) for the four corners.
  8236. * @todo handle `radius` as top-left, top-right, bottom-right, bottom-left array/object?
  8237. */
  8238. roundedRect: function (ctx, x, y, width, height, radius) {
  8239. if (radius) {
  8240. var rx = Math.min(radius, width / 2);
  8241. var ry = Math.min(radius, height / 2);
  8242. ctx.moveTo(x + rx, y);
  8243. ctx.lineTo(x + width - rx, y);
  8244. ctx.quadraticCurveTo(x + width, y, x + width, y + ry);
  8245. ctx.lineTo(x + width, y + height - ry);
  8246. ctx.quadraticCurveTo(x + width, y + height, x + width - rx, y + height);
  8247. ctx.lineTo(x + rx, y + height);
  8248. ctx.quadraticCurveTo(x, y + height, x, y + height - ry);
  8249. ctx.lineTo(x, y + ry);
  8250. ctx.quadraticCurveTo(x, y, x + rx, y);
  8251. } else {
  8252. ctx.rect(x, y, width, height);
  8253. }
  8254. },
  8255. drawPoint: function (ctx, style, radius, x, y) {
  8256. var type, edgeLength, xOffset, yOffset, height, size;
  8257. if (style && typeof style === 'object') {
  8258. type = style.toString();
  8259. if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
  8260. ctx.drawImage(style, x - style.width / 2, y - style.height / 2, style.width, style.height);
  8261. return;
  8262. }
  8263. }
  8264. if (isNaN(radius) || radius <= 0) {
  8265. return;
  8266. }
  8267. switch (style) {
  8268. // Default includes circle
  8269. default:
  8270. ctx.beginPath();
  8271. ctx.arc(x, y, radius, 0, Math.PI * 2);
  8272. ctx.closePath();
  8273. ctx.fill();
  8274. break;
  8275. case 'triangle':
  8276. ctx.beginPath();
  8277. edgeLength = 3 * radius / Math.sqrt(3);
  8278. height = edgeLength * Math.sqrt(3) / 2;
  8279. ctx.moveTo(x - edgeLength / 2, y + height / 3);
  8280. ctx.lineTo(x + edgeLength / 2, y + height / 3);
  8281. ctx.lineTo(x, y - 2 * height / 3);
  8282. ctx.closePath();
  8283. ctx.fill();
  8284. break;
  8285. case 'rect':
  8286. size = 1 / Math.SQRT2 * radius;
  8287. ctx.beginPath();
  8288. ctx.fillRect(x - size, y - size, 2 * size, 2 * size);
  8289. ctx.strokeRect(x - size, y - size, 2 * size, 2 * size);
  8290. break;
  8291. case 'rectRounded':
  8292. var offset = radius / Math.SQRT2;
  8293. var leftX = x - offset;
  8294. var topY = y - offset;
  8295. var sideSize = Math.SQRT2 * radius;
  8296. ctx.beginPath();
  8297. this.roundedRect(ctx, leftX, topY, sideSize, sideSize, radius / 2);
  8298. ctx.closePath();
  8299. ctx.fill();
  8300. break;
  8301. case 'rectRot':
  8302. size = 1 / Math.SQRT2 * radius;
  8303. ctx.beginPath();
  8304. ctx.moveTo(x - size, y);
  8305. ctx.lineTo(x, y + size);
  8306. ctx.lineTo(x + size, y);
  8307. ctx.lineTo(x, y - size);
  8308. ctx.closePath();
  8309. ctx.fill();
  8310. break;
  8311. case 'cross':
  8312. ctx.beginPath();
  8313. ctx.moveTo(x, y + radius);
  8314. ctx.lineTo(x, y - radius);
  8315. ctx.moveTo(x - radius, y);
  8316. ctx.lineTo(x + radius, y);
  8317. ctx.closePath();
  8318. break;
  8319. case 'crossRot':
  8320. ctx.beginPath();
  8321. xOffset = Math.cos(Math.PI / 4) * radius;
  8322. yOffset = Math.sin(Math.PI / 4) * radius;
  8323. ctx.moveTo(x - xOffset, y - yOffset);
  8324. ctx.lineTo(x + xOffset, y + yOffset);
  8325. ctx.moveTo(x - xOffset, y + yOffset);
  8326. ctx.lineTo(x + xOffset, y - yOffset);
  8327. ctx.closePath();
  8328. break;
  8329. case 'star':
  8330. ctx.beginPath();
  8331. ctx.moveTo(x, y + radius);
  8332. ctx.lineTo(x, y - radius);
  8333. ctx.moveTo(x - radius, y);
  8334. ctx.lineTo(x + radius, y);
  8335. xOffset = Math.cos(Math.PI / 4) * radius;
  8336. yOffset = Math.sin(Math.PI / 4) * radius;
  8337. ctx.moveTo(x - xOffset, y - yOffset);
  8338. ctx.lineTo(x + xOffset, y + yOffset);
  8339. ctx.moveTo(x - xOffset, y + yOffset);
  8340. ctx.lineTo(x + xOffset, y - yOffset);
  8341. ctx.closePath();
  8342. break;
  8343. case 'line':
  8344. ctx.beginPath();
  8345. ctx.moveTo(x - radius, y);
  8346. ctx.lineTo(x + radius, y);
  8347. ctx.closePath();
  8348. break;
  8349. case 'dash':
  8350. ctx.beginPath();
  8351. ctx.moveTo(x, y);
  8352. ctx.lineTo(x + radius, y);
  8353. ctx.closePath();
  8354. break;
  8355. }
  8356. ctx.stroke();
  8357. },
  8358. clipArea: function (ctx, area) {
  8359. ctx.save();
  8360. ctx.beginPath();
  8361. ctx.rect(area.left, area.top, area.right - area.left, area.bottom - area.top);
  8362. ctx.clip();
  8363. },
  8364. unclipArea: function (ctx) {
  8365. ctx.restore();
  8366. },
  8367. lineTo: function (ctx, previous, target, flip) {
  8368. if (target.steppedLine) {
  8369. if ((target.steppedLine === 'after' && !flip) || (target.steppedLine !== 'after' && flip)) {
  8370. ctx.lineTo(previous.x, target.y);
  8371. } else {
  8372. ctx.lineTo(target.x, previous.y);
  8373. }
  8374. ctx.lineTo(target.x, target.y);
  8375. return;
  8376. }
  8377. if (!target.tension) {
  8378. ctx.lineTo(target.x, target.y);
  8379. return;
  8380. }
  8381. ctx.bezierCurveTo(
  8382. flip ? previous.controlPointPreviousX : previous.controlPointNextX,
  8383. flip ? previous.controlPointPreviousY : previous.controlPointNextY,
  8384. flip ? target.controlPointNextX : target.controlPointPreviousX,
  8385. flip ? target.controlPointNextY : target.controlPointPreviousY,
  8386. target.x,
  8387. target.y);
  8388. }
  8389. };
  8390. // DEPRECATIONS
  8391. /**
  8392. * Provided for backward compatibility, use Chart.helpers.canvas.clear instead.
  8393. * @namespace Chart.helpers.clear
  8394. * @deprecated since version 2.7.0
  8395. * @todo remove at version 3
  8396. * @private
  8397. */
  8398. helpers.clear = exports.clear;
  8399. /**
  8400. * Provided for backward compatibility, use Chart.helpers.canvas.roundedRect instead.
  8401. * @namespace Chart.helpers.drawRoundedRectangle
  8402. * @deprecated since version 2.7.0
  8403. * @todo remove at version 3
  8404. * @private
  8405. */
  8406. helpers.drawRoundedRectangle = function (ctx) {
  8407. ctx.beginPath();
  8408. exports.roundedRect.apply(exports, arguments);
  8409. ctx.closePath();
  8410. };
  8411. }, {"42": 42}], 42: [function (require, module, exports) {
  8412. 'use strict';
  8413. /**
  8414. * @namespace Chart.helpers
  8415. */
  8416. var helpers = {
  8417. /**
  8418. * An empty function that can be used, for example, for optional callback.
  8419. */
  8420. noop: function () {},
  8421. /**
  8422. * Returns a unique id, sequentially generated from a global variable.
  8423. * @returns {Number}
  8424. * @function
  8425. */
  8426. uid: (function () {
  8427. var id = 0;
  8428. return function () {
  8429. return id++;
  8430. };
  8431. }()),
  8432. /**
  8433. * Returns true if `value` is neither null nor undefined, else returns false.
  8434. * @param {*} value - The value to test.
  8435. * @returns {Boolean}
  8436. * @since 2.7.0
  8437. */
  8438. isNullOrUndef: function (value) {
  8439. return value === null || typeof value === 'undefined';
  8440. },
  8441. /**
  8442. * Returns true if `value` is an array, else returns false.
  8443. * @param {*} value - The value to test.
  8444. * @returns {Boolean}
  8445. * @function
  8446. */
  8447. isArray: Array.isArray ? Array.isArray : function (value) {
  8448. return Object.prototype.toString.call(value) === '[object Array]';
  8449. },
  8450. /**
  8451. * Returns true if `value` is an object (excluding null), else returns false.
  8452. * @param {*} value - The value to test.
  8453. * @returns {Boolean}
  8454. * @since 2.7.0
  8455. */
  8456. isObject: function (value) {
  8457. return value !== null && Object.prototype.toString.call(value) === '[object Object]';
  8458. },
  8459. /**
  8460. * Returns `value` if defined, else returns `defaultValue`.
  8461. * @param {*} value - The value to return if defined.
  8462. * @param {*} defaultValue - The value to return if `value` is undefined.
  8463. * @returns {*}
  8464. */
  8465. valueOrDefault: function (value, defaultValue) {
  8466. return typeof value === 'undefined' ? defaultValue : value;
  8467. },
  8468. /**
  8469. * Returns value at the given `index` in array if defined, else returns `defaultValue`.
  8470. * @param {Array} value - The array to lookup for value at `index`.
  8471. * @param {Number} index - The index in `value` to lookup for value.
  8472. * @param {*} defaultValue - The value to return if `value[index]` is undefined.
  8473. * @returns {*}
  8474. */
  8475. valueAtIndexOrDefault: function (value, index, defaultValue) {
  8476. return helpers.valueOrDefault(helpers.isArray(value) ? value[index] : value, defaultValue);
  8477. },
  8478. /**
  8479. * Calls `fn` with the given `args` in the scope defined by `thisArg` and returns the
  8480. * value returned by `fn`. If `fn` is not a function, this method returns undefined.
  8481. * @param {Function} fn - The function to call.
  8482. * @param {Array|undefined|null} args - The arguments with which `fn` should be called.
  8483. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  8484. * @returns {*}
  8485. */
  8486. callback: function (fn, args, thisArg) {
  8487. if (fn && typeof fn.call === 'function') {
  8488. return fn.apply(thisArg, args);
  8489. }
  8490. },
  8491. /**
  8492. * Note(SB) for performance sake, this method should only be used when loopable type
  8493. * is unknown or in none intensive code (not called often and small loopable). Else
  8494. * it's preferable to use a regular for() loop and save extra function calls.
  8495. * @param {Object|Array} loopable - The object or array to be iterated.
  8496. * @param {Function} fn - The function to call for each item.
  8497. * @param {Object} [thisArg] - The value of `this` provided for the call to `fn`.
  8498. * @param {Boolean} [reverse] - If true, iterates backward on the loopable.
  8499. */
  8500. each: function (loopable, fn, thisArg, reverse) {
  8501. var i, len, keys;
  8502. if (helpers.isArray(loopable)) {
  8503. len = loopable.length;
  8504. if (reverse) {
  8505. for (i = len - 1; i >= 0; i--) {
  8506. fn.call(thisArg, loopable[i], i);
  8507. }
  8508. } else {
  8509. for (i = 0; i < len; i++) {
  8510. fn.call(thisArg, loopable[i], i);
  8511. }
  8512. }
  8513. } else if (helpers.isObject(loopable)) {
  8514. keys = Object.keys(loopable);
  8515. len = keys.length;
  8516. for (i = 0; i < len; i++) {
  8517. fn.call(thisArg, loopable[keys[i]], keys[i]);
  8518. }
  8519. }
  8520. },
  8521. /**
  8522. * Returns true if the `a0` and `a1` arrays have the same content, else returns false.
  8523. * @see http://stackoverflow.com/a/14853974
  8524. * @param {Array} a0 - The array to compare
  8525. * @param {Array} a1 - The array to compare
  8526. * @returns {Boolean}
  8527. */
  8528. arrayEquals: function (a0, a1) {
  8529. var i, ilen, v0, v1;
  8530. if (!a0 || !a1 || a0.length !== a1.length) {
  8531. return false;
  8532. }
  8533. for (i = 0, ilen = a0.length; i < ilen; ++i) {
  8534. v0 = a0[i];
  8535. v1 = a1[i];
  8536. if (v0 instanceof Array && v1 instanceof Array) {
  8537. if (!helpers.arrayEquals(v0, v1)) {
  8538. return false;
  8539. }
  8540. } else if (v0 !== v1) {
  8541. // NOTE: two different object instances will never be equal: {x:20} != {x:20}
  8542. return false;
  8543. }
  8544. }
  8545. return true;
  8546. },
  8547. /**
  8548. * Returns a deep copy of `source` without keeping references on objects and arrays.
  8549. * @param {*} source - The value to clone.
  8550. * @returns {*}
  8551. */
  8552. clone: function (source) {
  8553. if (helpers.isArray(source)) {
  8554. return source.map(helpers.clone);
  8555. }
  8556. if (helpers.isObject(source)) {
  8557. var target = {};
  8558. var keys = Object.keys(source);
  8559. var klen = keys.length;
  8560. var k = 0;
  8561. for (; k < klen; ++k) {
  8562. target[keys[k]] = helpers.clone(source[keys[k]]);
  8563. }
  8564. return target;
  8565. }
  8566. return source;
  8567. },
  8568. /**
  8569. * The default merger when Chart.helpers.merge is called without merger option.
  8570. * Note(SB): this method is also used by configMerge and scaleMerge as fallback.
  8571. * @private
  8572. */
  8573. _merger: function (key, target, source, options) {
  8574. var tval = target[key];
  8575. var sval = source[key];
  8576. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  8577. helpers.merge(tval, sval, options);
  8578. } else {
  8579. target[key] = helpers.clone(sval);
  8580. }
  8581. },
  8582. /**
  8583. * Merges source[key] in target[key] only if target[key] is undefined.
  8584. * @private
  8585. */
  8586. _mergerIf: function (key, target, source) {
  8587. var tval = target[key];
  8588. var sval = source[key];
  8589. if (helpers.isObject(tval) && helpers.isObject(sval)) {
  8590. helpers.mergeIf(tval, sval);
  8591. } else if (!target.hasOwnProperty(key)) {
  8592. target[key] = helpers.clone(sval);
  8593. }
  8594. },
  8595. /**
  8596. * Recursively deep copies `source` properties into `target` with the given `options`.
  8597. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  8598. * @param {Object} target - The target object in which all sources are merged into.
  8599. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  8600. * @param {Object} [options] - Merging options:
  8601. * @param {Function} [options.merger] - The merge method (key, target, source, options)
  8602. * @returns {Object} The `target` object.
  8603. */
  8604. merge: function (target, source, options) {
  8605. var sources = helpers.isArray(source) ? source : [source];
  8606. var ilen = sources.length;
  8607. var merge, i, keys, klen, k;
  8608. if (!helpers.isObject(target)) {
  8609. return target;
  8610. }
  8611. options = options || {};
  8612. merge = options.merger || helpers._merger;
  8613. for (i = 0; i < ilen; ++i) {
  8614. source = sources[i];
  8615. if (!helpers.isObject(source)) {
  8616. continue;
  8617. }
  8618. keys = Object.keys(source);
  8619. for (k = 0, klen = keys.length; k < klen; ++k) {
  8620. merge(keys[k], target, source, options);
  8621. }
  8622. }
  8623. return target;
  8624. },
  8625. /**
  8626. * Recursively deep copies `source` properties into `target` *only* if not defined in target.
  8627. * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
  8628. * @param {Object} target - The target object in which all sources are merged into.
  8629. * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
  8630. * @returns {Object} The `target` object.
  8631. */
  8632. mergeIf: function (target, source) {
  8633. return helpers.merge(target, source, {merger: helpers._mergerIf});
  8634. },
  8635. /**
  8636. * Applies the contents of two or more objects together into the first object.
  8637. * @param {Object} target - The target object in which all objects are merged into.
  8638. * @param {Object} arg1 - Object containing additional properties to merge in target.
  8639. * @param {Object} argN - Additional objects containing properties to merge in target.
  8640. * @returns {Object} The `target` object.
  8641. */
  8642. extend: function (target) {
  8643. var setFn = function (value, key) {
  8644. target[key] = value;
  8645. };
  8646. for (var i = 1, ilen = arguments.length; i < ilen; ++i) {
  8647. helpers.each(arguments[i], setFn);
  8648. }
  8649. return target;
  8650. },
  8651. /**
  8652. * Basic javascript inheritance based on the model created in Backbone.js
  8653. */
  8654. inherits: function (extensions) {
  8655. var me = this;
  8656. var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function () {
  8657. return me.apply(this, arguments);
  8658. };
  8659. var Surrogate = function () {
  8660. this.constructor = ChartElement;
  8661. };
  8662. Surrogate.prototype = me.prototype;
  8663. ChartElement.prototype = new Surrogate();
  8664. ChartElement.extend = helpers.inherits;
  8665. if (extensions) {
  8666. helpers.extend(ChartElement.prototype, extensions);
  8667. }
  8668. ChartElement.__super__ = me.prototype;
  8669. return ChartElement;
  8670. }
  8671. };
  8672. module.exports = helpers;
  8673. // DEPRECATIONS
  8674. /**
  8675. * Provided for backward compatibility, use Chart.helpers.callback instead.
  8676. * @function Chart.helpers.callCallback
  8677. * @deprecated since version 2.6.0
  8678. * @todo remove at version 3
  8679. * @private
  8680. */
  8681. helpers.callCallback = helpers.callback;
  8682. /**
  8683. * Provided for backward compatibility, use Array.prototype.indexOf instead.
  8684. * Array.prototype.indexOf compatibility: Chrome, Opera, Safari, FF1.5+, IE9+
  8685. * @function Chart.helpers.indexOf
  8686. * @deprecated since version 2.7.0
  8687. * @todo remove at version 3
  8688. * @private
  8689. */
  8690. helpers.indexOf = function (array, item, fromIndex) {
  8691. return Array.prototype.indexOf.call(array, item, fromIndex);
  8692. };
  8693. /**
  8694. * Provided for backward compatibility, use Chart.helpers.valueOrDefault instead.
  8695. * @function Chart.helpers.getValueOrDefault
  8696. * @deprecated since version 2.7.0
  8697. * @todo remove at version 3
  8698. * @private
  8699. */
  8700. helpers.getValueOrDefault = helpers.valueOrDefault;
  8701. /**
  8702. * Provided for backward compatibility, use Chart.helpers.valueAtIndexOrDefault instead.
  8703. * @function Chart.helpers.getValueAtIndexOrDefault
  8704. * @deprecated since version 2.7.0
  8705. * @todo remove at version 3
  8706. * @private
  8707. */
  8708. helpers.getValueAtIndexOrDefault = helpers.valueAtIndexOrDefault;
  8709. }, {}], 43: [function (require, module, exports) {
  8710. 'use strict';
  8711. var helpers = require(42);
  8712. /**
  8713. * Easing functions adapted from Robert Penner's easing equations.
  8714. * @namespace Chart.helpers.easingEffects
  8715. * @see http://www.robertpenner.com/easing/
  8716. */
  8717. var effects = {
  8718. linear: function (t) {
  8719. return t;
  8720. },
  8721. easeInQuad: function (t) {
  8722. return t * t;
  8723. },
  8724. easeOutQuad: function (t) {
  8725. return -t * (t - 2);
  8726. },
  8727. easeInOutQuad: function (t) {
  8728. if ((t /= 0.5) < 1) {
  8729. return 0.5 * t * t;
  8730. }
  8731. return -0.5 * ((--t) * (t - 2) - 1);
  8732. },
  8733. easeInCubic: function (t) {
  8734. return t * t * t;
  8735. },
  8736. easeOutCubic: function (t) {
  8737. return (t = t - 1) * t * t + 1;
  8738. },
  8739. easeInOutCubic: function (t) {
  8740. if ((t /= 0.5) < 1) {
  8741. return 0.5 * t * t * t;
  8742. }
  8743. return 0.5 * ((t -= 2) * t * t + 2);
  8744. },
  8745. easeInQuart: function (t) {
  8746. return t * t * t * t;
  8747. },
  8748. easeOutQuart: function (t) {
  8749. return -((t = t - 1) * t * t * t - 1);
  8750. },
  8751. easeInOutQuart: function (t) {
  8752. if ((t /= 0.5) < 1) {
  8753. return 0.5 * t * t * t * t;
  8754. }
  8755. return -0.5 * ((t -= 2) * t * t * t - 2);
  8756. },
  8757. easeInQuint: function (t) {
  8758. return t * t * t * t * t;
  8759. },
  8760. easeOutQuint: function (t) {
  8761. return (t = t - 1) * t * t * t * t + 1;
  8762. },
  8763. easeInOutQuint: function (t) {
  8764. if ((t /= 0.5) < 1) {
  8765. return 0.5 * t * t * t * t * t;
  8766. }
  8767. return 0.5 * ((t -= 2) * t * t * t * t + 2);
  8768. },
  8769. easeInSine: function (t) {
  8770. return -Math.cos(t * (Math.PI / 2)) + 1;
  8771. },
  8772. easeOutSine: function (t) {
  8773. return Math.sin(t * (Math.PI / 2));
  8774. },
  8775. easeInOutSine: function (t) {
  8776. return -0.5 * (Math.cos(Math.PI * t) - 1);
  8777. },
  8778. easeInExpo: function (t) {
  8779. return (t === 0) ? 0 : Math.pow(2, 10 * (t - 1));
  8780. },
  8781. easeOutExpo: function (t) {
  8782. return (t === 1) ? 1 : -Math.pow(2, -10 * t) + 1;
  8783. },
  8784. easeInOutExpo: function (t) {
  8785. if (t === 0) {
  8786. return 0;
  8787. }
  8788. if (t === 1) {
  8789. return 1;
  8790. }
  8791. if ((t /= 0.5) < 1) {
  8792. return 0.5 * Math.pow(2, 10 * (t - 1));
  8793. }
  8794. return 0.5 * (-Math.pow(2, -10 * --t) + 2);
  8795. },
  8796. easeInCirc: function (t) {
  8797. if (t >= 1) {
  8798. return t;
  8799. }
  8800. return -(Math.sqrt(1 - t * t) - 1);
  8801. },
  8802. easeOutCirc: function (t) {
  8803. return Math.sqrt(1 - (t = t - 1) * t);
  8804. },
  8805. easeInOutCirc: function (t) {
  8806. if ((t /= 0.5) < 1) {
  8807. return -0.5 * (Math.sqrt(1 - t * t) - 1);
  8808. }
  8809. return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
  8810. },
  8811. easeInElastic: function (t) {
  8812. var s = 1.70158;
  8813. var p = 0;
  8814. var a = 1;
  8815. if (t === 0) {
  8816. return 0;
  8817. }
  8818. if (t === 1) {
  8819. return 1;
  8820. }
  8821. if (!p) {
  8822. p = 0.3;
  8823. }
  8824. if (a < 1) {
  8825. a = 1;
  8826. s = p / 4;
  8827. } else {
  8828. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8829. }
  8830. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  8831. },
  8832. easeOutElastic: function (t) {
  8833. var s = 1.70158;
  8834. var p = 0;
  8835. var a = 1;
  8836. if (t === 0) {
  8837. return 0;
  8838. }
  8839. if (t === 1) {
  8840. return 1;
  8841. }
  8842. if (!p) {
  8843. p = 0.3;
  8844. }
  8845. if (a < 1) {
  8846. a = 1;
  8847. s = p / 4;
  8848. } else {
  8849. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8850. }
  8851. return a * Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
  8852. },
  8853. easeInOutElastic: function (t) {
  8854. var s = 1.70158;
  8855. var p = 0;
  8856. var a = 1;
  8857. if (t === 0) {
  8858. return 0;
  8859. }
  8860. if ((t /= 0.5) === 2) {
  8861. return 1;
  8862. }
  8863. if (!p) {
  8864. p = 0.45;
  8865. }
  8866. if (a < 1) {
  8867. a = 1;
  8868. s = p / 4;
  8869. } else {
  8870. s = p / (2 * Math.PI) * Math.asin(1 / a);
  8871. }
  8872. if (t < 1) {
  8873. return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
  8874. }
  8875. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p) * 0.5 + 1;
  8876. },
  8877. easeInBack: function (t) {
  8878. var s = 1.70158;
  8879. return t * t * ((s + 1) * t - s);
  8880. },
  8881. easeOutBack: function (t) {
  8882. var s = 1.70158;
  8883. return (t = t - 1) * t * ((s + 1) * t + s) + 1;
  8884. },
  8885. easeInOutBack: function (t) {
  8886. var s = 1.70158;
  8887. if ((t /= 0.5) < 1) {
  8888. return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s));
  8889. }
  8890. return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
  8891. },
  8892. easeInBounce: function (t) {
  8893. return 1 - effects.easeOutBounce(1 - t);
  8894. },
  8895. easeOutBounce: function (t) {
  8896. if (t < (1 / 2.75)) {
  8897. return 7.5625 * t * t;
  8898. }
  8899. if (t < (2 / 2.75)) {
  8900. return 7.5625 * (t -= (1.5 / 2.75)) * t + 0.75;
  8901. }
  8902. if (t < (2.5 / 2.75)) {
  8903. return 7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375;
  8904. }
  8905. return 7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375;
  8906. },
  8907. easeInOutBounce: function (t) {
  8908. if (t < 0.5) {
  8909. return effects.easeInBounce(t * 2) * 0.5;
  8910. }
  8911. return effects.easeOutBounce(t * 2 - 1) * 0.5 + 0.5;
  8912. }
  8913. };
  8914. module.exports = {
  8915. effects: effects
  8916. };
  8917. // DEPRECATIONS
  8918. /**
  8919. * Provided for backward compatibility, use Chart.helpers.easing.effects instead.
  8920. * @function Chart.helpers.easingEffects
  8921. * @deprecated since version 2.7.0
  8922. * @todo remove at version 3
  8923. * @private
  8924. */
  8925. helpers.easingEffects = effects;
  8926. }, {"42": 42}], 44: [function (require, module, exports) {
  8927. 'use strict';
  8928. var helpers = require(42);
  8929. /**
  8930. * @alias Chart.helpers.options
  8931. * @namespace
  8932. */
  8933. module.exports = {
  8934. /**
  8935. * Converts the given line height `value` in pixels for a specific font `size`.
  8936. * @param {Number|String} value - The lineHeight to parse (eg. 1.6, '14px', '75%', '1.6em').
  8937. * @param {Number} size - The font size (in pixels) used to resolve relative `value`.
  8938. * @returns {Number} The effective line height in pixels (size * 1.2 if value is invalid).
  8939. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
  8940. * @since 2.7.0
  8941. */
  8942. toLineHeight: function (value, size) {
  8943. var matches = ('' + value).match(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
  8944. if (!matches || matches[1] === 'normal') {
  8945. return size * 1.2;
  8946. }
  8947. value = +matches[2];
  8948. switch (matches[3]) {
  8949. case 'px':
  8950. return value;
  8951. case '%':
  8952. value /= 100;
  8953. break;
  8954. default:
  8955. break;
  8956. }
  8957. return size * value;
  8958. },
  8959. /**
  8960. * Converts the given value into a padding object with pre-computed width/height.
  8961. * @param {Number|Object} value - If a number, set the value to all TRBL component,
  8962. * else, if and object, use defined properties and sets undefined ones to 0.
  8963. * @returns {Object} The padding values (top, right, bottom, left, width, height)
  8964. * @since 2.7.0
  8965. */
  8966. toPadding: function (value) {
  8967. var t, r, b, l;
  8968. if (helpers.isObject(value)) {
  8969. t = +value.top || 0;
  8970. r = +value.right || 0;
  8971. b = +value.bottom || 0;
  8972. l = +value.left || 0;
  8973. } else {
  8974. t = r = b = l = +value || 0;
  8975. }
  8976. return {
  8977. top: t,
  8978. right: r,
  8979. bottom: b,
  8980. left: l,
  8981. height: t + b,
  8982. width: l + r
  8983. };
  8984. },
  8985. /**
  8986. * Evaluates the given `inputs` sequentially and returns the first defined value.
  8987. * @param {Array[]} inputs - An array of values, falling back to the last value.
  8988. * @param {Object} [context] - If defined and the current value is a function, the value
  8989. * is called with `context` as first argument and the result becomes the new input.
  8990. * @param {Number} [index] - If defined and the current value is an array, the value
  8991. * at `index` become the new input.
  8992. * @since 2.7.0
  8993. */
  8994. resolve: function (inputs, context, index) {
  8995. var i, ilen, value;
  8996. for (i = 0, ilen = inputs.length; i < ilen; ++i) {
  8997. value = inputs[i];
  8998. if (value === undefined) {
  8999. continue;
  9000. }
  9001. if (context !== undefined && typeof value === 'function') {
  9002. value = value(context);
  9003. }
  9004. if (index !== undefined && helpers.isArray(value)) {
  9005. value = value[index];
  9006. }
  9007. if (value !== undefined) {
  9008. return value;
  9009. }
  9010. }
  9011. }
  9012. };
  9013. }, {"42": 42}], 45: [function (require, module, exports) {
  9014. 'use strict';
  9015. module.exports = require(42);
  9016. module.exports.easing = require(43);
  9017. module.exports.canvas = require(41);
  9018. module.exports.options = require(44);
  9019. }, {"41": 41, "42": 42, "43": 43, "44": 44}], 46: [function (require, module, exports) {
  9020. /**
  9021. * Platform fallback implementation (minimal).
  9022. * @see https://github.com/chartjs/Chart.js/pull/4591#issuecomment-319575939
  9023. */
  9024. module.exports = {
  9025. acquireContext: function (item) {
  9026. if (item && item.canvas) {
  9027. // Support for any object associated to a canvas (including a context2d)
  9028. item = item.canvas;
  9029. }
  9030. return item && item.getContext('2d') || null;
  9031. }
  9032. };
  9033. }, {}], 47: [function (require, module, exports) {
  9034. /**
  9035. * Chart.Platform implementation for targeting a web browser
  9036. */
  9037. 'use strict';
  9038. var helpers = require(45);
  9039. var EXPANDO_KEY = '$chartjs';
  9040. var CSS_PREFIX = 'chartjs-';
  9041. var CSS_RENDER_MONITOR = CSS_PREFIX + 'render-monitor';
  9042. var CSS_RENDER_ANIMATION = CSS_PREFIX + 'render-animation';
  9043. var ANIMATION_START_EVENTS = ['animationstart', 'webkitAnimationStart'];
  9044. /**
  9045. * DOM event types -> Chart.js event types.
  9046. * Note: only events with different types are mapped.
  9047. * @see https://developer.mozilla.org/en-US/docs/Web/Events
  9048. */
  9049. var EVENT_TYPES = {
  9050. touchstart: 'mousedown',
  9051. touchmove: 'mousemove',
  9052. touchend: 'mouseup',
  9053. pointerenter: 'mouseenter',
  9054. pointerdown: 'mousedown',
  9055. pointermove: 'mousemove',
  9056. pointerup: 'mouseup',
  9057. pointerleave: 'mouseout',
  9058. pointerout: 'mouseout'
  9059. };
  9060. /**
  9061. * The "used" size is the final value of a dimension property after all calculations have
  9062. * been performed. This method uses the computed style of `element` but returns undefined
  9063. * if the computed style is not expressed in pixels. That can happen in some cases where
  9064. * `element` has a size relative to its parent and this last one is not yet displayed,
  9065. * for example because of `display: none` on a parent node.
  9066. * @see https://developer.mozilla.org/en-US/docs/Web/CSS/used_value
  9067. * @returns {Number} Size in pixels or undefined if unknown.
  9068. */
  9069. function readUsedSize(element, property) {
  9070. var value = helpers.getStyle(element, property);
  9071. var matches = value && value.match(/^(\d+)(\.\d+)?px$/);
  9072. return matches ? Number(matches[1]) : undefined;
  9073. }
  9074. /**
  9075. * Initializes the canvas style and render size without modifying the canvas display size,
  9076. * since responsiveness is handled by the controller.resize() method. The config is used
  9077. * to determine the aspect ratio to apply in case no explicit height has been specified.
  9078. */
  9079. function initCanvas(canvas, config) {
  9080. var style = canvas.style;
  9081. // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it
  9082. // returns null or '' if no explicit value has been set to the canvas attribute.
  9083. var renderHeight = canvas.getAttribute('height');
  9084. var renderWidth = canvas.getAttribute('width');
  9085. // Chart.js modifies some canvas values that we want to restore on destroy
  9086. canvas[EXPANDO_KEY] = {
  9087. initial: {
  9088. height: renderHeight,
  9089. width: renderWidth,
  9090. style: {
  9091. display: style.display,
  9092. height: style.height,
  9093. width: style.width
  9094. }
  9095. }
  9096. };
  9097. // Force canvas to display as block to avoid extra space caused by inline
  9098. // elements, which would interfere with the responsive resize process.
  9099. // https://github.com/chartjs/Chart.js/issues/2538
  9100. style.display = style.display || 'block';
  9101. if (renderWidth === null || renderWidth === '') {
  9102. var displayWidth = readUsedSize(canvas, 'width');
  9103. if (displayWidth !== undefined) {
  9104. canvas.width = displayWidth;
  9105. }
  9106. }
  9107. if (renderHeight === null || renderHeight === '') {
  9108. if (canvas.style.height === '') {
  9109. // If no explicit render height and style height, let's apply the aspect ratio,
  9110. // which one can be specified by the user but also by charts as default option
  9111. // (i.e. options.aspectRatio). If not specified, use canvas aspect ratio of 2.
  9112. canvas.height = canvas.width / (config.options.aspectRatio || 2);
  9113. } else {
  9114. var displayHeight = readUsedSize(canvas, 'height');
  9115. if (displayWidth !== undefined) {
  9116. canvas.height = displayHeight;
  9117. }
  9118. }
  9119. }
  9120. return canvas;
  9121. }
  9122. /**
  9123. * Detects support for options object argument in addEventListener.
  9124. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  9125. * @private
  9126. */
  9127. var supportsEventListenerOptions = (function () {
  9128. var supports = false;
  9129. try {
  9130. var options = Object.defineProperty({}, 'passive', {
  9131. get: function () {
  9132. supports = true;
  9133. }
  9134. });
  9135. window.addEventListener('e', null, options);
  9136. } catch (e) {
  9137. // continue regardless of error
  9138. }
  9139. return supports;
  9140. }());
  9141. // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
  9142. // https://github.com/chartjs/Chart.js/issues/4287
  9143. var eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;
  9144. function addEventListener(node, type, listener) {
  9145. node.addEventListener(type, listener, eventListenerOptions);
  9146. }
  9147. function removeEventListener(node, type, listener) {
  9148. node.removeEventListener(type, listener, eventListenerOptions);
  9149. }
  9150. function createEvent(type, chart, x, y, nativeEvent) {
  9151. return {
  9152. type: type,
  9153. chart: chart,
  9154. native: nativeEvent || null,
  9155. x: x !== undefined ? x : null,
  9156. y: y !== undefined ? y : null,
  9157. };
  9158. }
  9159. function fromNativeEvent(event, chart) {
  9160. var type = EVENT_TYPES[event.type] || event.type;
  9161. var pos = helpers.getRelativePosition(event, chart);
  9162. return createEvent(type, chart, pos.x, pos.y, event);
  9163. }
  9164. function throttled(fn, thisArg) {
  9165. var ticking = false;
  9166. var args = [];
  9167. return function () {
  9168. args = Array.prototype.slice.call(arguments);
  9169. thisArg = thisArg || this;
  9170. if (!ticking) {
  9171. ticking = true;
  9172. helpers.requestAnimFrame.call(window, function () {
  9173. ticking = false;
  9174. fn.apply(thisArg, args);
  9175. });
  9176. }
  9177. };
  9178. }
  9179. // Implementation based on https://github.com/marcj/css-element-queries
  9180. function createResizer(handler) {
  9181. var resizer = document.createElement('div');
  9182. var cls = CSS_PREFIX + 'size-monitor';
  9183. var maxSize = 1000000;
  9184. var style =
  9185. 'position:absolute;' +
  9186. 'left:0;' +
  9187. 'top:0;' +
  9188. 'right:0;' +
  9189. 'bottom:0;' +
  9190. 'overflow:hidden;' +
  9191. 'pointer-events:none;' +
  9192. 'visibility:hidden;' +
  9193. 'z-index:-1;';
  9194. resizer.style.cssText = style;
  9195. resizer.className = cls;
  9196. resizer.innerHTML =
  9197. '<div class="' + cls + '-expand" style="' + style + '">' +
  9198. '<div style="' +
  9199. 'position:absolute;' +
  9200. 'width:' + maxSize + 'px;' +
  9201. 'height:' + maxSize + 'px;' +
  9202. 'left:0;' +
  9203. 'top:0">' +
  9204. '</div>' +
  9205. '</div>' +
  9206. '<div class="' + cls + '-shrink" style="' + style + '">' +
  9207. '<div style="' +
  9208. 'position:absolute;' +
  9209. 'width:200%;' +
  9210. 'height:200%;' +
  9211. 'left:0; ' +
  9212. 'top:0">' +
  9213. '</div>' +
  9214. '</div>';
  9215. var expand = resizer.childNodes[0];
  9216. var shrink = resizer.childNodes[1];
  9217. resizer._reset = function () {
  9218. expand.scrollLeft = maxSize;
  9219. expand.scrollTop = maxSize;
  9220. shrink.scrollLeft = maxSize;
  9221. shrink.scrollTop = maxSize;
  9222. };
  9223. var onScroll = function () {
  9224. resizer._reset();
  9225. handler();
  9226. };
  9227. addEventListener(expand, 'scroll', onScroll.bind(expand, 'expand'));
  9228. addEventListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink'));
  9229. return resizer;
  9230. }
  9231. // https://davidwalsh.name/detect-node-insertion
  9232. function watchForRender(node, handler) {
  9233. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  9234. var proxy = expando.renderProxy = function (e) {
  9235. if (e.animationName === CSS_RENDER_ANIMATION) {
  9236. handler();
  9237. }
  9238. };
  9239. helpers.each(ANIMATION_START_EVENTS, function (type) {
  9240. addEventListener(node, type, proxy);
  9241. });
  9242. // #4737: Chrome might skip the CSS animation when the CSS_RENDER_MONITOR class
  9243. // is removed then added back immediately (same animation frame?). Accessing the
  9244. // `offsetParent` property will force a reflow and re-evaluate the CSS animation.
  9245. // https://gist.github.com/paulirish/5d52fb081b3570c81e3a#box-metrics
  9246. // https://github.com/chartjs/Chart.js/issues/4737
  9247. expando.reflow = !!node.offsetParent;
  9248. node.classList.add(CSS_RENDER_MONITOR);
  9249. }
  9250. function unwatchForRender(node) {
  9251. var expando = node[EXPANDO_KEY] || {};
  9252. var proxy = expando.renderProxy;
  9253. if (proxy) {
  9254. helpers.each(ANIMATION_START_EVENTS, function (type) {
  9255. removeEventListener(node, type, proxy);
  9256. });
  9257. delete expando.renderProxy;
  9258. }
  9259. node.classList.remove(CSS_RENDER_MONITOR);
  9260. }
  9261. function addResizeListener(node, listener, chart) {
  9262. var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
  9263. // Let's keep track of this added resizer and thus avoid DOM query when removing it.
  9264. var resizer = expando.resizer = createResizer(throttled(function () {
  9265. if (expando.resizer) {
  9266. return listener(createEvent('resize', chart));
  9267. }
  9268. }));
  9269. // The resizer needs to be attached to the node parent, so we first need to be
  9270. // sure that `node` is attached to the DOM before injecting the resizer element.
  9271. watchForRender(node, function () {
  9272. if (expando.resizer) {
  9273. var container = node.parentNode;
  9274. if (container && container !== resizer.parentNode) {
  9275. container.insertBefore(resizer, container.firstChild);
  9276. }
  9277. // The container size might have changed, let's reset the resizer state.
  9278. resizer._reset();
  9279. }
  9280. });
  9281. }
  9282. function removeResizeListener(node) {
  9283. var expando = node[EXPANDO_KEY] || {};
  9284. var resizer = expando.resizer;
  9285. delete expando.resizer;
  9286. unwatchForRender(node);
  9287. if (resizer && resizer.parentNode) {
  9288. resizer.parentNode.removeChild(resizer);
  9289. }
  9290. }
  9291. function injectCSS(platform, css) {
  9292. // http://stackoverflow.com/q/3922139
  9293. var style = platform._style || document.createElement('style');
  9294. if (!platform._style) {
  9295. platform._style = style;
  9296. css = '/* Chart.js */\n' + css;
  9297. style.setAttribute('type', 'text/css');
  9298. document.getElementsByTagName('head')[0].appendChild(style);
  9299. }
  9300. style.appendChild(document.createTextNode(css));
  9301. }
  9302. module.exports = {
  9303. /**
  9304. * This property holds whether this platform is enabled for the current environment.
  9305. * Currently used by platform.js to select the proper implementation.
  9306. * @private
  9307. */
  9308. _enabled: typeof window !== 'undefined' && typeof document !== 'undefined',
  9309. initialize: function () {
  9310. var keyframes = 'from{opacity:0.99}to{opacity:1}';
  9311. injectCSS(this,
  9312. // DOM rendering detection
  9313. // https://davidwalsh.name/detect-node-insertion
  9314. '@-webkit-keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  9315. '@keyframes ' + CSS_RENDER_ANIMATION + '{' + keyframes + '}' +
  9316. '.' + CSS_RENDER_MONITOR + '{' +
  9317. '-webkit-animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  9318. 'animation:' + CSS_RENDER_ANIMATION + ' 0.001s;' +
  9319. '}'
  9320. );
  9321. },
  9322. acquireContext: function (item, config) {
  9323. if (typeof item === 'string') {
  9324. item = document.getElementById(item);
  9325. } else if (item.length) {
  9326. // Support for array based queries (such as jQuery)
  9327. item = item[0];
  9328. }
  9329. if (item && item.canvas) {
  9330. // Support for any object associated to a canvas (including a context2d)
  9331. item = item.canvas;
  9332. }
  9333. // To prevent canvas fingerprinting, some add-ons undefine the getContext
  9334. // method, for example: https://github.com/kkapsner/CanvasBlocker
  9335. // https://github.com/chartjs/Chart.js/issues/2807
  9336. var context = item && item.getContext && item.getContext('2d');
  9337. // `instanceof HTMLCanvasElement/CanvasRenderingContext2D` fails when the item is
  9338. // inside an iframe or when running in a protected environment. We could guess the
  9339. // types from their toString() value but let's keep things flexible and assume it's
  9340. // a sufficient condition if the item has a context2D which has item as `canvas`.
  9341. // https://github.com/chartjs/Chart.js/issues/3887
  9342. // https://github.com/chartjs/Chart.js/issues/4102
  9343. // https://github.com/chartjs/Chart.js/issues/4152
  9344. if (context && context.canvas === item) {
  9345. initCanvas(item, config);
  9346. return context;
  9347. }
  9348. return null;
  9349. },
  9350. releaseContext: function (context) {
  9351. var canvas = context.canvas;
  9352. if (!canvas[EXPANDO_KEY]) {
  9353. return;
  9354. }
  9355. var initial = canvas[EXPANDO_KEY].initial;
  9356. ['height', 'width'].forEach(function (prop) {
  9357. var value = initial[prop];
  9358. if (helpers.isNullOrUndef(value)) {
  9359. canvas.removeAttribute(prop);
  9360. } else {
  9361. canvas.setAttribute(prop, value);
  9362. }
  9363. });
  9364. helpers.each(initial.style || {}, function (value, key) {
  9365. canvas.style[key] = value;
  9366. });
  9367. // The canvas render size might have been changed (and thus the state stack discarded),
  9368. // we can't use save() and restore() to restore the initial state. So make sure that at
  9369. // least the canvas context is reset to the default state by setting the canvas width.
  9370. // https://www.w3.org/TR/2011/WD-html5-20110525/the-canvas-element.html
  9371. canvas.width = canvas.width;
  9372. delete canvas[EXPANDO_KEY];
  9373. },
  9374. addEventListener: function (chart, type, listener) {
  9375. var canvas = chart.canvas;
  9376. if (type === 'resize') {
  9377. // Note: the resize event is not supported on all browsers.
  9378. addResizeListener(canvas, listener, chart);
  9379. return;
  9380. }
  9381. var expando = listener[EXPANDO_KEY] || (listener[EXPANDO_KEY] = {});
  9382. var proxies = expando.proxies || (expando.proxies = {});
  9383. var proxy = proxies[chart.id + '_' + type] = function (event) {
  9384. listener(fromNativeEvent(event, chart));
  9385. };
  9386. addEventListener(canvas, type, proxy);
  9387. },
  9388. removeEventListener: function (chart, type, listener) {
  9389. var canvas = chart.canvas;
  9390. if (type === 'resize') {
  9391. // Note: the resize event is not supported on all browsers.
  9392. removeResizeListener(canvas, listener);
  9393. return;
  9394. }
  9395. var expando = listener[EXPANDO_KEY] || {};
  9396. var proxies = expando.proxies || {};
  9397. var proxy = proxies[chart.id + '_' + type];
  9398. if (!proxy) {
  9399. return;
  9400. }
  9401. removeEventListener(canvas, type, proxy);
  9402. }
  9403. };
  9404. // DEPRECATIONS
  9405. /**
  9406. * Provided for backward compatibility, use EventTarget.addEventListener instead.
  9407. * EventTarget.addEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  9408. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
  9409. * @function Chart.helpers.addEvent
  9410. * @deprecated since version 2.7.0
  9411. * @todo remove at version 3
  9412. * @private
  9413. */
  9414. helpers.addEvent = addEventListener;
  9415. /**
  9416. * Provided for backward compatibility, use EventTarget.removeEventListener instead.
  9417. * EventTarget.removeEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
  9418. * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
  9419. * @function Chart.helpers.removeEvent
  9420. * @deprecated since version 2.7.0
  9421. * @todo remove at version 3
  9422. * @private
  9423. */
  9424. helpers.removeEvent = removeEventListener;
  9425. }, {"45": 45}], 48: [function (require, module, exports) {
  9426. 'use strict';
  9427. var helpers = require(45);
  9428. var basic = require(46);
  9429. var dom = require(47);
  9430. // @TODO Make possible to select another platform at build time.
  9431. var implementation = dom._enabled ? dom : basic;
  9432. /**
  9433. * @namespace Chart.platform
  9434. * @see https://chartjs.gitbooks.io/proposals/content/Platform.html
  9435. * @since 2.4.0
  9436. */
  9437. module.exports = helpers.extend({
  9438. /**
  9439. * @since 2.7.0
  9440. */
  9441. initialize: function () {},
  9442. /**
  9443. * Called at chart construction time, returns a context2d instance implementing
  9444. * the [W3C Canvas 2D Context API standard]{@link https://www.w3.org/TR/2dcontext/}.
  9445. * @param {*} item - The native item from which to acquire context (platform specific)
  9446. * @param {Object} options - The chart options
  9447. * @returns {CanvasRenderingContext2D} context2d instance
  9448. */
  9449. acquireContext: function () {},
  9450. /**
  9451. * Called at chart destruction time, releases any resources associated to the context
  9452. * previously returned by the acquireContext() method.
  9453. * @param {CanvasRenderingContext2D} context - The context2d instance
  9454. * @returns {Boolean} true if the method succeeded, else false
  9455. */
  9456. releaseContext: function () {},
  9457. /**
  9458. * Registers the specified listener on the given chart.
  9459. * @param {Chart} chart - Chart from which to listen for event
  9460. * @param {String} type - The ({@link IEvent}) type to listen for
  9461. * @param {Function} listener - Receives a notification (an object that implements
  9462. * the {@link IEvent} interface) when an event of the specified type occurs.
  9463. */
  9464. addEventListener: function () {},
  9465. /**
  9466. * Removes the specified listener previously registered with addEventListener.
  9467. * @param {Chart} chart -Chart from which to remove the listener
  9468. * @param {String} type - The ({@link IEvent}) type to remove
  9469. * @param {Function} listener - The listener function to remove from the event target.
  9470. */
  9471. removeEventListener: function () {}
  9472. }, implementation);
  9473. /**
  9474. * @interface IPlatform
  9475. * Allows abstracting platform dependencies away from the chart
  9476. * @borrows Chart.platform.acquireContext as acquireContext
  9477. * @borrows Chart.platform.releaseContext as releaseContext
  9478. * @borrows Chart.platform.addEventListener as addEventListener
  9479. * @borrows Chart.platform.removeEventListener as removeEventListener
  9480. */
  9481. /**
  9482. * @interface IEvent
  9483. * @prop {String} type - The event type name, possible values are:
  9484. * 'contextmenu', 'mouseenter', 'mousedown', 'mousemove', 'mouseup', 'mouseout',
  9485. * 'click', 'dblclick', 'keydown', 'keypress', 'keyup' and 'resize'
  9486. * @prop {*} native - The original native event (null for emulated events, e.g. 'resize')
  9487. * @prop {Number} x - The mouse x position, relative to the canvas (null for incompatible events)
  9488. * @prop {Number} y - The mouse y position, relative to the canvas (null for incompatible events)
  9489. */
  9490. }, {"45": 45, "46": 46, "47": 47}], 49: [function (require, module, exports) {
  9491. 'use strict';
  9492. module.exports = {};
  9493. module.exports.filler = require(50);
  9494. module.exports.legend = require(51);
  9495. module.exports.title = require(52);
  9496. }, {"50": 50, "51": 51, "52": 52}], 50: [function (require, module, exports) {
  9497. /**
  9498. * Plugin based on discussion from the following Chart.js issues:
  9499. * @see https://github.com/chartjs/Chart.js/issues/2380#issuecomment-279961569
  9500. * @see https://github.com/chartjs/Chart.js/issues/2440#issuecomment-256461897
  9501. */
  9502. 'use strict';
  9503. var defaults = require(25);
  9504. var elements = require(40);
  9505. var helpers = require(45);
  9506. defaults._set('global', {
  9507. plugins: {
  9508. filler: {
  9509. propagate: true
  9510. }
  9511. }
  9512. });
  9513. var mappers = {
  9514. dataset: function (source) {
  9515. var index = source.fill;
  9516. var chart = source.chart;
  9517. var meta = chart.getDatasetMeta(index);
  9518. var visible = meta && chart.isDatasetVisible(index);
  9519. var points = (visible && meta.dataset._children) || [];
  9520. var length = points.length || 0;
  9521. return !length ? null : function (point, i) {
  9522. return (i < length && points[i]._view) || null;
  9523. };
  9524. },
  9525. boundary: function (source) {
  9526. var boundary = source.boundary;
  9527. var x = boundary ? boundary.x : null;
  9528. var y = boundary ? boundary.y : null;
  9529. return function (point) {
  9530. return {
  9531. x: x === null ? point.x : x,
  9532. y: y === null ? point.y : y,
  9533. };
  9534. };
  9535. }
  9536. };
  9537. // @todo if (fill[0] === '#')
  9538. function decodeFill(el, index, count) {
  9539. var model = el._model || {};
  9540. var fill = model.fill;
  9541. var target;
  9542. if (fill === undefined) {
  9543. fill = !!model.backgroundColor;
  9544. }
  9545. if (fill === false || fill === null) {
  9546. return false;
  9547. }
  9548. if (fill === true) {
  9549. return 'origin';
  9550. }
  9551. target = parseFloat(fill, 10);
  9552. if (isFinite(target) && Math.floor(target) === target) {
  9553. if (fill[0] === '-' || fill[0] === '+') {
  9554. target = index + target;
  9555. }
  9556. if (target === index || target < 0 || target >= count) {
  9557. return false;
  9558. }
  9559. return target;
  9560. }
  9561. switch (fill) {
  9562. // compatibility
  9563. case 'bottom':
  9564. return 'start';
  9565. case 'top':
  9566. return 'end';
  9567. case 'zero':
  9568. return 'origin';
  9569. // supported boundaries
  9570. case 'origin':
  9571. case 'start':
  9572. case 'end':
  9573. return fill;
  9574. // invalid fill values
  9575. default:
  9576. return false;
  9577. }
  9578. }
  9579. function computeBoundary(source) {
  9580. var model = source.el._model || {};
  9581. var scale = source.el._scale || {};
  9582. var fill = source.fill;
  9583. var target = null;
  9584. var horizontal;
  9585. if (isFinite(fill)) {
  9586. return null;
  9587. }
  9588. // Backward compatibility: until v3, we still need to support boundary values set on
  9589. // the model (scaleTop, scaleBottom and scaleZero) because some external plugins and
  9590. // controllers might still use it (e.g. the Smith chart).
  9591. if (fill === 'start') {
  9592. target = model.scaleBottom === undefined ? scale.bottom : model.scaleBottom;
  9593. } else if (fill === 'end') {
  9594. target = model.scaleTop === undefined ? scale.top : model.scaleTop;
  9595. } else if (model.scaleZero !== undefined) {
  9596. target = model.scaleZero;
  9597. } else if (scale.getBasePosition) {
  9598. target = scale.getBasePosition();
  9599. } else if (scale.getBasePixel) {
  9600. target = scale.getBasePixel();
  9601. }
  9602. if (target !== undefined && target !== null) {
  9603. if (target.x !== undefined && target.y !== undefined) {
  9604. return target;
  9605. }
  9606. if (typeof target === 'number' && isFinite(target)) {
  9607. horizontal = scale.isHorizontal();
  9608. return {
  9609. x: horizontal ? target : null,
  9610. y: horizontal ? null : target
  9611. };
  9612. }
  9613. }
  9614. return null;
  9615. }
  9616. function resolveTarget(sources, index, propagate) {
  9617. var source = sources[index];
  9618. var fill = source.fill;
  9619. var visited = [index];
  9620. var target;
  9621. if (!propagate) {
  9622. return fill;
  9623. }
  9624. while (fill !== false && visited.indexOf(fill) === -1) {
  9625. if (!isFinite(fill)) {
  9626. return fill;
  9627. }
  9628. target = sources[fill];
  9629. if (!target) {
  9630. return false;
  9631. }
  9632. if (target.visible) {
  9633. return fill;
  9634. }
  9635. visited.push(fill);
  9636. fill = target.fill;
  9637. }
  9638. return false;
  9639. }
  9640. function createMapper(source) {
  9641. var fill = source.fill;
  9642. var type = 'dataset';
  9643. if (fill === false) {
  9644. return null;
  9645. }
  9646. if (!isFinite(fill)) {
  9647. type = 'boundary';
  9648. }
  9649. return mappers[type](source);
  9650. }
  9651. function isDrawable(point) {
  9652. return point && !point.skip;
  9653. }
  9654. function drawArea(ctx, curve0, curve1, len0, len1) {
  9655. var i;
  9656. if (!len0 || !len1) {
  9657. return;
  9658. }
  9659. // building first area curve (normal)
  9660. ctx.moveTo(curve0[0].x, curve0[0].y);
  9661. for (i = 1; i < len0; ++i) {
  9662. helpers.canvas.lineTo(ctx, curve0[i - 1], curve0[i]);
  9663. }
  9664. // joining the two area curves
  9665. ctx.lineTo(curve1[len1 - 1].x, curve1[len1 - 1].y);
  9666. // building opposite area curve (reverse)
  9667. for (i = len1 - 1; i > 0; --i) {
  9668. helpers.canvas.lineTo(ctx, curve1[i], curve1[i - 1], true);
  9669. }
  9670. }
  9671. function doFill(ctx, points, mapper, view, color, loop) {
  9672. var count = points.length;
  9673. var span = view.spanGaps;
  9674. var curve0 = [];
  9675. var curve1 = [];
  9676. var len0 = 0;
  9677. var len1 = 0;
  9678. var i, ilen, index, p0, p1, d0, d1;
  9679. ctx.beginPath();
  9680. for (i = 0, ilen = (count + !!loop); i < ilen; ++i) {
  9681. index = i % count;
  9682. p0 = points[index]._view;
  9683. p1 = mapper(p0, index, view);
  9684. d0 = isDrawable(p0);
  9685. d1 = isDrawable(p1);
  9686. if (d0 && d1) {
  9687. len0 = curve0.push(p0);
  9688. len1 = curve1.push(p1);
  9689. } else if (len0 && len1) {
  9690. if (!span) {
  9691. drawArea(ctx, curve0, curve1, len0, len1);
  9692. len0 = len1 = 0;
  9693. curve0 = [];
  9694. curve1 = [];
  9695. } else {
  9696. if (d0) {
  9697. curve0.push(p0);
  9698. }
  9699. if (d1) {
  9700. curve1.push(p1);
  9701. }
  9702. }
  9703. }
  9704. }
  9705. drawArea(ctx, curve0, curve1, len0, len1);
  9706. ctx.closePath();
  9707. ctx.fillStyle = color;
  9708. ctx.fill();
  9709. }
  9710. module.exports = {
  9711. id: 'filler',
  9712. afterDatasetsUpdate: function (chart, options) {
  9713. var count = (chart.data.datasets || []).length;
  9714. var propagate = options.propagate;
  9715. var sources = [];
  9716. var meta, i, el, source;
  9717. for (i = 0; i < count; ++i) {
  9718. meta = chart.getDatasetMeta(i);
  9719. el = meta.dataset;
  9720. source = null;
  9721. if (el && el._model && el instanceof elements.Line) {
  9722. source = {
  9723. visible: chart.isDatasetVisible(i),
  9724. fill: decodeFill(el, i, count),
  9725. chart: chart,
  9726. el: el
  9727. };
  9728. }
  9729. meta.$filler = source;
  9730. sources.push(source);
  9731. }
  9732. for (i = 0; i < count; ++i) {
  9733. source = sources[i];
  9734. if (!source) {
  9735. continue;
  9736. }
  9737. source.fill = resolveTarget(sources, i, propagate);
  9738. source.boundary = computeBoundary(source);
  9739. source.mapper = createMapper(source);
  9740. }
  9741. },
  9742. beforeDatasetDraw: function (chart, args) {
  9743. var meta = args.meta.$filler;
  9744. if (!meta) {
  9745. return;
  9746. }
  9747. var ctx = chart.ctx;
  9748. var el = meta.el;
  9749. var view = el._view;
  9750. var points = el._children || [];
  9751. var mapper = meta.mapper;
  9752. var color = view.backgroundColor || defaults.global.defaultColor;
  9753. if (mapper && color && points.length) {
  9754. helpers.canvas.clipArea(ctx, chart.chartArea);
  9755. doFill(ctx, points, mapper, view, color, el._loop);
  9756. helpers.canvas.unclipArea(ctx);
  9757. }
  9758. }
  9759. };
  9760. }, {"25": 25, "40": 40, "45": 45}], 51: [function (require, module, exports) {
  9761. 'use strict';
  9762. var defaults = require(25);
  9763. var Element = require(26);
  9764. var helpers = require(45);
  9765. var layouts = require(30);
  9766. var noop = helpers.noop;
  9767. defaults._set('global', {
  9768. legend: {
  9769. display: true,
  9770. position: 'top',
  9771. fullWidth: true,
  9772. reverse: false,
  9773. weight: 1000,
  9774. // a callback that will handle
  9775. onClick: function (e, legendItem) {
  9776. var index = legendItem.datasetIndex;
  9777. var ci = this.chart;
  9778. var meta = ci.getDatasetMeta(index);
  9779. // See controller.isDatasetVisible comment
  9780. meta.hidden = meta.hidden === null ? !ci.data.datasets[index].hidden : null;
  9781. // We hid a dataset ... rerender the chart
  9782. ci.update();
  9783. },
  9784. onHover: null,
  9785. labels: {
  9786. boxWidth: 40,
  9787. padding: 10,
  9788. // Generates labels shown in the legend
  9789. // Valid properties to return:
  9790. // text : text to display
  9791. // fillStyle : fill of coloured box
  9792. // strokeStyle: stroke of coloured box
  9793. // hidden : if this legend item refers to a hidden item
  9794. // lineCap : cap style for line
  9795. // lineDash
  9796. // lineDashOffset :
  9797. // lineJoin :
  9798. // lineWidth :
  9799. generateLabels: function (chart) {
  9800. var data = chart.data;
  9801. return helpers.isArray(data.datasets) ? data.datasets.map(function (dataset, i) {
  9802. return {
  9803. text: dataset.label,
  9804. fillStyle: (!helpers.isArray(dataset.backgroundColor) ? dataset.backgroundColor : dataset.backgroundColor[0]),
  9805. hidden: !chart.isDatasetVisible(i),
  9806. lineCap: dataset.borderCapStyle,
  9807. lineDash: dataset.borderDash,
  9808. lineDashOffset: dataset.borderDashOffset,
  9809. lineJoin: dataset.borderJoinStyle,
  9810. lineWidth: dataset.borderWidth,
  9811. strokeStyle: dataset.borderColor,
  9812. pointStyle: dataset.pointStyle,
  9813. // Below is extra data used for toggling the datasets
  9814. datasetIndex: i
  9815. };
  9816. }, this) : [];
  9817. }
  9818. }
  9819. },
  9820. legendCallback: function (chart) {
  9821. var text = [];
  9822. text.push('<ul class="' + chart.id + '-legend">');
  9823. for (var i = 0; i < chart.data.datasets.length; i++) {
  9824. text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '"></span>');
  9825. if (chart.data.datasets[i].label) {
  9826. text.push(chart.data.datasets[i].label);
  9827. }
  9828. text.push('</li>');
  9829. }
  9830. text.push('</ul>');
  9831. return text.join('');
  9832. }
  9833. });
  9834. /**
  9835. * Helper function to get the box width based on the usePointStyle option
  9836. * @param labelopts {Object} the label options on the legend
  9837. * @param fontSize {Number} the label font size
  9838. * @return {Number} width of the color box area
  9839. */
  9840. function getBoxWidth(labelOpts, fontSize) {
  9841. return labelOpts.usePointStyle ?
  9842. fontSize * Math.SQRT2 :
  9843. labelOpts.boxWidth;
  9844. }
  9845. /**
  9846. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  9847. */
  9848. var Legend = Element.extend({
  9849. initialize: function (config) {
  9850. helpers.extend(this, config);
  9851. // Contains hit boxes for each dataset (in dataset order)
  9852. this.legendHitBoxes = [];
  9853. // Are we in doughnut mode which has a different data type
  9854. this.doughnutMode = false;
  9855. },
  9856. // These methods are ordered by lifecycle. Utilities then follow.
  9857. // Any function defined here is inherited by all legend types.
  9858. // Any function can be extended by the legend type
  9859. beforeUpdate: noop,
  9860. update: function (maxWidth, maxHeight, margins) {
  9861. var me = this;
  9862. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  9863. me.beforeUpdate();
  9864. // Absorb the master measurements
  9865. me.maxWidth = maxWidth;
  9866. me.maxHeight = maxHeight;
  9867. me.margins = margins;
  9868. // Dimensions
  9869. me.beforeSetDimensions();
  9870. me.setDimensions();
  9871. me.afterSetDimensions();
  9872. // Labels
  9873. me.beforeBuildLabels();
  9874. me.buildLabels();
  9875. me.afterBuildLabels();
  9876. // Fit
  9877. me.beforeFit();
  9878. me.fit();
  9879. me.afterFit();
  9880. //
  9881. me.afterUpdate();
  9882. return me.minSize;
  9883. },
  9884. afterUpdate: noop,
  9885. //
  9886. beforeSetDimensions: noop,
  9887. setDimensions: function () {
  9888. var me = this;
  9889. // Set the unconstrained dimension before label rotation
  9890. if (me.isHorizontal()) {
  9891. // Reset position before calculating rotation
  9892. me.width = me.maxWidth;
  9893. me.left = 0;
  9894. me.right = me.width;
  9895. } else {
  9896. me.height = me.maxHeight;
  9897. // Reset position before calculating rotation
  9898. me.top = 0;
  9899. me.bottom = me.height;
  9900. }
  9901. // Reset padding
  9902. me.paddingLeft = 0;
  9903. me.paddingTop = 0;
  9904. me.paddingRight = 0;
  9905. me.paddingBottom = 0;
  9906. // Reset minSize
  9907. me.minSize = {
  9908. width: 0,
  9909. height: 0
  9910. };
  9911. },
  9912. afterSetDimensions: noop,
  9913. //
  9914. beforeBuildLabels: noop,
  9915. buildLabels: function () {
  9916. var me = this;
  9917. var labelOpts = me.options.labels || {};
  9918. var legendItems = helpers.callback(labelOpts.generateLabels, [me.chart], me) || [];
  9919. if (labelOpts.filter) {
  9920. legendItems = legendItems.filter(function (item) {
  9921. return labelOpts.filter(item, me.chart.data);
  9922. });
  9923. }
  9924. if (me.options.reverse) {
  9925. legendItems.reverse();
  9926. }
  9927. me.legendItems = legendItems;
  9928. },
  9929. afterBuildLabels: noop,
  9930. //
  9931. beforeFit: noop,
  9932. fit: function () {
  9933. var me = this;
  9934. var opts = me.options;
  9935. var labelOpts = opts.labels;
  9936. var display = opts.display;
  9937. var ctx = me.ctx;
  9938. var globalDefault = defaults.global;
  9939. var valueOrDefault = helpers.valueOrDefault;
  9940. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  9941. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  9942. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  9943. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  9944. // Reset hit boxes
  9945. var hitboxes = me.legendHitBoxes = [];
  9946. var minSize = me.minSize;
  9947. var isHorizontal = me.isHorizontal();
  9948. if (isHorizontal) {
  9949. minSize.width = me.maxWidth; // fill all the width
  9950. minSize.height = display ? 10 : 0;
  9951. } else {
  9952. minSize.width = display ? 10 : 0;
  9953. minSize.height = me.maxHeight; // fill all the height
  9954. }
  9955. // Increase sizes here
  9956. if (display) {
  9957. ctx.font = labelFont;
  9958. if (isHorizontal) {
  9959. // Labels
  9960. // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
  9961. var lineWidths = me.lineWidths = [0];
  9962. var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0;
  9963. ctx.textAlign = 'left';
  9964. ctx.textBaseline = 'top';
  9965. helpers.each(me.legendItems, function (legendItem, i) {
  9966. var boxWidth = getBoxWidth(labelOpts, fontSize);
  9967. var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  9968. if (lineWidths[lineWidths.length - 1] + width + labelOpts.padding >= me.width) {
  9969. totalHeight += fontSize + (labelOpts.padding);
  9970. lineWidths[lineWidths.length] = me.left;
  9971. }
  9972. // Store the hitbox width and height here. Final position will be updated in `draw`
  9973. hitboxes[i] = {
  9974. left: 0,
  9975. top: 0,
  9976. width: width,
  9977. height: fontSize
  9978. };
  9979. lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
  9980. });
  9981. minSize.height += totalHeight;
  9982. } else {
  9983. var vPadding = labelOpts.padding;
  9984. var columnWidths = me.columnWidths = [];
  9985. var totalWidth = labelOpts.padding;
  9986. var currentColWidth = 0;
  9987. var currentColHeight = 0;
  9988. var itemHeight = fontSize + vPadding;
  9989. helpers.each(me.legendItems, function (legendItem, i) {
  9990. var boxWidth = getBoxWidth(labelOpts, fontSize);
  9991. var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
  9992. // If too tall, go to new column
  9993. if (currentColHeight + itemHeight > minSize.height) {
  9994. totalWidth += currentColWidth + labelOpts.padding;
  9995. columnWidths.push(currentColWidth); // previous column width
  9996. currentColWidth = 0;
  9997. currentColHeight = 0;
  9998. }
  9999. // Get max width
  10000. currentColWidth = Math.max(currentColWidth, itemWidth);
  10001. currentColHeight += itemHeight;
  10002. // Store the hitbox width and height here. Final position will be updated in `draw`
  10003. hitboxes[i] = {
  10004. left: 0,
  10005. top: 0,
  10006. width: itemWidth,
  10007. height: fontSize
  10008. };
  10009. });
  10010. totalWidth += currentColWidth;
  10011. columnWidths.push(currentColWidth);
  10012. minSize.width += totalWidth;
  10013. }
  10014. }
  10015. me.width = minSize.width;
  10016. me.height = minSize.height;
  10017. },
  10018. afterFit: noop,
  10019. // Shared Methods
  10020. isHorizontal: function () {
  10021. return this.options.position === 'top' || this.options.position === 'bottom';
  10022. },
  10023. // Actually draw the legend on the canvas
  10024. draw: function () {
  10025. var me = this;
  10026. var opts = me.options;
  10027. var labelOpts = opts.labels;
  10028. var globalDefault = defaults.global;
  10029. var lineDefault = globalDefault.elements.line;
  10030. var legendWidth = me.width;
  10031. var lineWidths = me.lineWidths;
  10032. if (opts.display) {
  10033. var ctx = me.ctx;
  10034. var valueOrDefault = helpers.valueOrDefault;
  10035. var fontColor = valueOrDefault(labelOpts.fontColor, globalDefault.defaultFontColor);
  10036. var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);
  10037. var fontStyle = valueOrDefault(labelOpts.fontStyle, globalDefault.defaultFontStyle);
  10038. var fontFamily = valueOrDefault(labelOpts.fontFamily, globalDefault.defaultFontFamily);
  10039. var labelFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  10040. var cursor;
  10041. // Canvas setup
  10042. ctx.textAlign = 'left';
  10043. ctx.textBaseline = 'middle';
  10044. ctx.lineWidth = 0.5;
  10045. ctx.strokeStyle = fontColor; // for strikethrough effect
  10046. ctx.fillStyle = fontColor; // render in correct colour
  10047. ctx.font = labelFont;
  10048. var boxWidth = getBoxWidth(labelOpts, fontSize);
  10049. var hitboxes = me.legendHitBoxes;
  10050. // current position
  10051. var drawLegendBox = function (x, y, legendItem) {
  10052. if (isNaN(boxWidth) || boxWidth <= 0) {
  10053. return;
  10054. }
  10055. // Set the ctx for the box
  10056. ctx.save();
  10057. ctx.fillStyle = valueOrDefault(legendItem.fillStyle, globalDefault.defaultColor);
  10058. ctx.lineCap = valueOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
  10059. ctx.lineDashOffset = valueOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
  10060. ctx.lineJoin = valueOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
  10061. ctx.lineWidth = valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
  10062. ctx.strokeStyle = valueOrDefault(legendItem.strokeStyle, globalDefault.defaultColor);
  10063. var isLineWidthZero = (valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth) === 0);
  10064. if (ctx.setLineDash) {
  10065. // IE 9 and 10 do not support line dash
  10066. ctx.setLineDash(valueOrDefault(legendItem.lineDash, lineDefault.borderDash));
  10067. }
  10068. if (opts.labels && opts.labels.usePointStyle) {
  10069. // Recalculate x and y for drawPoint() because its expecting
  10070. // x and y to be center of figure (instead of top left)
  10071. var radius = fontSize * Math.SQRT2 / 2;
  10072. var offSet = radius / Math.SQRT2;
  10073. var centerX = x + offSet;
  10074. var centerY = y + offSet;
  10075. // Draw pointStyle as legend symbol
  10076. helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
  10077. } else {
  10078. // Draw box as legend symbol
  10079. if (!isLineWidthZero) {
  10080. ctx.strokeRect(x, y, boxWidth, fontSize);
  10081. }
  10082. ctx.fillRect(x, y, boxWidth, fontSize);
  10083. }
  10084. ctx.restore();
  10085. };
  10086. var fillText = function (x, y, legendItem, textWidth) {
  10087. var halfFontSize = fontSize / 2;
  10088. var xLeft = boxWidth + halfFontSize + x;
  10089. var yMiddle = y + halfFontSize;
  10090. ctx.fillText(legendItem.text, xLeft, yMiddle);
  10091. if (legendItem.hidden) {
  10092. // Strikethrough the text if hidden
  10093. ctx.beginPath();
  10094. ctx.lineWidth = 2;
  10095. ctx.moveTo(xLeft, yMiddle);
  10096. ctx.lineTo(xLeft + textWidth, yMiddle);
  10097. ctx.stroke();
  10098. }
  10099. };
  10100. // Horizontal
  10101. var isHorizontal = me.isHorizontal();
  10102. if (isHorizontal) {
  10103. cursor = {
  10104. x: me.left + ((legendWidth - lineWidths[0]) / 2),
  10105. y: me.top + labelOpts.padding,
  10106. line: 0
  10107. };
  10108. } else {
  10109. cursor = {
  10110. x: me.left + labelOpts.padding,
  10111. y: me.top + labelOpts.padding,
  10112. line: 0
  10113. };
  10114. }
  10115. var itemHeight = fontSize + labelOpts.padding;
  10116. helpers.each(me.legendItems, function (legendItem, i) {
  10117. var textWidth = ctx.measureText(legendItem.text).width;
  10118. var width = boxWidth + (fontSize / 2) + textWidth;
  10119. var x = cursor.x;
  10120. var y = cursor.y;
  10121. if (isHorizontal) {
  10122. if (x + width >= legendWidth) {
  10123. y = cursor.y += itemHeight;
  10124. cursor.line++;
  10125. x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
  10126. }
  10127. } else if (y + itemHeight > me.bottom) {
  10128. x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
  10129. y = cursor.y = me.top + labelOpts.padding;
  10130. cursor.line++;
  10131. }
  10132. drawLegendBox(x, y, legendItem);
  10133. hitboxes[i].left = x;
  10134. hitboxes[i].top = y;
  10135. // Fill the actual label
  10136. fillText(x, y, legendItem, textWidth);
  10137. if (isHorizontal) {
  10138. cursor.x += width + (labelOpts.padding);
  10139. } else {
  10140. cursor.y += itemHeight;
  10141. }
  10142. });
  10143. }
  10144. },
  10145. /**
  10146. * Handle an event
  10147. * @private
  10148. * @param {IEvent} event - The event to handle
  10149. * @return {Boolean} true if a change occured
  10150. */
  10151. handleEvent: function (e) {
  10152. var me = this;
  10153. var opts = me.options;
  10154. var type = e.type === 'mouseup' ? 'click' : e.type;
  10155. var changed = false;
  10156. if (type === 'mousemove') {
  10157. if (!opts.onHover) {
  10158. return;
  10159. }
  10160. } else if (type === 'click') {
  10161. if (!opts.onClick) {
  10162. return;
  10163. }
  10164. } else {
  10165. return;
  10166. }
  10167. // Chart event already has relative position in it
  10168. var x = e.x;
  10169. var y = e.y;
  10170. if (x >= me.left && x <= me.right && y >= me.top && y <= me.bottom) {
  10171. // See if we are touching one of the dataset boxes
  10172. var lh = me.legendHitBoxes;
  10173. for (var i = 0; i < lh.length; ++i) {
  10174. var hitBox = lh[i];
  10175. if (x >= hitBox.left && x <= hitBox.left + hitBox.width && y >= hitBox.top && y <= hitBox.top + hitBox.height) {
  10176. // Touching an element
  10177. if (type === 'click') {
  10178. // use e.native for backwards compatibility
  10179. opts.onClick.call(me, e.native, me.legendItems[i]);
  10180. changed = true;
  10181. break;
  10182. } else if (type === 'mousemove') {
  10183. // use e.native for backwards compatibility
  10184. opts.onHover.call(me, e.native, me.legendItems[i]);
  10185. changed = true;
  10186. break;
  10187. }
  10188. }
  10189. }
  10190. }
  10191. return changed;
  10192. }
  10193. });
  10194. function createNewLegendAndAttach(chart, legendOpts) {
  10195. var legend = new Legend({
  10196. ctx: chart.ctx,
  10197. options: legendOpts,
  10198. chart: chart
  10199. });
  10200. layouts.configure(chart, legend, legendOpts);
  10201. layouts.addBox(chart, legend);
  10202. chart.legend = legend;
  10203. }
  10204. module.exports = {
  10205. id: 'legend',
  10206. /**
  10207. * Backward compatibility: since 2.1.5, the legend is registered as a plugin, making
  10208. * Chart.Legend obsolete. To avoid a breaking change, we export the Legend as part of
  10209. * the plugin, which one will be re-exposed in the chart.js file.
  10210. * https://github.com/chartjs/Chart.js/pull/2640
  10211. * @private
  10212. */
  10213. _element: Legend,
  10214. beforeInit: function (chart) {
  10215. var legendOpts = chart.options.legend;
  10216. if (legendOpts) {
  10217. createNewLegendAndAttach(chart, legendOpts);
  10218. }
  10219. },
  10220. beforeUpdate: function (chart) {
  10221. var legendOpts = chart.options.legend;
  10222. var legend = chart.legend;
  10223. if (legendOpts) {
  10224. helpers.mergeIf(legendOpts, defaults.global.legend);
  10225. if (legend) {
  10226. layouts.configure(chart, legend, legendOpts);
  10227. legend.options = legendOpts;
  10228. } else {
  10229. createNewLegendAndAttach(chart, legendOpts);
  10230. }
  10231. } else if (legend) {
  10232. layouts.removeBox(chart, legend);
  10233. delete chart.legend;
  10234. }
  10235. },
  10236. afterEvent: function (chart, e) {
  10237. var legend = chart.legend;
  10238. if (legend) {
  10239. legend.handleEvent(e);
  10240. }
  10241. }
  10242. };
  10243. }, {"25": 25, "26": 26, "30": 30, "45": 45}], 52: [function (require, module, exports) {
  10244. 'use strict';
  10245. var defaults = require(25);
  10246. var Element = require(26);
  10247. var helpers = require(45);
  10248. var layouts = require(30);
  10249. var noop = helpers.noop;
  10250. defaults._set('global', {
  10251. title: {
  10252. display: false,
  10253. fontStyle: 'bold',
  10254. fullWidth: true,
  10255. lineHeight: 1.2,
  10256. padding: 10,
  10257. position: 'top',
  10258. text: '',
  10259. weight: 2000 // by default greater than legend (1000) to be above
  10260. }
  10261. });
  10262. /**
  10263. * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required!
  10264. */
  10265. var Title = Element.extend({
  10266. initialize: function (config) {
  10267. var me = this;
  10268. helpers.extend(me, config);
  10269. // Contains hit boxes for each dataset (in dataset order)
  10270. me.legendHitBoxes = [];
  10271. },
  10272. // These methods are ordered by lifecycle. Utilities then follow.
  10273. beforeUpdate: noop,
  10274. update: function (maxWidth, maxHeight, margins) {
  10275. var me = this;
  10276. // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
  10277. me.beforeUpdate();
  10278. // Absorb the master measurements
  10279. me.maxWidth = maxWidth;
  10280. me.maxHeight = maxHeight;
  10281. me.margins = margins;
  10282. // Dimensions
  10283. me.beforeSetDimensions();
  10284. me.setDimensions();
  10285. me.afterSetDimensions();
  10286. // Labels
  10287. me.beforeBuildLabels();
  10288. me.buildLabels();
  10289. me.afterBuildLabels();
  10290. // Fit
  10291. me.beforeFit();
  10292. me.fit();
  10293. me.afterFit();
  10294. //
  10295. me.afterUpdate();
  10296. return me.minSize;
  10297. },
  10298. afterUpdate: noop,
  10299. //
  10300. beforeSetDimensions: noop,
  10301. setDimensions: function () {
  10302. var me = this;
  10303. // Set the unconstrained dimension before label rotation
  10304. if (me.isHorizontal()) {
  10305. // Reset position before calculating rotation
  10306. me.width = me.maxWidth;
  10307. me.left = 0;
  10308. me.right = me.width;
  10309. } else {
  10310. me.height = me.maxHeight;
  10311. // Reset position before calculating rotation
  10312. me.top = 0;
  10313. me.bottom = me.height;
  10314. }
  10315. // Reset padding
  10316. me.paddingLeft = 0;
  10317. me.paddingTop = 0;
  10318. me.paddingRight = 0;
  10319. me.paddingBottom = 0;
  10320. // Reset minSize
  10321. me.minSize = {
  10322. width: 0,
  10323. height: 0
  10324. };
  10325. },
  10326. afterSetDimensions: noop,
  10327. //
  10328. beforeBuildLabels: noop,
  10329. buildLabels: noop,
  10330. afterBuildLabels: noop,
  10331. //
  10332. beforeFit: noop,
  10333. fit: function () {
  10334. var me = this;
  10335. var valueOrDefault = helpers.valueOrDefault;
  10336. var opts = me.options;
  10337. var display = opts.display;
  10338. var fontSize = valueOrDefault(opts.fontSize, defaults.global.defaultFontSize);
  10339. var minSize = me.minSize;
  10340. var lineCount = helpers.isArray(opts.text) ? opts.text.length : 1;
  10341. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  10342. var textSize = display ? (lineCount * lineHeight) + (opts.padding * 2) : 0;
  10343. if (me.isHorizontal()) {
  10344. minSize.width = me.maxWidth; // fill all the width
  10345. minSize.height = textSize;
  10346. } else {
  10347. minSize.width = textSize;
  10348. minSize.height = me.maxHeight; // fill all the height
  10349. }
  10350. me.width = minSize.width;
  10351. me.height = minSize.height;
  10352. },
  10353. afterFit: noop,
  10354. // Shared Methods
  10355. isHorizontal: function () {
  10356. var pos = this.options.position;
  10357. return pos === 'top' || pos === 'bottom';
  10358. },
  10359. // Actually draw the title block on the canvas
  10360. draw: function () {
  10361. var me = this;
  10362. var ctx = me.ctx;
  10363. var valueOrDefault = helpers.valueOrDefault;
  10364. var opts = me.options;
  10365. var globalDefaults = defaults.global;
  10366. if (opts.display) {
  10367. var fontSize = valueOrDefault(opts.fontSize, globalDefaults.defaultFontSize);
  10368. var fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle);
  10369. var fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily);
  10370. var titleFont = helpers.fontString(fontSize, fontStyle, fontFamily);
  10371. var lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize);
  10372. var offset = lineHeight / 2 + opts.padding;
  10373. var rotation = 0;
  10374. var top = me.top;
  10375. var left = me.left;
  10376. var bottom = me.bottom;
  10377. var right = me.right;
  10378. var maxWidth, titleX, titleY;
  10379. ctx.fillStyle = valueOrDefault(opts.fontColor, globalDefaults.defaultFontColor); // render in correct colour
  10380. ctx.font = titleFont;
  10381. // Horizontal
  10382. if (me.isHorizontal()) {
  10383. titleX = left + ((right - left) / 2); // midpoint of the width
  10384. titleY = top + offset;
  10385. maxWidth = right - left;
  10386. } else {
  10387. titleX = opts.position === 'left' ? left + offset : right - offset;
  10388. titleY = top + ((bottom - top) / 2);
  10389. maxWidth = bottom - top;
  10390. rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5);
  10391. }
  10392. ctx.save();
  10393. ctx.translate(titleX, titleY);
  10394. ctx.rotate(rotation);
  10395. ctx.textAlign = 'center';
  10396. ctx.textBaseline = 'middle';
  10397. var text = opts.text;
  10398. if (helpers.isArray(text)) {
  10399. var y = 0;
  10400. for (var i = 0; i < text.length; ++i) {
  10401. ctx.fillText(text[i], 0, y, maxWidth);
  10402. y += lineHeight;
  10403. }
  10404. } else {
  10405. ctx.fillText(text, 0, 0, maxWidth);
  10406. }
  10407. ctx.restore();
  10408. }
  10409. }
  10410. });
  10411. function createNewTitleBlockAndAttach(chart, titleOpts) {
  10412. var title = new Title({
  10413. ctx: chart.ctx,
  10414. options: titleOpts,
  10415. chart: chart
  10416. });
  10417. layouts.configure(chart, title, titleOpts);
  10418. layouts.addBox(chart, title);
  10419. chart.titleBlock = title;
  10420. }
  10421. module.exports = {
  10422. id: 'title',
  10423. /**
  10424. * Backward compatibility: since 2.1.5, the title is registered as a plugin, making
  10425. * Chart.Title obsolete. To avoid a breaking change, we export the Title as part of
  10426. * the plugin, which one will be re-exposed in the chart.js file.
  10427. * https://github.com/chartjs/Chart.js/pull/2640
  10428. * @private
  10429. */
  10430. _element: Title,
  10431. beforeInit: function (chart) {
  10432. var titleOpts = chart.options.title;
  10433. if (titleOpts) {
  10434. createNewTitleBlockAndAttach(chart, titleOpts);
  10435. }
  10436. },
  10437. beforeUpdate: function (chart) {
  10438. var titleOpts = chart.options.title;
  10439. var titleBlock = chart.titleBlock;
  10440. if (titleOpts) {
  10441. helpers.mergeIf(titleOpts, defaults.global.title);
  10442. if (titleBlock) {
  10443. layouts.configure(chart, titleBlock, titleOpts);
  10444. titleBlock.options = titleOpts;
  10445. } else {
  10446. createNewTitleBlockAndAttach(chart, titleOpts);
  10447. }
  10448. } else if (titleBlock) {
  10449. layouts.removeBox(chart, titleBlock);
  10450. delete chart.titleBlock;
  10451. }
  10452. }
  10453. };
  10454. }, {"25": 25, "26": 26, "30": 30, "45": 45}], 53: [function (require, module, exports) {
  10455. 'use strict';
  10456. module.exports = function (Chart) {
  10457. // Default config for a category scale
  10458. var defaultConfig = {
  10459. position: 'bottom'
  10460. };
  10461. var DatasetScale = Chart.Scale.extend({
  10462. /**
  10463. * Internal function to get the correct labels. If data.xLabels or data.yLabels are defined, use those
  10464. * else fall back to data.labels
  10465. * @private
  10466. */
  10467. getLabels: function () {
  10468. var data = this.chart.data;
  10469. return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels;
  10470. },
  10471. determineDataLimits: function () {
  10472. var me = this;
  10473. var labels = me.getLabels();
  10474. me.minIndex = 0;
  10475. me.maxIndex = labels.length - 1;
  10476. var findIndex;
  10477. if (me.options.ticks.min !== undefined) {
  10478. // user specified min value
  10479. findIndex = labels.indexOf(me.options.ticks.min);
  10480. me.minIndex = findIndex !== -1 ? findIndex : me.minIndex;
  10481. }
  10482. if (me.options.ticks.max !== undefined) {
  10483. // user specified max value
  10484. findIndex = labels.indexOf(me.options.ticks.max);
  10485. me.maxIndex = findIndex !== -1 ? findIndex : me.maxIndex;
  10486. }
  10487. me.min = labels[me.minIndex];
  10488. me.max = labels[me.maxIndex];
  10489. },
  10490. buildTicks: function () {
  10491. var me = this;
  10492. var labels = me.getLabels();
  10493. // If we are viewing some subset of labels, slice the original array
  10494. me.ticks = (me.minIndex === 0 && me.maxIndex === labels.length - 1) ? labels : labels.slice(me.minIndex, me.maxIndex + 1);
  10495. },
  10496. getLabelForIndex: function (index, datasetIndex) {
  10497. var me = this;
  10498. var data = me.chart.data;
  10499. var isHorizontal = me.isHorizontal();
  10500. if (data.yLabels && !isHorizontal) {
  10501. return me.getRightValue(data.datasets[datasetIndex].data[index]);
  10502. }
  10503. return me.ticks[index - me.minIndex];
  10504. },
  10505. // Used to get data value locations. Value can either be an index or a numerical value
  10506. getPixelForValue: function (value, index) {
  10507. var me = this;
  10508. var offset = me.options.offset;
  10509. // 1 is added because we need the length but we have the indexes
  10510. var offsetAmt = Math.max((me.maxIndex + 1 - me.minIndex - (offset ? 0 : 1)), 1);
  10511. // If value is a data object, then index is the index in the data array,
  10512. // not the index of the scale. We need to change that.
  10513. var valueCategory;
  10514. if (value !== undefined && value !== null) {
  10515. valueCategory = me.isHorizontal() ? value.x : value.y;
  10516. }
  10517. if (valueCategory !== undefined || (value !== undefined && isNaN(index))) {
  10518. var labels = me.getLabels();
  10519. value = valueCategory || value;
  10520. var idx = labels.indexOf(value);
  10521. index = idx !== -1 ? idx : index;
  10522. }
  10523. if (me.isHorizontal()) {
  10524. var valueWidth = me.width / offsetAmt;
  10525. var widthOffset = (valueWidth * (index - me.minIndex));
  10526. if (offset) {
  10527. widthOffset += (valueWidth / 2);
  10528. }
  10529. return me.left + Math.round(widthOffset);
  10530. }
  10531. var valueHeight = me.height / offsetAmt;
  10532. var heightOffset = (valueHeight * (index - me.minIndex));
  10533. if (offset) {
  10534. heightOffset += (valueHeight / 2);
  10535. }
  10536. return me.top + Math.round(heightOffset);
  10537. },
  10538. getPixelForTick: function (index) {
  10539. return this.getPixelForValue(this.ticks[index], index + this.minIndex, null);
  10540. },
  10541. getValueForPixel: function (pixel) {
  10542. var me = this;
  10543. var offset = me.options.offset;
  10544. var value;
  10545. var offsetAmt = Math.max((me._ticks.length - (offset ? 0 : 1)), 1);
  10546. var horz = me.isHorizontal();
  10547. var valueDimension = (horz ? me.width : me.height) / offsetAmt;
  10548. pixel -= horz ? me.left : me.top;
  10549. if (offset) {
  10550. pixel -= (valueDimension / 2);
  10551. }
  10552. if (pixel <= 0) {
  10553. value = 0;
  10554. } else {
  10555. value = Math.round(pixel / valueDimension);
  10556. }
  10557. return value + me.minIndex;
  10558. },
  10559. getBasePixel: function () {
  10560. return this.bottom;
  10561. }
  10562. });
  10563. Chart.scaleService.registerScaleType('category', DatasetScale, defaultConfig);
  10564. };
  10565. }, {}], 54: [function (require, module, exports) {
  10566. 'use strict';
  10567. var defaults = require(25);
  10568. var helpers = require(45);
  10569. var Ticks = require(34);
  10570. module.exports = function (Chart) {
  10571. var defaultConfig = {
  10572. position: 'left',
  10573. ticks: {
  10574. callback: Ticks.formatters.linear
  10575. }
  10576. };
  10577. var LinearScale = Chart.LinearScaleBase.extend({
  10578. determineDataLimits: function () {
  10579. var me = this;
  10580. var opts = me.options;
  10581. var chart = me.chart;
  10582. var data = chart.data;
  10583. var datasets = data.datasets;
  10584. var isHorizontal = me.isHorizontal();
  10585. var DEFAULT_MIN = 0;
  10586. var DEFAULT_MAX = 1;
  10587. function IDMatches(meta) {
  10588. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  10589. }
  10590. // First Calculate the range
  10591. me.min = null;
  10592. me.max = null;
  10593. var hasStacks = opts.stacked;
  10594. if (hasStacks === undefined) {
  10595. helpers.each(datasets, function (dataset, datasetIndex) {
  10596. if (hasStacks) {
  10597. return;
  10598. }
  10599. var meta = chart.getDatasetMeta(datasetIndex);
  10600. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  10601. meta.stack !== undefined) {
  10602. hasStacks = true;
  10603. }
  10604. });
  10605. }
  10606. if (opts.stacked || hasStacks) {
  10607. var valuesPerStack = {};
  10608. helpers.each(datasets, function (dataset, datasetIndex) {
  10609. var meta = chart.getDatasetMeta(datasetIndex);
  10610. var key = [
  10611. meta.type,
  10612. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  10613. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  10614. meta.stack
  10615. ].join('.');
  10616. if (valuesPerStack[key] === undefined) {
  10617. valuesPerStack[key] = {
  10618. positiveValues: [],
  10619. negativeValues: []
  10620. };
  10621. }
  10622. // Store these per type
  10623. var positiveValues = valuesPerStack[key].positiveValues;
  10624. var negativeValues = valuesPerStack[key].negativeValues;
  10625. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10626. helpers.each(dataset.data, function (rawValue, index) {
  10627. var value = +me.getRightValue(rawValue);
  10628. if (isNaN(value) || meta.data[index].hidden) {
  10629. return;
  10630. }
  10631. positiveValues[index] = positiveValues[index] || 0;
  10632. negativeValues[index] = negativeValues[index] || 0;
  10633. if (opts.relativePoints) {
  10634. positiveValues[index] = 100;
  10635. } else if (value < 0) {
  10636. negativeValues[index] += value;
  10637. } else {
  10638. positiveValues[index] += value;
  10639. }
  10640. });
  10641. }
  10642. });
  10643. helpers.each(valuesPerStack, function (valuesForType) {
  10644. var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
  10645. var minVal = helpers.min(values);
  10646. var maxVal = helpers.max(values);
  10647. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  10648. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  10649. });
  10650. } else {
  10651. helpers.each(datasets, function (dataset, datasetIndex) {
  10652. var meta = chart.getDatasetMeta(datasetIndex);
  10653. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10654. helpers.each(dataset.data, function (rawValue, index) {
  10655. var value = +me.getRightValue(rawValue);
  10656. if (isNaN(value) || meta.data[index].hidden) {
  10657. return;
  10658. }
  10659. if (me.min === null) {
  10660. me.min = value;
  10661. } else if (value < me.min) {
  10662. me.min = value;
  10663. }
  10664. if (me.max === null) {
  10665. me.max = value;
  10666. } else if (value > me.max) {
  10667. me.max = value;
  10668. }
  10669. });
  10670. }
  10671. });
  10672. }
  10673. me.min = isFinite(me.min) && !isNaN(me.min) ? me.min : DEFAULT_MIN;
  10674. me.max = isFinite(me.max) && !isNaN(me.max) ? me.max : DEFAULT_MAX;
  10675. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  10676. this.handleTickRangeOptions();
  10677. },
  10678. getTickLimit: function () {
  10679. var maxTicks;
  10680. var me = this;
  10681. var tickOpts = me.options.ticks;
  10682. if (me.isHorizontal()) {
  10683. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.width / 50));
  10684. } else {
  10685. // The factor of 2 used to scale the font size has been experimentally determined.
  10686. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, defaults.global.defaultFontSize);
  10687. maxTicks = Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(me.height / (2 * tickFontSize)));
  10688. }
  10689. return maxTicks;
  10690. },
  10691. // Called after the ticks are built. We need
  10692. handleDirectionalChanges: function () {
  10693. if (!this.isHorizontal()) {
  10694. // We are in a vertical orientation. The top value is the highest. So reverse the array
  10695. this.ticks.reverse();
  10696. }
  10697. },
  10698. getLabelForIndex: function (index, datasetIndex) {
  10699. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  10700. },
  10701. // Utils
  10702. getPixelForValue: function (value) {
  10703. // This must be called after fit has been run so that
  10704. // this.left, this.top, this.right, and this.bottom have been defined
  10705. var me = this;
  10706. var start = me.start;
  10707. var rightValue = +me.getRightValue(value);
  10708. var pixel;
  10709. var range = me.end - start;
  10710. if (me.isHorizontal()) {
  10711. pixel = me.left + (me.width / range * (rightValue - start));
  10712. } else {
  10713. pixel = me.bottom - (me.height / range * (rightValue - start));
  10714. }
  10715. return pixel;
  10716. },
  10717. getValueForPixel: function (pixel) {
  10718. var me = this;
  10719. var isHorizontal = me.isHorizontal();
  10720. var innerDimension = isHorizontal ? me.width : me.height;
  10721. var offset = (isHorizontal ? pixel - me.left : me.bottom - pixel) / innerDimension;
  10722. return me.start + ((me.end - me.start) * offset);
  10723. },
  10724. getPixelForTick: function (index) {
  10725. return this.getPixelForValue(this.ticksAsNumbers[index]);
  10726. }
  10727. });
  10728. Chart.scaleService.registerScaleType('linear', LinearScale, defaultConfig);
  10729. };
  10730. }, {"25": 25, "34": 34, "45": 45}], 55: [function (require, module, exports) {
  10731. 'use strict';
  10732. var helpers = require(45);
  10733. /**
  10734. * Generate a set of linear ticks
  10735. * @param generationOptions the options used to generate the ticks
  10736. * @param dataRange the range of the data
  10737. * @returns {Array<Number>} array of tick values
  10738. */
  10739. function generateTicks(generationOptions, dataRange) {
  10740. var ticks = [];
  10741. // To get a "nice" value for the tick spacing, we will use the appropriately named
  10742. // "nice number" algorithm. See http://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  10743. // for details.
  10744. var spacing;
  10745. if (generationOptions.stepSize && generationOptions.stepSize > 0) {
  10746. spacing = generationOptions.stepSize;
  10747. } else {
  10748. var niceRange = helpers.niceNum(dataRange.max - dataRange.min, false);
  10749. spacing = helpers.niceNum(niceRange / (generationOptions.maxTicks - 1), true);
  10750. }
  10751. var niceMin = Math.floor(dataRange.min / spacing) * spacing;
  10752. var niceMax = Math.ceil(dataRange.max / spacing) * spacing;
  10753. // If min, max and stepSize is set and they make an evenly spaced scale use it.
  10754. if (generationOptions.min && generationOptions.max && generationOptions.stepSize) {
  10755. // If very close to our whole number, use it.
  10756. if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) {
  10757. niceMin = generationOptions.min;
  10758. niceMax = generationOptions.max;
  10759. }
  10760. }
  10761. var numSpaces = (niceMax - niceMin) / spacing;
  10762. // If very close to our rounded value, use it.
  10763. if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
  10764. numSpaces = Math.round(numSpaces);
  10765. } else {
  10766. numSpaces = Math.ceil(numSpaces);
  10767. }
  10768. var precision = 1;
  10769. if (spacing < 1) {
  10770. precision = Math.pow(10, spacing.toString().length - 2);
  10771. niceMin = Math.round(niceMin * precision) / precision;
  10772. niceMax = Math.round(niceMax * precision) / precision;
  10773. }
  10774. ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin);
  10775. for (var j = 1; j < numSpaces; ++j) {
  10776. ticks.push(Math.round((niceMin + j * spacing) * precision) / precision);
  10777. }
  10778. ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax);
  10779. return ticks;
  10780. }
  10781. module.exports = function (Chart) {
  10782. var noop = helpers.noop;
  10783. Chart.LinearScaleBase = Chart.Scale.extend({
  10784. getRightValue: function (value) {
  10785. if (typeof value === 'string') {
  10786. return +value;
  10787. }
  10788. return Chart.Scale.prototype.getRightValue.call(this, value);
  10789. },
  10790. handleTickRangeOptions: function () {
  10791. var me = this;
  10792. var opts = me.options;
  10793. var tickOpts = opts.ticks;
  10794. // If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
  10795. // do nothing since that would make the chart weird. If the user really wants a weird chart
  10796. // axis, they can manually override it
  10797. if (tickOpts.beginAtZero) {
  10798. var minSign = helpers.sign(me.min);
  10799. var maxSign = helpers.sign(me.max);
  10800. if (minSign < 0 && maxSign < 0) {
  10801. // move the top up to 0
  10802. me.max = 0;
  10803. } else if (minSign > 0 && maxSign > 0) {
  10804. // move the bottom down to 0
  10805. me.min = 0;
  10806. }
  10807. }
  10808. var setMin = tickOpts.min !== undefined || tickOpts.suggestedMin !== undefined;
  10809. var setMax = tickOpts.max !== undefined || tickOpts.suggestedMax !== undefined;
  10810. if (tickOpts.min !== undefined) {
  10811. me.min = tickOpts.min;
  10812. } else if (tickOpts.suggestedMin !== undefined) {
  10813. if (me.min === null) {
  10814. me.min = tickOpts.suggestedMin;
  10815. } else {
  10816. me.min = Math.min(me.min, tickOpts.suggestedMin);
  10817. }
  10818. }
  10819. if (tickOpts.max !== undefined) {
  10820. me.max = tickOpts.max;
  10821. } else if (tickOpts.suggestedMax !== undefined) {
  10822. if (me.max === null) {
  10823. me.max = tickOpts.suggestedMax;
  10824. } else {
  10825. me.max = Math.max(me.max, tickOpts.suggestedMax);
  10826. }
  10827. }
  10828. if (setMin !== setMax) {
  10829. // We set the min or the max but not both.
  10830. // So ensure that our range is good
  10831. // Inverted or 0 length range can happen when
  10832. // ticks.min is set, and no datasets are visible
  10833. if (me.min >= me.max) {
  10834. if (setMin) {
  10835. me.max = me.min + 1;
  10836. } else {
  10837. me.min = me.max - 1;
  10838. }
  10839. }
  10840. }
  10841. if (me.min === me.max) {
  10842. me.max++;
  10843. if (!tickOpts.beginAtZero) {
  10844. me.min--;
  10845. }
  10846. }
  10847. },
  10848. getTickLimit: noop,
  10849. handleDirectionalChanges: noop,
  10850. buildTicks: function () {
  10851. var me = this;
  10852. var opts = me.options;
  10853. var tickOpts = opts.ticks;
  10854. // Figure out what the max number of ticks we can support it is based on the size of
  10855. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  10856. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  10857. // the graph. Make sure we always have at least 2 ticks
  10858. var maxTicks = me.getTickLimit();
  10859. maxTicks = Math.max(2, maxTicks);
  10860. var numericGeneratorOptions = {
  10861. maxTicks: maxTicks,
  10862. min: tickOpts.min,
  10863. max: tickOpts.max,
  10864. stepSize: helpers.valueOrDefault(tickOpts.fixedStepSize, tickOpts.stepSize)
  10865. };
  10866. var ticks = me.ticks = generateTicks(numericGeneratorOptions, me);
  10867. me.handleDirectionalChanges();
  10868. // At this point, we need to update our max and min given the tick values since we have expanded the
  10869. // range of the scale
  10870. me.max = helpers.max(ticks);
  10871. me.min = helpers.min(ticks);
  10872. if (tickOpts.reverse) {
  10873. ticks.reverse();
  10874. me.start = me.max;
  10875. me.end = me.min;
  10876. } else {
  10877. me.start = me.min;
  10878. me.end = me.max;
  10879. }
  10880. },
  10881. convertTicksToLabels: function () {
  10882. var me = this;
  10883. me.ticksAsNumbers = me.ticks.slice();
  10884. me.zeroLineIndex = me.ticks.indexOf(0);
  10885. Chart.Scale.prototype.convertTicksToLabels.call(me);
  10886. }
  10887. });
  10888. };
  10889. }, {"45": 45}], 56: [function (require, module, exports) {
  10890. 'use strict';
  10891. var helpers = require(45);
  10892. var Ticks = require(34);
  10893. /**
  10894. * Generate a set of logarithmic ticks
  10895. * @param generationOptions the options used to generate the ticks
  10896. * @param dataRange the range of the data
  10897. * @returns {Array<Number>} array of tick values
  10898. */
  10899. function generateTicks(generationOptions, dataRange) {
  10900. var ticks = [];
  10901. var valueOrDefault = helpers.valueOrDefault;
  10902. // Figure out what the max number of ticks we can support it is based on the size of
  10903. // the axis area. For now, we say that the minimum tick spacing in pixels must be 50
  10904. // We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
  10905. // the graph
  10906. var tickVal = valueOrDefault(generationOptions.min, Math.pow(10, Math.floor(helpers.log10(dataRange.min))));
  10907. var endExp = Math.floor(helpers.log10(dataRange.max));
  10908. var endSignificand = Math.ceil(dataRange.max / Math.pow(10, endExp));
  10909. var exp, significand;
  10910. if (tickVal === 0) {
  10911. exp = Math.floor(helpers.log10(dataRange.minNotZero));
  10912. significand = Math.floor(dataRange.minNotZero / Math.pow(10, exp));
  10913. ticks.push(tickVal);
  10914. tickVal = significand * Math.pow(10, exp);
  10915. } else {
  10916. exp = Math.floor(helpers.log10(tickVal));
  10917. significand = Math.floor(tickVal / Math.pow(10, exp));
  10918. }
  10919. var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1;
  10920. do {
  10921. ticks.push(tickVal);
  10922. ++significand;
  10923. if (significand === 10) {
  10924. significand = 1;
  10925. ++exp;
  10926. precision = exp >= 0 ? 1 : precision;
  10927. }
  10928. tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision;
  10929. } while (exp < endExp || (exp === endExp && significand < endSignificand));
  10930. var lastTick = valueOrDefault(generationOptions.max, tickVal);
  10931. ticks.push(lastTick);
  10932. return ticks;
  10933. }
  10934. module.exports = function (Chart) {
  10935. var defaultConfig = {
  10936. position: 'left',
  10937. // label settings
  10938. ticks: {
  10939. callback: Ticks.formatters.logarithmic
  10940. }
  10941. };
  10942. var LogarithmicScale = Chart.Scale.extend({
  10943. determineDataLimits: function () {
  10944. var me = this;
  10945. var opts = me.options;
  10946. var chart = me.chart;
  10947. var data = chart.data;
  10948. var datasets = data.datasets;
  10949. var isHorizontal = me.isHorizontal();
  10950. function IDMatches(meta) {
  10951. return isHorizontal ? meta.xAxisID === me.id : meta.yAxisID === me.id;
  10952. }
  10953. // Calculate Range
  10954. me.min = null;
  10955. me.max = null;
  10956. me.minNotZero = null;
  10957. var hasStacks = opts.stacked;
  10958. if (hasStacks === undefined) {
  10959. helpers.each(datasets, function (dataset, datasetIndex) {
  10960. if (hasStacks) {
  10961. return;
  10962. }
  10963. var meta = chart.getDatasetMeta(datasetIndex);
  10964. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta) &&
  10965. meta.stack !== undefined) {
  10966. hasStacks = true;
  10967. }
  10968. });
  10969. }
  10970. if (opts.stacked || hasStacks) {
  10971. var valuesPerStack = {};
  10972. helpers.each(datasets, function (dataset, datasetIndex) {
  10973. var meta = chart.getDatasetMeta(datasetIndex);
  10974. var key = [
  10975. meta.type,
  10976. // we have a separate stack for stack=undefined datasets when the opts.stacked is undefined
  10977. ((opts.stacked === undefined && meta.stack === undefined) ? datasetIndex : ''),
  10978. meta.stack
  10979. ].join('.');
  10980. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  10981. if (valuesPerStack[key] === undefined) {
  10982. valuesPerStack[key] = [];
  10983. }
  10984. helpers.each(dataset.data, function (rawValue, index) {
  10985. var values = valuesPerStack[key];
  10986. var value = +me.getRightValue(rawValue);
  10987. // invalid, hidden and negative values are ignored
  10988. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  10989. return;
  10990. }
  10991. values[index] = values[index] || 0;
  10992. values[index] += value;
  10993. });
  10994. }
  10995. });
  10996. helpers.each(valuesPerStack, function (valuesForType) {
  10997. if (valuesForType.length > 0) {
  10998. var minVal = helpers.min(valuesForType);
  10999. var maxVal = helpers.max(valuesForType);
  11000. me.min = me.min === null ? minVal : Math.min(me.min, minVal);
  11001. me.max = me.max === null ? maxVal : Math.max(me.max, maxVal);
  11002. }
  11003. });
  11004. } else {
  11005. helpers.each(datasets, function (dataset, datasetIndex) {
  11006. var meta = chart.getDatasetMeta(datasetIndex);
  11007. if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
  11008. helpers.each(dataset.data, function (rawValue, index) {
  11009. var value = +me.getRightValue(rawValue);
  11010. // invalid, hidden and negative values are ignored
  11011. if (isNaN(value) || meta.data[index].hidden || value < 0) {
  11012. return;
  11013. }
  11014. if (me.min === null) {
  11015. me.min = value;
  11016. } else if (value < me.min) {
  11017. me.min = value;
  11018. }
  11019. if (me.max === null) {
  11020. me.max = value;
  11021. } else if (value > me.max) {
  11022. me.max = value;
  11023. }
  11024. if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
  11025. me.minNotZero = value;
  11026. }
  11027. });
  11028. }
  11029. });
  11030. }
  11031. // Common base implementation to handle ticks.min, ticks.max
  11032. this.handleTickRangeOptions();
  11033. },
  11034. handleTickRangeOptions: function () {
  11035. var me = this;
  11036. var opts = me.options;
  11037. var tickOpts = opts.ticks;
  11038. var valueOrDefault = helpers.valueOrDefault;
  11039. var DEFAULT_MIN = 1;
  11040. var DEFAULT_MAX = 10;
  11041. me.min = valueOrDefault(tickOpts.min, me.min);
  11042. me.max = valueOrDefault(tickOpts.max, me.max);
  11043. if (me.min === me.max) {
  11044. if (me.min !== 0 && me.min !== null) {
  11045. me.min = Math.pow(10, Math.floor(helpers.log10(me.min)) - 1);
  11046. me.max = Math.pow(10, Math.floor(helpers.log10(me.max)) + 1);
  11047. } else {
  11048. me.min = DEFAULT_MIN;
  11049. me.max = DEFAULT_MAX;
  11050. }
  11051. }
  11052. if (me.min === null) {
  11053. me.min = Math.pow(10, Math.floor(helpers.log10(me.max)) - 1);
  11054. }
  11055. if (me.max === null) {
  11056. me.max = me.min !== 0
  11057. ? Math.pow(10, Math.floor(helpers.log10(me.min)) + 1)
  11058. : DEFAULT_MAX;
  11059. }
  11060. if (me.minNotZero === null) {
  11061. if (me.min > 0) {
  11062. me.minNotZero = me.min;
  11063. } else if (me.max < 1) {
  11064. me.minNotZero = Math.pow(10, Math.floor(helpers.log10(me.max)));
  11065. } else {
  11066. me.minNotZero = DEFAULT_MIN;
  11067. }
  11068. }
  11069. },
  11070. buildTicks: function () {
  11071. var me = this;
  11072. var opts = me.options;
  11073. var tickOpts = opts.ticks;
  11074. var reverse = !me.isHorizontal();
  11075. var generationOptions = {
  11076. min: tickOpts.min,
  11077. max: tickOpts.max
  11078. };
  11079. var ticks = me.ticks = generateTicks(generationOptions, me);
  11080. // At this point, we need to update our max and min given the tick values since we have expanded the
  11081. // range of the scale
  11082. me.max = helpers.max(ticks);
  11083. me.min = helpers.min(ticks);
  11084. if (tickOpts.reverse) {
  11085. reverse = !reverse;
  11086. me.start = me.max;
  11087. me.end = me.min;
  11088. } else {
  11089. me.start = me.min;
  11090. me.end = me.max;
  11091. }
  11092. if (reverse) {
  11093. ticks.reverse();
  11094. }
  11095. },
  11096. convertTicksToLabels: function () {
  11097. this.tickValues = this.ticks.slice();
  11098. Chart.Scale.prototype.convertTicksToLabels.call(this);
  11099. },
  11100. // Get the correct tooltip label
  11101. getLabelForIndex: function (index, datasetIndex) {
  11102. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11103. },
  11104. getPixelForTick: function (index) {
  11105. return this.getPixelForValue(this.tickValues[index]);
  11106. },
  11107. /**
  11108. * Returns the value of the first tick.
  11109. * @param {Number} value - The minimum not zero value.
  11110. * @return {Number} The first tick value.
  11111. * @private
  11112. */
  11113. _getFirstTickValue: function (value) {
  11114. var exp = Math.floor(helpers.log10(value));
  11115. var significand = Math.floor(value / Math.pow(10, exp));
  11116. return significand * Math.pow(10, exp);
  11117. },
  11118. getPixelForValue: function (value) {
  11119. var me = this;
  11120. var reverse = me.options.ticks.reverse;
  11121. var log10 = helpers.log10;
  11122. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  11123. var offset = 0;
  11124. var innerDimension, pixel, start, end, sign;
  11125. value = +me.getRightValue(value);
  11126. if (reverse) {
  11127. start = me.end;
  11128. end = me.start;
  11129. sign = -1;
  11130. } else {
  11131. start = me.start;
  11132. end = me.end;
  11133. sign = 1;
  11134. }
  11135. if (me.isHorizontal()) {
  11136. innerDimension = me.width;
  11137. pixel = reverse ? me.right : me.left;
  11138. } else {
  11139. innerDimension = me.height;
  11140. sign *= -1; // invert, since the upper-left corner of the canvas is at pixel (0, 0)
  11141. pixel = reverse ? me.top : me.bottom;
  11142. }
  11143. if (value !== start) {
  11144. if (start === 0) { // include zero tick
  11145. offset = helpers.getValueOrDefault(
  11146. me.options.ticks.fontSize,
  11147. Chart.defaults.global.defaultFontSize
  11148. );
  11149. innerDimension -= offset;
  11150. start = firstTickValue;
  11151. }
  11152. if (value !== 0) {
  11153. offset += innerDimension / (log10(end) - log10(start)) * (log10(value) - log10(start));
  11154. }
  11155. pixel += sign * offset;
  11156. }
  11157. return pixel;
  11158. },
  11159. getValueForPixel: function (pixel) {
  11160. var me = this;
  11161. var reverse = me.options.ticks.reverse;
  11162. var log10 = helpers.log10;
  11163. var firstTickValue = me._getFirstTickValue(me.minNotZero);
  11164. var innerDimension, start, end, value;
  11165. if (reverse) {
  11166. start = me.end;
  11167. end = me.start;
  11168. } else {
  11169. start = me.start;
  11170. end = me.end;
  11171. }
  11172. if (me.isHorizontal()) {
  11173. innerDimension = me.width;
  11174. value = reverse ? me.right - pixel : pixel - me.left;
  11175. } else {
  11176. innerDimension = me.height;
  11177. value = reverse ? pixel - me.top : me.bottom - pixel;
  11178. }
  11179. if (value !== start) {
  11180. if (start === 0) { // include zero tick
  11181. var offset = helpers.getValueOrDefault(
  11182. me.options.ticks.fontSize,
  11183. Chart.defaults.global.defaultFontSize
  11184. );
  11185. value -= offset;
  11186. innerDimension -= offset;
  11187. start = firstTickValue;
  11188. }
  11189. value *= log10(end) - log10(start);
  11190. value /= innerDimension;
  11191. value = Math.pow(10, log10(start) + value);
  11192. }
  11193. return value;
  11194. }
  11195. });
  11196. Chart.scaleService.registerScaleType('logarithmic', LogarithmicScale, defaultConfig);
  11197. };
  11198. }, {"34": 34, "45": 45}], 57: [function (require, module, exports) {
  11199. 'use strict';
  11200. var defaults = require(25);
  11201. var helpers = require(45);
  11202. var Ticks = require(34);
  11203. module.exports = function (Chart) {
  11204. var globalDefaults = defaults.global;
  11205. var defaultConfig = {
  11206. display: true,
  11207. // Boolean - Whether to animate scaling the chart from the centre
  11208. animate: true,
  11209. position: 'chartArea',
  11210. angleLines: {
  11211. display: true,
  11212. color: 'rgba(0, 0, 0, 0.1)',
  11213. lineWidth: 1
  11214. },
  11215. gridLines: {
  11216. circular: false
  11217. },
  11218. // label settings
  11219. ticks: {
  11220. // Boolean - Show a backdrop to the scale label
  11221. showLabelBackdrop: true,
  11222. // String - The colour of the label backdrop
  11223. backdropColor: 'rgba(255,255,255,0.75)',
  11224. // Number - The backdrop padding above & below the label in pixels
  11225. backdropPaddingY: 2,
  11226. // Number - The backdrop padding to the side of the label in pixels
  11227. backdropPaddingX: 2,
  11228. callback: Ticks.formatters.linear
  11229. },
  11230. pointLabels: {
  11231. // Boolean - if true, show point labels
  11232. display: true,
  11233. // Number - Point label font size in pixels
  11234. fontSize: 10,
  11235. // Function - Used to convert point labels
  11236. callback: function (label) {
  11237. return label;
  11238. }
  11239. }
  11240. };
  11241. function getValueCount(scale) {
  11242. var opts = scale.options;
  11243. return opts.angleLines.display || opts.pointLabels.display ? scale.chart.data.labels.length : 0;
  11244. }
  11245. function getPointLabelFontOptions(scale) {
  11246. var pointLabelOptions = scale.options.pointLabels;
  11247. var fontSize = helpers.valueOrDefault(pointLabelOptions.fontSize, globalDefaults.defaultFontSize);
  11248. var fontStyle = helpers.valueOrDefault(pointLabelOptions.fontStyle, globalDefaults.defaultFontStyle);
  11249. var fontFamily = helpers.valueOrDefault(pointLabelOptions.fontFamily, globalDefaults.defaultFontFamily);
  11250. var font = helpers.fontString(fontSize, fontStyle, fontFamily);
  11251. return {
  11252. size: fontSize,
  11253. style: fontStyle,
  11254. family: fontFamily,
  11255. font: font
  11256. };
  11257. }
  11258. function measureLabelSize(ctx, fontSize, label) {
  11259. if (helpers.isArray(label)) {
  11260. return {
  11261. w: helpers.longestText(ctx, ctx.font, label),
  11262. h: (label.length * fontSize) + ((label.length - 1) * 1.5 * fontSize)
  11263. };
  11264. }
  11265. return {
  11266. w: ctx.measureText(label).width,
  11267. h: fontSize
  11268. };
  11269. }
  11270. function determineLimits(angle, pos, size, min, max) {
  11271. if (angle === min || angle === max) {
  11272. return {
  11273. start: pos - (size / 2),
  11274. end: pos + (size / 2)
  11275. };
  11276. } else if (angle < min || angle > max) {
  11277. return {
  11278. start: pos - size - 5,
  11279. end: pos
  11280. };
  11281. }
  11282. return {
  11283. start: pos,
  11284. end: pos + size + 5
  11285. };
  11286. }
  11287. /**
  11288. * Helper function to fit a radial linear scale with point labels
  11289. */
  11290. function fitWithPointLabels(scale) {
  11291. /*
  11292. * Right, this is really confusing and there is a lot of maths going on here
  11293. * The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
  11294. *
  11295. * Reaction: https://dl.dropboxusercontent.com/u/34601363/toomuchscience.gif
  11296. *
  11297. * Solution:
  11298. *
  11299. * We assume the radius of the polygon is half the size of the canvas at first
  11300. * at each index we check if the text overlaps.
  11301. *
  11302. * Where it does, we store that angle and that index.
  11303. *
  11304. * After finding the largest index and angle we calculate how much we need to remove
  11305. * from the shape radius to move the point inwards by that x.
  11306. *
  11307. * We average the left and right distances to get the maximum shape radius that can fit in the box
  11308. * along with labels.
  11309. *
  11310. * Once we have that, we can find the centre point for the chart, by taking the x text protrusion
  11311. * on each side, removing that from the size, halving it and adding the left x protrusion width.
  11312. *
  11313. * This will mean we have a shape fitted to the canvas, as large as it can be with the labels
  11314. * and position it in the most space efficient manner
  11315. *
  11316. * https://dl.dropboxusercontent.com/u/34601363/yeahscience.gif
  11317. */
  11318. var plFont = getPointLabelFontOptions(scale);
  11319. // Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
  11320. // Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
  11321. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  11322. var furthestLimits = {
  11323. r: scale.width,
  11324. l: 0,
  11325. t: scale.height,
  11326. b: 0
  11327. };
  11328. var furthestAngles = {};
  11329. var i, textSize, pointPosition;
  11330. scale.ctx.font = plFont.font;
  11331. scale._pointLabelSizes = [];
  11332. var valueCount = getValueCount(scale);
  11333. for (i = 0; i < valueCount; i++) {
  11334. pointPosition = scale.getPointPosition(i, largestPossibleRadius);
  11335. textSize = measureLabelSize(scale.ctx, plFont.size, scale.pointLabels[i] || '');
  11336. scale._pointLabelSizes[i] = textSize;
  11337. // Add quarter circle to make degree 0 mean top of circle
  11338. var angleRadians = scale.getIndexAngle(i);
  11339. var angle = helpers.toDegrees(angleRadians) % 360;
  11340. var hLimits = determineLimits(angle, pointPosition.x, textSize.w, 0, 180);
  11341. var vLimits = determineLimits(angle, pointPosition.y, textSize.h, 90, 270);
  11342. if (hLimits.start < furthestLimits.l) {
  11343. furthestLimits.l = hLimits.start;
  11344. furthestAngles.l = angleRadians;
  11345. }
  11346. if (hLimits.end > furthestLimits.r) {
  11347. furthestLimits.r = hLimits.end;
  11348. furthestAngles.r = angleRadians;
  11349. }
  11350. if (vLimits.start < furthestLimits.t) {
  11351. furthestLimits.t = vLimits.start;
  11352. furthestAngles.t = angleRadians;
  11353. }
  11354. if (vLimits.end > furthestLimits.b) {
  11355. furthestLimits.b = vLimits.end;
  11356. furthestAngles.b = angleRadians;
  11357. }
  11358. }
  11359. scale.setReductions(largestPossibleRadius, furthestLimits, furthestAngles);
  11360. }
  11361. /**
  11362. * Helper function to fit a radial linear scale with no point labels
  11363. */
  11364. function fit(scale) {
  11365. var largestPossibleRadius = Math.min(scale.height / 2, scale.width / 2);
  11366. scale.drawingArea = Math.round(largestPossibleRadius);
  11367. scale.setCenterPoint(0, 0, 0, 0);
  11368. }
  11369. function getTextAlignForAngle(angle) {
  11370. if (angle === 0 || angle === 180) {
  11371. return 'center';
  11372. } else if (angle < 180) {
  11373. return 'left';
  11374. }
  11375. return 'right';
  11376. }
  11377. function fillText(ctx, text, position, fontSize) {
  11378. if (helpers.isArray(text)) {
  11379. var y = position.y;
  11380. var spacing = 1.5 * fontSize;
  11381. for (var i = 0; i < text.length; ++i) {
  11382. ctx.fillText(text[i], position.x, y);
  11383. y += spacing;
  11384. }
  11385. } else {
  11386. ctx.fillText(text, position.x, position.y);
  11387. }
  11388. }
  11389. function adjustPointPositionForLabelHeight(angle, textSize, position) {
  11390. if (angle === 90 || angle === 270) {
  11391. position.y -= (textSize.h / 2);
  11392. } else if (angle > 270 || angle < 90) {
  11393. position.y -= textSize.h;
  11394. }
  11395. }
  11396. function drawPointLabels(scale) {
  11397. var ctx = scale.ctx;
  11398. var opts = scale.options;
  11399. var angleLineOpts = opts.angleLines;
  11400. var pointLabelOpts = opts.pointLabels;
  11401. ctx.lineWidth = angleLineOpts.lineWidth;
  11402. ctx.strokeStyle = angleLineOpts.color;
  11403. var outerDistance = scale.getDistanceFromCenterForValue(opts.ticks.reverse ? scale.min : scale.max);
  11404. // Point Label Font
  11405. var plFont = getPointLabelFontOptions(scale);
  11406. ctx.textBaseline = 'top';
  11407. for (var i = getValueCount(scale) - 1; i >= 0; i--) {
  11408. if (angleLineOpts.display) {
  11409. var outerPosition = scale.getPointPosition(i, outerDistance);
  11410. ctx.beginPath();
  11411. ctx.moveTo(scale.xCenter, scale.yCenter);
  11412. ctx.lineTo(outerPosition.x, outerPosition.y);
  11413. ctx.stroke();
  11414. ctx.closePath();
  11415. }
  11416. if (pointLabelOpts.display) {
  11417. // Extra 3px out for some label spacing
  11418. var pointLabelPosition = scale.getPointPosition(i, outerDistance + 5);
  11419. // Keep this in loop since we may support array properties here
  11420. var pointLabelFontColor = helpers.valueAtIndexOrDefault(pointLabelOpts.fontColor, i, globalDefaults.defaultFontColor);
  11421. ctx.font = plFont.font;
  11422. ctx.fillStyle = pointLabelFontColor;
  11423. var angleRadians = scale.getIndexAngle(i);
  11424. var angle = helpers.toDegrees(angleRadians);
  11425. ctx.textAlign = getTextAlignForAngle(angle);
  11426. adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
  11427. fillText(ctx, scale.pointLabels[i] || '', pointLabelPosition, plFont.size);
  11428. }
  11429. }
  11430. }
  11431. function drawRadiusLine(scale, gridLineOpts, radius, index) {
  11432. var ctx = scale.ctx;
  11433. ctx.strokeStyle = helpers.valueAtIndexOrDefault(gridLineOpts.color, index - 1);
  11434. ctx.lineWidth = helpers.valueAtIndexOrDefault(gridLineOpts.lineWidth, index - 1);
  11435. if (scale.options.gridLines.circular) {
  11436. // Draw circular arcs between the points
  11437. ctx.beginPath();
  11438. ctx.arc(scale.xCenter, scale.yCenter, radius, 0, Math.PI * 2);
  11439. ctx.closePath();
  11440. ctx.stroke();
  11441. } else {
  11442. // Draw straight lines connecting each index
  11443. var valueCount = getValueCount(scale);
  11444. if (valueCount === 0) {
  11445. return;
  11446. }
  11447. ctx.beginPath();
  11448. var pointPosition = scale.getPointPosition(0, radius);
  11449. ctx.moveTo(pointPosition.x, pointPosition.y);
  11450. for (var i = 1; i < valueCount; i++) {
  11451. pointPosition = scale.getPointPosition(i, radius);
  11452. ctx.lineTo(pointPosition.x, pointPosition.y);
  11453. }
  11454. ctx.closePath();
  11455. ctx.stroke();
  11456. }
  11457. }
  11458. function numberOrZero(param) {
  11459. return helpers.isNumber(param) ? param : 0;
  11460. }
  11461. var LinearRadialScale = Chart.LinearScaleBase.extend({
  11462. setDimensions: function () {
  11463. var me = this;
  11464. var opts = me.options;
  11465. var tickOpts = opts.ticks;
  11466. // Set the unconstrained dimension before label rotation
  11467. me.width = me.maxWidth;
  11468. me.height = me.maxHeight;
  11469. me.xCenter = Math.round(me.width / 2);
  11470. me.yCenter = Math.round(me.height / 2);
  11471. var minSize = helpers.min([me.height, me.width]);
  11472. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11473. me.drawingArea = opts.display ? (minSize / 2) - (tickFontSize / 2 + tickOpts.backdropPaddingY) : (minSize / 2);
  11474. },
  11475. determineDataLimits: function () {
  11476. var me = this;
  11477. var chart = me.chart;
  11478. var min = Number.POSITIVE_INFINITY;
  11479. var max = Number.NEGATIVE_INFINITY;
  11480. helpers.each(chart.data.datasets, function (dataset, datasetIndex) {
  11481. if (chart.isDatasetVisible(datasetIndex)) {
  11482. var meta = chart.getDatasetMeta(datasetIndex);
  11483. helpers.each(dataset.data, function (rawValue, index) {
  11484. var value = +me.getRightValue(rawValue);
  11485. if (isNaN(value) || meta.data[index].hidden) {
  11486. return;
  11487. }
  11488. min = Math.min(value, min);
  11489. max = Math.max(value, max);
  11490. });
  11491. }
  11492. });
  11493. me.min = (min === Number.POSITIVE_INFINITY ? 0 : min);
  11494. me.max = (max === Number.NEGATIVE_INFINITY ? 0 : max);
  11495. // Common base implementation to handle ticks.min, ticks.max, ticks.beginAtZero
  11496. me.handleTickRangeOptions();
  11497. },
  11498. getTickLimit: function () {
  11499. var tickOpts = this.options.ticks;
  11500. var tickFontSize = helpers.valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11501. return Math.min(tickOpts.maxTicksLimit ? tickOpts.maxTicksLimit : 11, Math.ceil(this.drawingArea / (1.5 * tickFontSize)));
  11502. },
  11503. convertTicksToLabels: function () {
  11504. var me = this;
  11505. Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
  11506. // Point labels
  11507. me.pointLabels = me.chart.data.labels.map(me.options.pointLabels.callback, me);
  11508. },
  11509. getLabelForIndex: function (index, datasetIndex) {
  11510. return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
  11511. },
  11512. fit: function () {
  11513. if (this.options.pointLabels.display) {
  11514. fitWithPointLabels(this);
  11515. } else {
  11516. fit(this);
  11517. }
  11518. },
  11519. /**
  11520. * Set radius reductions and determine new radius and center point
  11521. * @private
  11522. */
  11523. setReductions: function (largestPossibleRadius, furthestLimits, furthestAngles) {
  11524. var me = this;
  11525. var radiusReductionLeft = furthestLimits.l / Math.sin(furthestAngles.l);
  11526. var radiusReductionRight = Math.max(furthestLimits.r - me.width, 0) / Math.sin(furthestAngles.r);
  11527. var radiusReductionTop = -furthestLimits.t / Math.cos(furthestAngles.t);
  11528. var radiusReductionBottom = -Math.max(furthestLimits.b - me.height, 0) / Math.cos(furthestAngles.b);
  11529. radiusReductionLeft = numberOrZero(radiusReductionLeft);
  11530. radiusReductionRight = numberOrZero(radiusReductionRight);
  11531. radiusReductionTop = numberOrZero(radiusReductionTop);
  11532. radiusReductionBottom = numberOrZero(radiusReductionBottom);
  11533. me.drawingArea = Math.min(
  11534. Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2),
  11535. Math.round(largestPossibleRadius - (radiusReductionTop + radiusReductionBottom) / 2));
  11536. me.setCenterPoint(radiusReductionLeft, radiusReductionRight, radiusReductionTop, radiusReductionBottom);
  11537. },
  11538. setCenterPoint: function (leftMovement, rightMovement, topMovement, bottomMovement) {
  11539. var me = this;
  11540. var maxRight = me.width - rightMovement - me.drawingArea;
  11541. var maxLeft = leftMovement + me.drawingArea;
  11542. var maxTop = topMovement + me.drawingArea;
  11543. var maxBottom = me.height - bottomMovement - me.drawingArea;
  11544. me.xCenter = Math.round(((maxLeft + maxRight) / 2) + me.left);
  11545. me.yCenter = Math.round(((maxTop + maxBottom) / 2) + me.top);
  11546. },
  11547. getIndexAngle: function (index) {
  11548. var angleMultiplier = (Math.PI * 2) / getValueCount(this);
  11549. var startAngle = this.chart.options && this.chart.options.startAngle ?
  11550. this.chart.options.startAngle :
  11551. 0;
  11552. var startAngleRadians = startAngle * Math.PI * 2 / 360;
  11553. // Start from the top instead of right, so remove a quarter of the circle
  11554. return index * angleMultiplier + startAngleRadians;
  11555. },
  11556. getDistanceFromCenterForValue: function (value) {
  11557. var me = this;
  11558. if (value === null) {
  11559. return 0; // null always in center
  11560. }
  11561. // Take into account half font size + the yPadding of the top value
  11562. var scalingFactor = me.drawingArea / (me.max - me.min);
  11563. if (me.options.ticks.reverse) {
  11564. return (me.max - value) * scalingFactor;
  11565. }
  11566. return (value - me.min) * scalingFactor;
  11567. },
  11568. getPointPosition: function (index, distanceFromCenter) {
  11569. var me = this;
  11570. var thisAngle = me.getIndexAngle(index) - (Math.PI / 2);
  11571. return {
  11572. x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + me.xCenter,
  11573. y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + me.yCenter
  11574. };
  11575. },
  11576. getPointPositionForValue: function (index, value) {
  11577. return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
  11578. },
  11579. getBasePosition: function () {
  11580. var me = this;
  11581. var min = me.min;
  11582. var max = me.max;
  11583. return me.getPointPositionForValue(0,
  11584. me.beginAtZero ? 0 :
  11585. min < 0 && max < 0 ? max :
  11586. min > 0 && max > 0 ? min :
  11587. 0);
  11588. },
  11589. draw: function () {
  11590. var me = this;
  11591. var opts = me.options;
  11592. var gridLineOpts = opts.gridLines;
  11593. var tickOpts = opts.ticks;
  11594. var valueOrDefault = helpers.valueOrDefault;
  11595. if (opts.display) {
  11596. var ctx = me.ctx;
  11597. var startAngle = this.getIndexAngle(0);
  11598. // Tick Font
  11599. var tickFontSize = valueOrDefault(tickOpts.fontSize, globalDefaults.defaultFontSize);
  11600. var tickFontStyle = valueOrDefault(tickOpts.fontStyle, globalDefaults.defaultFontStyle);
  11601. var tickFontFamily = valueOrDefault(tickOpts.fontFamily, globalDefaults.defaultFontFamily);
  11602. var tickLabelFont = helpers.fontString(tickFontSize, tickFontStyle, tickFontFamily);
  11603. helpers.each(me.ticks, function (label, index) {
  11604. // Don't draw a centre value (if it is minimum)
  11605. if (index > 0 || tickOpts.reverse) {
  11606. var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
  11607. // Draw circular lines around the scale
  11608. if (gridLineOpts.display && index !== 0) {
  11609. drawRadiusLine(me, gridLineOpts, yCenterOffset, index);
  11610. }
  11611. if (tickOpts.display) {
  11612. var tickFontColor = valueOrDefault(tickOpts.fontColor, globalDefaults.defaultFontColor);
  11613. ctx.font = tickLabelFont;
  11614. ctx.save();
  11615. ctx.translate(me.xCenter, me.yCenter);
  11616. ctx.rotate(startAngle);
  11617. if (tickOpts.showLabelBackdrop) {
  11618. var labelWidth = ctx.measureText(label).width;
  11619. ctx.fillStyle = tickOpts.backdropColor;
  11620. ctx.fillRect(
  11621. -labelWidth / 2 - tickOpts.backdropPaddingX,
  11622. -yCenterOffset - tickFontSize / 2 - tickOpts.backdropPaddingY,
  11623. labelWidth + tickOpts.backdropPaddingX * 2,
  11624. tickFontSize + tickOpts.backdropPaddingY * 2
  11625. );
  11626. }
  11627. ctx.textAlign = 'center';
  11628. ctx.textBaseline = 'middle';
  11629. ctx.fillStyle = tickFontColor;
  11630. ctx.fillText(label, 0, -yCenterOffset);
  11631. ctx.restore();
  11632. }
  11633. }
  11634. });
  11635. if (opts.angleLines.display || opts.pointLabels.display) {
  11636. drawPointLabels(me);
  11637. }
  11638. }
  11639. }
  11640. });
  11641. Chart.scaleService.registerScaleType('radialLinear', LinearRadialScale, defaultConfig);
  11642. };
  11643. }, {"25": 25, "34": 34, "45": 45}], 58: [function (require, module, exports) {
  11644. /* global window: false */
  11645. 'use strict';
  11646. var moment = require(1);
  11647. moment = typeof moment === 'function' ? moment : window.moment;
  11648. var defaults = require(25);
  11649. var helpers = require(45);
  11650. // Integer constants are from the ES6 spec.
  11651. var MIN_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
  11652. var MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
  11653. var INTERVALS = {
  11654. millisecond: {
  11655. common: true,
  11656. size: 1,
  11657. steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
  11658. },
  11659. second: {
  11660. common: true,
  11661. size: 1000,
  11662. steps: [1, 2, 5, 10, 30]
  11663. },
  11664. minute: {
  11665. common: true,
  11666. size: 60000,
  11667. steps: [1, 2, 5, 10, 30]
  11668. },
  11669. hour: {
  11670. common: true,
  11671. size: 3600000,
  11672. steps: [1, 2, 3, 6, 12]
  11673. },
  11674. day: {
  11675. common: true,
  11676. size: 86400000,
  11677. steps: [1, 2, 5]
  11678. },
  11679. week: {
  11680. common: false,
  11681. size: 604800000,
  11682. steps: [1, 2, 3, 4]
  11683. },
  11684. month: {
  11685. common: true,
  11686. size: 2.628e9,
  11687. steps: [1, 2, 3]
  11688. },
  11689. quarter: {
  11690. common: false,
  11691. size: 7.884e9,
  11692. steps: [1, 2, 3, 4]
  11693. },
  11694. year: {
  11695. common: true,
  11696. size: 3.154e10
  11697. }
  11698. };
  11699. var UNITS = Object.keys(INTERVALS);
  11700. function sorter(a, b) {
  11701. return a - b;
  11702. }
  11703. function arrayUnique(items) {
  11704. var hash = {};
  11705. var out = [];
  11706. var i, ilen, item;
  11707. for (i = 0, ilen = items.length; i < ilen; ++i) {
  11708. item = items[i];
  11709. if (!hash[item]) {
  11710. hash[item] = true;
  11711. out.push(item);
  11712. }
  11713. }
  11714. return out;
  11715. }
  11716. /**
  11717. * Returns an array of {time, pos} objects used to interpolate a specific `time` or position
  11718. * (`pos`) on the scale, by searching entries before and after the requested value. `pos` is
  11719. * a decimal between 0 and 1: 0 being the start of the scale (left or top) and 1 the other
  11720. * extremity (left + width or top + height). Note that it would be more optimized to directly
  11721. * store pre-computed pixels, but the scale dimensions are not guaranteed at the time we need
  11722. * to create the lookup table. The table ALWAYS contains at least two items: min and max.
  11723. *
  11724. * @param {Number[]} timestamps - timestamps sorted from lowest to highest.
  11725. * @param {String} distribution - If 'linear', timestamps will be spread linearly along the min
  11726. * and max range, so basically, the table will contains only two items: {min, 0} and {max, 1}.
  11727. * If 'series', timestamps will be positioned at the same distance from each other. In this
  11728. * case, only timestamps that break the time linearity are registered, meaning that in the
  11729. * best case, all timestamps are linear, the table contains only min and max.
  11730. */
  11731. function buildLookupTable(timestamps, min, max, distribution) {
  11732. if (distribution === 'linear' || !timestamps.length) {
  11733. return [
  11734. {time: min, pos: 0},
  11735. {time: max, pos: 1}
  11736. ];
  11737. }
  11738. var table = [];
  11739. var items = [min];
  11740. var i, ilen, prev, curr, next;
  11741. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  11742. curr = timestamps[i];
  11743. if (curr > min && curr < max) {
  11744. items.push(curr);
  11745. }
  11746. }
  11747. items.push(max);
  11748. for (i = 0, ilen = items.length; i < ilen; ++i) {
  11749. next = items[i + 1];
  11750. prev = items[i - 1];
  11751. curr = items[i];
  11752. // only add points that breaks the scale linearity
  11753. if (prev === undefined || next === undefined || Math.round((next + prev) / 2) !== curr) {
  11754. table.push({time: curr, pos: i / (ilen - 1)});
  11755. }
  11756. }
  11757. return table;
  11758. }
  11759. // @see adapted from http://www.anujgakhar.com/2014/03/01/binary-search-in-javascript/
  11760. function lookup(table, key, value) {
  11761. var lo = 0;
  11762. var hi = table.length - 1;
  11763. var mid, i0, i1;
  11764. while (lo >= 0 && lo <= hi) {
  11765. mid = (lo + hi) >> 1;
  11766. i0 = table[mid - 1] || null;
  11767. i1 = table[mid];
  11768. if (!i0) {
  11769. // given value is outside table (before first item)
  11770. return {lo: null, hi: i1};
  11771. } else if (i1[key] < value) {
  11772. lo = mid + 1;
  11773. } else if (i0[key] > value) {
  11774. hi = mid - 1;
  11775. } else {
  11776. return {lo: i0, hi: i1};
  11777. }
  11778. }
  11779. // given value is outside table (after last item)
  11780. return {lo: i1, hi: null};
  11781. }
  11782. /**
  11783. * Linearly interpolates the given source `value` using the table items `skey` values and
  11784. * returns the associated `tkey` value. For example, interpolate(table, 'time', 42, 'pos')
  11785. * returns the position for a timestamp equal to 42. If value is out of bounds, values at
  11786. * index [0, 1] or [n - 1, n] are used for the interpolation.
  11787. */
  11788. function interpolate(table, skey, sval, tkey) {
  11789. var range = lookup(table, skey, sval);
  11790. // Note: the lookup table ALWAYS contains at least 2 items (min and max)
  11791. var prev = !range.lo ? table[0] : !range.hi ? table[table.length - 2] : range.lo;
  11792. var next = !range.lo ? table[1] : !range.hi ? table[table.length - 1] : range.hi;
  11793. var span = next[skey] - prev[skey];
  11794. var ratio = span ? (sval - prev[skey]) / span : 0;
  11795. var offset = (next[tkey] - prev[tkey]) * ratio;
  11796. return prev[tkey] + offset;
  11797. }
  11798. /**
  11799. * Convert the given value to a moment object using the given time options.
  11800. * @see http://momentjs.com/docs/#/parsing/
  11801. */
  11802. function momentify(value, options) {
  11803. var parser = options.parser;
  11804. var format = options.parser || options.format;
  11805. if (typeof parser === 'function') {
  11806. return parser(value);
  11807. }
  11808. if (typeof value === 'string' && typeof format === 'string') {
  11809. return moment(value, format);
  11810. }
  11811. if (!(value instanceof moment)) {
  11812. value = moment(value);
  11813. }
  11814. if (value.isValid()) {
  11815. return value;
  11816. }
  11817. // Labels are in an incompatible moment format and no `parser` has been provided.
  11818. // The user might still use the deprecated `format` option to convert his inputs.
  11819. if (typeof format === 'function') {
  11820. return format(value);
  11821. }
  11822. return value;
  11823. }
  11824. function parse(input, scale) {
  11825. if (helpers.isNullOrUndef(input)) {
  11826. return null;
  11827. }
  11828. var options = scale.options.time;
  11829. var value = momentify(scale.getRightValue(input), options);
  11830. if (!value.isValid()) {
  11831. return null;
  11832. }
  11833. if (options.round) {
  11834. value.startOf(options.round);
  11835. }
  11836. return value.valueOf();
  11837. }
  11838. /**
  11839. * Returns the number of unit to skip to be able to display up to `capacity` number of ticks
  11840. * in `unit` for the given `min` / `max` range and respecting the interval steps constraints.
  11841. */
  11842. function determineStepSize(min, max, unit, capacity) {
  11843. var range = max - min;
  11844. var interval = INTERVALS[unit];
  11845. var milliseconds = interval.size;
  11846. var steps = interval.steps;
  11847. var i, ilen, factor;
  11848. if (!steps) {
  11849. return Math.ceil(range / (capacity * milliseconds));
  11850. }
  11851. for (i = 0, ilen = steps.length; i < ilen; ++i) {
  11852. factor = steps[i];
  11853. if (Math.ceil(range / (milliseconds * factor)) <= capacity) {
  11854. break;
  11855. }
  11856. }
  11857. return factor;
  11858. }
  11859. /**
  11860. * Figures out what unit results in an appropriate number of auto-generated ticks
  11861. */
  11862. function determineUnitForAutoTicks(minUnit, min, max, capacity) {
  11863. var ilen = UNITS.length;
  11864. var i, interval, factor;
  11865. for (i = UNITS.indexOf(minUnit); i < ilen - 1; ++i) {
  11866. interval = INTERVALS[UNITS[i]];
  11867. factor = interval.steps ? interval.steps[interval.steps.length - 1] : MAX_INTEGER;
  11868. if (interval.common && Math.ceil((max - min) / (factor * interval.size)) <= capacity) {
  11869. return UNITS[i];
  11870. }
  11871. }
  11872. return UNITS[ilen - 1];
  11873. }
  11874. /**
  11875. * Figures out what unit to format a set of ticks with
  11876. */
  11877. function determineUnitForFormatting(ticks, minUnit, min, max) {
  11878. var duration = moment.duration(moment(max).diff(moment(min)));
  11879. var ilen = UNITS.length;
  11880. var i, unit;
  11881. for (i = ilen - 1; i >= UNITS.indexOf(minUnit); i--) {
  11882. unit = UNITS[i];
  11883. if (INTERVALS[unit].common && duration.as(unit) >= ticks.length) {
  11884. return unit;
  11885. }
  11886. }
  11887. return UNITS[minUnit ? UNITS.indexOf(minUnit) : 0];
  11888. }
  11889. function determineMajorUnit(unit) {
  11890. for (var i = UNITS.indexOf(unit) + 1, ilen = UNITS.length; i < ilen; ++i) {
  11891. if (INTERVALS[UNITS[i]].common) {
  11892. return UNITS[i];
  11893. }
  11894. }
  11895. }
  11896. /**
  11897. * Generates a maximum of `capacity` timestamps between min and max, rounded to the
  11898. * `minor` unit, aligned on the `major` unit and using the given scale time `options`.
  11899. * Important: this method can return ticks outside the min and max range, it's the
  11900. * responsibility of the calling code to clamp values if needed.
  11901. */
  11902. function generate(min, max, capacity, options) {
  11903. var timeOpts = options.time;
  11904. var minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, capacity);
  11905. var major = determineMajorUnit(minor);
  11906. var stepSize = helpers.valueOrDefault(timeOpts.stepSize, timeOpts.unitStepSize);
  11907. var weekday = minor === 'week' ? timeOpts.isoWeekday : false;
  11908. var majorTicksEnabled = options.ticks.major.enabled;
  11909. var interval = INTERVALS[minor];
  11910. var first = moment(min);
  11911. var last = moment(max);
  11912. var ticks = [];
  11913. var time;
  11914. if (!stepSize) {
  11915. stepSize = determineStepSize(min, max, minor, capacity);
  11916. }
  11917. // For 'week' unit, handle the first day of week option
  11918. if (weekday) {
  11919. first = first.isoWeekday(weekday);
  11920. last = last.isoWeekday(weekday);
  11921. }
  11922. // Align first/last ticks on unit
  11923. first = first.startOf(weekday ? 'day' : minor);
  11924. last = last.startOf(weekday ? 'day' : minor);
  11925. // Make sure that the last tick include max
  11926. if (last < max) {
  11927. last.add(1, minor);
  11928. }
  11929. time = moment(first);
  11930. if (majorTicksEnabled && major && !weekday && !timeOpts.round) {
  11931. // Align the first tick on the previous `minor` unit aligned on the `major` unit:
  11932. // we first aligned time on the previous `major` unit then add the number of full
  11933. // stepSize there is between first and the previous major time.
  11934. time.startOf(major);
  11935. time.add(~~((first - time) / (interval.size * stepSize)) * stepSize, minor);
  11936. }
  11937. for (; time < last; time.add(stepSize, minor)) {
  11938. ticks.push(+time);
  11939. }
  11940. ticks.push(+time);
  11941. return ticks;
  11942. }
  11943. /**
  11944. * Returns the right and left offsets from edges in the form of {left, right}.
  11945. * Offsets are added when the `offset` option is true.
  11946. */
  11947. function computeOffsets(table, ticks, min, max, options) {
  11948. var left = 0;
  11949. var right = 0;
  11950. var upper, lower;
  11951. if (options.offset && ticks.length) {
  11952. if (!options.time.min) {
  11953. upper = ticks.length > 1 ? ticks[1] : max;
  11954. lower = ticks[0];
  11955. left = (
  11956. interpolate(table, 'time', upper, 'pos') -
  11957. interpolate(table, 'time', lower, 'pos')
  11958. ) / 2;
  11959. }
  11960. if (!options.time.max) {
  11961. upper = ticks[ticks.length - 1];
  11962. lower = ticks.length > 1 ? ticks[ticks.length - 2] : min;
  11963. right = (
  11964. interpolate(table, 'time', upper, 'pos') -
  11965. interpolate(table, 'time', lower, 'pos')
  11966. ) / 2;
  11967. }
  11968. }
  11969. return {left: left, right: right};
  11970. }
  11971. function ticksFromTimestamps(values, majorUnit) {
  11972. var ticks = [];
  11973. var i, ilen, value, major;
  11974. for (i = 0, ilen = values.length; i < ilen; ++i) {
  11975. value = values[i];
  11976. major = majorUnit ? value === +moment(value).startOf(majorUnit) : false;
  11977. ticks.push({
  11978. value: value,
  11979. major: major
  11980. });
  11981. }
  11982. return ticks;
  11983. }
  11984. function determineLabelFormat(data, timeOpts) {
  11985. var i, momentDate, hasTime;
  11986. var ilen = data.length;
  11987. // find the label with the most parts (milliseconds, minutes, etc.)
  11988. // format all labels with the same level of detail as the most specific label
  11989. for (i = 0; i < ilen; i++) {
  11990. momentDate = momentify(data[i], timeOpts);
  11991. if (momentDate.millisecond() !== 0) {
  11992. return 'MMM D, YYYY h:mm:ss.SSS a';
  11993. }
  11994. if (momentDate.second() !== 0 || momentDate.minute() !== 0 || momentDate.hour() !== 0) {
  11995. hasTime = true;
  11996. }
  11997. }
  11998. if (hasTime) {
  11999. return 'MMM D, YYYY h:mm:ss a';
  12000. }
  12001. return 'MMM D, YYYY';
  12002. }
  12003. module.exports = function (Chart) {
  12004. var defaultConfig = {
  12005. position: 'bottom',
  12006. /**
  12007. * Data distribution along the scale:
  12008. * - 'linear': data are spread according to their time (distances can vary),
  12009. * - 'series': data are spread at the same distance from each other.
  12010. * @see https://github.com/chartjs/Chart.js/pull/4507
  12011. * @since 2.7.0
  12012. */
  12013. distribution: 'linear',
  12014. /**
  12015. * Scale boundary strategy (bypassed by min/max time options)
  12016. * - `data`: make sure data are fully visible, ticks outside are removed
  12017. * - `ticks`: make sure ticks are fully visible, data outside are truncated
  12018. * @see https://github.com/chartjs/Chart.js/pull/4556
  12019. * @since 2.7.0
  12020. */
  12021. bounds: 'data',
  12022. time: {
  12023. 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
  12024. format: false, // DEPRECATED false == date objects, moment object, callback or a pattern string from http://momentjs.com/docs/#/parsing/string-format/
  12025. unit: false, // false == automatic or override with week, month, year, etc.
  12026. round: false, // none, or override with week, month, year, etc.
  12027. displayFormat: false, // DEPRECATED
  12028. isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
  12029. minUnit: 'millisecond',
  12030. // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
  12031. displayFormats: {
  12032. millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
  12033. second: 'h:mm:ss a', // 11:20:01 AM
  12034. minute: 'h:mm a', // 11:20 AM
  12035. hour: 'hA', // 5PM
  12036. day: 'MMM D', // Sep 4
  12037. week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
  12038. month: 'MMM YYYY', // Sept 2015
  12039. quarter: '[Q]Q - YYYY', // Q3
  12040. year: 'YYYY' // 2015
  12041. },
  12042. },
  12043. ticks: {
  12044. autoSkip: false,
  12045. /**
  12046. * Ticks generation input values:
  12047. * - 'auto': generates "optimal" ticks based on scale size and time options.
  12048. * - 'data': generates ticks from data (including labels from data {t|x|y} objects).
  12049. * - 'labels': generates ticks from user given `data.labels` values ONLY.
  12050. * @see https://github.com/chartjs/Chart.js/pull/4507
  12051. * @since 2.7.0
  12052. */
  12053. source: 'auto',
  12054. major: {
  12055. enabled: false
  12056. }
  12057. }
  12058. };
  12059. var TimeScale = Chart.Scale.extend({
  12060. initialize: function () {
  12061. if (!moment) {
  12062. 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');
  12063. }
  12064. this.mergeTicksOptions();
  12065. Chart.Scale.prototype.initialize.call(this);
  12066. },
  12067. update: function () {
  12068. var me = this;
  12069. var options = me.options;
  12070. // DEPRECATIONS: output a message only one time per update
  12071. if (options.time && options.time.format) {
  12072. console.warn('options.time.format is deprecated and replaced by options.time.parser.');
  12073. }
  12074. return Chart.Scale.prototype.update.apply(me, arguments);
  12075. },
  12076. /**
  12077. * Allows data to be referenced via 't' attribute
  12078. */
  12079. getRightValue: function (rawValue) {
  12080. if (rawValue && rawValue.t !== undefined) {
  12081. rawValue = rawValue.t;
  12082. }
  12083. return Chart.Scale.prototype.getRightValue.call(this, rawValue);
  12084. },
  12085. determineDataLimits: function () {
  12086. var me = this;
  12087. var chart = me.chart;
  12088. var timeOpts = me.options.time;
  12089. var unit = timeOpts.unit || 'day';
  12090. var min = MAX_INTEGER;
  12091. var max = MIN_INTEGER;
  12092. var timestamps = [];
  12093. var datasets = [];
  12094. var labels = [];
  12095. var i, j, ilen, jlen, data, timestamp;
  12096. // Convert labels to timestamps
  12097. for (i = 0, ilen = chart.data.labels.length; i < ilen; ++i) {
  12098. labels.push(parse(chart.data.labels[i], me));
  12099. }
  12100. // Convert data to timestamps
  12101. for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
  12102. if (chart.isDatasetVisible(i)) {
  12103. data = chart.data.datasets[i].data;
  12104. // Let's consider that all data have the same format.
  12105. if (helpers.isObject(data[0])) {
  12106. datasets[i] = [];
  12107. for (j = 0, jlen = data.length; j < jlen; ++j) {
  12108. timestamp = parse(data[j], me);
  12109. timestamps.push(timestamp);
  12110. datasets[i][j] = timestamp;
  12111. }
  12112. } else {
  12113. timestamps.push.apply(timestamps, labels);
  12114. datasets[i] = labels.slice(0);
  12115. }
  12116. } else {
  12117. datasets[i] = [];
  12118. }
  12119. }
  12120. if (labels.length) {
  12121. // Sort labels **after** data have been converted
  12122. labels = arrayUnique(labels).sort(sorter);
  12123. min = Math.min(min, labels[0]);
  12124. max = Math.max(max, labels[labels.length - 1]);
  12125. }
  12126. if (timestamps.length) {
  12127. timestamps = arrayUnique(timestamps).sort(sorter);
  12128. min = Math.min(min, timestamps[0]);
  12129. max = Math.max(max, timestamps[timestamps.length - 1]);
  12130. }
  12131. min = parse(timeOpts.min, me) || min;
  12132. max = parse(timeOpts.max, me) || max;
  12133. // In case there is no valid min/max, set limits based on unit time option
  12134. min = min === MAX_INTEGER ? +moment().startOf(unit) : min;
  12135. max = max === MIN_INTEGER ? +moment().endOf(unit) + 1 : max;
  12136. // Make sure that max is strictly higher than min (required by the lookup table)
  12137. me.min = Math.min(min, max);
  12138. me.max = Math.max(min + 1, max);
  12139. // PRIVATE
  12140. me._horizontal = me.isHorizontal();
  12141. me._table = [];
  12142. me._timestamps = {
  12143. data: timestamps,
  12144. datasets: datasets,
  12145. labels: labels
  12146. };
  12147. },
  12148. buildTicks: function () {
  12149. var me = this;
  12150. var min = me.min;
  12151. var max = me.max;
  12152. var options = me.options;
  12153. var timeOpts = options.time;
  12154. var timestamps = [];
  12155. var ticks = [];
  12156. var i, ilen, timestamp;
  12157. switch (options.ticks.source) {
  12158. case 'data':
  12159. timestamps = me._timestamps.data;
  12160. break;
  12161. case 'labels':
  12162. timestamps = me._timestamps.labels;
  12163. break;
  12164. case 'auto':
  12165. default:
  12166. timestamps = generate(min, max, me.getLabelCapacity(min), options);
  12167. }
  12168. if (options.bounds === 'ticks' && timestamps.length) {
  12169. min = timestamps[0];
  12170. max = timestamps[timestamps.length - 1];
  12171. }
  12172. // Enforce limits with user min/max options
  12173. min = parse(timeOpts.min, me) || min;
  12174. max = parse(timeOpts.max, me) || max;
  12175. // Remove ticks outside the min/max range
  12176. for (i = 0, ilen = timestamps.length; i < ilen; ++i) {
  12177. timestamp = timestamps[i];
  12178. if (timestamp >= min && timestamp <= max) {
  12179. ticks.push(timestamp);
  12180. }
  12181. }
  12182. me.min = min;
  12183. me.max = max;
  12184. // PRIVATE
  12185. me._unit = timeOpts.unit || determineUnitForFormatting(ticks, timeOpts.minUnit, me.min, me.max);
  12186. me._majorUnit = determineMajorUnit(me._unit);
  12187. me._table = buildLookupTable(me._timestamps.data, min, max, options.distribution);
  12188. me._offsets = computeOffsets(me._table, ticks, min, max, options);
  12189. me._labelFormat = determineLabelFormat(me._timestamps.data, timeOpts);
  12190. return ticksFromTimestamps(ticks, me._majorUnit);
  12191. },
  12192. getLabelForIndex: function (index, datasetIndex) {
  12193. var me = this;
  12194. var data = me.chart.data;
  12195. var timeOpts = me.options.time;
  12196. var label = data.labels && index < data.labels.length ? data.labels[index] : '';
  12197. var value = data.datasets[datasetIndex].data[index];
  12198. if (helpers.isObject(value)) {
  12199. label = me.getRightValue(value);
  12200. }
  12201. if (timeOpts.tooltipFormat) {
  12202. return momentify(label, timeOpts).format(timeOpts.tooltipFormat);
  12203. }
  12204. if (typeof label === 'string') {
  12205. return label;
  12206. }
  12207. return momentify(label, timeOpts).format(me._labelFormat);
  12208. },
  12209. /**
  12210. * Function to format an individual tick mark
  12211. * @private
  12212. */
  12213. tickFormatFunction: function (tick, index, ticks, formatOverride) {
  12214. var me = this;
  12215. var options = me.options;
  12216. var time = tick.valueOf();
  12217. var formats = options.time.displayFormats;
  12218. var minorFormat = formats[me._unit];
  12219. var majorUnit = me._majorUnit;
  12220. var majorFormat = formats[majorUnit];
  12221. var majorTime = tick.clone().startOf(majorUnit).valueOf();
  12222. var majorTickOpts = options.ticks.major;
  12223. var major = majorTickOpts.enabled && majorUnit && majorFormat && time === majorTime;
  12224. var label = tick.format(formatOverride ? formatOverride : major ? majorFormat : minorFormat);
  12225. var tickOpts = major ? majorTickOpts : options.ticks.minor;
  12226. var formatter = helpers.valueOrDefault(tickOpts.callback, tickOpts.userCallback);
  12227. return formatter ? formatter(label, index, ticks) : label;
  12228. },
  12229. convertTicksToLabels: function (ticks) {
  12230. var labels = [];
  12231. var i, ilen;
  12232. for (i = 0, ilen = ticks.length; i < ilen; ++i) {
  12233. labels.push(this.tickFormatFunction(moment(ticks[i].value), i, ticks));
  12234. }
  12235. return labels;
  12236. },
  12237. /**
  12238. * @private
  12239. */
  12240. getPixelForOffset: function (time) {
  12241. var me = this;
  12242. var size = me._horizontal ? me.width : me.height;
  12243. var start = me._horizontal ? me.left : me.top;
  12244. var pos = interpolate(me._table, 'time', time, 'pos');
  12245. return start + size * (me._offsets.left + pos) / (me._offsets.left + 1 + me._offsets.right);
  12246. },
  12247. getPixelForValue: function (value, index, datasetIndex) {
  12248. var me = this;
  12249. var time = null;
  12250. if (index !== undefined && datasetIndex !== undefined) {
  12251. time = me._timestamps.datasets[datasetIndex][index];
  12252. }
  12253. if (time === null) {
  12254. time = parse(value, me);
  12255. }
  12256. if (time !== null) {
  12257. return me.getPixelForOffset(time);
  12258. }
  12259. },
  12260. getPixelForTick: function (index) {
  12261. var ticks = this.getTicks();
  12262. return index >= 0 && index < ticks.length ?
  12263. this.getPixelForOffset(ticks[index].value) :
  12264. null;
  12265. },
  12266. getValueForPixel: function (pixel) {
  12267. var me = this;
  12268. var size = me._horizontal ? me.width : me.height;
  12269. var start = me._horizontal ? me.left : me.top;
  12270. var pos = (size ? (pixel - start) / size : 0) * (me._offsets.left + 1 + me._offsets.left) - me._offsets.right;
  12271. var time = interpolate(me._table, 'pos', pos, 'time');
  12272. return moment(time);
  12273. },
  12274. /**
  12275. * Crude approximation of what the label width might be
  12276. * @private
  12277. */
  12278. getLabelWidth: function (label) {
  12279. var me = this;
  12280. var ticksOpts = me.options.ticks;
  12281. var tickLabelWidth = me.ctx.measureText(label).width;
  12282. var angle = helpers.toRadians(ticksOpts.maxRotation);
  12283. var cosRotation = Math.cos(angle);
  12284. var sinRotation = Math.sin(angle);
  12285. var tickFontSize = helpers.valueOrDefault(ticksOpts.fontSize, defaults.global.defaultFontSize);
  12286. return (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
  12287. },
  12288. /**
  12289. * @private
  12290. */
  12291. getLabelCapacity: function (exampleTime) {
  12292. var me = this;
  12293. var formatOverride = me.options.time.displayFormats.millisecond; // Pick the longest format for guestimation
  12294. var exampleLabel = me.tickFormatFunction(moment(exampleTime), 0, [], formatOverride);
  12295. var tickLabelWidth = me.getLabelWidth(exampleLabel);
  12296. var innerWidth = me.isHorizontal() ? me.width : me.height;
  12297. var capacity = Math.floor(innerWidth / tickLabelWidth);
  12298. return capacity > 0 ? capacity : 1;
  12299. }
  12300. });
  12301. Chart.scaleService.registerScaleType('time', TimeScale, defaultConfig);
  12302. };
  12303. }, {"1": 1, "25": 25, "45": 45}]}, {}, [7])(7)
  12304. });