Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Chart.js 305KB

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