Chart.js 358 KB

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