Chart.js 299 KB

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